1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: PC Chen <pc.chen@mediatek.com>
5 * Tiffany Lin <tiffany.lin@mediatek.com>
6 */
7
8 #include <linux/bitfield.h>
9 #include <linux/slab.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/of_platform.h>
16 #include <linux/platform_device.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/regmap.h>
19 #include <media/v4l2-event.h>
20 #include <media/v4l2-mem2mem.h>
21 #include <media/videobuf2-dma-contig.h>
22 #include <media/v4l2-device.h>
23
24 #include "mtk_vcodec_dec.h"
25 #include "mtk_vcodec_dec_hw.h"
26 #include "mtk_vcodec_dec_pm.h"
27 #include "../common/mtk_vcodec_intr.h"
28
mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_ctx * ctx,struct mtk_vcodec_dec_dev * dev)29 static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_dec_dev *dev)
30 {
31 switch (dev->vdec_pdata->hw_arch) {
32 case MTK_VDEC_PURE_SINGLE_CORE:
33 return MTK_VDEC_ONE_CORE;
34 case MTK_VDEC_LAT_SINGLE_CORE:
35 return MTK_VDEC_ONE_LAT_ONE_CORE;
36 default:
37 mtk_v4l2_vdec_err(ctx, "hw arch %d not supported", dev->vdec_pdata->hw_arch);
38 return MTK_VDEC_NO_HW;
39 }
40 }
41
mtk_vcodec_is_hw_active(struct mtk_vcodec_dec_dev * dev)42 static bool mtk_vcodec_is_hw_active(struct mtk_vcodec_dec_dev *dev)
43 {
44 u32 cg_status;
45
46 if (dev->vdecsys_regmap)
47 return !regmap_test_bits(dev->vdecsys_regmap, VDEC_HW_ACTIVE_ADDR,
48 VDEC_HW_ACTIVE_MASK);
49
50 cg_status = readl(dev->reg_base[VDEC_SYS] + VDEC_HW_ACTIVE_ADDR);
51 return !FIELD_GET(VDEC_HW_ACTIVE_MASK, cg_status);
52 }
53
mtk_vcodec_dec_irq_handler(int irq,void * priv)54 static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
55 {
56 struct mtk_vcodec_dec_dev *dev = priv;
57 struct mtk_vcodec_dec_ctx *ctx;
58 unsigned int dec_done_status = 0;
59 void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC] +
60 VDEC_IRQ_CFG_REG;
61
62 ctx = mtk_vcodec_get_curr_ctx(dev, MTK_VDEC_CORE);
63
64 if (!mtk_vcodec_is_hw_active(dev)) {
65 mtk_v4l2_vdec_err(ctx, "DEC ISR, VDEC active is not 0x0");
66 return IRQ_HANDLED;
67 }
68
69 dec_done_status = readl(vdec_misc_addr);
70 ctx->irq_status = dec_done_status;
71 if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) !=
72 MTK_VDEC_IRQ_STATUS_DEC_SUCCESS)
73 return IRQ_HANDLED;
74
75 /* clear interrupt */
76 writel((readl(vdec_misc_addr) | VDEC_IRQ_CFG),
77 dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG);
78 writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR),
79 dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG);
80
81 wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
82
83 mtk_v4l2_vdec_dbg(3, ctx, "wake up ctx %d, dec_done_status=%x", ctx->id, dec_done_status);
84
85 return IRQ_HANDLED;
86 }
87
mtk_vcodec_get_reg_bases(struct mtk_vcodec_dec_dev * dev)88 static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dec_dev *dev)
89 {
90 struct platform_device *pdev = dev->plat_dev;
91 int reg_num, i;
92 struct resource *res;
93 bool has_vdecsys_reg;
94 int num_max_vdec_regs;
95 static const char * const mtk_dec_reg_names[] = {
96 "misc",
97 "ld",
98 "top",
99 "cm",
100 "ad",
101 "av",
102 "pp",
103 "hwd",
104 "hwq",
105 "hwb",
106 "hwg"
107 };
108
109 /*
110 * If we have reg-names in devicetree, this means that we're on a new
111 * register organization, which implies that the VDEC_SYS iospace gets
112 * R/W through a syscon (regmap).
113 * Here we try to get the "misc" iostart only to check if we have reg-names
114 */
115 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "misc");
116 if (res)
117 has_vdecsys_reg = false;
118 else
119 has_vdecsys_reg = true;
120
121 num_max_vdec_regs = has_vdecsys_reg ? NUM_MAX_VDEC_REG_BASE :
122 ARRAY_SIZE(mtk_dec_reg_names);
123
124 /* Sizeof(u32) * 4 bytes for each register base. */
125 reg_num = of_property_count_elems_of_size(pdev->dev.of_node, "reg",
126 sizeof(u32) * 4);
127 if (reg_num <= 0 || reg_num > num_max_vdec_regs) {
128 dev_err(&pdev->dev, "Invalid register property size: %d\n", reg_num);
129 return -EINVAL;
130 }
131
132 if (has_vdecsys_reg) {
133 for (i = 0; i < reg_num; i++) {
134 dev->reg_base[i] = devm_platform_ioremap_resource(pdev, i);
135 if (IS_ERR(dev->reg_base[i]))
136 return PTR_ERR(dev->reg_base[i]);
137
138 dev_dbg(&pdev->dev, "reg[%d] base=%p", i, dev->reg_base[i]);
139 }
140 } else {
141 for (i = 0; i < reg_num; i++) {
142 dev->reg_base[i+1] = devm_platform_ioremap_resource_byname(pdev, mtk_dec_reg_names[i]);
143 if (IS_ERR(dev->reg_base[i+1]))
144 return PTR_ERR(dev->reg_base[i+1]);
145
146 dev_dbg(&pdev->dev, "reg[%d] base=%p", i + 1, dev->reg_base[i + 1]);
147 }
148
149 dev->vdecsys_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
150 "mediatek,vdecsys");
151 if (IS_ERR(dev->vdecsys_regmap)) {
152 dev_err(&pdev->dev, "Missing mediatek,vdecsys property");
153 return PTR_ERR(dev->vdecsys_regmap);
154 }
155 }
156
157 return 0;
158 }
159
mtk_vcodec_init_dec_resources(struct mtk_vcodec_dec_dev * dev)160 static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dec_dev *dev)
161 {
162 struct platform_device *pdev = dev->plat_dev;
163 int ret;
164
165 ret = mtk_vcodec_get_reg_bases(dev);
166 if (ret)
167 return ret;
168
169 if (dev->vdec_pdata->is_subdev_supported)
170 return 0;
171
172 dev->dec_irq = platform_get_irq(pdev, 0);
173 if (dev->dec_irq < 0)
174 return dev->dec_irq;
175
176 irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
177 ret = devm_request_irq(&pdev->dev, dev->dec_irq,
178 mtk_vcodec_dec_irq_handler, 0, pdev->name, dev);
179 if (ret) {
180 dev_err(&pdev->dev, "failed to install dev->dec_irq %d (%d)",
181 dev->dec_irq, ret);
182 return ret;
183 }
184
185 ret = mtk_vcodec_init_dec_clk(pdev, &dev->pm);
186 if (ret < 0) {
187 dev_err(&pdev->dev, "failed to get mt vcodec clock source");
188 return ret;
189 }
190
191 pm_runtime_enable(&pdev->dev);
192 return 0;
193 }
194
fops_vcodec_open(struct file * file)195 static int fops_vcodec_open(struct file *file)
196 {
197 struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
198 struct mtk_vcodec_dec_ctx *ctx = NULL;
199 int ret = 0, i, hw_count;
200 struct vb2_queue *src_vq;
201
202 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
203 if (!ctx)
204 return -ENOMEM;
205
206 mutex_lock(&dev->dev_mutex);
207 ctx->id = dev->id_counter++;
208 v4l2_fh_init(&ctx->fh, video_devdata(file));
209 file->private_data = &ctx->fh;
210 v4l2_fh_add(&ctx->fh);
211 INIT_LIST_HEAD(&ctx->list);
212 ctx->dev = dev;
213 if (ctx->dev->vdec_pdata->is_subdev_supported) {
214 hw_count = mtk_vcodec_get_hw_count(ctx, dev);
215 if (!hw_count || !dev->subdev_prob_done) {
216 ret = -EINVAL;
217 goto err_ctrls_setup;
218 }
219
220 ret = dev->subdev_prob_done(dev);
221 if (ret)
222 goto err_ctrls_setup;
223
224 for (i = 0; i < hw_count; i++)
225 init_waitqueue_head(&ctx->queue[i]);
226 } else {
227 init_waitqueue_head(&ctx->queue[0]);
228 }
229 mutex_init(&ctx->lock);
230
231 ctx->type = MTK_INST_DECODER;
232 ret = dev->vdec_pdata->ctrls_setup(ctx);
233 if (ret) {
234 mtk_v4l2_vdec_err(ctx, "Failed to setup mt vcodec controls");
235 goto err_ctrls_setup;
236 }
237 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev_dec, ctx,
238 &mtk_vcodec_dec_queue_init);
239 if (IS_ERR((__force void *)ctx->m2m_ctx)) {
240 ret = PTR_ERR((__force void *)ctx->m2m_ctx);
241 mtk_v4l2_vdec_err(ctx, "Failed to v4l2_m2m_ctx_init() (%d)", ret);
242 goto err_m2m_ctx_init;
243 }
244 src_vq = v4l2_m2m_get_vq(ctx->m2m_ctx,
245 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
246 ctx->empty_flush_buf.vb.vb2_buf.vb2_queue = src_vq;
247 mtk_vcodec_dec_set_default_params(ctx);
248
249 if (v4l2_fh_is_singular(&ctx->fh)) {
250 /*
251 * Does nothing if firmware was already loaded.
252 */
253 ret = mtk_vcodec_fw_load_firmware(dev->fw_handler);
254 if (ret < 0) {
255 /*
256 * Return 0 if downloading firmware successfully,
257 * otherwise it is failed
258 */
259 mtk_v4l2_vdec_err(ctx, "failed to load firmware!");
260 goto err_load_fw;
261 }
262
263 dev->dec_capability =
264 mtk_vcodec_fw_get_vdec_capa(dev->fw_handler);
265
266 mtk_v4l2_vdec_dbg(0, ctx, "decoder capability %x", dev->dec_capability);
267 }
268
269 ctx->dev->vdec_pdata->init_vdec_params(ctx);
270
271 mutex_lock(&dev->dev_ctx_lock);
272 list_add(&ctx->list, &dev->ctx_list);
273 mutex_unlock(&dev->dev_ctx_lock);
274 mtk_vcodec_dbgfs_create(ctx);
275
276 mutex_unlock(&dev->dev_mutex);
277 mtk_v4l2_vdec_dbg(0, ctx, "%s decoder [%d]", dev_name(&dev->plat_dev->dev), ctx->id);
278 return ret;
279
280 /* Deinit when failure occurred */
281 err_load_fw:
282 v4l2_m2m_ctx_release(ctx->m2m_ctx);
283 err_m2m_ctx_init:
284 v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
285 err_ctrls_setup:
286 v4l2_fh_del(&ctx->fh);
287 v4l2_fh_exit(&ctx->fh);
288 kfree(ctx);
289 mutex_unlock(&dev->dev_mutex);
290
291 return ret;
292 }
293
fops_vcodec_release(struct file * file)294 static int fops_vcodec_release(struct file *file)
295 {
296 struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
297 struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(file->private_data);
298
299 mtk_v4l2_vdec_dbg(0, ctx, "[%d] decoder", ctx->id);
300 mutex_lock(&dev->dev_mutex);
301
302 /*
303 * Call v4l2_m2m_ctx_release before mtk_vcodec_dec_release. First, it
304 * makes sure the worker thread is not running after vdec_if_deinit.
305 * Second, the decoder will be flushed and all the buffers will be
306 * returned in stop_streaming.
307 */
308 v4l2_m2m_ctx_release(ctx->m2m_ctx);
309 mtk_vcodec_dec_release(ctx);
310
311 v4l2_fh_del(&ctx->fh);
312 v4l2_fh_exit(&ctx->fh);
313 v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
314
315 mtk_vcodec_dbgfs_remove(dev, ctx->id);
316 mutex_lock(&dev->dev_ctx_lock);
317 list_del_init(&ctx->list);
318 mutex_unlock(&dev->dev_ctx_lock);
319 kfree(ctx);
320 mutex_unlock(&dev->dev_mutex);
321 return 0;
322 }
323
324 static const struct v4l2_file_operations mtk_vcodec_fops = {
325 .owner = THIS_MODULE,
326 .open = fops_vcodec_open,
327 .release = fops_vcodec_release,
328 .poll = v4l2_m2m_fop_poll,
329 .unlocked_ioctl = video_ioctl2,
330 .mmap = v4l2_m2m_fop_mmap,
331 };
332
mtk_vcodec_dec_get_chip_name(struct mtk_vcodec_dec_dev * vdec_dev)333 static void mtk_vcodec_dec_get_chip_name(struct mtk_vcodec_dec_dev *vdec_dev)
334 {
335 struct device *dev = &vdec_dev->plat_dev->dev;
336
337 if (of_device_is_compatible(dev->of_node, "mediatek,mt8173-vcodec-dec"))
338 vdec_dev->chip_name = MTK_VDEC_MT8173;
339 else if (of_device_is_compatible(dev->of_node, "mediatek,mt8183-vcodec-dec"))
340 vdec_dev->chip_name = MTK_VDEC_MT8183;
341 else if (of_device_is_compatible(dev->of_node, "mediatek,mt8192-vcodec-dec"))
342 vdec_dev->chip_name = MTK_VDEC_MT8192;
343 else if (of_device_is_compatible(dev->of_node, "mediatek,mt8195-vcodec-dec"))
344 vdec_dev->chip_name = MTK_VDEC_MT8195;
345 else if (of_device_is_compatible(dev->of_node, "mediatek,mt8186-vcodec-dec"))
346 vdec_dev->chip_name = MTK_VDEC_MT8186;
347 else if (of_device_is_compatible(dev->of_node, "mediatek,mt8188-vcodec-dec"))
348 vdec_dev->chip_name = MTK_VDEC_MT8188;
349 else
350 vdec_dev->chip_name = MTK_VDEC_INVAL;
351 }
352
mtk_vcodec_probe(struct platform_device * pdev)353 static int mtk_vcodec_probe(struct platform_device *pdev)
354 {
355 struct mtk_vcodec_dec_dev *dev;
356 struct video_device *vfd_dec;
357 phandle rproc_phandle;
358 enum mtk_vcodec_fw_type fw_type;
359 int i, ret;
360
361 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
362 if (!dev)
363 return -ENOMEM;
364
365 INIT_LIST_HEAD(&dev->ctx_list);
366 dev->plat_dev = pdev;
367
368 mtk_vcodec_dec_get_chip_name(dev);
369 if (dev->chip_name == MTK_VDEC_INVAL) {
370 dev_err(&pdev->dev, "Failed to get decoder chip name");
371 return -EINVAL;
372 }
373
374 dev->vdec_pdata = of_device_get_match_data(&pdev->dev);
375 if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu",
376 &rproc_phandle)) {
377 fw_type = VPU;
378 } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp",
379 &rproc_phandle)) {
380 fw_type = SCP;
381 } else {
382 dev_dbg(&pdev->dev, "Could not get vdec IPI device");
383 return -ENODEV;
384 }
385 dma_set_max_seg_size(&pdev->dev, UINT_MAX);
386
387 dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, DECODER);
388 if (IS_ERR(dev->fw_handler))
389 return PTR_ERR(dev->fw_handler);
390
391 ret = mtk_vcodec_init_dec_resources(dev);
392 if (ret) {
393 dev_err(&pdev->dev, "Failed to init dec resources");
394 goto err_dec_pm;
395 }
396
397 if (IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch)) {
398 dev->core_workqueue =
399 alloc_ordered_workqueue("core-decoder",
400 WQ_MEM_RECLAIM | WQ_FREEZABLE);
401 if (!dev->core_workqueue) {
402 dev_dbg(&pdev->dev, "Failed to create core workqueue");
403 ret = -EINVAL;
404 goto err_res;
405 }
406 }
407
408 for (i = 0; i < MTK_VDEC_HW_MAX; i++)
409 mutex_init(&dev->dec_mutex[i]);
410 mutex_init(&dev->dev_mutex);
411 mutex_init(&dev->dev_ctx_lock);
412 spin_lock_init(&dev->irqlock);
413
414 snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
415 "[/MTK_V4L2_VDEC]");
416
417 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
418 if (ret) {
419 dev_err(&pdev->dev, "v4l2_device_register err=%d", ret);
420 goto err_core_workq;
421 }
422
423 vfd_dec = video_device_alloc();
424 if (!vfd_dec) {
425 dev_err(&pdev->dev, "Failed to allocate video device");
426 ret = -ENOMEM;
427 goto err_dec_alloc;
428 }
429 vfd_dec->fops = &mtk_vcodec_fops;
430 vfd_dec->ioctl_ops = &mtk_vdec_ioctl_ops;
431 vfd_dec->release = video_device_release;
432 vfd_dec->lock = &dev->dev_mutex;
433 vfd_dec->v4l2_dev = &dev->v4l2_dev;
434 vfd_dec->vfl_dir = VFL_DIR_M2M;
435 vfd_dec->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE |
436 V4L2_CAP_STREAMING;
437
438 snprintf(vfd_dec->name, sizeof(vfd_dec->name), "%s",
439 MTK_VCODEC_DEC_NAME);
440 video_set_drvdata(vfd_dec, dev);
441 dev->vfd_dec = vfd_dec;
442 platform_set_drvdata(pdev, dev);
443
444 dev->m2m_dev_dec = v4l2_m2m_init(&mtk_vdec_m2m_ops);
445 if (IS_ERR((__force void *)dev->m2m_dev_dec)) {
446 dev_err(&pdev->dev, "Failed to init mem2mem dec device");
447 ret = PTR_ERR((__force void *)dev->m2m_dev_dec);
448 goto err_dec_alloc;
449 }
450
451 dev->decode_workqueue =
452 alloc_ordered_workqueue(MTK_VCODEC_DEC_NAME,
453 WQ_MEM_RECLAIM | WQ_FREEZABLE);
454 if (!dev->decode_workqueue) {
455 dev_err(&pdev->dev, "Failed to create decode workqueue");
456 ret = -EINVAL;
457 goto err_event_workq;
458 }
459
460 if (dev->vdec_pdata->is_subdev_supported) {
461 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL,
462 &pdev->dev);
463 if (ret) {
464 dev_err(&pdev->dev, "Main device of_platform_populate failed.");
465 goto err_reg_cont;
466 }
467 } else {
468 set_bit(MTK_VDEC_CORE, dev->subdev_bitmap);
469 }
470
471 atomic_set(&dev->dec_active_cnt, 0);
472 memset(dev->vdec_racing_info, 0, sizeof(dev->vdec_racing_info));
473 mutex_init(&dev->dec_racing_info_mutex);
474
475 ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, -1);
476 if (ret) {
477 dev_err(&pdev->dev, "Failed to register video device");
478 goto err_reg_cont;
479 }
480
481 if (dev->vdec_pdata->uses_stateless_api) {
482 v4l2_disable_ioctl(vfd_dec, VIDIOC_DECODER_CMD);
483 v4l2_disable_ioctl(vfd_dec, VIDIOC_TRY_DECODER_CMD);
484
485 dev->mdev_dec.dev = &pdev->dev;
486 strscpy(dev->mdev_dec.model, MTK_VCODEC_DEC_NAME,
487 sizeof(dev->mdev_dec.model));
488
489 media_device_init(&dev->mdev_dec);
490 dev->mdev_dec.ops = &mtk_vcodec_media_ops;
491 dev->v4l2_dev.mdev = &dev->mdev_dec;
492
493 ret = v4l2_m2m_register_media_controller(dev->m2m_dev_dec, dev->vfd_dec,
494 MEDIA_ENT_F_PROC_VIDEO_DECODER);
495 if (ret) {
496 dev_err(&pdev->dev, "Failed to register media controller");
497 goto err_dec_mem_init;
498 }
499
500 ret = media_device_register(&dev->mdev_dec);
501 if (ret) {
502 dev_err(&pdev->dev, "Failed to register media device");
503 goto err_media_reg;
504 }
505
506 dev_dbg(&pdev->dev, "media registered as /dev/media%d", vfd_dec->minor);
507 }
508
509 mtk_vcodec_dbgfs_init(dev, false);
510 dev_dbg(&pdev->dev, "decoder registered as /dev/video%d", vfd_dec->minor);
511
512 return 0;
513
514 err_media_reg:
515 v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec);
516 err_dec_mem_init:
517 video_unregister_device(vfd_dec);
518 err_reg_cont:
519 if (dev->vdec_pdata->uses_stateless_api)
520 media_device_cleanup(&dev->mdev_dec);
521 destroy_workqueue(dev->decode_workqueue);
522 err_event_workq:
523 v4l2_m2m_release(dev->m2m_dev_dec);
524 err_dec_alloc:
525 v4l2_device_unregister(&dev->v4l2_dev);
526 err_core_workq:
527 if (IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch))
528 destroy_workqueue(dev->core_workqueue);
529 err_res:
530 if (!dev->vdec_pdata->is_subdev_supported)
531 pm_runtime_disable(dev->pm.dev);
532 err_dec_pm:
533 mtk_vcodec_fw_release(dev->fw_handler);
534 return ret;
535 }
536
537 static const struct of_device_id mtk_vcodec_match[] = {
538 {
539 .compatible = "mediatek,mt8173-vcodec-dec",
540 .data = &mtk_vdec_8173_pdata,
541 },
542 {
543 .compatible = "mediatek,mt8183-vcodec-dec",
544 .data = &mtk_vdec_8183_pdata,
545 },
546 {
547 .compatible = "mediatek,mt8192-vcodec-dec",
548 .data = &mtk_lat_sig_core_pdata,
549 },
550 {
551 .compatible = "mediatek,mt8186-vcodec-dec",
552 .data = &mtk_vdec_single_core_pdata,
553 },
554 {
555 .compatible = "mediatek,mt8195-vcodec-dec",
556 .data = &mtk_lat_sig_core_pdata,
557 },
558 {
559 .compatible = "mediatek,mt8188-vcodec-dec",
560 .data = &mtk_lat_sig_core_pdata,
561 },
562 {},
563 };
564
565 MODULE_DEVICE_TABLE(of, mtk_vcodec_match);
566
mtk_vcodec_dec_remove(struct platform_device * pdev)567 static void mtk_vcodec_dec_remove(struct platform_device *pdev)
568 {
569 struct mtk_vcodec_dec_dev *dev = platform_get_drvdata(pdev);
570
571 destroy_workqueue(dev->decode_workqueue);
572
573 if (media_devnode_is_registered(dev->mdev_dec.devnode)) {
574 media_device_unregister(&dev->mdev_dec);
575 v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec);
576 media_device_cleanup(&dev->mdev_dec);
577 }
578
579 if (dev->m2m_dev_dec)
580 v4l2_m2m_release(dev->m2m_dev_dec);
581
582 if (dev->vfd_dec)
583 video_unregister_device(dev->vfd_dec);
584
585 mtk_vcodec_dbgfs_deinit(&dev->dbgfs);
586 v4l2_device_unregister(&dev->v4l2_dev);
587 if (!dev->vdec_pdata->is_subdev_supported)
588 pm_runtime_disable(dev->pm.dev);
589 mtk_vcodec_fw_release(dev->fw_handler);
590 }
591
592 static struct platform_driver mtk_vcodec_dec_driver = {
593 .probe = mtk_vcodec_probe,
594 .remove_new = mtk_vcodec_dec_remove,
595 .driver = {
596 .name = MTK_VCODEC_DEC_NAME,
597 .of_match_table = mtk_vcodec_match,
598 },
599 };
600
601 module_platform_driver(mtk_vcodec_dec_driver);
602
603 MODULE_LICENSE("GPL v2");
604 MODULE_DESCRIPTION("Mediatek video codec V4L2 decoder driver");
605