diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-11-25 10:46:49 -0800 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2015-12-01 19:01:49 +0000 |
commit | 5c13f7e2c4d717fa5950f8f64c420a12d2674d30 (patch) | |
tree | bf8d8584e1603482978e6ca75f47063f5057ffd7 | |
parent | 42cb34b5292f5261fe8f844863bffd89efb54b89 (diff) | |
download | chrome-ec-5c13f7e2c4d717fa5950f8f64c420a12d2674d30.tar.gz |
motion: Set interrupt interval properly for sensor in force mode
cl/301134 has a bug. If the AP wants a forced sensor (i.e. light) at
100Hz but a sampling frequency at 1s, we would still wake it up every
.1s instead of 1s.
Take in account force mode only when calculating the sampling frequency
not the interrupt interval.
BRANCH=smaug
BUG=b:25425420
TEST=Check the device goes to suspend even with 40Hz light sampling
rate:
echo 0 > /sys/bus/iio/devices/iio:device0/frequency
echo 40000 > /sys/bus/iio/devices/iio:device3/frequency
echo mem >/sys/power/state
Before it would resume just after suspend/while suspending.
Change-Id: Ie4fe36268cb1b04bc8f01ec885af84fad9e8b282
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/314315
Reviewed-by: Alec Berg <alecaberg@chromium.org>
(cherry picked from commit 70915b501249017e4e962316bf178fd00d09e696)
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/314957
-rw-r--r-- | common/motion_sense.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 110f620e9d..c2574b64b7 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -280,13 +280,28 @@ end_set_ec_rate_from_ap: } - +/* + * motion_sense_select_ec_rate + * + * Calculate the ec_rate for a given sensor. + * - sensor: sensor to use + * - config_id: determine the requestor (AP or EC). + * - interrupt: + * If interrupt is set: return the sampling rate requested by AP or EC. + * If interrupt is not set and the sensor is in forced mode, + * we return the rate needed to probe the sensor at the right ODR. + * otherwise return the sampling rate requested by AP or EC. + * + * return rate in us. + */ static int motion_sense_select_ec_rate( const struct motion_sensor_t *sensor, - enum sensor_config config_id) + enum sensor_config config_id, + int interrupt) { #ifdef CONFIG_ACCEL_FORCE_MODE_MASK - if (CONFIG_ACCEL_FORCE_MODE_MASK & (1 << (sensor - motion_sensors))) { + if (interrupt == 0 && + (CONFIG_ACCEL_FORCE_MODE_MASK & (1 << (sensor - motion_sensors)))) { int rate_mhz = BASE_ODR(sensor->config[config_id].odr); /* we have to run ec at the sensor frequency rate.*/ if (rate_mhz > 0) @@ -311,10 +326,11 @@ static int motion_sense_ec_rate(struct motion_sensor_t *sensor) /* Check the AP setting first. */ if (sensor_active != SENSOR_ACTIVE_S5) - ec_rate = motion_sense_select_ec_rate(sensor, SENSOR_CONFIG_AP); + ec_rate = motion_sense_select_ec_rate( + sensor, SENSOR_CONFIG_AP, 0); ec_rate_from_cfg = motion_sense_select_ec_rate( - sensor, motion_sense_get_ec_config()); + sensor, motion_sense_get_ec_config(), 0); if (ec_rate_from_cfg != 0) if (ec_rate == 0 || ec_rate_from_cfg < ec_rate) @@ -350,7 +366,7 @@ static int motion_sense_set_motion_intervals(void) ec_rate = sensor_ec_rate; sensor_ec_rate = motion_sense_select_ec_rate( - sensor, SENSOR_CONFIG_AP); + sensor, SENSOR_CONFIG_AP, 1); if (ec_int_rate == 0 || (sensor_ec_rate && sensor_ec_rate < ec_int_rate)) ec_int_rate = sensor_ec_rate; |