From: David Lechner <dlechner@baylibre.com>
To: Chris Morgan <macromorgan@hotmail.com>
Cc: Chris Morgan <macroalpha82@gmail.com>,
linux-iio@vger.kernel.org, andy@kernel.org, nuno.sa@analog.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, andriy.shevchenko@intel.com
Subject: Re: [PATCH V3 6/9] iio: imu: inv_icm42607: Add Accelerometer for icm42607
Date: Tue, 28 Apr 2026 10:09:20 -0500 [thread overview]
Message-ID: <6347ce16-bf5c-4da4-91ba-fe6c88713b51@baylibre.com> (raw)
In-Reply-To: <PH0PR19MB997338EE6A13BD08879C4B9B2BA5372@PH0PR19MB997338.namprd19.prod.outlook.com>
On 4/28/26 9:01 AM, Chris Morgan wrote:
> On Fri, Apr 10, 2026 at 05:59:05PM -0500, David Lechner wrote:
>> On 3/30/26 2:58 PM, Chris Morgan wrote:
>>> From: Chris Morgan <macromorgan@hotmail.com>
>>>
>>> Add icm42607 accelerometer sensor for icm42607.
>>>
>>
...
>>
>> Usually we make these 2-D arrays for readability and then cast to int * if needed.
>>
>>> +static const int inv_icm42607_accel_scale[] = {
>>> + /* +/- 16G => 0.004788403 m/s-2 */
>>> + [2 * INV_ICM42607_ACCEL_FS_16G] = 0,
>>> + [2 * INV_ICM42607_ACCEL_FS_16G + 1] = 4788403,
>>> + /* +/- 8G => 0.002394202 m/s-2 */
>>> + [2 * INV_ICM42607_ACCEL_FS_8G] = 0,
>>> + [2 * INV_ICM42607_ACCEL_FS_8G + 1] = 2394202,
>>> + /* +/- 4G => 0.001197101 m/s-2 */
>>> + [2 * INV_ICM42607_ACCEL_FS_4G] = 0,
>>> + [2 * INV_ICM42607_ACCEL_FS_4G + 1] = 1197101,
>>> + /* +/- 2G => 0.000598550 m/s-2 */
>>> + [2 * INV_ICM42607_ACCEL_FS_2G] = 0,
>>> + [2 * INV_ICM42607_ACCEL_FS_2G + 1] = 598550,
>>> +};
>>> +
>
> I've gone through and implemented all of the changes everyone suggested, though
> this is one of the few on which I had a question. Obviously this driver was
> cobbled together from 2 different sources and checked to the best of my ability
> and tested/validated against the data sheet, but there are a few bits I'm not
> fully clear on such as this.
>
> What's the correct way to represent this data? Since it looks like one of the
> values is always 0, should I just assume it's always 0 and only represent the
> values that change in this scale?
>
Picking a random driver, bma220 has the most usual way of doing it.
static const int bma220_scale_table[][2] = {
{ 0, 623000 }, { 1, 248000 }, { 2, 491000 }, { 4, 983000 },
};
I do like using the enum to make it self documenting though (no
comments needed), so for this driver...
static const int inv_icm42607_accel_scale_nano[][2] = {
[INV_ICM42607_ACCEL_FS_16G] = { 0, 4788403 },
...
};
Then the read_avail callback in bma220 does:
case IIO_CHAN_INFO_SCALE:
*vals = (int *)bma220_scale_table;
*type = IIO_VAL_INT_PLUS_MICRO;
*length = ARRAY_SIZE(bma220_scale_table) * 2;
return IIO_AVAIL_LIST;
Although the cast would be better as `(const int *)` and I assume
you would want to use NANO instead of MICRO.
>>
>>> +int inv_icm42607_set_accel_conf(struct inv_icm42607_state *st,
>>> + struct inv_icm42607_sensor_conf *conf,
>>> + unsigned int *sleep_ms)
>>> +{
>>> + struct inv_icm42607_sensor_conf *oldconf = &st->conf.accel;
>>> + unsigned int val;
>>> + int ret;
>>> +
>>> + if (conf->mode < 0)
>>> + conf->mode = oldconf->mode;
>>> + if (conf->fs < 0)
>>> + conf->fs = oldconf->fs;
>>> + if (conf->odr < 0)
>>> + conf->odr = oldconf->odr;
>>> + if (conf->filter < 0)
>>> + conf->filter = oldconf->filter;
>>> +
>>> + if (conf->fs != oldconf->fs || conf->odr != oldconf->odr) {
>>
>> We could use the regmap cache feature to avoid having to manual keep
>> track of old values. Or just always write the same values anyway. I
>> find that is nice when debugging hardware with a logic analyzer. Unless
>> there is some measureable performance improvlment here?
>
> This is another one I had a question on. I'm not entirely clear from the
> datasheet which reg values are volatile and which ones are safe to cache.
> Performance wise the 42607 series appears to be the *least* performant
> in their lineup, so I don't imagine we care much either way. Should I just
> not worry about the old values and always write? Do you think that would
> work?
>
My personal preference is to always do extra SPI writes for anything
that is not performance critical. This makes debugging with a logic
analyzer much easier.
In cases where using caching makes sense, generally, "status" registers
are volatile because the chip can change the value when status changes.
"config" registers are not volatile because they don't change unless
written to.
next prev parent reply other threads:[~2026-04-28 15:09 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 19:58 [PATCH V3 0/9] Add Invensense ICM42607 Chris Morgan
2026-03-30 19:58 ` [PATCH V3 1/9] dt-bindings: iio: imu: icm42607: Add devicetree binding Chris Morgan
2026-04-08 13:19 ` Rob Herring
2026-04-08 14:31 ` Chris Morgan
2026-04-08 19:44 ` Rob Herring
2026-03-30 19:58 ` [PATCH V3 2/9] iio: imu: inv_icm42607: Add Core for inv_icm42607 Driver Chris Morgan
2026-04-10 22:06 ` David Lechner
2026-04-13 19:06 ` Jonathan Cameron
2026-04-14 7:14 ` Andy Shevchenko
2026-04-14 18:29 ` Jonathan Cameron
2026-03-30 19:58 ` [PATCH V3 3/9] iio: imu: inv_icm42607: Add I2C and SPI For icm42607 Chris Morgan
2026-04-10 22:21 ` David Lechner
2026-03-30 19:58 ` [PATCH V3 4/9] iio: imu: inv_icm42607: Add Buffer support functions to icm42607 Chris Morgan
2026-04-13 19:23 ` Jonathan Cameron
2026-03-30 19:58 ` [PATCH V3 5/9] iio: imu: inv_icm42607: Add Temperature Support in icm42607 Chris Morgan
2026-04-10 22:34 ` David Lechner
2026-03-30 19:58 ` [PATCH V3 6/9] iio: imu: inv_icm42607: Add Accelerometer for icm42607 Chris Morgan
2026-04-10 22:59 ` David Lechner
2026-04-28 14:01 ` Chris Morgan
2026-04-28 15:09 ` David Lechner [this message]
2026-04-29 19:46 ` Andy Shevchenko
2026-04-13 19:32 ` Jonathan Cameron
2026-03-30 19:58 ` [PATCH V3 7/9] iio: imu: inv_icm42607: Add Interrupt and Wake on Movement " Chris Morgan
2026-04-13 19:37 ` Jonathan Cameron
2026-03-30 19:58 ` [PATCH V3 8/9] iio: imu: inv_icm42607: Add Gyroscope to icm42607 Chris Morgan
2026-04-13 19:39 ` Jonathan Cameron
2026-03-30 19:58 ` [PATCH V3 9/9] arm64: dts: rockchip: Add icm42607p IMU for RG-DS Chris Morgan
2026-03-31 11:25 ` [PATCH V3 0/9] Add Invensense ICM42607 Andy Shevchenko
2026-03-31 15:15 ` 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=6347ce16-bf5c-4da4-91ba-fe6c88713b51@baylibre.com \
--to=dlechner@baylibre.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox