summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-11-27 12:50:42 -0800
committerCommit Bot <commit-bot@chromium.org>2019-05-30 05:56:41 +0000
commitf81d843fe25267a1660d1e45c0f593fa310f79d9 (patch)
tree7410a86cd60992129c67c066fd71f5242a439516
parent0aee48bdaab94faf674daa69b327d9a6675090a1 (diff)
downloadchrome-ec-f81d843fe25267a1660d1e45c0f593fa310f79d9.tar.gz
sensor: Adjust max_frequency based on EC performance
Put in max_frequency a value that the sensor AND the EC support. BRANCH=none BUG=b:118205424,b:118851581,chromium:615059 TEST=Compile. Check all max sensors frequencies have been altered with: for i in $(grep -rh max_frequency board | cut -d '=' -f 2 | sort | \ uniq | grep FREQ | sed 's/FREQ.*//') ; do echo -n $i ; git show | grep -q $i || break; echo check done Check on nocturne accel max frequency is still correct. (cherry picked from commit 77b306b340ca428ba6785add204ccdce82185274) Conflicts: driver/mag_lis2mdl.h : driver not present yet. include/config.h : added defines. Reviewed-on: https://chromium-review.googlesource.com/1352063 Commit-Ready: Elthan Huang <elthan_huang@compal.corp-partner.google.com> Reviewed-by: Jesse Schettler <jschettler@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Justin TerAvest <teravest@chromium.org> Change-Id: I848396d9f150a2e94d430a8feeafc1087a6bf2c3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1621506 Reviewed-by: Enrico Granata <egranata@chromium.org>
-rw-r--r--common/motion_sense.c8
-rw-r--r--driver/accel_bma2x2.h3
-rw-r--r--driver/accel_kx022.h2
-rw-r--r--driver/accel_kxcj9.h2
-rw-r--r--driver/accel_lis2dh.h3
-rw-r--r--driver/accelgyro_bmi160.h4
-rw-r--r--driver/accelgyro_lsm6ds0.h5
-rw-r--r--driver/accelgyro_lsm6dsm.h3
-rw-r--r--driver/als_opt3001.h3
-rw-r--r--driver/als_si114x.h3
-rw-r--r--driver/baro_bmp280.h3
-rw-r--r--driver/mag_bmm150.h4
-rw-r--r--include/config.h4
-rw-r--r--include/motion_sense.h10
-rw-r--r--include/util.h6
15 files changed, 43 insertions, 20 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 58e98f2d50..307a275e94 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -1135,13 +1135,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
out->info.chip = sensor->chip;
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.max_frequency = sensor->max_frequency;
out->info_3.fifo_max_event_count = MAX_FIFO_EVENT_COUNT;
args->response_size = sizeof(out->info_3);
} else {
diff --git a/driver/accel_bma2x2.h b/driver/accel_bma2x2.h
index 2fcbfadfdc..dbb8347c94 100644
--- a/driver/accel_bma2x2.h
+++ b/driver/accel_bma2x2.h
@@ -160,5 +160,6 @@ extern const struct accelgyro_drv bma2x2_accel_drv;
/* Min and Max sampling frequency in mHz */
#define BMA255_ACCEL_MIN_FREQ 7810
-#define BMA255_ACCEL_MAX_FREQ 1000000
+#define BMA255_ACCEL_MAX_FREQ \
+ MOTION_MAX_SENSOR_FREQUENCY(1000000, 125000)
#endif /* __CROS_EC_ACCEL_BMA2x2_H */
diff --git a/driver/accel_kx022.h b/driver/accel_kx022.h
index 1192881384..1d3e817f64 100644
--- a/driver/accel_kx022.h
+++ b/driver/accel_kx022.h
@@ -136,6 +136,6 @@
/* Min and Max sampling frequency in mHz */
#define KX022_ACCEL_MIN_FREQ 781
-#define KX022_ACCEL_MAX_FREQ 1600000
+#define KX022_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(1600000, 6250)
#endif /* __CROS_EC_ACCEL_KX022_H */
diff --git a/driver/accel_kxcj9.h b/driver/accel_kxcj9.h
index 778735a61b..e36119ccc1 100644
--- a/driver/accel_kxcj9.h
+++ b/driver/accel_kxcj9.h
@@ -106,6 +106,6 @@
/* Min and Max sampling frequency in mHz */
#define KXCJ9_ACCEL_MIN_FREQ 781
-#define KXCJ9_ACCEL_MAX_FREQ 1600000
+#define KXCJ9_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(1600000, 6250)
#endif /* __CROS_EC_ACCEL_KXCJ9_H */
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h
index 4a01cc995c..59d2007194 100644
--- a/driver/accel_lis2dh.h
+++ b/driver/accel_lis2dh.h
@@ -101,7 +101,8 @@ enum lis2dh_odr {
/* Absolute maximum rate for sensor */
#define LIS2DH_ODR_MIN_VAL 1000
-#define LIS2DH_ODR_MAX_VAL 400000
+#define LIS2DH_ODR_MAX_VAL \
+ MOTION_MAX_SENSOR_FREQUENCY(400000, 25000)
/* Return ODR reg value based on data rate set */
#define LIS2DH_ODR_TO_REG(_odr) \
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index 84acf29fb5..9dd869c7cd 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -427,9 +427,9 @@ enum fifo_header {
/* Min and Max sampling frequency in mHz */
#define BMI160_ACCEL_MIN_FREQ 12500
-#define BMI160_ACCEL_MAX_FREQ 1600000
+#define BMI160_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(1600000, 100000)
#define BMI160_GYRO_MIN_FREQ 25000
-#define BMI160_GYRO_MAX_FREQ 3200000
+#define BMI160_GYRO_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(3200000, 100000)
extern const struct accelgyro_drv bmi160_drv;
diff --git a/driver/accelgyro_lsm6ds0.h b/driver/accelgyro_lsm6ds0.h
index 3236203558..cd1fefb199 100644
--- a/driver/accelgyro_lsm6ds0.h
+++ b/driver/accelgyro_lsm6ds0.h
@@ -119,9 +119,10 @@ enum lsm6ds0_bdu {
/* Min and Max sampling frequency in mHz */
#define LSM6DS0_ACCEL_MIN_FREQ 14900
-#define LSM6DS0_ACCEL_MAX_FREQ 952000
+#define LSM6DS0_ACCEL_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(952000, 119000)
+
#define LSM6DS0_GYRO_MIN_FREQ 14900
-#define LSM6DS0_GYRO_MAX_FREQ 952000
+#define LSM6DS0_GYRO_MAX_FREQ MOTION_MAX_SENSOR_FREQUENCY(952000, 119000)
extern const struct accelgyro_drv lsm6ds0_drv;
struct lsm6ds0_data {
diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h
index bb332f71b5..53583d978f 100644
--- a/driver/accelgyro_lsm6dsm.h
+++ b/driver/accelgyro_lsm6dsm.h
@@ -121,7 +121,8 @@ struct fstatus {
/* Absolute maximum rate for acc and gyro sensors */
#define LSM6DSM_ODR_MIN_VAL 13000
-#define LSM6DSM_ODR_MAX_VAL 416000
+#define LSM6DSM_ODR_MAX_VAL \
+ MOTION_MAX_SENSOR_FREQUENCY(416000, LSM6DSM_ODR_MIN_VAL)
/* ODR reg value from selected data rate in mHz */
#define LSM6DSM_ODR_TO_REG(_odr) (__fls(_odr / LSM6DSM_ODR_MIN_VAL) + 1)
diff --git a/driver/als_opt3001.h b/driver/als_opt3001.h
index eeb05f3a10..d2d2737e20 100644
--- a/driver/als_opt3001.h
+++ b/driver/als_opt3001.h
@@ -39,6 +39,9 @@ enum opt3001_mode {
/* Min and Max sampling frequency in mHz */
#define OPT3001_LIGHT_MIN_FREQ 1250
#define OPT3001_LIGHT_MAX_FREQ 10000
+#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= OPT3001_LIGHT_MAX_FREQ)
+#error "EC too slow for light sensor"
+#endif
#ifdef HAS_TASK_ALS
int opt3001_init(void);
diff --git a/driver/als_si114x.h b/driver/als_si114x.h
index 85b8677cdf..e3a19895ba 100644
--- a/driver/als_si114x.h
+++ b/driver/als_si114x.h
@@ -219,6 +219,9 @@
#define SI114X_PROX_MAX_FREQ 50000
#define SI114X_LIGHT_MIN_FREQ 504
#define SI114X_LIGHT_MAX_FREQ 50000
+#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= SI114X_PROX_MAX_FREQ)
+#error "EC too slow for light sensor"
+#endif
extern const struct accelgyro_drv si114x_drv;
diff --git a/driver/baro_bmp280.h b/driver/baro_bmp280.h
index 94da35dbe1..be2611289c 100644
--- a/driver/baro_bmp280.h
+++ b/driver/baro_bmp280.h
@@ -166,6 +166,9 @@
*/
#define BMP280_BARO_MIN_FREQ 75000
#define BMP280_BARO_MAX_FREQ 87000
+#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= BMP280_BARO_MAX_FREQ)
+#error "EC too slow for accelerometer"
+#endif
/**************************************************************/
/* STRUCTURE and ENUM DEFINITIONS */
diff --git a/driver/mag_bmm150.h b/driver/mag_bmm150.h
index d3c07db11b..1fba0a7050 100644
--- a/driver/mag_bmm150.h
+++ b/driver/mag_bmm150.h
@@ -87,6 +87,10 @@
#define BMM150_MAG_MAX_FREQ(_preset) (750000000 / \
(145 * BMM150_REP(_preset, XY) + 500 * BMM150_REP(_preset, Z) + 980))
+#if (BMM150_MAG_MAX_FREQ(SPECIAL) > CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ)
+#error "EC too slow for magnetometer"
+#endif
+
struct bmm150_comp_registers {
/* Local copy of the compensation registers. */
int8_t dig1[2];
diff --git a/include/config.h b/include/config.h
index fb71433a05..0d1bca56c7 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1150,8 +1150,8 @@
/* Support EC to Internal bus bridge. */
#undef CONFIG_EC2I
-/* Usually, EC capable of sensor speeds up to 200000 mHz */
-#define CONFIG_EC_MAX_SENSOR_FREQ_DEFAULT_MILLIHZ 200000
+/* Usually, EC capable of sensor speeds up to 250 Hz */
+#define CONFIG_EC_MAX_SENSOR_FREQ_DEFAULT_MILLIHZ 250000
/* Maximal EC sampling rate */
#undef CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 7b574e37f7..326c8a13b6 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -51,6 +51,16 @@ enum sensor_config {
#define MAX_FIFO_EVENT_COUNT 0
#endif
+/*
+ * Define the frequency to use in max_frequency based on the maximal frequency
+ * the sensor support and what the EC can provide.
+ * Return a frequency the sensor supports.
+ * Trigger a compilation error when the EC way to slow for the sensor.
+ */
+#define MOTION_MAX_SENSOR_FREQUENCY(_max, _step) GENERIC_MIN( \
+ (_max) / (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ >= (_step)), \
+ (_step) << __fls(CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ / (_step)))
+
struct motion_data_t {
/*
* data rate the sensor will measure, in mHz: 0 suspended.
diff --git a/include/util.h b/include/util.h
index c8ae09db93..fe66936cf4 100644
--- a/include/util.h
+++ b/include/util.h
@@ -16,13 +16,15 @@
#include <stddef.h>
/* Standard macros / definitions */
+#define GENERIC_MAX(x, y) ((x) > (y) ? (x) : (y))
+#define GENERIC_MIN(x, y) ((x) < (y) ? (x) : (y))
#ifndef MAX
#define MAX(a, b) \
({ \
__typeof__(a) temp_a = (a); \
__typeof__(b) temp_b = (b); \
\
- temp_a > temp_b ? temp_a : temp_b; \
+ GENERIC_MAX(temp_a, temp_b); \
})
#endif
#ifndef MIN
@@ -31,7 +33,7 @@
__typeof__(a) temp_a = (a); \
__typeof__(b) temp_b = (b); \
\
- temp_a < temp_b ? temp_a : temp_b; \
+ GENERIC_MIN(temp_a, temp_b); \
})
#endif
#ifndef NULL