iio: pressure: dps310: fix input checks and resets
Subsystems (2)
cover iio: pressure: dps310: fix input checks and resets
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
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
Signature · 1 line
2.43.0
PATCH 1/3 iio: pressure: dps310: reject a zero rate or oversampling ratio
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.
---
Cc: Paulius Zaleckas <[email protected]>
drivers/iio/pressure/dps310.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/pressure/dps310.c +4 -4
@@ -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 ;
Signature · 1 line
2.43.0
Re: [PATCH 1/3] iio: pressure: dps310: reject a zero rate or oversampling ratio
Quoted 5 lines · On Fri, 30 Oct 2026 00:06:33 +0200 Rupesh Majhi <[email protected]> wrote:
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
-ERANGEand temperature read 974 degrees C.
Quoted 8 lines
Reject values below 1.
Fixes ba6ec48e76bc ("iio: Add driver for Infineon DPS310")Fixes d711a3c7dc82 ("iio: dps310: Add pressure sensing capability")Reported-by Sashiko <[email protected]>Signed-off-by Rupesh Majhi <[email protected]>---
Signature · 2 lines
Kind regards, Joshua Crofts
PATCH 2/3 iio: pressure: dps310: reset the chip at probe
In reply to Rupesh MajhiThe 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.
---
Cc: Paulius Zaleckas <[email protected]>
drivers/iio/pressure/dps310.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/pressure/dps310.c +5 -0
@@ -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;
Signature · 1 line
2.43.0
Re: [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
Quoted 24 lines · On Fri, 30 Oct 2026 00:06:34 +0200 Rupesh Majhi <[email protected]> wrote:
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 leavesFIFO_ENset, so the ready bits never come and every raw read times out. The timeout reset does not clear it either, since theCFG_REGupdate that follows writesFIFO_ENback 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 <[email protected]>Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Paulius Zaleckas <[email protected]>drivers/iio/pressure/dps310.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iio/pressure/dps310.c +0
-0@@ -1445,6 +1445,11 @@ static int dps310_probe(struct i2c_client *client)if (rc)
drivers/iio/pressure/dps310.c static int dps310_probe(struct i2c_client *client) · line 1455
Quoted 10 lines
drivers/iio/pressure/dps310.c +5
-0return 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;
Signature · 2 lines
Kind regards, Joshua Crofts
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
In reply to Rupesh MajhiQuoted 9 lines · On Fri, 30 Oct 2026 00:06:34 +0200 Rupesh Majhi <[email protected]> wrote:
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 leavesFIFO_ENset, so the ready bits never come and every raw read times out. The timeout reset does not clear it either, since theCFG_REGupdate that follows writesFIFO_ENback from the register cache.Reset the chip first, as remove already does.
Fixes 90f0d1016398 ("iio: pressure: dps310: read buffered samples from the hardware FIFO")
That's not a stable hash because it is recent enough that it is on the tree I've rebased since then and will do again on rc1. Given this will go in at same time as the fifo anyway during next merge cycle, I tend to just drop the fixes tags in cases like this to avoid having to fix them up.
Other than that, series looks fine to me, but given you asked Paulius for a test I'll wait on that!
Thanks
Jonathan
Quoted 25 lines
Reported-by Sashiko <[email protected]>Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Paulius Zaleckas <[email protected]>drivers/iio/pressure/dps310.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iio/pressure/dps310.c +5
-0@@ -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;
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
In reply to Rupesh MajhiQuoted 7 lines · On Fri, 30 Oct 2026 00:06:34 +0200 Rupesh Majhi <[email protected]> wrote:
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 leavesFIFO_ENset, so the ready bits never come and every raw read times out. The timeout reset does not clear it either, since theCFG_REGupdate that follows writesFIFO_ENback from the register cache.Reset the chip first, as remove already does.
Why do we do it in remove? Does it put it in a power saving mode or similar? It's fairly unusual to bother resetting in that path given as you've seen here, we pretty much have to reset in probe.
Jonathan
Quoted 27 lines
Fixes 90f0d1016398 ("iio: pressure: dps310: read buffered samples from the hardware FIFO")Reported-by Sashiko <[email protected]>Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Paulius Zaleckas <[email protected]>drivers/iio/pressure/dps310.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/iio/pressure/dps310.c +5
-0@@ -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;
Re: [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
Quoted 4 lines · On Sun, 01 Nov 2026 01:04:44 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 1 line
Reset the chip first, as remove already does.
Why do we do it in remove? Does it put it in a power saving mode or similar? It's fairly unusual to bother resetting in that path given as you've seen here, we pretty much have to reset in probe.
Yes, in effect. Driver leaves the chip measuring in background mode, and soft reset returns it to standby (datasheet 4.1). It came with the original driver without a stated reason.
Writing 0 to MEAS_CTRL would also stop it, if you'd rather not reset there.
Rupesh
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: pressure: dps310: reset the chip at probe
Quoted 8 lines · On Sun, 1 Nov 2026 12:58:55 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 4 lines · On Sun, 01 Nov 2026 01:04:44 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 1 line
Reset the chip first, as remove already does.
Why do we do it in remove? Does it put it in a power saving mode or similar? It's fairly unusual to bother resetting in that path given as you've seen here, we pretty much have to reset in probe.
Quoted 6 lines
Yes, in effect. Driver leaves the chip measuring in background mode, and soft reset returns it to standby (datasheet 4.1). It came with the original driver without a stated reason.
Writing 0 to
MEAS_CTRLwould also stop it, if you'd rather not reset there.
I would prefer that as it would avoid the need for documentation to say that the reset is there to put it into a low power mode. If there hadn't been any other way to do it (unlike writing that 0) then I'd have asked for a comment.
Thanks,
Jonathan
Quoted 2 lines
Rupesh
PATCH 3/3 iio: pressure: dps310: keep the user's settings across a timeout reset
In reply to Rupesh MajhiWhen 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.
---
Cc: Paulius Zaleckas <[email protected]>
drivers/iio/pressure/dps310.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/iio/pressure/dps310.c +19 -6
@@ -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;
Signature · 1 line
2.43.0
Re: [PATCH 3/3] iio: pressure: dps310: keep the user's settings across a timeout reset
On Fri, 30 Oct 2026 00:06:35 +0200
Rupesh Majhi <[email protected]> wrote:
...
Quoted 6 lines
drivers/iio/pressure/dps310.c +0
-2@@ -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 );
drivers/iio/pressure/dps310.c static int dps310_startup(struct dps310_data *data) · line 337
Quoted 10 lines
drivers/iio/pressure/dps310.c +8
-2-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;
A very small nit, but reverse xmas tree.
Signature · 2 lines
Kind regards, Joshua Crofts
Hi Paulius,
Jonathan is holding this series for your Tested-by. Could you give it a run on the ZTS8032 when you have time?
Rupesh
Paulius Zaleckas
Tested-byQuoted 2 lines · Rupesh Majhi
Jonathan is holding this series for your Tested-by. Could you give it a run on the ZTS8032 when you have time?
Tested on a ZTS8032, on iio testing backported to 6.12:
- 0 and 0.5 are rejected for both rates and ratios.
- 64x at 4 Hz survives a timeout reset forced by putting the chip in standby behind the driver's back.
- A warm reboot during a FIFO capture: FIFO_EN is clear after probe and reads work.
Paulius
Jonathan Cameron
maintainerQuoted 6 lines · On Wed, 4 Nov 2026 11:13:50 +0200 Paulius Zaleckas…
Quoted 2 lines · Rupesh Majhi
Jonathan is holding this series for your Tested-by. Could you give it a run on the ZTS8032 when you have time?
Tested on a ZTS8032, on iio testing backported to 6.12:
Quoted 7 lines
- 0 and 0.5 are rejected for both rates and ratios.
- 64x at 4 Hz survives a timeout reset forced by putting the chip in standby behind the driver's back.
- A warm reboot during a FIFO capture:FIFO_ENis clear after probe and reads work.Tested-by Paulius Zaleckas <[email protected]>
I'm going to take this the slow way mostly so other work can easily be applied on top.
Applied to the testing branch of iio.git which I'll push out as togreg for linux-next to pick up on sometime in next few days.
Thanks to both Rupesh for the patch and Paulius for the testing!
Jonathan
Quoted 2 lines
Paulius