557b7ac4067bcf53f0f7121aa4c140ce76800b79
[openwrt/staging/xback.git] /
1 From 3cafcfbab9b5f3f1357b415b6ca09911eeb405d6 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Thu, 4 May 2023 15:48:53 +0100
4 Subject: [PATCH] drivers: hwmon: rp1-adc: check conversion validity before
5 supplying value
6
7 The SAR ADC architecture may complete a conversion but instability in the
8 comparator can corrupt the result. Such corruption is signalled in the CS
9 ERR bit, asserted alongside each conversion result.
10
11 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
12 ---
13 drivers/hwmon/rp1-adc.c | 10 ++++++++--
14 1 file changed, 8 insertions(+), 2 deletions(-)
15
16 --- a/drivers/hwmon/rp1-adc.c
17 +++ b/drivers/hwmon/rp1-adc.c
18 @@ -97,8 +97,14 @@ static int rp1_adc_read(struct rp1_adc_d
19 data->base + RP1_ADC_RWTYPE_SET + RP1_ADC_CS);
20
21 ret = rp1_adc_ready_wait(data);
22 - if (!ret)
23 - *val = readl(data->base + RP1_ADC_RESULT);
24 + if (ret)
25 + return ret;
26 +
27 + /* Asserted if the completed conversion had a convergence error */
28 + if (readl(data->base + RP1_ADC_CS) & RP1_ADC_CS_ERR)
29 + return -EIO;
30 +
31 + *val = readl(data->base + RP1_ADC_RESULT);
32
33 spin_unlock(&data->lock);
34