* [PATCH 1/3]iio:pressure:bmp280: fix pressure calculation
@ 2014-10-31 1:22 Hartmut Knaack
2014-10-31 11:43 ` Vlad Dogaru
0 siblings, 1 reply; 3+ messages in thread
From: Hartmut Knaack @ 2014-10-31 1:22 UTC (permalink / raw)
To: IIO; +Cc: vlad.dogaru
According to the datasheet and as defined in struct bmp280_comp_press, dig_p1 is
of type u16, while dig_p2 to dig_p9 are of type s16. In
bmp280_read_compensation_press(), values read from the device were treated as
the wrong type.
In bmp280_read_press() the fractional part of the measured pressure is
calculated wrong. A better way is to use *val for the raw pressure and *val2 for
the quotient and let the core do the proper conversion using IIO_VAL_FRACTIONAL.
Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
---
diff --git a/drivers/iio/pressure/bmp280.c b/drivers/iio/pressure/bmp280.c
index ce29ff9..75038da 100644
--- a/drivers/iio/pressure/bmp280.c
+++ b/drivers/iio/pressure/bmp280.c
@@ -176,15 +176,15 @@ static int bmp280_read_compensation_press(struct bmp280_data *data,
return ret;
}
- comp->dig_p1 = (s16) le16_to_cpu(buf[0]);
- comp->dig_p2 = (u16) le16_to_cpu(buf[1]);
- comp->dig_p3 = (u16) le16_to_cpu(buf[2]);
- comp->dig_p4 = (u16) le16_to_cpu(buf[3]);
- comp->dig_p5 = (u16) le16_to_cpu(buf[4]);
- comp->dig_p6 = (u16) le16_to_cpu(buf[5]);
- comp->dig_p7 = (u16) le16_to_cpu(buf[6]);
- comp->dig_p8 = (u16) le16_to_cpu(buf[7]);
- comp->dig_p9 = (u16) le16_to_cpu(buf[8]);
+ comp->dig_p1 = (u16) le16_to_cpu(buf[0]);
+ comp->dig_p2 = (s16) le16_to_cpu(buf[1]);
+ comp->dig_p3 = (s16) le16_to_cpu(buf[2]);
+ comp->dig_p4 = (s16) le16_to_cpu(buf[3]);
+ comp->dig_p5 = (s16) le16_to_cpu(buf[4]);
+ comp->dig_p6 = (s16) le16_to_cpu(buf[5]);
+ comp->dig_p7 = (s16) le16_to_cpu(buf[6]);
+ comp->dig_p8 = (s16) le16_to_cpu(buf[7]);
+ comp->dig_p9 = (s16) le16_to_cpu(buf[8]);
return 0;
}
@@ -309,10 +309,10 @@ static int bmp280_read_press(struct bmp280_data *data,
adc_press = be32_to_cpu(tmp) >> 12;
comp_press = bmp280_compensate_press(data, &comp, adc_press);
- *val = comp_press / 256000;
- *val2 = comp_press * 1000000 / 256000;
+ *val = comp_press;
+ *val2 = 256000;
- return IIO_VAL_INT_PLUS_MICRO;
+ return IIO_VAL_FRACTIONAL;
}
static int bmp280_read_raw(struct iio_dev *indio_dev,
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3]iio:pressure:bmp280: fix pressure calculation
2014-10-31 1:22 [PATCH 1/3]iio:pressure:bmp280: fix pressure calculation Hartmut Knaack
@ 2014-10-31 11:43 ` Vlad Dogaru
2014-11-05 15:57 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Vlad Dogaru @ 2014-10-31 11:43 UTC (permalink / raw)
To: Hartmut Knaack; +Cc: IIO
On Fri, Oct 31, 2014 at 02:22:28AM +0100, Hartmut Knaack wrote:
> According to the datasheet and as defined in struct bmp280_comp_press, dig_p1 is
> of type u16, while dig_p2 to dig_p9 are of type s16. In
> bmp280_read_compensation_press(), values read from the device were treated as
> the wrong type.
> In bmp280_read_press() the fractional part of the measured pressure is
> calculated wrong. A better way is to use *val for the raw pressure and *val2 for
> the quotient and let the core do the proper conversion using IIO_VAL_FRACTIONAL.
>
> Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Acked-by: Vlad Dogaru <vlad.dogaru@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3]iio:pressure:bmp280: fix pressure calculation
2014-10-31 11:43 ` Vlad Dogaru
@ 2014-11-05 15:57 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2014-11-05 15:57 UTC (permalink / raw)
To: Vlad Dogaru, Hartmut Knaack; +Cc: IIO
On 31/10/14 11:43, Vlad Dogaru wrote:
> On Fri, Oct 31, 2014 at 02:22:28AM +0100, Hartmut Knaack wrote:
>> According to the datasheet and as defined in struct bmp280_comp_press, dig_p1 is
>> of type u16, while dig_p2 to dig_p9 are of type s16. In
>> bmp280_read_compensation_press(), values read from the device were treated as
>> the wrong type.
>> In bmp280_read_press() the fractional part of the measured pressure is
>> calculated wrong. A better way is to use *val for the raw pressure and *val2 for
>> the quotient and let the core do the proper conversion using IIO_VAL_FRACTIONAL.
>>
>> Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
>
> Acked-by: Vlad Dogaru <vlad.dogaru@intel.com>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play.
Thanks,
Jonathan
> --
> 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-11-05 15:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-31 1:22 [PATCH 1/3]iio:pressure:bmp280: fix pressure calculation Hartmut Knaack
2014-10-31 11:43 ` Vlad Dogaru
2014-11-05 15:57 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).