Skip to content

Commit bc05f30

Browse files
Olivier Moysanjic23
authored andcommitted
iio: adc: stm32: fix vrefint wrong calibration value handling
If the vrefint calibration is zero, the vrefint channel output value cannot be computed. Currently, in such case, the raw conversion value is returned, which is not relevant. Do not expose the vrefint channel when the output value cannot be computed, instead. Fixes: 0e346b2 ("iio: adc: stm32-adc: add vrefint calibration support") Signed-off-by: Olivier Moysan <[email protected]> Reviewed-by: Fabrice Gasnier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 106b391 commit bc05f30

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

drivers/iio/adc/stm32-adc.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
13651365
else
13661366
ret = -EINVAL;
13671367

1368-
if (mask == IIO_CHAN_INFO_PROCESSED && adc->vrefint.vrefint_cal)
1368+
if (mask == IIO_CHAN_INFO_PROCESSED)
13691369
*val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
13701370

13711371
iio_device_release_direct_mode(indio_dev);
@@ -1969,21 +1969,26 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
19691969

19701970
for (i = 0; i < STM32_ADC_INT_CH_NB; i++) {
19711971
if (!strncmp(stm32_adc_ic[i].name, ch_name, STM32_ADC_CH_SZ)) {
1972-
adc->int_ch[i] = chan;
1973-
1974-
if (stm32_adc_ic[i].idx != STM32_ADC_INT_CH_VREFINT)
1975-
continue;
1972+
if (stm32_adc_ic[i].idx != STM32_ADC_INT_CH_VREFINT) {
1973+
adc->int_ch[i] = chan;
1974+
break;
1975+
}
19761976

19771977
/* Get calibration data for vrefint channel */
19781978
ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint);
19791979
if (ret && ret != -ENOENT) {
19801980
return dev_err_probe(indio_dev->dev.parent, ret,
19811981
"nvmem access error\n");
19821982
}
1983-
if (ret == -ENOENT)
1984-
dev_dbg(&indio_dev->dev, "vrefint calibration not found\n");
1985-
else
1986-
adc->vrefint.vrefint_cal = vrefint;
1983+
if (ret == -ENOENT) {
1984+
dev_dbg(&indio_dev->dev, "vrefint calibration not found. Skip vrefint channel\n");
1985+
return ret;
1986+
} else if (!vrefint) {
1987+
dev_dbg(&indio_dev->dev, "Null vrefint calibration value. Skip vrefint channel\n");
1988+
return -ENOENT;
1989+
}
1990+
adc->int_ch[i] = chan;
1991+
adc->vrefint.vrefint_cal = vrefint;
19871992
}
19881993
}
19891994

@@ -2020,7 +2025,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
20202025
}
20212026
strncpy(adc->chan_name[val], name, STM32_ADC_CH_SZ);
20222027
ret = stm32_adc_populate_int_ch(indio_dev, name, val);
2023-
if (ret)
2028+
if (ret == -ENOENT)
2029+
continue;
2030+
else if (ret)
20242031
goto err;
20252032
} else if (ret != -EINVAL) {
20262033
dev_err(&indio_dev->dev, "Invalid label %d\n", ret);

0 commit comments

Comments
 (0)