* [PATCH RESEND 1/2] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit
@ 2014-02-04 9:15 Beomho Seo
2014-02-08 10:25 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Beomho Seo @ 2014-02-04 9:15 UTC (permalink / raw)
To: linux-iio, ldewangan
Cc: Jonathan Cameron, Peter Meerwald, Myungjoo Ham, Jaehoon Chung
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>
---
drivers/iio/magnetometer/ak8975.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index ff284e5..0542354 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -85,6 +85,7 @@
#define AK8975_MAX_CONVERSION_TIMEOUT 500
#define AK8975_CONVERSION_DONE_POLL_TIME 10
#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
+#define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256)
/*
* Per-instance context data for the device.
@@ -265,15 +266,15 @@ static int ak8975_setup(struct i2c_client *client)
*
* Since 1uT = 0.01 gauss, our final scale factor becomes:
*
- * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100
- * Hadj = H * ((ASA + 128) * 30 / 256
+ * Hadj = H * ((ASA + 128) / 256) * 3/10 * 1/100
+ * Hadj = H * ((ASA + 128) * 0.003) / 256
*
* Since ASA doesn't change, we cache the resultant scale factor into the
* device context in ak8975_setup().
*/
- data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8;
- data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8;
- data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8;
+ data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
+ data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
+ data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
return 0;
}
@@ -428,8 +429,9 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_RAW:
return ak8975_read_axis(indio_dev, chan->address, val);
case IIO_CHAN_INFO_SCALE:
- *val = data->raw_to_gauss[chan->address];
- return IIO_VAL_INT;
+ *val = 0;
+ *val2 = data->raw_to_gauss[chan->address];
+ return IIO_VAL_INT_PLUS_MICRO;
}
return -EINVAL;
}
--
1.7.9.5
--
Best Regards,
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND 1/2] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit
2014-02-04 9:15 [PATCH RESEND 1/2] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit Beomho Seo
@ 2014-02-08 10:25 ` Jonathan Cameron
2014-02-08 10:28 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2014-02-08 10:25 UTC (permalink / raw)
To: Beomho Seo, linux-iio, ldewangan
Cc: Peter Meerwald, Myungjoo Ham, Jaehoon Chung
On 04/02/14 09:15, Beomho Seo wrote:
>
> 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>
Applied to the fixes-togreg branch of iio.git
Thanks,
> ---
> drivers/iio/magnetometer/ak8975.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index ff284e5..0542354 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -85,6 +85,7 @@
> #define AK8975_MAX_CONVERSION_TIMEOUT 500
> #define AK8975_CONVERSION_DONE_POLL_TIME 10
> #define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
> +#define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256)
>
> /*
> * Per-instance context data for the device.
> @@ -265,15 +266,15 @@ static int ak8975_setup(struct i2c_client *client)
> *
> * Since 1uT = 0.01 gauss, our final scale factor becomes:
> *
> - * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100
> - * Hadj = H * ((ASA + 128) * 30 / 256
> + * Hadj = H * ((ASA + 128) / 256) * 3/10 * 1/100
> + * Hadj = H * ((ASA + 128) * 0.003) / 256
> *
> * Since ASA doesn't change, we cache the resultant scale factor into the
> * device context in ak8975_setup().
> */
> - data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8;
> - data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8;
> - data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8;
> + data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
> + data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
> + data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
>
> return 0;
> }
> @@ -428,8 +429,9 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_RAW:
> return ak8975_read_axis(indio_dev, chan->address, val);
> case IIO_CHAN_INFO_SCALE:
> - *val = data->raw_to_gauss[chan->address];
> - return IIO_VAL_INT;
> + *val = 0;
> + *val2 = data->raw_to_gauss[chan->address];
> + return IIO_VAL_INT_PLUS_MICRO;
> }
> return -EINVAL;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND 1/2] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit
2014-02-08 10:25 ` Jonathan Cameron
@ 2014-02-08 10:28 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2014-02-08 10:28 UTC (permalink / raw)
To: Beomho Seo, linux-iio, ldewangan
Cc: Peter Meerwald, Myungjoo Ham, Jaehoon Chung
On 08/02/14 10:25, Jonathan Cameron wrote:
> On 04/02/14 09:15, Beomho Seo wrote:
>>
>> 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>
> Applied to the fixes-togreg branch of iio.git
>
> Thanks,
I forgot to mention that I added a line to the description on what the effect of the bug
was and also marked this for stable.
Thanks,
Jonathan
>> ---
>> drivers/iio/magnetometer/ak8975.c | 16 +++++++++-------
>> 1 file changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
>> index ff284e5..0542354 100644
>> --- a/drivers/iio/magnetometer/ak8975.c
>> +++ b/drivers/iio/magnetometer/ak8975.c
>> @@ -85,6 +85,7 @@
>> #define AK8975_MAX_CONVERSION_TIMEOUT 500
>> #define AK8975_CONVERSION_DONE_POLL_TIME 10
>> #define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
>> +#define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256)
>>
>> /*
>> * Per-instance context data for the device.
>> @@ -265,15 +266,15 @@ static int ak8975_setup(struct i2c_client *client)
>> *
>> * Since 1uT = 0.01 gauss, our final scale factor becomes:
>> *
>> - * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100
>> - * Hadj = H * ((ASA + 128) * 30 / 256
>> + * Hadj = H * ((ASA + 128) / 256) * 3/10 * 1/100
>> + * Hadj = H * ((ASA + 128) * 0.003) / 256
>> *
>> * Since ASA doesn't change, we cache the resultant scale factor into the
>> * device context in ak8975_setup().
>> */
>> - data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8;
>> - data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8;
>> - data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8;
>> + data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
>> + data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
>> + data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
>>
>> return 0;
>> }
>> @@ -428,8 +429,9 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
>> case IIO_CHAN_INFO_RAW:
>> return ak8975_read_axis(indio_dev, chan->address, val);
>> case IIO_CHAN_INFO_SCALE:
>> - *val = data->raw_to_gauss[chan->address];
>> - return IIO_VAL_INT;
>> + *val = 0;
>> + *val2 = data->raw_to_gauss[chan->address];
>> + return IIO_VAL_INT_PLUS_MICRO;
>> }
>> return -EINVAL;
>> }
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-08 10:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-04 9:15 [PATCH RESEND 1/2] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit Beomho Seo
2014-02-08 10:25 ` Jonathan Cameron
2014-02-08 10:28 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.