linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad7124: Fix DT channel configuration
@ 2019-12-10  9:06 Alexandru Tachici
  2019-12-15 15:39 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Tachici @ 2019-12-10  9:06 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Tachici

This patch fixes device tree channel configuration.

Before this patch, the driver assumed that the DT children (adc channels)
are parsed in the order they are written in the DT. Now the driver uses the
reg property of each child to correctly identify to which channel the
parsed configuration belongs to.

Fixes b3af341bbd966: ("iio: adc: Add ad7124 support")
Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
 drivers/iio/adc/ad7124.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index edc6f1cc90b2..43a56c6f4cf3 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -489,13 +489,11 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 		st->channel_config[channel].buf_negative =
 			of_property_read_bool(child, "adi,buffered-negative");
 
-		*chan = ad7124_channel_template;
-		chan->address = channel;
-		chan->scan_index = channel;
-		chan->channel = ain[0];
-		chan->channel2 = ain[1];
-
-		chan++;
+		chan[channel] = ad7124_channel_template;
+		chan[channel].address = channel;
+		chan[channel].scan_index = channel;
+		chan[channel].channel = ain[0];
+		chan[channel].channel2 = ain[1];
 	}
 
 	return 0;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ad7124: Fix DT channel configuration
  2019-12-10  9:06 [PATCH] iio: adc: ad7124: Fix DT channel configuration Alexandru Tachici
@ 2019-12-15 15:39 ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2019-12-15 15:39 UTC (permalink / raw)
  To: Alexandru Tachici; +Cc: linux-iio, linux-kernel

On Tue, 10 Dec 2019 11:06:21 +0200
Alexandru Tachici <alexandru.tachici@analog.com> wrote:

> This patch fixes device tree channel configuration.
> 
> Before this patch, the driver assumed that the DT children (adc channels)
> are parsed in the order they are written in the DT. Now the driver uses the
> reg property of each child to correctly identify to which channel the
> parsed configuration belongs to.
> 
> Fixes b3af341bbd966: ("iio: adc: Add ad7124 support")
> Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
Hi Alexandru.

Patch seems correct to me, but I'd like a little more detail in this
description.  Could you give an example of what goes wrong without this
patch?  That will be useful for people to understand if this patch is
fixing a problem they are seeing.

Thanks,

Jonathan
> ---
>  drivers/iio/adc/ad7124.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index edc6f1cc90b2..43a56c6f4cf3 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -489,13 +489,11 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
>  		st->channel_config[channel].buf_negative =
>  			of_property_read_bool(child, "adi,buffered-negative");
>  
> -		*chan = ad7124_channel_template;
> -		chan->address = channel;
> -		chan->scan_index = channel;
> -		chan->channel = ain[0];
> -		chan->channel2 = ain[1];
> -
> -		chan++;
> +		chan[channel] = ad7124_channel_template;
> +		chan[channel].address = channel;
> +		chan[channel].scan_index = channel;
> +		chan[channel].channel = ain[0];
> +		chan[channel].channel2 = ain[1];
>  	}
>  
>  	return 0;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] iio: adc: ad7124: Fix DT channel configuration
@ 2019-12-20 10:07 Alexandru Tachici
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandru Tachici @ 2019-12-20 10:07 UTC (permalink / raw)
  To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Tachici

This patch fixes device tree channel configuration.

ad7124 driver reads channels configuration from the device tree.
It expects to find channel specifications as child nodes.
Before this patch ad7124 driver assumed that the child nodes are parsed
by for_each_available_child_of_node in the order 0,1,2,3...

This is wrong and the real order of the children can be seen by running:
dtc -I fs /sys/firmware/devicetree/base on the machine.

For example, running this on an rpi 3B+ yields the real
children order: 4,2,0,7,5,3,1,6

Before this patch the driver assigned the channel configuration
like this:
        - 0 <- 4
        - 1 <- 2
        - 2 <- 0
        ........
For example, the symptoms can be observed by connecting the 4th channel
to a 1V tension and then reading the in_voltage0-voltage19_raw sysfs
(multiplied of course by the scale) one would see that channel 0
measures 1V and channel 4 measures only noise.

Now the driver uses the reg property of each child in order to
correctly identify to which channel the parsed configuration
belongs to.

Fixes b3af341bbd966: ("iio: adc: Add ad7124 support")
Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
 drivers/iio/adc/ad7124.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index e24d141d3c74..ed37d2b2b3b3 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -495,13 +495,11 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 		st->channel_config[channel].buf_negative =
 			of_property_read_bool(child, "adi,buffered-negative");
 
-		*chan = ad7124_channel_template;
-		chan->address = channel;
-		chan->scan_index = channel;
-		chan->channel = ain[0];
-		chan->channel2 = ain[1];
-
-		chan++;
+		chan[channel] = ad7124_channel_template;
+		chan[channel].address = channel;
+		chan[channel].scan_index = channel;
+		chan[channel].channel = ain[0];
+		chan[channel].channel2 = ain[1];
 	}
 
 	return 0;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-20 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10  9:06 [PATCH] iio: adc: ad7124: Fix DT channel configuration Alexandru Tachici
2019-12-15 15:39 ` Jonathan Cameron
2019-12-20 10:07 Alexandru Tachici

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).