diff options
author | Marco Chen <marcochen@chromium.org> | 2017-11-16 14:12:43 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-11-26 05:21:39 -0800 |
commit | a2e2be193a46826fa6af7fbaab0e567e248e40b4 (patch) | |
tree | 45081aa3e8896b9cbd1764fbf7ca831b31c499d0 /board | |
parent | f326fb05b564b0975a9870b2831f9372539202db (diff) | |
download | chrome-ec-a2e2be193a46826fa6af7fbaab0e567e248e40b4.tar.gz |
OPT3001: Support MOTIONSENSE_CMD_SENSOR_[OFFSET|RANGE] for calibration.
1. The original driver of OPT3001
a. didn't support to process the command of offset.
b. implemented command of range to setter/getter of Range Number Field
of chip.
But reffering to cros_ec_light_prox.c from linux kernel side, these two
commands are actually leveraged for in_illuminance_calib[bias|scale]
and these calibration factors should be applied into raw lux value read
from the chip.
2. Move ALS in Poppy / Soraka boards from ALS_TASK to MOTIONSENSE_TASK.
3. Mofify parameters of ALS in Reef board in order to adapt changes
here.
BUG=b:69236269
BRANCH=none
TEST=Manually test on the DUT.
Change-Id: Ic3b593feb3e4bc6da0bada6b5d614975f0cf2280
Signed-off-by: Marco Chen <marcochen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/774341
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board')
-rw-r--r-- | board/poppy/board.c | 58 | ||||
-rw-r--r-- | board/poppy/board.h | 7 | ||||
-rw-r--r-- | board/poppy/ec.tasklist | 1 | ||||
-rw-r--r-- | board/reef/board.c | 6 |
4 files changed, 53 insertions, 19 deletions
diff --git a/board/poppy/board.c b/board/poppy/board.c index 6d87057ee2..09327c9801 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -534,17 +534,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -/* ALS instances. Must be in same order as enum als_id. */ -struct als_t als[] = { - /* - * attenuation_factor is set to 1 because there would be a calibration - * in iio framework of kernel which would be configured in factory - * flow. - */ - {"TI", opt3001_init, opt3001_read_lux, 1}, -}; -BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], @@ -853,6 +842,11 @@ int board_get_version(void) static struct mutex g_lid_mutex; static struct bmi160_drv_data_t g_bmi160_data; +static struct opt3001_drv_data_t g_opt3001_data = { + .scale = 1, + .uscale = 0, + .offset = 0, +}; /* Matrix to rotate accelrator into standard reference frame */ const matrix_3x3_t mag_standard_ref = { @@ -999,9 +993,51 @@ 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_ALS, + .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, + }, + [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); + #ifdef BOARD_SORAKA static void board_sensor_init(void) { diff --git a/board/poppy/board.h b/board/poppy/board.h index 245f8027d0..95050f8700 100644 --- a/board/poppy/board.h +++ b/board/poppy/board.h @@ -102,6 +102,7 @@ /* Sensor */ #define CONFIG_ALS #define CONFIG_ALS_OPT3001 +#define ALS_COUNT 1 #define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 #define CONFIG_TEMP_SENSOR #define CONFIG_TEMP_SENSOR_BD99992GW @@ -208,11 +209,6 @@ enum temp_sensor_id { TEMP_SENSOR_COUNT }; -enum als_id { - ALS_OPT3001, - ALS_COUNT -}; - /* * Motion sensors: * When reading through IO memory is set up for sensors (LPC is used), @@ -223,6 +219,7 @@ enum sensor_id { LID_ACCEL = 0, LID_GYRO, LID_MAG, + LID_ALS, }; enum adc_channel { diff --git a/board/poppy/ec.tasklist b/board/poppy/ec.tasklist index 376ac1965e..53c97a0cb5 100644 --- a/board/poppy/ec.tasklist +++ b/board/poppy/ec.tasklist @@ -22,7 +22,6 @@ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(ALS, als_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ diff --git a/board/reef/board.c b/board/reef/board.c index 43bee25318..fa16408e21 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -783,7 +783,9 @@ static struct kionix_accel_data g_kx022_data; static struct bmi160_drv_data_t g_bmi160_data; static struct bmp280_drv_data_t bmp280_drv_data; static struct opt3001_drv_data_t g_opt3001_data = { - .attenuation = 5, + .scale = 1, + .uscale = 0, + .offset = 0, }; /* FIXME(dhendrix): Copied from Amenia, probably need to tweak for Reef */ @@ -990,7 +992,7 @@ struct motion_sensor_t motion_sensors[] = { .port = I2C_PORT_ALS, .addr = OPT3001_I2C_ADDR1, .rot_standard_ref = NULL, - .default_range = OPT3001_RANGE_AUTOMATIC_FULL_SCALE, + .default_range = 0x10000, /* scale = 1; uscale = 0 */ .min_frequency = OPT3001_LIGHT_MIN_FREQ, .max_frequency = OPT3001_LIGHT_MAX_FREQ, .config = { |