summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-05-06 10:08:52 -0600
committerJett Rink <jettrink@chromium.org>2019-05-22 20:40:00 +0000
commit2b27041c23a40c136adf2d6cd6a1d056a4bc7677 (patch)
treee8dede5737ae69cfff30251fd5d6793a68ee4f8f
parentf9fa865f87b8dc4bbeb9ea03073811e60f9badb0 (diff)
downloadchrome-ec-2b27041c23a40c136adf2d6cd6a1d056a4bc7677.tar.gz
tabletmode: ignore lid angle if hall sensor active
If the 360 degree hall sensor is active, then we should remain in tablet mode even if the lid angle says we are 1 degree since an angle of 360 could wrap around to 1 degree. Also ensure that tablet mode always gets initialized to the correct state at startup (by setting initial value to -1) BRANCH=R75 BUG=b:131785573,b:132178305 TEST=NB_MODE# on arcada does not flutter when the device is at 360 degrees with CL stack. Change-Id: I962a9c23205766080a65d741c6c425452d9de608 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1597189 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1625785
-rw-r--r--common/tablet_mode.c42
-rw-r--r--include/config.h6
-rw-r--r--include/tablet_mode.h9
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