Message ID | 20250321-wip-bl-ad3552r-fixes-v1-3-3c1aa249d163@baylibre.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | iio: ad3552r-hs: add support for internal ramp generator | expand |
On Fri, 2025-03-21 at 21:28 +0100, Angelo Dureghello wrote: > From: Angelo Dureghello <adureghello@baylibre.com> > > Add data source getter. > > Signed-off-by: Angelo Dureghello <adureghello@baylibre.com> > --- > drivers/iio/dac/adi-axi-dac.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c > index > 892d770aec69c4259de777058801c9ab33c79923..a6abd828ebdb34800cc08a2151e52a9acda9eba1 > 100644 > --- a/drivers/iio/dac/adi-axi-dac.c > +++ b/drivers/iio/dac/adi-axi-dac.c > @@ -514,6 +514,32 @@ static int axi_dac_data_source_set(struct iio_backend *back, > unsigned int chan, > } > } > > +static int axi_dac_data_source_get(struct iio_backend *back, unsigned int chan, > + enum iio_backend_data_source *data) > +{ > + struct axi_dac_state *st = iio_backend_get_priv(back); > + int ret; > + u32 val; > + > + ret = regmap_read(st->regmap, AXI_DAC_CHAN_CNTRL_7_REG(chan), &val); > + if (ret) > + return ret; Is chan something that we can validate? Do we reliable know max number of channels? > + > + switch (val) { > + case AXI_DAC_DATA_INTERNAL_TONE: > + *data = IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE; > + return 0; > + case AXI_DAC_DATA_DMA: > + *data = IIO_BACKEND_EXTERNAL; > + return 0; > + case AXI_DAC_DATA_INTERNAL_RAMP_16BIT: > + *data = IIO_BACKEND_INTERNAL_RAMP_16BIT; > + return 0; > + default: > + return -EINVAL; More of a nitpick comment but I would some other error code. This is not really an "Invalid argument" situation. Maybe -EIO as the HW is giving something unexpected? or ENOTSUPP (likely not exactly like this)... - Nuno Sá > .ddr_disable = axi_dac_ddr_disable, > .data_stream_enable = axi_dac_data_stream_enable, >
On 28.03.2025 08:15, Nuno Sá wrote: > On Fri, 2025-03-21 at 21:28 +0100, Angelo Dureghello wrote: > > From: Angelo Dureghello <adureghello@baylibre.com> > > > > Add data source getter. > > > > Signed-off-by: Angelo Dureghello <adureghello@baylibre.com> > > --- > > drivers/iio/dac/adi-axi-dac.c | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c > > index > > 892d770aec69c4259de777058801c9ab33c79923..a6abd828ebdb34800cc08a2151e52a9acda9eba1 > > 100644 > > --- a/drivers/iio/dac/adi-axi-dac.c > > +++ b/drivers/iio/dac/adi-axi-dac.c > > @@ -514,6 +514,32 @@ static int axi_dac_data_source_set(struct iio_backend *back, > > unsigned int chan, > > } > > } > > > > +static int axi_dac_data_source_get(struct iio_backend *back, unsigned int chan, > > + enum iio_backend_data_source *data) > > +{ > > + struct axi_dac_state *st = iio_backend_get_priv(back); > > + int ret; > > + u32 val; > > + > > + ret = regmap_read(st->regmap, AXI_DAC_CHAN_CNTRL_7_REG(chan), &val); > > + if (ret) > > + return ret; > > Is chan something that we can validate? Do we reliable know max number of channels? > Ack, will set it to 15, 0 to 15 is what the documentation says. But at this point should be set in a diffetrent patch for the "set" too. Btw, there is something odd here. I tested the generator and it works, i am enabling RAMP for both channels 0 and 1. The channel offset here is 0x40, while in ad3552r and generic dac doc it is 0x58. So, since ramp is working i am supposing the documentation can be wrong. > > + > > + switch (val) { > > + case AXI_DAC_DATA_INTERNAL_TONE: > > + *data = IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE; > > + return 0; > > + case AXI_DAC_DATA_DMA: > > + *data = IIO_BACKEND_EXTERNAL; > > + return 0; > > + case AXI_DAC_DATA_INTERNAL_RAMP_16BIT: > > + *data = IIO_BACKEND_INTERNAL_RAMP_16BIT; > > + return 0; > > + default: > > + return -EINVAL; > > More of a nitpick comment but I would some other error code. This is not really an > "Invalid argument" situation. Maybe -EIO as the HW is giving something unexpected? or > ENOTSUPP (likely not exactly like this)... > Correct, will set EIO. > - Nuno Sá > > > .ddr_disable = axi_dac_ddr_disable, > > .data_stream_enable = axi_dac_data_stream_enable, > > >
diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c index 892d770aec69c4259de777058801c9ab33c79923..a6abd828ebdb34800cc08a2151e52a9acda9eba1 100644 --- a/drivers/iio/dac/adi-axi-dac.c +++ b/drivers/iio/dac/adi-axi-dac.c @@ -514,6 +514,32 @@ static int axi_dac_data_source_set(struct iio_backend *back, unsigned int chan, } } +static int axi_dac_data_source_get(struct iio_backend *back, unsigned int chan, + enum iio_backend_data_source *data) +{ + struct axi_dac_state *st = iio_backend_get_priv(back); + int ret; + u32 val; + + ret = regmap_read(st->regmap, AXI_DAC_CHAN_CNTRL_7_REG(chan), &val); + if (ret) + return ret; + + switch (val) { + case AXI_DAC_DATA_INTERNAL_TONE: + *data = IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE; + return 0; + case AXI_DAC_DATA_DMA: + *data = IIO_BACKEND_EXTERNAL; + return 0; + case AXI_DAC_DATA_INTERNAL_RAMP_16BIT: + *data = IIO_BACKEND_INTERNAL_RAMP_16BIT; + return 0; + default: + return -EINVAL; + } +} + static int axi_dac_set_sample_rate(struct iio_backend *back, unsigned int chan, u64 sample_rate) { @@ -794,6 +820,7 @@ static const struct iio_backend_ops axi_ad3552r_ops = { .request_buffer = axi_dac_request_buffer, .free_buffer = axi_dac_free_buffer, .data_source_set = axi_dac_data_source_set, + .data_source_get = axi_dac_data_source_get, .ddr_enable = axi_dac_ddr_enable, .ddr_disable = axi_dac_ddr_disable, .data_stream_enable = axi_dac_data_stream_enable,