From ab565efc144889dcd7a437e297c0a0fb0a061ec2 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Thu, 21 Mar 2019 14:05:36 -0700 Subject: bmm150: lower max frequency to match a frequency supported by BMI160 Be sure the frequency we report does not need to be rounded up by BMI160 when BMM150 is behind BMI160. For instance, if we set 29Hz as maximum frequency, 29Hz will be rounded up to 50Hz (BMI160 samples at its own recognized frequency). At that speed, the BMM150 will lock up. BUG=b:120942904 BRANCH=none TEST=On eve with magnetometer check the maximum frequency reported by the magnetometer is 25Hz. Check the magnetometer is working with 'ectool motionsense 3' (cherry picked from commit e726fe4b2c1ea392ed059c4dbdedec253605cd7f) Reviewed-on: https://chromium-review.googlesource.com/1535161 Reviewed-by: Enrico Granata Reviewed-by: Yilun Lin Change-Id: I7025fe8a400e050907af490784521295d987051a Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1621509 --- driver/mag_bmm150.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/driver/mag_bmm150.h b/driver/mag_bmm150.h index 1fba0a7050..402ebabf4f 100644 --- a/driver/mag_bmm150.h +++ b/driver/mag_bmm150.h @@ -84,10 +84,10 @@ * * To be safe, declare only 75% of the value. */ -#define BMM150_MAG_MAX_FREQ(_preset) (750000000 / \ +#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) +#if (__BMM150_MAG_MAX_FREQ(SPECIAL) > CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ) #error "EC too slow for magnetometer" #endif @@ -117,6 +117,18 @@ struct bmm150_private_data { #define BMM150_CAL(_s) \ (&BMI160_GET_DATA(_s)->compass.cal) +#ifdef CONFIG_MAG_BMI160_BMM150 +#include "accelgyro_bmi160.h" +/* + * Behind a BMI160, the BMM150 is in forced mode. Be sure to choose a frequency + * comptible with BMI160. + */ +#define BMM150_MAG_MAX_FREQ(_preset) \ + BMI160_REG_TO_ODR(BMI160_ODR_TO_REG(__BMM150_MAG_MAX_FREQ(_preset))) +#else +#define BMM150_MAG_MAX_FREQ(_preset) __BMM150_MAG_MAX_FREQ(_preset) +#endif + /* Specific initialization of BMM150 when behing BMI160 */ int bmm150_init(const struct motion_sensor_t *s); -- cgit v1.2.1