diff options
Diffstat (limited to 'board')
-rw-r--r-- | board/brya/board.c | 1 | ||||
-rw-r--r-- | board/brya/board.h | 11 | ||||
-rw-r--r-- | board/brya/generated-gpio.inc | 2 | ||||
-rw-r--r-- | board/brya/sensors.c | 101 |
4 files changed, 113 insertions, 2 deletions
diff --git a/board/brya/board.c b/board/brya/board.c index beb327739f..eca893cc2b 100644 --- a/board/brya/board.c +++ b/board/brya/board.c @@ -12,6 +12,7 @@ #include "console.h" #include "driver/accel_lis2dw12.h" #include "driver/accelgyro_lsm6dso.h" +#include "driver/als_tcs3400.h" #include "power_button.h" #include "power.h" #include "switch.h" diff --git a/board/brya/board.h b/board/brya/board.h index 7bbd19a6f5..149fe8c684 100644 --- a/board/brya/board.h +++ b/board/brya/board.h @@ -38,6 +38,13 @@ #define CONFIG_ACCEL_LSM6DSO_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +/* TCS3400 ALS */ +#define CONFIG_ALS +#define ALS_COUNT 1 +#define CONFIG_ALS_TCS3400 +#define CONFIG_ALS_TCS3400_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS) + /* Enable sensor fifo, must also define the _SIZE and _THRES */ #define CONFIG_ACCEL_FIFO /* FIFO size is in power of 2. */ @@ -47,7 +54,7 @@ /* Sensors without hardware FIFO are in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK \ - (BIT(LID_ACCEL)) + (BIT(LID_ACCEL) | BIT(CLEAR_ALS)) /* Lid accel */ #define CONFIG_ACCEL_LIS2DWL @@ -206,6 +213,8 @@ enum sensor_id { LID_ACCEL = 0, BASE_ACCEL, BASE_GYRO, + CLEAR_ALS, + RGB_ALS, SENSOR_COUNT }; diff --git a/board/brya/generated-gpio.inc b/board/brya/generated-gpio.inc index 67afb0bb09..4b927b5053 100644 --- a/board/brya/generated-gpio.inc +++ b/board/brya/generated-gpio.inc @@ -5,6 +5,7 @@ /* INTERRUPT GPIOs: */ GPIO_INT(ACOK_OD, PIN(0, 0), GPIO_INT_BOTH, extpower_interrupt) GPIO_INT(EC_ACCEL_INT_R_L, PIN(8, 1), GPIO_SEL_1P8V | GPIO_INT_FALLING, lis2dw12_interrupt) +GPIO_INT(EC_ALS_RGB_INT_R_L, PIN(D, 4), GPIO_INT_FALLING, tcs3400_interrupt) GPIO_INT(EC_IMU_INT_R_L, PIN(5, 6), GPIO_SEL_1P8V | GPIO_INT_FALLING, lsm6dso_interrupt) GPIO_INT(EC_PROCHOT_IN_L, PIN(F, 0), GPIO_INT_BOTH, throttle_ap_prochot_input_interrupt) GPIO_INT(EC_VOLDN_BTN_ODL, PIN(9, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) @@ -34,7 +35,6 @@ GPIO_INT(USB_C2_RT_INT_ODL, PIN(4, 1), GPIO_INT_BOTH, retimer_inter GPIO(CCD_MODE_ODL, PIN(E, 5), GPIO_INPUT) GPIO(CHARGER_VAP_OTG_EN, PIN(7, 3), GPIO_OUT_LOW) GPIO(CPU_C10_GATE_L, PIN(6, 7), GPIO_INPUT) -GPIO(EC_ALS_RGB_INT_R_L, PIN(D, 4), GPIO_INPUT) GPIO(EC_BATT_PRES_ODL, PIN(E, 1), GPIO_INPUT) GPIO(EC_ENTERING_RW, PIN(0, 3), GPIO_OUT_LOW) GPIO(EC_EN_EDP_BL, PIN(D, 3), GPIO_OUT_HIGH) diff --git a/board/brya/sensors.c b/board/brya/sensors.c index 0478b308a2..13463296b6 100644 --- a/board/brya/sensors.c +++ b/board/brya/sensors.c @@ -8,6 +8,7 @@ #include "adc_chip.h" #include "driver/accel_lis2dw12.h" #include "driver/accelgyro_lsm6dso.h" +#include "driver/als_tcs3400_public.h" #include "hooks.h" #include "motion_sense.h" #include "temp_sensor.h" @@ -52,6 +53,60 @@ static const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(1)} }; +/* 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 from VPD */ + .cover_scale = ALS_CHANNEL_SCALE(1.0), /* CT */ + }, +}; + +/* + * TODO: b/184702900 need to calibrate ALS/RGB sensor. At default settings, + * shining phone flashlight on sensor pegs all readings at 0xFFFF. + */ +static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = { + .calibration.rgb_cal[X] = { + .offset = 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), + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kr */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + } + }, + .calibration.rgb_cal[Y] = { + .offset = 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), + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kg */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + }, + }, + .calibration.rgb_cal[Z] = { + .offset = 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), + .scale = { + .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kb */ + .cover_scale = ALS_CHANNEL_SCALE(1.0) + } + }, + .calibration.irt = INT_TO_FP(1), + .saturation.again = TCS_DEFAULT_AGAIN, + .saturation.atime = TCS_DEFAULT_ATIME, +}; + struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", @@ -139,13 +194,59 @@ struct motion_sensor_t motion_sensors[] = { }, }, }, + + [CLEAR_ALS] = { + .name = "Clear Light", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_TCS3400, + .type = MOTIONSENSE_TYPE_LIGHT, + .location = MOTIONSENSE_LOC_CAMERA, + .drv = &tcs3400_drv, + .drv_data = &g_tcs3400_data, + .port = I2C_PORT_SENSOR, + .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 = 1000, + }, + }, + }, + + [RGB_ALS] = { + /* + * RGB channels read by CLEAR_ALS and so the i2c port and + * address do not need to be defined for RGB_ALS. + */ + .name = "RGB Light", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_TCS3400, + .type = MOTIONSENSE_TYPE_LIGHT_RGB, + .location = MOTIONSENSE_LOC_CAMERA, + .drv = &tcs3400_rgb_drv, + .drv_data = &g_tcs3400_rgb_data, + .rot_standard_ref = NULL, + .default_range = 0x10000, /* scale = 1x, uscale = 0 */ + }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */ +const struct motion_sensor_t *motion_als_sensors[] = { + &motion_sensors[CLEAR_ALS], +}; +BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); + static void baseboard_sensors_init(void) { /* Enable gpio interrupt for lid accel sensor */ gpio_enable_interrupt(GPIO_EC_ACCEL_INT_R_L); + /* Enable interrupt for the TCS3400 color light sensor */ + gpio_enable_interrupt(GPIO_EC_ALS_RGB_INT_R_L); /* Enable gpio interrupt for base accelgyro sensor */ gpio_enable_interrupt(GPIO_EC_IMU_INT_R_L); } |