summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-06-13 13:12:29 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-06-15 10:56:55 -0700
commit122d4f65b0c896e332baabafe88bf5087d724cd1 (patch)
tree01f52c9b72487352c8ae82efcd46a02bd4daf3a7 /common/motion_sense.c
parent062680833fcfd42bdd03f8422c023b7e1c12a6fd (diff)
downloadchrome-ec-122d4f65b0c896e332baabafe88bf5087d724cd1.tar.gz
FIXUP: motion_sense: Check presence of {set,get}_{range,offset}
Allow get_ operation, even if set_ operation is not defined. Some device (magnetometer) have a fixed range, but the range is needed by the driver to calculate real value. BUG=b:110143516 BRANCH=none TEST=Check that a sensor where the range can not be changed (magnetometer) that we can read the range, but write to it returns "Invalid argument". Check bias are still accessible on all sensors. Change-Id: I38470eae624393fd93d9fff7a26d026b4a7984b8 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1101549
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r--common/motion_sense.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index b7f943ed41..6929bb5710 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -1242,11 +1242,11 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
in->sensor_range.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
- if (!sensor->drv->set_range || !sensor->drv->get_range)
- return EC_RES_INVALID_COMMAND;
-
/* Set new range if the data arg has a value. */
if (in->sensor_range.data != EC_MOTION_SENSE_NO_VALUE) {
+ if (!sensor->drv->set_range)
+ return EC_RES_INVALID_COMMAND;
+
if (sensor->drv->set_range(sensor,
in->sensor_range.data,
in->sensor_range.roundup)
@@ -1255,6 +1255,9 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
}
}
+ if (!sensor->drv->get_range)
+ return EC_RES_INVALID_COMMAND;
+
out->sensor_range.ret = sensor->drv->get_range(sensor);
args->response_size = sizeof(out->sensor_range);
break;
@@ -1265,11 +1268,11 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
in->sensor_offset.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
- if (!sensor->drv->set_offset || !sensor->drv->get_offset)
- return EC_RES_INVALID_COMMAND;
-
/* Set new range if the data arg has a value. */
if (in->sensor_offset.flags & MOTION_SENSE_SET_OFFSET) {
+ if (!sensor->drv->set_offset)
+ return EC_RES_INVALID_COMMAND;
+
ret = sensor->drv->set_offset(sensor,
in->sensor_offset.offset,
in->sensor_offset.temp);
@@ -1277,6 +1280,9 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
return ret;
}
+ if (!sensor->drv->get_offset)
+ return EC_RES_INVALID_COMMAND;
+
ret = sensor->drv->get_offset(sensor, out->sensor_offset.offset,
&out->sensor_offset.temp);
if (ret != EC_SUCCESS)