summaryrefslogtreecommitdiff
path: root/baseboard/kukui/base_detect_kukui.c
diff options
context:
space:
mode:
Diffstat (limited to 'baseboard/kukui/base_detect_kukui.c')
-rw-r--r--baseboard/kukui/base_detect_kukui.c78
1 files changed, 29 insertions, 49 deletions
diff --git a/baseboard/kukui/base_detect_kukui.c b/baseboard/kukui/base_detect_kukui.c
index 3a6333b7cc..f72988543f 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,8 +95,32 @@ static void enable_power_supply(int enable)
static void base_detect_deferred(void);
DECLARE_DEFERRED(base_detect_deferred);
-static void base_set_device_type(enum kukui_pogo_device_type device_type)
+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);
+
switch (device_type) {
case DEVICE_TYPE_ERROR:
case DEVICE_TYPE_UNKNOWN:
@@ -107,21 +131,21 @@ static void base_set_device_type(enum kukui_pogo_device_type device_type)
case DEVICE_TYPE_DETACHED:
enable_power_supply(0);
enable_charge(0);
- base_set_state(0);
+ tablet_set_mode(1);
break;
#ifdef VARIANT_KUKUI_POGO_DOCK
case DEVICE_TYPE_DOCK:
enable_power_supply(0);
enable_charge(1);
- base_set_state(1);
+ tablet_set_mode(1);
break;
#endif
case DEVICE_TYPE_KEYBOARD:
enable_charge(0);
enable_power_supply(1);
- base_set_state(1);
+ tablet_set_mode(0);
break;
case DEVICE_TYPE_COUNT:
@@ -130,35 +154,6 @@ static void base_set_device_type(enum kukui_pogo_device_type device_type)
}
}
-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;
@@ -177,21 +172,6 @@ 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)
{