move common code to i2c-util.c