Merge tag 'drm-misc-next-2019-01-07-1' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / drivers / media / platform / mtk-vcodec / mtk_vcodec_util.h
1 /*
2 * Copyright (c) 2016 MediaTek Inc.
3 * Author: PC Chen <pc.chen@mediatek.com>
4 *       Tiffany Lin <tiffany.lin@mediatek.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 */
15
16 #ifndef _MTK_VCODEC_UTIL_H_
17 #define _MTK_VCODEC_UTIL_H_
18
19 #include <linux/types.h>
20 #include <linux/dma-direction.h>
21
22 struct mtk_vcodec_mem {
23         size_t size;
24         void *va;
25         dma_addr_t dma_addr;
26 };
27
28 struct mtk_vcodec_fb {
29         size_t size;
30         dma_addr_t dma_addr;
31 };
32
33 struct mtk_vcodec_ctx;
34 struct mtk_vcodec_dev;
35
36 extern int mtk_v4l2_dbg_level;
37 extern bool mtk_vcodec_dbg;
38
39
40 #define mtk_v4l2_err(fmt, args...)                \
41         pr_err("[MTK_V4L2][ERROR] %s:%d: " fmt "\n", __func__, __LINE__, \
42                ##args)
43
44 #define mtk_vcodec_err(h, fmt, args...)                                 \
45         pr_err("[MTK_VCODEC][ERROR][%d]: %s() " fmt "\n",               \
46                ((struct mtk_vcodec_ctx *)h->ctx)->id, __func__, ##args)
47
48
49 #if defined(DEBUG)
50
51 #define mtk_v4l2_debug(level, fmt, args...)                              \
52         do {                                                             \
53                 if (mtk_v4l2_dbg_level >= level)                         \
54                         pr_info("[MTK_V4L2] level=%d %s(),%d: " fmt "\n",\
55                                 level, __func__, __LINE__, ##args);      \
56         } while (0)
57
58 #define mtk_v4l2_debug_enter()  mtk_v4l2_debug(3, "+")
59 #define mtk_v4l2_debug_leave()  mtk_v4l2_debug(3, "-")
60
61 #define mtk_vcodec_debug(h, fmt, args...)                               \
62         do {                                                            \
63                 if (mtk_vcodec_dbg)                                     \
64                         pr_info("[MTK_VCODEC][%d]: %s() " fmt "\n",     \
65                                 ((struct mtk_vcodec_ctx *)h->ctx)->id, \
66                                 __func__, ##args);                      \
67         } while (0)
68
69 #define mtk_vcodec_debug_enter(h)  mtk_vcodec_debug(h, "+")
70 #define mtk_vcodec_debug_leave(h)  mtk_vcodec_debug(h, "-")
71
72 #else
73
74 #define mtk_v4l2_debug(level, fmt, args...) {}
75 #define mtk_v4l2_debug_enter() {}
76 #define mtk_v4l2_debug_leave() {}
77
78 #define mtk_vcodec_debug(h, fmt, args...) {}
79 #define mtk_vcodec_debug_enter(h) {}
80 #define mtk_vcodec_debug_leave(h) {}
81
82 #endif
83
84 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
85                                 unsigned int reg_idx);
86 int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
87                                 struct mtk_vcodec_mem *mem);
88 void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
89                                 struct mtk_vcodec_mem *mem);
90 void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev,
91         struct mtk_vcodec_ctx *ctx);
92 struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev);
93
94 #endif /* _MTK_VCODEC_UTIL_H_ */