summaryrefslogtreecommitdiff
path: root/board/rammus/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/rammus/board.c')
-rw-r--r--board/rammus/board.c115
1 files changed, 114 insertions, 1 deletions
diff --git a/board/rammus/board.c b/board/rammus/board.c
index 4fc874a2f9..7577819fb8 100644
--- a/board/rammus/board.c
+++ b/board/rammus/board.c
@@ -11,6 +11,7 @@
#include "bd99992gw.h"
#include "board_config.h"
#include "button.h"
+#include "cbi_ssfc.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "charge_ramp.h"
@@ -19,7 +20,11 @@
#include "console.h"
#include "cros_board_info.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm426xx.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_kionix.h"
+#include "driver/accel_kx022.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "driver/tcpm/tcpm.h"
@@ -600,9 +605,11 @@ static struct mutex g_lid_mutex;
static struct mutex g_base_mutex;
static struct bmi160_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm426xx_data;
-/* BMA255 private data */
+/* 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 */
const mat33_fp_t base_standard_ref = {
@@ -611,12 +618,93 @@ const mat33_fp_t base_standard_ref = {
{ 0, 0, FLOAT_TO_FP(-1) }
};
+const mat33_fp_t base_standard_ref_icm = {
+ { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(-1) }
+};
+
const mat33_fp_t lid_standard_ref = {
{ FLOAT_TO_FP(-1), 0, 0 },
{ 0, FLOAT_TO_FP(1), 0 },
{ 0, 0, FLOAT_TO_FP(-1) }
};
+struct motion_sensor_t base_accel_icm = {
+ .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,
+ .addr = ICM426XX_ADDR0_FLAGS,
+ .rot_standard_ref = &base_standard_ref_icm,
+ .min_frequency = ICM426XX_ACCEL_MIN_FREQ,
+ .max_frequency = ICM426XX_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 = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
+};
+
+struct motion_sensor_t base_gyro_icm = {
+ .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,
+ .addr = ICM426XX_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref_icm,
+ .min_frequency = ICM426XX_GYRO_MIN_FREQ,
+ .max_frequency = ICM426XX_GYRO_MAX_FREQ,
+};
+
+struct motion_sensor_t lid_accel_kx022 = {
+ .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,
+ .addr = KX022_ADDR1,
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, to support lid angle calculation. */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
+};
+
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
@@ -693,6 +781,31 @@ struct motion_sensor_t motion_sensors[] = {
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+void motion_interrupt(enum gpio_signal signal)
+{
+ if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX)
+ icm426xx_interrupt(signal);
+ else
+ bmi160_interrupt(signal);
+}
+
+static void board_detect_motionsense(void)
+{
+ if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) {
+ motion_sensors[LID_ACCEL] = lid_accel_kx022;
+ ccprints("LID_ACCEL is KX022");
+ } else
+ ccprints("LID_ACCEL is BMA253");
+
+ if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) {
+ motion_sensors[BASE_ACCEL] = base_accel_icm;
+ motion_sensors[BASE_GYRO] = base_gyro_icm;
+ ccprints("BASE_ACCEL is ICM426XX");
+ } else
+ ccprints("BASE_ACCEL is BMI160");
+}
+DECLARE_HOOK(HOOK_INIT, board_detect_motionsense, HOOK_PRIO_DEFAULT);
+
/* Enable or disable input devices, based on chipset state and tablet mode */
#ifndef TEST_BUILD
void lid_angle_peripheral_enable(int enable)