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