Commit aca68c02 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: light: tsl2563: Configure INT in one place

Introduce tsl2563_configure_irq() to configure INT in one place.

While at it, make use of TSL2563_INT_LEVEL and newly introduced
TSL2563_INT_MASK.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: default avatarFerry Toth <ftoth@exalondelft.nl>
Link: https://lore.kernel.org/r/20221207190348.9347-3-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 3c183534
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#define TSL2563_INT_DISABLED 0x00 #define TSL2563_INT_DISABLED 0x00
#define TSL2563_INT_LEVEL 0x10 #define TSL2563_INT_LEVEL 0x10
#define TSL2563_INT_MASK 0x30
#define TSL2563_INT_PERSIST(n) ((n) & 0x0F) #define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
struct tsl2563_gainlevel_coeff { struct tsl2563_gainlevel_coeff {
...@@ -211,6 +212,24 @@ static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id) ...@@ -211,6 +212,24 @@ static int tsl2563_read_id(struct tsl2563_chip *chip, u8 *id)
return 0; return 0;
} }
static int tsl2563_configure_irq(struct tsl2563_chip *chip, bool enable)
{
int ret;
chip->intr &= ~TSL2563_INT_MASK;
if (enable)
chip->intr |= TSL2563_INT_LEVEL;
ret = i2c_smbus_write_byte_data(chip->client,
TSL2563_CMD | TSL2563_REG_INT,
chip->intr);
if (ret < 0)
return ret;
chip->int_enabled = enable;
return 0;
}
/* /*
* "Normalized" ADC value is one obtained with 400ms of integration time and * "Normalized" ADC value is one obtained with 400ms of integration time and
* 16x gain. This function returns the number of bits of shift needed to * 16x gain. This function returns the number of bits of shift needed to
...@@ -620,9 +639,7 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, ...@@ -620,9 +639,7 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev,
int ret = 0; int ret = 0;
mutex_lock(&chip->lock); mutex_lock(&chip->lock);
if (state && !(chip->intr & 0x30)) { if (state && !(chip->intr & TSL2563_INT_MASK)) {
chip->intr &= ~0x30;
chip->intr |= 0x10;
/* ensure the chip is actually on */ /* ensure the chip is actually on */
cancel_delayed_work_sync(&chip->poweroff_work); cancel_delayed_work_sync(&chip->poweroff_work);
if (!tsl2563_get_power(chip)) { if (!tsl2563_get_power(chip)) {
...@@ -633,18 +650,11 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev, ...@@ -633,18 +650,11 @@ static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev,
if (ret) if (ret)
goto out; goto out;
} }
ret = i2c_smbus_write_byte_data(chip->client, ret = tsl2563_configure_irq(chip, true);
TSL2563_CMD | TSL2563_REG_INT,
chip->intr);
chip->int_enabled = true;
} }
if (!state && (chip->intr & 0x30)) { if (!state && (chip->intr & TSL2563_INT_MASK)) {
chip->intr &= ~0x30; ret = tsl2563_configure_irq(chip, false);
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 */ /* now the interrupt is not enabled, we can go to sleep */
schedule_delayed_work(&chip->poweroff_work, 5 * HZ); schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
} }
...@@ -668,7 +678,7 @@ static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev, ...@@ -668,7 +678,7 @@ static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
return !!(ret & 0x30); return !!(ret & TSL2563_INT_MASK);
} }
static const struct iio_info tsl2563_info_no_irq = { static const struct iio_info tsl2563_info_no_irq = {
...@@ -796,9 +806,7 @@ static void tsl2563_remove(struct i2c_client *client) ...@@ -796,9 +806,7 @@ static void tsl2563_remove(struct i2c_client *client)
if (!chip->int_enabled) if (!chip->int_enabled)
cancel_delayed_work_sync(&chip->poweroff_work); cancel_delayed_work_sync(&chip->poweroff_work);
/* Ensure that interrupts are disabled - then flush any bottom halves */ /* Ensure that interrupts are disabled - then flush any bottom halves */
chip->intr &= ~0x30; tsl2563_configure_irq(chip, false);
i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT,
chip->intr);
tsl2563_set_power(chip, 0); tsl2563_set_power(chip, 0);
} }
......
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