s5p_mfc_opr_v6.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315
  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 IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
  41. /* Allocate temporary buffers for decoding */
  42. static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
  43. {
  44. /* NOP */
  45. return 0;
  46. }
  47. /* Release temproary buffers for decoding */
  48. static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
  49. {
  50. /* NOP */
  51. }
  52. /* Allocate codec buffers */
  53. static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  54. {
  55. struct s5p_mfc_dev *dev = ctx->dev;
  56. unsigned int mb_width, mb_height;
  57. int ret;
  58. mb_width = MB_WIDTH(ctx->img_width);
  59. mb_height = MB_HEIGHT(ctx->img_height);
  60. if (ctx->type == MFCINST_DECODER) {
  61. mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
  62. ctx->luma_size, ctx->chroma_size, ctx->mv_size);
  63. mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
  64. } else if (ctx->type == MFCINST_ENCODER) {
  65. if (IS_MFCV8(dev))
  66. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  67. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
  68. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  69. else
  70. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  71. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
  72. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  73. ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
  74. S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
  75. S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
  76. ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
  77. S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
  78. S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
  79. if (IS_MFCV8(dev))
  80. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V8(
  81. ctx->img_width, ctx->img_height,
  82. mb_width, mb_height),
  83. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  84. else
  85. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
  86. ctx->img_width, ctx->img_height,
  87. mb_width, mb_height),
  88. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  89. mfc_debug(2, "recon luma size: %zu chroma size: %zu\n",
  90. ctx->luma_dpb_size, ctx->chroma_dpb_size);
  91. } else {
  92. return -EINVAL;
  93. }
  94. /* Codecs have different memory requirements */
  95. switch (ctx->codec_mode) {
  96. case S5P_MFC_CODEC_H264_DEC:
  97. case S5P_MFC_CODEC_H264_MVC_DEC:
  98. if (IS_MFCV8(dev))
  99. ctx->scratch_buf_size =
  100. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(
  101. mb_width,
  102. mb_height);
  103. else
  104. ctx->scratch_buf_size =
  105. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
  106. mb_width,
  107. mb_height);
  108. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  109. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  110. ctx->bank1.size =
  111. ctx->scratch_buf_size +
  112. (ctx->mv_count * ctx->mv_size);
  113. break;
  114. case S5P_MFC_CODEC_MPEG4_DEC:
  115. if (IS_MFCV7_PLUS(dev)) {
  116. ctx->scratch_buf_size =
  117. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
  118. mb_width,
  119. mb_height);
  120. } else {
  121. ctx->scratch_buf_size =
  122. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
  123. mb_width,
  124. mb_height);
  125. }
  126. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  127. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  128. ctx->bank1.size = ctx->scratch_buf_size;
  129. break;
  130. case S5P_MFC_CODEC_VC1RCV_DEC:
  131. case S5P_MFC_CODEC_VC1_DEC:
  132. ctx->scratch_buf_size =
  133. S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
  134. mb_width,
  135. mb_height);
  136. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  137. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  138. ctx->bank1.size = ctx->scratch_buf_size;
  139. break;
  140. case S5P_MFC_CODEC_MPEG2_DEC:
  141. ctx->bank1.size = 0;
  142. ctx->bank2.size = 0;
  143. break;
  144. case S5P_MFC_CODEC_H263_DEC:
  145. ctx->scratch_buf_size =
  146. S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
  147. mb_width,
  148. mb_height);
  149. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  150. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  151. ctx->bank1.size = ctx->scratch_buf_size;
  152. break;
  153. case S5P_MFC_CODEC_VP8_DEC:
  154. if (IS_MFCV8(dev))
  155. ctx->scratch_buf_size =
  156. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(
  157. mb_width,
  158. mb_height);
  159. else
  160. ctx->scratch_buf_size =
  161. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_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 = ctx->scratch_buf_size;
  167. break;
  168. case S5P_MFC_CODEC_H264_ENC:
  169. if (IS_MFCV8(dev))
  170. ctx->scratch_buf_size =
  171. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(
  172. mb_width,
  173. mb_height);
  174. else
  175. ctx->scratch_buf_size =
  176. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
  177. mb_width,
  178. mb_height);
  179. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  180. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  181. ctx->bank1.size =
  182. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  183. (ctx->pb_count * (ctx->luma_dpb_size +
  184. ctx->chroma_dpb_size + ctx->me_buffer_size));
  185. ctx->bank2.size = 0;
  186. break;
  187. case S5P_MFC_CODEC_MPEG4_ENC:
  188. case S5P_MFC_CODEC_H263_ENC:
  189. ctx->scratch_buf_size =
  190. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
  191. mb_width,
  192. mb_height);
  193. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  194. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  195. ctx->bank1.size =
  196. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  197. (ctx->pb_count * (ctx->luma_dpb_size +
  198. ctx->chroma_dpb_size + ctx->me_buffer_size));
  199. ctx->bank2.size = 0;
  200. break;
  201. case S5P_MFC_CODEC_VP8_ENC:
  202. if (IS_MFCV8(dev))
  203. ctx->scratch_buf_size =
  204. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(
  205. mb_width,
  206. mb_height);
  207. else
  208. ctx->scratch_buf_size =
  209. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
  210. mb_width,
  211. mb_height);
  212. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  213. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  214. ctx->bank1.size =
  215. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  216. (ctx->pb_count * (ctx->luma_dpb_size +
  217. ctx->chroma_dpb_size + ctx->me_buffer_size));
  218. ctx->bank2.size = 0;
  219. break;
  220. default:
  221. break;
  222. }
  223. /* Allocate only if memory from bank 1 is necessary */
  224. if (ctx->bank1.size > 0) {
  225. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
  226. if (ret) {
  227. mfc_err("Failed to allocate Bank1 memory\n");
  228. return ret;
  229. }
  230. BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  231. }
  232. return 0;
  233. }
  234. /* Release buffers allocated for codec */
  235. static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  236. {
  237. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
  238. }
  239. /* Allocate memory for instance data buffer */
  240. static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  241. {
  242. struct s5p_mfc_dev *dev = ctx->dev;
  243. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  244. int ret;
  245. mfc_debug_enter();
  246. switch (ctx->codec_mode) {
  247. case S5P_MFC_CODEC_H264_DEC:
  248. case S5P_MFC_CODEC_H264_MVC_DEC:
  249. ctx->ctx.size = buf_size->h264_dec_ctx;
  250. break;
  251. case S5P_MFC_CODEC_MPEG4_DEC:
  252. case S5P_MFC_CODEC_H263_DEC:
  253. case S5P_MFC_CODEC_VC1RCV_DEC:
  254. case S5P_MFC_CODEC_VC1_DEC:
  255. case S5P_MFC_CODEC_MPEG2_DEC:
  256. case S5P_MFC_CODEC_VP8_DEC:
  257. ctx->ctx.size = buf_size->other_dec_ctx;
  258. break;
  259. case S5P_MFC_CODEC_H264_ENC:
  260. ctx->ctx.size = buf_size->h264_enc_ctx;
  261. break;
  262. case S5P_MFC_CODEC_MPEG4_ENC:
  263. case S5P_MFC_CODEC_H263_ENC:
  264. case S5P_MFC_CODEC_VP8_ENC:
  265. ctx->ctx.size = buf_size->other_enc_ctx;
  266. break;
  267. default:
  268. ctx->ctx.size = 0;
  269. mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
  270. break;
  271. }
  272. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
  273. if (ret) {
  274. mfc_err("Failed to allocate instance buffer\n");
  275. return ret;
  276. }
  277. memset(ctx->ctx.virt, 0, ctx->ctx.size);
  278. wmb();
  279. mfc_debug_leave();
  280. return 0;
  281. }
  282. /* Release instance buffer */
  283. static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  284. {
  285. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
  286. }
  287. /* Allocate context buffers for SYS_INIT */
  288. static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  289. {
  290. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  291. int ret;
  292. mfc_debug_enter();
  293. dev->ctx_buf.size = buf_size->dev_ctx;
  294. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
  295. if (ret) {
  296. mfc_err("Failed to allocate device context buffer\n");
  297. return ret;
  298. }
  299. memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
  300. wmb();
  301. mfc_debug_leave();
  302. return 0;
  303. }
  304. /* Release context buffers for SYS_INIT */
  305. static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  306. {
  307. s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
  308. }
  309. static int calc_plane(int width, int height)
  310. {
  311. int mbX, mbY;
  312. mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  313. mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
  314. if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
  315. mbY = (mbY + 1) / 2 * 2;
  316. return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
  317. (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  318. }
  319. static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
  320. {
  321. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
  322. ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
  323. mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
  324. "buffer dimensions: %dx%d\n", ctx->img_width,
  325. ctx->img_height, ctx->buf_width, ctx->buf_height);
  326. ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
  327. ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
  328. if (IS_MFCV8(ctx->dev)) {
  329. /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/
  330. ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  331. ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  332. }
  333. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  334. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  335. ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
  336. ctx->img_height);
  337. ctx->mv_size = ALIGN(ctx->mv_size, 16);
  338. } else {
  339. ctx->mv_size = 0;
  340. }
  341. }
  342. static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
  343. {
  344. unsigned int mb_width, mb_height;
  345. mb_width = MB_WIDTH(ctx->img_width);
  346. mb_height = MB_HEIGHT(ctx->img_height);
  347. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
  348. ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
  349. ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
  350. /* MFCv7 needs pad bytes for Luma and Chroma */
  351. if (IS_MFCV7_PLUS(ctx->dev)) {
  352. ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
  353. ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
  354. }
  355. }
  356. /* Set registers for decoding stream buffer */
  357. static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  358. int buf_addr, unsigned int start_num_byte,
  359. unsigned int strm_size)
  360. {
  361. struct s5p_mfc_dev *dev = ctx->dev;
  362. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  363. struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
  364. mfc_debug_enter();
  365. mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
  366. "buf_size: 0x%08x (%d)\n",
  367. ctx->inst_no, buf_addr, strm_size, strm_size);
  368. writel(strm_size, mfc_regs->d_stream_data_size);
  369. writel(buf_addr, mfc_regs->d_cpb_buffer_addr);
  370. writel(buf_size->cpb, mfc_regs->d_cpb_buffer_size);
  371. writel(start_num_byte, mfc_regs->d_cpb_buffer_offset);
  372. mfc_debug_leave();
  373. return 0;
  374. }
  375. /* Set decoding frame buffer */
  376. static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
  377. {
  378. unsigned int frame_size, i;
  379. unsigned int frame_size_ch, frame_size_mv;
  380. struct s5p_mfc_dev *dev = ctx->dev;
  381. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  382. size_t buf_addr1;
  383. int buf_size1;
  384. int align_gap;
  385. buf_addr1 = ctx->bank1.dma;
  386. buf_size1 = ctx->bank1.size;
  387. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  388. mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
  389. mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
  390. writel(ctx->total_dpb_count, mfc_regs->d_num_dpb);
  391. writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size);
  392. writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size);
  393. writel(buf_addr1, mfc_regs->d_scratch_buffer_addr);
  394. writel(ctx->scratch_buf_size, mfc_regs->d_scratch_buffer_size);
  395. if (IS_MFCV8(dev)) {
  396. writel(ctx->img_width,
  397. mfc_regs->d_first_plane_dpb_stride_size);
  398. writel(ctx->img_width,
  399. mfc_regs->d_second_plane_dpb_stride_size);
  400. }
  401. buf_addr1 += ctx->scratch_buf_size;
  402. buf_size1 -= ctx->scratch_buf_size;
  403. if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
  404. ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
  405. writel(ctx->mv_size, mfc_regs->d_mv_buffer_size);
  406. writel(ctx->mv_count, mfc_regs->d_num_mv);
  407. }
  408. frame_size = ctx->luma_size;
  409. frame_size_ch = ctx->chroma_size;
  410. frame_size_mv = ctx->mv_size;
  411. mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
  412. frame_size, frame_size_ch, frame_size_mv);
  413. for (i = 0; i < ctx->total_dpb_count; i++) {
  414. /* Bank2 */
  415. mfc_debug(2, "Luma %d: %zx\n", i,
  416. ctx->dst_bufs[i].cookie.raw.luma);
  417. writel(ctx->dst_bufs[i].cookie.raw.luma,
  418. mfc_regs->d_first_plane_dpb + i * 4);
  419. mfc_debug(2, "\tChroma %d: %zx\n", i,
  420. ctx->dst_bufs[i].cookie.raw.chroma);
  421. writel(ctx->dst_bufs[i].cookie.raw.chroma,
  422. mfc_regs->d_second_plane_dpb + i * 4);
  423. }
  424. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  425. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  426. for (i = 0; i < ctx->mv_count; i++) {
  427. /* To test alignment */
  428. align_gap = buf_addr1;
  429. buf_addr1 = ALIGN(buf_addr1, 16);
  430. align_gap = buf_addr1 - align_gap;
  431. buf_size1 -= align_gap;
  432. mfc_debug(2, "\tBuf1: %zx, size: %d\n",
  433. buf_addr1, buf_size1);
  434. writel(buf_addr1, mfc_regs->d_mv_buffer + i * 4);
  435. buf_addr1 += frame_size_mv;
  436. buf_size1 -= frame_size_mv;
  437. }
  438. }
  439. mfc_debug(2, "Buf1: %zu, buf_size1: %d (frames %d)\n",
  440. buf_addr1, buf_size1, ctx->total_dpb_count);
  441. if (buf_size1 < 0) {
  442. mfc_debug(2, "Not enough memory has been allocated.\n");
  443. return -ENOMEM;
  444. }
  445. writel(ctx->inst_no, mfc_regs->instance_id);
  446. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  447. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  448. mfc_debug(2, "After setting buffers.\n");
  449. return 0;
  450. }
  451. /* Set registers for encoding stream buffer */
  452. static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  453. unsigned long addr, unsigned int size)
  454. {
  455. struct s5p_mfc_dev *dev = ctx->dev;
  456. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  457. writel(addr, mfc_regs->e_stream_buffer_addr); /* 16B align */
  458. writel(size, mfc_regs->e_stream_buffer_size);
  459. mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d\n",
  460. addr, size);
  461. return 0;
  462. }
  463. static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  464. unsigned long y_addr, unsigned long c_addr)
  465. {
  466. struct s5p_mfc_dev *dev = ctx->dev;
  467. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  468. writel(y_addr, mfc_regs->e_source_first_plane_addr);
  469. writel(c_addr, mfc_regs->e_source_second_plane_addr);
  470. mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr);
  471. mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr);
  472. }
  473. static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  474. unsigned long *y_addr, unsigned long *c_addr)
  475. {
  476. struct s5p_mfc_dev *dev = ctx->dev;
  477. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  478. unsigned long enc_recon_y_addr, enc_recon_c_addr;
  479. *y_addr = readl(mfc_regs->e_encoded_source_first_plane_addr);
  480. *c_addr = readl(mfc_regs->e_encoded_source_second_plane_addr);
  481. enc_recon_y_addr = readl(mfc_regs->e_recon_luma_dpb_addr);
  482. enc_recon_c_addr = readl(mfc_regs->e_recon_chroma_dpb_addr);
  483. mfc_debug(2, "recon y addr: 0x%08lx\n", enc_recon_y_addr);
  484. mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr);
  485. }
  486. /* Set encoding ref & codec buffer */
  487. static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
  488. {
  489. struct s5p_mfc_dev *dev = ctx->dev;
  490. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  491. size_t buf_addr1;
  492. int i, buf_size1;
  493. mfc_debug_enter();
  494. buf_addr1 = ctx->bank1.dma;
  495. buf_size1 = ctx->bank1.size;
  496. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  497. for (i = 0; i < ctx->pb_count; i++) {
  498. writel(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
  499. buf_addr1 += ctx->luma_dpb_size;
  500. writel(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
  501. buf_addr1 += ctx->chroma_dpb_size;
  502. writel(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
  503. buf_addr1 += ctx->me_buffer_size;
  504. buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
  505. ctx->me_buffer_size);
  506. }
  507. writel(buf_addr1, mfc_regs->e_scratch_buffer_addr);
  508. writel(ctx->scratch_buf_size, mfc_regs->e_scratch_buffer_size);
  509. buf_addr1 += ctx->scratch_buf_size;
  510. buf_size1 -= ctx->scratch_buf_size;
  511. writel(buf_addr1, mfc_regs->e_tmv_buffer0);
  512. buf_addr1 += ctx->tmv_buffer_size >> 1;
  513. writel(buf_addr1, mfc_regs->e_tmv_buffer1);
  514. buf_addr1 += ctx->tmv_buffer_size >> 1;
  515. buf_size1 -= ctx->tmv_buffer_size;
  516. mfc_debug(2, "Buf1: %zu, buf_size1: %d (ref frames %d)\n",
  517. buf_addr1, buf_size1, ctx->pb_count);
  518. if (buf_size1 < 0) {
  519. mfc_debug(2, "Not enough memory has been allocated.\n");
  520. return -ENOMEM;
  521. }
  522. writel(ctx->inst_no, mfc_regs->instance_id);
  523. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  524. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  525. mfc_debug_leave();
  526. return 0;
  527. }
  528. static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
  529. {
  530. struct s5p_mfc_dev *dev = ctx->dev;
  531. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  532. /* multi-slice control */
  533. /* multi-slice MB number or bit size */
  534. writel(ctx->slice_mode, mfc_regs->e_mslice_mode);
  535. if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  536. writel(ctx->slice_size.mb, mfc_regs->e_mslice_size_mb);
  537. } else if (ctx->slice_mode ==
  538. V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  539. writel(ctx->slice_size.bits, mfc_regs->e_mslice_size_bits);
  540. } else {
  541. writel(0x0, mfc_regs->e_mslice_size_mb);
  542. writel(0x0, mfc_regs->e_mslice_size_bits);
  543. }
  544. return 0;
  545. }
  546. static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
  547. {
  548. struct s5p_mfc_dev *dev = ctx->dev;
  549. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  550. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  551. unsigned int reg = 0;
  552. mfc_debug_enter();
  553. /* width */
  554. writel(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */
  555. /* height */
  556. writel(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */
  557. /* cropped width */
  558. writel(ctx->img_width, mfc_regs->e_cropped_frame_width);
  559. /* cropped height */
  560. writel(ctx->img_height, mfc_regs->e_cropped_frame_height);
  561. /* cropped offset */
  562. writel(0x0, mfc_regs->e_frame_crop_offset);
  563. /* pictype : IDR period */
  564. reg = 0;
  565. reg |= p->gop_size & 0xFFFF;
  566. writel(reg, mfc_regs->e_gop_config);
  567. /* multi-slice control */
  568. /* multi-slice MB number or bit size */
  569. ctx->slice_mode = p->slice_mode;
  570. reg = 0;
  571. if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  572. reg |= (0x1 << 3);
  573. writel(reg, mfc_regs->e_enc_options);
  574. ctx->slice_size.mb = p->slice_mb;
  575. } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  576. reg |= (0x1 << 3);
  577. writel(reg, mfc_regs->e_enc_options);
  578. ctx->slice_size.bits = p->slice_bit;
  579. } else {
  580. reg &= ~(0x1 << 3);
  581. writel(reg, mfc_regs->e_enc_options);
  582. }
  583. s5p_mfc_set_slice_mode(ctx);
  584. /* cyclic intra refresh */
  585. writel(p->intra_refresh_mb, mfc_regs->e_ir_size);
  586. reg = readl(mfc_regs->e_enc_options);
  587. if (p->intra_refresh_mb == 0)
  588. reg &= ~(0x1 << 4);
  589. else
  590. reg |= (0x1 << 4);
  591. writel(reg, mfc_regs->e_enc_options);
  592. /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
  593. reg = readl(mfc_regs->e_enc_options);
  594. reg &= ~(0x1 << 9);
  595. writel(reg, mfc_regs->e_enc_options);
  596. /* memory structure cur. frame */
  597. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
  598. /* 0: Linear, 1: 2D tiled*/
  599. reg = readl(mfc_regs->e_enc_options);
  600. reg &= ~(0x1 << 7);
  601. writel(reg, mfc_regs->e_enc_options);
  602. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  603. writel(0x0, mfc_regs->pixel_format);
  604. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
  605. /* 0: Linear, 1: 2D tiled*/
  606. reg = readl(mfc_regs->e_enc_options);
  607. reg &= ~(0x1 << 7);
  608. writel(reg, mfc_regs->e_enc_options);
  609. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  610. writel(0x1, mfc_regs->pixel_format);
  611. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
  612. /* 0: Linear, 1: 2D tiled*/
  613. reg = readl(mfc_regs->e_enc_options);
  614. reg |= (0x1 << 7);
  615. writel(reg, mfc_regs->e_enc_options);
  616. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  617. writel(0x0, mfc_regs->pixel_format);
  618. }
  619. /* memory structure recon. frame */
  620. /* 0: Linear, 1: 2D tiled */
  621. reg = readl(mfc_regs->e_enc_options);
  622. reg |= (0x1 << 8);
  623. writel(reg, mfc_regs->e_enc_options);
  624. /* padding control & value */
  625. writel(0x0, mfc_regs->e_padding_ctrl);
  626. if (p->pad) {
  627. reg = 0;
  628. /** enable */
  629. reg |= (1 << 31);
  630. /** cr value */
  631. reg |= ((p->pad_cr & 0xFF) << 16);
  632. /** cb value */
  633. reg |= ((p->pad_cb & 0xFF) << 8);
  634. /** y value */
  635. reg |= p->pad_luma & 0xFF;
  636. writel(reg, mfc_regs->e_padding_ctrl);
  637. }
  638. /* rate control config. */
  639. reg = 0;
  640. /* frame-level rate control */
  641. reg |= ((p->rc_frame & 0x1) << 9);
  642. writel(reg, mfc_regs->e_rc_config);
  643. /* bit rate */
  644. if (p->rc_frame)
  645. writel(p->rc_bitrate,
  646. mfc_regs->e_rc_bit_rate);
  647. else
  648. writel(1, mfc_regs->e_rc_bit_rate);
  649. /* reaction coefficient */
  650. if (p->rc_frame) {
  651. if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
  652. writel(1, mfc_regs->e_rc_mode);
  653. else /* loose CBR */
  654. writel(2, mfc_regs->e_rc_mode);
  655. }
  656. /* seq header ctrl */
  657. reg = readl(mfc_regs->e_enc_options);
  658. reg &= ~(0x1 << 2);
  659. reg |= ((p->seq_hdr_mode & 0x1) << 2);
  660. /* frame skip mode */
  661. reg &= ~(0x3);
  662. reg |= (p->frame_skip_mode & 0x3);
  663. writel(reg, mfc_regs->e_enc_options);
  664. /* 'DROP_CONTROL_ENABLE', disable */
  665. reg = readl(mfc_regs->e_rc_config);
  666. reg &= ~(0x1 << 10);
  667. writel(reg, mfc_regs->e_rc_config);
  668. /* setting for MV range [16, 256] */
  669. reg = (p->mv_h_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  670. writel(reg, mfc_regs->e_mv_hor_range);
  671. reg = (p->mv_v_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  672. writel(reg, mfc_regs->e_mv_ver_range);
  673. writel(0x0, mfc_regs->e_frame_insertion);
  674. writel(0x0, mfc_regs->e_roi_buffer_addr);
  675. writel(0x0, mfc_regs->e_param_change);
  676. writel(0x0, mfc_regs->e_rc_roi_ctrl);
  677. writel(0x0, mfc_regs->e_picture_tag);
  678. writel(0x0, mfc_regs->e_bit_count_enable);
  679. writel(0x0, mfc_regs->e_max_bit_count);
  680. writel(0x0, mfc_regs->e_min_bit_count);
  681. writel(0x0, mfc_regs->e_metadata_buffer_addr);
  682. writel(0x0, mfc_regs->e_metadata_buffer_size);
  683. mfc_debug_leave();
  684. return 0;
  685. }
  686. static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
  687. {
  688. struct s5p_mfc_dev *dev = ctx->dev;
  689. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  690. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  691. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  692. unsigned int reg = 0;
  693. int i;
  694. mfc_debug_enter();
  695. s5p_mfc_set_enc_params(ctx);
  696. /* pictype : number of B */
  697. reg = readl(mfc_regs->e_gop_config);
  698. reg &= ~(0x3 << 16);
  699. reg |= ((p->num_b_frame & 0x3) << 16);
  700. writel(reg, mfc_regs->e_gop_config);
  701. /* profile & level */
  702. reg = 0;
  703. /** level */
  704. reg |= ((p_h264->level & 0xFF) << 8);
  705. /** profile - 0 ~ 3 */
  706. reg |= p_h264->profile & 0x3F;
  707. writel(reg, mfc_regs->e_picture_profile);
  708. /* rate control config. */
  709. reg = readl(mfc_regs->e_rc_config);
  710. /** macroblock level rate control */
  711. reg &= ~(0x1 << 8);
  712. reg |= ((p->rc_mb & 0x1) << 8);
  713. writel(reg, mfc_regs->e_rc_config);
  714. /** frame QP */
  715. reg &= ~(0x3F);
  716. reg |= p_h264->rc_frame_qp & 0x3F;
  717. writel(reg, mfc_regs->e_rc_config);
  718. /* max & min value of QP */
  719. reg = 0;
  720. /** max QP */
  721. reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
  722. /** min QP */
  723. reg |= p_h264->rc_min_qp & 0x3F;
  724. writel(reg, mfc_regs->e_rc_qp_bound);
  725. /* other QPs */
  726. writel(0x0, mfc_regs->e_fixed_picture_qp);
  727. if (!p->rc_frame && !p->rc_mb) {
  728. reg = 0;
  729. reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
  730. reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
  731. reg |= p_h264->rc_frame_qp & 0x3F;
  732. writel(reg, mfc_regs->e_fixed_picture_qp);
  733. }
  734. /* frame rate */
  735. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  736. reg = 0;
  737. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  738. reg |= p->rc_framerate_denom & 0xFFFF;
  739. writel(reg, mfc_regs->e_rc_frame_rate);
  740. }
  741. /* vbv buffer size */
  742. if (p->frame_skip_mode ==
  743. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  744. writel(p_h264->cpb_size & 0xFFFF,
  745. mfc_regs->e_vbv_buffer_size);
  746. if (p->rc_frame)
  747. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  748. }
  749. /* interlace */
  750. reg = 0;
  751. reg |= ((p_h264->interlace & 0x1) << 3);
  752. writel(reg, mfc_regs->e_h264_options);
  753. /* height */
  754. if (p_h264->interlace) {
  755. writel(ctx->img_height >> 1,
  756. mfc_regs->e_frame_height); /* 32 align */
  757. /* cropped height */
  758. writel(ctx->img_height >> 1,
  759. mfc_regs->e_cropped_frame_height);
  760. }
  761. /* loop filter ctrl */
  762. reg = readl(mfc_regs->e_h264_options);
  763. reg &= ~(0x3 << 1);
  764. reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
  765. writel(reg, mfc_regs->e_h264_options);
  766. /* loopfilter alpha offset */
  767. if (p_h264->loop_filter_alpha < 0) {
  768. reg = 0x10;
  769. reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
  770. } else {
  771. reg = 0x00;
  772. reg |= (p_h264->loop_filter_alpha & 0xF);
  773. }
  774. writel(reg, mfc_regs->e_h264_lf_alpha_offset);
  775. /* loopfilter beta offset */
  776. if (p_h264->loop_filter_beta < 0) {
  777. reg = 0x10;
  778. reg |= (0xFF - p_h264->loop_filter_beta) + 1;
  779. } else {
  780. reg = 0x00;
  781. reg |= (p_h264->loop_filter_beta & 0xF);
  782. }
  783. writel(reg, mfc_regs->e_h264_lf_beta_offset);
  784. /* entropy coding mode */
  785. reg = readl(mfc_regs->e_h264_options);
  786. reg &= ~(0x1);
  787. reg |= p_h264->entropy_mode & 0x1;
  788. writel(reg, mfc_regs->e_h264_options);
  789. /* number of ref. picture */
  790. reg = readl(mfc_regs->e_h264_options);
  791. reg &= ~(0x1 << 7);
  792. reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
  793. writel(reg, mfc_regs->e_h264_options);
  794. /* 8x8 transform enable */
  795. reg = readl(mfc_regs->e_h264_options);
  796. reg &= ~(0x3 << 12);
  797. reg |= ((p_h264->_8x8_transform & 0x3) << 12);
  798. writel(reg, mfc_regs->e_h264_options);
  799. /* macroblock adaptive scaling features */
  800. writel(0x0, mfc_regs->e_mb_rc_config);
  801. if (p->rc_mb) {
  802. reg = 0;
  803. /** dark region */
  804. reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
  805. /** smooth region */
  806. reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
  807. /** static region */
  808. reg |= ((p_h264->rc_mb_static & 0x1) << 1);
  809. /** high activity region */
  810. reg |= p_h264->rc_mb_activity & 0x1;
  811. writel(reg, mfc_regs->e_mb_rc_config);
  812. }
  813. /* aspect ratio VUI */
  814. readl(mfc_regs->e_h264_options);
  815. reg &= ~(0x1 << 5);
  816. reg |= ((p_h264->vui_sar & 0x1) << 5);
  817. writel(reg, mfc_regs->e_h264_options);
  818. writel(0x0, mfc_regs->e_aspect_ratio);
  819. writel(0x0, mfc_regs->e_extended_sar);
  820. if (p_h264->vui_sar) {
  821. /* aspect ration IDC */
  822. reg = 0;
  823. reg |= p_h264->vui_sar_idc & 0xFF;
  824. writel(reg, mfc_regs->e_aspect_ratio);
  825. if (p_h264->vui_sar_idc == 0xFF) {
  826. /* extended SAR */
  827. reg = 0;
  828. reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
  829. reg |= p_h264->vui_ext_sar_height & 0xFFFF;
  830. writel(reg, mfc_regs->e_extended_sar);
  831. }
  832. }
  833. /* intra picture period for H.264 open GOP */
  834. /* control */
  835. readl(mfc_regs->e_h264_options);
  836. reg &= ~(0x1 << 4);
  837. reg |= ((p_h264->open_gop & 0x1) << 4);
  838. writel(reg, mfc_regs->e_h264_options);
  839. /* value */
  840. writel(0x0, mfc_regs->e_h264_i_period);
  841. if (p_h264->open_gop) {
  842. reg = 0;
  843. reg |= p_h264->open_gop_size & 0xFFFF;
  844. writel(reg, mfc_regs->e_h264_i_period);
  845. }
  846. /* 'WEIGHTED_BI_PREDICTION' for B is disable */
  847. readl(mfc_regs->e_h264_options);
  848. reg &= ~(0x3 << 9);
  849. writel(reg, mfc_regs->e_h264_options);
  850. /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
  851. readl(mfc_regs->e_h264_options);
  852. reg &= ~(0x1 << 14);
  853. writel(reg, mfc_regs->e_h264_options);
  854. /* ASO */
  855. readl(mfc_regs->e_h264_options);
  856. reg &= ~(0x1 << 6);
  857. reg |= ((p_h264->aso & 0x1) << 6);
  858. writel(reg, mfc_regs->e_h264_options);
  859. /* hier qp enable */
  860. readl(mfc_regs->e_h264_options);
  861. reg &= ~(0x1 << 8);
  862. reg |= ((p_h264->open_gop & 0x1) << 8);
  863. writel(reg, mfc_regs->e_h264_options);
  864. reg = 0;
  865. if (p_h264->hier_qp && p_h264->hier_qp_layer) {
  866. reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
  867. reg |= p_h264->hier_qp_layer & 0x7;
  868. writel(reg, mfc_regs->e_h264_num_t_layer);
  869. /* QP value for each layer */
  870. for (i = 0; i < p_h264->hier_qp_layer &&
  871. i < ARRAY_SIZE(p_h264->hier_qp_layer_qp); i++) {
  872. writel(p_h264->hier_qp_layer_qp[i],
  873. mfc_regs->e_h264_hierarchical_qp_layer0
  874. + i * 4);
  875. }
  876. }
  877. /* number of coding layer should be zero when hierarchical is disable */
  878. writel(reg, mfc_regs->e_h264_num_t_layer);
  879. /* frame packing SEI generation */
  880. readl(mfc_regs->e_h264_options);
  881. reg &= ~(0x1 << 25);
  882. reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
  883. writel(reg, mfc_regs->e_h264_options);
  884. if (p_h264->sei_frame_packing) {
  885. reg = 0;
  886. /** current frame0 flag */
  887. reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
  888. /** arrangement type */
  889. reg |= p_h264->sei_fp_arrangement_type & 0x3;
  890. writel(reg, mfc_regs->e_h264_frame_packing_sei_info);
  891. }
  892. if (p_h264->fmo) {
  893. switch (p_h264->fmo_map_type) {
  894. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
  895. if (p_h264->fmo_slice_grp > 4)
  896. p_h264->fmo_slice_grp = 4;
  897. for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
  898. writel(p_h264->fmo_run_len[i] - 1,
  899. mfc_regs->e_h264_fmo_run_length_minus1_0
  900. + i * 4);
  901. break;
  902. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
  903. if (p_h264->fmo_slice_grp > 4)
  904. p_h264->fmo_slice_grp = 4;
  905. break;
  906. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
  907. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
  908. if (p_h264->fmo_slice_grp > 2)
  909. p_h264->fmo_slice_grp = 2;
  910. writel(p_h264->fmo_chg_dir & 0x1,
  911. mfc_regs->e_h264_fmo_slice_grp_change_dir);
  912. /* the valid range is 0 ~ number of macroblocks -1 */
  913. writel(p_h264->fmo_chg_rate,
  914. mfc_regs->e_h264_fmo_slice_grp_change_rate_minus1);
  915. break;
  916. default:
  917. mfc_err("Unsupported map type for FMO: %d\n",
  918. p_h264->fmo_map_type);
  919. p_h264->fmo_map_type = 0;
  920. p_h264->fmo_slice_grp = 1;
  921. break;
  922. }
  923. writel(p_h264->fmo_map_type,
  924. mfc_regs->e_h264_fmo_slice_grp_map_type);
  925. writel(p_h264->fmo_slice_grp - 1,
  926. mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  927. } else {
  928. writel(0, mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  929. }
  930. mfc_debug_leave();
  931. return 0;
  932. }
  933. static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
  934. {
  935. struct s5p_mfc_dev *dev = ctx->dev;
  936. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  937. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  938. struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
  939. unsigned int reg = 0;
  940. mfc_debug_enter();
  941. s5p_mfc_set_enc_params(ctx);
  942. /* pictype : number of B */
  943. reg = readl(mfc_regs->e_gop_config);
  944. reg &= ~(0x3 << 16);
  945. reg |= ((p->num_b_frame & 0x3) << 16);
  946. writel(reg, mfc_regs->e_gop_config);
  947. /* profile & level */
  948. reg = 0;
  949. /** level */
  950. reg |= ((p_mpeg4->level & 0xFF) << 8);
  951. /** profile - 0 ~ 1 */
  952. reg |= p_mpeg4->profile & 0x3F;
  953. writel(reg, mfc_regs->e_picture_profile);
  954. /* rate control config. */
  955. reg = readl(mfc_regs->e_rc_config);
  956. /** macroblock level rate control */
  957. reg &= ~(0x1 << 8);
  958. reg |= ((p->rc_mb & 0x1) << 8);
  959. writel(reg, mfc_regs->e_rc_config);
  960. /** frame QP */
  961. reg &= ~(0x3F);
  962. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  963. writel(reg, mfc_regs->e_rc_config);
  964. /* max & min value of QP */
  965. reg = 0;
  966. /** max QP */
  967. reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
  968. /** min QP */
  969. reg |= p_mpeg4->rc_min_qp & 0x3F;
  970. writel(reg, mfc_regs->e_rc_qp_bound);
  971. /* other QPs */
  972. writel(0x0, mfc_regs->e_fixed_picture_qp);
  973. if (!p->rc_frame && !p->rc_mb) {
  974. reg = 0;
  975. reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
  976. reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
  977. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  978. writel(reg, mfc_regs->e_fixed_picture_qp);
  979. }
  980. /* frame rate */
  981. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  982. reg = 0;
  983. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  984. reg |= p->rc_framerate_denom & 0xFFFF;
  985. writel(reg, mfc_regs->e_rc_frame_rate);
  986. }
  987. /* vbv buffer size */
  988. if (p->frame_skip_mode ==
  989. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  990. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  991. if (p->rc_frame)
  992. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  993. }
  994. /* Disable HEC */
  995. writel(0x0, mfc_regs->e_mpeg4_options);
  996. writel(0x0, mfc_regs->e_mpeg4_hec_period);
  997. mfc_debug_leave();
  998. return 0;
  999. }
  1000. static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
  1001. {
  1002. struct s5p_mfc_dev *dev = ctx->dev;
  1003. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1004. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1005. struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
  1006. unsigned int reg = 0;
  1007. mfc_debug_enter();
  1008. s5p_mfc_set_enc_params(ctx);
  1009. /* profile & level */
  1010. reg = 0;
  1011. /** profile */
  1012. reg |= (0x1 << 4);
  1013. writel(reg, mfc_regs->e_picture_profile);
  1014. /* rate control config. */
  1015. reg = readl(mfc_regs->e_rc_config);
  1016. /** macroblock level rate control */
  1017. reg &= ~(0x1 << 8);
  1018. reg |= ((p->rc_mb & 0x1) << 8);
  1019. writel(reg, mfc_regs->e_rc_config);
  1020. /** frame QP */
  1021. reg &= ~(0x3F);
  1022. reg |= p_h263->rc_frame_qp & 0x3F;
  1023. writel(reg, mfc_regs->e_rc_config);
  1024. /* max & min value of QP */
  1025. reg = 0;
  1026. /** max QP */
  1027. reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
  1028. /** min QP */
  1029. reg |= p_h263->rc_min_qp & 0x3F;
  1030. writel(reg, mfc_regs->e_rc_qp_bound);
  1031. /* other QPs */
  1032. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1033. if (!p->rc_frame && !p->rc_mb) {
  1034. reg = 0;
  1035. reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
  1036. reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
  1037. reg |= p_h263->rc_frame_qp & 0x3F;
  1038. writel(reg, mfc_regs->e_fixed_picture_qp);
  1039. }
  1040. /* frame rate */
  1041. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1042. reg = 0;
  1043. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1044. reg |= p->rc_framerate_denom & 0xFFFF;
  1045. writel(reg, mfc_regs->e_rc_frame_rate);
  1046. }
  1047. /* vbv buffer size */
  1048. if (p->frame_skip_mode ==
  1049. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1050. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1051. if (p->rc_frame)
  1052. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1053. }
  1054. mfc_debug_leave();
  1055. return 0;
  1056. }
  1057. static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx)
  1058. {
  1059. struct s5p_mfc_dev *dev = ctx->dev;
  1060. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1061. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1062. struct s5p_mfc_vp8_enc_params *p_vp8 = &p->codec.vp8;
  1063. unsigned int reg = 0;
  1064. unsigned int val = 0;
  1065. mfc_debug_enter();
  1066. s5p_mfc_set_enc_params(ctx);
  1067. /* pictype : number of B */
  1068. reg = readl(mfc_regs->e_gop_config);
  1069. reg &= ~(0x3 << 16);
  1070. reg |= ((p->num_b_frame & 0x3) << 16);
  1071. writel(reg, mfc_regs->e_gop_config);
  1072. /* profile - 0 ~ 3 */
  1073. reg = p_vp8->profile & 0x3;
  1074. writel(reg, mfc_regs->e_picture_profile);
  1075. /* rate control config. */
  1076. reg = readl(mfc_regs->e_rc_config);
  1077. /** macroblock level rate control */
  1078. reg &= ~(0x1 << 8);
  1079. reg |= ((p->rc_mb & 0x1) << 8);
  1080. writel(reg, mfc_regs->e_rc_config);
  1081. /* frame rate */
  1082. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1083. reg = 0;
  1084. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1085. reg |= p->rc_framerate_denom & 0xFFFF;
  1086. writel(reg, mfc_regs->e_rc_frame_rate);
  1087. }
  1088. /* frame QP */
  1089. reg &= ~(0x7F);
  1090. reg |= p_vp8->rc_frame_qp & 0x7F;
  1091. writel(reg, mfc_regs->e_rc_config);
  1092. /* other QPs */
  1093. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1094. if (!p->rc_frame && !p->rc_mb) {
  1095. reg = 0;
  1096. reg |= ((p_vp8->rc_p_frame_qp & 0x7F) << 8);
  1097. reg |= p_vp8->rc_frame_qp & 0x7F;
  1098. writel(reg, mfc_regs->e_fixed_picture_qp);
  1099. }
  1100. /* max QP */
  1101. reg = ((p_vp8->rc_max_qp & 0x7F) << 8);
  1102. /* min QP */
  1103. reg |= p_vp8->rc_min_qp & 0x7F;
  1104. writel(reg, mfc_regs->e_rc_qp_bound);
  1105. /* vbv buffer size */
  1106. if (p->frame_skip_mode ==
  1107. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1108. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1109. if (p->rc_frame)
  1110. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1111. }
  1112. /* VP8 specific params */
  1113. reg = 0;
  1114. reg |= (p_vp8->imd_4x4 & 0x1) << 10;
  1115. switch (p_vp8->num_partitions) {
  1116. case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
  1117. val = 0;
  1118. break;
  1119. case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS:
  1120. val = 2;
  1121. break;
  1122. case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS:
  1123. val = 4;
  1124. break;
  1125. case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS:
  1126. val = 8;
  1127. break;
  1128. }
  1129. reg |= (val & 0xF) << 3;
  1130. reg |= (p_vp8->num_ref & 0x2);
  1131. writel(reg, mfc_regs->e_vp8_options);
  1132. mfc_debug_leave();
  1133. return 0;
  1134. }
  1135. /* Initialize decoding */
  1136. static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
  1137. {
  1138. struct s5p_mfc_dev *dev = ctx->dev;
  1139. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1140. unsigned int reg = 0;
  1141. int fmo_aso_ctrl = 0;
  1142. mfc_debug_enter();
  1143. mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
  1144. S5P_FIMV_CH_SEQ_HEADER_V6);
  1145. mfc_debug(2, "BUFs: %08x %08x %08x\n",
  1146. readl(mfc_regs->d_cpb_buffer_addr),
  1147. readl(mfc_regs->d_cpb_buffer_addr),
  1148. readl(mfc_regs->d_cpb_buffer_addr));
  1149. /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
  1150. reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
  1151. /* When user sets desplay_delay to 0,
  1152. * It works as "display_delay enable" and delay set to 0.
  1153. * If user wants display_delay disable, It should be
  1154. * set to negative value. */
  1155. if (ctx->display_delay >= 0) {
  1156. reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
  1157. writel(ctx->display_delay, mfc_regs->d_display_delay);
  1158. }
  1159. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
  1160. writel(reg, mfc_regs->d_dec_options);
  1161. reg = 0;
  1162. }
  1163. /* Setup loop filter, for decoding this is only valid for MPEG4 */
  1164. if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
  1165. mfc_debug(2, "Set loop filter to: %d\n",
  1166. ctx->loop_filter_mpeg4);
  1167. reg |= (ctx->loop_filter_mpeg4 <<
  1168. S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
  1169. }
  1170. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
  1171. reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
  1172. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
  1173. writel(reg, mfc_regs->d_init_buffer_options);
  1174. else
  1175. writel(reg, mfc_regs->d_dec_options);
  1176. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  1177. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
  1178. writel(0x1, mfc_regs->pixel_format);
  1179. else
  1180. writel(0x0, mfc_regs->pixel_format);
  1181. /* sei parse */
  1182. writel(ctx->sei_fp_parse & 0x1, mfc_regs->d_sei_enable);
  1183. writel(ctx->inst_no, mfc_regs->instance_id);
  1184. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1185. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1186. mfc_debug_leave();
  1187. return 0;
  1188. }
  1189. static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
  1190. {
  1191. struct s5p_mfc_dev *dev = ctx->dev;
  1192. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1193. if (flush) {
  1194. dev->curr_ctx = ctx->num;
  1195. writel(ctx->inst_no, mfc_regs->instance_id);
  1196. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1197. S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
  1198. }
  1199. }
  1200. /* Decode a single frame */
  1201. static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
  1202. enum s5p_mfc_decode_arg last_frame)
  1203. {
  1204. struct s5p_mfc_dev *dev = ctx->dev;
  1205. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1206. writel(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower);
  1207. writel(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable);
  1208. writel(ctx->inst_no, mfc_regs->instance_id);
  1209. /* Issue different commands to instance basing on whether it
  1210. * is the last frame or not. */
  1211. switch (last_frame) {
  1212. case 0:
  1213. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1214. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1215. break;
  1216. case 1:
  1217. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1218. S5P_FIMV_CH_LAST_FRAME_V6, NULL);
  1219. break;
  1220. default:
  1221. mfc_err("Unsupported last frame arg.\n");
  1222. return -EINVAL;
  1223. }
  1224. mfc_debug(2, "Decoding a usual frame.\n");
  1225. return 0;
  1226. }
  1227. static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
  1228. {
  1229. struct s5p_mfc_dev *dev = ctx->dev;
  1230. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1231. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1232. s5p_mfc_set_enc_params_h264(ctx);
  1233. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1234. s5p_mfc_set_enc_params_mpeg4(ctx);
  1235. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1236. s5p_mfc_set_enc_params_h263(ctx);
  1237. else if (ctx->codec_mode == S5P_MFC_CODEC_VP8_ENC)
  1238. s5p_mfc_set_enc_params_vp8(ctx);
  1239. else {
  1240. mfc_err("Unknown codec for encoding (%x).\n",
  1241. ctx->codec_mode);
  1242. return -EINVAL;
  1243. }
  1244. /* Set stride lengths for v7 & above */
  1245. if (IS_MFCV7_PLUS(dev)) {
  1246. writel(ctx->img_width, mfc_regs->e_source_first_plane_stride);
  1247. writel(ctx->img_width, mfc_regs->e_source_second_plane_stride);
  1248. }
  1249. writel(ctx->inst_no, mfc_regs->instance_id);
  1250. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1251. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1252. return 0;
  1253. }
  1254. static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
  1255. {
  1256. struct s5p_mfc_dev *dev = ctx->dev;
  1257. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1258. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1259. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  1260. int i;
  1261. if (p_h264->aso) {
  1262. for (i = 0; i < ARRAY_SIZE(p_h264->aso_slice_order); i++) {
  1263. writel(p_h264->aso_slice_order[i],
  1264. mfc_regs->e_h264_aso_slice_order_0 + i * 4);
  1265. }
  1266. }
  1267. return 0;
  1268. }
  1269. /* Encode a single frame */
  1270. static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
  1271. {
  1272. struct s5p_mfc_dev *dev = ctx->dev;
  1273. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1274. mfc_debug(2, "++\n");
  1275. /* memory structure cur. frame */
  1276. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1277. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1278. s5p_mfc_set_slice_mode(ctx);
  1279. writel(ctx->inst_no, mfc_regs->instance_id);
  1280. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1281. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1282. mfc_debug(2, "--\n");
  1283. return 0;
  1284. }
  1285. static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
  1286. {
  1287. unsigned long flags;
  1288. int new_ctx;
  1289. int cnt;
  1290. spin_lock_irqsave(&dev->condlock, flags);
  1291. mfc_debug(2, "Previous context: %d (bits %08lx)\n", dev->curr_ctx,
  1292. dev->ctx_work_bits);
  1293. new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
  1294. cnt = 0;
  1295. while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
  1296. new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
  1297. cnt++;
  1298. if (cnt > MFC_NUM_CONTEXTS) {
  1299. /* No contexts to run */
  1300. spin_unlock_irqrestore(&dev->condlock, flags);
  1301. return -EAGAIN;
  1302. }
  1303. }
  1304. spin_unlock_irqrestore(&dev->condlock, flags);
  1305. return new_ctx;
  1306. }
  1307. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1308. {
  1309. struct s5p_mfc_dev *dev = ctx->dev;
  1310. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1311. dev->curr_ctx = ctx->num;
  1312. s5p_mfc_decode_one_frame_v6(ctx, MFC_DEC_LAST_FRAME);
  1313. }
  1314. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1315. {
  1316. struct s5p_mfc_dev *dev = ctx->dev;
  1317. struct s5p_mfc_buf *temp_vb;
  1318. unsigned long flags;
  1319. int last_frame = 0;
  1320. if (ctx->state == MFCINST_FINISHING) {
  1321. last_frame = MFC_DEC_LAST_FRAME;
  1322. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1323. dev->curr_ctx = ctx->num;
  1324. s5p_mfc_clean_ctx_int_flags(ctx);
  1325. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1326. return 0;
  1327. }
  1328. spin_lock_irqsave(&dev->irqlock, flags);
  1329. /* Frames are being decoded */
  1330. if (list_empty(&ctx->src_queue)) {
  1331. mfc_debug(2, "No src buffers.\n");
  1332. spin_unlock_irqrestore(&dev->irqlock, flags);
  1333. return -EAGAIN;
  1334. }
  1335. /* Get the next source buffer */
  1336. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1337. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1338. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1339. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1340. ctx->consumed_stream,
  1341. temp_vb->b->v4l2_planes[0].bytesused);
  1342. spin_unlock_irqrestore(&dev->irqlock, flags);
  1343. dev->curr_ctx = ctx->num;
  1344. if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
  1345. last_frame = 1;
  1346. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1347. ctx->state = MFCINST_FINISHING;
  1348. }
  1349. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1350. return 0;
  1351. }
  1352. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1353. {
  1354. struct s5p_mfc_dev *dev = ctx->dev;
  1355. unsigned long flags;
  1356. struct s5p_mfc_buf *dst_mb;
  1357. struct s5p_mfc_buf *src_mb;
  1358. unsigned long src_y_addr, src_c_addr, dst_addr;
  1359. /*
  1360. unsigned int src_y_size, src_c_size;
  1361. */
  1362. unsigned int dst_size;
  1363. spin_lock_irqsave(&dev->irqlock, flags);
  1364. if (list_empty(&ctx->src_queue)) {
  1365. mfc_debug(2, "no src buffers.\n");
  1366. spin_unlock_irqrestore(&dev->irqlock, flags);
  1367. return -EAGAIN;
  1368. }
  1369. if (list_empty(&ctx->dst_queue)) {
  1370. mfc_debug(2, "no dst buffers.\n");
  1371. spin_unlock_irqrestore(&dev->irqlock, flags);
  1372. return -EAGAIN;
  1373. }
  1374. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1375. src_mb->flags |= MFC_BUF_FLAG_USED;
  1376. src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
  1377. src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
  1378. mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
  1379. mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
  1380. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1381. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1382. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1383. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1384. dst_size = vb2_plane_size(dst_mb->b, 0);
  1385. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1386. spin_unlock_irqrestore(&dev->irqlock, flags);
  1387. dev->curr_ctx = ctx->num;
  1388. s5p_mfc_encode_one_frame_v6(ctx);
  1389. return 0;
  1390. }
  1391. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1392. {
  1393. struct s5p_mfc_dev *dev = ctx->dev;
  1394. unsigned long flags;
  1395. struct s5p_mfc_buf *temp_vb;
  1396. /* Initializing decoding - parsing header */
  1397. spin_lock_irqsave(&dev->irqlock, flags);
  1398. mfc_debug(2, "Preparing to init decoding.\n");
  1399. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1400. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1401. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1402. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
  1403. temp_vb->b->v4l2_planes[0].bytesused);
  1404. spin_unlock_irqrestore(&dev->irqlock, flags);
  1405. dev->curr_ctx = ctx->num;
  1406. s5p_mfc_init_decode_v6(ctx);
  1407. }
  1408. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1409. {
  1410. struct s5p_mfc_dev *dev = ctx->dev;
  1411. unsigned long flags;
  1412. struct s5p_mfc_buf *dst_mb;
  1413. unsigned long dst_addr;
  1414. unsigned int dst_size;
  1415. spin_lock_irqsave(&dev->irqlock, flags);
  1416. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1417. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1418. dst_size = vb2_plane_size(dst_mb->b, 0);
  1419. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1420. spin_unlock_irqrestore(&dev->irqlock, flags);
  1421. dev->curr_ctx = ctx->num;
  1422. s5p_mfc_init_encode_v6(ctx);
  1423. }
  1424. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1425. {
  1426. struct s5p_mfc_dev *dev = ctx->dev;
  1427. int ret;
  1428. /* Header was parsed now start processing
  1429. * First set the output frame buffers
  1430. * s5p_mfc_alloc_dec_buffers(ctx); */
  1431. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1432. mfc_err("It seems that not all destionation buffers were\n"
  1433. "mmaped.MFC requires that all destination are mmaped\n"
  1434. "before starting processing.\n");
  1435. return -EAGAIN;
  1436. }
  1437. dev->curr_ctx = ctx->num;
  1438. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1439. if (ret) {
  1440. mfc_err("Failed to alloc frame mem.\n");
  1441. ctx->state = MFCINST_ERROR;
  1442. }
  1443. return ret;
  1444. }
  1445. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1446. {
  1447. struct s5p_mfc_dev *dev = ctx->dev;
  1448. int ret;
  1449. dev->curr_ctx = ctx->num;
  1450. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1451. if (ret) {
  1452. mfc_err("Failed to alloc frame mem.\n");
  1453. ctx->state = MFCINST_ERROR;
  1454. }
  1455. return ret;
  1456. }
  1457. /* Try running an operation on hardware */
  1458. static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1459. {
  1460. struct s5p_mfc_ctx *ctx;
  1461. int new_ctx;
  1462. unsigned int ret = 0;
  1463. mfc_debug(1, "Try run dev: %p\n", dev);
  1464. /* Check whether hardware is not running */
  1465. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1466. /* This is perfectly ok, the scheduled ctx should wait */
  1467. mfc_debug(1, "Couldn't lock HW.\n");
  1468. return;
  1469. }
  1470. /* Choose the context to run */
  1471. new_ctx = s5p_mfc_get_new_ctx(dev);
  1472. if (new_ctx < 0) {
  1473. /* No contexts to run */
  1474. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1475. mfc_err("Failed to unlock hardware.\n");
  1476. return;
  1477. }
  1478. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1479. return;
  1480. }
  1481. mfc_debug(1, "New context: %d\n", new_ctx);
  1482. ctx = dev->ctx[new_ctx];
  1483. mfc_debug(1, "Seting new context to %p\n", ctx);
  1484. /* Got context to run in ctx */
  1485. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1486. ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
  1487. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1488. /* Last frame has already been sent to MFC
  1489. * Now obtaining frames from MFC buffer */
  1490. s5p_mfc_clock_on();
  1491. s5p_mfc_clean_ctx_int_flags(ctx);
  1492. if (ctx->type == MFCINST_DECODER) {
  1493. switch (ctx->state) {
  1494. case MFCINST_FINISHING:
  1495. s5p_mfc_run_dec_last_frames(ctx);
  1496. break;
  1497. case MFCINST_RUNNING:
  1498. ret = s5p_mfc_run_dec_frame(ctx);
  1499. break;
  1500. case MFCINST_INIT:
  1501. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1502. ctx);
  1503. break;
  1504. case MFCINST_RETURN_INST:
  1505. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1506. ctx);
  1507. break;
  1508. case MFCINST_GOT_INST:
  1509. s5p_mfc_run_init_dec(ctx);
  1510. break;
  1511. case MFCINST_HEAD_PARSED:
  1512. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1513. break;
  1514. case MFCINST_FLUSH:
  1515. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  1516. break;
  1517. case MFCINST_RES_CHANGE_INIT:
  1518. s5p_mfc_run_dec_last_frames(ctx);
  1519. break;
  1520. case MFCINST_RES_CHANGE_FLUSH:
  1521. s5p_mfc_run_dec_last_frames(ctx);
  1522. break;
  1523. case MFCINST_RES_CHANGE_END:
  1524. mfc_debug(2, "Finished remaining frames after resolution change.\n");
  1525. ctx->capture_state = QUEUE_FREE;
  1526. mfc_debug(2, "Will re-init the codec`.\n");
  1527. s5p_mfc_run_init_dec(ctx);
  1528. break;
  1529. default:
  1530. ret = -EAGAIN;
  1531. }
  1532. } else if (ctx->type == MFCINST_ENCODER) {
  1533. switch (ctx->state) {
  1534. case MFCINST_FINISHING:
  1535. case MFCINST_RUNNING:
  1536. ret = s5p_mfc_run_enc_frame(ctx);
  1537. break;
  1538. case MFCINST_INIT:
  1539. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1540. ctx);
  1541. break;
  1542. case MFCINST_RETURN_INST:
  1543. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1544. ctx);
  1545. break;
  1546. case MFCINST_GOT_INST:
  1547. s5p_mfc_run_init_enc(ctx);
  1548. break;
  1549. case MFCINST_HEAD_PRODUCED:
  1550. ret = s5p_mfc_run_init_enc_buffers(ctx);
  1551. break;
  1552. default:
  1553. ret = -EAGAIN;
  1554. }
  1555. } else {
  1556. mfc_err("invalid context type: %d\n", ctx->type);
  1557. ret = -EAGAIN;
  1558. }
  1559. if (ret) {
  1560. /* Free hardware lock */
  1561. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1562. mfc_err("Failed to unlock hardware.\n");
  1563. /* This is in deed imporant, as no operation has been
  1564. * scheduled, reduce the clock count as no one will
  1565. * ever do this, because no interrupt related to this try_run
  1566. * will ever come from hardware. */
  1567. s5p_mfc_clock_off();
  1568. }
  1569. }
  1570. static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
  1571. {
  1572. struct s5p_mfc_buf *b;
  1573. int i;
  1574. while (!list_empty(lh)) {
  1575. b = list_entry(lh->next, struct s5p_mfc_buf, list);
  1576. for (i = 0; i < b->b->num_planes; i++)
  1577. vb2_set_plane_payload(b->b, i, 0);
  1578. vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
  1579. list_del(&b->list);
  1580. }
  1581. }
  1582. static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
  1583. {
  1584. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1585. writel(0, mfc_regs->risc2host_command);
  1586. writel(0, mfc_regs->risc2host_int);
  1587. }
  1588. static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
  1589. unsigned int ofs)
  1590. {
  1591. s5p_mfc_clock_on();
  1592. writel(data, (volatile void __iomem *)((unsigned long)ofs));
  1593. s5p_mfc_clock_off();
  1594. }
  1595. static unsigned int
  1596. s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned int ofs)
  1597. {
  1598. int ret;
  1599. s5p_mfc_clock_on();
  1600. ret = readl((volatile void __iomem *)((unsigned long)ofs));
  1601. s5p_mfc_clock_off();
  1602. return ret;
  1603. }
  1604. static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
  1605. {
  1606. return readl(dev->mfc_regs->d_display_first_plane_addr);
  1607. }
  1608. static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
  1609. {
  1610. return readl(dev->mfc_regs->d_decoded_first_plane_addr);
  1611. }
  1612. static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
  1613. {
  1614. return readl(dev->mfc_regs->d_display_status);
  1615. }
  1616. static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
  1617. {
  1618. return readl(dev->mfc_regs->d_decoded_status);
  1619. }
  1620. static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
  1621. {
  1622. return readl(dev->mfc_regs->d_decoded_frame_type) &
  1623. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1624. }
  1625. static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
  1626. {
  1627. struct s5p_mfc_dev *dev = ctx->dev;
  1628. return readl(dev->mfc_regs->d_display_frame_type) &
  1629. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1630. }
  1631. static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
  1632. {
  1633. return readl(dev->mfc_regs->d_decoded_nal_size);
  1634. }
  1635. static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
  1636. {
  1637. return readl(dev->mfc_regs->risc2host_command) &
  1638. S5P_FIMV_RISC2HOST_CMD_MASK;
  1639. }
  1640. static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
  1641. {
  1642. return readl(dev->mfc_regs->error_code);
  1643. }
  1644. static int s5p_mfc_err_dec_v6(unsigned int err)
  1645. {
  1646. return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
  1647. }
  1648. static int s5p_mfc_err_dspl_v6(unsigned int err)
  1649. {
  1650. return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
  1651. }
  1652. static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
  1653. {
  1654. return readl(dev->mfc_regs->d_display_frame_width);
  1655. }
  1656. static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
  1657. {
  1658. return readl(dev->mfc_regs->d_display_frame_height);
  1659. }
  1660. static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
  1661. {
  1662. return readl(dev->mfc_regs->d_min_num_dpb);
  1663. }
  1664. static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
  1665. {
  1666. return readl(dev->mfc_regs->d_min_num_mv);
  1667. }
  1668. static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
  1669. {
  1670. return readl(dev->mfc_regs->ret_instance_id);
  1671. }
  1672. static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
  1673. {
  1674. return readl(dev->mfc_regs->e_num_dpb);
  1675. }
  1676. static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
  1677. {
  1678. return readl(dev->mfc_regs->e_stream_size);
  1679. }
  1680. static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
  1681. {
  1682. return readl(dev->mfc_regs->e_slice_type);
  1683. }
  1684. static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
  1685. {
  1686. return readl(dev->mfc_regs->e_picture_count);
  1687. }
  1688. static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
  1689. {
  1690. struct s5p_mfc_dev *dev = ctx->dev;
  1691. return readl(dev->mfc_regs->d_frame_pack_sei_avail);
  1692. }
  1693. static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
  1694. {
  1695. return readl(dev->mfc_regs->d_mvc_num_views);
  1696. }
  1697. static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
  1698. {
  1699. return readl(dev->mfc_regs->d_mvc_view_id);
  1700. }
  1701. static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
  1702. {
  1703. return s5p_mfc_read_info_v6(ctx,
  1704. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_top);
  1705. }
  1706. static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
  1707. {
  1708. return s5p_mfc_read_info_v6(ctx,
  1709. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
  1710. }
  1711. static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
  1712. {
  1713. return s5p_mfc_read_info_v6(ctx,
  1714. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info1);
  1715. }
  1716. static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
  1717. {
  1718. return s5p_mfc_read_info_v6(ctx,
  1719. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info2);
  1720. }
  1721. static struct s5p_mfc_regs mfc_regs;
  1722. /* Initialize registers for MFC v6 onwards */
  1723. const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
  1724. {
  1725. memset(&mfc_regs, 0, sizeof(mfc_regs));
  1726. #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
  1727. #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
  1728. /* codec common registers */
  1729. R(risc_on, S5P_FIMV_RISC_ON_V6);
  1730. R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
  1731. R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
  1732. R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
  1733. R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
  1734. R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
  1735. R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
  1736. R(firmware_version, S5P_FIMV_FW_VERSION_V6);
  1737. R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
  1738. R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
  1739. R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
  1740. R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
  1741. R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
  1742. R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
  1743. R(error_code, S5P_FIMV_ERROR_CODE_V6);
  1744. /* decoder registers */
  1745. R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
  1746. R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
  1747. R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
  1748. R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
  1749. R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
  1750. R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
  1751. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
  1752. R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
  1753. R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
  1754. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
  1755. R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
  1756. R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
  1757. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
  1758. R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
  1759. R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
  1760. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
  1761. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
  1762. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
  1763. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
  1764. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
  1765. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1766. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
  1767. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1768. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
  1769. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
  1770. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
  1771. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
  1772. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
  1773. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
  1774. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
  1775. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
  1776. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
  1777. R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
  1778. R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
  1779. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
  1780. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
  1781. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
  1782. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
  1783. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
  1784. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
  1785. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
  1786. R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
  1787. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
  1788. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
  1789. /* encoder registers */
  1790. R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
  1791. R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
  1792. R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
  1793. R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  1794. R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
  1795. R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
  1796. R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
  1797. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  1798. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  1799. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  1800. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
  1801. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
  1802. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
  1803. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
  1804. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
  1805. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
  1806. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
  1807. R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
  1808. R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
  1809. R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
  1810. R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
  1811. R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
  1812. R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
  1813. R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
  1814. R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
  1815. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
  1816. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
  1817. R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
  1818. R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
  1819. R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
  1820. R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
  1821. R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
  1822. R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
  1823. R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
  1824. R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  1825. R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  1826. R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
  1827. R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
  1828. R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
  1829. R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
  1830. R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
  1831. R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
  1832. R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
  1833. R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
  1834. R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
  1835. R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
  1836. R(e_encoded_source_first_plane_addr,
  1837. S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
  1838. R(e_encoded_source_second_plane_addr,
  1839. S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
  1840. R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
  1841. R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
  1842. R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
  1843. R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
  1844. R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
  1845. R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
  1846. R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
  1847. R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
  1848. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
  1849. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
  1850. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
  1851. R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
  1852. R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
  1853. R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
  1854. R(e_h264_fmo_slice_grp_map_type,
  1855. S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
  1856. R(e_h264_fmo_num_slice_grp_minus1,
  1857. S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  1858. R(e_h264_fmo_slice_grp_change_dir,
  1859. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
  1860. R(e_h264_fmo_slice_grp_change_rate_minus1,
  1861. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
  1862. R(e_h264_fmo_run_length_minus1_0,
  1863. S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
  1864. R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
  1865. R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  1866. R(e_h264_hierarchical_qp_layer0,
  1867. S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
  1868. R(e_h264_frame_packing_sei_info,
  1869. S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
  1870. if (!IS_MFCV7_PLUS(dev))
  1871. goto done;
  1872. /* Initialize registers used in MFC v7+ */
  1873. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
  1874. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
  1875. R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
  1876. R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
  1877. R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
  1878. R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
  1879. R(e_encoded_source_first_plane_addr,
  1880. S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
  1881. R(e_encoded_source_second_plane_addr,
  1882. S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
  1883. R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
  1884. if (!IS_MFCV8(dev))
  1885. goto done;
  1886. /* Initialize registers used in MFC v8 only.
  1887. * Also, over-write the registers which have
  1888. * a different offset for MFC v8. */
  1889. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
  1890. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
  1891. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
  1892. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
  1893. R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
  1894. R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
  1895. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
  1896. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
  1897. R(d_first_plane_dpb_stride_size,
  1898. S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
  1899. R(d_second_plane_dpb_stride_size,
  1900. S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
  1901. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
  1902. R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
  1903. R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
  1904. R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
  1905. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
  1906. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
  1907. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
  1908. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
  1909. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
  1910. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
  1911. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
  1912. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
  1913. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
  1914. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
  1915. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
  1916. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
  1917. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
  1918. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
  1919. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
  1920. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
  1921. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
  1922. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
  1923. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
  1924. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
  1925. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
  1926. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
  1927. /* encoder registers */
  1928. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
  1929. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
  1930. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
  1931. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
  1932. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
  1933. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
  1934. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
  1935. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
  1936. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
  1937. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
  1938. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
  1939. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
  1940. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
  1941. done:
  1942. return &mfc_regs;
  1943. #undef S5P_MFC_REG_ADDR
  1944. #undef R
  1945. }
  1946. /* Initialize opr function pointers for MFC v6 */
  1947. static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
  1948. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
  1949. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
  1950. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
  1951. .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
  1952. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
  1953. .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
  1954. .alloc_dev_context_buffer =
  1955. s5p_mfc_alloc_dev_context_buffer_v6,
  1956. .release_dev_context_buffer =
  1957. s5p_mfc_release_dev_context_buffer_v6,
  1958. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
  1959. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
  1960. .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
  1961. .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
  1962. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
  1963. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
  1964. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
  1965. .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
  1966. .init_decode = s5p_mfc_init_decode_v6,
  1967. .init_encode = s5p_mfc_init_encode_v6,
  1968. .encode_one_frame = s5p_mfc_encode_one_frame_v6,
  1969. .try_run = s5p_mfc_try_run_v6,
  1970. .cleanup_queue = s5p_mfc_cleanup_queue_v6,
  1971. .clear_int_flags = s5p_mfc_clear_int_flags_v6,
  1972. .write_info = s5p_mfc_write_info_v6,
  1973. .read_info = s5p_mfc_read_info_v6,
  1974. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
  1975. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
  1976. .get_dspl_status = s5p_mfc_get_dspl_status_v6,
  1977. .get_dec_status = s5p_mfc_get_dec_status_v6,
  1978. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
  1979. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
  1980. .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
  1981. .get_int_reason = s5p_mfc_get_int_reason_v6,
  1982. .get_int_err = s5p_mfc_get_int_err_v6,
  1983. .err_dec = s5p_mfc_err_dec_v6,
  1984. .err_dspl = s5p_mfc_err_dspl_v6,
  1985. .get_img_width = s5p_mfc_get_img_width_v6,
  1986. .get_img_height = s5p_mfc_get_img_height_v6,
  1987. .get_dpb_count = s5p_mfc_get_dpb_count_v6,
  1988. .get_mv_count = s5p_mfc_get_mv_count_v6,
  1989. .get_inst_no = s5p_mfc_get_inst_no_v6,
  1990. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
  1991. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
  1992. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
  1993. .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
  1994. .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
  1995. .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
  1996. .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
  1997. .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
  1998. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
  1999. .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
  2000. .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
  2001. };
  2002. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
  2003. {
  2004. return &s5p_mfc_ops_v6;
  2005. }