aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorBeomho Seo <beomho.seo@samsung.com>2014-04-02 04:15:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-02-08 05:28:05 -0500
commitbef44abccb2677e8d16e50b75316d4fd1061be81 (patch)
tree01e79f0cd6e4b5d04e29f8887f858d46b1b2301b /drivers/iio
parentd180371d412627a10dc31d675ef8bc777567df09 (diff)
iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit
This effects the reported scale of the raw values, and thus userspace applications that use this value. One micro tesla equal 0.01 gauss. So I have fixed calculation formula And add RAW_TO_GAUSS macro. ASA is in the range of 0 to 255. If multiply 0.003, calculation result(in_magn_[*]_scale) is always 0. So multiply 3000 and return and IIO_VAL_INT_PLUS_MICRO. As a result, read_raw call back function return accurate scale value. Signed-off-by: Beomho Seo <beomho.seo@samsung.com> Cc: stable@vger.kernel.org Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/magnetometer/ak8975.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index ff284e5afd95..05423543f89d 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -85,6 +85,7 @@
85#define AK8975_MAX_CONVERSION_TIMEOUT 500 85#define AK8975_MAX_CONVERSION_TIMEOUT 500
86#define AK8975_CONVERSION_DONE_POLL_TIME 10 86#define AK8975_CONVERSION_DONE_POLL_TIME 10
87#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) 87#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
88#define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256)
88 89
89/* 90/*
90 * Per-instance context data for the device. 91 * Per-instance context data for the device.
@@ -265,15 +266,15 @@ static int ak8975_setup(struct i2c_client *client)
265 * 266 *
266 * Since 1uT = 0.01 gauss, our final scale factor becomes: 267 * Since 1uT = 0.01 gauss, our final scale factor becomes:
267 * 268 *
268 * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100 269 * Hadj = H * ((ASA + 128) / 256) * 3/10 * 1/100
269 * Hadj = H * ((ASA + 128) * 30 / 256 270 * Hadj = H * ((ASA + 128) * 0.003) / 256
270 * 271 *
271 * Since ASA doesn't change, we cache the resultant scale factor into the 272 * Since ASA doesn't change, we cache the resultant scale factor into the
272 * device context in ak8975_setup(). 273 * device context in ak8975_setup().
273 */ 274 */
274 data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8; 275 data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
275 data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8; 276 data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
276 data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8; 277 data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
277 278
278 return 0; 279 return 0;
279} 280}
@@ -428,8 +429,9 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
428 case IIO_CHAN_INFO_RAW: 429 case IIO_CHAN_INFO_RAW:
429 return ak8975_read_axis(indio_dev, chan->address, val); 430 return ak8975_read_axis(indio_dev, chan->address, val);
430 case IIO_CHAN_INFO_SCALE: 431 case IIO_CHAN_INFO_SCALE:
431 *val = data->raw_to_gauss[chan->address]; 432 *val = 0;
432 return IIO_VAL_INT; 433 *val2 = data->raw_to_gauss[chan->address];
434 return IIO_VAL_INT_PLUS_MICRO;
433 } 435 }
434 return -EINVAL; 436 return -EINVAL;
435} 437}