From 5e4df0a33de371076193e050d3234c5e67d66618 Mon Sep 17 00:00:00 2001 From: Andrew McRae Date: Wed, 16 Mar 2022 17:42:28 +1100 Subject: 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 Change-Id: Ifcbebf2ca9b9a336f10fe3659fd3452223474ed3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3528015 Reviewed-by: Peter Marheine Commit-Queue: Peter Marheine --- zephyr/projects/nissa/src/nivviks/board_config.c | 9 +++++++++ zephyr/shim/src/adc.c | 11 +++++++++++ 2 files changed, 20 insertions(+) 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 #include +#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; } -- cgit v1.2.1