summaryrefslogtreecommitdiff
path: root/common/motion_sense.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-07-01 12:39:07 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-15 03:39:12 +0000
commite095bad64e5a9e27bdfadae2c0746d2ee151ef67 (patch)
treeebe804d050f0d3c8c9cb2c3ae7308e028173c545 /common/motion_sense.c
parentc0f78b4c0aca20203fefbc96c7e52c709455c06b (diff)
downloadchrome-ec-e095bad64e5a9e27bdfadae2c0746d2ee151ef67.tar.gz
driver: bmi160 Add code for calibration
Add code for set/getting calibration data on bmi160 Add code to perform FOC (Fast Online Calibration) on bmi160. Add delay after getting out of suspend to be sure sensor is available. BRANCH=smaug TEST=Check sensors are properly calibrated on Smaug: Perform calibration: echo 1 > /sys/bus/iio/devices/iio:device1/calibrate Read calibration values: cat /sys/bus/iio/devices/iio:device1/*_calibbias Check the values are translated properly. Write calibration values and check it affects the sensor output. BUG=chromium:506101,chrome-os-partner:39900 Change-Id: Ib9aad9bbd90b4249625641d68febf94b69aa4987 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/283165 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r--common/motion_sense.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index b53fe1b1cd..0fc71d1677 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -672,17 +672,36 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
/* Set new range if the data arg has a value. */
if (in->sensor_offset.flags & MOTION_SENSE_SET_OFFSET) {
- if (sensor->drv->set_offset(sensor,
+ ret = sensor->drv->set_offset(sensor,
in->sensor_offset.offset,
- in->sensor_offset.temp)
- != EC_SUCCESS) {
- CPRINTS("MS bad sensor offsets");
- return EC_RES_INVALID_PARAM;
- }
+ in->sensor_offset.temp);
+ if (ret != EC_SUCCESS)
+ return ret;
}
- sensor->drv->get_offset(sensor, out->sensor_offset.offset,
+ ret = sensor->drv->get_offset(sensor, out->sensor_offset.offset,
+ &out->sensor_offset.temp);
+ if (ret != EC_SUCCESS)
+ return ret;
+ args->response_size = sizeof(out->sensor_offset);
+ break;
+
+ case MOTIONSENSE_CMD_PERFORM_CALIB:
+ /* Verify sensor number is valid. */
+ sensor = host_sensor_id_to_motion_sensor(
+ in->sensor_offset.sensor_num);
+ if (sensor == NULL)
+ return EC_RES_INVALID_PARAM;
+ if (!sensor->drv->perform_calib)
+ return EC_RES_INVALID_COMMAND;
+
+ ret = sensor->drv->perform_calib(sensor);
+ if (ret != EC_SUCCESS)
+ return ret;
+ ret = sensor->drv->get_offset(sensor, out->sensor_offset.offset,
&out->sensor_offset.temp);
+ if (ret != EC_SUCCESS)
+ return ret;
args->response_size = sizeof(out->sensor_offset);
break;