Skip to contentSkip to conversation

iio: pressure: dps310: don't wait for new temperature in trigger handler

PATCH In review Rupesh Majhi 2 participants 10 messages Nov 13 – Nov 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio: pressure: dps310: don't wait for new temperature in trigger handler

Each scan waits for a new temperature result before reading pressure. With pressure sampled faster than temperature, scans then come at the temperature rate: an 8 Hz trigger with temperature at its default 1 Hz gives one scan a second.

Read pressure first and take the latest temperature, as a direct pressure read already does. Wait for temperature only when pressure is not in the scan. Read a temperature in probe, so there is a latest one from the first scan on.

Fixes 9b7cad9ce2ed ("iio: pressure: dps310: add triggered buffer support")

---
v2: read a temperature in probe, so the first scans have one (Arnav Kapoor)
v1: https://lore.kernel.org/linux-iio/[email protected]/

Cc Arnav Kapoor <[email protected]>
Cc Jonathan Cameron <[email protected]>
 drivers/iio/pressure/dps310.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/iio/pressure/dps310.c +18 -8
index 85df58ac1809..3d05540f95dd 100644
@@ -910,10 +910,18 @@ static int dps310_fill_channels(struct dps310_data *data,
 	unsigned int i;
 	int rc;
 
-	/* Compensation needs a temperature, so it is sampled either way */
-	rc = dps310_read_temp_raw_locked(data);
-	if (rc)
-		return rc;
+	if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) {
+		rc = dps310_read_pres_raw_locked(data);
+		if (rc)
+			return rc;
+
+		/* Waiting here would hold scans to the temperature rate */
+		dps310_refresh_temp_locked(data);
+	} else {
+		rc = dps310_read_temp_raw_locked(data);
+		if (rc)
+			return rc;
+	}
 
 	i = 0;
 	if (test_bit(DPS310_SCAN_TEMP, scan_mask)) {
@@ -924,10 +932,6 @@ static int dps310_fill_channels(struct dps310_data *data,
 	}
 
 	if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) {
-		rc = dps310_read_pres_raw_locked(data);
-		if (rc)
-			return rc;
-
 		/* Pascals, see the channel definition */
 		rc = dps310_calculate_pressure(data, &channels[i++]);
 		if (rc)
@@ -1017,6 +1021,12 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	/* Pressure compensation needs a temperature from the start */
+	scoped_guard(mutex, &data->lock)
+		rc = dps310_read_temp_raw_locked(data);
+	if (rc)
+		return rc;
+
 	/*
 	 * The device measures continuously in background mode, so a capture is
 	 * just a read of the latest results. The trigger is not aligned with

base-commit: 9752760146e642f3e4a2ec860f8767fa72030d2c

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · On Sat, 14 Nov 2026 01:02:41 +0200 Rupesh Majhi <[email protected]> wrote:

Each scan waits for a new temperature result before reading pressure. With pressure sampled faster than temperature, scans then come at the temperature rate: an 8 Hz trigger with temperature at its default 1 Hz gives one scan a second.

Read pressure first and take the latest temperature, as a direct pressure read already does. Wait for temperature only when pressure is not in the scan. Read a temperature in probe, so there is a latest one from the first scan on.

That was potentially a while back. Why not do it in preenable for the buffer? Will make the buffer start a bit slow but should 'work' from there on.

Quoted 68 lines
Fixes 9b7cad9ce2ed ("iio: pressure: dps310: add triggered buffer support")

---
v2: read a temperature in probe, so the first scans have one (Arnav Kapoor)
v1: https://lore.kernel.org/linux-iio/[email protected]/

Cc Arnav Kapoor <[email protected]>
Cc Jonathan Cameron <[email protected]>
 drivers/iio/pressure/dps310.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/iio/pressure/dps310.c +18 -8
index 85df58ac1809..3d05540f95dd 100644
@@ -910,10 +910,18 @@ static int dps310_fill_channels(struct dps310_data *data,
 	unsigned int i;
 	int rc;
 
-	/* Compensation needs a temperature, so it is sampled either way */
-	rc = dps310_read_temp_raw_locked(data);
-	if (rc)
-		return rc;
+	if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) {
+		rc = dps310_read_pres_raw_locked(data);
+		if (rc)
+			return rc;
+
+		/* Waiting here would hold scans to the temperature rate */
+		dps310_refresh_temp_locked(data);
+	} else {
+		rc = dps310_read_temp_raw_locked(data);
+		if (rc)
+			return rc;
+	}
 
 	i = 0;
 	if (test_bit(DPS310_SCAN_TEMP, scan_mask)) {
@@ -924,10 +932,6 @@ static int dps310_fill_channels(struct dps310_data *data,
 	}
 
 	if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) {
-		rc = dps310_read_pres_raw_locked(data);
-		if (rc)
-			return rc;
-
 		/* Pascals, see the channel definition */
 		rc = dps310_calculate_pressure(data, &channels[i++]);
 		if (rc)
@@ -1017,6 +1021,12 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	/* Pressure compensation needs a temperature from the start */
+	scoped_guard(mutex, &data->lock)
+		rc = dps310_read_temp_raw_locked(data);
+	if (rc)
+		return rc;
+
 	/*
 	 * The device measures continuously in background mode, so a capture is
 	 * just a read of the latest results. The trigger is not aligned with

base-commit: 9752760146e642f3e4a2ec860f8767fa72030d2c

#2 lore raw
Quoted 7 lines · On Sat, 14 Nov 2026 01:38:17 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines

Read pressure first and take the latest temperature, as a direct pressure read already does. Wait for temperature only when pressure is not in the scan. Read a temperature in probe, so there is a latest one from the first scan on.

That was potentially a while back. Why not do it in preenable for the buffer? Will make the buffer start a bit slow but should 'work' from there on.

Probe value only lasts until the next temperature result. By the time the buffer starts TMP_RDY is set, so first scan takes a new temperature anyway (checked on the board, buffer enabled 5 s after probe). The probe read also covers direct pressure reads.

Happy to move it to preenable if you prefer.

Thanks,
Rupesh

maintainer
#3 lore raw
Quoted 8 lines · On Sat, 14 Nov 2026 10:35:25 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 5 lines · On Sat, 14 Nov 2026 01:38:17 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines

Read pressure first and take the latest temperature, as a direct pressure read already does. Wait for temperature only when pressure is not in the scan. Read a temperature in probe, so there is a latest one from the first scan on.

Quoted 7 lines
Quoted 2 lines

That was potentially a while back. Why not do it in preenable for the buffer? Will make the buffer start a bit slow but should 'work' from there on.

Probe value only lasts until the next temperature result. By the time the buffer starts TMP_RDY is set, so first scan takes a new temperature anyway (checked on the board, buffer enabled 5 s after probe). The probe read also covers direct pressure reads.

I'm a bit lost. So how stale can it be in the direct pressure read case?

Sounds like the buffer one is fine.

J

Quoted 5 lines

Happy to move it to preenable if you prefer.

Thanks,
Rupesh

#4 lore raw
Quoted 5 lines · On Sun, 15 Nov 2026 01:02:03 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines

Probe value only lasts until the next temperature result. By the time the buffer starts TMP_RDY is set, so first scan takes a new temperature anyway (checked on the board, buffer enabled 5 s after probe). The probe read also covers direct pressure reads.

I'm a bit lost. So how stale can it be in the direct pressure read case?

One temperature period, so 1 s at the default 1 Hz. A direct pressure read takes new temperature result whenever TMP_RDY is set.

Probe read is for a pressure read that comes before first temperature result after probe. That one would use temp_raw = 0.

Thanks,
Rupesh

maintainer
#5 lore raw
Quoted 7 lines · On Sun, 15 Nov 2026 20:39:49 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 4 lines · On Sun, 15 Nov 2026 01:02:03 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines

Probe value only lasts until the next temperature result. By the time the buffer starts TMP_RDY is set, so first scan takes a new temperature anyway (checked on the board, buffer enabled 5 s after probe). The probe read also covers direct pressure reads.

Quoted 7 lines
Quoted 1 line

I'm a bit lost. So how stale can it be in the direct pressure read case?

One temperature period, so 1 s at the default 1 Hz. A direct pressure read takes new temperature result whenever TMP_RDY is set.

Probe read is for a pressure read that comes before first temperature result after probe. That one would use temp_raw = 0.

That all sounds good. I tried to apply it to the testing branch of iio.git but I'm getting some build errors (+ a load of fuzz). I guess this has dependencies that I'm missing? If they are fixes, then I may just have to wait until I can merge back into my tree (after they are upstream).

Anyhow, if you can figure out what I have wrong wrt to patches before this then let know! + add that info to future patches.

Thanks,

Jonathan

Quoted 3 lines

Thanks,
Rupesh

#6 lore raw
Quoted 4 lines · On Sun, 15 Nov 2026 20:34:11 +0000 Jonathan Cameron <[email protected]> wrote:

That all sounds good. I tried to apply it to the testing branch of iio.git but I'm getting some build errors (+ a load of fuzz). I guess this has dependencies that I'm missing? If they are fixes, then I may just have to wait until I can merge back into my tree (after they are upstream).

No dependencies. It is based on fixes-togreg. On testing probe hunk no longer matches and with fuzz it lands in dps310_fifo_interval(). git am -3 gets it right there and it builds.

I can send a version on testing if that is easier.

Thanks,
Rupesh

maintainer
#7 lore raw
Quoted 8 lines · On Mon, 16 Nov 2026 00:38:17 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 4 lines · On Sun, 15 Nov 2026 20:34:11 +0000 Jonathan Cameron <[email protected]> wrote:

That all sounds good. I tried to apply it to the testing branch of iio.git but I'm getting some build errors (+ a load of fuzz). I guess this has dependencies that I'm missing? If they are fixes, then I may just have to wait until I can merge back into my tree (after they are upstream).

Quoted 5 lines

No dependencies. It is based on fixes-togreg. On testing probe hunk no longer matches and with fuzz it lands in dps310_fifo_interval(). git am -3 gets it right there and it builds.

I can send a version on testing if that is easier.

I actually looked at what was messing up this time. It was just that int rc; had been dropped. It's just used locally in this patch so I put a declaration in.

Have just merged rc3 into the testing branch anyway as a bunch of other stuff is queued up on it. So hopefully what I push out in a minute should be good.

Jonathan

Quoted 3 lines

Thanks,
Rupesh

maintainer
#8 lore raw
Quoted 15 lines · On Tue, 17 Nov 2026 03:31:53 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 12 lines · On Mon, 16 Nov 2026 00:38:17 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 4 lines · On Sun, 15 Nov 2026 20:34:11 +0000 Jonathan Cameron <[email protected]> wrote:

That all sounds good. I tried to apply it to the testing branch of iio.git but I'm getting some build errors (+ a load of fuzz). I guess this has dependencies that I'm missing? If they are fixes, then I may just have to wait until I can merge back into my tree (after they are upstream).

No dependencies. It is based on fixes-togreg. On testing probe hunk no longer matches and with fuzz it lands in dps310_fifo_interval(). git am -3 gets it right there and it builds.

Quoted 9 lines
Quoted 1 line

I can send a version on testing if that is easier.

I actually looked at what was messing up this time. It was just that int rc; had been dropped. It's just used locally in this patch so I put a declaration in.

Have just merged rc3 into the testing branch anyway as a bunch of other stuff is queued up on it. So hopefully what I push out in a minute should be good.

Scratch that - I just backed out the merge as completely failed to notice the char-misc merge was after rc3, thus little point :( Will have to wait for rc4 for a suitable tag to merge.

Anyhow, I cherry-picked my fixed up version and it applies fine without that anyway.

Thanks

Jonathan

Quoted 7 lines

Jonathan

Quoted 3 lines

Thanks,
Rupesh

#9 lore raw
Quoted 3 lines · On Tue, 17 Nov 2026 03:37:41 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 3 lines

I actually looked at what was messing up this time. It was just that int rc; had been dropped. It's just used locally in this patch so I put a declaration in.

On testing (d922ed738439) temperature read ended up in dps310_fifo_interval() instead of probe. That runs with data->lock held, so enabling the buffer without a trigger hangs on the board.

Diff below on top of testing moves it to probe, tested on the board.

Thanks,
Rupesh

drivers/iio/pressure/dps310.c +6 -7
index 9b52cbc2372a..ebfaa67a6b91 100644
@@ -1058,16 +1058,9 @@ static unsigned int dps310_fifo_interval(struct dps310_data *data,
 {
 	unsigned int drain_interval_ms, fill_ms, want_ms;
 	int scan_rate;
-	int rc;
 
 	fill_ms = MSEC_PER_SEC * DPS310_FIFO_DEPTH / (prs_rate + tmp_rate);
 
-	/* Pressure compensation needs a temperature from the start */
-	scoped_guard(mutex, &data->lock)
-		rc = dps310_read_temp_raw_locked(data);
-	if (rc)
-		return rc;
-
 	/*
 	 * There is no hardware watermark, so take it as the number of scans
 	 * the user will wait for and drain at that rate. Scans come from
@@ -1478,6 +1471,12 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	/* Pressure compensation needs a temperature from the start */
+	scoped_guard(mutex, &data->lock)
+		rc = dps310_read_temp_raw_locked(data);
+	if (rc)
+		return rc;
+
 	/*
 	 * The device measures continuously in background mode, so a triggered
 	 * capture is just a read of the latest results. The setup ops run the