staging: iio: tsl2x7x: add common function for reading chip status
There were three places where the same chunk of code was used to read the chip status. This patch creates a common function tsl2x7x_read_status() to reduce duplicate code. This patch also corrects tsl2x7x_event_handler() to properly check for an error after reading the chip status. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
eac15d8ded
commit
107eb59bc1
|
@ -293,6 +293,20 @@ static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = i2c_smbus_read_byte_data(chip->client,
|
||||||
|
TSL2X7X_CMD_REG | TSL2X7X_STATUS);
|
||||||
|
if (ret < 0)
|
||||||
|
dev_err(&chip->client->dev,
|
||||||
|
"%s: failed to read STATUS register: %d\n", __func__,
|
||||||
|
ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tsl2x7x_get_lux() - Reads and calculates current lux value.
|
* tsl2x7x_get_lux() - Reads and calculates current lux value.
|
||||||
* @indio_dev: pointer to IIO device
|
* @indio_dev: pointer to IIO device
|
||||||
|
@ -332,13 +346,10 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_smbus_read_byte_data(chip->client,
|
ret = tsl2x7x_read_status(chip);
|
||||||
TSL2X7X_CMD_REG | TSL2X7X_STATUS);
|
if (ret < 0)
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(&chip->client->dev,
|
|
||||||
"%s: Failed to read STATUS Reg\n", __func__);
|
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
|
||||||
/* is data new & valid */
|
/* is data new & valid */
|
||||||
if (!(ret & TSL2X7X_STA_ADC_VALID)) {
|
if (!(ret & TSL2X7X_STA_ADC_VALID)) {
|
||||||
dev_err(&chip->client->dev,
|
dev_err(&chip->client->dev,
|
||||||
|
@ -458,12 +469,9 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_smbus_read_byte_data(chip->client,
|
ret = tsl2x7x_read_status(chip);
|
||||||
TSL2X7X_CMD_REG | TSL2X7X_STATUS);
|
if (ret < 0)
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(&chip->client->dev, "i2c err=%d\n", ret);
|
|
||||||
goto prox_poll_err;
|
goto prox_poll_err;
|
||||||
}
|
|
||||||
|
|
||||||
switch (chip->id) {
|
switch (chip->id) {
|
||||||
case tsl2571:
|
case tsl2571:
|
||||||
|
@ -1396,13 +1404,13 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
|
||||||
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
|
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
|
||||||
s64 timestamp = iio_get_time_ns(indio_dev);
|
s64 timestamp = iio_get_time_ns(indio_dev);
|
||||||
int ret;
|
int ret;
|
||||||
u8 value;
|
|
||||||
|
|
||||||
value = i2c_smbus_read_byte_data(chip->client,
|
ret = tsl2x7x_read_status(chip);
|
||||||
TSL2X7X_CMD_REG | TSL2X7X_STATUS);
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* What type of interrupt do we need to process */
|
/* What type of interrupt do we need to process */
|
||||||
if (value & TSL2X7X_STA_PRX_INTR) {
|
if (ret & TSL2X7X_STA_PRX_INTR) {
|
||||||
tsl2x7x_get_prox(indio_dev); /* freshen data for ABI */
|
tsl2x7x_get_prox(indio_dev); /* freshen data for ABI */
|
||||||
iio_push_event(indio_dev,
|
iio_push_event(indio_dev,
|
||||||
IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
|
IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
|
||||||
|
@ -1412,7 +1420,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
|
||||||
timestamp);
|
timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value & TSL2X7X_STA_ALS_INTR) {
|
if (ret & TSL2X7X_STA_ALS_INTR) {
|
||||||
tsl2x7x_get_lux(indio_dev); /* freshen data for ABI */
|
tsl2x7x_get_lux(indio_dev); /* freshen data for ABI */
|
||||||
iio_push_event(indio_dev,
|
iio_push_event(indio_dev,
|
||||||
IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
|
IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
|
||||||
|
|
Loading…
Reference in New Issue