2 * drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
4 * Samsung MFC (Multi Function Codec - FIMV) driver
5 * This file contains hw related functions.
7 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
8 * http://www.samsung.com/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
17 #include <linux/delay.h>
20 #include <linux/jiffies.h>
21 #include <linux/firmware.h>
22 #include <linux/err.h>
23 #include <linux/sched.h>
24 #include <linux/dma-mapping.h>
26 #include <asm/cacheflush.h>
28 #include "s5p_mfc_common.h"
29 #include "s5p_mfc_cmd.h"
30 #include "s5p_mfc_intr.h"
31 #include "s5p_mfc_pm.h"
32 #include "s5p_mfc_debug.h"
33 #include "s5p_mfc_opr.h"
34 #include "s5p_mfc_opr_v6.h"
36 /* #define S5P_MFC_DEBUG_REGWRITE */
37 #ifdef S5P_MFC_DEBUG_REGWRITE
39 #define writel(v, r) \
41 pr_err("MFCWRITE(%p): %08x\n", r, (unsigned int)v); \
44 #endif /* S5P_MFC_DEBUG_REGWRITE */
46 #define READL(offset) readl(dev->regs_base + (offset))
47 #define WRITEL(data, offset) writel((data), dev->regs_base + (offset))
48 #define OFFSETA(x) (((x) - dev->port_a) >> S5P_FIMV_MEM_OFFSET)
49 #define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET)
51 /* Allocate temporary buffers for decoding */
52 int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
59 /* Release temproary buffers for decoding */
60 void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
65 int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
71 /* Allocate codec buffers */
72 int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
74 struct s5p_mfc_dev *dev = ctx->dev;
75 unsigned int mb_width, mb_height;
78 mb_width = MB_WIDTH(ctx->img_width);
79 mb_height = MB_HEIGHT(ctx->img_height);
81 if (ctx->type == MFCINST_DECODER) {
82 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
83 ctx->luma_size, ctx->chroma_size, ctx->mv_size);
84 mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
85 } else if (ctx->type == MFCINST_ENCODER) {
86 ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
87 ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
88 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);
95 ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
96 ctx->img_width, ctx->img_height,
98 S5P_FIMV_ME_BUFFER_ALIGN_V6);
100 mfc_debug(2, "recon luma size: %d chroma size: %d\n",
101 ctx->luma_dpb_size, ctx->chroma_dpb_size);
106 /* Codecs have different memory requirements */
107 switch (ctx->codec_mode) {
108 case S5P_MFC_CODEC_H264_DEC:
109 case S5P_MFC_CODEC_H264_MVC_DEC:
110 ctx->scratch_buf_size =
111 S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
114 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
115 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
117 ctx->scratch_buf_size +
118 (ctx->mv_count * ctx->mv_size);
120 case S5P_MFC_CODEC_MPEG4_DEC:
121 ctx->scratch_buf_size =
122 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
125 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
126 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
127 ctx->bank1.size = ctx->scratch_buf_size;
129 case S5P_MFC_CODEC_VC1RCV_DEC:
130 case S5P_MFC_CODEC_VC1_DEC:
131 ctx->scratch_buf_size =
132 S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
135 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
136 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
137 ctx->bank1.size = ctx->scratch_buf_size;
139 case S5P_MFC_CODEC_MPEG2_DEC:
143 case S5P_MFC_CODEC_H263_DEC:
144 ctx->scratch_buf_size =
145 S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
148 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
149 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
150 ctx->bank1.size = ctx->scratch_buf_size;
152 case S5P_MFC_CODEC_VP8_DEC:
153 ctx->scratch_buf_size =
154 S5P_FIMV_SCRATCH_BUF_SIZE_VP8_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_H264_ENC:
162 ctx->scratch_buf_size =
163 S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
166 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
167 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
169 ctx->scratch_buf_size + ctx->tmv_buffer_size +
170 (ctx->dpb_count * (ctx->luma_dpb_size +
171 ctx->chroma_dpb_size + ctx->me_buffer_size));
174 case S5P_MFC_CODEC_MPEG4_ENC:
175 case S5P_MFC_CODEC_H263_ENC:
176 ctx->scratch_buf_size =
177 S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
180 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
181 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
183 ctx->scratch_buf_size + ctx->tmv_buffer_size +
184 (ctx->dpb_count * (ctx->luma_dpb_size +
185 ctx->chroma_dpb_size + ctx->me_buffer_size));
192 /* Allocate only if memory from bank 1 is necessary */
193 if (ctx->bank1.size > 0) {
194 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
196 mfc_err("Failed to allocate Bank1 memory\n");
199 BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
205 /* Release buffers allocated for codec */
206 void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
208 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
211 /* Allocate memory for instance data buffer */
212 int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
214 struct s5p_mfc_dev *dev = ctx->dev;
215 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
220 switch (ctx->codec_mode) {
221 case S5P_MFC_CODEC_H264_DEC:
222 case S5P_MFC_CODEC_H264_MVC_DEC:
223 ctx->ctx.size = buf_size->h264_dec_ctx;
225 case S5P_MFC_CODEC_MPEG4_DEC:
226 case S5P_MFC_CODEC_H263_DEC:
227 case S5P_MFC_CODEC_VC1RCV_DEC:
228 case S5P_MFC_CODEC_VC1_DEC:
229 case S5P_MFC_CODEC_MPEG2_DEC:
230 case S5P_MFC_CODEC_VP8_DEC:
231 ctx->ctx.size = buf_size->other_dec_ctx;
233 case S5P_MFC_CODEC_H264_ENC:
234 ctx->ctx.size = buf_size->h264_enc_ctx;
236 case S5P_MFC_CODEC_MPEG4_ENC:
237 case S5P_MFC_CODEC_H263_ENC:
238 ctx->ctx.size = buf_size->other_enc_ctx;
242 mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
246 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
248 mfc_err("Failed to allocate instance buffer\n");
252 memset(ctx->ctx.virt, 0, ctx->ctx.size);
260 /* Release instance buffer */
261 void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
263 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
266 /* Allocate context buffers for SYS_INIT */
267 int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
269 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
274 dev->ctx_buf.size = buf_size->dev_ctx;
275 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
277 mfc_err("Failed to allocate device context buffer\n");
281 memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
289 /* Release context buffers for SYS_INIT */
290 void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
292 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
295 static int calc_plane(int width, int height)
299 mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
300 mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
302 if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
303 mbY = (mbY + 1) / 2 * 2;
305 return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
306 (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
309 void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
311 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
312 ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
313 mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
314 "buffer dimensions: %dx%d\n", ctx->img_width,
315 ctx->img_height, ctx->buf_width, ctx->buf_height);
317 ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
318 ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
319 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
320 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
321 ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
323 ctx->mv_size = ALIGN(ctx->mv_size, 16);
329 void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
331 unsigned int mb_width, mb_height;
333 mb_width = MB_WIDTH(ctx->img_width);
334 mb_height = MB_HEIGHT(ctx->img_height);
336 ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
337 ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
338 ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
341 /* Set registers for decoding stream buffer */
342 int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, int buf_addr,
343 unsigned int start_num_byte, unsigned int strm_size)
345 struct s5p_mfc_dev *dev = ctx->dev;
346 struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
349 mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
350 "buf_size: 0x%08x (%d)\n",
351 ctx->inst_no, buf_addr, strm_size, strm_size);
352 WRITEL(strm_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
353 WRITEL(buf_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
354 WRITEL(buf_size->cpb, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
355 WRITEL(start_num_byte, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
361 /* Set decoding frame buffer */
362 int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
364 unsigned int frame_size, i;
365 unsigned int frame_size_ch, frame_size_mv;
366 struct s5p_mfc_dev *dev = ctx->dev;
371 buf_addr1 = ctx->bank1.dma;
372 buf_size1 = ctx->bank1.size;
374 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
375 mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
376 mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
378 WRITEL(ctx->total_dpb_count, S5P_FIMV_D_NUM_DPB_V6);
379 WRITEL(ctx->luma_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
380 WRITEL(ctx->chroma_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
382 WRITEL(buf_addr1, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
383 WRITEL(ctx->scratch_buf_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
384 buf_addr1 += ctx->scratch_buf_size;
385 buf_size1 -= ctx->scratch_buf_size;
387 if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
388 ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
389 WRITEL(ctx->mv_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
390 WRITEL(ctx->mv_count, S5P_FIMV_D_NUM_MV_V6);
393 frame_size = ctx->luma_size;
394 frame_size_ch = ctx->chroma_size;
395 frame_size_mv = ctx->mv_size;
396 mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
397 frame_size, frame_size_ch, frame_size_mv);
399 for (i = 0; i < ctx->total_dpb_count; i++) {
401 mfc_debug(2, "Luma %d: %x\n", i,
402 ctx->dst_bufs[i].cookie.raw.luma);
403 WRITEL(ctx->dst_bufs[i].cookie.raw.luma,
404 S5P_FIMV_D_LUMA_DPB_V6 + i * 4);
405 mfc_debug(2, "\tChroma %d: %x\n", i,
406 ctx->dst_bufs[i].cookie.raw.chroma);
407 WRITEL(ctx->dst_bufs[i].cookie.raw.chroma,
408 S5P_FIMV_D_CHROMA_DPB_V6 + i * 4);
410 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
411 ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
412 for (i = 0; i < ctx->mv_count; i++) {
413 /* To test alignment */
414 align_gap = buf_addr1;
415 buf_addr1 = ALIGN(buf_addr1, 16);
416 align_gap = buf_addr1 - align_gap;
417 buf_size1 -= align_gap;
419 mfc_debug(2, "\tBuf1: %x, size: %d\n",
420 buf_addr1, buf_size1);
421 WRITEL(buf_addr1, S5P_FIMV_D_MV_BUFFER_V6 + i * 4);
422 buf_addr1 += frame_size_mv;
423 buf_size1 -= frame_size_mv;
427 mfc_debug(2, "Buf1: %u, buf_size1: %d (frames %d)\n",
428 buf_addr1, buf_size1, ctx->total_dpb_count);
430 mfc_debug(2, "Not enough memory has been allocated.\n");
434 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
435 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
436 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
438 mfc_debug(2, "After setting buffers.\n");
442 /* Set registers for encoding stream buffer */
443 int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
444 unsigned long addr, unsigned int size)
446 struct s5p_mfc_dev *dev = ctx->dev;
448 WRITEL(addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6); /* 16B align */
449 WRITEL(size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
451 mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d",
457 void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
458 unsigned long y_addr, unsigned long c_addr)
460 struct s5p_mfc_dev *dev = ctx->dev;
462 WRITEL(y_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6); /* 256B align */
463 WRITEL(c_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
465 mfc_debug(2, "enc src y buf addr: 0x%08lx", y_addr);
466 mfc_debug(2, "enc src c buf addr: 0x%08lx", c_addr);
469 void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
470 unsigned long *y_addr, unsigned long *c_addr)
472 struct s5p_mfc_dev *dev = ctx->dev;
473 unsigned long enc_recon_y_addr, enc_recon_c_addr;
475 *y_addr = READL(S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
476 *c_addr = READL(S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
478 enc_recon_y_addr = READL(S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
479 enc_recon_c_addr = READL(S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
481 mfc_debug(2, "recon y addr: 0x%08lx", enc_recon_y_addr);
482 mfc_debug(2, "recon c addr: 0x%08lx", enc_recon_c_addr);
485 /* Set encoding ref & codec buffer */
486 int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
488 struct s5p_mfc_dev *dev = ctx->dev;
494 buf_addr1 = ctx->bank1.dma;
495 buf_size1 = ctx->bank1.size;
497 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
499 for (i = 0; i < ctx->dpb_count; i++) {
500 WRITEL(buf_addr1, S5P_FIMV_E_LUMA_DPB_V6 + (4 * i));
501 buf_addr1 += ctx->luma_dpb_size;
502 WRITEL(buf_addr1, S5P_FIMV_E_CHROMA_DPB_V6 + (4 * i));
503 buf_addr1 += ctx->chroma_dpb_size;
504 WRITEL(buf_addr1, S5P_FIMV_E_ME_BUFFER_V6 + (4 * i));
505 buf_addr1 += ctx->me_buffer_size;
506 buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
507 ctx->me_buffer_size);
510 WRITEL(buf_addr1, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
511 WRITEL(ctx->scratch_buf_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
512 buf_addr1 += ctx->scratch_buf_size;
513 buf_size1 -= ctx->scratch_buf_size;
515 WRITEL(buf_addr1, S5P_FIMV_E_TMV_BUFFER0_V6);
516 buf_addr1 += ctx->tmv_buffer_size >> 1;
517 WRITEL(buf_addr1, S5P_FIMV_E_TMV_BUFFER1_V6);
518 buf_addr1 += ctx->tmv_buffer_size >> 1;
519 buf_size1 -= ctx->tmv_buffer_size;
521 mfc_debug(2, "Buf1: %u, buf_size1: %d (ref frames %d)\n",
522 buf_addr1, buf_size1, ctx->dpb_count);
524 mfc_debug(2, "Not enough memory has been allocated.\n");
528 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
529 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
530 S5P_FIMV_CH_INIT_BUFS_V6, NULL);
537 static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
539 struct s5p_mfc_dev *dev = ctx->dev;
541 /* multi-slice control */
542 /* multi-slice MB number or bit size */
543 WRITEL(ctx->slice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
544 if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
545 WRITEL(ctx->slice_size.mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
546 } else if (ctx->slice_mode ==
547 V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
548 WRITEL(ctx->slice_size.bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
550 WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
551 WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
557 static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
559 struct s5p_mfc_dev *dev = ctx->dev;
560 struct s5p_mfc_enc_params *p = &ctx->enc_params;
561 unsigned int reg = 0;
566 WRITEL(ctx->img_width, S5P_FIMV_E_FRAME_WIDTH_V6); /* 16 align */
568 WRITEL(ctx->img_height, S5P_FIMV_E_FRAME_HEIGHT_V6); /* 16 align */
571 WRITEL(ctx->img_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
573 WRITEL(ctx->img_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
575 WRITEL(0x0, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
577 /* pictype : IDR period */
579 reg |= p->gop_size & 0xFFFF;
580 WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
582 /* multi-slice control */
583 /* multi-slice MB number or bit size */
584 ctx->slice_mode = p->slice_mode;
586 if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
588 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
589 ctx->slice_size.mb = p->slice_mb;
590 } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
592 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
593 ctx->slice_size.bits = p->slice_bit;
596 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
599 s5p_mfc_set_slice_mode(ctx);
601 /* cyclic intra refresh */
602 WRITEL(p->intra_refresh_mb, S5P_FIMV_E_IR_SIZE_V6);
603 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
604 if (p->intra_refresh_mb == 0)
608 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
610 /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
611 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
613 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
615 /* memory structure cur. frame */
616 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
617 /* 0: Linear, 1: 2D tiled*/
618 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
620 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
621 /* 0: NV12(CbCr), 1: NV21(CrCb) */
622 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
623 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
624 /* 0: Linear, 1: 2D tiled*/
625 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
627 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
628 /* 0: NV12(CbCr), 1: NV21(CrCb) */
629 WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6);
630 } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
631 /* 0: Linear, 1: 2D tiled*/
632 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
634 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
635 /* 0: NV12(CbCr), 1: NV21(CrCb) */
636 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
639 /* memory structure recon. frame */
640 /* 0: Linear, 1: 2D tiled */
641 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
643 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
645 /* padding control & value */
646 WRITEL(0x0, S5P_FIMV_E_PADDING_CTRL_V6);
652 reg |= ((p->pad_cr & 0xFF) << 16);
654 reg |= ((p->pad_cb & 0xFF) << 8);
656 reg |= p->pad_luma & 0xFF;
657 WRITEL(reg, S5P_FIMV_E_PADDING_CTRL_V6);
660 /* rate control config. */
662 /* frame-level rate control */
663 reg |= ((p->rc_frame & 0x1) << 9);
664 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
668 WRITEL(p->rc_bitrate,
669 S5P_FIMV_E_RC_BIT_RATE_V6);
671 WRITEL(1, S5P_FIMV_E_RC_BIT_RATE_V6);
673 /* reaction coefficient */
675 if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
676 WRITEL(1, S5P_FIMV_E_RC_RPARAM_V6);
678 WRITEL(2, S5P_FIMV_E_RC_RPARAM_V6);
681 /* seq header ctrl */
682 reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
684 reg |= ((p->seq_hdr_mode & 0x1) << 2);
686 /* frame skip mode */
688 reg |= (p->frame_skip_mode & 0x3);
689 WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
691 /* 'DROP_CONTROL_ENABLE', disable */
692 reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
694 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
696 /* setting for MV range [16, 256] */
700 WRITEL(reg, S5P_FIMV_E_MV_HOR_RANGE_V6);
705 WRITEL(reg, S5P_FIMV_E_MV_VER_RANGE_V6);
707 WRITEL(0x0, S5P_FIMV_E_FRAME_INSERTION_V6);
708 WRITEL(0x0, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
709 WRITEL(0x0, S5P_FIMV_E_PARAM_CHANGE_V6);
710 WRITEL(0x0, S5P_FIMV_E_RC_ROI_CTRL_V6);
711 WRITEL(0x0, S5P_FIMV_E_PICTURE_TAG_V6);
713 WRITEL(0x0, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
714 WRITEL(0x0, S5P_FIMV_E_MAX_BIT_COUNT_V6);
715 WRITEL(0x0, S5P_FIMV_E_MIN_BIT_COUNT_V6);
717 WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
718 WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
725 static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
727 struct s5p_mfc_dev *dev = ctx->dev;
728 struct s5p_mfc_enc_params *p = &ctx->enc_params;
729 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
730 unsigned int reg = 0;
735 s5p_mfc_set_enc_params(ctx);
737 /* pictype : number of B */
738 reg = READL(S5P_FIMV_E_GOP_CONFIG_V6);
740 reg |= ((p->num_b_frame & 0x3) << 16);
741 WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
743 /* profile & level */
746 reg |= ((p_h264->level & 0xFF) << 8);
747 /** profile - 0 ~ 3 */
748 reg |= p_h264->profile & 0x3F;
749 WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
751 /* rate control config. */
752 reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
753 /** macroblock level rate control */
755 reg |= ((p->rc_mb & 0x1) << 8);
756 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
759 reg |= p_h264->rc_frame_qp & 0x3F;
760 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
762 /* max & min value of QP */
765 reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
767 reg |= p_h264->rc_min_qp & 0x3F;
768 WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
771 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
772 if (!p->rc_frame && !p->rc_mb) {
774 reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
775 reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
776 reg |= p_h264->rc_frame_qp & 0x3F;
777 WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
781 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
783 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
784 reg |= p->rc_framerate_denom & 0xFFFF;
785 WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
788 /* vbv buffer size */
789 if (p->frame_skip_mode ==
790 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
791 WRITEL(p_h264->cpb_size & 0xFFFF,
792 S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
795 WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
800 reg |= ((p_h264->interlace & 0x1) << 3);
801 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
804 if (p_h264->interlace) {
805 WRITEL(ctx->img_height >> 1,
806 S5P_FIMV_E_FRAME_HEIGHT_V6); /* 32 align */
808 WRITEL(ctx->img_height >> 1,
809 S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
812 /* loop filter ctrl */
813 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
815 reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
816 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
818 /* loopfilter alpha offset */
819 if (p_h264->loop_filter_alpha < 0) {
821 reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
824 reg |= (p_h264->loop_filter_alpha & 0xF);
826 WRITEL(reg, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
828 /* loopfilter beta offset */
829 if (p_h264->loop_filter_beta < 0) {
831 reg |= (0xFF - p_h264->loop_filter_beta) + 1;
834 reg |= (p_h264->loop_filter_beta & 0xF);
836 WRITEL(reg, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
838 /* entropy coding mode */
839 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
841 reg |= p_h264->entropy_mode & 0x1;
842 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
844 /* number of ref. picture */
845 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
847 reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
848 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
850 /* 8x8 transform enable */
851 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
853 reg |= ((p_h264->_8x8_transform & 0x3) << 12);
854 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
856 /* macroblock adaptive scaling features */
857 WRITEL(0x0, S5P_FIMV_E_MB_RC_CONFIG_V6);
861 reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
863 reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
865 reg |= ((p_h264->rc_mb_static & 0x1) << 1);
866 /** high activity region */
867 reg |= p_h264->rc_mb_activity & 0x1;
868 WRITEL(reg, S5P_FIMV_E_MB_RC_CONFIG_V6);
871 /* aspect ratio VUI */
872 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
874 reg |= ((p_h264->vui_sar & 0x1) << 5);
875 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
877 WRITEL(0x0, S5P_FIMV_E_ASPECT_RATIO_V6);
878 WRITEL(0x0, S5P_FIMV_E_EXTENDED_SAR_V6);
879 if (p_h264->vui_sar) {
880 /* aspect ration IDC */
882 reg |= p_h264->vui_sar_idc & 0xFF;
883 WRITEL(reg, S5P_FIMV_E_ASPECT_RATIO_V6);
884 if (p_h264->vui_sar_idc == 0xFF) {
887 reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
888 reg |= p_h264->vui_ext_sar_height & 0xFFFF;
889 WRITEL(reg, S5P_FIMV_E_EXTENDED_SAR_V6);
893 /* intra picture period for H.264 open GOP */
895 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
897 reg |= ((p_h264->open_gop & 0x1) << 4);
898 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
900 WRITEL(0x0, S5P_FIMV_E_H264_I_PERIOD_V6);
901 if (p_h264->open_gop) {
903 reg |= p_h264->open_gop_size & 0xFFFF;
904 WRITEL(reg, S5P_FIMV_E_H264_I_PERIOD_V6);
907 /* 'WEIGHTED_BI_PREDICTION' for B is disable */
908 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
910 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
912 /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
913 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
915 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
918 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
920 reg |= ((p_h264->aso & 0x1) << 6);
921 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
924 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
926 reg |= ((p_h264->open_gop & 0x1) << 8);
927 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
929 if (p_h264->hier_qp && p_h264->hier_qp_layer) {
930 reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
931 reg |= p_h264->hier_qp_layer & 0x7;
932 WRITEL(reg, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
933 /* QP value for each layer */
934 for (i = 0; i < (p_h264->hier_qp_layer & 0x7); i++)
935 WRITEL(p_h264->hier_qp_layer_qp[i],
936 S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6 +
939 /* number of coding layer should be zero when hierarchical is disable */
940 WRITEL(reg, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
942 /* frame packing SEI generation */
943 reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
945 reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
946 WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
947 if (p_h264->sei_frame_packing) {
949 /** current frame0 flag */
950 reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
951 /** arrangement type */
952 reg |= p_h264->sei_fp_arrangement_type & 0x3;
953 WRITEL(reg, S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
957 switch (p_h264->fmo_map_type) {
958 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
959 if (p_h264->fmo_slice_grp > 4)
960 p_h264->fmo_slice_grp = 4;
961 for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
962 WRITEL(p_h264->fmo_run_len[i] - 1,
963 S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6 +
966 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
967 if (p_h264->fmo_slice_grp > 4)
968 p_h264->fmo_slice_grp = 4;
970 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
971 case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
972 if (p_h264->fmo_slice_grp > 2)
973 p_h264->fmo_slice_grp = 2;
974 WRITEL(p_h264->fmo_chg_dir & 0x1,
975 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
976 /* the valid range is 0 ~ number of macroblocks -1 */
977 WRITEL(p_h264->fmo_chg_rate,
978 S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
981 mfc_err("Unsupported map type for FMO: %d\n",
982 p_h264->fmo_map_type);
983 p_h264->fmo_map_type = 0;
984 p_h264->fmo_slice_grp = 1;
988 WRITEL(p_h264->fmo_map_type,
989 S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
990 WRITEL(p_h264->fmo_slice_grp - 1,
991 S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
993 WRITEL(0, S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
1001 static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
1003 struct s5p_mfc_dev *dev = ctx->dev;
1004 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1005 struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
1006 unsigned int reg = 0;
1010 s5p_mfc_set_enc_params(ctx);
1012 /* pictype : number of B */
1013 reg = READL(S5P_FIMV_E_GOP_CONFIG_V6);
1014 reg &= ~(0x3 << 16);
1015 reg |= ((p->num_b_frame & 0x3) << 16);
1016 WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
1018 /* profile & level */
1021 reg |= ((p_mpeg4->level & 0xFF) << 8);
1022 /** profile - 0 ~ 1 */
1023 reg |= p_mpeg4->profile & 0x3F;
1024 WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
1026 /* rate control config. */
1027 reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
1028 /** macroblock level rate control */
1030 reg |= ((p->rc_mb & 0x1) << 8);
1031 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
1034 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1035 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
1037 /* max & min value of QP */
1040 reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
1042 reg |= p_mpeg4->rc_min_qp & 0x3F;
1043 WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
1046 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
1047 if (!p->rc_frame && !p->rc_mb) {
1049 reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
1050 reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
1051 reg |= p_mpeg4->rc_frame_qp & 0x3F;
1052 WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
1056 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1058 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1059 reg |= p->rc_framerate_denom & 0xFFFF;
1060 WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
1063 /* vbv buffer size */
1064 if (p->frame_skip_mode ==
1065 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1066 WRITEL(p->vbv_size & 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
1069 WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
1073 WRITEL(0x0, S5P_FIMV_E_MPEG4_OPTIONS_V6);
1074 WRITEL(0x0, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
1081 static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
1083 struct s5p_mfc_dev *dev = ctx->dev;
1084 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1085 struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
1086 unsigned int reg = 0;
1090 s5p_mfc_set_enc_params(ctx);
1092 /* profile & level */
1096 WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
1098 /* rate control config. */
1099 reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
1100 /** macroblock level rate control */
1102 reg |= ((p->rc_mb & 0x1) << 8);
1103 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
1106 reg |= p_h263->rc_frame_qp & 0x3F;
1107 WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
1109 /* max & min value of QP */
1112 reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
1114 reg |= p_h263->rc_min_qp & 0x3F;
1115 WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
1118 WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
1119 if (!p->rc_frame && !p->rc_mb) {
1121 reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
1122 reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
1123 reg |= p_h263->rc_frame_qp & 0x3F;
1124 WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
1128 if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
1130 reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
1131 reg |= p->rc_framerate_denom & 0xFFFF;
1132 WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
1135 /* vbv buffer size */
1136 if (p->frame_skip_mode ==
1137 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
1138 WRITEL(p->vbv_size & 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
1141 WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
1149 /* Initialize decoding */
1150 int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1152 struct s5p_mfc_dev *dev = ctx->dev;
1153 unsigned int reg = 0;
1154 int fmo_aso_ctrl = 0;
1157 mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
1158 S5P_FIMV_CH_SEQ_HEADER_V6);
1159 mfc_debug(2, "BUFs: %08x %08x %08x\n",
1160 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6),
1161 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6),
1162 READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6));
1164 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
1165 reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
1167 /* When user sets desplay_delay to 0,
1168 * It works as "display_delay enable" and delay set to 0.
1169 * If user wants display_delay disable, It should be
1170 * set to negative value. */
1171 if (ctx->display_delay >= 0) {
1172 reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
1173 WRITEL(ctx->display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
1175 /* Setup loop filter, for decoding this is only valid for MPEG4 */
1176 if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
1177 mfc_debug(2, "Set loop filter to: %d\n",
1178 ctx->loop_filter_mpeg4);
1179 reg |= (ctx->loop_filter_mpeg4 <<
1180 S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
1182 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
1183 reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
1185 WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
1187 /* 0: NV12(CbCr), 1: NV21(CrCb) */
1188 if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
1189 WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6);
1191 WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
1194 WRITEL(ctx->sei_fp_parse & 0x1, S5P_FIMV_D_SEI_ENABLE_V6);
1196 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1197 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1198 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1204 static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1206 struct s5p_mfc_dev *dev = ctx->dev;
1209 dev->curr_ctx = ctx->num;
1210 s5p_mfc_clean_ctx_int_flags(ctx);
1211 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1212 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1213 S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
1217 /* Decode a single frame */
1218 int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
1219 enum s5p_mfc_decode_arg last_frame)
1221 struct s5p_mfc_dev *dev = ctx->dev;
1223 WRITEL(ctx->dec_dst_flag, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
1224 WRITEL(ctx->slice_interface & 0x1, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
1226 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1227 /* Issue different commands to instance basing on whether it
1228 * is the last frame or not. */
1229 switch (last_frame) {
1231 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1232 S5P_FIMV_CH_FRAME_START_V6, NULL);
1235 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1236 S5P_FIMV_CH_LAST_FRAME_V6, NULL);
1239 mfc_err("Unsupported last frame arg.\n");
1243 mfc_debug(2, "Decoding a usual frame.\n");
1247 int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
1249 struct s5p_mfc_dev *dev = ctx->dev;
1251 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1252 s5p_mfc_set_enc_params_h264(ctx);
1253 else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
1254 s5p_mfc_set_enc_params_mpeg4(ctx);
1255 else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
1256 s5p_mfc_set_enc_params_h263(ctx);
1258 mfc_err("Unknown codec for encoding (%x).\n",
1263 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1264 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1265 S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
1270 int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
1272 struct s5p_mfc_dev *dev = ctx->dev;
1273 struct s5p_mfc_enc_params *p = &ctx->enc_params;
1274 struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
1278 for (i = 0; i < 8; i++)
1279 WRITEL(p_h264->aso_slice_order[i],
1280 S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6 + i * 4);
1285 /* Encode a single frame */
1286 int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
1288 struct s5p_mfc_dev *dev = ctx->dev;
1290 mfc_debug(2, "++\n");
1292 /* memory structure cur. frame */
1294 if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
1295 s5p_mfc_h264_set_aso_slice_order_v6(ctx);
1297 s5p_mfc_set_slice_mode(ctx);
1299 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1300 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1301 S5P_FIMV_CH_FRAME_START_V6, NULL);
1303 mfc_debug(2, "--\n");
1308 static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
1310 unsigned long flags;
1314 spin_lock_irqsave(&dev->condlock, flags);
1315 mfc_debug(2, "Previos context: %d (bits %08lx)\n", dev->curr_ctx,
1316 dev->ctx_work_bits);
1317 new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
1319 while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
1320 new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
1322 if (cnt > MFC_NUM_CONTEXTS) {
1323 /* No contexts to run */
1324 spin_unlock_irqrestore(&dev->condlock, flags);
1328 spin_unlock_irqrestore(&dev->condlock, flags);
1332 static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
1334 struct s5p_mfc_dev *dev = ctx->dev;
1335 struct s5p_mfc_buf *temp_vb;
1336 unsigned long flags;
1338 spin_lock_irqsave(&dev->irqlock, flags);
1340 /* Frames are being decoded */
1341 if (list_empty(&ctx->src_queue)) {
1342 mfc_debug(2, "No src buffers.\n");
1343 spin_unlock_irqrestore(&dev->irqlock, flags);
1346 /* Get the next source buffer */
1347 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1348 temp_vb->flags |= MFC_BUF_FLAG_USED;
1349 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1350 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
1351 spin_unlock_irqrestore(&dev->irqlock, flags);
1353 dev->curr_ctx = ctx->num;
1354 s5p_mfc_clean_ctx_int_flags(ctx);
1355 s5p_mfc_decode_one_frame_v6(ctx, 1);
1358 static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1360 struct s5p_mfc_dev *dev = ctx->dev;
1361 struct s5p_mfc_buf *temp_vb;
1362 unsigned long flags;
1365 spin_lock_irqsave(&dev->irqlock, flags);
1367 /* Frames are being decoded */
1368 if (list_empty(&ctx->src_queue)) {
1369 mfc_debug(2, "No src buffers.\n");
1370 spin_unlock_irqrestore(&dev->irqlock, flags);
1373 /* Get the next source buffer */
1374 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1375 temp_vb->flags |= MFC_BUF_FLAG_USED;
1376 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1377 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
1378 ctx->consumed_stream,
1379 temp_vb->b->v4l2_planes[0].bytesused);
1380 spin_unlock_irqrestore(&dev->irqlock, flags);
1382 dev->curr_ctx = ctx->num;
1383 s5p_mfc_clean_ctx_int_flags(ctx);
1384 if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
1386 mfc_debug(2, "Setting ctx->state to FINISHING\n");
1387 ctx->state = MFCINST_FINISHING;
1389 s5p_mfc_decode_one_frame_v6(ctx, last_frame);
1394 static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
1396 struct s5p_mfc_dev *dev = ctx->dev;
1397 unsigned long flags;
1398 struct s5p_mfc_buf *dst_mb;
1399 struct s5p_mfc_buf *src_mb;
1400 unsigned long src_y_addr, src_c_addr, dst_addr;
1402 unsigned int src_y_size, src_c_size;
1404 unsigned int dst_size;
1406 spin_lock_irqsave(&dev->irqlock, flags);
1408 if (list_empty(&ctx->src_queue)) {
1409 mfc_debug(2, "no src buffers.\n");
1410 spin_unlock_irqrestore(&dev->irqlock, flags);
1414 if (list_empty(&ctx->dst_queue)) {
1415 mfc_debug(2, "no dst buffers.\n");
1416 spin_unlock_irqrestore(&dev->irqlock, flags);
1420 src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1421 src_mb->flags |= MFC_BUF_FLAG_USED;
1422 src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
1423 src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
1425 mfc_debug(2, "enc src y addr: 0x%08lx", src_y_addr);
1426 mfc_debug(2, "enc src c addr: 0x%08lx", src_c_addr);
1428 s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
1430 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1431 dst_mb->flags |= MFC_BUF_FLAG_USED;
1432 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1433 dst_size = vb2_plane_size(dst_mb->b, 0);
1435 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1437 spin_unlock_irqrestore(&dev->irqlock, flags);
1439 dev->curr_ctx = ctx->num;
1440 s5p_mfc_clean_ctx_int_flags(ctx);
1441 s5p_mfc_encode_one_frame_v6(ctx);
1446 static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
1448 struct s5p_mfc_dev *dev = ctx->dev;
1449 unsigned long flags;
1450 struct s5p_mfc_buf *temp_vb;
1452 /* Initializing decoding - parsing header */
1453 spin_lock_irqsave(&dev->irqlock, flags);
1454 mfc_debug(2, "Preparing to init decoding.\n");
1455 temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
1456 mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
1457 s5p_mfc_set_dec_stream_buffer_v6(ctx,
1458 vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
1459 temp_vb->b->v4l2_planes[0].bytesused);
1460 spin_unlock_irqrestore(&dev->irqlock, flags);
1461 dev->curr_ctx = ctx->num;
1462 s5p_mfc_clean_ctx_int_flags(ctx);
1463 s5p_mfc_init_decode_v6(ctx);
1466 static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
1468 struct s5p_mfc_dev *dev = ctx->dev;
1469 unsigned long flags;
1470 struct s5p_mfc_buf *dst_mb;
1471 unsigned long dst_addr;
1472 unsigned int dst_size;
1474 spin_lock_irqsave(&dev->irqlock, flags);
1476 dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
1477 dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
1478 dst_size = vb2_plane_size(dst_mb->b, 0);
1479 s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
1480 spin_unlock_irqrestore(&dev->irqlock, flags);
1481 dev->curr_ctx = ctx->num;
1482 s5p_mfc_clean_ctx_int_flags(ctx);
1483 s5p_mfc_init_encode_v6(ctx);
1486 static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
1488 struct s5p_mfc_dev *dev = ctx->dev;
1490 /* Header was parsed now start processing
1491 * First set the output frame buffers
1492 * s5p_mfc_alloc_dec_buffers(ctx); */
1494 if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
1495 mfc_err("It seems that not all destionation buffers were\n"
1496 "mmaped.MFC requires that all destination are mmaped\n"
1497 "before starting processing.\n");
1501 dev->curr_ctx = ctx->num;
1502 s5p_mfc_clean_ctx_int_flags(ctx);
1503 ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
1505 mfc_err("Failed to alloc frame mem.\n");
1506 ctx->state = MFCINST_ERROR;
1511 static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
1513 struct s5p_mfc_dev *dev = ctx->dev;
1516 ret = s5p_mfc_alloc_codec_buffers_v6(ctx);
1518 mfc_err("Failed to allocate encoding buffers.\n");
1522 /* Header was generated now starting processing
1523 * First set the reference frame buffers
1525 if (ctx->capture_state != QUEUE_BUFS_REQUESTED) {
1526 mfc_err("It seems that destionation buffers were not\n"
1527 "requested.MFC requires that header should be generated\n"
1528 "before allocating codec buffer.\n");
1532 dev->curr_ctx = ctx->num;
1533 s5p_mfc_clean_ctx_int_flags(ctx);
1534 ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
1536 mfc_err("Failed to alloc frame mem.\n");
1537 ctx->state = MFCINST_ERROR;
1542 /* Try running an operation on hardware */
1543 void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1545 struct s5p_mfc_ctx *ctx;
1547 unsigned int ret = 0;
1549 mfc_debug(1, "Try run dev: %p\n", dev);
1551 /* Check whether hardware is not running */
1552 if (test_and_set_bit(0, &dev->hw_lock) != 0) {
1553 /* This is perfectly ok, the scheduled ctx should wait */
1554 mfc_debug(1, "Couldn't lock HW.\n");
1558 /* Choose the context to run */
1559 new_ctx = s5p_mfc_get_new_ctx(dev);
1561 /* No contexts to run */
1562 if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
1563 mfc_err("Failed to unlock hardware.\n");
1567 mfc_debug(1, "No ctx is scheduled to be run.\n");
1571 mfc_debug(1, "New context: %d\n", new_ctx);
1572 ctx = dev->ctx[new_ctx];
1573 mfc_debug(1, "Seting new context to %p\n", ctx);
1574 /* Got context to run in ctx */
1575 mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
1576 ctx->dst_queue_cnt, ctx->dpb_count, ctx->src_queue_cnt);
1577 mfc_debug(1, "ctx->state=%d\n", ctx->state);
1578 /* Last frame has already been sent to MFC
1579 * Now obtaining frames from MFC buffer */
1582 if (ctx->type == MFCINST_DECODER) {
1583 switch (ctx->state) {
1584 case MFCINST_FINISHING:
1585 s5p_mfc_run_dec_last_frames(ctx);
1587 case MFCINST_RUNNING:
1588 ret = s5p_mfc_run_dec_frame(ctx);
1591 s5p_mfc_clean_ctx_int_flags(ctx);
1592 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1595 case MFCINST_RETURN_INST:
1596 s5p_mfc_clean_ctx_int_flags(ctx);
1597 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1600 case MFCINST_GOT_INST:
1601 s5p_mfc_run_init_dec(ctx);
1603 case MFCINST_HEAD_PARSED:
1604 ret = s5p_mfc_run_init_dec_buffers(ctx);
1607 s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
1609 case MFCINST_RES_CHANGE_INIT:
1610 s5p_mfc_run_dec_last_frames(ctx);
1612 case MFCINST_RES_CHANGE_FLUSH:
1613 s5p_mfc_run_dec_last_frames(ctx);
1615 case MFCINST_RES_CHANGE_END:
1616 mfc_debug(2, "Finished remaining frames after resolution change.\n");
1617 ctx->capture_state = QUEUE_FREE;
1618 mfc_debug(2, "Will re-init the codec`.\n");
1619 s5p_mfc_run_init_dec(ctx);
1624 } else if (ctx->type == MFCINST_ENCODER) {
1625 switch (ctx->state) {
1626 case MFCINST_FINISHING:
1627 case MFCINST_RUNNING:
1628 ret = s5p_mfc_run_enc_frame(ctx);
1631 ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
1634 case MFCINST_RETURN_INST:
1635 ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
1638 case MFCINST_GOT_INST:
1639 s5p_mfc_run_init_enc(ctx);
1641 case MFCINST_HEAD_PARSED: /* Only for MFC6.x */
1642 ret = s5p_mfc_run_init_enc_buffers(ctx);
1648 mfc_err("invalid context type: %d\n", ctx->type);
1653 /* Free hardware lock */
1654 if (test_and_clear_bit(0, &dev->hw_lock) == 0)
1655 mfc_err("Failed to unlock hardware.\n");
1657 /* This is in deed imporant, as no operation has been
1658 * scheduled, reduce the clock count as no one will
1659 * ever do this, because no interrupt related to this try_run
1660 * will ever come from hardware. */
1661 s5p_mfc_clock_off();
1666 void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
1668 struct s5p_mfc_buf *b;
1671 while (!list_empty(lh)) {
1672 b = list_entry(lh->next, struct s5p_mfc_buf, list);
1673 for (i = 0; i < b->b->num_planes; i++)
1674 vb2_set_plane_payload(b->b, i, 0);
1675 vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
1680 void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
1682 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD_V6);
1683 mfc_write(dev, 0, S5P_FIMV_RISC2HOST_INT_V6);
1686 void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
1689 struct s5p_mfc_dev *dev = ctx->dev;
1693 s5p_mfc_clock_off();
1696 unsigned int s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
1698 struct s5p_mfc_dev *dev = ctx->dev;
1703 s5p_mfc_clock_off();
1708 int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
1710 return mfc_read(dev, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
1713 int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
1715 return mfc_read(dev, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
1718 int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
1720 return mfc_read(dev, S5P_FIMV_D_DISPLAY_STATUS_V6);
1723 int s5p_mfc_get_decoded_status_v6(struct s5p_mfc_dev *dev)
1725 return mfc_read(dev, S5P_FIMV_D_DECODED_STATUS_V6);
1728 int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
1730 return mfc_read(dev, S5P_FIMV_D_DECODED_FRAME_TYPE_V6) &
1731 S5P_FIMV_DECODE_FRAME_MASK_V6;
1734 int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
1736 return mfc_read(ctx->dev, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6) &
1737 S5P_FIMV_DECODE_FRAME_MASK_V6;
1740 int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
1742 return mfc_read(dev, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
1745 int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
1747 return mfc_read(dev, S5P_FIMV_RISC2HOST_CMD_V6) &
1748 S5P_FIMV_RISC2HOST_CMD_MASK;
1751 int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
1753 return mfc_read(dev, S5P_FIMV_ERROR_CODE_V6);
1756 int s5p_mfc_err_dec_v6(unsigned int err)
1758 return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
1761 int s5p_mfc_err_dspl_v6(unsigned int err)
1763 return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
1766 int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
1768 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
1771 int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
1773 return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
1776 int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
1778 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_DPB_V6);
1781 int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
1783 return mfc_read(dev, S5P_FIMV_D_MIN_NUM_MV_V6);
1786 int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
1788 return mfc_read(dev, S5P_FIMV_RET_INSTANCE_ID_V6);
1791 int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
1793 return mfc_read(dev, S5P_FIMV_E_NUM_DPB_V6);
1796 int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
1798 return mfc_read(dev, S5P_FIMV_E_STREAM_SIZE_V6);
1801 int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
1803 return mfc_read(dev, S5P_FIMV_E_SLICE_TYPE_V6);
1806 int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
1808 return mfc_read(dev, S5P_FIMV_E_PICTURE_COUNT_V6);
1811 int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
1813 return mfc_read(ctx->dev, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
1816 int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
1818 return mfc_read(dev, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
1821 int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
1823 return mfc_read(dev, S5P_FIMV_D_MVC_VIEW_ID_V6);
1826 unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
1828 return s5p_mfc_read_info_v6(ctx, PIC_TIME_TOP_V6);
1831 unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
1833 return s5p_mfc_read_info_v6(ctx, PIC_TIME_BOT_V6);
1836 unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
1838 return s5p_mfc_read_info_v6(ctx, CROP_INFO_H_V6);
1841 unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
1843 return s5p_mfc_read_info_v6(ctx, CROP_INFO_V_V6);
1846 /* Initialize opr function pointers for MFC v6 */
1847 static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
1848 .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
1849 .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
1850 .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
1851 .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
1852 .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
1853 .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
1854 .alloc_dev_context_buffer =
1855 s5p_mfc_alloc_dev_context_buffer_v6,
1856 .release_dev_context_buffer =
1857 s5p_mfc_release_dev_context_buffer_v6,
1858 .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
1859 .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
1860 .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
1861 .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
1862 .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
1863 .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
1864 .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
1865 .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
1866 .init_decode = s5p_mfc_init_decode_v6,
1867 .init_encode = s5p_mfc_init_encode_v6,
1868 .encode_one_frame = s5p_mfc_encode_one_frame_v6,
1869 .try_run = s5p_mfc_try_run_v6,
1870 .cleanup_queue = s5p_mfc_cleanup_queue_v6,
1871 .clear_int_flags = s5p_mfc_clear_int_flags_v6,
1872 .write_info = s5p_mfc_write_info_v6,
1873 .read_info = s5p_mfc_read_info_v6,
1874 .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
1875 .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
1876 .get_dspl_status = s5p_mfc_get_dspl_status_v6,
1877 .get_dec_status = s5p_mfc_get_dec_status_v6,
1878 .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
1879 .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
1880 .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
1881 .get_int_reason = s5p_mfc_get_int_reason_v6,
1882 .get_int_err = s5p_mfc_get_int_err_v6,
1883 .err_dec = s5p_mfc_err_dec_v6,
1884 .err_dspl = s5p_mfc_err_dspl_v6,
1885 .get_img_width = s5p_mfc_get_img_width_v6,
1886 .get_img_height = s5p_mfc_get_img_height_v6,
1887 .get_dpb_count = s5p_mfc_get_dpb_count_v6,
1888 .get_mv_count = s5p_mfc_get_mv_count_v6,
1889 .get_inst_no = s5p_mfc_get_inst_no_v6,
1890 .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
1891 .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
1892 .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
1893 .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
1894 .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
1895 .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
1896 .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
1897 .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
1898 .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
1899 .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
1900 .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
1903 struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
1905 return &s5p_mfc_ops_v6;