Merge tag 'acpi-6.5-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[sfrench/cifs-2.6.git] / drivers / media / platform / mediatek / vcodec / mtk_vcodec_util.h
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 #undef pr_fmt
29 #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
30
31 #define mtk_v4l2_err(fmt, args...)                \
32         pr_err("[MTK_V4L2][ERROR] " fmt "\n", ##args)
33
34 #define mtk_vcodec_err(h, fmt, args...)                         \
35         pr_err("[MTK_VCODEC][ERROR][%d]: " fmt "\n",            \
36                ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)
37
38 #if defined(CONFIG_DEBUG_FS)
39 extern int mtk_v4l2_dbg_level;
40 extern int mtk_vcodec_dbg;
41
42 #define mtk_v4l2_debug(level, fmt, args...)                             \
43         do {                                                            \
44                 if (mtk_v4l2_dbg_level >= (level))                      \
45                         pr_debug("[MTK_V4L2] %s, %d: " fmt "\n",        \
46                                  __func__, __LINE__, ##args);           \
47         } while (0)
48
49 #define mtk_vcodec_debug(h, fmt, args...)                                                     \
50         do {                                                                                  \
51                 if (mtk_vcodec_dbg)                                                           \
52                         dev_dbg(&(((struct mtk_vcodec_ctx *)(h)->ctx)->dev->plat_dev->dev),   \
53                                 "[MTK_VCODEC][%d]: %s, %d " fmt "\n",                         \
54                                 ((struct mtk_vcodec_ctx *)(h)->ctx)->id,                      \
55                                 __func__, __LINE__, ##args);                                  \
56         } while (0)
57 #else
58 #define mtk_v4l2_debug(level, fmt, args...) pr_debug(fmt, ##args)
59
60 #define mtk_vcodec_debug(h, fmt, args...)                       \
61         pr_debug("[MTK_VCODEC][%d]: " fmt "\n",                 \
62                 ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)
63 #endif
64
65 #define mtk_v4l2_debug_enter()  mtk_v4l2_debug(3, "+")
66 #define mtk_v4l2_debug_leave()  mtk_v4l2_debug(3, "-")
67
68 #define mtk_vcodec_debug_enter(h)  mtk_vcodec_debug(h, "+")
69 #define mtk_vcodec_debug_leave(h)  mtk_vcodec_debug(h, "-")
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 *vdec_dev,
78                              struct mtk_vcodec_ctx *ctx, int hw_idx);
79 struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
80                                                unsigned int hw_idx);
81 void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);
82
83 #endif /* _MTK_VCODEC_UTIL_H_ */