[PATCH v2 5/7] media: camss: csid-gen2: Report the hardware SOF timestamp
From: Loic Poulain
Date: Wed Nov 25 2026 - 05:20:34 EST
From: Bryan O'Donoghue <bryan.odonoghue@xxxxxxxxxx>
The CSID latches a free-running timer value for every RDI at
start-of-frame, a timer that keeps running across system suspend. The
driver already enables that latching, it just never reads the result,
leaving the frame sync event to be timestamped when the interrupt
handler gets around to queueing it.
Implement the sof_ts operation to read the CURRENT_SOF pair
instead, and let the CSID core put it on the CLOCK_MONOTONIC timebase
the event carries. CURRENT_EOF and the PREVIOUS_* pairs are left alone,
following the reference Qualcomm Camx code which only interacts with
CURRENT_SOF.
Upstream CAMSS uses a fixed mapping of RDI to virtual channel, hence
VC0 => RDI0 and VC1 => RDI1, so the event id indexes the register block
directly.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@xxxxxxxxxx>
Signed-off-by: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/qcom/camss/camss-csid-gen2.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen2.c b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
index 85e9eaf78df75f95d5f44f83b45dc7a3633401d0..47b0881e9c9942eeeaef53d8aa6b466ca21a366a 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-gen2.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
@@ -376,6 +376,20 @@ static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
return 0;
}
+static u64 csid_sof_ts(struct csid_device *csid, unsigned int rdi)
+{
+ u32 lo, hi;
+
+ /*
+ * The pair is latched on SOF rather than counting, so it can be read
+ * one word at a time without tearing.
+ */
+ lo = readl_relaxed(csid->base + CSID_RDI_TIMESTAMP_CURR0_SOF(rdi));
+ hi = readl_relaxed(csid->base + CSID_RDI_TIMESTAMP_CURR1_SOF(rdi));
+
+ return ((u64)hi << 32) | lo;
+}
+
/*
* csid_isr - CSID module interrupt service routine
* @irq: Interrupt line
@@ -459,6 +473,7 @@ const struct csid_hw_ops csid_ops_gen2 = {
.hw_version = csid_hw_version,
.isr = csid_isr,
.reset = csid_reset,
+ .sof_ts = csid_sof_ts,
.src_pad_code = csid_src_pad_code,
.subdev_init = csid_subdev_init,
};
--
2.34.1