media: qcom: camss: fix VFE/CSID/video error handling and register bugs
Subsystems (4)
v2 cover media: qcom: camss: fix VFE/CSID/video error handling and register bugs
This series fixes five bugs in the Qualcomm CAMSS driver found during Titan 175 (SC8180X) camera bring-up and code review:
1. vfe-17x: Check VFE_IRQ_STATUS_1 (status1) rather than VFE_IRQ_STATUS_0 (status0) against STATUS_1_RDI_SOF(i) in vfe_isr().
2. csid-gen2: Change enable to bool and use BIT(RDI_CFG0_ENABLE) to explicitly set or clear bit 31 in __csid_configure_rdi_stream().
3. csid: Release the parent device reference via parent_dev_ops->put() on all csid_set_power() power-on failure paths.
4. vfe: Destroy power_lock and stream_lock after unregistering VFE subdevices and video nodes in msm_vfe_unregister_entities().
5. video: Factor subdevice stream start/stop into a shared helper using v4l2_subdev_enable_streams()/v4l2_subdev_disable_streams(), unwinding partial start failures and continuing teardown on stop errors.
---
Changes in v2:
- Patch 1/5: Drop Fixes tag since vfe_isr_sof() is currently a no-op on vfe-17x (Loic); collect Reviewed-by tags from Loic and Bryan.
- Patch 2/5: Change enable parameter to bool (Loic), drop irrelevant sign-bit remark from commit message, and add Bryan's Reviewed-by (Bryan).
- Patch 3/5: Collect Reviewed-by tags from Loic and Bryan.
- Patch 4/5: Collect Reviewed-by tags from Loic and Bryan.
- Patch 5/5: Rework into a shared camss_subdev_pipeline_set_stream() helper using v4l2_subdev_enable_streams()/v4l2_subdev_disable_streams() and iterating entity sink pads rather than media_entity_remote_source_pad_unique() so entities with multiple active sink links (e.g. VFE with CSID + params) are handled cleanly (Loic). Dropped Bryan's v1 Reviewed-by due to rework.
- Link to v1: https://patch.msgid.link/[email protected]
---
Robert Ijtsma (5):
media: qcom: camss: vfe-17x: check status1 for RDI SOF interrupts
media: qcom: camss: csid-gen2: fix RDI enable bit manipulation
media: qcom: camss: csid: release parent device on power-on failure
media: qcom: camss: vfe: destroy mutexes after unregistering entities
media: qcom: camss: video: factor pipeline stream start/stop into helper
.../media/platform/qcom/camss/camss-csid-gen2.c | 8 +- drivers/media/platform/qcom/camss/camss-csid.c | 48 ++++----- drivers/media/platform/qcom/camss/camss-vfe-17x.c | 2 +- drivers/media/platform/qcom/camss/camss-vfe.c | 6 +- drivers/media/platform/qcom/camss/camss-video.c | 116 +++++++++++++-------- 5 files changed, 104 insertions(+), 76 deletions(-)
---
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
change-id: 20261122-camss-fixes-4a671ce21042
Best regards,
Signature · 1 line
Robert Ijtsma <[email protected]>
PATCH v2 1/5 media: qcom: camss: vfe-17x: check status1 for RDI SOF interrupts
In vfe_isr(), STATUS_1_RDI_SOF(i) is a bitmask for VFE_IRQ_STATUS_1 (status1), not VFE_IRQ_STATUS_0 (status0). Checking status0 instead tests the unrelated STATUS_0_IMAGE_COMPOSITE_DONE bits (27..30).
Check status1 against STATUS_1_RDI_SOF(i) as intended.
--- drivers/media/platform/qcom/camss/camss-vfe-17x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-vfe-17x.c +1 -1
@@ -356,7 +356,7 @@ static irqreturn_t vfe_isr(int irq, void *dev) vfe->isr_ops.reg_update (vfe, i);for (i =VFE_LINE_RDI0 ; i < vfe->res->line_num; i++) -if (status0 &STATUS_1_RDI_SOF (i)) +if (status1 &STATUS_1_RDI_SOF (i)) vfe->isr_ops.sof (vfe, i);for (i =0 ; i <MSM_VFE_COMPOSITE_IRQ_NUM ; i++)
Signature · 1 line
2.56.0
PATCH v2 2/5 media: qcom: camss: csid-gen2: fix RDI enable bit manipulation
In reply to Robert IjtsmaIn __csid_configure_rdi_stream(), bitwise ORing enable << RDI_CFG0_ENABLE into val never clears the enable bit when enable is zero.
Change enable to bool and explicitly set or clear BIT(RDI_CFG0_ENABLE) depending on enable, matching camss-csid-680.c.
--- drivers/media/platform/qcom/camss/camss-csid-gen2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/camss/camss-csid-gen2.c +6 -2
@@ -253,7 +253,8 @@ static void __csid_configure_testgen(struct csid_device *csid, u8 enable, u8 porwritel_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,bool enable, +u8 port,u8 vc) {/* 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];
@@ -318,7 +319,10 @@ static void __csid_configure_rdi_stream(struct csid_device *csid, u8 enable, u8writel_relaxed (val, csid->base +CSID_RDI_CTRL (port)); val =readl_relaxed (csid->base +CSID_RDI_CFG0 (port)); - val |= enable <<RDI_CFG0_ENABLE ; +if (enable) + val |=BIT (RDI_CFG0_ENABLE ); +else + val &= ~BIT (RDI_CFG0_ENABLE );writel_relaxed (val, csid->base +CSID_RDI_CFG0 (port)); }
Signature · 1 line
2.56.0
PATCH v2 3/5 media: qcom: camss: csid: release parent device on power-on failure
In reply to Robert Ijtsmacsid_set_power() acquires a reference on the parent device via parent_dev_ops->get() before resuming runtime PM, enabling regulators and clocks, and resetting the CSID hardware. If any of these subsequent steps fail, the function returns without calling parent_dev_ops->put(), leaking the parent VFE power reference.
Consolidate the power-on error paths using goto labels and release the parent device reference on all failure paths.
--- drivers/media/platform/qcom/camss/camss-csid.c | 48 ++++++++++++-------------- 1 file changed, 22 insertions(+), 26 deletions(-)
drivers/media/platform/qcom/camss/camss-csid.c +22 -26
@@ -682,7 +682,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)struct csid_device *csid =v4l2_get_subdevdata (sd);struct camss *camss = csid->camss;struct device *dev = camss->dev; -int ret =0 ; +int ret;if (on) {/*
@@ -696,44 +696,28 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) ret =pm_runtime_resume_and_get (dev);if (ret <0 ) -return ret; + goto err_parent_put; ret =regulator_bulk_enable (csid->num_supplies, csid->supplies); -if (ret <0 ) { -pm_runtime_put_sync (dev); -return ret; - } +if (ret <0 ) + goto err_pm_put; ret =csid_set_clock_rates (csid); -if (ret <0 ) { -regulator_bulk_disable (csid->num_supplies, - csid->supplies); -pm_runtime_put_sync (dev); -return ret; - } +if (ret <0 ) + goto err_regulators_disable; ret =camss_enable_clocks (csid->nclocks, csid->clock, dev); -if (ret <0 ) { -regulator_bulk_disable (csid->num_supplies, - csid->supplies); -pm_runtime_put_sync (dev); -return ret; - } +if (ret <0 ) + goto err_regulators_disable; csid->phy.need_vc_update = true;enable_irq (csid->irq); ret = csid->res->hw_ops->reset (csid); -if (ret <0 ) { -disable_irq (csid->irq); -camss_disable_clocks (csid->nclocks, csid->clock); -regulator_bulk_disable (csid->num_supplies, - csid->supplies); -pm_runtime_put_sync (dev); -return ret; - } +if (ret <0 ) + goto err_reset; csid->res->hw_ops->hw_version (csid); }else {
@@ -745,6 +729,18 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) csid->res->parent_dev_ops->put (camss, csid->id); } +return 0 ; + +err_reset: +disable_irq (csid->irq); +camss_disable_clocks (csid->nclocks, csid->clock); +err_regulators_disable: +regulator_bulk_disable (csid->num_supplies, csid->supplies); +err_pm_put: +pm_runtime_put_sync (dev); +err_parent_put: + csid->res->parent_dev_ops->put (camss, csid->id); +return ret; }
Signature · 1 line
2.56.0
PATCH v2 4/5 media: qcom: camss: vfe: destroy mutexes after unregistering entities
In reply to Robert Ijtsmamsm_vfe_unregister_entities() destroys vfe->power_lock and vfe->stream_lock before unregistering the VFE video devices and V4L2 subdevices. Active userspace handles or concurrent teardown callbacks can still acquire these mutexes until the entities are unregistered.
Destroy power_lock and stream_lock after all VFE entities have been unregistered and cleaned up.
--- drivers/media/platform/qcom/camss/camss-vfe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe.c +3 -3
@@ -2168,9 +2168,6 @@ void msm_vfe_unregister_entities(struct vfe_device *vfe) {int i; -mutex_destroy (&vfe->power_lock); -mutex_destroy (&vfe->stream_lock); -for (i =0 ; i < vfe->res->line_num; i++) {struct v4l2_subdev *sd = &vfe->line[i].subdev;struct camss_video *video_out = &vfe->line[i].video_out;
@@ -2179,6 +2176,9 @@ void msm_vfe_unregister_entities(struct vfe_device *vfe)v4l2_device_unregister_subdev (sd);media_entity_cleanup (&sd->entity); } + +mutex_destroy (&vfe->power_lock); +mutex_destroy (&vfe->stream_lock); }bool vfe_is_lite (struct vfe_device *vfe)
Signature · 1 line
2.56.0
PATCH v2 5/5 media: qcom: camss: video: factor pipeline stream start/stop into helper
In reply to Robert IjtsmaIf a subdevice fails to start partway through video_start_streaming(), previously started subdevices earlier in the pipeline (such as the VFE and CSID) are never stopped, leaking VFE stream counts and write master reservations. Conversely, video_stop_streaming() returns early on the first subdevice stop error, leaving remaining upstream subdevices running and skipping media pipeline teardown and buffer flushing.
Factor pipeline stream state changes into a shared helper, camss_subdev_pipeline_set_stream(), using v4l2_subdev_enable_streams() and v4l2_subdev_disable_streams(). Unwind partial start failures by disabling the pipeline (-EALREADY skips subdevices that were never enabled), and continue stopping remaining subdevices if an error occurs during teardown.
Iterate over each entity's sink pads with media_pad_remote_pad_first() rather than media_entity_remote_source_pad_unique() so entities with multiple active sink links (such as a VFE fed by both a CSID subdevice and a parameters video device) do not fail uniqueness checks.
--- drivers/media/platform/qcom/camss/camss-video.c | 116 +++++++++++++++--------- 1 file changed, 72 insertions(+), 44 deletions(-)
drivers/media/platform/qcom/camss/camss-video.c +72 -44
@@ -7,12 +7,14 @@* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. * Copyright (C) 2015-2018 Linaro Ltd. */ +#include <linux/bits.h> #include <linux/slab.h> #include <media/media-entity.h> #include <media/v4l2-dev.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-mc.h> +#include <media/v4l2-subdev.h> #include <media/videobuf2-dma-sg.h> #include "camss-video.h"
@@ -249,13 +251,73 @@ static int video_prepare_streaming(struct vb2_queue *q)return ret; } +/* +* camss_subdev_pipeline_set_stream - Enable or disable subdevices in pipeline +* @video: CAMSS video device +* @entity: Media entity whose upstream subdevices are toggled +* @enable: true to enable streams, false to disable streams +* +* Walk upstream across all sink pads of @entity so entities with multiple +* active sink links (such as a VFE fed by both a CSID subdevice and a +* parameters video output node) do not fail uniqueness checks. +* +* Return: 0 on success, or the error code of the first subdevice that failed. +*/ +static int camss_subdev_pipeline_set_stream (struct camss_video *video, +struct media_entity *entity, +bool enable) +{ +struct media_pad *sink_pad; +int ret =0 ; + +media_entity_for_each_pad (entity, sink_pad) { +struct v4l2_subdev *subdev; +struct media_pad *pad; +int err; + +if (!(sink_pad->flags &MEDIA_PAD_FL_SINK )) +continue ; + + pad =media_pad_remote_pad_first (sink_pad); +if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) +continue ; + + subdev =media_entity_to_v4l2_subdev (pad->entity); +if (enable) + err =v4l2_subdev_enable_streams (subdev, pad->index, +BIT_ULL (0 )); +else + err =v4l2_subdev_disable_streams (subdev, pad->index, +BIT_ULL (0 )); + +if (err && err != -EALREADY && err != -ENOIOCTLCMD ) { +if (enable) +return err; + +dev_err (video->camss->dev, +"Failed to stop %s pad %u: %d\n" , + pad->entity->name, pad->index, err); +if (!ret) + ret = err; + } + + err =camss_subdev_pipeline_set_stream (video, pad->entity, + enable); +if (err) { +if (enable) +return err; +if (!ret) + ret = err; + } + } + +return ret; +} +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_entity *entity; -struct media_pad *pad; -struct v4l2_subdev *subdev;int ret; ret =video_device_pipeline_alloc_start (vdev);
@@ -268,26 +330,15 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)if (ret <0 ) goto error; - entity = &vdev->entity; -while (1 ) { - pad = &entity->pads[0 ]; -if (!(pad->flags &MEDIA_PAD_FL_SINK )) -break ; - - pad =media_pad_remote_pad_first (pad); -if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) -break ; - - entity = pad->entity; - subdev =media_entity_to_v4l2_subdev (entity); - - ret =v4l2_subdev_call (subdev, video, s_stream,1 ); -if (ret <0 && ret != -ENOIOCTLCMD ) - goto error; - } + ret =camss_subdev_pipeline_set_stream (video, &vdev->entity, true); +if (ret <0 ) + goto error_stop_subdevs;return 0 ; +error_stop_subdevs: +camss_subdev_pipeline_set_stream (video, &vdev->entity, false); + error:video_device_pipeline_stop (vdev);
@@ -301,31 +352,8 @@ 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_entity *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 )) -break ; - - pad =media_pad_remote_pad_first (pad); -if (!pad || !is_media_entity_v4l2_subdev (pad->entity)) -break ; - - entity = pad->entity; - 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 ; - } - } +camss_subdev_pipeline_set_stream (video, &vdev->entity, false);video_device_pipeline_stop (vdev);
Signature · 1 line
2.56.0