Re: [PATCH] iio: gyro: mpu3050: fix sign of raw angular velocity readings
Joshua Crofts <[email protected]> Sun, 2 Aug 2026 17:55:47 +0200
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260802175517.288bd5a9@systembl0wer> |
On Sun, 2 Aug 2026 13:55:40 +0700 Cong Nguyen <[email protected]> wrote: > The MPU-3050 gyroscope output registers hold 16-bit two's complement > values; the angular velocity channels are declared with .sign = '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 = 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. > LGTM. Reviewed-by: Joshua Crofts <[email protected]> -- Kind regards, Joshua Crofts