s5p_mfc_opr_v6.c 55 KB

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