From 5754434287895683c4d197092eb120019ef12116 Mon Sep 17 00:00:00 2001 From: Dino Li Date: Tue, 22 Sep 2020 11:38:17 +0800 Subject: it83xx/adc: adjust ADC read timeout to 1ms. Voltage comparator has about 73us conversion time, and ADC read channel has about 122 us conversion time. ADC engine will convert each channel at a time (comparators and ADC read channel) and current timeout setting is 248us, so we might have a chance to trigger timeout if converting two comparators while EC starts ADC read channel. This change increased timeout to 1ms. BUG=b:164256608 BRANCH=none TEST=Verified that running 'ectool temps all' without error on drawcia x200. Change-Id: I803d3065a75adaee673a9724ec4fc2fd73da0c48 Signed-off-by: Dino Li Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2423663 Reviewed-by: Aseda Aboagye --- chip/it83xx/adc.c | 13 +++++++++++++ chip/it83xx/adc_chip.h | 6 +++--- chip/it83xx/clock.c | 4 ---- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'chip') diff --git a/chip/it83xx/adc.c b/chip/it83xx/adc.c index ec662b0490..f8a113beab 100644 --- a/chip/it83xx/adc.c +++ b/chip/it83xx/adc.c @@ -13,10 +13,13 @@ #include "gpio.h" #include "hooks.h" #include "registers.h" +#include "system.h" #include "task.h" #include "timer.h" #include "util.h" +#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) + /* Global variables */ static struct mutex adc_lock; static int adc_init_done; @@ -135,6 +138,7 @@ int adc_read_channel(enum adc_channel ch) mutex_lock(&adc_lock); + disable_sleep(SLEEP_MASK_ADC); task_waiting = task_get_current(); adc_ch = adc_channels[ch].channel; adc_enable_channel(adc_ch); @@ -162,7 +166,16 @@ int adc_read_channel(enum adc_channel ch) valid = 1; } } + + if (!valid) { + CPRINTS("ADC failed to read!!! (regs=%x, %x, ch=%d, evt=%x)", + IT83XX_ADC_ADCDVSTS, + IT83XX_ADC_ADCDVSTS2, + adc_ch, events); + } + adc_disable_channel(adc_ch); + enable_sleep(SLEEP_MASK_ADC); mutex_unlock(&adc_lock); diff --git a/chip/it83xx/adc_chip.h b/chip/it83xx/adc_chip.h index f843dca996..23cc68fb34 100644 --- a/chip/it83xx/adc_chip.h +++ b/chip/it83xx/adc_chip.h @@ -13,11 +13,11 @@ /* * Maximum time we allow for an ADC conversion. * NOTE: - * This setting must be less than "SLEEP_SET_HTIMER_DELAY_USEC" in clock.c - * or adding a sleep mask to prevent going in to deep sleep while ADC + * Because this setting greater than "SLEEP_SET_HTIMER_DELAY_USEC" in clock.c, + * so we enabled sleep mask to prevent going in to deep sleep while ADC * converting. */ -#define ADC_TIMEOUT_US 248 +#define ADC_TIMEOUT_US MSEC /* Minimum and maximum values returned by adc_read_channel(). */ #define ADC_READ_MIN 0 diff --git a/chip/it83xx/clock.c b/chip/it83xx/clock.c index 7c3bf25844..72b2191c2d 100644 --- a/chip/it83xx/clock.c +++ b/chip/it83xx/clock.c @@ -29,10 +29,6 @@ #define SLEEP_SET_HTIMER_DELAY_USEC 250 #define SLEEP_FTIMER_SKIP_USEC (HOOK_TICK_INTERVAL * 2) -#ifdef CONFIG_ADC -BUILD_ASSERT(ADC_TIMEOUT_US < SLEEP_SET_HTIMER_DELAY_USEC); -#endif - static timestamp_t sleep_mode_t0; static timestamp_t sleep_mode_t1; static int idle_doze_cnt; -- cgit v1.2.1