blob: 6192caa20fe41ffe911b26e7371e6a209140b231
1 | /* |
2 | * Copyright (C) 2017 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
12 | * more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | * |
18 | * Description: |
19 | */ |
20 | #ifndef _AML_VCODEC_UTIL_H_ |
21 | #define _AML_VCODEC_UTIL_H_ |
22 | |
23 | #include <linux/types.h> |
24 | #include <linux/dma-direction.h> |
25 | #include <linux/amlogic/media/codec_mm/codec_mm.h> |
26 | |
27 | #define DEBUG |
28 | |
29 | typedef unsigned long long u64; |
30 | typedef signed long long s64; |
31 | typedef unsigned int u32; |
32 | typedef unsigned short int u16; |
33 | typedef short int s16; |
34 | typedef unsigned char u8; |
35 | |
36 | #define CODEC_MODE(a, b, c, d)\ |
37 | (((u8)(a) << 24) | ((u8)(b) << 16) | ((u8)(c) << 8) | (u8)(d)) |
38 | |
39 | struct aml_vcodec_mem { |
40 | size_t size; |
41 | void *va; |
42 | dma_addr_t dma_addr; |
43 | unsigned int bytes_used; |
44 | }; |
45 | |
46 | struct aml_vcodec_ctx; |
47 | struct aml_vcodec_dev; |
48 | |
49 | extern int aml_v4l2_dbg_level; |
50 | extern bool aml_vcodec_dbg; |
51 | |
52 | |
53 | #if defined(DEBUG) |
54 | |
55 | #define aml_v4l2_debug(level, fmt, args...) \ |
56 | do { \ |
57 | if (aml_v4l2_dbg_level >= level) \ |
58 | pr_info(fmt "\n", ##args); \ |
59 | } while (0) |
60 | |
61 | #define aml_v4l2_debug_enter() aml_v4l2_debug(3, "+") |
62 | #define aml_v4l2_debug_leave() aml_v4l2_debug(3, "-") |
63 | |
64 | #define aml_vcodec_debug(h, fmt, args...) \ |
65 | do { \ |
66 | if (aml_vcodec_dbg) \ |
67 | pr_info("[%d]: %s() " fmt "\n", \ |
68 | ((struct aml_vcodec_ctx *)h->ctx)->id, \ |
69 | __func__, ##args); \ |
70 | } while (0) |
71 | |
72 | #define aml_vcodec_debug_enter(h) aml_vcodec_debug(h, "+") |
73 | #define aml_vcodec_debug_leave(h) aml_vcodec_debug(h, "-") |
74 | |
75 | #else |
76 | |
77 | #define aml_v4l2_debug(level, fmt, args...) |
78 | #define aml_v4l2_debug_enter() |
79 | #define aml_v4l2_debug_leave() |
80 | |
81 | #define aml_vcodec_debug(h, fmt, args...) |
82 | #define aml_vcodec_debug_enter(h) |
83 | #define aml_vcodec_debug_leave(h) |
84 | |
85 | #endif |
86 | |
87 | #define aml_v4l2_err(fmt, args...) \ |
88 | pr_err("[ERR]" fmt "\n", ##args) |
89 | |
90 | #define aml_vcodec_err(h, fmt, args...) \ |
91 | pr_err("[ERR][%d]" fmt "\n", \ |
92 | ((struct aml_vcodec_ctx *)h->ctx)->id, ##args) |
93 | |
94 | void __iomem *aml_vcodec_get_reg_addr(struct aml_vcodec_ctx *data, |
95 | unsigned int reg_idx); |
96 | int aml_vcodec_mem_alloc(struct aml_vcodec_ctx *data, |
97 | struct aml_vcodec_mem *mem); |
98 | void aml_vcodec_mem_free(struct aml_vcodec_ctx *data, |
99 | struct aml_vcodec_mem *mem); |
100 | void aml_vcodec_set_curr_ctx(struct aml_vcodec_dev *dev, |
101 | struct aml_vcodec_ctx *ctx); |
102 | struct aml_vcodec_ctx *aml_vcodec_get_curr_ctx(struct aml_vcodec_dev *dev); |
103 | |
104 | #endif /* _AML_VCODEC_UTIL_H_ */ |
105 |