Commit eac15d8d authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

staging: iio: tsl2x7x: add common function for clearing interrupts

There were three places where the same chunk of code was used to clear
interrupts. This patch creates a common function
tsl2x7x_clear_interrupts() to reduce duplicate code.
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent a4a21414
...@@ -279,6 +279,20 @@ static const u8 device_channel_config[] = { ...@@ -279,6 +279,20 @@ static const u8 device_channel_config[] = {
ALSPRX2 ALSPRX2
}; };
static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg)
{
int ret;
ret = i2c_smbus_write_byte(chip->client,
TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | reg);
if (ret < 0)
dev_err(&chip->client->dev,
"%s: failed to clear interrupt status %x: %d\n",
__func__, reg, 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
...@@ -346,16 +360,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) ...@@ -346,16 +360,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
buf[i] = ret; buf[i] = ret;
} }
/* clear any existing interrupt status */ ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_ALS_INT_CLR);
ret = i2c_smbus_write_byte(chip->client, if (ret < 0)
TSL2X7X_CMD_REG | goto out_unlock;
TSL2X7X_CMD_SPL_FN |
TSL2X7X_CMD_ALS_INT_CLR);
if (ret < 0) {
dev_err(&chip->client->dev,
"i2c_write_command failed - err = %d\n", ret);
goto out_unlock; /* have no data, so return failure */
}
/* extract ALS/lux data */ /* extract ALS/lux data */
ch0 = le16_to_cpup((const __le16 *)&buf[0]); ch0 = le16_to_cpup((const __le16 *)&buf[0]);
...@@ -706,18 +713,11 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) ...@@ -706,18 +713,11 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
"%s: failed in tsl2x7x_IOCTL_INT_SET.\n", "%s: failed in tsl2x7x_IOCTL_INT_SET.\n",
__func__); __func__);
/* Clear out any initial interrupts */ ret = tsl2x7x_clear_interrupts(chip,
ret = i2c_smbus_write_byte(chip->client,
TSL2X7X_CMD_REG |
TSL2X7X_CMD_SPL_FN |
TSL2X7X_CMD_PROXALS_INT_CLR); TSL2X7X_CMD_PROXALS_INT_CLR);
if (ret < 0) { if (ret < 0)
dev_err(&chip->client->dev,
"%s: Failed to clear Int status\n",
__func__);
return ret; return ret;
} }
}
return ret; return ret;
} }
...@@ -1421,14 +1421,10 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) ...@@ -1421,14 +1421,10 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
IIO_EV_DIR_EITHER), IIO_EV_DIR_EITHER),
timestamp); timestamp);
} }
/* Clear interrupt now that we have handled it. */
ret = i2c_smbus_write_byte(chip->client, ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR);
TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
TSL2X7X_CMD_PROXALS_INT_CLR);
if (ret < 0) if (ret < 0)
dev_err(&chip->client->dev, return ret;
"Failed to clear irq from event handler. err = %d\n",
ret);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment