s5p_mfc_opr_v6.c 53 KB

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