summaryrefslogtreecommitdiff
path: root/board/kindred/board.c
diff options
context:
space:
mode:
authorBen Chen <ben.chen2@quanta.corp-partner.google.com>2020-12-11 16:03:31 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-29 01:50:32 +0000
commit04661a072ecc00ef42112ceb223095808190ff68 (patch)
tree1aaaf3a22f296e8f4f6e966cd227fb733aeaf658 /board/kindred/board.c
parent45ab3777a6c300c74f89da82826b8859bf8d36db (diff)
downloadchrome-ec-04661a072ecc00ef42112ceb223095808190ff68.tar.gz
kindred: config motion sensor driver by chip id
config motion sensor icm/kx022/bmi160/bma255 driver by chip id value. BUG=b:175918382 BRANCH=main TEST=Work on DUT with ICM/KX022/BMA255/BMI160, check the motion function is workable. Change-Id: Ie76dc49f2e102c230ddb5675a52639acb22b2da4 Signed-off-by: Ben Chen <ben.chen2@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2592541 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'board/kindred/board.c')
-rw-r--r--board/kindred/board.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/board/kindred/board.c b/board/kindred/board.c
index 948eb980d3..936b192683 100644
--- a/board/kindred/board.c
+++ b/board/kindred/board.c
@@ -11,7 +11,10 @@
#include "common.h"
#include "cros_board_info.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_kionix.h"
#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm426xx.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/anx7447.h"
@@ -47,6 +50,9 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+static int lid_device_id;
+static int base_device_id;
+
static void check_reboot_deferred(void);
DECLARE_DEFERRED(check_reboot_deferred);
@@ -201,9 +207,11 @@ static struct mutex g_lid_mutex;
/* Base accel private data */
static struct bmi_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm426xx_data;
/* BMA255 private data */
static struct accelgyro_saved_data_t g_bma255_data;
+static struct kionix_accel_data g_kx022_data;
/* Matrix to rotate accelrator into standard reference frame */
static const mat33_fp_t base_standard_ref = {
@@ -218,6 +226,84 @@ static const mat33_fp_t lid_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+static const mat33_fp_t base_icm_ref = {
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+struct motion_sensor_t kx022_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_ACCEL,
+ .i2c_spi_addr_flags = KX022_ADDR0_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+};
+
+struct motion_sensor_t icm426xx_base_accel = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM426XX,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &icm426xx_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_icm426xx_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
+ .default_range = 2, /* g, enough for laptop */
+ .rot_standard_ref = &base_icm_ref,
+ .min_frequency = ICM426XX_ACCEL_MIN_FREQ,
+ .max_frequency = ICM426XX_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+};
+
+struct motion_sensor_t icm426xx_base_gyro = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM426XX,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &icm426xx_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_icm426xx_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_icm_ref,
+ .min_frequency = ICM426XX_GYRO_MIN_FREQ,
+ .max_frequency = ICM426XX_GYRO_MAX_FREQ,
+};
+
+
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
@@ -264,6 +350,7 @@ struct motion_sensor_t motion_sensors[] = {
.config = {
[SENSOR_CONFIG_EC_S0] = {
.odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
},
/* Sensor on in S3 */
[SENSOR_CONFIG_EC_S3] = {
@@ -455,6 +542,52 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+static void determine_accel_devices(void)
+{
+ static uint8_t read_time;
+
+ if (read_time == 0) {
+ /* Read g sensor chip id*/
+ i2c_read8(I2C_PORT_ACCEL,
+ KX022_ADDR0_FLAGS, KX022_WHOAMI, &lid_device_id);
+ /* Read gyro sensor id*/
+ i2c_read8(I2C_PORT_ACCEL,
+ ICM426XX_ADDR0_FLAGS,
+ ICM426XX_REG_WHO_AM_I, &base_device_id);
+
+ CPRINTS("Motion Sensor Base id = %d Lid id =%d",
+ base_device_id, lid_device_id);
+
+ if (lid_device_id == KX022_WHO_AM_I_VAL) {
+ motion_sensors[LID_ACCEL] = kx022_lid_accel;
+ ccprints("Lid Accel is KX022");
+ } else
+ ccprints("Lid Accel is BMA255");
+
+ if (base_device_id == ICM426XX_CHIP_ICM40608) {
+ motion_sensors[BASE_ACCEL] = icm426xx_base_accel;
+ motion_sensors[BASE_GYRO] = icm426xx_base_gyro;
+ ccprints("BASE Accel is ICM426XX");
+ } else
+ ccprints("BASE Accel is BMI160");
+
+ read_time++;
+ }
+}
+DECLARE_HOOK(HOOK_CHIPSET_RESUME, determine_accel_devices, HOOK_PRIO_DEFAULT);
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ switch (base_device_id) {
+ case ICM426XX_CHIP_ICM40608:
+ icm426xx_interrupt(signal);
+ break;
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
void board_overcurrent_event(int port, int is_overcurrented)
{
/* Check that port number is valid. */