Re: [PATCH] iio: gyro: mpu3050: fix sign of raw angular velocity readings
Jonathan Cameron <[email protected]> Mon, 3 Aug 2026 00:19:47 +0100
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260803001947.4ca48e75@jic23-huawei> |
On Sun, 2 Aug 2026 23:30:31 +0200 Linus Walleij <[email protected]> wrote: > On Sun, Aug 2, 2026 at 8:55=E2=80=AFAM Cong Nguyen <[email protected]> = wrote: >=20 > > The MPU-3050 gyroscope output registers hold 16-bit two's complement > > values; the angular velocity channels are declared with .sign =3D 's'. > > When mpu3050_read_raw() handles IIO_CHAN_INFO_RAW it reads the register > > via a big-endian regmap_bulk_read() and assigns it with: > > > > *val =3D be16_to_cpu(raw_val); > > > > be16_to_cpu() yields an unsigned 16-bit quantity, so negative rates > > (bit 15 set) are reported to userspace as large positive integers > > (e.g. -1 becomes 65535) instead of the correct negative value. > > > > Cast to s16 before the assignment, matching the temperature channel a > > few lines above which already handles the sign correctly. > > > > Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope") > > Cc: [email protected] > > Assisted-by: Claude:claude-opus-4 > > Signed-off-by: Cong Nguyen <[email protected]> =20 >=20 > Reviewed-by: Linus Walleij <[email protected]> Applied to the fixes-togreg branch of iio.git Note this will probably not go upstream until the merge window. Thanks, Jonathan >=20 > Yours, > Linus Walleij