Skip to contentSkip to conversation

Add SOF sequence logic

PATCH In review [email protected] 5 participants 21 messages Nov 7 – Nov 26

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v3 cover Add SOF sequence logic

v3:
- Added CSID-340 patches from Loic wit permission - Loic
- Explains the initial -1. - Loic
- Drops the .id field enumeration - Gjorgji
- Accumulates RB as indicated.
- Link to v2: https://patch.msgid.link/[email protected]

v2:
- Amends series title to drop EOF
- Drops EOF inclusion until we actually use it for stats production seq_no - Gjorgji, bod
- Moves QoS into pm_runtime() callbacks - Loic
- Switches on vb.sequence change for every SoC the silicon enabling code supports - bod, Loic
- Link to v1: https://patch.msgid.link/[email protected]

v1:

This series enables SOF AND EOF event tracking making use of both events. Whilst the code is actually very simple the functionality we want to build off of that simple code is not.

- SOF
Serves two functions. Firstly. Informing user-space of CSID SOF events. Standard Linux V4L2_EVENT_FRAME_SYNC is trigger from this event. User-space wants to capture this trigger because it allows user-space to better align the time a frame begins to events elsewhere such as IMU event timestamps.

That functionality is directly applicable in this series.

However we will also build on the SOF event in later patches to allow us to begin programming of shadow-registers for the next camera frame.

When the EOF event happens, we switch from one shadow bank to the next. This is only possible if you have the SOF event.

So SOF serves the immediate purpose of timestamp alignment in user-space as well as the 'evil plan' to trigger off of it programming camera parameters for the next frame.

- EOF
EOF even on its own is useful because it allows us to increment vb.sequence for each frame as per the spec not just when we have buffer-data.

There is another purpose to having an SOF and EOF event with sequence numbers and that is.

User-space submits a parameters buffer. Kernel accepts that parameters buffer but can make no guarantee about _when_ the entire buffer will be applied.

So when kernel finishes application of the entire params sequence the returned buffer contains the sequence number - from the EOF tracking which informs user-space _which_ frame vb.sequence its given params buffer was applied.

Similarly when kernel produces a statistics buffer that buffer will have a sequence number - and that sequence number will align to the frame sequence number that the statistics describe.

Thus SOF/EOF tracking is fundamental to passing parameters, returning statistics to user-space and for the IPA algorithm in user-space to understand which stats, params and frames are related.

The first patch in the series addresses a corner-case when a quiescent system can take quite a while to wake from idle, too long in fact such that the SOF event is effectively missed.

On 'normal' systems doing lots of things, this is not a problem we would see however on my test X1-CRD system running from ramdisk - there's basically nothing else happening and the wake-time becomes apparent.

This is not strictly speaking a bugfix since right now nothing in CAMSS cares about SOF or EOF so if we take an additional 2.5 ms to process a data-buffer on a fully quiescent system, that's not the end of the world.

OTOH as soon as you start to care about SOF/EOF then missing those events is no bueno.

The CPU latency value chosen is 100% stolen from IPU7 which seems like a good starting point - the stealing obviously - and happens to also work.

This series is really an enabling series for more work to come but even on its own is an improvement on the current situation.

---
Bryan O'Donoghue (9):
media: qcom: camss: Introduce CPU latency QoS during streaming
media: qcom: camss: Introduce SOF sequence tracking
media: qcom: camss: Use SOF sequence tracking for vb.sequence
media: qcom: camss: csid-gen3: Enable RDI SOF driving
media: qcom: camss: csid-680: Enable RDI SOF tracking
media: qcom: camss: csid-gen2: Enable RDI SOF tracking
media: qcom: camss: Switch on frame_sync_en logic for csid-gen3.
media: qcom: camss: Switch on frame_sync_en for x1e/x2e
media: qcom: camss: Switch on frame_sync_en for csid-gen2

Loic Poulain (2):
media: qcom: camss: csid-340: Enable RDI SOF tracking
media: qcom: camss: Switch on frame_sync_en for csid-340

 drivers/media/platform/qcom/camss/camss-csid-340.c | 39 ++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid-680.c | 18 ++++++
 .../media/platform/qcom/camss/camss-csid-gen2.c    | 15 +++++
 .../media/platform/qcom/camss/camss-csid-gen3.c    | 27 +++++++++
 drivers/media/platform/qcom/camss/camss-csid.c     | 68 +++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid.h     | 21 +++++++
 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 +
 drivers/media/platform/qcom/camss/camss.c          | 65 ++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss.h          |  2 +
 11 files changed, 265 insertions(+), 5 deletions(-)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261029-v4l2-frame-sync-0d6fb94ab6e6

Best regards,

Signature · 2 lines
---
bod
author maintainer
#1 lore raw

PATCH v3 1/11 media: qcom: camss: Introduce CPU latency QoS during streaming

From: Bryan O'Donoghue <[email protected]>

On a quiescent system - for example the X1 CRD booted to a simple ramdisk rootfs during development of V4L2_EVENT_FRAME_SYNC it was observed that interrupt for buffer done could be delayed until after the SOF for the next frame.

Fiddling about with the interrupt bits, clearing them and changing the logic of V4L2_EVENT_FRAME_SYNC to buffer completion didn't work and besides "felt wrong".

Tracing it looks like this:

<idle>-0       [000] d.h1.    36.374380: csid_isr: rdi0 sof=1 done=0
<idle>-0       [000] d.h1.    36.406601: csid_isr: rdi0 sof=1 done=1
<idle>-0       [000] d.h1.    36.439910: csid_isr: rdi0 sof=1 done=1
<idle>-0       [000] d.h1.    36.473245: csid_isr: rdi0 sof=1 done=1
<idle>-0       [000] d.h1.    36.504786: csid_isr: rdi0 sof=0 done=1
<idle>-0       [000] d.h1.    36.506350: csid_isr: rdi0 sof=1 done=0

Tracing with /dev/cpu_dma_latency = 0 looks like this:

<idle>-0       [000] d.h1.   556.149115: csid_isr: rdi0 sof=1 done=0
<idle>-0       [000] d.h1.   556.181338: csid_isr: rdi0 sof=0 done=1
<idle>-0       [000] d.h1.   556.182880: csid_isr: rdi0 sof=1 done=0
<idle>-0       [000] d.h1.   556.214643: csid_isr: rdi0 sof=0 done=1
<idle>-0       [000] d.h1.   556.216185: csid_isr: rdi0 sof=1 done=0

The second is the pattern you expect CSI SOF followed by data.

We will require SOF to track and understand which data-frame is correlated to which camera stastics and parameters frame. On an ordinary system with several things pinging off at once, WiFi, display, keyboard you will be unlikely to hit deep idle and hence unlikely to see the long exit. However we should design for the case where the system is otherwise quiescent with only the camera streaming.

Choosing a request of 300us - 1000us seemed to work fine but cutting the margin finer, similar to the value on IPU6.

---
 drivers/media/platform/qcom/camss/camss.c | 11 ++++++++++-
 drivers/media/platform/qcom/camss/camss.h |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss.c +10 -1
index c54185c93a8a9..52bb19f5fbf3b 100644
@@ -5834,6 +5834,8 @@ static const struct of_device_id camss_dt_match[] = {
 
 MODULE_DEVICE_TABLE(of, camss_dt_match);
 
+#define CAMSS_CPU_LATENCY_US	300
+
 static int __maybe_unused camss_runtime_suspend(struct device *dev)
 {
 	struct camss *camss = dev_get_drvdata(dev);
@@ -5846,6 +5848,8 @@ static int __maybe_unused camss_runtime_suspend(struct device *dev)
 			return ret;
 	}
 
+	cpu_latency_qos_remove_request(&camss->cpu_latency);
+
 #if IS_ENABLED(CONFIG_PM_CLK)
 	return pm_clk_suspend(dev);
 #else
@@ -5866,12 +5870,17 @@ static int __maybe_unused camss_runtime_resume(struct device *dev)
 		return ret;
 #endif
 
+	cpu_latency_qos_add_request(&camss->cpu_latency,
+				    CAMSS_CPU_LATENCY_US);
+
 	for (i = 0; i < camss->res->icc_path_num; i++) {
 		ret = icc_set_bw(camss->icc_path[i],
 				 icc_res[i].icc_bw_tbl.avg,
 				 icc_res[i].icc_bw_tbl.peak);
-		if (ret)
+		if (ret) {
+			cpu_latency_qos_remove_request(&camss->cpu_latency);
 			return ret;
+		}
 	}
 
 	return 0;
drivers/media/platform/qcom/camss/camss.h +2 -0
index 7dc2fd9f03e0d..7564a7c46fa24 100644
@@ -11,6 +11,7 @@
 #define QC_MSM_CAMSS_H
 
 #include <linux/device.h>
+#include <linux/pm_qos.h>
 #include <linux/types.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-device.h>
@@ -141,6 +142,7 @@ struct camss {
 	struct icc_path *icc_path[ICC_SM8250_COUNT];
 	const struct camss_resources *res;
 	bool legacy_phy;
+	struct pm_qos_request cpu_latency;
 };
 
 struct camss_camera_interface {
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH v3 2/11 media: qcom: camss: Introduce SOF sequence tracking

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

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.

---
 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(-)
drivers/media/platform/qcom/camss/camss-csid.c +53 -1
index a00791b00feb7..7f33fb81ca8cc 100644
@@ -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,10 @@ static int csid_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (csid->phy.need_vc_update) {
+		/* Set to -1 as we want to do atomic_inc_return to read */
+		for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
+			atomic_set(&csid->sof_seq[i], -1);
+
 		csid->res->hw_ops->configure_stream(csid, enable);
 		csid->phy.need_vc_update = false;
 	}
@@ -1316,9 +1321,56 @@ 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);
+
+	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);
+}
+
+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 (!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,
+		.u.frame_sync.frame_sequence =
+			atomic_inc_return(&csid->sof_seq[id]),
+	};
+
+	if (atomic_read(&csid->frame_sync_users))
+		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,
 };
 
drivers/media/platform/qcom/camss/camss-csid.h +12 -0
index 5296b10f6bac8..a9d88909d37fc 100644
@@ -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;
+	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 */
Signature · 1 line
2.56.0
author maintainer
#4 lore raw

PATCH v3 3/11 media: qcom: camss: Use SOF sequence tracking for vb.sequence

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

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.

---
 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(-)
drivers/media/platform/qcom/camss/camss-csid.c +14 -0
index 7f33fb81ca8cc..588122beec854 100644
@@ -1356,6 +1356,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 = {
drivers/media/platform/qcom/camss/camss-csid.h +9 -0
index a9d88909d37fc..8edb258b0ae58 100644
@@ -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 */
drivers/media/platform/qcom/camss/camss-vfe-17x.c +4 -1
index 62c2405359a06..4972d3ab65078 100644
@@ -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];
drivers/media/platform/qcom/camss/camss-vfe.c +8 -1
index 2680a9914765f..da373024c847e 100644
@@ -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);
drivers/media/platform/qcom/camss/camss-vfe.h +1 -0
index ae9dad353a378..0e2dfa58421ad 100644
@@ -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;
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH v3 4/11 media: qcom: camss: csid-gen3: Enable RDI SOF driving

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Add in silicon enabling code to generate SOF and trigger the routine which produces V4L2_EVENT_FRAME_SYNC based on SOF per standard v4l2 behaviour.

---
 .../media/platform/qcom/camss/camss-csid-gen3.c    | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/media/platform/qcom/camss/camss-csid-gen3.c +27 -0
index 0fdbf75fb27db..6a538d825f78b 100644
@@ -34,6 +34,7 @@
 #define		CSID_RUP_AUP_RDI(rdi)		((BIT(4) | BIT(20)) << (rdi))
 
 #define CSID_TOP_IRQ_STATUS		0x7C
+#define		TOP_IRQ_RDI(rdi)		BIT(8 + (rdi))
 #define		 TOP_IRQ_STATUS_RESET_DONE	BIT(0)
 
 #define CSID_TOP_IRQ_MASK		0x80
@@ -58,6 +59,9 @@
 #define CSID_CSI2_RDIN_IRQ_STATUS(rdi)	(0xEC + 0x10 * (rdi))
 #define		RUP_DONE_IRQ_STATUS		BIT(23)
 
+#define CSID_CSI2_RDIN_IRQ_MASK(rdi)	(0xF0 + 0x10 * (rdi))
+#define		INFO_INPUT_SOF_IRQ		BIT(12)
+
 #define CSID_CSI2_RDIN_IRQ_CLEAR(rdi)	(0xF4 + 0x10 * (rdi))
 #define CSID_CSI2_RDIN_IRQ_SET(rdi)	(0xF8 + 0x10 * (rdi))
 
@@ -219,6 +223,25 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8
 	writel(val, csid->base + CSID_RDI_CFG0(port));
 }
 
+static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi)
+{
+	u32 val = 0;
+
+	if (enable)
+		val = INFO_INPUT_SOF_IRQ;
+
+	writel(val, csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
+
+	val = readl(csid->base + CSID_TOP_IRQ_MASK);
+
+	if (enable)
+		val |= TOP_IRQ_RDI(rdi);
+	else
+		val &= ~TOP_IRQ_RDI(rdi);
+
+	writel(val, csid->base + CSID_TOP_IRQ_MASK);
+}
+
 static void csid_configure_stream(struct csid_device *csid, u8 enable)
 {
 	u8 i;
@@ -230,6 +253,7 @@ static void csid_configure_stream(struct csid_device *csid, u8 enable)
 		if (csid->phy.en_vc & BIT(i)) {
 			__csid_configure_rdi_stream(csid, enable, i, 0);
 			__csid_configure_rx(csid, &csid->phy, 0);
+			__csid_configure_rdi_irq(csid, enable, i);
 			__csid_ctrl_rdi(csid, enable, i);
 		}
 }
@@ -279,6 +303,9 @@ static irqreturn_t csid_isr(int irq, void *dev)
 			val = readl(csid->base + CSID_CSI2_RDIN_IRQ_STATUS(i));
 			writel(val, csid->base + CSID_CSI2_RDIN_IRQ_CLEAR(i));
 
+			if (val & INFO_INPUT_SOF_IRQ)
+				csid_sof_event(csid, i);
+
 			if (val & RUP_DONE_IRQ_STATUS)
 				/* clear the reg update bit */
 				csid_subdev_reg_update(csid, i, true);
Signature · 1 line
2.56.0
author maintainer
#8 lore raw

PATCH v3 5/11 media: qcom: camss: csid-680: Enable RDI SOF tracking

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Similarly to the sm8650 we can quite easily switch on V4L2_EVENT_FRAME_SYNC for x1e/x2e which uses csid-680.

Do so now.

---
 drivers/media/platform/qcom/camss/camss-csid-680.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/media/platform/qcom/camss/camss-csid-680.c +18 -0
index 345a67c8fb947..452640e72f6d5 100644
@@ -296,6 +296,20 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8
 	writel(val, csid->base + CSID_RDI_CFG0(port));
 }
 
+static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi)
+{
+	u32 val;
+
+	val = readl(csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
+
+	if (enable)
+		val |= CSID_CSI2_RDIN_INFO_INPUT_SOF;
+	else
+		val &= ~CSID_CSI2_RDIN_INFO_INPUT_SOF;
+
+	writel(val, csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
+}
+
 static void csid_configure_stream(struct csid_device *csid, u8 enable)
 {
 	int i;
@@ -307,6 +321,7 @@ static void csid_configure_stream(struct csid_device *csid, u8 enable)
 		if (csid->phy.en_vc & BIT(i)) {
 			__csid_configure_rdi_stream(csid, enable, i, 0);
 			__csid_configure_rx(csid, &csid->phy, 0);
+			__csid_configure_rdi_irq(csid, enable, i);
 			__csid_ctrl_rdi(csid, enable, i);
 		}
 	}
@@ -395,6 +410,9 @@ static irqreturn_t csid_isr(int irq, void *dev)
 		if (val)
 			writel(val, csid->base + CSID_CSI2_RDIN_IRQ_CLEAR(i));
 
+		if (val & CSID_CSI2_RDIN_INFO_INPUT_SOF)
+			csid_sof_event(csid, i);
+
 		if (val & CSID_CSI2_RDIN_RUP_DONE)
 			csid_rup_complete(csid, i);
 
Signature · 1 line
2.56.0
author maintainer
#9 lore raw

PATCH v3 6/11 media: qcom: camss: csid-gen2: Enable RDI SOF tracking

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Add silicon specific changes to get SOF triggering V4L2_EVENT_FRAME_SYNC 'gen2' CSID. Covers SDM845, SDM670, SM6150, SM6350, SC7280, SC8280XP, SM8250.

Tested thoroughly on sm8250 only for now. An additional patch is required in camss.c to enable this functionality on a per-SoC basis.

---
 drivers/media/platform/qcom/camss/camss-csid-gen2.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/media/platform/qcom/camss/camss-csid-gen2.c +15 -0
index eadcb2f7e3aaa..a351ac4b91728 100644
@@ -38,6 +38,8 @@
 #define CSID_CSI2_RDIN_IRQ_SET(rdi)		((csid_is_lite(csid) ? 0x3C : 0x4C) \
 						 + 0x10 * (rdi))
 
+#define		RDIN_IRQ_INFO_INPUT_SOF		BIT(12)
+
 #define CSID_TOP_IRQ_STATUS	0x70
 #define		TOP_IRQ_STATUS_RESET_DONE 0
 #define CSID_TOP_IRQ_MASK	0x74
@@ -322,6 +324,16 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8
 	writel_relaxed(val, csid->base + CSID_RDI_CFG0(port));
 }
 
+static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi)
+{
+	u32 val = 0;
+
+	if (enable)
+		val = RDIN_IRQ_INFO_INPUT_SOF;
+
+	writel_relaxed(val, csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
+}
+
 static void csid_configure_stream(struct csid_device *csid, u8 enable)
 {
 	struct csid_testgen_config *tg = &csid->testgen;
@@ -335,6 +347,7 @@ static void csid_configure_stream(struct csid_device *csid, u8 enable)
 
 			__csid_configure_rdi_stream(csid, enable, i, 0);
 			__csid_configure_rx(csid, &csid->phy, 0);
+			__csid_configure_rdi_irq(csid, enable, i);
 			__csid_ctrl_rdi(csid, enable, i);
 		}
 }
@@ -373,6 +386,8 @@ static irqreturn_t csid_isr(int irq, void *dev)
 		if (csid->phy.en_vc & BIT(i)) {
 			val = readl_relaxed(csid->base + CSID_CSI2_RDIN_IRQ_STATUS(i));
 			writel_relaxed(val, csid->base + CSID_CSI2_RDIN_IRQ_CLEAR(i));
+			if (val & RDIN_IRQ_INFO_INPUT_SOF)
+				csid_sof_event(csid, i);
 		}
 
 	val = 1 << IRQ_CMD_CLEAR;
Signature · 1 line
2.56.0
author maintainer
#10 lore raw

PATCH v3 7/11 media: qcom: camss: csid-340: Enable RDI SOF tracking

In reply to [email protected]

From: Loic Poulain <[email protected]>

Add silicon specific changes to get SOF triggering V4L2_EVENT_FRAME_SYNC on the '340' CSID. Covers QCM2290.

Unlike gen2 the 340 CSID has a per-interface IRQ block at 0x030 + 0x10 * iface, so the SOF mask and status have to be handled per interface rather than globally. Run the existing csid_port_iface_map[] through it so that PIX and RDI0-2 are all covered.

The spurious interrupt warning needs to account for the new per-interface status too, otherwise every SOF would be reported as spurious.

---
 drivers/media/platform/qcom/camss/camss-csid-340.c | 39 +++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-csid-340.c +38 -1
index eca3f07b8a8a2..42ff629ce410d 100644
@@ -22,6 +22,12 @@
 #define		CSID_RST_PHY_CLK			BIT(3)
 #define		CSID_RST_CSID_CLK			BIT(4)
 
+/* Per-interface IRQ block, indexed by enum csid_iface */
+#define CSID_IFACE_IRQ_STATUS(iface)				(0x030 + 0x10 * (iface))
+#define CSID_IFACE_IRQ_MASK(iface)				(0x034 + 0x10 * (iface))
+#define		CSID_IFACE_IRQ_INFO_INPUT_SOF		BIT(12)
+#define CSID_IFACE_IRQ_CLEAR(iface)				(0x038 + 0x10 * (iface))
+
 #define CSID_IRQ_STATUS						(0x070)
 #define CSID_IRQ_MASK						(0x074)
 #define		CSID_IRQ_MASK_RST_DONE			BIT(0)
@@ -83,6 +89,17 @@ static void __csid_configure_rx(struct csid_device *csid, struct csid_phy_config
 	writel_relaxed(val, csid->base + CSID_CSI2_RX_CFG1);
 }
 
+static void __csid_configure_iface_irq(struct csid_device *csid, u8 enable,
+				       enum csid_iface iface)
+{
+	u32 val = 0;
+
+	if (enable)
+		val = CSID_IFACE_IRQ_INFO_INPUT_SOF;
+
+	writel_relaxed(val, csid->base + CSID_IFACE_IRQ_MASK(iface));
+}
+
 static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 port, u8 vc)
 {
 	struct v4l2_mbus_framefmt *input_format = &csid->fmt[MSM_CSID_PAD_FIRST_SRC + port];
@@ -125,6 +142,7 @@ static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 port
 		format->decode_format, port, vc);
 
 	writel_relaxed(val, csid->base + CSID_CFG0(iface));
+	__csid_configure_iface_irq(csid, enable, iface);
 	writel_relaxed(enable, csid->base + CSID_CTRL(iface));
 }
 
@@ -169,15 +187,34 @@ static int csid_reset(struct csid_device *csid)
 static irqreturn_t csid_isr(int irq, void *dev)
 {
 	struct csid_device *csid = dev;
+	u32 iface_val = 0;
 	u32 val;
+	int i;
 
 	val = readl_relaxed(csid->base + CSID_IRQ_STATUS);
 	writel_relaxed(val, csid->base + CSID_IRQ_CLEAR);
+
+	/* Read and clear the IRQ status of each enabled interface */
+	for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) {
+		enum csid_iface iface = csid_port_iface_map[i];
+		u32 status;
+
+		if (!(csid->phy.en_vc & BIT(i)))
+			continue;
+
+		status = readl_relaxed(csid->base + CSID_IFACE_IRQ_STATUS(iface));
+		writel_relaxed(status, csid->base + CSID_IFACE_IRQ_CLEAR(iface));
+		iface_val |= status;
+
+		if (status & CSID_IFACE_IRQ_INFO_INPUT_SOF)
+			csid_sof_event(csid, i);
+	}
+
 	writel_relaxed(CSID_IRQ_CMD_CLEAR, csid->base + CSID_IRQ_CMD);
 
 	if (val & CSID_IRQ_MASK_RST_DONE)
 		complete(&csid->reset_complete);
-	else
+	else if (!iface_val)
 		dev_warn_ratelimited(csid->camss->dev, "Spurious CSID interrupt\n");
 
 	return IRQ_HANDLED;
Signature · 1 line
2.56.0
author maintainer
#12 lore raw

PATCH v3 8/11 media: qcom: camss: Switch on frame_sync_en logic for csid-gen3.

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

---
 drivers/media/platform/qcom/camss/camss.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/media/platform/qcom/camss/camss.c +17 -0
index 52bb19f5fbf3b..b7821019241d7 100644
@@ -3120,6 +3120,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3135,6 +3136,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3150,6 +3152,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3165,6 +3168,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
 		.reg = { "csid_lite0" },
 		.interrupt = { "csid_lite0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3180,6 +3184,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
 		.reg = { "csid_lite1" },
 		.interrupt = { "csid_lite1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3433,6 +3438,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
 			.formats = &csid_formats_gen2,
@@ -3447,6 +3453,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
 			.formats = &csid_formats_gen2,
@@ -3461,6 +3468,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
 			.formats = &csid_formats_gen2,
@@ -3476,6 +3484,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
 		.reg = { "csid_lite0" },
 		.interrupt = { "csid_lite0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3492,6 +3501,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
 		.reg = { "csid_lite1" },
 		.interrupt = { "csid_lite1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.hw_ops = &csid_ops_gen3,
@@ -3790,6 +3800,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3807,6 +3818,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3825,6 +3837,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid_lite0" },
 		.interrupt = { "csid_lite0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3842,6 +3855,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid_lite1" },
 		.interrupt = { "csid_lite1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3859,6 +3873,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid_lite2" },
 		.interrupt = { "csid_lite2" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3876,6 +3891,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid_lite3" },
 		.interrupt = { "csid_lite3" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -3893,6 +3909,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
 		.reg = { "csid_lite4" },
 		.interrupt = { "csid_lite4" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen3,
 			.parent_dev_ops = &vfe_parent_dev_ops,
Signature · 1 line
2.56.0
author maintainer
#15 lore raw

PATCH v3 9/11 media: qcom: camss: Switch on frame_sync_en for x1e/x2e

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

---
 drivers/media/platform/qcom/camss/camss.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/qcom/camss/camss.c +5 -0
index b7821019241d7..7911b30494ac9 100644
@@ -4255,6 +4255,7 @@ static const struct camss_subdev_resources csid_res_x1e80100[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_680,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -4275,6 +4276,7 @@ static const struct camss_subdev_resources csid_res_x1e80100[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_680,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -4295,6 +4297,7 @@ static const struct camss_subdev_resources csid_res_x1e80100[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_680,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -4316,6 +4319,7 @@ static const struct camss_subdev_resources csid_res_x1e80100[] = {
 		.interrupt = { "csid_lite0" },
 		.csid = {
 			.is_lite = true,
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_680,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -4338,6 +4342,7 @@ static const struct camss_subdev_resources csid_res_x1e80100[] = {
 		.interrupt = { "csid_lite1" },
 		.csid = {
 			.is_lite = true,
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_680,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
Signature · 1 line
2.56.0
author maintainer
#16 lore raw

PATCH v3 10/11 media: qcom: camss: Switch on frame_sync_en for csid-gen2

In reply to [email protected]

From: Bryan O'Donoghue <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

---
 drivers/media/platform/qcom/camss/camss.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/media/platform/qcom/camss/camss.c +30 -0
index 7911b30494ac9..bfff28e789b04 100644
@@ -1132,6 +1132,7 @@ static const struct camss_subdev_resources csid_res_670[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1151,6 +1152,7 @@ static const struct camss_subdev_resources csid_res_670[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1170,6 +1172,7 @@ static const struct camss_subdev_resources csid_res_670[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -1361,6 +1364,7 @@ static const struct camss_subdev_resources csid_res_845[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1389,6 +1393,7 @@ static const struct camss_subdev_resources csid_res_845[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1417,6 +1422,7 @@ static const struct camss_subdev_resources csid_res_845[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -1573,6 +1579,7 @@ static const struct camss_subdev_resources csid_res_sm6150[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -1588,6 +1595,7 @@ static const struct camss_subdev_resources csid_res_sm6150[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -1603,6 +1611,7 @@ static const struct camss_subdev_resources csid_res_sm6150[] = {
 		.reg = { "csid_lite" },
 		.interrupt = { "csid_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -1775,6 +1784,7 @@ static const struct camss_subdev_resources csid_res_sm6350[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1790,6 +1800,7 @@ static const struct camss_subdev_resources csid_res_sm6350[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1805,6 +1816,7 @@ static const struct camss_subdev_resources csid_res_sm6350[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -1820,6 +1832,7 @@ static const struct camss_subdev_resources csid_res_sm6350[] = {
 		.reg = { "csid_lite" },
 		.interrupt = { "csid_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2058,6 +2071,7 @@ static const struct camss_subdev_resources csid_res_8250[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2075,6 +2089,7 @@ static const struct camss_subdev_resources csid_res_8250[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2092,6 +2107,7 @@ static const struct camss_subdev_resources csid_res_8250[] = {
 		.interrupt = { "csid2" },
 		.csid = {
 			.is_lite = true,
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2109,6 +2125,7 @@ static const struct camss_subdev_resources csid_res_8250[] = {
 		.interrupt = { "csid3" },
 		.csid = {
 			.is_lite = true,
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2349,6 +2366,7 @@ static const struct camss_subdev_resources csid_res_7280[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2368,6 +2386,7 @@ static const struct camss_subdev_resources csid_res_7280[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2387,6 +2406,7 @@ static const struct camss_subdev_resources csid_res_7280[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = false,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2406,6 +2426,7 @@ static const struct camss_subdev_resources csid_res_7280[] = {
 		.reg = { "csid_lite0" },
 		.interrupt = { "csid_lite0" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2425,6 +2446,7 @@ static const struct camss_subdev_resources csid_res_7280[] = {
 		.reg = { "csid_lite1" },
 		.interrupt = { "csid_lite1" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2645,6 +2667,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2664,6 +2687,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2683,6 +2707,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid2" },
 		.interrupt = { "csid2" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2702,6 +2727,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid3" },
 		.interrupt = { "csid3" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -2720,6 +2746,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid0_lite" },
 		.interrupt = { "csid0_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2739,6 +2766,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid1_lite" },
 		.interrupt = { "csid1_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2758,6 +2786,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid2_lite" },
 		.interrupt = { "csid2_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
@@ -2777,6 +2806,7 @@ static const struct camss_subdev_resources csid_res_sc8280xp[] = {
 		.reg = { "csid3_lite" },
 		.interrupt = { "csid3_lite" },
 		.csid = {
+			.frame_sync_en = true,
 			.is_lite = true,
 			.hw_ops = &csid_ops_gen2,
 			.parent_dev_ops = &vfe_parent_dev_ops,
Signature · 1 line
2.56.0
author maintainer
#17 lore raw

PATCH v3 11/11 media: qcom: camss: Switch on frame_sync_en for csid-340

In reply to [email protected]

From: Loic Poulain <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

---
 drivers/media/platform/qcom/camss/camss.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/qcom/camss/camss.c +2 -0
index bfff28e789b04..ac12960264adf 100644
@@ -733,6 +733,7 @@ static const struct camss_subdev_resources csid_res_2290[] = {
 		.reg = { "csid0" },
 		.interrupt = { "csid0" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_340,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
@@ -749,6 +750,7 @@ static const struct camss_subdev_resources csid_res_2290[] = {
 		.reg = { "csid1" },
 		.interrupt = { "csid1" },
 		.csid = {
+			.frame_sync_en = true,
 			.hw_ops = &csid_ops_340,
 			.parent_dev_ops = &vfe_parent_dev_ops,
 			.formats = &csid_formats_gen2
Signature · 1 line
2.56.0
reviewer Reviewed-by on v3 2/11
#3 lore raw

Re: [PATCH v3 02/11] media: qcom: camss: Introduce SOF sequence tracking

In reply to [email protected]
Quoted 14 lines · On Sat, Nov 7, 2026 at 2:01 AM <[email protected]> wrote:

From: Bryan O'Donoghue <[email protected]>

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.

Quoted 4 lines

Subsequent patches will enable on a per-CSID basis.

Quoted 125 lines
---
 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(-)
drivers/media/platform/qcom/camss/camss-csid.c +53 -1
index a00791b00feb7..7f33fb81ca8cc 100644
@@ -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,10 @@ static int csid_set_stream(struct v4l2_subdev *sd, int enable)
        }
 
        if (csid->phy.need_vc_update) {
+               /* Set to -1 as we want to do atomic_inc_return to read */
+               for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
+                       atomic_set(&csid->sof_seq[i], -1);
+
                csid->res->hw_ops->configure_stream(csid, enable);
                csid->phy.need_vc_update = false;
        }
@@ -1316,9 +1321,56 @@ 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);
+
+       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);
+}
+
+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 (!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,
+               .u.frame_sync.frame_sequence =
+                       atomic_inc_return(&csid->sof_seq[id]),
+       };
+
+       if (atomic_read(&csid->frame_sync_users))
+               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,
 };
 
drivers/media/platform/qcom/camss/camss-csid.h +12 -1
index 5296b10f6bac8..a9d88909d37fc 100644
@@ -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;
+       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

reviewer
#5 lore raw

Re: [PATCH v3 03/11] media: qcom: camss: Use SOF sequence tracking for vb.sequence

In reply to [email protected]

Hi Bryan,

Quoted 25 lines · On Sat, Nov 7, 2026 at 2:02 AM <[email protected]> wrote:

From: Bryan O'Donoghue <[email protected]>

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.

---
 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(-)
drivers/media/platform/qcom/camss/camss-csid.c +0 -0
index 7f33fb81ca8cc..588122beec854 100644

drivers/media/platform/qcom/camss/camss-csid.c static int csid_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, · line 1359

Quoted 4 lines
drivers/media/platform/qcom/camss/camss-csid.c +1 -0
@@ -1356,6 +1356,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)

I would go with a const atomic_t * to preserve explicit ownership within the CSID.
This is also what atomic_read is using, so that should work.

Quoted 100 lines
drivers/media/platform/qcom/camss/camss-csid.c +13 -0
+{
+       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 = {
drivers/media/platform/qcom/camss/camss-csid.h +9 -0
index a9d88909d37fc..8edb258b0ae58 100644
@@ -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 */
drivers/media/platform/qcom/camss/camss-vfe-17x.c +4 -1
index 62c2405359a06..4972d3ab65078 100644
@@ -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];
drivers/media/platform/qcom/camss/camss-vfe.c +8 -1
index 2680a9914765f..da373024c847e 100644
@@ -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);
drivers/media/platform/qcom/camss/camss-vfe.h +1 -1
index ae9dad353a378..0e2dfa58421ad 100644
@@ -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

reviewer Reviewed-by on v3 8/11
#13 lore raw

Re: [PATCH v3 08/11] media: qcom: camss: Switch on frame_sync_en logic for csid-gen3.

In reply to [email protected]
Quoted 8 lines · On Sat, Nov 7, 2026 at 2:02 AM <[email protected]> wrote:

From: Bryan O'Donoghue <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

I would have preferred this to be defined directly in the corresponding CSID implementations rather than in the resource descriptors, so that the component implementing frame synchronization is also the one advertising support for it. In other words, something along the lines of a csid_hw_ops.features flag or a dedicated csid_hw_ops.has_frame_sync callback/field. That said, this is more of a design preference than a blocking concern for me, so:

Quoted 148 lines
---
 drivers/media/platform/qcom/camss/camss.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/media/platform/qcom/camss/camss.c +17 -1
index 52bb19f5fbf3b..b7821019241d7 100644
@@ -3120,6 +3120,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3135,6 +3136,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3150,6 +3152,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid2" },
                .interrupt = { "csid2" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3165,6 +3168,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3180,6 +3184,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3433,6 +3438,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3447,6 +3453,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3461,6 +3468,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid2" },
                .interrupt = { "csid2" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3476,6 +3484,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3492,6 +3501,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3790,6 +3800,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3807,6 +3818,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3825,6 +3837,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3842,6 +3855,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3859,6 +3873,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite2" },
                .interrupt = { "csid_lite2" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3876,6 +3891,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite3" },
                .interrupt = { "csid_lite3" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3893,6 +3909,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite4" },
                .interrupt = { "csid_lite4" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
 
--

2.56.0

maintainer Reviewed-by on v3 7/11
#11 lore raw

Re: [PATCH v3 07/11] media: qcom: camss: csid-340: Enable RDI SOF tracking

In reply to [email protected]
Quoted 10 lines · On 07/11/2026 01:01, [email protected] wrote:

From: Loic Poulain <[email protected]>

Add silicon specific changes to get SOF triggering V4L2_EVENT_FRAME_SYNC on the '340' CSID. Covers QCM2290.

Unlike gen2 the 340 CSID has a per-interface IRQ block at 0x030 + 0x10 * iface, so the SOF mask and status have to be handled per interface rather than globally. Run the existing csid_port_iface_map[] through it so that PIX and RDI0-2 are all covered.

Quoted 5 lines

The spurious interrupt warning needs to account for the new per-interface status too, otherwise every SOF would be reported as spurious.

maintainer Reviewed-by on v3 11/11
#18 lore raw

Re: [PATCH v3 11/11] media: qcom: camss: Switch on frame_sync_en for csid-340

In reply to [email protected]
Quoted 32 lines · On 07/11/2026 01:01, [email protected] wrote:

From: Loic Poulain <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

---
  drivers/media/platform/qcom/camss/camss.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/media/platform/qcom/camss/camss.c +2 -1
index bfff28e789b04..ac12960264adf 100644
@@ -733,6 +733,7 @@ static const struct camss_subdev_resources csid_res_2290[] = {
  		.reg = { "csid0" },
  		.interrupt = { "csid0" },
  		.csid = {
+			.frame_sync_en = true,
  			.hw_ops = &csid_ops_340,
  			.parent_dev_ops = &vfe_parent_dev_ops,
  			.formats = &csid_formats_gen2
@@ -749,6 +750,7 @@ static const struct camss_subdev_resources csid_res_2290[] = {
  		.reg = { "csid1" },
  		.interrupt = { "csid1" },
  		.csid = {
+			.frame_sync_en = true,
  			.hw_ops = &csid_ops_340,
  			.parent_dev_ops = &vfe_parent_dev_ops,
  			.formats = &csid_formats_gen2
 
--
Quoted 1 line

2.56.0

maintainer
#6 lore raw

Re: [PATCH v3 03/11] media: qcom: camss: Use SOF sequence tracking for vb.sequence

In reply to Loic Poulain
Quoted 4 lines · Loic Poulain
Quoted 1 line

+atomic_t *csid_get_sof_seq(struct media_pad *pad)

I would go with a const atomic_t * to preserve explicit ownership within the CSID.
This is also what atomic_read is using, so that should work.

I'll amend on application.

---
bod

Tested-by on the v3 series
#19 lore raw
In reply to [email protected]

Hi Bryan,

The whole series were verified on RB8 board (SA8775P).

~Gjorgji

Quoted 123 lines · On 11/7/2026 3:01 AM, [email protected] wrote:

v3:
- Added CSID-340 patches from Loic wit permission - Loic
- Explains the initial -1. - Loic
- Drops the .id field enumeration - Gjorgji
- Accumulates RB as indicated.
- Link to v2: https://patch.msgid.link/[email protected]

v2:
- Amends series title to drop EOF
- Drops EOF inclusion until we actually use it for stats production seq_no - Gjorgji, bod
- Moves QoS into pm_runtime() callbacks - Loic
- Switches on vb.sequence change for every SoC the silicon enabling code supports - bod, Loic
- Link to v1: https://patch.msgid.link/[email protected]

v1:

This series enables SOF AND EOF event tracking making use of both events. Whilst the code is actually very simple the functionality we want to build off of that simple code is not.

- SOF
Serves two functions. Firstly. Informing user-space of CSID SOF events. Standard Linux V4L2_EVENT_FRAME_SYNC is trigger from this event. User-space wants to capture this trigger because it allows user-space to better align the time a frame begins to events elsewhere such as IMU event timestamps.

That functionality is directly applicable in this series.

However we will also build on the SOF event in later patches to allow us to begin programming of shadow-registers for the next camera frame.

When the EOF event happens, we switch from one shadow bank to the next. This is only possible if you have the SOF event.

So SOF serves the immediate purpose of timestamp alignment in user-space as well as the 'evil plan' to trigger off of it programming camera parameters for the next frame.

- EOF
EOF even on its own is useful because it allows us to increment vb.sequence for each frame as per the spec not just when we have buffer-data.

There is another purpose to having an SOF and EOF event with sequence numbers and that is.

User-space submits a parameters buffer. Kernel accepts that parameters buffer but can make no guarantee about _when_ the entire buffer will be applied.

So when kernel finishes application of the entire params sequence the returned buffer contains the sequence number - from the EOF tracking which informs user-space _which_ frame vb.sequence its given params buffer was applied.

Similarly when kernel produces a statistics buffer that buffer will have a sequence number - and that sequence number will align to the frame sequence number that the statistics describe.

Thus SOF/EOF tracking is fundamental to passing parameters, returning statistics to user-space and for the IPA algorithm in user-space to understand which stats, params and frames are related.

The first patch in the series addresses a corner-case when a quiescent system can take quite a while to wake from idle, too long in fact such that the SOF event is effectively missed.

On 'normal' systems doing lots of things, this is not a problem we would see however on my test X1-CRD system running from ramdisk - there's basically nothing else happening and the wake-time becomes apparent.

This is not strictly speaking a bugfix since right now nothing in CAMSS cares about SOF or EOF so if we take an additional 2.5 ms to process a data-buffer on a fully quiescent system, that's not the end of the world.

OTOH as soon as you start to care about SOF/EOF then missing those events is no bueno.

The CPU latency value chosen is 100% stolen from IPU7 which seems like a good starting point - the stealing obviously - and happens to also work.

This series is really an enabling series for more work to come but even on its own is an improvement on the current situation.

---
Bryan O'Donoghue (9):
media: qcom: camss: Introduce CPU latency QoS during streaming
media: qcom: camss: Introduce SOF sequence tracking
media: qcom: camss: Use SOF sequence tracking for vb.sequence
media: qcom: camss: csid-gen3: Enable RDI SOF driving
media: qcom: camss: csid-680: Enable RDI SOF tracking
media: qcom: camss: csid-gen2: Enable RDI SOF tracking
media: qcom: camss: Switch on frame_sync_en logic for csid-gen3.
media: qcom: camss: Switch on frame_sync_en for x1e/x2e
media: qcom: camss: Switch on frame_sync_en for csid-gen2

Loic Poulain (2):
media: qcom: camss: csid-340: Enable RDI SOF tracking
media: qcom: camss: Switch on frame_sync_en for csid-340

 drivers/media/platform/qcom/camss/camss-csid-340.c | 39 ++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid-680.c | 18 ++++++
 .../media/platform/qcom/camss/camss-csid-gen2.c    | 15 +++++
 .../media/platform/qcom/camss/camss-csid-gen3.c    | 27 +++++++++
 drivers/media/platform/qcom/camss/camss-csid.c     | 68 +++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss-csid.h     | 21 +++++++
 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 +
 drivers/media/platform/qcom/camss/camss.c          | 65 ++++++++++++++++++++-
 drivers/media/platform/qcom/camss/camss.h          |  2 +
 11 files changed, 265 insertions(+), 5 deletions(-)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261029-v4l2-frame-sync-0d6fb94ab6e6

Best regards,

Signature · 2 lines
---
bod
#14 lore raw

Re: [PATCH v3 08/11] media: qcom: camss: Switch on frame_sync_en logic for csid-gen3.

In reply to Loic Poulain

Hi Loic, Bryan,

Quoted 10 lines · Loic Poulain
Quoted 8 lines · On Sat, Nov 7, 2026 at 2:02 AM <[email protected]> wrote:

From: Bryan O'Donoghue <[email protected]>

Switch frame_sync_en to true to track and consume SOF/EOF data.

Quoted 7 lines

I would have preferred this to be defined directly in the corresponding CSID implementations rather than in the resource descriptors, so that the component implementing frame synchronization is also the one advertising support for it. In other words, something along the lines of a csid_hw_ops.features flag or a dedicated csid_hw_ops.has_frame_sync callback/field. That said, this is more of a design preference than a blocking concern for me, so:

I double that. It make more sense to introduce capability field, only drawback is that as of today once the feature is validated for the SoC (which may contain same csid or vfe version) is marked as supported which may not be the case with caps, however the risk of breaking something is low.
Note that in multistream support we are introducing new field per SoC stream api which also can be taken based on the caps.

~Gjorgji

Quoted 152 lines
Quoted 148 lines
---
 drivers/media/platform/qcom/camss/camss.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/media/platform/qcom/camss/camss.c +17 -1
index 52bb19f5fbf3b..b7821019241d7 100644
@@ -3120,6 +3120,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3135,6 +3136,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3150,6 +3152,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid2" },
                .interrupt = { "csid2" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3165,6 +3168,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3180,6 +3184,7 @@ static const struct camss_subdev_resources csid_res_8550[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3433,6 +3438,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3447,6 +3453,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3461,6 +3468,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid2" },
                .interrupt = { "csid2" },
                .csid = {
+                       .frame_sync_en = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
                        .formats = &csid_formats_gen2,
@@ -3476,6 +3484,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3492,6 +3501,7 @@ static const struct camss_subdev_resources csid_res_sm8650[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .parent_dev_ops = &vfe_parent_dev_ops,
                        .hw_ops = &csid_ops_gen3,
@@ -3790,6 +3800,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid0" },
                .interrupt = { "csid0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3807,6 +3818,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid1" },
                .interrupt = { "csid1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = false,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3825,6 +3837,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite0" },
                .interrupt = { "csid_lite0" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3842,6 +3855,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite1" },
                .interrupt = { "csid_lite1" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3859,6 +3873,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite2" },
                .interrupt = { "csid_lite2" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3876,6 +3891,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite3" },
                .interrupt = { "csid_lite3" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
@@ -3893,6 +3909,7 @@ static const struct camss_subdev_resources csid_res_8775p[] = {
                .reg = { "csid_lite4" },
                .interrupt = { "csid_lite4" },
                .csid = {
+                       .frame_sync_en = true,
                        .is_lite = true,
                        .hw_ops = &csid_ops_gen3,
                        .parent_dev_ops = &vfe_parent_dev_ops,
 
--

2.56.0