diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-05-12 07:45:33 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-05-12 23:35:51 +0000 |
commit | a9a9ae1abc4ddb6a89ee0d29b88fbdd1d2ef67b1 (patch) | |
tree | 26b9855187a83412b181009031878826faab8b97 | |
parent | 39bd18b890bb708e79e9ba50dd3b5bf3d35e9ff1 (diff) | |
download | chrome-ec-a9a9ae1abc4ddb6a89ee0d29b88fbdd1d2ef67b1.tar.gz |
driver: Use common data structure to store default accel values
Move structure used by lms6ds0 to motion_sense.h,
so that bosh driver can use the same mechanism.
Use code to avoid reading chip range when reading data.
BUG=none
BRANCH=none
TEST=Check Bosh driver is working as expected.
Change-Id: Id8b5bb8735e479a122ef32ab9a400fba189d7488
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/270453
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/cyan/board.c | 42 | ||||
-rw-r--r-- | board/ryu_sh/board.c | 22 | ||||
-rw-r--r-- | board/samus/board.c | 24 | ||||
-rw-r--r-- | board/strago/board.c | 42 | ||||
-rw-r--r-- | common/motion_sense.c | 15 | ||||
-rw-r--r-- | driver/accel_kxcj9.c | 4 | ||||
-rw-r--r-- | driver/accelgyro_lsm6ds0.c | 33 | ||||
-rw-r--r-- | driver/accelgyro_lsm6ds0.h | 8 | ||||
-rw-r--r-- | include/motion_sense.h | 11 | ||||
-rw-r--r-- | test/motion_lid.c | 38 |
10 files changed, 156 insertions, 83 deletions
diff --git a/board/cyan/board.c b/board/cyan/board.c index 1118e4d5a8..90ffc7333a 100644 --- a/board/cyan/board.c +++ b/board/cyan/board.c @@ -109,14 +109,36 @@ const matrix_3x3_t lid_standard_ref = { }; struct motion_sensor_t motion_sensors[] = { - {SENSOR_ACTIVE_S0, "Base", MOTIONSENSE_CHIP_KXCJ9, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_BASE, - &kxcj9_drv, &g_kxcj9_mutex[0], &g_kxcj9_data[0], - KXCJ9_ADDR1, &base_standard_ref, 100000, 2}, - {SENSOR_ACTIVE_S0, "Lid", MOTIONSENSE_CHIP_KXCJ9, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_LID, - &kxcj9_drv, &g_kxcj9_mutex[1], &g_kxcj9_data[1], - KXCJ9_ADDR0, &lid_standard_ref, 100000, 2}, + {.name = "Base", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[0], + .drv_data = &g_kxcj9_data[0], + .i2c_addr = KXCJ9_ADDR1, + .rot_standard_ref = &base_standard_ref, + .default_config = { + .odr = 100000, + .range = 2 + } + }, + {.name = "Lid", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[1], + .drv_data = &g_kxcj9_data[1], + .i2c_addr = KXCJ9_ADDR0, + .rot_standard_ref = &lid_standard_ref, + .default_config = { + .odr = 100000, + .range = 2 + } + }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); @@ -151,8 +173,8 @@ static void motion_sensors_pre_init(void) sensor = &motion_sensors[i]; sensor->state = SENSOR_NOT_INITIALIZED; - sensor->odr = sensor->default_odr; - sensor->range = sensor->default_range; + sensor->runtime_config.odr = sensor->default_config.odr; + sensor->runtime_config.range = sensor->default_config.range; } } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sensors_pre_init, diff --git a/board/ryu_sh/board.c b/board/ryu_sh/board.c index 4e2f68f18a..dd2bb1fed6 100644 --- a/board/ryu_sh/board.c +++ b/board/ryu_sh/board.c @@ -37,8 +37,8 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); /* Sensor mutex */ static struct mutex g_mutex; -/* lsm6ds0 local sensor data (per-sensor) */ -struct lsm6ds0_data g_lsm6ds0_data[2]; +/* local sensor data (per-sensor) */ +struct motion_data_t g_saved_data[2]; struct motion_sensor_t motion_sensors[] = { @@ -54,11 +54,13 @@ struct motion_sensor_t motion_sensors[] = { .location = MOTIONSENSE_LOC_LID, .drv = &lsm6ds0_drv, .mutex = &g_mutex, - .drv_data = &g_lsm6ds0_data[0], + .drv_data = &g_saved_data[0], .i2c_addr = LSM6DS0_ADDR1, .rot_standard_ref = NULL, - .default_odr = 119000, - .default_range = 2 + .default_config = { + .odr = 119000, + .range = 2 + } }, {.name = "Gyro", @@ -68,11 +70,13 @@ struct motion_sensor_t motion_sensors[] = { .location = MOTIONSENSE_LOC_LID, .drv = &lsm6ds0_drv, .mutex = &g_mutex, - .drv_data = &g_lsm6ds0_data[1], + .drv_data = &g_saved_data[1], .i2c_addr = LSM6DS0_ADDR1, .rot_standard_ref = NULL, - .default_odr = 119000, - .default_range = 2000 + .default_config = { + .odr = 119000, + .range = 2000 + } }, }; @@ -82,7 +86,7 @@ const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); * Note: If a new sensor driver is added, make sure to update the following * assert. */ -BUILD_ASSERT(ARRAY_SIZE(motion_sensors) == ARRAY_SIZE(g_lsm6ds0_data)); +BUILD_ASSERT(ARRAY_SIZE(motion_sensors) == ARRAY_SIZE(g_saved_data)); void board_config_pre_init(void) { diff --git a/board/samus/board.c b/board/samus/board.c index 1222528959..909ba7eca3 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -262,7 +262,7 @@ static struct mutex g_lid_mutex; struct kxcj9_data g_kxcj9_data; /* lsm6ds0 local sensor data (per-sensor) */ -struct lsm6ds0_data g_lsm6ds0_data[2]; +struct motion_data_t g_saved_data[2]; /* Four Motion sensors */ /* Matrix to rotate accelrator into standard reference frame */ @@ -291,11 +291,13 @@ struct motion_sensor_t motion_sensors[] = { .location = MOTIONSENSE_LOC_BASE, .drv = &lsm6ds0_drv, .mutex = &g_base_mutex, - .drv_data = &g_lsm6ds0_data[0], + .drv_data = &g_saved_data[0], .i2c_addr = LSM6DS0_ADDR1, .rot_standard_ref = &base_standard_ref, - .default_odr = 119000, - .default_range = 2 + .default_config = { + .odr = 119000, + .range = 2 + } }, {.name = "Lid", @@ -308,8 +310,10 @@ struct motion_sensor_t motion_sensors[] = { .drv_data = &g_kxcj9_data, .i2c_addr = KXCJ9_ADDR0, .rot_standard_ref = &lid_standard_ref, - .default_odr = 100000, - .default_range = 2 + .default_config = { + .odr = 100000, + .range = 2 + } }, {.name = "Base Gyro", @@ -319,11 +323,13 @@ struct motion_sensor_t motion_sensors[] = { .location = MOTIONSENSE_LOC_BASE, .drv = &lsm6ds0_drv, .mutex = &g_base_mutex, - .drv_data = &g_lsm6ds0_data[1], + .drv_data = &g_saved_data[1], .i2c_addr = LSM6DS0_ADDR1, .rot_standard_ref = NULL, - .default_odr = 119000, - .default_range = 2000 + .default_config = { + .odr = 119000, + .range = 2000 + } }, }; diff --git a/board/strago/board.c b/board/strago/board.c index 2ed9b9c426..a18dd7ed78 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -123,14 +123,36 @@ const matrix_3x3_t lid_standard_ref = { }; struct motion_sensor_t motion_sensors[] = { - {SENSOR_ACTIVE_S0, "Base Accel", MOTIONSENSE_CHIP_KXCJ9, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_BASE, - &kxcj9_drv, &g_kxcj9_mutex[0], &g_kxcj9_data[0], - KXCJ9_ADDR1, &base_standard_ref, 100000, 2}, - {SENSOR_ACTIVE_S0, "Lid Accel", MOTIONSENSE_CHIP_KXCJ9, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_LID, - &kxcj9_drv, &g_kxcj9_mutex[1], &g_kxcj9_data[1], - KXCJ9_ADDR0, &lid_standard_ref, 100000, 2}, + {.name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[0], + .drv_data = &g_kxcj9_data[0], + .i2c_addr = KXCJ9_ADDR1, + .rot_standard_ref = &base_standard_ref, + .default_config = { + .odr = 100000, + .range = 2 + } + }, + {.name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[1], + .drv_data = &g_kxcj9_data[1], + .i2c_addr = KXCJ9_ADDR0, + .rot_standard_ref = &lid_standard_ref, + .default_config = { + .odr = 100000, + .range = 2 + } + }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); @@ -165,8 +187,8 @@ static void motion_sensors_pre_init(void) sensor = &motion_sensors[i]; sensor->state = SENSOR_NOT_INITIALIZED; - sensor->odr = sensor->default_odr; - sensor->range = sensor->default_range; + sensor->runtime_config.odr = sensor->default_config.odr; + sensor->runtime_config.range = sensor->default_config.range; } } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sensors_pre_init, diff --git a/common/motion_sense.c b/common/motion_sense.c index 0c1841b502..0ae21e5056 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -76,8 +76,8 @@ static void motion_sense_shutdown(void) for (i = 0; i < motion_sensor_count; i++) { sensor = &motion_sensors[i]; sensor->active = SENSOR_ACTIVE_S5; - sensor->odr = sensor->default_odr; - sensor->range = sensor->default_range; + sensor->runtime_config.odr = sensor->default_config.odr; + sensor->runtime_config.range = sensor->default_config.range; if ((sensor->state == SENSOR_INITIALIZED) && !(sensor->active_mask & sensor->active)) { sensor->drv->set_data_rate(sensor, 0, 0); @@ -127,7 +127,8 @@ static void motion_sense_resume(void) sensor->active = SENSOR_ACTIVE_S0; if (sensor->state == SENSOR_INITIALIZED) { /* Put back the odr previously set. */ - sensor->drv->set_data_rate(sensor, sensor->odr, 1); + sensor->drv->set_data_rate(sensor, + sensor->runtime_config.odr, 1); } } } @@ -233,8 +234,8 @@ void motion_sense_task(void) sensor = &motion_sensors[i]; sensor->state = SENSOR_NOT_INITIALIZED; - sensor->odr = sensor->default_odr; - sensor->range = sensor->default_range; + sensor->runtime_config.odr = sensor->default_config.odr; + sensor->runtime_config.range = sensor->default_config.range; } set_present(lpc_status); @@ -443,7 +444,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) sensor->drv->get_data_rate(sensor, &data); /* Save configuration parameter: ODR */ - sensor->odr = data; + sensor->runtime_config.odr = data; out->sensor_odr.ret = data; args->response_size = sizeof(out->sensor_odr); @@ -471,7 +472,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) sensor->drv->get_range(sensor, &data); /* Save configuration parameter: range */ - sensor->range = data; + sensor->runtime_config.range = data; out->sensor_range.ret = data; args->response_size = sizeof(out->sensor_range); diff --git a/driver/accel_kxcj9.c b/driver/accel_kxcj9.c index aa2a8ed9c5..26a737175c 100644 --- a/driver/accel_kxcj9.c +++ b/driver/accel_kxcj9.c @@ -504,7 +504,7 @@ static int init(const struct motion_sensor_t *s) } } while (1); - ret = set_range(s, s->range, 1); + ret = set_range(s, s->runtime_config.range, 1); if (ret != EC_SUCCESS) return ret; @@ -512,7 +512,7 @@ static int init(const struct motion_sensor_t *s) if (ret != EC_SUCCESS) return ret; - ret = set_data_rate(s, s->odr, 1); + ret = set_data_rate(s, s->runtime_config.odr, 1); if (ret != EC_SUCCESS) return ret; diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c index a93166c1de..47f243eb44 100644 --- a/driver/accelgyro_lsm6ds0.c +++ b/driver/accelgyro_lsm6ds0.c @@ -169,7 +169,7 @@ static int set_range(const struct motion_sensor_t *s, int ret, ctrl_val, range_tbl_size; uint8_t ctrl_reg, reg_val; const struct accel_param_pair *ranges; - struct lsm6ds0_data *data = (struct lsm6ds0_data *)s->drv_data; + struct motion_data_t *data = (struct motion_data_t *)s->drv_data; ctrl_reg = get_ctrl_reg(s->type); ranges = get_range_table(s->type, &range_tbl_size); @@ -191,20 +191,20 @@ static int set_range(const struct motion_sensor_t *s, /* Now that we have set the range, update the driver's value. */ if (ret == EC_SUCCESS) - data->sensor_range = get_engineering_val(reg_val, ranges, - range_tbl_size); + data->range = get_engineering_val(reg_val, ranges, + range_tbl_size); accel_cleanup: mutex_unlock(s->mutex); - return EC_SUCCESS; + return ret; } static int get_range(const struct motion_sensor_t *s, int *range) { - struct lsm6ds0_data *data = (struct lsm6ds0_data *)s->drv_data; + struct motion_data_t *data = (struct motion_data_t *)s->drv_data; - *range = data->sensor_range; + *range = data->range; return EC_SUCCESS; } @@ -230,7 +230,7 @@ static int set_data_rate(const struct motion_sensor_t *s, int ret, val, odr_tbl_size; uint8_t ctrl_reg, reg_val; const struct accel_param_pair *data_rates; - struct lsm6ds0_data *data = s->drv_data; + struct motion_data_t *data = s->drv_data; ctrl_reg = get_ctrl_reg(s->type); data_rates = get_odr_table(s->type, &odr_tbl_size); @@ -251,7 +251,7 @@ static int set_data_rate(const struct motion_sensor_t *s, /* Now that we have set the odr, update the driver's value. */ if (ret == EC_SUCCESS) - data->sensor_odr = get_engineering_val(reg_val, data_rates, + data->odr = get_engineering_val(reg_val, data_rates, odr_tbl_size); /* CTRL_REG3_G 12h @@ -274,15 +274,15 @@ static int set_data_rate(const struct motion_sensor_t *s, accel_cleanup: mutex_unlock(s->mutex); - return EC_SUCCESS; + return ret; } static int get_data_rate(const struct motion_sensor_t *s, int *rate) { - struct lsm6ds0_data *data = s->drv_data; + struct motion_data_t *data = s->drv_data; - *rate = data->sensor_odr; + *rate = data->odr; return EC_SUCCESS; } @@ -420,29 +420,30 @@ static int init(const struct motion_sensor_t *s) if (ret) return EC_ERROR_UNKNOWN; - ret = set_range(s, s->range, 1); + ret = set_range(s, s->runtime_config.range, 1); if (ret) return EC_ERROR_UNKNOWN; - ret = set_data_rate(s, s->odr, 1); + ret = set_data_rate(s, s->runtime_config.odr, 1); if (ret) return EC_ERROR_UNKNOWN; } if (MOTIONSENSE_TYPE_GYRO == s->type) { /* Config GYRO Range */ - ret = set_range(s, s->range, 1); + ret = set_range(s, s->runtime_config.range, 1); if (ret) return EC_ERROR_UNKNOWN; /* Config ACCEL & GYRO ODR */ - ret = set_data_rate(s, s->odr, 1); + ret = set_data_rate(s, s->runtime_config.odr, 1); if (ret) return EC_ERROR_UNKNOWN; } CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n", - s->name, s->type, s->range, s->odr); + s->name, s->type, s->runtime_config.range, + s->runtime_config.odr); return ret; } diff --git a/driver/accelgyro_lsm6ds0.h b/driver/accelgyro_lsm6ds0.h index 9f8953395d..c71fc37767 100644 --- a/driver/accelgyro_lsm6ds0.h +++ b/driver/accelgyro_lsm6ds0.h @@ -116,14 +116,6 @@ enum lsm6ds0_bdu { /* Sensor resolution in number of bits. This sensor has fixed resolution. */ #define LSM6DS0_RESOLUTION 16 -/* Run-time configurable parameters */ -struct lsm6ds0_data { - /* Current range */ - int sensor_range; - /* Current output data rate */ - int sensor_odr; -}; - extern const struct accelgyro_drv lsm6ds0_drv; #endif /* __CROS_EC_ACCEL_LSM6DS0_H */ diff --git a/include/motion_sense.h b/include/motion_sense.h index 9f971bb184..bdbd7b238c 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -26,6 +26,11 @@ enum sensor_state { #define SENSOR_ACTIVE_S0_S3 (SENSOR_ACTIVE_S3 | SENSOR_ACTIVE_S0) #define SENSOR_ACTIVE_S0_S3_S5 (SENSOR_ACTIVE_S0_S3 | SENSOR_ACTIVE_S5) +struct motion_data_t { + int odr; + int range; +}; + struct motion_sensor_t { /* RO fields */ uint32_t active_mask; @@ -40,12 +45,10 @@ struct motion_sensor_t { const matrix_3x3_t *rot_standard_ref; /* Default configuration parameters, RO only */ - int default_odr; - int default_range; + struct motion_data_t default_config; /* Run-Time configuration parameters */ - int odr; - int range; + struct motion_data_t runtime_config; /* state parameters */ enum sensor_state state; diff --git a/test/motion_lid.c b/test/motion_lid.c index a358a5056c..78ef019853 100644 --- a/test/motion_lid.c +++ b/test/motion_lid.c @@ -102,14 +102,36 @@ const matrix_3x3_t lid_standard_ref = { }; struct motion_sensor_t motion_sensors[] = { - {SENSOR_ACTIVE_S0_S3_S5, "base", MOTIONSENSE_CHIP_LSM6DS0, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_BASE, - &test_motion_sense, NULL, NULL, - 0, &base_standard_ref, 119000, 2}, - {SENSOR_ACTIVE_S0, "lid", MOTIONSENSE_CHIP_KXCJ9, - MOTIONSENSE_TYPE_ACCEL, MOTIONSENSE_LOC_LID, - &test_motion_sense, NULL, NULL, - 0, &lid_standard_ref, 100000, 2}, + {.name = "base", + .active_mask = SENSOR_ACTIVE_S0_S3_S5, + .chip = MOTIONSENSE_CHIP_LSM6DS0, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &test_motion_sense, + .mutex = NULL, + .drv_data = NULL, + .i2c_addr = 0, + .rot_standard_ref = &base_standard_ref, + .default_config = { + .odr = 119000, + .range = 2 + } + }, + {.name = "base", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &test_motion_sense, + .mutex = NULL, + .drv_data = NULL, + .i2c_addr = 0, + .rot_standard_ref = &lid_standard_ref, + .default_config = { + .odr = 119000, + .range = 2 + } + }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); |