summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@chromium.org>2017-04-25 19:09:03 -0700
committerCommit Bot <commit-bot@chromium.org>2019-12-19 08:22:39 +0000
commit2420d1a23918a77aac869b3dc06616f534a69c44 (patch)
tree7564cee4de7124ad88cabb081fe1b3ffc53c2f20
parent53c7235bba5e2bdb3fcb96df1e5920d8589ac6bd (diff)
downloadchrome-ec-2420d1a23918a77aac869b3dc06616f534a69c44.tar.gz
common: sensors: add extra sensor attributes
Adds min_frequency and max_frequency to struct motion_sensor_t. New attributes min_frequency and max_frequency are now returned in ectool's MOTIONSENSE_CMD_INFO response. Incremented ectool's MOTIONSENSE_CMD_INFO version to version 3. Add constants for MIN_FREQUENCY and MAX_FREQUENCY to each sensor's header file. BRANCH=none BUG=chromium:615059 TEST=build/boot and verify MOTIONSENSE_CMD_INFO response on kevin, make buildall -j passes. Conflicts: board/elm/board.c board/eve/board.c board/glados/board.c board/kahlee/board.c board/kevin/board.c board/oak/board.c board/poppy/board.c board/reef/board.c board/rowan/board.c board/ryu/board.c board/samus/board.c board/wheatley/board.c driver/accel_bma2x2.h driver/accelgyro_bmi160.h driver/als_opt3001.h driver/als_si114x.h driver/baro_bmp280.h driver/mag_bmm150.h : Files not in branch include/util.h : Comment fix. Add changes in ultima/board.c Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/482703 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Change-Id: I66db9715c122ef6bb4665ad5d086a9ecc9c7c93a Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1874635
-rw-r--r--board/strago/board.c4
-rw-r--r--board/ultima/board.c4
-rw-r--r--common/motion_sense.c19
-rw-r--r--driver/accel_kx022.h4
-rw-r--r--driver/accel_kxcj9.h4
-rw-r--r--driver/accelgyro_lsm6ds0.h6
-rw-r--r--driver/gyro_l3gd20h.h4
-rw-r--r--include/common.h3
-rw-r--r--include/config.h3
-rw-r--r--include/ec_commands.h24
-rw-r--r--include/motion_sense.h14
-rw-r--r--include/util.h2
-rw-r--r--util/ectool.c32
13 files changed, 113 insertions, 10 deletions
diff --git a/board/strago/board.c b/board/strago/board.c
index 3d0df634ae..6c1b5d7ab8 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -151,6 +151,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KXCJ9_ADDR1,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KXCJ9_ACCEL_MIN_FREQ,
+ .max_frequency = KXCJ9_ACCEL_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
@@ -187,6 +189,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KXCJ9_ADDR0,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KXCJ9_ACCEL_MIN_FREQ,
+ .max_frequency = KXCJ9_ACCEL_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/board/ultima/board.c b/board/ultima/board.c
index e2731faf54..9fa5a414c4 100644
--- a/board/ultima/board.c
+++ b/board/ultima/board.c
@@ -141,6 +141,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KXCJ9_ADDR1,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KXCJ9_ACCEL_MIN_FREQ,
+ .max_frequency = KXCJ9_ACCEL_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
@@ -177,6 +179,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KXCJ9_ADDR0,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KXCJ9_ACCEL_MIN_FREQ,
+ .max_frequency = KXCJ9_ACCEL_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/common/motion_sense.c b/common/motion_sense.c
index f58cdfa75a..ceee5af99b 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -951,10 +951,23 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
else
#endif
out->info.type = sensor->type;
+
out->info.location = sensor->location;
out->info.chip = sensor->chip;
-
- args->response_size = sizeof(out->info);
+ if (args->version >= 3) {
+ out->info_3.min_frequency = sensor->min_frequency;
+ /*
+ * Make sure reported max frequency for this sensor
+ * doesn't exceed the max sensor frequency the EC is
+ * capable of supporting
+ */
+ out->info_3.max_frequency = MIN(sensor->max_frequency,
+ CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ);
+ out->info_3.fifo_max_event_count = MAX_FIFO_EVENT_COUNT;
+ args->response_size = sizeof(out->info_3);
+ } else {
+ args->response_size = sizeof(out->info);
+ }
break;
case MOTIONSENSE_CMD_EC_RATE:
@@ -1206,7 +1219,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_MOTION_SENSE_CMD,
host_cmd_motion_sense,
- EC_VER_MASK(1) | EC_VER_MASK(2));
+ EC_VER_MASK(1) | EC_VER_MASK(2) | EC_VER_MASK(3));
/*****************************************************************************/
/* Console commands */
diff --git a/driver/accel_kx022.h b/driver/accel_kx022.h
index d25d68b380..7b1ea89c43 100644
--- a/driver/accel_kx022.h
+++ b/driver/accel_kx022.h
@@ -120,4 +120,8 @@
#define KX022_INC2_XPWUE (1 << 4)
#define KX022_INC2_XNWUE (1 << 5)
+/* Min and Max sampling frequency in mHz */
+#define KX022_ACCEL_MIN_FREQ 781
+#define KX022_ACCEL_MAX_FREQ 1600000
+
#endif /* __CROS_EC_ACCEL_KX022_H */
diff --git a/driver/accel_kxcj9.h b/driver/accel_kxcj9.h
index 368b7e50cb..210e68b64f 100644
--- a/driver/accel_kxcj9.h
+++ b/driver/accel_kxcj9.h
@@ -104,4 +104,8 @@
#define KXCJ9_OSA_1600_HZ 7
#define KXCJ9_OSA_FIELD 0xf
+/* Min and Max sampling frequency in mHz */
+#define KXCJ9_ACCEL_MIN_FREQ 781
+#define KXCJ9_ACCEL_MAX_FREQ 1600000
+
#endif /* __CROS_EC_ACCEL_KXCJ9_H */
diff --git a/driver/accelgyro_lsm6ds0.h b/driver/accelgyro_lsm6ds0.h
index 046b30d7be..f1e2c93ebb 100644
--- a/driver/accelgyro_lsm6ds0.h
+++ b/driver/accelgyro_lsm6ds0.h
@@ -117,6 +117,12 @@ enum lsm6ds0_bdu {
/* Sensor resolution in number of bits. This sensor has fixed resolution. */
#define LSM6DS0_RESOLUTION 16
+/* Min and Max sampling frequency in mHz */
+#define LSM6DS0_ACCEL_MIN_FREQ 14900
+#define LSM6DS0_ACCEL_MAX_FREQ 952000
+#define LSM6DS0_GYRO_MIN_FREQ 14900
+#define LSM6DS0_GYRO_MAX_FREQ 952000
+
extern const struct accelgyro_drv lsm6ds0_drv;
struct lsm6ds0_data {
struct accelgyro_saved_data_t base;
diff --git a/driver/gyro_l3gd20h.h b/driver/gyro_l3gd20h.h
index 6ff9fba044..81113c6a73 100644
--- a/driver/gyro_l3gd20h.h
+++ b/driver/gyro_l3gd20h.h
@@ -71,6 +71,10 @@
#define L3GD20_LOW_ODR_MASK (1 << 0)
#define L3GD20_ODR_PD_MASK (1 << 3)
+/* Min and Max sampling frequency in mHz */
+#define L3GD20_GYRO_MIN_FREQ 12500
+#define L3GD20_GYRO_MAX_FREQ 800000
+
/*
* Register : STATUS_REG
* Address : 0X27
diff --git a/include/common.h b/include/common.h
index d82f74f4dd..b45fc44ecd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -137,4 +137,7 @@ enum ec_error_list {
#define test_export_static static
#endif
+/* find the most significant bit. Not defined in n == 0. */
+#define __fls(n) (31 - __builtin_clz(n))
+
#endif /* __CROS_EC_COMMON_H */
diff --git a/include/config.h b/include/config.h
index f6a6100670..f7e4a5cf6c 100644
--- a/include/config.h
+++ b/include/config.h
@@ -652,6 +652,9 @@
/* Support EC to Internal bus bridge. */
#undef CONFIG_EC2I
+/* EC capable of sensor speeds up to 200000 mHz */
+#define CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ 200000
+
/* Support EC chip internal data EEPROM */
#undef CONFIG_EEPROM
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 7d90b9f5f9..f5cc2997b1 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1873,7 +1873,8 @@ struct ec_params_motion_sense {
* and MOTIONSENSE_CMD_PERFORM_CALIB. */
struct {
uint8_t sensor_num;
- } info, data, fifo_flush, perform_calib, list_activities;
+ } info, info_3, data, fifo_flush, perform_calib,
+ list_activities;
/*
* Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
@@ -1978,6 +1979,27 @@ struct ec_response_motion_sense {
uint8_t chip;
} info;
+ /* Used for MOTIONSENSE_CMD_INFO version 3 */
+ struct __ec_todo_unpacked {
+ /* Should be element of enum motionsensor_type. */
+ uint8_t type;
+
+ /* Should be element of enum motionsensor_location. */
+ uint8_t location;
+
+ /* Should be element of enum motionsensor_chip. */
+ uint8_t chip;
+
+ /* Minimum sensor sampling frequency */
+ uint32_t min_frequency;
+
+ /* Maximum sensor sampling frequency */
+ uint32_t max_frequency;
+
+ /* Max number of sensor events that could be in fifo */
+ uint32_t fifo_max_event_count;
+ } info_3;
+
/* Used for MOTIONSENSE_CMD_DATA */
struct ec_response_motion_sensor_data data;
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 866e30cc2e..326da74c73 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -45,6 +45,12 @@ enum sensor_config {
#define ROUND_UP_FLAG (1 << 31)
#define BASE_ODR(_odr) ((_odr) & ~ROUND_UP_FLAG)
+#ifdef CONFIG_ACCEL_FIFO
+#define MAX_FIFO_EVENT_COUNT CONFIG_ACCEL_FIFO
+#else
+#define MAX_FIFO_EVENT_COUNT 0
+#endif
+
struct motion_data_t {
/*
* data rate the sensor will measure, in mHz: 0 suspended.
@@ -133,7 +139,13 @@ struct motion_sensor_t {
* For sensor without FIFO, time since the last event was collect
* from sensor registers.
*/
- uint32_t last_collection;
+ uint32_t last_collection;
+
+ /* Minimum supported sampling frequency in miliHertz for this sensor */
+ uint32_t min_frequency;
+
+ /* Maximum supported sampling frequency in miliHertz for this sensor */
+ uint32_t max_frequency;
};
/* Defined at board level. */
diff --git a/include/util.h b/include/util.h
index 8ca1177807..1e5dda293f 100644
--- a/include/util.h
+++ b/include/util.h
@@ -77,7 +77,7 @@
/* True of x is a power of two */
#define POWER_OF_TWO(x) (x && !(x & (x - 1)))
-/**
+/*
* macros for integer division with various rounding variants
* default integer division rounds down.
*/
diff --git a/util/ectool.c b/util/ectool.c
index edb33c2083..97079b625e 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -3222,7 +3222,7 @@ static const struct {
uint8_t insize;
} ms_command_sizes[] = {
MS_DUMP_SIZE(),
- MS_SIZES(info),
+ MS_SIZES(info_3),
MS_SIZES(ec_rate),
MS_SIZES(sensor_odr),
MS_SIZES(sensor_range),
@@ -3347,18 +3347,34 @@ static int cmd_motionsense(int argc, char **argv)
}
if (argc == 3 && !strcasecmp(argv[1], "info")) {
- param.cmd = MOTIONSENSE_CMD_INFO;
+ struct ec_params_get_cmd_versions p;
+ struct ec_response_get_cmd_versions r;
+ int version = 0;
+ param.cmd = MOTIONSENSE_CMD_INFO;
param.sensor_odr.sensor_num = strtol(argv[2], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad %s arg.\n", argv[2]);
return -1;
}
- rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1,
+ /* tool defaults to using latest version of info command */
+ p.cmd = EC_CMD_MOTION_SENSE_CMD;
+ rv = ec_command(EC_CMD_GET_CMD_VERSIONS, 0, &p, sizeof(p),
+ &r, sizeof(r));
+ if (rv < 0) {
+ if (rv == -EC_RES_INVALID_PARAM)
+ printf("Command 0x%02x not supported by EC.\n",
+ EC_CMD_GET_CMD_VERSIONS);
+ return rv;
+ }
+
+ if (r.version_mask)
+ version = __fls(r.version_mask);
+
+ rv = ec_command(EC_CMD_MOTION_SENSE_CMD, version,
&param, ms_command_sizes[param.cmd].outsize,
resp, ms_command_sizes[param.cmd].insize);
-
if (rv < 0)
return rv;
@@ -3413,6 +3429,14 @@ static int cmd_motionsense(int argc, char **argv)
printf("unknown\n");
}
+ if (version >= 3) {
+ printf("Min Frequency: %d mHz\n",
+ resp->info_3.min_frequency);
+ printf("Max Frequency: %d mHz\n",
+ resp->info_3.max_frequency);
+ printf("FIFO Max Event Count: %d\n",
+ resp->info_3.fifo_max_event_count);
+ }
return 0;
}