summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-03-16 17:42:28 +1100
committerCommit Bot <commit-bot@chromium.org>2022-03-17 03:51:31 +0000
commit5e4df0a33de371076193e050d3234c5e67d66618 (patch)
tree39e5ef245f508f8a0a40bae171f995e36b8339f9
parent68e74b9d5e41ad73dbbfe95ac40e978b2b1c8f02 (diff)
downloadchrome-ec-5e4df0a33de371076193e050d3234c5e67d66618.tar.gz
nissa: Workaround for ADC initial read error
It appears the ADC comparator initialisation breaks other ADCs that have not been read, so workaround the issue by initially reading all ADCs so that they are correctly initialised. Also add a check so that zero reads are detected and returned as an error. BUG=b:224900226 TEST=zmake build nivviks; flash and run and check ADCs work. BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: Ifcbebf2ca9b9a336f10fe3659fd3452223474ed3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3528015 Reviewed-by: Peter Marheine <pmarheine@chromium.org> Commit-Queue: Peter Marheine <pmarheine@chromium.org>
-rw-r--r--zephyr/projects/nissa/src/nivviks/board_config.c9
-rw-r--r--zephyr/shim/src/adc.c11
2 files changed, 20 insertions, 0 deletions
diff --git a/zephyr/projects/nissa/src/nivviks/board_config.c b/zephyr/projects/nissa/src/nivviks/board_config.c
index 24531b62c6..89ecfc63c3 100644
--- a/zephyr/projects/nissa/src/nivviks/board_config.c
+++ b/zephyr/projects/nissa/src/nivviks/board_config.c
@@ -10,6 +10,7 @@
#include <kernel.h>
#include <sys/printk.h>
+#include "adc.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
#include "gpio/gpio_int.h"
@@ -78,6 +79,14 @@ static void nivviks_subboard_init(void)
gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_hpd_odl),
GPIO_INPUT);
}
+ /*
+ * Workaround for b/224900226.
+ * Read all ADCs so that they are initialised.
+ * TODO(b/224900226): Remove when fixed.
+ */
+ for (enum adc_channel adc = 0; adc < ADC_CH_COUNT; adc++) {
+ adc_read_channel(adc);
+ }
}
DECLARE_HOOK(HOOK_INIT, nivviks_subboard_init, HOOK_PRIO_FIRST+1);
diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c
index 68babcc576..d5f0ed4a8b 100644
--- a/zephyr/shim/src/adc.c
+++ b/zephyr/shim/src/adc.c
@@ -82,5 +82,16 @@ int adc_read_channel(enum adc_channel ch)
ADC_GAIN_1, CONFIG_PLATFORM_EC_ADC_RESOLUTION,
&ret);
ret = (ret * adc_channels[ch].factor_mul) / adc_channels[ch].factor_div;
+#ifdef CONFIG_BOARD_NIVVIKS
+ /*
+ * TODO(b/224900226): Remove when fixed.
+ * Temporary workaround for b/224900226, where
+ * the temperature ADCs sometimes read zero.
+ */
+ if (ret == 0) {
+ LOG_ERR("Zero read on sensor %d, ignored", ch);
+ return -1;
+ }
+#endif
return ret;
}