summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r--common/motion_sense.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index e94604fae5..1fb158b7c9 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -322,6 +322,27 @@ void accel_int_base(enum gpio_signal signal)
/*****************************************************************************/
/* Host commands */
+/**
+ * Temporary function to map host sensor IDs to EC sensor IDs.
+ *
+ * TODO(crosbug.com/p/27320): Eventually we need a board specific table
+ * specifying which motion sensors are attached and which driver to use to
+ * access that sensor. Once we have this, this function should be able to go
+ * away.
+ */
+static int host_sensor_id_to_ec_sensor_id(int host_id)
+{
+ switch (host_id) {
+ case EC_MOTION_SENSOR_ACCEL_BASE:
+ return ACCEL_BASE;
+ case EC_MOTION_SENSOR_ACCEL_LID:
+ return ACCEL_LID;
+ }
+
+ /* If no match then the EC currently doesn't support ID received. */
+ return -1;
+}
+
static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
{
const struct ec_params_motion_sense *in = args->params;
@@ -335,9 +356,13 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
* use some motion_sense data structure from the board file to
* help fill in this response.
*/
- out->dump.sensor_presence[0] = 1;
- out->dump.sensor_presence[1] = 1;
- out->dump.sensor_presence[2] = 0;
+ out->dump.module_flags =
+ (*(host_get_memmap(EC_MEMMAP_ACC_STATUS)) &
+ EC_MEMMAP_ACC_STATUS_PRESENCE_BIT) ?
+ MOTIONSENSE_MODULE_FLAG_ACTIVE : 0;
+ out->dump.sensor_flags[0] = MOTIONSENSE_SENSOR_FLAG_PRESENT;
+ out->dump.sensor_flags[1] = MOTIONSENSE_SENSOR_FLAG_PRESENT;
+ out->dump.sensor_flags[2] = 0;
out->dump.data[0] = acc_base_host[X];
out->dump.data[1] = acc_base_host[Y];
out->dump.data[2] = acc_base_host[Z];
@@ -354,7 +379,11 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
* use some motion_sense data structure from the board file to
* help fill in this response.
*/
- switch (in->sensor_odr.sensor_num) {
+ id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num);
+ if (id < 0)
+ return EC_RES_INVALID_PARAM;
+
+ switch (id) {
case ACCEL_BASE:
out->info.type = MOTIONSENSE_TYPE_ACCEL;
out->info.location = MOTIONSENSE_LOC_BASE;
@@ -396,11 +425,10 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_ODR:
/* Verify sensor number is valid. */
- if (in->sensor_odr.sensor_num >= ACCEL_COUNT)
+ id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num);
+ if (id < 0)
return EC_RES_INVALID_PARAM;
- id = in->sensor_odr.sensor_num;
-
/* Set new datarate if the data arg has a value. */
if (in->sensor_odr.data != EC_MOTION_SENSE_NO_VALUE) {
if (accel_set_datarate(id, in->sensor_odr.data,
@@ -419,11 +447,10 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
case MOTIONSENSE_CMD_SENSOR_RANGE:
/* Verify sensor number is valid. */
- if (in->sensor_odr.sensor_num >= ACCEL_COUNT)
+ id = host_sensor_id_to_ec_sensor_id(in->sensor_odr.sensor_num);
+ if (id < 0)
return EC_RES_INVALID_PARAM;
- id = in->sensor_odr.sensor_num;
-
/* Set new datarate if the data arg has a value. */
if (in->sensor_range.data != EC_MOTION_SENSE_NO_VALUE) {
if (accel_set_range(id, in->sensor_range.data,