diff mbox series

[09/16] iio: adc: max1027: Create a helper to configure the channels to scan

Message ID 20210818111139.330636-10-miquel.raynal@bootlin.com (mailing list archive)
State Changes Requested
Headers show
Series Bring software triggers support to MAX1027-like ADCs | expand

Commit Message

Miquel Raynal Aug. 18, 2021, 11:11 a.m. UTC
These bits are meant to be reused for triggered buffers setup.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/iio/adc/max1027.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

Comments

Nuno Sa Aug. 20, 2021, 7:18 a.m. UTC | #1
> -----Original Message-----
> From: Miquel Raynal <miquel.raynal@bootlin.com>
> Sent: Wednesday, August 18, 2021 1:12 PM
> To: Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen
> <lars@metafoo.de>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>; linux-
> iio@vger.kernel.org; linux-kernel@vger.kernel.org; Miquel Raynal
> <miquel.raynal@bootlin.com>
> Subject: [PATCH 09/16] iio: adc: max1027: Create a helper to configure
> the channels to scan
> 
> [External]
> 
> These bits are meant to be reused for triggered buffers setup.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/iio/adc/max1027.c | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c
> index 4a78c9cbc339..223c9e4abd86 100644
> --- a/drivers/iio/adc/max1027.c
> +++ b/drivers/iio/adc/max1027.c
> @@ -236,6 +236,22 @@ struct max1027_state {
>  	u8				reg ____cacheline_aligned;
>  };
> 
> +/* Scan from 0 to the highest requested channel */
> +static int max1027_configure_chans_to_scan(struct iio_dev
> *indio_dev)
> +{
> +	struct max1027_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	/* The temperature could be avoided but it simplifies a bit the
> logic */
> +	st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N |
> MAX1027_TEMP;
> +	st->reg |= MAX1027_CHAN(fls(*indio_dev-
> >active_scan_mask) - 2);
> +	ret = spi_write(st->spi, &st->reg, 1);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;

return spi_write(st->spi, &st->reg, 1);?

> +}
> +
>  static int max1027_configure_trigger(struct iio_dev *indio_dev)
>  {
>  	struct max1027_state *st = iio_priv(indio_dev);
> @@ -391,14 +407,8 @@ static int
> max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
>  		if (ret)
>  			return ret;
> 
> -		/*
> -		 * Scan from 0 to the highest requested channel. The
> temperature
> -		 * could be avoided but it simplifies a bit the logic.
> -		 */
> -		st->reg = MAX1027_CONV_REG |
> MAX1027_SCAN_0_N | MAX1027_TEMP;
> -		st->reg |= MAX1027_CHAN(fls(*indio_dev-
> >active_scan_mask) - 2);
> -		ret = spi_write(st->spi, &st->reg, 1);
> -		if (ret < 0)
> +		ret = max1027_configure_chans_to_scan(indio_dev);
> +		if (ret)
>  			return ret;
>  	} else {
>  		/*
> --
> 2.27.0
diff mbox series

Patch

diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c
index 4a78c9cbc339..223c9e4abd86 100644
--- a/drivers/iio/adc/max1027.c
+++ b/drivers/iio/adc/max1027.c
@@ -236,6 +236,22 @@  struct max1027_state {
 	u8				reg ____cacheline_aligned;
 };
 
+/* Scan from 0 to the highest requested channel */
+static int max1027_configure_chans_to_scan(struct iio_dev *indio_dev)
+{
+	struct max1027_state *st = iio_priv(indio_dev);
+	int ret;
+
+	/* The temperature could be avoided but it simplifies a bit the logic */
+	st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N | MAX1027_TEMP;
+	st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2);
+	ret = spi_write(st->spi, &st->reg, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static int max1027_configure_trigger(struct iio_dev *indio_dev)
 {
 	struct max1027_state *st = iio_priv(indio_dev);
@@ -391,14 +407,8 @@  static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state)
 		if (ret)
 			return ret;
 
-		/*
-		 * Scan from 0 to the highest requested channel. The temperature
-		 * could be avoided but it simplifies a bit the logic.
-		 */
-		st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N | MAX1027_TEMP;
-		st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2);
-		ret = spi_write(st->spi, &st->reg, 1);
-		if (ret < 0)
+		ret = max1027_configure_chans_to_scan(indio_dev);
+		if (ret)
 			return ret;
 	} else {
 		/*