aboutsummaryrefslogtreecommitdiff
path: root/drivers/iio/adc
diff options
context:
space:
mode:
authorMiquel Raynal2021-09-21 13:54:01 +0200
committerJonathan Cameron2021-10-19 08:27:33 +0100
commitaf8b93e27fb6cc74c0cf1e9b70ba01e85586d793 (patch)
tree605fc3ca23fb4439ac331f4330838d21fba0911c /drivers/iio/adc
parentcba18232c4f80b64325e351a6d2264cbbfeacb81 (diff)
iio: adc: max1027: Create a helper to configure the channels to scan
These bits are meant to be reused for triggered buffers setup. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/r/20210921115408.66711-10-miquel.raynal@bootlin.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/max1027.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c
index fe5e9f95174b..33f89f902b83 100644
--- a/drivers/iio/adc/max1027.c
+++ b/drivers/iio/adc/max1027.c
@@ -272,6 +272,19 @@ struct max1027_state {
u8 reg ____cacheline_aligned;
};
+/* Scan from chan 0 to the highest requested channel. Include temperature on demand. */
+static int max1027_configure_chans_and_start(struct iio_dev *indio_dev)
+{
+ struct max1027_state *st = iio_priv(indio_dev);
+
+ st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N;
+ st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2);
+ if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP)
+ st->reg |= MAX1027_TEMP;
+
+ return spi_write(st->spi, &st->reg, 1);
+}
+
static int max1027_enable_trigger(struct iio_dev *indio_dev, bool enable)
{
struct max1027_state *st = iio_priv(indio_dev);
@@ -403,7 +416,6 @@ static int max1027_validate_trigger(struct iio_dev *indio_dev,
static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
{
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
- struct max1027_state *st = iio_priv(indio_dev);
int ret;
/*
@@ -417,17 +429,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
return ret;
if (state) {
- /*
- * Scan from chan 0 to the highest requested channel.
- * Include temperature on demand.
- */
- st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N;
- st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2);
- if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP)
- st->reg |= MAX1027_TEMP;
-
- ret = spi_write(st->spi, &st->reg, 1);
- if (ret < 0)
+ ret = max1027_configure_chans_and_start(indio_dev);
+ if (ret)
return ret;
}