[PATCH RFC 7/9] iio: trigger: Add new API iio_trigger_attach_timestamp()

From: Gyeyoung Baek
Date: Mon May 19 2025 - 10:27:56 EST


This new API is used in `iio_poll_func_register()` to handle the case
where the trigger writes a timestamp directly into the consumer (i.e. early_timestamp == true).

Signed-off-by: Gyeyoung Baek <gye976@xxxxxxxxx>
---
drivers/iio/industrialio-trigger.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index d6b0e1ec4153..f394933b9d0a 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -288,6 +288,15 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
clear_bit(irq - trig->subirq_base, trig->pool);
}

+static int iio_trigger_attach_timestamp(struct iio_trigger *trig,
+ struct iio_poll_func *pf)
+{
+ /* RFC */
+ trig->consumer_pf[pf->irq - trig->subirq_base] = pf;
+
+ return 0;
+}
+
static int iio_poll_func_register(struct iio_poll_func *pf,
struct iio_trigger *trig)
{
@@ -302,6 +311,16 @@ static int iio_poll_func_register(struct iio_poll_func *pf,
if (!pf->timestamp_enabled)
goto out_request_irq;

+ /*
+ * The trigger supports grabbing timestamp.
+ * Just request raw irq handler.
+ */
+ if (trig->early_timestamp) {
+ ret = iio_trigger_attach_timestamp(trig, pf);
+ pf->timestamp_type = IIO_TIMESTAMP_TYPE_TRIGGER;
+ goto out_request_irq;
+ }
+
if (trig->trig_type & IIO_TRIG_TYPE_POLL_NESTED) {
bottomhalf = iio_pollfunc_bottom_half_wrapper;
pf->timestamp_type = IIO_TIMESTAMP_TYPE_CONSUMER_BOTTOM_HALF;
@@ -395,6 +414,9 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig,
module_put(iio_dev_opaque->driver_module);
pf->irq = 0;

+ /* RFC */
+ trig->consumer_pf[pf->irq - trig->subirq_base] = NULL;
+
return ret;
}


--
2.43.0