* [PATCH v3 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present
@ 2023-05-03 16:20 Sean Nyekjaer
2023-05-03 16:20 ` [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels " Sean Nyekjaer
0 siblings, 1 reply; 4+ messages in thread
From: Sean Nyekjaer @ 2023-05-03 16:20 UTC (permalink / raw)
To: jic23, olivier.moysan, alexandre.torgue, nuno.sa
Cc: Sean Nyekjaer, linux-iio, linux-stm32
If no adc differential channels are defined driver will fail with EINVAL:
stm32-adc: probe of 48003000.adc:adc@0 failed with error -22
Fix this by skipping the initialization if no channels are defined.
This applies only to the legacy way of initializing adc channels.
Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
Changes since v1:
- None
Changes since v2:
- None
drivers/iio/adc/stm32-adc.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index e179b6611e4d..14524c1b5583 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -2008,16 +2008,15 @@ static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm
* to get the *real* number of channels.
*/
ret = device_property_count_u32(dev, "st,adc-diff-channels");
- if (ret < 0)
- return ret;
-
- ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32));
- if (ret > adc_info->max_channels) {
- dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n");
- return -EINVAL;
- } else if (ret > 0) {
- adc->num_diff = ret;
- num_channels += ret;
+ if (ret > 0) {
+ ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32));
+ if (ret > adc_info->max_channels) {
+ dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n");
+ return -EINVAL;
+ } else if (ret > 0) {
+ adc->num_diff = ret;
+ num_channels += ret;
+ }
}
/* Optional sample time is provided either for each, or all channels */
--
2.40.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels setup if none is present
2023-05-03 16:20 [PATCH v3 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present Sean Nyekjaer
@ 2023-05-03 16:20 ` Sean Nyekjaer
2023-05-04 11:41 ` Olivier MOYSAN
0 siblings, 1 reply; 4+ messages in thread
From: Sean Nyekjaer @ 2023-05-03 16:20 UTC (permalink / raw)
To: jic23, olivier.moysan, alexandre.torgue, nuno.sa
Cc: Sean Nyekjaer, linux-iio, linux-stm32
If only adc differential channels are defined driver will fail with
stm32-adc: probe of 48003000.adc:adc@0 failed with error -22
Fix this by skipping the initialization if no channels are defined.
This applies only to the legacy way of initializing adc channels.
Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
Changes since v1:
- Ignore extra channel for timestamps in PIO mode
- Use single ended count in channel creation (Thanks Olivier Moysan)
Changes since v2:
- Avoid calling device_property_read_u32_array with num_se 0 (Thanks Olivier Moysan)
drivers/iio/adc/stm32-adc.c | 42 ++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 14524c1b5583..f7613efb870d 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -2038,6 +2038,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
struct device *dev = &indio_dev->dev;
u32 num_diff = adc->num_diff;
+ int num_se = nchans - num_diff;
int size = num_diff * sizeof(*diff) / sizeof(u32);
int scan_index = 0, ret, i, c;
u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX];
@@ -2064,29 +2065,32 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
scan_index++;
}
}
-
- ret = device_property_read_u32_array(dev, "st,adc-channels", chans,
- nchans);
- if (ret)
- return ret;
-
- for (c = 0; c < nchans; c++) {
- if (chans[c] >= adc_info->max_channels) {
- dev_err(&indio_dev->dev, "Invalid channel %d\n",
- chans[c]);
- return -EINVAL;
+ if (num_se > 0) {
+ ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se);
+ if (ret) {
+ dev_err(&indio_dev->dev, "Failed to get st,adc-channels %d\n", ret);
+ return ret;
}
- /* Channel can't be configured both as single-ended & diff */
- for (i = 0; i < num_diff; i++) {
- if (chans[c] == diff[i].vinp) {
- dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]);
+ for (c = 0; c < num_se; c++) {
+ if (chans[c] >= adc_info->max_channels) {
+ dev_err(&indio_dev->dev, "Invalid channel %d\n",
+ chans[c]);
return -EINVAL;
}
+
+ /* Channel can't be configured both as single-ended & diff */
+ for (i = 0; i < num_diff; i++) {
+ if (chans[c] == diff[i].vinp) {
+ dev_err(&indio_dev->dev, "channel %d misconfigured\n",
+ chans[c]);
+ return -EINVAL;
+ }
+ }
+ stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
+ chans[c], 0, scan_index, false);
+ scan_index++;
}
- stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
- chans[c], 0, scan_index, false);
- scan_index++;
}
if (adc->nsmps > 0) {
@@ -2307,7 +2311,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
if (legacy)
ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels,
- num_channels);
+ timestamping ? num_channels - 1 : num_channels);
else
ret = stm32_adc_generic_chan_init(indio_dev, adc, channels);
if (ret < 0)
--
2.40.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels setup if none is present
2023-05-03 16:20 ` [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels " Sean Nyekjaer
@ 2023-05-04 11:41 ` Olivier MOYSAN
2023-05-06 18:20 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Olivier MOYSAN @ 2023-05-04 11:41 UTC (permalink / raw)
To: Sean Nyekjaer, jic23, alexandre.torgue, nuno.sa, Fabrice GASNIER
Cc: linux-iio, linux-stm32
Hi Sean,
Thanks for your update
You can add my: Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com>
BRs
Olivier
On 5/3/23 18:20, Sean Nyekjaer wrote:
> If only adc differential channels are defined driver will fail with
> stm32-adc: probe of 48003000.adc:adc@0 failed with error -22
>
> Fix this by skipping the initialization if no channels are defined.
>
> This applies only to the legacy way of initializing adc channels.
>
> Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties")
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
> Changes since v1:
> - Ignore extra channel for timestamps in PIO mode
> - Use single ended count in channel creation (Thanks Olivier Moysan)
>
> Changes since v2:
> - Avoid calling device_property_read_u32_array with num_se 0 (Thanks Olivier Moysan)
>
> drivers/iio/adc/stm32-adc.c | 42 ++++++++++++++++++++-----------------
> 1 file changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index 14524c1b5583..f7613efb870d 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
> @@ -2038,6 +2038,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
> struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
> struct device *dev = &indio_dev->dev;
> u32 num_diff = adc->num_diff;
> + int num_se = nchans - num_diff;
> int size = num_diff * sizeof(*diff) / sizeof(u32);
> int scan_index = 0, ret, i, c;
> u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX];
> @@ -2064,29 +2065,32 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
> scan_index++;
> }
> }
> -
> - ret = device_property_read_u32_array(dev, "st,adc-channels", chans,
> - nchans);
> - if (ret)
> - return ret;
> -
> - for (c = 0; c < nchans; c++) {
> - if (chans[c] >= adc_info->max_channels) {
> - dev_err(&indio_dev->dev, "Invalid channel %d\n",
> - chans[c]);
> - return -EINVAL;
> + if (num_se > 0) {
> + ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se);
> + if (ret) {
> + dev_err(&indio_dev->dev, "Failed to get st,adc-channels %d\n", ret);
> + return ret;
> }
>
> - /* Channel can't be configured both as single-ended & diff */
> - for (i = 0; i < num_diff; i++) {
> - if (chans[c] == diff[i].vinp) {
> - dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]);
> + for (c = 0; c < num_se; c++) {
> + if (chans[c] >= adc_info->max_channels) {
> + dev_err(&indio_dev->dev, "Invalid channel %d\n",
> + chans[c]);
> return -EINVAL;
> }
> +
> + /* Channel can't be configured both as single-ended & diff */
> + for (i = 0; i < num_diff; i++) {
> + if (chans[c] == diff[i].vinp) {
> + dev_err(&indio_dev->dev, "channel %d misconfigured\n",
> + chans[c]);
> + return -EINVAL;
> + }
> + }
> + stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
> + chans[c], 0, scan_index, false);
> + scan_index++;
> }
> - stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
> - chans[c], 0, scan_index, false);
> - scan_index++;
> }
>
> if (adc->nsmps > 0) {
> @@ -2307,7 +2311,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
>
> if (legacy)
> ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels,
> - num_channels);
> + timestamping ? num_channels - 1 : num_channels);
> else
> ret = stm32_adc_generic_chan_init(indio_dev, adc, channels);
> if (ret < 0)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels setup if none is present
2023-05-04 11:41 ` Olivier MOYSAN
@ 2023-05-06 18:20 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2023-05-06 18:20 UTC (permalink / raw)
To: Olivier MOYSAN
Cc: Sean Nyekjaer, alexandre.torgue, nuno.sa, Fabrice GASNIER,
linux-iio, linux-stm32
On Thu, 4 May 2023 13:41:24 +0200
Olivier MOYSAN <olivier.moysan@foss.st.com> wrote:
> Hi Sean,
>
> Thanks for your update
> You can add my: Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com>
Please keep RB on a separate line as it makes it easier for scripts to find
it (e.g. b4) I wasn't clear on whether RB applied to both patches or just
this one, so I went with safe option and only applied it to this one.
Both patches applied to the fixes-togreg branch of iio.git
Thanks,
Jonathan
>
> BRs
> Olivier
>
> On 5/3/23 18:20, Sean Nyekjaer wrote:
> > If only adc differential channels are defined driver will fail with
> > stm32-adc: probe of 48003000.adc:adc@0 failed with error -22
> >
> > Fix this by skipping the initialization if no channels are defined.
> >
> > This applies only to the legacy way of initializing adc channels.
> >
> > Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties")
> > Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> > ---
> > Changes since v1:
> > - Ignore extra channel for timestamps in PIO mode
> > - Use single ended count in channel creation (Thanks Olivier Moysan)
> >
> > Changes since v2:
> > - Avoid calling device_property_read_u32_array with num_se 0 (Thanks Olivier Moysan)
> >
> > drivers/iio/adc/stm32-adc.c | 42 ++++++++++++++++++++-----------------
> > 1 file changed, 23 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> > index 14524c1b5583..f7613efb870d 100644
> > --- a/drivers/iio/adc/stm32-adc.c
> > +++ b/drivers/iio/adc/stm32-adc.c
> > @@ -2038,6 +2038,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
> > struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
> > struct device *dev = &indio_dev->dev;
> > u32 num_diff = adc->num_diff;
> > + int num_se = nchans - num_diff;
> > int size = num_diff * sizeof(*diff) / sizeof(u32);
> > int scan_index = 0, ret, i, c;
> > u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX];
> > @@ -2064,29 +2065,32 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
> > scan_index++;
> > }
> > }
> > -
> > - ret = device_property_read_u32_array(dev, "st,adc-channels", chans,
> > - nchans);
> > - if (ret)
> > - return ret;
> > -
> > - for (c = 0; c < nchans; c++) {
> > - if (chans[c] >= adc_info->max_channels) {
> > - dev_err(&indio_dev->dev, "Invalid channel %d\n",
> > - chans[c]);
> > - return -EINVAL;
> > + if (num_se > 0) {
> > + ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se);
> > + if (ret) {
> > + dev_err(&indio_dev->dev, "Failed to get st,adc-channels %d\n", ret);
> > + return ret;
> > }
> >
> > - /* Channel can't be configured both as single-ended & diff */
> > - for (i = 0; i < num_diff; i++) {
> > - if (chans[c] == diff[i].vinp) {
> > - dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]);
> > + for (c = 0; c < num_se; c++) {
> > + if (chans[c] >= adc_info->max_channels) {
> > + dev_err(&indio_dev->dev, "Invalid channel %d\n",
> > + chans[c]);
> > return -EINVAL;
> > }
> > +
> > + /* Channel can't be configured both as single-ended & diff */
> > + for (i = 0; i < num_diff; i++) {
> > + if (chans[c] == diff[i].vinp) {
> > + dev_err(&indio_dev->dev, "channel %d misconfigured\n",
> > + chans[c]);
> > + return -EINVAL;
> > + }
> > + }
> > + stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
> > + chans[c], 0, scan_index, false);
> > + scan_index++;
> > }
> > - stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
> > - chans[c], 0, scan_index, false);
> > - scan_index++;
> > }
> >
> > if (adc->nsmps > 0) {
> > @@ -2307,7 +2311,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
> >
> > if (legacy)
> > ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels,
> > - num_channels);
> > + timestamping ? num_channels - 1 : num_channels);
> > else
> > ret = stm32_adc_generic_chan_init(indio_dev, adc, channels);
> > if (ret < 0)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-06 18:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 16:20 [PATCH v3 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present Sean Nyekjaer
2023-05-03 16:20 ` [PATCH v3 2/2] iio: adc: stm32-adc: skip adc-channels " Sean Nyekjaer
2023-05-04 11:41 ` Olivier MOYSAN
2023-05-06 18:20 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.