summaryrefslogtreecommitdiff
path: root/board/fennel/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/fennel/board.c')
-rw-r--r--board/fennel/board.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/board/fennel/board.c b/board/fennel/board.c
index 0442cf3bd6..401eef5795 100644
--- a/board/fennel/board.c
+++ b/board/fennel/board.c
@@ -16,6 +16,8 @@
#include "console.h"
#include "driver/accel_lis2dw12.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm42607.h"
#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/isl923x.h"
@@ -333,6 +335,61 @@ static const mat33_fp_t lid_standard_ref = {
/* sensor private data */
static struct stprivate_data g_lis2dwl_data;
static struct bmi160_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm42607_data;
+
+enum base_accelgyro_type {
+ BASE_GYRO_NONE = 0,
+ BASE_GYRO_BMI160 = 1,
+ BASE_GYRO_ICM426XX = 2,
+};
+
+static enum base_accelgyro_type base_accelgyro_config;
+
+struct motion_sensor_t icm42607_base_accel = {
+ .name = "Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM42607,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &icm42607_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_icm42607_data,
+ .port = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs.*/
+ .rot_standard_ref = NULL,
+ .min_frequency = ICM42607_ACCEL_MIN_FREQ,
+ .max_frequency = ICM42607_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,
+ },
+ },
+};
+
+struct motion_sensor_t icm42607_base_gyro = {
+ .name = "Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM42607,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &icm42607_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_icm42607_data,
+ .port = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = NULL,
+ .min_frequency = ICM42607_GYRO_MIN_FREQ,
+ .max_frequency = ICM42607_GYRO_MAX_FREQ,
+};
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
@@ -413,6 +470,52 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+static void board_detect_motionsensor(void)
+{
+ int ret;
+ int val;
+
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ return;
+ if (base_accelgyro_config != BASE_GYRO_NONE)
+ return;
+ /* Check base accelgyro chip */
+ ret = icm_read8(&icm42607_base_accel,
+ ICM42607_REG_WHO_AM_I, &val);
+ if (ret)
+ ccprints("Get ICM fail.");
+ if (val == ICM42607_CHIP_ICM42607P) {
+ motion_sensors[BASE_ACCEL] = icm42607_base_accel;
+ motion_sensors[BASE_GYRO] = icm42607_base_gyro;
+ }
+ base_accelgyro_config = (val == ICM42607_CHIP_ICM42607P)
+ ? BASE_GYRO_ICM426XX : BASE_GYRO_BMI160;
+ ccprints("BASE Accelgyro: %s", (val == ICM42607_CHIP_ICM42607P)
+ ? "ICM42607" : "BMI160");
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_detect_motionsensor,
+ HOOK_PRIO_DEFAULT);
+/*
+ * board_spi_enable() will be called in the board_init() when sysjump to rw
+ * the board_init() is DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT)
+ * the board_detect_motionsensor() reads data via sensor SPI
+ * so the priority of board_detect_motionsensor should be HOOK_PRIO_DEFAULT+1
+ */
+DECLARE_HOOK(HOOK_INIT, board_detect_motionsensor, HOOK_PRIO_DEFAULT + 1);
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ switch (base_accelgyro_config) {
+ case BASE_GYRO_ICM426XX:
+ icm42607_interrupt(signal);
+ break;
+ case BASE_GYRO_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
const struct it8801_pwm_t it8801_pwm_channels[] = {
[IT8801_PWM_CH_KBLIGHT] = {.index = 4},
};