1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _MTK_VCODEC_DRV_H_
17#define _MTK_VCODEC_DRV_H_
18
19#include <linux/platform_device.h>
20#include <linux/videodev2.h>
21#include <media/v4l2-ctrls.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-ioctl.h>
24#include <media/videobuf2-core.h>
25#include "mtk_vcodec_util.h"
26
27#define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv"
28#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
29#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
30#define MTK_PLATFORM_STR "platform:mt8173"
31
32#define MTK_VCODEC_MAX_PLANES 3
33#define MTK_V4L2_BENCHMARK 0
34#define WAIT_INTR_TIMEOUT_MS 1000
35
36
37
38
39enum mtk_hw_reg_idx {
40 VDEC_SYS,
41 VDEC_MISC,
42 VDEC_LD,
43 VDEC_TOP,
44 VDEC_CM,
45 VDEC_AD,
46 VDEC_AV,
47 VDEC_PP,
48 VDEC_HWD,
49 VDEC_HWQ,
50 VDEC_HWB,
51 VDEC_HWG,
52 NUM_MAX_VDEC_REG_BASE,
53
54 VENC_SYS = NUM_MAX_VDEC_REG_BASE,
55
56 VENC_LT_SYS,
57 NUM_MAX_VCODEC_REG_BASE
58};
59
60
61
62
63enum mtk_instance_type {
64 MTK_INST_DECODER = 0,
65 MTK_INST_ENCODER = 1,
66};
67
68
69
70
71
72
73
74
75
76
77enum mtk_instance_state {
78 MTK_STATE_FREE = 0,
79 MTK_STATE_INIT = 1,
80 MTK_STATE_HEADER = 2,
81 MTK_STATE_FLUSH = 3,
82 MTK_STATE_ABORT = 4,
83};
84
85
86
87
88enum mtk_encode_param {
89 MTK_ENCODE_PARAM_NONE = 0,
90 MTK_ENCODE_PARAM_BITRATE = (1 << 0),
91 MTK_ENCODE_PARAM_FRAMERATE = (1 << 1),
92 MTK_ENCODE_PARAM_INTRA_PERIOD = (1 << 2),
93 MTK_ENCODE_PARAM_FORCE_INTRA = (1 << 3),
94 MTK_ENCODE_PARAM_GOP_SIZE = (1 << 4),
95};
96
97enum mtk_fmt_type {
98 MTK_FMT_DEC = 0,
99 MTK_FMT_ENC = 1,
100 MTK_FMT_FRAME = 2,
101};
102
103
104
105
106struct mtk_video_fmt {
107 u32 fourcc;
108 enum mtk_fmt_type type;
109 u32 num_planes;
110};
111
112
113
114
115
116struct mtk_codec_framesizes {
117 u32 fourcc;
118 struct v4l2_frmsize_stepwise stepwise;
119};
120
121
122
123
124enum mtk_q_type {
125 MTK_Q_DATA_SRC = 0,
126 MTK_Q_DATA_DST = 1,
127};
128
129
130
131
132struct mtk_q_data {
133 unsigned int visible_width;
134 unsigned int visible_height;
135 unsigned int coded_width;
136 unsigned int coded_height;
137 enum v4l2_field field;
138 unsigned int bytesperline[MTK_VCODEC_MAX_PLANES];
139 unsigned int sizeimage[MTK_VCODEC_MAX_PLANES];
140 struct mtk_video_fmt *fmt;
141};
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162struct mtk_enc_params {
163 unsigned int bitrate;
164 unsigned int num_b_frame;
165 unsigned int rc_frame;
166 unsigned int rc_mb;
167 unsigned int seq_hdr_mode;
168 unsigned int intra_period;
169 unsigned int gop_size;
170 unsigned int framerate_num;
171 unsigned int framerate_denom;
172 unsigned int h264_max_qp;
173 unsigned int h264_profile;
174 unsigned int h264_level;
175 unsigned int force_intra;
176};
177
178
179
180
181struct mtk_vcodec_pm {
182 struct clk *vdec_bus_clk_src;
183 struct clk *vencpll;
184
185 struct clk *vcodecpll;
186 struct clk *univpll_d2;
187 struct clk *clk_cci400_sel;
188 struct clk *vdecpll;
189 struct clk *vdec_sel;
190 struct clk *vencpll_d2;
191 struct clk *venc_sel;
192 struct clk *univpll1_d2;
193 struct clk *venc_lt_sel;
194 struct device *larbvdec;
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
214
215
216struct vdec_pic_info {
217 unsigned int pic_w;
218 unsigned int pic_h;
219 unsigned int buf_w;
220 unsigned int buf_h;
221 unsigned int y_bs_sz;
222 unsigned int c_bs_sz;
223 unsigned int y_len_sz;
224 unsigned int c_len_sz;
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
263
264
265
266struct mtk_vcodec_ctx {
267 enum mtk_instance_type type;
268 struct mtk_vcodec_dev *dev;
269 struct list_head list;
270
271 struct v4l2_fh fh;
272 struct v4l2_m2m_ctx *m2m_ctx;
273 struct mtk_q_data q_data[2];
274 int id;
275 enum mtk_instance_state state;
276 enum mtk_encode_param param_change;
277 struct mtk_enc_params enc_params;
278
279 const struct vdec_common_if *dec_if;
280 const struct venc_common_if *enc_if;
281 unsigned long drv_handle;
282
283 struct vdec_pic_info picinfo;
284 int dpb_size;
285
286 int int_cond;
287 int int_type;
288 wait_queue_head_t queue;
289 unsigned int irq_status;
290
291 struct v4l2_ctrl_handler ctrl_hdl;
292 struct work_struct decode_work;
293 struct work_struct encode_work;
294 struct vdec_pic_info last_decoded_picinfo;
295 struct mtk_video_dec_buf *empty_flush_buf;
296
297 enum v4l2_colorspace colorspace;
298 enum v4l2_ycbcr_encoding ycbcr_enc;
299 enum v4l2_quantization quantization;
300 enum v4l2_xfer_func xfer_func;
301
302 int decoded_frame_cnt;
303 struct mutex lock;
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
340
341
342
343struct mtk_vcodec_dev {
344 struct v4l2_device v4l2_dev;
345 struct video_device *vfd_dec;
346 struct video_device *vfd_enc;
347
348 struct v4l2_m2m_dev *m2m_dev_dec;
349 struct v4l2_m2m_dev *m2m_dev_enc;
350 struct platform_device *plat_dev;
351 struct platform_device *vpu_plat_dev;
352 struct list_head ctx_list;
353 spinlock_t irqlock;
354 struct mtk_vcodec_ctx *curr_ctx;
355 void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
356
357 unsigned long id_counter;
358
359 struct workqueue_struct *decode_workqueue;
360 struct workqueue_struct *encode_workqueue;
361 int int_cond;
362 int int_type;
363 struct mutex dev_mutex;
364 wait_queue_head_t queue;
365
366 int dec_irq;
367 int enc_irq;
368 int enc_lt_irq;
369
370 struct mutex dec_mutex;
371 struct mutex enc_mutex;
372
373 struct mtk_vcodec_pm pm;
374 unsigned int dec_capability;
375 unsigned int enc_capability;
376};
377
378static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh)
379{
380 return container_of(fh, struct mtk_vcodec_ctx, fh);
381}
382
383static inline struct mtk_vcodec_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
384{
385 return container_of(ctrl->handler, struct mtk_vcodec_ctx, ctrl_hdl);
386}
387
388#endif
389