mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: pressure: dps310: fix input checks and resets
@ 2026-10-29 22:06 Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio Rupesh Majhi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rupesh Majhi @ 2026-10-29 22:06 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Joel Stanley,
	Jonathan Cameron, Nuno Sá,
	Rupesh Majhi
  Cc: linux-iio, linux-kernel, Paulius Zaleckas

Sashiko flagged these as pre-existing in its review of the FIFO series
v8 [1]. All three reproduce on a DPS310 on a BeagleBone Black:

- 0 or 0.5 written to a rate or ratio is accepted. Ratio 0 puts a
  reserved value in the register: pressure reads fail with -ERANGE,
  temperature reads 974 C.
- A warm reboot during a FIFO capture leaves FIFO_EN set. After it,
  every raw read times out until the driver is unbound.
- The reset after a read timeout silently puts the rate and ratio back
  to their defaults.

Patch 2 fixes a commit that is only in iio testing so far.

Paulius, patch 2 also resets the ZTS8032 at probe, the same reset that
remove already does. A Tested-by would be welcome if you have time.

Based on iio testing. Reproduced and fixed with help from an LLM coding
assistant.

[1] https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com

Cc: Paulius Zaleckas <paulius.zaleckas@gmail.com>

Rupesh Majhi (3):
  iio: pressure: dps310: reject a zero rate or oversampling ratio
  iio: pressure: dps310: reset the chip at probe
  iio: pressure: dps310: keep the user's settings across a timeout reset

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


base-commit: 7d80b4b383bc53b48abd3a30ca4a91cdab568bfa
-- 
2.43.0


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

* [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio
  2026-10-29 22:06 [PATCH 0/3] iio: pressure: dps310: fix input checks and resets Rupesh Majhi
@ 2026-10-29 22:06 ` Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 2/3] iio: pressure: dps310: reset the chip at probe Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 3/3] iio: pressure: dps310: keep the user's settings across a timeout reset Rupesh Majhi
  2 siblings, 0 replies; 4+ messages in thread
From: Rupesh Majhi @ 2026-10-29 22:06 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Joel Stanley,
	Jonathan Cameron, Nuno Sá,
	Rupesh Majhi
  Cc: linux-iio, linux-kernel, Sashiko, Paulius Zaleckas

The rate and ratio setters accept 0, which also covers 0.5. ilog2(0)
gives -1, which masked into the register is 128 Hz or the reserved
precision 0b1111. The latter makes every pressure read fail with
-ERANGE and temperature read 974 degrees C.

Reject values below 1.

Fixes: ba6ec48e76bc ("iio: Add driver for Infineon DPS310")
Fixes: d711a3c7dc82 ("iio: dps310: Add pressure sensing capability")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
Cc: Paulius Zaleckas <paulius.zaleckas@gmail.com>

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

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 71053f4463e5..b6aa5dbe2bcd 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -410,7 +410,7 @@ static int dps310_set_pres_precision(struct dps310_data *data, int val)
 	int rc;
 	u8 shift_en;
 
-	if (val < 0 || val > 128)
+	if (val < 1 || val > 128)
 		return -EINVAL;
 
 	shift_en = val >= 16 ? DPS310_PRS_SHIFT_EN : 0;
@@ -433,7 +433,7 @@ static int dps310_set_temp_precision(struct dps310_data *data, int val)
 	int rc;
 	u8 shift_en;
 
-	if (val < 0 || val > 128)
+	if (val < 1 || val > 128)
 		return -EINVAL;
 
 	shift_en = val >= 16 ? DPS310_TMP_SHIFT_EN : 0;
@@ -455,7 +455,7 @@ static int dps310_set_pres_samp_freq(struct dps310_data *data, int freq)
 {
 	u8 val;
 
-	if (freq < 0 || freq > 128)
+	if (freq < 1 || freq > 128)
 		return -EINVAL;
 
 	val = ilog2(freq) << 4;
@@ -469,7 +469,7 @@ static int dps310_set_temp_samp_freq(struct dps310_data *data, int freq)
 {
 	u8 val;
 
-	if (freq < 0 || freq > 128)
+	if (freq < 1 || freq > 128)
 		return -EINVAL;
 
 	val = ilog2(freq) << 4;
-- 
2.43.0


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

* [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
  2026-10-29 22:06 [PATCH 0/3] iio: pressure: dps310: fix input checks and resets Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio Rupesh Majhi
@ 2026-10-29 22:06 ` Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 3/3] iio: pressure: dps310: keep the user's settings across a timeout reset Rupesh Majhi
  2 siblings, 0 replies; 4+ messages in thread
From: Rupesh Majhi @ 2026-10-29 22:06 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Joel Stanley,
	Jonathan Cameron, Nuno Sá,
	Rupesh Majhi
  Cc: linux-iio, linux-kernel, Sashiko, Paulius Zaleckas

The chip keeps its registers across a warm reboot, and probe changes
only the shift bits in CFG_REG. A reboot during a FIFO capture leaves
FIFO_EN set, so the ready bits never come and every raw read times
out. The timeout reset does not clear it either, since the CFG_REG
update that follows writes FIFO_EN back from the register cache.

Reset the chip first, as remove already does.

Fixes: 90f0d1016398 ("iio: pressure: dps310: read buffered samples from the hardware FIFO")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
Cc: Paulius Zaleckas <paulius.zaleckas@gmail.com>

 drivers/iio/pressure/dps310.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index b6aa5dbe2bcd..29778f25bb33 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -1445,6 +1445,11 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	/* The chip keeps its state across a warm reboot */
+	rc = dps310_reset_wait(data);
+	if (rc)
+		return rc;
+
 	rc = dps310_startup(data);
 	if (rc)
 		return rc;
-- 
2.43.0


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

* [PATCH 3/3] iio: pressure: dps310: keep the user's settings across a timeout reset
  2026-10-29 22:06 [PATCH 0/3] iio: pressure: dps310: fix input checks and resets Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio Rupesh Majhi
  2026-10-29 22:06 ` [PATCH 2/3] iio: pressure: dps310: reset the chip at probe Rupesh Majhi
@ 2026-10-29 22:06 ` Rupesh Majhi
  2 siblings, 0 replies; 4+ messages in thread
From: Rupesh Majhi @ 2026-10-29 22:06 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Joel Stanley,
	Jonathan Cameron, Nuno Sá,
	Rupesh Majhi
  Cc: linux-iio, linux-kernel, Sashiko, Paulius Zaleckas

When a sample never becomes ready, the driver resets the chip and runs
startup again, which writes the default rate and ratio. With 64x at
4 Hz set and the chip put in standby, the next read recovers, but both
channels are silently back to 1x at 1 Hz.

The register cache still holds the user's values. Write them back
after the reset, before measuring starts again, and move the defaults
out of dps310_startup() so only probe writes them.

A rate and ratio the chip cannot keep up with, such as 128x at 128 Hz,
now keep timing out instead of falling back to 1x at 1 Hz.

Fixes: 7b4ab4abcea4 ("iio: pressure: dps310: Reset chip after timeout")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
Cc: Paulius Zaleckas <paulius.zaleckas@gmail.com>

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

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 29778f25bb33..c364fbaeb3fe 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -306,10 +306,9 @@ static int dps310_temp_workaround(struct dps310_data *data)
 	return regmap_write(data->regmap, 0x0f, 0x00);
 }
 
-static int dps310_startup(struct dps310_data *data)
+static int dps310_set_defaults(struct dps310_data *data)
 {
 	int rc;
-	int ready;
 
 	/*
 	 * Set up pressure sensor in single sample, one measurement per second
@@ -328,10 +327,14 @@ static int dps310_startup(struct dps310_data *data)
 		return rc;
 
 	/* Temp and pressure shifts are disabled when PRC <= 8 */
-	rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
-			       DPS310_PRS_SHIFT_EN | DPS310_TMP_SHIFT_EN, 0);
-	if (rc)
-		return rc;
+	return regmap_write_bits(data->regmap, DPS310_CFG_REG,
+				 DPS310_PRS_SHIFT_EN | DPS310_TMP_SHIFT_EN, 0);
+}
+
+static int dps310_startup(struct dps310_data *data)
+{
+	int rc;
+	int ready;
 
 	/* MEAS_CFG doesn't update correctly unless first written with 0 */
 	rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG,
@@ -551,6 +554,12 @@ static int dps310_reset_reinit(struct dps310_data *data)
 	if (rc)
 		return rc;
 
+	/* Put back the configuration the reset cleared */
+	regcache_mark_dirty(data->regmap);
+	rc = regcache_sync_region(data->regmap, DPS310_PRS_CFG, DPS310_CFG_REG);
+	if (rc)
+		return rc;
+
 	return dps310_startup(data);
 }
 
@@ -1450,6 +1459,10 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	rc = dps310_set_defaults(data);
+	if (rc)
+		return rc;
+
 	rc = dps310_startup(data);
 	if (rc)
 		return rc;
-- 
2.43.0


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

end of thread, other threads:[~2026-10-29 22:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 22:06 [PATCH 0/3] iio: pressure: dps310: fix input checks and resets Rupesh Majhi
2026-10-29 22:06 ` [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio Rupesh Majhi
2026-10-29 22:06 ` [PATCH 2/3] iio: pressure: dps310: reset the chip at probe Rupesh Majhi
2026-10-29 22:06 ` [PATCH 3/3] iio: pressure: dps310: keep the user's settings across a timeout reset Rupesh Majhi

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

all inboxes | Powered by JetHome®