* [PATCH 1/7] iio: pressure: dps310: sort register field defines low to high
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*() Rupesh Majhi
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
Some field defines run from the high bit down, others from the low bit
up. Sort them all low to high.
Suggested-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 9ffef150cc4c..02dbc5a8ac37 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -51,13 +51,13 @@
#define DPS310_TMP_B1 0x04
#define DPS310_TMP_B2 0x05
#define DPS310_PRS_CFG 0x06
-#define DPS310_PRS_RATE_BITS GENMASK(6, 4)
#define DPS310_PRS_PRC_BITS GENMASK(3, 0)
+#define DPS310_PRS_RATE_BITS GENMASK(6, 4)
#define DPS310_TMP_CFG 0x07
-#define DPS310_TMP_RATE_BITS GENMASK(6, 4)
-#define DPS310_TMP_RATE_1SPS 0
#define DPS310_TMP_PRC_BITS GENMASK(3, 0)
#define DPS310_TMP_PRC_1 0
+#define DPS310_TMP_RATE_BITS GENMASK(6, 4)
+#define DPS310_TMP_RATE_1SPS 0
#define DPS310_TMP_EXT BIT(7)
#define DPS310_MEAS_CFG 0x08
#define DPS310_MEAS_CTRL_BITS GENMASK(2, 0)
@@ -69,19 +69,19 @@
#define DPS310_SENSOR_RDY BIT(6)
#define DPS310_COEF_RDY BIT(7)
#define DPS310_CFG_REG 0x09
-#define DPS310_INT_HL BIT(7)
-#define DPS310_INT_TMP BIT(5)
-#define DPS310_INT_PRS BIT(4)
-#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)
+#define DPS310_FIFO_EN BIT(1)
+#define DPS310_PRS_SHIFT_EN BIT(2)
+#define DPS310_TMP_SHIFT_EN BIT(3)
+#define DPS310_INT_PRS BIT(4)
+#define DPS310_INT_TMP BIT(5)
+#define DPS310_INT_HL BIT(7)
#define DPS310_INT_STS 0x0a
-#define DPS310_INT_STS_TMP BIT(1)
#define DPS310_INT_STS_PRS BIT(0)
+#define DPS310_INT_STS_TMP BIT(1)
#define DPS310_RESET 0x0c
-#define DPS310_FIFO_FLUSH BIT(7)
#define DPS310_RESET_MAGIC 0x09
+#define DPS310_FIFO_FLUSH BIT(7)
#define DPS310_COEF_BASE 0x10
#define DPS310_COEF_LEN 18
#define SPL07_COEF_LEN 21
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*()
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
2026-11-23 22:06 ` [PATCH 1/7] iio: pressure: dps310: sort register field defines low to high Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
The coefficients are big endian fields, some of them 12 or 20 bits
wide and not byte aligned. Read each with get_unaligned_be16() or
get_unaligned_be24() and let sign_extend32() drop the bits of the
neighbouring field, as the ZTS8032 coefficients already do.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 36 +++++++++--------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 02dbc5a8ac37..48df5a28c140 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -239,8 +239,6 @@ static int dps310_get_coefs(struct dps310_data *data)
{
int rc;
u8 coef[MAX_COEF_LEN];
- u32 c0, c1;
- u32 c00, c10, c20, c30, c01, c11, c21;
/* Read all sensor calibration coefficients from the COEF registers. */
rc = regmap_bulk_read(data->regmap, DPS310_COEF_BASE, coef,
@@ -252,37 +250,21 @@ static int dps310_get_coefs(struct dps310_data *data)
* Calculate temperature calibration coefficients c0 and c1. The
* numbers are 12-bit 2's complement numbers.
*/
- c0 = (coef[0] << 4) | (coef[1] >> 4);
- data->c0 = sign_extend32(c0, 11);
-
- c1 = ((coef[1] & GENMASK(3, 0)) << 8) | coef[2];
- data->c1 = sign_extend32(c1, 11);
+ data->c0 = sign_extend32(get_unaligned_be16(&coef[0]) >> 4, 11);
+ data->c1 = sign_extend32(get_unaligned_be16(&coef[1]), 11);
/*
* Calculate pressure calibration coefficients. c00 and c10 are 20 bit
* 2's complement numbers, while c01, c11, c20, c21 and c30 are 16 bit
* 2's complement numbers.
*/
- c00 = (coef[3] << 12) | (coef[4] << 4) | (coef[5] >> 4);
- data->c00 = sign_extend32(c00, 19);
-
- c10 = ((coef[5] & GENMASK(3, 0)) << 16) | (coef[6] << 8) | coef[7];
- data->c10 = sign_extend32(c10, 19);
-
- c01 = (coef[8] << 8) | coef[9];
- data->c01 = sign_extend32(c01, 15);
-
- c11 = (coef[10] << 8) | coef[11];
- data->c11 = sign_extend32(c11, 15);
-
- c20 = (coef[12] << 8) | coef[13];
- data->c20 = sign_extend32(c20, 15);
-
- c21 = (coef[14] << 8) | coef[15];
- data->c21 = sign_extend32(c21, 15);
-
- c30 = (coef[16] << 8) | coef[17];
- data->c30 = sign_extend32(c30, 15);
+ data->c00 = sign_extend32(get_unaligned_be24(&coef[3]) >> 4, 19);
+ data->c10 = sign_extend32(get_unaligned_be24(&coef[5]), 19);
+ data->c01 = sign_extend32(get_unaligned_be16(&coef[8]), 15);
+ data->c11 = sign_extend32(get_unaligned_be16(&coef[10]), 15);
+ data->c20 = sign_extend32(get_unaligned_be16(&coef[12]), 15);
+ data->c21 = sign_extend32(get_unaligned_be16(&coef[14]), 15);
+ data->c30 = sign_extend32(get_unaligned_be16(&coef[16]), 15);
if (!data->info->has_c31_c40)
return 0;
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 3/7] iio: pressure: dps310: use min() instead of min_t()
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
2026-11-23 22:06 ` [PATCH 1/7] iio: pressure: dps310: sort register field defines low to high Rupesh Majhi
2026-11-23 22:06 ` [PATCH 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*() Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion Rupesh Majhi
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
min() accepts s64 and int, both signed, so min_t() and the cast are
not needed.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 48df5a28c140..535b77da7654 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -848,7 +848,7 @@ static int dps310_calculate_pressure(struct dps310_data *data, int *val)
if (pressure < 0)
return -ERANGE;
- *val = (int)min_t(s64, pressure, INT_MAX);
+ *val = min(pressure, INT_MAX);
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
` (2 preceding siblings ...)
2026-11-23 22:06 ` [PATCH 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
Spell the Pa to kPa divisor as KILO from units.h, in both places.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 535b77da7654..e5a89dac1325 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -33,6 +33,7 @@
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/unaligned.h>
+#include <linux/units.h>
#include <linux/workqueue.h>
#include <linux/iio/buffer.h>
@@ -895,13 +896,13 @@ static int dps310_read_pressure(struct dps310_data *data, int *val, int *val2,
if (rc)
return rc;
- *val2 = 1000; /* Convert Pa to KPa per IIO ABI */
+ *val2 = KILO; /* Convert Pa to KPa per IIO ABI */
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_SCALE:
/* The raw value is in Pa, the ABI wants kPa */
*val = 1;
- *val2 = 1000;
+ *val2 = KILO;
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
` (3 preceding siblings ...)
2026-11-23 22:06 ` [PATCH 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata() Rupesh Majhi
2026-11-23 22:06 ` [PATCH 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
Write the microsecond values as multiples of USEC_PER_MSEC, like the
poll timeout next to them already uses USEC_PER_SEC. Wait the 15 ms
after a reset with fsleep(), which allows less slack than the old
55 ms upper bound.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index e5a89dac1325..eb5715f75e9e 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -20,6 +20,7 @@
#include <linux/bitfield.h>
#include <linux/cleanup.h>
+#include <linux/delay.h>
#include <linux/devm-helpers.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
@@ -103,7 +104,7 @@
#define DPS310_DRAIN_MAX_MS (2 * MSEC_PER_SEC)
/* Make sure sleep time is <= 30ms for usleep_range */
-#define DPS310_POLL_SLEEP_US(t) min(30000, (t) / 8)
+#define DPS310_POLL_SLEEP_US(t) min(30 * USEC_PER_MSEC, (t) / 8)
/* A period plus a measurement time; silently handle error in rate value */
#define DPS310_POLL_TIMEOUT_US(rc) (2 * USEC_PER_SEC / max(rc, 1))
@@ -370,7 +371,8 @@ static int dps310_startup(struct dps310_data *data)
* They are available 40ms after the device has started
*/
rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready,
- ready & DPS310_COEF_RDY, 10000, 40000);
+ ready & DPS310_COEF_RDY,
+ 10 * USEC_PER_MSEC, 40 * USEC_PER_MSEC);
if (rc)
return rc;
@@ -558,7 +560,7 @@ static int dps310_reset_wait(struct dps310_data *data)
return rc;
/* Wait for device chip access: 15ms in specification */
- usleep_range(15000, 55000);
+ fsleep(15 * USEC_PER_MSEC);
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata()
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
` (4 preceding siblings ...)
2026-11-23 22:06 ` [PATCH 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
2026-11-23 22:06 ` [PATCH 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
Nothing reads the client data back.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index eb5715f75e9e..7581ea4c99ba 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -1633,13 +1633,7 @@ static int dps310_probe(struct i2c_client *client)
return rc;
}
- rc = devm_iio_device_register(dev, iio);
- if (rc)
- return rc;
-
- i2c_set_clientdata(client, iio);
-
- return 0;
+ return devm_iio_device_register(dev, iio);
}
static const struct i2c_device_id dps310_id[] = {
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 7/7] iio: pressure: dps310: include what the driver uses
2026-11-23 22:06 [PATCH 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
` (5 preceding siblings ...)
2026-11-23 22:06 ` [PATCH 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata() Rupesh Majhi
@ 2026-11-23 22:06 ` Rupesh Majhi
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-11-23 22:06 UTC (permalink / raw)
To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
Nuno Sá
Cc: linux-iio, linux-kernel, Rupesh Majhi
Include the headers for what the driver uses directly and drop
linux/iio/sysfs.h, which it does not use.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 7581ea4c99ba..fd17fa38e9fc 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -18,28 +18,40 @@
* c0 * 0.5 + c1 * T_raw / kT °C
*/
+#include <linux/array_size.h>
#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/bits.h>
#include <linux/cleanup.h>
+#include <linux/container_of.h>
#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/device/devres.h>
#include <linux/devm-helpers.h>
+#include <linux/err.h>
+#include <linux/errno.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/jiffies.h>
#include <linux/limits.h>
+#include <linux/log2.h>
#include <linux/math64.h>
+#include <linux/minmax.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/overflow.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/time.h>
+#include <linux/types.h>
#include <linux/unaligned.h>
#include <linux/units.h>
#include <linux/workqueue.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread