summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSue Chen <sue.chen@quanta.corp-partner.google.com>2021-07-22 15:40:53 +0800
committerCommit Bot <commit-bot@chromium.org>2021-10-13 17:18:51 +0000
commitd72a1796e9b1ba8c722d2d323bf2544b8151d610 (patch)
tree62ad31a59149e8320ea719c7ee8fb8cab88ae211
parentfc03a9789d7db2dead547bbe7d885f44ce16af32 (diff)
downloadchrome-ec-d72a1796e9b1ba8c722d2d323bf2544b8151d610.tar.gz
Scout: Add light sensor ALS TCS3400
Enable interrupt pin EC_RGB_INT_L and motion_sense_task to read light sensor als_tcs3400 data. BUG=b:187667126 BRANCH=puff TEST="ectool motionsense" can read data from tcs3400. Signed-off-by: Sue Chen <sue.chen@quanta.corp-partner.google.com> Change-Id: I498c58b2c3309c66dfa9c8bc76bb4b7da1179a3b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3045025 Tested-by: Joe Tessler <jrt@chromium.org> Reviewed-by: Joe Tessler <jrt@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Joe Tessler <jrt@chromium.org> (cherry picked from commit 425146285cd32817f3db6b58a649067173e90aee) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219977
-rw-r--r--board/scout/board.c106
-rw-r--r--board/scout/board.h26
-rw-r--r--board/scout/ec.tasklist1
-rw-r--r--board/scout/gpio.inc6
4 files changed, 135 insertions, 4 deletions
diff --git a/board/scout/board.c b/board/scout/board.c
index b917020791..d679fe416a 100644
--- a/board/scout/board.c
+++ b/board/scout/board.c
@@ -5,6 +5,7 @@
/* Puff board-specific configuration */
+#include "accelgyro.h"
#include "adc.h"
#include "adc_chip.h"
#include "button.h"
@@ -12,6 +13,7 @@
#include "common.h"
#include "core/cortex-m/cpu.h"
#include "cros_board_info.h"
+#include "driver/als_tcs3400.h"
#include "driver/ina3221.h"
#include "ec_commands.h"
#include "extpower.h"
@@ -40,6 +42,110 @@
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
+/* Sensors */
+
+/* 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 = {
+ /*
+ * b/202465034: calculate the actual coefficients and scaling factors
+ */
+ .calibration.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),
+ },
+ .calibration.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),
+ },
+ .calibration.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),
+ },
+ .calibration.irt = INT_TO_FP(1),
+ .saturation.again = TCS_DEFAULT_AGAIN,
+ .saturation.atime = TCS_DEFAULT_ATIME,
+};
+
+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_BASE,
+ .drv = &tcs3400_drv,
+ .drv_data = &g_tcs3400_data,
+ .port = I2C_PORT_SENSORS,
+ .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] = {
+ .name = "RGB Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT_RGB,
+ .location = MOTIONSENSE_LOC_BASE,
+ .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 board_sensors_init(void)
+{
+ /* Enable interrupt for the TCS3400 color light sensor */
+ gpio_enable_interrupt(GPIO_EC_RGB_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_sensors_init, HOOK_PRIO_INIT_I2C + 1);
+
static void power_monitor(void);
DECLARE_DEFERRED(power_monitor);
diff --git a/board/scout/board.h b/board/scout/board.h
index 1d141b0166..e5b1b48e0d 100644
--- a/board/scout/board.h
+++ b/board/scout/board.h
@@ -52,6 +52,26 @@
#define CONFIG_SUPPRESSED_HOST_COMMANDS \
EC_CMD_CONSOLE_SNAPSHOT, EC_CMD_CONSOLE_READ, EC_CMD_PD_GET_LOG_ENTRY
+/* Sensor */
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_CMD_ACCEL_INFO
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
+/* FIFO size is in power of 2. */
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
+
+/* 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)
+
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(CLEAR_ALS)
+
/* EC Commands */
#define CONFIG_CMD_BUTTON
/* Include CLI command needed to support CCD testing. */
@@ -125,6 +145,7 @@
#define I2C_PORT_INA NPCX_I2C_PORT0_0
#define I2C_PORT_PPC0 NPCX_I2C_PORT1_0
#define I2C_PORT_SCALER NPCX_I2C_PORT2_0
+#define I2C_PORT_SENSORS NPCX_I2C_PORT3_0
#define I2C_PORT_TCPC0 NPCX_I2C_PORT3_0
#define I2C_PORT_POWER NPCX_I2C_PORT5_0
#define I2C_PORT_EEPROM NPCX_I2C_PORT7_0
@@ -174,6 +195,11 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
+enum sensor_id {
+ CLEAR_ALS,
+ RGB_ALS,
+ SENSOR_COUNT,
+};
/* Board specific handlers */
void board_reset_pd_mcu(void);
diff --git a/board/scout/ec.tasklist b/board/scout/ec.tasklist
index 787ffbf479..0e4ec4d284 100644
--- a/board/scout/ec.tasklist
+++ b/board/scout/ec.tasklist
@@ -9,6 +9,7 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, 2048) \
TASK_ALWAYS(POWERBTN, power_button_task, NULL, LARGER_TASK_STACK_SIZE) \
diff --git a/board/scout/gpio.inc b/board/scout/gpio.inc
index af8fbfb25b..e34fe3dadb 100644
--- a/board/scout/gpio.inc
+++ b/board/scout/gpio.inc
@@ -36,7 +36,8 @@ GPIO_INT(SLP_S3_L, PIN(A, 5), GPIO_INT_BOTH, slp_s3_interrupt)
GPIO_INT(PG_PP950_VCCIO_OD, PIN(1, 7), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(SLP_S0_L, PIN(D, 5), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(IMVP8_VRRDY_OD, PIN(1, 6), GPIO_INT_BOTH, power_signal_interrupt)
-
+/* ALS signals */
+GPIO_INT(EC_RGB_INT_L, PIN(9, 7), GPIO_INT_FALLING | GPIO_SEL_1P8V, tcs3400_interrupt)
/*
* Directly connected recovery button (not available on some boards).
*/
@@ -71,9 +72,6 @@ GPIO(BOOT_IND_EC, PIN(E, 2), GPIO_INPUT)
/* TSUM scaler signals */
GPIO(TSUM_WAKEUP_EC, PIN(B, 1), GPIO_INPUT)
-/* ALS signals */
-GPIO(EC_RGB_INT_L, PIN(9, 7), GPIO_INPUT)
-
/* Power control outputs */
GPIO(EN_PP5000_A, PIN(A, 4), GPIO_OUT_LOW)
GPIO(EN_PP3300_INA_H1_EC_ODL, PIN(5, 7), GPIO_ODR_HIGH)