diff options
author | Yilun Lin <yllin@chromium.org> | 2019-09-16 16:27:36 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-18 05:03:22 +0000 |
commit | 92b3e86b23b59ebec3e59132cae2b32288fcf1b4 (patch) | |
tree | 44d25039dc227e29761dee9d48142622a141a175 /baseboard | |
parent | fb041cc3ac80cbf7b3fd06a52eee465912ffa076 (diff) | |
download | chrome-ec-92b3e86b23b59ebec3e59132cae2b32288fcf1b4.tar.gz |
baseboard/kukui: use BASE_STATE_SWITCH instead
tablet mode will also depend on BASE_ATTACHED_SWITCH.
TEST=see EC sends BASE_ATTACHED event when keyboard attach/detach
BUG=b:140608847
BRANCH=none
Change-Id: Ib7d9bd0e8cf0efb5d0a3808f4649e0d9eb69b6d8
Signed-off-by: Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1806178
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'baseboard')
-rw-r--r-- | baseboard/kukui/base_detect_kukui.c | 78 | ||||
-rw-r--r-- | baseboard/kukui/baseboard.h | 6 |
2 files changed, 54 insertions, 30 deletions
diff --git a/baseboard/kukui/base_detect_kukui.c b/baseboard/kukui/base_detect_kukui.c index f72988543f..3a6333b7cc 100644 --- a/baseboard/kukui/base_detect_kukui.c +++ b/baseboard/kukui/base_detect_kukui.c @@ -4,12 +4,12 @@ */ #include "adc.h" +#include "base_state.h" #include "board.h" #include "charge_manager.h" #include "console.h" #include "gpio.h" #include "hooks.h" -#include "tablet_mode.h" #include "timer.h" #include "usb_pd.h" #include "util.h" @@ -95,32 +95,8 @@ static void enable_power_supply(int enable) static void base_detect_deferred(void); DECLARE_DEFERRED(base_detect_deferred); -static void base_detect_deferred(void) +static void base_set_device_type(enum kukui_pogo_device_type device_type) { - 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, - base_detect_debounce_time - time_now); - return; - } - - /* - * Disable interrupt first to prevent it triggered by value - * changed from 1 to disabled state(=0). - */ - gpio_disable_interrupt(GPIO_POGO_ADC_INT_L); - gpio_set_flags(GPIO_POGO_ADC_INT_L, GPIO_ANALOG); - mv = adc_read_channel(ADC_POGO_ADC_INT_L); - /* restore the pin function */ - 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); - switch (device_type) { case DEVICE_TYPE_ERROR: case DEVICE_TYPE_UNKNOWN: @@ -131,21 +107,21 @@ static void base_detect_deferred(void) case DEVICE_TYPE_DETACHED: enable_power_supply(0); enable_charge(0); - tablet_set_mode(1); + base_set_state(0); break; #ifdef VARIANT_KUKUI_POGO_DOCK case DEVICE_TYPE_DOCK: enable_power_supply(0); enable_charge(1); - tablet_set_mode(1); + base_set_state(1); break; #endif case DEVICE_TYPE_KEYBOARD: enable_charge(0); enable_power_supply(1); - tablet_set_mode(0); + base_set_state(1); break; case DEVICE_TYPE_COUNT: @@ -154,6 +130,35 @@ static void base_detect_deferred(void) } } +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, + base_detect_debounce_time - time_now); + return; + } + + /* + * Disable interrupt first to prevent it triggered by value + * changed from 1 to disabled state(=0). + */ + gpio_disable_interrupt(GPIO_POGO_ADC_INT_L); + gpio_set_flags(GPIO_POGO_ADC_INT_L, GPIO_ANALOG); + mv = adc_read_channel(ADC_POGO_ADC_INT_L); + /* restore the pin function */ + 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); + + base_set_device_type(device_type); +} + void pogo_adc_interrupt(enum gpio_signal signal) { uint64_t time_now = get_time().val; @@ -172,6 +177,21 @@ static void base_init(void) } DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_INIT_ADC + 1); +void base_force_state(int state) +{ + if (state != 1 && state != 0) { + gpio_enable_interrupt(GPIO_POGO_ADC_INT_L); + base_init(); + CPRINTS("BD forced reset"); + return; + } + + gpio_disable_interrupt(GPIO_POGO_ADC_INT_L); + base_set_device_type(state == 1 ? DEVICE_TYPE_KEYBOARD : + DEVICE_TYPE_DETACHED); + CPRINTS("BD forced %sconnected", state == 1 ? "" : "dis"); +} + #ifdef VARIANT_KUKUI_POGO_DOCK static void board_pogo_charge_init(void) { diff --git a/baseboard/kukui/baseboard.h b/baseboard/kukui/baseboard.h index 3bd6862426..4b6467462c 100644 --- a/baseboard/kukui/baseboard.h +++ b/baseboard/kukui/baseboard.h @@ -71,6 +71,11 @@ #define DEDICATED_CHARGE_PORT 1 #endif /* VARIANT_KUKUI_POGO_DOCK */ +#ifdef VARIANT_KUKUI_POGO_KEYBOARD +#define CONFIG_DETACHABLE_BASE +#define CONFIG_BASE_ATTACHED_SWITCH +#endif + /* * Define this flag if board controls dp mux via gpio pins USB_C0_DP_OE_L and * USB_C0_DP_POLARITY. @@ -153,7 +158,6 @@ /* To be able to indicate the device is in tablet mode. */ #define CONFIG_TABLET_MODE -#define CONFIG_TABLET_MODE_SWITCH #define GPIO_LID_OPEN GPIO_HALL_INT_L #ifndef VARIANT_KUKUI_NO_SENSORS |