AD7606-8 is referred to as AD7606 by Analog Devices. This comment aims
to avoid confusion. Also the compatible names were not sorted by
alphabetical order.
Signed-off-by: Guillaume Stols <redacted>
---
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -20,9 +20,9 @@ properties:compatible:enum:-adi,ad7605-4--adi,ad7606-8--adi,ad7606-6-adi,ad7606-4+-adi,ad7606-6+-adi,ad7606-8# Referred to as AD7606 (without -8) in the datasheet-adi,ad7606b-adi,ad7616
@@ -35,6 +35,15 @@ properties:avcc-supply:true+vdrive-supply:+description:+Determines the voltage level at which the interface logic pins will+operate.++refin-supply:+description:+The voltage supply for optional external reference voltage.+interrupts:description:The BUSY pin falling edge indicates that the conversion is over, and thus
Since the driver supports several parts that present differences in
their layout and behaviour, it is necessary to describe the differences
from one chip to another.
Signed-off-by: Guillaume Stols <redacted>
---
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 50 +++++++++++++++++++++-
1 file changed, 48 insertions(+), 2 deletions(-)
@@ -55,7 +55,8 @@ properties:Must be the device tree identifier of the CONVST pin(s). This logic inputis used to initiate conversions on the analog input channels. As the lineis active high, it should be marked GPIO_ACTIVE_HIGH.-maxItems:1+minItems:1+maxItems:2reset-gpios:description:
@@ -91,7 +92,8 @@ properties:GPIO_ACTIVE_HIGH. On the AD7616, there are 2 pins, and if the 2 pins aretied to a logic high, software mode is enabled, otherwise one of the 3possible range values is selected.-maxItems:1+minItems:1+maxItems:2adi,oversampling-ratio-gpios:description:
Reword a few descriptions, and normalize the text width to 80 characters.
Signed-off-by: Guillaume Stols <redacted>
---
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 61 ++++++++++++----------
1 file changed, 34 insertions(+), 27 deletions(-)
@@ -36,64 +36,71 @@ properties:avcc-supply:trueinterrupts:+description:+The BUSY pin falling edge indicates that the conversion is over, and thus+new data is available.maxItems:1adi,conversion-start-gpios:description:-Must be the device tree identifier of the CONVST pin.-This logic input is used to initiate conversions on the analog-input channels. As the line is active high, it should be marked-GPIO_ACTIVE_HIGH.+Must be the device tree identifier of the CONVST pin(s). This logic input+is used to initiate conversions on the analog input channels. As the line+is active high, it should be marked GPIO_ACTIVE_HIGH.maxItems:1reset-gpios:description:-Must be the device tree identifier of the RESET pin. If specified,-it will be asserted during driver probe. As the line is active high,-it should be marked GPIO_ACTIVE_HIGH.+Must be the device tree identifier of the RESET pin. If specified, it will+be asserted during driver probe. On the AD7606x, as the line is active+high, it should be marked GPIO_ACTIVE_HIGH. On the AD7616, as the line is+active low, it should be marked GPIO_ACTIVE_LOW.maxItems:1standby-gpios:description:-Must be the device tree identifier of the STBY pin. This pin is used-to place the AD7606 into one of two power-down modes, Standby mode or+Must be the device tree identifier of the STBY pin. This pin is used to+place the AD7606 into one of two power-down modes, Standby mode orShutdown mode. As the line is active low, it should be markedGPIO_ACTIVE_LOW.maxItems:1adi,first-data-gpios:description:-Must be the device tree identifier of the FRSTDATA pin.-The FRSTDATA output indicates when the first channel, V1, is-being read back on either the parallel, byte or serial interface.-As the line is active high, it should be marked GPIO_ACTIVE_HIGH.+Must be the device tree identifier of the FRSTDATA pin. The FRSTDATA+output indicates when the first channel, V1, is being read back on either+the parallel, byte or serial interface. As the line is active+high, it should be marked GPIO_ACTIVE_HIGH.maxItems:1adi,range-gpios:description:-Must be the device tree identifier of the RANGE pin. The polarity on-this pin determines the input range of the analog input channels. If-this pin is tied to a logic high, the analog input range is ±10V for-all channels. If this pin is tied to a logic low, the analog input range+Must be the device tree identifier of the RANGE pin. The state on this+pin determines the input range of the analog input channels. If this pin+is tied to a logic high, the analog input range is ±10V for all channels.+On the AD760X, if this pin is tied to a logic low, the analog input rangeis ±5V for all channels. As the line is active high, it should be marked-GPIO_ACTIVE_HIGH.+GPIO_ACTIVE_HIGH. On the AD7616, there are 2 pins, and if the 2 pins are+tied to a logic high, software mode is enabled, otherwise one of the 3+possible range values is selected.maxItems:1adi,oversampling-ratio-gpios:description:-Must be the device tree identifier of the over-sampling-mode pins. As the line is active high, it should be marked-GPIO_ACTIVE_HIGH.+Must be the device tree identifier of the over-sampling mode pins. As the+line is active high, it should be marked GPIO_ACTIVE_HIGH. On the AD7606X+parts that support it, if all 3 pins are tied to a logic high, software+mode is enabled.maxItems:3adi,sw-mode:description:-Software mode of operation, so far available only for ad7616 and ad7606b.-It is enabled when all three oversampling mode pins are connected to-high level. The device is configured by the corresponding registers. If the-adi,oversampling-ratio-gpios property is defined, then the driver will set the-oversampling gpios to high. Otherwise, it is assumed that the pins are hardwired-to VDD.+Software mode of operation, so far available only for AD7616 and AD7606b.+It is enabled when all three oversampling mode pins are connected to high+level for the AD7606B, or all two range selection pins are connected to+high level for the AD7616. The device is configured by the corresponding+registers. If the adi,oversampling-ratio-gpios property is defined, then+the driver will set the oversampling gpios to high. Otherwise, it is+assumed that the pins are hardwired to VDD.type:booleanrequired:
Example uses adi,ad7606-8 as compatible, but adi,sw-mode is not
available for it. So remove this property from example.
Signed-off-by: Guillaume Stols <redacted>
---
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 1 -
1 file changed, 1 deletion(-)
Switching to scoped_guard simplifies the code and avoids to take care to
unlock the mutex in case of premature return.
Signed-off-by: Guillaume Stols <redacted>
---
drivers/iio/adc/ad7606.c | 71 ++++++++++++++++++++++--------------------------
1 file changed, 33 insertions(+), 38 deletions(-)
@@ -69,19 +69,18 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,structad7606_state*st=iio_priv(indio_dev);intret;-mutex_lock(&st->lock);-if(readval){-ret=st->bops->reg_read(st,reg);-if(ret<0)-gotoerr_unlock;-*readval=ret;-ret=0;-}else{-ret=st->bops->reg_write(st,reg,writeval);+scoped_guard(mutex,&st->lock){+if(readval){+ret=st->bops->reg_read(st,reg);+if(ret<0)+returnret;+*readval=ret;+return0;+}else{+returnst->bops->reg_write(st,reg,writeval);+}}-err_unlock:-mutex_unlock(&st->lock);-returnret;+unreachable();}staticintad7606_read_samples(structad7606_state*st)
@@ -124,18 +123,18 @@ static irqreturn_t ad7606_trigger_handler(int irq, void *p)structad7606_state*st=iio_priv(indio_dev);intret;-mutex_lock(&st->lock);+scoped_guard(mutex,&st->lock){+ret=ad7606_read_samples(st);+if(ret)+gotoerror_ret;-ret=ad7606_read_samples(st);-if(ret==0)iio_push_to_buffers_with_timestamp(indio_dev,st->data,iio_get_time_ns(indio_dev));--iio_trigger_notify_done(indio_dev->trig);-/* The rising edge of the CONVST signal starts a new conversion. */-gpiod_set_value(st->gpio_convst,1);--mutex_unlock(&st->lock);+error_ret:+iio_trigger_notify_done(indio_dev->trig);+/* The rising edge of the CONVST signal starts a new conversion. */+gpiod_set_value(st->gpio_convst,1);+}returnIRQ_HANDLED;}
@@ -259,17 +258,15 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,switch(mask){caseIIO_CHAN_INFO_SCALE:-mutex_lock(&st->lock);-i=find_closest(val2,st->scale_avail,st->num_scales);-if(st->sw_mode_en)-ch=chan->address;-ret=st->write_scale(indio_dev,ch,i);-if(ret<0){-mutex_unlock(&st->lock);-returnret;+scoped_guard(mutex,&st->lock){+i=find_closest(val2,st->scale_avail,st->num_scales);+if(st->sw_mode_en)+ch=chan->address;+ret=st->write_scale(indio_dev,ch,i);+if(ret<0)+returnret;+st->range[ch]=i;}-st->range[ch]=i;-mutex_unlock(&st->lock);return0;caseIIO_CHAN_INFO_OVERSAMPLING_RATIO:
@@ -277,14 +274,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,return-EINVAL;i=find_closest(val,st->oversampling_avail,st->num_os_ratios);-mutex_lock(&st->lock);-ret=st->write_os(indio_dev,i);-if(ret<0){-mutex_unlock(&st->lock);-returnret;+scoped_guard(mutex,&st->lock){+ret=st->write_os(indio_dev,i);+if(ret<0)+returnret;+st->oversampling=st->oversampling_avail[i];}-st->oversampling=st->oversampling_avail[i];-mutex_unlock(&st->lock);return0;default:
gpiod_set_array_value was misused here: the implementation relied on the
assumption that an unsigned long was required for each gpio, while the
function expects a bit array stored in "as much unsigned long as needed
for storing one bit per GPIO", i.e it is using a bit field.
Fixes: d2a415c86c6b ("iio: adc: ad7606: Add support for AD7606B ADC")
Signed-off-by: Guillaume Stols <redacted>
---
drivers/iio/adc/ad7606.c | 4 ++--
drivers/iio/adc/ad7606_spi.c | 5 +++--
2 files changed, 5 insertions(+), 4 deletions(-)
@@ -235,9 +235,9 @@ static int ad7606_write_os_hw(struct iio_dev *indio_dev, int val)structad7606_state*st=iio_priv(indio_dev);DECLARE_BITMAP(values,3);-values[0]=val;+values[0]=val&GENMASK(2,0);-gpiod_set_array_value(ARRAY_SIZE(values),st->gpio_os->desc,+gpiod_set_array_value(st->gpio_os->ndescs,st->gpio_os->desc,st->gpio_os->info,values);/* AD7616 requires a reset to update value */
@@ -249,8 +249,9 @@ static int ad7616_sw_mode_config(struct iio_dev *indio_dev)staticintad7606B_sw_mode_config(structiio_dev*indio_dev){structad7606_state*st=iio_priv(indio_dev);-unsignedlongos[3]={1};+DECLARE_BITMAP(os,3);+bitmap_fill(os,3);/**Softwaremodeisenabledwhenallthreeoversampling*pinsaresettohigh.Ifoversamplinggpiosaredefined
@@ -258,7 +259,7 @@ static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)*otherwise,theymustbehardwiredtoVDD*/if(st->gpio_os){-gpiod_set_array_value(ARRAY_SIZE(os),+gpiod_set_array_value(st->gpio_os->ndescs,st->gpio_os->desc,st->gpio_os->info,os);}/* OS of 128 and 256 are available only in software mode */
The binding's documentation specifies that "As the line is active low, it
should be marked GPIO_ACTIVE_LOW". However, in the driver, it was handled
the opposite way. This commit sets the driver's behaviour in sync with the
documentation
Fixes: 722407a4e8c0 ("staging:iio:ad7606: Use GPIO descriptor API")
Signed-off-by: Guillaume Stols <redacted>
---
drivers/iio/adc/ad7606.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
On Tue, Jun 18, 2024 at 02:02:38PM +0000, Guillaume Stols wrote:
Example uses adi,ad7606-8 as compatible, but adi,sw-mode is not
available for it. So remove this property from example.
Signed-off-by: Guillaume Stols <redacted>
@@ -35,6 +35,15 @@ properties:avcc-supply:true+vdrive-supply:+description:+Determines the voltage level at which the interface logic pins will+operate.++refin-supply:+description:+The voltage supply for optional external reference voltage.+interrupts:description:The BUSY pin falling edge indicates that the conversion is over, and thus
On Tue, Jun 18, 2024 at 02:02:37PM +0000, Guillaume Stols wrote:
Since the driver supports several parts that present differences in
their layout and behaviour, it is necessary to describe the differences
from one chip to another.
Signed-off-by: Guillaume Stols <redacted>
Didn't check the datasheets etc, but the idea seems fine.
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
On Tue, Jun 18, 2024 at 02:02:36PM +0000, Guillaume Stols wrote:
quoted
Add voltage supplies
Are these available on all devices?
Yes all chips from AD7606 series (including AD7606B, AD7606C(-16,-18),
AD7605-4, AD7606 (-4,-8,-6), AD7607, AD7608, AD7609), as well as AD7616
have a VDrive pin, as well as a RefSelect + RefIn/RefOut pin that takes
an input voltage in case RefSelect is high, or outputs the internal
reference voltage if RefSelect is low.
@@ -35,6 +35,15 @@ properties:avcc-supply:true+vdrive-supply:+description:+Determines the voltage level at which the interface logic pins will+operate.++refin-supply:+description:+The voltage supply for optional external reference voltage.+interrupts:description:The BUSY pin falling edge indicates that the conversion is over, and thus
On Tue, 18 Jun 2024 14:02:37 +0000, Guillaume Stols wrote:
Since the driver supports several parts that present differences in
their layout and behaviour, it is necessary to describe the differences
from one chip to another.
Signed-off-by: Guillaume Stols <redacted>
---
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 50 +++++++++++++++++++++-
1 file changed, 48 insertions(+), 2 deletions(-)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/iio/adc/adi,ad7606.example.dtb: adc@0: adi,sw-mode: False schema does not allow True
from schema $id: http://devicetree.org/schemas/iio/adc/adi,ad7606.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20240618-cleanup-ad7606-v1-5-f1854d5c779d@baylibre.com
The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.
On Tue, Jun 18, 2024 at 05:33:16PM +0200, Guillaume Stols wrote:
On 6/18/24 17:12, Conor Dooley wrote:
quoted
On Tue, Jun 18, 2024 at 02:02:36PM +0000, Guillaume Stols wrote:
quoted
Add voltage supplies
Are these available on all devices?
Yes all chips from AD7606 series (including AD7606B, AD7606C(-16,-18),
AD7605-4, AD7606 (-4,-8,-6), AD7607, AD7608, AD7609), as well as AD7616
have a VDrive pin, as well as a RefSelect + RefIn/RefOut pin that takes
an input voltage in case RefSelect is high, or outputs the internal
reference voltage if RefSelect is low.
The lack of a blank line here is an artifact of the reply
quoted
quoted
+ description:
+ Determines the voltage level at which the interface logic pins will
+ operate.
+
+ refin-supply:
+ description:
+ The voltage supply for optional external reference voltage.
+
interrupts:
description:
The BUSY pin falling edge indicates that the conversion is over, and thus
--
2.34.1
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:28:36
On Tue, 18 Jun 2024 14:02:35 +0000
Guillaume Stols [off-list ref] wrote:
Reword a few descriptions, and normalize the text width to 80 characters.
Don't rewrap text in a patch that does anything else as those real
changes are hidden.
Even if you are changing the text, minimise rewraps to those necessary
to avoid lines getting too long and fix them up in a follow up patch
that just rewraps.
I think most of the changes are fine, but it's really hard to spot
the real changes in here!
@@ -36,64 +36,71 @@ properties:avcc-supply:trueinterrupts:+description:+The BUSY pin falling edge indicates that the conversion is over, and thus+new data is available.maxItems:1adi,conversion-start-gpios:description:-Must be the device tree identifier of the CONVST pin.-This logic input is used to initiate conversions on the analog-input channels. As the line is active high, it should be marked-GPIO_ACTIVE_HIGH.+Must be the device tree identifier of the CONVST pin(s). This logic input
Why plural when it has maxitems 1?
+ is used to initiate conversions on the analog input channels. As the line
+ is active high, it should be marked GPIO_ACTIVE_HIGH.
If you drop the plural change don't rewrap this in v2, it is unnecessary noise
that takes away from the real improvements.
maxItems: 1
reset-gpios:
description:
- Must be the device tree identifier of the RESET pin. If specified,
- it will be asserted during driver probe. As the line is active high,
- it should be marked GPIO_ACTIVE_HIGH.
+ Must be the device tree identifier of the RESET pin. If specified, it will
+ be asserted during driver probe. On the AD7606x, as the line is active
+ high, it should be marked GPIO_ACTIVE_HIGH. On the AD7616, as the line is
+ active low, it should be marked GPIO_ACTIVE_LOW.
maxItems: 1
adi,range-gpios:
description:
- Must be the device tree identifier of the RANGE pin. The polarity on
- this pin determines the input range of the analog input channels. If
- this pin is tied to a logic high, the analog input range is ±10V for
- all channels. If this pin is tied to a logic low, the analog input range
+ Must be the device tree identifier of the RANGE pin. The state on this
+ pin determines the input range of the analog input channels. If this pin
+ is tied to a logic high, the analog input range is ±10V for all channels.
+ On the AD760X, if this pin is tied to a logic low, the analog input range
is ±5V for all channels. As the line is active high, it should be marked
- GPIO_ACTIVE_HIGH.
+ GPIO_ACTIVE_HIGH. On the AD7616, there are 2 pins, and if the 2 pins are
+ tied to a logic high, software mode is enabled, otherwise one of the 3
+ possible range values is selected.
With max items 1 how do we have 2?
maxItems: 1
adi,oversampling-ratio-gpios:
description:
- Must be the device tree identifier of the over-sampling
- mode pins. As the line is active high, it should be marked
- GPIO_ACTIVE_HIGH.
+ Must be the device tree identifier of the over-sampling mode pins. As the
+ line is active high, it should be marked GPIO_ACTIVE_HIGH. On the AD7606X
+ parts that support it, if all 3 pins are tied to a logic high, software
+ mode is enabled.
maxItems: 3
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:31:41
On Tue, 18 Jun 2024 18:32:20 +0100
Conor Dooley [off-list ref] wrote:
On Tue, Jun 18, 2024 at 05:33:16PM +0200, Guillaume Stols wrote:
quoted
On 6/18/24 17:12, Conor Dooley wrote:
quoted
On Tue, Jun 18, 2024 at 02:02:36PM +0000, Guillaume Stols wrote:
quoted
Add voltage supplies
Are these available on all devices?
Yes all chips from AD7606 series (including AD7606B, AD7606C(-16,-18),
AD7605-4, AD7606 (-4,-8,-6), AD7607, AD7608, AD7609), as well as AD7616
have a VDrive pin, as well as a RefSelect + RefIn/RefOut pin that takes
an input voltage in case RefSelect is high, or outputs the internal
reference voltage if RefSelect is low.
Sounds like vdrive-supply is a requirement for the device to function but
refin may be optional.
So add vdrive-supply to the required property list.
Note the binding for supplies reflects what must be wired and ignores
the ability of the linux regulator framework to get fake supplies when
they are not provided in DT.
The lack of a blank line here is an artifact of the reply
quoted
quoted
quoted
+ description:
+ Determines the voltage level at which the interface logic pins will
+ operate.
+
+ refin-supply:
+ description:
+ The voltage supply for optional external reference voltage.
+
interrupts:
description:
The BUSY pin falling edge indicates that the conversion is over, and thus
--
2.34.1
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:33:41
On Tue, 18 Jun 2024 14:02:37 +0000
Guillaume Stols [off-list ref] wrote:
Since the driver supports several parts that present differences in
their layout and behaviour, it is necessary to describe the differences
from one chip to another.
Signed-off-by: Guillaume Stols <redacted>
I'd rather see the numbers / descriptions changed in this patch so
that it is clear why instead of the earlier documentation only patch.
If that is really hard to do, just make sure that patch description calls
out that it will briefly be inconsistent.
Otherwise LGTM
@@ -55,7 +55,8 @@ properties:Must be the device tree identifier of the CONVST pin(s). This logic inputis used to initiate conversions on the analog input channels. As the lineis active high, it should be marked GPIO_ACTIVE_HIGH.-maxItems:1+minItems:1+maxItems:2reset-gpios:description:
@@ -91,7 +92,8 @@ properties:GPIO_ACTIVE_HIGH. On the AD7616, there are 2 pins, and if the 2 pins aretied to a logic high, software mode is enabled, otherwise one of the 3possible range values is selected.-maxItems:1+minItems:1+maxItems:2adi,oversampling-ratio-gpios:description:
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:35:18
On Tue, 18 Jun 2024 16:10:15 +0100
Conor Dooley [off-list ref] wrote:
On Tue, Jun 18, 2024 at 02:02:38PM +0000, Guillaume Stols wrote:
quoted
Example uses adi,ad7606-8 as compatible, but adi,sw-mode is not
available for it. So remove this property from example.
Signed-off-by: Guillaume Stols <redacted>
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:41:33
On Tue, 18 Jun 2024 14:02:39 +0000
Guillaume Stols [off-list ref] wrote:
quoted hunk
Switching to scoped_guard simplifies the code and avoids to take care to
unlock the mutex in case of premature return.
Signed-off-by: Guillaume Stols <redacted>
---
drivers/iio/adc/ad7606.c | 71 ++++++++++++++++++++++--------------------------
1 file changed, 33 insertions(+), 38 deletions(-)
@@ -69,19 +69,18 @@ static int ad7606_reg_access(struct iio_dev *indio_dev,structad7606_state*st=iio_priv(indio_dev);intret;-mutex_lock(&st->lock);-if(readval){-ret=st->bops->reg_read(st,reg);-if(ret<0)-gotoerr_unlock;-*readval=ret;-ret=0;-}else{-ret=st->bops->reg_write(st,reg,writeval);+scoped_guard(mutex,&st->lock){+if(readval){+ret=st->bops->reg_read(st,reg);+if(ret<0)+returnret;+*readval=ret;+return0;+}else{+returnst->bops->reg_write(st,reg,writeval);+}}-err_unlock:-mutex_unlock(&st->lock);-returnret;+unreachable();
Unless you are going to add more code in this function later in the series
then a
guard(mutex)(&st->lock); is more appropriate in this function
as the scope is effectively the whole function. Also avoids the always
ugly need for an unreachable() marking.
I'm not sure what the build bot warning means though.
Otherwise looks good to me
J
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:45:53
On Tue, 18 Jun 2024 14:02:40 +0000
Guillaume Stols [off-list ref] wrote:
gpiod_set_array_value was misused here: the implementation relied on the
assumption that an unsigned long was required for each gpio, while the
function expects a bit array stored in "as much unsigned long as needed
for storing one bit per GPIO", i.e it is using a bit field.
Fixes: d2a415c86c6b ("iio: adc: ad7606: Add support for AD7606B ADC")
Signed-off-by: Guillaume Stols <redacted>
Always drag fixes to the start of a series. Probably doesn't matter
in this case but we want it to be obvious there are no necessary precursors
in this series for anyone backporting.
What is the user visible outcome of this bug? Superficially the numbers
all end up the same I think even though the code is clearly working
mostly by luck. So might not warrant a fixes tag?
@@ -235,9 +235,9 @@ static int ad7606_write_os_hw(struct iio_dev *indio_dev, int val)structad7606_state*st=iio_priv(indio_dev);DECLARE_BITMAP(values,3);-values[0]=val;+values[0]=val&GENMASK(2,0);-gpiod_set_array_value(ARRAY_SIZE(values),st->gpio_os->desc,+gpiod_set_array_value(st->gpio_os->ndescs,st->gpio_os->desc,st->gpio_os->info,values);/* AD7616 requires a reset to update value */
@@ -249,8 +249,9 @@ static int ad7616_sw_mode_config(struct iio_dev *indio_dev)staticintad7606B_sw_mode_config(structiio_dev*indio_dev){structad7606_state*st=iio_priv(indio_dev);-unsignedlongos[3]={1};+DECLARE_BITMAP(os,3);+bitmap_fill(os,3);/**Softwaremodeisenabledwhenallthreeoversampling*pinsaresettohigh.Ifoversamplinggpiosaredefined
@@ -258,7 +259,7 @@ static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)*otherwise,theymustbehardwiredtoVDD*/if(st->gpio_os){-gpiod_set_array_value(ARRAY_SIZE(os),+gpiod_set_array_value(st->gpio_os->ndescs,st->gpio_os->desc,st->gpio_os->info,os);}/* OS of 128 and 256 are available only in software mode */
From: Jonathan Cameron <jic23@kernel.org> Date: 2024-06-23 15:49:30
On Tue, 18 Jun 2024 14:02:41 +0000
Guillaume Stols [off-list ref] wrote:
The binding's documentation specifies that "As the line is active low, it
should be marked GPIO_ACTIVE_LOW". However, in the driver, it was handled
the opposite way. This commit sets the driver's behaviour in sync with the
documentation
Fixes: 722407a4e8c0 ("staging:iio:ad7606: Use GPIO descriptor API")
Signed-off-by: Guillaume Stols <redacted>
This sound dangerous. If anyone is using the driver before this an it's
working they indeed have the pin inverted wrt to the docs, but
as it works for them this will be a regression.
So messy corner - do we fix the docs or the driver? I'm not sure which
is more painful. In theory the DT binding might be in use by another
OS or similar which might have a non broken driver, but I suspect it isn't.
Whereas perhaps the driver as it stands is in use on Linux.
AD folk: You will get the support calls, do you want to risk them or
should we change the docs (and maybe add a note on it being 'odd' wrt
to the documentation as we are treating it as an active !standy pin)
Resend, previous mail was erroneously sent in HTML. I apologize for the
spamming.
On 6/23/24 17:45, Jonathan Cameron wrote:
> On Tue, 18 Jun 2024 14:02:40 +0000
> Guillaume Stols [off-list ref] wrote:
>> gpiod_set_array_value was misused here: the implementation relied on the
>> assumption that an unsigned long was required for each gpio, while the
>> function expects a bit array stored in "as much unsigned long as needed
>> for storing one bit per GPIO", i.e it is using a bit field.
>>
>> Fixes: d2a415c86c6b ("iio: adc: ad7606: Add support for AD7606B ADC")
>> Signed-off-by: Guillaume Stols [off-list ref]
> Always drag fixes to the start of a series. Probably doesn't matter
> in this case but we want it to be obvious there are no necessary
precursors
> in this series for anyone backporting.
OK will do this change in the next version.
>
> What is the user visible outcome of this bug? Superficially the numbers
> all end up the same I think even though the code is clearly working
> mostly by luck. So might not warrant a fixes tag?
This is leading into some issues I should maybe have better documented
in the commit message.
See below
>
>> ---
>> drivers/iio/adc/ad7606.c | 4 ++--
>> drivers/iio/adc/ad7606_spi.c | 5 +++--
>> 2 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
>> index e3426287edf6..502344e019e0 100644
>> --- a/drivers/iio/adc/ad7606.c
>> +++ b/drivers/iio/adc/ad7606.c
>> @@ -235,9 +235,9 @@ static int ad7606_write_os_hw(struct iio_dev
*indio_dev, int val)
>> struct ad7606_state *st = iio_priv(indio_dev);
>> DECLARE_BITMAP(values, 3);
>> - values[0] = val;
>> + values[0] = val & GENMASK(2, 0);
>> - gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
>> + gpiod_set_array_value(st->gpio_os->ndescs, st->gpio_os->desc,
>> st->gpio_os->info, values);
ARRAY_SIZE(values) is 1 because DECLARE_BITMAP will declare a dimension
1 unsigned long array (more than enough for 3 bits !).
We want to set 3 bits in gpiod_set_array_value, thus the first parameter
should be 3, not 1.
>> /* AD7616 requires a reset to update value */
>> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
>> index 263a778bcf25..287a0591533b 100644
>> --- a/drivers/iio/adc/ad7606_spi.c
>> +++ b/drivers/iio/adc/ad7606_spi.c
>> @@ -249,8 +249,9 @@ static int ad7616_sw_mode_config(struct iio_dev
*indio_dev)
>> static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
>> {
>> struct ad7606_state *st = iio_priv(indio_dev);
>> - unsigned long os[3] = {1};
>> + DECLARE_BITMAP(os, 3);
>> + bitmap_fill(os, 3);
Here we need 3 bits set HIGH in one unsigned long (i.e 0x07) and we get
3 times 0x01 instead.
Thus, it will not switch to software mode if OS pins are not hardwired
(which is I must admit, rather unlikely).
>> /*
>> * Software mode is enabled when all three oversampling
>> * pins are set to high. If oversampling gpios are defined
>> @@ -258,7 +259,7 @@ static int ad7606B_sw_mode_config(struct iio_dev
*indio_dev)
>> * otherwise, they must be hardwired to VDD
>> */
>> if (st->gpio_os) {
>> - gpiod_set_array_value(ARRAY_SIZE(os),
>> + gpiod_set_array_value(st->gpio_os->ndescs,
>> st->gpio_os->desc, st->gpio_os->info, os);
>> }
>> /* OS of 128 and 256 are available only in software mode */
>>
On Tue, 18 Jun 2024 14:02:34 +0000, Guillaume Stols wrote:
AD7606-8 is referred to as AD7606 by Analog Devices. This comment aims
to avoid confusion. Also the compatible names were not sorted by
alphabetical order.
Signed-off-by: Guillaume Stols <redacted>
---
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)