summaryrefslogtreecommitdiff
path: root/drivers/staging/iio
diff options
context:
space:
mode:
authorJonathan Cameron <Jonathan.Cameron@huawei.com>2021-03-14 18:14:51 +0000
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2021-04-07 08:36:36 +0100
commitc13ab9457fbbe67dbc1b1296ede05cccb812b81e (patch)
treeb9409ab3506d7de2fb21c4b21e7e0c57f84ab67d /drivers/staging/iio
parent0c4c4a868ab4af5886d070379b5964d1e0835c19 (diff)
staging:iio:cdc:ad7150: Timeout register covers both directions so both need updating
The timeout is treated as one single value, but the datasheet describes it as two 4 bit values, one for each direction of event. As such change the driver to support the separate directions. Also add limit checking to ensure it fits within the 4 bits. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Link: https://lore.kernel.org/r/20210314181511.531414-5-jic23@kernel.org
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r--drivers/staging/iio/cdc/ad7150.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index d6a7bfd94f1c..0dce1b8ce76d 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -49,6 +49,8 @@
/* AD7150 masks */
#define AD7150_THRESHTYPE_MSK GENMASK(6, 5)
+#define AD7150_CH_TIMEOUT_RECEDING GENMASK(3, 0)
+#define AD7150_CH_TIMEOUT_APPROACHING GENMASK(7, 4)
/**
* struct ad7150_chip_info - instance specific chip data
* @client: i2c client for this device
@@ -59,7 +61,9 @@
* from 'average' value.
* @thresh_timeout: a timeout, in samples from the moment an
* adaptive threshold event occurs to when the average
- * value jumps to current value.
+ * value jumps to current value. Note made up of two fields,
+ * 3:0 are for timeout receding - applies if below lower threshold
+ * 7:4 are for timeout approaching - applies if above upper threshold
* @old_state: store state from previous event, allowing confirmation
* of new condition.
* @conversion_mode: the current conversion mode.
@@ -191,7 +195,14 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev,
if (ret)
return ret;
- timeout = chip->thresh_timeout[rising][chan];
+ /*
+ * Single timeout register contains timeouts for both
+ * directions.
+ */
+ timeout = FIELD_PREP(AD7150_CH_TIMEOUT_APPROACHING,
+ chip->thresh_timeout[1][chan]);
+ timeout |= FIELD_PREP(AD7150_CH_TIMEOUT_RECEDING,
+ chip->thresh_timeout[0][chan]);
return i2c_smbus_write_byte_data(chip->client,
ad7150_addresses[chan][5],
timeout);
@@ -365,6 +376,9 @@ static ssize_t ad7150_store_timeout(struct device *dev,
if (ret < 0)
return ret;
+ if (data > GENMASK(3, 0))
+ return -EINVAL;
+
mutex_lock(&chip->state_lock);
switch (type) {
case IIO_EV_TYPE_THRESH_ADAPTIVE: