From: Rupesh Majhi <zoone.rupert@gmail.com>
To: "Andy Shevchenko" <andy@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Eddie James" <eajames@linux.ibm.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>, "Rob Herring" <robh@kernel.org>
Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Rupesh Majhi <zoone.rupert@gmail.com>,
Paulius Zaleckas <paulius.zaleckas@gmail.com>
Subject: [PATCH 2/2] iio: pressure: dps310: add a data-ready trigger
Date: Tue, 10 Nov 2026 17:42:54 +0200 [thread overview]
Message-ID: <20261110154254.39092-3-zoone.rupert@gmail.com> (raw)
In-Reply-To: <20261110154254.39092-1-zoone.rupert@gmail.com>
With an interrupt wired to SDO, the chip can signal each new pressure
result. Expose it as a trigger, so captures follow the measurements and
scans carry the time the result was ready, not when the handler ran.
Polarity follows the interrupt type. Status latches while the interrupt
is disabled, so it is cleared before enabling. The trigger is not the
default, so FIFO mode without a trigger is unchanged.
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
Cc: Paulius Zaleckas <paulius.zaleckas@gmail.com>
drivers/iio/pressure/dps310.c | 129 ++++++++++++++++++++++++++++++++--
1 file changed, 125 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 5cee23986f30..76738360e528 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -17,6 +17,8 @@
#include <linux/cleanup.h>
#include <linux/devm-helpers.h>
#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
#include <linux/limits.h>
#include <linux/math64.h>
#include <linux/module.h>
@@ -31,6 +33,7 @@
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
@@ -62,10 +65,13 @@
#define DPS310_COEF_RDY BIT(7)
#define DPS310_CFG_REG 0x09
#define DPS310_INT_HL BIT(7)
+#define DPS310_INT_PRS BIT(4)
#define DPS310_TMP_SHIFT_EN BIT(3)
#define DPS310_PRS_SHIFT_EN BIT(2)
#define DPS310_FIFO_EN BIT(1)
#define DPS310_SPI_EN BIT(0)
+#define DPS310_INT_STS 0x0a
+#define DPS310_INT_STS_PRS BIT(0)
#define DPS310_RESET 0x0c
#define DPS310_FIFO_FLUSH BIT(7)
#define DPS310_RESET_MAGIC 0x09
@@ -144,6 +150,9 @@ struct dps310_data {
bool timeout_recovery_failed;
bool fifo_temp_valid;
+ struct iio_trigger *trig;
+ s64 irq_timestamp;
+
/* Used only while the FIFO is enabled */
struct iio_dev *iio;
struct delayed_work fifo_work;
@@ -706,6 +715,7 @@ static bool dps310_is_volatile_reg(struct device *dev, unsigned int reg)
case DPS310_TMP_B1:
case DPS310_TMP_B2:
case DPS310_MEAS_CFG:
+ case DPS310_INT_STS:
case 0x32: /* No documentation available on this register */
return true;
default:
@@ -713,6 +723,12 @@ static bool dps310_is_volatile_reg(struct device *dev, unsigned int reg)
}
}
+/* Cleared on read */
+static bool dps310_is_precious_reg(struct device *dev, unsigned int reg)
+{
+ return reg == DPS310_INT_STS;
+}
+
static int dps310_write_raw(struct iio_dev *iio,
struct iio_chan_spec const *chan, int val,
int val2, long mask)
@@ -1048,7 +1064,7 @@ static int dps310_fifo_set_enable(struct dps310_data *data, bool enable)
enable);
}
-/* No interrupt pin is wired in tree, so drain on a timer */
+/* The FIFO only interrupts when full and then stops, so drain on a timer */
static unsigned int dps310_fifo_interval(struct dps310_data *data,
int prs_rate, int tmp_rate)
{
@@ -1375,6 +1391,7 @@ static irqreturn_t dps310_trigger_handler(int irq, void *p)
s32 channels[2];
aligned_s64 timestamp;
} scan = { };
+ s64 timestamp;
int rc;
mutex_lock(&data->lock);
@@ -1383,7 +1400,12 @@ static irqreturn_t dps310_trigger_handler(int irq, void *p)
if (rc)
goto err;
- iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), iio_get_time_ns(iio));
+ if (iio_trigger_using_own(iio))
+ timestamp = data->irq_timestamp;
+ else
+ timestamp = iio_get_time_ns(iio);
+
+ iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), timestamp);
err:
iio_trigger_notify_done(iio->trig);
@@ -1391,6 +1413,97 @@ static irqreturn_t dps310_trigger_handler(int irq, void *p)
return IRQ_HANDLED;
}
+static irqreturn_t dps310_irq_handler(int irq, void *private)
+{
+ struct dps310_data *data = private;
+
+ data->irq_timestamp = iio_get_time_ns(data->iio);
+
+ return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t dps310_irq_thread(int irq, void *private)
+{
+ struct dps310_data *data = private;
+ unsigned int status;
+
+ if (regmap_read(data->regmap, DPS310_INT_STS, &status))
+ return IRQ_NONE;
+
+ if (!(status & DPS310_INT_STS_PRS))
+ return IRQ_NONE;
+
+ iio_trigger_poll_nested(data->trig);
+
+ return IRQ_HANDLED;
+}
+
+static int dps310_trigger_set_state(struct iio_trigger *trig, bool state)
+{
+ struct dps310_data *data = iio_trigger_get_drvdata(trig);
+ unsigned int status;
+ int rc;
+
+ guard(mutex)(&data->lock);
+
+ /* Status latched while disabled would fire a stale interrupt */
+ if (state) {
+ rc = regmap_read(data->regmap, DPS310_INT_STS, &status);
+ if (rc)
+ return rc;
+ }
+
+ return regmap_assign_bits(data->regmap, DPS310_CFG_REG, DPS310_INT_PRS,
+ state);
+}
+
+static const struct iio_trigger_ops dps310_trigger_ops = {
+ .set_trigger_state = dps310_trigger_set_state,
+};
+
+static int dps310_trigger_probe(struct dps310_data *data)
+{
+ struct device *dev = &data->client->dev;
+ struct iio_dev *iio = data->iio;
+ int irq = data->client->irq;
+ bool active_high;
+ int rc;
+
+ switch (irq_get_trigger_type(irq)) {
+ case IRQ_TYPE_LEVEL_HIGH:
+ case IRQ_TYPE_EDGE_RISING:
+ active_high = true;
+ break;
+ case IRQ_TYPE_LEVEL_LOW:
+ case IRQ_TYPE_EDGE_FALLING:
+ active_high = false;
+ break;
+ default:
+ return dev_err_probe(dev, -EINVAL, "Unsupported interrupt type\n");
+ }
+
+ rc = regmap_assign_bits(data->regmap, DPS310_CFG_REG, DPS310_INT_HL,
+ active_high);
+ if (rc)
+ return rc;
+
+ data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", iio->name,
+ iio_device_id(iio));
+ if (!data->trig)
+ return -ENOMEM;
+
+ data->trig->ops = &dps310_trigger_ops;
+ iio_trigger_set_drvdata(data->trig, data);
+
+ rc = devm_request_threaded_irq(dev, irq, dps310_irq_handler,
+ dps310_irq_thread, IRQF_ONESHOT,
+ iio->name, data);
+ if (rc)
+ return rc;
+
+ return devm_iio_trigger_register(dev, data->trig);
+}
+
static void dps310_standby(void *action_data)
{
struct dps310_data *data = action_data;
@@ -1404,6 +1517,7 @@ static const struct regmap_config dps310_regmap_config = {
.val_bits = 8,
.writeable_reg = dps310_is_writeable_reg,
.volatile_reg = dps310_is_volatile_reg,
+ .precious_reg = dps310_is_precious_reg,
.cache_type = REGCACHE_RBTREE,
.max_register = 0x62, /* No documentation available on this register */
};
@@ -1470,8 +1584,9 @@ static int dps310_probe(struct i2c_client *client)
/*
* The device measures continuously in background mode, so a triggered
* capture is just a read of the latest results. The setup ops run the
- * FIFO drain when no trigger is attached. The trigger is not aligned
- * with the measurements, so the timestamp is taken in the handler.
+ * FIFO drain when no trigger is attached. Only the data-ready trigger
+ * is aligned with the measurements, so for others the timestamp is
+ * taken in the handler.
*/
rc = devm_iio_triggered_buffer_setup(dev, iio, NULL,
dps310_trigger_handler,
@@ -1484,6 +1599,12 @@ static int dps310_probe(struct i2c_client *client)
if (rc)
return rc;
+ if (client->irq > 0) {
+ rc = dps310_trigger_probe(data);
+ if (rc)
+ return rc;
+ }
+
rc = devm_iio_device_register(dev, iio);
if (rc)
return rc;
--
2.43.0
next prev parent reply other threads:[~2026-11-10 15:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 15:42 [PATCH 0/2] iio: pressure: dps310: " Rupesh Majhi
2026-11-10 15:42 ` [PATCH 1/2] dt-bindings: iio: pressure: infineon,dps310: Add interrupts Rupesh Majhi
2026-11-10 15:42 ` Rupesh Majhi [this message]
2026-11-10 16:48 ` [PATCH 2/2] iio: pressure: dps310: add a data-ready trigger Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110154254.39092-3-zoone.rupert@gmail.com \
--to=zoone.rupert@gmail.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=eajames@linux.ibm.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=paulius.zaleckas@gmail.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®