* [PATCH 1/2] iio: dac: adi-axi-dac: use unique bus free check
2025-04-08 20:48 [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
@ 2025-04-08 20:49 ` Angelo Dureghello
2025-04-08 20:49 ` [PATCH 2/2] iio: dac: adi-axi-dac: fix bus read Angelo Dureghello
2025-04-09 6:17 ` [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong " Nuno Sá
2 siblings, 0 replies; 4+ messages in thread
From: Angelo Dureghello @ 2025-04-08 20:49 UTC (permalink / raw)
To: Nuno Sa, Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Andy Shevchenko
Cc: linux-iio, linux-kernel, Jonathan Cameron, 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 | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 8ed5ad1fa24cef649056bc5f4ca80abbf28b9323..91557aa6797a3478de3607e5733c162d7745a3b2 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,
@@ -779,7 +787,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;
@@ -792,9 +800,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] 4+ messages in thread* [PATCH 2/2] iio: dac: adi-axi-dac: fix bus read
2025-04-08 20:48 [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
2025-04-08 20:49 ` [PATCH 1/2] iio: dac: adi-axi-dac: use unique bus free check Angelo Dureghello
@ 2025-04-08 20:49 ` Angelo Dureghello
2025-04-09 6:17 ` [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong " Nuno Sá
2 siblings, 0 replies; 4+ messages in thread
From: Angelo Dureghello @ 2025-04-08 20:49 UTC (permalink / raw)
To: Nuno Sa, Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Andy Shevchenko
Cc: linux-iio, linux-kernel, Jonathan Cameron, 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 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 | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 91557aa6797a3478de3607e5733c162d7745a3b2..de959ab116e26f98385d5f5c259d6d1e01a448d9 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -780,6 +780,10 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
if (ret)
return ret;
+ ret = axi_dac_wait_bus_free(st);
+ if (ret)
+ return ret;
+
return regmap_read(st->regmap, AXI_DAC_CUSTOM_RD_REG, val);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong bus read
2025-04-08 20:48 [PATCH 0/2] iio: dac: adi-axi-dac: fix for wrong bus read Angelo Dureghello
2025-04-08 20:49 ` [PATCH 1/2] iio: dac: adi-axi-dac: use unique bus free check Angelo Dureghello
2025-04-08 20:49 ` [PATCH 2/2] iio: dac: adi-axi-dac: fix bus read Angelo Dureghello
@ 2025-04-09 6:17 ` Nuno Sá
2 siblings, 0 replies; 4+ messages in thread
From: Nuno Sá @ 2025-04-09 6:17 UTC (permalink / raw)
To: Angelo Dureghello, Nuno Sa, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, David Lechner, Andy Shevchenko
Cc: linux-iio, linux-kernel, Jonathan Cameron
On Tue, 2025-04-08 at 22:48 +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 reorganizes a bit the busy-wait polling code, second patch
> fixes the wrong bus read occurence.
>
> 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>
> ---
Hi Angelo, patches look good but typically fixes should come first. The reason is
that we only want to backport fixes to stable branches and like this we depend on the
first patch. So first use the plain regmap_read_poll_timeout() before accessing the
bus and then add the helper...
- Nuno Sá
^ permalink raw reply [flat|nested] 4+ messages in thread