public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] iio: cros_ec: Allow enabling/disabling calibration mode
@ 2026-01-28  3:27 Gwendal Grignou
  2026-01-29  1:37 ` Tzung-Bi Shih
  0 siblings, 1 reply; 3+ messages in thread
From: Gwendal Grignou @ 2026-01-28  3:27 UTC (permalink / raw)
  To: jic23; +Cc: nvaccaro, tzungbi, linux-iio, Gwendal Grignou

'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>
---
Changes in v3:
- Update ABI documentation.

Changes in v2:
- Reword commit message to indicate the calibration mode is a state for
  some sensors (light)

 Documentation/ABI/testing/sysfs-bus-iio-cros-ec      |  9 ++++++---
 .../common/cros_ec_sensors/cros_ec_sensors_core.c    |  6 +++---
 include/linux/platform_data/cros_ec_commands.h       | 12 +++++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-cros-ec b/Documentation/ABI/testing/sysfs-bus-iio-cros-ec
index 9e39262437979..3de1dfc983893 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-cros-ec
+++ b/Documentation/ABI/testing/sysfs-bus-iio-cros-ec
@@ -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
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 9ac80e4b7d756..f1cdee2a61cbd 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -444,14 +444,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++)
diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index 69294f79cc88a..d363d60bb8a36 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -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.
-- 
2.53.0.rc1.225.gd81095ad13-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-29 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28  3:27 [PATCH v3] iio: cros_ec: Allow enabling/disabling calibration mode Gwendal Grignou
2026-01-29  1:37 ` Tzung-Bi Shih
2026-01-29 17:36   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox