[PATCH 5/6] media: camss: csid-gen2: Report the hardware SOF timestamp
From: Loic Poulain
Date: Mon Nov 23 2026 - 12:17:23 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.
Read the CURRENT_SOF pair instead and hand it to
csid_timestamp_to_monotonic(), which puts 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 | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen2.c b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
index ac085ede704653a532aa1ab77b2845471d1e6900..a2da70d5533314816fdacfb8b07248860d243b58 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_timestamp(struct csid_device *csid, u8 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 csid_timestamp_to_monotonic(csid, ((u64)hi << 32) | lo);
+}
+
/*
* csid_isr - CSID module interrupt service routine
* @irq: Interrupt line
@@ -403,7 +417,7 @@ static irqreturn_t csid_isr(int irq, void *dev)
val = readl_relaxed(csid->base + CSID_CSI2_RDIN_IRQ_STATUS(i));
writel_relaxed(val, csid->base + CSID_CSI2_RDIN_IRQ_CLEAR(i));
if (val & RDIN_IRQ_INFO_INPUT_SOF)
- csid_sof_event(csid, i, 0);
+ csid_sof_event(csid, i, __csid_sof_timestamp(csid, i));
}
val = 1 << IRQ_CMD_CLEAR;
--
2.34.1