From: Loic Poulain <loic.poulain@oss.qualcomm.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org,
Loic Poulain <loic.poulain@oss.qualcomm.com>
Subject: [PATCH v3 2/8] media: qcom: camss: csid-340: Report the hardware SOF timestamp
Date: Fri, 27 Nov 2026 17:11:52 +0100 [thread overview]
Message-ID: <20261127-camss-hw-ts-v3-2-e4b6ad98ce9c@oss.qualcomm.com> (raw)
In-Reply-To: <20261127-camss-hw-ts-v3-0-e4b6ad98ce9c@oss.qualcomm.com>
The CSID latches the global timestamp counter at start-of-frame into a
per-interface register pair. Implement the sof_ts operation to
read it, so that the frame sync event carries the time the frame
actually started rather than the time the interrupt handler ran.
Measured on QCM2290 that removes around 36 us of delay, with ~8 us of
jitter, from the timestamp userspace sees on a 60 fps stream.
TIMESTAMP_EN is not at the same bit in the PIX and the RDI layouts of
CSID_CFG0, so replace the single define with one for each.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss-csid-340.c | 37 +++++++++++++++++++---
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-340.c b/drivers/media/platform/qcom/camss/camss-csid-340.c
index 42ff629ce410d33f21930ee56d714f41911cc077..ec4b1d9a86fcf08c2ceb12b4c4c2b85b5c7b8e51 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-340.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-340.c
@@ -49,7 +49,8 @@
#define CSID_CFG0(iface) (0x200 + 0x100 * (iface))
#define CSID_CFG0_BYTE_CNTR_EN BIT(0)
-#define CSID_CFG0_TIMESTAMP_EN BIT(1)
+#define CSID_CFG0_PIX_TIMESTAMP_EN BIT(1)
+#define CSID_CFG0_RDI_TIMESTAMP_EN BIT(2)
#define CSID_CFG0_DECODE_FORMAT_MASK GENMASK(15, 12)
#define CSID_CFG0_DECODE_FORMAT_NOP CSID_CFG0_DECODE_FORMAT_MASK
#define CSID_CFG0_DT_MASK GENMASK(21, 16)
@@ -61,6 +62,13 @@
#define CSID_CTRL_HALT_AT_FRAME_BOUNDARY 0
#define CSID_CTRL_RESUME_AT_FRAME_BOUNDARY 1
+/*
+ * SOF timestamp of the most recent frame, a pair of registers holding a 56-bit
+ * counter value, the low 32 bits in the first and the high 24 in the second.
+ */
+#define CSID_TIMESTAMP_CURR0_SOF(iface) (0x290 + 0x100 * (iface))
+#define CSID_TIMESTAMP_CURR1_SOF(iface) (0x294 + 0x100 * (iface))
+
enum csid_iface {
CSID_IFACE_PIX,
CSID_IFACE_RDI0,
@@ -108,6 +116,7 @@ static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 port
input_format->code);
enum csid_iface iface = csid_port_iface_map[port];
+ u32 timestamp_en;
u8 dt_id;
u32 val;
@@ -125,17 +134,21 @@ static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 port
*/
dt_id = port & 0x03;
- if (iface == CSID_IFACE_PIX)
+ if (iface == CSID_IFACE_PIX) {
val = FIELD_PREP(CSID_CFG0_DECODE_FORMAT_MASK, format->decode_format);
- else /* RDI is raw, no decoding */
+ timestamp_en = CSID_CFG0_PIX_TIMESTAMP_EN;
+ } else {
+ /* RDI is raw, no decoding */
val = CSID_CFG0_DECODE_FORMAT_NOP;
+ timestamp_en = CSID_CFG0_RDI_TIMESTAMP_EN;
+ }
val |= FIELD_PREP(CSID_CFG0_DT_MASK, format->data_type);
val |= FIELD_PREP(CSID_CFG0_VC_MASK, vc);
val |= FIELD_PREP(CSID_CFG0_DTID_MASK, dt_id);
if (enable)
- val |= CSID_CFG0_ENABLE;
+ val |= CSID_CFG0_ENABLE | timestamp_en;
dev_dbg(csid->camss->dev, "CSID%u: Stream %s (dt:0x%x df=0x%x port=%u vc=%u)\n",
csid->id, enable ? "enable" : "disable", format->data_type,
@@ -184,6 +197,21 @@ static int csid_reset(struct csid_device *csid)
return 0;
}
+static u64 csid_sof_ts(struct csid_device *csid, unsigned int id)
+{
+ enum csid_iface iface = csid_port_iface_map[id];
+ 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_TIMESTAMP_CURR0_SOF(iface));
+ hi = readl_relaxed(csid->base + CSID_TIMESTAMP_CURR1_SOF(iface));
+
+ return ((u64)hi << 32) | lo;
+}
+
static irqreturn_t csid_isr(int irq, void *dev)
{
struct csid_device *csid = dev;
@@ -233,6 +261,7 @@ const struct csid_hw_ops csid_ops_340 = {
.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
next prev parent reply other threads:[~2026-11-27 16:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:11 [PATCH v3 0/8] media: qcom: camss: " Loic Poulain
2026-11-27 16:11 ` [PATCH v3 1/8] media: qcom: camss: csid: Add an operation to read the " Loic Poulain
2026-11-27 16:11 ` Loic Poulain [this message]
2026-11-27 16:11 ` [PATCH v3 3/8] media: camss: Define timestamp registers for csid-gen2 Loic Poulain
2026-11-27 16:11 ` [PATCH v3 4/8] media: camss: csid-gen2: Report the hardware SOF timestamp Loic Poulain
2026-11-27 16:11 ` [PATCH v3 5/8] media: qcom: camss: csid-gen3: Fix the RDI timestamp controls on Titan 690 Loic Poulain
2026-11-27 16:11 ` [PATCH v3 6/8] media: qcom: camss: csid-gen3: Report the hardware SOF timestamp Loic Poulain
2026-11-27 16:11 ` [PATCH v3 7/8] media: qcom: camss: Timestamp buffers at start of frame Loic Poulain
2026-11-27 16:11 ` [PATCH v3 8/8] media: qcom: camss: Tell userspace we're using start-of-frame timestamps Loic Poulain
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=20261127-camss-hw-ts-v3-2-e4b6ad98ce9c@oss.qualcomm.com \
--to=loic.poulain@oss.qualcomm.com \
--cc=bryan.odonoghue@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=vladimir.zapolskiy@linaro.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®