summaryrefslogtreecommitdiff
path: root/board/pico
diff options
context:
space:
mode:
authorSue Chen <sue.chen@quanta.corp-partner.google.com>2021-07-30 10:14:11 +0800
committerCommit Bot <commit-bot@chromium.org>2021-08-02 08:29:21 +0000
commit1cbae5e8a9ff1a39e753b4ba58851fff71bba156 (patch)
tree3a89cf1ce02997787dec30e4536fe2e32f5db409 /board/pico
parent5fced4898423ff6b4bceeb73fd8da51b4f83b923 (diff)
downloadchrome-ec-1cbae5e8a9ff1a39e753b4ba58851fff71bba156.tar.gz
Pico: Support motion sensors
Lid Accel: KX022 BASE Accelgyro: BMI160 BUG=none BRANCH=icarus TEST=EC can read sensors' data and lig angle is correct. Signed-off-by: Sue Chen <sue.chen@quanta.corp-partner.google.com> Change-Id: I07743c86a3d133dd96e499f23150fd4f20340470 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3062062 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'board/pico')
-rw-r--r--board/pico/board.c110
-rw-r--r--board/pico/board.h32
-rw-r--r--board/pico/ec.tasklist1
-rw-r--r--board/pico/gpio.inc3
4 files changed, 137 insertions, 9 deletions
diff --git a/board/pico/board.c b/board/pico/board.c
index d094210c67..aba144b73c 100644
--- a/board/pico/board.c
+++ b/board/pico/board.c
@@ -14,6 +14,8 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "driver/accel_kionix.h"
+#include "driver/accelgyro_bmi_common.h"
#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/isl923x.h"
@@ -32,6 +34,7 @@
#include "registers.h"
#include "spi.h"
#include "system.h"
+#include "tablet_mode.h"
#include "task.h"
#include "tcpm/tcpm.h"
#include "timer.h"
@@ -46,6 +49,111 @@
#include "gpio_list.h"
+#ifndef VARIANT_KUKUI_NO_SENSORS
+/* Motion sensors */
+/* Mutexes */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+/* Rotation matrixes */
+static const mat33_fp_t lid_standard_ref = {
+ {FLOAT_TO_FP(1), 0, 0},
+ {0, FLOAT_TO_FP(-1), 0},
+ {0, 0, FLOAT_TO_FP(-1)}
+};
+
+static const mat33_fp_t base_standard_ref = {
+ {FLOAT_TO_FP(1), 0, 0},
+ {0, FLOAT_TO_FP(1), 0},
+ {0, 0, FLOAT_TO_FP(1)}
+};
+
+/* sensor private data */
+static struct kionix_accel_data g_kx022_data;
+static struct bmi_drv_data_t g_bmi160_data;
+
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_SENSORS,
+ .i2c_spi_addr_flags = KX022_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2, /* g, enough to calculate lid angle. */
+ .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
+ * DO NOT change the order of the following table.
+ */
+ [BASE_ACCEL] = {
+ .name = "Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSORS,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+ [BASE_GYRO] = {
+ .name = "Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSORS,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
+};
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+int board_sensor_at_360(void)
+{
+ return !gpio_get_level(GMR_TABLET_MODE_GPIO_L);
+}
+#endif /* !VARIANT_KUKUI_NO_SENSORS */
/*
* Map keyboard connector pins to EC GPIO pins for factory test.
* Pins mapped to {-1, -1} are skipped.
@@ -236,8 +344,10 @@ static void board_init(void)
gpio_set_level(GPIO_PMIC_FORCE_RESET_ODL, 1);
}
+#ifndef VARIANT_KUKUI_NO_SENSORS
/* Enable interrupts from BMI160 sensor. */
gpio_enable_interrupt(GPIO_ACCEL_INT_ODL);
+#endif /* VARIANT_KUKUI_NO_SENSORS */
/* Enable interrupt from PMIC. */
gpio_enable_interrupt(GPIO_PMIC_EC_RESETB);
diff --git a/board/pico/board.h b/board/pico/board.h
index e70fc7113d..ff02019f42 100644
--- a/board/pico/board.h
+++ b/board/pico/board.h
@@ -13,6 +13,10 @@
#define VARIANT_KUKUI_CHARGER_ISL9238
#define VARIANT_KUKUI_EC_IT81202
+#ifndef SECTION_IS_RW
+#define VARIANT_KUKUI_NO_SENSORS
+#endif /* SECTION_IS_RW */
+
#include "baseboard.h"
/* TODO: remove me once we fix IT83XX_ILM_BLOCK_SIZE out of space issue */
@@ -43,9 +47,26 @@
#define CONFIG_USB_MUX_IT5205
-#undef CONFIG_ACCEL_FIFO
-#undef CONFIG_ACCEL_FIFO_SIZE
-#undef CONFIG_ACCEL_FIFO_THRES
+/* Motion Sensors */
+#ifndef VARIANT_KUKUI_NO_SENSORS
+#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+#define CONFIG_ACCEL_KX022 /* Lid accel */
+#define CONFIG_ACCELGYRO_BMI160 /* Base accel */
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ALS
+#define CONFIG_CMD_ACCEL_INFO
+
+#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_UPDATE
+#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
+#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
+
+#define CONFIG_GMR_TABLET_MODE_CUSTOM
+#endif /* !VARIANT_KUKUI_NO_SENSORS */
/* I2C ports */
#define I2C_PORT_BC12 IT83XX_I2C_CH_C
@@ -63,11 +84,6 @@
#define CONFIG_LED_ONOFF_STATES
-#undef CONFIG_GMR_TABLET_MODE
-#undef GMR_TABLET_MODE_GPIO_L
-#undef CONFIG_TABLET_MODE
-#undef CONFIG_TABLET_MODE_SWITCH
-
#ifndef __ASSEMBLER__
enum adc_channel {
diff --git a/board/pico/ec.tasklist b/board/pico/ec.tasklist
index e8ad538bc2..5c272d04f4 100644
--- a/board/pico/ec.tasklist
+++ b/board/pico/ec.tasklist
@@ -11,6 +11,7 @@
TASK_ALWAYS(CHARGER, charger_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS_RW(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, 1024) \
TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, LARGER_TASK_STACK_SIZE) \
diff --git a/board/pico/gpio.inc b/board/pico/gpio.inc
index a3a097c17b..dc12c5ce3f 100644
--- a/board/pico/gpio.inc
+++ b/board/pico/gpio.inc
@@ -19,6 +19,8 @@ GPIO_INT(PMIC_EC_RESETB, PIN(F, 3), GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL
power_signal_interrupt)
GPIO_INT(WARM_RESET_REQ, PIN(D, 3), GPIO_INT_RISING | GPIO_PULL_DOWN | GPIO_SEL_1P8V,
chipset_reset_request_interrupt)
+GPIO_INT_RW(ACCEL_INT_ODL, PIN(J, 2), GPIO_INT_FALLING | GPIO_SEL_1P8V,
+ bmi160_interrupt)
GPIO_INT_RO(BOOTBLOCK_EN_L, PIN(J, 1), GPIO_INT_RISING | GPIO_SEL_1P8V,
emmc_ap_jump_to_bl)
GPIO_INT(SPI0_CS, PIN(M, 5), GPIO_INT_FALLING,
@@ -34,7 +36,6 @@ GPIO_INT(AP_EC_WATCHDOG_L, PIN(C, 7), GPIO_INT_FALLING | GPIO_SEL_1P8V,
GPIO_INT(UART1_RX, PIN(B, 0), GPIO_INT_FALLING,
uart_deepsleep_interrupt) /* UART_DEBUG_TX_EC_RX */
/* Unimplemented interrupts */
-GPIO(ACCEL_INT_ODL, PIN(J, 2), GPIO_INPUT)
GPIO(TABLET_MODE_L, PIN(J, 7), GPIO_INPUT)
GPIO(VOLUME_DOWN_L, PIN(D, 5), GPIO_INPUT)
GPIO(VOLUME_UP_L, PIN(D, 6), GPIO_INPUT)