* [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode
@ 2026-01-19 7:49 Gwendal Grignou
2026-01-21 10:15 ` Tzung-Bi Shih
2026-01-22 19:43 ` Jonathan Cameron
0 siblings, 2 replies; 3+ messages in thread
From: Gwendal Grignou @ 2026-01-19 7:49 UTC (permalink / raw)
To: jic23; +Cc: nvaccaro, tzungbi, linux-iio, Gwendal Grignou
calibration was a one-shot event sent to the sensor to calibrate itself.
It is used on Bosch sensors (BMI160, BMA254).
For light sensor, we need to stay in calibration mode to run tests.
Accept boolean true and false (not just true) to enter/exit calibration.
Check "echo 0 > calibrate" is supported.
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
---
.../common/cros_ec_sensors/cros_ec_sensors_core.c | 6 +++---
include/linux/platform_data/cros_ec_commands.h | 12 +++++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
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.52.0.457.g6b5491de43-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode
2026-01-19 7:49 [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode Gwendal Grignou
@ 2026-01-21 10:15 ` Tzung-Bi Shih
2026-01-22 19:43 ` Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2026-01-21 10:15 UTC (permalink / raw)
To: Gwendal Grignou; +Cc: jic23, nvaccaro, linux-iio
On Sun, Jan 18, 2026 at 11:49:28PM -0800, Gwendal Grignou wrote:
> calibration was a one-shot event sent to the sensor to calibrate itself.
^ C
> It is used on Bosch sensors (BMI160, BMA254).
> For light sensor, we need to stay in calibration mode to run tests.
> Accept boolean true and false (not just true) to enter/exit calibration.
>
> Check "echo 0 > calibrate" is supported.
I can somehow understand because the patch is small. But I believe the
commit message should be rephrased. For example, if we only need to "stay"
in calibration mode to run tests, why do we need to add the patch for
disabling calibration?
> 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.
Missed a period here but that's also what current ec_commands.h [1] has.
It should be fine.
[1] https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/main/include/ec_commands.h#3158
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode
2026-01-19 7:49 [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode Gwendal Grignou
2026-01-21 10:15 ` Tzung-Bi Shih
@ 2026-01-22 19:43 ` Jonathan Cameron
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-01-22 19:43 UTC (permalink / raw)
To: Gwendal Grignou; +Cc: nvaccaro, tzungbi, linux-iio
On Sun, 18 Jan 2026 23:49:28 -0800
Gwendal Grignou <gwendal@chromium.org> wrote:
> calibration was a one-shot event sent to the sensor to calibrate itself.
> It is used on Bosch sensors (BMI160, BMA254).
> For light sensor, we need to stay in calibration mode to run tests.
> Accept boolean true and false (not just true) to enter/exit calibration.
>
> Check "echo 0 > calibrate" is supported.
>
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
Documentation/ABI/testing/sysfs-bus-iio-cros-ec needs an update I think.
Whilst this is an ABI change, given it was useless for light sensors
before it seems unlikely that anyone will notice.
J
> ---
> .../common/cros_ec_sensors/cros_ec_sensors_core.c | 6 +++---
> include/linux/platform_data/cros_ec_commands.h | 12 +++++++++---
> 2 files changed, 12 insertions(+), 6 deletions(-)
>
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-22 19:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19 7:49 [PATCH] iio: cros_ec: Allow enabling/disabling calibration mode Gwendal Grignou
2026-01-21 10:15 ` Tzung-Bi Shih
2026-01-22 19:43 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox