a0d7b7784cf7c01016ae47eb4495a0f50f7e182f
[platform/kernel/linux-rpi.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 #define MTK_DBG_VCODEC_STR "[MTK_VCODEC]"
15 #define MTK_DBG_V4L2_STR "[MTK_V4L2]"
16
17 struct mtk_vcodec_mem {
18         size_t size;
19         void *va;
20         dma_addr_t dma_addr;
21 };
22
23 struct mtk_vcodec_fb {
24         size_t size;
25         dma_addr_t dma_addr;
26 };
27
28 struct mtk_vcodec_dec_ctx;
29 struct mtk_vcodec_dev;
30
31 #undef pr_fmt
32 #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
33
34 #define mtk_v4l2_err(plat_dev, fmt, args...)                            \
35         dev_err(&(plat_dev)->dev, "[MTK_V4L2][ERROR] " fmt "\n", ##args)
36
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)
39
40 #if defined(CONFIG_DEBUG_FS)
41 extern int mtk_v4l2_dbg_level;
42 extern int mtk_vcodec_dbg;
43
44 #define mtk_v4l2_debug(plat_dev, level, fmt, args...)                             \
45         do {                                                                      \
46                 if (mtk_v4l2_dbg_level >= (level))                                \
47                         dev_dbg(&(plat_dev)->dev, "[MTK_V4L2] %s, %d: " fmt "\n", \
48                                  __func__, __LINE__, ##args);                     \
49         } while (0)
50
51 #define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...)                               \
52         do {                                                                            \
53                 if (mtk_vcodec_dbg)                                                     \
54                         dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: %s, %d " fmt "\n", \
55                                 inst_id, __func__, __LINE__, ##args);                   \
56         } while (0)
57 #else
58 #define mtk_v4l2_debug(plat_dev, level, fmt, args...)              \
59         dev_dbg(&(plat_dev)->dev, "[MTK_V4L2]: " fmt "\n", ##args)
60
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)
63 #endif
64
65 #define mtk_vdec_err(ctx, fmt, args...)                               \
66         mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
67
68 #define mtk_vdec_debug(ctx, fmt, args...)                             \
69         mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
70
71 #define mtk_venc_err(ctx, fmt, args...)                               \
72         mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
73
74 #define mtk_venc_debug(ctx, fmt, args...)                              \
75         mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)
76
77 #define mtk_v4l2_vdec_err(ctx, fmt, args...) mtk_v4l2_err((ctx)->dev->plat_dev, fmt, ##args)
78
79 #define mtk_v4l2_vdec_dbg(level, ctx, fmt, args...)             \
80         mtk_v4l2_debug((ctx)->dev->plat_dev, level, fmt, ##args)
81
82 #define mtk_v4l2_venc_err(ctx, fmt, args...) mtk_v4l2_err((ctx)->dev->plat_dev, fmt, ##args)
83
84 #define mtk_v4l2_venc_dbg(level, ctx, fmt, args...)             \
85         mtk_v4l2_debug((ctx)->dev->plat_dev, level, fmt, ##args)
86
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,
94                                                    unsigned int hw_idx);
95 void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);
96
97 #endif /* _MTK_VCODEC_UTIL_H_ */