patch "iio: kx022a: Fix acceleration value scaling" added to char-misc-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
iio: kx022a: Fix acceleration value scaling
to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From 92bfa4ab1b79be95c4f52d13f5386390f0a513c2 Mon Sep 17 00:00:00 2001
From: Matti Vaittinen <[email protected]>
Date: Thu, 19 Oct 2023 16:23:56 +0300
Subject: iio: kx022a: Fix acceleration value scaling
The IIO ABI mandates acceleration values from accelerometer to be emitted in m/s^2. The KX022A was emitting values in micro m/s^2.
Fix driver to report the correct scale values.
--- drivers/iio/accel/kionix-kx022a.c | 37 ++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-)
drivers/iio/accel/kionix-kx022a.c +26 -11
@@ -393,17 +393,17 @@ static const unsigned int kx022a_odrs[] = {* (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2 * => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed * in low-power mode(?) ) -* => +/-2G => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro) -* => +/-2G - 598.550415 -* +/-4G - 1197.10083 -* +/-8G - 2394.20166 -* +/-16G - 4788.40332 +* => +/-2G => 4 / 2^16 * 9,80665 +* => +/-2G - 0.000598550415 +* +/-4G - 0.00119710083 +* +/-8G - 0.00239420166 +* +/-16G - 0.00478840332 */ static const int kx022a_scale_table[][2 ] = { - {598 ,550415 }, - {1197 ,100830 }, - {2394 ,201660 }, - {4788 ,403320 }, + {0 ,598550 }, + {0 ,1197101 }, + {0 ,2394202 }, + {0 ,4788403 }, }; static int kx022a_read_avail(struct iio_dev *indio_dev,
@@ -422,7 +422,7 @@ static int kx022a_read_avail(struct iio_dev *indio_dev, *vals = (const int *)kx022a_scale_table; *length =ARRAY_SIZE (kx022a_scale_table) *ARRAY_SIZE (kx022a_scale_table[0 ]); - *type =IIO_VAL_INT_PLUS_MICRO ; + *type =IIO_VAL_INT_PLUS_NANO ;return IIO_AVAIL_LIST ;default :return -EINVAL ;
@@ -485,6 +485,20 @@ static int kx022a_turn_on_unlock(struct kx022a_data *data)return ret; } +static int kx022a_write_raw_get_fmt (struct iio_dev *idev, +struct iio_chan_spec const *chan, +long mask) +{ +switch (mask) { +case IIO_CHAN_INFO_SCALE : +return IIO_VAL_INT_PLUS_NANO ; +case IIO_CHAN_INFO_SAMP_FREQ : +return IIO_VAL_INT_PLUS_MICRO ; +default : +return -EINVAL ; + } +} +static int kx022a_write_raw (struct iio_dev *idev,struct iio_chan_spec const *chan,int val,int val2,long mask)
@@ -629,7 +643,7 @@ static int kx022a_read_raw(struct iio_dev *idev,kx022a_reg2scale (regval, val, val2); -return IIO_VAL_INT_PLUS_MICRO ; +return IIO_VAL_INT_PLUS_NANO ; }return -EINVAL ;
@@ -856,6 +870,7 @@ static int kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples)static const struct iio_info kx022a_info = { .read_raw = &kx022a_read_raw, .write_raw = &kx022a_write_raw, + .write_raw_get_fmt = &kx022a_write_raw_get_fmt, .read_avail = &kx022a_read_avail, .validate_trigger = iio_validate_own_trigger,
Signature · 1 line
2.43.0