a42fa7dfe1cd4be9279f06e7240f5d37be94d247
[openwrt/staging/yousong.git] /
1 From d1ceb85b7c6c7c3eec8b424e0172c29e93a570f2 Mon Sep 17 00:00:00 2001
2 From: Kieran Bingham <kieran.bingham@ideasonboard.com>
3 Date: Wed, 20 Mar 2019 12:54:15 +0000
4 Subject: [PATCH] staging: bcm2835-codec: add media controller support
5
6 Provide a single media device to contain all of the bcm2835_codec
7 devices created.
8
9 Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
10 ---
11 .../vc04_services/bcm2835-codec/Kconfig | 2 +-
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 41 +++++++++++++++++--
13 2 files changed, 38 insertions(+), 5 deletions(-)
14
15 --- a/drivers/staging/vc04_services/bcm2835-codec/Kconfig
16 +++ b/drivers/staging/vc04_services/bcm2835-codec/Kconfig
17 @@ -1,6 +1,6 @@
18 config VIDEO_CODEC_BCM2835
19 tristate "BCM2835 Video codec support"
20 - depends on MEDIA_SUPPORT
21 + depends on MEDIA_SUPPORT && MEDIA_CONTROLLER
22 depends on VIDEO_V4L2 && (ARCH_BCM2835 || COMPILE_TEST)
23 select BCM2835_VCHIQ_MMAL
24 select VIDEOBUF2_DMA_CONTIG
25 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
26 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
27 @@ -458,6 +458,7 @@ struct bcm2835_codec_ctx {
28
29 struct bcm2835_codec_driver {
30 struct platform_device *pdev;
31 + struct media_device mdev;
32
33 struct bcm2835_codec_dev *encode;
34 struct bcm2835_codec_dev *decode;
35 @@ -2596,6 +2597,7 @@ static int bcm2835_codec_create(struct b
36 struct platform_device *pdev = drv->pdev;
37 struct bcm2835_codec_dev *dev;
38 struct video_device *vfd;
39 + int function;
40 int video_nr;
41 int ret;
42
43 @@ -2615,18 +2617,21 @@ static int bcm2835_codec_create(struct b
44 if (ret)
45 goto vchiq_finalise;
46
47 - ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
48 - if (ret)
49 - goto vchiq_finalise;
50 -
51 atomic_set(&dev->num_inst, 0);
52 mutex_init(&dev->dev_mutex);
53
54 + /* Initialise the video device */
55 dev->vfd = bcm2835_codec_videodev;
56 +
57 vfd = &dev->vfd;
58 vfd->lock = &dev->dev_mutex;
59 vfd->v4l2_dev = &dev->v4l2_dev;
60 vfd->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
61 + vfd->v4l2_dev->mdev = &drv->mdev;
62 +
63 + ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
64 + if (ret)
65 + goto vchiq_finalise;
66
67 switch (role) {
68 case DECODE:
69 @@ -2634,11 +2639,13 @@ static int bcm2835_codec_create(struct b
70 v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
71 v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
72 v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
73 + function = MEDIA_ENT_F_PROC_VIDEO_DECODER;
74 video_nr = decode_video_nr;
75 break;
76 case ENCODE:
77 v4l2_disable_ioctl(vfd, VIDIOC_DECODER_CMD);
78 v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
79 + function = MEDIA_ENT_F_PROC_VIDEO_ENCODER;
80 video_nr = encode_video_nr;
81 break;
82 case ISP:
83 @@ -2648,6 +2655,7 @@ static int bcm2835_codec_create(struct b
84 v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
85 v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
86 v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
87 + function = MEDIA_ENT_F_PROC_VIDEO_SCALER;
88 video_nr = isp_video_nr;
89 break;
90 default:
91 @@ -2676,6 +2684,10 @@ static int bcm2835_codec_create(struct b
92 goto err_m2m;
93 }
94
95 + ret = v4l2_m2m_register_media_controller(dev->m2m_dev, vfd, function);
96 + if (ret)
97 + goto err_m2m;
98 +
99 v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n",
100 roles[role]);
101 return 0;
102 @@ -2697,6 +2709,7 @@ static int bcm2835_codec_destroy(struct
103
104 v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME ", %s\n",
105 roles[dev->role]);
106 + v4l2_m2m_unregister_media_controller(dev->m2m_dev);
107 v4l2_m2m_release(dev->m2m_dev);
108 video_unregister_device(&dev->vfd);
109 v4l2_device_unregister(&dev->v4l2_dev);
110 @@ -2708,6 +2721,7 @@ static int bcm2835_codec_destroy(struct
111 static int bcm2835_codec_probe(struct platform_device *pdev)
112 {
113 struct bcm2835_codec_driver *drv;
114 + struct media_device *mdev;
115 int ret = 0;
116
117 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
118 @@ -2715,6 +2729,17 @@ static int bcm2835_codec_probe(struct pl
119 return -ENOMEM;
120
121 drv->pdev = pdev;
122 + mdev = &drv->mdev;
123 + mdev->dev = &pdev->dev;
124 +
125 + strscpy(mdev->model, bcm2835_codec_videodev.name, sizeof(mdev->model));
126 + strscpy(mdev->serial, "0000", sizeof(mdev->serial));
127 + snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
128 + pdev->name);
129 +
130 + /* This should return the vgencmd version information or such .. */
131 + mdev->hw_revision = 1;
132 + media_device_init(mdev);
133
134 ret = bcm2835_codec_create(drv, &drv->decode, DECODE);
135 if (ret)
136 @@ -2728,6 +2753,10 @@ static int bcm2835_codec_probe(struct pl
137 if (ret)
138 goto out;
139
140 + /* Register the media device node */
141 + if (media_device_register(mdev) < 0)
142 + goto out;
143 +
144 platform_set_drvdata(pdev, drv);
145
146 return 0;
147 @@ -2748,12 +2777,16 @@ static int bcm2835_codec_remove(struct p
148 {
149 struct bcm2835_codec_driver *drv = platform_get_drvdata(pdev);
150
151 + media_device_unregister(&drv->mdev);
152 +
153 bcm2835_codec_destroy(drv->isp);
154
155 bcm2835_codec_destroy(drv->encode);
156
157 bcm2835_codec_destroy(drv->decode);
158
159 + media_device_cleanup(&drv->mdev);
160 +
161 return 0;
162 }
163