From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-iio@vger.kernel.org, andy@kernel.org, nuno.sa@analog.com,
dlechner@baylibre.com, jic23@kernel.org,
jean-baptiste.maneyrol@tdk.com,
linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
heiko@sntech.de, conor+dt@kernel.org, krzk+dt@kernel.org,
robh@kernel.org, Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH V15 5/9] iio: imu: inv_icm42607: Add PM support for icm42607
Date: Mon, 29 Jun 2026 10:21:06 +0300 [thread overview]
Message-ID: <akIc4vF06qtmIHFO@ashevche-desk.local> (raw)
In-Reply-To: <20260626161230.93069-6-macroalpha82@gmail.com>
On Fri, Jun 26, 2026 at 11:12:26AM -0500, Chris Morgan wrote:
> Add power management support for the ICM42607 device driver.
...
> +/*
> + * Suspend delay assumed from other icm42600 series device, not
> + * documented in datasheet.
> + */
> +#define INV_ICM42607_SUSPEND_DELAY_MS 2000
Perhaps (2 * MSEC_PER_SEC) ?
...
> +static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
> + enum inv_icm42607_sensor_mode gyro,
> + enum inv_icm42607_sensor_mode accel)
> +{
> + unsigned int oldaccel, oldgyro;
> + unsigned int sleepval_us = 0;
It's discouraged to have assignment here, as it's too far from the actual use
and makes code harder to maintain and prone to subtle errors. See also below.
> + unsigned int val;
> + s64 disable_wait;
> + int ret;
> +
> + ret = regmap_read(st->map, INV_ICM42607_REG_PWR_MGMT0, &val);
> + if (ret)
> + return ret;
> +
> + oldaccel = FIELD_GET(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, val);
> + oldgyro = FIELD_GET(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, val);
> +
> + if (gyro == oldgyro && accel == oldaccel)
> + return 0;
> +
> + /*
> + * Datasheet on page 14.26 says we need to ensure the gyro sensor is on
> + * for a minimum of 45ms. So if we transition from an on state to an
> + * off state make sure at least 45ms have passed before power off and
> + * wait if it hasn't.
> + */
> + if (!gyro && oldgyro) {
> + disable_wait = ktime_us_delta(st->conf.gyro_stop,
> + ktime_get());
It's perfectly a single line.
disable_wait = ktime_us_delta(st->conf.gyro_stop, ktime_get());
> + disable_wait = clamp(disable_wait, 0,
> + INV_ICM42607_GYRO_STOP_TIME_US);
I would leave on a single line, or split logically, meaning moving 0 to the
next line:
disable_wait = clamp(disable_wait,
0, INV_ICM42607_GYRO_STOP_TIME_US);
> + fsleep(disable_wait);
> + }
> + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro);
> + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
Perhaps
val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro) |
FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
which is slightly better to read in my opinion.
> + ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val);
> + if (ret)
> + return ret;
> +
> + /*
> + * If a state change occurs from off to on, sleep for the startup
> + * time of the sensor, unless a sleep_ms is specified. Since more
> + * than one sensor can be transitioned from off to on, select the
> + * maximum time from each of the sensors changing from off to on.
> + * The startup time for the temp sensor is considerably smaller
> + * than the startup time for the other sensors and one or more are
> + * required to be on for the temp sensor to function, so any start
> + * delay should be enough.
> + */
sleepval_us = 0;
> + if (accel && !oldaccel)
> + sleepval_us = max(sleepval_us, INV_ICM42607_ACCEL_STARTUP_TIME_US);
> +
> + if (gyro && !oldgyro) {
> + sleepval_us = max(sleepval_us, INV_ICM42607_GYRO_STARTUP_TIME_US);
> + /* Track the earliest we can turn off the gyroscope. */
> + st->conf.gyro_stop = ktime_add_us(ktime_get(),
> + INV_ICM42607_GYRO_STOP_TIME_US);
> + }
> +
> + fsleep(sleepval_us);
The problem is that the reaction to 0 is a gray area. Some architecture
implementations might even complain on that.
On x86, for instance, udelay(0) actually does some (supposed to be small) delay.
But I think due to above check for gyro == oldgyro && accel == oldaccel this
won't happen. Please, add a comment on top of fsleep().
> + return 0;
> +}
...
> + dev_set_drvdata(dev, st);
This will require device.h to be included and hence the rest related headers
can be dropped at the same time (like dev_printk.h).
--
With Best Regards,
Andy Shevchenko
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-iio@vger.kernel.org, andy@kernel.org, nuno.sa@analog.com,
dlechner@baylibre.com, jic23@kernel.org,
jean-baptiste.maneyrol@tdk.com,
linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org,
heiko@sntech.de, conor+dt@kernel.org, krzk+dt@kernel.org,
robh@kernel.org, Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH V15 5/9] iio: imu: inv_icm42607: Add PM support for icm42607
Date: Mon, 29 Jun 2026 10:21:06 +0300 [thread overview]
Message-ID: <akIc4vF06qtmIHFO@ashevche-desk.local> (raw)
In-Reply-To: <20260626161230.93069-6-macroalpha82@gmail.com>
On Fri, Jun 26, 2026 at 11:12:26AM -0500, Chris Morgan wrote:
> Add power management support for the ICM42607 device driver.
...
> +/*
> + * Suspend delay assumed from other icm42600 series device, not
> + * documented in datasheet.
> + */
> +#define INV_ICM42607_SUSPEND_DELAY_MS 2000
Perhaps (2 * MSEC_PER_SEC) ?
...
> +static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
> + enum inv_icm42607_sensor_mode gyro,
> + enum inv_icm42607_sensor_mode accel)
> +{
> + unsigned int oldaccel, oldgyro;
> + unsigned int sleepval_us = 0;
It's discouraged to have assignment here, as it's too far from the actual use
and makes code harder to maintain and prone to subtle errors. See also below.
> + unsigned int val;
> + s64 disable_wait;
> + int ret;
> +
> + ret = regmap_read(st->map, INV_ICM42607_REG_PWR_MGMT0, &val);
> + if (ret)
> + return ret;
> +
> + oldaccel = FIELD_GET(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, val);
> + oldgyro = FIELD_GET(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, val);
> +
> + if (gyro == oldgyro && accel == oldaccel)
> + return 0;
> +
> + /*
> + * Datasheet on page 14.26 says we need to ensure the gyro sensor is on
> + * for a minimum of 45ms. So if we transition from an on state to an
> + * off state make sure at least 45ms have passed before power off and
> + * wait if it hasn't.
> + */
> + if (!gyro && oldgyro) {
> + disable_wait = ktime_us_delta(st->conf.gyro_stop,
> + ktime_get());
It's perfectly a single line.
disable_wait = ktime_us_delta(st->conf.gyro_stop, ktime_get());
> + disable_wait = clamp(disable_wait, 0,
> + INV_ICM42607_GYRO_STOP_TIME_US);
I would leave on a single line, or split logically, meaning moving 0 to the
next line:
disable_wait = clamp(disable_wait,
0, INV_ICM42607_GYRO_STOP_TIME_US);
> + fsleep(disable_wait);
> + }
> + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro);
> + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
Perhaps
val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro) |
FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
which is slightly better to read in my opinion.
> + ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val);
> + if (ret)
> + return ret;
> +
> + /*
> + * If a state change occurs from off to on, sleep for the startup
> + * time of the sensor, unless a sleep_ms is specified. Since more
> + * than one sensor can be transitioned from off to on, select the
> + * maximum time from each of the sensors changing from off to on.
> + * The startup time for the temp sensor is considerably smaller
> + * than the startup time for the other sensors and one or more are
> + * required to be on for the temp sensor to function, so any start
> + * delay should be enough.
> + */
sleepval_us = 0;
> + if (accel && !oldaccel)
> + sleepval_us = max(sleepval_us, INV_ICM42607_ACCEL_STARTUP_TIME_US);
> +
> + if (gyro && !oldgyro) {
> + sleepval_us = max(sleepval_us, INV_ICM42607_GYRO_STARTUP_TIME_US);
> + /* Track the earliest we can turn off the gyroscope. */
> + st->conf.gyro_stop = ktime_add_us(ktime_get(),
> + INV_ICM42607_GYRO_STOP_TIME_US);
> + }
> +
> + fsleep(sleepval_us);
The problem is that the reaction to 0 is a gray area. Some architecture
implementations might even complain on that.
On x86, for instance, udelay(0) actually does some (supposed to be small) delay.
But I think due to above check for gyro == oldgyro && accel == oldaccel this
won't happen. Please, add a comment on top of fsleep().
> + return 0;
> +}
...
> + dev_set_drvdata(dev, st);
This will require device.h to be included and hence the rest related headers
can be dropped at the same time (like dev_printk.h).
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-06-29 7:21 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 16:12 [PATCH V15 0/9] Add Invensense ICM42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:12 ` [PATCH V15 1/9] dt-bindings: iio: imu: icm42600: Add mount-matrix Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:12 ` [PATCH V15 2/9] dt-bindings: iio: imu: icm42600: Add icm42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-07-01 1:45 ` Jonathan Cameron
2026-07-01 1:45 ` Jonathan Cameron
2026-07-01 1:45 ` Jonathan Cameron
2026-07-01 1:45 ` Jonathan Cameron
2026-06-26 16:12 ` [PATCH V15 3/9] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-07-01 19:15 ` Jonathan Cameron
2026-07-01 19:15 ` Jonathan Cameron
2026-06-26 16:12 ` [PATCH V15 4/9] iio: imu: inv_icm42607: Add SPI For icm42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:12 ` [PATCH V15 5/9] iio: imu: inv_icm42607: Add PM support for icm42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-29 7:21 ` Andy Shevchenko [this message]
2026-06-29 7:21 ` Andy Shevchenko
2026-06-26 16:12 ` [PATCH V15 6/9] iio: imu: inv_icm42607: Add Accelerometer " Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:29 ` sashiko-bot
2026-07-01 19:24 ` Jonathan Cameron
2026-07-01 19:24 ` Jonathan Cameron
2026-06-26 16:12 ` [PATCH V15 7/9] iio: imu: inv_icm42607: Add Gyroscope to icm42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:28 ` sashiko-bot
2026-07-01 19:28 ` Jonathan Cameron
2026-07-01 19:28 ` Jonathan Cameron
2026-06-26 16:12 ` [PATCH V15 8/9] iio: imu: inv_icm42607: Add Temp Support in icm42607 Chris Morgan
2026-06-26 16:12 ` Chris Morgan
2026-06-26 16:29 ` sashiko-bot
2026-07-01 19:30 ` Jonathan Cameron
2026-07-01 19:30 ` Jonathan Cameron
2026-06-26 16:12 ` [PATCH V15 9/9] arm64: dts: rockchip: Add icm42607p IMU for RG-DS Chris Morgan
2026-06-26 16:12 ` Chris Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akIc4vF06qtmIHFO@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=heiko@sntech.de \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=macroalpha82@gmail.com \
--cc=macromorgan@hotmail.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.