summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@chromium.org>2017-04-25 19:09:03 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-05-18 19:49:45 +0000
commitb0911b4362c12060c0f351f08f6fa341179c2637 (patch)
tree0a90bfaa83aeca6cedd85ac77ecd85c4b96ae592
parentcbc2cfced026989539cd2a2a2565ca768c0c1f8a (diff)
downloadchrome-ec-b0911b4362c12060c0f351f08f6fa341179c2637.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=firmware-glados-7820.B BUG=chromium:615059 TEST=build/boot and verify MOTIONSENSE_CMD_INFO response on caroline Change-Id: I66db9715c122ef6bb4665ad5d086a9ecc9c7c93a Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/486102 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--board/caroline/board.c6
-rw-r--r--board/cave/board.c6
-rw-r--r--board/glados/board.c6
-rw-r--r--board/lars/board.c4
-rw-r--r--board/pbody/board.c6
-rw-r--r--board/sentry/board.c6
-rw-r--r--board/wheatley/board.c6
-rw-r--r--common/motion_sense.c20
-rw-r--r--driver/accel_bma2x2.h4
-rw-r--r--driver/accel_kx022.h4
-rw-r--r--driver/accel_kxcj9.h4
-rw-r--r--driver/accelgyro_bmi160.h6
-rw-r--r--driver/accelgyro_lsm6ds0.h6
-rw-r--r--driver/als_si114x.h6
-rw-r--r--driver/gyro_l3gd20h.h4
-rw-r--r--driver/mag_bmm150.h3
-rw-r--r--include/common.h2
-rw-r--r--include/config.h20
-rw-r--r--include/ec_commands.h24
-rw-r--r--include/motion_sense.h12
-rw-r--r--include/util.h3
-rw-r--r--util/ectool.c32
22 files changed, 171 insertions, 19 deletions
diff --git a/board/caroline/board.c b/board/caroline/board.c
index d3ae1cf7ea..ec28ce6133 100644
--- a/board/caroline/board.c
+++ b/board/caroline/board.c
@@ -501,6 +501,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMA2x2_I2C_ADDR1,
.rot_standard_ref = &lid_standard_ref,
.default_range = 8, /* g, to support tablet mode */
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -537,6 +539,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.rot_standard_ref = &base_standard_ref,
.default_range = 8, /* g, to support tablet mode */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -573,6 +577,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/board/cave/board.c b/board/cave/board.c
index 42503a803f..8fa7a17bad 100644
--- a/board/cave/board.c
+++ b/board/cave/board.c
@@ -550,6 +550,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KX022_ADDR0,
.rot_standard_ref = &rot_lid_accel,
.default_range = 8, /* g, to support laptop mode */
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -586,6 +588,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.rot_standard_ref = &rot_base_accel,
.default_range = 8, /* g, to support laptop mode */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -622,6 +626,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.default_range = 1000, /* dps */
.rot_standard_ref = &rot_base_accel,
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/board/glados/board.c b/board/glados/board.c
index 6d99a1354b..05c47bc9f2 100644
--- a/board/glados/board.c
+++ b/board/glados/board.c
@@ -513,6 +513,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -548,6 +550,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.default_range = 1000, /* dps */
.rot_standard_ref = NULL, /* Identity Matrix. */
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
@@ -583,6 +587,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KX022_ADDR1,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
diff --git a/board/lars/board.c b/board/lars/board.c
index 90c665004f..035cc9d34a 100644
--- a/board/lars/board.c
+++ b/board/lars/board.c
@@ -217,6 +217,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] = {
@@ -251,6 +253,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/pbody/board.c b/board/pbody/board.c
index 7bd2db88ff..722546648b 100644
--- a/board/pbody/board.c
+++ b/board/pbody/board.c
@@ -530,6 +530,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KX022_ADDR0,
.rot_standard_ref = &rot_lid_accel, /* Identity matrix. */
.default_range = 8, /* g, enough for laptop. */
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -565,6 +567,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 8, /* g, enough for laptop. */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -601,6 +605,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.default_range = 1000, /* dps */
.rot_standard_ref = NULL, /* Identity Matrix. */
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/board/sentry/board.c b/board/sentry/board.c
index 4ef1110696..e06202e875 100644
--- a/board/sentry/board.c
+++ b/board/sentry/board.c
@@ -250,6 +250,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] = {
@@ -284,6 +286,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] = {
@@ -319,6 +323,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = L3GD20_ADDR1,
.rot_standard_ref = NULL,
.default_range = 2000, /* DPS */
+ .min_frequency = L3GD20_GYRO_MIN_FREQ,
+ .max_frequency = L3GD20_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
diff --git a/board/wheatley/board.c b/board/wheatley/board.c
index 2889a145e6..08afc81865 100644
--- a/board/wheatley/board.c
+++ b/board/wheatley/board.c
@@ -461,6 +461,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
@@ -496,6 +498,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = BMI160_ADDR0,
.default_range = 1000, /* dps */
.rot_standard_ref = NULL, /* Identity Matrix. */
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
.config = {
/* AP: by default shutdown all sensors */
[SENSOR_CONFIG_AP] = {
@@ -531,6 +535,8 @@ struct motion_sensor_t motion_sensors[] = {
.addr = KX022_ADDR1,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
.config = {
/* AP: by default use EC settings */
[SENSOR_CONFIG_AP] = {
diff --git a/common/motion_sense.c b/common/motion_sense.c
index a5e81d40f8..727f06dae1 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -964,10 +964,24 @@ 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 =
+ SENSOR_MAX_FIFO_EVENT_COUNT;
+ args->response_size = sizeof(out->info_3);
+ } else {
+ args->response_size = sizeof(out->info);
+ }
break;
case MOTIONSENSE_CMD_EC_RATE:
@@ -1219,7 +1233,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_bma2x2.h b/driver/accel_bma2x2.h
index f5facc90e9..7fb4e65028 100644
--- a/driver/accel_bma2x2.h
+++ b/driver/accel_bma2x2.h
@@ -158,4 +158,8 @@ extern const struct accelgyro_drv bma2x2_accel_drv;
#define BMA2x2_BW_250HZ 0x0D /* LowPass 250HZ */
#define BMA2x2_BW_500HZ 0x0E /* LowPass 500HZ */
#define BMA2x2_BW_1000HZ 0x0F /* LowPass 1000HZ */
+
+/* Min and Max sampling frequency in mHz */
+#define BMA255_ACCEL_MIN_FREQ 7810
+#define BMA255_ACCEL_MAX_FREQ 1000000
#endif /* __CROS_EC_ACCEL_BMA2x2_H */
diff --git a/driver/accel_kx022.h b/driver/accel_kx022.h
index 3ed95a30a8..5136615994 100644
--- a/driver/accel_kx022.h
+++ b/driver/accel_kx022.h
@@ -119,4 +119,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 4436f38e8b..d90f109316 100644
--- a/driver/accel_kxcj9.h
+++ b/driver/accel_kxcj9.h
@@ -103,4 +103,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_bmi160.h b/driver/accelgyro_bmi160.h
index 34b5e0cfae..06be4addd9 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -415,6 +415,12 @@ enum fifo_header {
/* Sensor resolution in number of bits. This sensor has fixed resolution. */
#define BMI160_RESOLUTION 16
+/* Min and Max sampling frequency in mHz */
+#define BMI160_ACCEL_MIN_FREQ 12500
+#define BMI160_ACCEL_MAX_FREQ 1600000
+#define BMI160_GYRO_MIN_FREQ 25
+#define BMI160_GYRO_MAX_FREQ 3200000
+
extern const struct accelgyro_drv bmi160_drv;
enum bmi160_running_mode {
diff --git a/driver/accelgyro_lsm6ds0.h b/driver/accelgyro_lsm6ds0.h
index 481f39aa10..3236203558 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/als_si114x.h b/driver/als_si114x.h
index 5fbc3c665f..2486d05dc2 100644
--- a/driver/als_si114x.h
+++ b/driver/als_si114x.h
@@ -211,6 +211,12 @@
/* Time to wait before re-initializing the device if access is denied */
#define SI114X_DENIED_THRESHOLD (10 * SECOND)
+/* Min and Max sampling frequency in mHz */
+#define SI114X_PROX_MIN_FREQ 504
+#define SI114X_PROX_MAX_FREQ 100000
+#define SI114X_LIGHT_MIN_FREQ 504
+#define SI114X_LIGHT_MAX_FREQ 100000
+
extern const struct accelgyro_drv si114x_drv;
enum si114x_state {
diff --git a/driver/gyro_l3gd20h.h b/driver/gyro_l3gd20h.h
index 73c0253d27..24ad81a693 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/driver/mag_bmm150.h b/driver/mag_bmm150.h
index a76c68cf3d..7eb469cf43 100644
--- a/driver/mag_bmm150.h
+++ b/driver/mag_bmm150.h
@@ -74,6 +74,9 @@
#define BMM150_HALL_OVERFLOW_ADCVAL (-16384)
#define BMM150_OVERFLOW_OUTPUT (0x8000)
+/* Min and Max sampling frequency in mHz */
+#define BMM150_MAG_MIN_FREQ 781
+#define BMM150_MAG_MAX_FREQ 800000
struct bmm150_comp_registers {
/* Local copy of the compensation registers. */
diff --git a/include/common.h b/include/common.h
index 84b9366064..ec6d386538 100644
--- a/include/common.h
+++ b/include/common.h
@@ -147,4 +147,6 @@ 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 5fe899a183..7054dd0a9f 100644
--- a/include/config.h
+++ b/include/config.h
@@ -852,6 +852,17 @@
*/
#undef CONFIG_MAPPED_STORAGE_BASE
+/* Protected region of storage belonging to EC */
+#undef CONFIG_EC_PROTECTED_STORAGE_OFF
+#undef CONFIG_EC_PROTECTED_STORAGE_SIZE
+
+/* Writable region of storage belonging to EC */
+#undef CONFIG_EC_WRITABLE_STORAGE_OFF
+#undef CONFIG_EC_WRITABLE_STORAGE_SIZE
+
+/* EC capable of sensor speeds up to 200000 mHz */
+#define CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ 200000
+
#undef CONFIG_FLASH_PROTECT_NEXT_BOOT
/*
@@ -882,14 +893,6 @@
/* Most efficient flash write size (in bytes) */
#undef CONFIG_FLASH_WRITE_IDEAL_SIZE
-/* Protected region of storage belonging to EC */
-#undef CONFIG_EC_PROTECTED_STORAGE_OFF
-#undef CONFIG_EC_PROTECTED_STORAGE_SIZE
-
-/* Writable region of storage belonging to EC */
-#undef CONFIG_EC_WRITABLE_STORAGE_OFF
-#undef CONFIG_EC_WRITABLE_STORAGE_SIZE
-
/*****************************************************************************/
/* Include a flashmap in the compiled firmware image */
@@ -2261,5 +2264,4 @@
#if (CONFIG_AUX_TIMER_PERIOD_MS) < ((HOOK_TICK_INTERVAL_MS) * 2)
#error "CONFIG_AUX_TIMER_PERIOD_MS must be at least 2x HOOK_TICK_INTERVAL_MS"
#endif
-
#endif /* __CROS_EC_CONFIG_H */
diff --git a/include/ec_commands.h b/include/ec_commands.h
index d0e7a25ca7..f92c6653de 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1988,7 +1988,8 @@ struct __ec_todo_packed ec_params_motion_sense {
* and MOTIONSENSE_CMD_PERFORM_CALIB. */
struct __ec_todo_unpacked {
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
@@ -2094,6 +2095,27 @@ struct __ec_todo_packed 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 5b3b8739dd..4822bb61b2 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 SENSOR_MAX_FIFO_EVENT_COUNT CONFIG_ACCEL_FIFO
+#else
+#define SENSOR_MAX_FIFO_EVENT_COUNT 0
+#endif
+
struct motion_data_t {
/*
* data rate the sensor will measure, in mHz: 0 suspended.
@@ -130,6 +136,12 @@ struct motion_sensor_t {
* from sensor registers.
*/
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 8fec4a14e8..9401dbf008 100644
--- a/include/util.h
+++ b/include/util.h
@@ -77,9 +77,6 @@
/* True of x is a power of two */
#define POWER_OF_TWO(x) (x && !(x & (x - 1)))
-/* find the most significant bit. Not defined in n == 0. */
-#define __fls(n) (31 - __builtin_clz(n))
-
/*
* macros for integer division with various rounding variants
* default integer division rounds down.
diff --git a/util/ectool.c b/util/ectool.c
index 5f1511816a..92030af7f7 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -24,6 +24,7 @@
#include "misc_util.h"
#include "panic.h"
#include "usb_pd.h"
+#include "common.h"
/* Command line options */
enum {
@@ -3254,7 +3255,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),
@@ -3379,15 +3380,32 @@ 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 != 0)
+ 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);
@@ -3451,6 +3469,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;
}