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 #define IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
53 /* Allocate temporary buffers for decoding */
54 static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
61 /* Release temproary buffers for decoding */
62 static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
67 /* Allocate codec buffers */
68 static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
70 struct s5p_mfc_dev *dev = ctx->dev;
71 unsigned int mb_width, mb_height;
74 mb_width = MB_WIDTH(ctx->img_width);
75 mb_height = MB_HEIGHT(ctx->img_height);
77 if (ctx->type == MFCINST_DECODER) {
78 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
79 ctx->luma_size, ctx->chroma_size, ctx->mv_size);
80 mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
81 } else if (ctx->type == MFCINST_ENCODER) {
83 ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
84 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
85 S5P_FIMV_TMV_BUFFER_ALIGN_V6);
87 ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
88 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
89 S5P_FIMV_TMV_BUFFER_ALIGN_V6);
91 ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
92 S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
93 S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
94 ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
95 S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
96 S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
98 ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V8(
99 ctx->img_width, ctx->img_height,
100 mb_width, mb_height),
101 S5P_FIMV_ME_BUFFER_ALIGN_V6);
103 ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
104 ctx->img_width, ctx->img_height,
105 mb_width, mb_height),
106 S5P_FIMV_ME_BUFFER_ALIGN_V6);
108 mfc_debug(2, "recon luma size: %d chroma size: %d\n",
109 ctx->luma_dpb_size, ctx->chroma_dpb_size);
114 /* Codecs have different memory requirements */
115 switch (ctx->codec_mode) {
116 case S5P_MFC_CODEC_H264_DEC:
117 case S5P_MFC_CODEC_H264_MVC_DEC:
119 ctx->scratch_buf_size =
120 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(
124 ctx->scratch_buf_size =
125 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
128 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
129 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
131 ctx->scratch_buf_size +
132 (ctx->mv_count * ctx->mv_size);
134 case S5P_MFC_CODEC_MPEG4_DEC:
135 if (IS_MFCV7_PLUS(dev)) {
136 ctx->scratch_buf_size =
137 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
141 ctx->scratch_buf_size =
142 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
147 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
148 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
149 ctx->bank1.size = ctx->scratch_buf_size;
151 case S5P_MFC_CODEC_VC1RCV_DEC:
152 case S5P_MFC_CODEC_VC1_DEC:
153 ctx->scratch_buf_size =
154 S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
157 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
158 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
159 ctx->bank1.size = ctx->scratch_buf_size;
161 case S5P_MFC_CODEC_MPEG2_DEC:
165 case S5P_MFC_CODEC_H263_DEC:
166 ctx->scratch_buf_size =
167 S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
170 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
171 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
172 ctx->bank1.size = ctx->scratch_buf_size;
174 case S5P_MFC_CODEC_VP8_DEC:
176 ctx->scratch_buf_size =
177 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(
181 ctx->scratch_buf_size =
182 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
185 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
186 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
187 ctx->bank1.size = ctx->scratch_buf_size;
189 case S5P_MFC_CODEC_H264_ENC:
191 ctx->scratch_buf_size =
192 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(
196 ctx->scratch_buf_size =
197 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
200 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
201 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
203 ctx->scratch_buf_size + ctx->tmv_buffer_size +
204 (ctx->pb_count * (ctx->luma_dpb_size +
205 ctx->chroma_dpb_size + ctx->me_buffer_size));
208 case S5P_MFC_CODEC_MPEG4_ENC:
209 case S5P_MFC_CODEC_H263_ENC:
210 ctx->scratch_buf_size =
211 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
214 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
215 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
217 ctx->scratch_buf_size + ctx->tmv_buffer_size +
218 (ctx->pb_count * (ctx->luma_dpb_size +
219 ctx->chroma_dpb_size + ctx->me_buffer_size));
222 case S5P_MFC_CODEC_VP8_ENC:
224 ctx->scratch_buf_size =
225 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(
229 ctx->scratch_buf_size =
230 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
233 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
234 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
236 ctx->scratch_buf_size + ctx->tmv_buffer_size +
237 (ctx->pb_count * (ctx->luma_dpb_size +
238 ctx->chroma_dpb_size + ctx->me_buffer_size));
245 /* Allocate only if memory from bank 1 is necessary */
246 if (ctx->bank1.size > 0) {
247 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
249 mfc_err("Failed to allocate Bank1 memory\n");
252 BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
257 /* Release buffers allocated for codec */
258 static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
260 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
263 /* Allocate memory for instance data buffer */
264 static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
266 struct s5p_mfc_dev *dev = ctx->dev;
267 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
272 switch (ctx->codec_mode) {
273 case S5P_MFC_CODEC_H264_DEC:
274 case S5P_MFC_CODEC_H264_MVC_DEC:
275 ctx->ctx.size = buf_size->h264_dec_ctx;
277 case S5P_MFC_CODEC_MPEG4_DEC:
278 case S5P_MFC_CODEC_H263_DEC:
279 case S5P_MFC_CODEC_VC1RCV_DEC:
280 case S5P_MFC_CODEC_VC1_DEC:
281 case S5P_MFC_CODEC_MPEG2_DEC:
282 case S5P_MFC_CODEC_VP8_DEC:
283 ctx->ctx.size = buf_size->other_dec_ctx;
285 case S5P_MFC_CODEC_H264_ENC:
286 ctx->ctx.size = buf_size->h264_enc_ctx;
288 case S5P_MFC_CODEC_MPEG4_ENC:
289 case S5P_MFC_CODEC_H263_ENC:
290 case S5P_MFC_CODEC_VP8_ENC:
291 ctx->ctx.size = buf_size->other_enc_ctx;
295 mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
299 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
301 mfc_err("Failed to allocate instance buffer\n");
305 memset(ctx->ctx.virt, 0, ctx->ctx.size);
313 /* Release instance buffer */
314 static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
316 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
319 /* Allocate context buffers for SYS_INIT */
320 static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
322 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
327 dev->ctx_buf.size = buf_size->dev_ctx;
328 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
330 mfc_err("Failed to allocate device context buffer\n");
334 memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
342 /* Release context buffers for SYS_INIT */
343 static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
345 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
348 static int calc_plane(int width, int height)
352 mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
353 mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
355 if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
356 mbY = (mbY + 1) / 2 * 2;
358 return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
359 (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
362 static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
364 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
365 ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
366 mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
367 "buffer dimensions: %dx%d\n", ctx->img_width,
368 ctx->img_height, ctx->buf_width, ctx->buf_height);
370 ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
371 ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
372 if (IS_MFCV8(ctx->dev)) {
373 /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/
374 ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
375 ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
378 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
379 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
380 ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
382 ctx->mv_size = ALIGN(ctx->mv_size, 16);
388 static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
390 unsigned int mb_width, mb_height;
392 mb_width = MB_WIDTH(ctx->img_width);
393 mb_height = MB_HEIGHT(ctx->img_height);
395 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
396 ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
397 ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
399 /* MFCv7 needs pad bytes for Luma and Chroma */
400 if (IS_MFCV7_PLUS(ctx->dev)) {
401 ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
402 ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
406 /* Set registers for decoding stream buffer */
407 static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
408 int buf_addr, unsigned int start_num_byte,
409 unsigned int strm_size)
411 struct s5p_mfc_dev *dev = ctx->dev;
412 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
413 struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
416 mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
417 "buf_size: 0x%08x (%d)\n",
418 ctx->inst_no, buf_addr, strm_size, strm_size);
419 WRITEL(strm_size, mfc_regs->d_stream_data_size);
420 WRITEL(buf_addr, mfc_regs->d_cpb_buffer_addr);
421 WRITEL(buf_size->cpb, mfc_regs->d_cpb_buffer_size);
422 WRITEL(start_num_byte, mfc_regs->d_cpb_buffer_offset);
428 /* Set decoding frame buffer */
429 static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
431 unsigned int frame_size, i;
432 unsigned int frame_size_ch, frame_size_mv;
433 struct s5p_mfc_dev *dev = ctx->dev;
434 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
439 buf_addr1 = ctx->bank1.dma;
440 buf_size1 = ctx->bank1.size;
442 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
443 mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
444 mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
446 WRITEL(ctx->total_dpb_count, mfc_regs->d_num_dpb);
447 WRITEL(ctx->luma_size, mfc_regs->d_first_plane_dpb_size);
448 WRITEL(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size);
450 WRITEL(buf_addr1, mfc_regs->d_scratch_buffer_addr);
451 WRITEL(ctx->scratch_buf_size, mfc_regs->d_scratch_buffer_size);
454 WRITEL(ctx->img_width,
455 mfc_regs->d_first_plane_dpb_stride_size);
456 WRITEL(ctx->img_width,
457 mfc_regs->d_second_plane_dpb_stride_size);
460 buf_addr1 += ctx->scratch_buf_size;
461 buf_size1 -= ctx->scratch_buf_size;
463 if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
464 ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
465 WRITEL(ctx->mv_size, mfc_regs->d_mv_buffer_size);
466 WRITEL(ctx->mv_count, mfc_regs->d_num_mv);
469 frame_size = ctx->luma_size;
470 frame_size_ch = ctx->chroma_size;
471 frame_size_mv = ctx->mv_size;
472 mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
473 frame_size, frame_size_ch, frame_size_mv);
475 for (i = 0; i < ctx->total_dpb_count; i++) {
477 mfc_debug(2, "Luma %d: %x\n", i,
478 ctx->dst_bufs[i].cookie.raw.luma);
479 WRITEL(ctx->dst_bufs[i].cookie.raw.luma,
480 mfc_regs->d_first_plane_dpb + i * 4);
481 mfc_debug(2, "\tChroma %d: %x\n", i,
482 ctx->dst_bufs[i].cookie.raw.chroma);
483 WRITEL(ctx->dst_bufs[i].cookie.raw.chroma,
484 mfc_regs->d_second_plane_dpb + i * 4);
486 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
487 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
488 for (i = 0; i < ctx->mv_count; i++) {
489 /* To test alignment */
490 align_gap = buf_addr1;
491 buf_addr1 = ALIGN(buf_addr1, 16);
492 align_gap = buf_addr1 - align_gap;
493 buf_size1 -= align_gap;
495 mfc_debug(2, "\tBuf1: %x, size: %d\n",
496 buf_addr1, buf_size1);
497 WRITEL(buf_addr1, mfc_regs->d_mv_buffer + i * 4);
498 buf_addr1 += frame_size_mv;
499 buf_size1 -= frame_size_mv;
503 mfc_debug(2, "Buf1: %u, buf_size1: %d (frames %d)\n",
504 buf_addr1, buf_size1, ctx->total_dpb_count);
506 mfc_debug(2, "Not enough memory has been allocated.\n");
510 WRITEL(ctx->inst_no, mfc_regs->instance_id);
511 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
512 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
514 mfc_debug(2, "After setting buffers.\n");
518 /* Set registers for encoding stream buffer */
519 static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
520 unsigned long addr, unsigned int size)
522 struct s5p_mfc_dev *dev = ctx->dev;
523 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
525 WRITEL(addr, mfc_regs->e_stream_buffer_addr); /* 16B align */
526 WRITEL(size, mfc_regs->e_stream_buffer_size);
528 mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d\n",
534 static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
535 unsigned long y_addr, unsigned long c_addr)
537 struct s5p_mfc_dev *dev = ctx->dev;
538 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
540 WRITEL(y_addr, mfc_regs->e_source_first_plane_addr);
541 WRITEL(c_addr, mfc_regs->e_source_second_plane_addr);
543 mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr);
544 mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr);
547 static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
548 unsigned long *y_addr, unsigned long *c_addr)
550 struct s5p_mfc_dev *dev = ctx->dev;
551 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
552 unsigned long enc_recon_y_addr, enc_recon_c_addr;
554 *y_addr = READL(mfc_regs->e_encoded_source_first_plane_addr);
555 *c_addr = READL(mfc_regs->e_encoded_source_second_plane_addr);
557 enc_recon_y_addr = READL(mfc_regs->e_recon_luma_dpb_addr);
558 enc_recon_c_addr = READL(mfc_regs->e_recon_chroma_dpb_addr);
560 mfc_debug(2, "recon y addr: 0x%08lx\n", enc_recon_y_addr);
561 mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr);
564 /* Set encoding ref & codec buffer */
565 static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
567 struct s5p_mfc_dev *dev = ctx->dev;
568 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
574 buf_addr1 = ctx->bank1.dma;
575 buf_size1 = ctx->bank1.size;
577 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
579 for (i = 0; i < ctx->pb_count; i++) {
580 WRITEL(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
581 buf_addr1 += ctx->luma_dpb_size;
582 WRITEL(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
583 buf_addr1 += ctx->chroma_dpb_size;
584 WRITEL(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
585 buf_addr1 += ctx->me_buffer_size;
586 buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
587 ctx->me_buffer_size);
590 WRITEL(buf_addr1, mfc_regs->e_scratch_buffer_addr);
591 WRITEL(ctx->scratch_buf_size, mfc_regs->e_scratch_buffer_size);
592 buf_addr1 += ctx->scratch_buf_size;
593 buf_size1 -= ctx->scratch_buf_size;
595 WRITEL(buf_addr1, mfc_regs->e_tmv_buffer0);
596 buf_addr1 += ctx->tmv_buffer_size >> 1;
597 WRITEL(buf_addr1, mfc_regs->e_tmv_buffer1);
598 buf_addr1 += ctx->tmv_buffer_size >> 1;
599 buf_size1 -= ctx->tmv_buffer_size;
601 mfc_debug(2, "Buf1: %u, buf_size1: %d (ref frames %d)\n",
602 buf_addr1, buf_size1, ctx->pb_count);
604 mfc_debug(2, "Not enough memory has been allocated.\n");
608 WRITEL(ctx->inst_no, mfc_regs->instance_id);
609 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
610 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
617 static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
619 struct s5p_mfc_dev *dev = ctx->dev;
620 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
622 /* multi-slice control */
623 /* multi-slice MB number or bit size */
624 WRITEL(ctx->slice_mode, mfc_regs->e_mslice_mode);
625 if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
626 WRITEL(ctx->slice_size.mb, mfc_regs->e_mslice_size_mb);
627 } else if (ctx->slice_mode ==
628 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
629 WRITEL(ctx->slice_size.bits, mfc_regs->e_mslice_size_bits);
631 WRITEL(0x0, mfc_regs->e_mslice_size_mb);
632 WRITEL(0x0, mfc_regs->e_mslice_size_bits);
638 static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
640 struct s5p_mfc_dev *dev = ctx->dev;
641 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
642 struct s5p_mfc_enc_params *p = &ctx->enc_params;
643 unsigned int reg = 0;
648 WRITEL(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */
650 WRITEL(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */
653 WRITEL(ctx->img_width, mfc_regs->e_cropped_frame_width);
655 WRITEL(ctx->img_height, mfc_regs->e_cropped_frame_height);
657 WRITEL(0x0, mfc_regs->e_frame_crop_offset);
659 /* pictype : IDR period */
661 reg |= p->gop_size & 0xFFFF;
662 WRITEL(reg, mfc_regs->e_gop_config);
664 /* multi-slice control */
665 /* multi-slice MB number or bit size */
666 ctx->slice_mode = p->slice_mode;
668 if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
670 WRITEL(reg, mfc_regs->e_enc_options);
671 ctx->slice_size.mb = p->slice_mb;
672 } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
674 WRITEL(reg, mfc_regs->e_enc_options);
675 ctx->slice_size.bits = p->slice_bit;
678 WRITEL(reg, mfc_regs->e_enc_options);
681 s5p_mfc_set_slice_mode(ctx);
683 /* cyclic intra refresh */
684 WRITEL(p->intra_refresh_mb, mfc_regs->e_ir_size);
685 reg = READL(mfc_regs->e_enc_options);
686 if (p->intra_refresh_mb == 0)
690 WRITEL(reg, mfc_regs->e_enc_options);
692 /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
693 reg = READL(mfc_regs->e_enc_options);
695 WRITEL(reg, mfc_regs->e_enc_options);
697 /* memory structure cur. frame */
698 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
699 /* 0: Linear, 1: 2D tiled*/
700 reg = READL(mfc_regs->e_enc_options);
702 WRITEL(reg, mfc_regs->e_enc_options);
703 /* 0: NV12(CbCr), 1: NV21(CrCb) */
704 WRITEL(0x0, mfc_regs->pixel_format);
705 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
706 /* 0: Linear, 1: 2D tiled*/
707 reg = READL(mfc_regs->e_enc_options);
709 WRITEL(reg, mfc_regs->e_enc_options);
710 /* 0: NV12(CbCr), 1: NV21(CrCb) */
711 WRITEL(0x1, mfc_regs->pixel_format);
712 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
713 /* 0: Linear, 1: 2D tiled*/
714 reg = READL(mfc_regs->e_enc_options);
716 WRITEL(reg, mfc_regs->e_enc_options);
717 /* 0: NV12(CbCr), 1: NV21(CrCb) */
718 WRITEL(0x0, mfc_regs->pixel_format);
721 /* memory structure recon. frame */
722 /* 0: Linear, 1: 2D tiled */
723 reg = READL(mfc_regs->e_enc_options);
725 WRITEL(reg, mfc_regs->e_enc_options);
727 /* padding control & value */
728 WRITEL(0x0, mfc_regs->e_padding_ctrl);
734 reg |= ((p->pad_cr & 0xFF) << 16);
736 reg |= ((p->pad_cb & 0xFF) << 8);
738 reg |= p->pad_luma & 0xFF;
739 WRITEL(reg, mfc_regs->e_padding_ctrl);
742 /* rate control config. */
744 /* frame-level rate control */
745 reg |= ((p->rc_frame & 0x1) << 9);
746 WRITEL(reg, mfc_regs->e_rc_config);
750 WRITEL(p->rc_bitrate,
751 mfc_regs->e_rc_bit_rate);
753 WRITEL(1, mfc_regs->e_rc_bit_rate);
755 /* reaction coefficient */
757 if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
758 WRITEL(1, mfc_regs->e_rc_mode);
760 WRITEL(2, mfc_regs->e_rc_mode);
763 /* seq header ctrl */
764 reg = READL(mfc_regs->e_enc_options);
766 reg |= ((p->seq_hdr_mode & 0x1) << 2);
768 /* frame skip mode */
770 reg |= (p->frame_skip_mode & 0x3);
771 WRITEL(reg, mfc_regs->e_enc_options);
773 /* 'DROP_CONTROL_ENABLE', disable */
774 reg = READL(mfc_regs->e_rc_config);
776 WRITEL(reg, mfc_regs->e_rc_config);
778 /* setting for MV range [16, 256] */
779 reg = (p->mv_h_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
780 WRITEL(reg, mfc_regs->e_mv_hor_range);
782 reg = (p->mv_v_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
783 WRITEL(reg, mfc_regs->e_mv_ver_range);
785 WRITEL(0x0, mfc_regs->e_frame_insertion);
786 WRITEL(0x0, mfc_regs->e_roi_buffer_addr);
787 WRITEL(0x0, mfc_regs->e_param_change);
788 WRITEL(0x0, mfc_regs->e_rc_roi_ctrl);
789 WRITEL(0x0, mfc_regs->e_picture_tag);
791 WRITEL(0x0, mfc_regs->e_bit_count_enable);
792 WRITEL(0x0, mfc_regs->e_max_bit_count);
793 WRITEL(0x0, mfc_regs->e_min_bit_count);
795 WRITEL(0x0, mfc_regs->e_metadata_buffer_addr);
796 WRITEL(0x0, mfc_regs->e_metadata_buffer_size);
803 static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
805 struct s5p_mfc_dev *dev = ctx->dev;
806 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
807 struct s5p_mfc_enc_params *p = &ctx->enc_params;
808 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
809 unsigned int reg = 0;
814 s5p_mfc_set_enc_params(ctx);
816 /* pictype : number of B */
817 reg = READL(mfc_regs->e_gop_config);
819 reg |= ((p->num_b_frame & 0x3) << 16);
820 WRITEL(reg, mfc_regs->e_gop_config);
822 /* profile & level */
825 reg |= ((p_h264->level & 0xFF) << 8);
826 /** profile - 0 ~ 3 */
827 reg |= p_h264->profile & 0x3F;
828 WRITEL(reg, mfc_regs->e_picture_profile);
830 /* rate control config. */
831 reg = READL(mfc_regs->e_rc_config);
832 /** macroblock level rate control */
834 reg |= ((p->rc_mb & 0x1) << 8);
835 WRITEL(reg, mfc_regs->e_rc_config);
839 reg |= p_h264->rc_frame_qp & 0x3F;
840 WRITEL(reg, mfc_regs->e_rc_config);
842 /* max & min value of QP */
845 reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
847 reg |= p_h264->rc_min_qp & 0x3F;
848 WRITEL(reg, mfc_regs->e_rc_qp_bound);
851 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
852 if (!p->rc_frame && !p->rc_mb) {
854 reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
855 reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
856 reg |= p_h264->rc_frame_qp & 0x3F;
857 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
861 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
863 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
864 reg |= p->rc_framerate_denom & 0xFFFF;
865 WRITEL(reg, mfc_regs->e_rc_frame_rate);
868 /* vbv buffer size */
869 if (p->frame_skip_mode ==
870 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
871 WRITEL(p_h264->cpb_size & 0xFFFF,
872 mfc_regs->e_vbv_buffer_size);
875 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
880 reg |= ((p_h264->interlace & 0x1) << 3);
881 WRITEL(reg, mfc_regs->e_h264_options);
884 if (p_h264->interlace) {
885 WRITEL(ctx->img_height >> 1,
886 mfc_regs->e_frame_height); /* 32 align */
888 WRITEL(ctx->img_height >> 1,
889 mfc_regs->e_cropped_frame_height);
892 /* loop filter ctrl */
893 reg = READL(mfc_regs->e_h264_options);
895 reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
896 WRITEL(reg, mfc_regs->e_h264_options);
898 /* loopfilter alpha offset */
899 if (p_h264->loop_filter_alpha < 0) {
901 reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
904 reg |= (p_h264->loop_filter_alpha & 0xF);
906 WRITEL(reg, mfc_regs->e_h264_lf_alpha_offset);
908 /* loopfilter beta offset */
909 if (p_h264->loop_filter_beta < 0) {
911 reg |= (0xFF - p_h264->loop_filter_beta) + 1;
914 reg |= (p_h264->loop_filter_beta & 0xF);
916 WRITEL(reg, mfc_regs->e_h264_lf_beta_offset);
918 /* entropy coding mode */
919 reg = READL(mfc_regs->e_h264_options);
921 reg |= p_h264->entropy_mode & 0x1;
922 WRITEL(reg, mfc_regs->e_h264_options);
924 /* number of ref. picture */
925 reg = READL(mfc_regs->e_h264_options);
927 reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
928 WRITEL(reg, mfc_regs->e_h264_options);
930 /* 8x8 transform enable */
931 reg = READL(mfc_regs->e_h264_options);
933 reg |= ((p_h264->_8x8_transform & 0x3) << 12);
934 WRITEL(reg, mfc_regs->e_h264_options);
936 /* macroblock adaptive scaling features */
937 WRITEL(0x0, mfc_regs->e_mb_rc_config);
941 reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
943 reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
945 reg |= ((p_h264->rc_mb_static & 0x1) << 1);
946 /** high activity region */
947 reg |= p_h264->rc_mb_activity & 0x1;
948 WRITEL(reg, mfc_regs->e_mb_rc_config);
951 /* aspect ratio VUI */
952 READL(mfc_regs->e_h264_options);
954 reg |= ((p_h264->vui_sar & 0x1) << 5);
955 WRITEL(reg, mfc_regs->e_h264_options);
957 WRITEL(0x0, mfc_regs->e_aspect_ratio);
958 WRITEL(0x0, mfc_regs->e_extended_sar);
959 if (p_h264->vui_sar) {
960 /* aspect ration IDC */
962 reg |= p_h264->vui_sar_idc & 0xFF;
963 WRITEL(reg, mfc_regs->e_aspect_ratio);
964 if (p_h264->vui_sar_idc == 0xFF) {
967 reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
968 reg |= p_h264->vui_ext_sar_height & 0xFFFF;
969 WRITEL(reg, mfc_regs->e_extended_sar);
973 /* intra picture period for H.264 open GOP */
975 READL(mfc_regs->e_h264_options);
977 reg |= ((p_h264->open_gop & 0x1) << 4);
978 WRITEL(reg, mfc_regs->e_h264_options);
981 WRITEL(0x0, mfc_regs->e_h264_i_period);
982 if (p_h264->open_gop) {
984 reg |= p_h264->open_gop_size & 0xFFFF;
985 WRITEL(reg, mfc_regs->e_h264_i_period);
988 /* 'WEIGHTED_BI_PREDICTION' for B is disable */
989 READL(mfc_regs->e_h264_options);
991 WRITEL(reg, mfc_regs->e_h264_options);
993 /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
994 READL(mfc_regs->e_h264_options);
996 WRITEL(reg, mfc_regs->e_h264_options);
999 READL(mfc_regs->e_h264_options);
1001 reg |= ((p_h264->aso & 0x1) << 6);
1002 WRITEL(reg, mfc_regs->e_h264_options);
1004 /* hier qp enable */
1005 READL(mfc_regs->e_h264_options);
1007 reg |= ((p_h264->open_gop & 0x1) << 8);
1008 WRITEL(reg, mfc_regs->e_h264_options);
1010 if (p_h264->hier_qp && p_h264->hier_qp_layer) {
1011 reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
1012 reg |= p_h264->hier_qp_layer & 0x7;
1013 WRITEL(reg, mfc_regs->e_h264_num_t_layer);
1014 /* QP value for each layer */
1015 for (i = 0; i < p_h264->hier_qp_layer &&
1016 i < ARRAY_SIZE(p_h264->hier_qp_layer_qp); i++) {
1017 WRITEL(p_h264->hier_qp_layer_qp[i],
1018 mfc_regs->e_h264_hierarchical_qp_layer0
1022 /* number of coding layer should be zero when hierarchical is disable */
1023 WRITEL(reg, mfc_regs->e_h264_num_t_layer);
1025 /* frame packing SEI generation */
1026 READL(mfc_regs->e_h264_options);
1027 reg &= ~(0x1 << 25);
1028 reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
1029 WRITEL(reg, mfc_regs->e_h264_options);
1030 if (p_h264->sei_frame_packing) {
1032 /** current frame0 flag */
1033 reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
1034 /** arrangement type */
1035 reg |= p_h264->sei_fp_arrangement_type & 0x3;
1036 WRITEL(reg, mfc_regs->e_h264_frame_packing_sei_info);
1040 switch (p_h264->fmo_map_type) {
1041 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
1042 if (p_h264->fmo_slice_grp > 4)
1043 p_h264->fmo_slice_grp = 4;
1044 for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
1045 WRITEL(p_h264->fmo_run_len[i] - 1,
1046 mfc_regs->e_h264_fmo_run_length_minus1_0
1049 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
1050 if (p_h264->fmo_slice_grp > 4)
1051 p_h264->fmo_slice_grp = 4;
1053 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
1054 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
1055 if (p_h264->fmo_slice_grp > 2)
1056 p_h264->fmo_slice_grp = 2;
1057 WRITEL(p_h264->fmo_chg_dir & 0x1,
1058 mfc_regs->e_h264_fmo_slice_grp_change_dir);
1059 /* the valid range is 0 ~ number of macroblocks -1 */
1060 WRITEL(p_h264->fmo_chg_rate,
1061 mfc_regs->e_h264_fmo_slice_grp_change_rate_minus1);
1064 mfc_err("Unsupported map type for FMO: %d\n",
1065 p_h264->fmo_map_type);
1066 p_h264->fmo_map_type = 0;
1067 p_h264->fmo_slice_grp = 1;
1071 WRITEL(p_h264->fmo_map_type,
1072 mfc_regs->e_h264_fmo_slice_grp_map_type);
1073 WRITEL(p_h264->fmo_slice_grp - 1,
1074 mfc_regs->e_h264_fmo_num_slice_grp_minus1);
1076 WRITEL(0, mfc_regs->e_h264_fmo_num_slice_grp_minus1);
1084 static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
1086 struct s5p_mfc_dev *dev = ctx->dev;
1087 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1088 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1089 struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
1090 unsigned int reg = 0;
1094 s5p_mfc_set_enc_params(ctx);
1096 /* pictype : number of B */
1097 reg = READL(mfc_regs->e_gop_config);
1098 reg &= ~(0x3 << 16);
1099 reg |= ((p->num_b_frame & 0x3) << 16);
1100 WRITEL(reg, mfc_regs->e_gop_config);
1102 /* profile & level */
1105 reg |= ((p_mpeg4->level & 0xFF) << 8);
1106 /** profile - 0 ~ 1 */
1107 reg |= p_mpeg4->profile & 0x3F;
1108 WRITEL(reg, mfc_regs->e_picture_profile);
1110 /* rate control config. */
1111 reg = READL(mfc_regs->e_rc_config);
1112 /** macroblock level rate control */
1114 reg |= ((p->rc_mb & 0x1) << 8);
1115 WRITEL(reg, mfc_regs->e_rc_config);
1119 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1120 WRITEL(reg, mfc_regs->e_rc_config);
1122 /* max & min value of QP */
1125 reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
1127 reg |= p_mpeg4->rc_min_qp & 0x3F;
1128 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1131 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1132 if (!p->rc_frame && !p->rc_mb) {
1134 reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
1135 reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
1136 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1137 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1141 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1143 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1144 reg |= p->rc_framerate_denom & 0xFFFF;
1145 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1148 /* vbv buffer size */
1149 if (p->frame_skip_mode ==
1150 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1151 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1154 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1158 WRITEL(0x0, mfc_regs->e_mpeg4_options);
1159 WRITEL(0x0, mfc_regs->e_mpeg4_hec_period);
1166 static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
1168 struct s5p_mfc_dev *dev = ctx->dev;
1169 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1170 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1171 struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
1172 unsigned int reg = 0;
1176 s5p_mfc_set_enc_params(ctx);
1178 /* profile & level */
1182 WRITEL(reg, mfc_regs->e_picture_profile);
1184 /* rate control config. */
1185 reg = READL(mfc_regs->e_rc_config);
1186 /** macroblock level rate control */
1188 reg |= ((p->rc_mb & 0x1) << 8);
1189 WRITEL(reg, mfc_regs->e_rc_config);
1193 reg |= p_h263->rc_frame_qp & 0x3F;
1194 WRITEL(reg, mfc_regs->e_rc_config);
1196 /* max & min value of QP */
1199 reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
1201 reg |= p_h263->rc_min_qp & 0x3F;
1202 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1205 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1206 if (!p->rc_frame && !p->rc_mb) {
1208 reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
1209 reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
1210 reg |= p_h263->rc_frame_qp & 0x3F;
1211 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1215 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1217 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1218 reg |= p->rc_framerate_denom & 0xFFFF;
1219 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1222 /* vbv buffer size */
1223 if (p->frame_skip_mode ==
1224 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1225 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1228 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1236 static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx)
1238 struct s5p_mfc_dev *dev = ctx->dev;
1239 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1240 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1241 struct s5p_mfc_vp8_enc_params *p_vp8 = &p->codec.vp8;
1242 unsigned int reg = 0;
1243 unsigned int val = 0;
1247 s5p_mfc_set_enc_params(ctx);
1249 /* pictype : number of B */
1250 reg = READL(mfc_regs->e_gop_config);
1251 reg &= ~(0x3 << 16);
1252 reg |= ((p->num_b_frame & 0x3) << 16);
1253 WRITEL(reg, mfc_regs->e_gop_config);
1255 /* profile - 0 ~ 3 */
1256 reg = p_vp8->profile & 0x3;
1257 WRITEL(reg, mfc_regs->e_picture_profile);
1259 /* rate control config. */
1260 reg = READL(mfc_regs->e_rc_config);
1261 /** macroblock level rate control */
1263 reg |= ((p->rc_mb & 0x1) << 8);
1264 WRITEL(reg, mfc_regs->e_rc_config);
1267 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1269 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1270 reg |= p->rc_framerate_denom & 0xFFFF;
1271 WRITEL(reg, mfc_regs->e_rc_frame_rate);
1276 reg |= p_vp8->rc_frame_qp & 0x7F;
1277 WRITEL(reg, mfc_regs->e_rc_config);
1280 WRITEL(0x0, mfc_regs->e_fixed_picture_qp);
1281 if (!p->rc_frame && !p->rc_mb) {
1283 reg |= ((p_vp8->rc_p_frame_qp & 0x7F) << 8);
1284 reg |= p_vp8->rc_frame_qp & 0x7F;
1285 WRITEL(reg, mfc_regs->e_fixed_picture_qp);
1289 reg = ((p_vp8->rc_max_qp & 0x7F) << 8);
1291 reg |= p_vp8->rc_min_qp & 0x7F;
1292 WRITEL(reg, mfc_regs->e_rc_qp_bound);
1294 /* vbv buffer size */
1295 if (p->frame_skip_mode ==
1296 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1297 WRITEL(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
1300 WRITEL(p->vbv_delay, mfc_regs->e_vbv_init_delay);
1303 /* VP8 specific params */
1305 reg |= (p_vp8->imd_4x4 & 0x1) << 10;
1306 switch (p_vp8->num_partitions) {
1307 case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
1310 case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS:
1313 case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS:
1316 case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS:
1320 reg |= (val & 0xF) << 3;
1321 reg |= (p_vp8->num_ref & 0x2);
1322 WRITEL(reg, mfc_regs->e_vp8_options);
1329 /* Initialize decoding */
1330 static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1332 struct s5p_mfc_dev *dev = ctx->dev;
1333 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1334 unsigned int reg = 0;
1335 int fmo_aso_ctrl = 0;
1338 mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
1339 S5P_FIMV_CH_SEQ_HEADER_V6);
1340 mfc_debug(2, "BUFs: %08x %08x %08x\n",
1341 READL(mfc_regs->d_cpb_buffer_addr),
1342 READL(mfc_regs->d_cpb_buffer_addr),
1343 READL(mfc_regs->d_cpb_buffer_addr));
1345 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
1346 reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
1348 /* When user sets desplay_delay to 0,
1349 * It works as "display_delay enable" and delay set to 0.
1350 * If user wants display_delay disable, It should be
1351 * set to negative value. */
1352 if (ctx->display_delay >= 0) {
1353 reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
1354 WRITEL(ctx->display_delay, mfc_regs->d_display_delay);
1357 if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
1358 WRITEL(reg, mfc_regs->d_dec_options);
1362 /* Setup loop filter, for decoding this is only valid for MPEG4 */
1363 if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
1364 mfc_debug(2, "Set loop filter to: %d\n",
1365 ctx->loop_filter_mpeg4);
1366 reg |= (ctx->loop_filter_mpeg4 <<
1367 S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
1369 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
1370 reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
1372 if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
1373 WRITEL(reg, mfc_regs->d_init_buffer_options);
1375 WRITEL(reg, mfc_regs->d_dec_options);
1377 /* 0: NV12(CbCr), 1: NV21(CrCb) */
1378 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
1379 WRITEL(0x1, mfc_regs->pixel_format);
1381 WRITEL(0x0, mfc_regs->pixel_format);
1385 WRITEL(ctx->sei_fp_parse & 0x1, mfc_regs->d_sei_enable);
1387 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1388 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1389 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1395 static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1397 struct s5p_mfc_dev *dev = ctx->dev;
1398 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1401 dev->curr_ctx = ctx->num;
1402 s5p_mfc_clean_ctx_int_flags(ctx);
1403 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1404 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1405 S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
1409 /* Decode a single frame */
1410 static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
1411 enum s5p_mfc_decode_arg last_frame)
1413 struct s5p_mfc_dev *dev = ctx->dev;
1414 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1416 WRITEL(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower);
1417 WRITEL(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable);
1419 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1420 /* Issue different commands to instance basing on whether it
1421 * is the last frame or not. */
1422 switch (last_frame) {
1424 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1425 S5P_FIMV_CH_FRAME_START_V6, NULL);
1428 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1429 S5P_FIMV_CH_LAST_FRAME_V6, NULL);
1432 mfc_err("Unsupported last frame arg.\n");
1436 mfc_debug(2, "Decoding a usual frame.\n");
1440 static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
1442 struct s5p_mfc_dev *dev = ctx->dev;
1443 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1445 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1446 s5p_mfc_set_enc_params_h264(ctx);
1447 else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
1448 s5p_mfc_set_enc_params_mpeg4(ctx);
1449 else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
1450 s5p_mfc_set_enc_params_h263(ctx);
1451 else if (ctx->codec_mode == S5P_MFC_CODEC_VP8_ENC)
1452 s5p_mfc_set_enc_params_vp8(ctx);
1454 mfc_err("Unknown codec for encoding (%x).\n",
1459 /* Set stride lengths for v7 & above */
1460 if (IS_MFCV7_PLUS(dev)) {
1461 WRITEL(ctx->img_width, mfc_regs->e_source_first_plane_stride);
1462 WRITEL(ctx->img_width, mfc_regs->e_source_second_plane_stride);
1465 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1466 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1467 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1472 static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
1474 struct s5p_mfc_dev *dev = ctx->dev;
1475 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1476 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1477 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
1481 for (i = 0; i < ARRAY_SIZE(p_h264->aso_slice_order); i++) {
1482 WRITEL(p_h264->aso_slice_order[i],
1483 mfc_regs->e_h264_aso_slice_order_0 + i * 4);
1489 /* Encode a single frame */
1490 static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
1492 struct s5p_mfc_dev *dev = ctx->dev;
1493 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1495 mfc_debug(2, "++\n");
1497 /* memory structure cur. frame */
1499 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1500 s5p_mfc_h264_set_aso_slice_order_v6(ctx);
1502 s5p_mfc_set_slice_mode(ctx);
1504 WRITEL(ctx->inst_no, mfc_regs->instance_id);
1505 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1506 S5P_FIMV_CH_FRAME_START_V6, NULL);
1508 mfc_debug(2, "--\n");
1513 static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
1515 unsigned long flags;
1519 spin_lock_irqsave(&dev->condlock, flags);
1520 mfc_debug(2, "Previous context: %d (bits %08lx)\n", dev->curr_ctx,
1521 dev->ctx_work_bits);
1522 new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
1524 while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
1525 new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
1527 if (cnt > MFC_NUM_CONTEXTS) {
1528 /* No contexts to run */
1529 spin_unlock_irqrestore(&dev->condlock, flags);
1533 spin_unlock_irqrestore(&dev->condlock, flags);
1537 static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
1539 struct s5p_mfc_dev *dev = ctx->dev;
1540 struct s5p_mfc_buf *temp_vb;
1541 unsigned long flags;
1543 spin_lock_irqsave(&dev->irqlock, flags);
1545 /* Frames are being decoded */
1546 if (list_empty(&ctx->src_queue)) {
1547 mfc_debug(2, "No src buffers.\n");
1548 spin_unlock_irqrestore(&dev->irqlock, flags);
1551 /* Get the next source buffer */
1552 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1553 temp_vb->flags |= MFC_BUF_FLAG_USED;
1554 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1555 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
1556 spin_unlock_irqrestore(&dev->irqlock, flags);
1558 dev->curr_ctx = ctx->num;
1559 s5p_mfc_clean_ctx_int_flags(ctx);
1560 s5p_mfc_decode_one_frame_v6(ctx, 1);
1563 static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1565 struct s5p_mfc_dev *dev = ctx->dev;
1566 struct s5p_mfc_buf *temp_vb;
1567 unsigned long flags;
1570 if (ctx->state == MFCINST_FINISHING) {
1571 last_frame = MFC_DEC_LAST_FRAME;
1572 s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
1573 dev->curr_ctx = ctx->num;
1574 s5p_mfc_clean_ctx_int_flags(ctx);
1575 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1579 spin_lock_irqsave(&dev->irqlock, flags);
1580 /* Frames are being decoded */
1581 if (list_empty(&ctx->src_queue)) {
1582 mfc_debug(2, "No src buffers.\n");
1583 spin_unlock_irqrestore(&dev->irqlock, flags);
1586 /* Get the next source buffer */
1587 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1588 temp_vb->flags |= MFC_BUF_FLAG_USED;
1589 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1590 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
1591 ctx->consumed_stream,
1592 temp_vb->b->v4l2_planes[0].bytesused);
1593 spin_unlock_irqrestore(&dev->irqlock, flags);
1595 dev->curr_ctx = ctx->num;
1596 s5p_mfc_clean_ctx_int_flags(ctx);
1597 if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
1599 mfc_debug(2, "Setting ctx->state to FINISHING\n");
1600 ctx->state = MFCINST_FINISHING;
1602 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1607 static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
1609 struct s5p_mfc_dev *dev = ctx->dev;
1610 unsigned long flags;
1611 struct s5p_mfc_buf *dst_mb;
1612 struct s5p_mfc_buf *src_mb;
1613 unsigned long src_y_addr, src_c_addr, dst_addr;
1615 unsigned int src_y_size, src_c_size;
1617 unsigned int dst_size;
1619 spin_lock_irqsave(&dev->irqlock, flags);
1621 if (list_empty(&ctx->src_queue)) {
1622 mfc_debug(2, "no src buffers.\n");
1623 spin_unlock_irqrestore(&dev->irqlock, flags);
1627 if (list_empty(&ctx->dst_queue)) {
1628 mfc_debug(2, "no dst buffers.\n");
1629 spin_unlock_irqrestore(&dev->irqlock, flags);
1633 src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1634 src_mb->flags |= MFC_BUF_FLAG_USED;
1635 src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
1636 src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
1638 mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
1639 mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
1641 s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
1643 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1644 dst_mb->flags |= MFC_BUF_FLAG_USED;
1645 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1646 dst_size = vb2_plane_size(dst_mb->b, 0);
1648 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1650 spin_unlock_irqrestore(&dev->irqlock, flags);
1652 dev->curr_ctx = ctx->num;
1653 s5p_mfc_clean_ctx_int_flags(ctx);
1654 s5p_mfc_encode_one_frame_v6(ctx);
1659 static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
1661 struct s5p_mfc_dev *dev = ctx->dev;
1662 unsigned long flags;
1663 struct s5p_mfc_buf *temp_vb;
1665 /* Initializing decoding - parsing header */
1666 spin_lock_irqsave(&dev->irqlock, flags);
1667 mfc_debug(2, "Preparing to init decoding.\n");
1668 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1669 mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
1670 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1671 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
1672 temp_vb->b->v4l2_planes[0].bytesused);
1673 spin_unlock_irqrestore(&dev->irqlock, flags);
1674 dev->curr_ctx = ctx->num;
1675 s5p_mfc_clean_ctx_int_flags(ctx);
1676 s5p_mfc_init_decode_v6(ctx);
1679 static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
1681 struct s5p_mfc_dev *dev = ctx->dev;
1682 unsigned long flags;
1683 struct s5p_mfc_buf *dst_mb;
1684 unsigned long dst_addr;
1685 unsigned int dst_size;
1687 spin_lock_irqsave(&dev->irqlock, flags);
1689 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1690 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1691 dst_size = vb2_plane_size(dst_mb->b, 0);
1692 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1693 spin_unlock_irqrestore(&dev->irqlock, flags);
1694 dev->curr_ctx = ctx->num;
1695 s5p_mfc_clean_ctx_int_flags(ctx);
1696 s5p_mfc_init_encode_v6(ctx);
1699 static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
1701 struct s5p_mfc_dev *dev = ctx->dev;
1703 /* Header was parsed now start processing
1704 * First set the output frame buffers
1705 * s5p_mfc_alloc_dec_buffers(ctx); */
1707 if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
1708 mfc_err("It seems that not all destionation buffers were\n"
1709 "mmaped.MFC requires that all destination are mmaped\n"
1710 "before starting processing.\n");
1714 dev->curr_ctx = ctx->num;
1715 s5p_mfc_clean_ctx_int_flags(ctx);
1716 ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
1718 mfc_err("Failed to alloc frame mem.\n");
1719 ctx->state = MFCINST_ERROR;
1724 static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
1726 struct s5p_mfc_dev *dev = ctx->dev;
1729 dev->curr_ctx = ctx->num;
1730 s5p_mfc_clean_ctx_int_flags(ctx);
1731 ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
1733 mfc_err("Failed to alloc frame mem.\n");
1734 ctx->state = MFCINST_ERROR;
1739 /* Try running an operation on hardware */
1740 static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1742 struct s5p_mfc_ctx *ctx;
1744 unsigned int ret = 0;
1746 mfc_debug(1, "Try run dev: %p\n", dev);
1748 /* Check whether hardware is not running */
1749 if (test_and_set_bit(0, &dev->hw_lock) != 0) {
1750 /* This is perfectly ok, the scheduled ctx should wait */
1751 mfc_debug(1, "Couldn't lock HW.\n");
1755 /* Choose the context to run */
1756 new_ctx = s5p_mfc_get_new_ctx(dev);
1758 /* No contexts to run */
1759 if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
1760 mfc_err("Failed to unlock hardware.\n");
1764 mfc_debug(1, "No ctx is scheduled to be run.\n");
1768 mfc_debug(1, "New context: %d\n", new_ctx);
1769 ctx = dev->ctx[new_ctx];
1770 mfc_debug(1, "Seting new context to %p\n", ctx);
1771 /* Got context to run in ctx */
1772 mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
1773 ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
1774 mfc_debug(1, "ctx->state=%d\n", ctx->state);
1775 /* Last frame has already been sent to MFC
1776 * Now obtaining frames from MFC buffer */
1779 if (ctx->type == MFCINST_DECODER) {
1780 switch (ctx->state) {
1781 case MFCINST_FINISHING:
1782 s5p_mfc_run_dec_last_frames(ctx);
1784 case MFCINST_RUNNING:
1785 ret = s5p_mfc_run_dec_frame(ctx);
1788 s5p_mfc_clean_ctx_int_flags(ctx);
1789 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1792 case MFCINST_RETURN_INST:
1793 s5p_mfc_clean_ctx_int_flags(ctx);
1794 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1797 case MFCINST_GOT_INST:
1798 s5p_mfc_run_init_dec(ctx);
1800 case MFCINST_HEAD_PARSED:
1801 ret = s5p_mfc_run_init_dec_buffers(ctx);
1804 s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
1806 case MFCINST_RES_CHANGE_INIT:
1807 s5p_mfc_run_dec_last_frames(ctx);
1809 case MFCINST_RES_CHANGE_FLUSH:
1810 s5p_mfc_run_dec_last_frames(ctx);
1812 case MFCINST_RES_CHANGE_END:
1813 mfc_debug(2, "Finished remaining frames after resolution change.\n");
1814 ctx->capture_state = QUEUE_FREE;
1815 mfc_debug(2, "Will re-init the codec`.\n");
1816 s5p_mfc_run_init_dec(ctx);
1821 } else if (ctx->type == MFCINST_ENCODER) {
1822 switch (ctx->state) {
1823 case MFCINST_FINISHING:
1824 case MFCINST_RUNNING:
1825 ret = s5p_mfc_run_enc_frame(ctx);
1828 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1831 case MFCINST_RETURN_INST:
1832 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1835 case MFCINST_GOT_INST:
1836 s5p_mfc_run_init_enc(ctx);
1838 case MFCINST_HEAD_PRODUCED:
1839 ret = s5p_mfc_run_init_enc_buffers(ctx);
1845 mfc_err("invalid context type: %d\n", ctx->type);
1850 /* Free hardware lock */
1851 if (test_and_clear_bit(0, &dev->hw_lock) == 0)
1852 mfc_err("Failed to unlock hardware.\n");
1854 /* This is in deed imporant, as no operation has been
1855 * scheduled, reduce the clock count as no one will
1856 * ever do this, because no interrupt related to this try_run
1857 * will ever come from hardware. */
1858 s5p_mfc_clock_off();
1863 static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
1865 struct s5p_mfc_buf *b;
1868 while (!list_empty(lh)) {
1869 b = list_entry(lh->next, struct s5p_mfc_buf, list);
1870 for (i = 0; i < b->b->num_planes; i++)
1871 vb2_set_plane_payload(b->b, i, 0);
1872 vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
1877 static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
1879 const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
1880 WRITEL(0, mfc_regs->risc2host_command);
1881 WRITEL(0, mfc_regs->risc2host_int);
1884 static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1888 WRITEL(data, (void *)ofs);
1889 s5p_mfc_clock_off();
1893 s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
1898 ret = READL((void *)ofs);
1899 s5p_mfc_clock_off();
1904 static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
1906 return READL(dev->mfc_regs->d_display_first_plane_addr);
1909 static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
1911 return READL(dev->mfc_regs->d_decoded_first_plane_addr);
1914 static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
1916 return READL(dev->mfc_regs->d_display_status);
1919 static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
1921 return READL(dev->mfc_regs->d_decoded_status);
1924 static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
1926 return READL(dev->mfc_regs->d_decoded_frame_type) &
1927 S5P_FIMV_DECODE_FRAME_MASK_V6;
1930 static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
1932 struct s5p_mfc_dev *dev = ctx->dev;
1933 return READL(dev->mfc_regs->d_display_frame_type) &
1934 S5P_FIMV_DECODE_FRAME_MASK_V6;
1937 static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
1939 return READL(dev->mfc_regs->d_decoded_nal_size);
1942 static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
1944 return READL(dev->mfc_regs->risc2host_command) &
1945 S5P_FIMV_RISC2HOST_CMD_MASK;
1948 static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
1950 return READL(dev->mfc_regs->error_code);
1953 static int s5p_mfc_err_dec_v6(unsigned int err)
1955 return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
1958 static int s5p_mfc_err_dspl_v6(unsigned int err)
1960 return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
1963 static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
1965 return READL(dev->mfc_regs->d_display_frame_width);
1968 static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
1970 return READL(dev->mfc_regs->d_display_frame_height);
1973 static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
1975 return READL(dev->mfc_regs->d_min_num_dpb);
1978 static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
1980 return READL(dev->mfc_regs->d_min_num_mv);
1983 static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
1985 return READL(dev->mfc_regs->ret_instance_id);
1988 static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
1990 return READL(dev->mfc_regs->e_num_dpb);
1993 static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
1995 return READL(dev->mfc_regs->e_stream_size);
1998 static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
2000 return READL(dev->mfc_regs->e_slice_type);
2003 static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
2005 return READL(dev->mfc_regs->e_picture_count);
2008 static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
2010 struct s5p_mfc_dev *dev = ctx->dev;
2011 return READL(dev->mfc_regs->d_frame_pack_sei_avail);
2014 static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
2016 return READL(dev->mfc_regs->d_mvc_num_views);
2019 static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
2021 return READL(dev->mfc_regs->d_mvc_view_id);
2024 static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
2026 return s5p_mfc_read_info_v6(ctx,
2027 (unsigned int) ctx->dev->mfc_regs->d_ret_picture_tag_top);
2030 static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
2032 return s5p_mfc_read_info_v6(ctx,
2033 (unsigned int) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
2036 static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
2038 return s5p_mfc_read_info_v6(ctx,
2039 (unsigned int) ctx->dev->mfc_regs->d_display_crop_info1);
2042 static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
2044 return s5p_mfc_read_info_v6(ctx,
2045 (unsigned int) ctx->dev->mfc_regs->d_display_crop_info2);
2048 static struct s5p_mfc_regs mfc_regs;
2050 /* Initialize registers for MFC v6 onwards */
2051 const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
2053 memset(&mfc_regs, 0, sizeof(mfc_regs));
2055 #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
2056 #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
2057 /* codec common registers */
2058 R(risc_on, S5P_FIMV_RISC_ON_V6);
2059 R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
2060 R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
2061 R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
2062 R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
2063 R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
2064 R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
2065 R(firmware_version, S5P_FIMV_FW_VERSION_V6);
2066 R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
2067 R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
2068 R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
2069 R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
2070 R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
2071 R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
2072 R(error_code, S5P_FIMV_ERROR_CODE_V6);
2074 /* decoder registers */
2075 R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
2076 R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
2077 R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
2078 R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
2079 R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
2080 R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
2081 R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
2082 R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
2083 R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
2084 R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
2085 R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
2086 R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
2087 R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
2088 R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
2089 R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
2090 R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
2091 R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
2092 R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
2093 R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
2094 R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
2095 R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
2096 R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
2097 R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
2098 R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
2099 R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
2100 R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
2101 R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
2102 R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
2103 R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
2104 R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
2105 R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
2106 R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
2107 R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
2108 R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
2109 R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
2110 R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
2111 R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
2112 R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
2113 R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
2114 R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
2115 R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
2116 R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
2117 R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
2118 R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
2120 /* encoder registers */
2121 R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
2122 R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
2123 R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
2124 R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
2125 R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
2126 R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
2127 R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
2128 R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
2129 R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
2130 R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
2131 R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
2132 R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
2133 R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
2134 R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
2135 R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
2136 R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
2137 R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
2138 R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
2139 R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
2140 R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
2141 R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
2142 R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
2143 R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
2144 R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
2145 R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
2146 R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
2147 R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
2148 R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
2149 R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
2150 R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
2151 R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
2152 R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
2153 R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
2154 R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
2155 R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
2156 R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
2157 R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
2158 R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
2159 R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
2160 R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
2161 R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
2162 R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
2163 R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
2164 R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
2165 R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
2166 R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
2167 R(e_encoded_source_first_plane_addr,
2168 S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
2169 R(e_encoded_source_second_plane_addr,
2170 S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
2171 R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
2172 R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
2173 R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
2174 R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
2175 R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
2176 R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
2177 R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
2178 R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
2179 R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
2180 R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
2181 R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
2182 R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
2183 R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
2184 R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
2185 R(e_h264_fmo_slice_grp_map_type,
2186 S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
2187 R(e_h264_fmo_num_slice_grp_minus1,
2188 S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
2189 R(e_h264_fmo_slice_grp_change_dir,
2190 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
2191 R(e_h264_fmo_slice_grp_change_rate_minus1,
2192 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
2193 R(e_h264_fmo_run_length_minus1_0,
2194 S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
2195 R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
2196 R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
2197 R(e_h264_hierarchical_qp_layer0,
2198 S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
2199 R(e_h264_frame_packing_sei_info,
2200 S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
2202 if (!IS_MFCV7_PLUS(dev))
2205 /* Initialize registers used in MFC v7+ */
2206 R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
2207 R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
2208 R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
2209 R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
2210 R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
2211 R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
2212 R(e_encoded_source_first_plane_addr,
2213 S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
2214 R(e_encoded_source_second_plane_addr,
2215 S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
2216 R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
2221 /* Initialize registers used in MFC v8 only.
2222 * Also, over-write the registers which have
2223 * a different offset for MFC v8. */
2224 R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
2225 R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
2226 R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
2227 R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
2228 R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
2229 R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
2230 R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
2231 R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
2232 R(d_first_plane_dpb_stride_size,
2233 S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
2234 R(d_second_plane_dpb_stride_size,
2235 S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
2236 R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
2237 R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
2238 R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
2239 R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
2240 R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
2241 R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
2242 R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
2243 R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
2244 R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
2245 R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
2246 R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
2247 R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
2248 R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
2249 R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
2250 R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
2251 R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
2252 R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
2253 R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
2254 R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
2255 R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
2256 R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
2257 R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
2258 R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
2259 R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
2260 R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
2261 R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
2263 /* encoder registers */
2264 R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
2265 R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
2266 R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
2267 R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
2268 R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
2269 R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
2270 R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
2271 R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
2272 R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
2273 R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
2274 R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
2275 R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
2276 R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
2280 #undef S5P_MFC_REG_ADDR
2284 /* Initialize opr function pointers for MFC v6 */
2285 static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
2286 .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
2287 .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
2288 .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
2289 .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
2290 .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
2291 .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
2292 .alloc_dev_context_buffer =
2293 s5p_mfc_alloc_dev_context_buffer_v6,
2294 .release_dev_context_buffer =
2295 s5p_mfc_release_dev_context_buffer_v6,
2296 .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
2297 .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
2298 .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
2299 .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
2300 .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
2301 .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
2302 .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
2303 .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
2304 .init_decode = s5p_mfc_init_decode_v6,
2305 .init_encode = s5p_mfc_init_encode_v6,
2306 .encode_one_frame = s5p_mfc_encode_one_frame_v6,
2307 .try_run = s5p_mfc_try_run_v6,
2308 .cleanup_queue = s5p_mfc_cleanup_queue_v6,
2309 .clear_int_flags = s5p_mfc_clear_int_flags_v6,
2310 .write_info = s5p_mfc_write_info_v6,
2311 .read_info = s5p_mfc_read_info_v6,
2312 .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
2313 .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
2314 .get_dspl_status = s5p_mfc_get_dspl_status_v6,
2315 .get_dec_status = s5p_mfc_get_dec_status_v6,
2316 .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
2317 .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
2318 .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
2319 .get_int_reason = s5p_mfc_get_int_reason_v6,
2320 .get_int_err = s5p_mfc_get_int_err_v6,
2321 .err_dec = s5p_mfc_err_dec_v6,
2322 .err_dspl = s5p_mfc_err_dspl_v6,
2323 .get_img_width = s5p_mfc_get_img_width_v6,
2324 .get_img_height = s5p_mfc_get_img_height_v6,
2325 .get_dpb_count = s5p_mfc_get_dpb_count_v6,
2326 .get_mv_count = s5p_mfc_get_mv_count_v6,
2327 .get_inst_no = s5p_mfc_get_inst_no_v6,
2328 .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
2329 .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
2330 .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
2331 .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
2332 .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
2333 .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
2334 .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
2335 .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
2336 .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
2337 .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
2338 .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
2341 struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
2343 return &s5p_mfc_ops_v6;