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 */
47 (WARN_ON_ONCE(!(reg)) ? 0 : readl(reg))
48 #define WRITEL(data, reg) \
49 (WARN_ON_ONCE(!(reg)) ? 0 : writel((data), (reg)))
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) {
81 ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
82 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
83 S5P_FIMV_TMV_BUFFER_ALIGN_V6);
85 ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
86 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
87 S5P_FIMV_TMV_BUFFER_ALIGN_V6);
89 ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
90 S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
91 S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
92 ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
93 S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
94 S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
96 ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V8(
97 ctx->img_width, ctx->img_height,
99 S5P_FIMV_ME_BUFFER_ALIGN_V6);
101 ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
102 ctx->img_width, ctx->img_height,
103 mb_width, mb_height),
104 S5P_FIMV_ME_BUFFER_ALIGN_V6);
106 mfc_debug(2, "recon luma size: %d chroma size: %d\n",
107 ctx->luma_dpb_size, ctx->chroma_dpb_size);
112 /* Codecs have different memory requirements */
113 switch (ctx->codec_mode) {
114 case S5P_MFC_CODEC_H264_DEC:
115 case S5P_MFC_CODEC_H264_MVC_DEC:
117 ctx->scratch_buf_size =
118 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(
122 ctx->scratch_buf_size =
123 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
126 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
127 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
129 ctx->scratch_buf_size +
130 (ctx->mv_count * ctx->mv_size);
132 case S5P_MFC_CODEC_MPEG4_DEC:
133 if (IS_MFCV7_PLUS(dev)) {
134 ctx->scratch_buf_size =
135 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
139 ctx->scratch_buf_size =
140 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
145 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
146 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
147 ctx->bank1.size = ctx->scratch_buf_size;
149 case S5P_MFC_CODEC_VC1RCV_DEC:
150 case S5P_MFC_CODEC_VC1_DEC:
151 ctx->scratch_buf_size =
152 S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
155 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
156 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
157 ctx->bank1.size = ctx->scratch_buf_size;
159 case S5P_MFC_CODEC_MPEG2_DEC:
163 case S5P_MFC_CODEC_H263_DEC:
164 ctx->scratch_buf_size =
165 S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
168 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
169 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
170 ctx->bank1.size = ctx->scratch_buf_size;
172 case S5P_MFC_CODEC_VP8_DEC:
174 ctx->scratch_buf_size =
175 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(
179 ctx->scratch_buf_size =
180 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
183 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
184 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
185 ctx->bank1.size = ctx->scratch_buf_size;
187 case S5P_MFC_CODEC_H264_ENC:
189 ctx->scratch_buf_size =
190 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(
194 ctx->scratch_buf_size =
195 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
198 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
199 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
201 ctx->scratch_buf_size + ctx->tmv_buffer_size +
202 (ctx->pb_count * (ctx->luma_dpb_size +
203 ctx->chroma_dpb_size + ctx->me_buffer_size));
206 case S5P_MFC_CODEC_MPEG4_ENC:
207 case S5P_MFC_CODEC_H263_ENC:
208 ctx->scratch_buf_size =
209 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
212 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
213 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
215 ctx->scratch_buf_size + ctx->tmv_buffer_size +
216 (ctx->pb_count * (ctx->luma_dpb_size +
217 ctx->chroma_dpb_size + ctx->me_buffer_size));
220 case S5P_MFC_CODEC_VP8_ENC:
222 ctx->scratch_buf_size =
223 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(
227 ctx->scratch_buf_size =
228 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
231 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
232 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
234 ctx->scratch_buf_size + ctx->tmv_buffer_size +
235 (ctx->pb_count * (ctx->luma_dpb_size +
236 ctx->chroma_dpb_size + ctx->me_buffer_size));
243 /* Allocate only if memory from bank 1 is necessary */
244 if (ctx->bank1.size > 0) {
245 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
247 mfc_err("Failed to allocate Bank1 memory\n");
250 BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
255 /* Release buffers allocated for codec */
256 static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
258 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
261 /* Allocate memory for instance data buffer */
262 static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
264 struct s5p_mfc_dev *dev = ctx->dev;
265 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
270 switch (ctx->codec_mode) {
271 case S5P_MFC_CODEC_H264_DEC:
272 case S5P_MFC_CODEC_H264_MVC_DEC:
273 ctx->ctx.size = buf_size->h264_dec_ctx;
275 case S5P_MFC_CODEC_MPEG4_DEC:
276 case S5P_MFC_CODEC_H263_DEC:
277 case S5P_MFC_CODEC_VC1RCV_DEC:
278 case S5P_MFC_CODEC_VC1_DEC:
279 case S5P_MFC_CODEC_MPEG2_DEC:
280 case S5P_MFC_CODEC_VP8_DEC:
281 ctx->ctx.size = buf_size->other_dec_ctx;
283 case S5P_MFC_CODEC_H264_ENC:
284 ctx->ctx.size = buf_size->h264_enc_ctx;
286 case S5P_MFC_CODEC_MPEG4_ENC:
287 case S5P_MFC_CODEC_H263_ENC:
288 case S5P_MFC_CODEC_VP8_ENC:
289 ctx->ctx.size = buf_size->other_enc_ctx;
293 mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
297 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
299 mfc_err("Failed to allocate instance buffer\n");
303 memset(ctx->ctx.virt, 0, ctx->ctx.size);
311 /* Release instance buffer */
312 static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
314 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
317 /* Allocate context buffers for SYS_INIT */
318 static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
320 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
325 dev->ctx_buf.size = buf_size->dev_ctx;
326 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
328 mfc_err("Failed to allocate device context buffer\n");
332 memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
340 /* Release context buffers for SYS_INIT */
341 static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
343 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
346 static int calc_plane(int width, int height)
350 mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
351 mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
353 if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
354 mbY = (mbY + 1) / 2 * 2;
356 return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
357 (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
360 static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
362 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
363 ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
364 mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
365 "buffer dimensions: %dx%d\n", ctx->img_width,
366 ctx->img_height, ctx->buf_width, ctx->buf_height);
368 ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
369 ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
370 if (IS_MFCV8(ctx->dev)) {
371 /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/
372 ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
373 ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
376 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
377 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
378 ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
380 ctx->mv_size = ALIGN(ctx->mv_size, 16);
386 static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
388 unsigned int mb_width, mb_height;
390 mb_width = MB_WIDTH(ctx->img_width);
391 mb_height = MB_HEIGHT(ctx->img_height);
393 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
394 ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
395 ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
397 /* MFCv7 needs pad bytes for Luma and Chroma */
398 if (IS_MFCV7_PLUS(ctx->dev)) {
399 ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
400 ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
404 /* Set registers for decoding stream buffer */
405 static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
406 int buf_addr, unsigned int start_num_byte,
407 unsigned int strm_size)
409 struct s5p_mfc_dev *dev = ctx->dev;
410 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
411 struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
414 mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
415 "buf_size: 0x%08x (%d)\n",
416 ctx->inst_no, buf_addr, strm_size, strm_size);
417 WRITEL(strm_size, mfc_regs->d_stream_data_size);
418 WRITEL(buf_addr, mfc_regs->d_cpb_buffer_addr);
419 WRITEL(buf_size->cpb, mfc_regs->d_cpb_buffer_size);
420 WRITEL(start_num_byte, mfc_regs->d_cpb_buffer_offset);
426 /* Set decoding frame buffer */
427 static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
429 unsigned int frame_size, i;
430 unsigned int frame_size_ch, frame_size_mv;
431 struct s5p_mfc_dev *dev = ctx->dev;
432 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
437 buf_addr1 = ctx->bank1.dma;
438 buf_size1 = ctx->bank1.size;
440 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
441 mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
442 mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
444 WRITEL(ctx->total_dpb_count, mfc_regs->d_num_dpb);
445 WRITEL(ctx->luma_size, mfc_regs->d_first_plane_dpb_size);
446 WRITEL(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size);
448 WRITEL(buf_addr1, mfc_regs->d_scratch_buffer_addr);
449 WRITEL(ctx->scratch_buf_size, mfc_regs->d_scratch_buffer_size);
452 WRITEL(ctx->img_width,
453 mfc_regs->d_first_plane_dpb_stride_size);
454 WRITEL(ctx->img_width,
455 mfc_regs->d_second_plane_dpb_stride_size);
458 buf_addr1 += ctx->scratch_buf_size;
459 buf_size1 -= ctx->scratch_buf_size;
461 if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
462 ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
463 WRITEL(ctx->mv_size, mfc_regs->d_mv_buffer_size);
464 WRITEL(ctx->mv_count, mfc_regs->d_num_mv);
467 frame_size = ctx->luma_size;
468 frame_size_ch = ctx->chroma_size;
469 frame_size_mv = ctx->mv_size;
470 mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
471 frame_size, frame_size_ch, frame_size_mv);
473 for (i = 0; i < ctx->total_dpb_count; i++) {
475 mfc_debug(2, "Luma %d: %x\n", i,
476 ctx->dst_bufs[i].cookie.raw.luma);
477 WRITEL(ctx->dst_bufs[i].cookie.raw.luma,
478 mfc_regs->d_first_plane_dpb + i * 4);
479 mfc_debug(2, "\tChroma %d: %x\n", i,
480 ctx->dst_bufs[i].cookie.raw.chroma);
481 WRITEL(ctx->dst_bufs[i].cookie.raw.chroma,
482 mfc_regs->d_second_plane_dpb + i * 4);
484 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
485 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
486 for (i = 0; i < ctx->mv_count; i++) {
487 /* To test alignment */
488 align_gap = buf_addr1;
489 buf_addr1 = ALIGN(buf_addr1, 16);
490 align_gap = buf_addr1 - align_gap;
491 buf_size1 -= align_gap;
493 mfc_debug(2, "\tBuf1: %x, size: %d\n",
494 buf_addr1, buf_size1);
495 WRITEL(buf_addr1, mfc_regs->d_mv_buffer + i * 4);
496 buf_addr1 += frame_size_mv;
497 buf_size1 -= frame_size_mv;
501 mfc_debug(2, "Buf1: %u, buf_size1: %d (frames %d)\n",
502 buf_addr1, buf_size1, ctx->total_dpb_count);
504 mfc_debug(2, "Not enough memory has been allocated.\n");
508 WRITEL(ctx->inst_no, mfc_regs->instance_id);
509 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
510 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
512 mfc_debug(2, "After setting buffers.\n");
516 /* Set registers for encoding stream buffer */
517 static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
518 unsigned long addr, unsigned int size)
520 struct s5p_mfc_dev *dev = ctx->dev;
521 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
523 WRITEL(addr, mfc_regs->e_stream_buffer_addr); /* 16B align */
524 WRITEL(size, mfc_regs->e_stream_buffer_size);
526 mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d\n",
532 static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
533 unsigned long y_addr, unsigned long c_addr)
535 struct s5p_mfc_dev *dev = ctx->dev;
536 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
538 WRITEL(y_addr, mfc_regs->e_source_first_plane_addr);
539 WRITEL(c_addr, mfc_regs->e_source_second_plane_addr);
541 mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr);
542 mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr);
545 static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
546 unsigned long *y_addr, unsigned long *c_addr)
548 struct s5p_mfc_dev *dev = ctx->dev;
549 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
550 unsigned long enc_recon_y_addr, enc_recon_c_addr;
552 *y_addr = READL(mfc_regs->e_encoded_source_first_plane_addr);
553 *c_addr = READL(mfc_regs->e_encoded_source_second_plane_addr);
555 enc_recon_y_addr = READL(mfc_regs->e_recon_luma_dpb_addr);
556 enc_recon_c_addr = READL(mfc_regs->e_recon_chroma_dpb_addr);
558 mfc_debug(2, "recon y addr: 0x%08lx\n", enc_recon_y_addr);
559 mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr);
562 /* Set encoding ref & codec buffer */
563 static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
565 struct s5p_mfc_dev *dev = ctx->dev;
566 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
572 buf_addr1 = ctx->bank1.dma;
573 buf_size1 = ctx->bank1.size;
575 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
577 for (i = 0; i < ctx->pb_count; i++) {
578 WRITEL(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
579 buf_addr1 += ctx->luma_dpb_size;
580 WRITEL(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
581 buf_addr1 += ctx->chroma_dpb_size;
582 WRITEL(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
583 buf_addr1 += ctx->me_buffer_size;
584 buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
585 ctx->me_buffer_size);
588 WRITEL(buf_addr1, mfc_regs->e_scratch_buffer_addr);
589 WRITEL(ctx->scratch_buf_size, mfc_regs->e_scratch_buffer_size);
590 buf_addr1 += ctx->scratch_buf_size;
591 buf_size1 -= ctx->scratch_buf_size;
593 WRITEL(buf_addr1, mfc_regs->e_tmv_buffer0);
594 buf_addr1 += ctx->tmv_buffer_size >> 1;
595 WRITEL(buf_addr1, mfc_regs->e_tmv_buffer1);
596 buf_addr1 += ctx->tmv_buffer_size >> 1;
597 buf_size1 -= ctx->tmv_buffer_size;
599 mfc_debug(2, "Buf1: %u, buf_size1: %d (ref frames %d)\n",
600 buf_addr1, buf_size1, ctx->pb_count);
602 mfc_debug(2, "Not enough memory has been allocated.\n");
606 WRITEL(ctx->inst_no, mfc_regs->instance_id);
607 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
608 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
615 static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
617 struct s5p_mfc_dev *dev = ctx->dev;
618 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
620 /* multi-slice control */
621 /* multi-slice MB number or bit size */
622 WRITEL(ctx->slice_mode, mfc_regs->e_mslice_mode);
623 if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
624 WRITEL(ctx->slice_size.mb, mfc_regs->e_mslice_size_mb);
625 } else if (ctx->slice_mode ==
626 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
627 WRITEL(ctx->slice_size.bits, mfc_regs->e_mslice_size_bits);
629 WRITEL(0x0, mfc_regs->e_mslice_size_mb);
630 WRITEL(0x0, mfc_regs->e_mslice_size_bits);
636 static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
638 struct s5p_mfc_dev *dev = ctx->dev;
639 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
640 struct s5p_mfc_enc_params *p = &ctx->enc_params;
641 unsigned int reg = 0;
646 WRITEL(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */
648 WRITEL(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */
651 WRITEL(ctx->img_width, mfc_regs->e_cropped_frame_width);
653 WRITEL(ctx->img_height, mfc_regs->e_cropped_frame_height);
655 WRITEL(0x0, mfc_regs->e_frame_crop_offset);
657 /* pictype : IDR period */
659 reg |= p->gop_size & 0xFFFF;
660 WRITEL(reg, mfc_regs->e_gop_config);
662 /* multi-slice control */
663 /* multi-slice MB number or bit size */
664 ctx->slice_mode = p->slice_mode;
666 if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
668 WRITEL(reg, mfc_regs->e_enc_options);
669 ctx->slice_size.mb = p->slice_mb;
670 } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
672 WRITEL(reg, mfc_regs->e_enc_options);
673 ctx->slice_size.bits = p->slice_bit;
676 WRITEL(reg, mfc_regs->e_enc_options);
679 s5p_mfc_set_slice_mode(ctx);
681 /* cyclic intra refresh */
682 WRITEL(p->intra_refresh_mb, mfc_regs->e_ir_size);
683 reg = READL(mfc_regs->e_enc_options);
684 if (p->intra_refresh_mb == 0)
688 WRITEL(reg, mfc_regs->e_enc_options);
690 /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
691 reg = READL(mfc_regs->e_enc_options);
693 WRITEL(reg, mfc_regs->e_enc_options);
695 /* memory structure cur. frame */
696 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
697 /* 0: Linear, 1: 2D tiled*/
698 reg = READL(mfc_regs->e_enc_options);
700 WRITEL(reg, mfc_regs->e_enc_options);
701 /* 0: NV12(CbCr), 1: NV21(CrCb) */
702 WRITEL(0x0, mfc_regs->pixel_format);
703 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
704 /* 0: Linear, 1: 2D tiled*/
705 reg = READL(mfc_regs->e_enc_options);
707 WRITEL(reg, mfc_regs->e_enc_options);
708 /* 0: NV12(CbCr), 1: NV21(CrCb) */
709 WRITEL(0x1, mfc_regs->pixel_format);
710 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
711 /* 0: Linear, 1: 2D tiled*/
712 reg = READL(mfc_regs->e_enc_options);
714 WRITEL(reg, mfc_regs->e_enc_options);
715 /* 0: NV12(CbCr), 1: NV21(CrCb) */
716 WRITEL(0x0, mfc_regs->pixel_format);
719 /* memory structure recon. frame */
720 /* 0: Linear, 1: 2D tiled */
721 reg = READL(mfc_regs->e_enc_options);
723 WRITEL(reg, mfc_regs->e_enc_options);
725 /* padding control & value */
726 WRITEL(0x0, mfc_regs->e_padding_ctrl);
732 reg |= ((p->pad_cr & 0xFF) << 16);
734 reg |= ((p->pad_cb & 0xFF) << 8);
736 reg |= p->pad_luma & 0xFF;
737 WRITEL(reg, mfc_regs->e_padding_ctrl);
740 /* rate control config. */
742 /* frame-level rate control */
743 reg |= ((p->rc_frame & 0x1) << 9);
744 WRITEL(reg, mfc_regs->e_rc_config);
748 WRITEL(p->rc_bitrate,
749 mfc_regs->e_rc_bit_rate);
751 WRITEL(1, mfc_regs->e_rc_bit_rate);
753 /* reaction coefficient */
755 if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
756 WRITEL(1, mfc_regs->e_rc_mode);
758 WRITEL(2, mfc_regs->e_rc_mode);
761 /* seq header ctrl */
762 reg = READL(mfc_regs->e_enc_options);
764 reg |= ((p->seq_hdr_mode & 0x1) << 2);
766 /* frame skip mode */
768 reg |= (p->frame_skip_mode & 0x3);
769 WRITEL(reg, mfc_regs->e_enc_options);
771 /* 'DROP_CONTROL_ENABLE', disable */
772 reg = READL(mfc_regs->e_rc_config);
774 WRITEL(reg, mfc_regs->e_rc_config);
776 /* setting for MV range [16, 256] */
777 reg = (p->mv_h_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
778 WRITEL(reg, mfc_regs->e_mv_hor_range);
780 reg = (p->mv_v_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
781 WRITEL(reg, mfc_regs->e_mv_ver_range);
783 WRITEL(0x0, mfc_regs->e_frame_insertion);
784 WRITEL(0x0, mfc_regs->e_roi_buffer_addr);
785 WRITEL(0x0, mfc_regs->e_param_change);
786 WRITEL(0x0, mfc_regs->e_rc_roi_ctrl);
787 WRITEL(0x0, mfc_regs->e_picture_tag);
789 WRITEL(0x0, mfc_regs->e_bit_count_enable);
790 WRITEL(0x0, mfc_regs->e_max_bit_count);
791 WRITEL(0x0, mfc_regs->e_min_bit_count);
793 WRITEL(0x0, mfc_regs->e_metadata_buffer_addr);
794 WRITEL(0x0, mfc_regs->e_metadata_buffer_size);
801 static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
803 struct s5p_mfc_dev *dev = ctx->dev;
804 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
805 struct s5p_mfc_enc_params *p = &ctx->enc_params;
806 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
807 unsigned int reg = 0;
812 s5p_mfc_set_enc_params(ctx);
814 /* pictype : number of B */
815 reg = READL(mfc_regs->e_gop_config);
817 reg |= ((p->num_b_frame & 0x3) << 16);
818 WRITEL(reg, mfc_regs->e_gop_config);
820 /* profile & level */
823 reg |= ((p_h264->level & 0xFF) << 8);
824 /** profile - 0 ~ 3 */
825 reg |= p_h264->profile & 0x3F;
826 WRITEL(reg, mfc_regs->e_picture_profile);
828 /* rate control config. */
829 reg = READL(mfc_regs->e_rc_config);
830 /** macroblock level rate control */
832 reg |= ((p->rc_mb & 0x1) << 8);
833 WRITEL(reg, mfc_regs->e_rc_config);
837 reg |= p_h264->rc_frame_qp & 0x3F;
838 WRITEL(reg, mfc_regs->e_rc_config);
840 /* max & min value of QP */
843 reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
845 reg |= p_h264->rc_min_qp & 0x3F;
846 WRITEL(reg, mfc_regs->e_rc_qp_bound);
849 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
850 if (!p->rc_frame && !p->rc_mb) {
852 reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
853 reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
854 reg |= p_h264->rc_frame_qp & 0x3F;
855 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
859 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
861 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
862 reg |= p->rc_framerate_denom & 0xFFFF;
863 WRITEL(reg, mfc_regs->e_rc_frame_rate);
866 /* vbv buffer size */
867 if (p->frame_skip_mode ==
868 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
869 WRITEL(p_h264->cpb_size & 0xFFFF,
870 mfc_regs->e_vbv_buffer_size);
873 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
878 reg |= ((p_h264->interlace & 0x1) << 3);
879 WRITEL(reg, mfc_regs->e_h264_options);
882 if (p_h264->interlace) {
883 WRITEL(ctx->img_height >> 1,
884 mfc_regs->e_frame_height); /* 32 align */
886 WRITEL(ctx->img_height >> 1,
887 mfc_regs->e_cropped_frame_height);
890 /* loop filter ctrl */
891 reg = READL(mfc_regs->e_h264_options);
893 reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
894 WRITEL(reg, mfc_regs->e_h264_options);
896 /* loopfilter alpha offset */
897 if (p_h264->loop_filter_alpha < 0) {
899 reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
902 reg |= (p_h264->loop_filter_alpha & 0xF);
904 WRITEL(reg, mfc_regs->e_h264_lf_alpha_offset);
906 /* loopfilter beta offset */
907 if (p_h264->loop_filter_beta < 0) {
909 reg |= (0xFF - p_h264->loop_filter_beta) + 1;
912 reg |= (p_h264->loop_filter_beta & 0xF);
914 WRITEL(reg, mfc_regs->e_h264_lf_beta_offset);
916 /* entropy coding mode */
917 reg = READL(mfc_regs->e_h264_options);
919 reg |= p_h264->entropy_mode & 0x1;
920 WRITEL(reg, mfc_regs->e_h264_options);
922 /* number of ref. picture */
923 reg = READL(mfc_regs->e_h264_options);
925 reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
926 WRITEL(reg, mfc_regs->e_h264_options);
928 /* 8x8 transform enable */
929 reg = READL(mfc_regs->e_h264_options);
931 reg |= ((p_h264->_8x8_transform & 0x3) << 12);
932 WRITEL(reg, mfc_regs->e_h264_options);
934 /* macroblock adaptive scaling features */
935 WRITEL(0x0, mfc_regs->e_mb_rc_config);
939 reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
941 reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
943 reg |= ((p_h264->rc_mb_static & 0x1) << 1);
944 /** high activity region */
945 reg |= p_h264->rc_mb_activity & 0x1;
946 WRITEL(reg, mfc_regs->e_mb_rc_config);
949 /* aspect ratio VUI */
950 READL(mfc_regs->e_h264_options);
952 reg |= ((p_h264->vui_sar & 0x1) << 5);
953 WRITEL(reg, mfc_regs->e_h264_options);
955 WRITEL(0x0, mfc_regs->e_aspect_ratio);
956 WRITEL(0x0, mfc_regs->e_extended_sar);
957 if (p_h264->vui_sar) {
958 /* aspect ration IDC */
960 reg |= p_h264->vui_sar_idc & 0xFF;
961 WRITEL(reg, mfc_regs->e_aspect_ratio);
962 if (p_h264->vui_sar_idc == 0xFF) {
965 reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
966 reg |= p_h264->vui_ext_sar_height & 0xFFFF;
967 WRITEL(reg, mfc_regs->e_extended_sar);
971 /* intra picture period for H.264 open GOP */
973 READL(mfc_regs->e_h264_options);
975 reg |= ((p_h264->open_gop & 0x1) << 4);
976 WRITEL(reg, mfc_regs->e_h264_options);
979 WRITEL(0x0, mfc_regs->e_h264_i_period);
980 if (p_h264->open_gop) {
982 reg |= p_h264->open_gop_size & 0xFFFF;
983 WRITEL(reg, mfc_regs->e_h264_i_period);
986 /* 'WEIGHTED_BI_PREDICTION' for B is disable */
987 READL(mfc_regs->e_h264_options);
989 WRITEL(reg, mfc_regs->e_h264_options);
991 /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
992 READL(mfc_regs->e_h264_options);
994 WRITEL(reg, mfc_regs->e_h264_options);
997 READL(mfc_regs->e_h264_options);
999 reg |= ((p_h264->aso & 0x1) << 6);
1000 WRITEL(reg, mfc_regs->e_h264_options);
1002 /* hier qp enable */
1003 READL(mfc_regs->e_h264_options);
1005 reg |= ((p_h264->open_gop & 0x1) << 8);
1006 WRITEL(reg, mfc_regs->e_h264_options);
1008 if (p_h264->hier_qp && p_h264->hier_qp_layer) {
1009 reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
1010 reg |= p_h264->hier_qp_layer & 0x7;
1011 WRITEL(reg, mfc_regs->e_h264_num_t_layer);
1012 /* QP value for each layer */
1013 for (i = 0; i < p_h264->hier_qp_layer &&
1014 i < ARRAY_SIZE(p_h264->hier_qp_layer_qp); i++) {
1015 WRITEL(p_h264->hier_qp_layer_qp[i],
1016 mfc_regs->e_h264_hierarchical_qp_layer0
1020 /* number of coding layer should be zero when hierarchical is disable */
1021 WRITEL(reg, mfc_regs->e_h264_num_t_layer);
1023 /* frame packing SEI generation */
1024 READL(mfc_regs->e_h264_options);
1025 reg &= ~(0x1 << 25);
1026 reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
1027 WRITEL(reg, mfc_regs->e_h264_options);
1028 if (p_h264->sei_frame_packing) {
1030 /** current frame0 flag */
1031 reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
1032 /** arrangement type */
1033 reg |= p_h264->sei_fp_arrangement_type & 0x3;
1034 WRITEL(reg, mfc_regs->e_h264_frame_packing_sei_info);
1038 switch (p_h264->fmo_map_type) {
1039 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
1040 if (p_h264->fmo_slice_grp > 4)
1041 p_h264->fmo_slice_grp = 4;
1042 for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
1043 WRITEL(p_h264->fmo_run_len[i] - 1,
1044 mfc_regs->e_h264_fmo_run_length_minus1_0
1047 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
1048 if (p_h264->fmo_slice_grp > 4)
1049 p_h264->fmo_slice_grp = 4;
1051 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
1052 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
1053 if (p_h264->fmo_slice_grp > 2)
1054 p_h264->fmo_slice_grp = 2;
1055 WRITEL(p_h264->fmo_chg_dir & 0x1,
1056 mfc_regs->e_h264_fmo_slice_grp_change_dir);
1057 /* the valid range is 0 ~ number of macroblocks -1 */
1058 WRITEL(p_h264->fmo_chg_rate,
1059 mfc_regs->e_h264_fmo_slice_grp_change_rate_minus1);
1062 mfc_err("Unsupported map type for FMO: %d\n",
1063 p_h264->fmo_map_type);
1064 p_h264->fmo_map_type = 0;
1065 p_h264->fmo_slice_grp = 1;
1069 WRITEL(p_h264->fmo_map_type,
1070 mfc_regs->e_h264_fmo_slice_grp_map_type);
1071 WRITEL(p_h264->fmo_slice_grp - 1,
1072 mfc_regs->e_h264_fmo_num_slice_grp_minus1);
1074 WRITEL(0, mfc_regs->e_h264_fmo_num_slice_grp_minus1);
1082 static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
1084 struct s5p_mfc_dev *dev = ctx->dev;
1085 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1086 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1087 struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
1088 unsigned int reg = 0;
1092 s5p_mfc_set_enc_params(ctx);
1094 /* pictype : number of B */
1095 reg = READL(mfc_regs->e_gop_config);
1096 reg &= ~(0x3 << 16);
1097 reg |= ((p->num_b_frame & 0x3) << 16);
1098 WRITEL(reg, mfc_regs->e_gop_config);
1100 /* profile & level */
1103 reg |= ((p_mpeg4->level & 0xFF) << 8);
1104 /** profile - 0 ~ 1 */
1105 reg |= p_mpeg4->profile & 0x3F;
1106 WRITEL(reg, mfc_regs->e_picture_profile);
1108 /* rate control config. */
1109 reg = READL(mfc_regs->e_rc_config);
1110 /** macroblock level rate control */
1112 reg |= ((p->rc_mb & 0x1) << 8);
1113 WRITEL(reg, mfc_regs->e_rc_config);
1117 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1118 WRITEL(reg, mfc_regs->e_rc_config);
1120 /* max & min value of QP */
1123 reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
1125 reg |= p_mpeg4->rc_min_qp & 0x3F;
1126 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1129 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1130 if (!p->rc_frame && !p->rc_mb) {
1132 reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
1133 reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
1134 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1135 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1139 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1141 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1142 reg |= p->rc_framerate_denom & 0xFFFF;
1143 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1146 /* vbv buffer size */
1147 if (p->frame_skip_mode ==
1148 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1149 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1152 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1156 WRITEL(0x0, mfc_regs->e_mpeg4_options);
1157 WRITEL(0x0, mfc_regs->e_mpeg4_hec_period);
1164 static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
1166 struct s5p_mfc_dev *dev = ctx->dev;
1167 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1168 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1169 struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
1170 unsigned int reg = 0;
1174 s5p_mfc_set_enc_params(ctx);
1176 /* profile & level */
1180 WRITEL(reg, mfc_regs->e_picture_profile);
1182 /* rate control config. */
1183 reg = READL(mfc_regs->e_rc_config);
1184 /** macroblock level rate control */
1186 reg |= ((p->rc_mb & 0x1) << 8);
1187 WRITEL(reg, mfc_regs->e_rc_config);
1191 reg |= p_h263->rc_frame_qp & 0x3F;
1192 WRITEL(reg, mfc_regs->e_rc_config);
1194 /* max & min value of QP */
1197 reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
1199 reg |= p_h263->rc_min_qp & 0x3F;
1200 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1203 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1204 if (!p->rc_frame && !p->rc_mb) {
1206 reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
1207 reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
1208 reg |= p_h263->rc_frame_qp & 0x3F;
1209 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1213 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1215 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1216 reg |= p->rc_framerate_denom & 0xFFFF;
1217 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1220 /* vbv buffer size */
1221 if (p->frame_skip_mode ==
1222 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1223 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1226 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1234 static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx)
1236 struct s5p_mfc_dev *dev = ctx->dev;
1237 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1238 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1239 struct s5p_mfc_vp8_enc_params *p_vp8 = &p->codec.vp8;
1240 unsigned int reg = 0;
1241 unsigned int val = 0;
1245 s5p_mfc_set_enc_params(ctx);
1247 /* pictype : number of B */
1248 reg = READL(mfc_regs->e_gop_config);
1249 reg &= ~(0x3 << 16);
1250 reg |= ((p->num_b_frame & 0x3) << 16);
1251 WRITEL(reg, mfc_regs->e_gop_config);
1253 /* profile - 0 ~ 3 */
1254 reg = p_vp8->profile & 0x3;
1255 WRITEL(reg, mfc_regs->e_picture_profile);
1257 /* rate control config. */
1258 reg = READL(mfc_regs->e_rc_config);
1259 /** macroblock level rate control */
1261 reg |= ((p->rc_mb & 0x1) << 8);
1262 WRITEL(reg, mfc_regs->e_rc_config);
1265 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1267 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1268 reg |= p->rc_framerate_denom & 0xFFFF;
1269 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1274 reg |= p_vp8->rc_frame_qp & 0x7F;
1275 WRITEL(reg, mfc_regs->e_rc_config);
1278 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1279 if (!p->rc_frame && !p->rc_mb) {
1281 reg |= ((p_vp8->rc_p_frame_qp & 0x7F) << 8);
1282 reg |= p_vp8->rc_frame_qp & 0x7F;
1283 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1287 reg = ((p_vp8->rc_max_qp & 0x7F) << 8);
1289 reg |= p_vp8->rc_min_qp & 0x7F;
1290 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1292 /* vbv buffer size */
1293 if (p->frame_skip_mode ==
1294 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1295 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1298 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1301 /* VP8 specific params */
1303 reg |= (p_vp8->imd_4x4 & 0x1) << 10;
1304 switch (p_vp8->num_partitions) {
1305 case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
1308 case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS:
1311 case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS:
1314 case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS:
1318 reg |= (val & 0xF) << 3;
1319 reg |= (p_vp8->num_ref & 0x2);
1320 WRITEL(reg, mfc_regs->e_vp8_options);
1327 /* Initialize decoding */
1328 static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1330 struct s5p_mfc_dev *dev = ctx->dev;
1331 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1332 unsigned int reg = 0;
1333 int fmo_aso_ctrl = 0;
1336 mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
1337 S5P_FIMV_CH_SEQ_HEADER_V6);
1338 mfc_debug(2, "BUFs: %08x %08x %08x\n",
1339 READL(mfc_regs->d_cpb_buffer_addr),
1340 READL(mfc_regs->d_cpb_buffer_addr),
1341 READL(mfc_regs->d_cpb_buffer_addr));
1343 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
1344 reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
1346 /* When user sets desplay_delay to 0,
1347 * It works as "display_delay enable" and delay set to 0.
1348 * If user wants display_delay disable, It should be
1349 * set to negative value. */
1350 if (ctx->display_delay >= 0) {
1351 reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
1352 WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
1355 if (IS_MFCV7_PLUS(dev)) {
1356 WRITEL(reg, mfc_regs->d_dec_options);
1360 /* Setup loop filter, for decoding this is only valid for MPEG4 */
1361 if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
1362 mfc_debug(2, "Set loop filter to: %d\n",
1363 ctx->loop_filter_mpeg4);
1364 reg |= (ctx->loop_filter_mpeg4 <<
1365 S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
1367 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
1368 reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
1370 if (IS_MFCV7_PLUS(dev))
1371 WRITEL(reg, mfc_regs->d_init_buffer_options);
1373 WRITEL(reg, mfc_regs->d_dec_options);
1375 /* 0: NV12(CbCr), 1: NV21(CrCb) */
1376 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
1377 WRITEL(0x1, mfc_regs->pixel_format);
1379 WRITEL(0x0, mfc_regs->pixel_format);
1383 WRITEL(ctx->sei_fp_parse & 0x1, mfc_regs->d_sei_enable);
1385 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1386 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1387 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1393 static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1395 struct s5p_mfc_dev *dev = ctx->dev;
1396 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1399 dev->curr_ctx = ctx->num;
1400 s5p_mfc_clean_ctx_int_flags(ctx);
1401 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1402 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1403 S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
1407 /* Decode a single frame */
1408 static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
1409 enum s5p_mfc_decode_arg last_frame)
1411 struct s5p_mfc_dev *dev = ctx->dev;
1412 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1414 WRITEL(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower);
1415 WRITEL(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable);
1417 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1418 /* Issue different commands to instance basing on whether it
1419 * is the last frame or not. */
1420 switch (last_frame) {
1422 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1423 S5P_FIMV_CH_FRAME_START_V6, NULL);
1426 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1427 S5P_FIMV_CH_LAST_FRAME_V6, NULL);
1430 mfc_err("Unsupported last frame arg.\n");
1434 mfc_debug(2, "Decoding a usual frame.\n");
1438 static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
1440 struct s5p_mfc_dev *dev = ctx->dev;
1441 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1443 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1444 s5p_mfc_set_enc_params_h264(ctx);
1445 else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
1446 s5p_mfc_set_enc_params_mpeg4(ctx);
1447 else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
1448 s5p_mfc_set_enc_params_h263(ctx);
1449 else if (ctx->codec_mode == S5P_MFC_CODEC_VP8_ENC)
1450 s5p_mfc_set_enc_params_vp8(ctx);
1452 mfc_err("Unknown codec for encoding (%x).\n",
1457 /* Set stride lengths for v7 & above */
1458 if (IS_MFCV7_PLUS(dev)) {
1459 WRITEL(ctx->img_width, mfc_regs->e_source_first_plane_stride);
1460 WRITEL(ctx->img_width, mfc_regs->e_source_second_plane_stride);
1463 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1464 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1465 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1470 static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
1472 struct s5p_mfc_dev *dev = ctx->dev;
1473 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1474 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1475 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
1479 for (i = 0; i < ARRAY_SIZE(p_h264->aso_slice_order); i++) {
1480 WRITEL(p_h264->aso_slice_order[i],
1481 mfc_regs->e_h264_aso_slice_order_0 + i * 4);
1487 /* Encode a single frame */
1488 static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
1490 struct s5p_mfc_dev *dev = ctx->dev;
1491 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1493 mfc_debug(2, "++\n");
1495 /* memory structure cur. frame */
1497 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1498 s5p_mfc_h264_set_aso_slice_order_v6(ctx);
1500 s5p_mfc_set_slice_mode(ctx);
1502 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1503 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1504 S5P_FIMV_CH_FRAME_START_V6, NULL);
1506 mfc_debug(2, "--\n");
1511 static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
1513 unsigned long flags;
1517 spin_lock_irqsave(&dev->condlock, flags);
1518 mfc_debug(2, "Previous context: %d (bits %08lx)\n", dev->curr_ctx,
1519 dev->ctx_work_bits);
1520 new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
1522 while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
1523 new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
1525 if (cnt > MFC_NUM_CONTEXTS) {
1526 /* No contexts to run */
1527 spin_unlock_irqrestore(&dev->condlock, flags);
1531 spin_unlock_irqrestore(&dev->condlock, flags);
1535 static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
1537 struct s5p_mfc_dev *dev = ctx->dev;
1538 struct s5p_mfc_buf *temp_vb;
1539 unsigned long flags;
1541 spin_lock_irqsave(&dev->irqlock, flags);
1543 /* Frames are being decoded */
1544 if (list_empty(&ctx->src_queue)) {
1545 mfc_debug(2, "No src buffers.\n");
1546 spin_unlock_irqrestore(&dev->irqlock, flags);
1549 /* Get the next source buffer */
1550 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1551 temp_vb->flags |= MFC_BUF_FLAG_USED;
1552 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1553 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
1554 spin_unlock_irqrestore(&dev->irqlock, flags);
1556 dev->curr_ctx = ctx->num;
1557 s5p_mfc_clean_ctx_int_flags(ctx);
1558 s5p_mfc_decode_one_frame_v6(ctx, 1);
1561 static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1563 struct s5p_mfc_dev *dev = ctx->dev;
1564 struct s5p_mfc_buf *temp_vb;
1565 unsigned long flags;
1568 if (ctx->state == MFCINST_FINISHING) {
1569 last_frame = MFC_DEC_LAST_FRAME;
1570 s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
1571 dev->curr_ctx = ctx->num;
1572 s5p_mfc_clean_ctx_int_flags(ctx);
1573 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1577 spin_lock_irqsave(&dev->irqlock, flags);
1578 /* Frames are being decoded */
1579 if (list_empty(&ctx->src_queue)) {
1580 mfc_debug(2, "No src buffers.\n");
1581 spin_unlock_irqrestore(&dev->irqlock, flags);
1584 /* Get the next source buffer */
1585 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1586 temp_vb->flags |= MFC_BUF_FLAG_USED;
1587 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1588 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
1589 ctx->consumed_stream,
1590 temp_vb->b->v4l2_planes[0].bytesused);
1591 spin_unlock_irqrestore(&dev->irqlock, flags);
1593 dev->curr_ctx = ctx->num;
1594 s5p_mfc_clean_ctx_int_flags(ctx);
1595 if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
1597 mfc_debug(2, "Setting ctx->state to FINISHING\n");
1598 ctx->state = MFCINST_FINISHING;
1600 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1605 static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
1607 struct s5p_mfc_dev *dev = ctx->dev;
1608 unsigned long flags;
1609 struct s5p_mfc_buf *dst_mb;
1610 struct s5p_mfc_buf *src_mb;
1611 unsigned long src_y_addr, src_c_addr, dst_addr;
1613 unsigned int src_y_size, src_c_size;
1615 unsigned int dst_size;
1617 spin_lock_irqsave(&dev->irqlock, flags);
1619 if (list_empty(&ctx->src_queue)) {
1620 mfc_debug(2, "no src buffers.\n");
1621 spin_unlock_irqrestore(&dev->irqlock, flags);
1625 if (list_empty(&ctx->dst_queue)) {
1626 mfc_debug(2, "no dst buffers.\n");
1627 spin_unlock_irqrestore(&dev->irqlock, flags);
1631 src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1632 src_mb->flags |= MFC_BUF_FLAG_USED;
1633 src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
1634 src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
1636 mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
1637 mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
1639 s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
1641 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1642 dst_mb->flags |= MFC_BUF_FLAG_USED;
1643 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1644 dst_size = vb2_plane_size(dst_mb->b, 0);
1646 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1648 spin_unlock_irqrestore(&dev->irqlock, flags);
1650 dev->curr_ctx = ctx->num;
1651 s5p_mfc_clean_ctx_int_flags(ctx);
1652 s5p_mfc_encode_one_frame_v6(ctx);
1657 static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
1659 struct s5p_mfc_dev *dev = ctx->dev;
1660 unsigned long flags;
1661 struct s5p_mfc_buf *temp_vb;
1663 /* Initializing decoding - parsing header */
1664 spin_lock_irqsave(&dev->irqlock, flags);
1665 mfc_debug(2, "Preparing to init decoding.\n");
1666 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1667 mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
1668 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1669 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
1670 temp_vb->b->v4l2_planes[0].bytesused);
1671 spin_unlock_irqrestore(&dev->irqlock, flags);
1672 dev->curr_ctx = ctx->num;
1673 s5p_mfc_clean_ctx_int_flags(ctx);
1674 s5p_mfc_init_decode_v6(ctx);
1677 static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
1679 struct s5p_mfc_dev *dev = ctx->dev;
1680 unsigned long flags;
1681 struct s5p_mfc_buf *dst_mb;
1682 unsigned long dst_addr;
1683 unsigned int dst_size;
1685 spin_lock_irqsave(&dev->irqlock, flags);
1687 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1688 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1689 dst_size = vb2_plane_size(dst_mb->b, 0);
1690 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1691 spin_unlock_irqrestore(&dev->irqlock, flags);
1692 dev->curr_ctx = ctx->num;
1693 s5p_mfc_clean_ctx_int_flags(ctx);
1694 s5p_mfc_init_encode_v6(ctx);
1697 static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
1699 struct s5p_mfc_dev *dev = ctx->dev;
1701 /* Header was parsed now start processing
1702 * First set the output frame buffers
1703 * s5p_mfc_alloc_dec_buffers(ctx); */
1705 if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
1706 mfc_err("It seems that not all destionation buffers were\n"
1707 "mmaped.MFC requires that all destination are mmaped\n"
1708 "before starting processing.\n");
1712 dev->curr_ctx = ctx->num;
1713 s5p_mfc_clean_ctx_int_flags(ctx);
1714 ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
1716 mfc_err("Failed to alloc frame mem.\n");
1717 ctx->state = MFCINST_ERROR;
1722 static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
1724 struct s5p_mfc_dev *dev = ctx->dev;
1727 dev->curr_ctx = ctx->num;
1728 s5p_mfc_clean_ctx_int_flags(ctx);
1729 ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
1731 mfc_err("Failed to alloc frame mem.\n");
1732 ctx->state = MFCINST_ERROR;
1737 /* Try running an operation on hardware */
1738 static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1740 struct s5p_mfc_ctx *ctx;
1742 unsigned int ret = 0;
1744 mfc_debug(1, "Try run dev: %p\n", dev);
1746 /* Check whether hardware is not running */
1747 if (test_and_set_bit(0, &dev->hw_lock) != 0) {
1748 /* This is perfectly ok, the scheduled ctx should wait */
1749 mfc_debug(1, "Couldn't lock HW.\n");
1753 /* Choose the context to run */
1754 new_ctx = s5p_mfc_get_new_ctx(dev);
1756 /* No contexts to run */
1757 if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
1758 mfc_err("Failed to unlock hardware.\n");
1762 mfc_debug(1, "No ctx is scheduled to be run.\n");
1766 mfc_debug(1, "New context: %d\n", new_ctx);
1767 ctx = dev->ctx[new_ctx];
1768 mfc_debug(1, "Seting new context to %p\n", ctx);
1769 /* Got context to run in ctx */
1770 mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
1771 ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
1772 mfc_debug(1, "ctx->state=%d\n", ctx->state);
1773 /* Last frame has already been sent to MFC
1774 * Now obtaining frames from MFC buffer */
1777 if (ctx->type == MFCINST_DECODER) {
1778 switch (ctx->state) {
1779 case MFCINST_FINISHING:
1780 s5p_mfc_run_dec_last_frames(ctx);
1782 case MFCINST_RUNNING:
1783 ret = s5p_mfc_run_dec_frame(ctx);
1786 s5p_mfc_clean_ctx_int_flags(ctx);
1787 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1790 case MFCINST_RETURN_INST:
1791 s5p_mfc_clean_ctx_int_flags(ctx);
1792 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1795 case MFCINST_GOT_INST:
1796 s5p_mfc_run_init_dec(ctx);
1798 case MFCINST_HEAD_PARSED:
1799 ret = s5p_mfc_run_init_dec_buffers(ctx);
1802 s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
1804 case MFCINST_RES_CHANGE_INIT:
1805 s5p_mfc_run_dec_last_frames(ctx);
1807 case MFCINST_RES_CHANGE_FLUSH:
1808 s5p_mfc_run_dec_last_frames(ctx);
1810 case MFCINST_RES_CHANGE_END:
1811 mfc_debug(2, "Finished remaining frames after resolution change.\n");
1812 ctx->capture_state = QUEUE_FREE;
1813 mfc_debug(2, "Will re-init the codec`.\n");
1814 s5p_mfc_run_init_dec(ctx);
1819 } else if (ctx->type == MFCINST_ENCODER) {
1820 switch (ctx->state) {
1821 case MFCINST_FINISHING:
1822 case MFCINST_RUNNING:
1823 ret = s5p_mfc_run_enc_frame(ctx);
1826 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1829 case MFCINST_RETURN_INST:
1830 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1833 case MFCINST_GOT_INST:
1834 s5p_mfc_run_init_enc(ctx);
1836 case MFCINST_HEAD_PRODUCED:
1837 ret = s5p_mfc_run_init_enc_buffers(ctx);
1843 mfc_err("invalid context type: %d\n", ctx->type);
1848 /* Free hardware lock */
1849 if (test_and_clear_bit(0, &dev->hw_lock) == 0)
1850 mfc_err("Failed to unlock hardware.\n");
1852 /* This is in deed imporant, as no operation has been
1853 * scheduled, reduce the clock count as no one will
1854 * ever do this, because no interrupt related to this try_run
1855 * will ever come from hardware. */
1856 s5p_mfc_clock_off();
1861 static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
1863 struct s5p_mfc_buf *b;
1866 while (!list_empty(lh)) {
1867 b = list_entry(lh->next, struct s5p_mfc_buf, list);
1868 for (i = 0; i < b->b->num_planes; i++)
1869 vb2_set_plane_payload(b->b, i, 0);
1870 vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
1875 static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
1877 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1878 WRITEL(0, mfc_regs->risc2host_command);
1879 WRITEL(0, mfc_regs->risc2host_int);
1882 static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1886 WRITEL(data, (void *)ofs);
1887 s5p_mfc_clock_off();
1891 s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
1896 ret = READL((void *)ofs);
1897 s5p_mfc_clock_off();
1902 static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
1904 return READL(dev->mfc_regs->d_display_first_plane_addr);
1907 static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
1909 return READL(dev->mfc_regs->d_decoded_first_plane_addr);
1912 static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
1914 return READL(dev->mfc_regs->d_display_status);
1917 static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
1919 return READL(dev->mfc_regs->d_decoded_status);
1922 static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
1924 return READL(dev->mfc_regs->d_decoded_frame_type) &
1925 S5P_FIMV_DECODE_FRAME_MASK_V6;
1928 static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
1930 struct s5p_mfc_dev *dev = ctx->dev;
1931 return READL(dev->mfc_regs->d_display_frame_type) &
1932 S5P_FIMV_DECODE_FRAME_MASK_V6;
1935 static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
1937 return READL(dev->mfc_regs->d_decoded_nal_size);
1940 static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
1942 return READL(dev->mfc_regs->risc2host_command) &
1943 S5P_FIMV_RISC2HOST_CMD_MASK;
1946 static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
1948 return READL(dev->mfc_regs->error_code);
1951 static int s5p_mfc_err_dec_v6(unsigned int err)
1953 return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
1956 static int s5p_mfc_err_dspl_v6(unsigned int err)
1958 return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
1961 static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
1963 return READL(dev->mfc_regs->d_display_frame_width);
1966 static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
1968 return READL(dev->mfc_regs->d_display_frame_height);
1971 static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
1973 return READL(dev->mfc_regs->d_min_num_dpb);
1976 static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
1978 return READL(dev->mfc_regs->d_min_num_mv);
1981 static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
1983 return READL(dev->mfc_regs->ret_instance_id);
1986 static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
1988 return READL(dev->mfc_regs->e_num_dpb);
1991 static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
1993 return READL(dev->mfc_regs->e_stream_size);
1996 static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
1998 return READL(dev->mfc_regs->e_slice_type);
2001 static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
2003 return READL(dev->mfc_regs->e_picture_count);
2006 static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
2008 struct s5p_mfc_dev *dev = ctx->dev;
2009 return READL(dev->mfc_regs->d_frame_pack_sei_avail);
2012 static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
2014 return READL(dev->mfc_regs->d_mvc_num_views);
2017 static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
2019 return READL(dev->mfc_regs->d_mvc_view_id);
2022 static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
2024 return s5p_mfc_read_info_v6(ctx,
2025 (unsigned int) ctx->dev->mfc_regs->d_ret_picture_tag_top);
2028 static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
2030 return s5p_mfc_read_info_v6(ctx,
2031 (unsigned int) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
2034 static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
2036 return s5p_mfc_read_info_v6(ctx,
2037 (unsigned int) ctx->dev->mfc_regs->d_display_crop_info1);
2040 static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
2042 return s5p_mfc_read_info_v6(ctx,
2043 (unsigned int) ctx->dev->mfc_regs->d_display_crop_info2);
2046 static struct s5p_mfc_regs mfc_regs;
2048 /* Initialize registers for MFC v6 onwards */
2049 const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
2051 memset(&mfc_regs, 0, sizeof(mfc_regs));
2053 #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
2054 #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
2055 /* codec common registers */
2056 R(risc_on, S5P_FIMV_RISC_ON_V6);
2057 R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
2058 R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
2059 R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
2060 R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
2061 R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
2062 R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
2063 R(firmware_version, S5P_FIMV_FW_VERSION_V6);
2064 R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
2065 R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
2066 R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
2067 R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
2068 R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
2069 R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
2070 R(error_code, S5P_FIMV_ERROR_CODE_V6);
2072 /* decoder registers */
2073 R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
2074 R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
2075 R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
2076 R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
2077 R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
2078 R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
2079 R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
2080 R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
2081 R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
2082 R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
2083 R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
2084 R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
2085 R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
2086 R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
2087 R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
2088 R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
2089 R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
2090 R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
2091 R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
2092 R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
2093 R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
2094 R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
2095 R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
2096 R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
2097 R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
2098 R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
2099 R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
2100 R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
2101 R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
2102 R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
2103 R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
2104 R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
2105 R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
2106 R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
2107 R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
2108 R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
2109 R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
2110 R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
2111 R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
2112 R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
2113 R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
2114 R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
2115 R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
2116 R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
2118 /* encoder registers */
2119 R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
2120 R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
2121 R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
2122 R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
2123 R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
2124 R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
2125 R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
2126 R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
2127 R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
2128 R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
2129 R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
2130 R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
2131 R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
2132 R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
2133 R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
2134 R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
2135 R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
2136 R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
2137 R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
2138 R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
2139 R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
2140 R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
2141 R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
2142 R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
2143 R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
2144 R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
2145 R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
2146 R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
2147 R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
2148 R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
2149 R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
2150 R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
2151 R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
2152 R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
2153 R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
2154 R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
2155 R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
2156 R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
2157 R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
2158 R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
2159 R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
2160 R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
2161 R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
2162 R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
2163 R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
2164 R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
2165 R(e_encoded_source_first_plane_addr,
2166 S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
2167 R(e_encoded_source_second_plane_addr,
2168 S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
2169 R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
2170 R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
2171 R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
2172 R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
2173 R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
2174 R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
2175 R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
2176 R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
2177 R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
2178 R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
2179 R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
2180 R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
2181 R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
2182 R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
2183 R(e_h264_fmo_slice_grp_map_type,
2184 S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
2185 R(e_h264_fmo_num_slice_grp_minus1,
2186 S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
2187 R(e_h264_fmo_slice_grp_change_dir,
2188 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
2189 R(e_h264_fmo_slice_grp_change_rate_minus1,
2190 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
2191 R(e_h264_fmo_run_length_minus1_0,
2192 S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
2193 R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
2194 R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
2195 R(e_h264_hierarchical_qp_layer0,
2196 S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
2197 R(e_h264_frame_packing_sei_info,
2198 S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
2200 if (!IS_MFCV7_PLUS(dev))
2203 /* Initialize registers used in MFC v7+ */
2204 R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
2205 R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
2206 R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
2207 R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
2208 R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
2209 R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
2210 R(e_encoded_source_first_plane_addr,
2211 S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
2212 R(e_encoded_source_second_plane_addr,
2213 S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
2214 R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
2219 /* Initialize registers used in MFC v8 only.
2220 * Also, over-write the registers which have
2221 * a different offset for MFC v8. */
2222 R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
2223 R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
2224 R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
2225 R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
2226 R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
2227 R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
2228 R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
2229 R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
2230 R(d_first_plane_dpb_stride_size,
2231 S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
2232 R(d_second_plane_dpb_stride_size,
2233 S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
2234 R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
2235 R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
2236 R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
2237 R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
2238 R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
2239 R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
2240 R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
2241 R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
2242 R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
2243 R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
2244 R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
2245 R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
2246 R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
2247 R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
2248 R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
2249 R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
2250 R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
2251 R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
2252 R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
2253 R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
2254 R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
2255 R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
2256 R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
2257 R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
2258 R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
2259 R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
2261 /* encoder registers */
2262 R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
2263 R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
2264 R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
2265 R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
2266 R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
2267 R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
2268 R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
2269 R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
2270 R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
2271 R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
2272 R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
2273 R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
2274 R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
2278 #undef S5P_MFC_REG_ADDR
2282 /* Initialize opr function pointers for MFC v6 */
2283 static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
2284 .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
2285 .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
2286 .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
2287 .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
2288 .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
2289 .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
2290 .alloc_dev_context_buffer =
2291 s5p_mfc_alloc_dev_context_buffer_v6,
2292 .release_dev_context_buffer =
2293 s5p_mfc_release_dev_context_buffer_v6,
2294 .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
2295 .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
2296 .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
2297 .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
2298 .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
2299 .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
2300 .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
2301 .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
2302 .init_decode = s5p_mfc_init_decode_v6,
2303 .init_encode = s5p_mfc_init_encode_v6,
2304 .encode_one_frame = s5p_mfc_encode_one_frame_v6,
2305 .try_run = s5p_mfc_try_run_v6,
2306 .cleanup_queue = s5p_mfc_cleanup_queue_v6,
2307 .clear_int_flags = s5p_mfc_clear_int_flags_v6,
2308 .write_info = s5p_mfc_write_info_v6,
2309 .read_info = s5p_mfc_read_info_v6,
2310 .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
2311 .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
2312 .get_dspl_status = s5p_mfc_get_dspl_status_v6,
2313 .get_dec_status = s5p_mfc_get_dec_status_v6,
2314 .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
2315 .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
2316 .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
2317 .get_int_reason = s5p_mfc_get_int_reason_v6,
2318 .get_int_err = s5p_mfc_get_int_err_v6,
2319 .err_dec = s5p_mfc_err_dec_v6,
2320 .err_dspl = s5p_mfc_err_dspl_v6,
2321 .get_img_width = s5p_mfc_get_img_width_v6,
2322 .get_img_height = s5p_mfc_get_img_height_v6,
2323 .get_dpb_count = s5p_mfc_get_dpb_count_v6,
2324 .get_mv_count = s5p_mfc_get_mv_count_v6,
2325 .get_inst_no = s5p_mfc_get_inst_no_v6,
2326 .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
2327 .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
2328 .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
2329 .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
2330 .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
2331 .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
2332 .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
2333 .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
2334 .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
2335 .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
2336 .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
2339 struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
2341 return &s5p_mfc_ops_v6;