summaryrefslogtreecommitdiff
path: root/board/trogdor/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/trogdor/board.c')
-rw-r--r--board/trogdor/board.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/board/trogdor/board.c b/board/trogdor/board.c
index 9dfb9ae3fb..a17599b21c 100644
--- a/board/trogdor/board.c
+++ b/board/trogdor/board.c
@@ -10,6 +10,7 @@
#include "charge_manager.h"
#include "charge_state.h"
#include "extpower.h"
+#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi_common.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
@@ -31,6 +32,7 @@
#include "system.h"
#include "shi_chip.h"
#include "switch.h"
+#include "tablet_mode.h"
#include "task.h"
#include "usbc_ocp.h"
#include "usbc_ppc.h"
@@ -521,8 +523,10 @@ uint16_t tcpc_get_alert_status(void)
/* Mutexes */
static struct mutex g_base_mutex;
+static struct mutex g_lid_mutex;
static struct bmi_drv_data_t g_bmi160_data;
+static struct accelgyro_saved_data_t g_bma255_data;
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t base_standard_ref = {
@@ -531,7 +535,39 @@ const mat33_fp_t base_standard_ref = {
{ 0, 0, FLOAT_TO_FP(-1)}
};
+static const mat33_fp_t lid_standard_ref = {
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA255,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma2x2_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bma255_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2, /* g, to support lid angle calculation. */
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
/*
* Note: bmi160: supports accelerometer and gyro sensor
* Requirement: accelerometer sensor must init before gyro sensor
@@ -556,6 +592,10 @@ struct motion_sensor_t motion_sensors[] = {
[SENSOR_CONFIG_EC_S0] = {
.odr = 10000 | ROUND_UP_FLAG,
},
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
},
},
[BASE_GYRO] = {
@@ -576,3 +616,23 @@ struct motion_sensor_t motion_sensors[] = {
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+#ifndef TEST_BUILD
+/* This callback disables keyboard when convertibles are fully open */
+void lid_angle_peripheral_enable(int enable)
+{
+ int chipset_in_s0 = chipset_in_state(CHIPSET_STATE_ON);
+
+ if (enable) {
+ keyboard_scan_enable(1, KB_SCAN_DISABLE_LID_ANGLE);
+ } else {
+ /*
+ * Ensure that the chipset is off before disabling the keyboard.
+ * When the chipset is on, the EC keeps the keyboard enabled and
+ * the AP decides whether to ignore input devices or not.
+ */
+ if (!chipset_in_s0)
+ keyboard_scan_enable(0, KB_SCAN_DISABLE_LID_ANGLE);
+ }
+}
+#endif