ath79: add support for COMFAST CF-E130N v2
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0686-media-bcm2835-unicam-add-media-controller-support.patch
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
5
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
8 V4L2 core.
9
10 Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
11 ---
12 drivers/media/platform/bcm2835/Kconfig | 2 +-
13 .../media/platform/bcm2835/bcm2835-unicam.c | 46 ++++++++++++++++++-
14 2 files changed, 45 insertions(+), 3 deletions(-)
15
16 --- a/drivers/media/platform/bcm2835/Kconfig
17 +++ b/drivers/media/platform/bcm2835/Kconfig
18 @@ -2,7 +2,7 @@
19
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
26 select V4L2_FWNODE
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 {
30 struct clk *clock;
31 /* V4l2 device */
32 struct v4l2_device v4l2_dev;
33 + struct media_device mdev;
34 + struct media_pad pad;
35 +
36 /* parent device */
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;
41
42 video_set_drvdata(vdev, unicam);
43 + vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT;
44 +
45 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
46 if (ret) {
47 unicam_err(unicam, "Unable to register video device.\n");
48 @@ -1953,6 +1958,16 @@ static int unicam_probe_complete(struct
49 return ret;
50 }
51
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);
56 + if (ret) {
57 + unicam_err(unicam, "Unable to create pad links.\n");
58 + video_unregister_device(&unicam->video_dev);
59 + return ret;
60 + }
61 +
62 return 0;
63 }
64
65 @@ -2155,18 +2170,38 @@ static int unicam_probe(struct platform_
66 return -EINVAL;
67 }
68
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;
76 +
77 + media_entity_pads_init(&unicam->video_dev.entity, 1, &unicam->pad);
78 + media_device_init(&unicam->mdev);
79 +
80 + unicam->v4l2_dev.mdev = &unicam->mdev;
81 +
82 ret = v4l2_device_register(&pdev->dev, &unicam->v4l2_dev);
83 if (ret) {
84 unicam_err(unicam,
85 "Unable to register v4l2 device.\n");
86 - return ret;
87 + goto media_cleanup;
88 + }
89 +
90 + ret = media_device_register(&unicam->mdev);
91 + if (ret < 0) {
92 + unicam_err(unicam,
93 + "Unable to register media-controller device.\n");
94 + goto probe_out_v4l2_unregister;
95 }
96
97 /* Reserve space for the controls */
98 hdl = &unicam->ctrl_handler;
99 ret = v4l2_ctrl_handler_init(hdl, 16);
100 if (ret < 0)
101 - goto probe_out_v4l2_unregister;
102 + goto media_unregister;
103 unicam->v4l2_dev.ctrl_handler = hdl;
104
105 /* set the driver data in platform device */
106 @@ -2185,8 +2220,13 @@ static int unicam_probe(struct platform_
107
108 free_hdl:
109 v4l2_ctrl_handler_free(hdl);
110 +media_unregister:
111 + media_device_unregister(&unicam->mdev);
112 probe_out_v4l2_unregister:
113 v4l2_device_unregister(&unicam->v4l2_dev);
114 +media_cleanup:
115 + media_device_cleanup(&unicam->mdev);
116 +
117 return ret;
118 }
119
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);
126
127 return 0;
128 }