summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonjoon Lee <woojoo.lee@samsung.com>2016-05-02 15:40:52 +0900
committerchrome-bot <chrome-bot@chromium.org>2016-05-12 20:13:53 -0700
commit849ccf7c91ef22c818896bb16c7fbc22c09cc637 (patch)
treefa70100507bb692d7aee63eced37c4e68c3a5862
parent7a12b8254146ee3e2fda69870814fe14f4498df9 (diff)
downloadchrome-ec-849ccf7c91ef22c818896bb16c7fbc22c09cc637.tar.gz
kevin: Add support bmi160 sensor
BMI168 is twins sensor with BMI160. Adding defines, drv. BUG=chrome-os-partner:52844 TEST="accelread 0" is working on kevin Change-Id: I8335ea4a766ae88e049791b9231ab752486be9d4 Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/341650 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/kevin/board.c97
-rw-r--r--board/kevin/board.h18
-rw-r--r--board/kevin/ec.tasklist1
3 files changed, 112 insertions, 4 deletions
diff --git a/board/kevin/board.c b/board/kevin/board.c
index 037707b95b..1e4cb24a77 100644
--- a/board/kevin/board.c
+++ b/board/kevin/board.c
@@ -13,6 +13,8 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "ec_commands.h"
+#include "driver/accelgyro_bmi160.h"
#include "driver/charger/bd99955.h"
#include "driver/tcpm/fusb302.h"
#include "extpower.h"
@@ -30,6 +32,7 @@
#include "shi_chip.h"
#include "spi.h"
#include "switch.h"
+#include "task.h"
#include "timer.h"
#include "thermal.h"
#include "usb_charge.h"
@@ -324,3 +327,97 @@ static void overtemp_interrupt_disable(void)
}
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, overtemp_interrupt_disable,
HOOK_PRIO_DEFAULT);
+
+/* Motion sensors */
+#ifdef HAS_TASK_MOTIONSENSE
+/* Mutexes */
+static struct mutex g_base_mutex;
+
+/* Matrix to rotate accelrator into standard reference frame */
+const matrix_3x3_t base_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[] = {
+ /*
+ * Note: bmi160: supports accelerometer and gyro sensor
+ * Requirement: accelerometer sensor must init before gyro sensor
+ * DO NOT change the order of the following table.
+ */
+ {.name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .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 = CONFIG_SPI_ACCEL_PORT,
+ .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .rot_standard_ref = NULL, /* Identity matrix. */
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default use EC settings */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
+ },
+
+ {.name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .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 = CONFIG_SPI_ACCEL_PORT,
+ .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = NULL, /* Identity Matrix. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC does not need in S0 */
+ /* TODO : Interrupt driven? */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ },
+ },
+};
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+#endif /* defined(HAS_TASK_MOTIONSENSE) */
diff --git a/board/kevin/board.h b/board/kevin/board.h
index 18c801ec99..3c71b52949 100644
--- a/board/kevin/board.h
+++ b/board/kevin/board.h
@@ -12,12 +12,16 @@
#define CONFIG_ADC
#define CONFIG_CHIPSET_RK3399
#define CONFIG_HOSTCMD_SPS
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
#define CONFIG_POWER_COMMON
#define CONFIG_PWM
#define CONFIG_PWM_DISPLIGHT
#ifdef BOARD_KEVIN
#define CONFIG_LED_COMMON
#endif
+#define CONFIG_SPI
+#define CONFIG_SPI_MASTER
#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands for testing */
@@ -38,15 +42,11 @@
#define CONFIG_BOARD_SPECIFIC_VERSION
#define CONFIG_BUTTON_COUNT 2
#define CONFIG_FLASH_SIZE 0x00080000 /* 512KB spi flash */
-#define CONFIG_I2C
-#define CONFIG_I2C_MASTER
#define CONFIG_KEYBOARD_BOARD_CONFIG
#define CONFIG_KEYBOARD_COL2_INVERTED
#define CONFIG_KEYBOARD_PROTOCOL_MKBP /* Instead of 8042 protocol of keyboard */
#define CONFIG_LTO
#define CONFIG_POWER_BUTTON
-#define CONFIG_SPI
-#define CONFIG_SPI_MASTER
#define CONFIG_VBOOT_HASH
#define CONFIG_CHARGER
@@ -54,6 +54,13 @@
#define CONFIG_CHARGER_INPUT_CURRENT 512
#define CONFIG_CHARGER_V2
+/* Motion Sensors */
+#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCEL_INTRRUPTS
+#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_SENSOR_BASE 0
+#define CONFIG_LID_ANGLE_SENSOR_LID 2
+
/* USB PD config */
#define CONFIG_CHARGE_MANAGER
#define CONFIG_USB_POWER_DELIVERY
@@ -87,6 +94,8 @@
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* Optional features for test commands */
+#define CONFIG_CMD_ACCELS
+#define CONFIG_CMD_ACCEL_INFO
#define CONFIG_CMD_TASKREADY
#define CONFIG_CMD_STACKOVERFLOW
#define CONFIG_CMD_JUMPTAGS
@@ -109,6 +118,7 @@
#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0
#define I2C_PORT_TCPC1 NPCX_I2C_PORT0_1
+#define I2C_PORT_ACCEL NPCX_I2C_PORT1
#define I2C_PORT_CHARGER NPCX_I2C_PORT2
#define I2C_PORT_BATTERY NPCX_I2C_PORT3
diff --git a/board/kevin/ec.tasklist b/board/kevin/ec.tasklist
index 4eec31e7f1..0f91c4f39a 100644
--- a/board/kevin/ec.tasklist
+++ b/board/kevin/ec.tasklist
@@ -20,6 +20,7 @@
TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \