[PATCH] iio: adc: adi-axi-adc: fix ad7606_bus_reg_read()

David Lechner posted 1 patch 6 months, 2 weeks ago
There is a newer version of this series
drivers/iio/adc/adi-axi-adc.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] iio: adc: adi-axi-adc: fix ad7606_bus_reg_read()
Posted by David Lechner 6 months, 2 weeks ago
Mask the value read before returning it. The value read over the
parallel bus via the AXI ADC IP block contains both the address and
the data, but callers expect val to only contain the data.

Cc: stable@vger.kernel.org
Fixes: 79c47485e438 ("iio: adc: adi-axi-adc: add support for AD7606 register writing")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/adi-axi-adc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index cf942c043457ccea49207c3900153ee371b3774f..d4759a98b4062bc25ea088e3868806e82db03e8d 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -457,6 +457,9 @@ static int ad7606_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val)
 	axi_adc_raw_write(back, addr);
 	axi_adc_raw_read(back, val);
 
+	/* Register value is 8 bits. Remove address bits. */
+	*val &= 0xFF;
+
 	/* Write 0x0 on the bus to get back to ADC mode */
 	axi_adc_raw_write(back, 0);
 

---
base-commit: 7cdfbc0113d087348b8e65dd79276d0f57b89a10
change-id: 20250530-iio-adc-adi-axi-adc-fix-ad7606_bus_reg_read-f2bbb503db8b

Best regards,
-- 
David Lechner <dlechner@baylibre.com>
Re: [PATCH] iio: adc: adi-axi-adc: fix ad7606_bus_reg_read()
Posted by David Lechner 6 months, 2 weeks ago
On 5/30/25 2:09 PM, David Lechner wrote:
> Mask the value read before returning it. The value read over the
> parallel bus via the AXI ADC IP block contains both the address and
> the data, but callers expect val to only contain the data.
> 
> Cc: stable@vger.kernel.org
> Fixes: 79c47485e438 ("iio: adc: adi-axi-adc: add support for AD7606 register writing")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/adc/adi-axi-adc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index cf942c043457ccea49207c3900153ee371b3774f..d4759a98b4062bc25ea088e3868806e82db03e8d 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -457,6 +457,9 @@ static int ad7606_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val)
>  	axi_adc_raw_write(back, addr);
>  	axi_adc_raw_read(back, val);
>  
> +	/* Register value is 8 bits. Remove address bits. */
> +	*val &= 0xFF;

I just found out that there is ADI_AXI_REG_VALUE_MASK we can use
here instead of 0xFF.

> +
>  	/* Write 0x0 on the bus to get back to ADC mode */
>  	axi_adc_raw_write(back, 0);
>  
> 
> ---
> base-commit: 7cdfbc0113d087348b8e65dd79276d0f57b89a10
> change-id: 20250530-iio-adc-adi-axi-adc-fix-ad7606_bus_reg_read-f2bbb503db8b
> 
> Best regards,
Re: [PATCH] iio: adc: adi-axi-adc: fix ad7606_bus_reg_read()
Posted by David Lechner 6 months, 2 weeks ago
On 5/30/25 2:14 PM, David Lechner wrote:
> On 5/30/25 2:09 PM, David Lechner wrote:
>> Mask the value read before returning it. The value read over the
>> parallel bus via the AXI ADC IP block contains both the address and
>> the data, but callers expect val to only contain the data.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: 79c47485e438 ("iio: adc: adi-axi-adc: add support for AD7606 register writing")
>> Signed-off-by: David Lechner <dlechner@baylibre.com>
>> ---
>>  drivers/iio/adc/adi-axi-adc.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
>> index cf942c043457ccea49207c3900153ee371b3774f..d4759a98b4062bc25ea088e3868806e82db03e8d 100644
>> --- a/drivers/iio/adc/adi-axi-adc.c
>> +++ b/drivers/iio/adc/adi-axi-adc.c
>> @@ -457,6 +457,9 @@ static int ad7606_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val)
>>  	axi_adc_raw_write(back, addr);
>>  	axi_adc_raw_read(back, val);
>>  
>> +	/* Register value is 8 bits. Remove address bits. */
>> +	*val &= 0xFF;
> 
> I just found out that there is ADI_AXI_REG_VALUE_MASK we can use
> here instead of 0xFF.
> 
>> +
>>  	/* Write 0x0 on the bus to get back to ADC mode */
>>  	axi_adc_raw_write(back, 0);
>>  
>>
>> ---
>> base-commit: 7cdfbc0113d087348b8e65dd79276d0f57b89a10
>> change-id: 20250530-iio-adc-adi-axi-adc-fix-ad7606_bus_reg_read-f2bbb503db8b
>>
>> Best regards,
> 

Normally I would wait longer for comments, but this is rather small and
I've got some other changes that depend on this ready to go, so skip
ahead to v2.