1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/media/platform/samsung/mfc5/s5p_mfc_opr_v5.c
5 * Samsung MFC (Multi Function Codec - FIMV) driver
6 * This file contains hw related functions.
8 * Kamil Debski, Copyright (c) 2011 Samsung Electronics
9 * http://www.samsung.com/
12 #include "s5p_mfc_common.h"
13 #include "s5p_mfc_cmd.h"
14 #include "s5p_mfc_ctrl.h"
15 #include "s5p_mfc_debug.h"
16 #include "s5p_mfc_intr.h"
17 #include "s5p_mfc_pm.h"
18 #include "s5p_mfc_opr.h"
19 #include "s5p_mfc_opr_v5.h"
20 #include <asm/cacheflush.h>
21 #include <linux/delay.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/err.h>
24 #include <linux/firmware.h>
26 #include <linux/jiffies.h>
28 #include <linux/sched.h>
30 #define OFFSETA(x) (((x) - dev->dma_base[BANK_L_CTX]) >> MFC_OFFSET_SHIFT)
31 #define OFFSETB(x) (((x) - dev->dma_base[BANK_R_CTX]) >> MFC_OFFSET_SHIFT)
33 /* Allocate temporary buffers for decoding */
34 static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx
*ctx
)
36 struct s5p_mfc_dev
*dev
= ctx
->dev
;
37 struct s5p_mfc_buf_size_v5
*buf_size
= dev
->variant
->buf_size
->priv
;
40 ctx
->dsc
.size
= buf_size
->dsc
;
41 ret
= s5p_mfc_alloc_priv_buf(dev
, BANK_L_CTX
, &ctx
->dsc
);
43 mfc_err("Failed to allocate temporary buffer\n");
47 BUG_ON(ctx
->dsc
.dma
& ((1 << MFC_BANK1_ALIGN_ORDER
) - 1));
48 memset(ctx
->dsc
.virt
, 0, ctx
->dsc
.size
);
54 /* Release temporary buffers for decoding */
55 static void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx
*ctx
)
57 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->dsc
);
60 /* Allocate codec buffers */
61 static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx
*ctx
)
63 struct s5p_mfc_dev
*dev
= ctx
->dev
;
64 unsigned int enc_ref_y_size
= 0;
65 unsigned int enc_ref_c_size
= 0;
66 unsigned int guard_width
, guard_height
;
69 if (ctx
->type
== MFCINST_DECODER
) {
70 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
71 ctx
->luma_size
, ctx
->chroma_size
, ctx
->mv_size
);
72 mfc_debug(2, "Totals bufs: %d\n", ctx
->total_dpb_count
);
73 } else if (ctx
->type
== MFCINST_ENCODER
) {
74 enc_ref_y_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
)
75 * ALIGN(ctx
->img_height
, S5P_FIMV_NV12MT_VALIGN
);
76 enc_ref_y_size
= ALIGN(enc_ref_y_size
, S5P_FIMV_NV12MT_SALIGN
);
78 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
) {
79 enc_ref_c_size
= ALIGN(ctx
->img_width
,
80 S5P_FIMV_NV12MT_HALIGN
)
81 * ALIGN(ctx
->img_height
>> 1,
82 S5P_FIMV_NV12MT_VALIGN
);
83 enc_ref_c_size
= ALIGN(enc_ref_c_size
,
84 S5P_FIMV_NV12MT_SALIGN
);
86 guard_width
= ALIGN(ctx
->img_width
+ 16,
87 S5P_FIMV_NV12MT_HALIGN
);
88 guard_height
= ALIGN((ctx
->img_height
>> 1) + 4,
89 S5P_FIMV_NV12MT_VALIGN
);
90 enc_ref_c_size
= ALIGN(guard_width
* guard_height
,
91 S5P_FIMV_NV12MT_SALIGN
);
93 mfc_debug(2, "recon luma size: %d chroma size: %d\n",
94 enc_ref_y_size
, enc_ref_c_size
);
98 /* Codecs have different memory requirements */
99 switch (ctx
->codec_mode
) {
100 case S5P_MFC_CODEC_H264_DEC
:
102 ALIGN(S5P_FIMV_DEC_NB_IP_SIZE
+
103 S5P_FIMV_DEC_VERT_NB_MV_SIZE
,
104 S5P_FIMV_DEC_BUF_ALIGN
);
105 ctx
->bank2
.size
= ctx
->total_dpb_count
* ctx
->mv_size
;
107 case S5P_MFC_CODEC_MPEG4_DEC
:
109 ALIGN(S5P_FIMV_DEC_NB_DCAC_SIZE
+
110 S5P_FIMV_DEC_UPNB_MV_SIZE
+
111 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
+
112 S5P_FIMV_DEC_STX_PARSER_SIZE
+
113 S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
,
114 S5P_FIMV_DEC_BUF_ALIGN
);
117 case S5P_MFC_CODEC_VC1RCV_DEC
:
118 case S5P_MFC_CODEC_VC1_DEC
:
120 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
+
121 S5P_FIMV_DEC_UPNB_MV_SIZE
+
122 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
+
123 S5P_FIMV_DEC_NB_DCAC_SIZE
+
124 3 * S5P_FIMV_DEC_VC1_BITPLANE_SIZE
,
125 S5P_FIMV_DEC_BUF_ALIGN
);
128 case S5P_MFC_CODEC_MPEG2_DEC
:
132 case S5P_MFC_CODEC_H263_DEC
:
134 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
+
135 S5P_FIMV_DEC_UPNB_MV_SIZE
+
136 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
+
137 S5P_FIMV_DEC_NB_DCAC_SIZE
,
138 S5P_FIMV_DEC_BUF_ALIGN
);
141 case S5P_MFC_CODEC_H264_ENC
:
142 ctx
->bank1
.size
= (enc_ref_y_size
* 2) +
143 S5P_FIMV_ENC_UPMV_SIZE
+
144 S5P_FIMV_ENC_COLFLG_SIZE
+
145 S5P_FIMV_ENC_INTRAMD_SIZE
+
146 S5P_FIMV_ENC_NBORINFO_SIZE
;
147 ctx
->bank2
.size
= (enc_ref_y_size
* 2) +
148 (enc_ref_c_size
* 4) +
149 S5P_FIMV_ENC_INTRAPRED_SIZE
;
151 case S5P_MFC_CODEC_MPEG4_ENC
:
152 ctx
->bank1
.size
= (enc_ref_y_size
* 2) +
153 S5P_FIMV_ENC_UPMV_SIZE
+
154 S5P_FIMV_ENC_COLFLG_SIZE
+
155 S5P_FIMV_ENC_ACDCCOEF_SIZE
;
156 ctx
->bank2
.size
= (enc_ref_y_size
* 2) +
157 (enc_ref_c_size
* 4);
159 case S5P_MFC_CODEC_H263_ENC
:
160 ctx
->bank1
.size
= (enc_ref_y_size
* 2) +
161 S5P_FIMV_ENC_UPMV_SIZE
+
162 S5P_FIMV_ENC_ACDCCOEF_SIZE
;
163 ctx
->bank2
.size
= (enc_ref_y_size
* 2) +
164 (enc_ref_c_size
* 4);
169 /* Allocate only if memory from bank 1 is necessary */
170 if (ctx
->bank1
.size
> 0) {
172 ret
= s5p_mfc_alloc_priv_buf(dev
, BANK_L_CTX
, &ctx
->bank1
);
174 mfc_err("Failed to allocate Bank1 temporary buffer\n");
177 BUG_ON(ctx
->bank1
.dma
& ((1 << MFC_BANK1_ALIGN_ORDER
) - 1));
179 /* Allocate only if memory from bank 2 is necessary */
180 if (ctx
->bank2
.size
> 0) {
181 ret
= s5p_mfc_alloc_priv_buf(dev
, BANK_R_CTX
, &ctx
->bank2
);
183 mfc_err("Failed to allocate Bank2 temporary buffer\n");
184 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->bank1
);
187 BUG_ON(ctx
->bank2
.dma
& ((1 << MFC_BANK2_ALIGN_ORDER
) - 1));
192 /* Release buffers allocated for codec */
193 static void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx
*ctx
)
195 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->bank1
);
196 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->bank2
);
199 /* Allocate memory for instance data buffer */
200 static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx
*ctx
)
202 struct s5p_mfc_dev
*dev
= ctx
->dev
;
203 struct s5p_mfc_buf_size_v5
*buf_size
= dev
->variant
->buf_size
->priv
;
206 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
||
207 ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
)
208 ctx
->ctx
.size
= buf_size
->h264_ctx
;
210 ctx
->ctx
.size
= buf_size
->non_h264_ctx
;
212 ret
= s5p_mfc_alloc_priv_buf(dev
, BANK_L_CTX
, &ctx
->ctx
);
214 mfc_err("Failed to allocate instance buffer\n");
217 ctx
->ctx
.ofs
= OFFSETA(ctx
->ctx
.dma
);
219 /* Zero content of the allocated memory */
220 memset(ctx
->ctx
.virt
, 0, ctx
->ctx
.size
);
223 /* Initialize shared memory */
224 ctx
->shm
.size
= buf_size
->shm
;
225 ret
= s5p_mfc_alloc_priv_buf(dev
, BANK_L_CTX
, &ctx
->shm
);
227 mfc_err("Failed to allocate shared memory buffer\n");
228 s5p_mfc_release_priv_buf(dev
, &ctx
->ctx
);
232 /* shared memory offset only keeps the offset from base (port a) */
233 ctx
->shm
.ofs
= ctx
->shm
.dma
- dev
->dma_base
[BANK_L_CTX
];
234 BUG_ON(ctx
->shm
.ofs
& ((1 << MFC_BANK1_ALIGN_ORDER
) - 1));
236 memset(ctx
->shm
.virt
, 0, buf_size
->shm
);
241 /* Release instance buffer */
242 static void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx
*ctx
)
244 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->ctx
);
245 s5p_mfc_release_priv_buf(ctx
->dev
, &ctx
->shm
);
248 static int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev
*dev
)
255 static void s5p_mfc_release_dev_context_buffer_v5(struct s5p_mfc_dev
*dev
)
260 static void s5p_mfc_write_info_v5(struct s5p_mfc_ctx
*ctx
, unsigned int data
,
263 *(u32
*)(ctx
->shm
.virt
+ ofs
) = data
;
267 static unsigned int s5p_mfc_read_info_v5(struct s5p_mfc_ctx
*ctx
,
271 return *(u32
*)(ctx
->shm
.virt
+ ofs
);
274 static void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx
*ctx
)
276 unsigned int guard_width
, guard_height
;
278 ctx
->buf_width
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
);
279 ctx
->buf_height
= ALIGN(ctx
->img_height
, S5P_FIMV_NV12MT_VALIGN
);
281 "SEQ Done: Movie dimensions %dx%d, buffer dimensions: %dx%d\n",
282 ctx
->img_width
, ctx
->img_height
, ctx
->buf_width
,
285 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
) {
286 ctx
->luma_size
= ALIGN(ctx
->buf_width
* ctx
->buf_height
,
287 S5P_FIMV_DEC_BUF_ALIGN
);
288 ctx
->chroma_size
= ALIGN(ctx
->buf_width
*
289 ALIGN((ctx
->img_height
>> 1),
290 S5P_FIMV_NV12MT_VALIGN
),
291 S5P_FIMV_DEC_BUF_ALIGN
);
292 ctx
->mv_size
= ALIGN(ctx
->buf_width
*
293 ALIGN((ctx
->buf_height
>> 2),
294 S5P_FIMV_NV12MT_VALIGN
),
295 S5P_FIMV_DEC_BUF_ALIGN
);
298 ALIGN(ctx
->img_width
+ 24, S5P_FIMV_NV12MT_HALIGN
);
300 ALIGN(ctx
->img_height
+ 16, S5P_FIMV_NV12MT_VALIGN
);
301 ctx
->luma_size
= ALIGN(guard_width
* guard_height
,
302 S5P_FIMV_DEC_BUF_ALIGN
);
305 ALIGN(ctx
->img_width
+ 16, S5P_FIMV_NV12MT_HALIGN
);
307 ALIGN((ctx
->img_height
>> 1) + 4,
308 S5P_FIMV_NV12MT_VALIGN
);
309 ctx
->chroma_size
= ALIGN(guard_width
* guard_height
,
310 S5P_FIMV_DEC_BUF_ALIGN
);
316 static void s5p_mfc_enc_calc_src_size_v5(struct s5p_mfc_ctx
*ctx
)
318 if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12M
) {
319 ctx
->buf_width
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12M_HALIGN
);
321 ctx
->luma_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12M_HALIGN
)
322 * ALIGN(ctx
->img_height
, S5P_FIMV_NV12M_LVALIGN
);
323 ctx
->chroma_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12M_HALIGN
)
324 * ALIGN((ctx
->img_height
>> 1), S5P_FIMV_NV12M_CVALIGN
);
326 ctx
->luma_size
= ALIGN(ctx
->luma_size
, S5P_FIMV_NV12M_SALIGN
);
328 ALIGN(ctx
->chroma_size
, S5P_FIMV_NV12M_SALIGN
);
329 } else if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12MT
) {
330 ctx
->buf_width
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
);
332 ctx
->luma_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
)
333 * ALIGN(ctx
->img_height
, S5P_FIMV_NV12MT_VALIGN
);
335 ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
)
336 * ALIGN((ctx
->img_height
>> 1), S5P_FIMV_NV12MT_VALIGN
);
338 ctx
->luma_size
= ALIGN(ctx
->luma_size
, S5P_FIMV_NV12MT_SALIGN
);
340 ALIGN(ctx
->chroma_size
, S5P_FIMV_NV12MT_SALIGN
);
344 /* Set registers for decoding temporary buffers */
345 static void s5p_mfc_set_dec_desc_buffer(struct s5p_mfc_ctx
*ctx
)
347 struct s5p_mfc_dev
*dev
= ctx
->dev
;
348 struct s5p_mfc_buf_size_v5
*buf_size
= dev
->variant
->buf_size
->priv
;
350 mfc_write(dev
, OFFSETA(ctx
->dsc
.dma
), S5P_FIMV_SI_CH0_DESC_ADR
);
351 mfc_write(dev
, buf_size
->dsc
, S5P_FIMV_SI_CH0_DESC_SIZE
);
354 /* Set registers for shared buffer */
355 static void s5p_mfc_set_shared_buffer(struct s5p_mfc_ctx
*ctx
)
357 struct s5p_mfc_dev
*dev
= ctx
->dev
;
358 mfc_write(dev
, ctx
->shm
.ofs
, S5P_FIMV_SI_CH0_HOST_WR_ADR
);
361 /* Set registers for decoding stream buffer */
362 static int s5p_mfc_set_dec_stream_buffer_v5(struct s5p_mfc_ctx
*ctx
,
363 int buf_addr
, unsigned int start_num_byte
,
364 unsigned int buf_size
)
366 struct s5p_mfc_dev
*dev
= ctx
->dev
;
368 mfc_write(dev
, OFFSETA(buf_addr
), S5P_FIMV_SI_CH0_SB_ST_ADR
);
369 mfc_write(dev
, ctx
->dec_src_buf_size
, S5P_FIMV_SI_CH0_CPB_SIZE
);
370 mfc_write(dev
, buf_size
, S5P_FIMV_SI_CH0_SB_FRM_SIZE
);
371 s5p_mfc_write_info_v5(ctx
, start_num_byte
, START_BYTE_NUM
);
375 /* Set decoding frame buffer */
376 static int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx
*ctx
)
378 unsigned int frame_size_lu
, i
;
379 unsigned int frame_size_ch
, frame_size_mv
;
380 struct s5p_mfc_dev
*dev
= ctx
->dev
;
382 size_t buf_addr1
, buf_addr2
;
383 int buf_size1
, buf_size2
;
385 buf_addr1
= ctx
->bank1
.dma
;
386 buf_size1
= ctx
->bank1
.size
;
387 buf_addr2
= ctx
->bank2
.dma
;
388 buf_size2
= ctx
->bank2
.size
;
389 dpb
= mfc_read(dev
, S5P_FIMV_SI_CH0_DPB_CONF_CTRL
) &
390 ~S5P_FIMV_DPB_COUNT_MASK
;
391 mfc_write(dev
, ctx
->total_dpb_count
| dpb
,
392 S5P_FIMV_SI_CH0_DPB_CONF_CTRL
);
393 s5p_mfc_set_shared_buffer(ctx
);
394 switch (ctx
->codec_mode
) {
395 case S5P_MFC_CODEC_H264_DEC
:
396 mfc_write(dev
, OFFSETA(buf_addr1
),
397 S5P_FIMV_H264_VERT_NB_MV_ADR
);
398 buf_addr1
+= S5P_FIMV_DEC_VERT_NB_MV_SIZE
;
399 buf_size1
-= S5P_FIMV_DEC_VERT_NB_MV_SIZE
;
400 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H264_NB_IP_ADR
);
401 buf_addr1
+= S5P_FIMV_DEC_NB_IP_SIZE
;
402 buf_size1
-= S5P_FIMV_DEC_NB_IP_SIZE
;
404 case S5P_MFC_CODEC_MPEG4_DEC
:
405 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_NB_DCAC_ADR
);
406 buf_addr1
+= S5P_FIMV_DEC_NB_DCAC_SIZE
;
407 buf_size1
-= S5P_FIMV_DEC_NB_DCAC_SIZE
;
408 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_UP_NB_MV_ADR
);
409 buf_addr1
+= S5P_FIMV_DEC_UPNB_MV_SIZE
;
410 buf_size1
-= S5P_FIMV_DEC_UPNB_MV_SIZE
;
411 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_SA_MV_ADR
);
412 buf_addr1
+= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
413 buf_size1
-= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
414 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_SP_ADR
);
415 buf_addr1
+= S5P_FIMV_DEC_STX_PARSER_SIZE
;
416 buf_size1
-= S5P_FIMV_DEC_STX_PARSER_SIZE
;
417 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_OT_LINE_ADR
);
418 buf_addr1
+= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
419 buf_size1
-= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
421 case S5P_MFC_CODEC_H263_DEC
:
422 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_OT_LINE_ADR
);
423 buf_addr1
+= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
424 buf_size1
-= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
425 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_UP_NB_MV_ADR
);
426 buf_addr1
+= S5P_FIMV_DEC_UPNB_MV_SIZE
;
427 buf_size1
-= S5P_FIMV_DEC_UPNB_MV_SIZE
;
428 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_SA_MV_ADR
);
429 buf_addr1
+= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
430 buf_size1
-= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
431 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_NB_DCAC_ADR
);
432 buf_addr1
+= S5P_FIMV_DEC_NB_DCAC_SIZE
;
433 buf_size1
-= S5P_FIMV_DEC_NB_DCAC_SIZE
;
435 case S5P_MFC_CODEC_VC1_DEC
:
436 case S5P_MFC_CODEC_VC1RCV_DEC
:
437 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_NB_DCAC_ADR
);
438 buf_addr1
+= S5P_FIMV_DEC_NB_DCAC_SIZE
;
439 buf_size1
-= S5P_FIMV_DEC_NB_DCAC_SIZE
;
440 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_OT_LINE_ADR
);
441 buf_addr1
+= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
442 buf_size1
-= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE
;
443 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_UP_NB_MV_ADR
);
444 buf_addr1
+= S5P_FIMV_DEC_UPNB_MV_SIZE
;
445 buf_size1
-= S5P_FIMV_DEC_UPNB_MV_SIZE
;
446 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_SA_MV_ADR
);
447 buf_addr1
+= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
448 buf_size1
-= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE
;
449 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_BITPLANE3_ADR
);
450 buf_addr1
+= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
451 buf_size1
-= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
452 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_BITPLANE2_ADR
);
453 buf_addr1
+= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
454 buf_size1
-= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
455 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_VC1_BITPLANE1_ADR
);
456 buf_addr1
+= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
457 buf_size1
-= S5P_FIMV_DEC_VC1_BITPLANE_SIZE
;
459 case S5P_MFC_CODEC_MPEG2_DEC
:
462 mfc_err("Unknown codec for decoding (%x)\n",
466 frame_size_lu
= ctx
->luma_size
;
467 frame_size_ch
= ctx
->chroma_size
;
468 frame_size_mv
= ctx
->mv_size
;
469 mfc_debug(2, "Frm size: %d ch: %d mv: %d\n", frame_size_lu
, frame_size_ch
,
471 for (i
= 0; i
< ctx
->total_dpb_count
; i
++) {
473 mfc_debug(2, "Luma %d: %zx\n", i
,
474 ctx
->dst_bufs
[i
].cookie
.raw
.luma
);
475 mfc_write(dev
, OFFSETB(ctx
->dst_bufs
[i
].cookie
.raw
.luma
),
476 S5P_FIMV_DEC_LUMA_ADR
+ i
* 4);
477 mfc_debug(2, "\tChroma %d: %zx\n", i
,
478 ctx
->dst_bufs
[i
].cookie
.raw
.chroma
);
479 mfc_write(dev
, OFFSETA(ctx
->dst_bufs
[i
].cookie
.raw
.chroma
),
480 S5P_FIMV_DEC_CHROMA_ADR
+ i
* 4);
481 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
) {
482 mfc_debug(2, "\tBuf2: %zx, size: %d\n",
483 buf_addr2
, buf_size2
);
484 mfc_write(dev
, OFFSETB(buf_addr2
),
485 S5P_FIMV_H264_MV_ADR
+ i
* 4);
486 buf_addr2
+= frame_size_mv
;
487 buf_size2
-= frame_size_mv
;
490 mfc_debug(2, "Buf1: %zu, buf_size1: %d\n", buf_addr1
, buf_size1
);
491 mfc_debug(2, "Buf 1/2 size after: %d/%d (frames %d)\n",
492 buf_size1
, buf_size2
, ctx
->total_dpb_count
);
493 if (buf_size1
< 0 || buf_size2
< 0) {
494 mfc_debug(2, "Not enough memory has been allocated\n");
497 s5p_mfc_write_info_v5(ctx
, frame_size_lu
, ALLOC_LUMA_DPB_SIZE
);
498 s5p_mfc_write_info_v5(ctx
, frame_size_ch
, ALLOC_CHROMA_DPB_SIZE
);
499 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_DEC
)
500 s5p_mfc_write_info_v5(ctx
, frame_size_mv
, ALLOC_MV_SIZE
);
501 mfc_write(dev
, ((S5P_FIMV_CH_INIT_BUFS
& S5P_FIMV_CH_MASK
)
502 << S5P_FIMV_CH_SHIFT
) | (ctx
->inst_no
),
503 S5P_FIMV_SI_CH0_INST_ID
);
507 /* Set registers for encoding stream buffer */
508 static int s5p_mfc_set_enc_stream_buffer_v5(struct s5p_mfc_ctx
*ctx
,
509 unsigned long addr
, unsigned int size
)
511 struct s5p_mfc_dev
*dev
= ctx
->dev
;
513 mfc_write(dev
, OFFSETA(addr
), S5P_FIMV_ENC_SI_CH0_SB_ADR
);
514 mfc_write(dev
, size
, S5P_FIMV_ENC_SI_CH0_SB_SIZE
);
518 static void s5p_mfc_set_enc_frame_buffer_v5(struct s5p_mfc_ctx
*ctx
,
519 unsigned long y_addr
, unsigned long c_addr
)
521 struct s5p_mfc_dev
*dev
= ctx
->dev
;
523 mfc_write(dev
, OFFSETB(y_addr
), S5P_FIMV_ENC_SI_CH0_CUR_Y_ADR
);
524 mfc_write(dev
, OFFSETB(c_addr
), S5P_FIMV_ENC_SI_CH0_CUR_C_ADR
);
527 static void s5p_mfc_get_enc_frame_buffer_v5(struct s5p_mfc_ctx
*ctx
,
528 unsigned long *y_addr
, unsigned long *c_addr
)
530 struct s5p_mfc_dev
*dev
= ctx
->dev
;
532 *y_addr
= dev
->dma_base
[BANK_R_CTX
] +
533 (mfc_read(dev
, S5P_FIMV_ENCODED_Y_ADDR
) << MFC_OFFSET_SHIFT
);
534 *c_addr
= dev
->dma_base
[BANK_R_CTX
] +
535 (mfc_read(dev
, S5P_FIMV_ENCODED_C_ADDR
) << MFC_OFFSET_SHIFT
);
538 /* Set encoding ref & codec buffer */
539 static int s5p_mfc_set_enc_ref_buffer_v5(struct s5p_mfc_ctx
*ctx
)
541 struct s5p_mfc_dev
*dev
= ctx
->dev
;
542 size_t buf_addr1
, buf_addr2
;
543 size_t buf_size1
, buf_size2
;
544 unsigned int enc_ref_y_size
, enc_ref_c_size
;
545 unsigned int guard_width
, guard_height
;
548 buf_addr1
= ctx
->bank1
.dma
;
549 buf_size1
= ctx
->bank1
.size
;
550 buf_addr2
= ctx
->bank2
.dma
;
551 buf_size2
= ctx
->bank2
.size
;
552 enc_ref_y_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
)
553 * ALIGN(ctx
->img_height
, S5P_FIMV_NV12MT_VALIGN
);
554 enc_ref_y_size
= ALIGN(enc_ref_y_size
, S5P_FIMV_NV12MT_SALIGN
);
555 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
) {
556 enc_ref_c_size
= ALIGN(ctx
->img_width
, S5P_FIMV_NV12MT_HALIGN
)
557 * ALIGN((ctx
->img_height
>> 1), S5P_FIMV_NV12MT_VALIGN
);
558 enc_ref_c_size
= ALIGN(enc_ref_c_size
, S5P_FIMV_NV12MT_SALIGN
);
560 guard_width
= ALIGN(ctx
->img_width
+ 16,
561 S5P_FIMV_NV12MT_HALIGN
);
562 guard_height
= ALIGN((ctx
->img_height
>> 1) + 4,
563 S5P_FIMV_NV12MT_VALIGN
);
564 enc_ref_c_size
= ALIGN(guard_width
* guard_height
,
565 S5P_FIMV_NV12MT_SALIGN
);
567 mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n", buf_size1
, buf_size2
);
568 switch (ctx
->codec_mode
) {
569 case S5P_MFC_CODEC_H264_ENC
:
570 for (i
= 0; i
< 2; i
++) {
571 mfc_write(dev
, OFFSETA(buf_addr1
),
572 S5P_FIMV_ENC_REF0_LUMA_ADR
+ (4 * i
));
573 buf_addr1
+= enc_ref_y_size
;
574 buf_size1
-= enc_ref_y_size
;
576 mfc_write(dev
, OFFSETB(buf_addr2
),
577 S5P_FIMV_ENC_REF2_LUMA_ADR
+ (4 * i
));
578 buf_addr2
+= enc_ref_y_size
;
579 buf_size2
-= enc_ref_y_size
;
581 for (i
= 0; i
< 4; i
++) {
582 mfc_write(dev
, OFFSETB(buf_addr2
),
583 S5P_FIMV_ENC_REF0_CHROMA_ADR
+ (4 * i
));
584 buf_addr2
+= enc_ref_c_size
;
585 buf_size2
-= enc_ref_c_size
;
587 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H264_UP_MV_ADR
);
588 buf_addr1
+= S5P_FIMV_ENC_UPMV_SIZE
;
589 buf_size1
-= S5P_FIMV_ENC_UPMV_SIZE
;
590 mfc_write(dev
, OFFSETA(buf_addr1
),
591 S5P_FIMV_H264_COZERO_FLAG_ADR
);
592 buf_addr1
+= S5P_FIMV_ENC_COLFLG_SIZE
;
593 buf_size1
-= S5P_FIMV_ENC_COLFLG_SIZE
;
594 mfc_write(dev
, OFFSETA(buf_addr1
),
595 S5P_FIMV_H264_UP_INTRA_MD_ADR
);
596 buf_addr1
+= S5P_FIMV_ENC_INTRAMD_SIZE
;
597 buf_size1
-= S5P_FIMV_ENC_INTRAMD_SIZE
;
598 mfc_write(dev
, OFFSETB(buf_addr2
),
599 S5P_FIMV_H264_UP_INTRA_PRED_ADR
);
600 buf_addr2
+= S5P_FIMV_ENC_INTRAPRED_SIZE
;
601 buf_size2
-= S5P_FIMV_ENC_INTRAPRED_SIZE
;
602 mfc_write(dev
, OFFSETA(buf_addr1
),
603 S5P_FIMV_H264_NBOR_INFO_ADR
);
604 buf_addr1
+= S5P_FIMV_ENC_NBORINFO_SIZE
;
605 buf_size1
-= S5P_FIMV_ENC_NBORINFO_SIZE
;
606 mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
607 buf_size1
, buf_size2
);
609 case S5P_MFC_CODEC_MPEG4_ENC
:
610 for (i
= 0; i
< 2; i
++) {
611 mfc_write(dev
, OFFSETA(buf_addr1
),
612 S5P_FIMV_ENC_REF0_LUMA_ADR
+ (4 * i
));
613 buf_addr1
+= enc_ref_y_size
;
614 buf_size1
-= enc_ref_y_size
;
615 mfc_write(dev
, OFFSETB(buf_addr2
),
616 S5P_FIMV_ENC_REF2_LUMA_ADR
+ (4 * i
));
617 buf_addr2
+= enc_ref_y_size
;
618 buf_size2
-= enc_ref_y_size
;
620 for (i
= 0; i
< 4; i
++) {
621 mfc_write(dev
, OFFSETB(buf_addr2
),
622 S5P_FIMV_ENC_REF0_CHROMA_ADR
+ (4 * i
));
623 buf_addr2
+= enc_ref_c_size
;
624 buf_size2
-= enc_ref_c_size
;
626 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_MPEG4_UP_MV_ADR
);
627 buf_addr1
+= S5P_FIMV_ENC_UPMV_SIZE
;
628 buf_size1
-= S5P_FIMV_ENC_UPMV_SIZE
;
629 mfc_write(dev
, OFFSETA(buf_addr1
),
630 S5P_FIMV_MPEG4_COZERO_FLAG_ADR
);
631 buf_addr1
+= S5P_FIMV_ENC_COLFLG_SIZE
;
632 buf_size1
-= S5P_FIMV_ENC_COLFLG_SIZE
;
633 mfc_write(dev
, OFFSETA(buf_addr1
),
634 S5P_FIMV_MPEG4_ACDC_COEF_ADR
);
635 buf_addr1
+= S5P_FIMV_ENC_ACDCCOEF_SIZE
;
636 buf_size1
-= S5P_FIMV_ENC_ACDCCOEF_SIZE
;
637 mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
638 buf_size1
, buf_size2
);
640 case S5P_MFC_CODEC_H263_ENC
:
641 for (i
= 0; i
< 2; i
++) {
642 mfc_write(dev
, OFFSETA(buf_addr1
),
643 S5P_FIMV_ENC_REF0_LUMA_ADR
+ (4 * i
));
644 buf_addr1
+= enc_ref_y_size
;
645 buf_size1
-= enc_ref_y_size
;
646 mfc_write(dev
, OFFSETB(buf_addr2
),
647 S5P_FIMV_ENC_REF2_LUMA_ADR
+ (4 * i
));
648 buf_addr2
+= enc_ref_y_size
;
649 buf_size2
-= enc_ref_y_size
;
651 for (i
= 0; i
< 4; i
++) {
652 mfc_write(dev
, OFFSETB(buf_addr2
),
653 S5P_FIMV_ENC_REF0_CHROMA_ADR
+ (4 * i
));
654 buf_addr2
+= enc_ref_c_size
;
655 buf_size2
-= enc_ref_c_size
;
657 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_UP_MV_ADR
);
658 buf_addr1
+= S5P_FIMV_ENC_UPMV_SIZE
;
659 buf_size1
-= S5P_FIMV_ENC_UPMV_SIZE
;
660 mfc_write(dev
, OFFSETA(buf_addr1
), S5P_FIMV_H263_ACDC_COEF_ADR
);
661 buf_addr1
+= S5P_FIMV_ENC_ACDCCOEF_SIZE
;
662 buf_size1
-= S5P_FIMV_ENC_ACDCCOEF_SIZE
;
663 mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
664 buf_size1
, buf_size2
);
667 mfc_err("Unknown codec set for encoding: %d\n",
674 static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx
*ctx
)
676 struct s5p_mfc_dev
*dev
= ctx
->dev
;
677 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
682 mfc_write(dev
, ctx
->img_width
, S5P_FIMV_ENC_HSIZE_PX
);
684 mfc_write(dev
, ctx
->img_height
, S5P_FIMV_ENC_VSIZE_PX
);
685 /* pictype : enable, IDR period */
686 reg
= mfc_read(dev
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
690 mfc_write(dev
, reg
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
691 mfc_write(dev
, 0, S5P_FIMV_ENC_B_RECON_WRITE_ON
);
692 /* multi-slice control */
693 /* multi-slice MB number or bit size */
694 mfc_write(dev
, p
->slice_mode
, S5P_FIMV_ENC_MSLICE_CTRL
);
695 if (p
->slice_mode
== V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB
) {
696 mfc_write(dev
, p
->slice_mb
, S5P_FIMV_ENC_MSLICE_MB
);
697 } else if (p
->slice_mode
== V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES
) {
698 mfc_write(dev
, p
->slice_bit
, S5P_FIMV_ENC_MSLICE_BIT
);
700 mfc_write(dev
, 0, S5P_FIMV_ENC_MSLICE_MB
);
701 mfc_write(dev
, 0, S5P_FIMV_ENC_MSLICE_BIT
);
703 /* cyclic intra refresh */
704 mfc_write(dev
, p
->intra_refresh_mb
, S5P_FIMV_ENC_CIR_CTRL
);
705 /* memory structure cur. frame */
706 if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12M
)
707 mfc_write(dev
, 0, S5P_FIMV_ENC_MAP_FOR_CUR
);
708 else if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12MT
)
709 mfc_write(dev
, 3, S5P_FIMV_ENC_MAP_FOR_CUR
);
710 /* padding control & value */
711 reg
= mfc_read(dev
, S5P_FIMV_ENC_PADDING_CTRL
);
716 reg
&= ~(0xFF << 16);
717 reg
|= (p
->pad_cr
<< 16);
720 reg
|= (p
->pad_cb
<< 8);
723 reg
|= (p
->pad_luma
);
725 /** disable & all value clear */
728 mfc_write(dev
, reg
, S5P_FIMV_ENC_PADDING_CTRL
);
729 /* rate control config. */
730 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_CONFIG
);
731 /** frame-level rate control */
733 reg
|= (p
->rc_frame
<< 9);
734 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_CONFIG
);
737 mfc_write(dev
, p
->rc_bitrate
,
738 S5P_FIMV_ENC_RC_BIT_RATE
);
740 mfc_write(dev
, 0, S5P_FIMV_ENC_RC_BIT_RATE
);
741 /* reaction coefficient */
743 mfc_write(dev
, p
->rc_reaction_coeff
, S5P_FIMV_ENC_RC_RPARA
);
744 shm
= s5p_mfc_read_info_v5(ctx
, EXT_ENC_CONTROL
);
745 /* seq header ctrl */
747 shm
|= (p
->seq_hdr_mode
<< 3);
748 /* frame skip mode */
750 shm
|= (p
->frame_skip_mode
<< 1);
751 s5p_mfc_write_info_v5(ctx
, shm
, EXT_ENC_CONTROL
);
752 /* fixed target bit */
753 s5p_mfc_write_info_v5(ctx
, p
->fixed_target_bit
, RC_CONTROL_CONFIG
);
757 static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx
*ctx
)
759 struct s5p_mfc_dev
*dev
= ctx
->dev
;
760 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
761 struct s5p_mfc_h264_enc_params
*p_264
= &p
->codec
.h264
;
765 s5p_mfc_set_enc_params(ctx
);
766 /* pictype : number of B */
767 reg
= mfc_read(dev
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
768 /* num_b_frame - 0 ~ 2 */
770 reg
|= (p
->num_b_frame
<< 16);
771 mfc_write(dev
, reg
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
772 /* profile & level */
773 reg
= mfc_read(dev
, S5P_FIMV_ENC_PROFILE
);
776 reg
|= (p_264
->level
<< 8);
777 /* profile - 0 ~ 2 */
779 reg
|= p_264
->profile
;
780 mfc_write(dev
, reg
, S5P_FIMV_ENC_PROFILE
);
782 mfc_write(dev
, p_264
->interlace
, S5P_FIMV_ENC_PIC_STRUCT
);
784 if (p_264
->interlace
)
785 mfc_write(dev
, ctx
->img_height
>> 1, S5P_FIMV_ENC_VSIZE_PX
);
786 /* loopfilter ctrl */
787 mfc_write(dev
, p_264
->loop_filter_mode
, S5P_FIMV_ENC_LF_CTRL
);
788 /* loopfilter alpha offset */
789 if (p_264
->loop_filter_alpha
< 0) {
791 reg
|= (0xFF - p_264
->loop_filter_alpha
) + 1;
794 reg
|= (p_264
->loop_filter_alpha
& 0xF);
796 mfc_write(dev
, reg
, S5P_FIMV_ENC_ALPHA_OFF
);
797 /* loopfilter beta offset */
798 if (p_264
->loop_filter_beta
< 0) {
800 reg
|= (0xFF - p_264
->loop_filter_beta
) + 1;
803 reg
|= (p_264
->loop_filter_beta
& 0xF);
805 mfc_write(dev
, reg
, S5P_FIMV_ENC_BETA_OFF
);
806 /* entropy coding mode */
807 if (p_264
->entropy_mode
== V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC
)
808 mfc_write(dev
, 1, S5P_FIMV_ENC_H264_ENTROPY_MODE
);
810 mfc_write(dev
, 0, S5P_FIMV_ENC_H264_ENTROPY_MODE
);
811 /* number of ref. picture */
812 reg
= mfc_read(dev
, S5P_FIMV_ENC_H264_NUM_OF_REF
);
813 /* num of ref. pictures of P */
815 reg
|= (p_264
->num_ref_pic_4p
<< 5);
816 /* max number of ref. pictures */
818 reg
|= p_264
->max_ref_pic
;
819 mfc_write(dev
, reg
, S5P_FIMV_ENC_H264_NUM_OF_REF
);
820 /* 8x8 transform enable */
821 mfc_write(dev
, p_264
->_8x8_transform
, S5P_FIMV_ENC_H264_TRANS_FLAG
);
822 /* rate control config. */
823 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_CONFIG
);
824 /* macroblock level rate control */
826 reg
|= (p
->rc_mb
<< 8);
829 reg
|= p_264
->rc_frame_qp
;
830 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_CONFIG
);
832 if (p
->rc_frame
&& p
->rc_framerate_denom
)
833 mfc_write(dev
, p
->rc_framerate_num
* 1000
834 / p
->rc_framerate_denom
, S5P_FIMV_ENC_RC_FRAME_RATE
);
836 mfc_write(dev
, 0, S5P_FIMV_ENC_RC_FRAME_RATE
);
837 /* max & min value of QP */
838 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_QBOUND
);
841 reg
|= (p_264
->rc_max_qp
<< 8);
844 reg
|= p_264
->rc_min_qp
;
845 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_QBOUND
);
846 /* macroblock adaptive scaling features */
848 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_MB_CTRL
);
851 reg
|= (p_264
->rc_mb_dark
<< 3);
854 reg
|= (p_264
->rc_mb_smooth
<< 2);
857 reg
|= (p_264
->rc_mb_static
<< 1);
858 /* high activity region */
860 reg
|= p_264
->rc_mb_activity
;
861 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_MB_CTRL
);
863 if (!p
->rc_frame
&& !p
->rc_mb
) {
864 shm
= s5p_mfc_read_info_v5(ctx
, P_B_FRAME_QP
);
866 shm
|= ((p_264
->rc_b_frame_qp
& 0x3F) << 6);
867 shm
|= (p_264
->rc_p_frame_qp
& 0x3F);
868 s5p_mfc_write_info_v5(ctx
, shm
, P_B_FRAME_QP
);
870 /* extended encoder ctrl */
871 shm
= s5p_mfc_read_info_v5(ctx
, EXT_ENC_CONTROL
);
874 shm
|= (p_264
->vui_sar
<< 1);
875 s5p_mfc_write_info_v5(ctx
, shm
, EXT_ENC_CONTROL
);
876 if (p_264
->vui_sar
) {
877 /* aspect ration IDC */
878 shm
= s5p_mfc_read_info_v5(ctx
, SAMPLE_ASPECT_RATIO_IDC
);
880 shm
|= p_264
->vui_sar_idc
;
881 s5p_mfc_write_info_v5(ctx
, shm
, SAMPLE_ASPECT_RATIO_IDC
);
882 if (p_264
->vui_sar_idc
== 0xFF) {
884 shm
= s5p_mfc_read_info_v5(ctx
, EXTENDED_SAR
);
885 shm
&= ~(0xFFFFFFFF);
886 shm
|= p_264
->vui_ext_sar_width
<< 16;
887 shm
|= p_264
->vui_ext_sar_height
;
888 s5p_mfc_write_info_v5(ctx
, shm
, EXTENDED_SAR
);
891 /* intra picture period for H.264 */
892 shm
= s5p_mfc_read_info_v5(ctx
, H264_I_PERIOD
);
895 shm
|= (p_264
->open_gop
<< 16);
897 if (p_264
->open_gop
) {
899 shm
|= p_264
->open_gop_size
;
901 s5p_mfc_write_info_v5(ctx
, shm
, H264_I_PERIOD
);
902 /* extended encoder ctrl */
903 shm
= s5p_mfc_read_info_v5(ctx
, EXT_ENC_CONTROL
);
904 /* vbv buffer size */
905 if (p
->frame_skip_mode
==
906 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
907 shm
&= ~(0xFFFF << 16);
908 shm
|= (p_264
->cpb_size
<< 16);
910 s5p_mfc_write_info_v5(ctx
, shm
, EXT_ENC_CONTROL
);
914 static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx
*ctx
)
916 struct s5p_mfc_dev
*dev
= ctx
->dev
;
917 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
918 struct s5p_mfc_mpeg4_enc_params
*p_mpeg4
= &p
->codec
.mpeg4
;
921 unsigned int framerate
;
923 s5p_mfc_set_enc_params(ctx
);
924 /* pictype : number of B */
925 reg
= mfc_read(dev
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
926 /* num_b_frame - 0 ~ 2 */
928 reg
|= (p
->num_b_frame
<< 16);
929 mfc_write(dev
, reg
, S5P_FIMV_ENC_PIC_TYPE_CTRL
);
930 /* profile & level */
931 reg
= mfc_read(dev
, S5P_FIMV_ENC_PROFILE
);
934 reg
|= (p_mpeg4
->level
<< 8);
935 /* profile - 0 ~ 2 */
937 reg
|= p_mpeg4
->profile
;
938 mfc_write(dev
, reg
, S5P_FIMV_ENC_PROFILE
);
940 mfc_write(dev
, p_mpeg4
->quarter_pixel
, S5P_FIMV_ENC_MPEG4_QUART_PXL
);
943 shm
= s5p_mfc_read_info_v5(ctx
, P_B_FRAME_QP
);
945 shm
|= ((p_mpeg4
->rc_b_frame_qp
& 0x3F) << 6);
946 shm
|= (p_mpeg4
->rc_p_frame_qp
& 0x3F);
947 s5p_mfc_write_info_v5(ctx
, shm
, P_B_FRAME_QP
);
951 if (p
->rc_framerate_denom
> 0) {
952 framerate
= p
->rc_framerate_num
* 1000 /
953 p
->rc_framerate_denom
;
954 mfc_write(dev
, framerate
,
955 S5P_FIMV_ENC_RC_FRAME_RATE
);
956 shm
= s5p_mfc_read_info_v5(ctx
, RC_VOP_TIMING
);
957 shm
&= ~(0xFFFFFFFF);
959 shm
|= ((p
->rc_framerate_num
& 0x7FFF) << 16);
960 shm
|= (p
->rc_framerate_denom
& 0xFFFF);
961 s5p_mfc_write_info_v5(ctx
, shm
, RC_VOP_TIMING
);
964 mfc_write(dev
, 0, S5P_FIMV_ENC_RC_FRAME_RATE
);
966 /* rate control config. */
967 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_CONFIG
);
970 reg
|= p_mpeg4
->rc_frame_qp
;
971 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_CONFIG
);
972 /* max & min value of QP */
973 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_QBOUND
);
976 reg
|= (p_mpeg4
->rc_max_qp
<< 8);
979 reg
|= p_mpeg4
->rc_min_qp
;
980 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_QBOUND
);
981 /* extended encoder ctrl */
982 shm
= s5p_mfc_read_info_v5(ctx
, EXT_ENC_CONTROL
);
983 /* vbv buffer size */
984 if (p
->frame_skip_mode
==
985 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
986 shm
&= ~(0xFFFF << 16);
987 shm
|= (p
->vbv_size
<< 16);
989 s5p_mfc_write_info_v5(ctx
, shm
, EXT_ENC_CONTROL
);
993 static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx
*ctx
)
995 struct s5p_mfc_dev
*dev
= ctx
->dev
;
996 struct s5p_mfc_enc_params
*p
= &ctx
->enc_params
;
997 struct s5p_mfc_mpeg4_enc_params
*p_h263
= &p
->codec
.mpeg4
;
1001 s5p_mfc_set_enc_params(ctx
);
1004 shm
= s5p_mfc_read_info_v5(ctx
, P_B_FRAME_QP
);
1006 shm
|= (p_h263
->rc_p_frame_qp
& 0x3F);
1007 s5p_mfc_write_info_v5(ctx
, shm
, P_B_FRAME_QP
);
1010 if (p
->rc_frame
&& p
->rc_framerate_denom
)
1011 mfc_write(dev
, p
->rc_framerate_num
* 1000
1012 / p
->rc_framerate_denom
, S5P_FIMV_ENC_RC_FRAME_RATE
);
1014 mfc_write(dev
, 0, S5P_FIMV_ENC_RC_FRAME_RATE
);
1015 /* rate control config. */
1016 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_CONFIG
);
1019 reg
|= p_h263
->rc_frame_qp
;
1020 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_CONFIG
);
1021 /* max & min value of QP */
1022 reg
= mfc_read(dev
, S5P_FIMV_ENC_RC_QBOUND
);
1024 reg
&= ~(0x3F << 8);
1025 reg
|= (p_h263
->rc_max_qp
<< 8);
1028 reg
|= p_h263
->rc_min_qp
;
1029 mfc_write(dev
, reg
, S5P_FIMV_ENC_RC_QBOUND
);
1030 /* extended encoder ctrl */
1031 shm
= s5p_mfc_read_info_v5(ctx
, EXT_ENC_CONTROL
);
1032 /* vbv buffer size */
1033 if (p
->frame_skip_mode
==
1034 V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT
) {
1035 shm
&= ~(0xFFFF << 16);
1036 shm
|= (p
->vbv_size
<< 16);
1038 s5p_mfc_write_info_v5(ctx
, shm
, EXT_ENC_CONTROL
);
1042 /* Initialize decoding */
1043 static int s5p_mfc_init_decode_v5(struct s5p_mfc_ctx
*ctx
)
1045 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1047 s5p_mfc_set_shared_buffer(ctx
);
1048 /* Setup loop filter, for decoding this is only valid for MPEG4 */
1049 if (ctx
->codec_mode
== S5P_MFC_CODEC_MPEG4_DEC
)
1050 mfc_write(dev
, ctx
->loop_filter_mpeg4
, S5P_FIMV_ENC_LF_CTRL
);
1052 mfc_write(dev
, 0, S5P_FIMV_ENC_LF_CTRL
);
1053 mfc_write(dev
, ((ctx
->slice_interface
& S5P_FIMV_SLICE_INT_MASK
) <<
1054 S5P_FIMV_SLICE_INT_SHIFT
) | (ctx
->display_delay_enable
<<
1055 S5P_FIMV_DDELAY_ENA_SHIFT
) | ((ctx
->display_delay
&
1056 S5P_FIMV_DDELAY_VAL_MASK
) << S5P_FIMV_DDELAY_VAL_SHIFT
),
1057 S5P_FIMV_SI_CH0_DPB_CONF_CTRL
);
1059 ((S5P_FIMV_CH_SEQ_HEADER
& S5P_FIMV_CH_MASK
) << S5P_FIMV_CH_SHIFT
)
1060 | (ctx
->inst_no
), S5P_FIMV_SI_CH0_INST_ID
);
1064 static void s5p_mfc_set_flush(struct s5p_mfc_ctx
*ctx
, int flush
)
1066 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1070 dpb
= mfc_read(dev
, S5P_FIMV_SI_CH0_DPB_CONF_CTRL
) | (
1071 S5P_FIMV_DPB_FLUSH_MASK
<< S5P_FIMV_DPB_FLUSH_SHIFT
);
1073 dpb
= mfc_read(dev
, S5P_FIMV_SI_CH0_DPB_CONF_CTRL
) &
1074 ~(S5P_FIMV_DPB_FLUSH_MASK
<< S5P_FIMV_DPB_FLUSH_SHIFT
);
1075 mfc_write(dev
, dpb
, S5P_FIMV_SI_CH0_DPB_CONF_CTRL
);
1078 /* Decode a single frame */
1079 static int s5p_mfc_decode_one_frame_v5(struct s5p_mfc_ctx
*ctx
,
1080 enum s5p_mfc_decode_arg last_frame
)
1082 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1084 mfc_write(dev
, ctx
->dec_dst_flag
, S5P_FIMV_SI_CH0_RELEASE_BUF
);
1085 s5p_mfc_set_shared_buffer(ctx
);
1086 s5p_mfc_set_flush(ctx
, ctx
->dpb_flush_flag
);
1087 /* Issue different commands to instance basing on whether it
1088 * is the last frame or not. */
1089 switch (last_frame
) {
1091 mfc_write(dev
, ((S5P_FIMV_CH_FRAME_START
& S5P_FIMV_CH_MASK
) <<
1092 S5P_FIMV_CH_SHIFT
) | (ctx
->inst_no
), S5P_FIMV_SI_CH0_INST_ID
);
1094 case MFC_DEC_LAST_FRAME
:
1095 mfc_write(dev
, ((S5P_FIMV_CH_LAST_FRAME
& S5P_FIMV_CH_MASK
) <<
1096 S5P_FIMV_CH_SHIFT
) | (ctx
->inst_no
), S5P_FIMV_SI_CH0_INST_ID
);
1098 case MFC_DEC_RES_CHANGE
:
1099 mfc_write(dev
, ((S5P_FIMV_CH_FRAME_START_REALLOC
&
1100 S5P_FIMV_CH_MASK
) << S5P_FIMV_CH_SHIFT
) | (ctx
->inst_no
),
1101 S5P_FIMV_SI_CH0_INST_ID
);
1104 mfc_debug(2, "Decoding a usual frame\n");
1108 static int s5p_mfc_init_encode_v5(struct s5p_mfc_ctx
*ctx
)
1110 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1112 if (ctx
->codec_mode
== S5P_MFC_CODEC_H264_ENC
)
1113 s5p_mfc_set_enc_params_h264(ctx
);
1114 else if (ctx
->codec_mode
== S5P_MFC_CODEC_MPEG4_ENC
)
1115 s5p_mfc_set_enc_params_mpeg4(ctx
);
1116 else if (ctx
->codec_mode
== S5P_MFC_CODEC_H263_ENC
)
1117 s5p_mfc_set_enc_params_h263(ctx
);
1119 mfc_err("Unknown codec for encoding (%x)\n",
1123 s5p_mfc_set_shared_buffer(ctx
);
1124 mfc_write(dev
, ((S5P_FIMV_CH_SEQ_HEADER
<< 16) & 0x70000) |
1125 (ctx
->inst_no
), S5P_FIMV_SI_CH0_INST_ID
);
1129 /* Encode a single frame */
1130 static int s5p_mfc_encode_one_frame_v5(struct s5p_mfc_ctx
*ctx
)
1132 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1134 /* memory structure cur. frame */
1135 if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12M
)
1136 mfc_write(dev
, 0, S5P_FIMV_ENC_MAP_FOR_CUR
);
1137 else if (ctx
->src_fmt
->fourcc
== V4L2_PIX_FMT_NV12MT
)
1138 mfc_write(dev
, 3, S5P_FIMV_ENC_MAP_FOR_CUR
);
1139 s5p_mfc_set_shared_buffer(ctx
);
1141 if (ctx
->state
== MFCINST_FINISHING
)
1142 cmd
= S5P_FIMV_CH_LAST_FRAME
;
1144 cmd
= S5P_FIMV_CH_FRAME_START
;
1145 mfc_write(dev
, ((cmd
& S5P_FIMV_CH_MASK
) << S5P_FIMV_CH_SHIFT
)
1146 | (ctx
->inst_no
), S5P_FIMV_SI_CH0_INST_ID
);
1151 static void s5p_mfc_run_res_change(struct s5p_mfc_ctx
*ctx
)
1153 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1155 s5p_mfc_set_dec_stream_buffer_v5(ctx
, 0, 0, 0);
1156 dev
->curr_ctx
= ctx
->num
;
1157 s5p_mfc_decode_one_frame_v5(ctx
, MFC_DEC_RES_CHANGE
);
1160 static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx
*ctx
, int last_frame
)
1162 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1163 struct s5p_mfc_buf
*temp_vb
;
1165 if (ctx
->state
== MFCINST_FINISHING
) {
1166 last_frame
= MFC_DEC_LAST_FRAME
;
1167 s5p_mfc_set_dec_stream_buffer_v5(ctx
, 0, 0, 0);
1168 dev
->curr_ctx
= ctx
->num
;
1169 s5p_mfc_decode_one_frame_v5(ctx
, last_frame
);
1173 /* Frames are being decoded */
1174 if (list_empty(&ctx
->src_queue
)) {
1175 mfc_debug(2, "No src buffers\n");
1178 /* Get the next source buffer */
1179 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1180 temp_vb
->flags
|= MFC_BUF_FLAG_USED
;
1181 s5p_mfc_set_dec_stream_buffer_v5(ctx
,
1182 vb2_dma_contig_plane_dma_addr(&temp_vb
->b
->vb2_buf
, 0),
1183 ctx
->consumed_stream
, temp_vb
->b
->vb2_buf
.planes
[0].bytesused
);
1184 dev
->curr_ctx
= ctx
->num
;
1185 if (temp_vb
->b
->vb2_buf
.planes
[0].bytesused
== 0) {
1186 last_frame
= MFC_DEC_LAST_FRAME
;
1187 mfc_debug(2, "Setting ctx->state to FINISHING\n");
1188 ctx
->state
= MFCINST_FINISHING
;
1190 s5p_mfc_decode_one_frame_v5(ctx
, last_frame
);
1194 static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx
*ctx
)
1196 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1197 struct s5p_mfc_buf
*dst_mb
;
1198 struct s5p_mfc_buf
*src_mb
;
1199 unsigned long src_y_addr
, src_c_addr
, dst_addr
;
1200 unsigned int dst_size
;
1202 if (list_empty(&ctx
->src_queue
) && ctx
->state
!= MFCINST_FINISHING
) {
1203 mfc_debug(2, "no src buffers\n");
1206 if (list_empty(&ctx
->dst_queue
)) {
1207 mfc_debug(2, "no dst buffers\n");
1210 if (list_empty(&ctx
->src_queue
)) {
1211 /* send null frame */
1212 s5p_mfc_set_enc_frame_buffer_v5(ctx
, dev
->dma_base
[BANK_R_CTX
],
1213 dev
->dma_base
[BANK_R_CTX
]);
1216 src_mb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
,
1218 src_mb
->flags
|= MFC_BUF_FLAG_USED
;
1219 if (src_mb
->b
->vb2_buf
.planes
[0].bytesused
== 0) {
1220 /* send null frame */
1221 s5p_mfc_set_enc_frame_buffer_v5(ctx
,
1222 dev
->dma_base
[BANK_R_CTX
],
1223 dev
->dma_base
[BANK_R_CTX
]);
1224 ctx
->state
= MFCINST_FINISHING
;
1226 src_y_addr
= vb2_dma_contig_plane_dma_addr(
1227 &src_mb
->b
->vb2_buf
, 0);
1228 src_c_addr
= vb2_dma_contig_plane_dma_addr(
1229 &src_mb
->b
->vb2_buf
, 1);
1230 s5p_mfc_set_enc_frame_buffer_v5(ctx
, src_y_addr
,
1232 if (src_mb
->flags
& MFC_BUF_FLAG_EOS
)
1233 ctx
->state
= MFCINST_FINISHING
;
1236 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1237 dst_mb
->flags
|= MFC_BUF_FLAG_USED
;
1238 dst_addr
= vb2_dma_contig_plane_dma_addr(&dst_mb
->b
->vb2_buf
, 0);
1239 dst_size
= vb2_plane_size(&dst_mb
->b
->vb2_buf
, 0);
1240 s5p_mfc_set_enc_stream_buffer_v5(ctx
, dst_addr
, dst_size
);
1241 dev
->curr_ctx
= ctx
->num
;
1242 mfc_debug(2, "encoding buffer with index=%d state=%d\n",
1243 src_mb
? src_mb
->b
->vb2_buf
.index
: -1, ctx
->state
);
1244 s5p_mfc_encode_one_frame_v5(ctx
);
1248 static void s5p_mfc_run_init_dec(struct s5p_mfc_ctx
*ctx
)
1250 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1251 struct s5p_mfc_buf
*temp_vb
;
1253 /* Initializing decoding - parsing header */
1254 mfc_debug(2, "Preparing to init decoding\n");
1255 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1256 s5p_mfc_set_dec_desc_buffer(ctx
);
1257 mfc_debug(2, "Header size: %d\n",
1258 temp_vb
->b
->vb2_buf
.planes
[0].bytesused
);
1259 s5p_mfc_set_dec_stream_buffer_v5(ctx
,
1260 vb2_dma_contig_plane_dma_addr(&temp_vb
->b
->vb2_buf
, 0),
1261 0, temp_vb
->b
->vb2_buf
.planes
[0].bytesused
);
1262 dev
->curr_ctx
= ctx
->num
;
1263 s5p_mfc_init_decode_v5(ctx
);
1266 static void s5p_mfc_run_init_enc(struct s5p_mfc_ctx
*ctx
)
1268 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1269 struct s5p_mfc_buf
*dst_mb
;
1270 unsigned long dst_addr
;
1271 unsigned int dst_size
;
1273 s5p_mfc_set_enc_ref_buffer_v5(ctx
);
1274 dst_mb
= list_entry(ctx
->dst_queue
.next
, struct s5p_mfc_buf
, list
);
1275 dst_addr
= vb2_dma_contig_plane_dma_addr(&dst_mb
->b
->vb2_buf
, 0);
1276 dst_size
= vb2_plane_size(&dst_mb
->b
->vb2_buf
, 0);
1277 s5p_mfc_set_enc_stream_buffer_v5(ctx
, dst_addr
, dst_size
);
1278 dev
->curr_ctx
= ctx
->num
;
1279 s5p_mfc_init_encode_v5(ctx
);
1282 static int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx
*ctx
)
1284 struct s5p_mfc_dev
*dev
= ctx
->dev
;
1285 struct s5p_mfc_buf
*temp_vb
;
1289 * Header was parsed now starting processing
1290 * First set the output frame buffers
1292 if (ctx
->capture_state
!= QUEUE_BUFS_MMAPED
) {
1293 mfc_err("It seems that not all destination buffers were mmapped\nMFC requires that all destination are mmapped before starting processing\n");
1296 if (list_empty(&ctx
->src_queue
)) {
1297 mfc_err("Header has been deallocated in the middle of initialization\n");
1300 temp_vb
= list_entry(ctx
->src_queue
.next
, struct s5p_mfc_buf
, list
);
1301 mfc_debug(2, "Header size: %d\n",
1302 temp_vb
->b
->vb2_buf
.planes
[0].bytesused
);
1303 s5p_mfc_set_dec_stream_buffer_v5(ctx
,
1304 vb2_dma_contig_plane_dma_addr(&temp_vb
->b
->vb2_buf
, 0),
1305 0, temp_vb
->b
->vb2_buf
.planes
[0].bytesused
);
1306 dev
->curr_ctx
= ctx
->num
;
1307 ret
= s5p_mfc_set_dec_frame_buffer_v5(ctx
);
1309 mfc_err("Failed to alloc frame mem\n");
1310 ctx
->state
= MFCINST_ERROR
;
1315 /* Try running an operation on hardware */
1316 static void s5p_mfc_try_run_v5(struct s5p_mfc_dev
*dev
)
1318 struct s5p_mfc_ctx
*ctx
;
1320 unsigned int ret
= 0;
1322 if (test_bit(0, &dev
->enter_suspend
)) {
1323 mfc_debug(1, "Entering suspend so do not schedule any jobs\n");
1326 /* Check whether hardware is not running */
1327 if (test_and_set_bit(0, &dev
->hw_lock
) != 0) {
1328 /* This is perfectly ok, the scheduled ctx should wait */
1329 mfc_debug(1, "Couldn't lock HW\n");
1332 /* Choose the context to run */
1333 new_ctx
= s5p_mfc_get_new_ctx(dev
);
1335 /* No contexts to run */
1336 if (test_and_clear_bit(0, &dev
->hw_lock
) == 0) {
1337 mfc_err("Failed to unlock hardware\n");
1340 mfc_debug(1, "No ctx is scheduled to be run\n");
1343 ctx
= dev
->ctx
[new_ctx
];
1344 /* Got context to run in ctx */
1346 * Last frame has already been sent to MFC.
1347 * Now obtaining frames from MFC buffer
1350 s5p_mfc_clean_ctx_int_flags(ctx
);
1352 if (ctx
->type
== MFCINST_DECODER
) {
1353 s5p_mfc_set_dec_desc_buffer(ctx
);
1354 switch (ctx
->state
) {
1355 case MFCINST_FINISHING
:
1356 s5p_mfc_run_dec_frame(ctx
, MFC_DEC_LAST_FRAME
);
1358 case MFCINST_RUNNING
:
1359 ret
= s5p_mfc_run_dec_frame(ctx
, MFC_DEC_FRAME
);
1362 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, open_inst_cmd
,
1365 case MFCINST_RETURN_INST
:
1366 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, close_inst_cmd
,
1369 case MFCINST_GOT_INST
:
1370 s5p_mfc_run_init_dec(ctx
);
1372 case MFCINST_HEAD_PARSED
:
1373 ret
= s5p_mfc_run_init_dec_buffers(ctx
);
1374 mfc_debug(1, "head parsed\n");
1376 case MFCINST_RES_CHANGE_INIT
:
1377 s5p_mfc_run_res_change(ctx
);
1379 case MFCINST_RES_CHANGE_FLUSH
:
1380 s5p_mfc_run_dec_frame(ctx
, MFC_DEC_FRAME
);
1382 case MFCINST_RES_CHANGE_END
:
1383 mfc_debug(2, "Finished remaining frames after resolution change\n");
1384 ctx
->capture_state
= QUEUE_FREE
;
1385 mfc_debug(2, "Will re-init the codec\n");
1386 s5p_mfc_run_init_dec(ctx
);
1391 } else if (ctx
->type
== MFCINST_ENCODER
) {
1392 switch (ctx
->state
) {
1393 case MFCINST_FINISHING
:
1394 case MFCINST_RUNNING
:
1395 ret
= s5p_mfc_run_enc_frame(ctx
);
1398 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, open_inst_cmd
,
1401 case MFCINST_RETURN_INST
:
1402 ret
= s5p_mfc_hw_call(dev
->mfc_cmds
, close_inst_cmd
,
1405 case MFCINST_GOT_INST
:
1406 s5p_mfc_run_init_enc(ctx
);
1412 mfc_err("Invalid context type: %d\n", ctx
->type
);
1417 /* Free hardware lock */
1418 if (test_and_clear_bit(0, &dev
->hw_lock
) == 0)
1419 mfc_err("Failed to unlock hardware\n");
1421 /* This is in deed imporant, as no operation has been
1422 * scheduled, reduce the clock count as no one will
1423 * ever do this, because no interrupt related to this try_run
1424 * will ever come from hardware. */
1425 s5p_mfc_clock_off();
1429 static void s5p_mfc_clear_int_flags_v5(struct s5p_mfc_dev
*dev
)
1431 mfc_write(dev
, 0, S5P_FIMV_RISC_HOST_INT
);
1432 mfc_write(dev
, 0, S5P_FIMV_RISC2HOST_CMD
);
1433 mfc_write(dev
, 0xffff, S5P_FIMV_SI_RTN_CHID
);
1436 static int s5p_mfc_get_dspl_y_adr_v5(struct s5p_mfc_dev
*dev
)
1438 return mfc_read(dev
, S5P_FIMV_SI_DISPLAY_Y_ADR
) << MFC_OFFSET_SHIFT
;
1441 static int s5p_mfc_get_dec_y_adr_v5(struct s5p_mfc_dev
*dev
)
1443 return mfc_read(dev
, S5P_FIMV_SI_DECODE_Y_ADR
) << MFC_OFFSET_SHIFT
;
1446 static int s5p_mfc_get_dspl_status_v5(struct s5p_mfc_dev
*dev
)
1448 return mfc_read(dev
, S5P_FIMV_SI_DISPLAY_STATUS
);
1451 static int s5p_mfc_get_dec_status_v5(struct s5p_mfc_dev
*dev
)
1453 return mfc_read(dev
, S5P_FIMV_SI_DECODE_STATUS
);
1456 static int s5p_mfc_get_dec_frame_type_v5(struct s5p_mfc_dev
*dev
)
1458 return mfc_read(dev
, S5P_FIMV_DECODE_FRAME_TYPE
) &
1459 S5P_FIMV_DECODE_FRAME_MASK
;
1462 static int s5p_mfc_get_disp_frame_type_v5(struct s5p_mfc_ctx
*ctx
)
1464 return (s5p_mfc_read_info_v5(ctx
, DISP_PIC_FRAME_TYPE
) >>
1465 S5P_FIMV_SHARED_DISP_FRAME_TYPE_SHIFT
) &
1466 S5P_FIMV_DECODE_FRAME_MASK
;
1469 static int s5p_mfc_get_consumed_stream_v5(struct s5p_mfc_dev
*dev
)
1471 return mfc_read(dev
, S5P_FIMV_SI_CONSUMED_BYTES
);
1474 static int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev
*dev
)
1477 reason
= mfc_read(dev
, S5P_FIMV_RISC2HOST_CMD
) &
1478 S5P_FIMV_RISC2HOST_CMD_MASK
;
1480 case S5P_FIMV_R2H_CMD_OPEN_INSTANCE_RET
:
1481 reason
= S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET
;
1483 case S5P_FIMV_R2H_CMD_CLOSE_INSTANCE_RET
:
1484 reason
= S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET
;
1486 case S5P_FIMV_R2H_CMD_SEQ_DONE_RET
:
1487 reason
= S5P_MFC_R2H_CMD_SEQ_DONE_RET
;
1489 case S5P_FIMV_R2H_CMD_FRAME_DONE_RET
:
1490 reason
= S5P_MFC_R2H_CMD_FRAME_DONE_RET
;
1492 case S5P_FIMV_R2H_CMD_SLICE_DONE_RET
:
1493 reason
= S5P_MFC_R2H_CMD_SLICE_DONE_RET
;
1495 case S5P_FIMV_R2H_CMD_SYS_INIT_RET
:
1496 reason
= S5P_MFC_R2H_CMD_SYS_INIT_RET
;
1498 case S5P_FIMV_R2H_CMD_FW_STATUS_RET
:
1499 reason
= S5P_MFC_R2H_CMD_FW_STATUS_RET
;
1501 case S5P_FIMV_R2H_CMD_SLEEP_RET
:
1502 reason
= S5P_MFC_R2H_CMD_SLEEP_RET
;
1504 case S5P_FIMV_R2H_CMD_WAKEUP_RET
:
1505 reason
= S5P_MFC_R2H_CMD_WAKEUP_RET
;
1507 case S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET
:
1508 reason
= S5P_MFC_R2H_CMD_INIT_BUFFERS_RET
;
1510 case S5P_FIMV_R2H_CMD_ENC_COMPLETE_RET
:
1511 reason
= S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET
;
1513 case S5P_FIMV_R2H_CMD_ERR_RET
:
1514 reason
= S5P_MFC_R2H_CMD_ERR_RET
;
1517 reason
= S5P_MFC_R2H_CMD_EMPTY
;
1522 static int s5p_mfc_get_int_err_v5(struct s5p_mfc_dev
*dev
)
1524 return mfc_read(dev
, S5P_FIMV_RISC2HOST_ARG2
);
1527 static int s5p_mfc_err_dec_v5(unsigned int err
)
1529 return (err
& S5P_FIMV_ERR_DEC_MASK
) >> S5P_FIMV_ERR_DEC_SHIFT
;
1532 static int s5p_mfc_get_img_width_v5(struct s5p_mfc_dev
*dev
)
1534 return mfc_read(dev
, S5P_FIMV_SI_HRESOL
);
1537 static int s5p_mfc_get_img_height_v5(struct s5p_mfc_dev
*dev
)
1539 return mfc_read(dev
, S5P_FIMV_SI_VRESOL
);
1542 static int s5p_mfc_get_dpb_count_v5(struct s5p_mfc_dev
*dev
)
1544 return mfc_read(dev
, S5P_FIMV_SI_BUF_NUMBER
);
1547 static int s5p_mfc_get_mv_count_v5(struct s5p_mfc_dev
*dev
)
1553 static int s5p_mfc_get_inst_no_v5(struct s5p_mfc_dev
*dev
)
1555 return mfc_read(dev
, S5P_FIMV_RISC2HOST_ARG1
);
1558 static int s5p_mfc_get_enc_strm_size_v5(struct s5p_mfc_dev
*dev
)
1560 return mfc_read(dev
, S5P_FIMV_ENC_SI_STRM_SIZE
);
1563 static int s5p_mfc_get_enc_slice_type_v5(struct s5p_mfc_dev
*dev
)
1565 return mfc_read(dev
, S5P_FIMV_ENC_SI_SLICE_TYPE
);
1568 static int s5p_mfc_get_enc_dpb_count_v5(struct s5p_mfc_dev
*dev
)
1573 static unsigned int s5p_mfc_get_pic_type_top_v5(struct s5p_mfc_ctx
*ctx
)
1575 return s5p_mfc_read_info_v5(ctx
, PIC_TIME_TOP
);
1578 static unsigned int s5p_mfc_get_pic_type_bot_v5(struct s5p_mfc_ctx
*ctx
)
1580 return s5p_mfc_read_info_v5(ctx
, PIC_TIME_BOT
);
1583 static unsigned int s5p_mfc_get_crop_info_h_v5(struct s5p_mfc_ctx
*ctx
)
1585 return s5p_mfc_read_info_v5(ctx
, CROP_INFO_H
);
1588 static unsigned int s5p_mfc_get_crop_info_v_v5(struct s5p_mfc_ctx
*ctx
)
1590 return s5p_mfc_read_info_v5(ctx
, CROP_INFO_V
);
1593 /* Initialize opr function pointers for MFC v5 */
1594 static struct s5p_mfc_hw_ops s5p_mfc_ops_v5
= {
1595 .alloc_dec_temp_buffers
= s5p_mfc_alloc_dec_temp_buffers_v5
,
1596 .release_dec_desc_buffer
= s5p_mfc_release_dec_desc_buffer_v5
,
1597 .alloc_codec_buffers
= s5p_mfc_alloc_codec_buffers_v5
,
1598 .release_codec_buffers
= s5p_mfc_release_codec_buffers_v5
,
1599 .alloc_instance_buffer
= s5p_mfc_alloc_instance_buffer_v5
,
1600 .release_instance_buffer
= s5p_mfc_release_instance_buffer_v5
,
1601 .alloc_dev_context_buffer
= s5p_mfc_alloc_dev_context_buffer_v5
,
1602 .release_dev_context_buffer
= s5p_mfc_release_dev_context_buffer_v5
,
1603 .dec_calc_dpb_size
= s5p_mfc_dec_calc_dpb_size_v5
,
1604 .enc_calc_src_size
= s5p_mfc_enc_calc_src_size_v5
,
1605 .set_enc_stream_buffer
= s5p_mfc_set_enc_stream_buffer_v5
,
1606 .set_enc_frame_buffer
= s5p_mfc_set_enc_frame_buffer_v5
,
1607 .get_enc_frame_buffer
= s5p_mfc_get_enc_frame_buffer_v5
,
1608 .try_run
= s5p_mfc_try_run_v5
,
1609 .clear_int_flags
= s5p_mfc_clear_int_flags_v5
,
1610 .get_dspl_y_adr
= s5p_mfc_get_dspl_y_adr_v5
,
1611 .get_dec_y_adr
= s5p_mfc_get_dec_y_adr_v5
,
1612 .get_dspl_status
= s5p_mfc_get_dspl_status_v5
,
1613 .get_dec_status
= s5p_mfc_get_dec_status_v5
,
1614 .get_dec_frame_type
= s5p_mfc_get_dec_frame_type_v5
,
1615 .get_disp_frame_type
= s5p_mfc_get_disp_frame_type_v5
,
1616 .get_consumed_stream
= s5p_mfc_get_consumed_stream_v5
,
1617 .get_int_reason
= s5p_mfc_get_int_reason_v5
,
1618 .get_int_err
= s5p_mfc_get_int_err_v5
,
1619 .err_dec
= s5p_mfc_err_dec_v5
,
1620 .get_img_width
= s5p_mfc_get_img_width_v5
,
1621 .get_img_height
= s5p_mfc_get_img_height_v5
,
1622 .get_dpb_count
= s5p_mfc_get_dpb_count_v5
,
1623 .get_mv_count
= s5p_mfc_get_mv_count_v5
,
1624 .get_inst_no
= s5p_mfc_get_inst_no_v5
,
1625 .get_enc_strm_size
= s5p_mfc_get_enc_strm_size_v5
,
1626 .get_enc_slice_type
= s5p_mfc_get_enc_slice_type_v5
,
1627 .get_enc_dpb_count
= s5p_mfc_get_enc_dpb_count_v5
,
1628 .get_pic_type_top
= s5p_mfc_get_pic_type_top_v5
,
1629 .get_pic_type_bot
= s5p_mfc_get_pic_type_bot_v5
,
1630 .get_crop_info_h
= s5p_mfc_get_crop_info_h_v5
,
1631 .get_crop_info_v
= s5p_mfc_get_crop_info_v_v5
,
1634 struct s5p_mfc_hw_ops
*s5p_mfc_init_hw_ops_v5(void)
1636 return &s5p_mfc_ops_v5
;