diff options
Diffstat (limited to 'board/kakadu/board.c')
-rw-r--r-- | board/kakadu/board.c | 223 |
1 files changed, 142 insertions, 81 deletions
diff --git a/board/kakadu/board.c b/board/kakadu/board.c index dc08f918e0..422036b409 100644 --- a/board/kakadu/board.c +++ b/board/kakadu/board.c @@ -14,13 +14,13 @@ #include "chipset.h" #include "common.h" #include "console.h" -#include "driver/accelgyro_lsm6dsm.h" +#include "driver/accelgyro_bmi160.h" +#include "driver/als_tcs3400.h" #include "driver/charger/rt946x.h" #include "driver/sync.h" #include "driver/tcpm/mt6370.h" #include "driver/usb_mux/it5205.h" #include "extpower.h" -#include "gesture.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" @@ -101,7 +101,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { }; struct mt6370_thermal_bound thermal_bound = { - .target = 90, + .target = 80, .err = 4, }; @@ -117,7 +117,7 @@ static void board_hpd_update(int port, int hpd_lvl, int hpd_irq) __override const struct rt946x_init_setting *board_rt946x_init_setting(void) { static const struct rt946x_init_setting battery_init_setting = { - .eoc_current = 500, + .eoc_current = 140, .mivr = 4000, .ircmp_vclamp = 32, .ircmp_res = 25, @@ -236,20 +236,8 @@ int pd_snk_is_vbus_provided(int port) return rt946x_is_vbus_ready(); } - -#define CHARGER_I2C_ADDR_FLAGS RT946X_ADDR_FLAGS - static void board_init(void) { - -#ifdef SECTION_IS_RW - int val; - i2c_read8(I2C_PORT_CHARGER, CHARGER_I2C_ADDR_FLAGS, - RT946X_REG_CHGCTRL1, &val); - val &= RT946X_MASK_OPA_MODE; - i2c_write8(I2C_PORT_CHARGER, CHARGER_I2C_ADDR_FLAGS, - RT946X_REG_CHGCTRL1, (val | RT946X_MASK_STAT_EN)); -#endif /* If the reset cause is external, pulse PMIC force reset. */ if (system_get_reset_flags() == EC_RESET_FLAG_RESET_PIN) { gpio_set_level(GPIO_PMIC_FORCE_RESET_ODL, 0); @@ -264,7 +252,7 @@ static void board_init(void) gpio_enable_interrupt(GPIO_CHARGER_INT_ODL); #ifdef SECTION_IS_RW - /* Enable interrupts from LSM6DS3TR sensor. */ + /* Enable interrupts from BMI160 sensor. */ gpio_enable_interrupt(GPIO_ACCEL_INT_ODL); /* Enable interrupt for the camera vsync. */ @@ -295,37 +283,76 @@ static void board_rev_init(void) * Keep this pin defaults to P1 setting since that eMMC enabled with * High-Z stat. */ - /* TODO */ /* Put initial code here for different EC board reversion */ - - /* Display bias settings. */ - mt6370_db_set_voltages(6000, 5800, 5800); - - /* - * Enable MT6370 DB_POSVOUT/DB_NEGVOUT (controlled by _EN pins). - */ - mt6370_db_external_control(1); - + return; } DECLARE_HOOK(HOOK_INIT, board_rev_init, HOOK_PRIO_INIT_ADC + 1); -void sensor_board_proc_double_tap(void) -{ - CPRINTS("Detect double tap"); -} - /* Motion sensors */ /* Mutexes */ #ifndef VARIANT_KUKUI_NO_SENSORS static struct mutex g_lid_mutex; -static struct lsm6dsm_data lsm6dsm_data; +static struct bmi160_drv_data_t g_bmi160_data; + +/* TCS3400 private data */ +static struct als_drv_data_t g_tcs3400_data = { + .als_cal.scale = 1, + .als_cal.uscale = 0, + .als_cal.offset = 0, + .als_cal.channel_scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kc */ + .cover_scale = ALS_CHANNEL_SCALE(1.0), /* CT */ + }, +}; + +static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = { + /* + * TODO(b:139366662): calculates the actual coefficients and scaling + * factors + */ + .rgb_cal[X] = { + .offset = 0, + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kr */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + }, + .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0), + }, + .rgb_cal[Y] = { + .offset = 0, + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kg */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + }, + .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0.1), + }, + .rgb_cal[Z] = { + .offset = 0, + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kb */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + }, + .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0), + .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0), + }, + .saturation.again = TCS_DEFAULT_AGAIN, + .saturation.atime = TCS_DEFAULT_ATIME, +}; /* Matrix to rotate accelerometer into standard reference frame */ static const mat33_fp_t lid_standard_ref = { - {0, FLOAT_TO_FP(1), 0}, {FLOAT_TO_FP(-1), 0, 0}, + {0, FLOAT_TO_FP(-1), 0}, {0, 0, FLOAT_TO_FP(1)} }; @@ -336,61 +363,95 @@ struct motion_sensor_t motion_sensors[] = { * DO NOT change the order of the following table. */ [LID_ACCEL] = { - .name = "Accel", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_LSM6DSM, - .type = MOTIONSENSE_TYPE_ACCEL, - .location = MOTIONSENSE_LOC_LID, - .drv = &lsm6dsm_drv, - .mutex = &g_lid_mutex, - .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, - MOTIONSENSE_TYPE_ACCEL), - .int_signal = GPIO_ACCEL_INT_ODL, - .flags = MOTIONSENSE_FLAG_INT_SIGNAL, - .port = I2C_PORT_ACCEL, - .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, - .rot_standard_ref = &lid_standard_ref, - .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ - .min_frequency = LSM6DSM_ODR_MIN_VAL, - .max_frequency = LSM6DSM_ODR_MAX_VAL, - .config = { - /* Enable accel in S0 */ + .name = "Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi160_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .default_range = 4, /* g */ + .min_frequency = BMI160_ACCEL_MIN_FREQ, + .max_frequency = BMI160_ACCEL_MAX_FREQ, + .config = { + /* Enable accel in S0 */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + }, + }, + [LID_GYRO] = { + .name = "Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi160_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &lid_standard_ref, + .min_frequency = BMI160_GYRO_MIN_FREQ, + .max_frequency = BMI160_GYRO_MAX_FREQ, + }, + [CLEAR_ALS] = { + .name = "Clear Light", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_TCS3400, + .type = MOTIONSENSE_TYPE_LIGHT, + .location = MOTIONSENSE_LOC_LID, + .drv = &tcs3400_drv, + .drv_data = &g_tcs3400_data, + .port = I2C_PORT_ALS, + .i2c_spi_addr_flags = TCS3400_I2C_ADDR_FLAGS, + .rot_standard_ref = NULL, + .default_range = 0x10000, /* scale = 1x, uscale = 0 */ + .min_frequency = TCS3400_LIGHT_MIN_FREQ, + .max_frequency = TCS3400_LIGHT_MAX_FREQ, + .config = { + /* Run ALS sensor in S0 */ [SENSOR_CONFIG_EC_S0] = { - .odr = 13000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, + .odr = 1000, }, + }, }, - [LID_GYRO] = { - .name = "Gyro", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_LSM6DSM, - .type = MOTIONSENSE_TYPE_GYRO, - .location = MOTIONSENSE_LOC_LID, - .drv = &lsm6dsm_drv, - .mutex = &g_lid_mutex, - .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, - MOTIONSENSE_TYPE_GYRO), - .port = I2C_PORT_ACCEL, - .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, - .default_range = 1000 | ROUND_UP_FLAG, /* dps */ - .rot_standard_ref = &lid_standard_ref, - .min_frequency = LSM6DSM_ODR_MIN_VAL, - .max_frequency = LSM6DSM_ODR_MAX_VAL, + [RGB_ALS] = { + .name = "RGB Light", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_TCS3400, + .type = MOTIONSENSE_TYPE_LIGHT_RGB, + .location = MOTIONSENSE_LOC_LID, + .drv = &tcs3400_rgb_drv, + .drv_data = &g_tcs3400_rgb_data, + /*.port = I2C_PORT_ALS,*/ /* Unused. RGB channels read by CLEAR_ALS. */ + .rot_standard_ref = NULL, + .default_range = 0x10000, /* scale = 1x, uscale = 0 */ + .min_frequency = 0, /* 0 indicates we should not use sensor directly */ + .max_frequency = 0, /* 0 indicates we should not use sensor directly */ }, [VSYNC] = { - .name = "Camera vsync", - .active_mask = SENSOR_ACTIVE_S0, - .chip = MOTIONSENSE_CHIP_GPIO, - .type = MOTIONSENSE_TYPE_SYNC, - .location = MOTIONSENSE_LOC_CAMERA, - .drv = &sync_drv, - .default_range = 0, - .min_frequency = 0, - .max_frequency = 1, + .name = "Camera vsync", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_GPIO, + .type = MOTIONSENSE_TYPE_SYNC, + .location = MOTIONSENSE_LOC_CAMERA, + .drv = &sync_drv, + .default_range = 0, + .min_frequency = 0, + .max_frequency = 1, }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +const struct motion_sensor_t *motion_als_sensors[] = { + &motion_sensors[CLEAR_ALS], +}; #endif /* VARIANT_KUKUI_NO_SENSORS */ void usb_charger_set_switches(int port, enum usb_switch setting) |