Skip to content

Commit 92bfa4a

Browse files
M-Vaittinenjic23
authored andcommitted
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. Signed-off-by: Matti Vaittinen <[email protected]> Reported-by: Jagath Jog J <[email protected]> Fixes: 7c1d167 ("iio: accel: Support Kionix/ROHM KX022A accelerometer") Tested-by: Jagath Jog J <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent b85ea95 commit 92bfa4a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

drivers/iio/accel/kionix-kx022a.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,17 @@ static const unsigned int kx022a_odrs[] = {
393393
* (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2
394394
* => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed
395395
* in low-power mode(?) )
396-
* => +/-2G => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro)
397-
* => +/-2G - 598.550415
398-
* +/-4G - 1197.10083
399-
* +/-8G - 2394.20166
400-
* +/-16G - 4788.40332
396+
* => +/-2G => 4 / 2^16 * 9,80665
397+
* => +/-2G - 0.000598550415
398+
* +/-4G - 0.00119710083
399+
* +/-8G - 0.00239420166
400+
* +/-16G - 0.00478840332
401401
*/
402402
static const int kx022a_scale_table[][2] = {
403-
{ 598, 550415 },
404-
{ 1197, 100830 },
405-
{ 2394, 201660 },
406-
{ 4788, 403320 },
403+
{ 0, 598550 },
404+
{ 0, 1197101 },
405+
{ 0, 2394202 },
406+
{ 0, 4788403 },
407407
};
408408

409409
static int kx022a_read_avail(struct iio_dev *indio_dev,
@@ -422,7 +422,7 @@ static int kx022a_read_avail(struct iio_dev *indio_dev,
422422
*vals = (const int *)kx022a_scale_table;
423423
*length = ARRAY_SIZE(kx022a_scale_table) *
424424
ARRAY_SIZE(kx022a_scale_table[0]);
425-
*type = IIO_VAL_INT_PLUS_MICRO;
425+
*type = IIO_VAL_INT_PLUS_NANO;
426426
return IIO_AVAIL_LIST;
427427
default:
428428
return -EINVAL;
@@ -485,6 +485,20 @@ static int kx022a_turn_on_unlock(struct kx022a_data *data)
485485
return ret;
486486
}
487487

488+
static int kx022a_write_raw_get_fmt(struct iio_dev *idev,
489+
struct iio_chan_spec const *chan,
490+
long mask)
491+
{
492+
switch (mask) {
493+
case IIO_CHAN_INFO_SCALE:
494+
return IIO_VAL_INT_PLUS_NANO;
495+
case IIO_CHAN_INFO_SAMP_FREQ:
496+
return IIO_VAL_INT_PLUS_MICRO;
497+
default:
498+
return -EINVAL;
499+
}
500+
}
501+
488502
static int kx022a_write_raw(struct iio_dev *idev,
489503
struct iio_chan_spec const *chan,
490504
int val, int val2, long mask)
@@ -629,7 +643,7 @@ static int kx022a_read_raw(struct iio_dev *idev,
629643

630644
kx022a_reg2scale(regval, val, val2);
631645

632-
return IIO_VAL_INT_PLUS_MICRO;
646+
return IIO_VAL_INT_PLUS_NANO;
633647
}
634648

635649
return -EINVAL;
@@ -856,6 +870,7 @@ static int kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples)
856870
static const struct iio_info kx022a_info = {
857871
.read_raw = &kx022a_read_raw,
858872
.write_raw = &kx022a_write_raw,
873+
.write_raw_get_fmt = &kx022a_write_raw_get_fmt,
859874
.read_avail = &kx022a_read_avail,
860875

861876
.validate_trigger = iio_validate_own_trigger,

0 commit comments

Comments
 (0)