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 #ifndef _MTK_VCODEC_UTIL_H_
9 #define _MTK_VCODEC_UTIL_H_
10 
11 #include <linux/types.h>
12 #include <linux/dma-direction.h>
13 
14 struct mtk_vcodec_mem {
15 	size_t size;
16 	void *va;
17 	dma_addr_t dma_addr;
18 };
19 
20 struct mtk_vcodec_fb {
21 	size_t size;
22 	dma_addr_t dma_addr;
23 };
24 
25 struct mtk_vcodec_ctx;
26 struct mtk_vcodec_dev;
27 
28 extern int mtk_v4l2_dbg_level;
29 extern bool mtk_vcodec_dbg;
30 
31 
32 #define mtk_v4l2_err(fmt, args...)                \
33 	pr_err("[MTK_V4L2][ERROR] %s:%d: " fmt "\n", __func__, __LINE__, \
34 	       ##args)
35 
36 #define mtk_vcodec_err(h, fmt, args...)					\
37 	pr_err("[MTK_VCODEC][ERROR][%d]: %s() " fmt "\n",		\
38 	       ((struct mtk_vcodec_ctx *)h->ctx)->id, __func__, ##args)
39 
40 
41 #if defined(DEBUG)
42 
43 #define mtk_v4l2_debug(level, fmt, args...)				 \
44 	do {								 \
45 		if (mtk_v4l2_dbg_level >= level)			 \
46 			pr_info("[MTK_V4L2] level=%d %s(),%d: " fmt "\n",\
47 				level, __func__, __LINE__, ##args);	 \
48 	} while (0)
49 
50 #define mtk_v4l2_debug_enter()  mtk_v4l2_debug(3, "+")
51 #define mtk_v4l2_debug_leave()  mtk_v4l2_debug(3, "-")
52 
53 #define mtk_vcodec_debug(h, fmt, args...)				\
54 	do {								\
55 		if (mtk_vcodec_dbg)					\
56 			pr_info("[MTK_VCODEC][%d]: %s() " fmt "\n",	\
57 				((struct mtk_vcodec_ctx *)h->ctx)->id, \
58 				__func__, ##args);			\
59 	} while (0)
60 
61 #define mtk_vcodec_debug_enter(h)  mtk_vcodec_debug(h, "+")
62 #define mtk_vcodec_debug_leave(h)  mtk_vcodec_debug(h, "-")
63 
64 #else
65 
66 #define mtk_v4l2_debug(level, fmt, args...) {}
67 #define mtk_v4l2_debug_enter() {}
68 #define mtk_v4l2_debug_leave() {}
69 
70 #define mtk_vcodec_debug(h, fmt, args...) {}
71 #define mtk_vcodec_debug_enter(h) {}
72 #define mtk_vcodec_debug_leave(h) {}
73 
74 #endif
75 
76 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
77 				unsigned int reg_idx);
78 int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
79 				struct mtk_vcodec_mem *mem);
80 void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
81 				struct mtk_vcodec_mem *mem);
82 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev,
83 	struct mtk_vcodec_ctx *ctx);
84 struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev);
85 
86 #endif /* _MTK_VCODEC_UTIL_H_ */
87