summaryrefslogtreecommitdiff
path: root/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
blob: 88d389b65f13f94f769d78916620f9c296a3d34b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2016 MediaTek Inc.
* Author: PC Chen <pc.chen@mediatek.com>
*	Tiffany Lin <tiffany.lin@mediatek.com>
*/

#ifndef _MTK_VCODEC_UTIL_H_
#define _MTK_VCODEC_UTIL_H_

#include <linux/types.h>
#include <linux/dma-direction.h>

struct mtk_vcodec_mem {
	size_t size;
	void *va;
	dma_addr_t dma_addr;
};

struct mtk_vcodec_fb {
	size_t size;
	dma_addr_t dma_addr;
};

struct mtk_vcodec_ctx;
struct mtk_vcodec_dev;

#undef pr_fmt
#define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__

#define mtk_v4l2_err(fmt, args...)                \
	pr_err("[MTK_V4L2][ERROR] " fmt "\n", ##args)

#define mtk_vcodec_err(h, fmt, args...)				\
	pr_err("[MTK_VCODEC][ERROR][%d]: " fmt "\n",		\
	       ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)

#if defined(CONFIG_DEBUG_FS)
extern int mtk_v4l2_dbg_level;
extern int mtk_vcodec_dbg;

#define mtk_v4l2_debug(level, fmt, args...)				\
	do {								\
		if (mtk_v4l2_dbg_level >= (level))			\
			pr_debug("[MTK_V4L2] %s, %d: " fmt "\n",        \
				 __func__, __LINE__, ##args);	        \
	} while (0)

#define mtk_vcodec_debug(h, fmt, args...)				                      \
	do {								                      \
		if (mtk_vcodec_dbg)					                      \
			dev_dbg(&(((struct mtk_vcodec_ctx *)(h)->ctx)->dev->plat_dev->dev),   \
				"[MTK_VCODEC][%d]: %s, %d " fmt "\n",                         \
				((struct mtk_vcodec_ctx *)(h)->ctx)->id,                      \
				__func__, __LINE__, ##args);                                  \
	} while (0)
#else
#define mtk_v4l2_debug(level, fmt, args...) pr_debug(fmt, ##args)

#define mtk_vcodec_debug(h, fmt, args...)			\
	pr_debug("[MTK_VCODEC][%d]: " fmt "\n",			\
		((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)
#endif

#define mtk_v4l2_debug_enter()  mtk_v4l2_debug(3, "+")
#define mtk_v4l2_debug_leave()  mtk_v4l2_debug(3, "-")

#define mtk_vcodec_debug_enter(h)  mtk_vcodec_debug(h, "+")
#define mtk_vcodec_debug_leave(h)  mtk_vcodec_debug(h, "-")

void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
				unsigned int reg_idx);
int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
				struct mtk_vcodec_mem *mem);
void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
				struct mtk_vcodec_mem *mem);
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
			     struct mtk_vcodec_ctx *ctx, int hw_idx);
struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
					       unsigned int hw_idx);
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);

#endif /* _MTK_VCODEC_UTIL_H_ */