summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-08-26 14:44:06 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-08-29 01:34:15 -0700
commitfa0c85b6c9c36cd677782eb97907162a371fbef2 (patch)
tree9da185e79d30e3380a0ec46b13b7ff57feccd5e4
parent32867104da45ae38e37163ba6d04f847bc15e6bc (diff)
downloadchrome-ec-fa0c85b6c9c36cd677782eb97907162a371fbef2.tar.gz
cyan, kunimitsu, strago: motion_sense: use new rate calculation
Use new config structure. Remove pre-init when sensors are shutdown in S3 on strago: motion_sense is not setting ODR to 0 inconditionally when sensors are not active. active_mask now means state (S0, S3, S5) where sensors are powered on. When sensor is powered but unused, EC can use the config array to set the polling and ODR to 0. BUG=chromium:513458 TEST=On Cyan, verify the sensors are working in S0. In S3, check the motion_sense task is idle (now sensor to probe). Check the task comes back on resume. BRANCH=cyan,strago Change-Id: Ib3d118b7139f94755fef4cb73fc1274e9e2f2826 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/295781 Reviewed-by: Sheng-liang Song <ssl@chromium.org>
-rw-r--r--board/cyan/board.c56
-rw-r--r--board/kunimitsu/board.c78
-rw-r--r--board/strago/board.c76
3 files changed, 137 insertions, 73 deletions
diff --git a/board/cyan/board.c b/board/cyan/board.c
index d77dbeb45c..595b2d08e4 100644
--- a/board/cyan/board.c
+++ b/board/cyan/board.c
@@ -126,11 +126,29 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[0],
.addr = KXCJ9_ADDR1,
.rot_standard_ref = &base_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
- }
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
},
{.name = "Lid",
.active_mask = SENSOR_ACTIVE_S0_S3,
@@ -142,11 +160,29 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[1],
.addr = KXCJ9_ADDR0,
.rot_standard_ref = &lid_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
- }
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c
index d2359de78c..ae2372b2b3 100644
--- a/board/kunimitsu/board.c
+++ b/board/kunimitsu/board.c
@@ -189,11 +189,29 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[0],
.addr = KXCJ9_ADDR1,
.rot_standard_ref = &base_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
- }
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
},
{.name = "Lid Accel",
.active_mask = SENSOR_ACTIVE_S0,
@@ -205,11 +223,29 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[1],
.addr = KXCJ9_ADDR0,
.rot_standard_ref = &lid_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
- }
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
@@ -231,28 +267,6 @@ const struct accel_orientation acc_orient = {
};
/*
- * In S3, power rail for sensors (+V3p3S) goes down asynchronous to EC. We need
- * to execute this routine first and set the sensor state to "Not Initialized".
- * This prevents the motion_sense_suspend hook routine from communicating with
- * the sensor.
- */
-static void motion_sensors_pre_init(void)
-{
- struct motion_sensor_t *sensor;
- int i;
-
- for (i = 0; i < motion_sensor_count; ++i) {
- sensor = &motion_sensors[i];
- sensor->state = SENSOR_NOT_INITIALIZED;
-
- sensor->runtime_config.odr = sensor->default_config.odr;
- sensor->runtime_config.range = sensor->default_config.range;
- }
-}
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sensors_pre_init,
- MOTION_SENSE_HOOK_PRIO - 1);
-
-/*
* Temperature sensors data; must be in same order as enum temp_sensor_id.
* Sensor index and name must match those present in coreboot:
* src/mainboard/google/${board}/acpi/dptf.asl
diff --git a/board/strago/board.c b/board/strago/board.c
index 6b6b3a7089..aec0a362f3 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -218,10 +218,28 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[0],
.addr = KXCJ9_ADDR1,
.rot_standard_ref = &base_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
}
},
{.name = "Lid Accel",
@@ -234,11 +252,29 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_kxcj9_data[1],
.addr = KXCJ9_ADDR0,
.rot_standard_ref = &lid_standard_ref,
- .default_config = {
- .odr = 100000,
- .range = 2,
- .ec_rate = SUSPEND_SAMPLING_INTERVAL,
- }
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* AP: by default shutdown all sensors */
+ [SENSOR_CONFIG_AP] = {
+ .odr = 0,
+ .ec_rate = 0,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 100000 | ROUND_UP_FLAG,
+ .ec_rate = 100,
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ /* Sensor off in S3/S5 */
+ [SENSOR_CONFIG_EC_S5] = {
+ .odr = 0,
+ .ec_rate = 0
+ },
+ },
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
@@ -259,28 +295,6 @@ const struct accel_orientation acc_orient = {
.hinge_axis = {1, 0, 0},
};
-/*
- * In S3, power rail for sensors (+V3p3S) goes down asynchronous to EC. We need
- * to execute this routine first and set the sensor state to "Not Initialized".
- * This prevents the motion_sense_suspend hook routine from communicating with
- * the sensor.
- */
-static void motion_sensors_pre_init(void)
-{
- struct motion_sensor_t *sensor;
- int i;
-
- for (i = 0; i < motion_sensor_count; ++i) {
- sensor = &motion_sensors[i];
- sensor->state = SENSOR_NOT_INITIALIZED;
-
- sensor->runtime_config.odr = sensor->default_config.odr;
- sensor->runtime_config.range = sensor->default_config.range;
- }
-}
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sensors_pre_init,
- MOTION_SENSE_HOOK_PRIO - 1);
-
/* init ADC ports to avoid floating state due to thermistors */
static void adc_pre_init(void)
{