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
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.
11 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
13 drivers/hwmon/rp1-adc.c | 10 ++++++++--
14 1 file changed, 8 insertions(+), 2 deletions(-)
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);
21 ret = rp1_adc_ready_wait(data);
23 - *val = readl(data->base + RP1_ADC_RESULT);
27 + /* Asserted if the completed conversion had a convergence error */
28 + if (readl(data->base + RP1_ADC_CS) & RP1_ADC_CS_ERR)
31 + *val = readl(data->base + RP1_ADC_RESULT);
33 spin_unlock(&data->lock);