diff options
-rw-r--r-- | common/tablet_mode.c | 42 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/tablet_mode.h | 9 |
3 files changed, 42 insertions, 15 deletions
diff --git a/common/tablet_mode.c b/common/tablet_mode.c index da2de38ad3..652756b665 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -14,14 +14,21 @@ #define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ## args) #define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ## args) -/* 1: in tablet mode. 0: otherwise */ -static int tablet_mode = 1; +/* 1: in tablet mode; 0: notebook mode; -1: uninitialized */ +static int tablet_mode = -1; +/* 1: hall sensor is reporting 360 degrees. */ +static int hall_sensor_at_360; + +/* + * 1: all calls to tablet_set_mode are ignored and tablet_mode if forced to 0 + * 0: all calls to tablet_set_mode are honored + */ static int disabled; int tablet_get_mode(void) { - return tablet_mode; + return !!tablet_mode; } void tablet_set_mode(int mode) @@ -34,15 +41,20 @@ void tablet_set_mode(int mode) return; } + if (hall_sensor_at_360 && !mode) { + CPRINTS("Ignoring tablet mode exit while hall sensor active."); + return; + } + tablet_mode = mode; CPRINTS("tablet mode %sabled", mode ? "en" : "dis"); hook_notify(HOOK_TABLET_MODE_CHANGE); +#ifdef CONFIG_HOSTCMD_EVENTS /* * When tablet mode changes, send an event to ACPI to retrieve * tablet mode value and send an event to the kernel. */ -#ifdef CONFIG_HOSTCMD_EVENTS host_set_single_event(EC_HOST_EVENT_MODE_CHANGE); #endif } @@ -54,7 +66,9 @@ void tablet_set_mode(int mode) #endif static void hall_sensor_interrupt_debounce(void) { - int flipped_360_mode = !gpio_get_level(HALL_SENSOR_GPIO_L); + hall_sensor_at_360 = IS_ENABLED(CONFIG_HALL_SENSOR_CUSTOM) + ? board_sensor_at_360() + : !gpio_get_level(HALL_SENSOR_GPIO_L); /* * 1. Peripherals are disabled only when lid reaches 360 position (It's @@ -69,15 +83,11 @@ static void hall_sensor_interrupt_debounce(void) * driver to clear it when lid goes into laptop zone. */ -#ifdef CONFIG_LID_ANGLE - if (flipped_360_mode) -#endif /* CONFIG_LID_ANGLE */ - tablet_set_mode(flipped_360_mode); + if (!IS_ENABLED(CONFIG_LID_ANGLE) || hall_sensor_at_360) + tablet_set_mode(hall_sensor_at_360); -#ifdef CONFIG_LID_ANGLE_UPDATE - if (flipped_360_mode) + if (IS_ENABLED(CONFIG_LID_ANGLE_UPDATE) && hall_sensor_at_360) lid_angle_peripheral_enable(0); -#endif /* CONFIG_LID_ANGLE_UPDATE */ } DECLARE_DEFERRED(hall_sensor_interrupt_debounce); @@ -87,7 +97,7 @@ DECLARE_DEFERRED(hall_sensor_interrupt_debounce); void hall_sensor_isr(enum gpio_signal signal) { hook_call_deferred(&hall_sensor_interrupt_debounce_data, - HALL_SENSOR_DEBOUNCE_US); + HALL_SENSOR_DEBOUNCE_US); } static void hall_sensor_init(void) @@ -97,8 +107,10 @@ static void hall_sensor_init(void) return; gpio_enable_interrupt(HALL_SENSOR_GPIO_L); - /* Ensure tablet mode is initialized according to the hardware state - * so that the cached state reflects reality. */ + /* + * Ensure tablet mode is initialized according to the hardware state + * so that the cached state reflects reality. + */ hall_sensor_interrupt_debounce(); } DECLARE_HOOK(HOOK_INIT, hall_sensor_init, HOOK_PRIO_DEFAULT); diff --git a/include/config.h b/include/config.h index e6d5f9fb82..e010636952 100644 --- a/include/config.h +++ b/include/config.h @@ -3067,6 +3067,12 @@ #undef CONFIG_HALL_SENSOR /* + * Board provides board_sensor_at_360 method instead of HALL_SENSOR_GPIO_L as + * the means for determining the state of the 360 hall sensor. + */ +#undef CONFIG_HALL_SENSOR_CUSTOM + +/* * Add a virtual switch to indicate when detachable device has * base attached. */ diff --git a/include/tablet_mode.h b/include/tablet_mode.h index 5edfb52f20..e4444aca1b 100644 --- a/include/tablet_mode.h +++ b/include/tablet_mode.h @@ -28,4 +28,13 @@ void hall_sensor_isr(enum gpio_signal signal); */ void hall_sensor_disable(void); +/* + * This must be defined when CONFIG_HALL_SENSOR_CUSTOM is defined. This allows + * a board to override the default behavior that determines if the 360 sensor is + * active: !gpio_get_level(HALL_SENSOR_GPIO_L). + * + * Returns 1 if the 360 sensor is active; otherwise 0. + */ +int board_sensor_at_360(void); + #endif |