openwrt/target/linux/bcm27xx/patches-6.1/950-0910-drivers-hwmon-rp1-adc-check-conversion-validity-befo.patch

35 lines
1.1 KiB
Diff
Raw Normal View History

From 3cafcfbab9b5f3f1357b415b6ca09911eeb405d6 Mon Sep 17 00:00:00 2001
From: Jonathan Bell <jonathan@raspberrypi.com>
Date: Thu, 4 May 2023 15:48:53 +0100
Subject: [PATCH] drivers: hwmon: rp1-adc: check conversion validity before
supplying value
The SAR ADC architecture may complete a conversion but instability in the
comparator can corrupt the result. Such corruption is signalled in the CS
ERR bit, asserted alongside each conversion result.
Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
---
drivers/hwmon/rp1-adc.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
--- a/drivers/hwmon/rp1-adc.c
+++ b/drivers/hwmon/rp1-adc.c
@@ -97,8 +97,14 @@ static int rp1_adc_read(struct rp1_adc_d
data->base + RP1_ADC_RWTYPE_SET + RP1_ADC_CS);
ret = rp1_adc_ready_wait(data);
- if (!ret)
- *val = readl(data->base + RP1_ADC_RESULT);
+ if (ret)
+ return ret;
+
+ /* Asserted if the completed conversion had a convergence error */
+ if (readl(data->base + RP1_ADC_CS) & RP1_ADC_CS_ERR)
+ return -EIO;
+
+ *val = readl(data->base + RP1_ADC_RESULT);
spin_unlock(&data->lock);