mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-22 15:02:32 +00:00
35 lines
1.1 KiB
Diff
35 lines
1.1 KiB
Diff
|
From 78fc5f683ee0e54489fa0022e920d07db237bd78 Mon Sep 17 00:00:00 2001
|
||
|
From: Jonathan Bell <jonathan@raspberrypi.com>
|
||
|
Date: Thu, 4 May 2023 15:48:53 +0100
|
||
|
Subject: [PATCH 0560/1085] 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);
|
||
|
|