From 62c9985607287f4994fb6657a65a0075ae54756e Mon Sep 17 00:00:00 2001 From: Yilun Lin Date: Mon, 11 Nov 2019 14:42:34 +0800 Subject: baseboard/kukui: fix pogo extpower status On krane, POGO provide extpower when only connects to a dock, so we should check if it's connecting to a dock, rather than checking POGO_VBUS_PRESENT only. TEST=see battery LED is off when connects to keyboard, and LED on when connets to a USB-C charger. BUG=b:144137508 BRANCH=kukui Change-Id: Iab38590780b1e86149287fb9985c8ffa625b016f Signed-off-by: Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1907670 Reviewed-by: Nicolas Boichat --- baseboard/kukui/base_detect_kukui.c | 19 +++++++++++++++---- baseboard/kukui/baseboard.h | 4 ++++ board/kukui/board.c | 9 ++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/baseboard/kukui/base_detect_kukui.c b/baseboard/kukui/base_detect_kukui.c index 0d5bc46b03..ac7d9f7616 100644 --- a/baseboard/kukui/base_detect_kukui.c +++ b/baseboard/kukui/base_detect_kukui.c @@ -50,6 +50,17 @@ struct { BUILD_ASSERT(ARRAY_SIZE(pogo_detect_table) == DEVICE_TYPE_COUNT); static uint64_t base_detect_debounce_time; +static enum kukui_pogo_device_type pogo_type; + +int kukui_pogo_extpower_present(void) +{ +#ifdef VARIANT_KUKUI_POGO_DOCK + return pogo_type == DEVICE_TYPE_DOCK && + gpio_get_level(GPIO_POGO_VBUS_PRESENT); +#else + return 0; +#endif +} static enum kukui_pogo_device_type get_device_type(int mv) { @@ -134,7 +145,6 @@ static void base_detect_deferred(void) { uint64_t time_now = get_time().val; int mv; - enum kukui_pogo_device_type device_type; if (base_detect_debounce_time > time_now) { hook_call_deferred(&base_detect_deferred_data, @@ -153,10 +163,10 @@ static void base_detect_deferred(void) gpio_set_flags(GPIO_POGO_ADC_INT_L, GPIO_INT_BOTH); gpio_enable_interrupt(GPIO_POGO_ADC_INT_L); - device_type = get_device_type(mv); - CPRINTS("POGO: adc=%d, device_type=%d", mv, device_type); + pogo_type = get_device_type(mv); + CPRINTS("POGO: adc=%d, type=%d", mv, pogo_type); - base_set_device_type(device_type); + base_set_device_type(pogo_type); } void pogo_adc_interrupt(enum gpio_signal signal) @@ -199,6 +209,7 @@ void base_force_state(int state) } gpio_disable_interrupt(GPIO_POGO_ADC_INT_L); + pogo_type = (state == 1 ? DEVICE_TYPE_KEYBOARD : DEVICE_TYPE_DETACHED); base_set_device_type(state == 1 ? DEVICE_TYPE_KEYBOARD : DEVICE_TYPE_DETACHED); CPRINTS("BD forced %sconnected", state == 1 ? "" : "dis"); diff --git a/baseboard/kukui/baseboard.h b/baseboard/kukui/baseboard.h index 43e95fe13f..af95ebba35 100644 --- a/baseboard/kukui/baseboard.h +++ b/baseboard/kukui/baseboard.h @@ -249,6 +249,10 @@ #ifdef VARIANT_KUKUI_DP_MUX_GPIO void board_set_dp_mux_control(int output_enable, int polarity); #endif /* VARIANT_KUKUI_DP_MUX_GPIO */ + +/* If POGO pin is providing power. */ +int kukui_pogo_extpower_present(void); + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BASEBOARD_H */ diff --git a/board/kukui/board.c b/board/kukui/board.c index 08463539cf..f388dca751 100644 --- a/board/kukui/board.c +++ b/board/kukui/board.c @@ -217,6 +217,13 @@ int board_discharge_on_ac(int enable) return charger_discharge_on_ac(enable); } +#ifndef VARIANT_KUKUI_POGO_KEYBOARD +int kukui_pogo_extpower_present(void) +{ + return 0; +} +#endif + int extpower_is_present(void) { /* @@ -230,7 +237,7 @@ int extpower_is_present(void) else usb_c_extpower_present = tcpm_get_vbus_level(CHARGE_PORT_USB_C); - return usb_c_extpower_present || gpio_get_level(GPIO_POGO_VBUS_PRESENT); + return usb_c_extpower_present || kukui_pogo_extpower_present(); } int pd_snk_is_vbus_provided(int port) -- cgit v1.2.1