From 8a2d0a5de6fc03eeea79a65469b361ae0ca694c9 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 27 Oct 2017 15:07:19 -0700 Subject: [PATCH] driver: BMM150: Set max frequency based on repetitions setting The compass uses oversampling to produce accurate values. MAX_ODR is functions of the repetitions setting. 80Hz is too high, calculate the frequency based on preset setting. Currently, we use 'SPECIAL' that was calculated for Ryu. BUG=b:68394559 BRANCH=eve,reef,poppy TEST=Check with ectool motionsense info 3 the frequency is around 30Hz. Before: Min Frequency: 781 mHz Max Frequency: 80000 mHz After: Min Frequency: 781 mHz Max Frequency: 29579 mHz Check with AIDA64 the compass is not stuck and return changing values. Fixup of CL/570482 Change-Id: Idcfed1418f59e755e5647d018351c6a7397ffe1b Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/742146 Reviewed-by: Aseda Aboagye --- board/eve/board.c | 2 +- board/nautilus/board.c | 2 +- board/poppy/board.c | 2 +- board/reef/board.c | 2 +- driver/mag_bmm150.h | 11 ++++++++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/board/eve/board.c b/board/eve/board.c index 0b02f79570..e0f168fca4 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -903,7 +903,7 @@ struct motion_sensor_t motion_sensors[] = { .default_range = 1 << 11, /* 16LSB / uT, fixed */ .rot_standard_ref = &mag_standard_ref, .min_frequency = BMM150_MAG_MIN_FREQ, - .max_frequency = BMM150_MAG_MAX_FREQ, + .max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL), .config = { /* AP: by default shutdown all sensors */ [SENSOR_CONFIG_AP] = { diff --git a/board/nautilus/board.c b/board/nautilus/board.c index ba3395e446..d50d4485de 100644 --- a/board/nautilus/board.c +++ b/board/nautilus/board.c @@ -976,7 +976,7 @@ struct motion_sensor_t motion_sensors[] = { .default_range = 1 << 11, /* 16LSB / uT, fixed */ .rot_standard_ref = &mag_standard_ref, .min_frequency = BMM150_MAG_MIN_FREQ, - .max_frequency = BMM150_MAG_MAX_FREQ, + .max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL), .config = { /* AP: by default shutdown all sensors */ [SENSOR_CONFIG_AP] = { diff --git a/board/poppy/board.c b/board/poppy/board.c index f2027516f2..60cdff40dd 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -998,7 +998,7 @@ struct motion_sensor_t motion_sensors[] = { .default_range = 1 << 11, /* 16LSB / uT, fixed */ .rot_standard_ref = &mag_standard_ref, .min_frequency = BMM150_MAG_MIN_FREQ, - .max_frequency = BMM150_MAG_MAX_FREQ, + .max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL), .config = { /* AP: by default shutdown all sensors */ [SENSOR_CONFIG_AP] = { diff --git a/board/reef/board.c b/board/reef/board.c index 0e5496db52..f4696b8ce2 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -956,7 +956,7 @@ struct motion_sensor_t motion_sensors[] = { .default_range = 1 << 11, /* 16LSB / uT, fixed */ .rot_standard_ref = &mag_standard_ref, .min_frequency = BMM150_MAG_MIN_FREQ, - .max_frequency = BMM150_MAG_MAX_FREQ, + .max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL), .config = { /* AP: by default shutdown all sensors */ [SENSOR_CONFIG_AP] = { diff --git a/driver/mag_bmm150.h b/driver/mag_bmm150.h index 51b2926e8a..d3c07db11b 100644 --- a/driver/mag_bmm150.h +++ b/driver/mag_bmm150.h @@ -76,7 +76,16 @@ /* Min and Max sampling frequency in mHz */ #define BMM150_MAG_MIN_FREQ 781 -#define BMM150_MAG_MAX_FREQ 80000 + +/* + * From Section 4.2.4, max frequency depends on the preset. + * + * Fmax ~= 1 / (145us * nXY + 500us * nZ + 980us) + * + * To be safe, declare only 75% of the value. + */ +#define BMM150_MAG_MAX_FREQ(_preset) (750000000 / \ + (145 * BMM150_REP(_preset, XY) + 500 * BMM150_REP(_preset, Z) + 980)) struct bmm150_comp_registers { /* Local copy of the compensation registers. */