Skip to content

Commit 3e27ef0

Browse files
sknseanjic23
authored andcommitted
iio: adc: stm32-adc: skip adc-channels setup if none is present
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: d7705f3 ("iio: adc: stm32-adc: convert to device properties") Signed-off-by: Sean Nyekjaer <[email protected]> Reviewed-by: Olivier Moysan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 9c0d6cc commit 3e27ef0

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

drivers/iio/adc/stm32-adc.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
20362036
struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
20372037
struct device *dev = &indio_dev->dev;
20382038
u32 num_diff = adc->num_diff;
2039+
int num_se = nchans - num_diff;
20392040
int size = num_diff * sizeof(*diff) / sizeof(u32);
20402041
int scan_index = 0, ret, i, c;
20412042
u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX];
@@ -2062,29 +2063,32 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
20622063
scan_index++;
20632064
}
20642065
}
2065-
2066-
ret = device_property_read_u32_array(dev, "st,adc-channels", chans,
2067-
nchans);
2068-
if (ret)
2069-
return ret;
2070-
2071-
for (c = 0; c < nchans; c++) {
2072-
if (chans[c] >= adc_info->max_channels) {
2073-
dev_err(&indio_dev->dev, "Invalid channel %d\n",
2074-
chans[c]);
2075-
return -EINVAL;
2066+
if (num_se > 0) {
2067+
ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se);
2068+
if (ret) {
2069+
dev_err(&indio_dev->dev, "Failed to get st,adc-channels %d\n", ret);
2070+
return ret;
20762071
}
20772072

2078-
/* Channel can't be configured both as single-ended & diff */
2079-
for (i = 0; i < num_diff; i++) {
2080-
if (chans[c] == diff[i].vinp) {
2081-
dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]);
2073+
for (c = 0; c < num_se; c++) {
2074+
if (chans[c] >= adc_info->max_channels) {
2075+
dev_err(&indio_dev->dev, "Invalid channel %d\n",
2076+
chans[c]);
20822077
return -EINVAL;
20832078
}
2079+
2080+
/* Channel can't be configured both as single-ended & diff */
2081+
for (i = 0; i < num_diff; i++) {
2082+
if (chans[c] == diff[i].vinp) {
2083+
dev_err(&indio_dev->dev, "channel %d misconfigured\n",
2084+
chans[c]);
2085+
return -EINVAL;
2086+
}
2087+
}
2088+
stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
2089+
chans[c], 0, scan_index, false);
2090+
scan_index++;
20842091
}
2085-
stm32_adc_chan_init_one(indio_dev, &channels[scan_index],
2086-
chans[c], 0, scan_index, false);
2087-
scan_index++;
20882092
}
20892093

20902094
if (adc->nsmps > 0) {
@@ -2305,7 +2309,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
23052309

23062310
if (legacy)
23072311
ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels,
2308-
num_channels);
2312+
timestamping ? num_channels - 1 : num_channels);
23092313
else
23102314
ret = stm32_adc_generic_chan_init(indio_dev, adc, channels);
23112315
if (ret < 0)

0 commit comments

Comments
 (0)