[PATCH v2 2/9] media: synopsys: hdmirx: add media entity for video capture device
From: Sascha Hauer
Date: Thu Sep 24 2026 - 08:08:25 EST
From: Gerald Loacker <gerald.loacker@xxxxxxxxxxxxxx>
Register the video device as a media entity with a sink pad to integrate
it into the media controller topology. This allows the capture device to
be properly represented in the media graph and enables userspace to
discover the device capabilities through the MC API.
The sink pad indicates that this entity receives data (HDMI video stream)
which is then made available through the V4L2 video capture interface.
Initialize the pad before registering the video device. The previous patch
gave v4l2_dev an mdev, so video_register_device() already registers the
entity, and doing it the other way round would hand
media_device_register_entity() an entity with no pads yet.
Signed-off-by: Gerald Loacker <gerald.loacker@xxxxxxxxxxxxxx>
Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
.../media/platform/synopsys/hdmirx/snps_hdmirx.c | 26 ++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
index f51a1619b71ec..11a9b16586a57 100644
--- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
+++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
@@ -125,6 +125,7 @@ struct snps_hdmirx_dev {
struct hdmirx_stream stream;
struct v4l2_device v4l2_dev;
struct media_device mdev;
+ struct media_pad pad;
struct v4l2_ctrl_handler hdl;
struct v4l2_ctrl *detect_tx_5v_ctrl;
struct v4l2_ctrl *rgb_range;
@@ -2751,15 +2752,29 @@ static int hdmirx_probe(struct platform_device *pdev)
stream = &hdmirx_dev->stream;
stream->hdmirx_dev = hdmirx_dev;
+
+ hdmirx_dev->pad.flags = MEDIA_PAD_FL_SINK;
+ ret = media_entity_pads_init(&stream->vdev.entity, 1, &hdmirx_dev->pad);
+ if (ret) {
+ dev_err_probe(dev, ret, "media entity pads initialization failed\n");
+ goto err_unreg_v4l2_dev;
+ }
+
ret = hdmirx_register_stream_vdev(stream);
if (ret < 0) {
dev_err_probe(dev, ret, "video device registration failed\n");
- goto err_unreg_v4l2_dev;
+ goto err_cleanup_entity;
+ }
+
+ ret = media_device_register(&hdmirx_dev->mdev);
+ if (ret) {
+ dev_err_probe(dev, ret, "media device registration failed\n");
+ goto err_unreg_video_dev;
}
ret = hdmirx_register_cec(hdmirx_dev, pdev);
if (ret)
- goto err_unreg_video_dev;
+ goto err_unreg_media;
hdmirx_load_default_edid(hdmirx_dev);
@@ -2774,8 +2789,12 @@ static int hdmirx_probe(struct platform_device *pdev)
return 0;
+err_unreg_media:
+ media_device_unregister(&hdmirx_dev->mdev);
err_unreg_video_dev:
vb2_video_unregister_device(&hdmirx_dev->stream.vdev);
+err_cleanup_entity:
+ media_entity_cleanup(&hdmirx_dev->stream.vdev.entity);
err_unreg_v4l2_dev:
v4l2_device_unregister(&hdmirx_dev->v4l2_dev);
media_device_cleanup(&hdmirx_dev->mdev);
@@ -2799,7 +2818,10 @@ static void hdmirx_remove(struct platform_device *pdev)
hdmirx_disable_irq(dev);
+ media_device_unregister(&hdmirx_dev->mdev);
+
vb2_video_unregister_device(&hdmirx_dev->stream.vdev);
+ media_entity_cleanup(&hdmirx_dev->stream.vdev.entity);
v4l2_ctrl_handler_free(&hdmirx_dev->hdl);
v4l2_device_unregister(&hdmirx_dev->v4l2_dev);
media_device_cleanup(&hdmirx_dev->mdev);
--
2.47.3