summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-11-27 12:50:42 -0800
committerCommit Bot <commit-bot@chromium.org>2020-05-13 18:46:58 +0000
commita005519834d2216c7d36b3eda51c5a71032ed786 (patch)
tree4bb56e71f141ebdcab3bca740db51a3dcfe2b2ab
parent21086c67e6549b89e902f55b59a91fa51c0ebaa3 (diff)
downloadchrome-ec-a005519834d2216c7d36b3eda51c5a71032ed786.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/accel_bma2x2.h : indent driver/accel_lis2dh.h : not present driver/accelgyro_lsm6dsm.h : not present driver/baro_bmp280.h : not present driver/mag_lis2mdl.h : not present include/config.h : reorder. driver/als_opt3001.c : config.h needed. Change-Id: I848396d9f150a2e94d430a8feeafc1087a6bf2c3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> 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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2199518
-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/accelgyro_bmi160.h4
-rw-r--r--driver/accelgyro_lsm6ds0.h5
-rw-r--r--driver/als_opt3001.c1
-rw-r--r--driver/als_opt3001.h3
-rw-r--r--driver/als_si114x.h3
-rw-r--r--driver/mag_bmm150.h4
-rw-r--r--include/motion_sense.h10
-rw-r--r--include/util.h6
12 files changed, 35 insertions, 16 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 95ee799bdf..87b8426f1b 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -975,13 +975,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 7fb4e65028..2e5e5c801b 100644
--- a/driver/accel_bma2x2.h
+++ b/driver/accel_bma2x2.h
@@ -161,5 +161,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 5136615994..852ec90b37 100644
--- a/driver/accel_kx022.h
+++ b/driver/accel_kx022.h
@@ -121,6 +121,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 d90f109316..819f811f08 100644
--- a/driver/accel_kxcj9.h
+++ b/driver/accel_kxcj9.h
@@ -105,6 +105,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/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index 279117193c..1a5ca6403c 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -417,9 +417,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/als_opt3001.c b/driver/als_opt3001.c
index 5de413eac4..3c9bea7958 100644
--- a/driver/als_opt3001.c
+++ b/driver/als_opt3001.c
@@ -5,6 +5,7 @@
* TI OPT3001 light sensor driver
*/
+#include "config.h"
#include "driver/als_opt3001.h"
#include "i2c.h"
diff --git a/driver/als_opt3001.h b/driver/als_opt3001.h
index 305fa97aff..16e2bc7cc8 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 67f7a24b09..28b1c8ae5b 100644
--- a/driver/als_si114x.h
+++ b/driver/als_si114x.h
@@ -216,6 +216,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/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/motion_sense.h b/include/motion_sense.h
index b0dc136974..9d66ae66ee 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 9401dbf008..81b5ad6d8b 100644
--- a/include/util.h
+++ b/include/util.h
@@ -44,13 +44,15 @@
#endif
/* 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
@@ -59,7 +61,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