Re: [PATCH v4 10/14] media: qcom: camss: csid: Let a consumer hook into the frame start
From: Gjorgji Rosikopulos (Consultant)
Date: Fri Dec 04 2026 - 08:18:59 EST
Hi Loic,
On 12/3/2026 6:53 PM, Loic Poulain wrote:
> The CSID publishes what it knows about a frame start and leaves a
> consumer to read it whenever it next needs it. That is too late. By the
> time the VFE handles a buffer done, the published state may already
> describe a later frame, so neither the timestamp nor the sequence number
> can be attributed to the buffer the VFE is completing. With two frames
> in flight,
>
> SOF_0 BUF_DONE_0 SOF_1 SOF_2 BUF_DONE_1 BUF_DONE_2
>
> BUF_DONE_1 reads back what SOF_2 published, and the two buffers end up
> carrying the same timestamp and the same sequence number.
>
> Add an optional callback, invoked from the CSID interrupt handler once
> the SOF state describes the frame that just started, so a consumer can
> act while that frame is still the one being captured. Nobody registers
> one yet.
Just to add i am not in favor to this kind of notifications. Apart from
that it is called from IRQ. So i think is better to have a flag and call
directly the function you need.
>
> Signed-off-by: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>
> ---
> drivers/media/platform/qcom/camss/camss-csid.c | 15 +++++++++++++++
> drivers/media/platform/qcom/camss/camss-csid.h | 17 +++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
> index fd53e854454a6fc9d7cbe0c946a852a6f009cab3..b237eb6a47c59626f33ed8342104b333dff98e44 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss/camss-csid.c
> @@ -1400,6 +1400,14 @@ struct csid_sof *csid_get_sof(struct media_pad *pad)
> return &csid->sof[csid_pad_to_port(pad->index)];
> }
>
> +void csid_set_sof_notify(struct csid_sof *sof, void (*notify)(void *priv), void *priv)
> +{
> + if (notify)
> + sof->priv = priv;
> +
> + WRITE_ONCE(sof->notify, notify);
> +}
> +
> static u64 csid_timestamp_to_ns(u64 ticks)
> {
> return mul_u64_u32_div(ticks, CSID_TIMESTAMP_NS_MUL, CSID_TIMESTAMP_NS_DIV);
> @@ -1488,6 +1496,7 @@ void csid_sof_event(struct csid_device *csid, unsigned int id)
> {
> /* Read before the sequence number below, which arms the first SOF */
> u64 ts = csid_hw_sof_ts(csid, id);
> + void (*notify)(void *priv);
> struct v4l2_event event = {
> .type = V4L2_EVENT_FRAME_SYNC,
> .u.frame_sync.frame_sequence =
> @@ -1496,6 +1505,12 @@ void csid_sof_event(struct csid_device *csid, unsigned int id)
>
> atomic64_set(&csid->sof[id].ts, ts);
>
> + /* Internal notification */
> + notify = READ_ONCE(csid->sof[id].notify);
> + if (notify)
> + notify(csid->sof[id].priv);
> +
> + /* User notification */
> if (atomic_read(&csid->frame_sync_users))
> v4l2_event_queue(csid->subdev.devnode, &event);
> }
> diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h
> index 4925ea714aa74081a2b602f08696734b1087babb..53c82b0546cde02b07ffc6f841ff02b8088e3d9a 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.h
> +++ b/drivers/media/platform/qcom/camss/camss-csid.h
> @@ -168,10 +168,14 @@ struct csid_subdev_resources {
> * struct csid_sof - What the CSID tracks at start of frame, per src stream
> * @seq: Frame sequence number, -1 until the first SOF of the stream
> * @ts: CLOCK_MONOTONIC time of the frame start, 0 until the first SOF
> + * @notify: Consumer to tell about a frame start, NULL if nobody asked
> + * @priv: Handed to @notify
> */
> struct csid_sof {
> atomic_t seq;
> atomic64_t ts;
> + void (*notify)(void *priv);
> + void *priv;
> };
Just to add i am not in favor to this kind of notifications. Apart from
that it is called from IRQ. So i think is better to have a flag and call
directly the function you need.
~Gjorgji
>
> struct csid_device {
> @@ -298,4 +302,17 @@ void csid_sof_event(struct csid_device *csid, unsigned int id);
> */
> struct csid_sof *csid_get_sof(struct media_pad *pad);
>
> +/*
> + * csid_set_sof_notify - Ask to be told about every start of frame
> + * @sof: SOF state of a CSID source stream, as returned by csid_get_sof()
> + * @notify: Called from the CSID interrupt handler with @sof already describing
> + * the frame that started, or NULL to stop being called
> + * @priv: Handed to @notify
> + *
> + * Unregistering does not wait for a call already in progress, so @notify has to
> + * cope with running once the consumer has started tearing its stream down.
> + */
> +void csid_set_sof_notify(struct csid_sof *sof, void (*notify)(void *priv),
> + void *priv);
> +
> #endif /* QC_MSM_CAMSS_CSID_H */
>