summaryrefslogtreecommitdiff
path: root/board/kukui
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2019-05-24 15:28:52 +0800
committerCommit Bot <commit-bot@chromium.org>2019-06-25 07:02:10 +0000
commit494330077071487009cab05809deb96aaf337421 (patch)
treef989e83b0fea66c446125cc7661f2f625967f9d8 /board/kukui
parentae22b703601122b14005dd1afadd327939b5dfab (diff)
downloadchrome-ec-494330077071487009cab05809deb96aaf337421.tar.gz
krane: enable TCS3400 ALS sensor
BUG=b:129419982 TEST=Combined with CL:1621449, run ectool motionsense. BRANCH=None Change-Id: I028f9a286ba96d7813bb76ba5e1e5235955e40b3 Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1628630 Reviewed-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Nick Vaccaro <nvaccaro@google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'board/kukui')
-rw-r--r--board/kukui/board.c65
-rw-r--r--board/kukui/board.h11
2 files changed, 76 insertions, 0 deletions
diff --git a/board/kukui/board.c b/board/kukui/board.c
index 53bd3f6222..70f89c5149 100644
--- a/board/kukui/board.c
+++ b/board/kukui/board.c
@@ -15,6 +15,7 @@
#include "common.h"
#include "console.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/als_tcs3400.h"
#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/rt946x.h"
@@ -80,6 +81,7 @@ const struct i2c_port_t i2c_ports[] = {
{"battery", I2C_PORT_BATTERY, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
{"accelgyro", I2C_PORT_ACCEL, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
{"bc12", I2C_PORT_BC12, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"als", I2C_PORT_ALS, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
@@ -431,9 +433,33 @@ int board_get_version(void)
/* Mutexes */
#ifdef SECTION_IS_RW
static struct mutex g_lid_mutex;
+static struct mutex g_als_mutex;
static struct bmi160_drv_data_t g_bmi160_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,
+ },
+};
+
#ifdef BOARD_KRANE
/* Matrix to rotate accelerometer into standard reference frame */
static const mat33_fp_t lid_standard_ref_rev3 = {
@@ -522,6 +548,42 @@ struct motion_sensor_t motion_sensors[] = {
.max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
},
#endif /* CONFIG_MAG_BMI160_BMM150 */
+ [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,
+ .mutex = &g_als_mutex,
+ .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] = {
+ .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,
@@ -535,6 +597,9 @@ struct motion_sensor_t motion_sensors[] = {
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+const struct motion_sensor_t *motion_als_sensors[] = {
+ &motion_sensors[CLEAR_ALS],
+};
#endif /* SECTION_IS_RW */
diff --git a/board/kukui/board.h b/board/kukui/board.h
index a42342bc1f..39e1260324 100644
--- a/board/kukui/board.h
+++ b/board/kukui/board.h
@@ -97,6 +97,14 @@
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
+#define CONFIG_ALS
+
+#define ALS_COUNT 1
+#define CONFIG_ALS_TCS3400
+#define CONFIG_ALS_TCS3400_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS)
+#define CONFIG_ALS_TCS3400_EMULATED_IRQ_EVENT
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(CLEAR_ALS)
/* Camera VSYNC */
#define CONFIG_SYNC
@@ -209,6 +217,7 @@
#define I2C_PORT_VIRTUAL_BATTERY I2C_PORT_BATTERY
#define I2C_PORT_ACCEL 1
#define I2C_PORT_BC12 1
+#define I2C_PORT_ALS 1
/* Route sbs host requests to virtual battery driver */
#define VIRTUAL_BATTERY_ADDR 0x16
@@ -251,6 +260,8 @@ enum sensor_id {
#ifdef CONFIG_MAG_BMI160_BMM150
LID_MAG,
#endif /* CONFIG_MAG_BMI160_BMM150 */
+ CLEAR_ALS,
+ RGB_ALS,
VSYNC,
SENSOR_COUNT,
};