1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 MediaTek Inc.
8 #include <linux/module.h>
10 #include "mtk_vcodec_drv.h"
11 #include "mtk_vcodec_util.h"
13 /* For encoder, this will enable logs in venc/*/
15 EXPORT_SYMBOL(mtk_vcodec_dbg);
17 /* The log level of v4l2 encoder or decoder driver.
18 * That is, files under mtk-vcodec/.
20 int mtk_v4l2_dbg_level;
21 EXPORT_SYMBOL(mtk_v4l2_dbg_level);
23 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
26 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
28 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) {
29 mtk_v4l2_err("Invalid arguments, reg_idx=%d", reg_idx);
32 return ctx->dev->reg_base[reg_idx];
34 EXPORT_SYMBOL(mtk_vcodec_get_reg_addr);
36 int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
37 struct mtk_vcodec_mem *mem)
39 unsigned long size = mem->size;
40 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
41 struct device *dev = &ctx->dev->plat_dev->dev;
43 mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
45 mtk_v4l2_err("%s dma_alloc size=%ld failed!", dev_name(dev),
50 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
51 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
52 (unsigned long)mem->dma_addr);
53 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
57 EXPORT_SYMBOL(mtk_vcodec_mem_alloc);
59 void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
60 struct mtk_vcodec_mem *mem)
62 unsigned long size = mem->size;
63 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
64 struct device *dev = &ctx->dev->plat_dev->dev;
67 mtk_v4l2_err("%s dma_free size=%ld failed!", dev_name(dev),
72 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
73 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
74 (unsigned long)mem->dma_addr);
75 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
77 dma_free_coherent(dev, size, mem->va, mem->dma_addr);
82 EXPORT_SYMBOL(mtk_vcodec_mem_free);
84 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev,
85 struct mtk_vcodec_ctx *ctx)
89 spin_lock_irqsave(&dev->irqlock, flags);
91 spin_unlock_irqrestore(&dev->irqlock, flags);
93 EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx);
95 struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev)
98 struct mtk_vcodec_ctx *ctx;
100 spin_lock_irqsave(&dev->irqlock, flags);
102 spin_unlock_irqrestore(&dev->irqlock, flags);
105 EXPORT_SYMBOL(mtk_vcodec_get_curr_ctx);
107 MODULE_LICENSE("GPL v2");
108 MODULE_DESCRIPTION("Mediatek video codec driver");