drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.c- Extension
.c- Size
- 16800 bytes
- Lines
- 606
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/slab.hlinux/interrupt.hlinux/irq.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/pm_runtime.hlinux/regmap.hmedia/v4l2-event.hmedia/v4l2-mem2mem.hmedia/videobuf2-dma-contig.hmedia/v4l2-device.hmtk_vcodec_dec.hmtk_vcodec_dec_hw.hmtk_vcodec_dec_pm.h../common/mtk_vcodec_intr.h
Detected Declarations
function Copyrightfunction mtk_vcodec_is_hw_activefunction mtk_vcodec_dec_irq_handlerfunction mtk_vcodec_get_reg_basesfunction mtk_vcodec_init_dec_resourcesfunction fops_vcodec_openfunction fops_vcodec_releasefunction mtk_vcodec_dec_get_chip_namefunction mtk_vcodec_probefunction mtk_vcodec_dec_remove
Annotated Snippet
if (IS_ERR(dev->vdecsys_regmap)) {
dev_err(&pdev->dev, "Missing mediatek,vdecsys property");
return PTR_ERR(dev->vdecsys_regmap);
}
}
return 0;
}
static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dec_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int ret;
ret = mtk_vcodec_get_reg_bases(dev);
if (ret)
return ret;
if (dev->vdec_pdata->is_subdev_supported)
return 0;
dev->dec_irq = platform_get_irq(pdev, 0);
if (dev->dec_irq < 0)
return dev->dec_irq;
irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
ret = devm_request_irq(&pdev->dev, dev->dec_irq,
mtk_vcodec_dec_irq_handler, 0, pdev->name, dev);
if (ret) {
dev_err(&pdev->dev, "failed to install dev->dec_irq %d (%d)",
dev->dec_irq, ret);
return ret;
}
ret = mtk_vcodec_init_dec_clk(pdev, &dev->pm);
if (ret < 0) {
dev_err(&pdev->dev, "failed to get mt vcodec clock source");
return ret;
}
pm_runtime_enable(&pdev->dev);
return 0;
}
static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_ctx *ctx = NULL;
int ret = 0, i, hw_count;
struct vb2_queue *src_vq;
unsigned long flags;
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
mutex_lock(&dev->dev_mutex);
ctx->id = dev->id_counter++;
v4l2_fh_init(&ctx->fh, video_devdata(file));
v4l2_fh_add(&ctx->fh, file);
INIT_LIST_HEAD(&ctx->list);
ctx->dev = dev;
if (ctx->dev->vdec_pdata->is_subdev_supported) {
hw_count = mtk_vcodec_get_hw_count(ctx, dev);
if (!hw_count || !dev->subdev_prob_done) {
ret = -EINVAL;
goto err_ctrls_setup;
}
ret = dev->subdev_prob_done(dev);
if (ret)
goto err_ctrls_setup;
for (i = 0; i < hw_count; i++)
init_waitqueue_head(&ctx->queue[i]);
} else {
init_waitqueue_head(&ctx->queue[0]);
}
mutex_init(&ctx->lock);
ctx->type = MTK_INST_DECODER;
ret = dev->vdec_pdata->ctrls_setup(ctx);
if (ret) {
mtk_v4l2_vdec_err(ctx, "Failed to setup mt vcodec controls");
goto err_ctrls_setup;
}
ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev_dec, ctx,
&mtk_vcodec_dec_queue_init);
if (IS_ERR((__force void *)ctx->m2m_ctx)) {
ret = PTR_ERR((__force void *)ctx->m2m_ctx);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/slab.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/of.h`, `linux/of_platform.h`.
- Detected declarations: `function Copyright`, `function mtk_vcodec_is_hw_active`, `function mtk_vcodec_dec_irq_handler`, `function mtk_vcodec_get_reg_bases`, `function mtk_vcodec_init_dec_resources`, `function fops_vcodec_open`, `function fops_vcodec_release`, `function mtk_vcodec_dec_get_chip_name`, `function mtk_vcodec_probe`, `function mtk_vcodec_dec_remove`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.