From: Jonathan Cameron <jic23@kernel.org>
To: Kanak Shilledar <kanak.shilledar@axis.com>
Cc: "Henrik Grimler" <henrik.grimler@axis.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>,
"Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
"Joshua Crofts" <joshua.crofts1@gmail.com>,
"Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
"Chris Morgan" <macromorgan@hotmail.com>,
kernel@axis.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 5/5] iio: imu: inv_icm42607: Add accelerometer calibbias support
Date: Mon, 21 Sep 2026 00:55:38 +0100 [thread overview]
Message-ID: <20260921005538.41e600b9@jic23-hlaptop> (raw)
In-Reply-To: <20260917-b4-inv_icm42370p-v4-5-fd9373f123c9@axis.com>
On Thu, 17 Sep 2026 15:38:20 +0200
Kanak Shilledar <kanak.shilledar@axis.com> wrote:
> Expose IIO_CHAN_INFO_CALIBBIAS on the accelerometer channels. The
> registers are stored in MREG1. The calibration bias is written to
> OFFSET_USER4 to OFFSET_USER8 registers in MREG1. Reject the out of
> limit calibbias values instead of clamping it.
>
> Note: The accelerometer functionality is tested with Invensense,
> ICM42370-P development board.
>
> Datasheet: https://www.invensense.tdk.com/en-us/products/3-axis/icm-42370-p
> Datasheet: https://www.lcsc.com/product-detail/C5129967.html
> Signed-off-by: Kanak Shilledar <kanak.shilledar@axis.com>
A few comments from me this time.
> +
> +static int inv_icm42607_accel_write_offset(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2)
> +{
> + struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
> + struct device *dev = regmap_get_device(st->map);
> + s32 min, max;
> + s16 offset;
> + s64 val64;
> + int ret;
> +
> + if (chan->type != IIO_ACCEL)
> + return -EINVAL;
> +
> + /* inv_icm42607_accel_calibbias: min - step - max in micro */
> + min = inv_icm42607_accel_calibbias[0] * (long)MEGA -
> + inv_icm42607_accel_calibbias[1];
> + max = inv_icm42607_accel_calibbias[4] * (long)MEGA +
> + inv_icm42607_accel_calibbias[5];
> +
> + val64 = (s64)val * (s64)MEGA;
Shouldn't need to cast them both I think.
> + if (val >= 0)
> + val64 += (s64)val2;
These casts are looking excessive. Check all the other casts
in here.
> + else
> + val64 -= (s64)val2;
> +
> + if (val64 < min || val64 > max)
> + return -EINVAL;
> +
> + /*
> + * Convert m/s² to g then to raw value
> + * m/s² to g: 1 / 9.806650
> + * g to raw 12 bits signed, step 0.5mg: 10000 / 5
> + * val in micro (1000000)
> + * val * 10000 / (9.806650 * 1000000 * 5)
> + */
> + val64 = val64 * 10000LL;
val64 *= 10000;
should be enough unless I'm missing something.
> +
> + /* For rounding, add + or - divisor (9806650 * 5) divided by 2 */
> + if (val64 >= 0)
> + val64 += 9806650 * 5 / 2;
> + else
prev parent reply other threads:[~2026-09-20 23:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 13:38 [PATCH v4 0/5] Add support for InvenSense ICM-42370-P accelerometer Kanak Shilledar
2026-09-17 13:38 ` [PATCH v4 1/5] dt-bindings: Add InvenSense ICM-42370-p accelerometer Kanak Shilledar
2026-09-20 13:52 ` Marcelo Schmitt
2026-09-28 8:55 ` Kanak Shilledar
2026-09-28 17:56 ` Rob Herring
2026-09-29 15:15 ` Marcelo Schmitt
2026-09-28 17:58 ` Rob Herring
2026-09-17 13:38 ` [PATCH v4 2/5] iio: imu: inv_icm42607: Simplify IIO channel macros Kanak Shilledar
2026-09-20 13:55 ` Marcelo Schmitt
2026-09-20 23:29 ` Jonathan Cameron
2026-09-17 13:38 ` [PATCH v4 3/5] iio: imu: inv_icm42607: Add support for ICM-42370-P Kanak Shilledar
2026-09-17 13:49 ` sashiko-bot
2026-09-20 14:03 ` Marcelo Schmitt
2026-09-20 23:33 ` Jonathan Cameron
2026-09-17 13:38 ` [PATCH v4 4/5] iio: imu: inv_icm42607: Implement MREGx register access Kanak Shilledar
2026-09-17 13:51 ` sashiko-bot
2026-09-20 14:09 ` Marcelo Schmitt
2026-09-20 23:51 ` Jonathan Cameron
2026-09-17 13:38 ` [PATCH v4 5/5] iio: imu: inv_icm42607: Add accelerometer calibbias support Kanak Shilledar
2026-09-17 13:50 ` sashiko-bot
2026-09-20 23:55 ` Jonathan Cameron [this message]
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=20260921005538.41e600b9@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=henrik.grimler@axis.com \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=joshua.crofts1@gmail.com \
--cc=kanak.shilledar@axis.com \
--cc=kernel@axis.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=macromorgan@hotmail.com \
--cc=marcelo.schmitt1@gmail.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.