summaryrefslogtreecommitdiff
path: root/board/waddledoo
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-01-09 17:10:21 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-14 18:58:04 +0000
commita3d44f8770d37266122f7c12515ae9932713db5a (patch)
tree96adf8aac16c669c1c593e1bbed87b1936b8441c /board/waddledoo
parente57217a25040bfdb2cb3b6ba8a6e672c157478ed (diff)
downloadchrome-ec-a3d44f8770d37266122f7c12515ae9932713db5a.tar.gz
Waddledoo: Add sensor support
Waddledoo is using the BMI160 as a base accel and the BMA253 lid accel, which is compatible with the current bma2x2 driver. BUG=b:147258603 BRANCH=none TEST=builds Change-Id: Id76e826f11154f8b687021713a2bf176bd82fef4 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1993952 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/waddledoo')
-rw-r--r--board/waddledoo/board.c115
-rw-r--r--board/waddledoo/board.h41
-rw-r--r--board/waddledoo/ec.tasklist1
-rw-r--r--board/waddledoo/gpio.inc8
4 files changed, 165 insertions, 0 deletions
diff --git a/board/waddledoo/board.c b/board/waddledoo/board.c
index 8c5a865035..8ef3330887 100644
--- a/board/waddledoo/board.c
+++ b/board/waddledoo/board.c
@@ -9,16 +9,112 @@
#include "button.h"
#include "common.h"
#include "compile_time_macros.h"
+#include "driver/accel_bma2x2.h"
+#include "driver/accelgyro_bmi160.h"
+#include "driver/sync.h"
#include "extpower.h"
#include "gpio.h"
#include "i2c.h"
#include "lid_switch.h"
+#include "motion_sense.h"
#include "power.h"
#include "power_button.h"
#include "switch.h"
+#include "tablet_mode.h"
+#include "task.h"
#include "gpio_list.h"
+/* Sensors */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+static struct accelgyro_saved_data_t g_bma253_data;
+static struct bmi160_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_BMA255,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma2x2_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bma253_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
+ .rot_standard_ref = NULL,
+ .default_range = 2,
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_ACCEL_MAX_FREQ,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+ [BASE_ACCEL] = {
+ .name = "Base 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_SENSOR,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .rot_standard_ref = NULL,
+ .default_range = 4,
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+ [BASE_GYRO] = {
+ .name = "Base 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_SENSOR,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = NULL,
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
+ },
+ [VSYNC] = {
+ .name = "Camera VSYNC",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_GPIO,
+ .type = MOTIONSENSE_TYPE_SYNC,
+ .location = MOTIONSENSE_LOC_CAMERA,
+ .drv = &sync_drv,
+ .default_range = 0,
+ .min_frequency = 0,
+ .max_frequency = 1,
+ },
+};
+
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+
int extpower_is_present(void)
{
/*
@@ -27,3 +123,22 @@ int extpower_is_present(void)
*/
return 1;
}
+
+#ifndef TEST_BUILD
+/* This callback disables keyboard when convertibles are fully open */
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in tablet position via other sensors,
+ * ignore the lid angle, which might be faulty then
+ * disable keyboard.
+ */
+ if (tablet_get_mode())
+ enable = 0;
+ /*
+ * TODO(b/147453459): Waddledoo: add keyboard support
+ * disable keyboard here when AP is off
+ *
+ */
+}
+#endif
diff --git a/board/waddledoo/board.h b/board/waddledoo/board.h
index f7a595d545..f19f92133e 100644
--- a/board/waddledoo/board.h
+++ b/board/waddledoo/board.h
@@ -18,8 +18,41 @@
#define I2C_PORT_USB_C0 NPCX_I2C_PORT1_0
#define I2C_PORT_SUB_USB_C1 NPCX_I2C_PORT2_0
+#define I2C_PORT_ACCEL I2C_PORT_SENSOR
+
#define I2C_ADDR_EEPROM_FLAGS 0x50 /* 7b address */
+/* Sensors */
+#define CONFIG_CMD_ACCELS
+#define CONFIG_CMD_ACCEL_INFO
+
+#define CONFIG_ACCEL_BMA255 /* Lid accel */
+#define CONFIG_ACCELGYRO_BMI160 /* Base accel */
+#define CONFIG_SYNC /* Camera VSYNC */
+
+/* Lid operates in forced mode, base in FIFO */
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
+#define CONFIG_ACCEL_FIFO
+#define CONFIG_ACCEL_FIFO_SIZE 256 /* Must be a power of 2 */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
+
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_SYNC_INT_EVENT TASK_EVENT_MOTION_SENSOR_INTERRUPT(VSYNC)
+
+#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_TABLET_MODE
+#define CONFIG_TABLET_MODE_SWITCH
+#define CONFIG_GMR_TABLET_MODE
+
+#define CONFIG_MKBP_EVENT
+#define CONFIG_MKBP_USE_GPIO
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
@@ -34,5 +67,13 @@ enum adc_channel {
ADC_CH_COUNT
};
+enum sensor_id {
+ LID_ACCEL,
+ BASE_ACCEL,
+ BASE_GYRO,
+ VSYNC,
+ SENSOR_COUNT
+};
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/waddledoo/ec.tasklist b/board/waddledoo/ec.tasklist
index 57bcccc28f..2bc06ded0c 100644
--- a/board/waddledoo/ec.tasklist
+++ b/board/waddledoo/ec.tasklist
@@ -9,6 +9,7 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \
diff --git a/board/waddledoo/gpio.inc b/board/waddledoo/gpio.inc
index 68d27b4025..ccf041cb44 100644
--- a/board/waddledoo/gpio.inc
+++ b/board/waddledoo/gpio.inc
@@ -10,6 +10,7 @@
* Note: Those with interrupt handlers must be declared first.
*/
+/* Power Interrupts */
GPIO_INT(SLP_S0_L, PIN(D, 5), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(SLP_S3_L, PIN(A, 5), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(SLP_S4_L, PIN(D, 4), GPIO_INT_BOTH, power_signal_interrupt)
@@ -21,12 +22,19 @@ GPIO_INT(VCCIN_AUX_VID0, PIN(F, 4), GPIO_INT_BOTH | GPIO_SEL_1P8V, power_signal
GPIO_INT(PG_VCCIO_EXT_OD, PIN(B, 0), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(PG_PP5000_U_OD, PIN(E, 2), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(PG_DRAM_OD, PIN(E, 4), GPIO_INT_BOTH, power_signal_interrupt)
+
+/* Button interrupts */
GPIO_INT(H1_EC_PWR_BTN_ODL, PIN(0, 1), GPIO_INT_BOTH | GPIO_PULL_UP, power_button_interrupt)
GPIO_INT(VOLDN_BTN_ODL, PIN(4, 0), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_SEL_1P8V, button_interrupt)
/* TODO(b:147257497) Fix this and EN_PP5000_U before board rev 0. */
GPIO_INT(VOLUP_BTN_ODL, PIN(A, 4), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_SEL_1P8V, button_interrupt)
+
+/* Other interrupts */
GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH, lid_interrupt)
GPIO_INT(EC_WP_OD, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt)
+GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+GPIO_INT(CAM_EC_VSYNC, PIN(0, 0), GPIO_INT_FALLING | GPIO_SEL_1P8V, sync_interrupt)
+GPIO_INT(LID_360_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr)
/* I2C Ports */
GPIO(EC_I2C_EEPROM_SCL, PIN(B, 3), GPIO_INPUT)