s5p_mfc_opr_v6.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  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. if (flush) {
  1074. dev->curr_ctx = ctx->num;
  1075. s5p_mfc_clean_ctx_int_flags(ctx);
  1076. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1077. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1078. S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
  1079. }
  1080. }
  1081. /* Decode a single frame */
  1082. int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
  1083. enum s5p_mfc_decode_arg last_frame)
  1084. {
  1085. struct s5p_mfc_dev *dev = ctx->dev;
  1086. WRITEL(ctx->dec_dst_flag, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1087. WRITEL(ctx->slice_interface & 0x1, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1088. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1089. /* Issue different commands to instance basing on whether it
  1090. * is the last frame or not. */
  1091. switch (last_frame) {
  1092. case 0:
  1093. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1094. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1095. break;
  1096. case 1:
  1097. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1098. S5P_FIMV_CH_LAST_FRAME_V6, NULL);
  1099. break;
  1100. default:
  1101. mfc_err("Unsupported last frame arg.\n");
  1102. return -EINVAL;
  1103. }
  1104. mfc_debug(2, "Decoding a usual frame.\n");
  1105. return 0;
  1106. }
  1107. int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
  1108. {
  1109. struct s5p_mfc_dev *dev = ctx->dev;
  1110. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1111. s5p_mfc_set_enc_params_h264(ctx);
  1112. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1113. s5p_mfc_set_enc_params_mpeg4(ctx);
  1114. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1115. s5p_mfc_set_enc_params_h263(ctx);
  1116. else {
  1117. mfc_err("Unknown codec for encoding (%x).\n",
  1118. ctx->codec_mode);
  1119. return -EINVAL;
  1120. }
  1121. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1122. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1123. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1124. return 0;
  1125. }
  1126. int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
  1127. {
  1128. struct s5p_mfc_dev *dev = ctx->dev;
  1129. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1130. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  1131. int i;
  1132. if (p_h264->aso) {
  1133. for (i = 0; i < 8; i++)
  1134. WRITEL(p_h264->aso_slice_order[i],
  1135. S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6 + i * 4);
  1136. }
  1137. return 0;
  1138. }
  1139. /* Encode a single frame */
  1140. int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
  1141. {
  1142. struct s5p_mfc_dev *dev = ctx->dev;
  1143. mfc_debug(2, "++\n");
  1144. /* memory structure cur. frame */
  1145. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1146. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1147. s5p_mfc_set_slice_mode(ctx);
  1148. WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
  1149. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
  1150. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1151. mfc_debug(2, "--\n");
  1152. return 0;
  1153. }
  1154. static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
  1155. {
  1156. unsigned long flags;
  1157. int new_ctx;
  1158. int cnt;
  1159. spin_lock_irqsave(&dev->condlock, flags);
  1160. mfc_debug(2, "Previos context: %d (bits %08lx)\n", dev->curr_ctx,
  1161. dev->ctx_work_bits);
  1162. new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
  1163. cnt = 0;
  1164. while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
  1165. new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
  1166. cnt++;
  1167. if (cnt > MFC_NUM_CONTEXTS) {
  1168. /* No contexts to run */
  1169. spin_unlock_irqrestore(&dev->condlock, flags);
  1170. return -EAGAIN;
  1171. }
  1172. }
  1173. spin_unlock_irqrestore(&dev->condlock, flags);
  1174. return new_ctx;
  1175. }
  1176. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1177. {
  1178. struct s5p_mfc_dev *dev = ctx->dev;
  1179. struct s5p_mfc_buf *temp_vb;
  1180. unsigned long flags;
  1181. spin_lock_irqsave(&dev->irqlock, flags);
  1182. /* Frames are being decoded */
  1183. if (list_empty(&ctx->src_queue)) {
  1184. mfc_debug(2, "No src buffers.\n");
  1185. spin_unlock_irqrestore(&dev->irqlock, flags);
  1186. return;
  1187. }
  1188. /* Get the next source buffer */
  1189. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1190. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1191. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1192. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0, 0);
  1193. spin_unlock_irqrestore(&dev->irqlock, flags);
  1194. dev->curr_ctx = ctx->num;
  1195. s5p_mfc_clean_ctx_int_flags(ctx);
  1196. s5p_mfc_decode_one_frame_v6(ctx, 1);
  1197. }
  1198. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1199. {
  1200. struct s5p_mfc_dev *dev = ctx->dev;
  1201. struct s5p_mfc_buf *temp_vb;
  1202. unsigned long flags;
  1203. int last_frame = 0;
  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. dev->curr_ctx = ctx->num;
  1220. s5p_mfc_clean_ctx_int_flags(ctx);
  1221. if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
  1222. last_frame = 1;
  1223. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1224. ctx->state = MFCINST_FINISHING;
  1225. }
  1226. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1227. return 0;
  1228. }
  1229. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1230. {
  1231. struct s5p_mfc_dev *dev = ctx->dev;
  1232. unsigned long flags;
  1233. struct s5p_mfc_buf *dst_mb;
  1234. struct s5p_mfc_buf *src_mb;
  1235. unsigned long src_y_addr, src_c_addr, dst_addr;
  1236. /*
  1237. unsigned int src_y_size, src_c_size;
  1238. */
  1239. unsigned int dst_size;
  1240. spin_lock_irqsave(&dev->irqlock, flags);
  1241. if (list_empty(&ctx->src_queue)) {
  1242. mfc_debug(2, "no src buffers.\n");
  1243. spin_unlock_irqrestore(&dev->irqlock, flags);
  1244. return -EAGAIN;
  1245. }
  1246. if (list_empty(&ctx->dst_queue)) {
  1247. mfc_debug(2, "no dst buffers.\n");
  1248. spin_unlock_irqrestore(&dev->irqlock, flags);
  1249. return -EAGAIN;
  1250. }
  1251. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1252. src_mb->flags |= MFC_BUF_FLAG_USED;
  1253. src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
  1254. src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
  1255. mfc_debug(2, "enc src y addr: 0x%08lx", src_y_addr);
  1256. mfc_debug(2, "enc src c addr: 0x%08lx", src_c_addr);
  1257. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1258. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1259. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1260. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1261. dst_size = vb2_plane_size(dst_mb->b, 0);
  1262. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1263. spin_unlock_irqrestore(&dev->irqlock, flags);
  1264. dev->curr_ctx = ctx->num;
  1265. s5p_mfc_clean_ctx_int_flags(ctx);
  1266. s5p_mfc_encode_one_frame_v6(ctx);
  1267. return 0;
  1268. }
  1269. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1270. {
  1271. struct s5p_mfc_dev *dev = ctx->dev;
  1272. unsigned long flags;
  1273. struct s5p_mfc_buf *temp_vb;
  1274. /* Initializing decoding - parsing header */
  1275. spin_lock_irqsave(&dev->irqlock, flags);
  1276. mfc_debug(2, "Preparing to init decoding.\n");
  1277. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1278. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1279. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1280. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
  1281. temp_vb->b->v4l2_planes[0].bytesused);
  1282. spin_unlock_irqrestore(&dev->irqlock, flags);
  1283. dev->curr_ctx = ctx->num;
  1284. s5p_mfc_clean_ctx_int_flags(ctx);
  1285. s5p_mfc_init_decode_v6(ctx);
  1286. }
  1287. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1288. {
  1289. struct s5p_mfc_dev *dev = ctx->dev;
  1290. unsigned long flags;
  1291. struct s5p_mfc_buf *dst_mb;
  1292. unsigned long dst_addr;
  1293. unsigned int dst_size;
  1294. spin_lock_irqsave(&dev->irqlock, flags);
  1295. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1296. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1297. dst_size = vb2_plane_size(dst_mb->b, 0);
  1298. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1299. spin_unlock_irqrestore(&dev->irqlock, flags);
  1300. dev->curr_ctx = ctx->num;
  1301. s5p_mfc_clean_ctx_int_flags(ctx);
  1302. s5p_mfc_init_encode_v6(ctx);
  1303. }
  1304. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1305. {
  1306. struct s5p_mfc_dev *dev = ctx->dev;
  1307. int ret;
  1308. /* Header was parsed now start processing
  1309. * First set the output frame buffers
  1310. * s5p_mfc_alloc_dec_buffers(ctx); */
  1311. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1312. mfc_err("It seems that not all destionation buffers were\n"
  1313. "mmaped.MFC requires that all destination are mmaped\n"
  1314. "before starting processing.\n");
  1315. return -EAGAIN;
  1316. }
  1317. dev->curr_ctx = ctx->num;
  1318. s5p_mfc_clean_ctx_int_flags(ctx);
  1319. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1320. if (ret) {
  1321. mfc_err("Failed to alloc frame mem.\n");
  1322. ctx->state = MFCINST_ERROR;
  1323. }
  1324. return ret;
  1325. }
  1326. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1327. {
  1328. struct s5p_mfc_dev *dev = ctx->dev;
  1329. int ret;
  1330. ret = s5p_mfc_alloc_codec_buffers_v6(ctx);
  1331. if (ret) {
  1332. mfc_err("Failed to allocate encoding buffers.\n");
  1333. return -ENOMEM;
  1334. }
  1335. /* Header was generated now starting processing
  1336. * First set the reference frame buffers
  1337. */
  1338. if (ctx->capture_state != QUEUE_BUFS_REQUESTED) {
  1339. mfc_err("It seems that destionation buffers were not\n"
  1340. "requested.MFC requires that header should be generated\n"
  1341. "before allocating codec buffer.\n");
  1342. return -EAGAIN;
  1343. }
  1344. dev->curr_ctx = ctx->num;
  1345. s5p_mfc_clean_ctx_int_flags(ctx);
  1346. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1347. if (ret) {
  1348. mfc_err("Failed to alloc frame mem.\n");
  1349. ctx->state = MFCINST_ERROR;
  1350. }
  1351. return ret;
  1352. }
  1353. /* Try running an operation on hardware */
  1354. void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1355. {
  1356. struct s5p_mfc_ctx *ctx;
  1357. int new_ctx;
  1358. unsigned int ret = 0;
  1359. mfc_debug(1, "Try run dev: %p\n", dev);
  1360. /* Check whether hardware is not running */
  1361. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1362. /* This is perfectly ok, the scheduled ctx should wait */
  1363. mfc_debug(1, "Couldn't lock HW.\n");
  1364. return;
  1365. }
  1366. /* Choose the context to run */
  1367. new_ctx = s5p_mfc_get_new_ctx(dev);
  1368. if (new_ctx < 0) {
  1369. /* No contexts to run */
  1370. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1371. mfc_err("Failed to unlock hardware.\n");
  1372. return;
  1373. }
  1374. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1375. return;
  1376. }
  1377. mfc_debug(1, "New context: %d\n", new_ctx);
  1378. ctx = dev->ctx[new_ctx];
  1379. mfc_debug(1, "Seting new context to %p\n", ctx);
  1380. /* Got context to run in ctx */
  1381. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1382. ctx->dst_queue_cnt, ctx->dpb_count, ctx->src_queue_cnt);
  1383. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1384. /* Last frame has already been sent to MFC
  1385. * Now obtaining frames from MFC buffer */
  1386. s5p_mfc_clock_on();
  1387. if (ctx->type == MFCINST_DECODER) {
  1388. switch (ctx->state) {
  1389. case MFCINST_FINISHING:
  1390. s5p_mfc_run_dec_last_frames(ctx);
  1391. break;
  1392. case MFCINST_RUNNING:
  1393. ret = s5p_mfc_run_dec_frame(ctx);
  1394. break;
  1395. case MFCINST_INIT:
  1396. s5p_mfc_clean_ctx_int_flags(ctx);
  1397. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1398. ctx);
  1399. break;
  1400. case MFCINST_RETURN_INST:
  1401. s5p_mfc_clean_ctx_int_flags(ctx);
  1402. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1403. ctx);
  1404. break;
  1405. case MFCINST_GOT_INST:
  1406. s5p_mfc_run_init_dec(ctx);
  1407. break;
  1408. case MFCINST_HEAD_PARSED:
  1409. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1410. break;
  1411. case MFCINST_FLUSH:
  1412. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  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. }