Commit 85795d3e authored by Subhajit Ghosh's avatar Subhajit Ghosh Committed by Jonathan Cameron
parent 47ef0501
...@@ -1075,14 +1075,16 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev, ...@@ -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_data *data = iio_priv(indio_dev);
struct apds9306_regfields *rf = &data->rf; struct apds9306_regfields *rf = &data->rf;
int ret, val; int ret, enabled;
state = !!state;
switch (type) { switch (type) {
case IIO_EV_TYPE_THRESH: { case IIO_EV_TYPE_THRESH: {
guard(mutex)(&data->mutex); 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 * If interrupt is enabled, the channel is set before enabling
* the interrupt. In case of disable, no need to switch * 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, ...@@ -1091,38 +1093,42 @@ static int apds9306_write_event_config(struct iio_dev *indio_dev,
*/ */
if (state) { if (state) {
if (chan->type == IIO_LIGHT) if (chan->type == IIO_LIGHT)
val = 1; ret = regmap_field_write(rf->int_src, 1);
else if (chan->type == IIO_INTENSITY) else if (chan->type == IIO_INTENSITY)
val = 0; ret = regmap_field_write(rf->int_src, 0);
else else
return -EINVAL; return -EINVAL;
ret = regmap_field_write(rf->int_src, val);
if (ret) if (ret)
return ret; return ret;
}
ret = regmap_field_read(rf->int_en, &val); if (enabled)
if (ret) return 0;
return ret;
if (val == state)
return 0;
ret = regmap_field_write(rf->int_en, state); ret = regmap_field_write(rf->int_en, 1);
if (ret) if (ret)
return ret; return ret;
if (state)
return pm_runtime_resume_and_get(data->dev); return pm_runtime_resume_and_get(data->dev);
} else {
if (!enabled)
return 0;
pm_runtime_mark_last_busy(data->dev); ret = regmap_field_write(rf->int_en, 0);
pm_runtime_put_autosuspend(data->dev); 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: 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: default:
return -EINVAL; return -EINVAL;
} }
......
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