diff options
-rw-r--r-- | common/motion_sense.c | 8 | ||||
-rw-r--r-- | driver/accel_bma2x2.h | 3 | ||||
-rw-r--r-- | driver/accel_kx022.h | 2 | ||||
-rw-r--r-- | driver/accel_kxcj9.h | 2 | ||||
-rw-r--r-- | driver/accel_lis2dh.h | 3 | ||||
-rw-r--r-- | driver/accelgyro_bmi160.h | 4 | ||||
-rw-r--r-- | driver/accelgyro_lsm6ds0.h | 5 | ||||
-rw-r--r-- | driver/accelgyro_lsm6dsm.h | 3 | ||||
-rw-r--r-- | driver/als_opt3001.h | 3 | ||||
-rw-r--r-- | driver/als_si114x.h | 3 | ||||
-rw-r--r-- | driver/baro_bmp280.h | 3 | ||||
-rw-r--r-- | driver/mag_bmm150.h | 4 | ||||
-rw-r--r-- | driver/mag_lis2mdl.h | 3 | ||||
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/motion_sense.h | 10 | ||||
-rw-r--r-- | include/util.h | 6 |
16 files changed, 46 insertions, 20 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index c4c380629b..6e29a070c9 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -1150,13 +1150,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 fe8d17641e..7523404986 100644 --- a/driver/accel_lis2dh.h +++ b/driver/accel_lis2dh.h @@ -77,7 +77,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 fa72649e01..5b934b57a2 100644 --- a/driver/accelgyro_bmi160.h +++ b/driver/accelgyro_bmi160.h @@ -432,9 +432,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 6e603e6df5..763260894b 100644 --- a/driver/accelgyro_lsm6dsm.h +++ b/driver/accelgyro_lsm6dsm.h @@ -160,7 +160,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 8824872977..bedd66d9b8 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/driver/mag_lis2mdl.h b/driver/mag_lis2mdl.h index ae7907c225..13e1b422e4 100644 --- a/driver/mag_lis2mdl.h +++ b/driver/mag_lis2mdl.h @@ -29,6 +29,9 @@ #define LIS2MDL_ODR_MIN_VAL 10000 #define LIS2MDL_ODR_MAX_VAL 100000 +#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= LIS2MDL_ODR_MAX_VAL) +#error "EC too slow for magnetometer" +#endif extern const struct accelgyro_drv lis2mdl_drv; diff --git a/include/config.h b/include/config.h index 85f6204388..9a693a0dbc 100644 --- a/include/config.h +++ b/include/config.h @@ -1341,8 +1341,8 @@ /* Compile extra debugging and tests for the DMA module */ #undef CONFIG_DMA_HELP -/* 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 b7290e7bb4..2d81c9b003 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 39a07e4b1e..5c2a7f38a6 100644 --- a/include/util.h +++ b/include/util.h @@ -20,13 +20,15 @@ extern "C" { #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 @@ -35,7 +37,7 @@ extern "C" { __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 |