1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2016 MediaTek Inc.
4 * Author: PC Chen <pc.chen@mediatek.com>
5 * Tiffany Lin <tiffany.lin@mediatek.com>
8 #ifndef _MTK_VCODEC_UTIL_H_
9 #define _MTK_VCODEC_UTIL_H_
11 #include <linux/types.h>
12 #include <linux/dma-direction.h>
14 #define MTK_DBG_VCODEC_STR "[MTK_VCODEC]"
15 #define MTK_DBG_V4L2_STR "[MTK_V4L2]"
17 struct mtk_vcodec_mem {
23 struct mtk_vcodec_fb {
28 struct mtk_vcodec_dec_ctx;
29 struct mtk_vcodec_dev;
32 #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
34 #define mtk_v4l2_err(plat_dev, fmt, args...) \
35 dev_err(&(plat_dev)->dev, "[MTK_V4L2][ERROR] " fmt "\n", ##args)
37 #define mtk_vcodec_err(inst_id, plat_dev, fmt, args...) \
38 dev_err(&(plat_dev)->dev, "[MTK_VCODEC][ERROR][%d]: " fmt "\n", inst_id, ##args)
40 #if defined(CONFIG_DEBUG_FS)
41 extern int mtk_v4l2_dbg_level;
42 extern int mtk_vcodec_dbg;
44 #define mtk_v4l2_debug(plat_dev, level, fmt, args...) \
46 if (mtk_v4l2_dbg_level >= (level)) \
47 dev_dbg(&(plat_dev)->dev, "[MTK_V4L2] %s, %d: " fmt "\n", \
48 __func__, __LINE__, ##args); \
51 #define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...) \
54 dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: %s, %d " fmt "\n", \
55 inst_id, __func__, __LINE__, ##args); \
58 #define mtk_v4l2_debug(plat_dev, level, fmt, args...) \
59 dev_dbg(&(plat_dev)->dev, "[MTK_V4L2]: " fmt "\n", ##args)
61 #define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...) \
62 dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: " fmt "\n", inst_id, ##args)
65 #define mtk_vdec_err(ctx, fmt, args...) \
66 mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
68 #define mtk_vdec_debug(ctx, fmt, args...) \
69 mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
71 #define mtk_venc_err(ctx, fmt, args...) \
72 mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
74 #define mtk_venc_debug(ctx, fmt, args...) \
75 mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
77 #define mtk_v4l2_vdec_err(ctx, fmt, args...) mtk_v4l2_err((ctx)->dev->plat_dev, fmt, ##args)
79 #define mtk_v4l2_vdec_dbg(level, ctx, fmt, args...) \
80 mtk_v4l2_debug((ctx)->dev->plat_dev, level, fmt, ##args)
82 #define mtk_v4l2_venc_err(ctx, fmt, args...) mtk_v4l2_err((ctx)->dev->plat_dev, fmt, ##args)
84 #define mtk_v4l2_venc_dbg(level, ctx, fmt, args...) \
85 mtk_v4l2_debug((ctx)->dev->plat_dev, level, fmt, ##args)
87 void __iomem *mtk_vcodec_get_reg_addr(void __iomem **reg_base, unsigned int reg_idx);
88 int mtk_vcodec_write_vdecsys(struct mtk_vcodec_dec_ctx *ctx, unsigned int reg, unsigned int val);
89 int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem);
90 void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem);
91 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
92 struct mtk_vcodec_dec_ctx *ctx, int hw_idx);
93 struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
95 void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);
97 #endif /* _MTK_VCODEC_UTIL_H_ */