summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2016-10-21 16:35:12 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-11-08 17:11:28 -0800
commit9b67ffcd527c6244a9f1946072f40e8e9fd9b940 (patch)
tree34b363bfdbe8a74123724b7cf6cd44a417e91376
parent8bb2d9fbf0d0a8d6810a9f08dd0437cfa3745db2 (diff)
downloadchrome-ec-9b67ffcd527c6244a9f1946072f40e8e9fd9b940.tar.gz
common: Add tablet_mode API
Simple API to set/get the tablet mode. It can be set via lid angle calculation or if a board has a dedicated HAL sensor/GPIO. Merged from glados branch, add MKBP switch support. BUG=chromium:606718 BRANCH=gru TEST=Check with Cave that both mode works. Reviewed-on: https://chromium-review.googlesource.com/402089 Reviewed-by: Shawn N <shawnn@chromium.org> (cherry picked from commit c940f36ceabcf2425284001298f03ebdb4c3079e) Change-Id: I2ee5130f3e0a1307ec3ea543f7a32d66bc32b31d Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/404915 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--board/kevin/board.h1
-rw-r--r--common/acpi.c3
-rw-r--r--common/build.mk1
-rw-r--r--common/keyboard_mkbp.c5
-rw-r--r--common/motion_lid.c15
-rw-r--r--common/motion_sense.c11
-rw-r--r--common/tablet_mode.c18
-rw-r--r--include/config.h5
-rw-r--r--include/motion_lid.h6
-rw-r--r--include/tablet_mode.h12
-rw-r--r--test/test_config.h1
11 files changed, 49 insertions, 29 deletions
diff --git a/board/kevin/board.h b/board/kevin/board.h
index 5d14aad4dd..fc550fd7c1 100644
--- a/board/kevin/board.h
+++ b/board/kevin/board.h
@@ -103,6 +103,7 @@
((1 << LID_ACCEL) | (1 << BASE_BARO))
#endif
+#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
/* USB PD config */
diff --git a/common/acpi.c b/common/acpi.c
index f73dfd2db5..d9815100e1 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -11,6 +11,7 @@
#include "host_command.h"
#include "lpc.h"
#include "ec_commands.h"
+#include "tablet_mode.h"
#include "pwm.h"
#include "timer.h"
#include "util.h"
@@ -170,7 +171,7 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
#ifdef CONFIG_DPTF_DEVICE_ORIENTATION
case EC_ACPI_MEM_DEVICE_ORIENTATION:
- result = board_get_device_orientation();
+ result = tablet_get_mode();
break;
#endif
diff --git a/common/build.mk b/common/build.mk
index a97e789ddd..d835badad9 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -84,6 +84,7 @@ common-$(CONFIG_SPI_FLASH)+=spi_flash.o spi_flash_reg.o
common-$(CONFIG_SPI_NOR)+=spi_nor.o
common-$(CONFIG_SWITCH)+=switch.o
common-$(CONFIG_SW_CRC)+=crc.o
+common-$(CONFIG_TABLET_MODE)+=tablet_mode.o
common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
common-$(CONFIG_THROTTLE_AP)+=thermal.o throttle_ap.o
common-$(CONFIG_TPM_I2CS)+=i2cs_tpm.o
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c
index 85e9a7b106..e687bf2966 100644
--- a/common/keyboard_mkbp.c
+++ b/common/keyboard_mkbp.c
@@ -22,9 +22,9 @@
#include "keyboard_test.h"
#include "lid_switch.h"
#include "mkbp_event.h"
-#include "motion_lid.h"
#include "power_button.h"
#include "system.h"
+#include "tablet_mode.h"
#include "task.h"
#include "timer.h"
#include "util.h"
@@ -222,8 +222,7 @@ DECLARE_HOOK(HOOK_INIT, mkbp_lid_change, HOOK_PRIO_INIT_LID+1);
#ifdef CONFIG_TABLET_MODE_SWITCH
static void mkbp_tablet_mode_change(void)
{
- mkbp_update_switches(EC_MKBP_TABLET_MODE,
- motion_lid_in_tablet_mode());
+ mkbp_update_switches(EC_MKBP_TABLET_MODE, tablet_get_mode());
}
DECLARE_HOOK(HOOK_TABLET_MODE_CHANGE, mkbp_tablet_mode_change, HOOK_PRIO_LAST);
DECLARE_HOOK(HOOK_INIT, mkbp_tablet_mode_change, HOOK_PRIO_INIT_LID+1);
diff --git a/common/motion_lid.c b/common/motion_lid.c
index 3f68480484..3209492a65 100644
--- a/common/motion_lid.c
+++ b/common/motion_lid.c
@@ -17,6 +17,7 @@
#include "motion_lid.h"
#include "motion_sense.h"
#include "power.h"
+#include "tablet_mode.h"
#include "timer.h"
#include "task.h"
#include "util.h"
@@ -57,7 +58,6 @@
#define TABLET_ZONE_LID_ANGLE FLOAT_TO_FP(300)
#define LAPTOP_ZONE_LID_ANGLE FLOAT_TO_FP(240)
-static int tablet_mode = 1;
#endif
#ifdef CONFIG_LID_ANGLE_INVALID_CHECK
@@ -148,7 +148,7 @@ static int calculate_lid_angle(const vector_3_t base, const vector_3_t lid,
fp_t denominator;
int reliable = 1;
#ifdef CONFIG_LID_ANGLE_TABLET_MODE
- int new_tablet_mode = tablet_mode;
+ int new_tablet_mode = tablet_get_mode();
#endif
/*
@@ -234,8 +234,8 @@ static int calculate_lid_angle(const vector_3_t base, const vector_3_t lid,
new_tablet_mode = 1;
else if (last_lid_angle_fp < LAPTOP_ZONE_LID_ANGLE)
new_tablet_mode = 0;
- if (tablet_mode != new_tablet_mode) {
- tablet_mode = new_tablet_mode;
+ if (tablet_get_mode() != new_tablet_mode) {
+ tablet_set_mode(new_tablet_mode);
hook_notify(HOOK_TABLET_MODE_CHANGE);
}
#endif /* CONFIG_LID_ANGLE_TABLET_MODE */
@@ -283,13 +283,6 @@ void motion_lid_calc(void)
#endif
}
-#ifdef CONFIG_LID_ANGLE_TABLET_MODE
-int motion_lid_in_tablet_mode(void)
-{
- return tablet_mode;
-}
-#endif
-
/*****************************************************************************/
/* Host commands */
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 65cb7de93d..8c6a8516d9 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -22,6 +22,7 @@
#include "motion_lid.h"
#include "power.h"
#include "queue.h"
+#include "tablet_mode.h"
#include "timer.h"
#include "task.h"
#include "util.h"
@@ -127,15 +128,9 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
motion_sense_insert_timestamp();
wake_up_needed = 1;
}
-#ifdef CONFIG_LID_ANGLE_TABLET_MODE
- data->flags |= (motion_lid_in_tablet_mode() ?
+#ifdef CONFIG_TABLET_MODE
+ data->flags |= (tablet_get_mode() ?
MOTIONSENSE_SENSOR_FLAG_TABLET_MODE : 0);
-#elif defined(CONFIG_DPTF_DEVICE_ORIENTATION)
- /*
- * TODO(gwendal): When other method finding tablet mode are used.
- * define them here.
- */
-#error "Need to set we are in tablet mode"
#endif
mutex_lock(&g_sensor_mutex);
queue_add_unit(&motion_sense_fifo, data);
diff --git a/common/tablet_mode.c b/common/tablet_mode.c
new file mode 100644
index 0000000000..c2937250da
--- /dev/null
+++ b/common/tablet_mode.c
@@ -0,0 +1,18 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Return 1 if in tablet mode, 0 otherwise */
+static int tablet_mode = 1;
+
+int tablet_get_mode(void)
+{
+ return tablet_mode;
+}
+
+void tablet_set_mode(int mode)
+{
+ tablet_mode = mode;
+}
+
diff --git a/include/config.h b/include/config.h
index 797340ede3..5cc38a6c14 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1819,6 +1819,11 @@
#undef CONFIG_SYSTEM_UNLOCKED
/*
+ * Device can be a tablet as well as a clamshell.
+ */
+#undef CONFIG_TABLET_MODE
+
+/*
* Add a virtual switch to indicate when we are in tablet mode.
*/
#undef CONFIG_TABLET_MODE_SWITCH
diff --git a/include/motion_lid.h b/include/motion_lid.h
index 405d5e5e5d..155c7735c9 100644
--- a/include/motion_lid.h
+++ b/include/motion_lid.h
@@ -46,12 +46,6 @@ int host_cmd_motion_lid(struct host_cmd_handler_args *args);
void motion_lid_calc(void);
-#ifdef CONFIG_LID_ANGLE_TABLET_MODE
-int motion_lid_in_tablet_mode(void);
-#else
-static inline int motion_lid_in_tablet_mode(void) { return 0; }
-#endif
-
#endif /* __CROS_EC_MOTION_LID_H */
diff --git a/include/tablet_mode.h b/include/tablet_mode.h
new file mode 100644
index 0000000000..6f4ee95e1e
--- /dev/null
+++ b/include/tablet_mode.h
@@ -0,0 +1,12 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Header for tablet_mode.c */
+
+/* Return 1 if in tablet mode, 0 otherwise */
+int tablet_get_mode(void);
+void tablet_set_mode(int mode);
+
+
diff --git a/test/test_config.h b/test/test_config.h
index 371303b4cb..0cfd7c0b83 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -48,6 +48,7 @@
#define CONFIG_LID_ANGLE_TABLET_MODE
#define CONFIG_LID_ANGLE_SENSOR_BASE 0
#define CONFIG_LID_ANGLE_SENSOR_LID 1
+#define CONFIG_TABLET_MODE
#endif
#ifdef TEST_SBS_CHARGING