iio: adis16480: Fix scale factors

The different devices support by the adis16480 driver have slightly
different scales for the gyroscope and accelerometer channels.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Lars-Peter Clausen 2015-08-05 15:38:15 +02:00 committed by Jonathan Cameron
parent c689a923c8
commit 7abad1063d
1 changed files with 33 additions and 6 deletions

View File

@ -110,6 +110,10 @@
struct adis16480_chip_info { struct adis16480_chip_info {
unsigned int num_channels; unsigned int num_channels;
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
unsigned int gyro_max_val;
unsigned int gyro_max_scale;
unsigned int accel_max_val;
unsigned int accel_max_scale;
}; };
struct adis16480 { struct adis16480 {
@ -497,19 +501,21 @@ static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
static int adis16480_read_raw(struct iio_dev *indio_dev, static int adis16480_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val, int *val2, long info) const struct iio_chan_spec *chan, int *val, int *val2, long info)
{ {
struct adis16480 *st = iio_priv(indio_dev);
switch (info) { switch (info) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
return adis_single_conversion(indio_dev, chan, 0, val); return adis_single_conversion(indio_dev, chan, 0, val);
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
switch (chan->type) { switch (chan->type) {
case IIO_ANGL_VEL: case IIO_ANGL_VEL:
*val = 0; *val = st->chip_info->gyro_max_scale;
*val2 = IIO_DEGREE_TO_RAD(20000); /* 0.02 degree/sec */ *val2 = st->chip_info->gyro_max_val;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_FRACTIONAL;
case IIO_ACCEL: case IIO_ACCEL:
*val = 0; *val = st->chip_info->accel_max_scale;
*val2 = IIO_G_TO_M_S_2(800); /* 0.8 mg */ *val2 = st->chip_info->accel_max_val;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_FRACTIONAL;
case IIO_MAGN: case IIO_MAGN:
*val = 0; *val = 0;
*val2 = 100; /* 0.0001 gauss */ *val2 = 100; /* 0.0001 gauss */
@ -674,18 +680,39 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
[ADIS16375] = { [ADIS16375] = {
.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
* gives us the result in rad and better precession than
* storing the scale directly in rad.
*/
.gyro_max_val = IIO_RAD_TO_DEGREE(22887),
.gyro_max_scale = 300,
.accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18,
}, },
[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_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 5,
}, },
[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_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(20000),
.accel_max_scale = 5,
}, },
[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_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18,
}, },
}; };