diff options
author | Yilun Lin <yllin@chromium.org> | 2019-09-16 16:27:36 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-20 05:54:23 +0000 |
commit | ced60ee210e02d09c2cad2637cae913bd5083c7e (patch) | |
tree | 3157f3b1d657fe76f5cb5be6a4528b74221b19fa /baseboard/kukui | |
parent | 58ac5f86059f85e24036fd4933a024dadae28f25 (diff) | |
download | chrome-ec-ced60ee210e02d09c2cad2637cae913bd5083c7e.tar.gz |
Reland "baseboard/kukui: use BASE_STATE_SWITCH instead"
This is a reland of 92b3e86b23b59ebec3e59132cae2b32288fcf1b4,
fixing up the call to base_init that does not exist anymore.
Original change's description:
> 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>
BRANCH=kukui
BUG=b:140608847
BUG=b:141518464
TEST=see EC sends BASE_ATTACHED event when keyboard attach/detach
Cq-Depend: chromium:1844514
Change-Id: I609c8ac958f7d344d73f28934e2b1187a8d11f22
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1844653
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Commit-Queue: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'baseboard/kukui')
-rw-r--r-- | baseboard/kukui/base_detect_kukui.c | 77 | ||||
-rw-r--r-- | baseboard/kukui/baseboard.h | 6 |
2 files changed, 53 insertions, 30 deletions
diff --git a/baseboard/kukui/base_detect_kukui.c b/baseboard/kukui/base_detect_kukui.c index 12c0090a52..ba1ea001bd 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; @@ -186,6 +191,20 @@ static void pogo_chipset_shutdown(void) } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, pogo_chipset_shutdown, HOOK_PRIO_DEFAULT); +void base_force_state(int state) +{ + if (state != 1 && state != 0) { + CPRINTS("BD forced reset"); + pogo_chipset_startup(); + 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 |