s5p_mfc_opr_v6.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  1. /*
  2. * drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
  3. *
  4. * Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains hw related functions.
  6. *
  7. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  8. * http://www.samsung.com/
  9. *
  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.
  13. */
  14. #undef DEBUG
  15. #include <linux/delay.h>
  16. #include <linux/mm.h>
  17. #include <linux/io.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/firmware.h>
  20. #include <linux/err.h>
  21. #include <linux/sched.h>
  22. #include <linux/dma-mapping.h>
  23. #include <asm/cacheflush.h>
  24. #include "s5p_mfc_common.h"
  25. #include "s5p_mfc_cmd.h"
  26. #include "s5p_mfc_intr.h"
  27. #include "s5p_mfc_pm.h"
  28. #include "s5p_mfc_debug.h"
  29. #include "s5p_mfc_opr.h"
  30. #include "s5p_mfc_opr_v6.h"
  31. /* #define S5P_MFC_DEBUG_REGWRITE */
  32. #ifdef S5P_MFC_DEBUG_REGWRITE
  33. #undef writel
  34. #define writel(v, r) \
  35. do { \
  36. pr_err("MFCWRITE(%p): %08x\n", r, (unsigned int)v); \
  37. __raw_writel(v, r); \
  38. } while (0)
  39. #endif /* S5P_MFC_DEBUG_REGWRITE */
  40. #define READL(offset) readl(dev->regs_base + (offset))
  41. #define WRITEL(data, offset) writel((data), dev->regs_base + (offset))
  42. #define OFFSETA(x) (((x) - dev->port_a) >> S5P_FIMV_MEM_OFFSET)
  43. #define OFFSETB(x) (((x) - dev->port_b) >> S5P_FIMV_MEM_OFFSET)
  44. /* Allocate temporary buffers for decoding */
  45. int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
  46. {
  47. /* NOP */
  48. return 0;
  49. }
  50. /* Release temproary buffers for decoding */
  51. void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
  52. {
  53. /* NOP */
  54. }
  55. int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
  56. {
  57. /* NOP */
  58. return -1;
  59. }
  60. /* Allocate codec buffers */
  61. int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  62. {
  63. struct s5p_mfc_dev *dev = ctx->dev;
  64. unsigned int mb_width, mb_height;
  65. mb_width = MB_WIDTH(ctx->img_width);
  66. mb_height = MB_HEIGHT(ctx->img_height);
  67. if (ctx->type == MFCINST_DECODER) {
  68. mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
  69. ctx->luma_size, ctx->chroma_size, ctx->mv_size);
  70. mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
  71. } else if (ctx->type == MFCINST_ENCODER) {
  72. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  73. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
  74. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  75. ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
  76. S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
  77. S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
  78. ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
  79. S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
  80. S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
  81. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
  82. ctx->img_width, ctx->img_height,
  83. mb_width, mb_height),
  84. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  85. mfc_debug(2, "recon luma size: %d chroma size: %d\n",
  86. ctx->luma_dpb_size, ctx->chroma_dpb_size);
  87. } else {
  88. return -EINVAL;
  89. }
  90. /* Codecs have different memory requirements */
  91. switch (ctx->codec_mode) {
  92. case S5P_MFC_CODEC_H264_DEC:
  93. case S5P_MFC_CODEC_H264_MVC_DEC:
  94. ctx->scratch_buf_size =
  95. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
  96. mb_width,
  97. mb_height);
  98. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  99. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  100. ctx->bank1_size =
  101. ctx->scratch_buf_size +
  102. (ctx->mv_count * ctx->mv_size);
  103. break;
  104. case S5P_MFC_CODEC_MPEG4_DEC:
  105. ctx->scratch_buf_size =
  106. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
  107. mb_width,
  108. mb_height);
  109. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  110. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  111. ctx->bank1_size = ctx->scratch_buf_size;
  112. break;
  113. case S5P_MFC_CODEC_VC1RCV_DEC:
  114. case S5P_MFC_CODEC_VC1_DEC:
  115. ctx->scratch_buf_size =
  116. S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
  117. mb_width,
  118. mb_height);
  119. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  120. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  121. ctx->bank1_size = ctx->scratch_buf_size;
  122. break;
  123. case S5P_MFC_CODEC_MPEG2_DEC:
  124. ctx->bank1_size = 0;
  125. ctx->bank2_size = 0;
  126. break;
  127. case S5P_MFC_CODEC_H263_DEC:
  128. ctx->scratch_buf_size =
  129. S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
  130. mb_width,
  131. mb_height);
  132. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  133. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  134. ctx->bank1_size = ctx->scratch_buf_size;
  135. break;
  136. case S5P_MFC_CODEC_VP8_DEC:
  137. ctx->scratch_buf_size =
  138. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
  139. mb_width,
  140. mb_height);
  141. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  142. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  143. ctx->bank1_size = ctx->scratch_buf_size;
  144. break;
  145. case S5P_MFC_CODEC_H264_ENC:
  146. ctx->scratch_buf_size =
  147. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
  148. mb_width,
  149. mb_height);
  150. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  151. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  152. ctx->bank1_size =
  153. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  154. (ctx->dpb_count * (ctx->luma_dpb_size +
  155. ctx->chroma_dpb_size + ctx->me_buffer_size));
  156. ctx->bank2_size = 0;
  157. break;
  158. case S5P_MFC_CODEC_MPEG4_ENC:
  159. case S5P_MFC_CODEC_H263_ENC:
  160. ctx->scratch_buf_size =
  161. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
  162. mb_width,
  163. mb_height);
  164. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  165. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  166. ctx->bank1_size =
  167. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  168. (ctx->dpb_count * (ctx->luma_dpb_size +
  169. ctx->chroma_dpb_size + ctx->me_buffer_size));
  170. ctx->bank2_size = 0;
  171. break;
  172. default:
  173. break;
  174. }
  175. /* Allocate only if memory from bank 1 is necessary */
  176. if (ctx->bank1_size > 0) {
  177. ctx->bank1_buf = vb2_dma_contig_memops.alloc(
  178. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_size);
  179. if (IS_ERR(ctx->bank1_buf)) {
  180. ctx->bank1_buf = 0;
  181. pr_err("Buf alloc for decoding failed (port A)\n");
  182. return -ENOMEM;
  183. }
  184. ctx->bank1_phys = s5p_mfc_mem_cookie(
  185. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_buf);
  186. BUG_ON(ctx->bank1_phys & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  187. }
  188. return 0;
  189. }
  190. /* Release buffers allocated for codec */
  191. void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  192. {
  193. if (ctx->bank1_buf) {
  194. vb2_dma_contig_memops.put(ctx->bank1_buf);
  195. ctx->bank1_buf = 0;
  196. ctx->bank1_phys = 0;
  197. ctx->bank1_size = 0;
  198. }
  199. }
  200. /* Allocate memory for instance data buffer */
  201. int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  202. {
  203. struct s5p_mfc_dev *dev = ctx->dev;
  204. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  205. mfc_debug_enter();
  206. switch (ctx->codec_mode) {
  207. case S5P_MFC_CODEC_H264_DEC:
  208. case S5P_MFC_CODEC_H264_MVC_DEC:
  209. ctx->ctx.size = buf_size->h264_dec_ctx;
  210. break;
  211. case S5P_MFC_CODEC_MPEG4_DEC:
  212. case S5P_MFC_CODEC_H263_DEC:
  213. case S5P_MFC_CODEC_VC1RCV_DEC:
  214. case S5P_MFC_CODEC_VC1_DEC:
  215. case S5P_MFC_CODEC_MPEG2_DEC:
  216. case S5P_MFC_CODEC_VP8_DEC:
  217. ctx->ctx.size = buf_size->other_dec_ctx;
  218. break;
  219. case S5P_MFC_CODEC_H264_ENC:
  220. ctx->ctx.size = buf_size->h264_enc_ctx;
  221. break;
  222. case S5P_MFC_CODEC_MPEG4_ENC:
  223. case S5P_MFC_CODEC_H263_ENC:
  224. ctx->ctx.size = buf_size->other_enc_ctx;
  225. break;
  226. default:
  227. ctx->ctx.size = 0;
  228. mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
  229. break;
  230. }
  231. ctx->ctx.alloc = vb2_dma_contig_memops.alloc(
  232. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.size);
  233. if (IS_ERR(ctx->ctx.alloc)) {
  234. mfc_err("Allocating context buffer failed.\n");
  235. return PTR_ERR(ctx->ctx.alloc);
  236. }
  237. ctx->ctx.dma = s5p_mfc_mem_cookie(
  238. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.alloc);
  239. ctx->ctx.virt = vb2_dma_contig_memops.vaddr(ctx->ctx.alloc);
  240. if (!ctx->ctx.virt) {
  241. vb2_dma_contig_memops.put(ctx->ctx.alloc);
  242. ctx->ctx.alloc = NULL;
  243. ctx->ctx.dma = 0;
  244. ctx->ctx.virt = NULL;
  245. mfc_err("Remapping context buffer failed.\n");
  246. return -ENOMEM;
  247. }
  248. memset(ctx->ctx.virt, 0, ctx->ctx.size);
  249. wmb();
  250. mfc_debug_leave();
  251. return 0;
  252. }
  253. /* Release instance buffer */
  254. void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  255. {
  256. mfc_debug_enter();
  257. if (ctx->ctx.alloc) {
  258. vb2_dma_contig_memops.put(ctx->ctx.alloc);
  259. ctx->ctx.alloc = NULL;
  260. ctx->ctx.dma = 0;
  261. ctx->ctx.virt = NULL;
  262. }
  263. mfc_debug_leave();
  264. }
  265. /* Allocate context buffers for SYS_INIT */
  266. int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  267. {
  268. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  269. mfc_debug_enter();
  270. dev->ctx_buf.alloc = vb2_dma_contig_memops.alloc(
  271. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], buf_size->dev_ctx);
  272. if (IS_ERR(dev->ctx_buf.alloc)) {
  273. mfc_err("Allocating DESC buffer failed.\n");
  274. return PTR_ERR(dev->ctx_buf.alloc);
  275. }
  276. dev->ctx_buf.dma = s5p_mfc_mem_cookie(
  277. dev->alloc_ctx[MFC_BANK1_ALLOC_CTX],
  278. dev->ctx_buf.alloc);
  279. dev->ctx_buf.virt = vb2_dma_contig_memops.vaddr(dev->ctx_buf.alloc);
  280. if (!dev->ctx_buf.virt) {
  281. vb2_dma_contig_memops.put(dev->ctx_buf.alloc);
  282. dev->ctx_buf.alloc = NULL;
  283. dev->ctx_buf.dma = 0;
  284. mfc_err("Remapping DESC buffer failed.\n");
  285. return -ENOMEM;
  286. }
  287. memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
  288. wmb();
  289. mfc_debug_leave();
  290. return 0;
  291. }
  292. /* Release context buffers for SYS_INIT */
  293. void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  294. {
  295. if (dev->ctx_buf.alloc) {
  296. vb2_dma_contig_memops.put(dev->ctx_buf.alloc);
  297. dev->ctx_buf.alloc = NULL;
  298. dev->ctx_buf.dma = 0;
  299. dev->ctx_buf.virt = NULL;
  300. }
  301. }
  302. static int calc_plane(int width, int height)
  303. {
  304. int mbX, mbY;
  305. mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  306. mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
  307. if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
  308. mbY = (mbY + 1) / 2 * 2;
  309. return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
  310. (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  311. }
  312. void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
  313. {
  314. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
  315. ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
  316. mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
  317. "buffer dimensions: %dx%d\n", ctx->img_width,
  318. ctx->img_height, ctx->buf_width, ctx->buf_height);
  319. ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
  320. ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
  321. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  322. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  323. ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
  324. ctx->img_height);
  325. ctx->mv_size = ALIGN(ctx->mv_size, 16);
  326. } else {
  327. ctx->mv_size = 0;
  328. }
  329. }
  330. void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
  331. {
  332. unsigned int mb_width, mb_height;
  333. mb_width = MB_WIDTH(ctx->img_width);
  334. mb_height = MB_HEIGHT(ctx->img_height);
  335. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
  336. ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
  337. ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
  338. }
  339. /* Set registers for decoding stream buffer */
  340. int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, int buf_addr,
  341. unsigned int start_num_byte, unsigned int strm_size)
  342. {
  343. struct s5p_mfc_dev *dev = ctx->dev;
  344. struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
  345. mfc_debug_enter();
  346. mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
  347. "buf_size: 0x%08x (%d)\n",
  348. ctx->inst_no, buf_addr, strm_size, strm_size);
  349. WRITEL(strm_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
  350. WRITEL(buf_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
  351. WRITEL(buf_size->cpb, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
  352. WRITEL(start_num_byte, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
  353. mfc_debug_leave();
  354. return 0;
  355. }
  356. /* Set decoding frame buffer */
  357. int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
  358. {
  359. unsigned int frame_size, i;
  360. unsigned int frame_size_ch, frame_size_mv;
  361. struct s5p_mfc_dev *dev = ctx->dev;
  362. size_t buf_addr1;
  363. int buf_size1;
  364. int align_gap;
  365. buf_addr1 = ctx->bank1_phys;
  366. buf_size1 = ctx->bank1_size;
  367. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  368. mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
  369. mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
  370. WRITEL(ctx->total_dpb_count, S5P_FIMV_D_NUM_DPB_V6);
  371. WRITEL(ctx->luma_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
  372. WRITEL(ctx->chroma_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
  373. WRITEL(buf_addr1, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
  374. WRITEL(ctx->scratch_buf_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
  375. buf_addr1 += ctx->scratch_buf_size;
  376. buf_size1 -= ctx->scratch_buf_size;
  377. if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
  378. ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
  379. WRITEL(ctx->mv_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
  380. WRITEL(ctx->mv_count, S5P_FIMV_D_NUM_MV_V6);
  381. }
  382. frame_size = ctx->luma_size;
  383. frame_size_ch = ctx->chroma_size;
  384. frame_size_mv = ctx->mv_size;
  385. mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
  386. frame_size, frame_size_ch, frame_size_mv);
  387. for (i = 0; i < ctx->total_dpb_count; i++) {
  388. /* Bank2 */
  389. mfc_debug(2, "Luma %d: %x\n", i,
  390. ctx->dst_bufs[i].cookie.raw.luma);
  391. WRITEL(ctx->dst_bufs[i].cookie.raw.luma,
  392. S5P_FIMV_D_LUMA_DPB_V6 + i * 4);
  393. mfc_debug(2, "\tChroma %d: %x\n", i,
  394. ctx->dst_bufs[i].cookie.raw.chroma);
  395. WRITEL(ctx->dst_bufs[i].cookie.raw.chroma,
  396. S5P_FIMV_D_CHROMA_DPB_V6 + i * 4);
  397. }
  398. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  399. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  400. for (i = 0; i < ctx->mv_count; i++) {
  401. /* To test alignment */
  402. align_gap = buf_addr1;
  403. buf_addr1 = ALIGN(buf_addr1, 16);
  404. align_gap = buf_addr1 - align_gap;
  405. buf_size1 -= align_gap;
  406. mfc_debug(2, "\tBuf1: %x, size: %d\n",
  407. buf_addr1, buf_size1);
  408. WRITEL(buf_addr1, S5P_FIMV_D_MV_BUFFER_V6 + i * 4);
  409. buf_addr1 += frame_size_mv;
  410. buf_size1 -= frame_size_mv;
  411. }
  412. }
  413. mfc_debug(2, "Buf1: %u, buf_size1: %d (frames %d)\n",
  414. buf_addr1, buf_size1, ctx->total_dpb_count);
  415. if (buf_size1 < 0) {
  416. mfc_debug(2, "Not enough memory has been allocated.\n");
  417. return -ENOMEM;
  418. }
  419. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  420. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  421. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  422. mfc_debug(2, "After setting buffers.\n");
  423. return 0;
  424. }
  425. /* Set registers for encoding stream buffer */
  426. int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  427. unsigned long addr, unsigned int size)
  428. {
  429. struct s5p_mfc_dev *dev = ctx->dev;
  430. WRITEL(addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6); /* 16B align */
  431. WRITEL(size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
  432. mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d",
  433. addr, size);
  434. return 0;
  435. }
  436. void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  437. unsigned long y_addr, unsigned long c_addr)
  438. {
  439. struct s5p_mfc_dev *dev = ctx->dev;
  440. WRITEL(y_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6); /* 256B align */
  441. WRITEL(c_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
  442. mfc_debug(2, "enc src y buf addr: 0x%08lx", y_addr);
  443. mfc_debug(2, "enc src c buf addr: 0x%08lx", c_addr);
  444. }
  445. void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  446. unsigned long *y_addr, unsigned long *c_addr)
  447. {
  448. struct s5p_mfc_dev *dev = ctx->dev;
  449. unsigned long enc_recon_y_addr, enc_recon_c_addr;
  450. *y_addr = READL(S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
  451. *c_addr = READL(S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
  452. enc_recon_y_addr = READL(S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
  453. enc_recon_c_addr = READL(S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
  454. mfc_debug(2, "recon y addr: 0x%08lx", enc_recon_y_addr);
  455. mfc_debug(2, "recon c addr: 0x%08lx", enc_recon_c_addr);
  456. }
  457. /* Set encoding ref & codec buffer */
  458. int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
  459. {
  460. struct s5p_mfc_dev *dev = ctx->dev;
  461. size_t buf_addr1, buf_size1;
  462. int i;
  463. mfc_debug_enter();
  464. buf_addr1 = ctx->bank1_phys;
  465. buf_size1 = ctx->bank1_size;
  466. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  467. for (i = 0; i < ctx->dpb_count; i++) {
  468. WRITEL(buf_addr1, S5P_FIMV_E_LUMA_DPB_V6 + (4 * i));
  469. buf_addr1 += ctx->luma_dpb_size;
  470. WRITEL(buf_addr1, S5P_FIMV_E_CHROMA_DPB_V6 + (4 * i));
  471. buf_addr1 += ctx->chroma_dpb_size;
  472. WRITEL(buf_addr1, S5P_FIMV_E_ME_BUFFER_V6 + (4 * i));
  473. buf_addr1 += ctx->me_buffer_size;
  474. buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
  475. ctx->me_buffer_size);
  476. }
  477. WRITEL(buf_addr1, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
  478. WRITEL(ctx->scratch_buf_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
  479. buf_addr1 += ctx->scratch_buf_size;
  480. buf_size1 -= ctx->scratch_buf_size;
  481. WRITEL(buf_addr1, S5P_FIMV_E_TMV_BUFFER0_V6);
  482. buf_addr1 += ctx->tmv_buffer_size >> 1;
  483. WRITEL(buf_addr1, S5P_FIMV_E_TMV_BUFFER1_V6);
  484. buf_addr1 += ctx->tmv_buffer_size >> 1;
  485. buf_size1 -= ctx->tmv_buffer_size;
  486. mfc_debug(2, "Buf1: %u, buf_size1: %d (ref frames %d)\n",
  487. buf_addr1, buf_size1, ctx->dpb_count);
  488. if (buf_size1 < 0) {
  489. mfc_debug(2, "Not enough memory has been allocated.\n");
  490. return -ENOMEM;
  491. }
  492. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  493. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  494. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  495. mfc_debug_leave();
  496. return 0;
  497. }
  498. static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
  499. {
  500. struct s5p_mfc_dev *dev = ctx->dev;
  501. /* multi-slice control */
  502. /* multi-slice MB number or bit size */
  503. WRITEL(ctx->slice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
  504. if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  505. WRITEL(ctx->slice_size.mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  506. } else if (ctx->slice_mode ==
  507. V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  508. WRITEL(ctx->slice_size.bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  509. } else {
  510. WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  511. WRITEL(0x0, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  512. }
  513. return 0;
  514. }
  515. static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
  516. {
  517. struct s5p_mfc_dev *dev = ctx->dev;
  518. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  519. unsigned int reg = 0;
  520. mfc_debug_enter();
  521. /* width */
  522. WRITEL(ctx->img_width, S5P_FIMV_E_FRAME_WIDTH_V6); /* 16 align */
  523. /* height */
  524. WRITEL(ctx->img_height, S5P_FIMV_E_FRAME_HEIGHT_V6); /* 16 align */
  525. /* cropped width */
  526. WRITEL(ctx->img_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
  527. /* cropped height */
  528. WRITEL(ctx->img_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  529. /* cropped offset */
  530. WRITEL(0x0, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
  531. /* pictype : IDR period */
  532. reg = 0;
  533. reg |= p->gop_size & 0xFFFF;
  534. WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
  535. /* multi-slice control */
  536. /* multi-slice MB number or bit size */
  537. ctx->slice_mode = p->slice_mode;
  538. reg = 0;
  539. if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  540. reg |= (0x1 << 3);
  541. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  542. ctx->slice_size.mb = p->slice_mb;
  543. } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  544. reg |= (0x1 << 3);
  545. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  546. ctx->slice_size.bits = p->slice_bit;
  547. } else {
  548. reg &= ~(0x1 << 3);
  549. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  550. }
  551. s5p_mfc_set_slice_mode(ctx);
  552. /* cyclic intra refresh */
  553. WRITEL(p->intra_refresh_mb, S5P_FIMV_E_IR_SIZE_V6);
  554. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  555. if (p->intra_refresh_mb == 0)
  556. reg &= ~(0x1 << 4);
  557. else
  558. reg |= (0x1 << 4);
  559. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  560. /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
  561. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  562. reg &= ~(0x1 << 9);
  563. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  564. /* memory structure cur. frame */
  565. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
  566. /* 0: Linear, 1: 2D tiled*/
  567. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  568. reg &= ~(0x1 << 7);
  569. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  570. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  571. WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
  572. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
  573. /* 0: Linear, 1: 2D tiled*/
  574. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  575. reg &= ~(0x1 << 7);
  576. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  577. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  578. WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6);
  579. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
  580. /* 0: Linear, 1: 2D tiled*/
  581. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  582. reg |= (0x1 << 7);
  583. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  584. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  585. WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
  586. }
  587. /* memory structure recon. frame */
  588. /* 0: Linear, 1: 2D tiled */
  589. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  590. reg |= (0x1 << 8);
  591. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  592. /* padding control & value */
  593. WRITEL(0x0, S5P_FIMV_E_PADDING_CTRL_V6);
  594. if (p->pad) {
  595. reg = 0;
  596. /** enable */
  597. reg |= (1 << 31);
  598. /** cr value */
  599. reg |= ((p->pad_cr & 0xFF) << 16);
  600. /** cb value */
  601. reg |= ((p->pad_cb & 0xFF) << 8);
  602. /** y value */
  603. reg |= p->pad_luma & 0xFF;
  604. WRITEL(reg, S5P_FIMV_E_PADDING_CTRL_V6);
  605. }
  606. /* rate control config. */
  607. reg = 0;
  608. /* frame-level rate control */
  609. reg |= ((p->rc_frame & 0x1) << 9);
  610. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  611. /* bit rate */
  612. if (p->rc_frame)
  613. WRITEL(p->rc_bitrate,
  614. S5P_FIMV_E_RC_BIT_RATE_V6);
  615. else
  616. WRITEL(1, S5P_FIMV_E_RC_BIT_RATE_V6);
  617. /* reaction coefficient */
  618. if (p->rc_frame) {
  619. if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
  620. WRITEL(1, S5P_FIMV_E_RC_RPARAM_V6);
  621. else /* loose CBR */
  622. WRITEL(2, S5P_FIMV_E_RC_RPARAM_V6);
  623. }
  624. /* seq header ctrl */
  625. reg = READL(S5P_FIMV_E_ENC_OPTIONS_V6);
  626. reg &= ~(0x1 << 2);
  627. reg |= ((p->seq_hdr_mode & 0x1) << 2);
  628. /* frame skip mode */
  629. reg &= ~(0x3);
  630. reg |= (p->frame_skip_mode & 0x3);
  631. WRITEL(reg, S5P_FIMV_E_ENC_OPTIONS_V6);
  632. /* 'DROP_CONTROL_ENABLE', disable */
  633. reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
  634. reg &= ~(0x1 << 10);
  635. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  636. /* setting for MV range [16, 256] */
  637. reg = 0;
  638. reg &= ~(0x3FFF);
  639. reg = 256;
  640. WRITEL(reg, S5P_FIMV_E_MV_HOR_RANGE_V6);
  641. reg = 0;
  642. reg &= ~(0x3FFF);
  643. reg = 256;
  644. WRITEL(reg, S5P_FIMV_E_MV_VER_RANGE_V6);
  645. WRITEL(0x0, S5P_FIMV_E_FRAME_INSERTION_V6);
  646. WRITEL(0x0, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
  647. WRITEL(0x0, S5P_FIMV_E_PARAM_CHANGE_V6);
  648. WRITEL(0x0, S5P_FIMV_E_RC_ROI_CTRL_V6);
  649. WRITEL(0x0, S5P_FIMV_E_PICTURE_TAG_V6);
  650. WRITEL(0x0, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
  651. WRITEL(0x0, S5P_FIMV_E_MAX_BIT_COUNT_V6);
  652. WRITEL(0x0, S5P_FIMV_E_MIN_BIT_COUNT_V6);
  653. WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
  654. WRITEL(0x0, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
  655. mfc_debug_leave();
  656. return 0;
  657. }
  658. static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
  659. {
  660. struct s5p_mfc_dev *dev = ctx->dev;
  661. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  662. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  663. unsigned int reg = 0;
  664. int i;
  665. mfc_debug_enter();
  666. s5p_mfc_set_enc_params(ctx);
  667. /* pictype : number of B */
  668. reg = READL(S5P_FIMV_E_GOP_CONFIG_V6);
  669. reg &= ~(0x3 << 16);
  670. reg |= ((p->num_b_frame & 0x3) << 16);
  671. WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
  672. /* profile & level */
  673. reg = 0;
  674. /** level */
  675. reg |= ((p_h264->level & 0xFF) << 8);
  676. /** profile - 0 ~ 3 */
  677. reg |= p_h264->profile & 0x3F;
  678. WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
  679. /* rate control config. */
  680. reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
  681. /** macroblock level rate control */
  682. reg &= ~(0x1 << 8);
  683. reg |= ((p->rc_mb & 0x1) << 8);
  684. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  685. /** frame QP */
  686. reg &= ~(0x3F);
  687. reg |= p_h264->rc_frame_qp & 0x3F;
  688. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  689. /* max & min value of QP */
  690. reg = 0;
  691. /** max QP */
  692. reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
  693. /** min QP */
  694. reg |= p_h264->rc_min_qp & 0x3F;
  695. WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
  696. /* other QPs */
  697. WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  698. if (!p->rc_frame && !p->rc_mb) {
  699. reg = 0;
  700. reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
  701. reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
  702. reg |= p_h264->rc_frame_qp & 0x3F;
  703. WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  704. }
  705. /* frame rate */
  706. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  707. reg = 0;
  708. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  709. reg |= p->rc_framerate_denom & 0xFFFF;
  710. WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
  711. }
  712. /* vbv buffer size */
  713. if (p->frame_skip_mode ==
  714. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  715. WRITEL(p_h264->cpb_size & 0xFFFF,
  716. S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  717. if (p->rc_frame)
  718. WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  719. }
  720. /* interlace */
  721. reg = 0;
  722. reg |= ((p_h264->interlace & 0x1) << 3);
  723. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  724. /* height */
  725. if (p_h264->interlace) {
  726. WRITEL(ctx->img_height >> 1,
  727. S5P_FIMV_E_FRAME_HEIGHT_V6); /* 32 align */
  728. /* cropped height */
  729. WRITEL(ctx->img_height >> 1,
  730. S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  731. }
  732. /* loop filter ctrl */
  733. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  734. reg &= ~(0x3 << 1);
  735. reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
  736. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  737. /* loopfilter alpha offset */
  738. if (p_h264->loop_filter_alpha < 0) {
  739. reg = 0x10;
  740. reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
  741. } else {
  742. reg = 0x00;
  743. reg |= (p_h264->loop_filter_alpha & 0xF);
  744. }
  745. WRITEL(reg, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
  746. /* loopfilter beta offset */
  747. if (p_h264->loop_filter_beta < 0) {
  748. reg = 0x10;
  749. reg |= (0xFF - p_h264->loop_filter_beta) + 1;
  750. } else {
  751. reg = 0x00;
  752. reg |= (p_h264->loop_filter_beta & 0xF);
  753. }
  754. WRITEL(reg, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
  755. /* entropy coding mode */
  756. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  757. reg &= ~(0x1);
  758. reg |= p_h264->entropy_mode & 0x1;
  759. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  760. /* number of ref. picture */
  761. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  762. reg &= ~(0x1 << 7);
  763. reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
  764. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  765. /* 8x8 transform enable */
  766. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  767. reg &= ~(0x3 << 12);
  768. reg |= ((p_h264->_8x8_transform & 0x3) << 12);
  769. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  770. /* macroblock adaptive scaling features */
  771. WRITEL(0x0, S5P_FIMV_E_MB_RC_CONFIG_V6);
  772. if (p->rc_mb) {
  773. reg = 0;
  774. /** dark region */
  775. reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
  776. /** smooth region */
  777. reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
  778. /** static region */
  779. reg |= ((p_h264->rc_mb_static & 0x1) << 1);
  780. /** high activity region */
  781. reg |= p_h264->rc_mb_activity & 0x1;
  782. WRITEL(reg, S5P_FIMV_E_MB_RC_CONFIG_V6);
  783. }
  784. /* aspect ratio VUI */
  785. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  786. reg &= ~(0x1 << 5);
  787. reg |= ((p_h264->vui_sar & 0x1) << 5);
  788. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  789. WRITEL(0x0, S5P_FIMV_E_ASPECT_RATIO_V6);
  790. WRITEL(0x0, S5P_FIMV_E_EXTENDED_SAR_V6);
  791. if (p_h264->vui_sar) {
  792. /* aspect ration IDC */
  793. reg = 0;
  794. reg |= p_h264->vui_sar_idc & 0xFF;
  795. WRITEL(reg, S5P_FIMV_E_ASPECT_RATIO_V6);
  796. if (p_h264->vui_sar_idc == 0xFF) {
  797. /* extended SAR */
  798. reg = 0;
  799. reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
  800. reg |= p_h264->vui_ext_sar_height & 0xFFFF;
  801. WRITEL(reg, S5P_FIMV_E_EXTENDED_SAR_V6);
  802. }
  803. }
  804. /* intra picture period for H.264 open GOP */
  805. /* control */
  806. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  807. reg &= ~(0x1 << 4);
  808. reg |= ((p_h264->open_gop & 0x1) << 4);
  809. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  810. /* value */
  811. WRITEL(0x0, S5P_FIMV_E_H264_I_PERIOD_V6);
  812. if (p_h264->open_gop) {
  813. reg = 0;
  814. reg |= p_h264->open_gop_size & 0xFFFF;
  815. WRITEL(reg, S5P_FIMV_E_H264_I_PERIOD_V6);
  816. }
  817. /* 'WEIGHTED_BI_PREDICTION' for B is disable */
  818. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  819. reg &= ~(0x3 << 9);
  820. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  821. /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
  822. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  823. reg &= ~(0x1 << 14);
  824. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  825. /* ASO */
  826. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  827. reg &= ~(0x1 << 6);
  828. reg |= ((p_h264->aso & 0x1) << 6);
  829. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  830. /* hier qp enable */
  831. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  832. reg &= ~(0x1 << 8);
  833. reg |= ((p_h264->open_gop & 0x1) << 8);
  834. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  835. reg = 0;
  836. if (p_h264->hier_qp && p_h264->hier_qp_layer) {
  837. reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
  838. reg |= p_h264->hier_qp_layer & 0x7;
  839. WRITEL(reg, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  840. /* QP value for each layer */
  841. for (i = 0; i < (p_h264->hier_qp_layer & 0x7); i++)
  842. WRITEL(p_h264->hier_qp_layer_qp[i],
  843. S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6 +
  844. i * 4);
  845. }
  846. /* number of coding layer should be zero when hierarchical is disable */
  847. WRITEL(reg, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  848. /* frame packing SEI generation */
  849. reg = READL(S5P_FIMV_E_H264_OPTIONS_V6);
  850. reg &= ~(0x1 << 25);
  851. reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
  852. WRITEL(reg, S5P_FIMV_E_H264_OPTIONS_V6);
  853. if (p_h264->sei_frame_packing) {
  854. reg = 0;
  855. /** current frame0 flag */
  856. reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
  857. /** arrangement type */
  858. reg |= p_h264->sei_fp_arrangement_type & 0x3;
  859. WRITEL(reg, S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
  860. }
  861. if (p_h264->fmo) {
  862. switch (p_h264->fmo_map_type) {
  863. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
  864. if (p_h264->fmo_slice_grp > 4)
  865. p_h264->fmo_slice_grp = 4;
  866. for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
  867. WRITEL(p_h264->fmo_run_len[i] - 1,
  868. S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6 +
  869. i * 4);
  870. break;
  871. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
  872. if (p_h264->fmo_slice_grp > 4)
  873. p_h264->fmo_slice_grp = 4;
  874. break;
  875. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
  876. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
  877. if (p_h264->fmo_slice_grp > 2)
  878. p_h264->fmo_slice_grp = 2;
  879. WRITEL(p_h264->fmo_chg_dir & 0x1,
  880. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
  881. /* the valid range is 0 ~ number of macroblocks -1 */
  882. WRITEL(p_h264->fmo_chg_rate,
  883. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
  884. break;
  885. default:
  886. mfc_err("Unsupported map type for FMO: %d\n",
  887. p_h264->fmo_map_type);
  888. p_h264->fmo_map_type = 0;
  889. p_h264->fmo_slice_grp = 1;
  890. break;
  891. }
  892. WRITEL(p_h264->fmo_map_type,
  893. S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
  894. WRITEL(p_h264->fmo_slice_grp - 1,
  895. S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  896. } else {
  897. WRITEL(0, S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  898. }
  899. mfc_debug_leave();
  900. return 0;
  901. }
  902. static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
  903. {
  904. struct s5p_mfc_dev *dev = ctx->dev;
  905. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  906. struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
  907. unsigned int reg = 0;
  908. mfc_debug_enter();
  909. s5p_mfc_set_enc_params(ctx);
  910. /* pictype : number of B */
  911. reg = READL(S5P_FIMV_E_GOP_CONFIG_V6);
  912. reg &= ~(0x3 << 16);
  913. reg |= ((p->num_b_frame & 0x3) << 16);
  914. WRITEL(reg, S5P_FIMV_E_GOP_CONFIG_V6);
  915. /* profile & level */
  916. reg = 0;
  917. /** level */
  918. reg |= ((p_mpeg4->level & 0xFF) << 8);
  919. /** profile - 0 ~ 1 */
  920. reg |= p_mpeg4->profile & 0x3F;
  921. WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
  922. /* rate control config. */
  923. reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
  924. /** macroblock level rate control */
  925. reg &= ~(0x1 << 8);
  926. reg |= ((p->rc_mb & 0x1) << 8);
  927. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  928. /** frame QP */
  929. reg &= ~(0x3F);
  930. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  931. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  932. /* max & min value of QP */
  933. reg = 0;
  934. /** max QP */
  935. reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
  936. /** min QP */
  937. reg |= p_mpeg4->rc_min_qp & 0x3F;
  938. WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
  939. /* other QPs */
  940. WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  941. if (!p->rc_frame && !p->rc_mb) {
  942. reg = 0;
  943. reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
  944. reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
  945. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  946. WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  947. }
  948. /* frame rate */
  949. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  950. reg = 0;
  951. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  952. reg |= p->rc_framerate_denom & 0xFFFF;
  953. WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
  954. }
  955. /* vbv buffer size */
  956. if (p->frame_skip_mode ==
  957. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  958. WRITEL(p->vbv_size & 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  959. if (p->rc_frame)
  960. WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  961. }
  962. /* Disable HEC */
  963. WRITEL(0x0, S5P_FIMV_E_MPEG4_OPTIONS_V6);
  964. WRITEL(0x0, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
  965. mfc_debug_leave();
  966. return 0;
  967. }
  968. static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
  969. {
  970. struct s5p_mfc_dev *dev = ctx->dev;
  971. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  972. struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
  973. unsigned int reg = 0;
  974. mfc_debug_enter();
  975. s5p_mfc_set_enc_params(ctx);
  976. /* profile & level */
  977. reg = 0;
  978. /** profile */
  979. reg |= (0x1 << 4);
  980. WRITEL(reg, S5P_FIMV_E_PICTURE_PROFILE_V6);
  981. /* rate control config. */
  982. reg = READL(S5P_FIMV_E_RC_CONFIG_V6);
  983. /** macroblock level rate control */
  984. reg &= ~(0x1 << 8);
  985. reg |= ((p->rc_mb & 0x1) << 8);
  986. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  987. /** frame QP */
  988. reg &= ~(0x3F);
  989. reg |= p_h263->rc_frame_qp & 0x3F;
  990. WRITEL(reg, S5P_FIMV_E_RC_CONFIG_V6);
  991. /* max & min value of QP */
  992. reg = 0;
  993. /** max QP */
  994. reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
  995. /** min QP */
  996. reg |= p_h263->rc_min_qp & 0x3F;
  997. WRITEL(reg, S5P_FIMV_E_RC_QP_BOUND_V6);
  998. /* other QPs */
  999. WRITEL(0x0, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  1000. if (!p->rc_frame && !p->rc_mb) {
  1001. reg = 0;
  1002. reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
  1003. reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
  1004. reg |= p_h263->rc_frame_qp & 0x3F;
  1005. WRITEL(reg, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  1006. }
  1007. /* frame rate */
  1008. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1009. reg = 0;
  1010. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1011. reg |= p->rc_framerate_denom & 0xFFFF;
  1012. WRITEL(reg, S5P_FIMV_E_RC_FRAME_RATE_V6);
  1013. }
  1014. /* vbv buffer size */
  1015. if (p->frame_skip_mode ==
  1016. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1017. WRITEL(p->vbv_size & 0xFFFF, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  1018. if (p->rc_frame)
  1019. WRITEL(p->vbv_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  1020. }
  1021. mfc_debug_leave();
  1022. return 0;
  1023. }
  1024. /* Initialize decoding */
  1025. int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
  1026. {
  1027. struct s5p_mfc_dev *dev = ctx->dev;
  1028. unsigned int reg = 0;
  1029. int fmo_aso_ctrl = 0;
  1030. mfc_debug_enter();
  1031. mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
  1032. S5P_FIMV_CH_SEQ_HEADER_V6);
  1033. mfc_debug(2, "BUFs: %08x %08x %08x\n",
  1034. READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6),
  1035. READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6),
  1036. READL(S5P_FIMV_D_CPB_BUFFER_ADDR_V6));
  1037. /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
  1038. reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
  1039. /* When user sets desplay_delay to 0,
  1040. * It works as "display_delay enable" and delay set to 0.
  1041. * If user wants display_delay disable, It should be
  1042. * set to negative value. */
  1043. if (ctx->display_delay >= 0) {
  1044. reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
  1045. WRITEL(ctx->display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
  1046. }
  1047. /* Setup loop filter, for decoding this is only valid for MPEG4 */
  1048. if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
  1049. mfc_debug(2, "Set loop filter to: %d\n",
  1050. ctx->loop_filter_mpeg4);
  1051. reg |= (ctx->loop_filter_mpeg4 <<
  1052. S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
  1053. }
  1054. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
  1055. reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
  1056. WRITEL(reg, S5P_FIMV_D_DEC_OPTIONS_V6);
  1057. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  1058. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
  1059. WRITEL(0x1, S5P_FIMV_PIXEL_FORMAT_V6);
  1060. else
  1061. WRITEL(0x0, S5P_FIMV_PIXEL_FORMAT_V6);
  1062. /* sei parse */
  1063. WRITEL(ctx->sei_fp_parse & 0x1, S5P_FIMV_D_SEI_ENABLE_V6);
  1064. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1065. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1066. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1067. mfc_debug_leave();
  1068. return 0;
  1069. }
  1070. static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
  1071. {
  1072. struct s5p_mfc_dev *dev = ctx->dev;
  1073. unsigned int dpb;
  1074. if (flush)
  1075. dpb = READL(S5P_FIMV_SI_CH0_DPB_CONF_CTRL) | (1 << 14);
  1076. else
  1077. dpb = READL(S5P_FIMV_SI_CH0_DPB_CONF_CTRL) & ~(1 << 14);
  1078. WRITEL(dpb, S5P_FIMV_SI_CH0_DPB_CONF_CTRL);
  1079. }
  1080. /* Decode a single frame */
  1081. int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
  1082. enum s5p_mfc_decode_arg last_frame)
  1083. {
  1084. struct s5p_mfc_dev *dev = ctx->dev;
  1085. WRITEL(ctx->dec_dst_flag, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1086. WRITEL(ctx->slice_interface & 0x1, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1087. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1088. /* Issue different commands to instance basing on whether it
  1089. * is the last frame or not. */
  1090. switch (last_frame) {
  1091. case 0:
  1092. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1093. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1094. break;
  1095. case 1:
  1096. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1097. S5P_FIMV_CH_LAST_FRAME_V6, NULL);
  1098. break;
  1099. default:
  1100. mfc_err("Unsupported last frame arg.\n");
  1101. return -EINVAL;
  1102. }
  1103. mfc_debug(2, "Decoding a usual frame.\n");
  1104. return 0;
  1105. }
  1106. int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
  1107. {
  1108. struct s5p_mfc_dev *dev = ctx->dev;
  1109. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1110. s5p_mfc_set_enc_params_h264(ctx);
  1111. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1112. s5p_mfc_set_enc_params_mpeg4(ctx);
  1113. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1114. s5p_mfc_set_enc_params_h263(ctx);
  1115. else {
  1116. mfc_err("Unknown codec for encoding (%x).\n",
  1117. ctx->codec_mode);
  1118. return -EINVAL;
  1119. }
  1120. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1121. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1122. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1123. return 0;
  1124. }
  1125. int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
  1126. {
  1127. struct s5p_mfc_dev *dev = ctx->dev;
  1128. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1129. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  1130. int i;
  1131. if (p_h264->aso) {
  1132. for (i = 0; i < 8; i++)
  1133. WRITEL(p_h264->aso_slice_order[i],
  1134. S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6 + i * 4);
  1135. }
  1136. return 0;
  1137. }
  1138. /* Encode a single frame */
  1139. int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
  1140. {
  1141. struct s5p_mfc_dev *dev = ctx->dev;
  1142. mfc_debug(2, "++\n");
  1143. /* memory structure cur. frame */
  1144. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1145. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1146. s5p_mfc_set_slice_mode(ctx);
  1147. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1148. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1149. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1150. mfc_debug(2, "--\n");
  1151. return 0;
  1152. }
  1153. static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
  1154. {
  1155. unsigned long flags;
  1156. int new_ctx;
  1157. int cnt;
  1158. spin_lock_irqsave(&dev->condlock, flags);
  1159. mfc_debug(2, "Previos context: %d (bits %08lx)\n", dev->curr_ctx,
  1160. dev->ctx_work_bits);
  1161. new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
  1162. cnt = 0;
  1163. while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
  1164. new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
  1165. cnt++;
  1166. if (cnt > MFC_NUM_CONTEXTS) {
  1167. /* No contexts to run */
  1168. spin_unlock_irqrestore(&dev->condlock, flags);
  1169. return -EAGAIN;
  1170. }
  1171. }
  1172. spin_unlock_irqrestore(&dev->condlock, flags);
  1173. return new_ctx;
  1174. }
  1175. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1176. {
  1177. struct s5p_mfc_dev *dev = ctx->dev;
  1178. struct s5p_mfc_buf *temp_vb;
  1179. unsigned long flags;
  1180. spin_lock_irqsave(&dev->irqlock, flags);
  1181. /* Frames are being decoded */
  1182. if (list_empty(&ctx->src_queue)) {
  1183. mfc_debug(2, "No src buffers.\n");
  1184. spin_unlock_irqrestore(&dev->irqlock, flags);
  1185. return;
  1186. }
  1187. /* Get the next source buffer */
  1188. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1189. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1190. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1191. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
  1192. spin_unlock_irqrestore(&dev->irqlock, flags);
  1193. dev->curr_ctx = ctx->num;
  1194. s5p_mfc_clean_ctx_int_flags(ctx);
  1195. s5p_mfc_decode_one_frame_v6(ctx, 1);
  1196. }
  1197. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1198. {
  1199. struct s5p_mfc_dev *dev = ctx->dev;
  1200. struct s5p_mfc_buf *temp_vb;
  1201. unsigned long flags;
  1202. int last_frame = 0;
  1203. unsigned int index;
  1204. spin_lock_irqsave(&dev->irqlock, flags);
  1205. /* Frames are being decoded */
  1206. if (list_empty(&ctx->src_queue)) {
  1207. mfc_debug(2, "No src buffers.\n");
  1208. spin_unlock_irqrestore(&dev->irqlock, flags);
  1209. return -EAGAIN;
  1210. }
  1211. /* Get the next source buffer */
  1212. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1213. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1214. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1215. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1216. ctx->consumed_stream,
  1217. temp_vb->b->v4l2_planes[0].bytesused);
  1218. spin_unlock_irqrestore(&dev->irqlock, flags);
  1219. index = temp_vb->b->v4l2_buf.index;
  1220. dev->curr_ctx = ctx->num;
  1221. s5p_mfc_clean_ctx_int_flags(ctx);
  1222. if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
  1223. last_frame = 1;
  1224. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1225. ctx->state = MFCINST_FINISHING;
  1226. }
  1227. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1228. return 0;
  1229. }
  1230. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1231. {
  1232. struct s5p_mfc_dev *dev = ctx->dev;
  1233. unsigned long flags;
  1234. struct s5p_mfc_buf *dst_mb;
  1235. struct s5p_mfc_buf *src_mb;
  1236. unsigned long src_y_addr, src_c_addr, dst_addr;
  1237. /*
  1238. unsigned int src_y_size, src_c_size;
  1239. */
  1240. unsigned int dst_size;
  1241. unsigned int index;
  1242. spin_lock_irqsave(&dev->irqlock, flags);
  1243. if (list_empty(&ctx->src_queue)) {
  1244. mfc_debug(2, "no src buffers.\n");
  1245. spin_unlock_irqrestore(&dev->irqlock, flags);
  1246. return -EAGAIN;
  1247. }
  1248. if (list_empty(&ctx->dst_queue)) {
  1249. mfc_debug(2, "no dst buffers.\n");
  1250. spin_unlock_irqrestore(&dev->irqlock, flags);
  1251. return -EAGAIN;
  1252. }
  1253. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1254. src_mb->flags |= MFC_BUF_FLAG_USED;
  1255. src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
  1256. src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
  1257. mfc_debug(2, "enc src y addr: 0x%08lx", src_y_addr);
  1258. mfc_debug(2, "enc src c addr: 0x%08lx", src_c_addr);
  1259. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1260. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1261. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1262. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1263. dst_size = vb2_plane_size(dst_mb->b, 0);
  1264. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1265. spin_unlock_irqrestore(&dev->irqlock, flags);
  1266. index = src_mb->b->v4l2_buf.index;
  1267. dev->curr_ctx = ctx->num;
  1268. s5p_mfc_clean_ctx_int_flags(ctx);
  1269. s5p_mfc_encode_one_frame_v6(ctx);
  1270. return 0;
  1271. }
  1272. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1273. {
  1274. struct s5p_mfc_dev *dev = ctx->dev;
  1275. unsigned long flags;
  1276. struct s5p_mfc_buf *temp_vb;
  1277. /* Initializing decoding - parsing header */
  1278. spin_lock_irqsave(&dev->irqlock, flags);
  1279. mfc_debug(2, "Preparing to init decoding.\n");
  1280. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1281. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1282. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1283. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
  1284. temp_vb->b->v4l2_planes[0].bytesused);
  1285. spin_unlock_irqrestore(&dev->irqlock, flags);
  1286. dev->curr_ctx = ctx->num;
  1287. s5p_mfc_clean_ctx_int_flags(ctx);
  1288. s5p_mfc_init_decode_v6(ctx);
  1289. }
  1290. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1291. {
  1292. struct s5p_mfc_dev *dev = ctx->dev;
  1293. unsigned long flags;
  1294. struct s5p_mfc_buf *dst_mb;
  1295. unsigned long dst_addr;
  1296. unsigned int dst_size;
  1297. spin_lock_irqsave(&dev->irqlock, flags);
  1298. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1299. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1300. dst_size = vb2_plane_size(dst_mb->b, 0);
  1301. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1302. spin_unlock_irqrestore(&dev->irqlock, flags);
  1303. dev->curr_ctx = ctx->num;
  1304. s5p_mfc_clean_ctx_int_flags(ctx);
  1305. s5p_mfc_init_encode_v6(ctx);
  1306. }
  1307. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1308. {
  1309. struct s5p_mfc_dev *dev = ctx->dev;
  1310. int ret;
  1311. /* Header was parsed now start processing
  1312. * First set the output frame buffers
  1313. * s5p_mfc_alloc_dec_buffers(ctx); */
  1314. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1315. mfc_err("It seems that not all destionation buffers were\n"
  1316. "mmaped.MFC requires that all destination are mmaped\n"
  1317. "before starting processing.\n");
  1318. return -EAGAIN;
  1319. }
  1320. dev->curr_ctx = ctx->num;
  1321. s5p_mfc_clean_ctx_int_flags(ctx);
  1322. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1323. if (ret) {
  1324. mfc_err("Failed to alloc frame mem.\n");
  1325. ctx->state = MFCINST_ERROR;
  1326. }
  1327. return ret;
  1328. }
  1329. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1330. {
  1331. struct s5p_mfc_dev *dev = ctx->dev;
  1332. int ret;
  1333. ret = s5p_mfc_alloc_codec_buffers_v6(ctx);
  1334. if (ret) {
  1335. mfc_err("Failed to allocate encoding buffers.\n");
  1336. return -ENOMEM;
  1337. }
  1338. /* Header was generated now starting processing
  1339. * First set the reference frame buffers
  1340. */
  1341. if (ctx->capture_state != QUEUE_BUFS_REQUESTED) {
  1342. mfc_err("It seems that destionation buffers were not\n"
  1343. "requested.MFC requires that header should be generated\n"
  1344. "before allocating codec buffer.\n");
  1345. return -EAGAIN;
  1346. }
  1347. dev->curr_ctx = ctx->num;
  1348. s5p_mfc_clean_ctx_int_flags(ctx);
  1349. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1350. if (ret) {
  1351. mfc_err("Failed to alloc frame mem.\n");
  1352. ctx->state = MFCINST_ERROR;
  1353. }
  1354. return ret;
  1355. }
  1356. /* Try running an operation on hardware */
  1357. void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1358. {
  1359. struct s5p_mfc_ctx *ctx;
  1360. int new_ctx;
  1361. unsigned int ret = 0;
  1362. mfc_debug(1, "Try run dev: %p\n", dev);
  1363. /* Check whether hardware is not running */
  1364. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1365. /* This is perfectly ok, the scheduled ctx should wait */
  1366. mfc_debug(1, "Couldn't lock HW.\n");
  1367. return;
  1368. }
  1369. /* Choose the context to run */
  1370. new_ctx = s5p_mfc_get_new_ctx(dev);
  1371. if (new_ctx < 0) {
  1372. /* No contexts to run */
  1373. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1374. mfc_err("Failed to unlock hardware.\n");
  1375. return;
  1376. }
  1377. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1378. return;
  1379. }
  1380. mfc_debug(1, "New context: %d\n", new_ctx);
  1381. ctx = dev->ctx[new_ctx];
  1382. mfc_debug(1, "Seting new context to %p\n", ctx);
  1383. /* Got context to run in ctx */
  1384. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1385. ctx->dst_queue_cnt, ctx->dpb_count, ctx->src_queue_cnt);
  1386. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1387. /* Last frame has already been sent to MFC
  1388. * Now obtaining frames from MFC buffer */
  1389. s5p_mfc_clock_on();
  1390. if (ctx->type == MFCINST_DECODER) {
  1391. switch (ctx->state) {
  1392. case MFCINST_FINISHING:
  1393. s5p_mfc_run_dec_last_frames(ctx);
  1394. break;
  1395. case MFCINST_RUNNING:
  1396. ret = s5p_mfc_run_dec_frame(ctx);
  1397. break;
  1398. case MFCINST_INIT:
  1399. s5p_mfc_clean_ctx_int_flags(ctx);
  1400. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1401. ctx);
  1402. break;
  1403. case MFCINST_RETURN_INST:
  1404. s5p_mfc_clean_ctx_int_flags(ctx);
  1405. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1406. ctx);
  1407. break;
  1408. case MFCINST_GOT_INST:
  1409. s5p_mfc_run_init_dec(ctx);
  1410. break;
  1411. case MFCINST_HEAD_PARSED:
  1412. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1413. break;
  1414. case MFCINST_RES_CHANGE_INIT:
  1415. s5p_mfc_run_dec_last_frames(ctx);
  1416. break;
  1417. case MFCINST_RES_CHANGE_FLUSH:
  1418. s5p_mfc_run_dec_last_frames(ctx);
  1419. break;
  1420. case MFCINST_RES_CHANGE_END:
  1421. mfc_debug(2, "Finished remaining frames after resolution change.\n");
  1422. ctx->capture_state = QUEUE_FREE;
  1423. mfc_debug(2, "Will re-init the codec`.\n");
  1424. s5p_mfc_run_init_dec(ctx);
  1425. break;
  1426. default:
  1427. ret = -EAGAIN;
  1428. }
  1429. } else if (ctx->type == MFCINST_ENCODER) {
  1430. switch (ctx->state) {
  1431. case MFCINST_FINISHING:
  1432. case MFCINST_RUNNING:
  1433. ret = s5p_mfc_run_enc_frame(ctx);
  1434. break;
  1435. case MFCINST_INIT:
  1436. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1437. ctx);
  1438. break;
  1439. case MFCINST_RETURN_INST:
  1440. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1441. ctx);
  1442. break;
  1443. case MFCINST_GOT_INST:
  1444. s5p_mfc_run_init_enc(ctx);
  1445. break;
  1446. case MFCINST_HEAD_PARSED: /* Only for MFC6.x */
  1447. ret = s5p_mfc_run_init_enc_buffers(ctx);
  1448. break;
  1449. default:
  1450. ret = -EAGAIN;
  1451. }
  1452. } else {
  1453. mfc_err("invalid context type: %d\n", ctx->type);
  1454. ret = -EAGAIN;
  1455. }
  1456. if (ret) {
  1457. /* Free hardware lock */
  1458. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1459. mfc_err("Failed to unlock hardware.\n");
  1460. /* This is in deed imporant, as no operation has been
  1461. * scheduled, reduce the clock count as no one will
  1462. * ever do this, because no interrupt related to this try_run
  1463. * will ever come from hardware. */
  1464. s5p_mfc_clock_off();
  1465. }
  1466. }
  1467. void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
  1468. {
  1469. struct s5p_mfc_buf *b;
  1470. int i;
  1471. while (!list_empty(lh)) {
  1472. b = list_entry(lh->next, struct s5p_mfc_buf, list);
  1473. for (i = 0; i < b->b->num_planes; i++)
  1474. vb2_set_plane_payload(b->b, i, 0);
  1475. vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
  1476. list_del(&b->list);
  1477. }
  1478. }
  1479. void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
  1480. {
  1481. mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD_V6);
  1482. mfc_write(dev, 0, S5P_FIMV_RISC2HOST_INT_V6);
  1483. }
  1484. void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
  1485. unsigned int ofs)
  1486. {
  1487. struct s5p_mfc_dev *dev = ctx->dev;
  1488. s5p_mfc_clock_on();
  1489. WRITEL(data, ofs);
  1490. s5p_mfc_clock_off();
  1491. }
  1492. unsigned int s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
  1493. {
  1494. struct s5p_mfc_dev *dev = ctx->dev;
  1495. int ret;
  1496. s5p_mfc_clock_on();
  1497. ret = READL(ofs);
  1498. s5p_mfc_clock_off();
  1499. return ret;
  1500. }
  1501. int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
  1502. {
  1503. return mfc_read(dev, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
  1504. }
  1505. int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
  1506. {
  1507. return mfc_read(dev, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
  1508. }
  1509. int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
  1510. {
  1511. return mfc_read(dev, S5P_FIMV_D_DISPLAY_STATUS_V6);
  1512. }
  1513. int s5p_mfc_get_decoded_status_v6(struct s5p_mfc_dev *dev)
  1514. {
  1515. return mfc_read(dev, S5P_FIMV_D_DECODED_STATUS_V6);
  1516. }
  1517. int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
  1518. {
  1519. return mfc_read(dev, S5P_FIMV_D_DECODED_FRAME_TYPE_V6) &
  1520. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1521. }
  1522. int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
  1523. {
  1524. return mfc_read(ctx->dev, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6) &
  1525. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1526. }
  1527. int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
  1528. {
  1529. return mfc_read(dev, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
  1530. }
  1531. int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
  1532. {
  1533. return mfc_read(dev, S5P_FIMV_RISC2HOST_CMD_V6) &
  1534. S5P_FIMV_RISC2HOST_CMD_MASK;
  1535. }
  1536. int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
  1537. {
  1538. return mfc_read(dev, S5P_FIMV_ERROR_CODE_V6);
  1539. }
  1540. int s5p_mfc_err_dec_v6(unsigned int err)
  1541. {
  1542. return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
  1543. }
  1544. int s5p_mfc_err_dspl_v6(unsigned int err)
  1545. {
  1546. return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
  1547. }
  1548. int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
  1549. {
  1550. return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
  1551. }
  1552. int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
  1553. {
  1554. return mfc_read(dev, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
  1555. }
  1556. int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
  1557. {
  1558. return mfc_read(dev, S5P_FIMV_D_MIN_NUM_DPB_V6);
  1559. }
  1560. int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
  1561. {
  1562. return mfc_read(dev, S5P_FIMV_D_MIN_NUM_MV_V6);
  1563. }
  1564. int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
  1565. {
  1566. return mfc_read(dev, S5P_FIMV_RET_INSTANCE_ID_V6);
  1567. }
  1568. int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
  1569. {
  1570. return mfc_read(dev, S5P_FIMV_E_NUM_DPB_V6);
  1571. }
  1572. int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
  1573. {
  1574. return mfc_read(dev, S5P_FIMV_E_STREAM_SIZE_V6);
  1575. }
  1576. int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
  1577. {
  1578. return mfc_read(dev, S5P_FIMV_E_SLICE_TYPE_V6);
  1579. }
  1580. int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
  1581. {
  1582. return mfc_read(dev, S5P_FIMV_E_PICTURE_COUNT_V6);
  1583. }
  1584. int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
  1585. {
  1586. return mfc_read(ctx->dev, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
  1587. }
  1588. int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
  1589. {
  1590. return mfc_read(dev, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
  1591. }
  1592. int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
  1593. {
  1594. return mfc_read(dev, S5P_FIMV_D_MVC_VIEW_ID_V6);
  1595. }
  1596. unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
  1597. {
  1598. return s5p_mfc_read_info_v6(ctx, PIC_TIME_TOP_V6);
  1599. }
  1600. unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
  1601. {
  1602. return s5p_mfc_read_info_v6(ctx, PIC_TIME_BOT_V6);
  1603. }
  1604. unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
  1605. {
  1606. return s5p_mfc_read_info_v6(ctx, CROP_INFO_H_V6);
  1607. }
  1608. unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
  1609. {
  1610. return s5p_mfc_read_info_v6(ctx, CROP_INFO_V_V6);
  1611. }
  1612. /* Initialize opr function pointers for MFC v6 */
  1613. static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
  1614. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
  1615. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
  1616. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
  1617. .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
  1618. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
  1619. .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
  1620. .alloc_dev_context_buffer =
  1621. s5p_mfc_alloc_dev_context_buffer_v6,
  1622. .release_dev_context_buffer =
  1623. s5p_mfc_release_dev_context_buffer_v6,
  1624. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
  1625. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
  1626. .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
  1627. .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
  1628. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
  1629. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
  1630. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
  1631. .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
  1632. .init_decode = s5p_mfc_init_decode_v6,
  1633. .init_encode = s5p_mfc_init_encode_v6,
  1634. .encode_one_frame = s5p_mfc_encode_one_frame_v6,
  1635. .try_run = s5p_mfc_try_run_v6,
  1636. .cleanup_queue = s5p_mfc_cleanup_queue_v6,
  1637. .clear_int_flags = s5p_mfc_clear_int_flags_v6,
  1638. .write_info = s5p_mfc_write_info_v6,
  1639. .read_info = s5p_mfc_read_info_v6,
  1640. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
  1641. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
  1642. .get_dspl_status = s5p_mfc_get_dspl_status_v6,
  1643. .get_dec_status = s5p_mfc_get_dec_status_v6,
  1644. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
  1645. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
  1646. .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
  1647. .get_int_reason = s5p_mfc_get_int_reason_v6,
  1648. .get_int_err = s5p_mfc_get_int_err_v6,
  1649. .err_dec = s5p_mfc_err_dec_v6,
  1650. .err_dspl = s5p_mfc_err_dspl_v6,
  1651. .get_img_width = s5p_mfc_get_img_width_v6,
  1652. .get_img_height = s5p_mfc_get_img_height_v6,
  1653. .get_dpb_count = s5p_mfc_get_dpb_count_v6,
  1654. .get_mv_count = s5p_mfc_get_mv_count_v6,
  1655. .get_inst_no = s5p_mfc_get_inst_no_v6,
  1656. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
  1657. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
  1658. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
  1659. .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
  1660. .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
  1661. .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
  1662. .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
  1663. .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
  1664. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
  1665. .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
  1666. .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
  1667. };
  1668. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
  1669. {
  1670. return &s5p_mfc_ops_v6;
  1671. }