iio: dac: adi-axi-dac: use unique bus free check
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> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://patch.msgid.link/20250523-ad3552r-fix-bus-read-v3-2-310e726dd964@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
1543572fff
commit
9182f3b4c3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user