All of lore.kernel.org
 help / color / mirror / Atom feed
* Bugs in dps310 Linux driver
@ 2023-03-03 11:10 Andres Heinloo
  2023-03-04 17:06 ` Jonathan Cameron
  0 siblings, 1 reply; 9+ messages in thread
From: Andres Heinloo @ 2023-03-03 11:10 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Eddie James, linux-iio

Hello,

I've been struggling with the dps310 driver, which gives incorrect 
pressure values and in particular different values than manufacturers 
code (https://github.com/Infineon/RaspberryPi_DPS).

I think I've found where the problem is. Firstly, there is a mistake 
in bit numbering at 
https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L51

According to datasheet, correct is:

#define  DPS310_INT_HL          BIT(7)
#define  DPS310_TMP_SHIFT_EN    BIT(3)
#define  DPS310_PRS_SHIFT_EN    BIT(2)
#define  DPS310_FIFO_EN         BIT(1)
#define  DPS310_SPI_EN          BIT(0)

Eg., the current code is using wrong bit (4) for DPS310_PRS_SHIFT_EN, 
which means that pressure shift is never enabled.

Secondly, there is a problem with overflows starting at 
https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L654

Since p is a 24-bit value,

nums[3] = p * p * p * (s64)data->c30;

can and does overflow.

Second overflow problem is at 
https://github.com/torvalds/linux/blob/857f1268a591147f7be7509f249dbb3aba6fc65c/drivers/iio/pressure/dps310.c#L684

In fact, I don't understand why 1000000000LL is needed. Since only 7 
values are summed, using 10LL should give the same precision.

Best regards,
Andres

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-03-19 14:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 11:10 Bugs in dps310 Linux driver Andres Heinloo
2023-03-04 17:06 ` Jonathan Cameron
2023-03-05  2:05   ` Andres Heinloo
2023-03-06 21:15     ` Andres Heinloo
2023-03-12 15:43       ` Jonathan Cameron
2023-03-13 16:36         ` Andres Heinloo
2023-03-18 17:09           ` Jonathan Cameron
2023-03-19 14:24             ` Andres Heinloo
2023-03-12 15:46     ` 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.