1 From 06cd9857f8faa63321506a75988c475906a32970 Mon Sep 17 00:00:00 2001
2 From: Kieran Bingham <kieran.bingham@ideasonboard.com>
3 Date: Wed, 20 Mar 2019 12:54:47 +0000
4 Subject: [PATCH] media: bcm2835: unicam: add media controller support
6 Add a media controller device node to represent the Unicam device.
7 The attached sensor will be automatically added to the media graph by
10 Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
12 drivers/media/platform/bcm2835/Kconfig | 2 +-
13 .../media/platform/bcm2835/bcm2835-unicam.c | 46 ++++++++++++++++++-
14 2 files changed, 45 insertions(+), 3 deletions(-)
16 --- a/drivers/media/platform/bcm2835/Kconfig
17 +++ b/drivers/media/platform/bcm2835/Kconfig
20 config VIDEO_BCM2835_UNICAM
21 tristate "Broadcom BCM2835 Unicam video capture driver"
22 - depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
23 + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
24 depends on ARCH_BCM2835 || COMPILE_TEST
25 select VIDEOBUF2_DMA_CONTIG
27 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
28 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
29 @@ -314,6 +314,9 @@ struct unicam_device {
32 struct v4l2_device v4l2_dev;
33 + struct media_device mdev;
34 + struct media_pad pad;
37 struct platform_device *pdev;
38 /* subdevice async Notifier */
39 @@ -1912,6 +1915,8 @@ static int unicam_probe_complete(struct
40 unicam->v4l2_dev.ctrl_handler = NULL;
42 video_set_drvdata(vdev, unicam);
43 + vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT;
45 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
47 unicam_err(unicam, "Unable to register video device.\n");
48 @@ -1953,6 +1958,16 @@ static int unicam_probe_complete(struct
52 + ret = media_create_pad_link(&unicam->sensor->entity, 0,
53 + &unicam->video_dev.entity, 0,
54 + MEDIA_LNK_FL_ENABLED |
55 + MEDIA_LNK_FL_IMMUTABLE);
57 + unicam_err(unicam, "Unable to create pad links.\n");
58 + video_unregister_device(&unicam->video_dev);
65 @@ -2155,18 +2170,38 @@ static int unicam_probe(struct platform_
69 + unicam->mdev.dev = &pdev->dev;
70 + strscpy(unicam->mdev.model, UNICAM_MODULE_NAME,
71 + sizeof(unicam->mdev.model));
72 + strscpy(unicam->mdev.serial, "", sizeof(unicam->mdev.serial));
73 + snprintf(unicam->mdev.bus_info, sizeof(unicam->mdev.bus_info),
74 + "platform:%s", pdev->name);
75 + unicam->mdev.hw_revision = 1;
77 + media_entity_pads_init(&unicam->video_dev.entity, 1, &unicam->pad);
78 + media_device_init(&unicam->mdev);
80 + unicam->v4l2_dev.mdev = &unicam->mdev;
82 ret = v4l2_device_register(&pdev->dev, &unicam->v4l2_dev);
85 "Unable to register v4l2 device.\n");
90 + ret = media_device_register(&unicam->mdev);
93 + "Unable to register media-controller device.\n");
94 + goto probe_out_v4l2_unregister;
97 /* Reserve space for the controls */
98 hdl = &unicam->ctrl_handler;
99 ret = v4l2_ctrl_handler_init(hdl, 16);
101 - goto probe_out_v4l2_unregister;
102 + goto media_unregister;
103 unicam->v4l2_dev.ctrl_handler = hdl;
105 /* set the driver data in platform device */
106 @@ -2185,8 +2220,13 @@ static int unicam_probe(struct platform_
109 v4l2_ctrl_handler_free(hdl);
111 + media_device_unregister(&unicam->mdev);
112 probe_out_v4l2_unregister:
113 v4l2_device_unregister(&unicam->v4l2_dev);
115 + media_device_cleanup(&unicam->mdev);
120 @@ -2204,6 +2244,8 @@ static int unicam_remove(struct platform
121 video_unregister_device(&unicam->video_dev);
122 if (unicam->sensor_config)
123 v4l2_subdev_free_pad_config(unicam->sensor_config);
124 + media_device_unregister(&unicam->mdev);
125 + media_device_cleanup(&unicam->mdev);