Skip to content

Commit 0077e9b

Browse files
gwendalcrjic23
authored andcommitted
iio: cros_ec: Allow enabling/disabling calibration mode
'calibrate' was a one-shot event sent to the sensor to calibrate itself. It is used on Bosch sensors (BMI160, BMA254). Light sensors work differently: They are first put in calibration mode, tests are run to collect information and calculate the calibration values to apply. Once done, the sensors are put back in normal mode. Accept boolean true and false (not just true) to enter/exit calibration state. Check "echo 0 > calibrate" is supported. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 2693ca2 commit 0077e9b

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

Documentation/ABI/testing/sysfs-bus-iio-cros-ec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Date: July 2015
33
KernelVersion: 4.7
44
Contact: linux-iio@vger.kernel.org
55
Description:
6-
Writing '1' will perform a FOC (Fast Online Calibration). The
7-
corresponding calibration offsets can be read from `*_calibbias`
8-
entries.
6+
Writing '1' either perform a FOC (Fast Online Calibration) or
7+
enter calibration mode.
8+
Writing '0` exits calibration mode. It is a NOP for FOC enabled
9+
sensors.
10+
The corresponding calibration offsets can be read from `*_calibbias`
11+
entries.
912

1013
What: /sys/bus/iio/devices/iio:deviceX/id
1114
Date: September 2017

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,14 @@ static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev,
441441
ret = kstrtobool(buf, &calibrate);
442442
if (ret < 0)
443443
return ret;
444-
if (!calibrate)
445-
return -EINVAL;
446444

447445
mutex_lock(&st->cmd_lock);
448446
st->param.cmd = MOTIONSENSE_CMD_PERFORM_CALIB;
447+
st->param.perform_calib.enable = calibrate;
449448
ret = cros_ec_motion_send_host_cmd(st, 0);
450449
if (ret != 0) {
451-
dev_warn(&indio_dev->dev, "Unable to calibrate sensor\n");
450+
dev_warn(&indio_dev->dev, "Unable to calibrate sensor: %d\n",
451+
ret);
452452
} else {
453453
/* Save values */
454454
for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)

include/linux/platform_data/cros_ec_commands.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,13 +2598,19 @@ struct ec_params_motion_sense {
25982598

25992599
/*
26002600
* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2601-
* and MOTIONSENSE_CMD_PERFORM_CALIB.
26022601
*/
26032602
struct __ec_todo_unpacked {
26042603
uint8_t sensor_num;
2605-
} info, info_3, data, fifo_flush, perform_calib,
2606-
list_activities;
2604+
} info, info_3, data, fifo_flush, list_activities;
26072605

2606+
/*
2607+
* Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2608+
* Allow entering/exiting the calibration mode.
2609+
*/
2610+
struct __ec_todo_unpacked {
2611+
uint8_t sensor_num;
2612+
uint8_t enable;
2613+
} perform_calib;
26082614
/*
26092615
* Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
26102616
* and MOTIONSENSE_CMD_SENSOR_RANGE.

0 commit comments

Comments
 (0)