mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iio: pressure: dps310: don't wait for new temperature in trigger handler
@ 2026-11-13 23:02 Rupesh Majhi
  2026-11-14  1:38 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Rupesh Majhi @ 2026-11-13 23:02 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá,
	Rupesh Majhi
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Sashiko, Arnav Kapoor

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")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261110154254.39092-1-zoone.rupert%40gmail.com
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
v2: read a temperature in probe, so the first scans have one (Arnav Kapoor)
v1: https://lore.kernel.org/linux-iio/20261111195118.36853-1-zoone.rupert@gmail.com/

Cc: Arnav Kapoor <kapoorarnav43@gmail.com>
Cc: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>

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

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 85df58ac1809..3d05540f95dd 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -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.43.0


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

* Re: [PATCH v2] iio: pressure: dps310: don't wait for new temperature in trigger handler
  2026-11-13 23:02 [PATCH v2] iio: pressure: dps310: don't wait for new temperature in trigger handler Rupesh Majhi
@ 2026-11-14  1:38 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-11-14  1:38 UTC (permalink / raw)
  To: Rupesh Majhi
  Cc: Andy Shevchenko, David Lechner, Eddie James, Nuno Sá,
	Jonathan Cameron, linux-iio, linux-kernel, Sashiko, Arnav Kapoor

On Sat, 14 Nov 2026 01:02:41 +0200
Rupesh Majhi <zoone.rupert@gmail.com> 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.

> 
> Fixes: 9b7cad9ce2ed ("iio: pressure: dps310: add triggered buffer support")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20261110154254.39092-1-zoone.rupert%40gmail.com
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
> ---
> v2: read a temperature in probe, so the first scans have one (Arnav Kapoor)
> v1: https://lore.kernel.org/linux-iio/20261111195118.36853-1-zoone.rupert@gmail.com/
> 
> Cc: Arnav Kapoor <kapoorarnav43@gmail.com>
> Cc: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> 
>  drivers/iio/pressure/dps310.c | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index 85df58ac1809..3d05540f95dd 100644
> --- a/drivers/iio/pressure/dps310.c
> +++ b/drivers/iio/pressure/dps310.c
> @@ -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


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 23:02 [PATCH v2] iio: pressure: dps310: don't wait for new temperature in trigger handler Rupesh Majhi
2026-11-14  1:38 ` Jonathan Cameron

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®