diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-11-25 10:46:49 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-12-01 01:11:11 -0800 |
commit | 70915b501249017e4e962316bf178fd00d09e696 (patch) | |
tree | bbe7bb3214f1be25217057045c7955b177a066c2 /common | |
parent | 02ddede08eb66c752b868c86293eff8fed9e8160 (diff) | |
download | chrome-ec-70915b501249017e4e962316bf178fd00d09e696.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>
Diffstat (limited to 'common')
-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 80885fabb8..cf201ba4e4 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -279,13 +279,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) @@ -310,10 +325,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) @@ -349,7 +365,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; |