2 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
7 * Jeongtae Park <jtp.park@samsung.com>
8 * Kamil Debski <k.debski@samsung.com>
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.
16 #include <linux/clk.h>
17 #include <linux/interrupt.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"
34 #define DEF_SRC_FMT_ENC V4L2_PIX_FMT_NV12M
35 #define DEF_DST_FMT_ENC V4L2_PIX_FMT_H264
37 static struct s5p_mfc_fmt formats
[] = {
39 .name
= "4:2:0 2 Planes 16x16 Tiles",
40 .fourcc
= V4L2_PIX_FMT_NV12MT_16X16
,
41 .codec_mode
= S5P_MFC_CODEC_NONE
,
44 .versions
= MFC_V6_BIT
| MFC_V7_BIT
,
47 .name
= "4:2:0 2 Planes 64x32 Tiles",
48 .fourcc
= V4L2_PIX_FMT_NV12MT
,
49 .codec_mode
= S5P_MFC_CODEC_NONE
,
52 .versions
= MFC_V5_BIT
,
55 .name
= "4:2:0 2 Planes Y/CbCr",
56 .fourcc
= V4L2_PIX_FMT_NV12M
,
57 .codec_mode
= S5P_MFC_CODEC_NONE
,
60 .versions
= MFC_V5PLUS_BITS
,
63 .name
= "4:2:0 2 Planes Y/CrCb",
64 .fourcc
= V4L2_PIX_FMT_NV21M
,
65 .codec_mode
= S5P_MFC_CODEC_NONE
,
68 .versions
= MFC_V6PLUS_BITS
,
71 .name
= "H264 Encoded Stream",
72 .fourcc
= V4L2_PIX_FMT_H264
,
73 .codec_mode
= S5P_MFC_CODEC_H264_ENC
,
76 .versions
= MFC_V5PLUS_BITS
,
79 .name
= "MPEG4 Encoded Stream",
80 .fourcc
= V4L2_PIX_FMT_MPEG4
,
81 .codec_mode
= S5P_MFC_CODEC_MPEG4_ENC
,
84 .versions
= MFC_V5PLUS_BITS
,
87 .name
= "H263 Encoded Stream",
88 .fourcc
= V4L2_PIX_FMT_H263
,
89 .codec_mode
= S5P_MFC_CODEC_H263_ENC
,
92 .versions
= MFC_V5PLUS_BITS
,
95 .name
= "VP8 Encoded Stream",
96 .fourcc
= V4L2_PIX_FMT_VP8
,
97 .codec_mode
= S5P_MFC_CODEC_VP8_ENC
,
100 .versions
= MFC_V7PLUS_BITS
,
103 .fourcc
= V4L2_PIX_FMT_HEVC
,
104 .codec_mode
= S5P_FIMV_CODEC_HEVC_ENC
,
107 .versions
= MFC_V10_BIT
,
111 #define NUM_FORMATS ARRAY_SIZE(formats)
112 static struct s5p_mfc_fmt
*find_format(struct v4l2_format
*f
, unsigned int t
)
116 for (i
= 0; i
< NUM_FORMATS
; i
++) {
117 if (formats
[i
].fourcc
== f
->fmt
.pix_mp
.pixelformat
&&
118 formats
[i
].type
== t
)
124 static struct mfc_control controls
[] = {
126 .id
= V4L2_CID_MPEG_VIDEO_GOP_SIZE
,
127 .type
= V4L2_CTRL_TYPE_INTEGER
,
129 .maximum
= (1 << 16) - 1,
134 .id
= V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE
,
135 .type
= V4L2_CTRL_TYPE_MENU
,
136 .minimum
= V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE
,
137 .maximum
= V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES
,
138 .default_value
= V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE
,
142 .id
= V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB
,
143 .type
= V4L2_CTRL_TYPE_INTEGER
,
145 .maximum
= (1 << 16) - 1,
150 .id
= V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES
,
151 .type
= V4L2_CTRL_TYPE_INTEGER
,
153 .maximum
= (1 << 30) - 1,
155 .default_value
= 1900,
158 .id
= V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB
,
159 .type
= V4L2_CTRL_TYPE_INTEGER
,
161 .maximum
= (1 << 16) - 1,
166 .id
= V4L2_CID_MPEG_MFC51_VIDEO_PADDING
,
167 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
168 .name
= "Padding Control Enable",
175 .id
= V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV
,
176 .type
= V4L2_CTRL_TYPE_INTEGER
,
177 .name
= "Padding Color YUV Value",
179 .maximum
= (1 << 25) - 1,
184 .id
= V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE
,
185 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
192 .id
= V4L2_CID_MPEG_VIDEO_BITRATE
,
193 .type
= V4L2_CTRL_TYPE_INTEGER
,
195 .maximum
= (1 << 30) - 1,
200 .id
= V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF
,
201 .type
= V4L2_CTRL_TYPE_INTEGER
,
202 .name
= "Rate Control Reaction Coeff.",
204 .maximum
= (1 << 16) - 1,
209 .id
= V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE
,
210 .type
= V4L2_CTRL_TYPE_MENU
,
211 .name
= "Force frame type",
212 .minimum
= V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED
,
213 .maximum
= V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED
,
214 .default_value
= V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED
,
218 .id
= V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
,
219 .type
= V4L2_CTRL_TYPE_BUTTON
,
226 .id
= V4L2_CID_MPEG_VIDEO_VBV_SIZE
,
227 .type
= V4L2_CTRL_TYPE_INTEGER
,
229 .maximum
= (1 << 16) - 1,
234 .id
= V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE
,
235 .type
= V4L2_CTRL_TYPE_INTEGER
,
236 .name
= "Horizontal MV Search Range",
243 .id
= V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE
,
244 .type
= V4L2_CTRL_TYPE_INTEGER
,
245 .name
= "Vertical MV Search Range",
252 .id
= V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE
,
253 .type
= V4L2_CTRL_TYPE_INTEGER
,
255 .maximum
= (1 << 16) - 1,
260 .id
= V4L2_CID_MPEG_VIDEO_HEADER_MODE
,
261 .type
= V4L2_CTRL_TYPE_MENU
,
262 .minimum
= V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE
,
263 .maximum
= V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME
,
264 .default_value
= V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE
,
268 .id
= V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE
,
269 .type
= V4L2_CTRL_TYPE_MENU
,
270 .name
= "Frame Skip Enable",
271 .minimum
= V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED
,
272 .maximum
= V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
,
274 .default_value
= V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED
,
277 .id
= V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT
,
278 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
279 .name
= "Fixed Target Bit Enable",
287 .id
= V4L2_CID_MPEG_VIDEO_B_FRAMES
,
288 .type
= V4L2_CTRL_TYPE_INTEGER
,
295 .id
= V4L2_CID_MPEG_VIDEO_H264_PROFILE
,
296 .type
= V4L2_CTRL_TYPE_MENU
,
297 .minimum
= V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE
,
298 .maximum
= V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH
,
299 .default_value
= V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE
,
301 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE
) |
302 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN
) |
303 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH
)
307 .id
= V4L2_CID_MPEG_VIDEO_H264_LEVEL
,
308 .type
= V4L2_CTRL_TYPE_MENU
,
309 .minimum
= V4L2_MPEG_VIDEO_H264_LEVEL_1_0
,
310 .maximum
= V4L2_MPEG_VIDEO_H264_LEVEL_4_0
,
311 .default_value
= V4L2_MPEG_VIDEO_H264_LEVEL_1_0
,
314 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL
,
315 .type
= V4L2_CTRL_TYPE_MENU
,
316 .minimum
= V4L2_MPEG_VIDEO_MPEG4_LEVEL_0
,
317 .maximum
= V4L2_MPEG_VIDEO_MPEG4_LEVEL_5
,
318 .default_value
= V4L2_MPEG_VIDEO_MPEG4_LEVEL_0
,
322 .id
= V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE
,
323 .type
= V4L2_CTRL_TYPE_MENU
,
324 .minimum
= V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED
,
325 .maximum
= V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
,
326 .default_value
= V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED
,
330 .id
= V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA
,
331 .type
= V4L2_CTRL_TYPE_INTEGER
,
338 .id
= V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA
,
339 .type
= V4L2_CTRL_TYPE_INTEGER
,
346 .id
= V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE
,
347 .type
= V4L2_CTRL_TYPE_MENU
,
348 .minimum
= V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC
,
349 .maximum
= V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC
,
350 .default_value
= V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC
,
354 .id
= V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P
,
355 .type
= V4L2_CTRL_TYPE_INTEGER
,
356 .name
= "The Number of Ref. Pic for P",
363 .id
= V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM
,
364 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
371 .id
= V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE
,
372 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
379 .id
= V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP
,
380 .type
= V4L2_CTRL_TYPE_INTEGER
,
387 .id
= V4L2_CID_MPEG_VIDEO_H264_MIN_QP
,
388 .type
= V4L2_CTRL_TYPE_INTEGER
,
395 .id
= V4L2_CID_MPEG_VIDEO_H264_MAX_QP
,
396 .type
= V4L2_CTRL_TYPE_INTEGER
,
403 .id
= V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP
,
404 .type
= V4L2_CTRL_TYPE_INTEGER
,
411 .id
= V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP
,
412 .type
= V4L2_CTRL_TYPE_INTEGER
,
419 .id
= V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP
,
420 .type
= V4L2_CTRL_TYPE_INTEGER
,
421 .name
= "H263 I-Frame QP value",
428 .id
= V4L2_CID_MPEG_VIDEO_H263_MIN_QP
,
429 .type
= V4L2_CTRL_TYPE_INTEGER
,
430 .name
= "H263 Minimum QP value",
437 .id
= V4L2_CID_MPEG_VIDEO_H263_MAX_QP
,
438 .type
= V4L2_CTRL_TYPE_INTEGER
,
439 .name
= "H263 Maximum QP value",
446 .id
= V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP
,
447 .type
= V4L2_CTRL_TYPE_INTEGER
,
448 .name
= "H263 P frame QP value",
455 .id
= V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP
,
456 .type
= V4L2_CTRL_TYPE_INTEGER
,
457 .name
= "H263 B frame QP value",
464 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP
,
465 .type
= V4L2_CTRL_TYPE_INTEGER
,
466 .name
= "MPEG4 I-Frame QP value",
473 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP
,
474 .type
= V4L2_CTRL_TYPE_INTEGER
,
475 .name
= "MPEG4 Minimum QP value",
482 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP
,
483 .type
= V4L2_CTRL_TYPE_INTEGER
,
484 .name
= "MPEG4 Maximum QP value",
491 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP
,
492 .type
= V4L2_CTRL_TYPE_INTEGER
,
493 .name
= "MPEG4 P frame QP value",
500 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP
,
501 .type
= V4L2_CTRL_TYPE_INTEGER
,
502 .name
= "MPEG4 B frame QP value",
509 .id
= V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK
,
510 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
511 .name
= "H264 Dark Reg Adaptive RC",
518 .id
= V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH
,
519 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
520 .name
= "H264 Smooth Reg Adaptive RC",
527 .id
= V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC
,
528 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
529 .name
= "H264 Static Reg Adaptive RC",
536 .id
= V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY
,
537 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
538 .name
= "H264 Activity Reg Adaptive RC",
545 .id
= V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE
,
546 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
553 .id
= V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC
,
554 .type
= V4L2_CTRL_TYPE_MENU
,
555 .minimum
= V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED
,
556 .maximum
= V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED
,
557 .default_value
= V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED
,
561 .id
= V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH
,
562 .type
= V4L2_CTRL_TYPE_INTEGER
,
564 .maximum
= (1 << 16) - 1,
569 .id
= V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT
,
570 .type
= V4L2_CTRL_TYPE_INTEGER
,
572 .maximum
= (1 << 16) - 1,
577 .id
= V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
,
578 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
585 .id
= V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
,
586 .type
= V4L2_CTRL_TYPE_INTEGER
,
588 .maximum
= (1 << 16) - 1,
593 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE
,
594 .type
= V4L2_CTRL_TYPE_MENU
,
595 .minimum
= V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE
,
596 .maximum
= V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE
,
597 .default_value
= V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE
,
601 .id
= V4L2_CID_MPEG_VIDEO_MPEG4_QPEL
,
602 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
609 .id
= V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS
,
610 .type
= V4L2_CTRL_TYPE_INTEGER_MENU
,
611 .maximum
= V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS
,
612 .default_value
= V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION
,
616 .id
= V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4
,
617 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
624 .id
= V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES
,
625 .type
= V4L2_CTRL_TYPE_INTEGER_MENU
,
626 .maximum
= V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME
,
627 .default_value
= V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME
,
631 .id
= V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL
,
632 .type
= V4L2_CTRL_TYPE_INTEGER
,
639 .id
= V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS
,
640 .type
= V4L2_CTRL_TYPE_INTEGER
,
647 .id
= V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD
,
648 .type
= V4L2_CTRL_TYPE_INTEGER
,
650 .maximum
= (1 << 16) - 1,
655 .id
= V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL
,
656 .type
= V4L2_CTRL_TYPE_MENU
,
657 .minimum
= V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV
,
658 .maximum
= V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD
,
659 .default_value
= V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV
,
663 .id
= V4L2_CID_MPEG_VIDEO_VPX_MAX_QP
,
664 .type
= V4L2_CTRL_TYPE_INTEGER
,
668 .default_value
= 127,
671 .id
= V4L2_CID_MPEG_VIDEO_VPX_MIN_QP
,
672 .type
= V4L2_CTRL_TYPE_INTEGER
,
679 .id
= V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP
,
680 .type
= V4L2_CTRL_TYPE_INTEGER
,
687 .id
= V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP
,
688 .type
= V4L2_CTRL_TYPE_INTEGER
,
695 .id
= V4L2_CID_MPEG_VIDEO_VP8_PROFILE
,
696 .type
= V4L2_CTRL_TYPE_MENU
,
697 .minimum
= V4L2_MPEG_VIDEO_VP8_PROFILE_0
,
698 .maximum
= V4L2_MPEG_VIDEO_VP8_PROFILE_3
,
699 .default_value
= V4L2_MPEG_VIDEO_VP8_PROFILE_0
,
703 .id
= V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP
,
704 .type
= V4L2_CTRL_TYPE_INTEGER
,
705 .name
= "HEVC I Frame QP Value",
712 .id
= V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP
,
713 .type
= V4L2_CTRL_TYPE_INTEGER
,
714 .name
= "HEVC P Frame QP Value",
721 .id
= V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP
,
722 .type
= V4L2_CTRL_TYPE_INTEGER
,
729 .id
= V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP
,
730 .type
= V4L2_CTRL_TYPE_INTEGER
,
737 .id
= V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP
,
738 .type
= V4L2_CTRL_TYPE_INTEGER
,
745 .id
= V4L2_CID_MPEG_VIDEO_HEVC_PROFILE
,
746 .type
= V4L2_CTRL_TYPE_MENU
,
747 .minimum
= V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN
,
748 .maximum
= V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE
,
750 .default_value
= V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN
,
753 .id
= V4L2_CID_MPEG_VIDEO_HEVC_LEVEL
,
754 .type
= V4L2_CTRL_TYPE_MENU
,
755 .minimum
= V4L2_MPEG_VIDEO_HEVC_LEVEL_1
,
756 .maximum
= V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2
,
758 .default_value
= V4L2_MPEG_VIDEO_HEVC_LEVEL_1
,
761 .id
= V4L2_CID_MPEG_VIDEO_HEVC_TIER
,
762 .type
= V4L2_CTRL_TYPE_MENU
,
763 .minimum
= V4L2_MPEG_VIDEO_HEVC_TIER_MAIN
,
764 .maximum
= V4L2_MPEG_VIDEO_HEVC_TIER_HIGH
,
766 .default_value
= V4L2_MPEG_VIDEO_HEVC_TIER_MAIN
,
769 .id
= V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION
,
770 .type
= V4L2_CTRL_TYPE_INTEGER
,
772 .maximum
= (1 << 16) - 1,
777 .id
= V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH
,
778 .type
= V4L2_CTRL_TYPE_INTEGER
,
785 .id
= V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES
,
786 .type
= V4L2_CTRL_TYPE_INTEGER
,
793 .id
= V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE
,
794 .type
= V4L2_CTRL_TYPE_MENU
,
795 .minimum
= V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE
,
796 .maximum
= V4L2_MPEG_VIDEO_HEVC_REFRESH_IDR
,
798 .default_value
= V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE
,
801 .id
= V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED
,
802 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
809 .id
= V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU
,
810 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
817 .id
= V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT
,
818 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
825 .id
= V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE
,
826 .type
= V4L2_CTRL_TYPE_MENU
,
827 .minimum
= V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED
,
828 .maximum
= V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
,
830 .default_value
= V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED
,
833 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP
,
834 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
841 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE
,
842 .type
= V4L2_CTRL_TYPE_MENU
,
843 .minimum
= V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B
,
844 .maximum
= V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P
,
846 .default_value
= V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B
,
849 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER
,
850 .type
= V4L2_CTRL_TYPE_INTEGER
,
857 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP
,
858 .type
= V4L2_CTRL_TYPE_INTEGER
,
865 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP
,
866 .type
= V4L2_CTRL_TYPE_INTEGER
,
873 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP
,
874 .type
= V4L2_CTRL_TYPE_INTEGER
,
881 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP
,
882 .type
= V4L2_CTRL_TYPE_INTEGER
,
889 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP
,
890 .type
= V4L2_CTRL_TYPE_INTEGER
,
897 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP
,
898 .type
= V4L2_CTRL_TYPE_INTEGER
,
905 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP
,
906 .type
= V4L2_CTRL_TYPE_INTEGER
,
913 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR
,
914 .type
= V4L2_CTRL_TYPE_INTEGER
,
921 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR
,
922 .type
= V4L2_CTRL_TYPE_INTEGER
,
929 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR
,
930 .type
= V4L2_CTRL_TYPE_INTEGER
,
937 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR
,
938 .type
= V4L2_CTRL_TYPE_INTEGER
,
945 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR
,
946 .type
= V4L2_CTRL_TYPE_INTEGER
,
953 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR
,
954 .type
= V4L2_CTRL_TYPE_INTEGER
,
961 .id
= V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR
,
962 .type
= V4L2_CTRL_TYPE_INTEGER
,
969 .id
= V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB
,
970 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
977 .id
= V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID
,
978 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
985 .id
= V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING
,
986 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
993 .id
= V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT
,
994 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
1001 .id
= V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION
,
1002 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
1009 .id
= V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1
,
1010 .type
= V4L2_CTRL_TYPE_INTEGER
,
1017 .id
= V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE
,
1018 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
1025 .id
= V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD
,
1026 .type
= V4L2_CTRL_TYPE_INTEGER
,
1028 .maximum
= (1 << 16) - 1,
1033 .id
= V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2
,
1034 .type
= V4L2_CTRL_TYPE_INTEGER
,
1041 .id
= V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2
,
1042 .type
= V4L2_CTRL_TYPE_INTEGER
,
1049 .id
= V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD
,
1050 .type
= V4L2_CTRL_TYPE_MENU
,
1051 .minimum
= V4L2_MPEG_VIDEO_HEVC_SIZE_0
,
1052 .maximum
= V4L2_MPEG_VIDEO_HEVC_SIZE_4
,
1054 .default_value
= V4L2_MPEG_VIDEO_HEVC_SIZE_0
,
1057 .id
= V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR
,
1058 .type
= V4L2_CTRL_TYPE_INTEGER
,
1065 .id
= V4L2_CID_MIN_BUFFERS_FOR_OUTPUT
,
1066 .type
= V4L2_CTRL_TYPE_INTEGER
,
1067 .name
= "Minimum number of output bufs",
1076 #define NUM_CTRLS ARRAY_SIZE(controls)
1077 static const char * const *mfc51_get_menu(u32 id
)
1079 static const char * const mfc51_video_frame_skip
[] = {
1085 static const char * const mfc51_video_force_frame
[] = {
1092 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE
:
1093 return mfc51_video_frame_skip
;
1094 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE
:
1095 return mfc51_video_force_frame
;
1100 static int s5p_mfc_ctx_ready(struct s5p_mfc_ctx
*ctx
)
1102 mfc_debug(2, "src=%d, dst=%d, state=%d\n",
1103 ctx
->src_queue_cnt
, ctx
->dst_queue_cnt
, ctx
->state
);
1104 /* context is ready to make header */
1105 if (ctx
->state
== MFCINST_GOT_INST
&& ctx
->dst_queue_cnt
>= 1)
1107 /* context is ready to encode a frame */
1108 if ((ctx
->state
== MFCINST_RUNNING
||
1109 ctx
->state
== MFCINST_HEAD_PRODUCED
) &&
1110 ctx
->src_queue_cnt
>= 1 && ctx
->dst_queue_cnt
>= 1)
1112 /* context is ready to encode remaining frames */
1113 if (ctx
->state
== MFCINST_FINISHING
&&
1114 ctx
->dst_queue_cnt
>= 1)
1116 mfc_debug(2, "ctx is not ready\n");
1120 static void cleanup_ref_queue(struct s5p_mfc_ctx
*ctx
)
1122 struct s5p_mfc_buf
*mb_entry
;
1124 /* move buffers in ref queue to src queue */
1125 while (!list_empty(&ctx
->ref_queue
)) {
1126 mb_entry
= list_entry((&ctx
->ref_queue
)->next
,
1127 struct s5p_mfc_buf
, list
);
1128 list_del(&mb_entry
->list
);
1129 ctx
->ref_queue_cnt
--;
1130 list_add_tail(&mb_entry
->list
, &ctx
->src_queue
);
1131 ctx
->src_queue_cnt
++;
1133 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
1134 ctx
->src_queue_cnt
, ctx
->ref_queue_cnt
);
1135 INIT_LIST_HEAD(&ctx
->ref_queue
);
1136 ctx
->ref_queue_cnt
= 0;
1139 static int enc_pre_seq_start(struct s5p_mfc_ctx
*ctx
)
1141 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1142 struct s5p_mfc_buf
*dst_mb
;
1143 unsigned long dst_addr
;
1144 unsigned int dst_size
;
1146 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1147 dst_addr
= vb2_dma_contig_plane_dma_addr(&dst_mb
->b
->vb2_buf
, 0);
1148 dst_size
= vb2_plane_size(&dst_mb
->b
->vb2_buf
, 0);
1149 s5p_mfc_hw_call(dev
->mfc_ops
, set_enc_stream_buffer
, ctx
, dst_addr
,
1154 static int enc_post_seq_start(struct s5p_mfc_ctx
*ctx
)
1156 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1157 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1158 struct s5p_mfc_buf
*dst_mb
;
1159 unsigned int enc_pb_count
;
1161 if (p
->seq_hdr_mode
== V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE
) {
1162 if (!list_empty(&ctx
->dst_queue
)) {
1163 dst_mb
= list_entry(ctx
->dst_queue
.next
,
1164 struct s5p_mfc_buf
, list
);
1165 list_del(&dst_mb
->list
);
1166 ctx
->dst_queue_cnt
--;
1167 vb2_set_plane_payload(&dst_mb
->b
->vb2_buf
, 0,
1168 s5p_mfc_hw_call(dev
->mfc_ops
, get_enc_strm_size
,
1170 vb2_buffer_done(&dst_mb
->b
->vb2_buf
,
1171 VB2_BUF_STATE_DONE
);
1175 if (!IS_MFCV6_PLUS(dev
)) {
1176 ctx
->state
= MFCINST_RUNNING
;
1177 if (s5p_mfc_ctx_ready(ctx
))
1178 set_work_bit_irqsave(ctx
);
1179 s5p_mfc_hw_call(dev
->mfc_ops
, try_run
, dev
);
1181 enc_pb_count
= s5p_mfc_hw_call(dev
->mfc_ops
,
1182 get_enc_dpb_count
, dev
);
1183 if (ctx
->pb_count
< enc_pb_count
)
1184 ctx
->pb_count
= enc_pb_count
;
1185 if (FW_HAS_E_MIN_SCRATCH_BUF(dev
)) {
1186 ctx
->scratch_buf_size
= s5p_mfc_hw_call(dev
->mfc_ops
,
1187 get_e_min_scratch_buf_size
, dev
);
1188 ctx
->bank1
.size
+= ctx
->scratch_buf_size
;
1190 ctx
->state
= MFCINST_HEAD_PRODUCED
;
1196 static int enc_pre_frame_start(struct s5p_mfc_ctx
*ctx
)
1198 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1199 struct s5p_mfc_buf
*dst_mb
;
1200 struct s5p_mfc_buf
*src_mb
;
1201 unsigned long src_y_addr
, src_c_addr
, dst_addr
;
1202 unsigned int dst_size
;
1204 src_mb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1205 src_y_addr
= vb2_dma_contig_plane_dma_addr(&src_mb
->b
->vb2_buf
, 0);
1206 src_c_addr
= vb2_dma_contig_plane_dma_addr(&src_mb
->b
->vb2_buf
, 1);
1207 s5p_mfc_hw_call(dev
->mfc_ops
, set_enc_frame_buffer
, ctx
,
1208 src_y_addr
, src_c_addr
);
1210 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1211 dst_addr
= vb2_dma_contig_plane_dma_addr(&dst_mb
->b
->vb2_buf
, 0);
1212 dst_size
= vb2_plane_size(&dst_mb
->b
->vb2_buf
, 0);
1213 s5p_mfc_hw_call(dev
->mfc_ops
, set_enc_stream_buffer
, ctx
, dst_addr
,
1219 static int enc_post_frame_start(struct s5p_mfc_ctx
*ctx
)
1221 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1222 struct s5p_mfc_buf
*mb_entry
;
1223 unsigned long enc_y_addr
= 0, enc_c_addr
= 0;
1224 unsigned long mb_y_addr
, mb_c_addr
;
1226 unsigned int strm_size
;
1228 slice_type
= s5p_mfc_hw_call(dev
->mfc_ops
, get_enc_slice_type
, dev
);
1229 strm_size
= s5p_mfc_hw_call(dev
->mfc_ops
, get_enc_strm_size
, dev
);
1230 mfc_debug(2, "Encoded slice type: %d\n", slice_type
);
1231 mfc_debug(2, "Encoded stream size: %d\n", strm_size
);
1232 mfc_debug(2, "Display order: %d\n",
1233 mfc_read(dev
, S5P_FIMV_ENC_SI_PIC_CNT
));
1234 if (slice_type
>= 0) {
1235 s5p_mfc_hw_call(dev
->mfc_ops
, get_enc_frame_buffer
, ctx
,
1236 &enc_y_addr
, &enc_c_addr
);
1237 list_for_each_entry(mb_entry
, &ctx
->src_queue
, list
) {
1238 mb_y_addr
= vb2_dma_contig_plane_dma_addr(
1239 &mb_entry
->b
->vb2_buf
, 0);
1240 mb_c_addr
= vb2_dma_contig_plane_dma_addr(
1241 &mb_entry
->b
->vb2_buf
, 1);
1242 if ((enc_y_addr
== mb_y_addr
) &&
1243 (enc_c_addr
== mb_c_addr
)) {
1244 list_del(&mb_entry
->list
);
1245 ctx
->src_queue_cnt
--;
1246 vb2_buffer_done(&mb_entry
->b
->vb2_buf
,
1247 VB2_BUF_STATE_DONE
);
1251 list_for_each_entry(mb_entry
, &ctx
->ref_queue
, list
) {
1252 mb_y_addr
= vb2_dma_contig_plane_dma_addr(
1253 &mb_entry
->b
->vb2_buf
, 0);
1254 mb_c_addr
= vb2_dma_contig_plane_dma_addr(
1255 &mb_entry
->b
->vb2_buf
, 1);
1256 if ((enc_y_addr
== mb_y_addr
) &&
1257 (enc_c_addr
== mb_c_addr
)) {
1258 list_del(&mb_entry
->list
);
1259 ctx
->ref_queue_cnt
--;
1260 vb2_buffer_done(&mb_entry
->b
->vb2_buf
,
1261 VB2_BUF_STATE_DONE
);
1266 if ((ctx
->src_queue_cnt
> 0) && (ctx
->state
== MFCINST_RUNNING
)) {
1267 mb_entry
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
,
1269 if (mb_entry
->flags
& MFC_BUF_FLAG_USED
) {
1270 list_del(&mb_entry
->list
);
1271 ctx
->src_queue_cnt
--;
1272 list_add_tail(&mb_entry
->list
, &ctx
->ref_queue
);
1273 ctx
->ref_queue_cnt
++;
1276 mfc_debug(2, "enc src count: %d, enc ref count: %d\n",
1277 ctx
->src_queue_cnt
, ctx
->ref_queue_cnt
);
1278 if ((ctx
->dst_queue_cnt
> 0) && (strm_size
> 0)) {
1279 mb_entry
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
,
1281 list_del(&mb_entry
->list
);
1282 ctx
->dst_queue_cnt
--;
1283 switch (slice_type
) {
1284 case S5P_FIMV_ENC_SI_SLICE_TYPE_I
:
1285 mb_entry
->b
->flags
|= V4L2_BUF_FLAG_KEYFRAME
;
1287 case S5P_FIMV_ENC_SI_SLICE_TYPE_P
:
1288 mb_entry
->b
->flags
|= V4L2_BUF_FLAG_PFRAME
;
1290 case S5P_FIMV_ENC_SI_SLICE_TYPE_B
:
1291 mb_entry
->b
->flags
|= V4L2_BUF_FLAG_BFRAME
;
1294 vb2_set_plane_payload(&mb_entry
->b
->vb2_buf
, 0, strm_size
);
1295 vb2_buffer_done(&mb_entry
->b
->vb2_buf
, VB2_BUF_STATE_DONE
);
1297 if ((ctx
->src_queue_cnt
== 0) || (ctx
->dst_queue_cnt
== 0))
1298 clear_work_bit(ctx
);
1303 static const struct s5p_mfc_codec_ops encoder_codec_ops
= {
1304 .pre_seq_start
= enc_pre_seq_start
,
1305 .post_seq_start
= enc_post_seq_start
,
1306 .pre_frame_start
= enc_pre_frame_start
,
1307 .post_frame_start
= enc_post_frame_start
,
1310 /* Query capabilities of the device */
1311 static int vidioc_querycap(struct file
*file
, void *priv
,
1312 struct v4l2_capability
*cap
)
1314 struct s5p_mfc_dev
*dev
= video_drvdata(file
);
1316 strlcpy(cap
->driver
, S5P_MFC_NAME
, sizeof(cap
->driver
));
1317 strlcpy(cap
->card
, dev
->vfd_enc
->name
, sizeof(cap
->card
));
1318 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "platform:%s",
1319 dev_name(&dev
->plat_dev
->dev
));
1321 * This is only a mem-to-mem video device. The capture and output
1322 * device capability flags are left only for backward compatibility
1323 * and are scheduled for removal.
1325 cap
->device_caps
= V4L2_CAP_VIDEO_M2M_MPLANE
| V4L2_CAP_STREAMING
;
1326 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1330 static int vidioc_enum_fmt(struct file
*file
, struct v4l2_fmtdesc
*f
,
1333 struct s5p_mfc_dev
*dev
= video_drvdata(file
);
1334 struct s5p_mfc_fmt
*fmt
;
1337 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
) {
1338 if (out
&& formats
[i
].type
!= MFC_FMT_RAW
)
1340 else if (!out
&& formats
[i
].type
!= MFC_FMT_ENC
)
1342 else if ((dev
->variant
->version_bit
& formats
[i
].versions
) == 0)
1345 if (j
== f
->index
) {
1347 strlcpy(f
->description
, fmt
->name
,
1348 sizeof(f
->description
));
1349 f
->pixelformat
= fmt
->fourcc
;
1357 static int vidioc_enum_fmt_vid_cap_mplane(struct file
*file
, void *pirv
,
1358 struct v4l2_fmtdesc
*f
)
1360 return vidioc_enum_fmt(file
, f
, false);
1363 static int vidioc_enum_fmt_vid_out_mplane(struct file
*file
, void *prov
,
1364 struct v4l2_fmtdesc
*f
)
1366 return vidioc_enum_fmt(file
, f
, true);
1369 static int vidioc_g_fmt(struct file
*file
, void *priv
, struct v4l2_format
*f
)
1371 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1372 struct v4l2_pix_format_mplane
*pix_fmt_mp
= &f
->fmt
.pix_mp
;
1374 mfc_debug(2, "f->type = %d ctx->state = %d\n", f
->type
, ctx
->state
);
1375 if (f
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1376 /* This is run on output (encoder dest) */
1377 pix_fmt_mp
->width
= 0;
1378 pix_fmt_mp
->height
= 0;
1379 pix_fmt_mp
->field
= V4L2_FIELD_NONE
;
1380 pix_fmt_mp
->pixelformat
= ctx
->dst_fmt
->fourcc
;
1381 pix_fmt_mp
->num_planes
= ctx
->dst_fmt
->num_planes
;
1383 pix_fmt_mp
->plane_fmt
[0].bytesperline
= ctx
->enc_dst_buf_size
;
1384 pix_fmt_mp
->plane_fmt
[0].sizeimage
= ctx
->enc_dst_buf_size
;
1385 } else if (f
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1386 /* This is run on capture (encoder src) */
1387 pix_fmt_mp
->width
= ctx
->img_width
;
1388 pix_fmt_mp
->height
= ctx
->img_height
;
1390 pix_fmt_mp
->field
= V4L2_FIELD_NONE
;
1391 pix_fmt_mp
->pixelformat
= ctx
->src_fmt
->fourcc
;
1392 pix_fmt_mp
->num_planes
= ctx
->src_fmt
->num_planes
;
1394 pix_fmt_mp
->plane_fmt
[0].bytesperline
= ctx
->buf_width
;
1395 pix_fmt_mp
->plane_fmt
[0].sizeimage
= ctx
->luma_size
;
1396 pix_fmt_mp
->plane_fmt
[1].bytesperline
= ctx
->buf_width
;
1397 pix_fmt_mp
->plane_fmt
[1].sizeimage
= ctx
->chroma_size
;
1399 mfc_err("invalid buf type\n");
1405 static int vidioc_try_fmt(struct file
*file
, void *priv
, struct v4l2_format
*f
)
1407 struct s5p_mfc_dev
*dev
= video_drvdata(file
);
1408 struct s5p_mfc_fmt
*fmt
;
1409 struct v4l2_pix_format_mplane
*pix_fmt_mp
= &f
->fmt
.pix_mp
;
1411 if (f
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1412 fmt
= find_format(f
, MFC_FMT_ENC
);
1414 mfc_err("failed to try output format\n");
1417 if ((dev
->variant
->version_bit
& fmt
->versions
) == 0) {
1418 mfc_err("Unsupported format by this MFC version.\n");
1422 pix_fmt_mp
->plane_fmt
[0].bytesperline
=
1423 pix_fmt_mp
->plane_fmt
[0].sizeimage
;
1424 } else if (f
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1425 fmt
= find_format(f
, MFC_FMT_RAW
);
1427 mfc_err("failed to try output format\n");
1430 if ((dev
->variant
->version_bit
& fmt
->versions
) == 0) {
1431 mfc_err("Unsupported format by this MFC version.\n");
1435 v4l_bound_align_image(&pix_fmt_mp
->width
, 8, 1920, 1,
1436 &pix_fmt_mp
->height
, 4, 1080, 1, 0);
1438 mfc_err("invalid buf type\n");
1444 static int vidioc_s_fmt(struct file
*file
, void *priv
, struct v4l2_format
*f
)
1446 struct s5p_mfc_dev
*dev
= video_drvdata(file
);
1447 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1448 struct v4l2_pix_format_mplane
*pix_fmt_mp
= &f
->fmt
.pix_mp
;
1451 ret
= vidioc_try_fmt(file
, priv
, f
);
1454 if (ctx
->vq_src
.streaming
|| ctx
->vq_dst
.streaming
) {
1455 v4l2_err(&dev
->v4l2_dev
, "%s queue busy\n", __func__
);
1459 if (f
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1460 /* dst_fmt is validated by call to vidioc_try_fmt */
1461 ctx
->dst_fmt
= find_format(f
, MFC_FMT_ENC
);
1462 ctx
->state
= MFCINST_INIT
;
1463 ctx
->codec_mode
= ctx
->dst_fmt
->codec_mode
;
1464 ctx
->enc_dst_buf_size
= pix_fmt_mp
->plane_fmt
[0].sizeimage
;
1465 pix_fmt_mp
->plane_fmt
[0].bytesperline
= 0;
1466 ctx
->dst_bufs_cnt
= 0;
1467 ctx
->capture_state
= QUEUE_FREE
;
1468 ret
= s5p_mfc_open_mfc_inst(dev
, ctx
);
1469 } else if (f
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1470 /* src_fmt is validated by call to vidioc_try_fmt */
1471 ctx
->src_fmt
= find_format(f
, MFC_FMT_RAW
);
1472 ctx
->img_width
= pix_fmt_mp
->width
;
1473 ctx
->img_height
= pix_fmt_mp
->height
;
1474 mfc_debug(2, "codec number: %d\n", ctx
->src_fmt
->codec_mode
);
1475 mfc_debug(2, "fmt - w: %d, h: %d, ctx - w: %d, h: %d\n",
1476 pix_fmt_mp
->width
, pix_fmt_mp
->height
,
1477 ctx
->img_width
, ctx
->img_height
);
1479 s5p_mfc_hw_call(dev
->mfc_ops
, enc_calc_src_size
, ctx
);
1480 pix_fmt_mp
->plane_fmt
[0].sizeimage
= ctx
->luma_size
;
1481 pix_fmt_mp
->plane_fmt
[0].bytesperline
= ctx
->buf_width
;
1482 pix_fmt_mp
->plane_fmt
[1].sizeimage
= ctx
->chroma_size
;
1483 pix_fmt_mp
->plane_fmt
[1].bytesperline
= ctx
->buf_width
;
1485 ctx
->src_bufs_cnt
= 0;
1486 ctx
->output_state
= QUEUE_FREE
;
1488 mfc_err("invalid buf type\n");
1496 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1497 struct v4l2_requestbuffers
*reqbufs
)
1499 struct s5p_mfc_dev
*dev
= video_drvdata(file
);
1500 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1503 /* if memory is not mmp or userptr return error */
1504 if ((reqbufs
->memory
!= V4L2_MEMORY_MMAP
) &&
1505 (reqbufs
->memory
!= V4L2_MEMORY_USERPTR
))
1507 if (reqbufs
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1508 if (reqbufs
->count
== 0) {
1509 mfc_debug(2, "Freeing buffers\n");
1510 ret
= vb2_reqbufs(&ctx
->vq_dst
, reqbufs
);
1511 s5p_mfc_hw_call(dev
->mfc_ops
, release_codec_buffers
,
1513 ctx
->capture_state
= QUEUE_FREE
;
1516 if (ctx
->capture_state
!= QUEUE_FREE
) {
1517 mfc_err("invalid capture state: %d\n",
1518 ctx
->capture_state
);
1521 ret
= vb2_reqbufs(&ctx
->vq_dst
, reqbufs
);
1523 mfc_err("error in vb2_reqbufs() for E(D)\n");
1526 ctx
->capture_state
= QUEUE_BUFS_REQUESTED
;
1528 ret
= s5p_mfc_hw_call(ctx
->dev
->mfc_ops
,
1529 alloc_codec_buffers
, ctx
);
1531 mfc_err("Failed to allocate encoding buffers\n");
1533 ret
= vb2_reqbufs(&ctx
->vq_dst
, reqbufs
);
1536 } else if (reqbufs
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1537 if (reqbufs
->count
== 0) {
1538 mfc_debug(2, "Freeing buffers\n");
1539 ret
= vb2_reqbufs(&ctx
->vq_src
, reqbufs
);
1540 s5p_mfc_hw_call(dev
->mfc_ops
, release_codec_buffers
,
1542 ctx
->output_state
= QUEUE_FREE
;
1545 if (ctx
->output_state
!= QUEUE_FREE
) {
1546 mfc_err("invalid output state: %d\n",
1551 if (IS_MFCV6_PLUS(dev
)) {
1552 /* Check for min encoder buffers */
1553 if (ctx
->pb_count
&&
1554 (reqbufs
->count
< ctx
->pb_count
)) {
1555 reqbufs
->count
= ctx
->pb_count
;
1556 mfc_debug(2, "Minimum %d output buffers needed\n",
1559 ctx
->pb_count
= reqbufs
->count
;
1563 ret
= vb2_reqbufs(&ctx
->vq_src
, reqbufs
);
1565 mfc_err("error in vb2_reqbufs() for E(S)\n");
1568 ctx
->output_state
= QUEUE_BUFS_REQUESTED
;
1570 mfc_err("invalid buf type\n");
1576 static int vidioc_querybuf(struct file
*file
, void *priv
,
1577 struct v4l2_buffer
*buf
)
1579 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1582 /* if memory is not mmp or userptr return error */
1583 if ((buf
->memory
!= V4L2_MEMORY_MMAP
) &&
1584 (buf
->memory
!= V4L2_MEMORY_USERPTR
))
1586 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1587 if (ctx
->state
!= MFCINST_GOT_INST
) {
1588 mfc_err("invalid context state: %d\n", ctx
->state
);
1591 ret
= vb2_querybuf(&ctx
->vq_dst
, buf
);
1593 mfc_err("error in vb2_querybuf() for E(D)\n");
1596 buf
->m
.planes
[0].m
.mem_offset
+= DST_QUEUE_OFF_BASE
;
1597 } else if (buf
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1598 ret
= vb2_querybuf(&ctx
->vq_src
, buf
);
1600 mfc_err("error in vb2_querybuf() for E(S)\n");
1604 mfc_err("invalid buf type\n");
1610 /* Queue a buffer */
1611 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*buf
)
1613 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1615 if (ctx
->state
== MFCINST_ERROR
) {
1616 mfc_err("Call on QBUF after unrecoverable error\n");
1619 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1620 if (ctx
->state
== MFCINST_FINISHING
) {
1621 mfc_err("Call on QBUF after EOS command\n");
1624 return vb2_qbuf(&ctx
->vq_src
, buf
);
1625 } else if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1626 return vb2_qbuf(&ctx
->vq_dst
, buf
);
1631 /* Dequeue a buffer */
1632 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*buf
)
1634 const struct v4l2_event ev
= {
1635 .type
= V4L2_EVENT_EOS
1637 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1640 if (ctx
->state
== MFCINST_ERROR
) {
1641 mfc_err_limited("Call on DQBUF after unrecoverable error\n");
1644 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
1645 ret
= vb2_dqbuf(&ctx
->vq_src
, buf
, file
->f_flags
& O_NONBLOCK
);
1646 } else if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
1647 ret
= vb2_dqbuf(&ctx
->vq_dst
, buf
, file
->f_flags
& O_NONBLOCK
);
1648 if (ret
== 0 && ctx
->state
== MFCINST_FINISHED
1649 && list_empty(&ctx
->vq_dst
.done_list
))
1650 v4l2_event_queue_fh(&ctx
->fh
, &ev
);
1658 /* Export DMA buffer */
1659 static int vidioc_expbuf(struct file
*file
, void *priv
,
1660 struct v4l2_exportbuffer
*eb
)
1662 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1664 if (eb
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
1665 return vb2_expbuf(&ctx
->vq_src
, eb
);
1666 if (eb
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
1667 return vb2_expbuf(&ctx
->vq_dst
, eb
);
1672 static int vidioc_streamon(struct file
*file
, void *priv
,
1673 enum v4l2_buf_type type
)
1675 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1677 if (type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
1678 return vb2_streamon(&ctx
->vq_src
, type
);
1679 else if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
1680 return vb2_streamon(&ctx
->vq_dst
, type
);
1684 /* Stream off, which equals to a pause */
1685 static int vidioc_streamoff(struct file
*file
, void *priv
,
1686 enum v4l2_buf_type type
)
1688 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
1690 if (type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
)
1691 return vb2_streamoff(&ctx
->vq_src
, type
);
1692 else if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)
1693 return vb2_streamoff(&ctx
->vq_dst
, type
);
1697 static inline int h264_level(enum v4l2_mpeg_video_h264_level lvl
)
1699 static unsigned int t
[V4L2_MPEG_VIDEO_H264_LEVEL_4_0
+ 1] = {
1700 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_0 */ 10,
1701 /* V4L2_MPEG_VIDEO_H264_LEVEL_1B */ 9,
1702 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_1 */ 11,
1703 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_2 */ 12,
1704 /* V4L2_MPEG_VIDEO_H264_LEVEL_1_3 */ 13,
1705 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_0 */ 20,
1706 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_1 */ 21,
1707 /* V4L2_MPEG_VIDEO_H264_LEVEL_2_2 */ 22,
1708 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_0 */ 30,
1709 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_1 */ 31,
1710 /* V4L2_MPEG_VIDEO_H264_LEVEL_3_2 */ 32,
1711 /* V4L2_MPEG_VIDEO_H264_LEVEL_4_0 */ 40,
1716 static inline int mpeg4_level(enum v4l2_mpeg_video_mpeg4_level lvl
)
1718 static unsigned int t
[V4L2_MPEG_VIDEO_MPEG4_LEVEL_5
+ 1] = {
1719 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 */ 0,
1720 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B */ 9,
1721 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 */ 1,
1722 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 */ 2,
1723 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 */ 3,
1724 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B */ 7,
1725 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 */ 4,
1726 /* V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 */ 5,
1731 static inline int hevc_level(enum v4l2_mpeg_video_hevc_level lvl
)
1733 static unsigned int t
[] = {
1734 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_1 */ 10,
1735 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_2 */ 20,
1736 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1 */ 21,
1737 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_3 */ 30,
1738 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1 */ 31,
1739 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_4 */ 40,
1740 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1 */ 41,
1741 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_5 */ 50,
1742 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1 */ 51,
1743 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2 */ 52,
1744 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_6 */ 60,
1745 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1 */ 61,
1746 /* V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2 */ 62,
1751 static inline int vui_sar_idc(enum v4l2_mpeg_video_h264_vui_sar_idc sar
)
1753 static unsigned int t
[V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED
+ 1] = {
1754 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED */ 0,
1755 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 */ 1,
1756 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 */ 2,
1757 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 */ 3,
1758 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 */ 4,
1759 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 */ 5,
1760 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 */ 6,
1761 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 */ 7,
1762 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 */ 8,
1763 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 */ 9,
1764 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 */ 10,
1765 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 */ 11,
1766 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 */ 12,
1767 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 */ 13,
1768 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 */ 14,
1769 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 */ 15,
1770 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 */ 16,
1771 /* V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED */ 255,
1777 * Update range of all HEVC quantization parameter controls that depend on the
1778 * V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP, V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP controls.
1780 static void __enc_update_hevc_qp_ctrls_range(struct s5p_mfc_ctx
*ctx
,
1783 static const int __hevc_qp_ctrls
[] = {
1784 V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP
,
1785 V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP
,
1786 V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP
,
1787 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP
,
1788 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP
,
1789 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP
,
1790 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP
,
1791 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP
,
1792 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP
,
1793 V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP
,
1795 struct v4l2_ctrl
*ctrl
= NULL
;
1798 for (i
= 0; i
< ARRAY_SIZE(__hevc_qp_ctrls
); i
++) {
1799 for (j
= 0; j
< ARRAY_SIZE(ctx
->ctrls
); j
++) {
1800 if (ctx
->ctrls
[j
]->id
== __hevc_qp_ctrls
[i
]) {
1801 ctrl
= ctx
->ctrls
[j
];
1808 __v4l2_ctrl_modify_range(ctrl
, min
, max
, ctrl
->step
, min
);
1812 static int s5p_mfc_enc_s_ctrl(struct v4l2_ctrl
*ctrl
)
1814 struct s5p_mfc_ctx
*ctx
= ctrl_to_ctx(ctrl
);
1815 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1816 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1820 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
1821 p
->gop_size
= ctrl
->val
;
1823 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE
:
1824 p
->slice_mode
= ctrl
->val
;
1826 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB
:
1827 p
->slice_mb
= ctrl
->val
;
1829 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES
:
1830 p
->slice_bit
= ctrl
->val
* 8;
1832 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB
:
1833 p
->intra_refresh_mb
= ctrl
->val
;
1835 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING
:
1838 case V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV
:
1839 p
->pad_luma
= (ctrl
->val
>> 16) & 0xff;
1840 p
->pad_cb
= (ctrl
->val
>> 8) & 0xff;
1841 p
->pad_cr
= (ctrl
->val
>> 0) & 0xff;
1843 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE
:
1844 p
->rc_frame
= ctrl
->val
;
1846 case V4L2_CID_MPEG_VIDEO_BITRATE
:
1847 p
->rc_bitrate
= ctrl
->val
;
1849 case V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF
:
1850 p
->rc_reaction_coeff
= ctrl
->val
;
1852 case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE
:
1853 ctx
->force_frame_type
= ctrl
->val
;
1855 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
:
1856 ctx
->force_frame_type
=
1857 V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME
;
1859 case V4L2_CID_MPEG_VIDEO_VBV_SIZE
:
1860 p
->vbv_size
= ctrl
->val
;
1862 case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE
:
1863 p
->mv_h_range
= ctrl
->val
;
1865 case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE
:
1866 p
->mv_v_range
= ctrl
->val
;
1868 case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE
:
1869 p
->codec
.h264
.cpb_size
= ctrl
->val
;
1871 case V4L2_CID_MPEG_VIDEO_HEADER_MODE
:
1872 p
->seq_hdr_mode
= ctrl
->val
;
1874 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE
:
1875 p
->frame_skip_mode
= ctrl
->val
;
1877 case V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT
:
1878 p
->fixed_target_bit
= ctrl
->val
;
1880 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
1881 p
->num_b_frame
= ctrl
->val
;
1883 case V4L2_CID_MPEG_VIDEO_H264_PROFILE
:
1884 switch (ctrl
->val
) {
1885 case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN
:
1886 p
->codec
.h264
.profile
=
1887 S5P_FIMV_ENC_PROFILE_H264_MAIN
;
1889 case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH
:
1890 p
->codec
.h264
.profile
=
1891 S5P_FIMV_ENC_PROFILE_H264_HIGH
;
1893 case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE
:
1894 p
->codec
.h264
.profile
=
1895 S5P_FIMV_ENC_PROFILE_H264_BASELINE
;
1897 case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE
:
1898 if (IS_MFCV6_PLUS(dev
))
1899 p
->codec
.h264
.profile
=
1900 S5P_FIMV_ENC_PROFILE_H264_CONSTRAINED_BASELINE
;
1908 case V4L2_CID_MPEG_VIDEO_H264_LEVEL
:
1909 p
->codec
.h264
.level_v4l2
= ctrl
->val
;
1910 p
->codec
.h264
.level
= h264_level(ctrl
->val
);
1911 if (p
->codec
.h264
.level
< 0) {
1912 mfc_err("Level number is wrong\n");
1913 ret
= p
->codec
.h264
.level
;
1916 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL
:
1917 p
->codec
.mpeg4
.level_v4l2
= ctrl
->val
;
1918 p
->codec
.mpeg4
.level
= mpeg4_level(ctrl
->val
);
1919 if (p
->codec
.mpeg4
.level
< 0) {
1920 mfc_err("Level number is wrong\n");
1921 ret
= p
->codec
.mpeg4
.level
;
1924 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE
:
1925 p
->codec
.h264
.loop_filter_mode
= ctrl
->val
;
1927 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA
:
1928 p
->codec
.h264
.loop_filter_alpha
= ctrl
->val
;
1930 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA
:
1931 p
->codec
.h264
.loop_filter_beta
= ctrl
->val
;
1933 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE
:
1934 p
->codec
.h264
.entropy_mode
= ctrl
->val
;
1936 case V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P
:
1937 p
->codec
.h264
.num_ref_pic_4p
= ctrl
->val
;
1939 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM
:
1940 p
->codec
.h264
._8x8_transform
= ctrl
->val
;
1942 case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE
:
1943 p
->rc_mb
= ctrl
->val
;
1945 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP
:
1946 p
->codec
.h264
.rc_frame_qp
= ctrl
->val
;
1948 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP
:
1949 p
->codec
.h264
.rc_min_qp
= ctrl
->val
;
1951 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP
:
1952 p
->codec
.h264
.rc_max_qp
= ctrl
->val
;
1954 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP
:
1955 p
->codec
.h264
.rc_p_frame_qp
= ctrl
->val
;
1957 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP
:
1958 p
->codec
.h264
.rc_b_frame_qp
= ctrl
->val
;
1960 case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP
:
1961 case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP
:
1962 p
->codec
.mpeg4
.rc_frame_qp
= ctrl
->val
;
1964 case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP
:
1965 case V4L2_CID_MPEG_VIDEO_H263_MIN_QP
:
1966 p
->codec
.mpeg4
.rc_min_qp
= ctrl
->val
;
1968 case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP
:
1969 case V4L2_CID_MPEG_VIDEO_H263_MAX_QP
:
1970 p
->codec
.mpeg4
.rc_max_qp
= ctrl
->val
;
1972 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP
:
1973 case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP
:
1974 p
->codec
.mpeg4
.rc_p_frame_qp
= ctrl
->val
;
1976 case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP
:
1977 case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP
:
1978 p
->codec
.mpeg4
.rc_b_frame_qp
= ctrl
->val
;
1980 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK
:
1981 p
->codec
.h264
.rc_mb_dark
= ctrl
->val
;
1983 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH
:
1984 p
->codec
.h264
.rc_mb_smooth
= ctrl
->val
;
1986 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC
:
1987 p
->codec
.h264
.rc_mb_static
= ctrl
->val
;
1989 case V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY
:
1990 p
->codec
.h264
.rc_mb_activity
= ctrl
->val
;
1992 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE
:
1993 p
->codec
.h264
.vui_sar
= ctrl
->val
;
1995 case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC
:
1996 p
->codec
.h264
.vui_sar_idc
= vui_sar_idc(ctrl
->val
);
1998 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH
:
1999 p
->codec
.h264
.vui_ext_sar_width
= ctrl
->val
;
2001 case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT
:
2002 p
->codec
.h264
.vui_ext_sar_height
= ctrl
->val
;
2004 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
:
2005 p
->codec
.h264
.open_gop
= !ctrl
->val
;
2007 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD
:
2008 p
->codec
.h264
.open_gop_size
= ctrl
->val
;
2010 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE
:
2011 switch (ctrl
->val
) {
2012 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE
:
2013 p
->codec
.mpeg4
.profile
=
2014 S5P_FIMV_ENC_PROFILE_MPEG4_SIMPLE
;
2016 case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE
:
2017 p
->codec
.mpeg4
.profile
=
2018 S5P_FIMV_ENC_PROFILE_MPEG4_ADVANCED_SIMPLE
;
2024 case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL
:
2025 p
->codec
.mpeg4
.quarter_pixel
= ctrl
->val
;
2027 case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS
:
2028 p
->codec
.vp8
.num_partitions
= ctrl
->val
;
2030 case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4
:
2031 p
->codec
.vp8
.imd_4x4
= ctrl
->val
;
2033 case V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES
:
2034 p
->codec
.vp8
.num_ref
= ctrl
->val
;
2036 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL
:
2037 p
->codec
.vp8
.filter_level
= ctrl
->val
;
2039 case V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS
:
2040 p
->codec
.vp8
.filter_sharpness
= ctrl
->val
;
2042 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD
:
2043 p
->codec
.vp8
.golden_frame_ref_period
= ctrl
->val
;
2045 case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL
:
2046 p
->codec
.vp8
.golden_frame_sel
= ctrl
->val
;
2048 case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP
:
2049 p
->codec
.vp8
.rc_min_qp
= ctrl
->val
;
2051 case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP
:
2052 p
->codec
.vp8
.rc_max_qp
= ctrl
->val
;
2054 case V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP
:
2055 p
->codec
.vp8
.rc_frame_qp
= ctrl
->val
;
2057 case V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP
:
2058 p
->codec
.vp8
.rc_p_frame_qp
= ctrl
->val
;
2060 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE
:
2061 p
->codec
.vp8
.profile
= ctrl
->val
;
2063 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP
:
2064 p
->codec
.hevc
.rc_frame_qp
= ctrl
->val
;
2066 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP
:
2067 p
->codec
.hevc
.rc_p_frame_qp
= ctrl
->val
;
2069 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP
:
2070 p
->codec
.hevc
.rc_b_frame_qp
= ctrl
->val
;
2072 case V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION
:
2073 p
->codec
.hevc
.rc_framerate
= ctrl
->val
;
2075 case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP
:
2076 p
->codec
.hevc
.rc_min_qp
= ctrl
->val
;
2077 __enc_update_hevc_qp_ctrls_range(ctx
, ctrl
->val
,
2078 p
->codec
.hevc
.rc_max_qp
);
2080 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP
:
2081 p
->codec
.hevc
.rc_max_qp
= ctrl
->val
;
2082 __enc_update_hevc_qp_ctrls_range(ctx
, p
->codec
.hevc
.rc_min_qp
,
2085 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL
:
2086 p
->codec
.hevc
.level_v4l2
= ctrl
->val
;
2087 p
->codec
.hevc
.level
= hevc_level(ctrl
->val
);
2089 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE
:
2090 switch (ctrl
->val
) {
2091 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN
:
2092 p
->codec
.hevc
.profile
=
2093 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN
;
2095 case V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE
:
2096 p
->codec
.hevc
.profile
=
2097 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE
;
2103 case V4L2_CID_MPEG_VIDEO_HEVC_TIER
:
2104 p
->codec
.hevc
.tier
= ctrl
->val
;
2106 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH
:
2107 p
->codec
.hevc
.max_partition_depth
= ctrl
->val
;
2109 case V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES
:
2110 p
->codec
.hevc
.num_refs_for_p
= ctrl
->val
;
2112 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE
:
2113 p
->codec
.hevc
.refreshtype
= ctrl
->val
;
2115 case V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED
:
2116 p
->codec
.hevc
.const_intra_period_enable
= ctrl
->val
;
2118 case V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU
:
2119 p
->codec
.hevc
.lossless_cu_enable
= ctrl
->val
;
2121 case V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT
:
2122 p
->codec
.hevc
.wavefront_enable
= ctrl
->val
;
2124 case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE
:
2125 p
->codec
.hevc
.loopfilter
= ctrl
->val
;
2127 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP
:
2128 p
->codec
.hevc
.hier_qp_enable
= ctrl
->val
;
2130 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE
:
2131 p
->codec
.hevc
.hier_qp_type
= ctrl
->val
;
2133 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER
:
2134 p
->codec
.hevc
.num_hier_layer
= ctrl
->val
;
2136 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP
:
2137 p
->codec
.hevc
.hier_qp_layer
[0] = ctrl
->val
;
2139 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP
:
2140 p
->codec
.hevc
.hier_qp_layer
[1] = ctrl
->val
;
2142 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP
:
2143 p
->codec
.hevc
.hier_qp_layer
[2] = ctrl
->val
;
2145 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP
:
2146 p
->codec
.hevc
.hier_qp_layer
[3] = ctrl
->val
;
2148 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP
:
2149 p
->codec
.hevc
.hier_qp_layer
[4] = ctrl
->val
;
2151 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP
:
2152 p
->codec
.hevc
.hier_qp_layer
[5] = ctrl
->val
;
2154 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP
:
2155 p
->codec
.hevc
.hier_qp_layer
[6] = ctrl
->val
;
2157 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR
:
2158 p
->codec
.hevc
.hier_bit_layer
[0] = ctrl
->val
;
2160 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR
:
2161 p
->codec
.hevc
.hier_bit_layer
[1] = ctrl
->val
;
2163 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR
:
2164 p
->codec
.hevc
.hier_bit_layer
[2] = ctrl
->val
;
2166 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR
:
2167 p
->codec
.hevc
.hier_bit_layer
[3] = ctrl
->val
;
2169 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR
:
2170 p
->codec
.hevc
.hier_bit_layer
[4] = ctrl
->val
;
2172 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR
:
2173 p
->codec
.hevc
.hier_bit_layer
[5] = ctrl
->val
;
2175 case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR
:
2176 p
->codec
.hevc
.hier_bit_layer
[6] = ctrl
->val
;
2178 case V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB
:
2179 p
->codec
.hevc
.general_pb_enable
= ctrl
->val
;
2181 case V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID
:
2182 p
->codec
.hevc
.temporal_id_enable
= ctrl
->val
;
2184 case V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING
:
2185 p
->codec
.hevc
.strong_intra_smooth
= ctrl
->val
;
2187 case V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT
:
2188 p
->codec
.hevc
.intra_pu_split_disable
= ctrl
->val
;
2190 case V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION
:
2191 p
->codec
.hevc
.tmv_prediction_disable
= !ctrl
->val
;
2193 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1
:
2194 p
->codec
.hevc
.max_num_merge_mv
= ctrl
->val
;
2196 case V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE
:
2197 p
->codec
.hevc
.encoding_nostartcode_enable
= ctrl
->val
;
2199 case V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD
:
2200 p
->codec
.hevc
.refreshperiod
= ctrl
->val
;
2202 case V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2
:
2203 p
->codec
.hevc
.lf_beta_offset_div2
= ctrl
->val
;
2205 case V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2
:
2206 p
->codec
.hevc
.lf_tc_offset_div2
= ctrl
->val
;
2208 case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD
:
2209 p
->codec
.hevc
.size_of_length_field
= ctrl
->val
;
2211 case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR
:
2212 p
->codec
.hevc
.prepend_sps_pps_to_idr
= ctrl
->val
;
2215 v4l2_err(&dev
->v4l2_dev
, "Invalid control, id=%d, val=%d\n",
2216 ctrl
->id
, ctrl
->val
);
2222 static int s5p_mfc_enc_g_v_ctrl(struct v4l2_ctrl
*ctrl
)
2224 struct s5p_mfc_ctx
*ctx
= ctrl_to_ctx(ctrl
);
2225 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2228 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT
:
2229 if (ctx
->state
>= MFCINST_HEAD_PARSED
&&
2230 ctx
->state
< MFCINST_ABORT
) {
2231 ctrl
->val
= ctx
->pb_count
;
2233 } else if (ctx
->state
!= MFCINST_INIT
) {
2234 v4l2_err(&dev
->v4l2_dev
, "Encoding not initialised\n");
2237 /* Should wait for the header to be produced */
2238 s5p_mfc_wait_for_done_ctx(ctx
,
2239 S5P_MFC_R2H_CMD_SEQ_DONE_RET
, 0);
2240 if (ctx
->state
>= MFCINST_HEAD_PARSED
&&
2241 ctx
->state
< MFCINST_ABORT
) {
2242 ctrl
->val
= ctx
->pb_count
;
2244 v4l2_err(&dev
->v4l2_dev
, "Encoding not initialised\n");
2252 static const struct v4l2_ctrl_ops s5p_mfc_enc_ctrl_ops
= {
2253 .s_ctrl
= s5p_mfc_enc_s_ctrl
,
2254 .g_volatile_ctrl
= s5p_mfc_enc_g_v_ctrl
,
2257 static int vidioc_s_parm(struct file
*file
, void *priv
,
2258 struct v4l2_streamparm
*a
)
2260 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
2262 if (a
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2263 ctx
->enc_params
.rc_framerate_num
=
2264 a
->parm
.output
.timeperframe
.denominator
;
2265 ctx
->enc_params
.rc_framerate_denom
=
2266 a
->parm
.output
.timeperframe
.numerator
;
2268 mfc_err("Setting FPS is only possible for the output queue\n");
2274 static int vidioc_g_parm(struct file
*file
, void *priv
,
2275 struct v4l2_streamparm
*a
)
2277 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
2279 if (a
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
2280 a
->parm
.output
.timeperframe
.denominator
=
2281 ctx
->enc_params
.rc_framerate_num
;
2282 a
->parm
.output
.timeperframe
.numerator
=
2283 ctx
->enc_params
.rc_framerate_denom
;
2285 mfc_err("Setting FPS is only possible for the output queue\n");
2291 static int vidioc_encoder_cmd(struct file
*file
, void *priv
,
2292 struct v4l2_encoder_cmd
*cmd
)
2294 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(priv
);
2295 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2296 struct s5p_mfc_buf
*buf
;
2297 unsigned long flags
;
2300 case V4L2_ENC_CMD_STOP
:
2301 if (cmd
->flags
!= 0)
2304 if (!ctx
->vq_src
.streaming
)
2307 spin_lock_irqsave(&dev
->irqlock
, flags
);
2308 if (list_empty(&ctx
->src_queue
)) {
2309 mfc_debug(2, "EOS: empty src queue, entering finishing state\n");
2310 ctx
->state
= MFCINST_FINISHING
;
2311 if (s5p_mfc_ctx_ready(ctx
))
2312 set_work_bit_irqsave(ctx
);
2313 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
2314 s5p_mfc_hw_call(dev
->mfc_ops
, try_run
, dev
);
2316 mfc_debug(2, "EOS: marking last buffer of stream\n");
2317 buf
= list_entry(ctx
->src_queue
.prev
,
2318 struct s5p_mfc_buf
, list
);
2319 if (buf
->flags
& MFC_BUF_FLAG_USED
)
2320 ctx
->state
= MFCINST_FINISHING
;
2322 buf
->flags
|= MFC_BUF_FLAG_EOS
;
2323 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
2333 static int vidioc_subscribe_event(struct v4l2_fh
*fh
,
2334 const struct v4l2_event_subscription
*sub
)
2336 switch (sub
->type
) {
2337 case V4L2_EVENT_EOS
:
2338 return v4l2_event_subscribe(fh
, sub
, 2, NULL
);
2344 static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops
= {
2345 .vidioc_querycap
= vidioc_querycap
,
2346 .vidioc_enum_fmt_vid_cap_mplane
= vidioc_enum_fmt_vid_cap_mplane
,
2347 .vidioc_enum_fmt_vid_out_mplane
= vidioc_enum_fmt_vid_out_mplane
,
2348 .vidioc_g_fmt_vid_cap_mplane
= vidioc_g_fmt
,
2349 .vidioc_g_fmt_vid_out_mplane
= vidioc_g_fmt
,
2350 .vidioc_try_fmt_vid_cap_mplane
= vidioc_try_fmt
,
2351 .vidioc_try_fmt_vid_out_mplane
= vidioc_try_fmt
,
2352 .vidioc_s_fmt_vid_cap_mplane
= vidioc_s_fmt
,
2353 .vidioc_s_fmt_vid_out_mplane
= vidioc_s_fmt
,
2354 .vidioc_reqbufs
= vidioc_reqbufs
,
2355 .vidioc_querybuf
= vidioc_querybuf
,
2356 .vidioc_qbuf
= vidioc_qbuf
,
2357 .vidioc_dqbuf
= vidioc_dqbuf
,
2358 .vidioc_expbuf
= vidioc_expbuf
,
2359 .vidioc_streamon
= vidioc_streamon
,
2360 .vidioc_streamoff
= vidioc_streamoff
,
2361 .vidioc_s_parm
= vidioc_s_parm
,
2362 .vidioc_g_parm
= vidioc_g_parm
,
2363 .vidioc_encoder_cmd
= vidioc_encoder_cmd
,
2364 .vidioc_subscribe_event
= vidioc_subscribe_event
,
2365 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
2368 static int check_vb_with_fmt(struct s5p_mfc_fmt
*fmt
, struct vb2_buffer
*vb
)
2374 if (fmt
->num_planes
!= vb
->num_planes
) {
2375 mfc_err("invalid plane number for the format\n");
2378 for (i
= 0; i
< fmt
->num_planes
; i
++) {
2379 dma_addr_t dma
= vb2_dma_contig_plane_dma_addr(vb
, i
);
2381 mfc_err("failed to get plane cookie\n");
2384 mfc_debug(2, "index: %d, plane[%d] cookie: %pad\n",
2385 vb
->index
, i
, &dma
);
2390 static int s5p_mfc_queue_setup(struct vb2_queue
*vq
,
2391 unsigned int *buf_count
, unsigned int *plane_count
,
2392 unsigned int psize
[], struct device
*alloc_devs
[])
2394 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(vq
->drv_priv
);
2395 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2397 if (vq
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
2398 if (ctx
->state
!= MFCINST_GOT_INST
) {
2399 mfc_err("invalid state: %d\n", ctx
->state
);
2404 *plane_count
= ctx
->dst_fmt
->num_planes
;
2406 *plane_count
= MFC_ENC_CAP_PLANE_COUNT
;
2409 if (*buf_count
> MFC_MAX_BUFFERS
)
2410 *buf_count
= MFC_MAX_BUFFERS
;
2411 psize
[0] = ctx
->enc_dst_buf_size
;
2412 alloc_devs
[0] = ctx
->dev
->mem_dev
[BANK_L_CTX
];
2413 } else if (vq
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2415 *plane_count
= ctx
->src_fmt
->num_planes
;
2417 *plane_count
= MFC_ENC_OUT_PLANE_COUNT
;
2421 if (*buf_count
> MFC_MAX_BUFFERS
)
2422 *buf_count
= MFC_MAX_BUFFERS
;
2424 psize
[0] = ctx
->luma_size
;
2425 psize
[1] = ctx
->chroma_size
;
2427 if (IS_MFCV6_PLUS(dev
)) {
2428 alloc_devs
[0] = ctx
->dev
->mem_dev
[BANK_L_CTX
];
2429 alloc_devs
[1] = ctx
->dev
->mem_dev
[BANK_L_CTX
];
2431 alloc_devs
[0] = ctx
->dev
->mem_dev
[BANK_R_CTX
];
2432 alloc_devs
[1] = ctx
->dev
->mem_dev
[BANK_R_CTX
];
2435 mfc_err("invalid queue type: %d\n", vq
->type
);
2441 static int s5p_mfc_buf_init(struct vb2_buffer
*vb
)
2443 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
2444 struct vb2_queue
*vq
= vb
->vb2_queue
;
2445 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(vq
->drv_priv
);
2449 if (vq
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
2450 ret
= check_vb_with_fmt(ctx
->dst_fmt
, vb
);
2454 ctx
->dst_bufs
[i
].b
= vbuf
;
2455 ctx
->dst_bufs
[i
].cookie
.stream
=
2456 vb2_dma_contig_plane_dma_addr(vb
, 0);
2457 ctx
->dst_bufs_cnt
++;
2458 } else if (vq
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2459 ret
= check_vb_with_fmt(ctx
->src_fmt
, vb
);
2463 ctx
->src_bufs
[i
].b
= vbuf
;
2464 ctx
->src_bufs
[i
].cookie
.raw
.luma
=
2465 vb2_dma_contig_plane_dma_addr(vb
, 0);
2466 ctx
->src_bufs
[i
].cookie
.raw
.chroma
=
2467 vb2_dma_contig_plane_dma_addr(vb
, 1);
2468 ctx
->src_bufs_cnt
++;
2470 mfc_err("invalid queue type: %d\n", vq
->type
);
2476 static int s5p_mfc_buf_prepare(struct vb2_buffer
*vb
)
2478 struct vb2_queue
*vq
= vb
->vb2_queue
;
2479 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(vq
->drv_priv
);
2482 if (vq
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
2483 ret
= check_vb_with_fmt(ctx
->dst_fmt
, vb
);
2486 mfc_debug(2, "plane size: %ld, dst size: %zu\n",
2487 vb2_plane_size(vb
, 0), ctx
->enc_dst_buf_size
);
2488 if (vb2_plane_size(vb
, 0) < ctx
->enc_dst_buf_size
) {
2489 mfc_err("plane size is too small for capture\n");
2492 } else if (vq
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2493 ret
= check_vb_with_fmt(ctx
->src_fmt
, vb
);
2496 mfc_debug(2, "plane size: %ld, luma size: %d\n",
2497 vb2_plane_size(vb
, 0), ctx
->luma_size
);
2498 mfc_debug(2, "plane size: %ld, chroma size: %d\n",
2499 vb2_plane_size(vb
, 1), ctx
->chroma_size
);
2500 if (vb2_plane_size(vb
, 0) < ctx
->luma_size
||
2501 vb2_plane_size(vb
, 1) < ctx
->chroma_size
) {
2502 mfc_err("plane size is too small for output\n");
2506 mfc_err("invalid queue type: %d\n", vq
->type
);
2512 static int s5p_mfc_start_streaming(struct vb2_queue
*q
, unsigned int count
)
2514 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(q
->drv_priv
);
2515 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2517 if (IS_MFCV6_PLUS(dev
) &&
2518 (q
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
)) {
2520 if ((ctx
->state
== MFCINST_GOT_INST
) &&
2521 (dev
->curr_ctx
== ctx
->num
) && dev
->hw_lock
) {
2522 s5p_mfc_wait_for_done_ctx(ctx
,
2523 S5P_MFC_R2H_CMD_SEQ_DONE_RET
,
2527 if (ctx
->src_bufs_cnt
< ctx
->pb_count
) {
2528 mfc_err("Need minimum %d OUTPUT buffers\n",
2534 /* If context is ready then dev = work->data;schedule it to run */
2535 if (s5p_mfc_ctx_ready(ctx
))
2536 set_work_bit_irqsave(ctx
);
2537 s5p_mfc_hw_call(dev
->mfc_ops
, try_run
, dev
);
2542 static void s5p_mfc_stop_streaming(struct vb2_queue
*q
)
2544 unsigned long flags
;
2545 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(q
->drv_priv
);
2546 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2548 if ((ctx
->state
== MFCINST_FINISHING
||
2549 ctx
->state
== MFCINST_RUNNING
) &&
2550 dev
->curr_ctx
== ctx
->num
&& dev
->hw_lock
) {
2551 ctx
->state
= MFCINST_ABORT
;
2552 s5p_mfc_wait_for_done_ctx(ctx
, S5P_MFC_R2H_CMD_FRAME_DONE_RET
,
2555 ctx
->state
= MFCINST_FINISHED
;
2556 spin_lock_irqsave(&dev
->irqlock
, flags
);
2557 if (q
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
2558 s5p_mfc_cleanup_queue(&ctx
->dst_queue
, &ctx
->vq_dst
);
2559 INIT_LIST_HEAD(&ctx
->dst_queue
);
2560 ctx
->dst_queue_cnt
= 0;
2562 if (q
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2563 cleanup_ref_queue(ctx
);
2564 s5p_mfc_cleanup_queue(&ctx
->src_queue
, &ctx
->vq_src
);
2565 INIT_LIST_HEAD(&ctx
->src_queue
);
2566 ctx
->src_queue_cnt
= 0;
2568 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
2571 static void s5p_mfc_buf_queue(struct vb2_buffer
*vb
)
2573 struct vb2_queue
*vq
= vb
->vb2_queue
;
2574 struct s5p_mfc_ctx
*ctx
= fh_to_ctx(vq
->drv_priv
);
2575 struct s5p_mfc_dev
*dev
= ctx
->dev
;
2576 unsigned long flags
;
2577 struct s5p_mfc_buf
*mfc_buf
;
2579 if (ctx
->state
== MFCINST_ERROR
) {
2580 vb2_buffer_done(vb
, VB2_BUF_STATE_ERROR
);
2581 cleanup_ref_queue(ctx
);
2584 if (vq
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
) {
2585 mfc_buf
= &ctx
->dst_bufs
[vb
->index
];
2586 mfc_buf
->flags
&= ~MFC_BUF_FLAG_USED
;
2587 /* Mark destination as available for use by MFC */
2588 spin_lock_irqsave(&dev
->irqlock
, flags
);
2589 list_add_tail(&mfc_buf
->list
, &ctx
->dst_queue
);
2590 ctx
->dst_queue_cnt
++;
2591 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
2592 } else if (vq
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
2593 mfc_buf
= &ctx
->src_bufs
[vb
->index
];
2594 mfc_buf
->flags
&= ~MFC_BUF_FLAG_USED
;
2595 spin_lock_irqsave(&dev
->irqlock
, flags
);
2596 list_add_tail(&mfc_buf
->list
, &ctx
->src_queue
);
2597 ctx
->src_queue_cnt
++;
2598 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
2600 mfc_err("unsupported buffer type (%d)\n", vq
->type
);
2602 if (s5p_mfc_ctx_ready(ctx
))
2603 set_work_bit_irqsave(ctx
);
2604 s5p_mfc_hw_call(dev
->mfc_ops
, try_run
, dev
);
2607 static struct vb2_ops s5p_mfc_enc_qops
= {
2608 .queue_setup
= s5p_mfc_queue_setup
,
2609 .wait_prepare
= vb2_ops_wait_prepare
,
2610 .wait_finish
= vb2_ops_wait_finish
,
2611 .buf_init
= s5p_mfc_buf_init
,
2612 .buf_prepare
= s5p_mfc_buf_prepare
,
2613 .start_streaming
= s5p_mfc_start_streaming
,
2614 .stop_streaming
= s5p_mfc_stop_streaming
,
2615 .buf_queue
= s5p_mfc_buf_queue
,
2618 const struct s5p_mfc_codec_ops
*get_enc_codec_ops(void)
2620 return &encoder_codec_ops
;
2623 struct vb2_ops
*get_enc_queue_ops(void)
2625 return &s5p_mfc_enc_qops
;
2628 const struct v4l2_ioctl_ops
*get_enc_v4l2_ioctl_ops(void)
2630 return &s5p_mfc_enc_ioctl_ops
;
2633 #define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2WHICH(x) == V4L2_CTRL_CLASS_MPEG) \
2634 && V4L2_CTRL_DRIVER_PRIV(x))
2636 int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx
*ctx
)
2638 struct v4l2_ctrl_config cfg
;
2641 v4l2_ctrl_handler_init(&ctx
->ctrl_handler
, NUM_CTRLS
);
2642 if (ctx
->ctrl_handler
.error
) {
2643 mfc_err("v4l2_ctrl_handler_init failed\n");
2644 return ctx
->ctrl_handler
.error
;
2646 for (i
= 0; i
< NUM_CTRLS
; i
++) {
2647 if (IS_MFC51_PRIV(controls
[i
].id
)) {
2648 memset(&cfg
, 0, sizeof(struct v4l2_ctrl_config
));
2649 cfg
.ops
= &s5p_mfc_enc_ctrl_ops
;
2650 cfg
.id
= controls
[i
].id
;
2651 cfg
.min
= controls
[i
].minimum
;
2652 cfg
.max
= controls
[i
].maximum
;
2653 cfg
.def
= controls
[i
].default_value
;
2654 cfg
.name
= controls
[i
].name
;
2655 cfg
.type
= controls
[i
].type
;
2658 if (cfg
.type
== V4L2_CTRL_TYPE_MENU
) {
2660 cfg
.menu_skip_mask
= controls
[i
].menu_skip_mask
;
2661 cfg
.qmenu
= mfc51_get_menu(cfg
.id
);
2663 cfg
.step
= controls
[i
].step
;
2664 cfg
.menu_skip_mask
= 0;
2666 ctx
->ctrls
[i
] = v4l2_ctrl_new_custom(&ctx
->ctrl_handler
,
2669 if ((controls
[i
].type
== V4L2_CTRL_TYPE_MENU
) ||
2670 (controls
[i
].type
==
2671 V4L2_CTRL_TYPE_INTEGER_MENU
)) {
2672 ctx
->ctrls
[i
] = v4l2_ctrl_new_std_menu(
2674 &s5p_mfc_enc_ctrl_ops
, controls
[i
].id
,
2675 controls
[i
].maximum
, 0,
2676 controls
[i
].default_value
);
2678 ctx
->ctrls
[i
] = v4l2_ctrl_new_std(
2680 &s5p_mfc_enc_ctrl_ops
, controls
[i
].id
,
2681 controls
[i
].minimum
,
2682 controls
[i
].maximum
, controls
[i
].step
,
2683 controls
[i
].default_value
);
2686 if (ctx
->ctrl_handler
.error
) {
2687 mfc_err("Adding control (%d) failed\n", i
);
2688 return ctx
->ctrl_handler
.error
;
2690 if (controls
[i
].is_volatile
&& ctx
->ctrls
[i
])
2691 ctx
->ctrls
[i
]->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
2693 v4l2_ctrl_handler_setup(&ctx
->ctrl_handler
);
2697 void s5p_mfc_enc_ctrls_delete(struct s5p_mfc_ctx
*ctx
)
2701 v4l2_ctrl_handler_free(&ctx
->ctrl_handler
);
2702 for (i
= 0; i
< NUM_CTRLS
; i
++)
2703 ctx
->ctrls
[i
] = NULL
;
2706 void s5p_mfc_enc_init(struct s5p_mfc_ctx
*ctx
)
2708 struct v4l2_format f
;
2709 f
.fmt
.pix_mp
.pixelformat
= DEF_SRC_FMT_ENC
;
2710 ctx
->src_fmt
= find_format(&f
, MFC_FMT_RAW
);
2711 f
.fmt
.pix_mp
.pixelformat
= DEF_DST_FMT_ENC
;
2712 ctx
->dst_fmt
= find_format(&f
, MFC_FMT_ENC
);