Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read
@ 2025-05-23  9:00 Angelo Dureghello
  2025-05-23  9:00 ` [PATCH v3 1/2] iio: dac: adi-axi-dac: fix " Angelo Dureghello
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Angelo Dureghello @ 2025-05-23  9:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sa, Jonathan Cameron,
	David Lechner, Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Angelo Dureghello

This patchset is intended to fix a random wrong chip ID read, or a
scratchpad test mismatch, tests done in the ad3552r-hs driver probe. The
bus "read" operation must always check for busy flag before reading.

First patch fixes the wrong bus read occurence, second patch reorganizes
a bit the busy-wait polling code.

NOTE: due to ongoing changes in adi-axi-dac.c, this patch is intended to be
applied after the linked "ramp generator" patch.

Link: https://lore.kernel.org/linux-iio/20250408-wip-bl-ad3552r-fixes-v4-0-b33c0264bd78@baylibre.com
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
Changes in v3:
- fix axi_dac_wait_bus_free(), 0 must be checked on poll, not -1. Someway
  failed testing it here initially.
- Link to v2: https://lore.kernel.org/r/20250409-ad3552r-fix-bus-read-v2-0-34d3b21e8ca0@baylibre.com

Changes in v2:
- invert patch order, fix first.
- Link to v1: https://lore.kernel.org/r/20250408-ad3552r-fix-bus-read-v1-0-37add66aeb08@baylibre.com

---
Angelo Dureghello (2):
      iio: dac: adi-axi-dac: fix bus read
      iio: dac: adi-axi-dac: use unique bus free check

 drivers/iio/dac/adi-axi-dac.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)
---
base-commit: 6fb85f14853ddde06d57030c753168402bf69cd9
change-id: 20250408-ad3552r-fix-bus-read-1522622fbd2b

Best regards,
-- 
Angelo Dureghello <adureghello@baylibre.com>


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

* [PATCH v3 1/2] iio: dac: adi-axi-dac: fix bus read
  2025-05-23  9:00 [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
@ 2025-05-23  9:00 ` Angelo Dureghello
  2025-05-25 13:47   ` Jonathan Cameron
  2025-05-23  9:00 ` [PATCH v3 2/2] iio: dac: adi-axi-dac: use unique bus free check Angelo Dureghello
  2025-05-23 13:36 ` [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Nuno Sá
  2 siblings, 1 reply; 6+ messages in thread
From: Angelo Dureghello @ 2025-05-23  9:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sa, Jonathan Cameron,
	David Lechner, Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Angelo Dureghello

From: Angelo Dureghello <adureghello@baylibre.com>

Fix bus read function.

Testing the driver, on a random basis, wrong reads was detected, mainly
by a wrong DAC chip ID read at first boot.
Before reading the expected value from the AXI regmap, need always to
wait for busy flag to be cleared.

Fixes: e61d7178429a ("iio: dac: adi-axi-dac: extend features")
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
 drivers/iio/dac/adi-axi-dac.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 8ed5ad1fa24cef649056bc5f4ca80abbf28b9323..5ee077c58d7f9730aec8a9c9dff5b84108b3a47e 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -760,6 +760,7 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
 {
 	struct axi_dac_state *st = iio_backend_get_priv(back);
 	int ret;
+	u32 ival;
 
 	guard(mutex)(&st->lock);
 
@@ -772,6 +773,13 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
 	if (ret)
 		return ret;
 
+	ret = regmap_read_poll_timeout(st->regmap,
+				AXI_DAC_UI_STATUS_REG, ival,
+				FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0,
+				10, 100 * KILO);
+	if (ret)
+		return ret;
+
 	return regmap_read(st->regmap, AXI_DAC_CUSTOM_RD_REG, val);
 }
 

-- 
2.49.0


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

* [PATCH v3 2/2] iio: dac: adi-axi-dac: use unique bus free check
  2025-05-23  9:00 [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
  2025-05-23  9:00 ` [PATCH v3 1/2] iio: dac: adi-axi-dac: fix " Angelo Dureghello
@ 2025-05-23  9:00 ` Angelo Dureghello
  2025-05-23 13:36 ` [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Nuno Sá
  2 siblings, 0 replies; 6+ messages in thread
From: Angelo Dureghello @ 2025-05-23  9:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sa, Jonathan Cameron,
	David Lechner, Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Angelo Dureghello

From: Angelo Dureghello <adureghello@baylibre.com>

Use a unique function for the bus free check by polling, to reduce
duplicated code. An error is always thrown in case of timeout.

Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
 drivers/iio/dac/adi-axi-dac.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 5ee077c58d7f9730aec8a9c9dff5b84108b3a47e..de959ab116e26f98385d5f5c259d6d1e01a448d9 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -635,15 +635,26 @@ static int axi_dac_ddr_disable(struct iio_backend *back)
 			       AXI_DAC_CNTRL_2_SDR_DDR_N);
 }
 
+static int axi_dac_wait_bus_free(struct axi_dac_state *st)
+{
+	u32 val;
+	int ret;
+
+	ret = regmap_read_poll_timeout(st->regmap, AXI_DAC_UI_STATUS_REG, val,
+		FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, val) == 0, 10,
+		100 * KILO);
+	if (ret == -ETIMEDOUT)
+		dev_err(st->dev, "AXI bus timeout\n");
+
+	return ret;
+}
+
 static int axi_dac_data_stream_enable(struct iio_backend *back)
 {
 	struct axi_dac_state *st = iio_backend_get_priv(back);
-	int ret, val;
+	int ret;
 
-	ret = regmap_read_poll_timeout(st->regmap,
-				AXI_DAC_UI_STATUS_REG, val,
-				FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, val) == 0,
-				10, 100 * KILO);
+	ret = axi_dac_wait_bus_free(st);
 	if (ret)
 		return ret;
 
@@ -734,12 +745,9 @@ static int __axi_dac_bus_reg_write(struct iio_backend *back, u32 reg,
 	if (ret)
 		return ret;
 
-	ret = regmap_read_poll_timeout(st->regmap,
-				AXI_DAC_UI_STATUS_REG, ival,
-				FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0,
-				10, 100 * KILO);
-	if (ret == -ETIMEDOUT)
-		dev_err(st->dev, "AXI read timeout\n");
+	ret = axi_dac_wait_bus_free(st);
+	if (ret)
+		return ret;
 
 	/* Cleaning always AXI_DAC_CUSTOM_CTRL_TRANSFER_DATA */
 	return regmap_clear_bits(st->regmap, AXI_DAC_CUSTOM_CTRL_REG,
@@ -760,7 +768,6 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
 {
 	struct axi_dac_state *st = iio_backend_get_priv(back);
 	int ret;
-	u32 ival;
 
 	guard(mutex)(&st->lock);
 
@@ -773,10 +780,7 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
 	if (ret)
 		return ret;
 
-	ret = regmap_read_poll_timeout(st->regmap,
-				AXI_DAC_UI_STATUS_REG, ival,
-				FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0,
-				10, 100 * KILO);
+	ret = axi_dac_wait_bus_free(st);
 	if (ret)
 		return ret;
 
@@ -787,7 +791,7 @@ static int axi_dac_bus_set_io_mode(struct iio_backend *back,
 				   enum ad3552r_io_mode mode)
 {
 	struct axi_dac_state *st = iio_backend_get_priv(back);
-	int ival, ret;
+	int ret;
 
 	if (mode > AD3552R_IO_MODE_QSPI)
 		return -EINVAL;
@@ -800,9 +804,7 @@ static int axi_dac_bus_set_io_mode(struct iio_backend *back,
 	if (ret)
 		return ret;
 
-	return regmap_read_poll_timeout(st->regmap, AXI_DAC_UI_STATUS_REG, ival,
-			FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0, 10,
-			100 * KILO);
+	return axi_dac_wait_bus_free(st);
 }
 
 static void axi_dac_child_remove(void *data)

-- 
2.49.0


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

* Re: [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read
  2025-05-23  9:00 [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
  2025-05-23  9:00 ` [PATCH v3 1/2] iio: dac: adi-axi-dac: fix " Angelo Dureghello
  2025-05-23  9:00 ` [PATCH v3 2/2] iio: dac: adi-axi-dac: use unique bus free check Angelo Dureghello
@ 2025-05-23 13:36 ` Nuno Sá
  2025-05-25 13:48   ` Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Nuno Sá @ 2025-05-23 13:36 UTC (permalink / raw)
  To: Angelo Dureghello, Lars-Peter Clausen, Michael Hennerich, Nuno Sa,
	Jonathan Cameron, David Lechner, Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, linux-kernel

On Fri, 2025-05-23 at 11:00 +0200, Angelo Dureghello wrote:
> This patchset is intended to fix a random wrong chip ID read, or a
> scratchpad test mismatch, tests done in the ad3552r-hs driver probe. The
> bus "read" operation must always check for busy flag before reading.
> 
> First patch fixes the wrong bus read occurence, second patch reorganizes
> a bit the busy-wait polling code.
> 
> NOTE: due to ongoing changes in adi-axi-dac.c, this patch is intended to be
> applied after the linked "ramp generator" patch.
> 
> Link:
> https://lore.kernel.org/linux-iio/20250408-wip-bl-ad3552r-fixes-v4-0-b33c0264bd78@baylibre.com
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

> Changes in v3:
> - fix axi_dac_wait_bus_free(), 0 must be checked on poll, not -1. Someway
>   failed testing it here initially.
> - Link to v2:
> https://lore.kernel.org/r/20250409-ad3552r-fix-bus-read-v2-0-34d3b21e8ca0@baylibre.com
> 
> Changes in v2:
> - invert patch order, fix first.
> - Link to v1:
> https://lore.kernel.org/r/20250408-ad3552r-fix-bus-read-v1-0-37add66aeb08@baylibre.com
> 
> ---
> Angelo Dureghello (2):
>       iio: dac: adi-axi-dac: fix bus read
>       iio: dac: adi-axi-dac: use unique bus free check
> 
>  drivers/iio/dac/adi-axi-dac.c | 40 +++++++++++++++++++++++++---------------
>  1 file changed, 25 insertions(+), 15 deletions(-)
> ---
> base-commit: 6fb85f14853ddde06d57030c753168402bf69cd9
> change-id: 20250408-ad3552r-fix-bus-read-1522622fbd2b
> 
> Best regards,

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

* Re: [PATCH v3 1/2] iio: dac: adi-axi-dac: fix bus read
  2025-05-23  9:00 ` [PATCH v3 1/2] iio: dac: adi-axi-dac: fix " Angelo Dureghello
@ 2025-05-25 13:47   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2025-05-25 13:47 UTC (permalink / raw)
  To: Angelo Dureghello
  Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sa, David Lechner,
	Andy Shevchenko, Jonathan Cameron, linux-iio, linux-kernel

On Fri, 23 May 2025 11:00:51 +0200
Angelo Dureghello <adureghello@baylibre.com> wrote:

> From: Angelo Dureghello <adureghello@baylibre.com>
> 
> Fix bus read function.
> 
> Testing the driver, on a random basis, wrong reads was detected, mainly
> by a wrong DAC chip ID read at first boot.
> Before reading the expected value from the AXI regmap, need always to
> wait for busy flag to be cleared.
> 
> Fixes: e61d7178429a ("iio: dac: adi-axi-dac: extend features")
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Huh. Seems I never replied to original thread, but I took this a while
back.  Looks unchanged at a quick glance so no problem.

Jonathan


> ---
>  drivers/iio/dac/adi-axi-dac.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
> index 8ed5ad1fa24cef649056bc5f4ca80abbf28b9323..5ee077c58d7f9730aec8a9c9dff5b84108b3a47e 100644
> --- a/drivers/iio/dac/adi-axi-dac.c
> +++ b/drivers/iio/dac/adi-axi-dac.c
> @@ -760,6 +760,7 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
>  {
>  	struct axi_dac_state *st = iio_backend_get_priv(back);
>  	int ret;
> +	u32 ival;
>  
>  	guard(mutex)(&st->lock);
>  
> @@ -772,6 +773,13 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
>  	if (ret)
>  		return ret;
>  
> +	ret = regmap_read_poll_timeout(st->regmap,
> +				AXI_DAC_UI_STATUS_REG, ival,
> +				FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0,
> +				10, 100 * KILO);
> +	if (ret)
> +		return ret;
> +
>  	return regmap_read(st->regmap, AXI_DAC_CUSTOM_RD_REG, val);
>  }
>  
> 


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

* Re: [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read
  2025-05-23 13:36 ` [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Nuno Sá
@ 2025-05-25 13:48   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2025-05-25 13:48 UTC (permalink / raw)
  To: Nuno Sá
  Cc: Angelo Dureghello, Lars-Peter Clausen, Michael Hennerich, Nuno Sa,
	David Lechner, Andy Shevchenko, Jonathan Cameron, linux-iio,
	linux-kernel

On Fri, 23 May 2025 14:36:50 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Fri, 2025-05-23 at 11:00 +0200, Angelo Dureghello wrote:
> > This patchset is intended to fix a random wrong chip ID read, or a
> > scratchpad test mismatch, tests done in the ad3552r-hs driver probe. The
> > bus "read" operation must always check for busy flag before reading.
> > 
> > First patch fixes the wrong bus read occurence, second patch reorganizes
> > a bit the busy-wait polling code.
> > 
> > NOTE: due to ongoing changes in adi-axi-dac.c, this patch is intended to be
> > applied after the linked "ramp generator" patch.
> > 
> > Link:
> > https://lore.kernel.org/linux-iio/20250408-wip-bl-ad3552r-fixes-v4-0-b33c0264bd78@baylibre.com
> > Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> > ---  
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Applied patch 2 - though note I'll be rebasing on rc1 once that is out so for
now this will only appear as testing.

> 
> > Changes in v3:
> > - fix axi_dac_wait_bus_free(), 0 must be checked on poll, not -1. Someway
> >   failed testing it here initially.
> > - Link to v2:
> > https://lore.kernel.org/r/20250409-ad3552r-fix-bus-read-v2-0-34d3b21e8ca0@baylibre.com
> > 
> > Changes in v2:
> > - invert patch order, fix first.
> > - Link to v1:
> > https://lore.kernel.org/r/20250408-ad3552r-fix-bus-read-v1-0-37add66aeb08@baylibre.com
> > 
> > ---
> > Angelo Dureghello (2):
> >       iio: dac: adi-axi-dac: fix bus read
> >       iio: dac: adi-axi-dac: use unique bus free check
> > 
> >  drivers/iio/dac/adi-axi-dac.c | 40 +++++++++++++++++++++++++---------------
> >  1 file changed, 25 insertions(+), 15 deletions(-)
> > ---
> > base-commit: 6fb85f14853ddde06d57030c753168402bf69cd9
> > change-id: 20250408-ad3552r-fix-bus-read-1522622fbd2b
> > 
> > Best regards,  


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

end of thread, other threads:[~2025-05-25 13:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23  9:00 [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
2025-05-23  9:00 ` [PATCH v3 1/2] iio: dac: adi-axi-dac: fix " Angelo Dureghello
2025-05-25 13:47   ` Jonathan Cameron
2025-05-23  9:00 ` [PATCH v3 2/2] iio: dac: adi-axi-dac: use unique bus free check Angelo Dureghello
2025-05-23 13:36 ` [PATCH v3 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Nuno Sá
2025-05-25 13:48   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox