From: Jonathan Cameron <jic23@kernel.org>
To: Remi Buisson via B4 Relay <devnull+remi.buisson.tdk.com@kernel.org>
Cc: remi.buisson@tdk.com, "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v6 2/9] iio: imu: inv_icm45600: add new inv_icm45600 driver
Date: Sun, 28 Sep 2025 09:30:26 +0100 [thread overview]
Message-ID: <20250928093000.6753d920@jic23-huawei> (raw)
In-Reply-To: <20250924-add_newport_driver-v6-2-76687b9d8a6e@tdk.com>
On Wed, 24 Sep 2025 09:23:55 +0000
Remi Buisson via B4 Relay <devnull+remi.buisson.tdk.com@kernel.org> wrote:
> From: Remi Buisson <remi.buisson@tdk.com>
>
> Core component of a new driver for InvenSense ICM-45600 devices.
> It includes registers definition, main probe/setup, and device
> utility functions.
>
> ICM-456xx devices are latest generation of 6-axis IMU,
> gyroscope+accelerometer and temperature sensor. This device
> includes a 8K FIFO, supports I2C/I3C/SPI, and provides
> intelligent motion features like pedometer, tilt detection,
> and tap detection.
>
> Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Hi Remi,
Just a few really minor things from a fresh read through.
Given the request for a commit message change on the DT that is slightly
beyond what I'd normally just tweak whilst applying I think we'll have
a v7 anyway, so if you could tidy these up that would be great.
We are very early in this cycle anyway, so I'm not inclined to rush!
Jonathan
> diff --git a/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c b/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..04f04c72e1710efde0ab8e83f9ce26d28e102c9b
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm45600/inv_icm45600_core.c
> @@ -0,0 +1,623 @@
> +u32 inv_icm45600_odr_to_period(enum inv_icm45600_odr odr)
> +{
> + static const u32 odr_periods[INV_ICM45600_ODR_MAX] = {
> + 0, /* reserved value */
> + 0, /* reserved value */
> + 0, /* reserved value */
I'd preferred this done with the enum values.
[INV_ICM45600_ODR_6400HZ_LN] = 156250,
etc and just a comment to say there are some reserved initial values.
that way we don't have to compare the comments with the enum values to be sure
there isn't one missing etc.
> + 156250, /* 6.4kHz */
> + 312500, /* 3.2kHz */
> + 625000, /* 1.6kHz */
> + 1250000, /* 800kHz */
> + 2500000, /* 400Hz */
> + 5000000, /* 200Hz */
> + 10000000, /* 100Hz */
> + 20000000, /* 50Hz */
> + 40000000, /* 25Hz */
> + 80000000, /* 12.5Hz */
> + 160000000, /* 6.25Hz */
> + 320000000, /* 3.125Hz */
> + 640000000, /* 1.5625Hz */
> + };
> +
> + return odr_periods[odr];
> +}
> +
> +/**
> + * inv_icm45600_setup() - check and setup chip
> + * @st: driver internal state
> + * @chip_info: detected chip description
> + * @reset: define whether a reset is required or not
> + * @bus_setup: callback for setting up bus specific registers
> + *
> + * Returns: 0 on success, a negative error code otherwise.
> + */
> +static int inv_icm45600_setup(struct inv_icm45600_state *st,
> + const struct inv_icm45600_chip_info *chip_info,
> + bool reset, inv_icm45600_bus_setup bus_setup)
> +{
> + const struct device *dev = regmap_get_device(st->map);
> + unsigned int val;
> + int ret;
> +
> + /* Set chip bus configuration if specified. */
> + if (bus_setup) {
> + ret = bus_setup(st);
> + if (ret)
> + return ret;
> + }
> +
> + /* Check chip self-identification value. */
> + ret = regmap_read(st->map, INV_ICM45600_REG_WHOAMI, &val);
> + if (ret)
> + return ret;
> + if (val != chip_info->whoami) {
> + /*
> + * SPI interface has no ack mechanism.
> + * 0xFF or 0x00 wwhoami means no response from the device.
whoami?
> + */
> + if (val == U8_MAX || val == 0)
> + return dev_err_probe(dev, -ENODEV,
> + "Invalid whoami %#02x expected %#02x (%s)\n",
> + val, chip_info->whoami, chip_info->name);
> +
> + dev_warn(dev, "Unexpected whoami %#02x expected %#02x (%s)\n",
> + val, chip_info->whoami, chip_info->name);
> + }
> +
> + st->chip_info = chip_info;
> +
> + if (reset) {
> + /* Reset previous state. */
> + ret = regmap_write(st->map, INV_ICM45600_REG_MISC2,
> + INV_ICM45600_MISC2_SOFT_RESET);
> + if (ret)
> + return ret;
> + /*
> + * IMU reset time.
> + * Datasheet: 16.84 REG_MISC2
> + */
> + fsleep(USEC_PER_MSEC);
> +
> + if (bus_setup) {
> + ret = bus_setup(st);
> + if (ret)
> + return ret;
> + }
> +
> + ret = regmap_read(st->map, INV_ICM45600_REG_INT_STATUS, &val);
> + if (ret)
> + return ret;
> + if (!(val & INV_ICM45600_INT_STATUS_RESET_DONE)) {
> + dev_err(dev, "reset error, reset done bit not set\n");
> + return -ENODEV;
> + }
> + }
> +
> + return inv_icm45600_set_conf(st, chip_info->conf);
> +}
> +
> +/* Runtime suspend will turn off sensors that are enabled by iio devices. */
> +static int inv_icm45600_runtime_suspend(struct device *dev)
> +{
> + struct inv_icm45600_state *st = dev_get_drvdata(dev);
> + int ret;
> +
> + guard(mutex)(&st->lock);
> +
> + /* disable all sensors */
> + ret = inv_icm45600_set_pwr_mgmt0(st, INV_ICM45600_SENSOR_MODE_OFF,
> + INV_ICM45600_SENSOR_MODE_OFF, NULL);
> + if (ret)
> + return ret;
> +
> + regulator_disable(st->vddio_supply);
> +
> + return 0;
> +}
> +
> +/* Sensors are enabled by iio devices, no need to turn them back on here. */
> +static int inv_icm45600_runtime_resume(struct device *dev)
> +{
> + struct inv_icm45600_state *st = dev_get_drvdata(dev);
> +
> + guard(mutex)(&st->lock);
Trivial but why is the lock needed? I'm fairly sure nothing can race
with this regulator getting reenabled.
I guess, given you are holding the lock in the suspend path across regulator
disable this is reasonable for balance if not strictly needed.
So leave this if you like.
> +
> + return inv_icm45600_enable_regulator_vddio(st);
> +}
> +
> +EXPORT_NS_GPL_DEV_PM_OPS(inv_icm45600_pm_ops, IIO_ICM45600) = {
> + SYSTEM_SLEEP_PM_OPS(inv_icm45600_suspend, inv_icm45600_resume)
> + RUNTIME_PM_OPS(inv_icm45600_runtime_suspend,
> + inv_icm45600_runtime_resume, NULL)
> +};
> +
> +MODULE_AUTHOR("InvenSense, Inc.");
> +MODULE_DESCRIPTION("InvenSense ICM-456xx device driver");
> +MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS("IIO_INV_SENSORS_TIMESTAMP");
>
next prev parent reply other threads:[~2025-09-28 8:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 9:23 [PATCH v6 0/9] iio: imu: new inv_icm45600 driver Remi Buisson via B4 Relay
2025-09-24 9:23 ` [PATCH v6 1/9] dt-bindings: iio: imu: Add inv_icm45600 Remi Buisson via B4 Relay
2025-09-24 19:17 ` Conor Dooley
2025-09-24 9:23 ` [PATCH v6 2/9] iio: imu: inv_icm45600: add new inv_icm45600 driver Remi Buisson via B4 Relay
2025-09-28 8:30 ` Jonathan Cameron [this message]
2025-09-24 9:23 ` [PATCH v6 3/9] iio: imu: inv_icm45600: add buffer support in iio devices Remi Buisson via B4 Relay
2025-09-28 8:45 ` Jonathan Cameron
2025-10-01 12:07 ` Remi Buisson
2025-10-04 15:41 ` Jonathan Cameron
2025-09-24 9:23 ` [PATCH v6 4/9] iio: imu: inv_icm45600: add IMU IIO gyroscope device Remi Buisson via B4 Relay
2025-09-28 8:52 ` Jonathan Cameron
2025-09-24 9:23 ` [PATCH v6 5/9] iio: imu: inv_icm45600: add IMU IIO accelerometer device Remi Buisson via B4 Relay
2025-09-24 9:23 ` [PATCH v6 6/9] iio: imu: inv_icm45600: add I2C driver for inv_icm45600 driver Remi Buisson via B4 Relay
2025-09-24 9:24 ` [PATCH v6 7/9] iio: imu: inv_icm45600: add SPI " Remi Buisson via B4 Relay
2025-09-25 0:34 ` kernel test robot
2025-09-28 9:00 ` Jonathan Cameron
2025-09-24 9:24 ` [PATCH v6 8/9] iio: imu: inv_icm45600: add I3C " Remi Buisson via B4 Relay
2025-09-24 9:24 ` [PATCH v6 9/9] MAINTAINERS: add entry for inv_icm45600 6-axis imu sensor Remi Buisson via B4 Relay
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=20250928093000.6753d920@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=devnull+remi.buisson.tdk.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=remi.buisson@tdk.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).