This source file includes following definitions.
- find_format
- mfc51_get_menu
- s5p_mfc_ctx_ready
- cleanup_ref_queue
- enc_pre_seq_start
- enc_post_seq_start
- enc_pre_frame_start
- enc_post_frame_start
- vidioc_querycap
- vidioc_enum_fmt
- vidioc_enum_fmt_vid_cap
- vidioc_enum_fmt_vid_out
- vidioc_g_fmt
- vidioc_try_fmt
- vidioc_s_fmt
- vidioc_reqbufs
- vidioc_querybuf
- vidioc_qbuf
- vidioc_dqbuf
- vidioc_expbuf
- vidioc_streamon
- vidioc_streamoff
- h264_level
- mpeg4_level
- hevc_level
- vui_sar_idc
- __enc_update_hevc_qp_ctrls_range
- s5p_mfc_enc_s_ctrl
- s5p_mfc_enc_g_v_ctrl
- vidioc_s_parm
- vidioc_g_parm
- vidioc_encoder_cmd
- vidioc_subscribe_event
- check_vb_with_fmt
- s5p_mfc_queue_setup
- s5p_mfc_buf_init
- s5p_mfc_buf_prepare
- s5p_mfc_start_streaming
- s5p_mfc_stop_streaming
- s5p_mfc_buf_queue
- get_enc_codec_ops
- get_enc_queue_ops
- get_enc_v4l2_ioctl_ops
- s5p_mfc_enc_ctrls_setup
- s5p_mfc_enc_ctrls_delete
- s5p_mfc_enc_init
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/clk.h>
13 #include <linux/interrupt.h>
14 #include <linux/io.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/sched.h>
18 #include <linux/videodev2.h>
19 #include <media/v4l2-event.h>
20 #include <linux/workqueue.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/videobuf2-v4l2.h>
23 #include "s5p_mfc_common.h"
24 #include "s5p_mfc_ctrl.h"
25 #include "s5p_mfc_debug.h"
26 #include "s5p_mfc_enc.h"
27 #include "s5p_mfc_intr.h"
28 #include "s5p_mfc_opr.h"
29
30 #define DEF_SRC_FMT_ENC V4L2_PIX_FMT_NV12M
31 #define DEF_DST_FMT_ENC V4L2_PIX_FMT_H264
32
33 static struct s5p_mfc_fmt formats[] = {
34 {
35 .fourcc = V4L2_PIX_FMT_NV12MT_16X16,
36 .codec_mode = S5P_MFC_CODEC_NONE,
37 .type = MFC_FMT_RAW,
38 .num_planes = 2,
39 .versions = MFC_V6_BIT | MFC_V7_BIT,
40 },
41 {
42 .fourcc = V4L2_PIX_FMT_NV12MT,
43 .codec_mode = S5P_MFC_CODEC_NONE,
44 .type = MFC_FMT_RAW,
45 .num_planes = 2,
46 .versions = MFC_V5_BIT,
47 },
48 {
49 .fourcc = V4L2_PIX_FMT_NV12M,
50 .codec_mode = S5P_MFC_CODEC_NONE,
51 .type = MFC_FMT_RAW,
52 .num_planes = 2,
53 .versions = MFC_V5PLUS_BITS,
54 },
55 {
56 .fourcc = V4L2_PIX_FMT_NV21M,
57 .codec_mode = S5P_MFC_CODEC_NONE,
58 .type = MFC_FMT_RAW,
59 .num_planes = 2,
60 .versions = MFC_V6PLUS_BITS,
61 },
62 {
63 .fourcc = V4L2_PIX_FMT_H264,
64 .codec_mode = S5P_MFC_CODEC_H264_ENC,
65 .type = MFC_FMT_ENC,
66 .num_planes = 1,
67 .versions = MFC_V5PLUS_BITS,
68 },
69 {
70 .fourcc = V4L2_PIX_FMT_MPEG4,
71 .codec_mode = S5P_MFC_CODEC_MPEG4_ENC,
72 .type = MFC_FMT_ENC,
73 .num_planes = 1,
74 .versions = MFC_V5PLUS_BITS,
75 },
76 {
77 .fourcc = V4L2_PIX_FMT_H263,
78 .codec_mode = S5P_MFC_CODEC_H263_ENC,
79 .type = MFC_FMT_ENC,
80 .num_planes = 1,
81 .versions = MFC_V5PLUS_BITS,
82 },
83 {
84 .fourcc = V4L2_PIX_FMT_VP8,
85 .codec_mode = S5P_MFC_CODEC_VP8_ENC,
86 .type = MFC_FMT_ENC,
87 .num_planes = 1,
88 .versions = MFC_V7PLUS_BITS,
89 },
90 {
91 .fourcc = V4L2_PIX_FMT_HEVC,
92 .codec_mode = S5P_FIMV_CODEC_HEVC_ENC,
93 .type = MFC_FMT_ENC,
94 .num_planes = 1,
95 .versions = MFC_V10_BIT,
96 },
97 };
98
99 #define NUM_FORMATS ARRAY_SIZE(formats)
100 static struct s5p_mfc_fmt *find_format(struct v4l2_format *f, unsigned int t)
101 {
102 unsigned int i;
103
104 for (i = 0; i < NUM_FORMATS; i++) {
105 if (formats[i].fourcc == f->fmt.pix_mp.pixelformat &&
106 formats[i].type == t)
107 return &formats[i];
108 }
109 return NULL;
110 }
111
112 static struct mfc_control controls[] = {
113 {
114 .id = V4L2_CID_MPEG_VIDEO_GOP_SIZE,
115 .type = V4L2_CTRL_TYPE_INTEGER,
116 .minimum = 0,
117 .maximum = (1 << 16) - 1,
118 .step = 1,
119 .default_value = 12,
120 },
121 {
122 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
123 .type = V4L2_CTRL_TYPE_MENU,
124 .minimum = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
125 .maximum = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES,
126 .default_value = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
127 .menu_skip_mask = 0,
128 },
129 {
130 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB,
131 .type = V4L2_CTRL_TYPE_INTEGER,
132 .minimum = 1,
133 .maximum = (1 << 16) - 1,
134 .step = 1,
135 .default_value = 1,
136 },
137 {
138 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES,
139 .type = V4L2_CTRL_TYPE_INTEGER,
140 .minimum = 1900,
141 .maximum = (1 << 30) - 1,
142 .step = 1,
143 .default_value = 1900,
144 },
145 {
146 .id = V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB,
147 .type = V4L2_CTRL_TYPE_INTEGER,
148 .minimum = 0,
149 .maximum = (1 << 16) - 1,
150 .step = 1,
151 .default_value = 0,
152 },
153 {
154 .id = V4L2_CID_MPEG_MFC51_VIDEO_PADDING,
155 .type = V4L2_CTRL_TYPE_BOOLEAN,
156 .name = "Padding Control Enable",
157 .minimum = 0,
158 .maximum = 1,
159 .step = 1,
160 .default_value = 0,
161 },
162 {
163 .id = V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV,
164 .type = V4L2_CTRL_TYPE_INTEGER,
165 .name = "Padding Color YUV Value",
166 .minimum = 0,
167 .maximum = (1 << 25) - 1,
168 .step = 1,
169 .default_value = 0,
170 },
171 {
172 .id = V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE,
173 .type = V4L2_CTRL_TYPE_BOOLEAN,
174 .minimum = 0,
175 .maximum = 1,
176 .step = 1,
177 .default_value = 0,
178 },
179 {
180 .id = V4L2_CID_MPEG_VIDEO_BITRATE,
181 .type = V4L2_CTRL_TYPE_INTEGER,
182 .minimum = 1,
183 .maximum = (1 << 30) - 1,
184 .step = 1,
185 .default_value = 1,
186 },
187 {
188 .id = V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "Rate Control Reaction Coeff.",
191 .minimum = 1,
192 .maximum = (1 << 16) - 1,
193 .step = 1,
194 .default_value = 1,
195 },
196 {
197 .id = V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE,
198 .type = V4L2_CTRL_TYPE_MENU,
199 .name = "Force frame type",
200 .minimum = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED,
201 .maximum = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED,
202 .default_value = V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED,
203 .menu_skip_mask = 0,
204 },
205 {
206 .id = V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME,
207 .type = V4L2_CTRL_TYPE_BUTTON,
208 .minimum = 0,
209 .maximum = 0,
210 .step = 0,
211 .default_value = 0,
212 },
213 {
214 .id = V4L2_CID_MPEG_VIDEO_VBV_SIZE,
215 .type = V4L2_CTRL_TYPE_INTEGER,
216 .minimum = 0,
217 .maximum = (1 << 16) - 1,
218 .step = 1,
219 .default_value = 0,
220 },
221 {
222 .id = V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE,
223 .type = V4L2_CTRL_TYPE_INTEGER,
224 .name = "Horizontal MV Search Range",
225 .minimum = 16,
226 .maximum = 128,
227 .step = 16,
228 .default_value = 32,
229 },
230 {
231 .id = V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE,
232 .type = V4L2_CTRL_TYPE_INTEGER,
233 .name = "Vertical MV Search Range",
234 .minimum = 16,
235 .maximum = 128,
236 .step = 16,
237 .default_value = 32,
238 },
239 {
240 .id = V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE,
241 .type = V4L2_CTRL_TYPE_INTEGER,
242 .minimum = 0,
243 .maximum = (1 << 16) - 1,
244 .step = 1,
245 .default_value = 0,
246 },
247 {
248 .id = V4L2_CID_MPEG_VIDEO_HEADER_MODE,
249 .type = V4L2_CTRL_TYPE_MENU,
250 .minimum = V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE,
251 .maximum = V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
252 .default_value = V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE,
253 .menu_skip_mask = 0,
254 },
255 {
256 .id = V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE,
257 .type = V4L2_CTRL_TYPE_MENU,
258 .name = "Frame Skip Enable",
259 .minimum = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED,
260 .maximum = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT,
261 .menu_skip_mask = 0,
262 .default_value = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED,
263 },
264 {
265 .id = V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT,
266 .type = V4L2_CTRL_TYPE_BOOLEAN,
267 .name = "Fixed Target Bit Enable",
268 .minimum = 0,
269 .maximum = 1,
270 .default_value = 0,
271 .step = 1,
272 .menu_skip_mask = 0,
273 },
274 {
275 .id = V4L2_CID_MPEG_VIDEO_B_FRAMES,
276 .type = V4L2_CTRL_TYPE_INTEGER,
277 .minimum = 0,
278 .maximum = 2,
279 .step = 1,
280 .default_value = 0,
281 },
282 {
283 .id = V4L2_CID_MPEG_VIDEO_H264_PROFILE,
284 .type = V4L2_CTRL_TYPE_MENU,
285 .minimum = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
286 .maximum = V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH,
287 .default_value = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE,
288 .menu_skip_mask = ~(
289 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
290 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
291 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)
292 ),
293 },
294 {
295 .id = V4L2_CID_MPEG_VIDEO_H264_LEVEL,
296 .type = V4L2_CTRL_TYPE_MENU,
297 .minimum = V4L2_MPEG_VIDEO_H264_LEVEL_1_0,
298 .maximum = V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
299 .default_value = V4L2_MPEG_VIDEO_H264_LEVEL_1_0,
300 },
301 {
302 .id = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL,
303 .type = V4L2_CTRL_TYPE_MENU,
304 .minimum = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0,
305 .maximum = V4L2_MPEG_VIDEO_MPEG4_LEVEL_5,
306 .default_value = V4L2_MPEG_VIDEO_MPEG4_LEVEL_0,
307 .menu_skip_mask = 0,
308 },
309 {
310 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
311 .type = V4L2_CTRL_TYPE_MENU,
312 .minimum = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED,
313 .maximum = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY,
314 .default_value = V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED,
315 .menu_skip_mask = 0,
316 },
317 {
318 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA,
319 .type = V4L2_CTRL_TYPE_INTEGER,
320 .minimum = -6,
321 .maximum = 6,
322 .step = 1,
323 .default_value = 0,
324 },
325 {
326 .id = V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA,
327 .type = V4L2_CTRL_TYPE_INTEGER,
328 .minimum = -6,
329 .maximum = 6,
330 .step = 1,
331 .default_value = 0,
332 },
333 {
334 .id = V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE,
335 .type = V4L2_CTRL_TYPE_MENU,
336 .minimum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
337 .maximum = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC,
338 .default_value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC,
339 .menu_skip_mask = 0,
340 },
341 {
342 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P,
343 .type = V4L2_CTRL_TYPE_INTEGER,
344 .name = "The Number of Ref. Pic for P",
345 .minimum = 1,
346 .maximum = 2,
347 .step = 1,
348 .default_value = 1,
349 },
350 {
351 .id = V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM,
352 .type = V4L2_CTRL_TYPE_BOOLEAN,
353 .minimum = 0,
354 .maximum = 1,
355 .step = 1,
356 .default_value = 0,
357 },
358 {
359 .id = V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE,
360 .type = V4L2_CTRL_TYPE_BOOLEAN,
361 .minimum = 0,
362 .maximum = 1,
363 .step = 1,
364 .default_value = 0,
365 },
366 {
367 .id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP,
368 .type = V4L2_CTRL_TYPE_INTEGER,
369 .minimum = 0,
370 .maximum = 51,
371 .step = 1,
372 .default_value = 1,
373 },
374 {
375 .id = V4L2_CID_MPEG_VIDEO_H264_MIN_QP,
376 .type = V4L2_CTRL_TYPE_INTEGER,
377 .minimum = 0,
378 .maximum = 51,
379 .step = 1,
380 .default_value = 1,
381 },
382 {
383 .id = V4L2_CID_MPEG_VIDEO_H264_MAX_QP,
384 .type = V4L2_CTRL_TYPE_INTEGER,
385 .minimum = 0,
386 .maximum = 51,
387 .step = 1,
388 .default_value = 51,
389 },
390 {
391 .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP,
392 .type = V4L2_CTRL_TYPE_INTEGER,
393 .minimum = 0,
394 .maximum = 51,
395 .step = 1,
396 .default_value = 1,
397 },
398 {
399 .id = V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP,
400 .type = V4L2_CTRL_TYPE_INTEGER,
401 .minimum = 0,
402 .maximum = 51,
403 .step = 1,
404 .default_value = 1,
405 },
406 {
407 .id = V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP,
408 .type = V4L2_CTRL_TYPE_INTEGER,
409 .name = "H263 I-Frame QP value",
410 .minimum = 1,
411 .maximum = 31,
412 .step = 1,
413 .default_value = 1,
414 },
415 {
416 .id = V4L2_CID_MPEG_VIDEO_H263_MIN_QP,
417 .type = V4L2_CTRL_TYPE_INTEGER,
418 .name = "H263 Minimum QP value",
419 .minimum = 1,
420 .maximum = 31,
421 .step = 1,
422 .default_value = 1,
423 },
424 {
425 .id = V4L2_CID_MPEG_VIDEO_H263_MAX_QP,
426 .type = V4L2_CTRL_TYPE_INTEGER,
427 .name = "H263 Maximum QP value",
428 .minimum = 1,
429 .maximum = 31,
430 .step = 1,
431 .default_value = 31,
432 },
433 {
434 .id = V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP,
435 .type = V4L2_CTRL_TYPE_INTEGER,
436 .name = "H263 P frame QP value",
437 .minimum = 1,
438 .maximum = 31,
439 .step = 1,
440 .default_value = 1,
441 },
442 {
443 .id = V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP,
444 .type = V4L2_CTRL_TYPE_INTEGER,
445 .name = "H263 B frame QP value",
446 .minimum = 1,
447 .maximum = 31,
448 .step = 1,
449 .default_value = 1,
450 },
451 {
452 .id = V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP,
453 .type = V4L2_CTRL_TYPE_INTEGER,
454 .name = "MPEG4 I-Frame QP value",
455 .minimum = 1,
456 .maximum = 31,
457 .step = 1,
458 .default_value = 1,
459 },
460 {
461 .id = V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP,
462 .type = V4L2_CTRL_TYPE_INTEGER,
463 .name = "MPEG4 Minimum QP value",
464 .minimum = 1,
465 .maximum = 31,
466 .step = 1,
467 .default_value = 1,
468 },
469 {
470 .id = V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP,
471 .type = V4L2_CTRL_TYPE_INTEGER,
472 .name = "MPEG4 Maximum QP value",
473 .minimum = 0,
474 .maximum = 51,
475 .step = 1,
476 .default_value = 51,
477 },
478 {
479 .id = V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP,
480 .type = V4L2_CTRL_TYPE_INTEGER,
481 .name = "MPEG4 P frame QP value",
482 .minimum = 1,
483 .maximum = 31,
484 .step = 1,
485 .default_value = 1,
486 },
487 {
488 .id = V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP,
489 .type = V4L2_CTRL_TYPE_INTEGER,
490 .name = "MPEG4 B frame QP value",
491 .minimum = 1,
492 .maximum = 31,
493 .step = 1,
494 .default_value = 1,
495 },
496 {
497 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK,
498 .type = V4L2_CTRL_TYPE_BOOLEAN,
499 .name = "H264 Dark Reg Adaptive RC",
500 .minimum = 0,
501 .maximum = 1,
502 .step = 1,
503 .default_value = 0,
504 },
505 {
506 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH,
507 .type = V4L2_CTRL_TYPE_BOOLEAN,
508 .name = "H264 Smooth Reg Adaptive RC",
509 .minimum = 0,
510 .maximum = 1,
511 .step = 1,
512 .default_value = 0,
513 },
514 {
515 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC,
516 .type = V4L2_CTRL_TYPE_BOOLEAN,
517 .name = "H264 Static Reg Adaptive RC",
518 .minimum = 0,
519 .maximum = 1,
520 .step = 1,
521 .default_value = 0,
522 },
523 {
524 .id = V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY,
525 .type = V4L2_CTRL_TYPE_BOOLEAN,
526 .name = "H264 Activity Reg Adaptive RC",
527 .minimum = 0,
528 .maximum = 1,
529 .step = 1,
530 .default_value = 0,
531 },
532 {
533 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE,
534 .type = V4L2_CTRL_TYPE_BOOLEAN,
535 .minimum = 0,
536 .maximum = 1,
537 .step = 1,
538 .default_value = 0,
539 },
540 {
541 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC,
542 .type = V4L2_CTRL_TYPE_MENU,
543 .minimum = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED,
544 .maximum = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED,
545 .default_value = V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED,
546 .menu_skip_mask = 0,
547 },
548 {
549 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH,
550 .type = V4L2_CTRL_TYPE_INTEGER,
551 .minimum = 0,
552 .maximum = (1 << 16) - 1,
553 .step = 1,
554 .default_value = 0,
555 },
556 {
557 .id = V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT,
558 .type = V4L2_CTRL_TYPE_INTEGER,
559 .minimum = 0,
560 .maximum = (1 << 16) - 1,
561 .step = 1,
562 .default_value = 0,
563 },
564 {
565 .id = V4L2_CID_MPEG_VIDEO_GOP_CLOSURE,
566 .type = V4L2_CTRL_TYPE_BOOLEAN,
567 .minimum = 0,
568 .maximum = 1,
569 .step = 1,
570 .default_value = 1,
571 },
572 {
573 .id = V4L2_CID_MPEG_VIDEO_H264_I_PERIOD,
574 .type = V4L2_CTRL_TYPE_INTEGER,
575 .minimum = 0,
576 .maximum = (1 << 16) - 1,
577 .step = 1,
578 .default_value = 0,
579 },
580 {
581 .id = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE,
582 .type = V4L2_CTRL_TYPE_MENU,
583 .minimum = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE,
584 .maximum = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE,
585 .default_value = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE,
586 .menu_skip_mask = 0,
587 },
588 {
589 .id = V4L2_CID_MPEG_VIDEO_MPEG4_QPEL,
590 .type = V4L2_CTRL_TYPE_BOOLEAN,
591 .minimum = 0,
592 .maximum = 1,
593 .step = 1,
594 .default_value = 0,
595 },
596 {
597 .id = V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS,
598 .type = V4L2_CTRL_TYPE_INTEGER_MENU,
599 .maximum = V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS,
600 .default_value = V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION,
601 .menu_skip_mask = 0,
602 },
603 {
604 .id = V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4,
605 .type = V4L2_CTRL_TYPE_BOOLEAN,
606 .minimum = 0,
607 .maximum = 1,
608 .step = 1,
609 .default_value = 0,
610 },
611 {
612 .id = V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES,
613 .type = V4L2_CTRL_TYPE_INTEGER_MENU,
614 .maximum = V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME,
615 .default_value = V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME,
616 .menu_skip_mask = 0,
617 },
618 {
619 .id = V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL,
620 .type = V4L2_CTRL_TYPE_INTEGER,
621 .minimum = 0,
622 .maximum = 63,
623 .step = 1,
624 .default_value = 0,
625 },
626 {
627 .id = V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS,
628 .type = V4L2_CTRL_TYPE_INTEGER,
629 .minimum = 0,
630 .maximum = 7,
631 .step = 1,
632 .default_value = 0,
633 },
634 {
635 .id = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD,
636 .type = V4L2_CTRL_TYPE_INTEGER,
637 .minimum = 0,
638 .maximum = (1 << 16) - 1,
639 .step = 1,
640 .default_value = 0,
641 },
642 {
643 .id = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL,
644 .type = V4L2_CTRL_TYPE_MENU,
645 .minimum = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV,
646 .maximum = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD,
647 .default_value = V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV,
648 .menu_skip_mask = 0,
649 },
650 {
651 .id = V4L2_CID_MPEG_VIDEO_VPX_MAX_QP,
652 .type = V4L2_CTRL_TYPE_INTEGER,
653 .minimum = 0,
654 .maximum = 127,
655 .step = 1,
656 .default_value = 127,
657 },
658 {
659 .id = V4L2_CID_MPEG_VIDEO_VPX_MIN_QP,
660 .type = V4L2_CTRL_TYPE_INTEGER,
661 .minimum = 0,
662 .maximum = 11,
663 .step = 1,
664 .default_value = 0,
665 },
666 {
667 .id = V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP,
668 .type = V4L2_CTRL_TYPE_INTEGER,
669 .minimum = 0,
670 .maximum = 127,
671 .step = 1,
672 .default_value = 10,
673 },
674 {
675 .id = V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP,
676 .type = V4L2_CTRL_TYPE_INTEGER,
677 .minimum = 0,
678 .maximum = 127,
679 .step = 1,
680 .default_value = 10,
681 },
682 {
683 .id = V4L2_CID_MPEG_VIDEO_VP8_PROFILE,
684 .type = V4L2_CTRL_TYPE_MENU,
685 .minimum = V4L2_MPEG_VIDEO_VP8_PROFILE_0,
686 .maximum = V4L2_MPEG_VIDEO_VP8_PROFILE_3,
687 .default_value = V4L2_MPEG_VIDEO_VP8_PROFILE_0,
688 .menu_skip_mask = 0,
689 },
690 {
691 .id = V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP,
692 .type = V4L2_CTRL_TYPE_INTEGER,
693 .name = "HEVC I Frame QP Value",
694 .minimum = 0,
695 .maximum = 51,
696 .step = 1,
697 .default_value = 0,
698 },
699 {
700 .id = V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP,
701 .type = V4L2_CTRL_TYPE_INTEGER,
702 .name = "HEVC P Frame QP Value",
703 .minimum = 0,
704 .maximum = 51,
705 .step = 1,
706 .default_value = 0,
707 },
708 {
709 .id = V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP,
710 .type = V4L2_CTRL_TYPE_INTEGER,
711 .minimum = 0,
712 .maximum = 51,
713 .step = 1,
714 .default_value = 0,
715 },
716 {
717 .id = V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP,
718 .type = V4L2_CTRL_TYPE_INTEGER,
719 .minimum = 0,
720 .maximum = 51,
721 .step = 1,
722 .default_value = 0,
723 },
724 {
725 .id = V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP,
726 .type = V4L2_CTRL_TYPE_INTEGER,
727 .minimum = 0,
728 .maximum = 51,
729 .step = 1,
730 .default_value = 0,
731 },
732 {
733 .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
734 .type = V4L2_CTRL_TYPE_MENU,
735 .minimum = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
736 .maximum = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE,
737 .step = 1,
738 .default_value = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
739 },
740 {
741 .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
742 .type = V4L2_CTRL_TYPE_MENU,
743 .minimum = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
744 .maximum = V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2,
745 .step = 1,
746 .default_value = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
747 },
748 {
749 .id = V4L2_CID_MPEG_VIDEO_HEVC_TIER,
750 .type = V4L2_CTRL_TYPE_MENU,
751 .minimum = V4L2_MPEG_VIDEO_HEVC_TIER_MAIN,
752 .maximum = V4L2_MPEG_VIDEO_HEVC_TIER_HIGH,
753 .step = 1,
754 .default_value = V4L2_MPEG_VIDEO_HEVC_TIER_MAIN,
755 },
756 {
757 .id = V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION,
758 .type = V4L2_CTRL_TYPE_INTEGER,
759 .minimum = 1,
760 .maximum = (1 << 16) - 1,
761 .step = 1,
762 .default_value = 1,
763 },
764 {
765 .id = V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH,
766 .type = V4L2_CTRL_TYPE_INTEGER,
767 .minimum = 0,
768 .maximum = 1,
769 .step = 1,
770 .default_value = 0,
771 },
772 {
773 .id = V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES,
774 .type = V4L2_CTRL_TYPE_INTEGER,
775 .minimum = 1,
776 .maximum = 2,
777 .step = 1,
778 .default_value = 1,
779 },
780 {
781 .id = V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE,
782 .type = V4L2_CTRL_TYPE_MENU,
783 .minimum = V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE,
784 .maximum = V4L2_MPEG_VIDEO_HEVC_REFRESH_IDR,
785 .step = 1,
786 .default_value = V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE,
787 },
788 {
789 .id = V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED,
790 .type = V4L2_CTRL_TYPE_BOOLEAN,
791 .minimum = 0,
792 .maximum = 1,
793 .step = 1,
794 .default_value = 0,
795 },
796 {
797 .id = V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU,
798 .type = V4L2_CTRL_TYPE_BOOLEAN,
799 .minimum = 0,
800 .maximum = 1,
801 .step = 1,
802 .default_value = 0,
803 },
804 {
805 .id = V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT,
806 .type = V4L2_CTRL_TYPE_BOOLEAN,
807 .minimum = 0,
808 .maximum = 1,
809 .step = 1,
810 .default_value = 0,
811 },
812 {
813 .id = V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE,
814 .type = V4L2_CTRL_TYPE_MENU,
815 .minimum = V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED,
816 .maximum = V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY,
817 .step = 1,
818 .default_value = V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED,
819 },
820 {
821 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP,
822 .type = V4L2_CTRL_TYPE_BOOLEAN,
823 .minimum = 0,
824 .maximum = 1,
825 .step = 1,
826 .default_value = 0,
827 },
828 {
829 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE,
830 .type = V4L2_CTRL_TYPE_MENU,
831 .minimum = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B,
832 .maximum = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P,
833 .step = 1,
834 .default_value = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B,
835 },
836 {
837 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER,
838 .type = V4L2_CTRL_TYPE_INTEGER,
839 .minimum = 0,
840 .maximum = 6,
841 .step = 1,
842 .default_value = 0,
843 },
844 {
845 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP,
846 .type = V4L2_CTRL_TYPE_INTEGER,
847 .minimum = 0,
848 .maximum = 51,
849 .step = 1,
850 .default_value = 0,
851 },
852 {
853 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP,
854 .type = V4L2_CTRL_TYPE_INTEGER,
855 .minimum = 0,
856 .maximum = 51,
857 .step = 1,
858 .default_value = 0,
859 },
860 {
861 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP,
862 .type = V4L2_CTRL_TYPE_INTEGER,
863 .minimum = 0,
864 .maximum = 51,
865 .step = 1,
866 .default_value = 0,
867 },
868 {
869 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP,
870 .type = V4L2_CTRL_TYPE_INTEGER,
871 .minimum = 0,
872 .maximum = 51,
873 .step = 1,
874 .default_value = 0,
875 },
876 {
877 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP,
878 .type = V4L2_CTRL_TYPE_INTEGER,
879 .minimum = 0,
880 .maximum = 51,
881 .step = 1,
882 .default_value = 0,
883 },
884 {
885 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP,
886 .type = V4L2_CTRL_TYPE_INTEGER,
887 .minimum = 0,
888 .maximum = 51,
889 .step = 1,
890 .default_value = 0,
891 },
892 {
893 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP,
894 .type = V4L2_CTRL_TYPE_INTEGER,
895 .minimum = 0,
896 .maximum = 51,
897 .step = 1,
898 .default_value = 0,
899 },
900 {
901 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR,
902 .type = V4L2_CTRL_TYPE_INTEGER,
903 .minimum = INT_MIN,
904 .maximum = INT_MAX,
905 .step = 1,
906 .default_value = 0,
907 },
908 {
909 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR,
910 .type = V4L2_CTRL_TYPE_INTEGER,
911 .minimum = INT_MIN,
912 .maximum = INT_MAX,
913 .step = 1,
914 .default_value = 0,
915 },
916 {
917 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR,
918 .type = V4L2_CTRL_TYPE_INTEGER,
919 .minimum = INT_MIN,
920 .maximum = INT_MAX,
921 .step = 1,
922 .default_value = 0,
923 },
924 {
925 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR,
926 .type = V4L2_CTRL_TYPE_INTEGER,
927 .minimum = INT_MIN,
928 .maximum = INT_MAX,
929 .step = 1,
930 .default_value = 0,
931 },
932 {
933 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR,
934 .type = V4L2_CTRL_TYPE_INTEGER,
935 .minimum = INT_MIN,
936 .maximum = INT_MAX,
937 .step = 1,
938 .default_value = 0,
939 },
940 {
941 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR,
942 .type = V4L2_CTRL_TYPE_INTEGER,
943 .minimum = INT_MIN,
944 .maximum = INT_MAX,
945 .step = 1,
946 .default_value = 0,
947 },
948 {
949 .id = V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR,
950 .type = V4L2_CTRL_TYPE_INTEGER,
951 .minimum = INT_MIN,
952 .maximum = INT_MAX,
953 .step = 1,
954 .default_value = 0,
955 },
956 {
957 .id = V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB,
958 .type = V4L2_CTRL_TYPE_BOOLEAN,
959 .minimum = 0,
960 .maximum = 1,
961 .step = 1,
962 .default_value = 0,
963 },
964 {
965 .id = V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID,
966 .type = V4L2_CTRL_TYPE_BOOLEAN,
967 .minimum = 0,
968 .maximum = 1,
969 .step = 1,
970 .default_value = 0,
971 },
972 {
973 .id = V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING,
974 .type = V4L2_CTRL_TYPE_BOOLEAN,
975 .minimum = 0,
976 .maximum = 1,
977 .step = 1,
978 .default_value = 0,
979 },
980 {
981 .id = V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT,
982 .type = V4L2_CTRL_TYPE_BOOLEAN,
983 .minimum = 0,
984 .maximum = 1,
985 .step = 1,
986 .default_value = 0,
987 },
988 {
989 .id = V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION,
990 .type = V4L2_CTRL_TYPE_BOOLEAN,
991 .minimum = 0,
992 .maximum = 1,
993 .step = 1,
994 .default_value = 0,
995 },
996 {
997 .id = V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1,
998 .type = V4L2_CTRL_TYPE_INTEGER,
999 .minimum = 0,
1000 .maximum = 4,
1001 .step = 1,
1002 .default_value = 0,
1003 },
1004 {
1005 .id = V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE,
1006 .type = V4L2_CTRL_TYPE_BOOLEAN,
1007 .minimum = 0,
1008 .maximum = 1,
1009 .step = 1,
1010 .default_value = 0,
1011 },
1012 {
1013 .id = V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD,
1014 .type = V4L2_CTRL_TYPE_INTEGER,
1015 .minimum = 0,
1016 .maximum = (1 << 16) - 1,
1017 .step = 1,
1018 .default_value = 0,
1019 },
1020 {
1021 .id = V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2,
1022 .type = V4L2_CTRL_TYPE_INTEGER,
1023 .minimum = -6,
1024 .maximum = 6,
1025 .step = 1,
1026 .default_value = 0,
1027 },
1028 {
1029 .id = V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2,
1030 .type = V4L2_CTRL_TYPE_INTEGER,
1031 .minimum = -6,
1032 .maximum = 6,
1033 .step = 1,
1034 .default_value = 0,
1035 },
1036 {
1037 .id = V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD,
1038 .type = V4L2_CTRL_TYPE_MENU,
1039 .minimum = V4L2_MPEG_VIDEO_HEVC_SIZE_0,
1040 .maximum = V4L2_MPEG_VIDEO_HEVC_SIZE_4,
1041 .step = 1,
1042 .default_value = V4L2_MPEG_VIDEO_HEVC_SIZE_0,
1043 },
1044 {
1045 .id = V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR,
1046 .type = V4L2_CTRL_TYPE_INTEGER,
1047 .minimum = 0,
1048 .maximum = 1,
1049 .step = 1,
1050 .default_value = 0,
1051 },
1052 {
1053 .id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
1054 .type = V4L2_CTRL_TYPE_INTEGER,
1055 .name = "Minimum number of output bufs",
1056 .minimum = 1,
1057 .maximum = 32,
1058 .step = 1,
1059 .default_value = 1,
1060 .is_volatile = 1,
1061 },
1062 };
1063
1064 #define NUM_CTRLS ARRAY_SIZE(controls)
1065 static const char * const *mfc51_get_menu(u32 id)
1066 {
1067 static const char * const mfc51_video_frame_skip[] = {
1068 "Disabled",
1069 "Level Limit",
1070 "VBV/CPB Limit",
1071 NULL,
1072 };
1073 static const char * const mfc51_video_force_frame[] = {
1074 "Disabled",
1075 "I Frame",
1076 "Not Coded",
1077 NULL,
1078 };
1079 switch (id) {
1080 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE:
1081 return mfc51_video_frame_skip;
1082 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE:
1083 return mfc51_video_force_frame;
1084 }
1085 return NULL;
1086 }
1087
1088 static int s5p_mfc_ctx_ready(struct s5p_mfc_ctx *ctx)
1089 {
1090 mfc_debug(2, "src=%d, dst=%d, state=%d\n",
1091 ctx->src_queue_cnt, ctx->dst_queue_cnt, ctx->state);
1092
1093 if (ctx->state == MFCINST_GOT_INST && ctx->dst_queue_cnt >= 1)
1094 return 1;
1095
1096 if ((ctx->state == MFCINST_RUNNING ||
1097 ctx->state == MFCINST_HEAD_PRODUCED) &&
1098 ctx->src_queue_cnt >= 1 && ctx->dst_queue_cnt >= 1)
1099 return 1;
1100
1101 if (ctx->state == MFCINST_FINISHING &&
1102 ctx->dst_queue_cnt >= 1)
1103 return 1;
1104 mfc_debug(2, "ctx is not ready\n");
1105 return 0;
1106 }
1107
1108 static void cleanup_ref_queue(struct s5p_mfc_ctx *ctx)
1109 {
1110 struct s5p_mfc_buf *mb_entry;
1111
1112
1113 while (!list_empty(&ctx->ref_queue)) {
1114 mb_entry = list_entry((&ctx->ref_queue)->next,
1115 struct s5p_mfc_buf, list);
1116 list_del(&mb_entry->list);
1117 ctx->ref_queue_cnt--;
1118 list_add_tail(&mb_entry->list, &ctx->src_queue);
1119 ctx->src_queue_cnt++;
1120 }
1121 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
1122 ctx->src_queue_cnt, ctx->ref_queue_cnt);
1123 INIT_LIST_HEAD(&ctx->ref_queue);
1124 ctx->ref_queue_cnt = 0;
1125 }
1126
1127 static int enc_pre_seq_start(struct s5p_mfc_ctx *ctx)
1128 {
1129 struct s5p_mfc_dev *dev = ctx->dev;
1130 struct s5p_mfc_buf *dst_mb;
1131 unsigned long dst_addr;
1132 unsigned int dst_size;
1133
1134 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1135 dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
1136 dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
1137 s5p_mfc_hw_call(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
1138 dst_size);
1139 return 0;
1140 }
1141
1142 static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
1143 {
1144 struct s5p_mfc_dev *dev = ctx->dev;
1145 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1146 struct s5p_mfc_buf *dst_mb;
1147 unsigned int enc_pb_count;
1148
1149 if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) {
1150 if (!list_empty(&ctx->dst_queue)) {
1151 dst_mb = list_entry(ctx->dst_queue.next,
1152 struct s5p_mfc_buf, list);
1153 list_del(&dst_mb->list);
1154 ctx->dst_queue_cnt--;
1155 vb2_set_plane_payload(&dst_mb->b->vb2_buf, 0,
1156 s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size,
1157 dev));
1158 vb2_buffer_done(&dst_mb->b->vb2_buf,
1159 VB2_BUF_STATE_DONE);
1160 }
1161 }
1162
1163 if (!IS_MFCV6_PLUS(dev)) {
1164 ctx->state = MFCINST_RUNNING;
1165 if (s5p_mfc_ctx_ready(ctx))
1166 set_work_bit_irqsave(ctx);
1167 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
1168 } else {
1169 enc_pb_count = s5p_mfc_hw_call(dev->mfc_ops,
1170 get_enc_dpb_count, dev);
1171 if (ctx->pb_count < enc_pb_count)
1172 ctx->pb_count = enc_pb_count;
1173 if (FW_HAS_E_MIN_SCRATCH_BUF(dev)) {
1174 ctx->scratch_buf_size = s5p_mfc_hw_call(dev->mfc_ops,
1175 get_e_min_scratch_buf_size, dev);
1176 ctx->bank1.size += ctx->scratch_buf_size;
1177 }
1178 ctx->state = MFCINST_HEAD_PRODUCED;
1179 }
1180
1181 return 0;
1182 }
1183
1184 static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx)
1185 {
1186 struct s5p_mfc_dev *dev = ctx->dev;
1187 struct s5p_mfc_buf *dst_mb;
1188 struct s5p_mfc_buf *src_mb;
1189 unsigned long src_y_addr, src_c_addr, dst_addr;
1190 unsigned int dst_size;
1191
1192 src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1193 src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0);
1194 src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1);
1195 s5p_mfc_hw_call(dev->mfc_ops, set_enc_frame_buffer, ctx,
1196 src_y_addr, src_c_addr);
1197
1198 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1199 dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
1200 dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
1201 s5p_mfc_hw_call(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
1202 dst_size);
1203
1204 return 0;
1205 }
1206
1207 static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
1208 {
1209 struct s5p_mfc_dev *dev = ctx->dev;
1210 struct s5p_mfc_buf *mb_entry;
1211 unsigned long enc_y_addr = 0, enc_c_addr = 0;
1212 unsigned long mb_y_addr, mb_c_addr;
1213 int slice_type;
1214 unsigned int strm_size;
1215
1216 slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
1217 strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
1218 mfc_debug(2, "Encoded slice type: %d\n", slice_type);
1219 mfc_debug(2, "Encoded stream size: %d\n", strm_size);
1220 mfc_debug(2, "Display order: %d\n",
1221 mfc_read(dev, S5P_FIMV_ENC_SI_PIC_CNT));
1222 if (slice_type >= 0) {
1223 s5p_mfc_hw_call(dev->mfc_ops, get_enc_frame_buffer, ctx,
1224 &enc_y_addr, &enc_c_addr);
1225 list_for_each_entry(mb_entry, &ctx->src_queue, list) {
1226 mb_y_addr = vb2_dma_contig_plane_dma_addr(
1227 &mb_entry->b->vb2_buf, 0);
1228 mb_c_addr = vb2_dma_contig_plane_dma_addr(
1229 &mb_entry->b->vb2_buf, 1);
1230 if ((enc_y_addr == mb_y_addr) &&
1231 (enc_c_addr == mb_c_addr)) {
1232 list_del(&mb_entry->list);
1233 ctx->src_queue_cnt--;
1234 vb2_buffer_done(&mb_entry->b->vb2_buf,
1235 VB2_BUF_STATE_DONE);
1236 break;
1237 }
1238 }
1239 list_for_each_entry(mb_entry, &ctx->ref_queue, list) {
1240 mb_y_addr = vb2_dma_contig_plane_dma_addr(
1241 &mb_entry->b->vb2_buf, 0);
1242 mb_c_addr = vb2_dma_contig_plane_dma_addr(
1243 &mb_entry->b->vb2_buf, 1);
1244 if ((enc_y_addr == mb_y_addr) &&
1245 (enc_c_addr == mb_c_addr)) {
1246 list_del(&mb_entry->list);
1247 ctx->ref_queue_cnt--;
1248 vb2_buffer_done(&mb_entry->b->vb2_buf,
1249 VB2_BUF_STATE_DONE);
1250 break;
1251 }
1252 }
1253 }
1254 if ((ctx->src_queue_cnt > 0) && (ctx->state == MFCINST_RUNNING)) {
1255 mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
1256 list);
1257 if (mb_entry->flags & MFC_BUF_FLAG_USED) {
1258 list_del(&mb_entry->list);
1259 ctx->src_queue_cnt--;
1260 list_add_tail(&mb_entry->list, &ctx->ref_queue);
1261 ctx->ref_queue_cnt++;
1262 }
1263 }
1264 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
1265 ctx->src_queue_cnt, ctx->ref_queue_cnt);
1266 if ((ctx->dst_queue_cnt > 0) && (strm_size > 0)) {
1267 mb_entry = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf,
1268 list);
1269 list_del(&mb_entry->list);
1270 ctx->dst_queue_cnt--;
1271 switch (slice_type) {
1272 case S5P_FIMV_ENC_SI_SLICE_TYPE_I:
1273 mb_entry->b->flags |= V4L2_BUF_FLAG_KEYFRAME;
1274 break;
1275 case S5P_FIMV_ENC_SI_SLICE_TYPE_P:
1276 mb_entry->b->flags |= V4L2_BUF_FLAG_PFRAME;
1277 break;
1278 case S5P_FIMV_ENC_SI_SLICE_TYPE_B:
1279 mb_entry->b->flags |= V4L2_BUF_FLAG_BFRAME;
1280 break;
1281 }
1282 vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
1283 vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
1284 }
1285 if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
1286 clear_work_bit(ctx);
1287
1288 return 0;
1289 }
1290
1291 static const struct s5p_mfc_codec_ops encoder_codec_ops = {
1292 .pre_seq_start = enc_pre_seq_start,
1293 .post_seq_start = enc_post_seq_start,
1294 .pre_frame_start = enc_pre_frame_start,
1295 .post_frame_start = enc_post_frame_start,
1296 };
1297
1298
1299 static int vidioc_querycap(struct file *file, void *priv,
1300 struct v4l2_capability *cap)
1301 {
1302 struct s5p_mfc_dev *dev = video_drvdata(file);
1303
1304 strscpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver));
1305 strscpy(cap->card, dev->vfd_enc->name, sizeof(cap->card));
1306 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1307 dev_name(&dev->plat_dev->dev));
1308 return 0;
1309 }
1310
1311 static int vidioc_enum_fmt(struct file *file, struct v4l2_fmtdesc *f,
1312 bool out)
1313 {
1314 struct s5p_mfc_dev *dev = video_drvdata(file);
1315 int i, j = 0;
1316
1317 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
1318 if (out && formats[i].type != MFC_FMT_RAW)
1319 continue;
1320 else if (!out && formats[i].type != MFC_FMT_ENC)
1321 continue;
1322 else if ((dev->variant->version_bit & formats[i].versions) == 0)
1323 continue;
1324
1325 if (j == f->index) {
1326 f->pixelformat = formats[i].fourcc;
1327 return 0;
1328 }
1329 ++j;
1330 }
1331 return -EINVAL;
1332 }
1333
1334 static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv,
1335 struct v4l2_fmtdesc *f)
1336 {
1337 return vidioc_enum_fmt(file, f, false);
1338 }
1339
1340 static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
1341 struct v4l2_fmtdesc *f)
1342 {
1343 return vidioc_enum_fmt(file, f, true);
1344 }
1345
1346 static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
1347 {
1348 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1349 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1350
1351 mfc_debug(2, "f->type = %d ctx->state = %d\n", f->type, ctx->state);
1352 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1353
1354 pix_fmt_mp->width = 0;
1355 pix_fmt_mp->height = 0;
1356 pix_fmt_mp->field = V4L2_FIELD_NONE;
1357 pix_fmt_mp->pixelformat = ctx->dst_fmt->fourcc;
1358 pix_fmt_mp->num_planes = ctx->dst_fmt->num_planes;
1359
1360 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->enc_dst_buf_size;
1361 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->enc_dst_buf_size;
1362 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1363
1364 pix_fmt_mp->width = ctx->img_width;
1365 pix_fmt_mp->height = ctx->img_height;
1366
1367 pix_fmt_mp->field = V4L2_FIELD_NONE;
1368 pix_fmt_mp->pixelformat = ctx->src_fmt->fourcc;
1369 pix_fmt_mp->num_planes = ctx->src_fmt->num_planes;
1370
1371 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->buf_width;
1372 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->luma_size;
1373 pix_fmt_mp->plane_fmt[1].bytesperline = ctx->buf_width;
1374 pix_fmt_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
1375 } else {
1376 mfc_err("invalid buf type\n");
1377 return -EINVAL;
1378 }
1379 return 0;
1380 }
1381
1382 static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
1383 {
1384 struct s5p_mfc_dev *dev = video_drvdata(file);
1385 struct s5p_mfc_fmt *fmt;
1386 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1387
1388 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1389 fmt = find_format(f, MFC_FMT_ENC);
1390 if (!fmt) {
1391 mfc_err("failed to try output format\n");
1392 return -EINVAL;
1393 }
1394 if ((dev->variant->version_bit & fmt->versions) == 0) {
1395 mfc_err("Unsupported format by this MFC version.\n");
1396 return -EINVAL;
1397 }
1398
1399 pix_fmt_mp->plane_fmt[0].bytesperline =
1400 pix_fmt_mp->plane_fmt[0].sizeimage;
1401 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1402 fmt = find_format(f, MFC_FMT_RAW);
1403 if (!fmt) {
1404 mfc_err("failed to try output format\n");
1405 return -EINVAL;
1406 }
1407 if ((dev->variant->version_bit & fmt->versions) == 0) {
1408 mfc_err("Unsupported format by this MFC version.\n");
1409 return -EINVAL;
1410 }
1411
1412 v4l_bound_align_image(&pix_fmt_mp->width, 8, 1920, 1,
1413 &pix_fmt_mp->height, 4, 1080, 1, 0);
1414 } else {
1415 mfc_err("invalid buf type\n");
1416 return -EINVAL;
1417 }
1418 return 0;
1419 }
1420
1421 static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
1422 {
1423 struct s5p_mfc_dev *dev = video_drvdata(file);
1424 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1425 struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
1426 int ret = 0;
1427
1428 ret = vidioc_try_fmt(file, priv, f);
1429 if (ret)
1430 return ret;
1431 if (ctx->vq_src.streaming || ctx->vq_dst.streaming) {
1432 v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
1433 ret = -EBUSY;
1434 goto out;
1435 }
1436 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1437
1438 ctx->dst_fmt = find_format(f, MFC_FMT_ENC);
1439 ctx->state = MFCINST_INIT;
1440 ctx->codec_mode = ctx->dst_fmt->codec_mode;
1441 ctx->enc_dst_buf_size = pix_fmt_mp->plane_fmt[0].sizeimage;
1442 pix_fmt_mp->plane_fmt[0].bytesperline = 0;
1443 ctx->dst_bufs_cnt = 0;
1444 ctx->capture_state = QUEUE_FREE;
1445 ret = s5p_mfc_open_mfc_inst(dev, ctx);
1446 } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1447
1448 ctx->src_fmt = find_format(f, MFC_FMT_RAW);
1449 ctx->img_width = pix_fmt_mp->width;
1450 ctx->img_height = pix_fmt_mp->height;
1451 mfc_debug(2, "codec number: %d\n", ctx->src_fmt->codec_mode);
1452 mfc_debug(2, "fmt - w: %d, h: %d, ctx - w: %d, h: %d\n",
1453 pix_fmt_mp->width, pix_fmt_mp->height,
1454 ctx->img_width, ctx->img_height);
1455
1456 s5p_mfc_hw_call(dev->mfc_ops, enc_calc_src_size, ctx);
1457 pix_fmt_mp->plane_fmt[0].sizeimage = ctx->luma_size;
1458 pix_fmt_mp->plane_fmt[0].bytesperline = ctx->buf_width;
1459 pix_fmt_mp->plane_fmt[1].sizeimage = ctx->chroma_size;
1460 pix_fmt_mp->plane_fmt[1].bytesperline = ctx->buf_width;
1461
1462 ctx->src_bufs_cnt = 0;
1463 ctx->output_state = QUEUE_FREE;
1464 } else {
1465 mfc_err("invalid buf type\n");
1466 ret = -EINVAL;
1467 }
1468 out:
1469 mfc_debug_leave();
1470 return ret;
1471 }
1472
1473 static int vidioc_reqbufs(struct file *file, void *priv,
1474 struct v4l2_requestbuffers *reqbufs)
1475 {
1476 struct s5p_mfc_dev *dev = video_drvdata(file);
1477 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1478 int ret = 0;
1479
1480
1481 if ((reqbufs->memory != V4L2_MEMORY_MMAP) &&
1482 (reqbufs->memory != V4L2_MEMORY_USERPTR))
1483 return -EINVAL;
1484 if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1485 if (reqbufs->count == 0) {
1486 mfc_debug(2, "Freeing buffers\n");
1487 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1488 s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers,
1489 ctx);
1490 ctx->capture_state = QUEUE_FREE;
1491 return ret;
1492 }
1493 if (ctx->capture_state != QUEUE_FREE) {
1494 mfc_err("invalid capture state: %d\n",
1495 ctx->capture_state);
1496 return -EINVAL;
1497 }
1498 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1499 if (ret != 0) {
1500 mfc_err("error in vb2_reqbufs() for E(D)\n");
1501 return ret;
1502 }
1503 ctx->capture_state = QUEUE_BUFS_REQUESTED;
1504
1505 ret = s5p_mfc_hw_call(ctx->dev->mfc_ops,
1506 alloc_codec_buffers, ctx);
1507 if (ret) {
1508 mfc_err("Failed to allocate encoding buffers\n");
1509 reqbufs->count = 0;
1510 ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
1511 return -ENOMEM;
1512 }
1513 } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1514 if (reqbufs->count == 0) {
1515 mfc_debug(2, "Freeing buffers\n");
1516 ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
1517 s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers,
1518 ctx);
1519 ctx->output_state = QUEUE_FREE;
1520 return ret;
1521 }
1522 if (ctx->output_state != QUEUE_FREE) {
1523 mfc_err("invalid output state: %d\n",
1524 ctx->output_state);
1525 return -EINVAL;
1526 }
1527
1528 if (IS_MFCV6_PLUS(dev)) {
1529
1530 if (ctx->pb_count &&
1531 (reqbufs->count < ctx->pb_count)) {
1532 reqbufs->count = ctx->pb_count;
1533 mfc_debug(2, "Minimum %d output buffers needed\n",
1534 ctx->pb_count);
1535 } else {
1536 ctx->pb_count = reqbufs->count;
1537 }
1538 }
1539
1540 ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
1541 if (ret != 0) {
1542 mfc_err("error in vb2_reqbufs() for E(S)\n");
1543 return ret;
1544 }
1545 ctx->output_state = QUEUE_BUFS_REQUESTED;
1546 } else {
1547 mfc_err("invalid buf type\n");
1548 return -EINVAL;
1549 }
1550 return ret;
1551 }
1552
1553 static int vidioc_querybuf(struct file *file, void *priv,
1554 struct v4l2_buffer *buf)
1555 {
1556 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1557 int ret = 0;
1558
1559
1560 if ((buf->memory != V4L2_MEMORY_MMAP) &&
1561 (buf->memory != V4L2_MEMORY_USERPTR))
1562 return -EINVAL;
1563 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1564 if (ctx->state != MFCINST_GOT_INST) {
1565 mfc_err("invalid context state: %d\n", ctx->state);
1566 return -EINVAL;
1567 }
1568 ret = vb2_querybuf(&ctx->vq_dst, buf);
1569 if (ret != 0) {
1570 mfc_err("error in vb2_querybuf() for E(D)\n");
1571 return ret;
1572 }
1573 buf->m.planes[0].m.mem_offset += DST_QUEUE_OFF_BASE;
1574 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1575 ret = vb2_querybuf(&ctx->vq_src, buf);
1576 if (ret != 0) {
1577 mfc_err("error in vb2_querybuf() for E(S)\n");
1578 return ret;
1579 }
1580 } else {
1581 mfc_err("invalid buf type\n");
1582 return -EINVAL;
1583 }
1584 return ret;
1585 }
1586
1587
1588 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1589 {
1590 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1591
1592 if (ctx->state == MFCINST_ERROR) {
1593 mfc_err("Call on QBUF after unrecoverable error\n");
1594 return -EIO;
1595 }
1596 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1597 if (ctx->state == MFCINST_FINISHING) {
1598 mfc_err("Call on QBUF after EOS command\n");
1599 return -EIO;
1600 }
1601 return vb2_qbuf(&ctx->vq_src, NULL, buf);
1602 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1603 return vb2_qbuf(&ctx->vq_dst, NULL, buf);
1604 }
1605 return -EINVAL;
1606 }
1607
1608
1609 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1610 {
1611 const struct v4l2_event ev = {
1612 .type = V4L2_EVENT_EOS
1613 };
1614 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1615 int ret;
1616
1617 if (ctx->state == MFCINST_ERROR) {
1618 mfc_err_limited("Call on DQBUF after unrecoverable error\n");
1619 return -EIO;
1620 }
1621 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1622 ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
1623 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1624 ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
1625 if (ret == 0 && ctx->state == MFCINST_FINISHED
1626 && list_empty(&ctx->vq_dst.done_list))
1627 v4l2_event_queue_fh(&ctx->fh, &ev);
1628 } else {
1629 ret = -EINVAL;
1630 }
1631
1632 return ret;
1633 }
1634
1635
1636 static int vidioc_expbuf(struct file *file, void *priv,
1637 struct v4l2_exportbuffer *eb)
1638 {
1639 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1640
1641 if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1642 return vb2_expbuf(&ctx->vq_src, eb);
1643 if (eb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1644 return vb2_expbuf(&ctx->vq_dst, eb);
1645 return -EINVAL;
1646 }
1647
1648
1649 static int vidioc_streamon(struct file *file, void *priv,
1650 enum v4l2_buf_type type)
1651 {
1652 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1653
1654 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1655 return vb2_streamon(&ctx->vq_src, type);
1656 else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1657 return vb2_streamon(&ctx->vq_dst, type);
1658 return -EINVAL;
1659 }
1660
1661
1662 static int vidioc_streamoff(struct file *file, void *priv,
1663 enum v4l2_buf_type type)
1664 {
1665 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
1666
1667 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
1668 return vb2_streamoff(&ctx->vq_src, type);
1669 else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1670 return vb2_streamoff(&ctx->vq_dst, type);
1671 return -EINVAL;
1672 }
1673
1674 static inline int h264_level(enum v4l2_mpeg_video_h264_level lvl)
1675 {
1676 static unsigned int t[V4L2_MPEG_VIDEO_H264_LEVEL_4_0 + 1] = {
1677 10,
1678 9,
1679 11,
1680 12,
1681 13,
1682 20,
1683 21,
1684 22,
1685 30,
1686 31,
1687 32,
1688 40,
1689 };
1690 return t[lvl];
1691 }
1692
1693 static inline int mpeg4_level(enum v4l2_mpeg_video_mpeg4_level lvl)
1694 {
1695 static unsigned int t[V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 + 1] = {
1696 0,
1697 9,
1698 1,
1699 2,
1700 3,
1701 7,
1702 4,
1703 5,
1704 };
1705 return t[lvl];
1706 }
1707
1708 static inline int hevc_level(enum v4l2_mpeg_video_hevc_level lvl)
1709 {
1710 static unsigned int t[] = {
1711 10,
1712 20,
1713 21,
1714 30,
1715 31,
1716 40,
1717 41,
1718 50,
1719 51,
1720 52,
1721 60,
1722 61,
1723 62,
1724 };
1725 return t[lvl];
1726 }
1727
1728 static inline int vui_sar_idc(enum v4l2_mpeg_video_h264_vui_sar_idc sar)
1729 {
1730 static unsigned int t[V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED + 1] = {
1731 0,
1732 1,
1733 2,
1734 3,
1735 4,
1736 5,
1737 6,
1738 7,
1739 8,
1740 9,
1741 10,
1742 11,
1743 12,
1744 13,
1745 14,
1746 15,
1747 16,
1748 255,
1749 };
1750 return t[sar];
1751 }
1752
1753
1754
1755
1756
1757 static void __enc_update_hevc_qp_ctrls_range(struct s5p_mfc_ctx *ctx,
1758 int min, int max)
1759 {
1760 static const int __hevc_qp_ctrls[] = {
1761 V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP,
1762 V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP,
1763 V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP,
1764 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP,
1765 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP,
1766 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP,
1767 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP,
1768 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP,
1769 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP,
1770 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP,
1771 };
1772 struct v4l2_ctrl *ctrl = NULL;
1773 int i, j;
1774
1775 for (i = 0; i < ARRAY_SIZE(__hevc_qp_ctrls); i++) {
1776 for (j = 0; j < ARRAY_SIZE(ctx->ctrls); j++) {
1777 if (ctx->ctrls[j]->id == __hevc_qp_ctrls[i]) {
1778 ctrl = ctx->ctrls[j];
1779 break;
1780 }
1781 }
1782 if (WARN_ON(!ctrl))
1783 break;
1784
1785 __v4l2_ctrl_modify_range(ctrl, min, max, ctrl->step, min);
1786 }
1787 }
1788
1789 static int s5p_mfc_enc_s_ctrl(struct v4l2_ctrl *ctrl)
1790 {
1791 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
1792 struct s5p_mfc_dev *dev = ctx->dev;
1793 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1794 int ret = 0;
1795
1796 switch (ctrl->id) {
1797 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
1798 p->gop_size = ctrl->val;
1799 break;
1800 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
1801 p->slice_mode = ctrl->val;
1802 break;
1803 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
1804 p->slice_mb = ctrl->val;
1805 break;
1806 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
1807 p->slice_bit = ctrl->val * 8;
1808 break;
1809 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
1810 p->intra_refresh_mb = ctrl->val;
1811 break;
1812 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING:
1813 p->pad = ctrl->val;
1814 break;
1815 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV:
1816 p->pad_luma = (ctrl->val >> 16) & 0xff;
1817 p->pad_cb = (ctrl->val >> 8) & 0xff;
1818 p->pad_cr = (ctrl->val >> 0) & 0xff;
1819 break;
1820 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
1821 p->rc_frame = ctrl->val;
1822 break;
1823 case V4L2_CID_MPEG_VIDEO_BITRATE:
1824 p->rc_bitrate = ctrl->val;
1825 break;
1826 case V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF:
1827 p->rc_reaction_coeff = ctrl->val;
1828 break;
1829 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE:
1830 ctx->force_frame_type = ctrl->val;
1831 break;
1832 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
1833 ctx->force_frame_type =
1834 V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME;
1835 break;
1836 case V4L2_CID_MPEG_VIDEO_VBV_SIZE:
1837 p->vbv_size = ctrl->val;
1838 break;
1839 case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE:
1840 p->mv_h_range = ctrl->val;
1841 break;
1842 case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE:
1843 p->mv_v_range = ctrl->val;
1844 break;
1845 case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE:
1846 p->codec.h264.cpb_size = ctrl->val;
1847 break;
1848 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
1849 p->seq_hdr_mode = ctrl->val;
1850 break;
1851 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE:
1852 p->frame_skip_mode = ctrl->val;
1853 break;
1854 case V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT:
1855 p->fixed_target_bit = ctrl->val;
1856 break;
1857 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1858 p->num_b_frame = ctrl->val;
1859 break;
1860 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
1861 switch (ctrl->val) {
1862 case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
1863 p->codec.h264.profile =
1864 S5P_FIMV_ENC_PROFILE_H264_MAIN;
1865 break;
1866 case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
1867 p->codec.h264.profile =
1868 S5P_FIMV_ENC_PROFILE_H264_HIGH;
1869 break;
1870 case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
1871 p->codec.h264.profile =
1872 S5P_FIMV_ENC_PROFILE_H264_BASELINE;
1873 break;
1874 case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
1875 if (IS_MFCV6_PLUS(dev))
1876 p->codec.h264.profile =
1877 S5P_FIMV_ENC_PROFILE_H264_CONSTRAINED_BASELINE;
1878 else
1879 ret = -EINVAL;
1880 break;
1881 default:
1882 ret = -EINVAL;
1883 }
1884 break;
1885 case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
1886 p->codec.h264.level_v4l2 = ctrl->val;
1887 p->codec.h264.level = h264_level(ctrl->val);
1888 if (p->codec.h264.level < 0) {
1889 mfc_err("Level number is wrong\n");
1890 ret = p->codec.h264.level;
1891 }
1892 break;
1893 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
1894 p->codec.mpeg4.level_v4l2 = ctrl->val;
1895 p->codec.mpeg4.level = mpeg4_level(ctrl->val);
1896 if (p->codec.mpeg4.level < 0) {
1897 mfc_err("Level number is wrong\n");
1898 ret = p->codec.mpeg4.level;
1899 }
1900 break;
1901 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
1902 p->codec.h264.loop_filter_mode = ctrl->val;
1903 break;
1904 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
1905 p->codec.h264.loop_filter_alpha = ctrl->val;
1906 break;
1907 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
1908 p->codec.h264.loop_filter_beta = ctrl->val;
1909 break;
1910 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
1911 p->codec.h264.entropy_mode = ctrl->val;
1912 break;
1913 case V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P:
1914 p->codec.h264.num_ref_pic_4p = ctrl->val;
1915 break;
1916 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
1917 p->codec.h264._8x8_transform = ctrl->val;
1918 break;
1919 case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
1920 p->rc_mb = ctrl->val;
1921 break;
1922 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
1923 p->codec.h264.rc_frame_qp = ctrl->val;
1924 break;
1925 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
1926 p->codec.h264.rc_min_qp = ctrl->val;
1927 break;
1928 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
1929 p->codec.h264.rc_max_qp = ctrl->val;
1930 break;
1931 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
1932 p->codec.h264.rc_p_frame_qp = ctrl->val;
1933 break;
1934 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
1935 p->codec.h264.rc_b_frame_qp = ctrl->val;
1936 break;
1937 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
1938 case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
1939 p->codec.mpeg4.rc_frame_qp = ctrl->val;
1940 break;
1941 case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
1942 case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
1943 p->codec.mpeg4.rc_min_qp = ctrl->val;
1944 break;
1945 case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
1946 case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
1947 p->codec.mpeg4.rc_max_qp = ctrl->val;
1948 break;
1949 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
1950 case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
1951 p->codec.mpeg4.rc_p_frame_qp = ctrl->val;
1952 break;
1953 case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
1954 case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
1955 p->codec.mpeg4.rc_b_frame_qp = ctrl->val;
1956 break;
1957 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK:
1958 p->codec.h264.rc_mb_dark = ctrl->val;
1959 break;
1960 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH:
1961 p->codec.h264.rc_mb_smooth = ctrl->val;
1962 break;
1963 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC:
1964 p->codec.h264.rc_mb_static = ctrl->val;
1965 break;
1966 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY:
1967 p->codec.h264.rc_mb_activity = ctrl->val;
1968 break;
1969 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
1970 p->codec.h264.vui_sar = ctrl->val;
1971 break;
1972 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
1973 p->codec.h264.vui_sar_idc = vui_sar_idc(ctrl->val);
1974 break;
1975 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH:
1976 p->codec.h264.vui_ext_sar_width = ctrl->val;
1977 break;
1978 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT:
1979 p->codec.h264.vui_ext_sar_height = ctrl->val;
1980 break;
1981 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1982 p->codec.h264.open_gop = !ctrl->val;
1983 break;
1984 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
1985 p->codec.h264.open_gop_size = ctrl->val;
1986 break;
1987 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
1988 switch (ctrl->val) {
1989 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE:
1990 p->codec.mpeg4.profile =
1991 S5P_FIMV_ENC_PROFILE_MPEG4_SIMPLE;
1992 break;
1993 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE:
1994 p->codec.mpeg4.profile =
1995 S5P_FIMV_ENC_PROFILE_MPEG4_ADVANCED_SIMPLE;
1996 break;
1997 default:
1998 ret = -EINVAL;
1999 }
2000 break;
2001 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
2002 p->codec.mpeg4.quarter_pixel = ctrl->val;
2003 break;
2004 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS:
2005 p->codec.vp8.num_partitions = ctrl->val;
2006 break;
2007 case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4:
2008 p->codec.vp8.imd_4x4 = ctrl->val;
2009 break;
2010 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES:
2011 p->codec.vp8.num_ref = ctrl->val;
2012 break;
2013 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL:
2014 p->codec.vp8.filter_level = ctrl->val;
2015 break;
2016 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS:
2017 p->codec.vp8.filter_sharpness = ctrl->val;
2018 break;
2019 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD:
2020 p->codec.vp8.golden_frame_ref_period = ctrl->val;
2021 break;
2022 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
2023 p->codec.vp8.golden_frame_sel = ctrl->val;
2024 break;
2025 case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP:
2026 p->codec.vp8.rc_min_qp = ctrl->val;
2027 break;
2028 case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP:
2029 p->codec.vp8.rc_max_qp = ctrl->val;
2030 break;
2031 case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP:
2032 p->codec.vp8.rc_frame_qp = ctrl->val;
2033 break;
2034 case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP:
2035 p->codec.vp8.rc_p_frame_qp = ctrl->val;
2036 break;
2037 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
2038 p->codec.vp8.profile = ctrl->val;
2039 break;
2040 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP:
2041 p->codec.hevc.rc_frame_qp = ctrl->val;
2042 break;
2043 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP:
2044 p->codec.hevc.rc_p_frame_qp = ctrl->val;
2045 break;
2046 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP:
2047 p->codec.hevc.rc_b_frame_qp = ctrl->val;
2048 break;
2049 case V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION:
2050 p->codec.hevc.rc_framerate = ctrl->val;
2051 break;
2052 case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP:
2053 p->codec.hevc.rc_min_qp = ctrl->val;
2054 __enc_update_hevc_qp_ctrls_range(ctx, ctrl->val,
2055 p->codec.hevc.rc_max_qp);
2056 break;
2057 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP:
2058 p->codec.hevc.rc_max_qp = ctrl->val;
2059 __enc_update_hevc_qp_ctrls_range(ctx, p->codec.hevc.rc_min_qp,
2060 ctrl->val);
2061 break;
2062 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
2063 p->codec.hevc.level_v4l2 = ctrl->val;
2064 p->codec.hevc.level = hevc_level(ctrl->val);
2065 break;
2066 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
2067 switch (ctrl->val) {
2068 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN:
2069 p->codec.hevc.profile =
2070 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN;
2071 break;
2072 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE:
2073 p->codec.hevc.profile =
2074 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE;
2075 break;
2076 default:
2077 ret = -EINVAL;
2078 }
2079 break;
2080 case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
2081 p->codec.hevc.tier = ctrl->val;
2082 break;
2083 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH:
2084 p->codec.hevc.max_partition_depth = ctrl->val;
2085 break;
2086 case V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES:
2087 p->codec.hevc.num_refs_for_p = ctrl->val;
2088 break;
2089 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE:
2090 p->codec.hevc.refreshtype = ctrl->val;
2091 break;
2092 case V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED:
2093 p->codec.hevc.const_intra_period_enable = ctrl->val;
2094 break;
2095 case V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU:
2096 p->codec.hevc.lossless_cu_enable = ctrl->val;
2097 break;
2098 case V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT:
2099 p->codec.hevc.wavefront_enable = ctrl->val;
2100 break;
2101 case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
2102 p->codec.hevc.loopfilter = ctrl->val;
2103 break;
2104 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP:
2105 p->codec.hevc.hier_qp_enable = ctrl->val;
2106 break;
2107 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
2108 p->codec.hevc.hier_qp_type = ctrl->val;
2109 break;
2110 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER:
2111 p->codec.hevc.num_hier_layer = ctrl->val;
2112 break;
2113 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP:
2114 p->codec.hevc.hier_qp_layer[0] = ctrl->val;
2115 break;
2116 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP:
2117 p->codec.hevc.hier_qp_layer[1] = ctrl->val;
2118 break;
2119 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP:
2120 p->codec.hevc.hier_qp_layer[2] = ctrl->val;
2121 break;
2122 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP:
2123 p->codec.hevc.hier_qp_layer[3] = ctrl->val;
2124 break;
2125 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP:
2126 p->codec.hevc.hier_qp_layer[4] = ctrl->val;
2127 break;
2128 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP:
2129 p->codec.hevc.hier_qp_layer[5] = ctrl->val;
2130 break;
2131 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP:
2132 p->codec.hevc.hier_qp_layer[6] = ctrl->val;
2133 break;
2134 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR:
2135 p->codec.hevc.hier_bit_layer[0] = ctrl->val;
2136 break;
2137 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR:
2138 p->codec.hevc.hier_bit_layer[1] = ctrl->val;
2139 break;
2140 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR:
2141 p->codec.hevc.hier_bit_layer[2] = ctrl->val;
2142 break;
2143 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR:
2144 p->codec.hevc.hier_bit_layer[3] = ctrl->val;
2145 break;
2146 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR:
2147 p->codec.hevc.hier_bit_layer[4] = ctrl->val;
2148 break;
2149 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR:
2150 p->codec.hevc.hier_bit_layer[5] = ctrl->val;
2151 break;
2152 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR:
2153 p->codec.hevc.hier_bit_layer[6] = ctrl->val;
2154 break;
2155 case V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB:
2156 p->codec.hevc.general_pb_enable = ctrl->val;
2157 break;
2158 case V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID:
2159 p->codec.hevc.temporal_id_enable = ctrl->val;
2160 break;
2161 case V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING:
2162 p->codec.hevc.strong_intra_smooth = ctrl->val;
2163 break;
2164 case V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT:
2165 p->codec.hevc.intra_pu_split_disable = ctrl->val;
2166 break;
2167 case V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION:
2168 p->codec.hevc.tmv_prediction_disable = !ctrl->val;
2169 break;
2170 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1:
2171 p->codec.hevc.max_num_merge_mv = ctrl->val;
2172 break;
2173 case V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE:
2174 p->codec.hevc.encoding_nostartcode_enable = ctrl->val;
2175 break;
2176 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD:
2177 p->codec.hevc.refreshperiod = ctrl->val;
2178 break;
2179 case V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2:
2180 p->codec.hevc.lf_beta_offset_div2 = ctrl->val;
2181 break;
2182 case V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2:
2183 p->codec.hevc.lf_tc_offset_div2 = ctrl->val;
2184 break;
2185 case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
2186 p->codec.hevc.size_of_length_field = ctrl->val;
2187 break;
2188 case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR:
2189 p->codec.hevc.prepend_sps_pps_to_idr = ctrl->val;
2190 break;
2191 default:
2192 v4l2_err(&dev->v4l2_dev, "Invalid control, id=%d, val=%d\n",
2193 ctrl->id, ctrl->val);
2194 ret = -EINVAL;
2195 }
2196 return ret;
2197 }
2198
2199 static int s5p_mfc_enc_g_v_ctrl(struct v4l2_ctrl *ctrl)
2200 {
2201 struct s5p_mfc_ctx *ctx = ctrl_to_ctx(ctrl);
2202 struct s5p_mfc_dev *dev = ctx->dev;
2203
2204 switch (ctrl->id) {
2205 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
2206 if (ctx->state >= MFCINST_HEAD_PARSED &&
2207 ctx->state < MFCINST_ABORT) {
2208 ctrl->val = ctx->pb_count;
2209 break;
2210 } else if (ctx->state != MFCINST_INIT) {
2211 v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
2212 return -EINVAL;
2213 }
2214
2215 s5p_mfc_wait_for_done_ctx(ctx,
2216 S5P_MFC_R2H_CMD_SEQ_DONE_RET, 0);
2217 if (ctx->state >= MFCINST_HEAD_PARSED &&
2218 ctx->state < MFCINST_ABORT) {
2219 ctrl->val = ctx->pb_count;
2220 } else {
2221 v4l2_err(&dev->v4l2_dev, "Encoding not initialised\n");
2222 return -EINVAL;
2223 }
2224 break;
2225 }
2226 return 0;
2227 }
2228
2229 static const struct v4l2_ctrl_ops s5p_mfc_enc_ctrl_ops = {
2230 .s_ctrl = s5p_mfc_enc_s_ctrl,
2231 .g_volatile_ctrl = s5p_mfc_enc_g_v_ctrl,
2232 };
2233
2234 static int vidioc_s_parm(struct file *file, void *priv,
2235 struct v4l2_streamparm *a)
2236 {
2237 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
2238
2239 if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2240 ctx->enc_params.rc_framerate_num =
2241 a->parm.output.timeperframe.denominator;
2242 ctx->enc_params.rc_framerate_denom =
2243 a->parm.output.timeperframe.numerator;
2244 } else {
2245 mfc_err("Setting FPS is only possible for the output queue\n");
2246 return -EINVAL;
2247 }
2248 return 0;
2249 }
2250
2251 static int vidioc_g_parm(struct file *file, void *priv,
2252 struct v4l2_streamparm *a)
2253 {
2254 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
2255
2256 if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
2257 a->parm.output.timeperframe.denominator =
2258 ctx->enc_params.rc_framerate_num;
2259 a->parm.output.timeperframe.numerator =
2260 ctx->enc_params.rc_framerate_denom;
2261 } else {
2262 mfc_err("Setting FPS is only possible for the output queue\n");
2263 return -EINVAL;
2264 }
2265 return 0;
2266 }
2267
2268 static int vidioc_encoder_cmd(struct file *file, void *priv,
2269 struct v4l2_encoder_cmd *cmd)
2270 {
2271 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
2272 struct s5p_mfc_dev *dev = ctx->dev;
2273 struct s5p_mfc_buf *buf;
2274 unsigned long flags;
2275
2276 switch (cmd->cmd) {
2277 case V4L2_ENC_CMD_STOP:
2278 if (cmd->flags != 0)
2279 return -EINVAL;
2280
2281 if (!ctx->vq_src.streaming)
2282 return -EINVAL;
2283
2284 spin_lock_irqsave(&dev->irqlock, flags);
2285 if (list_empty(&ctx->src_queue)) {
2286 mfc_debug(2, "EOS: empty src queue, entering finishing state\n");
2287 ctx->state = MFCINST_FINISHING;
2288 if (s5p_mfc_ctx_ready(ctx))
2289 set_work_bit_irqsave(ctx);
2290 spin_unlock_irqrestore(&dev->irqlock, flags);
2291 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
2292 } else {
2293 mfc_debug(2, "EOS: marking last buffer of stream\n");
2294 buf = list_entry(ctx->src_queue.prev,
2295 struct s5p_mfc_buf, list);
2296 if (buf->flags & MFC_BUF_FLAG_USED)
2297 ctx->state = MFCINST_FINISHING;
2298 else
2299 buf->flags |= MFC_BUF_FLAG_EOS;
2300 spin_unlock_irqrestore(&dev->irqlock, flags);
2301 }
2302 break;
2303 default:
2304 return -EINVAL;
2305
2306 }
2307 return 0;
2308 }
2309
2310 static int vidioc_subscribe_event(struct v4l2_fh *fh,
2311 const struct v4l2_event_subscription *sub)
2312 {
2313 switch (sub->type) {
2314 case V4L2_EVENT_EOS:
2315 return v4l2_event_subscribe(fh, sub, 2, NULL);
2316 default:
2317 return -EINVAL;
2318 }
2319 }
2320
2321 static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = {
2322 .vidioc_querycap = vidioc_querycap,
2323 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2324 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
2325 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
2326 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
2327 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
2328 .vidioc_try_fmt_vid_out_mplane = vidioc_try_fmt,
2329 .vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt,
2330 .vidioc_s_fmt_vid_out_mplane = vidioc_s_fmt,
2331 .vidioc_reqbufs = vidioc_reqbufs,
2332 .vidioc_querybuf = vidioc_querybuf,
2333 .vidioc_qbuf = vidioc_qbuf,
2334 .vidioc_dqbuf = vidioc_dqbuf,
2335 .vidioc_expbuf = vidioc_expbuf,
2336 .vidioc_streamon = vidioc_streamon,
2337 .vidioc_streamoff = vidioc_streamoff,
2338 .vidioc_s_parm = vidioc_s_parm,
2339 .vidioc_g_parm = vidioc_g_parm,
2340 .vidioc_encoder_cmd = vidioc_encoder_cmd,
2341 .vidioc_subscribe_event = vidioc_subscribe_event,
2342 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2343 };
2344
2345 static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
2346 {
2347 int i;
2348
2349 if (!fmt)
2350 return -EINVAL;
2351 if (fmt->num_planes != vb->num_planes) {
2352 mfc_err("invalid plane number for the format\n");
2353 return -EINVAL;
2354 }
2355 for (i = 0; i < fmt->num_planes; i++) {
2356 dma_addr_t dma = vb2_dma_contig_plane_dma_addr(vb, i);
2357 if (!dma) {
2358 mfc_err("failed to get plane cookie\n");
2359 return -EINVAL;
2360 }
2361 mfc_debug(2, "index: %d, plane[%d] cookie: %pad\n",
2362 vb->index, i, &dma);
2363 }
2364 return 0;
2365 }
2366
2367 static int s5p_mfc_queue_setup(struct vb2_queue *vq,
2368 unsigned int *buf_count, unsigned int *plane_count,
2369 unsigned int psize[], struct device *alloc_devs[])
2370 {
2371 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
2372 struct s5p_mfc_dev *dev = ctx->dev;
2373
2374 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2375 if (ctx->state != MFCINST_GOT_INST) {
2376 mfc_err("invalid state: %d\n", ctx->state);
2377 return -EINVAL;
2378 }
2379
2380 if (ctx->dst_fmt)
2381 *plane_count = ctx->dst_fmt->num_planes;
2382 else
2383 *plane_count = MFC_ENC_CAP_PLANE_COUNT;
2384 if (*buf_count < 1)
2385 *buf_count = 1;
2386 if (*buf_count > MFC_MAX_BUFFERS)
2387 *buf_count = MFC_MAX_BUFFERS;
2388 psize[0] = ctx->enc_dst_buf_size;
2389 alloc_devs[0] = ctx->dev->mem_dev[BANK_L_CTX];
2390 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2391 if (ctx->src_fmt)
2392 *plane_count = ctx->src_fmt->num_planes;
2393 else
2394 *plane_count = MFC_ENC_OUT_PLANE_COUNT;
2395
2396 if (*buf_count < 1)
2397 *buf_count = 1;
2398 if (*buf_count > MFC_MAX_BUFFERS)
2399 *buf_count = MFC_MAX_BUFFERS;
2400
2401 psize[0] = ctx->luma_size;
2402 psize[1] = ctx->chroma_size;
2403
2404 if (IS_MFCV6_PLUS(dev)) {
2405 alloc_devs[0] = ctx->dev->mem_dev[BANK_L_CTX];
2406 alloc_devs[1] = ctx->dev->mem_dev[BANK_L_CTX];
2407 } else {
2408 alloc_devs[0] = ctx->dev->mem_dev[BANK_R_CTX];
2409 alloc_devs[1] = ctx->dev->mem_dev[BANK_R_CTX];
2410 }
2411 } else {
2412 mfc_err("invalid queue type: %d\n", vq->type);
2413 return -EINVAL;
2414 }
2415 return 0;
2416 }
2417
2418 static int s5p_mfc_buf_init(struct vb2_buffer *vb)
2419 {
2420 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
2421 struct vb2_queue *vq = vb->vb2_queue;
2422 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
2423 unsigned int i;
2424 int ret;
2425
2426 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2427 ret = check_vb_with_fmt(ctx->dst_fmt, vb);
2428 if (ret < 0)
2429 return ret;
2430 i = vb->index;
2431 ctx->dst_bufs[i].b = vbuf;
2432 ctx->dst_bufs[i].cookie.stream =
2433 vb2_dma_contig_plane_dma_addr(vb, 0);
2434 ctx->dst_bufs_cnt++;
2435 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2436 ret = check_vb_with_fmt(ctx->src_fmt, vb);
2437 if (ret < 0)
2438 return ret;
2439 i = vb->index;
2440 ctx->src_bufs[i].b = vbuf;
2441 ctx->src_bufs[i].cookie.raw.luma =
2442 vb2_dma_contig_plane_dma_addr(vb, 0);
2443 ctx->src_bufs[i].cookie.raw.chroma =
2444 vb2_dma_contig_plane_dma_addr(vb, 1);
2445 ctx->src_bufs_cnt++;
2446 } else {
2447 mfc_err("invalid queue type: %d\n", vq->type);
2448 return -EINVAL;
2449 }
2450 return 0;
2451 }
2452
2453 static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
2454 {
2455 struct vb2_queue *vq = vb->vb2_queue;
2456 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
2457 int ret;
2458
2459 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2460 ret = check_vb_with_fmt(ctx->dst_fmt, vb);
2461 if (ret < 0)
2462 return ret;
2463 mfc_debug(2, "plane size: %ld, dst size: %zu\n",
2464 vb2_plane_size(vb, 0), ctx->enc_dst_buf_size);
2465 if (vb2_plane_size(vb, 0) < ctx->enc_dst_buf_size) {
2466 mfc_err("plane size is too small for capture\n");
2467 return -EINVAL;
2468 }
2469 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2470 ret = check_vb_with_fmt(ctx->src_fmt, vb);
2471 if (ret < 0)
2472 return ret;
2473 mfc_debug(2, "plane size: %ld, luma size: %d\n",
2474 vb2_plane_size(vb, 0), ctx->luma_size);
2475 mfc_debug(2, "plane size: %ld, chroma size: %d\n",
2476 vb2_plane_size(vb, 1), ctx->chroma_size);
2477 if (vb2_plane_size(vb, 0) < ctx->luma_size ||
2478 vb2_plane_size(vb, 1) < ctx->chroma_size) {
2479 mfc_err("plane size is too small for output\n");
2480 return -EINVAL;
2481 }
2482 } else {
2483 mfc_err("invalid queue type: %d\n", vq->type);
2484 return -EINVAL;
2485 }
2486 return 0;
2487 }
2488
2489 static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
2490 {
2491 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
2492 struct s5p_mfc_dev *dev = ctx->dev;
2493
2494 if (IS_MFCV6_PLUS(dev) &&
2495 (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
2496
2497 if ((ctx->state == MFCINST_GOT_INST) &&
2498 (dev->curr_ctx == ctx->num) && dev->hw_lock) {
2499 s5p_mfc_wait_for_done_ctx(ctx,
2500 S5P_MFC_R2H_CMD_SEQ_DONE_RET,
2501 0);
2502 }
2503
2504 if (ctx->src_bufs_cnt < ctx->pb_count) {
2505 mfc_err("Need minimum %d OUTPUT buffers\n",
2506 ctx->pb_count);
2507 return -ENOBUFS;
2508 }
2509 }
2510
2511
2512 if (s5p_mfc_ctx_ready(ctx))
2513 set_work_bit_irqsave(ctx);
2514 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
2515
2516 return 0;
2517 }
2518
2519 static void s5p_mfc_stop_streaming(struct vb2_queue *q)
2520 {
2521 unsigned long flags;
2522 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
2523 struct s5p_mfc_dev *dev = ctx->dev;
2524
2525 if ((ctx->state == MFCINST_FINISHING ||
2526 ctx->state == MFCINST_RUNNING) &&
2527 dev->curr_ctx == ctx->num && dev->hw_lock) {
2528 ctx->state = MFCINST_ABORT;
2529 s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_FRAME_DONE_RET,
2530 0);
2531 }
2532 ctx->state = MFCINST_FINISHED;
2533 spin_lock_irqsave(&dev->irqlock, flags);
2534 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2535 s5p_mfc_cleanup_queue(&ctx->dst_queue, &ctx->vq_dst);
2536 INIT_LIST_HEAD(&ctx->dst_queue);
2537 ctx->dst_queue_cnt = 0;
2538 }
2539 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2540 cleanup_ref_queue(ctx);
2541 s5p_mfc_cleanup_queue(&ctx->src_queue, &ctx->vq_src);
2542 INIT_LIST_HEAD(&ctx->src_queue);
2543 ctx->src_queue_cnt = 0;
2544 }
2545 spin_unlock_irqrestore(&dev->irqlock, flags);
2546 }
2547
2548 static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
2549 {
2550 struct vb2_queue *vq = vb->vb2_queue;
2551 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
2552 struct s5p_mfc_dev *dev = ctx->dev;
2553 unsigned long flags;
2554 struct s5p_mfc_buf *mfc_buf;
2555
2556 if (ctx->state == MFCINST_ERROR) {
2557 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
2558 cleanup_ref_queue(ctx);
2559 return;
2560 }
2561 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2562 mfc_buf = &ctx->dst_bufs[vb->index];
2563 mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
2564
2565 spin_lock_irqsave(&dev->irqlock, flags);
2566 list_add_tail(&mfc_buf->list, &ctx->dst_queue);
2567 ctx->dst_queue_cnt++;
2568 spin_unlock_irqrestore(&dev->irqlock, flags);
2569 } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2570 mfc_buf = &ctx->src_bufs[vb->index];
2571 mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
2572 spin_lock_irqsave(&dev->irqlock, flags);
2573 list_add_tail(&mfc_buf->list, &ctx->src_queue);
2574 ctx->src_queue_cnt++;
2575 spin_unlock_irqrestore(&dev->irqlock, flags);
2576 } else {
2577 mfc_err("unsupported buffer type (%d)\n", vq->type);
2578 }
2579 if (s5p_mfc_ctx_ready(ctx))
2580 set_work_bit_irqsave(ctx);
2581 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
2582 }
2583
2584 static struct vb2_ops s5p_mfc_enc_qops = {
2585 .queue_setup = s5p_mfc_queue_setup,
2586 .wait_prepare = vb2_ops_wait_prepare,
2587 .wait_finish = vb2_ops_wait_finish,
2588 .buf_init = s5p_mfc_buf_init,
2589 .buf_prepare = s5p_mfc_buf_prepare,
2590 .start_streaming = s5p_mfc_start_streaming,
2591 .stop_streaming = s5p_mfc_stop_streaming,
2592 .buf_queue = s5p_mfc_buf_queue,
2593 };
2594
2595 const struct s5p_mfc_codec_ops *get_enc_codec_ops(void)
2596 {
2597 return &encoder_codec_ops;
2598 }
2599
2600 struct vb2_ops *get_enc_queue_ops(void)
2601 {
2602 return &s5p_mfc_enc_qops;
2603 }
2604
2605 const struct v4l2_ioctl_ops *get_enc_v4l2_ioctl_ops(void)
2606 {
2607 return &s5p_mfc_enc_ioctl_ops;
2608 }
2609
2610 #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2WHICH(x) == V4L2_CTRL_CLASS_MPEG) \
2611 && V4L2_CTRL_DRIVER_PRIV(x))
2612
2613 int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx)
2614 {
2615 struct v4l2_ctrl_config cfg;
2616 int i;
2617
2618 v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
2619 if (ctx->ctrl_handler.error) {
2620 mfc_err("v4l2_ctrl_handler_init failed\n");
2621 return ctx->ctrl_handler.error;
2622 }
2623 for (i = 0; i < NUM_CTRLS; i++) {
2624 if (IS_MFC51_PRIV(controls[i].id)) {
2625 memset(&cfg, 0, sizeof(struct v4l2_ctrl_config));
2626 cfg.ops = &s5p_mfc_enc_ctrl_ops;
2627 cfg.id = controls[i].id;
2628 cfg.min = controls[i].minimum;
2629 cfg.max = controls[i].maximum;
2630 cfg.def = controls[i].default_value;
2631 cfg.name = controls[i].name;
2632 cfg.type = controls[i].type;
2633 cfg.flags = 0;
2634
2635 if (cfg.type == V4L2_CTRL_TYPE_MENU) {
2636 cfg.step = 0;
2637 cfg.menu_skip_mask = controls[i].menu_skip_mask;
2638 cfg.qmenu = mfc51_get_menu(cfg.id);
2639 } else {
2640 cfg.step = controls[i].step;
2641 cfg.menu_skip_mask = 0;
2642 }
2643 ctx->ctrls[i] = v4l2_ctrl_new_custom(&ctx->ctrl_handler,
2644 &cfg, NULL);
2645 } else {
2646 if ((controls[i].type == V4L2_CTRL_TYPE_MENU) ||
2647 (controls[i].type ==
2648 V4L2_CTRL_TYPE_INTEGER_MENU)) {
2649 ctx->ctrls[i] = v4l2_ctrl_new_std_menu(
2650 &ctx->ctrl_handler,
2651 &s5p_mfc_enc_ctrl_ops, controls[i].id,
2652 controls[i].maximum, 0,
2653 controls[i].default_value);
2654 } else {
2655 ctx->ctrls[i] = v4l2_ctrl_new_std(
2656 &ctx->ctrl_handler,
2657 &s5p_mfc_enc_ctrl_ops, controls[i].id,
2658 controls[i].minimum,
2659 controls[i].maximum, controls[i].step,
2660 controls[i].default_value);
2661 }
2662 }
2663 if (ctx->ctrl_handler.error) {
2664 mfc_err("Adding control (%d) failed\n", i);
2665 return ctx->ctrl_handler.error;
2666 }
2667 if (controls[i].is_volatile && ctx->ctrls[i])
2668 ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
2669 }
2670 v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
2671 return 0;
2672 }
2673
2674 void s5p_mfc_enc_ctrls_delete(struct s5p_mfc_ctx *ctx)
2675 {
2676 int i;
2677
2678 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
2679 for (i = 0; i < NUM_CTRLS; i++)
2680 ctx->ctrls[i] = NULL;
2681 }
2682
2683 void s5p_mfc_enc_init(struct s5p_mfc_ctx *ctx)
2684 {
2685 struct v4l2_format f;
2686 f.fmt.pix_mp.pixelformat = DEF_SRC_FMT_ENC;
2687 ctx->src_fmt = find_format(&f, MFC_FMT_RAW);
2688 f.fmt.pix_mp.pixelformat = DEF_DST_FMT_ENC;
2689 ctx->dst_fmt = find_format(&f, MFC_FMT_ENC);
2690 }