mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bryan.odonoghue@linaro.org
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	 Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>,
	 Loic Poulain <loic.poulain@oss.qualcomm.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Bryan O'Donoghue <bod@kernel.org>
Subject: [PATCH 03/14] media: qcom: camss: Introduce SOF sequence tracking
Date: Thu, 29 Oct 2026 09:55:12 +0000	[thread overview]
Message-ID: <20261029-v4l2-frame-sync-v1-3-d37992559c58@kernel.org> (raw)
In-Reply-To: <20261029-v4l2-frame-sync-v1-0-d37992559c58@kernel.org>

From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

In order to communicate to user-space CSI2 SOF events we will need to hook
into and control v4l2_ctrl_subdev_subscribe_event. In-line with other
implementations of FRAME_SYNC have CSI decoders which support the event
always generate it in our case if and only if an atomic user count
indicates it should be so.

A flag in the CSID descriptor indicates if frame_sync_en is supported so
for each SoC that supports it this flag should be true. Since bool is false
by default no negative enumeration of existing or in-flight CSID is
required.

Subsequent patches will enable on a per-CSID basis.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/media/platform/qcom/camss/camss-csid.c | 54 +++++++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid.h | 12 ++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
index a00791b00feb7..2f1426e77e87c 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -760,6 +760,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
 static int csid_set_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct csid_device *csid = v4l2_get_subdevdata(sd);
+	unsigned int i;
 	int ret;
 
 	if (enable) {
@@ -778,6 +779,9 @@ static int csid_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (csid->phy.need_vc_update) {
+		for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
+			atomic_set(&csid->sof_seq[i], 0);
+
 		csid->res->hw_ops->configure_stream(csid, enable);
 		csid->phy.need_vc_update = false;
 	}
@@ -1316,9 +1320,57 @@ static int csid_link_setup(struct media_entity *entity,
 	return 0;
 }
 
+static int csid_frame_sync_add(struct v4l2_subscribed_event *sev, unsigned int elems)
+{
+	struct csid_device *csid = v4l2_get_subdevdata(vdev_to_v4l2_subdev(sev->fh->vdev));
+
+	atomic_inc(&csid->frame_sync_users[sev->id]);
+
+	return 0;
+}
+
+static void csid_frame_sync_del(struct v4l2_subscribed_event *sev)
+{
+	struct csid_device *csid = v4l2_get_subdevdata(vdev_to_v4l2_subdev(sev->fh->vdev));
+
+	atomic_dec(&csid->frame_sync_users[sev->id]);
+}
+
+static const struct v4l2_subscribed_event_ops csid_frame_sync_ops = {
+	.add = csid_frame_sync_add,
+	.del = csid_frame_sync_del,
+};
+
+static int csid_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
+				struct v4l2_event_subscription *sub)
+{
+	struct csid_device *csid = v4l2_get_subdevdata(sd);
+
+	if (sub->type != V4L2_EVENT_FRAME_SYNC)
+		return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub);
+
+	if (sub->id >= MSM_CSID_MAX_SRC_STREAMS || !csid->res->frame_sync_en)
+		return -EINVAL;
+
+	return v4l2_event_subscribe(fh, sub, 0, &csid_frame_sync_ops);
+}
+
+void csid_sof_event(struct csid_device *csid, unsigned int id)
+{
+	struct v4l2_event event = {
+		.type = V4L2_EVENT_FRAME_SYNC,
+		.id = id,
+		.u.frame_sync.frame_sequence =
+			atomic_fetch_inc(&csid->sof_seq[id]),
+	};
+
+	if (atomic_read(&csid->frame_sync_users[id]))
+		v4l2_event_queue(csid->subdev.devnode, &event);
+}
+
 static const struct v4l2_subdev_core_ops csid_core_ops = {
 	.s_power = csid_set_power,
-	.subscribe_event = v4l2_ctrl_subdev_subscribe_event,
+	.subscribe_event = csid_subscribe_event,
 	.unsubscribe_event = v4l2_event_subdev_unsubscribe,
 };
 
diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h
index 5296b10f6bac8..2e48b08b93592 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.h
+++ b/drivers/media/platform/qcom/camss/camss-csid.h
@@ -141,6 +141,7 @@ struct csid_hw_ops {
 
 struct csid_subdev_resources {
 	bool is_lite;
+	bool frame_sync_en;
 	const struct csid_hw_ops *hw_ops;
 	const struct parent_dev_ops *parent_dev_ops;
 	const struct csid_formats *formats;
@@ -167,6 +168,8 @@ struct csid_device {
 	struct v4l2_ctrl_handler ctrls;
 	struct v4l2_ctrl *testgen_mode;
 	const struct csid_subdev_resources *res;
+	atomic_t frame_sync_users[MSM_CSID_MAX_SRC_STREAMS];
+	atomic_t sof_seq[MSM_CSID_MAX_SRC_STREAMS];
 };
 
 struct camss_subdev_resources;
@@ -248,4 +251,13 @@ u32 csid_hw_version(struct csid_device *csid);
 u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
 		      unsigned int match_format_idx, u32 match_code);
 
+/*
+ * csid_sof_event - Track SOF generate V4L2_EVENT_FRAME_SYNC
+ * @csid: CSID device
+ * @id: CSID src-stream ID
+ *
+ *  Called from the CSID interrupt handler on SOF of the path driving the event.
+ */
+void csid_sof_event(struct csid_device *csid, unsigned int id);
+
 #endif /* QC_MSM_CAMSS_CSID_H */

-- 
2.56.0


  parent reply	other threads:[~2026-10-29  9:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  9:55 [PATCH 00/14] Add SOF/EOF sequence logic bryan.odonoghue
2026-10-29  9:55 ` [PATCH 01/14] media: qcom: camss: Introduce CPU latency QoS during streaming bryan.odonoghue
2026-10-29 10:10   ` Loic Poulain
2026-10-29 11:03     ` Bryan O'Donoghue
2026-10-29  9:55 ` [PATCH 02/14] media: qcom: camss: vfe: Add eof_seq to vfe_line bryan.odonoghue
2026-10-29  9:55 ` bryan.odonoghue [this message]
2026-10-29  9:55 ` [PATCH 04/14] media: qcom: camss: Introduce EOF sequence tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 05/14] media: qcom: camss: csid-gen3: Enable RDI SOF driving bryan.odonoghue
2026-10-29 15:43   ` Loic Poulain
2026-10-29 15:46     ` Loic Poulain
2026-10-29 15:49       ` Bryan O'Donoghue
2026-10-29 16:25         ` Gjorgji Rosikopulos (Consultant)
2026-10-29 16:36           ` Loic Poulain
2026-10-29 15:47     ` Bryan O'Donoghue
2026-10-29  9:55 ` [PATCH 06/14] media: qcom: camss: csid-gen3: Enable RDI EOF tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 07/14] media: qcom: camss: csid-680: Enable RDI SOF tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 08/14] media: qcom: camss: csid-680: Enable RDI EOF tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 09/14] media: qcom: camss: csid-gen2: Enable RDI SOF tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 10/14] media: qcom: camss: csid-gen2: Enable RDI EOF tracking bryan.odonoghue
2026-10-29  9:55 ` [PATCH 11/14] media: qcom: camss: Switch on frame_sync_en logic for sm8650 bryan.odonoghue
2026-10-29  9:55 ` [PATCH 12/14] media: qcom: camss: Switch on frame_sync_en for x1e/x2e bryan.odonoghue
2026-10-29  9:55 ` [PATCH 13/14] media: qcom: camss: Switch on frame_sync_en for sm8250 bryan.odonoghue
2026-10-29  9:55 ` [PATCH 14/14] media: qcom: camss: Switch on frame_sync_en for sdm845 bryan.odonoghue
2026-10-29 13:28 ` [PATCH 00/14] Add SOF/EOF sequence logic Gjorgji Rosikopulos (Consultant)
2026-10-29 14:44   ` Bryan O'Donoghue
2026-10-29 14:51     ` Gjorgji Rosikopulos (Consultant)

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=20261029-v4l2-frame-sync-v1-3-d37992559c58@kernel.org \
    --to=bryan.odonoghue@linaro.org \
    --cc=bod@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --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®