summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSue Chen <sue.chen@quanta.corp-partner.google.com>2021-08-25 16:44:25 +0800
committerCommit Bot <commit-bot@chromium.org>2021-08-27 15:32:12 +0000
commitfc28fe14b724523278ff4f3d0e549e7e38a2763f (patch)
tree0584f69824afe94e1952b6896b111ff16740490b
parent5df9a840bca8bd9cc9bb0b0131a23046760ac4d4 (diff)
downloadchrome-ec-fc28fe14b724523278ff4f3d0e549e7e38a2763f.tar.gz
Tomato: Add BMA422 for LID ACCEL
board_id >= 2: BMA422 board_id < 2 : KX022 BUG=b:197383637 BRANCH=none TEST=ectool motionsense can get BMA422 data Signed-off-by: Sue Chen <sue.chen@quanta.corp-partner.google.com> Change-Id: Ib0582c7606c4965eec52f58f4ff0fbc026512ca6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3117365 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--board/cherry/board.c68
-rw-r--r--board/cherry/board.h3
2 files changed, 59 insertions, 12 deletions
diff --git a/board/cherry/board.c b/board/cherry/board.c
index bb321880e3..479c998b23 100644
--- a/board/cherry/board.c
+++ b/board/cherry/board.c
@@ -12,6 +12,7 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "driver/accel_bma422.h"
#include "driver/accel_kionix.h"
#include "driver/accel_kx022.h"
#include "driver/accelgyro_icm42607.h"
@@ -38,6 +39,7 @@
#include "regulator.h"
#include "spi.h"
#include "switch.h"
+#include "system.h"
#include "tablet_mode.h"
#include "task.h"
#include "temp_sensor.h"
@@ -51,24 +53,13 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-/* Initialize board. */
-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);
-
- /* Disable PWM_CH_LED2(Green) for unuse */
- pwm_enable(PWM_CH_LED2, 0);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
/* Sensor */
static struct mutex g_base_mutex;
static struct mutex g_lid_mutex;
static struct icm_drv_data_t g_icm42607_data;
static struct kionix_accel_data g_kx022_data;
+static struct accelgyro_saved_data_t g_bma422_data;
/* Matrix to rotate accelrator into standard reference frame */
static const mat33_fp_t base_standard_ref = {
@@ -160,3 +151,56 @@ struct motion_sensor_t motion_sensors[] = {
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+struct motion_sensor_t bma422_lid_accel = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA422,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma4_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bma422_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMA4_I2C_ADDR_PRIMARY,
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = BMA4_ACCEL_MIN_FREQ,
+ .max_frequency = BMA4_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, enough for laptop. */
+ .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,
+ },
+ },
+};
+
+static void board_update_motion_sensor_config(void)
+{
+ if (system_get_board_version() >= 2) {
+ motion_sensors[LID_ACCEL] = bma422_lid_accel;
+ ccprints("LID ACCEL is BMA422");
+ } else {
+ ccprints("LID ACCEL is KX022");
+ }
+}
+
+/* Initialize board. */
+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);
+
+ /* Disable PWM_CH_LED2(Green) for unuse */
+ pwm_enable(PWM_CH_LED2, 0);
+
+ board_update_motion_sensor_config();
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/cherry/board.h b/board/cherry/board.h
index 368f4fcd96..afe06c62b4 100644
--- a/board/cherry/board.h
+++ b/board/cherry/board.h
@@ -55,6 +55,9 @@
/* KX022 Lid accel */
#define CONFIG_ACCEL_KX022
+/* BMA422 Lid accel */
+#define CONFIG_ACCEL_BMA4XX
+
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
#define CONFIG_LID_ANGLE