This source file includes following definitions.
- fh_to_ctx
- ctrl_to_ctx
1
2
3
4
5
6
7
8 #ifndef _MTK_VCODEC_DRV_H_
9 #define _MTK_VCODEC_DRV_H_
10
11 #include <linux/platform_device.h>
12 #include <linux/videodev2.h>
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-device.h>
15 #include <media/v4l2-ioctl.h>
16 #include <media/videobuf2-core.h>
17 #include "mtk_vcodec_util.h"
18
19 #define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv"
20 #define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
21 #define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
22 #define MTK_PLATFORM_STR "platform:mt8173"
23
24 #define MTK_VCODEC_MAX_PLANES 3
25 #define MTK_V4L2_BENCHMARK 0
26 #define WAIT_INTR_TIMEOUT_MS 1000
27
28
29
30
31 enum mtk_hw_reg_idx {
32 VDEC_SYS,
33 VDEC_MISC,
34 VDEC_LD,
35 VDEC_TOP,
36 VDEC_CM,
37 VDEC_AD,
38 VDEC_AV,
39 VDEC_PP,
40 VDEC_HWD,
41 VDEC_HWQ,
42 VDEC_HWB,
43 VDEC_HWG,
44 NUM_MAX_VDEC_REG_BASE,
45
46 VENC_SYS = NUM_MAX_VDEC_REG_BASE,
47
48 VENC_LT_SYS,
49 NUM_MAX_VCODEC_REG_BASE
50 };
51
52
53
54
55 enum mtk_instance_type {
56 MTK_INST_DECODER = 0,
57 MTK_INST_ENCODER = 1,
58 };
59
60
61
62
63
64
65
66
67
68
69 enum mtk_instance_state {
70 MTK_STATE_FREE = 0,
71 MTK_STATE_INIT = 1,
72 MTK_STATE_HEADER = 2,
73 MTK_STATE_FLUSH = 3,
74 MTK_STATE_ABORT = 4,
75 };
76
77
78
79
80 enum mtk_encode_param {
81 MTK_ENCODE_PARAM_NONE = 0,
82 MTK_ENCODE_PARAM_BITRATE = (1 << 0),
83 MTK_ENCODE_PARAM_FRAMERATE = (1 << 1),
84 MTK_ENCODE_PARAM_INTRA_PERIOD = (1 << 2),
85 MTK_ENCODE_PARAM_FORCE_INTRA = (1 << 3),
86 MTK_ENCODE_PARAM_GOP_SIZE = (1 << 4),
87 };
88
89 enum mtk_fmt_type {
90 MTK_FMT_DEC = 0,
91 MTK_FMT_ENC = 1,
92 MTK_FMT_FRAME = 2,
93 };
94
95
96
97
98 struct mtk_video_fmt {
99 u32 fourcc;
100 enum mtk_fmt_type type;
101 u32 num_planes;
102 u32 flags;
103 };
104
105
106
107
108
109 struct mtk_codec_framesizes {
110 u32 fourcc;
111 struct v4l2_frmsize_stepwise stepwise;
112 };
113
114
115
116
117 enum mtk_q_type {
118 MTK_Q_DATA_SRC = 0,
119 MTK_Q_DATA_DST = 1,
120 };
121
122
123
124
125 struct mtk_q_data {
126 unsigned int visible_width;
127 unsigned int visible_height;
128 unsigned int coded_width;
129 unsigned int coded_height;
130 enum v4l2_field field;
131 unsigned int bytesperline[MTK_VCODEC_MAX_PLANES];
132 unsigned int sizeimage[MTK_VCODEC_MAX_PLANES];
133 const struct mtk_video_fmt *fmt;
134 };
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 struct mtk_enc_params {
156 unsigned int bitrate;
157 unsigned int num_b_frame;
158 unsigned int rc_frame;
159 unsigned int rc_mb;
160 unsigned int seq_hdr_mode;
161 unsigned int intra_period;
162 unsigned int gop_size;
163 unsigned int framerate_num;
164 unsigned int framerate_denom;
165 unsigned int h264_max_qp;
166 unsigned int h264_profile;
167 unsigned int h264_level;
168 unsigned int force_intra;
169 };
170
171
172
173
174 struct mtk_vcodec_clk_info {
175 const char *clk_name;
176 struct clk *vcodec_clk;
177 };
178
179
180
181
182 struct mtk_vcodec_clk {
183 struct mtk_vcodec_clk_info *clk_info;
184 int clk_num;
185 };
186
187
188
189
190 struct mtk_vcodec_pm {
191 struct mtk_vcodec_clk vdec_clk;
192 struct device *larbvdec;
193
194 struct mtk_vcodec_clk venc_clk;
195 struct device *larbvenc;
196 struct device *larbvenclt;
197 struct device *dev;
198 struct mtk_vcodec_dev *mtkdev;
199 };
200
201
202
203
204
205
206
207
208
209
210
211
212
213 struct vdec_pic_info {
214 unsigned int pic_w;
215 unsigned int pic_h;
216 unsigned int buf_w;
217 unsigned int buf_h;
218 unsigned int fb_sz[VIDEO_MAX_PLANES];
219 unsigned int cap_fourcc;
220 unsigned int reserved;
221 };
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262 struct mtk_vcodec_ctx {
263 enum mtk_instance_type type;
264 struct mtk_vcodec_dev *dev;
265 struct list_head list;
266
267 struct v4l2_fh fh;
268 struct v4l2_m2m_ctx *m2m_ctx;
269 struct mtk_q_data q_data[2];
270 int id;
271 enum mtk_instance_state state;
272 enum mtk_encode_param param_change;
273 struct mtk_enc_params enc_params;
274
275 const struct vdec_common_if *dec_if;
276 const struct venc_common_if *enc_if;
277 void *drv_handle;
278
279 struct vdec_pic_info picinfo;
280 int dpb_size;
281
282 int int_cond;
283 int int_type;
284 wait_queue_head_t queue;
285 unsigned int irq_status;
286
287 struct v4l2_ctrl_handler ctrl_hdl;
288 struct work_struct decode_work;
289 struct work_struct encode_work;
290 struct vdec_pic_info last_decoded_picinfo;
291 struct mtk_video_dec_buf *empty_flush_buf;
292
293 enum v4l2_colorspace colorspace;
294 enum v4l2_ycbcr_encoding ycbcr_enc;
295 enum v4l2_quantization quantization;
296 enum v4l2_xfer_func xfer_func;
297
298 int decoded_frame_cnt;
299 struct mutex lock;
300
301 };
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339 struct mtk_vcodec_dev {
340 struct v4l2_device v4l2_dev;
341 struct video_device *vfd_dec;
342 struct video_device *vfd_enc;
343
344 struct v4l2_m2m_dev *m2m_dev_dec;
345 struct v4l2_m2m_dev *m2m_dev_enc;
346 struct platform_device *plat_dev;
347 struct platform_device *vpu_plat_dev;
348 struct list_head ctx_list;
349 spinlock_t irqlock;
350 struct mtk_vcodec_ctx *curr_ctx;
351 void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
352
353 unsigned long id_counter;
354
355 struct workqueue_struct *decode_workqueue;
356 struct workqueue_struct *encode_workqueue;
357 int int_cond;
358 int int_type;
359 struct mutex dev_mutex;
360 wait_queue_head_t queue;
361
362 int dec_irq;
363 int enc_irq;
364 int enc_lt_irq;
365
366 struct mutex dec_mutex;
367 struct mutex enc_mutex;
368
369 struct mtk_vcodec_pm pm;
370 unsigned int dec_capability;
371 unsigned int enc_capability;
372 };
373
374 static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh)
375 {
376 return container_of(fh, struct mtk_vcodec_ctx, fh);
377 }
378
379 static inline struct mtk_vcodec_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
380 {
381 return container_of(ctrl->handler, struct mtk_vcodec_ctx, ctrl_hdl);
382 }
383
384 #endif