Re: [PATCH v2 3/9] media: qcom: camss: Use SOF sequence tracking for vb.sequence
From: Loic Poulain
Date: Mon Nov 02 2026 - 10:58:56 EST
On Mon, Nov 2, 2026 at 2:57 PM <bryan.odonoghue@xxxxxxxxxx> wrote:
>
> From: Bryan O'Donoghue <bryan.odonoghue@xxxxxxxxxx>
>
> We want to correlate statistics buffers with data-buffers. To do that we
> will need to have a sequence number driven by the SOF signal.
>
> Rather than incrementing vb.sequence when data arrives, we should increment
> when SOF happens.
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@xxxxxxxxxx>
Reviewed-by: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>
> ---
> drivers/media/platform/qcom/camss/camss-csid.c | 14 ++++++++++++++
> drivers/media/platform/qcom/camss/camss-csid.h | 9 +++++++++
> drivers/media/platform/qcom/camss/camss-vfe-17x.c | 5 ++++-
> drivers/media/platform/qcom/camss/camss-vfe.c | 9 ++++++++-
> drivers/media/platform/qcom/camss/camss-vfe.h | 1 +
> 5 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
> index e9b399fcb9c7a..4f4ed4fa46aac 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss/camss-csid.c
> @@ -1355,6 +1355,20 @@ static int csid_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
> return v4l2_event_subscribe(fh, sub, 0, &csid_frame_sync_ops);
> }
>
> +atomic_t *csid_get_sof_seq(struct media_pad *pad)
> +{
> + struct csid_device *csid;
> +
> + if (!pad || pad->index < MSM_CSID_PAD_FIRST_SRC)
> + return NULL;
> +
> + csid = v4l2_get_subdevdata(media_entity_to_v4l2_subdev(pad->entity));
> + if (!csid->res->frame_sync_en)
> + return NULL;
> +
> + return &csid->sof_seq[pad->index - MSM_CSID_PAD_FIRST_SRC];
> +}
> +
> void csid_sof_event(struct csid_device *csid, unsigned int id)
> {
> struct v4l2_event event = {
> diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h
> index 2e48b08b93592..f3199579e3442 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.h
> +++ b/drivers/media/platform/qcom/camss/camss-csid.h
> @@ -260,4 +260,13 @@ u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
> */
> void csid_sof_event(struct csid_device *csid, unsigned int id);
>
> +/*
> + * csid_get_sof_seq - Get a pointer to the SOF frame sequence variable.
> + * @pad: Remote pad of a consumer's sink pad
> + *
> + * Return the counter or NULL if @pad isn't a CSID or the CSID doesn't support
> + * SOF tracking.
> + */
> +atomic_t *csid_get_sof_seq(struct media_pad *pad);
> +
> #endif /* QC_MSM_CAMSS_CSID_H */
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-17x.c b/drivers/media/platform/qcom/camss/camss-vfe-17x.c
> index 62c2405359a06..4972d3ab65078 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-17x.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-17x.c
> @@ -491,7 +491,10 @@ static void vfe_isr_wm_done(struct vfe_device *vfe, u8 wm)
> }
>
> ready_buf->vb.vb2_buf.timestamp = ts;
> - ready_buf->vb.sequence = output->sequence++;
> + if (line->sof_seq)
> + ready_buf->vb.sequence = atomic_read(line->sof_seq);
> + else
> + ready_buf->vb.sequence = output->sequence++;
>
> index = 0;
> output->buf[0] = output->buf[1];
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
> index 2680a9914765f..da373024c847e 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe.c
> @@ -474,7 +474,10 @@ void vfe_buf_done(struct vfe_device *vfe, int wm)
> }
>
> ready_buf->vb.vb2_buf.timestamp = ts;
> - ready_buf->vb.sequence = output->sequence++;
> + if (line->sof_seq)
> + ready_buf->vb.sequence = atomic_read(line->sof_seq);
> + else
> + ready_buf->vb.sequence = output->sequence++;
>
> index = 0;
> output->buf[0] = output->buf[1];
> @@ -508,6 +511,7 @@ int vfe_enable_output_v2(struct vfe_line *line)
> struct vfe_output *output = &line->output;
> const struct vfe_hw_ops *ops = vfe->res->hw_ops;
> struct media_pad *sensor_pad;
> + struct media_pad *csid_pad;
> unsigned long flags;
> unsigned int frame_skip = 0;
> unsigned int i;
> @@ -523,6 +527,9 @@ int vfe_enable_output_v2(struct vfe_line *line)
> frame_skip = VFE_FRAME_DROP_VAL - 1;
> }
>
> + csid_pad = media_pad_remote_pad_first(&line->pads[MSM_VFE_PAD_SINK]);
> + line->sof_seq = csid_get_sof_seq(csid_pad);
> +
> spin_lock_irqsave(&vfe->output_lock, flags);
>
> ops->reg_update_clear(vfe, line->id);
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe.h b/drivers/media/platform/qcom/camss/camss-vfe.h
> index ae9dad353a378..0e2dfa58421ad 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe.h
> +++ b/drivers/media/platform/qcom/camss/camss-vfe.h
> @@ -94,6 +94,7 @@ struct vfe_line {
> struct vfe_output output;
> const struct camss_format_info *formats;
> unsigned int nformats;
> + atomic_t *sof_seq;
> };
>
> struct vfe_device;
>
> --
> 2.56.0
>