* [PATCH] iio: pressure: dps310: add FIFO support
@ 2026-05-18 16:53 Rupesh Majhi
2026-05-18 18:58 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Rupesh Majhi @ 2026-05-18 16:53 UTC (permalink / raw)
To: linux-iio; +Cc: eajames, jic23, Rupesh Majhi
The DPS310 has a 32-sample hardware FIFO that buffers interleaved
pressure and temperature measurements in background mode. The FIFO_EN
bit was already defined but unused.
Add register defines for the FIFO status register and sample type
encoding, implement FIFO enabled/flush helpers, and wire FIFO initialization
into the probe path after dps310_startup() has established background
measurement mode.
FIFO initialization failure is treated as non-fatal so the driver continues
to operate via single reads if FIFO enable fails.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 73 +++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 8edaa4d10a70..5b031c9573d0 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -53,6 +53,19 @@
#define DPS310_PRS_SHIFT_EN BIT(4)
#define DPS310_FIFO_EN BIT(5)
#define DPS310_SPI_EN BIT(6)
+/* FIFO status register */
+#define DPS310_FIFO_STS 0x0B
+#define DPS310_FIFO_EMPTY BIT(0)
+#define DPS310_FIFO_FULL BIT(1)
+
+/* FIFO samples are read from DPS310_PRS_BASE (0x00). The lower 2 bits
+ * of the third byte encode the sample type; the remaining bits are
+ * the signed measurement value.
+ */
+#define DPS310_FIFO_TYPE_MASK GENMASK(0, 0)
+#define DPS310_FIFO_TMP_SAMPLE 0x00
+#define DPS310_FIFO_PRS_SAMPLE 0x01
+
#define DPS310_RESET 0x0c
#define DPS310_RESET_MAGIC 0x09
#define DPS310_COEF_BASE 0x10
@@ -90,6 +103,7 @@ struct dps310_data {
s32 pressure_raw;
s32 temp_raw;
bool timeout_recovery_failed;
+ bool fifo_enabled;
};
static const struct iio_chan_spec dps310_channels[] = {
@@ -843,6 +857,61 @@ static const struct iio_info dps310_info = {
.write_raw = dps310_write_raw,
};
+static int dps310_fifo_flush(struct dps310_data *data)
+{
+ int rc;
+
+ rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+ DPS310_FIFO_EN, 0);
+ if (rc)
+ return rc;
+
+ data->fifo_enabled = false;
+ return 0;
+}
+
+static int __maybe_unused dps310_fifo_read_sample(struct dps310_data *data)
+{
+ int rc;
+ u8 val[3];
+ s32 raw;
+ u8 type;
+
+ rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE,
+ val, sizeof(val));
+ if (rc)
+ return rc;
+
+ type = val[2] & DPS310_FIFO_TYPE_MASK;
+ raw = (val[0] << 16) | (val[1] << 8) | (val[2] & ~DPS310_FIFO_TYPE_MASK);
+ raw = sign_extend32(raw, 23);
+
+ if (type == DPS310_FIFO_TMP_SAMPLE)
+ data->temp_raw = raw;
+ else
+ data->pressure_raw = raw;
+
+ return 0;
+}
+
+static int dps310_fifo_init(struct dps310_data *data)
+{
+ int rc;
+
+ rc = dps310_fifo_flush(data);
+ if (rc)
+ return rc;
+
+ rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+ DPS310_FIFO_EN, DPS310_FIFO_EN);
+
+ if (rc)
+ return rc;
+
+ data->fifo_enabled = true;
+ return 0;
+}
+
static int dps310_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
@@ -877,6 +946,10 @@ static int dps310_probe(struct i2c_client *client)
if (rc)
return rc;
+ rc = dps310_fifo_init(data);
+ if (rc)
+ dev_warn(&client->dev,
+ "FIFO init failed (%d), continuing without FIFO\n", rc);
rc = devm_iio_device_register(&client->dev, iio);
if (rc)
return rc;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: pressure: dps310: add FIFO support
2026-05-18 16:53 [PATCH] iio: pressure: dps310: add FIFO support Rupesh Majhi
@ 2026-05-18 18:58 ` Jonathan Cameron
[not found] ` <CABpb+S7rW5c_40eCLesRq8yVeUziQYK9x8Uy-FBJ4z_JqhGPDQ@mail.gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2026-05-18 18:58 UTC (permalink / raw)
To: Rupesh Majhi; +Cc: linux-iio, eajames
On Mon, 18 May 2026 19:53:20 +0300
Rupesh Majhi <zoone.rupert@gmail.com> wrote:
> The DPS310 has a 32-sample hardware FIFO that buffers interleaved
> pressure and temperature measurements in background mode. The FIFO_EN
> bit was already defined but unused.
>
> Add register defines for the FIFO status register and sample type
> encoding, implement FIFO enabled/flush helpers, and wire FIFO initialization
> into the probe path after dps310_startup() has established background
> measurement mode.
>
> FIFO initialization failure is treated as non-fatal so the driver continues
> to operate via single reads if FIFO enable fails.
I'm not sure I understand why one would enable this? You've not
modified any of the reading paths. Normally we'd expect a hardware fifo
to be connected up to an IIO buffered interface (via chrdev) and provide
things like watermark control.
There are lots of examples in tree of how to handle fifos. This seems
to be maybe the 1st 5% of what's needed. Was it perhaps meant to be
an RFC with some questions?
Jonathan
>
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
> ---
> drivers/iio/pressure/dps310.c | 73 +++++++++++++++++++++++++++++++++++
> 1 file changed, 73 insertions(+)
>
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index 8edaa4d10a70..5b031c9573d0 100644
> --- a/drivers/iio/pressure/dps310.c
> +++ b/drivers/iio/pressure/dps310.c
> @@ -53,6 +53,19 @@
> #define DPS310_PRS_SHIFT_EN BIT(4)
> #define DPS310_FIFO_EN BIT(5)
> #define DPS310_SPI_EN BIT(6)
> +/* FIFO status register */
> +#define DPS310_FIFO_STS 0x0B
> +#define DPS310_FIFO_EMPTY BIT(0)
> +#define DPS310_FIFO_FULL BIT(1)
> +
> +/* FIFO samples are read from DPS310_PRS_BASE (0x00). The lower 2 bits
Wrong comment style.
> + * of the third byte encode the sample type; the remaining bits are
> + * the signed measurement value.
> + */
> +#define DPS310_FIFO_TYPE_MASK GENMASK(0, 0)
Smells like a BIT(0) We don't use genmask for single bits.
However, you mention 2 bits.
> +#define DPS310_FIFO_TMP_SAMPLE 0x00
> +#define DPS310_FIFO_PRS_SAMPLE 0x01
If it's only 2 bits (or maybe 1?) then 0 / 1
is fine.
> +
> #define DPS310_RESET 0x0c
> #define DPS310_RESET_MAGIC 0x09
> #define DPS310_COEF_BASE 0x10
> @@ -90,6 +103,7 @@ struct dps310_data {
> s32 pressure_raw;
> s32 temp_raw;
> bool timeout_recovery_failed;
> + bool fifo_enabled;
> };
>
> static const struct iio_chan_spec dps310_channels[] = {
> @@ -843,6 +857,61 @@ static const struct iio_info dps310_info = {
> .write_raw = dps310_write_raw,
> };
>
> +static int dps310_fifo_flush(struct dps310_data *data)
> +{
> + int rc;
> +
> + rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
> + DPS310_FIFO_EN, 0);
> + if (rc)
> + return rc;
> +
> + data->fifo_enabled = false;
> + return 0;
> +}
> +
> +static int __maybe_unused dps310_fifo_read_sample(struct dps310_data *data)
Given the fairly obvious __maybe_unused what is the point?
> +{
> + int rc;
> + u8 val[3];
> + s32 raw;
> + u8 type;
> +
> + rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE,
> + val, sizeof(val));
> + if (rc)
> + return rc;
> +
> + type = val[2] & DPS310_FIFO_TYPE_MASK;
> + raw = (val[0] << 16) | (val[1] << 8) | (val[2] & ~DPS310_FIFO_TYPE_MASK);
get_unaligned_be24() and then mask. However - why not also shift right to
drop those 0s?
> + raw = sign_extend32(raw, 23);
> +
> + if (type == DPS310_FIFO_TMP_SAMPLE)
> + data->temp_raw = raw;
> + else
> + data->pressure_raw = raw;
> +
> + return 0;
> +}
> +
> +static int dps310_fifo_init(struct dps310_data *data)
> +{
> + int rc;
> +
> + rc = dps310_fifo_flush(data);
> + if (rc)
> + return rc;
> +
> + rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
> + DPS310_FIFO_EN, DPS310_FIFO_EN);
Align to just after (
> +
No blank line here.
> + if (rc)
> + return rc;
> +
> + data->fifo_enabled = true;
> + return 0;
> +}
> +
> static int dps310_probe(struct i2c_client *client)
> {
> const struct i2c_device_id *id = i2c_client_get_device_id(client);
> @@ -877,6 +946,10 @@ static int dps310_probe(struct i2c_client *client)
> if (rc)
> return rc;
>
> + rc = dps310_fifo_init(data);
> + if (rc)
> + dev_warn(&client->dev,
> + "FIFO init failed (%d), continuing without FIFO\n", rc);
Why continue? The hardware either has a fifo or it doesn't. Any failure
in here smells like dead hardware to me. Hence just fail.
> rc = devm_iio_device_register(&client->dev, iio);
> if (rc)
> return rc;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: pressure: dps310: add FIFO support
[not found] ` <CABpb+S7rW5c_40eCLesRq8yVeUziQYK9x8Uy-FBJ4z_JqhGPDQ@mail.gmail.com>
@ 2026-05-21 12:25 ` Rupert Zoone
0 siblings, 0 replies; 5+ messages in thread
From: Rupert Zoone @ 2026-05-21 12:25 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, eajames
Jonathan,
Thanks for the review. You're right, this was intentionally the first
piece, with the IIO buffered interface as the follow-up.
I'll fix the style issues and send v2 as a proper patch series along
with triggered buffer support.
br,
rupesh
On Thu, May 21, 2026 at 9:48 AM Rupert Zoone <zoone.rupert@gmail.com> wrote:
>
> Jonathan,
> Thanks for the review. You're right, this was intentionally the first piece, with the IIO buffered interface as the follow-up.
> I'll fix the style issues and send v2 as a proper patch series along with triggered buffer support.
>
> br,
> rupesh
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] iio: pressure: dps310: add FIFO support
@ 2026-07-18 21:17 Rupesh Majhi
2026-07-18 21:44 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Rupesh Majhi @ 2026-07-18 21:17 UTC (permalink / raw)
To: eajames, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel, Rupesh Majhi
The DPS310 has a 32-sample FIFO that buffers pressure and temperature
readings. The FIFO_EN bit was defined but never used.
This enables the FIFO in the probe after startup. Add the necessary
register defines and init/flush functions. If FIFO init fails, driver
falls back to single-shot mode.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 73 +++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index f45af72a0554..83f1326f542a 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -53,6 +53,19 @@
#define DPS310_PRS_SHIFT_EN BIT(4)
#define DPS310_FIFO_EN BIT(5)
#define DPS310_SPI_EN BIT(6)
+/* FIFO status register */
+#define DPS310_FIFO_STS 0x0B
+#define DPS310_FIFO_EMPTY BIT(0)
+#define DPS310_FIFO_FULL BIT(1)
+
+/* FIFO samples are read from DPS310_PRS_BASE (0x00). The lower 2 bits
+ * of the third byte encode the sample type; the remaining bits are
+ * the signed measurement value.
+ */
+#define DPS310_FIFO_TYPE_MASK GENMASK(0, 0)
+#define DPS310_FIFO_TMP_SAMPLE 0x00
+#define DPS310_FIFO_PRS_SAMPLE 0x01
+
#define DPS310_RESET 0x0c
#define DPS310_RESET_MAGIC 0x09
#define DPS310_COEF_BASE 0x10
@@ -90,6 +103,7 @@ struct dps310_data {
s32 pressure_raw;
s32 temp_raw;
bool timeout_recovery_failed;
+ bool fifo_enabled;
};
static const struct iio_chan_spec dps310_channels[] = {
@@ -843,6 +857,61 @@ static const struct iio_info dps310_info = {
.write_raw = dps310_write_raw,
};
+static int dps310_fifo_flush(struct dps310_data *data)
+{
+ int rc;
+
+ rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+ DPS310_FIFO_EN, 0);
+ if (rc)
+ return rc;
+
+ data->fifo_enabled = false;
+ return 0;
+}
+
+static int __maybe_unused dps310_fifo_read_sample(struct dps310_data *data)
+{
+ int rc;
+ u8 val[3];
+ s32 raw;
+ u8 type;
+
+ rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE,
+ val, sizeof(val));
+ if (rc)
+ return rc;
+
+ type = val[2] & DPS310_FIFO_TYPE_MASK;
+ raw = (val[0] << 16) | (val[1] << 8) | (val[2] & ~DPS310_FIFO_TYPE_MASK);
+ raw = sign_extend32(raw, 23);
+
+ if (type == DPS310_FIFO_TMP_SAMPLE)
+ data->temp_raw = raw;
+ else
+ data->pressure_raw = raw;
+
+ return 0;
+}
+
+static int dps310_fifo_init(struct dps310_data *data)
+{
+ int rc;
+
+ rc = dps310_fifo_flush(data);
+ if (rc)
+ return rc;
+
+ rc = regmap_write_bits(data->regmap, DPS310_CFG_REG,
+ DPS310_FIFO_EN, DPS310_FIFO_EN);
+
+ if (rc)
+ return rc;
+
+ data->fifo_enabled = true;
+ return 0;
+}
+
static int dps310_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
@@ -877,6 +946,10 @@ static int dps310_probe(struct i2c_client *client)
if (rc)
return rc;
+ rc = dps310_fifo_init(data);
+ if (rc)
+ dev_warn(&client->dev,
+ "FIFO init failed (%d), continuing without FIFO\n", rc);
rc = devm_iio_device_register(&client->dev, iio);
if (rc)
return rc;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: pressure: dps310: add FIFO support
2026-07-18 21:17 Rupesh Majhi
@ 2026-07-18 21:44 ` Jonathan Cameron
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-07-18 21:44 UTC (permalink / raw)
To: Rupesh Majhi; +Cc: eajames, dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Sun, 19 Jul 2026 00:17:26 +0300
Rupesh Majhi <zoone.rupert@gmail.com> wrote:
> The DPS310 has a 32-sample FIFO that buffers pressure and temperature
> readings. The FIFO_EN bit was defined but never used.
>
> This enables the FIFO in the probe after startup. Add the necessary
> register defines and init/flush functions. If FIFO init fails, driver
> falls back to single-shot mode.
>
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
Hi Rupesh,
This looks to be a v2. So check Documentation/process/submitting-patches.rst
for the format and use that if you need a v3.
> ---
Also change log needed here.
I thought you were going to submit v2 with the full buffered support?
Perhaps this was an accidental resend of the earlier code.
Jonathan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-18 21:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 16:53 [PATCH] iio: pressure: dps310: add FIFO support Rupesh Majhi
2026-05-18 18:58 ` Jonathan Cameron
[not found] ` <CABpb+S7rW5c_40eCLesRq8yVeUziQYK9x8Uy-FBJ4z_JqhGPDQ@mail.gmail.com>
2026-05-21 12:25 ` Rupert Zoone
-- strict thread matches above, loose matches on Subject: below --
2026-07-18 21:17 Rupesh Majhi
2026-07-18 21:44 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox