]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: cros_ec: Allow enabling/disabling calibration mode
authorGwendal Grignou <gwendal@chromium.org>
Wed, 28 Jan 2026 03:27:02 +0000 (19:27 -0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 29 Jan 2026 17:35:31 +0000 (17:35 +0000)
'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>
Documentation/ABI/testing/sysfs-bus-iio-cros-ec
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
include/linux/platform_data/cros_ec_commands.h

index 9e392624379794db0eee02c9db33612e3a896263..3de1dfc9838932caafed5cab0015cfd1b28d33da 100644 (file)
@@ -3,9 +3,12 @@ Date:          July 2015
 KernelVersion: 4.7
 Contact:       linux-iio@vger.kernel.org
 Description:
-               Writing '1' will perform a FOC (Fast Online Calibration). The
-                corresponding calibration offsets can be read from `*_calibbias`
-                entries.
+               Writing '1' either perform a FOC (Fast Online Calibration) or
+               enter calibration mode.
+               Writing '0` exits calibration mode. It is a NOP for FOC enabled
+               sensors.
+               The corresponding calibration offsets can be read from `*_calibbias`
+               entries.
 
 What:          /sys/bus/iio/devices/iio:deviceX/id
 Date:          September 2017
index ef53066b1735bc366749911bc1d4f4f94b382270..5133755c2ea61c05c5a063998df6a955b30541e2 100644 (file)
@@ -441,14 +441,14 @@ static ssize_t cros_ec_sensors_calibrate(struct iio_dev *indio_dev,
        ret = kstrtobool(buf, &calibrate);
        if (ret < 0)
                return ret;
-       if (!calibrate)
-               return -EINVAL;
 
        mutex_lock(&st->cmd_lock);
        st->param.cmd = MOTIONSENSE_CMD_PERFORM_CALIB;
+       st->param.perform_calib.enable = calibrate;
        ret = cros_ec_motion_send_host_cmd(st, 0);
        if (ret != 0) {
-               dev_warn(&indio_dev->dev, "Unable to calibrate sensor\n");
+               dev_warn(&indio_dev->dev, "Unable to calibrate sensor: %d\n",
+                        ret);
        } else {
                /* Save values */
                for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
index 69294f79cc88aaa6289af3f104743ff0d93ab753..d363d60bb8a36b81ac7b85d7537896ad24f27a98 100644 (file)
@@ -2598,13 +2598,19 @@ struct ec_params_motion_sense {
 
                /*
                 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
-                * and MOTIONSENSE_CMD_PERFORM_CALIB.
                 */
                struct __ec_todo_unpacked {
                        uint8_t sensor_num;
-               } info, info_3, data, fifo_flush, perform_calib,
-                               list_activities;
+               } info, info_3, data, fifo_flush, list_activities;
 
+               /*
+                * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
+                * Allow entering/exiting the calibration mode.
+                */
+               struct __ec_todo_unpacked {
+                       uint8_t sensor_num;
+                       uint8_t enable;
+               } perform_calib;
                /*
                 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
                 * and MOTIONSENSE_CMD_SENSOR_RANGE.