mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 0/8] media: qcom: camss: Report the hardware SOF timestamp
Date: Fri, 27 Nov 2026 17:11:50 +0100	[thread overview]
Message-ID: <20261127-camss-hw-ts-v3-0-e4b6ad98ce9c@oss.qualcomm.com> (raw)

The CAMSS CSID latches the ARM architected counter on every start of
frame. This series uses that time to stamp the captured buffers.

V4L2 defines vb2_buf.timestamp as the time the first data byte was
captured, but CAMSS stamps buffers from the write master done interrupt,
once the frame has finished being written out to memory, which is about
a frame period late. The hardware value is free of interrupt latency and
is directly comparable with CLOCK_MONOTONIC, so it can be correlated
with other timestamped data such as IMU samples.

Patch 1 adds a CSID operation for reading the counter latched at SOF,
converts it to CLOCK_MONOTONIC once in the CSID core and keeps it for
the frame being captured. Patches 2 to 6 implement that operation on
csid-340, csid-gen2 and csid-gen3. Patch 7 uses it to stamp the buffers
and patch 8 reports the new source to userspace.

Patches 3 and 4 are picked from the timestamp support Bryan shared
earlier, with patch 4 adapted to the operation added in patch 1 rather
than doing its own conversion.

Tested on QCM2290 (Arduino UNO Q) with an IMX219 sensor. Over ~1030
consecutive frames at 60 fps, the jitter of the timestamp the CSID
computes, measured as the residual against a least-squares fit of the
frame cadence, against the interrupt time it replaces:

                        hardware SOF    interrupt time
      median                   43 ns            356 ns
      p95                     113 ns           1135 ns
      p99                     139 ns           4901 ns
      max                     181 ns          10680 ns
      rms                      60 ns           1123 ns
      cycle-to-cycle           72 ns           2658 ns

That is 19x tighter in rms and 59x in the worst case, and what is left
is essentially the 52 ns period of the 19.2 MHz counter the value comes
from.

Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
Changes in v3:
- Dropped the v4l2-event patch and with it the event timestamp. The
  series now only changes the buffer timestamp, and the SOF time is kept
  for the frame being captured rather than put in the frame sync event.
  Reporting it through V4L2_EVENT_FRAME_SYNC needs the core change and a
  decision on the raw-value field asked for in v2, so it comes
  separately.
- New patches 5 and 6: implement the SOF timestamp on csid-gen3. Titan
  690 moved the timestamp controls from RDI_CFG0 to RDI_CFG1, so patch 5
  picks the register per SoC before patch 6 reports the value.
- Patch 1: fall back to the interrupt time when the CSID has no usable
  clock snapshot, and keep the first SOF of a stream on that fallback -
  the register update arming the latch is only committed at the frame
  boundary that same SOF signals, so no counter value is captured there.
  As a result the stored timestamp is never 0 and needs no fallback of
  its own.
- Add measured jitter numbers to this cover letter.
- Link to v2: https://lore.kernel.org/r/20261125-camss-hw-ts-v2-0-24c955e43d75@oss.qualcomm.com

Changes in v2:
- Patch 2: read the latched counter through a new csid_hw_ops operation
  and do the conversion once in the CSID core, instead of passing the
  time into csid_sof_event() and open coding the register read in every
  CSI decoder (Bryan).
- New patch 7: report the timestamp source as V4L2_BUF_FLAG_TSTAMP_SRC_SOE
  on the SoCs that can track SOF, rather than leaving the queue
  advertising V4L2_BUF_FLAG_TSTAMP_SRC_EOF.
- Link to v1: https://lore.kernel.org/r/20261123-camss-hw-ts-v1-0-7b62dda6d7a9@oss.qualcomm.com

---
Bryan O'Donoghue (2):
      media: camss: Define timestamp registers for csid-gen2
      media: camss: csid-gen2: Report the hardware SOF timestamp

Loic Poulain (6):
      media: qcom: camss: csid: Add an operation to read the SOF timestamp
      media: qcom: camss: csid-340: Report the hardware SOF timestamp
      media: qcom: camss: csid-gen3: Fix the RDI timestamp controls on Titan 690
      media: qcom: camss: csid-gen3: Report the hardware SOF timestamp
      media: qcom: camss: Timestamp buffers at start of frame
      media: qcom: camss: Tell userspace we're using start-of-frame timestamps

 drivers/media/platform/qcom/camss/camss-csid-340.c |  37 ++++++-
 .../media/platform/qcom/camss/camss-csid-gen2.c    |  31 ++++++
 .../media/platform/qcom/camss/camss-csid-gen3.c    |  44 +++++++-
 drivers/media/platform/qcom/camss/camss-csid.c     | 112 ++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid.h     |  19 ++++
 drivers/media/platform/qcom/camss/camss-vfe-17x.c  |   7 +-
 drivers/media/platform/qcom/camss/camss-vfe.c      |   8 +-
 drivers/media/platform/qcom/camss/camss-vfe.h      |   1 +
 drivers/media/platform/qcom/camss/camss-video.c    |   2 +
 drivers/media/platform/qcom/camss/camss.c          |   6 ++
 drivers/media/platform/qcom/camss/camss.h          |   1 +
 11 files changed, 253 insertions(+), 15 deletions(-)
---
base-commit: 9bac1a31a7d2c1b9022913e52adffaff63c0784e
change-id: 20261123-camss-hw-ts-e0297adb69d9

Best regards,
-- 
Loic Poulain <loic.poulain@oss.qualcomm.com>


             reply	other threads:[~2026-11-27 16:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 16:11 Loic Poulain [this message]
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 ` [PATCH v3 2/8] media: qcom: camss: csid-340: Report the hardware " Loic Poulain
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-0-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®