summaryrefslogtreecommitdiff
path: root/drivers/iio
diff options
context:
space:
mode:
authorSubhajit Ghosh <subhajit.ghosh@tweaklogic.com>2024-04-05 21:16:41 +1030
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-04-06 16:52:45 +0100
commit85795d3eddeb5f0e3e11caad24cc78f6c43d7fd1 (patch)
treea33262c9b49639e4960b1e74ae08f9f848713d79 /drivers/iio
parent47ef0501a9cc25c88dcac2b57ed3bab4da53f3d5 (diff)
iio: light: apds9306: Improve apds9306_write_event_config()
Simplify event configuration flow. Suggested-by: Jonathan Cameron <jic23@kernel.org> Link: https://lore.kernel.org/all/20240310124237.52fa8a56@jic23-huawei/ Signed-off-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com> Link: https://lore.kernel.org/r/20240405104641.29478-1-subhajit.ghosh@tweaklogic.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/light/apds9306.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index 49fa6b7d5170..46c647ccd44c 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -1075,14 +1075,16 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev,
{
struct apds9306_data *data = iio_priv(indio_dev);
struct apds9306_regfields *rf = &data->rf;
- int ret, val;
-
- state = !!state;
+ int ret, enabled;
switch (type) {
case IIO_EV_TYPE_THRESH: {
guard(mutex)(&data->mutex);
+ ret = regmap_field_read(rf->int_en, &enabled);
+ if (ret)
+ return ret;
+
/*
* If interrupt is enabled, the channel is set before enabling
* the interrupt. In case of disable, no need to switch
@@ -1091,38 +1093,42 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev,
*/
if (state) {
if (chan->type == IIO_LIGHT)
- val = 1;
+ ret = regmap_field_write(rf->int_src, 1);
else if (chan->type == IIO_INTENSITY)
- val = 0;
+ ret = regmap_field_write(rf->int_src, 0);
else
return -EINVAL;
- ret = regmap_field_write(rf->int_src, val);
if (ret)
return ret;
- }
- ret = regmap_field_read(rf->int_en, &val);
- if (ret)
- return ret;
-
- if (val == state)
- return 0;
+ if (enabled)
+ return 0;
- ret = regmap_field_write(rf->int_en, state);
- if (ret)
- return ret;
+ ret = regmap_field_write(rf->int_en, 1);
+ if (ret)
+ return ret;
- if (state)
return pm_runtime_resume_and_get(data->dev);
+ } else {
+ if (!enabled)
+ return 0;
- pm_runtime_mark_last_busy(data->dev);
- pm_runtime_put_autosuspend(data->dev);
+ ret = regmap_field_write(rf->int_en, 0);
+ if (ret)
+ return ret;
- return 0;
+ pm_runtime_mark_last_busy(data->dev);
+ pm_runtime_put_autosuspend(data->dev);
+
+ return 0;
+ }
}
case IIO_EV_TYPE_THRESH_ADAPTIVE:
- return regmap_field_write(rf->int_thresh_var_en, state);
+ if (state)
+ return regmap_field_write(rf->int_thresh_var_en, 1);
+ else
+ return regmap_field_write(rf->int_thresh_var_en, 0);
default:
return -EINVAL;
}