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
6 Provide a single media device to contain all of the bcm2835_codec
9 Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
11 .../vc04_services/bcm2835-codec/Kconfig | 2 +-
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 41 +++++++++++++++++--
13 2 files changed, 38 insertions(+), 5 deletions(-)
15 --- a/drivers/staging/vc04_services/bcm2835-codec/Kconfig
16 +++ b/drivers/staging/vc04_services/bcm2835-codec/Kconfig
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 {
29 struct bcm2835_codec_driver {
30 struct platform_device *pdev;
31 + struct media_device mdev;
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;
43 @@ -2615,18 +2617,21 @@ static int bcm2835_codec_create(struct b
47 - ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
49 - goto vchiq_finalise;
51 atomic_set(&dev->num_inst, 0);
52 mutex_init(&dev->dev_mutex);
54 + /* Initialise the video device */
55 dev->vfd = bcm2835_codec_videodev;
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;
63 + ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
65 + goto vchiq_finalise;
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;
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;
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;
91 @@ -2676,6 +2684,10 @@ static int bcm2835_codec_create(struct b
95 + ret = v4l2_m2m_register_media_controller(dev->m2m_dev, vfd, function);
99 v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n",
102 @@ -2697,6 +2709,7 @@ static int bcm2835_codec_destroy(struct
104 v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME ", %s\n",
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)
113 struct bcm2835_codec_driver *drv;
114 + struct media_device *mdev;
117 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
118 @@ -2715,6 +2729,17 @@ static int bcm2835_codec_probe(struct pl
123 + mdev->dev = &pdev->dev;
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",
130 + /* This should return the vgencmd version information or such .. */
131 + mdev->hw_revision = 1;
132 + media_device_init(mdev);
134 ret = bcm2835_codec_create(drv, &drv->decode, DECODE);
136 @@ -2728,6 +2753,10 @@ static int bcm2835_codec_probe(struct pl
140 + /* Register the media device node */
141 + if (media_device_register(mdev) < 0)
144 platform_set_drvdata(pdev, drv);
147 @@ -2748,12 +2777,16 @@ static int bcm2835_codec_remove(struct p
149 struct bcm2835_codec_driver *drv = platform_get_drvdata(pdev);
151 + media_device_unregister(&drv->mdev);
153 bcm2835_codec_destroy(drv->isp);
155 bcm2835_codec_destroy(drv->encode);
157 bcm2835_codec_destroy(drv->decode);
159 + media_device_cleanup(&drv->mdev);