diff options
Diffstat (limited to 'board/dooly')
-rw-r--r-- | board/dooly/board.c | 128 | ||||
-rw-r--r-- | board/dooly/board.h | 36 | ||||
-rw-r--r-- | board/dooly/ec.tasklist | 1 | ||||
-rw-r--r-- | board/dooly/gpio.inc | 5 |
4 files changed, 169 insertions, 1 deletions
diff --git a/board/dooly/board.c b/board/dooly/board.c index 8c1c295a66..b78eaced73 100644 --- a/board/dooly/board.c +++ b/board/dooly/board.c @@ -5,6 +5,7 @@ /* Dooly board-specific configuration */ +#include "accelgyro.h" #include "adc.h" #include "adc_chip.h" #include "button.h" @@ -14,6 +15,8 @@ #include "common.h" #include "core/cortex-m/cpu.h" #include "cros_board_info.h" +#include "driver/accel_bma2x2.h" +#include "driver/als_tcs3400.h" #include "driver/ina3221.h" #include "driver/led/oz554.h" #include "driver/ppc/sn5s330.h" @@ -50,6 +53,128 @@ #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) +/* Sensors */ +static struct mutex g_accel_mutex; +static struct accelgyro_saved_data_t g_bma253_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, + .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 = { + /* + * TODO: 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[] = { + [SCREEN_ACCEL] = { + .name = "Screen Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMA255, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &bma2x2_accel_drv, + .mutex = &g_accel_mutex, + .drv_data = &g_bma253_data, + .port = I2C_PORT_SENSORS, + .i2c_spi_addr_flags = BMA2x2_I2C_ADDR2_FLAGS, + .rot_standard_ref = NULL, + .default_range = 2, + .min_frequency = BMA255_ACCEL_MIN_FREQ, + .max_frequency = BMA255_ACCEL_MAX_FREQ, + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + [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_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_LID, + .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 power_monitor(void); DECLARE_DEFERRED(power_monitor); @@ -510,6 +635,9 @@ static void board_init(void) gpio_enable_interrupt(GPIO_BJ_ADP_PRESENT_L); + /* Enable interrupt for the TCS3400 color light sensor */ + gpio_enable_interrupt(GPIO_ALS_GSENSOR_INT_ODL); + /* Always claim AC is online, because we don't have a battery. */ memmap_batt_flags = host_get_memmap(EC_MEMMAP_BATT_FLAG); *memmap_batt_flags |= EC_BATT_FLAG_AC_PRESENT; diff --git a/board/dooly/board.h b/board/dooly/board.h index 3ea5583766..b49c6457cf 100644 --- a/board/dooly/board.h +++ b/board/dooly/board.h @@ -20,6 +20,34 @@ #define CONFIG_SPI_FLASH_REGS #define CONFIG_SPI_FLASH_W25Q80 /* Internal SPI flash type. */ +/* Sensor */ +#define CONFIG_ACCEL_INTERRUPTS +#define CONFIG_ALS_TCS3400_EMULATED_IRQ_EVENT +#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) + +/* BMA253 accelerometer */ +#define CONFIG_ACCEL_BMA255 +#define CONFIG_CMD_ACCELS + +/* 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(SCREEN_ACCEL) | BIT(CLEAR_ALS)) + +#define CONFIG_LID_ANGLE_SENSOR_LID SCREEN_ACCEL + /* EC Defines */ #define CONFIG_ADC #define CONFIG_BOARD_HAS_RTC_RESET @@ -173,6 +201,7 @@ #define CONFIG_I2C #define CONFIG_I2C_MASTER #define I2C_PORT_INA NPCX_I2C_PORT0_0 +#define I2C_PORT_SENSORS NPCX_I2C_PORT0_0 #define I2C_PORT_PPC0 NPCX_I2C_PORT1_0 #define I2C_PORT_PPC1 NPCX_I2C_PORT2_0 #define I2C_PORT_TCPC0 NPCX_I2C_PORT3_0 @@ -236,6 +265,13 @@ enum temp_sensor_id { TEMP_SENSOR_COUNT }; +enum sensor_id { + SCREEN_ACCEL = 0, + CLEAR_ALS, + RGB_ALS, + SENSOR_COUNT, +}; + /* Board specific handlers */ void board_reset_pd_mcu(void); diff --git a/board/dooly/ec.tasklist b/board/dooly/ec.tasklist index 5d42008105..72b81be8d8 100644 --- a/board/dooly/ec.tasklist +++ b/board/dooly/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/dooly/gpio.inc b/board/dooly/gpio.inc index aed8bedd82..d2e0fe4f80 100644 --- a/board/dooly/gpio.inc +++ b/board/dooly/gpio.inc @@ -43,6 +43,10 @@ GPIO_INT(USB_C0_TCPC_INT_ODL, PIN(6, 2), GPIO_INT_FALLING, tcpc_alert_event) GPIO_INT(USB_C1_TCPPC_INT_ODL, PIN(A, 2), GPIO_INT_FALLING, ppc_interrupt) GPIO_INT(USB_C1_TCPC_INT_ODL, PIN(E, 4), GPIO_INT_FALLING, tcpc_alert_event) GPIO_INT(PANEL_BACKLIGHT_EN, PIN(B, 1), GPIO_INT_RISING, backlight_enable_interrupt) + +/* Sensor Interrupts */ +GPIO_INT(ALS_GSENSOR_INT_ODL, PIN(9, 6), GPIO_INT_FALLING, tcs3400_interrupt) + /* * Directly connected recovery button. */ @@ -151,7 +155,6 @@ UNUSED(PIN(D, 3)) /* E9 TP55 */ UNUSED(PIN(9, 5)) /* H10 TP54 */ UNUSED(PIN(4, 0)) /* E4 TP56 */ UNUSED(PIN(5, 0)) /* G4 NC */ -UNUSED(PIN(9, 6)) /* M12 TP998 */ UNUSED(PIN(0, 7)) /* E8 TP991 */ UNUSED(PIN(0, 6)) /* B10 TP992 */ UNUSED(PIN(D, 6)) /* F6 */ |