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