From 540601885f0cd3c7be6d55c29b9f2eb22458079d Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 19 Oct 2017 14:24:48 +0800 Subject: poppy: If base ADC value is unclear, try reading it again If the base ADC value does not clearly indicate attach, reverse attach, or disconnect, read the ADC value again in 500ms. This time should be long enough that even if the ADC value is wrong, it would not use an inconsiderate amount of power. BRANCH=none BUG=b:67970530 TEST=Connect 6K and 30K resistors in parallel between DET and GND pin, EC detects an unclear 27 mV ADC value, and retries every 500ms until the 6K resistor is removed and a clear attach value is read (154 mV). TEST=Connect base in reverse, ADC value is around 475 mV, and ADC is not polled again. TEST=Disconnect base, ADC value is at maximum (2816 mV), and ADC is not polled again. Change-Id: I616114afc683608b853c18d0a081c6cd1e150c75 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/727790 Reviewed-by: Furquan Shaikh --- board/poppy/board.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'board') diff --git a/board/poppy/board.c b/board/poppy/board.c index 424e77b1b4..c3b45aaa2f 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -139,12 +139,14 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal) } #endif +/* Base detection and debouncing */ +#define BASE_DETECT_DEBOUNCE_US (20 * MSEC) + /* - * Base detection and debouncing - * - * TODO(b/35585396): Fine-tune these values. + * If the base status is unclear (i.e. not within expected ranges, read + * the ADC value again every 500ms. */ -#define BASE_DETECT_DEBOUNCE_US (20 * MSEC) +#define BASE_DETECT_RETRY_US (500 * MSEC) /* * rev0: Lid has 100K pull-up, base has 5.1K pull-down, so the ADC @@ -167,6 +169,9 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal) #define BASE_DETECT_REVERSE_MIN_MV 450 #define BASE_DETECT_REVERSE_MAX_MV 500 +/* Minimum ADC value to indicate base is disconnected for sure */ +#define BASE_DETECT_DISCONNECT_MIN_MV 1500 + /* * Base EC pulses detection pin for 500 us to signal out of band USB wake (that * can be used to wake system from deep S3). @@ -259,13 +264,15 @@ static void base_detect_deferred(void) CPRINTS("Sending event to AP"); host_set_single_event(EC_HOST_EVENT_KEY_PRESSED); } - } else { - /* - * TODO(b/35585396): Figure out what to do with - * other ADC values that do not clearly indicate base - * presence or absence. - */ + } else if ((v >= BASE_DETECT_REVERSE_MIN_MV && + v <= BASE_DETECT_REVERSE_MAX_MV) || + v >= BASE_DETECT_DISCONNECT_MIN_MV) { + /* TODO(b/35585396): Handle reverse connection separately. */ base_detect_change(BASE_DISCONNECTED); + } else { + /* Unclear base status, schedule again in a while. */ + hook_call_deferred(&base_detect_deferred_data, + BASE_DETECT_RETRY_US); } } -- cgit v1.2.1