[1/4] iio: adc: mcp3422: fix scale read bug

Message ID 20221111112657.1521307-2-mitja@lxnav.com
State New
Headers
Series iio: adc: mcp3422 improvements |

Commit Message

Mitja Špes Nov. 11, 2022, 11:26 a.m. UTC
  Scale was returned for currently active channel instead of the specified
channel.

Signed-off-by: Mitja Spes <mitja@lxnav.com>
Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
---
 drivers/iio/adc/mcp3422.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Jonathan Cameron Nov. 12, 2022, 5:10 p.m. UTC | #1
On Fri, 11 Nov 2022 12:26:53 +0100
Mitja Spes <mitja@lxnav.com> wrote:

> Scale was returned for currently active channel instead of the specified
> channel.
> 
> Signed-off-by: Mitja Spes <mitja@lxnav.com>
> Fixes: 07914c84ba30 ("iio: adc: Add driver for Microchip MCP3422/3/4 high resolution ADC")
Hi Mitja,

One trivial comment inline. I might tidy that up whilst applying if others are
otherwise happy with this patch.  If you do a v2 for some other reason please
get rid of that unrelated change.

Jonathan

> ---
>  drivers/iio/adc/mcp3422.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
> index da353dcb1e9d..3d53de300c89 100644
> --- a/drivers/iio/adc/mcp3422.c
> +++ b/drivers/iio/adc/mcp3422.c
> @@ -164,8 +164,9 @@ static int mcp3422_read_raw(struct iio_dev *iio,
>  	struct mcp3422 *adc = iio_priv(iio);
>  	int err;
>  
> +	u8 req_channel = channel->channel;
>  	u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config);
> -	u8 pga		 = MCP3422_PGA(adc->config);
> +	u8 pga		 = adc->pga[req_channel];
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> @@ -175,7 +176,6 @@ static int mcp3422_read_raw(struct iio_dev *iio,
>  		return IIO_VAL_INT;
>  
>  	case IIO_CHAN_INFO_SCALE:
> -
Unrelated change.  No problem with cleaning this up but definitely not
in a fix patch!

>  		*val1 = 0;
>  		*val2 = mcp3422_scales[sample_rate][pga];
>  		return IIO_VAL_INT_PLUS_NANO;
  
Mitja Špes Nov. 12, 2022, 8:06 p.m. UTC | #2
Hi Jonathan,

On Sat, Nov 12, 2022 at 5:57 PM Jonathan Cameron <jic23@kernel.org> wrote:

> One trivial comment inline. I might tidy that up whilst applying if others are
> otherwise happy with this patch.  If you do a v2 for some other reason please
> get rid of that unrelated change.

Ok, I will move it to a styling patch and fix it in v2.

Kind regards,
Mitja
  

Patch

diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index da353dcb1e9d..3d53de300c89 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -164,8 +164,9 @@  static int mcp3422_read_raw(struct iio_dev *iio,
 	struct mcp3422 *adc = iio_priv(iio);
 	int err;
 
+	u8 req_channel = channel->channel;
 	u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config);
-	u8 pga		 = MCP3422_PGA(adc->config);
+	u8 pga		 = adc->pga[req_channel];
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
@@ -175,7 +176,6 @@  static int mcp3422_read_raw(struct iio_dev *iio,
 		return IIO_VAL_INT;
 
 	case IIO_CHAN_INFO_SCALE:
-
 		*val1 = 0;
 		*val2 = mcp3422_scales[sample_rate][pga];
 		return IIO_VAL_INT_PLUS_NANO;