diff options
-rw-r--r-- | board/zoombini/board.c | 56 | ||||
-rw-r--r-- | board/zoombini/board.h | 11 | ||||
-rw-r--r-- | board/zoombini/ec.tasklist | 2 |
3 files changed, 69 insertions, 0 deletions
diff --git a/board/zoombini/board.c b/board/zoombini/board.c index ea3fb89dca..f7f6a444b4 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -13,6 +13,7 @@ #include "common.h" #include "console.h" #include "compile_time_macros.h" +#include "driver/als_opt3001.h" #include "driver/pmic_tps650x30.h" #include "driver/ppc/sn5s330.h" #include "driver/tcpm/ps8xxx.h" @@ -26,6 +27,7 @@ #include "i2c.h" #include "keyboard_scan.h" #include "lid_switch.h" +#include "motion_sense.h" #include "power.h" #include "power_button.h" #include "pwm.h" @@ -182,6 +184,60 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); +static struct opt3001_drv_data_t g_opt3001_data = { + .scale = 1, + .uscale = 0, + .offset = 0, +}; + +struct motion_sensor_t motion_sensors[] = { + [LID_ALS] = { + .name = "Light", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_OPT3001, + .type = MOTIONSENSE_TYPE_LIGHT, + .location = MOTIONSENSE_LOC_LID, + .drv = &opt3001_drv, + .drv_data = &g_opt3001_data, + .port = I2C_PORT_SENSOR, + .addr = OPT3001_I2C_ADDR, + .rot_standard_ref = NULL, + .default_range = 0x10000, /* scale = 1; uscale = 0 */ + .min_frequency = OPT3001_LIGHT_MIN_FREQ, + .max_frequency = OPT3001_LIGHT_MAX_FREQ, + .config = { + /* AP: by default shutdown all sensors */ + [SENSOR_CONFIG_AP] = { + .odr = 0, + .ec_rate = 0, + }, + /* Run ALS sensor in S0 */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 1000, + .ec_rate = 0, + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 0, + .ec_rate = 0, + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 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[LID_ALS], +}; +BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); + +/* TODO(aaboagye): Add the other ports. 3 for Zoombini, 2 for Meowth */ const struct ppc_config_t ppc_chips[] = { { .i2c_port = I2C_PORT_TCPC0, diff --git a/board/zoombini/board.h b/board/zoombini/board.h index 20463624ee..b1c6f29dae 100644 --- a/board/zoombini/board.h +++ b/board/zoombini/board.h @@ -33,6 +33,11 @@ #define CONFIG_LPC #define CONFIG_PWM +/* TODO(aaboagye): Verify the right address. */ +#define CONFIG_ALS_OPT3001 +#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 +#define ALS_COUNT 1 + #define CONFIG_BACKLIGHT_LID #define CONFIG_BATTERY_CUT_OFF @@ -223,6 +228,12 @@ enum power_signal { POWER_SIGNAL_COUNT }; +enum sensor_id { + LID_ALS, +}; + +#define CONFIG_ACCEL_FORCE_MODE_MASK (1 << LID_ALS) + /* Reset all TCPCs. */ void board_reset_pd_mcu(void); diff --git a/board/zoombini/ec.tasklist b/board/zoombini/ec.tasklist index e1a96a4263..5d173b39b8 100644 --- a/board/zoombini/ec.tasklist +++ b/board/zoombini/ec.tasklist @@ -27,6 +27,7 @@ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 1, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P2, usb_charger_task, 2, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_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_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(PDCMD, pd_command_task, NULL, LARGER_TASK_STACK_SIZE) \ @@ -41,6 +42,7 @@ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_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_NOTEST(PDCMD, pd_command_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ |