Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 0/7] iio: pressure: dps310: cleanups
@ 2026-11-26 12:13 Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá
  Cc: linux-iio, linux-kernel, Rupesh Majhi, u.kleine-koenig, crofts

The cleanups promised in the FIFO series cover letter [1], plus the
rest of Andy's list from his review of the ACPI fix.

Patches 1, 3, 4 and 7 build to the same object code. Patch 2 gives the
same coefficients as the old parsing, checked on random input. Patch 5
changes the wait after a reset from 15 to 55 ms to 20 ms. Tested on a
DPS310 on a BeagleBone Black.

Based on iio testing.

v2:
- 1: sort high to low, fewer lines move and it is the datasheet order
  (Andy)
- 2: "No functional change intended." (Andy)
- 5: wrap the poll call on logical boundaries, msleep(20) after a
  reset (Andy)
- 7: drop bits.h and errno.h (Andy), drop mod_devicetable.h (Uwe,
  Joshua)
- Reviewed-by from Andy on 2, 4 and 6

v1: https://lore.kernel.org/linux-iio/20261123220649.36887-1-zoone.rupert@gmail.com/
[1] https://lore.kernel.org/linux-iio/20260921183132.233136-1-zoone.rupert@gmail.com/

Cc: u.kleine-koenig@baylibre.com
Cc: crofts@kernel.org

Rupesh Majhi (7):
  iio: pressure: dps310: sort register field defines high to low
  iio: pressure: dps310: read the coefficients with get_unaligned_be*()
  iio: pressure: dps310: use min() instead of min_t()
  iio: pressure: dps310: use KILO for the Pa to kPa conversion
  iio: pressure: dps310: use time unit macros for sleeps and timeouts
  iio: pressure: dps310: drop the unused i2c_set_clientdata()
  iio: pressure: dps310: include what the driver uses

 drivers/iio/pressure/dps310.c | 86 +++++++++++++++--------------------
 1 file changed, 37 insertions(+), 49 deletions(-)


base-commit: f2cbef9101b9fc979a324bb1242b8b802a2484b6
-- 
2.43.0


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

* [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 13:20   ` Joshua Crofts
  2026-11-26 13:44   ` Andy Shevchenko
  2026-11-26 12:13 ` [PATCH v2 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*() Rupesh Majhi
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 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 high to low, as the datasheet lists them.

Suggested-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
v2:
- sort high to low instead of low to high, fewer lines move and it is
  the datasheet order (Andy)

 drivers/iio/pressure/dps310.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 9ffef150cc4c..ce83bd3691af 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -54,20 +54,20 @@
 #define  DPS310_PRS_RATE_BITS	GENMASK(6, 4)
 #define  DPS310_PRS_PRC_BITS	GENMASK(3, 0)
 #define DPS310_TMP_CFG		0x07
+#define  DPS310_TMP_EXT		BIT(7)
 #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_EXT		BIT(7)
 #define DPS310_MEAS_CFG		0x08
+#define  DPS310_COEF_RDY	BIT(7)
+#define  DPS310_SENSOR_RDY	BIT(6)
+#define  DPS310_TMP_RDY		BIT(5)
+#define  DPS310_PRS_RDY		BIT(4)
 #define  DPS310_MEAS_CTRL_BITS	GENMASK(2, 0)
-#define   DPS310_PRS_EN		BIT(0)
-#define   DPS310_TEMP_EN	BIT(1)
 #define   DPS310_BACKGROUND	BIT(2)
-#define  DPS310_PRS_RDY		BIT(4)
-#define  DPS310_TMP_RDY		BIT(5)
-#define  DPS310_SENSOR_RDY	BIT(6)
-#define  DPS310_COEF_RDY	BIT(7)
+#define   DPS310_TEMP_EN	BIT(1)
+#define   DPS310_PRS_EN		BIT(0)
 #define DPS310_CFG_REG		0x09
 #define  DPS310_INT_HL		BIT(7)
 #define  DPS310_INT_TMP		BIT(5)
-- 
2.43.0


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

* [PATCH v2 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*()
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá
  Cc: linux-iio, linux-kernel, Rupesh Majhi, Andy Shevchenko

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.

No functional change intended.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
v2:
- "No functional change intended." (Andy)

 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 ce83bd3691af..abf1652980ea 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 related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t()
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*() Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 13:18   ` Joshua Crofts
  2026-11-26 13:44   ` Andy Shevchenko
  2026-11-26 12:13 ` [PATCH v2 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion Rupesh Majhi
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 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 abf1652980ea..493eb56bde98 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 related	[flat|nested] 18+ messages in thread

* [PATCH v2 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
                   ` (2 preceding siblings ...)
  2026-11-26 12:13 ` [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá
  Cc: linux-iio, linux-kernel, Rupesh Majhi, Andy Shevchenko

Spell the Pa to kPa divisor as KILO from units.h, in both places.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
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 493eb56bde98..f802c2c59072 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 related	[flat|nested] 18+ messages in thread

* [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
                   ` (3 preceding siblings ...)
  2026-11-26 12:13 ` [PATCH v2 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 13:17   ` Joshua Crofts
  2026-11-26 13:49   ` Andy Shevchenko
  2026-11-26 12:13 ` [PATCH v2 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata() Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
  6 siblings, 2 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 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.

After a reset wait 20 ms with msleep() instead of 15 to 55 ms. The
specification says 15 ms, so this keeps some margin.

Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
v2:
- wrap the poll call on logical boundaries (Andy)
- msleep(20) after a reset (Andy)

 drivers/iio/pressure/dps310.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index f802c2c59072..1d46817ad04a 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))
 
@@ -369,8 +370,9 @@ static int dps310_startup(struct dps310_data *data)
 	 * Calibration coefficients required for reporting temperature.
 	 * 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);
+	rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG,
+				      ready, 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);
+	msleep(20);
 	return 0;
 }
 
-- 
2.43.0


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

* [PATCH v2 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata()
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
                   ` (4 preceding siblings ...)
  2026-11-26 12:13 ` [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 12:13 ` [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
  6 siblings, 0 replies; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá
  Cc: linux-iio, linux-kernel, Rupesh Majhi, Andy Shevchenko

Nothing reads the client data back.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
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 1d46817ad04a..72f62a1aa3ea 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 related	[flat|nested] 18+ messages in thread

* [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses
  2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
                   ` (5 preceding siblings ...)
  2026-11-26 12:13 ` [PATCH v2 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata() Rupesh Majhi
@ 2026-11-26 12:13 ` Rupesh Majhi
  2026-11-26 13:12   ` Joshua Crofts
  6 siblings, 1 reply; 18+ messages in thread
From: Rupesh Majhi @ 2026-11-26 12:13 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá
  Cc: linux-iio, linux-kernel, Rupesh Majhi, u.kleine-koenig, crofts

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>
---
v2:
- drop bits.h and errno.h, bitops.h and err.h bring them (Andy)
- drop mod_devicetable.h, i2c.h brings the ID table types (Uwe, Joshua)

Cc: u.kleine-koenig@baylibre.com
Cc: crofts@kernel.org

 drivers/iio/pressure/dps310.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 72f62a1aa3ea..74d4111b5e29 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -18,28 +18,37 @@
  *   c0 * 0.5 + c1 * T_raw / kT °C
  */
 
+#include <linux/array_size.h>
 #include <linux/bitfield.h>
+#include <linux/bitops.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/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/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 related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses
  2026-11-26 12:13 ` [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
@ 2026-11-26 13:12   ` Joshua Crofts
  0 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:12 UTC (permalink / raw)
  To: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá
  Cc: linux-iio, linux-kernel, u.kleine-koenig

On 26-Nov-26 13:13, Rupesh Majhi wrote:
> 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>
> ---
Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts

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

* Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 12:13 ` [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
@ 2026-11-26 13:17   ` Joshua Crofts
  2026-11-26 13:49     ` Andy Shevchenko
  2026-11-26 13:49   ` Andy Shevchenko
  1 sibling, 1 reply; 18+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:17 UTC (permalink / raw)
  To: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá
  Cc: linux-iio, linux-kernel

On 26-Nov-26 13:13, Rupesh Majhi wrote:
> Write the microsecond values as multiples of USEC_PER_MSEC, like the
> poll timeout next to them already uses USEC_PER_SEC.
> 
> After a reset wait 20 ms with msleep() instead of 15 to 55 ms. The
> specification says 15 ms, so this keeps some margin.
> 
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
> ---
> v2:
> - wrap the poll call on logical boundaries (Andy)
> - msleep(20) after a reset (Andy)
> 
>  drivers/iio/pressure/dps310.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index f802c2c59072..1d46817ad04a 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))
>  
> @@ -369,8 +370,9 @@ static int dps310_startup(struct dps310_data *data)
>  	 * Calibration coefficients required for reporting temperature.
>  	 * 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);
> +	rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG,
> +				      ready, 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);
> +	msleep(20);
I think it's safe to use 15 as specified in the datasheet, as msleep()
guarantees sleep for the specified time + a max of 12.5% slack.

This can be tweaked whilst applying though (or not, at it's pretty minuscule).

Either way,

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts


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

* Re: [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t()
  2026-11-26 12:13 ` [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
@ 2026-11-26 13:18   ` Joshua Crofts
  2026-11-26 13:44   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:18 UTC (permalink / raw)
  To: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá
  Cc: linux-iio, linux-kernel

On 26-Nov-26 13:13, Rupesh Majhi wrote:
> 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>
> ---
Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts


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

* Re: [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low
  2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
@ 2026-11-26 13:20   ` Joshua Crofts
  2026-11-26 13:44   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-11-26 13:20 UTC (permalink / raw)
  To: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá
  Cc: linux-iio, linux-kernel

On 26-Nov-26 13:13, Rupesh Majhi wrote:
> Some field defines run from the high bit down, others from the low bit
> up. Sort them all high to low, as the datasheet lists them.
> 
> Suggested-by: David Lechner <dlechner@baylibre.com>
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
> ---

Reviewed-by: Joshua Crofts <crofts@kernel.org>

-- 
Kind regards,
Joshua Crofts


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

* Re: [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t()
  2026-11-26 12:13 ` [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
  2026-11-26 13:18   ` Joshua Crofts
@ 2026-11-26 13:44   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-26 13:44 UTC (permalink / raw)
  To: Rupesh Majhi
  Cc: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá, linux-iio, linux-kernel

On Thu, Nov 26, 2026 at 02:13:26PM +0200, Rupesh Majhi wrote:
> min() accepts s64 and int, both signed, so min_t() and the cast are
> not needed.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low
  2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
  2026-11-26 13:20   ` Joshua Crofts
@ 2026-11-26 13:44   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-26 13:44 UTC (permalink / raw)
  To: Rupesh Majhi
  Cc: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá, linux-iio, linux-kernel

On Thu, Nov 26, 2026 at 02:13:24PM +0200, Rupesh Majhi wrote:
> Some field defines run from the high bit down, others from the low bit
> up. Sort them all high to low, as the datasheet lists them.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 13:17   ` Joshua Crofts
@ 2026-11-26 13:49     ` Andy Shevchenko
  2026-11-26 14:19       ` Joshua Crofts
  0 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-26 13:49 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá, linux-iio, linux-kernel

On Thu, Nov 26, 2026 at 02:17:34PM +0100, Joshua Crofts wrote:
> On 26-Nov-26 13:13, Rupesh Majhi wrote:

...

> > -	usleep_range(15000, 55000);
> > +	msleep(20);
> I think it's safe to use 15 as specified in the datasheet, as msleep()
> guarantees sleep for the specified time + a max of 12.5% slack.

Wouldn't be better to have some margin still? You know that time goes
differently on different CPUs and in general time can go backwards (in
computers), so the long sleeps can (I haven't checked though) go both ways,
and a minimum sleeping time can be less. Also on the other side firmware
might have issues in some circumstances and require slightly bigger sleep
than specified. That's why I proposed margin.

> This can be tweaked whilst applying though (or not, at it's pretty minuscule).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 12:13 ` [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
  2026-11-26 13:17   ` Joshua Crofts
@ 2026-11-26 13:49   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-26 13:49 UTC (permalink / raw)
  To: Rupesh Majhi
  Cc: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá, linux-iio, linux-kernel

On Thu, Nov 26, 2026 at 02:13:28PM +0200, Rupesh Majhi wrote:
> Write the microsecond values as multiples of USEC_PER_MSEC, like the
> poll timeout next to them already uses USEC_PER_SEC.
> 
> After a reset wait 20 ms with msleep() instead of 15 to 55 ms. The
> specification says 15 ms, so this keeps some margin.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 13:49     ` Andy Shevchenko
@ 2026-11-26 14:19       ` Joshua Crofts
  2026-11-26 14:37         ` Andy Shevchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Joshua Crofts @ 2026-11-26 14:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá, linux-iio, linux-kernel

On 26-Nov-26 14:49, Andy Shevchenko wrote:
> On Thu, Nov 26, 2026 at 02:17:34PM +0100, Joshua Crofts wrote:
>> On 26-Nov-26 13:13, Rupesh Majhi wrote:
> 
> ...
> 
>> > -	usleep_range(15000, 55000);
>> > +	msleep(20);
>> I think it's safe to use 15 as specified in the datasheet, as msleep()
>> guarantees sleep for the specified time + a max of 12.5% slack.
> 
> Wouldn't be better to have some margin still? You know that time goes
> differently on different CPUs and in general time can go backwards (in
> computers), so the long sleeps can (I haven't checked though) go both ways,
> and a minimum sleeping time can be less. Also on the other side firmware
> might have issues in some circumstances and require slightly bigger sleep
> than specified. That's why I proposed margin.
Sure, it's just that some patches add a margin and some patches ignore this
and just add the default datasheet value. A lot of times slack is an adequate
enough margin. I was always for just the default value.

-- 
Kind regards,
Joshua Crofts

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

* Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
  2026-11-26 14:19       ` Joshua Crofts
@ 2026-11-26 14:37         ` Andy Shevchenko
  0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-26 14:37 UTC (permalink / raw)
  To: Joshua Crofts
  Cc: Rupesh Majhi, Andy Shevchenko, David Lechner, Eddie James,
	Jonathan Cameron, Nuno Sá, linux-iio, linux-kernel

On Thu, Nov 26, 2026 at 03:19:06PM +0100, Joshua Crofts wrote:
> On 26-Nov-26 14:49, Andy Shevchenko wrote:
> > On Thu, Nov 26, 2026 at 02:17:34PM +0100, Joshua Crofts wrote:
> >> On 26-Nov-26 13:13, Rupesh Majhi wrote:

...

> >> > -	usleep_range(15000, 55000);
> >> > +	msleep(20);
> >> I think it's safe to use 15 as specified in the datasheet, as msleep()
> >> guarantees sleep for the specified time + a max of 12.5% slack.
> > 
> > Wouldn't be better to have some margin still? You know that time goes
> > differently on different CPUs and in general time can go backwards (in
> > computers), so the long sleeps can (I haven't checked though) go both ways,
> > and a minimum sleeping time can be less. Also on the other side firmware
> > might have issues in some circumstances and require slightly bigger sleep
> > than specified. That's why I proposed margin.
> Sure, it's just that some patches add a margin and some patches ignore this
> and just add the default datasheet value. A lot of times slack is an adequate
> enough margin. I was always for just the default value.

Yeah, probably for 10+ ms delays this is fine.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-11-26 14:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:13 [PATCH v2 0/7] iio: pressure: dps310: cleanups Rupesh Majhi
2026-11-26 12:13 ` [PATCH v2 1/7] iio: pressure: dps310: sort register field defines high to low Rupesh Majhi
2026-11-26 13:20   ` Joshua Crofts
2026-11-26 13:44   ` Andy Shevchenko
2026-11-26 12:13 ` [PATCH v2 2/7] iio: pressure: dps310: read the coefficients with get_unaligned_be*() Rupesh Majhi
2026-11-26 12:13 ` [PATCH v2 3/7] iio: pressure: dps310: use min() instead of min_t() Rupesh Majhi
2026-11-26 13:18   ` Joshua Crofts
2026-11-26 13:44   ` Andy Shevchenko
2026-11-26 12:13 ` [PATCH v2 4/7] iio: pressure: dps310: use KILO for the Pa to kPa conversion Rupesh Majhi
2026-11-26 12:13 ` [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts Rupesh Majhi
2026-11-26 13:17   ` Joshua Crofts
2026-11-26 13:49     ` Andy Shevchenko
2026-11-26 14:19       ` Joshua Crofts
2026-11-26 14:37         ` Andy Shevchenko
2026-11-26 13:49   ` Andy Shevchenko
2026-11-26 12:13 ` [PATCH v2 6/7] iio: pressure: dps310: drop the unused i2c_set_clientdata() Rupesh Majhi
2026-11-26 12:13 ` [PATCH v2 7/7] iio: pressure: dps310: include what the driver uses Rupesh Majhi
2026-11-26 13:12   ` Joshua Crofts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox