Re: [PATCH v3 1/2] iio: imu: inv_icm42600: add WoM support

From: Jean-Baptiste Maneyrol
Date: Tue Jun 10 2025 - 10:45:41 EST


Hello Jonathan,

sorry for the very late response, here are my answers.

Thanks,
JB

>________________________________________
>From: Jonathan Cameron <jic23@xxxxxxxxxx>
>Sent: Monday, April 21, 2025 12:48
>To: Jean-Baptiste Maneyrol via B4 Relay <devnull+jean-baptiste.maneyrol.tdk.com@xxxxxxxxxx>
>Cc: Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@xxxxxxx>; Lars-Peter Clausen <lars@xxxxxxxxxx>; David Lechner <dlechner@xxxxxxxxxxxx>; Nuno Sá <nuno.sa@xxxxxxxxxx>; Andy Shevchenko <andy@xxxxxxxxxx>; linux-iio@xxxxxxxxxxxxxxx <linux-iio@xxxxxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx <linux-kernel@xxxxxxxxxxxxxxx>
>Subject: Re: [PATCH v3 1/2] iio: imu: inv_icm42600: add WoM support
> 
>This Message Is From an External Sender
>This message came from outside your organization.
> 
>On Fri, 18 Apr 2025 18:19:02 +0200
>Jean-Baptiste Maneyrol via B4 Relay <devnull+jean-baptiste.maneyrol.tdk.com@xxxxxxxxxx> wrote:
>
>> From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@xxxxxxx>
>>
>> Add WoM as accel roc rising x|y|z event.
>>
>> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@xxxxxxx>
>Hi Jean-Baptiste,
>
>One thing on mixing gotos and scoped_guard(). It might be fine but we've
>had weird issues with compilers and this stuff + the guidance in cleanup.h
>suggests not mixing the two approaches.
>
>Easy enough to sort out here with a helper function and I think the
>end result will both avoid that issue and be easier to read.
>
>Jonathan
>
>> ---
>> drivers/iio/imu/inv_icm42600/inv_icm42600.h | 54 +++-
>> drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 279 ++++++++++++++++++++-
>> drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +-
>> drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 58 +++++
>> 4 files changed, 385 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>> index f893dbe6996506a33eb5d3be47e6765a923665c9..bcf588a048836f909c26908f0677833303a94ef9 100644
>> --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>> +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>> @@ -135,6 +135,14 @@ struct inv_icm42600_suspended {
>> bool temp;
>> };
>>
>> +struct inv_icm42600_apex {
>> + unsigned int on;
>> + struct {
>> + uint64_t value;
>> + bool enable;
>> + } wom;
>> +};
>> +
>> /**
>> * struct inv_icm42600_state - driver state variables
>> * @lock: lock for serializing multiple registers access.
>> @@ -148,9 +156,10 @@ struct inv_icm42600_suspended {
>> * @suspended: suspended sensors configuration.
>> * @indio_gyro: gyroscope IIO device.
>> * @indio_accel: accelerometer IIO device.
>> - * @buffer: data transfer buffer aligned for DMA.
>> - * @fifo: FIFO management structure.
>> * @timestamp: interrupt timestamps.
>> + * @apex: APEX features management.
>
>Maybe give a little more info on what APEX is somewhere?

No problem, it stands for Advanced Pedometer and Event detection. It is a small
compute core that runs algo like pedometer, gestures, ...

>
>
>
>> +static int inv_icm42600_accel_enable_wom(struct iio_dev *indio_dev)
>> +{
>> + struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>> + struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev);
>> + struct device *pdev = regmap_get_device(st->map);
>> + struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
>> + unsigned int sleep_ms = 0;
>> + int ret;
>> +
>> + ret = pm_runtime_resume_and_get(pdev);
>> + if (ret)
>> + return ret;
>> +
>> + scoped_guard(mutex, &st->lock) {
>> + /* turn on accel sensor */
>> + conf.mode = accel_st->power_mode;
>> + conf.filter = accel_st->filter;
>> + ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_ms);
>> + if (ret)
>> + goto error_suspend;
>
>As below. Compilers are not great at the more complex scope vs goto stuff.
>This one may be fine buf in general we avoid it.

Will fix it.

>
>> + }
>> +
>> + if (sleep_ms)
>> + msleep(sleep_ms);
>> +
>> + scoped_guard(mutex, &st->lock) {
>> + ret = inv_icm42600_enable_wom(st);
>> + if (ret)
>> + goto error_suspend;
>
>This doesn't follow the guidance in cleanup.h about never mixing gotos and
>scoped cleanup. Two options here, either factor out everthing after the
>pm handling and have

Will change it.

> ret = pm_runtime_resume_and_get(pdev);
> if (ret)
> return ret;
>
> ret = __inv_icm62600_accel_enabled_wom();
> if (ret) {
> pm_runtime_mark_last_busy(pdev);
> pm_runtime_put_autosuspend(pdev)'
> return ret;
> }
>
> return 0;
>
>The rest of the cases are fine.
>
>> + st->apex.on++;
>> + st->apex.wom.enable = true;
>> + }
>> +
>> + return 0;
>> +
>> +error_suspend:
>> + pm_runtime_mark_last_busy(pdev);
>> + pm_runtime_put_autosuspend(pdev);
>> + return ret;
>> +}
>
>
>