u32 data1;
};
-static int tsl2563_write(struct i2c_client *client, u8 reg, u8 value)
-{
- int ret;
- u8 buf[2];
-
- buf[0] = TSL2563_CMD | reg;
- buf[1] = value;
-
- ret = i2c_master_send(client, buf, sizeof(buf));
- return (ret == sizeof(buf)) ? 0 : ret;
-}
-
-static int tsl2563_read(struct i2c_client *client, u8 reg, void *buf, int len)
-{
- int ret;
- u8 cmd = TSL2563_CMD | reg;
-
- ret = i2c_master_send(client, &cmd, sizeof(cmd));
- if (ret != sizeof(cmd))
- return ret;
-
- return i2c_master_recv(client, buf, len);
-}
-
static int tsl2563_set_power(struct tsl2563_chip *chip, int on)
{
struct i2c_client *client = chip->client;
u8 cmd;
cmd = on ? TSL2563_CMD_POWER_ON : TSL2563_CMD_POWER_OFF;
- return tsl2563_write(client, TSL2563_REG_CTRL, cmd);
+ return i2c_smbus_write_byte_data(client,
+ TSL2563_CMD | TSL2563_REG_CTRL, cmd);
}
/*
{
struct i2c_client *client = chip->client;
int ret;
- u8 val;
- ret = tsl2563_read(client, TSL2563_REG_CTRL, &val, sizeof(val));
- if (ret != sizeof(val))
+ ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_CTRL);
+ if (ret < 0)
return ret;
- return (val & TSL2563_CTRL_POWER_MASK) == TSL2563_CMD_POWER_ON;
+ return (ret & TSL2563_CTRL_POWER_MASK) == TSL2563_CMD_POWER_ON;
}
static int tsl2563_configure(struct tsl2563_chip *chip)
{
int ret;
- ret = tsl2563_write(chip->client, TSL2563_REG_TIMING,
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_TIMING,
chip->gainlevel->gaintime);
if (ret)
goto error_ret;
- ret = tsl2563_write(chip->client, TSL2563_REG_HIGHLOW,
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_HIGHLOW,
chip->high_thres & 0xFF);
if (ret)
goto error_ret;
- ret = tsl2563_write(chip->client, TSL2563_REG_HIGHHIGH,
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_HIGHHIGH,
(chip->high_thres >> 8) & 0xFF);
if (ret)
goto error_ret;
- ret = tsl2563_write(chip->client, TSL2563_REG_LOWLOW,
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_LOWLOW,
chip->low_thres & 0xFF);
if (ret)
goto error_ret;
- ret = tsl2563_write(chip->client, TSL2563_REG_LOWHIGH,
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_LOWHIGH,
(chip->low_thres >> 8) & 0xFF);
/* Interrupt register is automatically written anyway if it is relevant
so is not here */
struct i2c_client *client = chip->client;
int ret;
- ret = tsl2563_read(client, TSL2563_REG_ID, id, sizeof(*id));
- if (ret != sizeof(*id))
+ ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_ID);
+ if (ret < 0)
return ret;
return 0;
(adc > chip->gainlevel->max) ?
chip->gainlevel++ : chip->gainlevel--;
- tsl2563_write(client, TSL2563_REG_TIMING,
- chip->gainlevel->gaintime);
+ i2c_smbus_write_byte_data(client,
+ TSL2563_CMD | TSL2563_REG_TIMING,
+ chip->gainlevel->gaintime);
tsl2563_wait_adc(chip);
tsl2563_wait_adc(chip);
static int tsl2563_get_adc(struct tsl2563_chip *chip)
{
struct i2c_client *client = chip->client;
- u8 buf0[2], buf1[2];
u16 adc0, adc1;
int retry = 1;
int ret = 0;
}
while (retry) {
- ret = tsl2563_read(client,
- TSL2563_REG_DATA0LOW,
- buf0, sizeof(buf0));
- if (ret != sizeof(buf0))
+ ret = i2c_smbus_read_word_data(client,
+ TSL2563_CMD | TSL2563_REG_DATA0LOW);
+ if (ret < 0)
goto out;
+ adc0 = ret;
- ret = tsl2563_read(client, TSL2563_REG_DATA1LOW,
- buf1, sizeof(buf1));
- if (ret != sizeof(buf1))
+ ret = i2c_smbus_read_word_data(client,
+ TSL2563_CMD | TSL2563_REG_DATA1LOW);
+ if (ret < 0)
goto out;
-
- adc0 = (buf0[1] << 8) + buf0[0];
- adc1 = (buf1[1] << 8) + buf1[0];
+ adc1 = ret;
retry = tsl2563_adjust_gainlevel(chip, adc0);
}
else
address = TSL2563_REG_LOWLOW;
mutex_lock(&chip->lock);
- ret = tsl2563_write(chip->client, address, val & 0xFF);
+ ret = i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | address,
+ val & 0xFF);
if (ret)
goto error_ret;
- ret = tsl2563_write(chip->client, address + 1,
- (val >> 8) & 0xFF);
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | (address + 1),
+ (val >> 8) & 0xFF);
if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
chip->high_thres = val;
else
{
struct iio_dev *dev_info = private;
struct tsl2563_chip *chip = iio_priv(dev_info);
- u8 cmd = TSL2563_CMD | TSL2563_CLEARINT;
iio_push_event(dev_info, 0,
IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_LIGHT,
iio_get_time_ns());
/* clear the interrupt and push the event */
- i2c_master_send(chip->client, &cmd, sizeof(cmd));
+ i2c_smbus_write_byte(chip->client, TSL2563_CMD | TSL2563_CLEARINT);
return IRQ_HANDLED;
}
if (ret)
goto out;
}
- ret = tsl2563_write(chip->client, TSL2563_REG_INT, chip->intr);
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_INT,
+ chip->intr);
chip->int_enabled = true;
}
if (!state && (chip->intr & 0x30)) {
chip->intr |= ~0x30;
- ret = tsl2563_write(chip->client, TSL2563_REG_INT, chip->intr);
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_INT,
+ chip->intr);
chip->int_enabled = false;
/* now the interrupt is not enabled, we can go to sleep */
schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
int event_code)
{
struct tsl2563_chip *chip = iio_priv(indio_dev);
- u8 rxbuf;
int ret;
mutex_lock(&chip->lock);
- ret = tsl2563_read(chip->client, TSL2563_REG_INT,
- &rxbuf, sizeof(rxbuf));
+ ret = i2c_smbus_read_byte_data(chip->client,
+ TSL2563_CMD | TSL2563_REG_INT);
mutex_unlock(&chip->lock);
if (ret < 0)
goto error_ret;
- ret = !!(rxbuf & 0x30);
+ ret = !!(ret & 0x30);
error_ret:
return ret;
cancel_delayed_work(&chip->poweroff_work);
/* Ensure that interrupts are disabled - then flush any bottom halves */
chip->intr |= ~0x30;
- tsl2563_write(chip->client, TSL2563_REG_INT, chip->intr);
+ i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT,
+ chip->intr);
flush_scheduled_work();
tsl2563_set_power(chip, 0);
if (client->irq)