summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2019-06-20 15:33:53 -0700
committerCommit Bot <commit-bot@chromium.org>2019-06-25 08:21:27 +0000
commit08429fb35a85944eb7314926a7cba3254b3de86a (patch)
treebcb5eacb54da415add3b610fa341d03a1b488637
parent71c5056bd1f27b52f99c1ed4cff01bdc8cee032e (diff)
downloadchrome-ec-08429fb35a85944eb7314926a7cba3254b3de86a.tar.gz
kohaku: Add support for TCS3400 as clear ALS and RGB sesnor
BUG=b:134207072, b:135216932 BRANCH=none TEST=build kohaku Change-Id: I7b3d01d5dfb193262055b6aff2d101844159aa94 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1670165 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org>
-rw-r--r--board/kohaku/board.c66
-rw-r--r--board/kohaku/board.h16
-rw-r--r--board/kohaku/gpio.inc2
3 files changed, 80 insertions, 4 deletions
diff --git a/board/kohaku/board.c b/board/kohaku/board.c
index 543c656a52..5635cbf3f8 100644
--- a/board/kohaku/board.c
+++ b/board/kohaku/board.c
@@ -13,6 +13,7 @@
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/als_bh1730.h"
+#include "driver/als_tcs3400.h"
#include "driver/ppc/sn5s330.h"
#include "driver/bc12/max14637.h"
#include "driver/sync.h"
@@ -170,6 +171,30 @@ static struct accelgyro_saved_data_t g_bma255_data;
/* BH1730 private data */
struct bh1730_drv_data_t g_bh1730_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,
+};
+
+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 */
static const mat33_fp_t base_standard_ref = {
{ 0, FLOAT_TO_FP(1), 0},
@@ -292,12 +317,51 @@ struct motion_sensor_t motion_sensors[] = {
.min_frequency = 0,
.max_frequency = 1,
},
+
+ [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,
+ .addr = TCS3400_I2C_ADDR,
+ .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_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);
@@ -335,6 +399,8 @@ static void board_init(void)
gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
/* Enable gpio interrupt for camera vsync */
gpio_enable_interrupt(GPIO_WFCAM_VSYNC);
+ /* Enable interrupt for the TCS3400 color light sensor */
+ gpio_enable_interrupt(GPIO_TCS3400_INT_ODL);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/kohaku/board.h b/board/kohaku/board.h
index 58c1b6928f..bd29caa150 100644
--- a/board/kohaku/board.h
+++ b/board/kohaku/board.h
@@ -42,15 +42,23 @@
TASK_EVENT_MOTION_SENSOR_INTERRUPT(VSYNC)
/* BMA253 Lid accel */
#define CONFIG_ACCEL_BMA255
-#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(LID_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 */
+/* BH1730 and TCS3400 ALS */
#define CONFIG_ALS
-#define ALS_COUNT 1
+#define ALS_COUNT 2
+#define I2C_PORT_ALS I2C_PORT_SENSOR
#define CONFIG_ALS_BH1730
+#define CONFIG_ALS_TCS3400
+#define CONFIG_ALS_TCS3400_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS)
+
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK \
+ (BIT(LID_ACCEL) | BIT(LID_ALS) | BIT(CLEAR_ALS))
+
/* Parameter to calculate LUX on Kohaku */
/*
* TODO (b/130835790): These values are from Caroline. Do they need to be
@@ -140,6 +148,8 @@ enum sensor_id {
BASE_GYRO,
LID_ALS,
VSYNC,
+ CLEAR_ALS,
+ RGB_ALS,
SENSOR_COUNT,
};
diff --git a/board/kohaku/gpio.inc b/board/kohaku/gpio.inc
index e47c487ab4..257a5c493e 100644
--- a/board/kohaku/gpio.inc
+++ b/board/kohaku/gpio.inc
@@ -27,6 +27,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(WFCAM_VSYNC, PIN(B, 7), GPIO_INT_RISING , sync_interrupt)
+GPIO_INT(TCS3400_INT_ODL, PIN(7, 2), GPIO_INT_FALLING, tcs3400_interrupt)
/* USB-C interrupts */
GPIO_INT(USB_C0_PPC_INT_ODL, PIN(E, 0), GPIO_INT_FALLING, ppc_interrupt)
@@ -105,7 +106,6 @@ GPIO(I2C7_SCL, PIN(B, 3), GPIO_INPUT) /* EC_I2C_EEPROM
GPIO(I2C7_SDA, PIN(B, 2), GPIO_INPUT) /* EC_I2C_EEPROM_SDA */
/* NC / TP */
-GPIO(TP62, PIN(7, 2), GPIO_INPUT | GPIO_PULL_UP)
GPIO(TP58, PIN(0, 4), GPIO_INPUT | GPIO_PULL_UP)
GPIO(TP73, PIN(8, 2), GPIO_INPUT | GPIO_PULL_UP)
GPIO(TP18, PIN(C, 0), GPIO_INPUT | GPIO_PULL_UP)