From 70915b501249017e4e962316bf178fd00d09e696 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Wed, 25 Nov 2015 10:46:49 -0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/314315 Reviewed-by: Alec Berg --- common/motion_sense.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'common') 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; -- cgit v1.2.1