summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTang Qijun <qijun.tang@ecs.corp-partner.google.com>2022-08-16 15:01:37 +0800
committerBob Moragues <moragues@chromium.org>2022-09-03 03:13:00 +0000
commit91a7d31b52b98872c4b24d905a5ea10ab227f8a3 (patch)
tree9c88b62bc6710863a753bcd1c0a15bc0a9d3775f
parent51af2f83c9c77e1ea302cd16b7738d63c930a228 (diff)
downloadchrome-ec-91a7d31b52b98872c4b24d905a5ea10ab227f8a3.tar.gz
Pazquel360: update board sensor config from sku
Pazquel board form factor is clamshell, pazquel360 board form factor is convertible. Firmware is distinguished by different sku id. This submit is cherrypicked from main branch , it depend on motionsense chip BMI232 driver ready. But firmware branch the driver still not exist. For example have not the file ("driver/accelgyro_bmi323.h") BRANCH=trogdor BUG=b:243492849 TEST=EC console command: "accelinfo", pazquel board: Motion sensors count = 0 pazquel360 board: Motion sensors count = 3 Signed-off-by: Tang Qijun <qijun.tang@ecs.corp-partner.google.com> Change-Id: I8101bc3934af93d3f557dc1bc31f77bd1a8fa4fb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3832335 Reviewed-by: Chao Gui <chaogui@google.com> Reviewed-by: Wai-Hong Tam <waihong@google.com> Tested-by: Yunlong Jia <yunlong.jia@ecs.corp-partner.google.com> Reviewed-by: Bob Moragues <moragues@chromium.org> (cherry picked from commit 84028b330e9892e53bcfd1d494497e150f3f3f29) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3853442 Tested-by: Bob Moragues <moragues@chromium.org> Commit-Queue: Bob Moragues <moragues@chromium.org>
-rw-r--r--board/pazquel/board.c206
-rw-r--r--board/pazquel/board.h12
-rw-r--r--board/pazquel/gpio.inc2
3 files changed, 139 insertions, 81 deletions
diff --git a/board/pazquel/board.c b/board/pazquel/board.c
index 12e18aa267..842d622641 100644
--- a/board/pazquel/board.c
+++ b/board/pazquel/board.c
@@ -10,8 +10,10 @@
#include "charge_manager.h"
#include "charge_state.h"
#include "extpower.h"
+#include "driver/accel_kionix.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_bmi323.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
@@ -262,17 +264,6 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
.i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS,
},
};
-
-static void board_update_sensor_config_clamshell(void)
-{
- motion_sensor_count = 0;
- gmr_tablet_switch_disable();
- /* The sensors are not stuffed; don't allow lines to float */
- gpio_set_flags(GPIO_ACCEL_GYRO_INT_L, GPIO_INPUT | GPIO_PULL_DOWN);
- gpio_set_flags(GPIO_LID_ACCEL_INT_L, GPIO_INPUT | GPIO_PULL_DOWN);
-}
-DECLARE_HOOK(HOOK_INIT, board_update_sensor_config_clamshell,
- HOOK_PRIO_INIT_I2C + 2);
/* Initialize board. */
static void board_init(void)
{
@@ -567,90 +558,149 @@ uint16_t tcpc_get_alert_status(void)
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_bma255_data;
-
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t base_standard_ref = { { FLOAT_TO_FP(1), 0, 0 },
{ 0, FLOAT_TO_FP(-1), 0 },
{ 0, 0, FLOAT_TO_FP(-1) } };
-static const mat33_fp_t lid_standard_ref = { { 0, FLOAT_TO_FP(1), 0 },
- { FLOAT_TO_FP(-1), 0, 0 },
- { 0, 0, FLOAT_TO_FP(1) } };
+static struct kionix_accel_data g_kx022_data;
+
+static const mat33_fp_t lid_standard_ref_kx022 = { { FLOAT_TO_FP(1), 0, 0 },
+ { 0, FLOAT_TO_FP(1), 0 },
+ { 0, 0, FLOAT_TO_FP(-1) } };
+
+static struct bmi_drv_data_t g_bmi_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_bma255_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
- .rot_standard_ref = &lid_standard_ref,
- .default_range = 2, /* g, to support lid angle calculation. */
- .min_frequency = BMA255_ACCEL_MIN_FREQ,
- .max_frequency = BMA255_ACCEL_MAX_FREQ,
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
+ .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_SENSOR,
+ .i2c_spi_addr_flags = KX022_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref_kx022,
+ .default_range = 2, /* g */
+ /* We only use 2g because its resolution is only 8-bits */
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
},
- },
},
/*
- * Note: bmi160: supports accelerometer and gyro sensor
+ * Note: bmi232: 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_SENSOR,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .rot_standard_ref = &base_standard_ref,
- .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_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI323,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi3xx_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI3_ADDR_I2C_PRIM,
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_ACCEL_MAX_FREQ,
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
},
[BASE_GYRO] = {
- .name = "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 = &base_standard_ref,
- .min_frequency = BMI_GYRO_MIN_FREQ,
- .max_frequency = BMI_GYRO_MAX_FREQ,
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI323,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi3xx_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI3_ADDR_I2C_PRIM,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
},
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+static void board_update_sensor_config_from_sku(void)
+{
+ if (board_is_clamshell()) {
+ motion_sensor_count = 0;
+ gmr_tablet_switch_disable();
+ /* The sensors are not stuffed; don't allow lines to float */
+ gpio_set_flags(GPIO_ACCEL_GYRO_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_LID_ACCEL_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ } else {
+ motion_sensor_count = ARRAY_SIZE(motion_sensors);
+ /* Enable interrupt for the base accel sensor */
+ gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L);
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_update_sensor_config_from_sku,
+ HOOK_PRIO_INIT_I2C + 2);
+
+static uint8_t sku_id;
+
+enum board_model {
+ PAZQUEL,
+ PAZQUEL360,
+ UNKNOWN,
+};
+
+static const char *const model_name[] = {
+ "PAZQUEL",
+ "PAZQUEL360",
+ "UNKNOWN",
+};
+
+static enum board_model get_model(void)
+{
+ if (sku_id == 0 || sku_id == 1 || sku_id == 2 || sku_id == 3 ||
+ sku_id == 4 || sku_id == 5 || sku_id == 6)
+ return PAZQUEL;
+ if (sku_id >= 8)
+ return PAZQUEL360;
+ return UNKNOWN;
+}
+
+int board_is_clamshell(void)
+{
+ return get_model() == PAZQUEL;
+}
+
+/* Read SKU ID from GPIO and initialize variables for board variants */
+static void sku_init(void)
+{
+ sku_id = board_get_sku_id();
+ CPRINTS("SKU: %u (%s)", sku_id, model_name[get_model()]);
+}
+DECLARE_HOOK(HOOK_INIT, sku_init, HOOK_PRIO_INIT_I2C + 1);
diff --git a/board/pazquel/board.h b/board/pazquel/board.h
index 74e985ff46..2714b8ecda 100644
--- a/board/pazquel/board.h
+++ b/board/pazquel/board.h
@@ -42,15 +42,22 @@
/* Sensors */
#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+<<<<<<< HEAD
/* BMI160 Base accel/gyro */
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+=======
+
+/* BMI323 Base accel/gyro */
+#define CONFIG_ACCELGYRO_BMI3XX
+#define CONFIG_ACCELGYRO_BMI3XX_INT_EVENT \
+>>>>>>> 5ae49e09bb... Pazquel360: update board sensor config from sku
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
#define OPT3001_I2C_ADDR_FLAGS OPT3001_I2C_ADDR1_FLAGS
-/* BMA253 lid accel */
-#define CONFIG_ACCEL_BMA255
+/* KX022 lid accel */
+#define CONFIG_ACCEL_KX022
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
#define CONFIG_LID_ANGLE
@@ -99,6 +106,7 @@ enum battery_type {
/* Reset all TCPCs. */
void board_reset_pd_mcu(void);
void board_set_tcpc_power_mode(int port, int mode);
+int board_is_clamshell(void);
#endif /* !defined(__ASSEMBLER__) */
diff --git a/board/pazquel/gpio.inc b/board/pazquel/gpio.inc
index 4ebd09b4ee..a698422169 100644
--- a/board/pazquel/gpio.inc
+++ b/board/pazquel/gpio.inc
@@ -39,7 +39,7 @@ GPIO_INT(AP_EC_SPI_CS_L, PIN(5, 3), GPIO_INT_FALLING | GPIO_PULL_DOWN, shi_cs
/* Sensor interrupts */
GPIO_INT(TABLET_MODE_L, PIN(C, 6), GPIO_INT_BOTH, gmr_tablet_switch_isr)
-GPIO_INT(ACCEL_GYRO_INT_L, PIN(A, 0), GPIO_INT_FALLING, bmi160_interrupt) /* Accelerometer/gyro interrupt */
+GPIO_INT(ACCEL_GYRO_INT_L, PIN(A, 0), GPIO_INT_FALLING, bmi3xx_interrupt) /* Accelerometer/gyro interrupt */
/*
* EC_RST_ODL used to be a wake source from PSL mode. However, we disabled