[media] media: s5p-mfc: use vb2_ops_wait_prepare/finish helper
[deliverable/linux.git] / drivers / media / platform / s5p-mfc / s5p_mfc_enc.c
1 /*
2 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
3 *
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * Jeongtae Park <jtp.park@samsung.com>
8 * Kamil Debski <k.debski@samsung.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 */
15
16 #include <linux/clk.h>
17 #include <linux/interrupt.h>
18 #include <linux/io.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/sched.h>
22 #include <linux/version.h>
23 #include <linux/videodev2.h>
24 #include <media/v4l2-event.h>
25 #include <linux/workqueue.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/videobuf2-core.h>
28 #include "s5p_mfc_common.h"
29 #include "s5p_mfc_ctrl.h"
30 #include "s5p_mfc_debug.h"
31 #include "s5p_mfc_enc.h"
32 #include "s5p_mfc_intr.h"
33 #include "s5p_mfc_opr.h"
34
35 #define DEF_SRC_FMT_ENC V4L2_PIX_FMT_NV12M
36 #define DEF_DST_FMT_ENC V4L2_PIX_FMT_H264
37
38 static struct s5p_mfc_fmt formats[] = {
39 {
40 .name = "4:2:0 2 Planes 16x16 Tiles",
41 .fourcc = V4L2_PIX_FMT_NV12MT_16X16,
42 .codec_mode = S5P_MFC_CODEC_NONE,
43 .type = MFC_FMT_RAW,
44 .num_planes = 2,
45 .versions = MFC_V6_BIT | MFC_V7_BIT,
46 },
47 {
48 .name = "4:2:0 2 Planes 64x32 Tiles",
49 .fourcc = V4L2_PIX_FMT_NV12MT,
50 .codec_mode = S5P_MFC_CODEC_NONE,
51 .type = MFC_FMT_RAW,
52 .num_planes = 2,
53 .versions = MFC_V5_BIT,
54 },
55 {
56 .name = "4:2:0 2 Planes Y/CbCr",
57 .fourcc = V4L2_PIX_FMT_NV12M,
58 .codec_mode = S5P_MFC_CODEC_NONE,
59 .type = MFC_FMT_RAW,
60 .num_planes = 2,
61 .versions = MFC_V5_BIT | MFC_V6_BIT | MFC_V7_BIT |
62 MFC_V8_BIT,
63 },
64 {
65 .name = "4:2:0 2 Planes Y/CrCb",
66 .fourcc = V4L2_PIX_FMT_NV21M,
67 .codec_mode = S5P_MFC_CODEC_NONE,
68 .type = MFC_FMT_RAW,
69 .num_planes = 2,
70 .versions = MFC_V6_BIT | MFC_V7_BIT | MFC_V8_BIT,
71 },
72 {
73 .name = "H264 Encoded Stream",
74 .fourcc = V4L2_PIX_FMT_H264,
75 .codec_mode = S5P_MFC_CODEC_H264_ENC,
76 .type = MFC_FMT_ENC,
77 .num_planes = 1,
78 .versions = MFC_V5_BIT | MFC_V6_BIT | MFC_V7_BIT |
79 MFC_V8_BIT,
80 },
81 {
82 .name = "MPEG4 Encoded Stream",
83 .fourcc = V4L2_PIX_FMT_MPEG4,
84 .codec_mode = S5P_MFC_CODEC_MPEG4_ENC,
85 .type = MFC_FMT_ENC,
86 .num_planes = 1,
87 .versions = MFC_V5_BIT | MFC_V6_BIT | MFC_V7_BIT |
88 MFC_V8_BIT,
89 },
90 {
91 .name = "H263 Encoded Stream",
92 .fourcc = V4L2_PIX_FMT_H263,
93 .codec_mode = S5P_MFC_CODEC_H263_ENC,
94 .type = MFC_FMT_ENC,
95 .num_planes = 1,
96 .versions = MFC_V5_BIT | MFC_V6_BIT | MFC_V7_BIT |
97 MFC_V8_BIT,
98 },
99 {
100 .name = "VP8 Encoded Stream",
101 .fourcc = V4L2_PIX_FMT_VP8,
102 .codec_mode = S5P_MFC_CODEC_VP8_ENC,
103 .type = MFC_FMT_ENC,
104 .num_planes = 1,
105 .versions = MFC_V7_BIT | MFC_V8_BIT,
106 },
107 };
108
109 #define NUM_FORMATS ARRAY_SIZE(formats)
110 static struct s5p_mfc_fmt *find_format(struct v4l2_format *f, unsigned int t)
111 {
112 unsigned int i;
113
114 for (i = 0; i < NUM_FORMATS; i++) {
115 if (formats[i].fourcc == f->fmt.pix_mp.pixelformat &&
116 formats[i].type == t)
117 return &formats[i];
118 }
119 return NULL;
120 }
121
122 static struct mfc_control controls[] = {
123 {
124 .id = V4L2_CID_MPEG_VIDEO_GOP_SIZE,
125 .type = V4L2_CTRL_TYPE_INTEGER,
126 .minimum = 0,
127 .maximum = (1 << 16) - 1,
128 .step = 1,
129 .default_value = 12,
130 },
131 {
132 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
133 .type = V4L2_CTRL_TYPE_MENU,
134 .minimum = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
135 .maximum = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES,
136 .default_value = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
137 .menu_skip_mask = 0,
138 },
139 {
140 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .minimum = 1,
143 .maximum = (1 << 16) - 1,
144 .step = 1,
145 .default_value = 1,
146 },
147 {
148 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES,
149 .type = V4L2_CTRL_TYPE_INTEGER,
150 .minimum = 1900,
151 .maximum = (1 << 30) - 1,
152 .step = 1,
153 .default_value = 1900,
154 },
155 {
156 .id = V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB,
157 .type = V4L2_CTRL_TYPE_INTEGER,
158 .minimum = 0,
159 .maximum = (1 << 16) - 1,
160 .step = 1,
161 .default_value = 0,
162 },
163 {
164 .id = V4L2_CID_MPEG_MFC51_VIDEO_PADDING,
165 .type = V4L2_CTRL_TYPE_BOOLEAN,
166 .name = "Padding Control Enable",
167 .minimum = 0,
168 .maximum = 1,
169 .step = 1,
170 .default_value = 0,
171 },
172 {
173 .id = V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV,
174 .type = V4L2_CTRL_TYPE_INTEGER,
175 .name = "Padding Color YUV Value",
176 .minimum = 0,
177 .maximum = (1 << 25) - 1,
178 .step = 1,
179 .default_value = 0,
180 },
181 {
182 .id = V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE,
183 .type = V4L2_CTRL_TYPE_BOOLEAN,
184 .minimum = 0,
185 .maximum = 1,
186 .step = 1,
187 .default_value = 0,
188 },
189 {
190 .id = V4L2_CID_MPEG_VIDEO_BITRATE,
191 .type = V4L2_CTRL_TYPE_INTEGER,
192 .minimum = 1,
193 .maximum = (1 << 30) - 1,
194 .step = 1,
195 .default_value = 1,
196 },
197 {
198 .id = V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF,
199 .type = V4L2_CTRL_TYPE_INTEGER,
200 .name = "Rate Control Reaction Coeff.",
201 .minimum = 1,
202 .maximum = (1 << 16) - 1,
203 .step = 1,
204 .default_value = 1,
205 },
206 {
207 .id = V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE,
208 .type = V4L2_CTRL_TYPE_MENU,
209 .name = "Force frame type",
210 .minimum = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED,
211 .maximum = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED,
212 .default_value = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED,
213 .menu_skip_mask = 0,
214 },
215 {
216 .id = V4L2_CID_MPEG_VIDEO_VBV_SIZE,
217 .type = V4L2_CTRL_TYPE_INTEGER,
218 .minimum = 0,
219 .maximum = (1 << 16) - 1,
220 .step = 1,
221 .default_value = 0,
222 },
223 {
224 .id = V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE,
225 .type = V4L2_CTRL_TYPE_INTEGER,
226 .name = "Horizontal MV Search Range",
227 .minimum = 16,
228 .maximum = 128,
229 .step = 16,
230 .default_value = 32,
231 },
232 {
233 .id = V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE,
234 .type = V4L2_CTRL_TYPE_INTEGER,
235 .name = "Vertical MV Search Range",
236 .minimum = 16,
237 .maximum = 128,
238 .step = 16,
239 .default_value = 32,
240 },
241 {
242 .id = V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE,
243 .type = V4L2_CTRL_TYPE_INTEGER,
244 .minimum = 0,
245 .maximum = (1 << 16) - 1,
246 .step = 1,
247 .default_value = 0,
248 },
249 {
250 .id = V4L2_CID_MPEG_VIDEO_HEADER_MODE,
251 .type = V4L2_CTRL_TYPE_MENU,
252 .minimum = V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE,
253 .maximum = V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
254 .default_value = V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE,
255 .menu_skip_mask = 0,
256 },
257 {
258 .id = V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE,
259 .type = V4L2_CTRL_TYPE_MENU,
260 .name = "Frame Skip Enable",
261 .minimum = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED,
262 .maximum = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT,
263 .menu_skip_mask = 0,
264 .default_value = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED,
265 },
266 {
267 .id = V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT,
268 .type = V4L2_CTRL_TYPE_BOOLEAN,
269 .name = "Fixed Target Bit Enable",
270 .minimum = 0,
271 .maximum = 1,
272 .default_value = 0,
273 .step = 1,
274 .menu_skip_mask = 0,
275 },
276 {
277 .id = V4L2_CID_MPEG_VIDEO_B_FRAMES,
278 .type = V4L2_CTRL_TYPE_INTEGER,
279 .minimum = 0,
280 .maximum = 2,
281 .step = 1,
282 .default_value = 0,
283 },
284 {
285 .id = V4L2_CID_MPEG_VIDEO_H264_PROFILE,
286 .type = V4L2_CTRL_TYPE_MENU,
287 .minimum = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
288 .maximum = V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH,
289 .default_value = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
290 .menu_skip_mask = ~(
291 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
292 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
293 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)
294 ),
295 },
296 {
297 .id = V4L2_CID_MPEG_VIDEO_H264_LEVEL,
298 .type = V4L2_CTRL_TYPE_MENU,
299 .minimum = V4L2_MPEG_VIDEO_H264_LEVEL_1_0,
300 .maximum = V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
301 .default_value = V4L2_MPEG_VIDEO_H264_LEVEL_1_0,
302 },
303 {
304 .id = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL,
305 .type = V4L2_CTRL_TYPE_MENU,
306 .minimum = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0,
307 .maximum = V4L2_MPEG_VIDEO_MPEG4_LEVEL_5,
308 .default_value = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0,
309 .menu_skip_mask = 0,
310 },
311 {
312 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
313 .type = V4L2_CTRL_TYPE_MENU,
314 .minimum = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED,
315 .maximum = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY,
316 .default_value = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED,
317 .menu_skip_mask = 0,
318 },
319 {
320 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA,
321 .type = V4L2_CTRL_TYPE_INTEGER,
322 .minimum = -6,
323 .maximum = 6,
324 .step = 1,
325 .default_value = 0,
326 },
327 {
328 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA,
329 .type = V4L2_CTRL_TYPE_INTEGER,
330 .minimum = -6,
331 .maximum = 6,
332 .step = 1,
333 .default_value = 0,
334 },
335 {
336 .id = V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE,
337 .type = V4L2_CTRL_TYPE_MENU,
338 .minimum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
339 .maximum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC,
340 .default_value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
341 .menu_skip_mask = 0,
342 },
343 {
344 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P,
345 .type = V4L2_CTRL_TYPE_INTEGER,
346 .name = "The Number of Ref. Pic for P",
347 .minimum = 1,
348 .maximum = 2,
349 .step = 1,
350 .default_value = 1,
351 },
352 {
353 .id = V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM,
354 .type = V4L2_CTRL_TYPE_BOOLEAN,
355 .minimum = 0,
356 .maximum = 1,
357 .step = 1,
358 .default_value = 0,
359 },
360 {
361 .id = V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE,
362 .type = V4L2_CTRL_TYPE_BOOLEAN,
363 .minimum = 0,
364 .maximum = 1,
365 .step = 1,
366 .default_value = 0,
367 },
368 {
369 .id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP,
370 .type = V4L2_CTRL_TYPE_INTEGER,
371 .minimum = 0,
372 .maximum = 51,
373 .step = 1,
374 .default_value = 1,
375 },
376 {
377 .id = V4L2_CID_MPEG_VIDEO_H264_MIN_QP,
378 .type = V4L2_CTRL_TYPE_INTEGER,
379 .minimum = 0,
380 .maximum = 51,
381 .step = 1,
382 .default_value = 1,
383 },
384 {
385 .id = V4L2_CID_MPEG_VIDEO_H264_MAX_QP,
386 .type = V4L2_CTRL_TYPE_INTEGER,
387 .minimum = 0,
388 .maximum = 51,
389 .step = 1,
390 .default_value = 51,
391 },
392 {
393 .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP,
394 .type = V4L2_CTRL_TYPE_INTEGER,
395 .minimum = 0,
396 .maximum = 51,
397 .step = 1,
398 .default_value = 1,
399 },
400 {
401 .id = V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP,
402 .type = V4L2_CTRL_TYPE_INTEGER,
403 .minimum = 0,
404 .maximum = 51,
405 .step = 1,
406 .default_value = 1,
407 },
408 {
409 .id = V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP,
410 .type = V4L2_CTRL_TYPE_INTEGER,
411 .name = "H263 I-Frame QP value",
412 .minimum = 1,
413 .maximum = 31,
414 .step = 1,
415 .default_value = 1,
416 },
417 {
418 .id = V4L2_CID_MPEG_VIDEO_H263_MIN_QP,
419 .type = V4L2_CTRL_TYPE_INTEGER,
420 .name = "H263 Minimum QP value",
421 .minimum = 1,
422 .maximum = 31,
423 .step = 1,
424 .default_value = 1,
425 },
426 {
427 .id = V4L2_CID_MPEG_VIDEO_H263_MAX_QP,
428 .type = V4L2_CTRL_TYPE_INTEGER,
429 .name = "H263 Maximum QP value",
430 .minimum = 1,
431 .maximum = 31,
432 .step = 1,
433 .default_value = 31,
434 },
435 {
436 .id = V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP,
437 .type = V4L2_CTRL_TYPE_INTEGER,
438 .name = "H263 P frame QP value",
439 .minimum = 1,
440 .maximum = 31,
441 .step = 1,
442 .default_value = 1,
443 },
444 {
445 .id = V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP,
446 .type = V4L2_CTRL_TYPE_INTEGER,
447 .name = "H263 B frame QP value",
448 .minimum = 1,
449 .maximum = 31,
450 .step = 1,
451 .default_value = 1,
452 },
453 {
454 .id = V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP,
455 .type = V4L2_CTRL_TYPE_INTEGER,
456 .name = "MPEG4 I-Frame QP value",
457 .minimum = 1,
458 .maximum = 31,
459 .step = 1,
460 .default_value = 1,
461 },
462 {
463 .id = V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP,
464 .type = V4L2_CTRL_TYPE_INTEGER,
465 .name = "MPEG4 Minimum QP value",
466 .minimum = 1,
467 .maximum = 31,
468 .step = 1,
469 .default_value = 1,
470 },
471 {
472 .id = V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP,
473 .type = V4L2_CTRL_TYPE_INTEGER,
474 .name = "MPEG4 Maximum QP value",
475 .minimum = 0,
476 .maximum = 51,
477 .step = 1,
478 .default_value = 51,
479 },
480 {
481 .id = V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP,
482 .type = V4L2_CTRL_TYPE_INTEGER,
483 .name = "MPEG4 P frame QP value",
484 .minimum = 1,
485 .maximum = 31,
486 .step = 1,
487 .default_value = 1,
488 },
489 {
490 .id = V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP,
491 .type = V4L2_CTRL_TYPE_INTEGER,
492 .name = "MPEG4 B frame QP value",
493 .minimum = 1,
494 .maximum = 31,
495 .step = 1,
496 .default_value = 1,
497 },
498 {
499 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK,
500 .type = V4L2_CTRL_TYPE_BOOLEAN,
501 .name = "H264 Dark Reg Adaptive RC",
502 .minimum = 0,
503 .maximum = 1,
504 .step = 1,
505 .default_value = 0,
506 },
507 {
508 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH,
509 .type = V4L2_CTRL_TYPE_BOOLEAN,
510 .name = "H264 Smooth Reg Adaptive RC",
511 .minimum = 0,
512 .maximum = 1,
513 .step = 1,
514 .default_value = 0,
515 },
516 {
517 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC,
518 .type = V4L2_CTRL_TYPE_BOOLEAN,
519 .name = "H264 Static Reg Adaptive RC",
520 .minimum = 0,
521 .maximum = 1,
522 .step = 1,
523 .default_value = 0,
524 },
525 {
526 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY,
527 .type = V4L2_CTRL_TYPE_BOOLEAN,
528 .name = "H264 Activity Reg Adaptive RC",
529 .minimum = 0,
530 .maximum = 1,
531 .step = 1,
532 .default_value = 0,
533 },
534 {
535 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE,
536 .type = V4L2_CTRL_TYPE_BOOLEAN,
537 .minimum = 0,
538 .maximum = 1,
539 .step = 1,
540 .default_value = 0,
541 },
542 {
543 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC,
544 .type = V4L2_CTRL_TYPE_MENU,
545 .minimum = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED,
546 .maximum = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED,
547 .default_value = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED,
548 .menu_skip_mask = 0,
549 },
550 {
551 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH,
552 .type = V4L2_CTRL_TYPE_INTEGER,
553 .minimum = 0,
554 .maximum = (1 << 16) - 1,
555 .step = 1,
556 .default_value = 0,
557 },
558 {
559 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT,
560 .type = V4L2_CTRL_TYPE_INTEGER,
561 .minimum = 0,
562 .maximum = (1 << 16) - 1,
563 .step = 1,
564 .default_value = 0,
565 },
566 {
567 .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
568 .type = V4L2_CTRL_TYPE_BOOLEAN,
569 .minimum = 0,
570 .maximum = 1,
571 .step = 1,
572 .default_value = 1,
573 },
574 {
575 .id = V4L2_CID_MPEG_VIDEO_H264_I_PERIOD,
576 .type = V4L2_CTRL_TYPE_INTEGER,
577 .minimum = 0,
578 .maximum = (1 << 16) - 1,
579 .step = 1,
580 .default_value = 0,
581 },
582 {
583 .id = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE,
584 .type = V4L2_CTRL_TYPE_MENU,
585 .minimum = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE,
586 .maximum = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE,
587 .default_value = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE,
588 .menu_skip_mask = 0,
589 },
590 {
591 .id = V4L2_CID_MPEG_VIDEO_MPEG4_QPEL,
592 .type = V4L2_CTRL_TYPE_BOOLEAN,
593 .minimum = 0,
594 .maximum = 1,
595 .step = 1,
596 .default_value = 0,
597 },
598 {
599 .id = V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS,
600 .type = V4L2_CTRL_TYPE_INTEGER_MENU,
601 .maximum = V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS,
602 .default_value = V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION,
603 .menu_skip_mask = 0,
604 },
605 {
606 .id = V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4,
607 .type = V4L2_CTRL_TYPE_BOOLEAN,
608 .minimum = 0,
609 .maximum = 1,
610 .step = 1,
611 .default_value = 0,
612 },
613 {
614 .id = V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES,
615 .type = V4L2_CTRL_TYPE_INTEGER_MENU,
616 .maximum = V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME,
617 .default_value = V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME,
618 .menu_skip_mask = 0,
619 },
620 {
621 .id = V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL,
622 .type = V4L2_CTRL_TYPE_INTEGER,
623 .minimum = 0,
624 .maximum = 63,
625 .step = 1,
626 .default_value = 0,
627 },
628 {
629 .id = V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS,
630 .type = V4L2_CTRL_TYPE_INTEGER,
631 .minimum = 0,
632 .maximum = 7,
633 .step = 1,
634 .default_value = 0,
635 },
636 {
637 .id = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD,
638 .type = V4L2_CTRL_TYPE_INTEGER,
639 .minimum = 0,
640 .maximum = (1 << 16) - 1,
641 .step = 1,
642 .default_value = 0,
643 },
644 {
645 .id = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL,
646 .type = V4L2_CTRL_TYPE_MENU,
647 .minimum = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV,
648 .maximum = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD,
649 .default_value = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV,
650 .menu_skip_mask = 0,
651 },
652 {
653 .id = V4L2_CID_MPEG_VIDEO_VPX_MAX_QP,
654 .type = V4L2_CTRL_TYPE_INTEGER,
655 .minimum = 0,
656 .maximum = 127,
657 .step = 1,
658 .default_value = 127,
659 },
660 {
661 .id = V4L2_CID_MPEG_VIDEO_VPX_MIN_QP,
662 .type = V4L2_CTRL_TYPE_INTEGER,
663 .minimum = 0,
664 .maximum = 11,
665 .step = 1,
666 .default_value = 0,
667 },
668 {
669 .id = V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP,
670 .type = V4L2_CTRL_TYPE_INTEGER,
671 .minimum = 0,
672 .maximum = 127,
673 .step = 1,
674 .default_value = 10,
675 },
676 {
677 .id = V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP,
678 .type = V4L2_CTRL_TYPE_INTEGER,
679 .minimum = 0,
680 .maximum = 127,
681 .step = 1,
682 .default_value = 10,
683 },
684 {
685 .id = V4L2_CID_MPEG_VIDEO_VPX_PROFILE,
686 .type = V4L2_CTRL_TYPE_INTEGER,
687 .minimum = 0,
688 .maximum = 3,
689 .step = 1,
690 .default_value = 0,
691 },
692 {
693 .id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
694 .type = V4L2_CTRL_TYPE_INTEGER,
695 .name = "Minimum number of output bufs",
696 .minimum = 1,
697 .maximum = 32,
698 .step = 1,
699 .default_value = 1,
700 .is_volatile = 1,
701 },
702 };
703
704 #define NUM_CTRLS ARRAY_SIZE(controls)
705 static const char * const *mfc51_get_menu(u32 id)
706 {
707 static const char * const mfc51_video_frame_skip[] = {
708 "Disabled",
709 "Level Limit",
710 "VBV/CPB Limit",
711 NULL,
712 };
713 static const char * const mfc51_video_force_frame[] = {
714 "Disabled",
715 "I Frame",
716 "Not Coded",
717 NULL,
718 };
719 switch (id) {
720 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE:
721 return mfc51_video_frame_skip;
722 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE:
723 return mfc51_video_force_frame;
724 }
725 return NULL;
726 }
727
728 static int s5p_mfc_ctx_ready(struct s5p_mfc_ctx *ctx)
729 {
730 mfc_debug(2, "src=%d, dst=%d, state=%d\n",
731 ctx->src_queue_cnt, ctx->dst_queue_cnt, ctx->state);
732 /* context is ready to make header */
733 if (ctx->state == MFCINST_GOT_INST && ctx->dst_queue_cnt >= 1)
734 return 1;
735 /* context is ready to encode a frame */
736 if ((ctx->state == MFCINST_RUNNING ||
737 ctx->state == MFCINST_HEAD_PRODUCED) &&
738 ctx->src_queue_cnt >= 1 && ctx->dst_queue_cnt >= 1)
739 return 1;
740 /* context is ready to encode remaining frames */
741 if (ctx->state == MFCINST_FINISHING &&
742 ctx->dst_queue_cnt >= 1)
743 return 1;
744 mfc_debug(2, "ctx is not ready\n");
745 return 0;
746 }
747
748 static void cleanup_ref_queue(struct s5p_mfc_ctx *ctx)
749 {
750 struct s5p_mfc_buf *mb_entry;
751
752 /* move buffers in ref queue to src queue */
753 while (!list_empty(&ctx->ref_queue)) {
754 mb_entry = list_entry((&ctx->ref_queue)->next,
755 struct s5p_mfc_buf, list);
756 list_del(&mb_entry->list);
757 ctx->ref_queue_cnt--;
758 list_add_tail(&mb_entry->list, &ctx->src_queue);
759 ctx->src_queue_cnt++;
760 }
761 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
762 ctx->src_queue_cnt, ctx->ref_queue_cnt);
763 INIT_LIST_HEAD(&ctx->ref_queue);
764 ctx->ref_queue_cnt = 0;
765 }
766
767 static int enc_pre_seq_start(struct s5p_mfc_ctx *ctx)
768 {
769 struct s5p_mfc_dev *dev = ctx->dev;
770 struct s5p_mfc_buf *dst_mb;
771 unsigned long dst_addr;
772 unsigned int dst_size;
773 unsigned long flags;
774
775 spin_lock_irqsave(&dev->irqlock, flags);
776 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
777 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
778 dst_size = vb2_plane_size(dst_mb->b, 0);
779 s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
780 dst_size);
781 spin_unlock_irqrestore(&dev->irqlock, flags);
782 return 0;
783 }
784
785 static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
786 {
787 struct s5p_mfc_dev *dev = ctx->dev;
788 struct s5p_mfc_enc_params *p = &ctx->enc_params;
789 struct s5p_mfc_buf *dst_mb;
790 unsigned long flags;
791 unsigned int enc_pb_count;
792
793 if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) {
794 spin_lock_irqsave(&dev->irqlock, flags);
795 if (!list_empty(&ctx->dst_queue)) {
796 dst_mb = list_entry(ctx->dst_queue.next,
797 struct s5p_mfc_buf, list);
798 list_del(&dst_mb->list);
799 ctx->dst_queue_cnt--;
800 vb2_set_plane_payload(dst_mb->b, 0,
801 s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size,
802 dev));
803 vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE);
804 }
805 spin_unlock_irqrestore(&dev->irqlock, flags);
806 }
807
808 if (!IS_MFCV6_PLUS(dev)) {
809 ctx->state = MFCINST_RUNNING;
810 if (s5p_mfc_ctx_ready(ctx))
811 set_work_bit_irqsave(ctx);
812 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
813 } else {
814 enc_pb_count = s5p_mfc_hw_call(dev->mfc_ops,
815 get_enc_dpb_count, dev);
816 if (ctx->pb_count < enc_pb_count)
817 ctx->pb_count = enc_pb_count;
818 ctx->state = MFCINST_HEAD_PRODUCED;
819 }
820
821 return 0;
822 }
823
824 static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx)
825 {
826 struct s5p_mfc_dev *dev = ctx->dev;
827 struct s5p_mfc_buf *dst_mb;
828 struct s5p_mfc_buf *src_mb;
829 unsigned long flags;
830 unsigned long src_y_addr, src_c_addr, dst_addr;
831 unsigned int dst_size;
832
833 spin_lock_irqsave(&dev->irqlock, flags);
834 src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
835 src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
836 src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
837 s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_frame_buffer, ctx,
838 src_y_addr, src_c_addr);
839 spin_unlock_irqrestore(&dev->irqlock, flags);
840
841 spin_lock_irqsave(&dev->irqlock, flags);
842 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
843 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
844 dst_size = vb2_plane_size(dst_mb->b, 0);
845 s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
846 dst_size);
847 spin_unlock_irqrestore(&dev->irqlock, flags);
848
849 return 0;
850 }
851
852 static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
853 {
854 struct s5p_mfc_dev *dev = ctx->dev;
855 struct s5p_mfc_buf *mb_entry;
856 unsigned long enc_y_addr, enc_c_addr;
857 unsigned long mb_y_addr, mb_c_addr;
858 int slice_type;
859 unsigned int strm_size;
860 unsigned long flags;
861
862 slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
863 strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
864 mfc_debug(2, "Encoded slice type: %d\n", slice_type);
865 mfc_debug(2, "Encoded stream size: %d\n", strm_size);
866 mfc_debug(2, "Display order: %d\n",
867 mfc_read(dev, S5P_FIMV_ENC_SI_PIC_CNT));
868 spin_lock_irqsave(&dev->irqlock, flags);
869 if (slice_type >= 0) {
870 s5p_mfc_hw_call_void(dev->mfc_ops, get_enc_frame_buffer, ctx,
871 &enc_y_addr, &enc_c_addr);
872 list_for_each_entry(mb_entry, &ctx->src_queue, list) {
873 mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
874 mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
875 if ((enc_y_addr == mb_y_addr) &&
876 (enc_c_addr == mb_c_addr)) {
877 list_del(&mb_entry->list);
878 ctx->src_queue_cnt--;
879 vb2_buffer_done(mb_entry->b,
880 VB2_BUF_STATE_DONE);
881 break;
882 }
883 }
884 list_for_each_entry(mb_entry, &ctx->ref_queue, list) {
885 mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
886 mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
887 if ((enc_y_addr == mb_y_addr) &&
888 (enc_c_addr == mb_c_addr)) {
889 list_del(&mb_entry->list);
890 ctx->ref_queue_cnt--;
891 vb2_buffer_done(mb_entry->b,
892 VB2_BUF_STATE_DONE);
893 break;
894 }
895 }
896 }
897 if ((ctx->src_queue_cnt > 0) && (ctx->state == MFCINST_RUNNING)) {
898 mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
899 list);
900 if (mb_entry->flags & MFC_BUF_FLAG_USED) {
901 list_del(&mb_entry->list);
902 ctx->src_queue_cnt--;
903 list_add_tail(&mb_entry->list, &ctx->ref_queue);
904 ctx->ref_queue_cnt++;
905 }
906 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
907 ctx->src_queue_cnt, ctx->ref_queue_cnt);
908 }
909 if ((ctx->dst_queue_cnt > 0) && (strm_size > 0)) {
910 mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf,
911 list);
912 list_del(&mb_entry->list);
913 ctx->dst_queue_cnt--;
914 switch (slice_type) {
915 case S5P_FIMV_ENC_SI_SLICE_TYPE_I:
916 mb_entry->b->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
917 break;
918 case S5P_FIMV_ENC_SI_SLICE_TYPE_P:
919 mb_entry->b->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
920 break;
921 case S5P_FIMV_ENC_SI_SLICE_TYPE_B:
922 mb_entry->b->v4l2_buf.flags |= V4L2_BUF_FLAG_BFRAME;
923 break;
924 }
925 vb2_set_plane_payload(mb_entry->b, 0, strm_size);
926 vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE);
927 }
928 spin_unlock_irqrestore(&dev->irqlock, flags);
929 if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
930 clear_work_bit(ctx);
931 return 0;
932 }
933
934 static struct s5p_mfc_codec_ops encoder_codec_ops = {
935 .pre_seq_start = enc_pre_seq_start,
936 .post_seq_start = enc_post_seq_start,
937 .pre_frame_start = enc_pre_frame_start,
938 .post_frame_start = enc_post_frame_start,
939 };
940
941 /* Query capabilities of the device */
942 static int vidioc_querycap(struct file *file, void *priv,
943 struct v4l2_capability *cap)
944 {
945 struct s5p_mfc_dev *dev = video_drvdata(file);
946
947 strncpy(cap->driver, dev->plat_dev->name, sizeof(cap->driver) - 1);
948 strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1);
949 cap->bus_info[0] = 0;
950 /*
951 * This is only a mem-to-mem video device. The capture and output
952 * device capability flags are left only for backward compatibility
953 * and are scheduled for removal.
954 */
955 cap->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
956 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
957 return 0;
958 }
959
960 static int vidioc_enum_fmt(struct file *file, struct v4l2_fmtdesc *f,
961 bool out)
962 {
963 struct s5p_mfc_dev *dev = video_drvdata(file);
964 struct s5p_mfc_fmt *fmt;
965 int i, j = 0;
966
967 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
968 if (out && formats[i].type != MFC_FMT_RAW)
969 continue;
970 else if (!out && formats[i].type != MFC_FMT_ENC)
971 continue;
972 else if ((dev->variant->version_bit & formats[i].versions) == 0)
973 continue;
974
975 if (j == f->index) {
976 fmt = &formats[i];
977 strlcpy(f->description, fmt->name,
978 sizeof(f->description));
979 f->pixelformat = fmt->fourcc;
980 return 0;
981 }
982 ++j;
983 }
984 return -EINVAL;
985 }
986
987 static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
988 struct v4l2_fmtdesc *f)
989 {
990 return vidioc_enum_fmt(file, f, false);
991 }
992
993 static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *prov,
994 struct v4l2_fmtdesc *f)
995 {
996 return vidioc_enum_fmt(file, f, true);
997 }
998
999 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
1000 {
1001 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1002 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1003
1004 mfc_debug(2, "f->type = %d ctx->state = %d\n", f->type, ctx->state);
1005 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1006 /* This is run on output (encoder dest) */
1007 pix_fmt_mp->width = 0;
1008 pix_fmt_mp->height = 0;
1009 pix_fmt_mp->field = V4L2_FIELD_NONE;
1010 pix_fmt_mp->pixelformat = ctx->dst_fmt->fourcc;
1011 pix_fmt_mp->num_planes = ctx->dst_fmt->num_planes;
1012
1013 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->enc_dst_buf_size;
1014 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->enc_dst_buf_size;
1015 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1016 /* This is run on capture (encoder src) */
1017 pix_fmt_mp->width = ctx->img_width;
1018 pix_fmt_mp->height = ctx->img_height;
1019
1020 pix_fmt_mp->field = V4L2_FIELD_NONE;
1021 pix_fmt_mp->pixelformat = ctx->src_fmt->fourcc;
1022 pix_fmt_mp->num_planes = ctx->src_fmt->num_planes;
1023
1024 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->buf_width;
1025 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->luma_size;
1026 pix_fmt_mp->plane_fmt[1].bytesperline = ctx->buf_width;
1027 pix_fmt_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
1028 } else {
1029 mfc_err("invalid buf type\n");
1030 return -EINVAL;
1031 }
1032 return 0;
1033 }
1034
1035 static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
1036 {
1037 struct s5p_mfc_dev *dev = video_drvdata(file);
1038 struct s5p_mfc_fmt *fmt;
1039 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1040
1041 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1042 fmt = find_format(f, MFC_FMT_ENC);
1043 if (!fmt) {
1044 mfc_err("failed to try output format\n");
1045 return -EINVAL;
1046 }
1047 if (pix_fmt_mp->plane_fmt[0].sizeimage == 0) {
1048 mfc_err("must be set encoding output size\n");
1049 return -EINVAL;
1050 }
1051 if ((dev->variant->version_bit & fmt->versions) == 0) {
1052 mfc_err("Unsupported format by this MFC version.\n");
1053 return -EINVAL;
1054 }
1055
1056 pix_fmt_mp->plane_fmt[0].bytesperline =
1057 pix_fmt_mp->plane_fmt[0].sizeimage;
1058 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1059 fmt = find_format(f, MFC_FMT_RAW);
1060 if (!fmt) {
1061 mfc_err("failed to try output format\n");
1062 return -EINVAL;
1063 }
1064
1065 if (fmt->num_planes != pix_fmt_mp->num_planes) {
1066 mfc_err("failed to try output format\n");
1067 return -EINVAL;
1068 }
1069 if ((dev->variant->version_bit & fmt->versions) == 0) {
1070 mfc_err("Unsupported format by this MFC version.\n");
1071 return -EINVAL;
1072 }
1073
1074 v4l_bound_align_image(&pix_fmt_mp->width, 8, 1920, 1,
1075 &pix_fmt_mp->height, 4, 1080, 1, 0);
1076 } else {
1077 mfc_err("invalid buf type\n");
1078 return -EINVAL;
1079 }
1080 return 0;
1081 }
1082
1083 static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
1084 {
1085 struct s5p_mfc_dev *dev = video_drvdata(file);
1086 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1087 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1088 int ret = 0;
1089
1090 ret = vidioc_try_fmt(file, priv, f);
1091 if (ret)
1092 return ret;
1093 if (ctx->vq_src.streaming || ctx->vq_dst.streaming) {
1094 v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
1095 ret = -EBUSY;
1096 goto out;
1097 }
1098 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1099 /* dst_fmt is validated by call to vidioc_try_fmt */
1100 ctx->dst_fmt = find_format(f, MFC_FMT_ENC);
1101 ctx->state = MFCINST_INIT;
1102 ctx->codec_mode = ctx->dst_fmt->codec_mode;
1103 ctx->enc_dst_buf_size = pix_fmt_mp->plane_fmt[0].sizeimage;
1104 pix_fmt_mp->plane_fmt[0].bytesperline = 0;
1105 ctx->dst_bufs_cnt = 0;
1106 ctx->capture_state = QUEUE_FREE;
1107 ret = s5p_mfc_open_mfc_inst(dev, ctx);
1108 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1109 /* src_fmt is validated by call to vidioc_try_fmt */
1110 ctx->src_fmt = find_format(f, MFC_FMT_RAW);
1111 ctx->img_width = pix_fmt_mp->width;
1112 ctx->img_height = pix_fmt_mp->height;
1113 mfc_debug(2, "codec number: %d\n", ctx->src_fmt->codec_mode);
1114 mfc_debug(2, "fmt - w: %d, h: %d, ctx - w: %d, h: %d\n",
1115 pix_fmt_mp->width, pix_fmt_mp->height,
1116 ctx->img_width, ctx->img_height);
1117
1118 s5p_mfc_hw_call_void(dev->mfc_ops, enc_calc_src_size, ctx);
1119 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->luma_size;
1120 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->buf_width;
1121 pix_fmt_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
1122 pix_fmt_mp->plane_fmt[1].bytesperline = ctx->buf_width;
1123
1124 ctx->src_bufs_cnt = 0;
1125 ctx->output_state = QUEUE_FREE;
1126 } else {
1127 mfc_err("invalid buf type\n");
1128 ret = -EINVAL;
1129 }
1130 out:
1131 mfc_debug_leave();
1132 return ret;
1133 }
1134
1135 static int vidioc_reqbufs(struct file *file, void *priv,
1136 struct v4l2_requestbuffers *reqbufs)
1137 {
1138 struct s5p_mfc_dev *dev = video_drvdata(file);
1139 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1140 int ret = 0;
1141
1142 /* if memory is not mmp or userptr return error */
1143 if ((reqbufs->memory != V4L2_MEMORY_MMAP) &&
1144 (reqbufs->memory != V4L2_MEMORY_USERPTR))
1145 return -EINVAL;
1146 if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1147 if (reqbufs->count == 0) {
1148 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1149 ctx->capture_state = QUEUE_FREE;
1150 return ret;
1151 }
1152 if (ctx->capture_state != QUEUE_FREE) {
1153 mfc_err("invalid capture state: %d\n",
1154 ctx->capture_state);
1155 return -EINVAL;
1156 }
1157 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1158 if (ret != 0) {
1159 mfc_err("error in vb2_reqbufs() for E(D)\n");
1160 return ret;
1161 }
1162 ctx->capture_state = QUEUE_BUFS_REQUESTED;
1163
1164 ret = s5p_mfc_hw_call(ctx->dev->mfc_ops,
1165 alloc_codec_buffers, ctx);
1166 if (ret) {
1167 mfc_err("Failed to allocate encoding buffers\n");
1168 reqbufs->count = 0;
1169 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1170 return -ENOMEM;
1171 }
1172 } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1173 if (reqbufs->count == 0) {
1174 mfc_debug(2, "Freeing buffers\n");
1175 ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
1176 s5p_mfc_hw_call_void(dev->mfc_ops, release_codec_buffers,
1177 ctx);
1178 ctx->output_state = QUEUE_FREE;
1179 return ret;
1180 }
1181 if (ctx->output_state != QUEUE_FREE) {
1182 mfc_err("invalid output state: %d\n",
1183 ctx->output_state);
1184 return -EINVAL;
1185 }
1186
1187 if (IS_MFCV6_PLUS(dev)) {
1188 /* Check for min encoder buffers */
1189 if (ctx->pb_count &&
1190 (reqbufs->count < ctx->pb_count)) {
1191 reqbufs->count = ctx->pb_count;
1192 mfc_debug(2, "Minimum %d output buffers needed\n",
1193 ctx->pb_count);
1194 } else {
1195 ctx->pb_count = reqbufs->count;
1196 }
1197 }
1198
1199 ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
1200 if (ret != 0) {
1201 mfc_err("error in vb2_reqbufs() for E(S)\n");
1202 return ret;
1203 }
1204 ctx->output_state = QUEUE_BUFS_REQUESTED;
1205 } else {
1206 mfc_err("invalid buf type\n");
1207 return -EINVAL;
1208 }
1209 return ret;
1210 }
1211
1212 static int vidioc_querybuf(struct file *file, void *priv,
1213 struct v4l2_buffer *buf)
1214 {
1215 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1216 int ret = 0;
1217
1218 /* if memory is not mmp or userptr return error */
1219 if ((buf->memory != V4L2_MEMORY_MMAP) &&
1220 (buf->memory != V4L2_MEMORY_USERPTR))
1221 return -EINVAL;
1222 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1223 if (ctx->state != MFCINST_GOT_INST) {
1224 mfc_err("invalid context state: %d\n", ctx->state);
1225 return -EINVAL;
1226 }
1227 ret = vb2_querybuf(&ctx->vq_dst, buf);
1228 if (ret != 0) {
1229 mfc_err("error in vb2_querybuf() for E(D)\n");
1230 return ret;
1231 }
1232 buf->m.planes[0].m.mem_offset += DST_QUEUE_OFF_BASE;
1233 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1234 ret = vb2_querybuf(&ctx->vq_src, buf);
1235 if (ret != 0) {
1236 mfc_err("error in vb2_querybuf() for E(S)\n");
1237 return ret;
1238 }
1239 } else {
1240 mfc_err("invalid buf type\n");
1241 return -EINVAL;
1242 }
1243 return ret;
1244 }
1245
1246 /* Queue a buffer */
1247 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1248 {
1249 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1250
1251 if (ctx->state == MFCINST_ERROR) {
1252 mfc_err("Call on QBUF after unrecoverable error\n");
1253 return -EIO;
1254 }
1255 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1256 if (ctx->state == MFCINST_FINISHING) {
1257 mfc_err("Call on QBUF after EOS command\n");
1258 return -EIO;
1259 }
1260 return vb2_qbuf(&ctx->vq_src, buf);
1261 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1262 return vb2_qbuf(&ctx->vq_dst, buf);
1263 }
1264 return -EINVAL;
1265 }
1266
1267 /* Dequeue a buffer */
1268 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1269 {
1270 const struct v4l2_event ev = {
1271 .type = V4L2_EVENT_EOS
1272 };
1273 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1274 int ret;
1275
1276 if (ctx->state == MFCINST_ERROR) {
1277 mfc_err("Call on DQBUF after unrecoverable error\n");
1278 return -EIO;
1279 }
1280 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1281 ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
1282 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1283 ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
1284 if (ret == 0 && ctx->state == MFCINST_FINISHED
1285 && list_empty(&ctx->vq_dst.done_list))
1286 v4l2_event_queue_fh(&ctx->fh, &ev);
1287 } else {
1288 ret = -EINVAL;
1289 }
1290
1291 return ret;
1292 }
1293
1294 /* Export DMA buffer */
1295 static int vidioc_expbuf(struct file *file, void *priv,
1296 struct v4l2_exportbuffer *eb)
1297 {
1298 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1299
1300 if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1301 return vb2_expbuf(&ctx->vq_src, eb);
1302 if (eb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1303 return vb2_expbuf(&ctx->vq_dst, eb);
1304 return -EINVAL;
1305 }
1306
1307 /* Stream on */
1308 static int vidioc_streamon(struct file *file, void *priv,
1309 enum v4l2_buf_type type)
1310 {
1311 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1312
1313 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1314 return vb2_streamon(&ctx->vq_src, type);
1315 else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1316 return vb2_streamon(&ctx->vq_dst, type);
1317 return -EINVAL;
1318 }
1319
1320 /* Stream off, which equals to a pause */
1321 static int vidioc_streamoff(struct file *file, void *priv,
1322 enum v4l2_buf_type type)
1323 {
1324 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1325
1326 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1327 return vb2_streamoff(&ctx->vq_src, type);
1328 else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1329 return vb2_streamoff(&ctx->vq_dst, type);
1330 return -EINVAL;
1331 }
1332
1333 static inline int h264_level(enum v4l2_mpeg_video_h264_level lvl)
1334 {
1335 static unsigned int t[V4L2_MPEG_VIDEO_H264_LEVEL_4_0 + 1] = {
1336 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_0 */ 10,
1337 /* V4L2_MPEG_VIDEO_H264_LEVEL_1B */ 9,
1338 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_1 */ 11,
1339 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_2 */ 12,
1340 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_3 */ 13,
1341 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_0 */ 20,
1342 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_1 */ 21,
1343 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_2 */ 22,
1344 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_0 */ 30,
1345 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_1 */ 31,
1346 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_2 */ 32,
1347 /* V4L2_MPEG_VIDEO_H264_LEVEL_4_0 */ 40,
1348 };
1349 return t[lvl];
1350 }
1351
1352 static inline int mpeg4_level(enum v4l2_mpeg_video_mpeg4_level lvl)
1353 {
1354 static unsigned int t[V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 + 1] = {
1355 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 */ 0,
1356 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B */ 9,
1357 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 */ 1,
1358 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 */ 2,
1359 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 */ 3,
1360 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B */ 7,
1361 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 */ 4,
1362 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 */ 5,
1363 };
1364 return t[lvl];
1365 }
1366
1367 static inline int vui_sar_idc(enum v4l2_mpeg_video_h264_vui_sar_idc sar)
1368 {
1369 static unsigned int t[V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED + 1] = {
1370 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED */ 0,
1371 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 */ 1,
1372 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 */ 2,
1373 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 */ 3,
1374 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 */ 4,
1375 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 */ 5,
1376 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 */ 6,
1377 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 */ 7,
1378 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 */ 8,
1379 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 */ 9,
1380 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 */ 10,
1381 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 */ 11,
1382 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 */ 12,
1383 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 */ 13,
1384 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 */ 14,
1385 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 */ 15,
1386 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 */ 16,
1387 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED */ 255,
1388 };
1389 return t[sar];
1390 }
1391
1392 static int s5p_mfc_enc_s_ctrl(struct v4l2_ctrl *ctrl)
1393 {
1394 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
1395 struct s5p_mfc_dev *dev = ctx->dev;
1396 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1397 int ret = 0;
1398
1399 switch (ctrl->id) {
1400 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1401 p->gop_size = ctrl->val;
1402 break;
1403 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
1404 p->slice_mode = ctrl->val;
1405 break;
1406 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
1407 p->slice_mb = ctrl->val;
1408 break;
1409 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
1410 p->slice_bit = ctrl->val * 8;
1411 break;
1412 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
1413 p->intra_refresh_mb = ctrl->val;
1414 break;
1415 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING:
1416 p->pad = ctrl->val;
1417 break;
1418 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV:
1419 p->pad_luma = (ctrl->val >> 16) & 0xff;
1420 p->pad_cb = (ctrl->val >> 8) & 0xff;
1421 p->pad_cr = (ctrl->val >> 0) & 0xff;
1422 break;
1423 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
1424 p->rc_frame = ctrl->val;
1425 break;
1426 case V4L2_CID_MPEG_VIDEO_BITRATE:
1427 p->rc_bitrate = ctrl->val;
1428 break;
1429 case V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF:
1430 p->rc_reaction_coeff = ctrl->val;
1431 break;
1432 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE:
1433 ctx->force_frame_type = ctrl->val;
1434 break;
1435 case V4L2_CID_MPEG_VIDEO_VBV_SIZE:
1436 p->vbv_size = ctrl->val;
1437 break;
1438 case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE:
1439 p->mv_h_range = ctrl->val;
1440 break;
1441 case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE:
1442 p->mv_v_range = ctrl->val;
1443 break;
1444 case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE:
1445 p->codec.h264.cpb_size = ctrl->val;
1446 break;
1447 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
1448 p->seq_hdr_mode = ctrl->val;
1449 break;
1450 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE:
1451 p->frame_skip_mode = ctrl->val;
1452 break;
1453 case V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT:
1454 p->fixed_target_bit = ctrl->val;
1455 break;
1456 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1457 p->num_b_frame = ctrl->val;
1458 break;
1459 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
1460 switch (ctrl->val) {
1461 case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
1462 p->codec.h264.profile =
1463 S5P_FIMV_ENC_PROFILE_H264_MAIN;
1464 break;
1465 case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
1466 p->codec.h264.profile =
1467 S5P_FIMV_ENC_PROFILE_H264_HIGH;
1468 break;
1469 case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
1470 p->codec.h264.profile =
1471 S5P_FIMV_ENC_PROFILE_H264_BASELINE;
1472 break;
1473 case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
1474 if (IS_MFCV6_PLUS(dev))
1475 p->codec.h264.profile =
1476 S5P_FIMV_ENC_PROFILE_H264_CONSTRAINED_BASELINE;
1477 else
1478 ret = -EINVAL;
1479 break;
1480 default:
1481 ret = -EINVAL;
1482 }
1483 break;
1484 case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
1485 p->codec.h264.level_v4l2 = ctrl->val;
1486 p->codec.h264.level = h264_level(ctrl->val);
1487 if (p->codec.h264.level < 0) {
1488 mfc_err("Level number is wrong\n");
1489 ret = p->codec.h264.level;
1490 }
1491 break;
1492 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
1493 p->codec.mpeg4.level_v4l2 = ctrl->val;
1494 p->codec.mpeg4.level = mpeg4_level(ctrl->val);
1495 if (p->codec.mpeg4.level < 0) {
1496 mfc_err("Level number is wrong\n");
1497 ret = p->codec.mpeg4.level;
1498 }
1499 break;
1500 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
1501 p->codec.h264.loop_filter_mode = ctrl->val;
1502 break;
1503 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
1504 p->codec.h264.loop_filter_alpha = ctrl->val;
1505 break;
1506 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
1507 p->codec.h264.loop_filter_beta = ctrl->val;
1508 break;
1509 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
1510 p->codec.h264.entropy_mode = ctrl->val;
1511 break;
1512 case V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P:
1513 p->codec.h264.num_ref_pic_4p = ctrl->val;
1514 break;
1515 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
1516 p->codec.h264._8x8_transform = ctrl->val;
1517 break;
1518 case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
1519 p->rc_mb = ctrl->val;
1520 break;
1521 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
1522 p->codec.h264.rc_frame_qp = ctrl->val;
1523 break;
1524 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
1525 p->codec.h264.rc_min_qp = ctrl->val;
1526 break;
1527 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
1528 p->codec.h264.rc_max_qp = ctrl->val;
1529 break;
1530 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
1531 p->codec.h264.rc_p_frame_qp = ctrl->val;
1532 break;
1533 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
1534 p->codec.h264.rc_b_frame_qp = ctrl->val;
1535 break;
1536 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
1537 case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
1538 p->codec.mpeg4.rc_frame_qp = ctrl->val;
1539 break;
1540 case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
1541 case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
1542 p->codec.mpeg4.rc_min_qp = ctrl->val;
1543 break;
1544 case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
1545 case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
1546 p->codec.mpeg4.rc_max_qp = ctrl->val;
1547 break;
1548 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
1549 case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
1550 p->codec.mpeg4.rc_p_frame_qp = ctrl->val;
1551 break;
1552 case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
1553 case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
1554 p->codec.mpeg4.rc_b_frame_qp = ctrl->val;
1555 break;
1556 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK:
1557 p->codec.h264.rc_mb_dark = ctrl->val;
1558 break;
1559 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH:
1560 p->codec.h264.rc_mb_smooth = ctrl->val;
1561 break;
1562 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC:
1563 p->codec.h264.rc_mb_static = ctrl->val;
1564 break;
1565 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY:
1566 p->codec.h264.rc_mb_activity = ctrl->val;
1567 break;
1568 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
1569 p->codec.h264.vui_sar = ctrl->val;
1570 break;
1571 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
1572 p->codec.h264.vui_sar_idc = vui_sar_idc(ctrl->val);
1573 break;
1574 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH:
1575 p->codec.h264.vui_ext_sar_width = ctrl->val;
1576 break;
1577 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT:
1578 p->codec.h264.vui_ext_sar_height = ctrl->val;
1579 break;
1580 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1581 p->codec.h264.open_gop = !ctrl->val;
1582 break;
1583 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
1584 p->codec.h264.open_gop_size = ctrl->val;
1585 break;
1586 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
1587 switch (ctrl->val) {
1588 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE:
1589 p->codec.mpeg4.profile =
1590 S5P_FIMV_ENC_PROFILE_MPEG4_SIMPLE;
1591 break;
1592 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE:
1593 p->codec.mpeg4.profile =
1594 S5P_FIMV_ENC_PROFILE_MPEG4_ADVANCED_SIMPLE;
1595 break;
1596 default:
1597 ret = -EINVAL;
1598 }
1599 break;
1600 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
1601 p->codec.mpeg4.quarter_pixel = ctrl->val;
1602 break;
1603 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
1604 p->codec.vp8.num_partitions = ctrl->val;
1605 break;
1606 case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4:
1607 p->codec.vp8.imd_4x4 = ctrl->val;
1608 break;
1609 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
1610 p->codec.vp8.num_ref = ctrl->val;
1611 break;
1612 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL:
1613 p->codec.vp8.filter_level = ctrl->val;
1614 break;
1615 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS:
1616 p->codec.vp8.filter_sharpness = ctrl->val;
1617 break;
1618 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD:
1619 p->codec.vp8.golden_frame_ref_period = ctrl->val;
1620 break;
1621 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
1622 p->codec.vp8.golden_frame_sel = ctrl->val;
1623 break;
1624 case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP:
1625 p->codec.vp8.rc_min_qp = ctrl->val;
1626 break;
1627 case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP:
1628 p->codec.vp8.rc_max_qp = ctrl->val;
1629 break;
1630 case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP:
1631 p->codec.vp8.rc_frame_qp = ctrl->val;
1632 break;
1633 case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP:
1634 p->codec.vp8.rc_p_frame_qp = ctrl->val;
1635 break;
1636 case V4L2_CID_MPEG_VIDEO_VPX_PROFILE:
1637 p->codec.vp8.profile = ctrl->val;
1638 break;
1639 default:
1640 v4l2_err(&dev->v4l2_dev, "Invalid control, id=%d, val=%d\n",
1641 ctrl->id, ctrl->val);
1642 ret = -EINVAL;
1643 }
1644 return ret;
1645 }
1646
1647 static int s5p_mfc_enc_g_v_ctrl(struct v4l2_ctrl *ctrl)
1648 {
1649 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
1650 struct s5p_mfc_dev *dev = ctx->dev;
1651
1652 switch (ctrl->id) {
1653 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
1654 if (ctx->state >= MFCINST_HEAD_PARSED &&
1655 ctx->state < MFCINST_ABORT) {
1656 ctrl->val = ctx->pb_count;
1657 break;
1658 } else if (ctx->state != MFCINST_INIT) {
1659 v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
1660 return -EINVAL;
1661 }
1662 /* Should wait for the header to be produced */
1663 s5p_mfc_wait_for_done_ctx(ctx,
1664 S5P_MFC_R2H_CMD_SEQ_DONE_RET, 0);
1665 if (ctx->state >= MFCINST_HEAD_PARSED &&
1666 ctx->state < MFCINST_ABORT) {
1667 ctrl->val = ctx->pb_count;
1668 } else {
1669 v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
1670 return -EINVAL;
1671 }
1672 break;
1673 }
1674 return 0;
1675 }
1676
1677 static const struct v4l2_ctrl_ops s5p_mfc_enc_ctrl_ops = {
1678 .s_ctrl = s5p_mfc_enc_s_ctrl,
1679 .g_volatile_ctrl = s5p_mfc_enc_g_v_ctrl,
1680 };
1681
1682 static int vidioc_s_parm(struct file *file, void *priv,
1683 struct v4l2_streamparm *a)
1684 {
1685 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1686
1687 if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1688 ctx->enc_params.rc_framerate_num =
1689 a->parm.output.timeperframe.denominator;
1690 ctx->enc_params.rc_framerate_denom =
1691 a->parm.output.timeperframe.numerator;
1692 } else {
1693 mfc_err("Setting FPS is only possible for the output queue\n");
1694 return -EINVAL;
1695 }
1696 return 0;
1697 }
1698
1699 static int vidioc_g_parm(struct file *file, void *priv,
1700 struct v4l2_streamparm *a)
1701 {
1702 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1703
1704 if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1705 a->parm.output.timeperframe.denominator =
1706 ctx->enc_params.rc_framerate_num;
1707 a->parm.output.timeperframe.numerator =
1708 ctx->enc_params.rc_framerate_denom;
1709 } else {
1710 mfc_err("Setting FPS is only possible for the output queue\n");
1711 return -EINVAL;
1712 }
1713 return 0;
1714 }
1715
1716 static int vidioc_encoder_cmd(struct file *file, void *priv,
1717 struct v4l2_encoder_cmd *cmd)
1718 {
1719 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1720 struct s5p_mfc_dev *dev = ctx->dev;
1721 struct s5p_mfc_buf *buf;
1722 unsigned long flags;
1723
1724 switch (cmd->cmd) {
1725 case V4L2_ENC_CMD_STOP:
1726 if (cmd->flags != 0)
1727 return -EINVAL;
1728
1729 if (!ctx->vq_src.streaming)
1730 return -EINVAL;
1731
1732 spin_lock_irqsave(&dev->irqlock, flags);
1733 if (list_empty(&ctx->src_queue)) {
1734 mfc_debug(2, "EOS: empty src queue, entering finishing state\n");
1735 ctx->state = MFCINST_FINISHING;
1736 if (s5p_mfc_ctx_ready(ctx))
1737 set_work_bit_irqsave(ctx);
1738 spin_unlock_irqrestore(&dev->irqlock, flags);
1739 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
1740 } else {
1741 mfc_debug(2, "EOS: marking last buffer of stream\n");
1742 buf = list_entry(ctx->src_queue.prev,
1743 struct s5p_mfc_buf, list);
1744 if (buf->flags & MFC_BUF_FLAG_USED)
1745 ctx->state = MFCINST_FINISHING;
1746 else
1747 buf->flags |= MFC_BUF_FLAG_EOS;
1748 spin_unlock_irqrestore(&dev->irqlock, flags);
1749 }
1750 break;
1751 default:
1752 return -EINVAL;
1753
1754 }
1755 return 0;
1756 }
1757
1758 static int vidioc_subscribe_event(struct v4l2_fh *fh,
1759 const struct v4l2_event_subscription *sub)
1760 {
1761 switch (sub->type) {
1762 case V4L2_EVENT_EOS:
1763 return v4l2_event_subscribe(fh, sub, 2, NULL);
1764 default:
1765 return -EINVAL;
1766 }
1767 }
1768
1769 static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = {
1770 .vidioc_querycap = vidioc_querycap,
1771 .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane,
1772 .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane,
1773 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
1774 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
1775 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
1776 .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt,
1777 .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt,
1778 .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt,
1779 .vidioc_reqbufs = vidioc_reqbufs,
1780 .vidioc_querybuf = vidioc_querybuf,
1781 .vidioc_qbuf = vidioc_qbuf,
1782 .vidioc_dqbuf = vidioc_dqbuf,
1783 .vidioc_expbuf = vidioc_expbuf,
1784 .vidioc_streamon = vidioc_streamon,
1785 .vidioc_streamoff = vidioc_streamoff,
1786 .vidioc_s_parm = vidioc_s_parm,
1787 .vidioc_g_parm = vidioc_g_parm,
1788 .vidioc_encoder_cmd = vidioc_encoder_cmd,
1789 .vidioc_subscribe_event = vidioc_subscribe_event,
1790 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1791 };
1792
1793 static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
1794 {
1795 int i;
1796
1797 if (!fmt)
1798 return -EINVAL;
1799 if (fmt->num_planes != vb->num_planes) {
1800 mfc_err("invalid plane number for the format\n");
1801 return -EINVAL;
1802 }
1803 for (i = 0; i < fmt->num_planes; i++) {
1804 dma_addr_t dma = vb2_dma_contig_plane_dma_addr(vb, i);
1805 if (!dma) {
1806 mfc_err("failed to get plane cookie\n");
1807 return -EINVAL;
1808 }
1809 mfc_debug(2, "index: %d, plane[%d] cookie: %pad\n",
1810 vb->v4l2_buf.index, i, &dma);
1811 }
1812 return 0;
1813 }
1814
1815 static int s5p_mfc_queue_setup(struct vb2_queue *vq,
1816 const struct v4l2_format *fmt,
1817 unsigned int *buf_count, unsigned int *plane_count,
1818 unsigned int psize[], void *allocators[])
1819 {
1820 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
1821 struct s5p_mfc_dev *dev = ctx->dev;
1822
1823 if (ctx->state != MFCINST_GOT_INST) {
1824 mfc_err("inavlid state: %d\n", ctx->state);
1825 return -EINVAL;
1826 }
1827 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1828 if (ctx->dst_fmt)
1829 *plane_count = ctx->dst_fmt->num_planes;
1830 else
1831 *plane_count = MFC_ENC_CAP_PLANE_COUNT;
1832 if (*buf_count < 1)
1833 *buf_count = 1;
1834 if (*buf_count > MFC_MAX_BUFFERS)
1835 *buf_count = MFC_MAX_BUFFERS;
1836 psize[0] = ctx->enc_dst_buf_size;
1837 allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
1838 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1839 if (ctx->src_fmt)
1840 *plane_count = ctx->src_fmt->num_planes;
1841 else
1842 *plane_count = MFC_ENC_OUT_PLANE_COUNT;
1843
1844 if (*buf_count < 1)
1845 *buf_count = 1;
1846 if (*buf_count > MFC_MAX_BUFFERS)
1847 *buf_count = MFC_MAX_BUFFERS;
1848
1849 psize[0] = ctx->luma_size;
1850 psize[1] = ctx->chroma_size;
1851
1852 if (IS_MFCV6_PLUS(dev)) {
1853 allocators[0] =
1854 ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
1855 allocators[1] =
1856 ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
1857 } else {
1858 allocators[0] =
1859 ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
1860 allocators[1] =
1861 ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
1862 }
1863 } else {
1864 mfc_err("inavlid queue type: %d\n", vq->type);
1865 return -EINVAL;
1866 }
1867 return 0;
1868 }
1869
1870 static int s5p_mfc_buf_init(struct vb2_buffer *vb)
1871 {
1872 struct vb2_queue *vq = vb->vb2_queue;
1873 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
1874 unsigned int i;
1875 int ret;
1876
1877 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1878 ret = check_vb_with_fmt(ctx->dst_fmt, vb);
1879 if (ret < 0)
1880 return ret;
1881 i = vb->v4l2_buf.index;
1882 ctx->dst_bufs[i].b = vb;
1883 ctx->dst_bufs[i].cookie.stream =
1884 vb2_dma_contig_plane_dma_addr(vb, 0);
1885 ctx->dst_bufs_cnt++;
1886 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1887 ret = check_vb_with_fmt(ctx->src_fmt, vb);
1888 if (ret < 0)
1889 return ret;
1890 i = vb->v4l2_buf.index;
1891 ctx->src_bufs[i].b = vb;
1892 ctx->src_bufs[i].cookie.raw.luma =
1893 vb2_dma_contig_plane_dma_addr(vb, 0);
1894 ctx->src_bufs[i].cookie.raw.chroma =
1895 vb2_dma_contig_plane_dma_addr(vb, 1);
1896 ctx->src_bufs_cnt++;
1897 } else {
1898 mfc_err("inavlid queue type: %d\n", vq->type);
1899 return -EINVAL;
1900 }
1901 return 0;
1902 }
1903
1904 static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
1905 {
1906 struct vb2_queue *vq = vb->vb2_queue;
1907 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
1908 int ret;
1909
1910 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1911 ret = check_vb_with_fmt(ctx->dst_fmt, vb);
1912 if (ret < 0)
1913 return ret;
1914 mfc_debug(2, "plane size: %ld, dst size: %zu\n",
1915 vb2_plane_size(vb, 0), ctx->enc_dst_buf_size);
1916 if (vb2_plane_size(vb, 0) < ctx->enc_dst_buf_size) {
1917 mfc_err("plane size is too small for capture\n");
1918 return -EINVAL;
1919 }
1920 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1921 ret = check_vb_with_fmt(ctx->src_fmt, vb);
1922 if (ret < 0)
1923 return ret;
1924 mfc_debug(2, "plane size: %ld, luma size: %d\n",
1925 vb2_plane_size(vb, 0), ctx->luma_size);
1926 mfc_debug(2, "plane size: %ld, chroma size: %d\n",
1927 vb2_plane_size(vb, 1), ctx->chroma_size);
1928 if (vb2_plane_size(vb, 0) < ctx->luma_size ||
1929 vb2_plane_size(vb, 1) < ctx->chroma_size) {
1930 mfc_err("plane size is too small for output\n");
1931 return -EINVAL;
1932 }
1933 } else {
1934 mfc_err("inavlid queue type: %d\n", vq->type);
1935 return -EINVAL;
1936 }
1937 return 0;
1938 }
1939
1940 static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
1941 {
1942 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
1943 struct s5p_mfc_dev *dev = ctx->dev;
1944
1945 if (IS_MFCV6_PLUS(dev) &&
1946 (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
1947
1948 if ((ctx->state == MFCINST_GOT_INST) &&
1949 (dev->curr_ctx == ctx->num) && dev->hw_lock) {
1950 s5p_mfc_wait_for_done_ctx(ctx,
1951 S5P_MFC_R2H_CMD_SEQ_DONE_RET,
1952 0);
1953 }
1954
1955 if (ctx->src_bufs_cnt < ctx->pb_count) {
1956 mfc_err("Need minimum %d OUTPUT buffers\n",
1957 ctx->pb_count);
1958 return -ENOBUFS;
1959 }
1960 }
1961
1962 /* If context is ready then dev = work->data;schedule it to run */
1963 if (s5p_mfc_ctx_ready(ctx))
1964 set_work_bit_irqsave(ctx);
1965 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
1966
1967 return 0;
1968 }
1969
1970 static void s5p_mfc_stop_streaming(struct vb2_queue *q)
1971 {
1972 unsigned long flags;
1973 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
1974 struct s5p_mfc_dev *dev = ctx->dev;
1975
1976 if ((ctx->state == MFCINST_FINISHING ||
1977 ctx->state == MFCINST_RUNNING) &&
1978 dev->curr_ctx == ctx->num && dev->hw_lock) {
1979 ctx->state = MFCINST_ABORT;
1980 s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_FRAME_DONE_RET,
1981 0);
1982 }
1983 ctx->state = MFCINST_FINISHED;
1984 spin_lock_irqsave(&dev->irqlock, flags);
1985 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1986 s5p_mfc_hw_call_void(dev->mfc_ops, cleanup_queue,
1987 &ctx->dst_queue, &ctx->vq_dst);
1988 INIT_LIST_HEAD(&ctx->dst_queue);
1989 ctx->dst_queue_cnt = 0;
1990 }
1991 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1992 cleanup_ref_queue(ctx);
1993 s5p_mfc_hw_call_void(dev->mfc_ops, cleanup_queue, &ctx->src_queue,
1994 &ctx->vq_src);
1995 INIT_LIST_HEAD(&ctx->src_queue);
1996 ctx->src_queue_cnt = 0;
1997 }
1998 spin_unlock_irqrestore(&dev->irqlock, flags);
1999 }
2000
2001 static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
2002 {
2003 struct vb2_queue *vq = vb->vb2_queue;
2004 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
2005 struct s5p_mfc_dev *dev = ctx->dev;
2006 unsigned long flags;
2007 struct s5p_mfc_buf *mfc_buf;
2008
2009 if (ctx->state == MFCINST_ERROR) {
2010 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
2011 cleanup_ref_queue(ctx);
2012 return;
2013 }
2014 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2015 mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
2016 mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
2017 /* Mark destination as available for use by MFC */
2018 spin_lock_irqsave(&dev->irqlock, flags);
2019 list_add_tail(&mfc_buf->list, &ctx->dst_queue);
2020 ctx->dst_queue_cnt++;
2021 spin_unlock_irqrestore(&dev->irqlock, flags);
2022 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2023 mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
2024 mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
2025 spin_lock_irqsave(&dev->irqlock, flags);
2026 list_add_tail(&mfc_buf->list, &ctx->src_queue);
2027 ctx->src_queue_cnt++;
2028 spin_unlock_irqrestore(&dev->irqlock, flags);
2029 } else {
2030 mfc_err("unsupported buffer type (%d)\n", vq->type);
2031 }
2032 if (s5p_mfc_ctx_ready(ctx))
2033 set_work_bit_irqsave(ctx);
2034 s5p_mfc_hw_call_void(dev->mfc_ops, try_run, dev);
2035 }
2036
2037 static struct vb2_ops s5p_mfc_enc_qops = {
2038 .queue_setup = s5p_mfc_queue_setup,
2039 .wait_prepare = vb2_ops_wait_prepare,
2040 .wait_finish = vb2_ops_wait_finish,
2041 .buf_init = s5p_mfc_buf_init,
2042 .buf_prepare = s5p_mfc_buf_prepare,
2043 .start_streaming = s5p_mfc_start_streaming,
2044 .stop_streaming = s5p_mfc_stop_streaming,
2045 .buf_queue = s5p_mfc_buf_queue,
2046 };
2047
2048 struct s5p_mfc_codec_ops *get_enc_codec_ops(void)
2049 {
2050 return &encoder_codec_ops;
2051 }
2052
2053 struct vb2_ops *get_enc_queue_ops(void)
2054 {
2055 return &s5p_mfc_enc_qops;
2056 }
2057
2058 const struct v4l2_ioctl_ops *get_enc_v4l2_ioctl_ops(void)
2059 {
2060 return &s5p_mfc_enc_ioctl_ops;
2061 }
2062
2063 #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
2064 && V4L2_CTRL_DRIVER_PRIV(x))
2065
2066 int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx)
2067 {
2068 struct v4l2_ctrl_config cfg;
2069 int i;
2070
2071 v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
2072 if (ctx->ctrl_handler.error) {
2073 mfc_err("v4l2_ctrl_handler_init failed\n");
2074 return ctx->ctrl_handler.error;
2075 }
2076 for (i = 0; i < NUM_CTRLS; i++) {
2077 if (IS_MFC51_PRIV(controls[i].id)) {
2078 memset(&cfg, 0, sizeof(struct v4l2_ctrl_config));
2079 cfg.ops = &s5p_mfc_enc_ctrl_ops;
2080 cfg.id = controls[i].id;
2081 cfg.min = controls[i].minimum;
2082 cfg.max = controls[i].maximum;
2083 cfg.def = controls[i].default_value;
2084 cfg.name = controls[i].name;
2085 cfg.type = controls[i].type;
2086 cfg.flags = 0;
2087
2088 if (cfg.type == V4L2_CTRL_TYPE_MENU) {
2089 cfg.step = 0;
2090 cfg.menu_skip_mask = cfg.menu_skip_mask;
2091 cfg.qmenu = mfc51_get_menu(cfg.id);
2092 } else {
2093 cfg.step = controls[i].step;
2094 cfg.menu_skip_mask = 0;
2095 }
2096 ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
2097 &cfg, NULL);
2098 } else {
2099 if ((controls[i].type == V4L2_CTRL_TYPE_MENU) ||
2100 (controls[i].type ==
2101 V4L2_CTRL_TYPE_INTEGER_MENU)) {
2102 ctx->ctrls[i] = v4l2_ctrl_new_std_menu(
2103 &ctx->ctrl_handler,
2104 &s5p_mfc_enc_ctrl_ops, controls[i].id,
2105 controls[i].maximum, 0,
2106 controls[i].default_value);
2107 } else {
2108 ctx->ctrls[i] = v4l2_ctrl_new_std(
2109 &ctx->ctrl_handler,
2110 &s5p_mfc_enc_ctrl_ops, controls[i].id,
2111 controls[i].minimum,
2112 controls[i].maximum, controls[i].step,
2113 controls[i].default_value);
2114 }
2115 }
2116 if (ctx->ctrl_handler.error) {
2117 mfc_err("Adding control (%d) failed\n", i);
2118 return ctx->ctrl_handler.error;
2119 }
2120 if (controls[i].is_volatile && ctx->ctrls[i])
2121 ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
2122 }
2123 v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
2124 return 0;
2125 }
2126
2127 void s5p_mfc_enc_ctrls_delete(struct s5p_mfc_ctx *ctx)
2128 {
2129 int i;
2130
2131 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
2132 for (i = 0; i < NUM_CTRLS; i++)
2133 ctx->ctrls[i] = NULL;
2134 }
2135
2136 void s5p_mfc_enc_init(struct s5p_mfc_ctx *ctx)
2137 {
2138 struct v4l2_format f;
2139 f.fmt.pix_mp.pixelformat = DEF_SRC_FMT_ENC;
2140 ctx->src_fmt = find_format(&f, MFC_FMT_RAW);
2141 f.fmt.pix_mp.pixelformat = DEF_DST_FMT_ENC;
2142 ctx->dst_fmt = find_format(&f, MFC_FMT_ENC);
2143 }
2144
This page took 0.098016 seconds and 5 git commands to generate.