diff options
author | Scott Collyer <scollyer@google.com> | 2019-05-15 16:34:28 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-20 19:38:41 +0000 |
commit | 83be6d22cdfa82740802b6e7938bcc929102671e (patch) | |
tree | adb7f46b4618eb3a75b470435a01c95a898143c6 | |
parent | b4c70fd9371ecc133161d513c32d7546ccf00c5c (diff) | |
download | chrome-ec-83be6d22cdfa82740802b6e7938bcc929102671e.tar.gz |
hatch: Add support for TCS3400 as clear ALS and RGB sesnor
This CL removes the OPT3001 ALS and adds support for both the
CLEAR_ALS and RGB_ALS sensor.
BUG=b:132285560
BRANCH=none
TEST=Used ec console command 'accelinfo on 10000' to see values for
both clear and rgb light. Verfied that clear light went to 0 when I
covered the aperture and maxed out as I shined a phone light on it.
Change-Id: I8dcbbbecee552fe528ac9e18fb6c268509d504c0
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1615427
Tested-by: Scott Collyer <scollyer@chromium.org>
Auto-Submit: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Commit-Queue: Scott Collyer <scollyer@chromium.org>
-rw-r--r-- | board/hatch/board.c | 68 | ||||
-rw-r--r-- | board/hatch/board.h | 13 | ||||
-rw-r--r-- | board/hatch/gpio.inc | 1 |
3 files changed, 61 insertions, 21 deletions
diff --git a/board/hatch/board.c b/board/hatch/board.c index 4737239042..da1349208a 100644 --- a/board/hatch/board.c +++ b/board/hatch/board.c @@ -12,7 +12,7 @@ #include "cros_board_info.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi160.h" -#include "driver/als_opt3001.h" +#include "driver/als_tcs3400.h" #include "driver/bc12/pi3usb9201.h" #include "driver/ppc/sn5s330.h" #include "driver/tcpm/anx7447.h" @@ -180,10 +180,28 @@ static struct bmi160_drv_data_t g_bmi160_data; /* BMA255 private data */ static struct accelgyro_saved_data_t g_bma255_data; -static struct opt3001_drv_data_t g_opt3001_data = { - .scale = 1, - .uscale = 0, - .offset = 0, +/* ALS private data */ +static struct als_drv_data_t g_tcs3400_data = { + .als_cal.scale = 1, + .als_cal.uscale = 0, + .als_cal.offset = 0, +}; + +static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = { + .device_scale = 1, + .device_uscale = 0, + .rgb_cal[X] = { + .scale = ALS_CHANNEL_SCALE(1), + .offset = 0, + }, + .rgb_cal[Y] = { + .scale = ALS_CHANNEL_SCALE(1), + .offset = 0, + }, + .rgb_cal[Z] = { + .scale = ALS_CHANNEL_SCALE(1), + .offset = 0, + }, }; /* Matrix to rotate accelrator into standard reference frame */ @@ -275,20 +293,20 @@ struct motion_sensor_t motion_sensors[] = { .max_frequency = BMI160_GYRO_MAX_FREQ, }, - [LID_ALS] = { - .name = "Light", + [CLEAR_ALS] = { + .name = "Clear Light", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_OPT3001, + .chip = MOTIONSENSE_CHIP_TCS3400, .type = MOTIONSENSE_TYPE_LIGHT, .location = MOTIONSENSE_LOC_LID, - .drv = &opt3001_drv, - .drv_data = &g_opt3001_data, - .port = I2C_PORT_ACCEL, - .addr = OPT3001_I2C_ADDR, + .drv = &tcs3400_drv, + .drv_data = &g_tcs3400_data, + .port = I2C_PORT_ALS, + .addr = TCS3400_I2C_ADDR, .rot_standard_ref = NULL, - .default_range = 0x2b11a1, - .min_frequency = OPT3001_LIGHT_MIN_FREQ, - .max_frequency = OPT3001_LIGHT_MAX_FREQ, + .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] = { @@ -296,12 +314,28 @@ struct motion_sensor_t motion_sensors[] = { }, }, }, + + [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_LID, + .drv = &tcs3400_rgb_drv, + .drv_data = &g_tcs3400_rgb_data, + .rot_standard_ref = NULL, + .default_range = 0x10000, /* scale = 1x, uscale = 0 */ + }, }; 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[LID_ALS], + &motion_sensors[CLEAR_ALS], }; BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); @@ -426,6 +460,8 @@ static void board_init(void) setup_fans(); /* Enable gpio interrupt for base accelgyro sensor */ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); + /* Enable interrupt for the TCS3400 color light sensor */ + gpio_enable_interrupt(GPIO_TCS3400_INT_ODL); /* Enable HDMI HPD interrupt. */ gpio_enable_interrupt(GPIO_HDMI_CONN_HPD); /* Select correct gpio signal for PP5000_A control */ diff --git a/board/hatch/board.h b/board/hatch/board.h index 356d2883d8..c5d6da53bf 100644 --- a/board/hatch/board.h +++ b/board/hatch/board.h @@ -38,16 +38,18 @@ #define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT /* BMA253 Lid accel */ #define CONFIG_ACCEL_BMA255 -#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(LID_ALS)) +#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(CLEAR_ALS)) #define CONFIG_LID_ANGLE #define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL #define CONFIG_LID_ANGLE_UPDATE -/* OPT3001 ALS */ +/* TC3400 ALS */ #define CONFIG_ALS #define ALS_COUNT 1 -#define CONFIG_ALS_OPT3001 -#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 +#define CONFIG_ALS_TCS3400 +#define CONFIG_ALS_TCS3400_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS) +#define I2C_PORT_ALS I2C_PORT_SENSOR /* USB Type C and USB PD defines */ #define CONFIG_USB_PD_TCPM_ANX7447 @@ -136,7 +138,8 @@ enum sensor_id { LID_ACCEL = 0, BASE_ACCEL, BASE_GYRO, - LID_ALS, + CLEAR_ALS, + RGB_ALS, SENSOR_COUNT, }; diff --git a/board/hatch/gpio.inc b/board/hatch/gpio.inc index 63ac5a2271..91ee333503 100644 --- a/board/hatch/gpio.inc +++ b/board/hatch/gpio.inc @@ -26,6 +26,7 @@ GPIO_INT(PP5000_A_PG_OD, PIN(D, 7), GPIO_INT_BOTH, power_signal_interrupt) /* Sensor Interrupts */ GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING, bmi160_interrupt) +GPIO_INT(TCS3400_INT_ODL, PIN(F, 1), GPIO_INT_FALLING, tcs3400_interrupt) /* USB-C interrupts */ GPIO_INT(USB_C0_PPC_INT_ODL, PIN(E, 0), GPIO_INT_FALLING, ppc_interrupt) |