summaryrefslogtreecommitdiff
path: root/board/goroh
diff options
context:
space:
mode:
authorEric Yilun Lin <yllin@chromium.org>2021-08-13 15:36:10 +0800
committerCommit Bot <commit-bot@chromium.org>2021-11-17 01:58:47 +0000
commit57a3bcaf4f1e68376c883b8e0739bbaa9e2cde96 (patch)
tree704b368817fb43366052d6da5248b3a63868633a /board/goroh
parent0cfd1836354b47ea0d47e01dd7701f9bdad399f5 (diff)
downloadchrome-ec-57a3bcaf4f1e68376c883b8e0739bbaa9e2cde96.tar.gz
goroh: configure sensors
add base gyro, base accel, and lid accel. BUG=b:185846337 TEST=accelinfo BRANCH=none Change-Id: I96d4d3ee424b17d388e7720c41477a121d61c183 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3093651 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@google.com> Tested-by: Eric Yilun Lin <yllin@google.com>
Diffstat (limited to 'board/goroh')
-rw-r--r--board/goroh/board.c116
-rw-r--r--board/goroh/board.h14
-rw-r--r--board/goroh/build.mk5
-rw-r--r--board/goroh/gpio.inc5
-rw-r--r--board/goroh/sensors.c99
5 files changed, 111 insertions, 128 deletions
diff --git a/board/goroh/board.c b/board/goroh/board.c
index 9354dec618..b6ffb3e8de 100644
--- a/board/goroh/board.c
+++ b/board/goroh/board.c
@@ -50,116 +50,9 @@ static void board_init(void)
{
/* Enable motion sensor interrupt */
gpio_enable_interrupt(GPIO_BASE_IMU_INT_L);
- gpio_enable_interrupt(GPIO_LID_ACCEL_INT_L);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-/* Sensor */
-static struct mutex g_base_mutex;
-static struct mutex g_lid_mutex;
-
-static struct bmi_drv_data_t g_bmi160_data;
-static struct stprivate_data g_lis2dwl_data;
-
-/* Matrix to rotate accelerometer into standard reference frame */
-static const mat33_fp_t base_standard_ref = {
- {0, FLOAT_TO_FP(1), 0},
- {FLOAT_TO_FP(-1), 0, 0},
- {0, 0, FLOAT_TO_FP(1)},
-};
-
-static void update_rotation_matrix(void)
-{
- if (board_get_version() >= 2) {
- motion_sensors[BASE_ACCEL].rot_standard_ref =
- &base_standard_ref;
- motion_sensors[BASE_GYRO].rot_standard_ref =
- &base_standard_ref;
- }
-}
-DECLARE_HOOK(HOOK_INIT, update_rotation_matrix, HOOK_PRIO_INIT_ADC + 2);
-
-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.
- */
- [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_ACCEL,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .rot_standard_ref = NULL, /* identity matrix */
- .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 = {
- /* Sensor on 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 = "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_ACCEL,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .default_range = 1000, /* dps */
- .rot_standard_ref = NULL, /* identity matrix */
- .min_frequency = BMI_GYRO_MIN_FREQ,
- .max_frequency = BMI_GYRO_MAX_FREQ,
- },
- [LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_LIS2DWL,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &lis2dw12_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_lis2dwl_data,
- .int_signal = GPIO_LID_ACCEL_INT_L,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = LIS2DWL_ADDR1_FLAGS,
- .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
- .rot_standard_ref = NULL, /* identity matrix */
- .default_range = 2, /* g */
- .min_frequency = LIS2DW12_ODR_MIN_VAL,
- .max_frequency = LIS2DW12_ODR_MAX_VAL,
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 12500 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
- },
-};
-const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
-
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
const struct adc_t adc_channels[] = {
{"VBUS", ADC_MAX_MVOLT * 10, ADC_READ_MAX + 1, 0, CHIP_ADC_CH0},
@@ -207,15 +100,6 @@ const struct pwm_t pwm_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
-int board_accel_force_mode_mask(void)
-{
- int version = board_get_version();
-
- if (version == -1 || version >= 2)
- return 0;
- return BIT(LID_ACCEL);
-}
-
static void board_suspend(void)
{
}
diff --git a/board/goroh/board.h b/board/goroh/board.h
index 33c6ca901e..42569aa1b6 100644
--- a/board/goroh/board.h
+++ b/board/goroh/board.h
@@ -46,18 +46,16 @@
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
-#define CONFIG_ACCEL_LIS2DWL
-#define CONFIG_ACCEL_LIS2DW_AS_BASE
-#define CONFIG_ACCEL_LIS2DW12_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
-
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
#define CONFIG_LID_ANGLE_UPDATE
-/* TODO(b/171931139): remove this after rev1 board deprecated */
-#define CONFIG_ACCEL_FORCE_MODE_MASK (board_accel_force_mode_mask())
+#define CONFIG_ACCEL_BMA255 /* Lid accel BMA253 */
+
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK \
+ (BIT(LID_ACCEL) | BIT(BASE_GYRO) | BIT(BASE_ACCEL))
/* SPI / Host Command */
#undef CONFIG_HOSTCMD_DEBUG_MODE
@@ -102,7 +100,5 @@ enum pwm_channel {
PWM_CH_COUNT,
};
-int board_accel_force_mode_mask(void);
-
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/goroh/build.mk b/board/goroh/build.mk
index 468d9ad365..3a33f14b2e 100644
--- a/board/goroh/build.mk
+++ b/board/goroh/build.mk
@@ -11,4 +11,7 @@ CHIP_FAMILY:=it8xxx2
CHIP_VARIANT:=it81202bx_1024
BASEBOARD:=goroh
-board-y+=battery.o board.o led.o
+board-y+=battery.o
+board-y+=board.o
+board-y+=led.o
+board-y+=sensors.o
diff --git a/board/goroh/gpio.inc b/board/goroh/gpio.inc
index bb9c18ece3..80ba89a7b6 100644
--- a/board/goroh/gpio.inc
+++ b/board/goroh/gpio.inc
@@ -38,8 +38,6 @@ GPIO_INT(PG_VDD_DDR_OD, PIN(J, 5), GPIO_INT_BOTH,
/* Sensor Interrupts */
GPIO_INT(BASE_IMU_INT_L, PIN(M, 2), GPIO_INT_FALLING | GPIO_SEL_1P8V,
bmi160_interrupt)
-GPIO_INT(LID_ACCEL_INT_L, PIN(G, 0), GPIO_INT_FALLING | GPIO_SEL_1P8V,
- lis2dw12_interrupt)
/* USB-C interrupts */
GPIO_INT(USB_C0_FAULT_ODL, PIN(D, 1), GPIO_INT_BOTH, ppc_interrupt)
@@ -135,6 +133,9 @@ ALTERNATE(PIN_MASK(I, 0x6E), 0, MODULE_ADC, 0) /* ADC 1,2,3,5,6 */
/* SPI */
ALTERNATE(PIN_MASK(M, 0x33), 0, MODULE_SPI, 0) /* SPI */
+/* unused, configure as input pin */
+GPIO(LID_ACCEL_INT_L, PIN(G, 0), GPIO_INPUT | GPIO_SEL_1P8V)
+
/* *_ODL pin has external pullup so don't pull it down. */
/* reserved for future use */
diff --git a/board/goroh/sensors.c b/board/goroh/sensors.c
new file mode 100644
index 0000000000..e6ecf99073
--- /dev/null
+++ b/board/goroh/sensors.c
@@ -0,0 +1,99 @@
+/* Copyright 2021 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.
+ */
+/* Goroh sensors configuration */
+
+#include "driver/accel_bma2x2.h"
+#include "driver/accelgyro_bmi_common.h"
+#include "driver/als_tcs3400.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "spi.h"
+
+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_bma253_data;
+
+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.
+ */
+ [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_ACCEL,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .rot_standard_ref = NULL, /* identity matrix */
+ .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 = {
+ /* Sensor on 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 = "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_ACCEL,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = NULL, /* identity matrix */
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
+ [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_ACCEL,
+ .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
+ .rot_standard_ref = NULL, /* identity matrix */
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, to support tablet mode */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+};
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+