Commit 49549cb2 authored by Nuno Sá's avatar Nuno Sá Committed by Jonathan Cameron

iio: adis16480: Fix scales factors

This patch fixes the scales for the gyroscope, accelerometer and
barometer. The pressure scale was just wrong. For the others, the scale
factors were not taking into account that a 32bit word is being read
from the device.

Fixes: 7abad106 ("iio: adis16480: Fix scale factors")
Fixes: 82e7a1b2 ("iio: imu: adis16480: Add support for ADIS1649x family of devices")
Signed-off-by: default avatarNuno Sá <nuno.sa@analog.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 731b60af
...@@ -622,9 +622,13 @@ static int adis16480_read_raw(struct iio_dev *indio_dev, ...@@ -622,9 +622,13 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
*val2 = (st->chip_info->temp_scale % 1000) * 1000; *val2 = (st->chip_info->temp_scale % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_PRESSURE: case IIO_PRESSURE:
*val = 0; /*
*val2 = 4000; /* 40ubar = 0.004 kPa */ * max scale is 1310 mbar
return IIO_VAL_INT_PLUS_MICRO; * max raw value is 32767 shifted for 32bits
*/
*val = 131; /* 1310mbar = 131 kPa */
*val2 = 32767 << 16;
return IIO_VAL_FRACTIONAL;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -785,13 +789,14 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -785,13 +789,14 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
/* /*
* storing the value in rad/degree and the scale in degree * Typically we do IIO_RAD_TO_DEGREE in the denominator, which
* gives us the result in rad and better precession than * is exactly the same as IIO_DEGREE_TO_RAD in numerator, since
* storing the scale directly in rad. * it gives better approximation. However, in this case we
* cannot do it since it would not fit in a 32bit variable.
*/ */
.gyro_max_val = IIO_RAD_TO_DEGREE(22887), .gyro_max_val = 22887 << 16,
.gyro_max_scale = 300, .gyro_max_scale = IIO_DEGREE_TO_RAD(300),
.accel_max_val = IIO_M_S_2_TO_G(21973), .accel_max_val = IIO_M_S_2_TO_G(21973 << 16),
.accel_max_scale = 18, .accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000, .int_clk = 2460000,
...@@ -801,9 +806,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -801,9 +806,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16480] = { [ADIS16480] = {
.channels = adis16480_channels, .channels = adis16480_channels,
.num_channels = ARRAY_SIZE(adis16480_channels), .num_channels = ARRAY_SIZE(adis16480_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(22500), .gyro_max_val = 22500 << 16,
.gyro_max_scale = 450, .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
.accel_max_val = IIO_M_S_2_TO_G(12500), .accel_max_val = IIO_M_S_2_TO_G(12500 << 16),
.accel_max_scale = 10, .accel_max_scale = 10,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000, .int_clk = 2460000,
...@@ -813,9 +818,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -813,9 +818,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16485] = { [ADIS16485] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(22500), .gyro_max_val = 22500 << 16,
.gyro_max_scale = 450, .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
.accel_max_val = IIO_M_S_2_TO_G(20000), .accel_max_val = IIO_M_S_2_TO_G(20000 << 16),
.accel_max_scale = 5, .accel_max_scale = 5,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000, .int_clk = 2460000,
...@@ -825,9 +830,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -825,9 +830,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16488] = { [ADIS16488] = {
.channels = adis16480_channels, .channels = adis16480_channels,
.num_channels = ARRAY_SIZE(adis16480_channels), .num_channels = ARRAY_SIZE(adis16480_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(22500), .gyro_max_val = 22500 << 16,
.gyro_max_scale = 450, .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
.accel_max_val = IIO_M_S_2_TO_G(22500), .accel_max_val = IIO_M_S_2_TO_G(22500 << 16),
.accel_max_scale = 18, .accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000, .int_clk = 2460000,
...@@ -837,9 +842,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -837,9 +842,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16495_1] = { [ADIS16495_1] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(20000), .gyro_max_val = 20000 << 16,
.gyro_max_scale = 125, .gyro_max_scale = IIO_DEGREE_TO_RAD(125),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 8, .accel_max_scale = 8,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
...@@ -850,9 +855,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -850,9 +855,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16495_2] = { [ADIS16495_2] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(18000), .gyro_max_val = 18000 << 16,
.gyro_max_scale = 450, .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 8, .accel_max_scale = 8,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
...@@ -863,9 +868,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -863,9 +868,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16495_3] = { [ADIS16495_3] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(20000), .gyro_max_val = 20000 << 16,
.gyro_max_scale = 2000, .gyro_max_scale = IIO_DEGREE_TO_RAD(2000),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 8, .accel_max_scale = 8,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
...@@ -876,9 +881,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -876,9 +881,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16497_1] = { [ADIS16497_1] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(20000), .gyro_max_val = 20000 << 16,
.gyro_max_scale = 125, .gyro_max_scale = IIO_DEGREE_TO_RAD(125),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 40, .accel_max_scale = 40,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
...@@ -889,9 +894,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -889,9 +894,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16497_2] = { [ADIS16497_2] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(18000), .gyro_max_val = 18000 << 16,
.gyro_max_scale = 450, .gyro_max_scale = IIO_DEGREE_TO_RAD(450),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 40, .accel_max_scale = 40,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
...@@ -902,9 +907,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -902,9 +907,9 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16497_3] = { [ADIS16497_3] = {
.channels = adis16485_channels, .channels = adis16485_channels,
.num_channels = ARRAY_SIZE(adis16485_channels), .num_channels = ARRAY_SIZE(adis16485_channels),
.gyro_max_val = IIO_RAD_TO_DEGREE(20000), .gyro_max_val = 20000 << 16,
.gyro_max_scale = 2000, .gyro_max_scale = IIO_DEGREE_TO_RAD(2000),
.accel_max_val = IIO_M_S_2_TO_G(32000), .accel_max_val = IIO_M_S_2_TO_G(32000 << 16),
.accel_max_scale = 40, .accel_max_scale = 40,
.temp_scale = 12500, /* 12.5 milli degree Celsius */ .temp_scale = 12500, /* 12.5 milli degree Celsius */
.int_clk = 4250000, .int_clk = 4250000,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment