static int max14656_read_block_reg(struct i2c_client *client, u8 reg,
				  u8 length, u8 *val)
{
	int ret;

	ret = i2c_smbus_read_i2c_block_data(client, reg,
			length, val);

	if (ret < 0) {
		dev_err(&client->dev, "failed to block read reg 0x%x: %d\n",
				reg, ret);
		return ret;
	}

	return 0;
}
Пример #2
0
static int wl1273_fm_read_reg(struct wl1273_core *core, u8 reg, u16 *value)
{
	struct i2c_client *client = core->client;
	u8 b[2];
	int r;

	r = i2c_smbus_read_i2c_block_data(client, reg, sizeof(b), b);
	if (r != 2) {
		dev_err(&client->dev, "%s: Read: %d fails.\n", __func__, reg);
		return -EREMOTEIO;
	}

	*value = (u16)b[0] << 8 | b[1];

	return 0;
}
Пример #3
0
int max77693_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
{
	struct max77693_dev *max77693 = i2c_get_clientdata(i2c);
	int ret;

	mutex_lock(&max77693->iolock);
	ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
	mutex_unlock(&max77693->iolock);

	if (unlikely(ret < 0)) {
		dev_err(max77693->dev, "%s failed: reg=0x%x\n", __func__, reg);
		return ret;
	}

	return 0;
}
static int bcmpmu_i2c_read_device_direct_bulk(struct bcmpmu59xxx *bcmpmu,
					      u32 reg, u8 *val, int len)
{
	int err = 0;
	struct i2c_client *clt;

	if ((DEC_REG_ADD(reg) + len) >= PMU_REG_MAX)
		return -ENODEV;
	clt = bcmpmu_get_client(bcmpmu, reg);

	bcmpmu_i2c_lock(bcmpmu);
	err =
	    i2c_smbus_read_i2c_block_data(clt, (u8) DEC_REG_ADD(reg), len, val);
	bcmpmu_i2c_unlock(bcmpmu);
	return (err < 0 ? err : 0);
}
static ssize_t ak8975_adc(struct device *dev,
		struct device_attribute *attr, char *strbuf)
{
	struct akm8975_data *ak_data  = dev_get_drvdata(dev);
	u8 buf[8];
	s16 x, y, z;
	int err, success;
	
	printk("ak8975_adc\n");
	
	mutex_lock(&ak_data->lock);
	
	/* start ADC conversion */
	err = i2c_smbus_write_byte_data(ak_data->this_client,
					AK8975_REG_CNTL, REG_CNTL_MODE_ONCE);
	
	printk("ak8975_adc write err:%d\n", err);
	
	/* wait for ADC conversion to complete */
	err = akm8975_wait_for_data_ready(ak_data);
	if (err) {
		pr_err("%s: wait for data ready failed\n", __func__);
		return;
	}
	msleep(10);
	/* get the value and report it */
	err = i2c_smbus_read_i2c_block_data(ak_data->this_client,
					AK8975_REG_ST1, sizeof(buf), buf);
	//printk("ak8975_adc read err:%d\n", err);
	if (err != sizeof(buf)) {
		pr_err("%s: read data over i2c failed\n", __func__);
		return;
	}
	mutex_unlock(&ak_data->lock);
	
	/* buf[0] is status1, buf[7] is status2 */
	if ((buf[0] == 0) | (buf[7] == 1)) success = 0;
	else success = 1;

	x = buf[1] | (buf[2] << 8);
	y = buf[3] | (buf[4] << 8);
	z = buf[5] | (buf[6] << 8);

	pr_info("%s: raw x = %d, y = %d, z = %d\n", __func__, x, y, z);
	
	return sprintf(strbuf, "%s, %d, %d, %d\n", (success ? "OK" : "NG"), x, y, z);
}
Пример #6
0
static void silead_ts_read_data(struct i2c_client *client)
{
	struct silead_ts_data *data = i2c_get_clientdata(client);
	struct input_dev *input = data->input;
	struct device *dev = &client->dev;
	u8 *bufp, buf[SILEAD_TS_DATA_LEN];
	int touch_nr, error, i;

	error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_DATA,
					      SILEAD_TS_DATA_LEN, buf);
	if (error < 0) {
		dev_err(dev, "Data read error %d\n", error);
		return;
	}

	touch_nr = buf[0];
	if (touch_nr > data->max_fingers) {
		dev_warn(dev, "More touches reported then supported %d > %d\n",
			 touch_nr, data->max_fingers);
		touch_nr = data->max_fingers;
	}

	bufp = buf + SILEAD_POINT_DATA_LEN;
	for (i = 0; i < touch_nr; i++, bufp += SILEAD_POINT_DATA_LEN) {
		/* Bits 4-7 are the touch id */
		data->id[i] = (bufp[SILEAD_POINT_X_MSB_OFF] &
			       SILEAD_TOUCH_ID_MASK) >> 4;
		touchscreen_set_mt_pos(&data->pos[i], &data->prop,
			get_unaligned_le16(&bufp[SILEAD_POINT_X_OFF]) & 0xfff,
			get_unaligned_le16(&bufp[SILEAD_POINT_Y_OFF]) & 0xfff);
	}

	input_mt_assign_slots(input, data->slots, data->pos, touch_nr, 0);

	for (i = 0; i < touch_nr; i++) {
		input_mt_slot(input, data->slots[i]);
		input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
		input_report_abs(input, ABS_MT_POSITION_X, data->pos[i].x);
		input_report_abs(input, ABS_MT_POSITION_Y, data->pos[i].y);

		dev_dbg(dev, "x=%d y=%d hw_id=%d sw_id=%d\n", data->pos[i].x,
			data->pos[i].y, data->id[i], data->slots[i]);
	}

	input_mt_sync_frame(input);
	input_sync(input);
}
Пример #7
0
// Reads the 3 gyro channels and stores them in vector g
void L3G4200D::read()
{
  // Specify the address of the slave device.
  if (ioctl(file, I2C_SLAVE, GYR_ADDRESS) < 0)
  {
      printf("Failed to acquire bus access and/or talk to slave %x", GYR_ADDRESS);
      exit(1);
  }

  __s32 res;
  __u8  reg, val;

  reg = L3G4200D_OUT_X_L | (1 << 7) ;
  __u8  buf[6];

  res = i2c_smbus_read_i2c_block_data(file, reg, 6, (__u8 *)buf);
  if (res != 6)
  {
    printf("Failed to read acc data in read()\n");
    exit(1);
  }

  for (int i = 0; i < 6; i++)
  {
    buf[i] = ~buf[i];
    buf[i] += 0x01;
  }
  printf("g: ");
  for (int i = 0; i < 6; i++)
    printf("%02x ", buf[i]);
  printf("\n");

  __u8 xla = buf[0];
  __u8 xha = buf[1];
  __u8 yla = buf[2];
  __u8 yha = buf[3];
  __u8 zla = buf[4];
  __u8 zha = buf[5];

  __s16 x = xha << 8 | xla;
  __s16 y = yha << 8 | yla;
  __s16 z = zha << 8 | zla;

	g.x = x;
	g.y = y;
	g.z = z;
}
static void get_fw_ver_ic(void *device_data)
{
	struct mms_info *info = (struct mms_info *)device_data;
	struct mms_fac_data *fac_data = info->fac_data;
	struct i2c_client *client = info->client;
	char buff[TSP_CMD_FULL_VER_LEN] = {0,};
	int ret;

	set_default_result(fac_data);

	ret = i2c_smbus_read_i2c_block_data(client, MMS_VENDOR_ID, 2, buff);
	if (ret < 0) {
		dev_err(&client->dev, "Failed to read vendor ID(%d)\n", ret);
		goto out;
	}

	ret = i2c_smbus_read_byte_data(client, MMS_HW_ID);
	if (ret < 0) {
		dev_err(&client->dev, "Failed to read HW ID(%d)\n", ret);
		goto out;
	}

	sprintf(buff + 2, "%02X", ret);

	ret = i2c_smbus_read_byte_data(client, MMS_CONFIG_VERSION);
	if (ret < 0) {
		dev_err(&client->dev, "Failed to read FW ver (%d)\n", ret);
		goto out;
	}

	sprintf(buff + 4, "%04X", ret);

	fac_data->cmd_state = CMD_STATUS_OK;
	sprintf(fac_data->cmd_buff, "%s", buff);
	set_cmd_result(fac_data, fac_data->cmd_buff, strlen(fac_data->cmd_buff));

	dev_info(&client->dev, "%s : %s\n", __func__, fac_data->cmd_buff);

	return;

out:
	fac_data->cmd_state = CMD_STATUS_FAIL;
	sprintf(fac_data->cmd_buff, "NG");
	set_cmd_result(fac_data, fac_data->cmd_buff, strlen(fac_data->cmd_buff));

	return ;
}
static void an30259a_debug(struct i2c_client *client)
{
	struct an30259a_data *data = i2c_get_clientdata(client);
	int ret;
	u8 buff[21] = {0,};
	ret = i2c_smbus_read_i2c_block_data(client,
		AN30259A_REG_SRESET|AN30259A_CTN_RW_FLG,
		sizeof(buff), buff);
	if (ret != sizeof(buff)) {
		dev_err(&data->client->dev,
			"%s: failure on i2c_smbus_read_i2c_block_data\n",
			__func__);
	}
	print_hex_dump(KERN_ERR, "an30259a: ",
		DUMP_PREFIX_OFFSET, 32, 1, buff,
		sizeof(buff), false);
}
Пример #10
0
static int nastech_set_int_mode(struct i2c_client *client, int data)
{
	unsigned char datareg;
	int ret = 0;
	datareg = data;
	ret = i2c_smbus_write_i2c_block_data(client, NAS_INT_MODE, 1, &datareg);
	if (ret < 0) {
		printk(KERN_ERR "%s: Failed to set INT MODE\n", __func__);
		return ret;
	} else {
		ret = i2c_smbus_read_i2c_block_data(client, NAS_INT_MODE, 1,
						  &datareg);
		printk(KERN_DEBUG
		       "%s: Success to set INT MODE, INT MODE =0x%x\n",__func__, datareg);
	}
	return ret;
}
Пример #11
0
static int cs42l51_fill_cache(struct snd_soc_codec *codec)
{
	u8 *cache = codec->reg_cache + 1;
	struct i2c_client *i2c_client = to_i2c_client(codec->dev);
	s32 length;

	length = i2c_smbus_read_i2c_block_data(i2c_client,
			CS42L51_FIRSTREG | 0x80, CS42L51_NUMREGS, cache);
	if (length != CS42L51_NUMREGS) {
		dev_err(&i2c_client->dev,
				"I2C read failure, addr=0x%x (ret=%d vs %d)\n",
				i2c_client->addr, length, CS42L51_NUMREGS);
		return -EIO;
	}

	return 0;
}
static int mma8x5x_read_data(struct i2c_client *client,
		struct mma8x5x_data_axis *data)
{
	u8 tmp_data[MMA8X5X_BUF_SIZE];
	int ret;

	ret = i2c_smbus_read_i2c_block_data(client,
					MMA8X5X_OUT_X_MSB, 7, tmp_data);
	if (ret < MMA8X5X_BUF_SIZE) {
		dev_err(&client->dev, "i2c block read failed\n");
		return -EIO;
	}
	data->x = ((tmp_data[0] << 8) & 0xff00) | tmp_data[1];
	data->y = ((tmp_data[2] << 8) & 0xff00) | tmp_data[3];
	data->z = ((tmp_data[4] << 8) & 0xff00) | tmp_data[5];
	return 0;
}
Пример #13
0
static inline int __ricoh61x_bulk_reads(struct i2c_client *client, u8 reg,
				int len, uint8_t *val)
{
	int ret;
	int i;

	ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
	if (ret < 0) {
		dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
		return ret;
	}
	for (i = 0; i < len; ++i) {
		dev_dbg(&client->dev, "ricoh61x: reg read  reg=%x, val=%x\n",
				reg + i, *(val + i));
	}
	return 0;
}
Пример #14
0
/*
 * Pre-fill the CS4270 register cache.
 *
 * We use the auto-increment feature of the CS4270 to read all registers in
 * one shot.
 */
static int cs4270_fill_cache(struct snd_soc_codec *codec)
{
	u8 *cache = codec->reg_cache;
	struct i2c_client *i2c_client = codec->control_data;
	s32 length;

	length = i2c_smbus_read_i2c_block_data(i2c_client,
		CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);

	if (length != CS4270_NUMREGS) {
		printk(KERN_ERR "cs4270: I2C read failure, addr=0x%x\n",
		       i2c_client->addr);
		return -EIO;
	}

	return 0;
}
Пример #15
0
/**
 * cs4270_fill_cache - pre-fill the CS4270 register cache.
 * @codec: the codec for this CS4270
 *
 * This function fills in the CS4270 register cache by reading the register
 * values from the hardware.
 *
 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
 * After the initial read to pre-fill the cache, the CS4270 never updates
 * the register values, so we won't have a cache coherency problem.
 *
 * We use the auto-increment feature of the CS4270 to read all registers in
 * one shot.
 */
static int cs4270_fill_cache(struct snd_soc_codec *codec)
{
	u8 *cache = codec->reg_cache;
	struct i2c_client *i2c_client = codec->control_data;
	s32 length;

	length = i2c_smbus_read_i2c_block_data(i2c_client,
		CS4270_FIRSTREG | CS4270_I2C_INCR, CS4270_NUMREGS, cache);

	if (length != CS4270_NUMREGS) {
		dev_err(codec->dev, "i2c read failure, addr=0x%x\n",
		       i2c_client->addr);
		return -EIO;
	}

	return 0;
}
Пример #16
0
/*
 * User data attribute
 */
static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj,
				  struct bin_attribute *attr,
				  char *buf, loff_t off, size_t count)
{
	struct i2c_client *client = kobj_to_i2c_client(kobj);
	int rc;

	dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
		buf, off, count);

	rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
					   count, buf);
	if (rc < 0)
		return -EIO;

	return count;
}
Пример #17
0
static int
rv3029c2_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf,
	unsigned len)
{
	int ret;

	if ((reg > RV3029C2_USR1_RAM_PAGE + 7) ||
		(reg + len > RV3029C2_USR1_RAM_PAGE + 8))
		return -EINVAL;

	ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf);
	if (ret < 0)
		return ret;
	if (ret < len)
		return -EIO;
	return 0;
}
static int as5812_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,
              int data_len)
{
    int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data);

    if (unlikely(result < 0))
        goto abort;
    if (unlikely(result != data_len)) {
        result = -EIO;
        goto abort;
    }

    result = 0;

abort:
    return result;
}
void nxt_i2c_sensor_poll_work(struct work_struct *work)
{
	struct nxt_i2c_sensor_data *data =
		container_of(work, struct nxt_i2c_sensor_data, poll_work);
	const struct nxt_i2c_sensor_mode_info *i2c_mode_info =
		&data->info->i2c_mode_info[data->sensor.mode];
	struct lego_sensor_mode_info *mode_info =
			&data->sensor.mode_info[data->sensor.mode];

	if (data->info->ops && data->info->ops->poll_cb)
		data->info->ops->poll_cb(data);
	else
		i2c_smbus_read_i2c_block_data(data->client,
			i2c_mode_info->read_data_reg,
			lego_sensor_get_raw_data_size(mode_info),
			mode_info->raw_data);
}
Пример #20
0
static int zopt2201_read(struct zopt2201_data *data, u8 reg)
{
	struct i2c_client *client = data->client;
	int tries = 10;
	u8 buf[3];
	int ret;

	mutex_lock(&data->lock);
	ret = zopt2201_enable_mode(data, reg == ZOPT2201_UVB_DATA);
	if (ret < 0)
		goto fail;

	while (tries--) {
		unsigned long t = zopt2201_resolution[data->res].us;

		if (t <= 20000)
			usleep_range(t, t + 1000);
		else
			msleep(t / 1000);
		ret = i2c_smbus_read_byte_data(client, ZOPT2201_MAIN_STATUS);
		if (ret < 0)
			goto fail;
		if (ret & ZOPT2201_MAIN_STATUS_DRDY)
			break;
	}

	if (tries < 0) {
		ret = -ETIMEDOUT;
		goto fail;
	}

	ret = i2c_smbus_read_i2c_block_data(client, reg, sizeof(buf), buf);
	if (ret < 0)
		goto fail;

	ret = i2c_smbus_write_byte_data(client, ZOPT2201_MAIN_CTRL, 0x00);
	if (ret < 0)
		goto fail;
	mutex_unlock(&data->lock);

	return (buf[2] << 16) | (buf[1] << 8) | buf[0];

fail:
	mutex_unlock(&data->lock);
	return ret;
}
static int backlight_i2c_read(struct i2c_client *client,
		u8 reg, u8 *val, unsigned int len)
{

	int err = 0;
	int retry = 3;

	while (retry--) {
		err = i2c_smbus_read_i2c_block_data(client,
				reg, len, val);
		if (err >= 0)
			return err;

		dev_info(&client->dev, "%s: i2c transfer error.\n", __func__);
	}
	return err;

}
Пример #22
0
static int clearpad_i2c_read(struct device *dev, u8 reg, u8 *buf, u8 len)
{
	s32 rc = 0;
	int rsize = I2C_SMBUS_BLOCK_MAX;
	int off;

	for (off = 0; off < len; off += rsize) {
		if (len < off + I2C_SMBUS_BLOCK_MAX)
			rsize = len - off;
		rc = i2c_smbus_read_i2c_block_data(to_i2c_client(dev),
				reg + off, rsize, &buf[off]);
		if (rc != rsize) {
			dev_err(dev, "%s: rc = %d\n", __func__, rc);
			return rc;
		}
	}
	return 0;
}
inline static int sm5703_read_device(struct i2c_client *i2c,
		int reg, int bytes, void *dest)
{
	int ret;
	if (bytes > 1) {
		ret = i2c_smbus_read_i2c_block_data(i2c, reg, bytes, dest);
	} else {
		ret = i2c_smbus_read_byte_data(i2c, reg);
		if (ret < 0)
			return ret;
		*(unsigned char *)dest = (unsigned char)ret;

		pr_debug("%s : ret = 0x%x, reg = 0x%d, dest = 0x%d\n",
				__func__, ret, reg, *(unsigned char *)dest);
	}

	return ret;
}
Пример #24
0
static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
{
	int ret = mma8452_drdy(data);

	if (ret < 0)
		return ret;

	ret = mma8452_set_runtime_pm_state(data->client, true);
	if (ret)
		return ret;

	ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
					    3 * sizeof(__be16), (u8 *)buf);

	ret = mma8452_set_runtime_pm_state(data->client, false);

	return ret;
}
Пример #25
0
int hook() 
{

	__u8 HOOK_CMD[6]={0x06,0x00,0x00,0x00,0x02,0x08};
	int ret=0;
	int i=0;
	
	ret=i2c_smbus_write_i2c_block_data(i2c_fd, 0x06, 5, &HOOK_CMD[1]);
	i2c_smbus_read_i2c_block_data(i2c_fd, FC_CMD_HOOK_ACK, &FC_RX_INFO[0]);
	//printf("i2c_smbus_read_i2c_block_data ret=%d\n",ret);

	if (FC_RX_INFO[0]!=FC_CMD_HOOK_ACK || FC_RX_INFO[1]!=FC_CMD_ACK){//Check Return 0xFC
		printf("FC_RX_INFO[0]=%x, FC_RX_INFO[1]=%x\n",FC_RX_INFO[0],FC_RX_INFO[1]);
		return -1;
	}
	
	return ret;
}
Пример #26
0
static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val)
{
	int ret;

	/* wake up the device */
	pm_runtime_get_sync(pm2->dev);

	ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg,
				1, val);
	if (ret < 0)
		dev_err(pm2->dev, "Error reading register at 0x%x\n", reg);
	else
		ret = 0;

	pm_runtime_put_sync(pm2->dev);

	return ret;
}
Пример #27
0
static int hmc5843_detect(struct i2c_client *client,
			  struct i2c_board_info *info)
{
	unsigned char id_str[HMC5843_ID_REG_LENGTH];

	if (client->addr != HMC5843_I2C_ADDRESS)
		return -ENODEV;

	if (i2c_smbus_read_i2c_block_data(client, HMC5843_ID_REG_A,
				HMC5843_ID_REG_LENGTH, id_str)
			!= HMC5843_ID_REG_LENGTH)
		return -ENODEV;

	if (0 != strncmp(id_str, HMC5843_ID_STRING, HMC5843_ID_REG_LENGTH))
		return -ENODEV;

	return 0;
}
Пример #28
0
static int silead_ts_get_id(struct i2c_client *client)
{
	struct silead_ts_data *data = i2c_get_clientdata(client);
	__le32 chip_id;
	int error;

	error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_ID,
					      sizeof(chip_id), (u8 *)&chip_id);
	if (error < 0) {
		dev_err(&client->dev, "Chip ID read error %d\n", error);
		return error;
	}

	data->chip_id = le32_to_cpu(chip_id);
	dev_info(&client->dev, "Silead chip ID: 0x%8X", data->chip_id);

	return 0;
}
Пример #29
0
static int rs5c_get_regs(struct rs5c372 *rs5c)
{
	struct i2c_client	*client = rs5c->client;
	struct i2c_msg		msgs[] = {
		{ client->addr, I2C_M_RD, sizeof rs5c->buf, rs5c->buf },
	};

	/* This implements the third reading method from the datasheet, using
	 * an internal address that's reset after each transaction (by STOP)
	 * to 0x0f ... so we read extra registers, and skip the first one.
	 *
	 * The first method doesn't work with the iop3xx adapter driver, on at
	 * least 80219 chips; this works around that bug.
	 *
	 * The third method on the other hand doesn't work for the SMBus-only
	 * configurations, so we use the the first method there, stripping off
	 * the extra register in the process.
	 */
	if (rs5c->smbus) {
		int addr = RS5C_ADDR(RS5C372_REG_SECS);
		int size = sizeof(rs5c->buf) - 1;

		if (i2c_smbus_read_i2c_block_data(client, addr, size,
						  rs5c->buf + 1) != size) {
			dev_warn(&client->dev, "can't read registers\n");
			return -EIO;
		}
	} else {
		if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
			dev_warn(&client->dev, "can't read registers\n");
			return -EIO;
		}
	}

	dev_dbg(&client->dev,
		"%02x %02x %02x (%02x) %02x %02x %02x (%02x), "
		"%02x %02x %02x, %02x %02x %02x; %02x %02x\n",
		rs5c->regs[0],  rs5c->regs[1],  rs5c->regs[2],  rs5c->regs[3],
		rs5c->regs[4],  rs5c->regs[5],  rs5c->regs[6],  rs5c->regs[7],
		rs5c->regs[8],  rs5c->regs[9],  rs5c->regs[10], rs5c->regs[11],
		rs5c->regs[12], rs5c->regs[13], rs5c->regs[14], rs5c->regs[15]);

	return 0;
}
static int lm3561_set_reg_data(struct lm3561_drv_data *data,
				u8 addr, u8 mask, u8 value)
{
	u8 current_value;
	s32 result;
	u8 reg = reg_map[addr];

	if (mask != 0xFF) {
		result = i2c_smbus_read_i2c_block_data(
						data->client,
						reg,
						1,
						&current_value);
		if (result < 0) {
			dev_err(&data->client->dev,
				"%s(): Failed to read register(0x%02x)"
					". errno=%d\n",
					__func__, reg, result);
			return -EIO;
		}
		value = (current_value & ~mask) | value;
	}

	/* For debug-purpose, get info on what is written to chip */
	dev_dbg(&data->client->dev,
		"%s write register(0x%02x) data(0x%02x)\n",
		__func__, reg, value);

	result = i2c_smbus_write_i2c_block_data(
					data->client,
					reg,
					1,
					&value);
	if (result < 0) {
		dev_err(&data->client->dev,
			"%s(): Failed to write register(0x%02x). "
				"errno=%d\n",
				__func__, reg, result);
		return -EIO;
	}
	data->shadow[addr].val = value;
	data->shadow[addr].updated = 1;
	return 0;
}