summaryrefslogtreecommitdiff
path: root/board/burnet/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/burnet/board.c')
-rw-r--r--board/burnet/board.c143
1 files changed, 137 insertions, 6 deletions
diff --git a/board/burnet/board.c b/board/burnet/board.c
index 7a8b2989ae..e2588c0cd4 100644
--- a/board/burnet/board.c
+++ b/board/burnet/board.c
@@ -14,6 +14,7 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi_common.h"
#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
@@ -114,8 +115,8 @@ struct ioexpander_config_t ioex_config[CONFIG_IO_EXPANDER_PORT_COUNT] = {
/******************************************************************************/
/* SPI devices */
-/* TODO: to be added once sensors land via CL:1714436 */
const struct spi_device_t spi_devices[] = {
+ { CONFIG_SPI_ACCEL_PORT, 2, GPIO_EC_SENSOR_SPI_NSS },
};
const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
@@ -240,6 +241,41 @@ void bc12_interrupt(enum gpio_signal signal)
task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12, 0);
}
+#ifndef VARIANT_KUKUI_NO_SENSORS
+static void board_spi_enable(void)
+{
+ cputs(CC_ACCEL, "board_spi_enable");
+ gpio_config_module(MODULE_SPI_MASTER, 1);
+
+ /* Enable clocks to SPI2 module */
+ STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI2;
+
+ /* Reset SPI2 */
+ STM32_RCC_APB1RSTR |= STM32_RCC_PB1_SPI2;
+ STM32_RCC_APB1RSTR &= ~STM32_RCC_PB1_SPI2;
+
+ spi_enable(CONFIG_SPI_ACCEL_PORT, 1);
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
+ board_spi_enable,
+ MOTION_SENSE_HOOK_PRIO - 1);
+
+static void board_spi_disable(void)
+{
+ spi_enable(CONFIG_SPI_ACCEL_PORT, 0);
+
+ /* Disable clocks to SPI2 module */
+ STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_SPI2;
+
+ gpio_config_module(MODULE_SPI_MASTER, 0);
+ gpio_set_flags(GPIO_EC_SENSOR_SPI_CK, GPIO_OUT_LOW);
+ gpio_set_level(GPIO_EC_SENSOR_SPI_CK, 0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
+ board_spi_disable,
+ MOTION_SENSE_HOOK_PRIO + 1);
+#endif /* !VARIANT_KUKUI_NO_SENSORS */
+
static void board_init(void)
{
/* If the reset cause is external, pulse PMIC force reset. */
@@ -252,10 +288,13 @@ static void board_init(void)
/* Enable TCPC alert interrupts */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
-#ifdef SECTION_IS_RW
+#ifndef VARIANT_KUKUI_NO_SENSORS
/* Enable interrupts from BMI160 sensor. */
gpio_enable_interrupt(GPIO_ACCEL_INT_ODL);
-#endif /* SECTION_IS_RW */
+
+ /* For some reason we have to do this again in case of sysjump */
+ board_spi_enable();
+#endif /* !VARIANT_KUKUI_NO_SENSORS */
/* Enable interrupt from PMIC. */
gpio_enable_interrupt(GPIO_PMIC_EC_RESETB);
@@ -265,15 +304,107 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+#ifndef VARIANT_KUKUI_NO_SENSORS
/* Motion sensors */
/* Mutexes */
-#ifdef SECTION_IS_RW
-/* TODO: to be added once sensors land via CL:1714436 */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+/* Rotation matrixes */
+static 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)}
+};
+
+static 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)}
+};
+
+/* sensor private data */
+static struct accelgyro_saved_data_t g_bma253_data;
+static struct bmi_drv_data_t g_bmi160_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_bma253_data,
+ .port = I2C_PORT_SENSORS,
+ .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2,
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_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
+ * Requirement: accelerometer sensor must init before gyro sensor
+ * DO NOT change the order of the following table.
+ */
+ [BASE_ACCEL] = {
+ .name = "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 = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 2, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_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,
+ },
+ },
+ },
+ [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 = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
-#endif /* SECTION_IS_RW */
+#endif /* !VARIANT_KUKUI_NO_SENSORS */
/* Called on AP S5 -> S3 transition */
static void board_chipset_startup(void)