Commit 3e27ef0c authored by Sean Nyekjaer's avatar Sean Nyekjaer Committed by Jonathan Cameron

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: d7705f35 ("iio: adc: stm32-adc: convert to device properties")
Signed-off-by: default avatarSean Nyekjaer <sean@geanix.com>
Reviewed-by: default avatarOlivier Moysan <olivier.moysan@foss.st.com>
Link: https://lore.kernel.org/r/20230503162029.3654093-2-sean@geanix.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 9c0d6ccd
...@@ -2036,6 +2036,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev, ...@@ -2036,6 +2036,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX]; struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX];
struct device *dev = &indio_dev->dev; struct device *dev = &indio_dev->dev;
u32 num_diff = adc->num_diff; u32 num_diff = adc->num_diff;
int num_se = nchans - num_diff;
int size = num_diff * sizeof(*diff) / sizeof(u32); int size = num_diff * sizeof(*diff) / sizeof(u32);
int scan_index = 0, ret, i, c; int scan_index = 0, ret, i, c;
u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX]; 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, ...@@ -2062,29 +2063,32 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev,
scan_index++; scan_index++;
} }
} }
if (num_se > 0) {
ret = device_property_read_u32_array(dev, "st,adc-channels", chans, ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se);
nchans); if (ret) {
if (ret) dev_err(&indio_dev->dev, "Failed to get st,adc-channels %d\n", ret);
return 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;
} }
/* Channel can't be configured both as single-ended & diff */ for (c = 0; c < num_se; c++) {
for (i = 0; i < num_diff; i++) { if (chans[c] >= adc_info->max_channels) {
if (chans[c] == diff[i].vinp) { dev_err(&indio_dev->dev, "Invalid channel %d\n",
dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]); chans[c]);
return -EINVAL; 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) { if (adc->nsmps > 0) {
...@@ -2305,7 +2309,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) ...@@ -2305,7 +2309,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
if (legacy) if (legacy)
ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels, ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels,
num_channels); timestamping ? num_channels - 1 : num_channels);
else else
ret = stm32_adc_generic_chan_init(indio_dev, adc, channels); ret = stm32_adc_generic_chan_init(indio_dev, adc, channels);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment