2 * drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
4 * Samsung MFC (Multi Function Codec - FIMV) driver
5 * This file contains hw related functions.
7 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
8 * http://www.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 version 2 as
12 * published by the Free Software Foundation.
17 #include <linux/delay.h>
20 #include <linux/jiffies.h>
21 #include <linux/firmware.h>
22 #include <linux/err.h>
23 #include <linux/sched.h>
24 #include <linux/dma-mapping.h>
26 #include <asm/cacheflush.h>
28 #include "s5p_mfc_common.h"
29 #include "s5p_mfc_cmd.h"
30 #include "s5p_mfc_intr.h"
31 #include "s5p_mfc_pm.h"
32 #include "s5p_mfc_debug.h"
33 #include "s5p_mfc_opr.h"
34 #include "s5p_mfc_opr_v6.h"
36 /* #define S5P_MFC_DEBUG_REGWRITE */
37 #ifdef S5P_MFC_DEBUG_REGWRITE
39 #define writel(v, r) \
41 pr_err("MFCWRITE(%p): %08x\n", r, (unsigned int)v); \
44 #endif /* S5P_MFC_DEBUG_REGWRITE */
46 #define READL(offset) readl(dev->regs_base + (offset))
47 #define WRITEL(data, offset) writel((data), dev->regs_base + (offset))
48 #define OFFSETA(x) (((x) - dev->port_a) >> S5P_FIMV_MEM_OFFSET)
49 #define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET)
51 /* Allocate temporary buffers for decoding */
52 static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx
*ctx
)
59 /* Release temproary buffers for decoding */
60 static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx
*ctx
)
65 /* Allocate codec buffers */
66 static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx
*ctx
)
68 struct s5p_mfc_dev
*dev
= ctx
->dev
;
69 unsigned int mb_width
, mb_height
;
72 mb_width
= MB_WIDTH(ctx
->img_width
);
73 mb_height
= MB_HEIGHT(ctx
->img_height
);
75 if (ctx
->type
== MFCINST_DECODER
) {
76 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
77 ctx
->luma_size
, ctx
->chroma_size
, ctx
->mv_size
);
78 mfc_debug(2, "Totals bufs: %d\n", ctx
->total_dpb_count
);
79 } else if (ctx
->type
== MFCINST_ENCODER
) {
80 ctx
->tmv_buffer_size
= S5P_FIMV_NUM_TMV_BUFFERS_V6
*
81 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width
, mb_height
),
82 S5P_FIMV_TMV_BUFFER_ALIGN_V6
);
84 ctx
->luma_dpb_size
= ALIGN((mb_width
* mb_height
) *
85 S5P_FIMV_LUMA_MB_TO_PIXEL_V6
,
86 S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6
);
87 ctx
->chroma_dpb_size
= ALIGN((mb_width
* mb_height
) *
88 S5P_FIMV_CHROMA_MB_TO_PIXEL_V6
,
89 S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6
);
90 ctx
->me_buffer_size
= ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
91 ctx
->img_width
, ctx
->img_height
,
93 S5P_FIMV_ME_BUFFER_ALIGN_V6
);
95 mfc_debug(2, "recon luma size: %d chroma size: %d\n",
96 ctx
->luma_dpb_size
, ctx
->chroma_dpb_size
);
101 /* Codecs have different memory requirements */
102 switch (ctx
->codec_mode
) {
103 case S5P_MFC_CODEC_H264_DEC
:
104 case S5P_MFC_CODEC_H264_MVC_DEC
:
105 ctx
->scratch_buf_size
=
106 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
109 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
110 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
112 ctx
->scratch_buf_size
+
113 (ctx
->mv_count
* ctx
->mv_size
);
115 case S5P_MFC_CODEC_MPEG4_DEC
:
117 ctx
->scratch_buf_size
=
118 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
122 ctx
->scratch_buf_size
=
123 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
128 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
129 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
130 ctx
->bank1
.size
= ctx
->scratch_buf_size
;
132 case S5P_MFC_CODEC_VC1RCV_DEC
:
133 case S5P_MFC_CODEC_VC1_DEC
:
134 ctx
->scratch_buf_size
=
135 S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
138 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
139 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
140 ctx
->bank1
.size
= ctx
->scratch_buf_size
;
142 case S5P_MFC_CODEC_MPEG2_DEC
:
146 case S5P_MFC_CODEC_H263_DEC
:
147 ctx
->scratch_buf_size
=
148 S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
151 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
152 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
153 ctx
->bank1
.size
= ctx
->scratch_buf_size
;
155 case S5P_MFC_CODEC_VP8_DEC
:
156 ctx
->scratch_buf_size
=
157 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
160 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
161 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
162 ctx
->bank1
.size
= ctx
->scratch_buf_size
;
164 case S5P_MFC_CODEC_H264_ENC
:
165 ctx
->scratch_buf_size
=
166 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
169 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
170 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
172 ctx
->scratch_buf_size
+ ctx
->tmv_buffer_size
+
173 (ctx
->pb_count
* (ctx
->luma_dpb_size
+
174 ctx
->chroma_dpb_size
+ ctx
->me_buffer_size
));
177 case S5P_MFC_CODEC_MPEG4_ENC
:
178 case S5P_MFC_CODEC_H263_ENC
:
179 ctx
->scratch_buf_size
=
180 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
183 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
184 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
186 ctx
->scratch_buf_size
+ ctx
->tmv_buffer_size
+
187 (ctx
->pb_count
* (ctx
->luma_dpb_size
+
188 ctx
->chroma_dpb_size
+ ctx
->me_buffer_size
));
191 case S5P_MFC_CODEC_VP8_ENC
:
192 ctx
->scratch_buf_size
=
193 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
196 ctx
->scratch_buf_size
= ALIGN(ctx
->scratch_buf_size
,
197 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6
);
199 ctx
->scratch_buf_size
+ ctx
->tmv_buffer_size
+
200 (ctx
->pb_count
* (ctx
->luma_dpb_size
+
201 ctx
->chroma_dpb_size
+ ctx
->me_buffer_size
));
208 /* Allocate only if memory from bank 1 is necessary */
209 if (ctx
->bank1
.size
> 0) {
210 ret
= s5p_mfc_alloc_priv_buf(dev
->mem_dev_l
, &ctx
->bank1
);
212 mfc_err("Failed to allocate Bank1 memory\n");
215 BUG_ON(ctx
->bank1
.dma
& ((1 << MFC_BANK1_ALIGN_ORDER
) - 1));
220 /* Release buffers allocated for codec */
221 static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx
*ctx
)
223 s5p_mfc_release_priv_buf(ctx
->dev
->mem_dev_l
, &ctx
->bank1
);
226 /* Allocate memory for instance data buffer */
227 static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx
*ctx
)
229 struct s5p_mfc_dev
*dev
= ctx
->dev
;
230 struct s5p_mfc_buf_size_v6
*buf_size
= dev
->variant
->buf_size
->priv
;
235 switch (ctx
->codec_mode
) {
236 case S5P_MFC_CODEC_H264_DEC
:
237 case S5P_MFC_CODEC_H264_MVC_DEC
:
238 ctx
->ctx
.size
= buf_size
->h264_dec_ctx
;
240 case S5P_MFC_CODEC_MPEG4_DEC
:
241 case S5P_MFC_CODEC_H263_DEC
:
242 case S5P_MFC_CODEC_VC1RCV_DEC
:
243 case S5P_MFC_CODEC_VC1_DEC
:
244 case S5P_MFC_CODEC_MPEG2_DEC
:
245 case S5P_MFC_CODEC_VP8_DEC
:
246 ctx
->ctx
.size
= buf_size
->other_dec_ctx
;
248 case S5P_MFC_CODEC_H264_ENC
:
249 ctx
->ctx
.size
= buf_size
->h264_enc_ctx
;
251 case S5P_MFC_CODEC_MPEG4_ENC
:
252 case S5P_MFC_CODEC_H263_ENC
:
253 case S5P_MFC_CODEC_VP8_ENC
:
254 ctx
->ctx
.size
= buf_size
->other_enc_ctx
;
258 mfc_err("Codec type(%d) should be checked!\n", ctx
->codec_mode
);
262 ret
= s5p_mfc_alloc_priv_buf(dev
->mem_dev_l
, &ctx
->ctx
);
264 mfc_err("Failed to allocate instance buffer\n");
268 memset(ctx
->ctx
.virt
, 0, ctx
->ctx
.size
);
276 /* Release instance buffer */
277 static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx
*ctx
)
279 s5p_mfc_release_priv_buf(ctx
->dev
->mem_dev_l
, &ctx
->ctx
);
282 /* Allocate context buffers for SYS_INIT */
283 static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev
*dev
)
285 struct s5p_mfc_buf_size_v6
*buf_size
= dev
->variant
->buf_size
->priv
;
290 dev
->ctx_buf
.size
= buf_size
->dev_ctx
;
291 ret
= s5p_mfc_alloc_priv_buf(dev
->mem_dev_l
, &dev
->ctx_buf
);
293 mfc_err("Failed to allocate device context buffer\n");
297 memset(dev
->ctx_buf
.virt
, 0, buf_size
->dev_ctx
);
305 /* Release context buffers for SYS_INIT */
306 static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev
*dev
)
308 s5p_mfc_release_priv_buf(dev
->mem_dev_l
, &dev
->ctx_buf
);
311 static int calc_plane(int width
, int height
)
315 mbX
= DIV_ROUND_UP(width
, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6
);
316 mbY
= DIV_ROUND_UP(height
, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6
);
318 if (width
* height
< S5P_FIMV_MAX_FRAME_SIZE_V6
)
319 mbY
= (mbY
+ 1) / 2 * 2;
321 return (mbX
* S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6
) *
322 (mbY
* S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6
);
325 static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx
*ctx
)
327 ctx
->buf_width
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN_V6
);
328 ctx
->buf_height
= ALIGN(ctx
->img_height
, S5P_FIMV_NV12MT_VALIGN_V6
);
329 mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
330 "buffer dimensions: %dx%d\n", ctx
->img_width
,
331 ctx
->img_height
, ctx
->buf_width
, ctx
->buf_height
);
333 ctx
->luma_size
= calc_plane(ctx
->img_width
, ctx
->img_height
);
334 ctx
->chroma_size
= calc_plane(ctx
->img_width
, (ctx
->img_height
>> 1));
335 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
||
336 ctx
->codec_mode
== S5P_MFC_CODEC_H264_MVC_DEC
) {
337 ctx
->mv_size
= S5P_MFC_DEC_MV_SIZE_V6(ctx
->img_width
,
339 ctx
->mv_size
= ALIGN(ctx
->mv_size
, 16);
345 static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx
*ctx
)
347 unsigned int mb_width
, mb_height
;
349 mb_width
= MB_WIDTH(ctx
->img_width
);
350 mb_height
= MB_HEIGHT(ctx
->img_height
);
352 ctx
->buf_width
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12M_HALIGN_V6
);
353 ctx
->luma_size
= ALIGN((mb_width
* mb_height
) * 256, 256);
354 ctx
->chroma_size
= ALIGN((mb_width
* mb_height
) * 128, 256);
356 /* MFCv7 needs pad bytes for Luma and Chroma */
357 if (IS_MFCV7(ctx
->dev
)) {
358 ctx
->luma_size
+= MFC_LUMA_PAD_BYTES_V7
;
359 ctx
->chroma_size
+= MFC_CHROMA_PAD_BYTES_V7
;
363 /* Set registers for decoding stream buffer */
364 static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx
*ctx
,
365 int buf_addr
, unsigned int start_num_byte
,
366 unsigned int strm_size
)
368 struct s5p_mfc_dev
*dev
= ctx
->dev
;
369 struct s5p_mfc_buf_size
*buf_size
= dev
->variant
->buf_size
;
372 mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
373 "buf_size: 0x%08x (%d)\n",
374 ctx
->inst_no
, buf_addr
, strm_size
, strm_size
);
375 WRITEL(strm_size
, S5P_FIMV_D_STREAM_DATA_SIZE_V6
);
376 WRITEL(buf_addr
, S5P_FIMV_D_CPB_BUFFER_ADDR_V6
);
377 WRITEL(buf_size
->cpb
, S5P_FIMV_D_CPB_BUFFER_SIZE_V6
);
378 WRITEL(start_num_byte
, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6
);
384 /* Set decoding frame buffer */
385 static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx
*ctx
)
387 unsigned int frame_size
, i
;
388 unsigned int frame_size_ch
, frame_size_mv
;
389 struct s5p_mfc_dev
*dev
= ctx
->dev
;
394 buf_addr1
= ctx
->bank1
.dma
;
395 buf_size1
= ctx
->bank1
.size
;
397 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1
, buf_size1
);
398 mfc_debug(2, "Total DPB COUNT: %d\n", ctx
->total_dpb_count
);
399 mfc_debug(2, "Setting display delay to %d\n", ctx
->display_delay
);
401 WRITEL(ctx
->total_dpb_count
, S5P_FIMV_D_NUM_DPB_V6
);
402 WRITEL(ctx
->luma_size
, S5P_FIMV_D_LUMA_DPB_SIZE_V6
);
403 WRITEL(ctx
->chroma_size
, S5P_FIMV_D_CHROMA_DPB_SIZE_V6
);
405 WRITEL(buf_addr1
, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6
);
406 WRITEL(ctx
->scratch_buf_size
, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6
);
407 buf_addr1
+= ctx
->scratch_buf_size
;
408 buf_size1
-= ctx
->scratch_buf_size
;
410 if (ctx
->codec_mode
== S5P_FIMV_CODEC_H264_DEC
||
411 ctx
->codec_mode
== S5P_FIMV_CODEC_H264_MVC_DEC
){
412 WRITEL(ctx
->mv_size
, S5P_FIMV_D_MV_BUFFER_SIZE_V6
);
413 WRITEL(ctx
->mv_count
, S5P_FIMV_D_NUM_MV_V6
);
416 frame_size
= ctx
->luma_size
;
417 frame_size_ch
= ctx
->chroma_size
;
418 frame_size_mv
= ctx
->mv_size
;
419 mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
420 frame_size
, frame_size_ch
, frame_size_mv
);
422 for (i
= 0; i
< ctx
->total_dpb_count
; i
++) {
424 mfc_debug(2, "Luma %d: %x\n", i
,
425 ctx
->dst_bufs
[i
].cookie
.raw
.luma
);
426 WRITEL(ctx
->dst_bufs
[i
].cookie
.raw
.luma
,
427 S5P_FIMV_D_LUMA_DPB_V6
+ i
* 4);
428 mfc_debug(2, "\tChroma %d: %x\n", i
,
429 ctx
->dst_bufs
[i
].cookie
.raw
.chroma
);
430 WRITEL(ctx
->dst_bufs
[i
].cookie
.raw
.chroma
,
431 S5P_FIMV_D_CHROMA_DPB_V6
+ i
* 4);
433 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
||
434 ctx
->codec_mode
== S5P_MFC_CODEC_H264_MVC_DEC
) {
435 for (i
= 0; i
< ctx
->mv_count
; i
++) {
436 /* To test alignment */
437 align_gap
= buf_addr1
;
438 buf_addr1
= ALIGN(buf_addr1
, 16);
439 align_gap
= buf_addr1
- align_gap
;
440 buf_size1
-= align_gap
;
442 mfc_debug(2, "\tBuf1: %x, size: %d\n",
443 buf_addr1
, buf_size1
);
444 WRITEL(buf_addr1
, S5P_FIMV_D_MV_BUFFER_V6
+ i
* 4);
445 buf_addr1
+= frame_size_mv
;
446 buf_size1
-= frame_size_mv
;
450 mfc_debug(2, "Buf1: %u, buf_size1: %d (frames %d)\n",
451 buf_addr1
, buf_size1
, ctx
->total_dpb_count
);
453 mfc_debug(2, "Not enough memory has been allocated.\n");
457 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
458 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
459 S5P_FIMV_CH_INIT_BUFS_V6
, NULL
);
461 mfc_debug(2, "After setting buffers.\n");
465 /* Set registers for encoding stream buffer */
466 static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx
*ctx
,
467 unsigned long addr
, unsigned int size
)
469 struct s5p_mfc_dev
*dev
= ctx
->dev
;
471 WRITEL(addr
, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6
); /* 16B align */
472 WRITEL(size
, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6
);
474 mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d\n",
480 static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx
*ctx
,
481 unsigned long y_addr
, unsigned long c_addr
)
483 struct s5p_mfc_dev
*dev
= ctx
->dev
;
486 WRITEL(y_addr
, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7
);
487 WRITEL(c_addr
, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7
);
489 WRITEL(y_addr
, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6
);
490 WRITEL(c_addr
, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6
);
493 mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr
);
494 mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr
);
497 static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx
*ctx
,
498 unsigned long *y_addr
, unsigned long *c_addr
)
500 struct s5p_mfc_dev
*dev
= ctx
->dev
;
501 unsigned long enc_recon_y_addr
, enc_recon_c_addr
;
504 *y_addr
= READL(S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7
);
505 *c_addr
= READL(S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7
);
507 *y_addr
= READL(S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6
);
508 *c_addr
= READL(S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6
);
511 enc_recon_y_addr
= READL(S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6
);
512 enc_recon_c_addr
= READL(S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6
);
514 mfc_debug(2, "recon y addr: 0x%08lx\n", enc_recon_y_addr
);
515 mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr
);
518 /* Set encoding ref & codec buffer */
519 static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx
*ctx
)
521 struct s5p_mfc_dev
*dev
= ctx
->dev
;
527 buf_addr1
= ctx
->bank1
.dma
;
528 buf_size1
= ctx
->bank1
.size
;
530 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1
, buf_size1
);
532 for (i
= 0; i
< ctx
->pb_count
; i
++) {
533 WRITEL(buf_addr1
, S5P_FIMV_E_LUMA_DPB_V6
+ (4 * i
));
534 buf_addr1
+= ctx
->luma_dpb_size
;
535 WRITEL(buf_addr1
, S5P_FIMV_E_CHROMA_DPB_V6
+ (4 * i
));
536 buf_addr1
+= ctx
->chroma_dpb_size
;
537 WRITEL(buf_addr1
, S5P_FIMV_E_ME_BUFFER_V6
+ (4 * i
));
538 buf_addr1
+= ctx
->me_buffer_size
;
539 buf_size1
-= (ctx
->luma_dpb_size
+ ctx
->chroma_dpb_size
+
540 ctx
->me_buffer_size
);
543 WRITEL(buf_addr1
, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6
);
544 WRITEL(ctx
->scratch_buf_size
, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6
);
545 buf_addr1
+= ctx
->scratch_buf_size
;
546 buf_size1
-= ctx
->scratch_buf_size
;
548 WRITEL(buf_addr1
, S5P_FIMV_E_TMV_BUFFER0_V6
);
549 buf_addr1
+= ctx
->tmv_buffer_size
>> 1;
550 WRITEL(buf_addr1
, S5P_FIMV_E_TMV_BUFFER1_V6
);
551 buf_addr1
+= ctx
->tmv_buffer_size
>> 1;
552 buf_size1
-= ctx
->tmv_buffer_size
;
554 mfc_debug(2, "Buf1: %u, buf_size1: %d (ref frames %d)\n",
555 buf_addr1
, buf_size1
, ctx
->pb_count
);
557 mfc_debug(2, "Not enough memory has been allocated.\n");
561 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
562 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
563 S5P_FIMV_CH_INIT_BUFS_V6
, NULL
);
570 static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx
*ctx
)
572 struct s5p_mfc_dev
*dev
= ctx
->dev
;
574 /* multi-slice control */
575 /* multi-slice MB number or bit size */
576 WRITEL(ctx
->slice_mode
, S5P_FIMV_E_MSLICE_MODE_V6
);
577 if (ctx
->slice_mode
== V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB
) {
578 WRITEL(ctx
->slice_size
.mb
, S5P_FIMV_E_MSLICE_SIZE_MB_V6
);
579 } else if (ctx
->slice_mode
==
580 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES
) {
581 WRITEL(ctx
->slice_size
.bits
, S5P_FIMV_E_MSLICE_SIZE_BITS_V6
);
583 WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_MB_V6
);
584 WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_BITS_V6
);
590 static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx
*ctx
)
592 struct s5p_mfc_dev
*dev
= ctx
->dev
;
593 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
594 unsigned int reg
= 0;
599 WRITEL(ctx
->img_width
, S5P_FIMV_E_FRAME_WIDTH_V6
); /* 16 align */
601 WRITEL(ctx
->img_height
, S5P_FIMV_E_FRAME_HEIGHT_V6
); /* 16 align */
604 WRITEL(ctx
->img_width
, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6
);
606 WRITEL(ctx
->img_height
, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6
);
608 WRITEL(0x0, S5P_FIMV_E_FRAME_CROP_OFFSET_V6
);
610 /* pictype : IDR period */
612 reg
|= p
->gop_size
& 0xFFFF;
613 WRITEL(reg
, S5P_FIMV_E_GOP_CONFIG_V6
);
615 /* multi-slice control */
616 /* multi-slice MB number or bit size */
617 ctx
->slice_mode
= p
->slice_mode
;
619 if (p
->slice_mode
== V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB
) {
621 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
622 ctx
->slice_size
.mb
= p
->slice_mb
;
623 } else if (p
->slice_mode
== V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES
) {
625 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
626 ctx
->slice_size
.bits
= p
->slice_bit
;
629 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
632 s5p_mfc_set_slice_mode(ctx
);
634 /* cyclic intra refresh */
635 WRITEL(p
->intra_refresh_mb
, S5P_FIMV_E_IR_SIZE_V6
);
636 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
637 if (p
->intra_refresh_mb
== 0)
641 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
643 /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
644 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
646 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
648 /* memory structure cur. frame */
649 if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12M
) {
650 /* 0: Linear, 1: 2D tiled*/
651 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
653 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
654 /* 0: NV12(CbCr), 1: NV21(CrCb) */
655 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6
);
656 } else if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV21M
) {
657 /* 0: Linear, 1: 2D tiled*/
658 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
660 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
661 /* 0: NV12(CbCr), 1: NV21(CrCb) */
662 WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6
);
663 } else if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12MT_16X16
) {
664 /* 0: Linear, 1: 2D tiled*/
665 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
667 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
668 /* 0: NV12(CbCr), 1: NV21(CrCb) */
669 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6
);
672 /* memory structure recon. frame */
673 /* 0: Linear, 1: 2D tiled */
674 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
676 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
678 /* padding control & value */
679 WRITEL(0x0, S5P_FIMV_E_PADDING_CTRL_V6
);
685 reg
|= ((p
->pad_cr
& 0xFF) << 16);
687 reg
|= ((p
->pad_cb
& 0xFF) << 8);
689 reg
|= p
->pad_luma
& 0xFF;
690 WRITEL(reg
, S5P_FIMV_E_PADDING_CTRL_V6
);
693 /* rate control config. */
695 /* frame-level rate control */
696 reg
|= ((p
->rc_frame
& 0x1) << 9);
697 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
701 WRITEL(p
->rc_bitrate
,
702 S5P_FIMV_E_RC_BIT_RATE_V6
);
704 WRITEL(1, S5P_FIMV_E_RC_BIT_RATE_V6
);
706 /* reaction coefficient */
708 if (p
->rc_reaction_coeff
< TIGHT_CBR_MAX
) /* tight CBR */
709 WRITEL(1, S5P_FIMV_E_RC_RPARAM_V6
);
711 WRITEL(2, S5P_FIMV_E_RC_RPARAM_V6
);
714 /* seq header ctrl */
715 reg
= READL(S5P_FIMV_E_ENC_OPTIONS_V6
);
717 reg
|= ((p
->seq_hdr_mode
& 0x1) << 2);
719 /* frame skip mode */
721 reg
|= (p
->frame_skip_mode
& 0x3);
722 WRITEL(reg
, S5P_FIMV_E_ENC_OPTIONS_V6
);
724 /* 'DROP_CONTROL_ENABLE', disable */
725 reg
= READL(S5P_FIMV_E_RC_CONFIG_V6
);
727 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
729 /* setting for MV range [16, 256] */
730 reg
= (p
->mv_h_range
& S5P_FIMV_E_MV_RANGE_V6_MASK
);
731 WRITEL(reg
, S5P_FIMV_E_MV_HOR_RANGE_V6
);
733 reg
= (p
->mv_v_range
& S5P_FIMV_E_MV_RANGE_V6_MASK
);
734 WRITEL(reg
, S5P_FIMV_E_MV_VER_RANGE_V6
);
736 WRITEL(0x0, S5P_FIMV_E_FRAME_INSERTION_V6
);
737 WRITEL(0x0, S5P_FIMV_E_ROI_BUFFER_ADDR_V6
);
738 WRITEL(0x0, S5P_FIMV_E_PARAM_CHANGE_V6
);
739 WRITEL(0x0, S5P_FIMV_E_RC_ROI_CTRL_V6
);
740 WRITEL(0x0, S5P_FIMV_E_PICTURE_TAG_V6
);
742 WRITEL(0x0, S5P_FIMV_E_BIT_COUNT_ENABLE_V6
);
743 WRITEL(0x0, S5P_FIMV_E_MAX_BIT_COUNT_V6
);
744 WRITEL(0x0, S5P_FIMV_E_MIN_BIT_COUNT_V6
);
746 WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6
);
747 WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6
);
754 static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx
*ctx
)
756 struct s5p_mfc_dev
*dev
= ctx
->dev
;
757 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
758 struct s5p_mfc_h264_enc_params
*p_h264
= &p
->codec
.h264
;
759 unsigned int reg
= 0;
764 s5p_mfc_set_enc_params(ctx
);
766 /* pictype : number of B */
767 reg
= READL(S5P_FIMV_E_GOP_CONFIG_V6
);
769 reg
|= ((p
->num_b_frame
& 0x3) << 16);
770 WRITEL(reg
, S5P_FIMV_E_GOP_CONFIG_V6
);
772 /* profile & level */
775 reg
|= ((p_h264
->level
& 0xFF) << 8);
776 /** profile - 0 ~ 3 */
777 reg
|= p_h264
->profile
& 0x3F;
778 WRITEL(reg
, S5P_FIMV_E_PICTURE_PROFILE_V6
);
780 /* rate control config. */
781 reg
= READL(S5P_FIMV_E_RC_CONFIG_V6
);
782 /** macroblock level rate control */
784 reg
|= ((p
->rc_mb
& 0x1) << 8);
785 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
788 reg
|= p_h264
->rc_frame_qp
& 0x3F;
789 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
791 /* max & min value of QP */
794 reg
|= ((p_h264
->rc_max_qp
& 0x3F) << 8);
796 reg
|= p_h264
->rc_min_qp
& 0x3F;
797 WRITEL(reg
, S5P_FIMV_E_RC_QP_BOUND_V6
);
800 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
801 if (!p
->rc_frame
&& !p
->rc_mb
) {
803 reg
|= ((p_h264
->rc_b_frame_qp
& 0x3F) << 16);
804 reg
|= ((p_h264
->rc_p_frame_qp
& 0x3F) << 8);
805 reg
|= p_h264
->rc_frame_qp
& 0x3F;
806 WRITEL(reg
, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
810 if (p
->rc_frame
&& p
->rc_framerate_num
&& p
->rc_framerate_denom
) {
812 reg
|= ((p
->rc_framerate_num
& 0xFFFF) << 16);
813 reg
|= p
->rc_framerate_denom
& 0xFFFF;
814 WRITEL(reg
, S5P_FIMV_E_RC_FRAME_RATE_V6
);
817 /* vbv buffer size */
818 if (p
->frame_skip_mode
==
819 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
820 WRITEL(p_h264
->cpb_size
& 0xFFFF,
821 S5P_FIMV_E_VBV_BUFFER_SIZE_V6
);
824 WRITEL(p
->vbv_delay
, S5P_FIMV_E_VBV_INIT_DELAY_V6
);
829 reg
|= ((p_h264
->interlace
& 0x1) << 3);
830 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
833 if (p_h264
->interlace
) {
834 WRITEL(ctx
->img_height
>> 1,
835 S5P_FIMV_E_FRAME_HEIGHT_V6
); /* 32 align */
837 WRITEL(ctx
->img_height
>> 1,
838 S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6
);
841 /* loop filter ctrl */
842 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
844 reg
|= ((p_h264
->loop_filter_mode
& 0x3) << 1);
845 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
847 /* loopfilter alpha offset */
848 if (p_h264
->loop_filter_alpha
< 0) {
850 reg
|= (0xFF - p_h264
->loop_filter_alpha
) + 1;
853 reg
|= (p_h264
->loop_filter_alpha
& 0xF);
855 WRITEL(reg
, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6
);
857 /* loopfilter beta offset */
858 if (p_h264
->loop_filter_beta
< 0) {
860 reg
|= (0xFF - p_h264
->loop_filter_beta
) + 1;
863 reg
|= (p_h264
->loop_filter_beta
& 0xF);
865 WRITEL(reg
, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6
);
867 /* entropy coding mode */
868 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
870 reg
|= p_h264
->entropy_mode
& 0x1;
871 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
873 /* number of ref. picture */
874 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
876 reg
|= (((p_h264
->num_ref_pic_4p
- 1) & 0x1) << 7);
877 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
879 /* 8x8 transform enable */
880 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
882 reg
|= ((p_h264
->_8x8_transform
& 0x3) << 12);
883 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
885 /* macroblock adaptive scaling features */
886 WRITEL(0x0, S5P_FIMV_E_MB_RC_CONFIG_V6
);
890 reg
|= ((p_h264
->rc_mb_dark
& 0x1) << 3);
892 reg
|= ((p_h264
->rc_mb_smooth
& 0x1) << 2);
894 reg
|= ((p_h264
->rc_mb_static
& 0x1) << 1);
895 /** high activity region */
896 reg
|= p_h264
->rc_mb_activity
& 0x1;
897 WRITEL(reg
, S5P_FIMV_E_MB_RC_CONFIG_V6
);
900 /* aspect ratio VUI */
901 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
903 reg
|= ((p_h264
->vui_sar
& 0x1) << 5);
904 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
906 WRITEL(0x0, S5P_FIMV_E_ASPECT_RATIO_V6
);
907 WRITEL(0x0, S5P_FIMV_E_EXTENDED_SAR_V6
);
908 if (p_h264
->vui_sar
) {
909 /* aspect ration IDC */
911 reg
|= p_h264
->vui_sar_idc
& 0xFF;
912 WRITEL(reg
, S5P_FIMV_E_ASPECT_RATIO_V6
);
913 if (p_h264
->vui_sar_idc
== 0xFF) {
916 reg
|= (p_h264
->vui_ext_sar_width
& 0xFFFF) << 16;
917 reg
|= p_h264
->vui_ext_sar_height
& 0xFFFF;
918 WRITEL(reg
, S5P_FIMV_E_EXTENDED_SAR_V6
);
922 /* intra picture period for H.264 open GOP */
924 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
926 reg
|= ((p_h264
->open_gop
& 0x1) << 4);
927 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
929 WRITEL(0x0, S5P_FIMV_E_H264_I_PERIOD_V6
);
930 if (p_h264
->open_gop
) {
932 reg
|= p_h264
->open_gop_size
& 0xFFFF;
933 WRITEL(reg
, S5P_FIMV_E_H264_I_PERIOD_V6
);
936 /* 'WEIGHTED_BI_PREDICTION' for B is disable */
937 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
939 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
941 /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
942 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
944 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
947 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
949 reg
|= ((p_h264
->aso
& 0x1) << 6);
950 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
953 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
955 reg
|= ((p_h264
->open_gop
& 0x1) << 8);
956 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
958 if (p_h264
->hier_qp
&& p_h264
->hier_qp_layer
) {
959 reg
|= (p_h264
->hier_qp_type
& 0x1) << 0x3;
960 reg
|= p_h264
->hier_qp_layer
& 0x7;
961 WRITEL(reg
, S5P_FIMV_E_H264_NUM_T_LAYER_V6
);
962 /* QP value for each layer */
963 for (i
= 0; i
< (p_h264
->hier_qp_layer
& 0x7); i
++)
964 WRITEL(p_h264
->hier_qp_layer_qp
[i
],
965 S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6
+
968 /* number of coding layer should be zero when hierarchical is disable */
969 WRITEL(reg
, S5P_FIMV_E_H264_NUM_T_LAYER_V6
);
971 /* frame packing SEI generation */
972 reg
= READL(S5P_FIMV_E_H264_OPTIONS_V6
);
974 reg
|= ((p_h264
->sei_frame_packing
& 0x1) << 25);
975 WRITEL(reg
, S5P_FIMV_E_H264_OPTIONS_V6
);
976 if (p_h264
->sei_frame_packing
) {
978 /** current frame0 flag */
979 reg
|= ((p_h264
->sei_fp_curr_frame_0
& 0x1) << 2);
980 /** arrangement type */
981 reg
|= p_h264
->sei_fp_arrangement_type
& 0x3;
982 WRITEL(reg
, S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6
);
986 switch (p_h264
->fmo_map_type
) {
987 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES
:
988 if (p_h264
->fmo_slice_grp
> 4)
989 p_h264
->fmo_slice_grp
= 4;
990 for (i
= 0; i
< (p_h264
->fmo_slice_grp
& 0xF); i
++)
991 WRITEL(p_h264
->fmo_run_len
[i
] - 1,
992 S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6
+
995 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES
:
996 if (p_h264
->fmo_slice_grp
> 4)
997 p_h264
->fmo_slice_grp
= 4;
999 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN
:
1000 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN
:
1001 if (p_h264
->fmo_slice_grp
> 2)
1002 p_h264
->fmo_slice_grp
= 2;
1003 WRITEL(p_h264
->fmo_chg_dir
& 0x1,
1004 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6
);
1005 /* the valid range is 0 ~ number of macroblocks -1 */
1006 WRITEL(p_h264
->fmo_chg_rate
,
1007 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6
);
1010 mfc_err("Unsupported map type for FMO: %d\n",
1011 p_h264
->fmo_map_type
);
1012 p_h264
->fmo_map_type
= 0;
1013 p_h264
->fmo_slice_grp
= 1;
1017 WRITEL(p_h264
->fmo_map_type
,
1018 S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6
);
1019 WRITEL(p_h264
->fmo_slice_grp
- 1,
1020 S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6
);
1022 WRITEL(0, S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6
);
1030 static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx
*ctx
)
1032 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1033 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1034 struct s5p_mfc_mpeg4_enc_params
*p_mpeg4
= &p
->codec
.mpeg4
;
1035 unsigned int reg
= 0;
1039 s5p_mfc_set_enc_params(ctx
);
1041 /* pictype : number of B */
1042 reg
= READL(S5P_FIMV_E_GOP_CONFIG_V6
);
1043 reg
&= ~(0x3 << 16);
1044 reg
|= ((p
->num_b_frame
& 0x3) << 16);
1045 WRITEL(reg
, S5P_FIMV_E_GOP_CONFIG_V6
);
1047 /* profile & level */
1050 reg
|= ((p_mpeg4
->level
& 0xFF) << 8);
1051 /** profile - 0 ~ 1 */
1052 reg
|= p_mpeg4
->profile
& 0x3F;
1053 WRITEL(reg
, S5P_FIMV_E_PICTURE_PROFILE_V6
);
1055 /* rate control config. */
1056 reg
= READL(S5P_FIMV_E_RC_CONFIG_V6
);
1057 /** macroblock level rate control */
1059 reg
|= ((p
->rc_mb
& 0x1) << 8);
1060 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1063 reg
|= p_mpeg4
->rc_frame_qp
& 0x3F;
1064 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1066 /* max & min value of QP */
1069 reg
|= ((p_mpeg4
->rc_max_qp
& 0x3F) << 8);
1071 reg
|= p_mpeg4
->rc_min_qp
& 0x3F;
1072 WRITEL(reg
, S5P_FIMV_E_RC_QP_BOUND_V6
);
1075 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1076 if (!p
->rc_frame
&& !p
->rc_mb
) {
1078 reg
|= ((p_mpeg4
->rc_b_frame_qp
& 0x3F) << 16);
1079 reg
|= ((p_mpeg4
->rc_p_frame_qp
& 0x3F) << 8);
1080 reg
|= p_mpeg4
->rc_frame_qp
& 0x3F;
1081 WRITEL(reg
, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1085 if (p
->rc_frame
&& p
->rc_framerate_num
&& p
->rc_framerate_denom
) {
1087 reg
|= ((p
->rc_framerate_num
& 0xFFFF) << 16);
1088 reg
|= p
->rc_framerate_denom
& 0xFFFF;
1089 WRITEL(reg
, S5P_FIMV_E_RC_FRAME_RATE_V6
);
1092 /* vbv buffer size */
1093 if (p
->frame_skip_mode
==
1094 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
1095 WRITEL(p
->vbv_size
& 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6
);
1098 WRITEL(p
->vbv_delay
, S5P_FIMV_E_VBV_INIT_DELAY_V6
);
1102 WRITEL(0x0, S5P_FIMV_E_MPEG4_OPTIONS_V6
);
1103 WRITEL(0x0, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6
);
1110 static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx
*ctx
)
1112 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1113 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1114 struct s5p_mfc_mpeg4_enc_params
*p_h263
= &p
->codec
.mpeg4
;
1115 unsigned int reg
= 0;
1119 s5p_mfc_set_enc_params(ctx
);
1121 /* profile & level */
1125 WRITEL(reg
, S5P_FIMV_E_PICTURE_PROFILE_V6
);
1127 /* rate control config. */
1128 reg
= READL(S5P_FIMV_E_RC_CONFIG_V6
);
1129 /** macroblock level rate control */
1131 reg
|= ((p
->rc_mb
& 0x1) << 8);
1132 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1135 reg
|= p_h263
->rc_frame_qp
& 0x3F;
1136 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1138 /* max & min value of QP */
1141 reg
|= ((p_h263
->rc_max_qp
& 0x3F) << 8);
1143 reg
|= p_h263
->rc_min_qp
& 0x3F;
1144 WRITEL(reg
, S5P_FIMV_E_RC_QP_BOUND_V6
);
1147 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1148 if (!p
->rc_frame
&& !p
->rc_mb
) {
1150 reg
|= ((p_h263
->rc_b_frame_qp
& 0x3F) << 16);
1151 reg
|= ((p_h263
->rc_p_frame_qp
& 0x3F) << 8);
1152 reg
|= p_h263
->rc_frame_qp
& 0x3F;
1153 WRITEL(reg
, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1157 if (p
->rc_frame
&& p
->rc_framerate_num
&& p
->rc_framerate_denom
) {
1159 reg
|= ((p
->rc_framerate_num
& 0xFFFF) << 16);
1160 reg
|= p
->rc_framerate_denom
& 0xFFFF;
1161 WRITEL(reg
, S5P_FIMV_E_RC_FRAME_RATE_V6
);
1164 /* vbv buffer size */
1165 if (p
->frame_skip_mode
==
1166 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
1167 WRITEL(p
->vbv_size
& 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6
);
1170 WRITEL(p
->vbv_delay
, S5P_FIMV_E_VBV_INIT_DELAY_V6
);
1178 static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx
*ctx
)
1180 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1181 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1182 struct s5p_mfc_vp8_enc_params
*p_vp8
= &p
->codec
.vp8
;
1183 unsigned int reg
= 0;
1184 unsigned int val
= 0;
1188 s5p_mfc_set_enc_params(ctx
);
1190 /* pictype : number of B */
1191 reg
= READL(S5P_FIMV_E_GOP_CONFIG_V6
);
1192 reg
&= ~(0x3 << 16);
1193 reg
|= ((p
->num_b_frame
& 0x3) << 16);
1194 WRITEL(reg
, S5P_FIMV_E_GOP_CONFIG_V6
);
1196 /* profile - 0 ~ 3 */
1197 reg
= p_vp8
->profile
& 0x3;
1198 WRITEL(reg
, S5P_FIMV_E_PICTURE_PROFILE_V6
);
1200 /* rate control config. */
1201 reg
= READL(S5P_FIMV_E_RC_CONFIG_V6
);
1202 /** macroblock level rate control */
1204 reg
|= ((p
->rc_mb
& 0x1) << 8);
1205 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1208 if (p
->rc_frame
&& p
->rc_framerate_num
&& p
->rc_framerate_denom
) {
1210 reg
|= ((p
->rc_framerate_num
& 0xFFFF) << 16);
1211 reg
|= p
->rc_framerate_denom
& 0xFFFF;
1212 WRITEL(reg
, S5P_FIMV_E_RC_FRAME_RATE_V6
);
1217 reg
|= p_vp8
->rc_frame_qp
& 0x7F;
1218 WRITEL(reg
, S5P_FIMV_E_RC_CONFIG_V6
);
1221 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1222 if (!p
->rc_frame
&& !p
->rc_mb
) {
1224 reg
|= ((p_vp8
->rc_p_frame_qp
& 0x7F) << 8);
1225 reg
|= p_vp8
->rc_frame_qp
& 0x7F;
1226 WRITEL(reg
, S5P_FIMV_E_FIXED_PICTURE_QP_V6
);
1230 reg
= ((p_vp8
->rc_max_qp
& 0x7F) << 8);
1232 reg
|= p_vp8
->rc_min_qp
& 0x7F;
1233 WRITEL(reg
, S5P_FIMV_E_RC_QP_BOUND_V6
);
1235 /* vbv buffer size */
1236 if (p
->frame_skip_mode
==
1237 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
1238 WRITEL(p
->vbv_size
& 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6
);
1241 WRITEL(p
->vbv_delay
, S5P_FIMV_E_VBV_INIT_DELAY_V6
);
1244 /* VP8 specific params */
1246 reg
|= (p_vp8
->imd_4x4
& 0x1) << 10;
1247 switch (p_vp8
->num_partitions
) {
1248 case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION
:
1251 case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS
:
1254 case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS
:
1257 case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS
:
1261 reg
|= (val
& 0xF) << 3;
1262 reg
|= (p_vp8
->num_ref
& 0x2);
1263 WRITEL(reg
, S5P_FIMV_E_VP8_OPTIONS_V7
);
1270 /* Initialize decoding */
1271 static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx
*ctx
)
1273 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1274 unsigned int reg
= 0;
1275 int fmo_aso_ctrl
= 0;
1278 mfc_debug(2, "InstNo: %d/%d\n", ctx
->inst_no
,
1279 S5P_FIMV_CH_SEQ_HEADER_V6
);
1280 mfc_debug(2, "BUFs: %08x %08x %08x\n",
1281 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6
),
1282 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6
),
1283 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6
));
1285 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
1286 reg
|= (fmo_aso_ctrl
<< S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6
);
1288 /* When user sets desplay_delay to 0,
1289 * It works as "display_delay enable" and delay set to 0.
1290 * If user wants display_delay disable, It should be
1291 * set to negative value. */
1292 if (ctx
->display_delay
>= 0) {
1293 reg
|= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6
);
1294 WRITEL(ctx
->display_delay
, S5P_FIMV_D_DISPLAY_DELAY_V6
);
1297 if (IS_MFCV7(dev
)) {
1298 WRITEL(reg
, S5P_FIMV_D_DEC_OPTIONS_V6
);
1302 /* Setup loop filter, for decoding this is only valid for MPEG4 */
1303 if (ctx
->codec_mode
== S5P_MFC_CODEC_MPEG4_DEC
) {
1304 mfc_debug(2, "Set loop filter to: %d\n",
1305 ctx
->loop_filter_mpeg4
);
1306 reg
|= (ctx
->loop_filter_mpeg4
<<
1307 S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6
);
1309 if (ctx
->dst_fmt
->fourcc
== V4L2_PIX_FMT_NV12MT_16X16
)
1310 reg
|= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6
);
1313 WRITEL(reg
, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V7
);
1315 WRITEL(reg
, S5P_FIMV_D_DEC_OPTIONS_V6
);
1317 /* 0: NV12(CbCr), 1: NV21(CrCb) */
1318 if (ctx
->dst_fmt
->fourcc
== V4L2_PIX_FMT_NV21M
)
1319 WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6
);
1321 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6
);
1325 WRITEL(ctx
->sei_fp_parse
& 0x1, S5P_FIMV_D_SEI_ENABLE_V6
);
1327 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
1328 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1329 S5P_FIMV_CH_SEQ_HEADER_V6
, NULL
);
1335 static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx
*ctx
, int flush
)
1337 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1340 dev
->curr_ctx
= ctx
->num
;
1341 s5p_mfc_clean_ctx_int_flags(ctx
);
1342 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
1343 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1344 S5P_FIMV_H2R_CMD_FLUSH_V6
, NULL
);
1348 /* Decode a single frame */
1349 static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx
*ctx
,
1350 enum s5p_mfc_decode_arg last_frame
)
1352 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1354 WRITEL(ctx
->dec_dst_flag
, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6
);
1355 WRITEL(ctx
->slice_interface
& 0x1, S5P_FIMV_D_SLICE_IF_ENABLE_V6
);
1357 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
1358 /* Issue different commands to instance basing on whether it
1359 * is the last frame or not. */
1360 switch (last_frame
) {
1362 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1363 S5P_FIMV_CH_FRAME_START_V6
, NULL
);
1366 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1367 S5P_FIMV_CH_LAST_FRAME_V6
, NULL
);
1370 mfc_err("Unsupported last frame arg.\n");
1374 mfc_debug(2, "Decoding a usual frame.\n");
1378 static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx
*ctx
)
1380 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1382 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
)
1383 s5p_mfc_set_enc_params_h264(ctx
);
1384 else if (ctx
->codec_mode
== S5P_MFC_CODEC_MPEG4_ENC
)
1385 s5p_mfc_set_enc_params_mpeg4(ctx
);
1386 else if (ctx
->codec_mode
== S5P_MFC_CODEC_H263_ENC
)
1387 s5p_mfc_set_enc_params_h263(ctx
);
1388 else if (ctx
->codec_mode
== S5P_MFC_CODEC_VP8_ENC
)
1389 s5p_mfc_set_enc_params_vp8(ctx
);
1391 mfc_err("Unknown codec for encoding (%x).\n",
1396 /* Set stride lengths */
1397 if (IS_MFCV7(dev
)) {
1398 WRITEL(ctx
->img_width
, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7
);
1399 WRITEL(ctx
->img_width
, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7
);
1402 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
1403 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1404 S5P_FIMV_CH_SEQ_HEADER_V6
, NULL
);
1409 static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx
*ctx
)
1411 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1412 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
1413 struct s5p_mfc_h264_enc_params
*p_h264
= &p
->codec
.h264
;
1417 for (i
= 0; i
< 8; i
++)
1418 WRITEL(p_h264
->aso_slice_order
[i
],
1419 S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6
+ i
* 4);
1424 /* Encode a single frame */
1425 static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx
*ctx
)
1427 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1429 mfc_debug(2, "++\n");
1431 /* memory structure cur. frame */
1433 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
)
1434 s5p_mfc_h264_set_aso_slice_order_v6(ctx
);
1436 s5p_mfc_set_slice_mode(ctx
);
1438 WRITEL(ctx
->inst_no
, S5P_FIMV_INSTANCE_ID_V6
);
1439 s5p_mfc_hw_call(dev
->mfc_cmds
, cmd_host2risc
, dev
,
1440 S5P_FIMV_CH_FRAME_START_V6
, NULL
);
1442 mfc_debug(2, "--\n");
1447 static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev
*dev
)
1449 unsigned long flags
;
1453 spin_lock_irqsave(&dev
->condlock
, flags
);
1454 mfc_debug(2, "Previous context: %d (bits %08lx)\n", dev
->curr_ctx
,
1455 dev
->ctx_work_bits
);
1456 new_ctx
= (dev
->curr_ctx
+ 1) % MFC_NUM_CONTEXTS
;
1458 while (!test_bit(new_ctx
, &dev
->ctx_work_bits
)) {
1459 new_ctx
= (new_ctx
+ 1) % MFC_NUM_CONTEXTS
;
1461 if (cnt
> MFC_NUM_CONTEXTS
) {
1462 /* No contexts to run */
1463 spin_unlock_irqrestore(&dev
->condlock
, flags
);
1467 spin_unlock_irqrestore(&dev
->condlock
, flags
);
1471 static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx
*ctx
)
1473 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1474 struct s5p_mfc_buf
*temp_vb
;
1475 unsigned long flags
;
1477 spin_lock_irqsave(&dev
->irqlock
, flags
);
1479 /* Frames are being decoded */
1480 if (list_empty(&ctx
->src_queue
)) {
1481 mfc_debug(2, "No src buffers.\n");
1482 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1485 /* Get the next source buffer */
1486 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1487 temp_vb
->flags
|= MFC_BUF_FLAG_USED
;
1488 s5p_mfc_set_dec_stream_buffer_v6(ctx
,
1489 vb2_dma_contig_plane_dma_addr(temp_vb
->b
, 0), 0, 0);
1490 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1492 dev
->curr_ctx
= ctx
->num
;
1493 s5p_mfc_clean_ctx_int_flags(ctx
);
1494 s5p_mfc_decode_one_frame_v6(ctx
, 1);
1497 static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx
*ctx
)
1499 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1500 struct s5p_mfc_buf
*temp_vb
;
1501 unsigned long flags
;
1504 if (ctx
->state
== MFCINST_FINISHING
) {
1505 last_frame
= MFC_DEC_LAST_FRAME
;
1506 s5p_mfc_set_dec_stream_buffer_v6(ctx
, 0, 0, 0);
1507 dev
->curr_ctx
= ctx
->num
;
1508 s5p_mfc_clean_ctx_int_flags(ctx
);
1509 s5p_mfc_decode_one_frame_v6(ctx
, last_frame
);
1513 spin_lock_irqsave(&dev
->irqlock
, flags
);
1514 /* Frames are being decoded */
1515 if (list_empty(&ctx
->src_queue
)) {
1516 mfc_debug(2, "No src buffers.\n");
1517 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1520 /* Get the next source buffer */
1521 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1522 temp_vb
->flags
|= MFC_BUF_FLAG_USED
;
1523 s5p_mfc_set_dec_stream_buffer_v6(ctx
,
1524 vb2_dma_contig_plane_dma_addr(temp_vb
->b
, 0),
1525 ctx
->consumed_stream
,
1526 temp_vb
->b
->v4l2_planes
[0].bytesused
);
1527 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1529 dev
->curr_ctx
= ctx
->num
;
1530 s5p_mfc_clean_ctx_int_flags(ctx
);
1531 if (temp_vb
->b
->v4l2_planes
[0].bytesused
== 0) {
1533 mfc_debug(2, "Setting ctx->state to FINISHING\n");
1534 ctx
->state
= MFCINST_FINISHING
;
1536 s5p_mfc_decode_one_frame_v6(ctx
, last_frame
);
1541 static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx
*ctx
)
1543 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1544 unsigned long flags
;
1545 struct s5p_mfc_buf
*dst_mb
;
1546 struct s5p_mfc_buf
*src_mb
;
1547 unsigned long src_y_addr
, src_c_addr
, dst_addr
;
1549 unsigned int src_y_size, src_c_size;
1551 unsigned int dst_size
;
1553 spin_lock_irqsave(&dev
->irqlock
, flags
);
1555 if (list_empty(&ctx
->src_queue
)) {
1556 mfc_debug(2, "no src buffers.\n");
1557 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1561 if (list_empty(&ctx
->dst_queue
)) {
1562 mfc_debug(2, "no dst buffers.\n");
1563 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1567 src_mb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1568 src_mb
->flags
|= MFC_BUF_FLAG_USED
;
1569 src_y_addr
= vb2_dma_contig_plane_dma_addr(src_mb
->b
, 0);
1570 src_c_addr
= vb2_dma_contig_plane_dma_addr(src_mb
->b
, 1);
1572 mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr
);
1573 mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr
);
1575 s5p_mfc_set_enc_frame_buffer_v6(ctx
, src_y_addr
, src_c_addr
);
1577 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1578 dst_mb
->flags
|= MFC_BUF_FLAG_USED
;
1579 dst_addr
= vb2_dma_contig_plane_dma_addr(dst_mb
->b
, 0);
1580 dst_size
= vb2_plane_size(dst_mb
->b
, 0);
1582 s5p_mfc_set_enc_stream_buffer_v6(ctx
, dst_addr
, dst_size
);
1584 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1586 dev
->curr_ctx
= ctx
->num
;
1587 s5p_mfc_clean_ctx_int_flags(ctx
);
1588 s5p_mfc_encode_one_frame_v6(ctx
);
1593 static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx
*ctx
)
1595 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1596 unsigned long flags
;
1597 struct s5p_mfc_buf
*temp_vb
;
1599 /* Initializing decoding - parsing header */
1600 spin_lock_irqsave(&dev
->irqlock
, flags
);
1601 mfc_debug(2, "Preparing to init decoding.\n");
1602 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1603 mfc_debug(2, "Header size: %d\n", temp_vb
->b
->v4l2_planes
[0].bytesused
);
1604 s5p_mfc_set_dec_stream_buffer_v6(ctx
,
1605 vb2_dma_contig_plane_dma_addr(temp_vb
->b
, 0), 0,
1606 temp_vb
->b
->v4l2_planes
[0].bytesused
);
1607 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1608 dev
->curr_ctx
= ctx
->num
;
1609 s5p_mfc_clean_ctx_int_flags(ctx
);
1610 s5p_mfc_init_decode_v6(ctx
);
1613 static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx
*ctx
)
1615 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1616 unsigned long flags
;
1617 struct s5p_mfc_buf
*dst_mb
;
1618 unsigned long dst_addr
;
1619 unsigned int dst_size
;
1621 spin_lock_irqsave(&dev
->irqlock
, flags
);
1623 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1624 dst_addr
= vb2_dma_contig_plane_dma_addr(dst_mb
->b
, 0);
1625 dst_size
= vb2_plane_size(dst_mb
->b
, 0);
1626 s5p_mfc_set_enc_stream_buffer_v6(ctx
, dst_addr
, dst_size
);
1627 spin_unlock_irqrestore(&dev
->irqlock
, flags
);
1628 dev
->curr_ctx
= ctx
->num
;
1629 s5p_mfc_clean_ctx_int_flags(ctx
);
1630 s5p_mfc_init_encode_v6(ctx
);
1633 static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx
*ctx
)
1635 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1637 /* Header was parsed now start processing
1638 * First set the output frame buffers
1639 * s5p_mfc_alloc_dec_buffers(ctx); */
1641 if (ctx
->capture_state
!= QUEUE_BUFS_MMAPED
) {
1642 mfc_err("It seems that not all destionation buffers were\n"
1643 "mmaped.MFC requires that all destination are mmaped\n"
1644 "before starting processing.\n");
1648 dev
->curr_ctx
= ctx
->num
;
1649 s5p_mfc_clean_ctx_int_flags(ctx
);
1650 ret
= s5p_mfc_set_dec_frame_buffer_v6(ctx
);
1652 mfc_err("Failed to alloc frame mem.\n");
1653 ctx
->state
= MFCINST_ERROR
;
1658 static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx
*ctx
)
1660 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1663 dev
->curr_ctx
= ctx
->num
;
1664 s5p_mfc_clean_ctx_int_flags(ctx
);
1665 ret
= s5p_mfc_set_enc_ref_buffer_v6(ctx
);
1667 mfc_err("Failed to alloc frame mem.\n");
1668 ctx
->state
= MFCINST_ERROR
;
1673 /* Try running an operation on hardware */
1674 static void s5p_mfc_try_run_v6(struct s5p_mfc_dev
*dev
)
1676 struct s5p_mfc_ctx
*ctx
;
1678 unsigned int ret
= 0;
1680 mfc_debug(1, "Try run dev: %p\n", dev
);
1682 /* Check whether hardware is not running */
1683 if (test_and_set_bit(0, &dev
->hw_lock
) != 0) {
1684 /* This is perfectly ok, the scheduled ctx should wait */
1685 mfc_debug(1, "Couldn't lock HW.\n");
1689 /* Choose the context to run */
1690 new_ctx
= s5p_mfc_get_new_ctx(dev
);
1692 /* No contexts to run */
1693 if (test_and_clear_bit(0, &dev
->hw_lock
) == 0) {
1694 mfc_err("Failed to unlock hardware.\n");
1698 mfc_debug(1, "No ctx is scheduled to be run.\n");
1702 mfc_debug(1, "New context: %d\n", new_ctx
);
1703 ctx
= dev
->ctx
[new_ctx
];
1704 mfc_debug(1, "Seting new context to %p\n", ctx
);
1705 /* Got context to run in ctx */
1706 mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
1707 ctx
->dst_queue_cnt
, ctx
->pb_count
, ctx
->src_queue_cnt
);
1708 mfc_debug(1, "ctx->state=%d\n", ctx
->state
);
1709 /* Last frame has already been sent to MFC
1710 * Now obtaining frames from MFC buffer */
1713 if (ctx
->type
== MFCINST_DECODER
) {
1714 switch (ctx
->state
) {
1715 case MFCINST_FINISHING
:
1716 s5p_mfc_run_dec_last_frames(ctx
);
1718 case MFCINST_RUNNING
:
1719 ret
= s5p_mfc_run_dec_frame(ctx
);
1722 s5p_mfc_clean_ctx_int_flags(ctx
);
1723 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, open_inst_cmd
,
1726 case MFCINST_RETURN_INST
:
1727 s5p_mfc_clean_ctx_int_flags(ctx
);
1728 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, close_inst_cmd
,
1731 case MFCINST_GOT_INST
:
1732 s5p_mfc_run_init_dec(ctx
);
1734 case MFCINST_HEAD_PARSED
:
1735 ret
= s5p_mfc_run_init_dec_buffers(ctx
);
1738 s5p_mfc_set_flush(ctx
, ctx
->dpb_flush_flag
);
1740 case MFCINST_RES_CHANGE_INIT
:
1741 s5p_mfc_run_dec_last_frames(ctx
);
1743 case MFCINST_RES_CHANGE_FLUSH
:
1744 s5p_mfc_run_dec_last_frames(ctx
);
1746 case MFCINST_RES_CHANGE_END
:
1747 mfc_debug(2, "Finished remaining frames after resolution change.\n");
1748 ctx
->capture_state
= QUEUE_FREE
;
1749 mfc_debug(2, "Will re-init the codec`.\n");
1750 s5p_mfc_run_init_dec(ctx
);
1755 } else if (ctx
->type
== MFCINST_ENCODER
) {
1756 switch (ctx
->state
) {
1757 case MFCINST_FINISHING
:
1758 case MFCINST_RUNNING
:
1759 ret
= s5p_mfc_run_enc_frame(ctx
);
1762 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, open_inst_cmd
,
1765 case MFCINST_RETURN_INST
:
1766 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, close_inst_cmd
,
1769 case MFCINST_GOT_INST
:
1770 s5p_mfc_run_init_enc(ctx
);
1772 case MFCINST_HEAD_PRODUCED
:
1773 ret
= s5p_mfc_run_init_enc_buffers(ctx
);
1779 mfc_err("invalid context type: %d\n", ctx
->type
);
1784 /* Free hardware lock */
1785 if (test_and_clear_bit(0, &dev
->hw_lock
) == 0)
1786 mfc_err("Failed to unlock hardware.\n");
1788 /* This is in deed imporant, as no operation has been
1789 * scheduled, reduce the clock count as no one will
1790 * ever do this, because no interrupt related to this try_run
1791 * will ever come from hardware. */
1792 s5p_mfc_clock_off();
1797 static void s5p_mfc_cleanup_queue_v6(struct list_head
*lh
, struct vb2_queue
*vq
)
1799 struct s5p_mfc_buf
*b
;
1802 while (!list_empty(lh
)) {
1803 b
= list_entry(lh
->next
, struct s5p_mfc_buf
, list
);
1804 for (i
= 0; i
< b
->b
->num_planes
; i
++)
1805 vb2_set_plane_payload(b
->b
, i
, 0);
1806 vb2_buffer_done(b
->b
, VB2_BUF_STATE_ERROR
);
1811 static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev
*dev
)
1813 mfc_write(dev
, 0, S5P_FIMV_RISC2HOST_CMD_V6
);
1814 mfc_write(dev
, 0, S5P_FIMV_RISC2HOST_INT_V6
);
1817 static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx
*ctx
, unsigned int data
,
1820 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1824 s5p_mfc_clock_off();
1828 s5p_mfc_read_info_v6(struct s5p_mfc_ctx
*ctx
, unsigned int ofs
)
1830 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1835 s5p_mfc_clock_off();
1840 static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev
*dev
)
1842 return mfc_read(dev
, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6
);
1845 static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev
*dev
)
1847 return mfc_read(dev
, S5P_FIMV_D_DECODED_LUMA_ADDR_V6
);
1850 static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev
*dev
)
1852 return mfc_read(dev
, S5P_FIMV_D_DISPLAY_STATUS_V6
);
1855 static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev
*dev
)
1857 return mfc_read(dev
, S5P_FIMV_D_DECODED_STATUS_V6
);
1860 static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev
*dev
)
1862 return mfc_read(dev
, S5P_FIMV_D_DECODED_FRAME_TYPE_V6
) &
1863 S5P_FIMV_DECODE_FRAME_MASK_V6
;
1866 static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx
*ctx
)
1868 return mfc_read(ctx
->dev
, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6
) &
1869 S5P_FIMV_DECODE_FRAME_MASK_V6
;
1872 static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev
*dev
)
1874 return mfc_read(dev
, S5P_FIMV_D_DECODED_NAL_SIZE_V6
);
1877 static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev
*dev
)
1879 return mfc_read(dev
, S5P_FIMV_RISC2HOST_CMD_V6
) &
1880 S5P_FIMV_RISC2HOST_CMD_MASK
;
1883 static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev
*dev
)
1885 return mfc_read(dev
, S5P_FIMV_ERROR_CODE_V6
);
1888 static int s5p_mfc_err_dec_v6(unsigned int err
)
1890 return (err
& S5P_FIMV_ERR_DEC_MASK_V6
) >> S5P_FIMV_ERR_DEC_SHIFT_V6
;
1893 static int s5p_mfc_err_dspl_v6(unsigned int err
)
1895 return (err
& S5P_FIMV_ERR_DSPL_MASK_V6
) >> S5P_FIMV_ERR_DSPL_SHIFT_V6
;
1898 static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev
*dev
)
1900 return mfc_read(dev
, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6
);
1903 static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev
*dev
)
1905 return mfc_read(dev
, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6
);
1908 static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev
*dev
)
1910 return mfc_read(dev
, S5P_FIMV_D_MIN_NUM_DPB_V6
);
1913 static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev
*dev
)
1915 return mfc_read(dev
, S5P_FIMV_D_MIN_NUM_MV_V6
);
1918 static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev
*dev
)
1920 return mfc_read(dev
, S5P_FIMV_RET_INSTANCE_ID_V6
);
1923 static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev
*dev
)
1925 return mfc_read(dev
, S5P_FIMV_E_NUM_DPB_V6
);
1928 static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev
*dev
)
1930 return mfc_read(dev
, S5P_FIMV_E_STREAM_SIZE_V6
);
1933 static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev
*dev
)
1935 return mfc_read(dev
, S5P_FIMV_E_SLICE_TYPE_V6
);
1938 static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev
*dev
)
1940 return mfc_read(dev
, S5P_FIMV_E_PICTURE_COUNT_V6
);
1943 static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx
*ctx
)
1945 return mfc_read(ctx
->dev
, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6
);
1948 static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev
*dev
)
1950 return mfc_read(dev
, S5P_FIMV_D_MVC_NUM_VIEWS_V6
);
1953 static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev
*dev
)
1955 return mfc_read(dev
, S5P_FIMV_D_MVC_VIEW_ID_V6
);
1958 static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx
*ctx
)
1960 return s5p_mfc_read_info_v6(ctx
, PIC_TIME_TOP_V6
);
1963 static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx
*ctx
)
1965 return s5p_mfc_read_info_v6(ctx
, PIC_TIME_BOT_V6
);
1968 static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx
*ctx
)
1970 return s5p_mfc_read_info_v6(ctx
, CROP_INFO_H_V6
);
1973 static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx
*ctx
)
1975 return s5p_mfc_read_info_v6(ctx
, CROP_INFO_V_V6
);
1978 /* Initialize opr function pointers for MFC v6 */
1979 static struct s5p_mfc_hw_ops s5p_mfc_ops_v6
= {
1980 .alloc_dec_temp_buffers
= s5p_mfc_alloc_dec_temp_buffers_v6
,
1981 .release_dec_desc_buffer
= s5p_mfc_release_dec_desc_buffer_v6
,
1982 .alloc_codec_buffers
= s5p_mfc_alloc_codec_buffers_v6
,
1983 .release_codec_buffers
= s5p_mfc_release_codec_buffers_v6
,
1984 .alloc_instance_buffer
= s5p_mfc_alloc_instance_buffer_v6
,
1985 .release_instance_buffer
= s5p_mfc_release_instance_buffer_v6
,
1986 .alloc_dev_context_buffer
=
1987 s5p_mfc_alloc_dev_context_buffer_v6
,
1988 .release_dev_context_buffer
=
1989 s5p_mfc_release_dev_context_buffer_v6
,
1990 .dec_calc_dpb_size
= s5p_mfc_dec_calc_dpb_size_v6
,
1991 .enc_calc_src_size
= s5p_mfc_enc_calc_src_size_v6
,
1992 .set_dec_stream_buffer
= s5p_mfc_set_dec_stream_buffer_v6
,
1993 .set_dec_frame_buffer
= s5p_mfc_set_dec_frame_buffer_v6
,
1994 .set_enc_stream_buffer
= s5p_mfc_set_enc_stream_buffer_v6
,
1995 .set_enc_frame_buffer
= s5p_mfc_set_enc_frame_buffer_v6
,
1996 .get_enc_frame_buffer
= s5p_mfc_get_enc_frame_buffer_v6
,
1997 .set_enc_ref_buffer
= s5p_mfc_set_enc_ref_buffer_v6
,
1998 .init_decode
= s5p_mfc_init_decode_v6
,
1999 .init_encode
= s5p_mfc_init_encode_v6
,
2000 .encode_one_frame
= s5p_mfc_encode_one_frame_v6
,
2001 .try_run
= s5p_mfc_try_run_v6
,
2002 .cleanup_queue
= s5p_mfc_cleanup_queue_v6
,
2003 .clear_int_flags
= s5p_mfc_clear_int_flags_v6
,
2004 .write_info
= s5p_mfc_write_info_v6
,
2005 .read_info
= s5p_mfc_read_info_v6
,
2006 .get_dspl_y_adr
= s5p_mfc_get_dspl_y_adr_v6
,
2007 .get_dec_y_adr
= s5p_mfc_get_dec_y_adr_v6
,
2008 .get_dspl_status
= s5p_mfc_get_dspl_status_v6
,
2009 .get_dec_status
= s5p_mfc_get_dec_status_v6
,
2010 .get_dec_frame_type
= s5p_mfc_get_dec_frame_type_v6
,
2011 .get_disp_frame_type
= s5p_mfc_get_disp_frame_type_v6
,
2012 .get_consumed_stream
= s5p_mfc_get_consumed_stream_v6
,
2013 .get_int_reason
= s5p_mfc_get_int_reason_v6
,
2014 .get_int_err
= s5p_mfc_get_int_err_v6
,
2015 .err_dec
= s5p_mfc_err_dec_v6
,
2016 .err_dspl
= s5p_mfc_err_dspl_v6
,
2017 .get_img_width
= s5p_mfc_get_img_width_v6
,
2018 .get_img_height
= s5p_mfc_get_img_height_v6
,
2019 .get_dpb_count
= s5p_mfc_get_dpb_count_v6
,
2020 .get_mv_count
= s5p_mfc_get_mv_count_v6
,
2021 .get_inst_no
= s5p_mfc_get_inst_no_v6
,
2022 .get_enc_strm_size
= s5p_mfc_get_enc_strm_size_v6
,
2023 .get_enc_slice_type
= s5p_mfc_get_enc_slice_type_v6
,
2024 .get_enc_dpb_count
= s5p_mfc_get_enc_dpb_count_v6
,
2025 .get_enc_pic_count
= s5p_mfc_get_enc_pic_count_v6
,
2026 .get_sei_avail_status
= s5p_mfc_get_sei_avail_status_v6
,
2027 .get_mvc_num_views
= s5p_mfc_get_mvc_num_views_v6
,
2028 .get_mvc_view_id
= s5p_mfc_get_mvc_view_id_v6
,
2029 .get_pic_type_top
= s5p_mfc_get_pic_type_top_v6
,
2030 .get_pic_type_bot
= s5p_mfc_get_pic_type_bot_v6
,
2031 .get_crop_info_h
= s5p_mfc_get_crop_info_h_v6
,
2032 .get_crop_info_v
= s5p_mfc_get_crop_info_v_v6
,
2035 struct s5p_mfc_hw_ops
*s5p_mfc_init_hw_ops_v6(void)
2037 return &s5p_mfc_ops_v6
;