1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: PC Chen <pc.chen@mediatek.com>
5 * Tiffany Lin <tiffany.lin@mediatek.com>
8 #include <linux/module.h>
10 #include "mtk_vcodec_drv.h"
11 #include "mtk_vcodec_util.h"
14 /* For encoder, this will enable logs in venc/*/
16 EXPORT_SYMBOL(mtk_vcodec_dbg);
18 /* The log level of v4l2 encoder or decoder driver.
19 * That is, files under mtk-vcodec/.
21 int mtk_v4l2_dbg_level;
22 EXPORT_SYMBOL(mtk_v4l2_dbg_level);
24 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
27 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
29 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) {
30 mtk_v4l2_err("Invalid arguments, reg_idx=%d", reg_idx);
33 return ctx->dev->reg_base[reg_idx];
35 EXPORT_SYMBOL(mtk_vcodec_get_reg_addr);
37 int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
38 struct mtk_vcodec_mem *mem)
40 unsigned long size = mem->size;
41 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
42 struct device *dev = &ctx->dev->plat_dev->dev;
44 mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
46 mtk_v4l2_err("%s dma_alloc size=%ld failed!", dev_name(dev),
51 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
52 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
53 (unsigned long)mem->dma_addr);
54 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
58 EXPORT_SYMBOL(mtk_vcodec_mem_alloc);
60 void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
61 struct mtk_vcodec_mem *mem)
63 unsigned long size = mem->size;
64 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
65 struct device *dev = &ctx->dev->plat_dev->dev;
68 mtk_v4l2_err("%s dma_free size=%ld failed!", dev_name(dev),
73 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
74 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
75 (unsigned long)mem->dma_addr);
76 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
78 dma_free_coherent(dev, size, mem->va, mem->dma_addr);
83 EXPORT_SYMBOL(mtk_vcodec_mem_free);
85 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev,
86 struct mtk_vcodec_ctx *ctx)
90 spin_lock_irqsave(&dev->irqlock, flags);
92 spin_unlock_irqrestore(&dev->irqlock, flags);
94 EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx);
96 struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev)
99 struct mtk_vcodec_ctx *ctx;
101 spin_lock_irqsave(&dev->irqlock, flags);
103 spin_unlock_irqrestore(&dev->irqlock, flags);
106 EXPORT_SYMBOL(mtk_vcodec_get_curr_ctx);
108 MODULE_LICENSE("GPL v2");
109 MODULE_DESCRIPTION("Mediatek video codec driver");