* [PATCH RESEND v2 01/12] media: qcom: camss: csid_gen3: Fix multi-VC buf-done IRQ mask
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 02/12] media: qcom: camss: Add csid pad to port helper Gjorgji Rosikopulos
` (10 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Csid reset programs CSID_BUF_DONE_IRQ_MASK with a separate write
per enabled VC instead of accumulating the bits.
This change removes the not needed for cycle and write regs
in one pass.
Confirmed on RB8/SA8775P hardware during TPG multi-VC capture
testing.
Fixes: d96fe1808dcc ("media: qcom: camss: Add CSID 780 support")
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../media/platform/qcom/camss/camss-csid-gen3.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen3.c b/drivers/media/platform/qcom/camss/camss-csid-gen3.c
index 6a538d825f78..231b53d3e44e 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-gen3.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-gen3.c
@@ -339,7 +339,6 @@ static int csid_reset(struct csid_device *csid)
{
unsigned long time;
u32 val;
- int i;
reinit_completion(&csid->reset_complete);
@@ -347,14 +346,14 @@ static int csid_reset(struct csid_device *csid)
writel(1, csid->base + CSID_IRQ_CMD);
writel(1, csid->base + CSID_TOP_IRQ_MASK);
- for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
- if (csid->phy.en_vc & BIT(i)) {
- writel(BIT(BUF_DONE_IRQ_STATUS_RDI_OFFSET + i),
- csid->base + CSID_BUF_DONE_IRQ_CLEAR);
- writel(IRQ_CMD_CLEAR, csid->base + CSID_IRQ_CMD);
- writel(BIT(BUF_DONE_IRQ_STATUS_RDI_OFFSET + i),
- csid->base + CSID_BUF_DONE_IRQ_MASK);
- }
+ if (csid->phy.en_vc) {
+ u32 vc_mask = GENMASK(MSM_CSID_MAX_SRC_STREAMS - 1, 0);
+
+ val = (csid->phy.en_vc & vc_mask) << BUF_DONE_IRQ_STATUS_RDI_OFFSET;
+ writel(val, csid->base + CSID_BUF_DONE_IRQ_CLEAR);
+ writel(IRQ_CMD_CLEAR, csid->base + CSID_IRQ_CMD);
+ writel(val, csid->base + CSID_BUF_DONE_IRQ_MASK);
+ }
/* preserve registers */
val = RST_LOCATION | RST_MODE;
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 02/12] media: qcom: camss: Add csid pad to port helper
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 01/12] media: qcom: camss: csid_gen3: Fix multi-VC buf-done IRQ mask Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 03/12] media: qcom: camss: Add streams enable field to camss resources Gjorgji Rosikopulos
` (9 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
The function to convert a source pad number to its port
index, and use it in csid_get_sof_seq instead of the inline
subtraction.
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss-csid.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
index 588122beec85..0f819c34e760 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -1356,6 +1356,17 @@ static int csid_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
return v4l2_event_subscribe(fh, sub, 0, &csid_frame_sync_ops);
}
+/*
+ * csid_pad_to_port - Convert a CSID source pad number to its port index
+ * @pad: Source pad number (MSM_CSID_PAD_FIRST_SRC or greater)
+ *
+ * Return the zero-based port index corresponding to @pad
+ */
+static inline unsigned int csid_pad_to_port(u32 pad)
+{
+ return pad - MSM_CSID_PAD_FIRST_SRC;
+}
+
atomic_t *csid_get_sof_seq(struct media_pad *pad)
{
struct csid_device *csid;
@@ -1367,7 +1378,7 @@ atomic_t *csid_get_sof_seq(struct media_pad *pad)
if (!csid->res->frame_sync_en)
return NULL;
- return &csid->sof_seq[pad->index - MSM_CSID_PAD_FIRST_SRC];
+ return &csid->sof_seq[csid_pad_to_port(pad->index)];
}
void csid_sof_event(struct csid_device *csid, unsigned int id)
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 03/12] media: qcom: camss: Add streams enable field to camss resources
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 01/12] media: qcom: camss: csid_gen3: Fix multi-VC buf-done IRQ mask Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 02/12] media: qcom: camss: Add csid pad to port helper Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-12-03 16:01 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 18:23 ` [PATCH RESEND v2 04/12] media: qcom: camss: Add streams API support for CSIPHY Gjorgji Rosikopulos
` (8 subsequent siblings)
11 siblings, 1 reply; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Add a per-SoC streams_enable field to struct camss_resources, used by
subsequent subdevices to select between the legacy s_stream()-based
pipeline and the V4L2 subdev streams API.
Suggested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/platform/qcom/camss/camss.h
index 7564a7c46fa2..621ea2e3eba1 100644
--- a/drivers/media/platform/qcom/camss/camss.h
+++ b/drivers/media/platform/qcom/camss/camss.h
@@ -121,6 +121,7 @@ struct camss_resources {
const unsigned int tpg_num;
const unsigned int csid_num;
const unsigned int vfe_num;
+ const bool streams_enable;
};
struct camss {
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH RESEND v2 03/12] media: qcom: camss: Add streams enable field to camss resources
2026-11-25 18:23 ` [PATCH RESEND v2 03/12] media: qcom: camss: Add streams enable field to camss resources Gjorgji Rosikopulos
@ 2026-12-03 16:01 ` Gjorgji Rosikopulos (Consultant)
0 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos (Consultant) @ 2026-12-03 16:01 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala
On 11/25/2026 8:23 PM, Gjorgji Rosikopulos wrote:
> Add a per-SoC streams_enable field to struct camss_resources, used by
> subsequent subdevices to select between the legacy s_stream()-based
> pipeline and the V4L2 subdev streams API.
>
> Suggested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
> ---
> drivers/media/platform/qcom/camss/camss.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/platform/qcom/camss/camss.h
> index 7564a7c46fa2..621ea2e3eba1 100644
> --- a/drivers/media/platform/qcom/camss/camss.h
> +++ b/drivers/media/platform/qcom/camss/camss.h
> @@ -121,6 +121,7 @@ struct camss_resources {
> const unsigned int tpg_num;
> const unsigned int csid_num;
> const unsigned int vfe_num;
> + const bool streams_enable;
During the internal discussion we have decided to use stream_api by default.
This means that no need of additional flag.
The v4l2 is backward compatible so everything should work as expected.
We will need to test on all platforms we can test and most probably
ask for the community members with old available boards to verify this patchet.
~Gjorgji
> };
>
> struct camss {
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH RESEND v2 04/12] media: qcom: camss: Add streams API support for CSIPHY
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (2 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 03/12] media: qcom: camss: Add streams enable field to camss resources Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 05/12] media: qcom: camss: Add per-port config to CSID configure_stream Gjorgji Rosikopulos
` (7 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Implement the V4L2 subdev streams API (enable_streams/disable_streams,
set_routing) on CSIPHY, selected per SoC via the new streams_enable
field on struct camss_resources.
The shared D-PHY lanes are enabled once, on the transition to an
active state, and torn down once no sink stream is referenced by any
source pad any more. CSIPHY has no per-VC demux, so every route must
pass a sink stream straight through as the same source stream; a
multi-VC sensor is supported by userspace adding further routes via
.set_routing.
CSIPHY can be wired through either the legacy s_power/s_stream path
or the generic PHY framework (camss->legacy_phy); the streams-API
pad ops are shared between both, with enable/disable dispatching to
the matching backend.
Co-developed-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../media/platform/qcom/camss/camss-csiphy.c | 249 +++++++++++++++++-
.../media/platform/qcom/camss/camss-csiphy.h | 1 +
2 files changed, 244 insertions(+), 6 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c
index f99eea2ef228..41df8f1dad83 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -421,6 +421,129 @@ static int csiphy_set_stream(struct v4l2_subdev *sd, int enable)
return ret;
}
+/*
+ * csiphy_streams_set_stream - Enable/disable streaming on CSIPHY module
+ * @sd: CSIPHY V4L2 subdevice
+ * @enable: Requested streaming state
+ *
+ * Dispatches to the legacy or generic PHY depending on how this
+ * CSIPHY instance is wired, mirroring msm_csiphy_register_entity().
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csiphy_streams_set_stream(struct v4l2_subdev *sd, int enable)
+{
+ struct csiphy_device *csiphy = v4l2_get_subdevdata(sd);
+
+ if (csiphy->camss->legacy_phy)
+ return csiphy_set_stream_legacy(sd, enable);
+
+ return csiphy_set_stream(sd, enable);
+}
+
+/*
+ * csiphy_pad_enable_streams - Enable one or more streams on the source pad
+ * @sd: CSIPHY V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of streams to enable
+ *
+ * The shared PHY lanes are enabled once, on the transition to an active
+ * state. The sink stream(s) are propagated upstream to the sensor only for
+ * streams which are inactive, so a stream that's already running is never
+ * redundantly re-propagated.
+ *
+ * CSIPHY is only ever linked to a single entity on its source pad, and that
+ * entity is responsible for only enabling a stream on this pad while it
+ * itself still needs it, so no cross-consumer refcounting is needed here.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csiphy_pad_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct csiphy_device *csiphy = v4l2_get_subdevdata(sd);
+ struct media_pad *remote_pad =
+ media_pad_remote_pad_first(&csiphy->pads[MSM_CSIPHY_PAD_SINK]);
+ u64 sink_streams, propagate_mask;
+ int ret;
+
+ if (!csiphy->enabled_streams) {
+ ret = csiphy_streams_set_stream(sd, 1);
+ if (ret)
+ return ret;
+ }
+
+ sink_streams = v4l2_subdev_state_xlate_streams(state, pad, MSM_CSIPHY_PAD_SINK,
+ &streams_mask);
+
+ propagate_mask = sink_streams & ~csiphy->enabled_streams;
+ if (propagate_mask) {
+ struct v4l2_subdev *remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+
+ ret = v4l2_subdev_enable_streams(remote_sd, remote_pad->index, propagate_mask);
+ if (ret) {
+ if (!csiphy->enabled_streams)
+ csiphy_streams_set_stream(sd, 0);
+
+ return ret;
+ }
+ }
+ csiphy->enabled_streams |= sink_streams;
+
+ return 0;
+}
+
+/*
+ * csiphy_pad_disable_streams - Disable one or more streams on the source pad
+ * @sd: CSIPHY V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of streams to disable
+ *
+ * The shared PHY lanes, and the propagation to the sensor, are only torn
+ * down once no sink stream is referenced by any source pad any more.
+ *
+ * CSIPHY is only ever linked to a single entity on its source pad, and that
+ * entity is responsible for only disabling a stream on this pad once it no
+ * longer needs it, so no cross-consumer refcounting is needed here.
+ * If error occurs propagate the error but continue to disable the streams
+ * on best effort.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csiphy_pad_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct csiphy_device *csiphy = v4l2_get_subdevdata(sd);
+ struct media_pad *remote_pad =
+ media_pad_remote_pad_first(&csiphy->pads[MSM_CSIPHY_PAD_SINK]);
+ u64 sink_streams;
+ int ret = 0;
+
+ sink_streams = v4l2_subdev_state_xlate_streams(state, pad, MSM_CSIPHY_PAD_SINK,
+ &streams_mask);
+
+ csiphy->enabled_streams &= ~sink_streams;
+
+ if (!csiphy->enabled_streams)
+ ret = csiphy_streams_set_stream(sd, 0);
+
+ if (sink_streams) {
+ struct v4l2_subdev *remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+ int remote_ret;
+
+ remote_ret = v4l2_subdev_disable_streams(remote_sd, remote_pad->index,
+ sink_streams);
+ if (!ret)
+ ret = remote_ret;
+ }
+
+ return ret;
+}
+
/*
* __csiphy_get_format - Get pointer to format structure
* @csiphy: CSIPHY device
@@ -881,6 +1004,71 @@ static int csiphy_link_setup(struct media_entity *entity,
return 0;
}
+static int csiphy_init_state(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_subdev_route routes[] = {
+ {
+ .sink_pad = MSM_CSIPHY_PAD_SINK,
+ .sink_stream = 0,
+ .source_pad = MSM_CSIPHY_PAD_SRC,
+ .source_stream = 0,
+ .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE,
+ },
+ };
+ struct v4l2_subdev_krouting routing = {
+ .num_routes = ARRAY_SIZE(routes),
+ .routes = routes,
+ };
+
+ /*
+ * CSIPHY has no per-VC demux, so every sink stream (VC) a
+ * multi-stream sensor may drive must pass straight through as the
+ * same source stream, or downstream link validation (e.g. against
+ * CSID's multi-pad sink) will flag it as dangling. A multi-VC sensor
+ * is supported by userspace adding further routes via .set_routing;
+ * this default covers the common single-VC case.
+ */
+ return v4l2_subdev_set_routing(sd, state, &routing);
+}
+
+/*
+ * csiphy_set_routing - Set routing for the CSIPHY subdev
+ * @sd: CSIPHY V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @which: Type of format state (V4L2_SUBDEV_FORMAT_ACTIVE or TRY)
+ * @routing: Routing table to set
+ *
+ * CSIPHY has no per-VC demux, so every route must pass a sink stream
+ * straight through as the same source stream.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csiphy_set_routing(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ enum v4l2_subdev_format_whence which,
+ struct v4l2_subdev_krouting *routing)
+{
+ struct csiphy_device *csiphy = v4l2_get_subdevdata(sd);
+ unsigned int i;
+ int ret;
+
+ if (which == V4L2_SUBDEV_FORMAT_ACTIVE && csiphy->enabled_streams)
+ return -EBUSY;
+
+ for (i = 0; i < routing->num_routes; i++)
+ if (routing->routes[i].sink_stream != routing->routes[i].source_stream)
+ return -EINVAL;
+
+ ret = v4l2_subdev_routing_validate(sd, routing,
+ V4L2_SUBDEV_ROUTING_NO_STREAM_MIX |
+ V4L2_SUBDEV_ROUTING_NO_N_TO_1);
+ if (ret)
+ return ret;
+
+ return v4l2_subdev_set_routing(sd, state, routing);
+}
+
static const struct v4l2_subdev_core_ops csiphy_core_ops_legacy = {
.s_power = csiphy_set_power_legacy,
};
@@ -911,10 +1099,40 @@ static const struct v4l2_subdev_ops csiphy_v4l2_ops = {
.pad = &csiphy_pad_ops,
};
+static const struct v4l2_subdev_pad_ops csiphy_streams_pad_ops = {
+ .enum_mbus_code = csiphy_enum_mbus_code,
+ .enum_frame_size = csiphy_enum_frame_size,
+ .get_fmt = csiphy_get_format,
+ .set_fmt = csiphy_set_format,
+ .get_frame_desc = v4l2_subdev_get_frame_desc_passthrough,
+ .set_routing = csiphy_set_routing,
+ .enable_streams = csiphy_pad_enable_streams,
+ .disable_streams = csiphy_pad_disable_streams,
+};
+
+static const struct v4l2_subdev_video_ops csiphy_streams_video_ops = {
+ .s_stream = v4l2_subdev_s_stream_helper,
+};
+
+static const struct v4l2_subdev_ops csiphy_streams_v4l2_ops_legacy = {
+ .core = &csiphy_core_ops_legacy,
+ .pad = &csiphy_streams_pad_ops,
+ .video = &csiphy_streams_video_ops,
+};
+
+static const struct v4l2_subdev_ops csiphy_streams_v4l2_ops = {
+ .pad = &csiphy_streams_pad_ops,
+ .video = &csiphy_streams_video_ops,
+};
+
static const struct v4l2_subdev_internal_ops csiphy_v4l2_internal_ops = {
.open = csiphy_init_formats,
};
+static const struct v4l2_subdev_internal_ops csiphy_streams_internal_ops = {
+ .init_state = csiphy_init_state,
+};
+
static const struct media_entity_operations csiphy_media_ops = {
.link_setup = csiphy_link_setup,
.link_validate = v4l2_subdev_link_validate,
@@ -934,15 +1152,21 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy,
struct media_pad *pads = csiphy->pads;
struct camss *camss = csiphy->camss;
struct device *dev = camss->dev;
+ bool streams_api = camss->res->streams_enable;
int ret;
- if (camss->legacy_phy)
- v4l2_subdev_init(sd, &csiphy_v4l2_ops_legacy);
+ if (streams_api)
+ v4l2_subdev_init(sd, camss->legacy_phy ? &csiphy_streams_v4l2_ops_legacy
+ : &csiphy_streams_v4l2_ops);
else
- v4l2_subdev_init(sd, &csiphy_v4l2_ops);
+ v4l2_subdev_init(sd, camss->legacy_phy ? &csiphy_v4l2_ops_legacy
+ : &csiphy_v4l2_ops);
- sd->internal_ops = &csiphy_v4l2_internal_ops;
+ sd->internal_ops = streams_api ? &csiphy_streams_internal_ops
+ : &csiphy_v4l2_internal_ops;
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+ if (streams_api)
+ sd->flags |= V4L2_SUBDEV_FL_STREAMS;
snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d",
MSM_CSIPHY_NAME, csiphy->id);
sd->grp_id = CSIPHY_GRP_ID;
@@ -965,10 +1189,18 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy,
return ret;
}
+ if (streams_api) {
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret) {
+ dev_err(dev, "Failed to finalize subdev: %d\n", ret);
+ goto media_entity_err;
+ }
+ }
+
ret = v4l2_device_register_subdev(v4l2_dev, sd);
if (ret < 0) {
dev_err(dev, "Failed to register subdev: %d\n", ret);
- goto media_entity_err;
+ goto subdev_cleanup_err;
}
if (!IS_ERR(csiphy->phy)) {
@@ -976,12 +1208,15 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy,
if (ret) {
dev_err(dev, "%s init fail %d\n", csiphy->name, ret);
v4l2_device_unregister_subdev(sd);
- goto media_entity_err;
+ goto subdev_cleanup_err;
}
}
return 0;
+subdev_cleanup_err:
+ if (streams_api)
+ v4l2_subdev_cleanup(sd);
media_entity_err:
media_entity_cleanup(&sd->entity);
return ret;
@@ -996,5 +1231,7 @@ void msm_csiphy_unregister_entity(struct csiphy_device *csiphy)
if (!IS_ERR(csiphy->phy))
phy_exit(csiphy->phy);
v4l2_device_unregister_subdev(&csiphy->subdev);
+ if (csiphy->camss->res->streams_enable)
+ v4l2_subdev_cleanup(&csiphy->subdev);
media_entity_cleanup(&csiphy->subdev.entity);
}
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/media/platform/qcom/camss/camss-csiphy.h
index 8c3319f2ca1c..cd15369d132e 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.h
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.h
@@ -118,6 +118,7 @@ struct csiphy_device {
struct v4l2_mbus_framefmt fmt[MSM_CSIPHY_PADS_NUM];
const struct csiphy_subdev_resources *res;
struct csiphy_device_regs *regs;
+ u64 enabled_streams;
};
struct camss_subdev_resources;
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 05/12] media: qcom: camss: Add per-port config to CSID configure_stream
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (3 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 04/12] media: qcom: camss: Add streams API support for CSIPHY Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 06/12] media: qcom: camss: Add streams API support in CSID subdevice Gjorgji Rosikopulos
` (6 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Add struct csid_port_config {vc, dt} and change csid_hw_ops's
configure_stream() to take a port_mask and a port_cfg array, replacing
the old single enable-only entry point. Bit(i) of port_mask selects
port i (pad - MSM_CSID_PAD_FIRST_SRC). The VC/DT to program for each
such port comes from csid->port_cfg[port], which the csid subdev
is guaranteed to populate for every port set in
port_mask.
configure_stream() remains the single entry point for configuring
CSID input streams, used by both the legacy (non-streams-API) path
and the future streams API, selected by streams_enable. The legacy
caller in csid subdevice populates csid->port_cfg[] from the
negotiated format (VC 0) before calling configure_stream(),
matching prior behaviour exactly.
configure_stream() is a single function pointer in struct
csid_hw_ops, shared by all six CSID backends (gen2, gen3, 340, 4-1,
4-7, 680), so its signature is updated for all of them in this same
commit. camss-csid-340.c and camss-csid-680.c replace their internal
csid->phy.en_vc loop condition with port_mask; camss-csid-4-1.c and
camss-csid-4-7.c are legacy-only, single-port backends and get a
purely mechanical signature update, with port_mask and port_cfg
unused.
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../platform/qcom/camss/camss-csid-340.c | 5 +-
.../platform/qcom/camss/camss-csid-4-1.c | 3 +-
.../platform/qcom/camss/camss-csid-4-7.c | 3 +-
.../platform/qcom/camss/camss-csid-680.c | 7 +--
.../platform/qcom/camss/camss-csid-gen2.c | 54 +++++++++++++------
.../platform/qcom/camss/camss-csid-gen3.c | 34 ++++++------
.../media/platform/qcom/camss/camss-csid.c | 18 ++++++-
.../media/platform/qcom/camss/camss-csid.h | 21 +++++++-
8 files changed, 103 insertions(+), 42 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-340.c b/drivers/media/platform/qcom/camss/camss-csid-340.c
index 42ff629ce410..46fbc46102e4 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-340.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-340.c
@@ -146,14 +146,15 @@ static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 port
writel_relaxed(enable, csid->base + CSID_CTRL(iface));
}
-static void csid_configure_streams(struct csid_device *csid, u8 enable)
+static void csid_configure_streams(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
int i;
__csid_configure_rx(csid, &csid->phy);
for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) {
- if (csid->phy.en_vc & BIT(i))
+ if (port_mask & BIT(i))
__csid_configure_stream(csid, !!enable, i, 0);
}
}
diff --git a/drivers/media/platform/qcom/camss/camss-csid-4-1.c b/drivers/media/platform/qcom/camss/camss-csid-4-1.c
index 6998e1c52895..c3e00de326aa 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-4-1.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-4-1.c
@@ -44,7 +44,8 @@
#define CAMSS_CSID_TG_DT_n_CGG_1(n) (0x0b0 + 0xc * (n))
#define CAMSS_CSID_TG_DT_n_CGG_2(n) (0x0b4 + 0xc * (n))
-static void csid_configure_stream(struct csid_device *csid, u8 enable)
+static void csid_configure_stream(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
struct csid_testgen_config *tg = &csid->testgen;
u32 val;
diff --git a/drivers/media/platform/qcom/camss/camss-csid-4-7.c b/drivers/media/platform/qcom/camss/camss-csid-4-7.c
index 66054d4872e6..2e8aea3ee545 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-4-7.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-4-7.c
@@ -43,7 +43,8 @@
#define CAMSS_CSID_TG_DT_n_CGG_1(n) (0x0b8 + 0xc * (n))
#define CAMSS_CSID_TG_DT_n_CGG_2(n) (0x0bc + 0xc * (n))
-static void csid_configure_stream(struct csid_device *csid, u8 enable)
+static void csid_configure_stream(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
struct csid_testgen_config *tg = &csid->testgen;
u32 sink_code = csid->fmt[MSM_CSID_PAD_SINK].code;
diff --git a/drivers/media/platform/qcom/camss/camss-csid-680.c b/drivers/media/platform/qcom/camss/camss-csid-680.c
index 452640e72f6d..a864dcf7a1e8 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-680.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-680.c
@@ -310,15 +310,16 @@ static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi
writel(val, csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
}
-static void csid_configure_stream(struct csid_device *csid, u8 enable)
+static void csid_configure_stream(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
int i;
__csid_configure_top(csid);
- /* Loop through all enabled ports and configure a stream for each */
+ /* Loop through all ports set in port_mask and configure a stream for each */
for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) {
- if (csid->phy.en_vc & BIT(i)) {
+ if (port_mask & BIT(i)) {
__csid_configure_rdi_stream(csid, enable, i, 0);
__csid_configure_rx(csid, &csid->phy, 0);
__csid_configure_rdi_irq(csid, enable, i);
diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen2.c b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
index a351ac4b9172..1ed7ca63907b 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-gen2.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
@@ -255,13 +255,8 @@ static void __csid_configure_testgen(struct csid_device *csid, u8 enable, u8 por
writel_relaxed(val, csid->base + CSID_TPG_CTRL);
}
-static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8 port, u8 vc)
+static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8 port, u8 vc, u8 dt)
{
- /* Source pads matching RDI channels on hardware. Pad 1 -> RDI0, Pad 2 -> RDI1, etc. */
- struct v4l2_mbus_framefmt *input_format = &csid->fmt[MSM_CSID_PAD_FIRST_SRC + port];
- const struct csid_format_info *format = csid_get_fmt_entry(csid->res->formats->formats,
- csid->res->formats->nformats,
- input_format->code);
u32 val;
/*
@@ -283,7 +278,7 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8
val |= 1 << RDI_CFG0_TIMESTAMP_EN;
/* note: for non-RDI path, this should be format->decode_format */
val |= DECODE_FORMAT_PAYLOAD_ONLY << RDI_CFG0_DECODE_FORMAT;
- val |= format->data_type << RDI_CFG0_DATA_TYPE;
+ val |= dt << RDI_CFG0_DATA_TYPE;
val |= vc << RDI_CFG0_VIRTUAL_CHANNEL;
val |= dt_id << RDI_CFG0_DT_ID;
writel_relaxed(val, csid->base + CSID_RDI_CFG0(port));
@@ -334,22 +329,47 @@ static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi
writel_relaxed(val, csid->base + CSID_CSI2_RDIN_IRQ_MASK(rdi));
}
-static void csid_configure_stream(struct csid_device *csid, u8 enable)
+static void csid_configure_stream(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
struct csid_testgen_config *tg = &csid->testgen;
+ unsigned long mask = port_mask;
+ bool config_testgen = false;
u8 i;
- /* Loop through all enabled ports and configure a stream for each */
- for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
- if (csid->phy.en_vc & BIT(i)) {
- if (tg->enabled)
- __csid_configure_testgen(csid, enable, i, 0);
-
- __csid_configure_rdi_stream(csid, enable, i, 0);
+ /*
+ * Testgen has only one configuration for all ports.
+ * The csid guarantees that the enabled_ports is set/cleared
+ * after configure stream. !csid->enabled_ports is
+ * on first enable, (port_mask == csid->enabled_ports) is
+ * on last disable.
+ */
+ if (!csid->enabled_ports || port_mask == csid->enabled_ports)
+ config_testgen = true;
+
+ for_each_set_bit(i, &mask, MSM_CSID_MAX_SRC_STREAMS) {
+ if (enable) {
+ if (tg->enabled && config_testgen) {
+ __csid_configure_testgen(csid, 1, i, port_cfg[i].vc);
+ config_testgen = false;
+ }
+ __csid_configure_rdi_stream(csid, 1, i, port_cfg[i].vc,
+ port_cfg[i].dt);
__csid_configure_rx(csid, &csid->phy, 0);
- __csid_configure_rdi_irq(csid, enable, i);
- __csid_ctrl_rdi(csid, enable, i);
+ __csid_configure_rdi_irq(csid, 1, i);
+ __csid_ctrl_rdi(csid, 1, i);
+ } else {
+ __csid_ctrl_rdi(csid, 0, i);
+ __csid_configure_rdi_irq(csid, 0, i);
+
+ if (tg->enabled && config_testgen) {
+ __csid_configure_testgen(csid, 0, i, 0);
+ config_testgen = false;
+ }
+
+ __csid_configure_rdi_stream(csid, 0, i, 0, 0);
}
+ }
}
static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen3.c b/drivers/media/platform/qcom/camss/camss-csid-gen3.c
index 231b53d3e44e..f270c17d041e 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-gen3.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-gen3.c
@@ -161,15 +161,11 @@ static void __csid_configure_wrapper(struct csid_device *csid)
writel(val, csid->camss->csid_wrapper_base + CSID_IO_PATH_CFG0(csid->id));
}
-static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8 port, u8 vc)
+static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable,
+ u8 port, u8 vc, u8 dt)
{
u32 val;
u8 lane_cnt = csid->phy.lane_cnt;
- /* Source pads matching RDI channels on hardware. Pad 1 -> RDI0, Pad 2 -> RDI1, etc. */
- struct v4l2_mbus_framefmt *input_format = &csid->fmt[MSM_CSID_PAD_FIRST_SRC + port];
- const struct csid_format_info *format = csid_get_fmt_entry(csid->res->formats->formats,
- csid->res->formats->nformats,
- input_format->code);
if (!lane_cnt)
lane_cnt = 4;
@@ -193,7 +189,7 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8
/* note: for non-RDI path, this should be format->decode_format */
val |= DECODE_FORMAT_PAYLOAD_ONLY << RDI_CFG0_DECODE_FORMAT;
val |= vc << RDI_CFG0_VC;
- val |= format->data_type << RDI_CFG0_DT;
+ val |= dt << RDI_CFG0_DT;
val |= dt_id << RDI_CFG0_DT_ID;
writel(val, csid->base + CSID_RDI_CFG0(port));
@@ -242,20 +238,28 @@ static void __csid_configure_rdi_irq(struct csid_device *csid, u8 enable, u8 rdi
writel(val, csid->base + CSID_TOP_IRQ_MASK);
}
-static void csid_configure_stream(struct csid_device *csid, u8 enable)
+static void csid_configure_stream(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable)
{
+ unsigned long mask = port_mask;
u8 i;
__csid_configure_wrapper(csid);
- /* Loop through all enabled ports and configure a stream for each */
- for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++)
- 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);
+ /* Loop through all ports set in port_mask and configure a stream for each */
+ for_each_set_bit(i, &mask, MSM_CSID_MAX_SRC_STREAMS) {
+ u8 vc = 0, dt = 0;
+
+ if (enable) {
+ vc = port_cfg[i].vc;
+ dt = port_cfg[i].dt;
}
+
+ __csid_configure_rdi_stream(csid, enable, i, vc, dt);
+ __csid_configure_rx(csid, &csid->phy, 0);
+ __csid_configure_rdi_irq(csid, enable, i);
+ __csid_ctrl_rdi(csid, enable, i);
+ }
}
static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
index 0f819c34e760..2efaeef83606 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -783,7 +783,23 @@ static int csid_set_stream(struct v4l2_subdev *sd, int enable)
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);
+ for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) {
+ if (csid->phy.en_vc & BIT(i)) {
+ struct v4l2_mbus_framefmt *input_format =
+ &csid->fmt[MSM_CSID_PAD_FIRST_SRC + i];
+ const struct csid_format_info *format =
+ csid_get_fmt_entry(csid->res->formats->formats,
+ csid->res->formats->nformats,
+ input_format->code);
+
+ csid->port_cfg[i].vc = 0;
+ csid->port_cfg[i].dt = format->data_type;
+ }
+ }
+
+ csid->res->hw_ops->configure_stream(csid, csid->phy.en_vc, csid->port_cfg, enable);
+ csid->enabled_ports = enable ? csid->phy.en_vc : 0;
+
csid->phy.need_vc_update = false;
}
diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h
index 8edb258b0ae5..5f09beffa5f5 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.h
+++ b/drivers/media/platform/qcom/camss/camss-csid.h
@@ -72,14 +72,29 @@ struct csid_phy_config {
u8 need_vc_update;
};
+/*
+ * struct csid_port_config - Per-port CSI-2 virtual channel/data type
+ * @vc: Virtual channel
+ * @dt: Data type
+ */
+struct csid_port_config {
+ u8 vc;
+ u8 dt;
+};
+
struct csid_device;
struct csid_hw_ops {
/*
- * configure_stream - Configures and starts CSID input stream
+ * configure_stream - Configure and start/stop CSID input streams
* @csid: CSID device
+ * @port_mask: bitmask of ports (bit i = port i) to configure
+ * @port_cfg: per-port VC/DT, valid at every port position set in
+ * @port_mask. If @enable is 0, @port_cfg can be NULL.
+ * @enable: 1 to enable the ports in @port_mask, 0 to disable them
*/
- void (*configure_stream)(struct csid_device *csid, u8 enable);
+ void (*configure_stream)(struct csid_device *csid, u32 port_mask,
+ const struct csid_port_config *port_cfg, u8 enable);
/*
* configure_testgen_pattern - Validates and configures output pattern mode
@@ -170,6 +185,8 @@ struct csid_device {
const struct csid_subdev_resources *res;
atomic_t frame_sync_users;
atomic_t sof_seq[MSM_CSID_MAX_SRC_STREAMS];
+ struct csid_port_config port_cfg[MSM_CSID_MAX_SRC_STREAMS];
+ u32 enabled_ports;
};
struct camss_subdev_resources;
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 06/12] media: qcom: camss: Add streams API support in CSID subdevice
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (4 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 05/12] media: qcom: camss: Add per-port config to CSID configure_stream Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 07/12] media: qcom: camss: Add streams API support in tpg subdev Gjorgji Rosikopulos
` (5 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Implement the V4L2 subdev streams API (enable_streams/disable_streams,
set_routing, get/set_fmt) on the CSID subdevice, selected per SoC via
camss->res->streams_enable.
Each CSID source pad carries a single stream fanned out from the sink
pad by default; a multi-VC sensor is supported by remapping a route's
sink_stream via .set_routing, leaving source_pad/source_stream
untouched. The virtual channel and data type programmed into the
hardware are discovered from the remote subdev's CSI-2 frame
descriptor when available, falling back to the format's data type
otherwise.
The Rx front-end and, where present, the test-pattern generator's
v4l2 controls are synced once, on the transition from no active sink
streams to at least one; propagation to the sensor and teardown are
likewise only done when no other source pad still references a given
sink stream.
The full IFE's pix pad/route is still excluded on non-lite CSIDs
pending a correctness fix for the non-functional pix path; this is a
known limitation carried over from the non-streams driver, not
specific to the streams API.
Co-developed-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../media/platform/qcom/camss/camss-csid.c | 490 +++++++++++++++++-
.../media/platform/qcom/camss/camss-csid.h | 1 +
2 files changed, 486 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
index 2efaeef83606..652c4dd31093 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -1432,10 +1432,469 @@ static const struct v4l2_subdev_ops csid_v4l2_ops = {
.pad = &csid_pad_ops,
};
+/*
+ * csid_fill_port_configs - Discover and populate the virtual channel/data
+ * type to program for every actively routed port
+ * @csid: CSID device
+ * @state: V4L2 subdevice state
+ * @remote_pad: Remote pad linked on the CSID sink pad, or NULL if unlinked
+ *
+ * Fetches the frame descriptor from the remote subdev linked on the sink pad
+ * once, then walks every active route to populate csid->port_cfg[] for each
+ * routed source pad, falling back to {0, format_dt} when no frame descriptor
+ * is available.
+
+ * Return 0 on success, error otherwise.
+ */
+static int csid_fill_port_configs(struct csid_device *csid, struct v4l2_subdev_state *state,
+ struct media_pad *remote_pad)
+{
+ struct v4l2_mbus_frame_desc frame_desc = { };
+ struct v4l2_subdev_route *route;
+ int ret;
+
+ if (remote_pad) {
+ struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+
+ ret = v4l2_subdev_call(sd, pad, get_frame_desc,
+ remote_pad->index, &frame_desc);
+ if (ret)
+ return ret;
+ /* Only csi2 frame descriptors are supported for now */
+ if (frame_desc.type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2)
+ return -EINVAL;
+ /* Frame descriptor of type csi2 should contain entries! */
+ if (!frame_desc.num_entries)
+ return -EINVAL;
+ }
+
+ for_each_active_route(&state->routing, route) {
+ int src_port = csid_pad_to_port(route->source_pad);
+ struct csid_port_config *port_cfg = &csid->port_cfg[src_port];
+ const struct csid_format_info *pad_fmt;
+ u32 sink_stream;
+ unsigned int i;
+
+ pad_fmt = csid_get_fmt_entry(csid->res->formats->formats,
+ csid->res->formats->nformats,
+ csid->fmt[route->source_pad].code);
+ /* If there are no entries fill dt from the format */
+ if (!frame_desc.num_entries) {
+ port_cfg->vc = 0;
+ port_cfg->dt = pad_fmt->data_type;
+ continue;
+ }
+
+ ret = v4l2_subdev_routing_find_opposite_end(&state->routing,
+ route->source_pad, 0, NULL,
+ &sink_stream);
+ /* This should never fail, anyways handle error cases */
+ if (ret)
+ return ret;
+
+ for (i = 0; i < frame_desc.num_entries; i++) {
+ if (frame_desc.entry[i].stream != sink_stream)
+ continue;
+
+ port_cfg->vc = frame_desc.entry[i].bus.csi2.vc;
+ port_cfg->dt = frame_desc.entry[i].bus.csi2.dt;
+
+ if (port_cfg->dt != pad_fmt->data_type) {
+ dev_warn(csid->camss->dev,
+ "Sink stream %u dt mismatch %u, %u\n",
+ sink_stream, port_cfg->dt,
+ pad_fmt->data_type);
+ return -EINVAL;
+ }
+ break;
+ }
+ if (i == frame_desc.num_entries) {
+ dev_warn(csid->camss->dev,
+ "Cannot find CSI2 desc for sink stream %u\n",
+ sink_stream);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * csid_pad_enable_streams - Enable one or more streams on a source pad
+ * @sd: CSID V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of v4l2 streams to enable
+ *
+ * The v4l2 core only calls this on a source pad (v4l2_subdev_enable_streams()
+ * rejects sink pads with -EOPNOTSUPP before reaching the driver), so @pad is
+ * not checked here. Each source pad only ever carries stream 0.
+ *
+ * The shared sink stream(s) are propagated upstream only once, on the
+ * transition from no active sink streams to at least one, so that a second
+ * consumer of the same shared sink stream never triggers a second, redundant
+ * propagation to the sensor.
+ *
+ * Return 0 on success, -ENOLINK if there is no remote sink link and the test
+ * generator is disabled, or another negative error code otherwise
+ */
+static int csid_pad_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ const struct csid_hw_ops *hw_ops = csid->res->hw_ops;
+ struct media_pad *remote_pad = media_pad_remote_pad_first(&csid->pads[MSM_CSID_PAD_SINK]);
+ unsigned int hw_port = csid_pad_to_port(pad);
+ u64 sink_streams, propagate_mask;
+ int ret;
+
+ if (!csid->testgen.enabled && !remote_pad)
+ return -ENOLINK;
+
+ sink_streams = v4l2_subdev_state_xlate_streams(state, pad, MSM_CSID_PAD_SINK,
+ &streams_mask);
+ if (!csid->enabled_sink_streams) {
+ if (csid->testgen.nmodes != CSID_PAYLOAD_MODE_DISABLED) {
+ /*
+ * sd->state_lock is aliased to csid->ctrls.lock, and is
+ * already held here by the v4l2_subdev_enable_streams()
+ * caller, so use the lock-free variant to avoid
+ * self-deadlocking on the same mutex.
+ */
+ ret = __v4l2_ctrl_handler_setup(&csid->ctrls);
+ if (ret < 0) {
+ dev_err(csid->camss->dev,
+ "could not sync v4l2 controls: %d\n", ret);
+ return ret;
+ }
+ }
+
+ /* Routing cannot change while any sink stream is enabled */
+ ret = csid_fill_port_configs(csid, state, remote_pad);
+ if (ret)
+ return ret;
+ }
+
+ /* If sink streams are already active elsewhere don't need to re-propagate */
+ propagate_mask = sink_streams & ~csid->enabled_sink_streams;
+ csid->enabled_sink_streams |= sink_streams;
+
+ hw_ops->configure_stream(csid, BIT(hw_port), csid->port_cfg, 1);
+ csid->enabled_ports |= BIT(hw_port);
+ if (propagate_mask && remote_pad) {
+ ret = v4l2_subdev_enable_streams(media_entity_to_v4l2_subdev(remote_pad->entity),
+ remote_pad->index, propagate_mask);
+ if (ret) {
+ csid->enabled_sink_streams &= ~propagate_mask;
+
+ hw_ops->configure_stream(csid, BIT(hw_port), NULL, 0);
+ csid->enabled_ports &= ~BIT(hw_port);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * csid_sink_streams_in_use - Compute the subset of sink streams still
+ * referenced by a source pad other than @pad
+ * @csid: CSID device
+ * @state: V4L2 subdevice state
+ * @pad: Source pad to exclude from the check
+ * @sink_streams: Candidate sink streams to check
+ *
+ * Return the subset of @sink_streams still referenced by some other source
+ * pad
+ */
+static u64 csid_sink_streams_in_use(struct csid_device *csid, struct v4l2_subdev_state *state,
+ u32 pad, u64 sink_streams)
+{
+ u64 in_use = 0;
+ unsigned int i;
+
+ for (i = MSM_CSID_PAD_FIRST_SRC; i < MSM_CSID_PADS_NUM; i++) {
+ u64 other_streams;
+ u64 other_sink_streams;
+
+ if (i == pad)
+ continue;
+
+ other_streams = !!(csid->enabled_ports & BIT(csid_pad_to_port(i)));
+
+ other_sink_streams = v4l2_subdev_state_xlate_streams(state, i, MSM_CSID_PAD_SINK,
+ &other_streams);
+ in_use |= sink_streams & other_sink_streams;
+ }
+
+ return in_use;
+}
+
+/*
+ * csid_pad_disable_streams - Disable one or more streams on a source pad
+ * @sd: CSID V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of v4l2 streams to disable
+ *
+ * The v4l2 core only calls this on a source pad (v4l2_subdev_disable_streams()
+ * rejects sink pads with -EOPNOTSUPP before reaching the driver), so @pad is
+ * not checked here. Each source pad only ever carries stream 0.
+ *
+ * A sink stream is only disabled, and propagated upstream to disable it there
+ * too, once no source pad references it any more.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csid_pad_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ const struct csid_hw_ops *hw_ops = csid->res->hw_ops;
+ unsigned int hw_port = csid_pad_to_port(pad);
+ u64 sink_streams, disable_sink_streams, streams_in_use;
+ struct media_pad *remote_pad;
+ int ret = 0;
+
+ sink_streams = v4l2_subdev_state_xlate_streams(state, pad, MSM_CSID_PAD_SINK,
+ &streams_mask);
+
+ /* Keep a sink stream active as long as any other source pad still uses it. */
+ streams_in_use = csid_sink_streams_in_use(csid, state, pad, sink_streams);
+ disable_sink_streams = sink_streams & ~streams_in_use;
+
+ hw_ops->configure_stream(csid, BIT(hw_port), NULL, 0);
+
+ remote_pad = media_pad_remote_pad_first(&csid->pads[MSM_CSID_PAD_SINK]);
+ if (disable_sink_streams && remote_pad) {
+ ret = v4l2_subdev_disable_streams(media_entity_to_v4l2_subdev(remote_pad->entity),
+ remote_pad->index, disable_sink_streams);
+ if (ret)
+ dev_err(csid->camss->dev,
+ "Failed to disable stream on remote pad: %d\n", ret);
+ }
+
+ csid->enabled_ports &= ~BIT(hw_port);
+ csid->enabled_sink_streams &= ~disable_sink_streams;
+
+ return ret;
+}
+
+static const struct v4l2_mbus_framefmt csid_default_format = {
+ .code = MEDIA_BUS_FMT_UYVY8_1X16,
+ .width = 1920,
+ .height = 1080,
+ .field = V4L2_FIELD_NONE,
+ .colorspace = V4L2_COLORSPACE_SRGB,
+};
+
+/*
+ * csid_set_routing - Handle setting of routing table
+ * @sd: CSID V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @which: TRY or ACTIVE routing
+ * @routing: Routing table to set
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csid_set_routing(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ enum v4l2_subdev_format_whence which,
+ struct v4l2_subdev_krouting *routing)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ unsigned int i;
+ int ret;
+
+ if (which == V4L2_SUBDEV_FORMAT_ACTIVE && csid->enabled_sink_streams)
+ return -EBUSY;
+
+ for (i = 0; i < routing->num_routes; i++)
+ if (routing->routes[i].source_stream != 0)
+ return -EINVAL;
+
+ ret = v4l2_subdev_routing_validate(sd, routing,
+ V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX |
+ V4L2_SUBDEV_ROUTING_NO_SOURCE_MULTIPLEXING |
+ V4L2_SUBDEV_ROUTING_NO_N_TO_1);
+ if (ret)
+ return ret;
+
+ return v4l2_subdev_set_routing_with_fmt(sd, state, routing, &csid_default_format);
+}
+
+/*
+ * __csid_get_stream_format - Get pointer to per-stream format structure
+ * @csid: CSID device
+ * @sd_state: V4L2 subdev state
+ * @pad: pad from which format is requested
+ * @stream: stream from which format is requested
+ * @which: TRY or ACTIVE format
+ *
+ * Same as __csid_get_format(), but honors @stream for TRY-state lookups.
+ * For ACTIVE state, csid->fmt[] is indexed by pad + stream. @stream is
+ * always 0 and @pad selects the RDI channel (0-3).
+ *
+ * Return pointer to TRY or ACTIVE format structure
+ */
+static struct v4l2_mbus_framefmt *
+__csid_get_stream_format(struct csid_device *csid,
+ struct v4l2_subdev_state *sd_state,
+ unsigned int pad, u32 stream,
+ enum v4l2_subdev_format_whence which)
+{
+ if (which == V4L2_SUBDEV_FORMAT_TRY)
+ return v4l2_subdev_state_get_format(sd_state, pad, stream);
+
+ if (pad == MSM_CSID_PAD_SINK)
+ return &csid->fmt[MSM_CSID_PAD_SINK];
+
+ return &csid->fmt[pad + stream];
+}
+
+/*
+ * csid_streams_get_format - Handle get format by pads subdev method
+ * @sd: CSID V4L2 subdevice
+ * @sd_state: V4L2 subdev state
+ * @fmt: pointer to v4l2 subdev format structure
+ *
+ * Return -EINVAL or zero on success
+ */
+static int csid_streams_get_format(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *sd_state,
+ struct v4l2_subdev_format *fmt)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ struct v4l2_mbus_framefmt *format;
+
+ format = __csid_get_stream_format(csid, sd_state, fmt->pad, fmt->stream, fmt->which);
+ if (!format)
+ return -EINVAL;
+
+ fmt->format = *format;
+
+ return 0;
+}
+
+/*
+ * csid_streams_set_format - Handle set format by pads subdev method
+ * @sd: CSID V4L2 subdevice
+ * @sd_state: V4L2 subdev state
+ * @fmt: pointer to v4l2 subdev format structure
+ *
+ * Return -EINVAL or zero on success
+ */
+static int csid_streams_set_format(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *sd_state,
+ struct v4l2_subdev_format *fmt)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ struct v4l2_mbus_framefmt *format;
+ struct v4l2_subdev_route *route;
+
+ if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE && csid->enabled_sink_streams)
+ return -EBUSY;
+
+ format = __csid_get_stream_format(csid, sd_state, fmt->pad, fmt->stream, fmt->which);
+ if (!format)
+ return -EINVAL;
+
+ csid_try_format(csid, sd_state, fmt->pad, &fmt->format, fmt->which);
+ *format = fmt->format;
+
+ /* Propagate the format from the sink stream to every source stream it feeds */
+ for_each_active_route(&sd_state->routing, route) {
+ struct v4l2_mbus_framefmt *src_format;
+
+ if (route->sink_pad != fmt->pad || route->sink_stream != fmt->stream)
+ continue;
+
+ src_format = __csid_get_stream_format(csid, sd_state, route->source_pad,
+ route->source_stream, fmt->which);
+ if (!src_format)
+ continue;
+
+ *src_format = fmt->format;
+ csid_try_format(csid, sd_state, route->source_pad, src_format, fmt->which);
+ }
+
+ return 0;
+}
+
+static const struct v4l2_subdev_pad_ops csid_streams_pad_ops = {
+ .enum_mbus_code = csid_enum_mbus_code,
+ .enum_frame_size = csid_enum_frame_size,
+ .get_fmt = csid_streams_get_format,
+ .set_fmt = csid_streams_set_format,
+ .set_routing = csid_set_routing,
+ .enable_streams = csid_pad_enable_streams,
+ .disable_streams = csid_pad_disable_streams,
+};
+
+static const struct v4l2_subdev_video_ops csid_streams_video_ops = {
+ .s_stream = v4l2_subdev_s_stream_helper,
+};
+
+static const struct v4l2_subdev_ops csid_streams_v4l2_ops = {
+ .core = &csid_core_ops,
+ .pad = &csid_streams_pad_ops,
+ .video = &csid_streams_video_ops,
+};
+
+/*
+ * csid_init_state - Initialize the routing table for the streams API subdev
+ * @sd: CSID V4L2 subdevice
+ * @state: V4L2 subdev state
+ *
+ * source_stream is always 0: each source pad MSM_CSID_PAD_FIRST_SRC + i
+ * links to its own independent downstream subdev, and a link's sink side is
+ * validated against the implicit stream 0 exposed by any subdev without
+ * V4L2_SUBDEV_FL_STREAMS (see v4l2_link_validate_get_streams()) -- every
+ * downstream VFE line is such a subdev.
+ *
+ * All source pads route from sink_stream 0 by default, fanning the single
+ * incoming stream out to every port; a multi-VC source is supported by
+ * remapping each route's sink_stream via .set_routing, leaving
+ * source_pad/source_stream untouched.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int csid_init_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *state)
+{
+ struct csid_device *csid = v4l2_get_subdevdata(sd);
+ struct v4l2_subdev_route routes[MSM_CSID_MAX_SRC_STREAMS];
+ struct v4l2_subdev_krouting routing = { };
+ unsigned int num_routes = MSM_CSID_MAX_SRC_STREAMS;
+ int i, ret;
+
+ for (i = 0; i < num_routes; i++) {
+ routes[i].sink_pad = MSM_CSID_PAD_SINK;
+ routes[i].sink_stream = 0;
+ routes[i].source_pad = MSM_CSID_PAD_FIRST_SRC + i;
+ routes[i].source_stream = 0;
+ routes[i].flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE;
+ }
+
+ routing.num_routes = num_routes;
+ routing.routes = routes;
+ ret = v4l2_subdev_set_routing_with_fmt(sd, state, &routing, &csid_default_format);
+ if (ret)
+ dev_err(csid->camss->dev, "Failed to set routing: %d\n", ret);
+
+ return ret;
+}
+
static const struct v4l2_subdev_internal_ops csid_v4l2_internal_ops = {
.open = csid_init_formats,
};
+static const struct v4l2_subdev_internal_ops csid_streams_internal_ops = {
+ .init_state = csid_init_state,
+};
+
static const struct media_entity_operations csid_media_ops = {
.link_setup = csid_link_setup,
.link_validate = v4l2_subdev_link_validate,
@@ -1454,13 +1913,18 @@ int msm_csid_register_entity(struct csid_device *csid,
struct v4l2_subdev *sd = &csid->subdev;
struct media_pad *pads = csid->pads;
struct device *dev = csid->camss->dev;
+ bool streams_api = csid->camss->res->streams_enable;
+ unsigned int num_pads = MSM_CSID_PADS_NUM;
int i;
int ret;
- v4l2_subdev_init(sd, &csid_v4l2_ops);
- sd->internal_ops = &csid_v4l2_internal_ops;
+ v4l2_subdev_init(sd, streams_api ? &csid_streams_v4l2_ops : &csid_v4l2_ops);
+ sd->internal_ops = streams_api ? &csid_streams_internal_ops
+ : &csid_v4l2_internal_ops;
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
V4L2_SUBDEV_FL_HAS_EVENTS;
+ if (streams_api)
+ sd->flags |= V4L2_SUBDEV_FL_STREAMS;
snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d",
MSM_CSID_NAME, csid->id);
v4l2_set_subdevdata(sd, csid);
@@ -1494,25 +1958,39 @@ int msm_csid_register_entity(struct csid_device *csid,
}
pads[MSM_CSID_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
- for (i = MSM_CSID_PAD_FIRST_SRC; i < MSM_CSID_PADS_NUM; ++i)
+ for (i = MSM_CSID_PAD_FIRST_SRC; i < num_pads; ++i)
pads[i].flags = MEDIA_PAD_FL_SOURCE;
sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
sd->entity.ops = &csid_media_ops;
- ret = media_entity_pads_init(&sd->entity, MSM_CSID_PADS_NUM, pads);
+ ret = media_entity_pads_init(&sd->entity, num_pads, pads);
if (ret < 0) {
dev_err(dev, "Failed to init media entity: %d\n", ret);
goto free_ctrl;
}
+ if (streams_api) {
+ if (csid->testgen.nmodes != CSID_PAYLOAD_MODE_DISABLED)
+ sd->state_lock = csid->ctrls.lock;
+
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret) {
+ dev_err(dev, "Failed to finalize subdev: %d\n", ret);
+ goto media_cleanup;
+ }
+ }
+
ret = v4l2_device_register_subdev(v4l2_dev, sd);
if (ret < 0) {
dev_err(dev, "Failed to register subdev: %d\n", ret);
- goto media_cleanup;
+ goto subdev_cleanup;
}
return 0;
+subdev_cleanup:
+ if (streams_api)
+ v4l2_subdev_cleanup(sd);
media_cleanup:
media_entity_cleanup(&sd->entity);
free_ctrl:
@@ -1529,6 +2007,8 @@ int msm_csid_register_entity(struct csid_device *csid,
void msm_csid_unregister_entity(struct csid_device *csid)
{
v4l2_device_unregister_subdev(&csid->subdev);
+ if (csid->camss->res->streams_enable)
+ v4l2_subdev_cleanup(&csid->subdev);
media_entity_cleanup(&csid->subdev.entity);
if (csid->testgen.nmodes != CSID_PAYLOAD_MODE_DISABLED)
v4l2_ctrl_handler_free(&csid->ctrls);
diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h
index 5f09beffa5f5..70bb4e34cad8 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.h
+++ b/drivers/media/platform/qcom/camss/camss-csid.h
@@ -187,6 +187,7 @@ struct csid_device {
atomic_t sof_seq[MSM_CSID_MAX_SRC_STREAMS];
struct csid_port_config port_cfg[MSM_CSID_MAX_SRC_STREAMS];
u32 enabled_ports;
+ u64 enabled_sink_streams;
};
struct camss_subdev_resources;
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 07/12] media: qcom: camss: Add streams API support in tpg subdev
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (5 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 06/12] media: qcom: camss: Add streams API support in CSID subdevice Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 08/12] media: qcom: camss: Add streams API support for VFE Gjorgji Rosikopulos
` (4 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Add support for the TPG subdevice to generate multiple concurrent
virtual channels under the streams API. Replace the single fmt field
with a per-stream array sized MSM_TPG_MAX_STREAMS and track the set
of active streams in a new enabled_streams bitmask.
Add tpg_pad_enable_streams()/tpg_pad_disable_streams() pad ops that
update enabled_streams and (re)configure the hardware, a
tpg_get_frame_desc() implementation that reports one CSI-2 frame
descriptor entry per active route with VC equal to the stream index,
and a tpg_init_state() internal op that sets up one default route per
stream.
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../platform/qcom/camss/camss-tpg-gen1.c | 63 +++---
drivers/media/platform/qcom/camss/camss-tpg.c | 179 +++++++++++++++++-
drivers/media/platform/qcom/camss/camss-tpg.h | 6 +-
3 files changed, 205 insertions(+), 43 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-tpg-gen1.c b/drivers/media/platform/qcom/camss/camss-tpg-gen1.c
index d29de5f93c18..22fdeef8e76f 100644
--- a/drivers/media/platform/qcom/camss/camss-tpg-gen1.c
+++ b/drivers/media/platform/qcom/camss/camss-tpg-gen1.c
@@ -5,6 +5,7 @@
*
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
+#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/kernel.h>
@@ -106,13 +107,16 @@ static int tpg_stream_on(struct tpg_device *tpg)
u8 payload_mode = (tg->mode > TPG_PAYLOAD_MODE_DISABLED) ?
tg->mode - 1 : 0;
u8 lane_cnt = tpg->res->lane_cnt;
- u8 vc, dt, last_vc = 0;
+ u8 vc, last_vc = fls64(tpg->enabled_streams) - 1;
u32 val;
- for (vc = 0; vc <= MSM_TPG_ACTIVE_VC; vc++) {
- last_vc = vc;
-
- input_format = &tpg->fmt;
+ /*
+ * The hardware generates traffic for VC 0 up to last_vc as a
+ * contiguous block, so every VC in that range must be configured
+ * with a valid format, not just the ones actually streaming.
+ */
+ for (vc = 0; vc <= last_vc; vc++) {
+ input_format = &tpg->fmt[vc];
format = tpg_get_fmt_entry(tpg->res->formats->formats,
tpg->res->formats->nformats,
input_format->code);
@@ -120,7 +124,8 @@ static int tpg_stream_on(struct tpg_device *tpg)
return -EINVAL;
/* VC configuration */
- val = FIELD_PREP(TPG_VC_n_CFG0_NUM_ACTIVE_DT, MSM_TPG_ACTIVE_DT) |
+ val = FIELD_PREP(TPG_VC_n_CFG0_VC_NUM, vc) |
+ FIELD_PREP(TPG_VC_n_CFG0_NUM_ACTIVE_DT, 0) |
FIELD_PREP(TPG_VC_n_CFG0_NUM_FRAMES, 0);
writel(val, tpg->base + TPG_VC_n_CFG0(vc));
@@ -136,31 +141,29 @@ static int tpg_stream_on(struct tpg_device *tpg)
writel(TPG_COLOR_BARS_CFG_STANDARD, tpg->base + TPG_VC_n_COLOR_BARS_CFG(vc));
/* DT configuration */
- for (dt = 0; dt <= MSM_TPG_ACTIVE_DT; dt++) {
- val = FIELD_PREP(TPG_VC_m_DT_n_CFG_0_FRAME_HEIGHT,
- input_format->height & 0xffff) |
- FIELD_PREP(TPG_VC_m_DT_n_CFG_0_FRAME_WIDTH,
- input_format->width & 0xffff);
- writel(val, tpg->base + TPG_VC_m_DT_n_CFG_0(vc, dt));
-
- val = FIELD_PREP(TPG_VC_m_DT_n_CFG_1_DATA_TYPE, format->data_type);
- writel(val, tpg->base + TPG_VC_m_DT_n_CFG_1(vc, dt));
-
- if (tpg->hw_version == TPG_HW_VER_2_0_0) {
- val = FIELD_PREP(TPG_VC_m_DT_n_CFG_2_PAYLOAD_MODE, payload_mode) |
- FIELD_PREP(TPG_V2_0_0_VC_m_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD,
- TPG_USER_SPECIFIED_PAYLOAD_DEFAULT) |
- FIELD_PREP(TPG_V2_0_0_VC_m_DT_n_CFG_2_ENCODE_FORMAT,
- format->encode_format);
- } else if (tpg->hw_version >= TPG_HW_VER_2_1_0) {
- val = FIELD_PREP(TPG_VC_m_DT_n_CFG_2_PAYLOAD_MODE, payload_mode) |
- FIELD_PREP(TPG_V2_1_0_VC_m_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD,
- TPG_USER_SPECIFIED_PAYLOAD_DEFAULT) |
- FIELD_PREP(TPG_V2_1_0_VC_m_DT_n_CFG_2_ENCODE_FORMAT,
- format->encode_format);
- }
- writel(val, tpg->base + TPG_VC_m_DT_n_CFG_2(vc, dt));
+ val = FIELD_PREP(TPG_VC_m_DT_n_CFG_0_FRAME_HEIGHT,
+ input_format->height & 0xffff) |
+ FIELD_PREP(TPG_VC_m_DT_n_CFG_0_FRAME_WIDTH,
+ input_format->width & 0xffff);
+ writel(val, tpg->base + TPG_VC_m_DT_n_CFG_0(vc, 0));
+
+ val = FIELD_PREP(TPG_VC_m_DT_n_CFG_1_DATA_TYPE, format->data_type);
+ writel(val, tpg->base + TPG_VC_m_DT_n_CFG_1(vc, 0));
+
+ if (tpg->hw_version == TPG_HW_VER_2_0_0) {
+ val = FIELD_PREP(TPG_VC_m_DT_n_CFG_2_PAYLOAD_MODE, payload_mode) |
+ FIELD_PREP(TPG_V2_0_0_VC_m_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD,
+ TPG_USER_SPECIFIED_PAYLOAD_DEFAULT) |
+ FIELD_PREP(TPG_V2_0_0_VC_m_DT_n_CFG_2_ENCODE_FORMAT,
+ format->encode_format);
+ } else if (tpg->hw_version >= TPG_HW_VER_2_1_0) {
+ val = FIELD_PREP(TPG_VC_m_DT_n_CFG_2_PAYLOAD_MODE, payload_mode) |
+ FIELD_PREP(TPG_V2_1_0_VC_m_DT_n_CFG_2_USER_SPECIFIED_PAYLOAD,
+ TPG_USER_SPECIFIED_PAYLOAD_DEFAULT) |
+ FIELD_PREP(TPG_V2_1_0_VC_m_DT_n_CFG_2_ENCODE_FORMAT,
+ format->encode_format);
}
+ writel(val, tpg->base + TPG_VC_m_DT_n_CFG_2(vc, 0));
}
/* Global TPG control */
diff --git a/drivers/media/platform/qcom/camss/camss-tpg.c b/drivers/media/platform/qcom/camss/camss-tpg.c
index 5764a60fa34c..a7ef6d2bb4e8 100644
--- a/drivers/media/platform/qcom/camss/camss-tpg.c
+++ b/drivers/media/platform/qcom/camss/camss-tpg.c
@@ -200,22 +200,78 @@ static int tpg_set_stream(struct v4l2_subdev *sd, int enable)
"could not sync v4l2 controls: %d\n", ret);
return ret;
}
+
+ tpg->enabled_streams = BIT_ULL(0);
+ } else {
+ tpg->enabled_streams = 0;
}
return tpg->res->hw_ops->configure_stream(tpg, enable);
}
+static int tpg_pad_enable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct tpg_device *tpg = v4l2_get_subdevdata(sd);
+ bool start = !tpg->enabled_streams;
+ int ret;
+
+ if (pad != MSM_TPG_PAD_SRC)
+ return -EINVAL;
+
+ tpg->enabled_streams |= streams_mask;
+ if (!start)
+ return tpg->res->hw_ops->configure_stream(tpg, 1);
+
+ ret = v4l2_ctrl_handler_setup(&tpg->ctrls);
+ if (ret < 0) {
+ tpg->enabled_streams &= ~streams_mask;
+ return ret;
+ }
+
+ ret = tpg->res->hw_ops->configure_stream(tpg, 1);
+ if (ret)
+ tpg->enabled_streams &= ~streams_mask;
+
+ return ret;
+}
+
+static int tpg_pad_disable_streams(struct v4l2_subdev *sd,
+ struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct tpg_device *tpg = v4l2_get_subdevdata(sd);
+
+ if (pad != MSM_TPG_PAD_SRC)
+ return -EINVAL;
+
+ tpg->enabled_streams &= ~streams_mask;
+
+ /*
+ * Growing the active VC range live is safe, but shrinking it while
+ * the generator is still running for the remaining VCs corrupts its
+ * state machine. Only touch the hardware when the last VC disables.
+ */
+ if (tpg->enabled_streams)
+ return 0;
+
+ return tpg->res->hw_ops->configure_stream(tpg, 0);
+}
+
static struct v4l2_mbus_framefmt *
__tpg_get_format(struct tpg_device *tpg,
struct v4l2_subdev_state *sd_state,
- unsigned int pad,
+ unsigned int pad, u32 stream,
enum v4l2_subdev_format_whence which)
{
+ if (pad != MSM_TPG_PAD_SRC || stream >= MSM_TPG_MAX_STREAMS)
+ return NULL;
+
if (which == V4L2_SUBDEV_FORMAT_TRY)
- return v4l2_subdev_state_get_format(sd_state,
- pad);
+ return v4l2_subdev_state_get_format(sd_state, pad, stream);
- return &tpg->fmt;
+ return &tpg->fmt[stream];
}
static void tpg_try_format(struct tpg_device *tpg,
@@ -282,7 +338,7 @@ static int tpg_get_format(struct v4l2_subdev *sd,
struct tpg_device *tpg = v4l2_get_subdevdata(sd);
struct v4l2_mbus_framefmt *format;
- format = __tpg_get_format(tpg, sd_state, fmt->pad, fmt->which);
+ format = __tpg_get_format(tpg, sd_state, fmt->pad, fmt->stream, fmt->which);
if (!format)
return -EINVAL;
@@ -299,10 +355,13 @@ static int tpg_set_format(struct v4l2_subdev *sd,
struct tpg_device *tpg = v4l2_get_subdevdata(sd);
struct v4l2_mbus_framefmt *format;
- format = __tpg_get_format(tpg, sd_state, fmt->pad, fmt->which);
+ format = __tpg_get_format(tpg, sd_state, fmt->pad, fmt->stream, fmt->which);
if (!format)
return -EINVAL;
+ if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE && tpg->enabled_streams)
+ return -EBUSY;
+
tpg_try_format(tpg, &fmt->format);
*format = fmt->format;
@@ -326,6 +385,69 @@ static int tpg_init_formats(struct v4l2_subdev *sd,
return tpg_set_format(sd, NULL, fh ? fh->state : NULL, &format);
}
+static int tpg_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+ struct v4l2_mbus_frame_desc *fd)
+{
+ struct tpg_device *tpg = v4l2_get_subdevdata(sd);
+ struct v4l2_subdev_state *state;
+ struct v4l2_subdev_route *route;
+ unsigned int i = 0;
+
+ if (pad != MSM_TPG_PAD_SRC)
+ return -EINVAL;
+
+ state = v4l2_subdev_lock_and_get_active_state(sd);
+ fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2;
+
+ for_each_active_route(&state->routing, route) {
+ const struct tpg_format_info *format;
+
+ format = tpg_get_fmt_entry(tpg->res->formats->formats,
+ tpg->res->formats->nformats,
+ tpg->fmt[route->source_stream].code);
+ if (IS_ERR(format))
+ continue;
+
+ fd->entry[i].stream = route->source_stream;
+ fd->entry[i].flags = 0;
+ fd->entry[i].bus.csi2.vc = route->source_stream;
+ fd->entry[i].bus.csi2.dt = format->data_type;
+ i++;
+ }
+
+ fd->num_entries = i;
+ v4l2_subdev_unlock_state(state);
+
+ return 0;
+}
+
+static int tpg_init_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *state)
+{
+ struct tpg_device *tpg = v4l2_get_subdevdata(sd);
+ struct v4l2_subdev_route routes[MSM_TPG_MAX_STREAMS];
+ struct v4l2_subdev_krouting routing = {
+ .num_routes = ARRAY_SIZE(routes),
+ .routes = routes,
+ };
+ struct v4l2_mbus_framefmt fmt = {
+ .code = MEDIA_BUS_FMT_SBGGR8_1X8,
+ .width = 1920,
+ .height = 1080,
+ };
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(routes); i++) {
+ routes[i].sink_pad = MSM_TPG_PAD_SRC;
+ routes[i].sink_stream = i;
+ routes[i].source_pad = MSM_TPG_PAD_SRC;
+ routes[i].source_stream = i;
+ routes[i].flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE;
+ tpg->fmt[i] = fmt;
+ }
+
+ return v4l2_subdev_set_routing_with_fmt(sd, state, &routing, &fmt);
+}
+
static int tpg_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct tpg_device *tpg = container_of(ctrl->handler,
@@ -433,16 +555,36 @@ static const struct v4l2_subdev_pad_ops tpg_pad_ops = {
.set_fmt = tpg_set_format,
};
+static const struct v4l2_subdev_pad_ops tpg_streams_pad_ops = {
+ .enum_mbus_code = tpg_enum_mbus_code,
+ .enum_frame_size = tpg_enum_frame_size,
+ .get_fmt = tpg_get_format,
+ .set_fmt = tpg_set_format,
+ .get_frame_desc = tpg_get_frame_desc,
+ .enable_streams = tpg_pad_enable_streams,
+ .disable_streams = tpg_pad_disable_streams,
+};
+
static const struct v4l2_subdev_ops tpg_v4l2_ops = {
.core = &tpg_core_ops,
.video = &tpg_video_ops,
.pad = &tpg_pad_ops,
};
+static const struct v4l2_subdev_ops tpg_streams_v4l2_ops = {
+ .core = &tpg_core_ops,
+ .video = &tpg_video_ops,
+ .pad = &tpg_streams_pad_ops,
+};
+
static const struct v4l2_subdev_internal_ops tpg_v4l2_internal_ops = {
.open = tpg_init_formats,
};
+static const struct v4l2_subdev_internal_ops tpg_streams_internal_ops = {
+ .init_state = tpg_init_state,
+};
+
static const struct media_entity_operations tpg_media_ops = {
.link_setup = tpg_link_setup,
.link_validate = v4l2_subdev_link_validate,
@@ -453,12 +595,15 @@ int msm_tpg_register_entity(struct tpg_device *tpg,
{
struct v4l2_subdev *sd = &tpg->subdev;
struct device *dev = tpg->camss->dev;
+ bool streams_api = tpg->camss->res->streams_enable;
int ret;
- v4l2_subdev_init(sd, &tpg_v4l2_ops);
- sd->internal_ops = &tpg_v4l2_internal_ops;
+ v4l2_subdev_init(sd, streams_api ? &tpg_streams_v4l2_ops : &tpg_v4l2_ops);
+ sd->internal_ops = streams_api ? &tpg_streams_internal_ops : &tpg_v4l2_internal_ops;
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
V4L2_SUBDEV_FL_HAS_EVENTS;
+ if (streams_api)
+ sd->flags |= V4L2_SUBDEV_FL_STREAMS;
snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d",
"msm_tpg", tpg->id);
sd->grp_id = TPG_GRP_ID;
@@ -497,15 +642,27 @@ int msm_tpg_register_entity(struct tpg_device *tpg,
goto free_ctrl;
}
+ if (streams_api) {
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret) {
+ dev_err(dev, "Failed to finalize subdev: %d\n", ret);
+ goto media_cleanup;
+ }
+ }
+
ret = v4l2_device_register_subdev(v4l2_dev, sd);
if (ret < 0) {
dev_err(dev, "Failed to register subdev: %d\n", ret);
- media_entity_cleanup(&sd->entity);
- goto free_ctrl;
+ goto subdev_cleanup;
}
return 0;
+subdev_cleanup:
+ if (streams_api)
+ v4l2_subdev_cleanup(sd);
+media_cleanup:
+ media_entity_cleanup(&sd->entity);
free_ctrl:
v4l2_ctrl_handler_free(&tpg->ctrls);
@@ -515,6 +672,8 @@ int msm_tpg_register_entity(struct tpg_device *tpg,
void msm_tpg_unregister_entity(struct tpg_device *tpg)
{
v4l2_device_unregister_subdev(&tpg->subdev);
+ if (tpg->camss->res->streams_enable)
+ v4l2_subdev_cleanup(&tpg->subdev);
media_entity_cleanup(&tpg->subdev.entity);
v4l2_ctrl_handler_free(&tpg->ctrls);
}
diff --git a/drivers/media/platform/qcom/camss/camss-tpg.h b/drivers/media/platform/qcom/camss/camss-tpg.h
index 7fb35a97dd06..5a6e9e726716 100644
--- a/drivers/media/platform/qcom/camss/camss-tpg.h
+++ b/drivers/media/platform/qcom/camss/camss-tpg.h
@@ -26,8 +26,7 @@
#define ENCODE_FORMAT_UNCOMPRESSED_24_BIT 0x7
#define MSM_TPG_PAD_SRC 0
-#define MSM_TPG_ACTIVE_VC 0
-#define MSM_TPG_ACTIVE_DT 0
+#define MSM_TPG_MAX_STREAMS 4
#define TPG_MIN_WIDTH 1
#define TPG_MIN_HEIGHT 1
@@ -89,11 +88,12 @@ struct tpg_device {
struct camss_clock *clock;
int nclocks;
struct tpg_testgen_config testgen;
- struct v4l2_mbus_framefmt fmt;
+ struct v4l2_mbus_framefmt fmt[MSM_TPG_MAX_STREAMS];
struct v4l2_ctrl_handler ctrls;
struct v4l2_ctrl *testgen_mode;
const struct tpg_subdev_resources *res;
u32 hw_version;
+ u64 enabled_streams;
};
struct camss_subdev_resources;
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 08/12] media: qcom: camss: Add streams API support for VFE
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (6 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 07/12] media: qcom: camss: Add streams API support in tpg subdev Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 09/12] media: qcom: camss: Add streams API support in camss-video Gjorgji Rosikopulos
` (3 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Implement the V4L2 subdev streams API (enable_streams/disable_streams)
on VFE lines, selected per SoC via camss->res->streams_enable.
VFE lines are inherently single-consumer (vfe_link_setup() enforces
one link per pad, and each line exposes only the implicit stream 0 of
a non-streams subdev), so no local refcount is needed. Local and
remote teardown are both attempted unconditionally on disable, on a
best-effort basis: a failure on either side is logged and does not
skip the other side's teardown, since there is no way to roll back a
partially disabled pipeline.
Co-developed-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss-vfe.c | 119 +++++++++++++++++-
1 file changed, 117 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
index da373024c847..31ee3a0d3717 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -1996,6 +1996,104 @@ static const struct v4l2_subdev_ops vfe_v4l2_ops = {
.pad = &vfe_pad_ops,
};
+/*
+ * vfe_pad_enable_streams - Enable one or more streams on the source pad
+ * @sd: VFE V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of streams to enable
+ *
+ * VFE lines are inherently single-consumer (vfe_link_setup() enforces one
+ * link per pad, and each line exposes only the implicit stream 0 of a
+ * non-streams subdev), so no local refcount is needed here.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int vfe_pad_enable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct vfe_line *line = v4l2_get_subdevdata(sd);
+ struct vfe_device *vfe = to_vfe(line);
+ struct media_pad *sink_pad = &line->pads[MSM_VFE_PAD_SINK];
+ struct media_pad *remote_pad = media_pad_remote_pad_first(sink_pad);
+ int ret;
+
+ line->output.state = VFE_OUTPUT_RESERVED;
+ ret = vfe->res->hw_ops->vfe_enable(line);
+ if (ret)
+ return ret;
+
+ if (remote_pad) {
+ ret = v4l2_subdev_enable_streams(media_entity_to_v4l2_subdev(remote_pad->entity),
+ remote_pad->index, BIT_ULL(0));
+ if (ret) {
+ vfe->res->hw_ops->vfe_disable(line);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * vfe_pad_disable_streams - Disable one or more streams on the source pad
+ * @sd: VFE V4L2 subdevice
+ * @state: V4L2 subdevice state
+ * @pad: Pad number
+ * @streams_mask: Bitmask of streams to disable
+ *
+ * Local and remote teardown are both attempted unconditionally on a
+ * best-effort basis, matching the convention used by other streams-API
+ * drivers (e.g. dw-mipi-csi2rx, ds90ub960, cdns-csi2rx): a failure on
+ * either side is logged and does not skip the other side's teardown, since
+ * there is no way to roll back a partially disabled pipeline. If the local
+ * disable also failed, its error takes precedence in the return value.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int vfe_pad_disable_streams(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
+ u32 pad, u64 streams_mask)
+{
+ struct vfe_line *line = v4l2_get_subdevdata(sd);
+ struct vfe_device *vfe = to_vfe(line);
+ struct media_pad *sink_pad = &line->pads[MSM_VFE_PAD_SINK];
+ struct media_pad *remote_pad = media_pad_remote_pad_first(sink_pad);
+ int ret;
+
+ ret = vfe->res->hw_ops->vfe_disable(line);
+
+ if (remote_pad) {
+ struct v4l2_subdev *remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+ int remote_ret;
+
+ remote_ret = v4l2_subdev_disable_streams(remote_sd, remote_pad->index, BIT_ULL(0));
+ if (remote_ret) {
+ dev_err(vfe->camss->dev,
+ "Failed to disable stream on remote pad: %d\n", remote_ret);
+ if (!ret)
+ ret = remote_ret;
+ }
+ }
+
+ return ret;
+}
+
+static const struct v4l2_subdev_pad_ops vfe_streams_pad_ops = {
+ .enum_mbus_code = vfe_enum_mbus_code,
+ .enum_frame_size = vfe_enum_frame_size,
+ .get_fmt = vfe_get_format,
+ .set_fmt = vfe_set_format,
+ .get_selection = vfe_get_selection,
+ .set_selection = vfe_set_selection,
+ .enable_streams = vfe_pad_enable_streams,
+ .disable_streams = vfe_pad_disable_streams,
+};
+
+static const struct v4l2_subdev_ops vfe_streams_v4l2_ops = {
+ .core = &vfe_core_ops,
+ .pad = &vfe_streams_pad_ops,
+};
+
static const struct v4l2_subdev_internal_ops vfe_v4l2_internal_ops = {
.open = vfe_init_formats,
};
@@ -2067,6 +2165,7 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
struct v4l2_subdev *sd;
struct media_pad *pads;
struct camss_video *video_out;
+ bool streams_api = vfe->camss->res->streams_enable;
int ret;
int i;
@@ -2077,7 +2176,7 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
pads = vfe->line[i].pads;
video_out = &vfe->line[i].video_out;
- v4l2_subdev_init(sd, &vfe_v4l2_ops);
+ v4l2_subdev_init(sd, streams_api ? &vfe_streams_v4l2_ops : &vfe_v4l2_ops);
sd->internal_ops = &vfe_v4l2_internal_ops;
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
if (i == VFE_LINE_PIX && vfe->res->is_lite == false)
@@ -2107,10 +2206,18 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
goto error_init;
}
+ if (streams_api) {
+ ret = v4l2_subdev_init_finalize(sd);
+ if (ret) {
+ dev_err(dev, "Failed to finalize subdev: %d\n", ret);
+ goto error_reg_subdev;
+ }
+ }
+
ret = v4l2_device_register_subdev(v4l2_dev, sd);
if (ret < 0) {
dev_err(dev, "Failed to register subdev: %d\n", ret);
- goto error_reg_subdev;
+ goto error_subdev_cleanup;
}
video_out->ops = &vfe->video_ops;
@@ -2154,6 +2261,10 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
error_reg_video:
v4l2_device_unregister_subdev(sd);
+error_subdev_cleanup:
+ if (streams_api)
+ v4l2_subdev_cleanup(sd);
+
error_reg_subdev:
media_entity_cleanup(&sd->entity);
@@ -2164,6 +2275,8 @@ int msm_vfe_register_entities(struct vfe_device *vfe,
msm_video_unregister(video_out);
v4l2_device_unregister_subdev(sd);
+ if (streams_api)
+ v4l2_subdev_cleanup(sd);
media_entity_cleanup(&sd->entity);
}
@@ -2187,6 +2300,8 @@ void msm_vfe_unregister_entities(struct vfe_device *vfe)
msm_video_unregister(video_out);
v4l2_device_unregister_subdev(sd);
+ if (vfe->camss->res->streams_enable)
+ v4l2_subdev_cleanup(sd);
media_entity_cleanup(&sd->entity);
}
}
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 09/12] media: qcom: camss: Add streams API support in camss-video
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (7 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 08/12] media: qcom: camss: Add streams API support for VFE Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 10/12] media: qcom: camss: Enable streams API on SM8250 Gjorgji Rosikopulos
` (2 subsequent siblings)
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Prefer the streams API when starting/stopping the capture pipeline:
if the subdev directly connected to the video device's pad supports
.enable_streams/.disable_streams, use it instead of walking the whole
subdev chain and calling .s_stream() on each one.
The legacy walk is kept as a fallback (video_start/stop_streaming_legacy())
for subdevs that do not implement the streams API, so platforms that
have not opted in keep working unchanged.
Co-developed-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
.../media/platform/qcom/camss/camss-video.c | 119 ++++++++++++++----
1 file changed, 94 insertions(+), 25 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c
index 0852eb6f1315..7f7212996c4a 100644
--- a/drivers/media/platform/qcom/camss/camss-video.c
+++ b/drivers/media/platform/qcom/camss/camss-video.c
@@ -249,26 +249,27 @@ static int video_prepare_streaming(struct vb2_queue *q)
return ret;
}
-static int video_start_streaming(struct vb2_queue *q, unsigned int count)
+/*
+ * video_start_streaming_legacy - Walk the whole subdev chain and enable
+ * streaming via .s_stream()
+ * @video: Video device
+ * @sink_pad: Video device's own (single) pad
+ *
+ * Fallback used when the subdev directly connected to @sink_pad has no
+ * .enable_streams op. Mirrors the pre-streams-API pipeline walk: each
+ * subdev's pad 0 is assumed to be its sink pad, and streaming is started
+ * one subdev at a time via .s_stream() rather than the streams API.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int video_start_streaming_legacy(struct camss_video *video,
+ struct media_pad *sink_pad)
{
- struct camss_video *video = vb2_get_drv_priv(q);
- struct video_device *vdev = &video->vdev;
- struct media_entity *entity;
+ struct media_entity *entity = sink_pad->entity;
struct media_pad *pad;
struct v4l2_subdev *subdev;
int ret;
- ret = video_device_pipeline_alloc_start(vdev);
- if (ret < 0) {
- dev_err(video->camss->dev, "Failed to start media pipeline: %d\n", ret);
- goto flush_buffers;
- }
-
- ret = video_check_format(video);
- if (ret < 0)
- goto error;
-
- entity = &vdev->entity;
while (1) {
pad = &entity->pads[0];
if (!(pad->flags & MEDIA_PAD_FL_SINK))
@@ -283,6 +284,42 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)
ret = v4l2_subdev_call(subdev, video, s_stream, 1);
if (ret < 0 && ret != -ENOIOCTLCMD)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int video_start_streaming(struct vb2_queue *q, unsigned int count)
+{
+ struct camss_video *video = vb2_get_drv_priv(q);
+ struct video_device *vdev = &video->vdev;
+ struct media_pad *sink_pad = &vdev->entity.pads[0];
+ struct media_pad *src_pad;
+ struct v4l2_subdev *subdev = NULL;
+ int ret;
+
+ ret = video_device_pipeline_alloc_start(vdev);
+ if (ret < 0) {
+ dev_err(video->camss->dev, "Failed to start media pipeline: %d\n", ret);
+ goto flush_buffers;
+ }
+
+ ret = video_check_format(video);
+ if (ret < 0)
+ goto error;
+
+ src_pad = media_pad_remote_pad_first(sink_pad);
+ if (src_pad && is_media_entity_v4l2_subdev(src_pad->entity))
+ subdev = media_entity_to_v4l2_subdev(src_pad->entity);
+
+ if (subdev && v4l2_subdev_has_op(subdev, pad, enable_streams)) {
+ ret = v4l2_subdev_enable_streams(subdev, src_pad->index, BIT_ULL(0));
+ if (ret < 0)
+ goto error;
+ } else {
+ ret = video_start_streaming_legacy(video, sink_pad);
+ if (ret < 0)
goto error;
}
@@ -297,16 +334,27 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)
return ret;
}
-static void video_stop_streaming(struct vb2_queue *q)
+/*
+ * video_stop_streaming_legacy - Walk the whole subdev chain and disable
+ * streaming via .s_stream()
+ * @video: Video device
+ * @sink_pad: Video device's own (single) pad
+ *
+ * Fallback used when the subdev directly connected to @sink_pad has no
+ * .disable_streams op. Mirrors the pre-streams-API pipeline walk: each
+ * subdev's pad 0 is assumed to be its sink pad, and streaming is stopped
+ * one subdev at a time via .s_stream() rather than the streams API.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static int video_stop_streaming_legacy(struct camss_video *video,
+ struct media_pad *sink_pad)
{
- struct camss_video *video = vb2_get_drv_priv(q);
- struct video_device *vdev = &video->vdev;
- struct media_entity *entity;
+ struct media_entity *entity = sink_pad->entity;
struct media_pad *pad;
struct v4l2_subdev *subdev;
int ret;
- entity = &vdev->entity;
while (1) {
pad = &entity->pads[0];
if (!(pad->flags & MEDIA_PAD_FL_SINK))
@@ -320,13 +368,34 @@ static void video_stop_streaming(struct vb2_queue *q)
subdev = media_entity_to_v4l2_subdev(entity);
ret = v4l2_subdev_call(subdev, video, s_stream, 0);
-
- if (ret) {
- dev_err(video->camss->dev, "Video pipeline stop failed: %d\n", ret);
- return;
- }
+ if (ret)
+ return ret;
}
+ return 0;
+}
+
+static void video_stop_streaming(struct vb2_queue *q)
+{
+ struct camss_video *video = vb2_get_drv_priv(q);
+ struct video_device *vdev = &video->vdev;
+ struct media_pad *sink_pad = &vdev->entity.pads[0];
+ struct media_pad *src_pad;
+ struct v4l2_subdev *subdev = NULL;
+ int ret;
+
+ src_pad = media_pad_remote_pad_first(sink_pad);
+ if (src_pad && is_media_entity_v4l2_subdev(src_pad->entity))
+ subdev = media_entity_to_v4l2_subdev(src_pad->entity);
+
+ if (subdev && v4l2_subdev_has_op(subdev, pad, disable_streams))
+ ret = v4l2_subdev_disable_streams(subdev, src_pad->index, BIT_ULL(0));
+ else
+ ret = video_stop_streaming_legacy(video, sink_pad);
+
+ if (ret)
+ dev_err(video->camss->dev, "Video pipeline stop failed: %d\n", ret);
+
video_device_pipeline_stop(vdev);
video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR);
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 10/12] media: qcom: camss: Enable streams API on SM8250
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (8 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 09/12] media: qcom: camss: Add streams API support in camss-video Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 11/12] media: qcom: camss: Enable streams API on SA8775P Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 12/12] media: qcom: camss: Enable streams API on SC7280 Gjorgji Rosikopulos
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Set streams_enable on sm8250_resources so CSIPHY, CSID, and VFE
register their streams-API subdev ops and probe with
V4L2_SUBDEV_FL_STREAMS instead of the legacy .s_stream() path.
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
index ac12960264ad..77fa80dd79c4 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -5790,6 +5790,7 @@ static const struct camss_resources sm8250_resources = {
.csiphy_num = ARRAY_SIZE(csiphy_res_8250),
.csid_num = ARRAY_SIZE(csid_res_8250),
.vfe_num = ARRAY_SIZE(vfe_res_8250),
+ .streams_enable = true,
};
static const struct camss_resources sc8280xp_resources = {
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 11/12] media: qcom: camss: Enable streams API on SA8775P
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (9 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 10/12] media: qcom: camss: Enable streams API on SM8250 Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
2026-11-25 18:23 ` [PATCH RESEND v2 12/12] media: qcom: camss: Enable streams API on SC7280 Gjorgji Rosikopulos
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
Set streams_enable on sa8775p_resources so CSIPHY, CSID, and VFE
register their streams-API subdev ops and probe with
V4L2_SUBDEV_FL_STREAMS instead of the legacy .s_stream() path, same
as already done for SM8250.
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
index 77fa80dd79c4..e444c29fe847 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -5719,6 +5719,7 @@ static const struct camss_resources sa8775p_resources = {
.csid_num = ARRAY_SIZE(csid_res_8775p),
.vfe_num = ARRAY_SIZE(vfe_res_8775p),
.icc_path_num = ARRAY_SIZE(icc_res_sa8775p),
+ .streams_enable = true,
};
static const struct camss_resources sdm660_resources = {
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH RESEND v2 12/12] media: qcom: camss: Enable streams API on SC7280
2026-11-25 18:23 [PATCH RESEND v2 00/12] media: qcom: camss: add V4L2 subdev streams API support Gjorgji Rosikopulos
` (10 preceding siblings ...)
2026-11-25 18:23 ` [PATCH RESEND v2 11/12] media: qcom: camss: Enable streams API on SA8775P Gjorgji Rosikopulos
@ 2026-11-25 18:23 ` Gjorgji Rosikopulos
11 siblings, 0 replies; 14+ messages in thread
From: Gjorgji Rosikopulos @ 2026-11-25 18:23 UTC (permalink / raw)
To: Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media, linux-arm-msm
Cc: Vladimir Zapolskiy, Loic Poulain, linux-kernel, Hitesh Patel,
Atanas Filipov, Jigarkumar Zala, Gjorgji Rosikopulos
From: Hitesh Patel <hitesh@ebytelogic.com>
Tested on RB3 Gen2 (QCS6490) with two GMSL cameras behind a MAX9296A
deserializer, one camera per CSI-2 port, so two independent pipelines
share the deserializer subdev: both cameras stream concurrently, and
each can be started and stopped repeatedly while the other keeps
streaming, without the WARN in call_s_stream() and without the second
pipeline tearing the first one down that the legacy s_stream path
produces. The CSID test pattern generator keeps working.
SC7280 has no camss child node named "phy", so camss_detect_legacy_phy()
puts it in legacy PHY mode; the streams path dispatches the lane
enable/disable accordingly.
Signed-off-by: Hitesh Patel <hitesh@ebytelogic.com>
Signed-off-by: Gjorgji Rosikopulos <gjorgji.rosikopulos@oss.qualcomm.com>
---
drivers/media/platform/qcom/camss/camss.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
index e444c29fe847..60d3d21f6548 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -5819,6 +5819,7 @@ static const struct camss_resources sc7280_resources = {
.csiphy_num = ARRAY_SIZE(csiphy_res_7280),
.csid_num = ARRAY_SIZE(csid_res_7280),
.vfe_num = ARRAY_SIZE(vfe_res_7280),
+ .streams_enable = true,
};
static const struct camss_resources sm8550_resources = {
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread