s5p_mfc_opr_v5.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  1. /*
  2. * drivers/media/platform/samsung/mfc5/s5p_mfc_opr_v5.c
  3. *
  4. * Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains hw related functions.
  6. *
  7. * Kamil Debski, Copyright (c) 2011 Samsung Electronics
  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. #include "s5p_mfc_common.h"
  15. #include "s5p_mfc_cmd.h"
  16. #include "s5p_mfc_ctrl.h"
  17. #include "s5p_mfc_debug.h"
  18. #include "s5p_mfc_intr.h"
  19. #include "s5p_mfc_pm.h"
  20. #include "s5p_mfc_opr.h"
  21. #include "s5p_mfc_opr_v5.h"
  22. #include <asm/cacheflush.h>
  23. #include <linux/delay.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/err.h>
  26. #include <linux/firmware.h>
  27. #include <linux/io.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/mm.h>
  30. #include <linux/sched.h>
  31. #define OFFSETA(x) (((x) - dev->bank1) >> MFC_OFFSET_SHIFT)
  32. #define OFFSETB(x) (((x) - dev->bank2) >> MFC_OFFSET_SHIFT)
  33. /* Allocate temporary buffers for decoding */
  34. static int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx)
  35. {
  36. struct s5p_mfc_dev *dev = ctx->dev;
  37. struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv;
  38. int ret;
  39. ctx->dsc.size = buf_size->dsc;
  40. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->dsc);
  41. if (ret) {
  42. mfc_err("Failed to allocate temporary buffer\n");
  43. return ret;
  44. }
  45. BUG_ON(ctx->dsc.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  46. memset(ctx->dsc.virt, 0, ctx->dsc.size);
  47. wmb();
  48. return 0;
  49. }
  50. /* Release temporary buffers for decoding */
  51. static void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx)
  52. {
  53. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->dsc);
  54. }
  55. /* Allocate codec buffers */
  56. static int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
  57. {
  58. struct s5p_mfc_dev *dev = ctx->dev;
  59. unsigned int enc_ref_y_size = 0;
  60. unsigned int enc_ref_c_size = 0;
  61. unsigned int guard_width, guard_height;
  62. int ret;
  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. enc_ref_y_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
  69. * ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN);
  70. enc_ref_y_size = ALIGN(enc_ref_y_size, S5P_FIMV_NV12MT_SALIGN);
  71. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC) {
  72. enc_ref_c_size = ALIGN(ctx->img_width,
  73. S5P_FIMV_NV12MT_HALIGN)
  74. * ALIGN(ctx->img_height >> 1,
  75. S5P_FIMV_NV12MT_VALIGN);
  76. enc_ref_c_size = ALIGN(enc_ref_c_size,
  77. S5P_FIMV_NV12MT_SALIGN);
  78. } else {
  79. guard_width = ALIGN(ctx->img_width + 16,
  80. S5P_FIMV_NV12MT_HALIGN);
  81. guard_height = ALIGN((ctx->img_height >> 1) + 4,
  82. S5P_FIMV_NV12MT_VALIGN);
  83. enc_ref_c_size = ALIGN(guard_width * guard_height,
  84. S5P_FIMV_NV12MT_SALIGN);
  85. }
  86. mfc_debug(2, "recon luma size: %d chroma size: %d\n",
  87. enc_ref_y_size, enc_ref_c_size);
  88. } else {
  89. return -EINVAL;
  90. }
  91. /* Codecs have different memory requirements */
  92. switch (ctx->codec_mode) {
  93. case S5P_MFC_CODEC_H264_DEC:
  94. ctx->bank1.size =
  95. ALIGN(S5P_FIMV_DEC_NB_IP_SIZE +
  96. S5P_FIMV_DEC_VERT_NB_MV_SIZE,
  97. S5P_FIMV_DEC_BUF_ALIGN);
  98. ctx->bank2.size = ctx->total_dpb_count * ctx->mv_size;
  99. break;
  100. case S5P_MFC_CODEC_MPEG4_DEC:
  101. ctx->bank1.size =
  102. ALIGN(S5P_FIMV_DEC_NB_DCAC_SIZE +
  103. S5P_FIMV_DEC_UPNB_MV_SIZE +
  104. S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
  105. S5P_FIMV_DEC_STX_PARSER_SIZE +
  106. S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE,
  107. S5P_FIMV_DEC_BUF_ALIGN);
  108. ctx->bank2.size = 0;
  109. break;
  110. case S5P_MFC_CODEC_VC1RCV_DEC:
  111. case S5P_MFC_CODEC_VC1_DEC:
  112. ctx->bank1.size =
  113. ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE +
  114. S5P_FIMV_DEC_UPNB_MV_SIZE +
  115. S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
  116. S5P_FIMV_DEC_NB_DCAC_SIZE +
  117. 3 * S5P_FIMV_DEC_VC1_BITPLANE_SIZE,
  118. S5P_FIMV_DEC_BUF_ALIGN);
  119. ctx->bank2.size = 0;
  120. break;
  121. case S5P_MFC_CODEC_MPEG2_DEC:
  122. ctx->bank1.size = 0;
  123. ctx->bank2.size = 0;
  124. break;
  125. case S5P_MFC_CODEC_H263_DEC:
  126. ctx->bank1.size =
  127. ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE +
  128. S5P_FIMV_DEC_UPNB_MV_SIZE +
  129. S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
  130. S5P_FIMV_DEC_NB_DCAC_SIZE,
  131. S5P_FIMV_DEC_BUF_ALIGN);
  132. ctx->bank2.size = 0;
  133. break;
  134. case S5P_MFC_CODEC_H264_ENC:
  135. ctx->bank1.size = (enc_ref_y_size * 2) +
  136. S5P_FIMV_ENC_UPMV_SIZE +
  137. S5P_FIMV_ENC_COLFLG_SIZE +
  138. S5P_FIMV_ENC_INTRAMD_SIZE +
  139. S5P_FIMV_ENC_NBORINFO_SIZE;
  140. ctx->bank2.size = (enc_ref_y_size * 2) +
  141. (enc_ref_c_size * 4) +
  142. S5P_FIMV_ENC_INTRAPRED_SIZE;
  143. break;
  144. case S5P_MFC_CODEC_MPEG4_ENC:
  145. ctx->bank1.size = (enc_ref_y_size * 2) +
  146. S5P_FIMV_ENC_UPMV_SIZE +
  147. S5P_FIMV_ENC_COLFLG_SIZE +
  148. S5P_FIMV_ENC_ACDCCOEF_SIZE;
  149. ctx->bank2.size = (enc_ref_y_size * 2) +
  150. (enc_ref_c_size * 4);
  151. break;
  152. case S5P_MFC_CODEC_H263_ENC:
  153. ctx->bank1.size = (enc_ref_y_size * 2) +
  154. S5P_FIMV_ENC_UPMV_SIZE +
  155. S5P_FIMV_ENC_ACDCCOEF_SIZE;
  156. ctx->bank2.size = (enc_ref_y_size * 2) +
  157. (enc_ref_c_size * 4);
  158. break;
  159. default:
  160. break;
  161. }
  162. /* Allocate only if memory from bank 1 is necessary */
  163. if (ctx->bank1.size > 0) {
  164. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
  165. if (ret) {
  166. mfc_err("Failed to allocate Bank1 temporary buffer\n");
  167. return ret;
  168. }
  169. BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  170. }
  171. /* Allocate only if memory from bank 2 is necessary */
  172. if (ctx->bank2.size > 0) {
  173. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, &ctx->bank2);
  174. if (ret) {
  175. mfc_err("Failed to allocate Bank2 temporary buffer\n");
  176. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
  177. return ret;
  178. }
  179. BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1));
  180. }
  181. return 0;
  182. }
  183. /* Release buffers allocated for codec */
  184. static void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
  185. {
  186. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
  187. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_r, &ctx->bank2);
  188. }
  189. /* Allocate memory for instance data buffer */
  190. static int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
  191. {
  192. struct s5p_mfc_dev *dev = ctx->dev;
  193. struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv;
  194. int ret;
  195. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  196. ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  197. ctx->ctx.size = buf_size->h264_ctx;
  198. else
  199. ctx->ctx.size = buf_size->non_h264_ctx;
  200. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
  201. if (ret) {
  202. mfc_err("Failed to allocate instance buffer\n");
  203. return ret;
  204. }
  205. ctx->ctx.ofs = OFFSETA(ctx->ctx.dma);
  206. /* Zero content of the allocated memory */
  207. memset(ctx->ctx.virt, 0, ctx->ctx.size);
  208. wmb();
  209. /* Initialize shared memory */
  210. ctx->shm.size = buf_size->shm;
  211. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->shm);
  212. if (ret) {
  213. mfc_err("Failed to allocate shared memory buffer\n");
  214. s5p_mfc_release_priv_buf(dev->mem_dev_l, &ctx->ctx);
  215. return ret;
  216. }
  217. /* shared memory offset only keeps the offset from base (port a) */
  218. ctx->shm.ofs = ctx->shm.dma - dev->bank1;
  219. BUG_ON(ctx->shm.ofs & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  220. memset(ctx->shm.virt, 0, buf_size->shm);
  221. wmb();
  222. return 0;
  223. }
  224. /* Release instance buffer */
  225. static void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
  226. {
  227. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
  228. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->shm);
  229. }
  230. static int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
  231. {
  232. /* NOP */
  233. return 0;
  234. }
  235. static void s5p_mfc_release_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
  236. {
  237. /* NOP */
  238. }
  239. static void s5p_mfc_write_info_v5(struct s5p_mfc_ctx *ctx, unsigned int data,
  240. unsigned int ofs)
  241. {
  242. writel(data, (void *)(ctx->shm.virt + ofs));
  243. wmb();
  244. }
  245. static unsigned int s5p_mfc_read_info_v5(struct s5p_mfc_ctx *ctx,
  246. unsigned long ofs)
  247. {
  248. rmb();
  249. return readl((void *)(ctx->shm.virt + ofs));
  250. }
  251. static void s5p_mfc_dec_calc_dpb_size_v5(struct s5p_mfc_ctx *ctx)
  252. {
  253. unsigned int guard_width, guard_height;
  254. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN);
  255. ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN);
  256. mfc_debug(2,
  257. "SEQ Done: Movie dimensions %dx%d, buffer dimensions: %dx%d\n",
  258. ctx->img_width, ctx->img_height, ctx->buf_width,
  259. ctx->buf_height);
  260. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC) {
  261. ctx->luma_size = ALIGN(ctx->buf_width * ctx->buf_height,
  262. S5P_FIMV_DEC_BUF_ALIGN);
  263. ctx->chroma_size = ALIGN(ctx->buf_width *
  264. ALIGN((ctx->img_height >> 1),
  265. S5P_FIMV_NV12MT_VALIGN),
  266. S5P_FIMV_DEC_BUF_ALIGN);
  267. ctx->mv_size = ALIGN(ctx->buf_width *
  268. ALIGN((ctx->buf_height >> 2),
  269. S5P_FIMV_NV12MT_VALIGN),
  270. S5P_FIMV_DEC_BUF_ALIGN);
  271. } else {
  272. guard_width =
  273. ALIGN(ctx->img_width + 24, S5P_FIMV_NV12MT_HALIGN);
  274. guard_height =
  275. ALIGN(ctx->img_height + 16, S5P_FIMV_NV12MT_VALIGN);
  276. ctx->luma_size = ALIGN(guard_width * guard_height,
  277. S5P_FIMV_DEC_BUF_ALIGN);
  278. guard_width =
  279. ALIGN(ctx->img_width + 16, S5P_FIMV_NV12MT_HALIGN);
  280. guard_height =
  281. ALIGN((ctx->img_height >> 1) + 4,
  282. S5P_FIMV_NV12MT_VALIGN);
  283. ctx->chroma_size = ALIGN(guard_width * guard_height,
  284. S5P_FIMV_DEC_BUF_ALIGN);
  285. ctx->mv_size = 0;
  286. }
  287. }
  288. static void s5p_mfc_enc_calc_src_size_v5(struct s5p_mfc_ctx *ctx)
  289. {
  290. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
  291. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN);
  292. ctx->luma_size = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN)
  293. * ALIGN(ctx->img_height, S5P_FIMV_NV12M_LVALIGN);
  294. ctx->chroma_size = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN)
  295. * ALIGN((ctx->img_height >> 1), S5P_FIMV_NV12M_CVALIGN);
  296. ctx->luma_size = ALIGN(ctx->luma_size, S5P_FIMV_NV12M_SALIGN);
  297. ctx->chroma_size =
  298. ALIGN(ctx->chroma_size, S5P_FIMV_NV12M_SALIGN);
  299. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT) {
  300. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN);
  301. ctx->luma_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
  302. * ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN);
  303. ctx->chroma_size =
  304. ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
  305. * ALIGN((ctx->img_height >> 1), S5P_FIMV_NV12MT_VALIGN);
  306. ctx->luma_size = ALIGN(ctx->luma_size, S5P_FIMV_NV12MT_SALIGN);
  307. ctx->chroma_size =
  308. ALIGN(ctx->chroma_size, S5P_FIMV_NV12MT_SALIGN);
  309. }
  310. }
  311. /* Set registers for decoding temporary buffers */
  312. static void s5p_mfc_set_dec_desc_buffer(struct s5p_mfc_ctx *ctx)
  313. {
  314. struct s5p_mfc_dev *dev = ctx->dev;
  315. struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv;
  316. mfc_write(dev, OFFSETA(ctx->dsc.dma), S5P_FIMV_SI_CH0_DESC_ADR);
  317. mfc_write(dev, buf_size->dsc, S5P_FIMV_SI_CH0_DESC_SIZE);
  318. }
  319. /* Set registers for shared buffer */
  320. static void s5p_mfc_set_shared_buffer(struct s5p_mfc_ctx *ctx)
  321. {
  322. struct s5p_mfc_dev *dev = ctx->dev;
  323. mfc_write(dev, ctx->shm.ofs, S5P_FIMV_SI_CH0_HOST_WR_ADR);
  324. }
  325. /* Set registers for decoding stream buffer */
  326. static int s5p_mfc_set_dec_stream_buffer_v5(struct s5p_mfc_ctx *ctx,
  327. int buf_addr, unsigned int start_num_byte,
  328. unsigned int buf_size)
  329. {
  330. struct s5p_mfc_dev *dev = ctx->dev;
  331. mfc_write(dev, OFFSETA(buf_addr), S5P_FIMV_SI_CH0_SB_ST_ADR);
  332. mfc_write(dev, ctx->dec_src_buf_size, S5P_FIMV_SI_CH0_CPB_SIZE);
  333. mfc_write(dev, buf_size, S5P_FIMV_SI_CH0_SB_FRM_SIZE);
  334. s5p_mfc_write_info_v5(ctx, start_num_byte, START_BYTE_NUM);
  335. return 0;
  336. }
  337. /* Set decoding frame buffer */
  338. static int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx)
  339. {
  340. unsigned int frame_size_lu, i;
  341. unsigned int frame_size_ch, frame_size_mv;
  342. struct s5p_mfc_dev *dev = ctx->dev;
  343. unsigned int dpb;
  344. size_t buf_addr1, buf_addr2;
  345. int buf_size1, buf_size2;
  346. buf_addr1 = ctx->bank1.dma;
  347. buf_size1 = ctx->bank1.size;
  348. buf_addr2 = ctx->bank2.dma;
  349. buf_size2 = ctx->bank2.size;
  350. dpb = mfc_read(dev, S5P_FIMV_SI_CH0_DPB_CONF_CTRL) &
  351. ~S5P_FIMV_DPB_COUNT_MASK;
  352. mfc_write(dev, ctx->total_dpb_count | dpb,
  353. S5P_FIMV_SI_CH0_DPB_CONF_CTRL);
  354. s5p_mfc_set_shared_buffer(ctx);
  355. switch (ctx->codec_mode) {
  356. case S5P_MFC_CODEC_H264_DEC:
  357. mfc_write(dev, OFFSETA(buf_addr1),
  358. S5P_FIMV_H264_VERT_NB_MV_ADR);
  359. buf_addr1 += S5P_FIMV_DEC_VERT_NB_MV_SIZE;
  360. buf_size1 -= S5P_FIMV_DEC_VERT_NB_MV_SIZE;
  361. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H264_NB_IP_ADR);
  362. buf_addr1 += S5P_FIMV_DEC_NB_IP_SIZE;
  363. buf_size1 -= S5P_FIMV_DEC_NB_IP_SIZE;
  364. break;
  365. case S5P_MFC_CODEC_MPEG4_DEC:
  366. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_NB_DCAC_ADR);
  367. buf_addr1 += S5P_FIMV_DEC_NB_DCAC_SIZE;
  368. buf_size1 -= S5P_FIMV_DEC_NB_DCAC_SIZE;
  369. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_UP_NB_MV_ADR);
  370. buf_addr1 += S5P_FIMV_DEC_UPNB_MV_SIZE;
  371. buf_size1 -= S5P_FIMV_DEC_UPNB_MV_SIZE;
  372. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_SA_MV_ADR);
  373. buf_addr1 += S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  374. buf_size1 -= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  375. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_SP_ADR);
  376. buf_addr1 += S5P_FIMV_DEC_STX_PARSER_SIZE;
  377. buf_size1 -= S5P_FIMV_DEC_STX_PARSER_SIZE;
  378. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_OT_LINE_ADR);
  379. buf_addr1 += S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  380. buf_size1 -= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  381. break;
  382. case S5P_MFC_CODEC_H263_DEC:
  383. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_OT_LINE_ADR);
  384. buf_addr1 += S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  385. buf_size1 -= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  386. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_UP_NB_MV_ADR);
  387. buf_addr1 += S5P_FIMV_DEC_UPNB_MV_SIZE;
  388. buf_size1 -= S5P_FIMV_DEC_UPNB_MV_SIZE;
  389. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_SA_MV_ADR);
  390. buf_addr1 += S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  391. buf_size1 -= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  392. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_NB_DCAC_ADR);
  393. buf_addr1 += S5P_FIMV_DEC_NB_DCAC_SIZE;
  394. buf_size1 -= S5P_FIMV_DEC_NB_DCAC_SIZE;
  395. break;
  396. case S5P_MFC_CODEC_VC1_DEC:
  397. case S5P_MFC_CODEC_VC1RCV_DEC:
  398. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_NB_DCAC_ADR);
  399. buf_addr1 += S5P_FIMV_DEC_NB_DCAC_SIZE;
  400. buf_size1 -= S5P_FIMV_DEC_NB_DCAC_SIZE;
  401. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_OT_LINE_ADR);
  402. buf_addr1 += S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  403. buf_size1 -= S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE;
  404. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_UP_NB_MV_ADR);
  405. buf_addr1 += S5P_FIMV_DEC_UPNB_MV_SIZE;
  406. buf_size1 -= S5P_FIMV_DEC_UPNB_MV_SIZE;
  407. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_SA_MV_ADR);
  408. buf_addr1 += S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  409. buf_size1 -= S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE;
  410. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_BITPLANE3_ADR);
  411. buf_addr1 += S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  412. buf_size1 -= S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  413. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_BITPLANE2_ADR);
  414. buf_addr1 += S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  415. buf_size1 -= S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  416. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_VC1_BITPLANE1_ADR);
  417. buf_addr1 += S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  418. buf_size1 -= S5P_FIMV_DEC_VC1_BITPLANE_SIZE;
  419. break;
  420. case S5P_MFC_CODEC_MPEG2_DEC:
  421. break;
  422. default:
  423. mfc_err("Unknown codec for decoding (%x)\n",
  424. ctx->codec_mode);
  425. return -EINVAL;
  426. }
  427. frame_size_lu = ctx->luma_size;
  428. frame_size_ch = ctx->chroma_size;
  429. frame_size_mv = ctx->mv_size;
  430. mfc_debug(2, "Frm size: %d ch: %d mv: %d\n", frame_size_lu, frame_size_ch,
  431. frame_size_mv);
  432. for (i = 0; i < ctx->total_dpb_count; i++) {
  433. /* Bank2 */
  434. mfc_debug(2, "Luma %d: %zx\n", i,
  435. ctx->dst_bufs[i].cookie.raw.luma);
  436. mfc_write(dev, OFFSETB(ctx->dst_bufs[i].cookie.raw.luma),
  437. S5P_FIMV_DEC_LUMA_ADR + i * 4);
  438. mfc_debug(2, "\tChroma %d: %zx\n", i,
  439. ctx->dst_bufs[i].cookie.raw.chroma);
  440. mfc_write(dev, OFFSETA(ctx->dst_bufs[i].cookie.raw.chroma),
  441. S5P_FIMV_DEC_CHROMA_ADR + i * 4);
  442. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC) {
  443. mfc_debug(2, "\tBuf2: %zx, size: %d\n",
  444. buf_addr2, buf_size2);
  445. mfc_write(dev, OFFSETB(buf_addr2),
  446. S5P_FIMV_H264_MV_ADR + i * 4);
  447. buf_addr2 += frame_size_mv;
  448. buf_size2 -= frame_size_mv;
  449. }
  450. }
  451. mfc_debug(2, "Buf1: %zu, buf_size1: %d\n", buf_addr1, buf_size1);
  452. mfc_debug(2, "Buf 1/2 size after: %d/%d (frames %d)\n",
  453. buf_size1, buf_size2, ctx->total_dpb_count);
  454. if (buf_size1 < 0 || buf_size2 < 0) {
  455. mfc_debug(2, "Not enough memory has been allocated\n");
  456. return -ENOMEM;
  457. }
  458. s5p_mfc_write_info_v5(ctx, frame_size_lu, ALLOC_LUMA_DPB_SIZE);
  459. s5p_mfc_write_info_v5(ctx, frame_size_ch, ALLOC_CHROMA_DPB_SIZE);
  460. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC)
  461. s5p_mfc_write_info_v5(ctx, frame_size_mv, ALLOC_MV_SIZE);
  462. mfc_write(dev, ((S5P_FIMV_CH_INIT_BUFS & S5P_FIMV_CH_MASK)
  463. << S5P_FIMV_CH_SHIFT) | (ctx->inst_no),
  464. S5P_FIMV_SI_CH0_INST_ID);
  465. return 0;
  466. }
  467. /* Set registers for encoding stream buffer */
  468. static int s5p_mfc_set_enc_stream_buffer_v5(struct s5p_mfc_ctx *ctx,
  469. unsigned long addr, unsigned int size)
  470. {
  471. struct s5p_mfc_dev *dev = ctx->dev;
  472. mfc_write(dev, OFFSETA(addr), S5P_FIMV_ENC_SI_CH0_SB_ADR);
  473. mfc_write(dev, size, S5P_FIMV_ENC_SI_CH0_SB_SIZE);
  474. return 0;
  475. }
  476. static void s5p_mfc_set_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
  477. unsigned long y_addr, unsigned long c_addr)
  478. {
  479. struct s5p_mfc_dev *dev = ctx->dev;
  480. mfc_write(dev, OFFSETB(y_addr), S5P_FIMV_ENC_SI_CH0_CUR_Y_ADR);
  481. mfc_write(dev, OFFSETB(c_addr), S5P_FIMV_ENC_SI_CH0_CUR_C_ADR);
  482. }
  483. static void s5p_mfc_get_enc_frame_buffer_v5(struct s5p_mfc_ctx *ctx,
  484. unsigned long *y_addr, unsigned long *c_addr)
  485. {
  486. struct s5p_mfc_dev *dev = ctx->dev;
  487. *y_addr = dev->bank2 + (mfc_read(dev, S5P_FIMV_ENCODED_Y_ADDR)
  488. << MFC_OFFSET_SHIFT);
  489. *c_addr = dev->bank2 + (mfc_read(dev, S5P_FIMV_ENCODED_C_ADDR)
  490. << MFC_OFFSET_SHIFT);
  491. }
  492. /* Set encoding ref & codec buffer */
  493. static int s5p_mfc_set_enc_ref_buffer_v5(struct s5p_mfc_ctx *ctx)
  494. {
  495. struct s5p_mfc_dev *dev = ctx->dev;
  496. size_t buf_addr1, buf_addr2;
  497. size_t buf_size1, buf_size2;
  498. unsigned int enc_ref_y_size, enc_ref_c_size;
  499. unsigned int guard_width, guard_height;
  500. int i;
  501. buf_addr1 = ctx->bank1.dma;
  502. buf_size1 = ctx->bank1.size;
  503. buf_addr2 = ctx->bank2.dma;
  504. buf_size2 = ctx->bank2.size;
  505. enc_ref_y_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
  506. * ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN);
  507. enc_ref_y_size = ALIGN(enc_ref_y_size, S5P_FIMV_NV12MT_SALIGN);
  508. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC) {
  509. enc_ref_c_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
  510. * ALIGN((ctx->img_height >> 1), S5P_FIMV_NV12MT_VALIGN);
  511. enc_ref_c_size = ALIGN(enc_ref_c_size, S5P_FIMV_NV12MT_SALIGN);
  512. } else {
  513. guard_width = ALIGN(ctx->img_width + 16,
  514. S5P_FIMV_NV12MT_HALIGN);
  515. guard_height = ALIGN((ctx->img_height >> 1) + 4,
  516. S5P_FIMV_NV12MT_VALIGN);
  517. enc_ref_c_size = ALIGN(guard_width * guard_height,
  518. S5P_FIMV_NV12MT_SALIGN);
  519. }
  520. mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n", buf_size1, buf_size2);
  521. switch (ctx->codec_mode) {
  522. case S5P_MFC_CODEC_H264_ENC:
  523. for (i = 0; i < 2; i++) {
  524. mfc_write(dev, OFFSETA(buf_addr1),
  525. S5P_FIMV_ENC_REF0_LUMA_ADR + (4 * i));
  526. buf_addr1 += enc_ref_y_size;
  527. buf_size1 -= enc_ref_y_size;
  528. mfc_write(dev, OFFSETB(buf_addr2),
  529. S5P_FIMV_ENC_REF2_LUMA_ADR + (4 * i));
  530. buf_addr2 += enc_ref_y_size;
  531. buf_size2 -= enc_ref_y_size;
  532. }
  533. for (i = 0; i < 4; i++) {
  534. mfc_write(dev, OFFSETB(buf_addr2),
  535. S5P_FIMV_ENC_REF0_CHROMA_ADR + (4 * i));
  536. buf_addr2 += enc_ref_c_size;
  537. buf_size2 -= enc_ref_c_size;
  538. }
  539. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H264_UP_MV_ADR);
  540. buf_addr1 += S5P_FIMV_ENC_UPMV_SIZE;
  541. buf_size1 -= S5P_FIMV_ENC_UPMV_SIZE;
  542. mfc_write(dev, OFFSETA(buf_addr1),
  543. S5P_FIMV_H264_COZERO_FLAG_ADR);
  544. buf_addr1 += S5P_FIMV_ENC_COLFLG_SIZE;
  545. buf_size1 -= S5P_FIMV_ENC_COLFLG_SIZE;
  546. mfc_write(dev, OFFSETA(buf_addr1),
  547. S5P_FIMV_H264_UP_INTRA_MD_ADR);
  548. buf_addr1 += S5P_FIMV_ENC_INTRAMD_SIZE;
  549. buf_size1 -= S5P_FIMV_ENC_INTRAMD_SIZE;
  550. mfc_write(dev, OFFSETB(buf_addr2),
  551. S5P_FIMV_H264_UP_INTRA_PRED_ADR);
  552. buf_addr2 += S5P_FIMV_ENC_INTRAPRED_SIZE;
  553. buf_size2 -= S5P_FIMV_ENC_INTRAPRED_SIZE;
  554. mfc_write(dev, OFFSETA(buf_addr1),
  555. S5P_FIMV_H264_NBOR_INFO_ADR);
  556. buf_addr1 += S5P_FIMV_ENC_NBORINFO_SIZE;
  557. buf_size1 -= S5P_FIMV_ENC_NBORINFO_SIZE;
  558. mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
  559. buf_size1, buf_size2);
  560. break;
  561. case S5P_MFC_CODEC_MPEG4_ENC:
  562. for (i = 0; i < 2; i++) {
  563. mfc_write(dev, OFFSETA(buf_addr1),
  564. S5P_FIMV_ENC_REF0_LUMA_ADR + (4 * i));
  565. buf_addr1 += enc_ref_y_size;
  566. buf_size1 -= enc_ref_y_size;
  567. mfc_write(dev, OFFSETB(buf_addr2),
  568. S5P_FIMV_ENC_REF2_LUMA_ADR + (4 * i));
  569. buf_addr2 += enc_ref_y_size;
  570. buf_size2 -= enc_ref_y_size;
  571. }
  572. for (i = 0; i < 4; i++) {
  573. mfc_write(dev, OFFSETB(buf_addr2),
  574. S5P_FIMV_ENC_REF0_CHROMA_ADR + (4 * i));
  575. buf_addr2 += enc_ref_c_size;
  576. buf_size2 -= enc_ref_c_size;
  577. }
  578. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_MPEG4_UP_MV_ADR);
  579. buf_addr1 += S5P_FIMV_ENC_UPMV_SIZE;
  580. buf_size1 -= S5P_FIMV_ENC_UPMV_SIZE;
  581. mfc_write(dev, OFFSETA(buf_addr1),
  582. S5P_FIMV_MPEG4_COZERO_FLAG_ADR);
  583. buf_addr1 += S5P_FIMV_ENC_COLFLG_SIZE;
  584. buf_size1 -= S5P_FIMV_ENC_COLFLG_SIZE;
  585. mfc_write(dev, OFFSETA(buf_addr1),
  586. S5P_FIMV_MPEG4_ACDC_COEF_ADR);
  587. buf_addr1 += S5P_FIMV_ENC_ACDCCOEF_SIZE;
  588. buf_size1 -= S5P_FIMV_ENC_ACDCCOEF_SIZE;
  589. mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
  590. buf_size1, buf_size2);
  591. break;
  592. case S5P_MFC_CODEC_H263_ENC:
  593. for (i = 0; i < 2; i++) {
  594. mfc_write(dev, OFFSETA(buf_addr1),
  595. S5P_FIMV_ENC_REF0_LUMA_ADR + (4 * i));
  596. buf_addr1 += enc_ref_y_size;
  597. buf_size1 -= enc_ref_y_size;
  598. mfc_write(dev, OFFSETB(buf_addr2),
  599. S5P_FIMV_ENC_REF2_LUMA_ADR + (4 * i));
  600. buf_addr2 += enc_ref_y_size;
  601. buf_size2 -= enc_ref_y_size;
  602. }
  603. for (i = 0; i < 4; i++) {
  604. mfc_write(dev, OFFSETB(buf_addr2),
  605. S5P_FIMV_ENC_REF0_CHROMA_ADR + (4 * i));
  606. buf_addr2 += enc_ref_c_size;
  607. buf_size2 -= enc_ref_c_size;
  608. }
  609. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_UP_MV_ADR);
  610. buf_addr1 += S5P_FIMV_ENC_UPMV_SIZE;
  611. buf_size1 -= S5P_FIMV_ENC_UPMV_SIZE;
  612. mfc_write(dev, OFFSETA(buf_addr1), S5P_FIMV_H263_ACDC_COEF_ADR);
  613. buf_addr1 += S5P_FIMV_ENC_ACDCCOEF_SIZE;
  614. buf_size1 -= S5P_FIMV_ENC_ACDCCOEF_SIZE;
  615. mfc_debug(2, "buf_size1: %zu, buf_size2: %zu\n",
  616. buf_size1, buf_size2);
  617. break;
  618. default:
  619. mfc_err("Unknown codec set for encoding: %d\n",
  620. ctx->codec_mode);
  621. return -EINVAL;
  622. }
  623. return 0;
  624. }
  625. static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
  626. {
  627. struct s5p_mfc_dev *dev = ctx->dev;
  628. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  629. unsigned int reg;
  630. unsigned int shm;
  631. /* width */
  632. mfc_write(dev, ctx->img_width, S5P_FIMV_ENC_HSIZE_PX);
  633. /* height */
  634. mfc_write(dev, ctx->img_height, S5P_FIMV_ENC_VSIZE_PX);
  635. /* pictype : enable, IDR period */
  636. reg = mfc_read(dev, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  637. reg |= (1 << 18);
  638. reg &= ~(0xFFFF);
  639. reg |= p->gop_size;
  640. mfc_write(dev, reg, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  641. mfc_write(dev, 0, S5P_FIMV_ENC_B_RECON_WRITE_ON);
  642. /* multi-slice control */
  643. /* multi-slice MB number or bit size */
  644. mfc_write(dev, p->slice_mode, S5P_FIMV_ENC_MSLICE_CTRL);
  645. if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  646. mfc_write(dev, p->slice_mb, S5P_FIMV_ENC_MSLICE_MB);
  647. } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  648. mfc_write(dev, p->slice_bit, S5P_FIMV_ENC_MSLICE_BIT);
  649. } else {
  650. mfc_write(dev, 0, S5P_FIMV_ENC_MSLICE_MB);
  651. mfc_write(dev, 0, S5P_FIMV_ENC_MSLICE_BIT);
  652. }
  653. /* cyclic intra refresh */
  654. mfc_write(dev, p->intra_refresh_mb, S5P_FIMV_ENC_CIR_CTRL);
  655. /* memory structure cur. frame */
  656. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M)
  657. mfc_write(dev, 0, S5P_FIMV_ENC_MAP_FOR_CUR);
  658. else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT)
  659. mfc_write(dev, 3, S5P_FIMV_ENC_MAP_FOR_CUR);
  660. /* padding control & value */
  661. reg = mfc_read(dev, S5P_FIMV_ENC_PADDING_CTRL);
  662. if (p->pad) {
  663. /** enable */
  664. reg |= (1 << 31);
  665. /** cr value */
  666. reg &= ~(0xFF << 16);
  667. reg |= (p->pad_cr << 16);
  668. /** cb value */
  669. reg &= ~(0xFF << 8);
  670. reg |= (p->pad_cb << 8);
  671. /** y value */
  672. reg &= ~(0xFF);
  673. reg |= (p->pad_luma);
  674. } else {
  675. /** disable & all value clear */
  676. reg = 0;
  677. }
  678. mfc_write(dev, reg, S5P_FIMV_ENC_PADDING_CTRL);
  679. /* rate control config. */
  680. reg = mfc_read(dev, S5P_FIMV_ENC_RC_CONFIG);
  681. /** frame-level rate control */
  682. reg &= ~(0x1 << 9);
  683. reg |= (p->rc_frame << 9);
  684. mfc_write(dev, reg, S5P_FIMV_ENC_RC_CONFIG);
  685. /* bit rate */
  686. if (p->rc_frame)
  687. mfc_write(dev, p->rc_bitrate,
  688. S5P_FIMV_ENC_RC_BIT_RATE);
  689. else
  690. mfc_write(dev, 0, S5P_FIMV_ENC_RC_BIT_RATE);
  691. /* reaction coefficient */
  692. if (p->rc_frame)
  693. mfc_write(dev, p->rc_reaction_coeff, S5P_FIMV_ENC_RC_RPARA);
  694. shm = s5p_mfc_read_info_v5(ctx, EXT_ENC_CONTROL);
  695. /* seq header ctrl */
  696. shm &= ~(0x1 << 3);
  697. shm |= (p->seq_hdr_mode << 3);
  698. /* frame skip mode */
  699. shm &= ~(0x3 << 1);
  700. shm |= (p->frame_skip_mode << 1);
  701. s5p_mfc_write_info_v5(ctx, shm, EXT_ENC_CONTROL);
  702. /* fixed target bit */
  703. s5p_mfc_write_info_v5(ctx, p->fixed_target_bit, RC_CONTROL_CONFIG);
  704. return 0;
  705. }
  706. static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
  707. {
  708. struct s5p_mfc_dev *dev = ctx->dev;
  709. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  710. struct s5p_mfc_h264_enc_params *p_264 = &p->codec.h264;
  711. unsigned int reg;
  712. unsigned int shm;
  713. s5p_mfc_set_enc_params(ctx);
  714. /* pictype : number of B */
  715. reg = mfc_read(dev, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  716. /* num_b_frame - 0 ~ 2 */
  717. reg &= ~(0x3 << 16);
  718. reg |= (p->num_b_frame << 16);
  719. mfc_write(dev, reg, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  720. /* profile & level */
  721. reg = mfc_read(dev, S5P_FIMV_ENC_PROFILE);
  722. /* level */
  723. reg &= ~(0xFF << 8);
  724. reg |= (p_264->level << 8);
  725. /* profile - 0 ~ 2 */
  726. reg &= ~(0x3F);
  727. reg |= p_264->profile;
  728. mfc_write(dev, reg, S5P_FIMV_ENC_PROFILE);
  729. /* interlace */
  730. mfc_write(dev, p_264->interlace, S5P_FIMV_ENC_PIC_STRUCT);
  731. /* height */
  732. if (p_264->interlace)
  733. mfc_write(dev, ctx->img_height >> 1, S5P_FIMV_ENC_VSIZE_PX);
  734. /* loopfilter ctrl */
  735. mfc_write(dev, p_264->loop_filter_mode, S5P_FIMV_ENC_LF_CTRL);
  736. /* loopfilter alpha offset */
  737. if (p_264->loop_filter_alpha < 0) {
  738. reg = 0x10;
  739. reg |= (0xFF - p_264->loop_filter_alpha) + 1;
  740. } else {
  741. reg = 0x00;
  742. reg |= (p_264->loop_filter_alpha & 0xF);
  743. }
  744. mfc_write(dev, reg, S5P_FIMV_ENC_ALPHA_OFF);
  745. /* loopfilter beta offset */
  746. if (p_264->loop_filter_beta < 0) {
  747. reg = 0x10;
  748. reg |= (0xFF - p_264->loop_filter_beta) + 1;
  749. } else {
  750. reg = 0x00;
  751. reg |= (p_264->loop_filter_beta & 0xF);
  752. }
  753. mfc_write(dev, reg, S5P_FIMV_ENC_BETA_OFF);
  754. /* entropy coding mode */
  755. if (p_264->entropy_mode == V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC)
  756. mfc_write(dev, 1, S5P_FIMV_ENC_H264_ENTROPY_MODE);
  757. else
  758. mfc_write(dev, 0, S5P_FIMV_ENC_H264_ENTROPY_MODE);
  759. /* number of ref. picture */
  760. reg = mfc_read(dev, S5P_FIMV_ENC_H264_NUM_OF_REF);
  761. /* num of ref. pictures of P */
  762. reg &= ~(0x3 << 5);
  763. reg |= (p_264->num_ref_pic_4p << 5);
  764. /* max number of ref. pictures */
  765. reg &= ~(0x1F);
  766. reg |= p_264->max_ref_pic;
  767. mfc_write(dev, reg, S5P_FIMV_ENC_H264_NUM_OF_REF);
  768. /* 8x8 transform enable */
  769. mfc_write(dev, p_264->_8x8_transform, S5P_FIMV_ENC_H264_TRANS_FLAG);
  770. /* rate control config. */
  771. reg = mfc_read(dev, S5P_FIMV_ENC_RC_CONFIG);
  772. /* macroblock level rate control */
  773. reg &= ~(0x1 << 8);
  774. reg |= (p->rc_mb << 8);
  775. /* frame QP */
  776. reg &= ~(0x3F);
  777. reg |= p_264->rc_frame_qp;
  778. mfc_write(dev, reg, S5P_FIMV_ENC_RC_CONFIG);
  779. /* frame rate */
  780. if (p->rc_frame && p->rc_framerate_denom)
  781. mfc_write(dev, p->rc_framerate_num * 1000
  782. / p->rc_framerate_denom, S5P_FIMV_ENC_RC_FRAME_RATE);
  783. else
  784. mfc_write(dev, 0, S5P_FIMV_ENC_RC_FRAME_RATE);
  785. /* max & min value of QP */
  786. reg = mfc_read(dev, S5P_FIMV_ENC_RC_QBOUND);
  787. /* max QP */
  788. reg &= ~(0x3F << 8);
  789. reg |= (p_264->rc_max_qp << 8);
  790. /* min QP */
  791. reg &= ~(0x3F);
  792. reg |= p_264->rc_min_qp;
  793. mfc_write(dev, reg, S5P_FIMV_ENC_RC_QBOUND);
  794. /* macroblock adaptive scaling features */
  795. if (p->rc_mb) {
  796. reg = mfc_read(dev, S5P_FIMV_ENC_RC_MB_CTRL);
  797. /* dark region */
  798. reg &= ~(0x1 << 3);
  799. reg |= (p_264->rc_mb_dark << 3);
  800. /* smooth region */
  801. reg &= ~(0x1 << 2);
  802. reg |= (p_264->rc_mb_smooth << 2);
  803. /* static region */
  804. reg &= ~(0x1 << 1);
  805. reg |= (p_264->rc_mb_static << 1);
  806. /* high activity region */
  807. reg &= ~(0x1);
  808. reg |= p_264->rc_mb_activity;
  809. mfc_write(dev, reg, S5P_FIMV_ENC_RC_MB_CTRL);
  810. }
  811. if (!p->rc_frame && !p->rc_mb) {
  812. shm = s5p_mfc_read_info_v5(ctx, P_B_FRAME_QP);
  813. shm &= ~(0xFFF);
  814. shm |= ((p_264->rc_b_frame_qp & 0x3F) << 6);
  815. shm |= (p_264->rc_p_frame_qp & 0x3F);
  816. s5p_mfc_write_info_v5(ctx, shm, P_B_FRAME_QP);
  817. }
  818. /* extended encoder ctrl */
  819. shm = s5p_mfc_read_info_v5(ctx, EXT_ENC_CONTROL);
  820. /* AR VUI control */
  821. shm &= ~(0x1 << 15);
  822. shm |= (p_264->vui_sar << 1);
  823. s5p_mfc_write_info_v5(ctx, shm, EXT_ENC_CONTROL);
  824. if (p_264->vui_sar) {
  825. /* aspect ration IDC */
  826. shm = s5p_mfc_read_info_v5(ctx, SAMPLE_ASPECT_RATIO_IDC);
  827. shm &= ~(0xFF);
  828. shm |= p_264->vui_sar_idc;
  829. s5p_mfc_write_info_v5(ctx, shm, SAMPLE_ASPECT_RATIO_IDC);
  830. if (p_264->vui_sar_idc == 0xFF) {
  831. /* sample AR info */
  832. shm = s5p_mfc_read_info_v5(ctx, EXTENDED_SAR);
  833. shm &= ~(0xFFFFFFFF);
  834. shm |= p_264->vui_ext_sar_width << 16;
  835. shm |= p_264->vui_ext_sar_height;
  836. s5p_mfc_write_info_v5(ctx, shm, EXTENDED_SAR);
  837. }
  838. }
  839. /* intra picture period for H.264 */
  840. shm = s5p_mfc_read_info_v5(ctx, H264_I_PERIOD);
  841. /* control */
  842. shm &= ~(0x1 << 16);
  843. shm |= (p_264->open_gop << 16);
  844. /* value */
  845. if (p_264->open_gop) {
  846. shm &= ~(0xFFFF);
  847. shm |= p_264->open_gop_size;
  848. }
  849. s5p_mfc_write_info_v5(ctx, shm, H264_I_PERIOD);
  850. /* extended encoder ctrl */
  851. shm = s5p_mfc_read_info_v5(ctx, EXT_ENC_CONTROL);
  852. /* vbv buffer size */
  853. if (p->frame_skip_mode ==
  854. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  855. shm &= ~(0xFFFF << 16);
  856. shm |= (p_264->cpb_size << 16);
  857. }
  858. s5p_mfc_write_info_v5(ctx, shm, EXT_ENC_CONTROL);
  859. return 0;
  860. }
  861. static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
  862. {
  863. struct s5p_mfc_dev *dev = ctx->dev;
  864. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  865. struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
  866. unsigned int reg;
  867. unsigned int shm;
  868. unsigned int framerate;
  869. s5p_mfc_set_enc_params(ctx);
  870. /* pictype : number of B */
  871. reg = mfc_read(dev, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  872. /* num_b_frame - 0 ~ 2 */
  873. reg &= ~(0x3 << 16);
  874. reg |= (p->num_b_frame << 16);
  875. mfc_write(dev, reg, S5P_FIMV_ENC_PIC_TYPE_CTRL);
  876. /* profile & level */
  877. reg = mfc_read(dev, S5P_FIMV_ENC_PROFILE);
  878. /* level */
  879. reg &= ~(0xFF << 8);
  880. reg |= (p_mpeg4->level << 8);
  881. /* profile - 0 ~ 2 */
  882. reg &= ~(0x3F);
  883. reg |= p_mpeg4->profile;
  884. mfc_write(dev, reg, S5P_FIMV_ENC_PROFILE);
  885. /* quarter_pixel */
  886. mfc_write(dev, p_mpeg4->quarter_pixel, S5P_FIMV_ENC_MPEG4_QUART_PXL);
  887. /* qp */
  888. if (!p->rc_frame) {
  889. shm = s5p_mfc_read_info_v5(ctx, P_B_FRAME_QP);
  890. shm &= ~(0xFFF);
  891. shm |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 6);
  892. shm |= (p_mpeg4->rc_p_frame_qp & 0x3F);
  893. s5p_mfc_write_info_v5(ctx, shm, P_B_FRAME_QP);
  894. }
  895. /* frame rate */
  896. if (p->rc_frame) {
  897. if (p->rc_framerate_denom > 0) {
  898. framerate = p->rc_framerate_num * 1000 /
  899. p->rc_framerate_denom;
  900. mfc_write(dev, framerate,
  901. S5P_FIMV_ENC_RC_FRAME_RATE);
  902. shm = s5p_mfc_read_info_v5(ctx, RC_VOP_TIMING);
  903. shm &= ~(0xFFFFFFFF);
  904. shm |= (1 << 31);
  905. shm |= ((p->rc_framerate_num & 0x7FFF) << 16);
  906. shm |= (p->rc_framerate_denom & 0xFFFF);
  907. s5p_mfc_write_info_v5(ctx, shm, RC_VOP_TIMING);
  908. }
  909. } else {
  910. mfc_write(dev, 0, S5P_FIMV_ENC_RC_FRAME_RATE);
  911. }
  912. /* rate control config. */
  913. reg = mfc_read(dev, S5P_FIMV_ENC_RC_CONFIG);
  914. /* frame QP */
  915. reg &= ~(0x3F);
  916. reg |= p_mpeg4->rc_frame_qp;
  917. mfc_write(dev, reg, S5P_FIMV_ENC_RC_CONFIG);
  918. /* max & min value of QP */
  919. reg = mfc_read(dev, S5P_FIMV_ENC_RC_QBOUND);
  920. /* max QP */
  921. reg &= ~(0x3F << 8);
  922. reg |= (p_mpeg4->rc_max_qp << 8);
  923. /* min QP */
  924. reg &= ~(0x3F);
  925. reg |= p_mpeg4->rc_min_qp;
  926. mfc_write(dev, reg, S5P_FIMV_ENC_RC_QBOUND);
  927. /* extended encoder ctrl */
  928. shm = s5p_mfc_read_info_v5(ctx, EXT_ENC_CONTROL);
  929. /* vbv buffer size */
  930. if (p->frame_skip_mode ==
  931. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  932. shm &= ~(0xFFFF << 16);
  933. shm |= (p->vbv_size << 16);
  934. }
  935. s5p_mfc_write_info_v5(ctx, shm, EXT_ENC_CONTROL);
  936. return 0;
  937. }
  938. static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
  939. {
  940. struct s5p_mfc_dev *dev = ctx->dev;
  941. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  942. struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
  943. unsigned int reg;
  944. unsigned int shm;
  945. s5p_mfc_set_enc_params(ctx);
  946. /* qp */
  947. if (!p->rc_frame) {
  948. shm = s5p_mfc_read_info_v5(ctx, P_B_FRAME_QP);
  949. shm &= ~(0xFFF);
  950. shm |= (p_h263->rc_p_frame_qp & 0x3F);
  951. s5p_mfc_write_info_v5(ctx, shm, P_B_FRAME_QP);
  952. }
  953. /* frame rate */
  954. if (p->rc_frame && p->rc_framerate_denom)
  955. mfc_write(dev, p->rc_framerate_num * 1000
  956. / p->rc_framerate_denom, S5P_FIMV_ENC_RC_FRAME_RATE);
  957. else
  958. mfc_write(dev, 0, S5P_FIMV_ENC_RC_FRAME_RATE);
  959. /* rate control config. */
  960. reg = mfc_read(dev, S5P_FIMV_ENC_RC_CONFIG);
  961. /* frame QP */
  962. reg &= ~(0x3F);
  963. reg |= p_h263->rc_frame_qp;
  964. mfc_write(dev, reg, S5P_FIMV_ENC_RC_CONFIG);
  965. /* max & min value of QP */
  966. reg = mfc_read(dev, S5P_FIMV_ENC_RC_QBOUND);
  967. /* max QP */
  968. reg &= ~(0x3F << 8);
  969. reg |= (p_h263->rc_max_qp << 8);
  970. /* min QP */
  971. reg &= ~(0x3F);
  972. reg |= p_h263->rc_min_qp;
  973. mfc_write(dev, reg, S5P_FIMV_ENC_RC_QBOUND);
  974. /* extended encoder ctrl */
  975. shm = s5p_mfc_read_info_v5(ctx, EXT_ENC_CONTROL);
  976. /* vbv buffer size */
  977. if (p->frame_skip_mode ==
  978. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  979. shm &= ~(0xFFFF << 16);
  980. shm |= (p->vbv_size << 16);
  981. }
  982. s5p_mfc_write_info_v5(ctx, shm, EXT_ENC_CONTROL);
  983. return 0;
  984. }
  985. /* Initialize decoding */
  986. static int s5p_mfc_init_decode_v5(struct s5p_mfc_ctx *ctx)
  987. {
  988. struct s5p_mfc_dev *dev = ctx->dev;
  989. s5p_mfc_set_shared_buffer(ctx);
  990. /* Setup loop filter, for decoding this is only valid for MPEG4 */
  991. if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC)
  992. mfc_write(dev, ctx->loop_filter_mpeg4, S5P_FIMV_ENC_LF_CTRL);
  993. else
  994. mfc_write(dev, 0, S5P_FIMV_ENC_LF_CTRL);
  995. mfc_write(dev, ((ctx->slice_interface & S5P_FIMV_SLICE_INT_MASK) <<
  996. S5P_FIMV_SLICE_INT_SHIFT) | (ctx->display_delay_enable <<
  997. S5P_FIMV_DDELAY_ENA_SHIFT) | ((ctx->display_delay &
  998. S5P_FIMV_DDELAY_VAL_MASK) << S5P_FIMV_DDELAY_VAL_SHIFT),
  999. S5P_FIMV_SI_CH0_DPB_CONF_CTRL);
  1000. mfc_write(dev,
  1001. ((S5P_FIMV_CH_SEQ_HEADER & S5P_FIMV_CH_MASK) << S5P_FIMV_CH_SHIFT)
  1002. | (ctx->inst_no), S5P_FIMV_SI_CH0_INST_ID);
  1003. return 0;
  1004. }
  1005. static void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
  1006. {
  1007. struct s5p_mfc_dev *dev = ctx->dev;
  1008. unsigned int dpb;
  1009. if (flush)
  1010. dpb = mfc_read(dev, S5P_FIMV_SI_CH0_DPB_CONF_CTRL) | (
  1011. S5P_FIMV_DPB_FLUSH_MASK << S5P_FIMV_DPB_FLUSH_SHIFT);
  1012. else
  1013. dpb = mfc_read(dev, S5P_FIMV_SI_CH0_DPB_CONF_CTRL) &
  1014. ~(S5P_FIMV_DPB_FLUSH_MASK << S5P_FIMV_DPB_FLUSH_SHIFT);
  1015. mfc_write(dev, dpb, S5P_FIMV_SI_CH0_DPB_CONF_CTRL);
  1016. }
  1017. /* Decode a single frame */
  1018. static int s5p_mfc_decode_one_frame_v5(struct s5p_mfc_ctx *ctx,
  1019. enum s5p_mfc_decode_arg last_frame)
  1020. {
  1021. struct s5p_mfc_dev *dev = ctx->dev;
  1022. mfc_write(dev, ctx->dec_dst_flag, S5P_FIMV_SI_CH0_RELEASE_BUF);
  1023. s5p_mfc_set_shared_buffer(ctx);
  1024. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  1025. /* Issue different commands to instance basing on whether it
  1026. * is the last frame or not. */
  1027. switch (last_frame) {
  1028. case MFC_DEC_FRAME:
  1029. mfc_write(dev, ((S5P_FIMV_CH_FRAME_START & S5P_FIMV_CH_MASK) <<
  1030. S5P_FIMV_CH_SHIFT) | (ctx->inst_no), S5P_FIMV_SI_CH0_INST_ID);
  1031. break;
  1032. case MFC_DEC_LAST_FRAME:
  1033. mfc_write(dev, ((S5P_FIMV_CH_LAST_FRAME & S5P_FIMV_CH_MASK) <<
  1034. S5P_FIMV_CH_SHIFT) | (ctx->inst_no), S5P_FIMV_SI_CH0_INST_ID);
  1035. break;
  1036. case MFC_DEC_RES_CHANGE:
  1037. mfc_write(dev, ((S5P_FIMV_CH_FRAME_START_REALLOC &
  1038. S5P_FIMV_CH_MASK) << S5P_FIMV_CH_SHIFT) | (ctx->inst_no),
  1039. S5P_FIMV_SI_CH0_INST_ID);
  1040. break;
  1041. }
  1042. mfc_debug(2, "Decoding a usual frame\n");
  1043. return 0;
  1044. }
  1045. static int s5p_mfc_init_encode_v5(struct s5p_mfc_ctx *ctx)
  1046. {
  1047. struct s5p_mfc_dev *dev = ctx->dev;
  1048. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1049. s5p_mfc_set_enc_params_h264(ctx);
  1050. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1051. s5p_mfc_set_enc_params_mpeg4(ctx);
  1052. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1053. s5p_mfc_set_enc_params_h263(ctx);
  1054. else {
  1055. mfc_err("Unknown codec for encoding (%x)\n",
  1056. ctx->codec_mode);
  1057. return -EINVAL;
  1058. }
  1059. s5p_mfc_set_shared_buffer(ctx);
  1060. mfc_write(dev, ((S5P_FIMV_CH_SEQ_HEADER << 16) & 0x70000) |
  1061. (ctx->inst_no), S5P_FIMV_SI_CH0_INST_ID);
  1062. return 0;
  1063. }
  1064. /* Encode a single frame */
  1065. static int s5p_mfc_encode_one_frame_v5(struct s5p_mfc_ctx *ctx)
  1066. {
  1067. struct s5p_mfc_dev *dev = ctx->dev;
  1068. int cmd;
  1069. /* memory structure cur. frame */
  1070. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M)
  1071. mfc_write(dev, 0, S5P_FIMV_ENC_MAP_FOR_CUR);
  1072. else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT)
  1073. mfc_write(dev, 3, S5P_FIMV_ENC_MAP_FOR_CUR);
  1074. s5p_mfc_set_shared_buffer(ctx);
  1075. if (ctx->state == MFCINST_FINISHING)
  1076. cmd = S5P_FIMV_CH_LAST_FRAME;
  1077. else
  1078. cmd = S5P_FIMV_CH_FRAME_START;
  1079. mfc_write(dev, ((cmd & S5P_FIMV_CH_MASK) << S5P_FIMV_CH_SHIFT)
  1080. | (ctx->inst_no), S5P_FIMV_SI_CH0_INST_ID);
  1081. return 0;
  1082. }
  1083. static int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
  1084. {
  1085. unsigned long flags;
  1086. int new_ctx;
  1087. int cnt;
  1088. spin_lock_irqsave(&dev->condlock, flags);
  1089. new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
  1090. cnt = 0;
  1091. while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
  1092. new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
  1093. if (++cnt > MFC_NUM_CONTEXTS) {
  1094. /* No contexts to run */
  1095. spin_unlock_irqrestore(&dev->condlock, flags);
  1096. return -EAGAIN;
  1097. }
  1098. }
  1099. spin_unlock_irqrestore(&dev->condlock, flags);
  1100. return new_ctx;
  1101. }
  1102. static void s5p_mfc_run_res_change(struct s5p_mfc_ctx *ctx)
  1103. {
  1104. struct s5p_mfc_dev *dev = ctx->dev;
  1105. s5p_mfc_set_dec_stream_buffer_v5(ctx, 0, 0, 0);
  1106. dev->curr_ctx = ctx->num;
  1107. s5p_mfc_decode_one_frame_v5(ctx, MFC_DEC_RES_CHANGE);
  1108. }
  1109. static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx, int last_frame)
  1110. {
  1111. struct s5p_mfc_dev *dev = ctx->dev;
  1112. struct s5p_mfc_buf *temp_vb;
  1113. unsigned long flags;
  1114. if (ctx->state == MFCINST_FINISHING) {
  1115. last_frame = MFC_DEC_LAST_FRAME;
  1116. s5p_mfc_set_dec_stream_buffer_v5(ctx, 0, 0, 0);
  1117. dev->curr_ctx = ctx->num;
  1118. s5p_mfc_decode_one_frame_v5(ctx, last_frame);
  1119. return 0;
  1120. }
  1121. spin_lock_irqsave(&dev->irqlock, flags);
  1122. /* Frames are being decoded */
  1123. if (list_empty(&ctx->src_queue)) {
  1124. mfc_debug(2, "No src buffers\n");
  1125. spin_unlock_irqrestore(&dev->irqlock, flags);
  1126. return -EAGAIN;
  1127. }
  1128. /* Get the next source buffer */
  1129. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1130. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1131. s5p_mfc_set_dec_stream_buffer_v5(ctx,
  1132. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1133. ctx->consumed_stream, temp_vb->b->v4l2_planes[0].bytesused);
  1134. spin_unlock_irqrestore(&dev->irqlock, flags);
  1135. dev->curr_ctx = ctx->num;
  1136. if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
  1137. last_frame = MFC_DEC_LAST_FRAME;
  1138. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1139. ctx->state = MFCINST_FINISHING;
  1140. }
  1141. s5p_mfc_decode_one_frame_v5(ctx, last_frame);
  1142. return 0;
  1143. }
  1144. static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1145. {
  1146. struct s5p_mfc_dev *dev = ctx->dev;
  1147. unsigned long flags;
  1148. struct s5p_mfc_buf *dst_mb;
  1149. struct s5p_mfc_buf *src_mb;
  1150. unsigned long src_y_addr, src_c_addr, dst_addr;
  1151. unsigned int dst_size;
  1152. spin_lock_irqsave(&dev->irqlock, flags);
  1153. if (list_empty(&ctx->src_queue) && ctx->state != MFCINST_FINISHING) {
  1154. mfc_debug(2, "no src buffers\n");
  1155. spin_unlock_irqrestore(&dev->irqlock, flags);
  1156. return -EAGAIN;
  1157. }
  1158. if (list_empty(&ctx->dst_queue)) {
  1159. mfc_debug(2, "no dst buffers\n");
  1160. spin_unlock_irqrestore(&dev->irqlock, flags);
  1161. return -EAGAIN;
  1162. }
  1163. if (list_empty(&ctx->src_queue)) {
  1164. /* send null frame */
  1165. s5p_mfc_set_enc_frame_buffer_v5(ctx, dev->bank2, dev->bank2);
  1166. src_mb = NULL;
  1167. } else {
  1168. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
  1169. list);
  1170. src_mb->flags |= MFC_BUF_FLAG_USED;
  1171. if (src_mb->b->v4l2_planes[0].bytesused == 0) {
  1172. /* send null frame */
  1173. s5p_mfc_set_enc_frame_buffer_v5(ctx, dev->bank2,
  1174. dev->bank2);
  1175. ctx->state = MFCINST_FINISHING;
  1176. } else {
  1177. src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b,
  1178. 0);
  1179. src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b,
  1180. 1);
  1181. s5p_mfc_set_enc_frame_buffer_v5(ctx, src_y_addr,
  1182. src_c_addr);
  1183. if (src_mb->flags & MFC_BUF_FLAG_EOS)
  1184. ctx->state = MFCINST_FINISHING;
  1185. }
  1186. }
  1187. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1188. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1189. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1190. dst_size = vb2_plane_size(dst_mb->b, 0);
  1191. s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
  1192. spin_unlock_irqrestore(&dev->irqlock, flags);
  1193. dev->curr_ctx = ctx->num;
  1194. mfc_debug(2, "encoding buffer with index=%d state=%d\n",
  1195. src_mb ? src_mb->b->v4l2_buf.index : -1, ctx->state);
  1196. s5p_mfc_encode_one_frame_v5(ctx);
  1197. return 0;
  1198. }
  1199. static void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1200. {
  1201. struct s5p_mfc_dev *dev = ctx->dev;
  1202. unsigned long flags;
  1203. struct s5p_mfc_buf *temp_vb;
  1204. /* Initializing decoding - parsing header */
  1205. spin_lock_irqsave(&dev->irqlock, flags);
  1206. mfc_debug(2, "Preparing to init decoding\n");
  1207. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1208. s5p_mfc_set_dec_desc_buffer(ctx);
  1209. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1210. s5p_mfc_set_dec_stream_buffer_v5(ctx,
  1211. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1212. 0, temp_vb->b->v4l2_planes[0].bytesused);
  1213. spin_unlock_irqrestore(&dev->irqlock, flags);
  1214. dev->curr_ctx = ctx->num;
  1215. s5p_mfc_init_decode_v5(ctx);
  1216. }
  1217. static void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1218. {
  1219. struct s5p_mfc_dev *dev = ctx->dev;
  1220. unsigned long flags;
  1221. struct s5p_mfc_buf *dst_mb;
  1222. unsigned long dst_addr;
  1223. unsigned int dst_size;
  1224. s5p_mfc_set_enc_ref_buffer_v5(ctx);
  1225. spin_lock_irqsave(&dev->irqlock, flags);
  1226. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1227. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1228. dst_size = vb2_plane_size(dst_mb->b, 0);
  1229. s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
  1230. spin_unlock_irqrestore(&dev->irqlock, flags);
  1231. dev->curr_ctx = ctx->num;
  1232. s5p_mfc_init_encode_v5(ctx);
  1233. }
  1234. static int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1235. {
  1236. struct s5p_mfc_dev *dev = ctx->dev;
  1237. unsigned long flags;
  1238. struct s5p_mfc_buf *temp_vb;
  1239. int ret;
  1240. /*
  1241. * Header was parsed now starting processing
  1242. * First set the output frame buffers
  1243. */
  1244. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1245. mfc_err("It seems that not all destionation buffers were "
  1246. "mmaped\nMFC requires that all destination are mmaped "
  1247. "before starting processing\n");
  1248. return -EAGAIN;
  1249. }
  1250. spin_lock_irqsave(&dev->irqlock, flags);
  1251. if (list_empty(&ctx->src_queue)) {
  1252. mfc_err("Header has been deallocated in the middle of"
  1253. " initialization\n");
  1254. spin_unlock_irqrestore(&dev->irqlock, flags);
  1255. return -EIO;
  1256. }
  1257. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1258. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1259. s5p_mfc_set_dec_stream_buffer_v5(ctx,
  1260. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1261. 0, temp_vb->b->v4l2_planes[0].bytesused);
  1262. spin_unlock_irqrestore(&dev->irqlock, flags);
  1263. dev->curr_ctx = ctx->num;
  1264. ret = s5p_mfc_set_dec_frame_buffer_v5(ctx);
  1265. if (ret) {
  1266. mfc_err("Failed to alloc frame mem\n");
  1267. ctx->state = MFCINST_ERROR;
  1268. }
  1269. return ret;
  1270. }
  1271. /* Try running an operation on hardware */
  1272. static void s5p_mfc_try_run_v5(struct s5p_mfc_dev *dev)
  1273. {
  1274. struct s5p_mfc_ctx *ctx;
  1275. int new_ctx;
  1276. unsigned int ret = 0;
  1277. if (test_bit(0, &dev->enter_suspend)) {
  1278. mfc_debug(1, "Entering suspend so do not schedule any jobs\n");
  1279. return;
  1280. }
  1281. /* Check whether hardware is not running */
  1282. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1283. /* This is perfectly ok, the scheduled ctx should wait */
  1284. mfc_debug(1, "Couldn't lock HW\n");
  1285. return;
  1286. }
  1287. /* Choose the context to run */
  1288. new_ctx = s5p_mfc_get_new_ctx(dev);
  1289. if (new_ctx < 0) {
  1290. /* No contexts to run */
  1291. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1292. mfc_err("Failed to unlock hardware\n");
  1293. return;
  1294. }
  1295. mfc_debug(1, "No ctx is scheduled to be run\n");
  1296. return;
  1297. }
  1298. ctx = dev->ctx[new_ctx];
  1299. /* Got context to run in ctx */
  1300. /*
  1301. * Last frame has already been sent to MFC.
  1302. * Now obtaining frames from MFC buffer
  1303. */
  1304. s5p_mfc_clock_on();
  1305. s5p_mfc_clean_ctx_int_flags(ctx);
  1306. if (ctx->type == MFCINST_DECODER) {
  1307. s5p_mfc_set_dec_desc_buffer(ctx);
  1308. switch (ctx->state) {
  1309. case MFCINST_FINISHING:
  1310. s5p_mfc_run_dec_frame(ctx, MFC_DEC_LAST_FRAME);
  1311. break;
  1312. case MFCINST_RUNNING:
  1313. ret = s5p_mfc_run_dec_frame(ctx, MFC_DEC_FRAME);
  1314. break;
  1315. case MFCINST_INIT:
  1316. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1317. ctx);
  1318. break;
  1319. case MFCINST_RETURN_INST:
  1320. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1321. ctx);
  1322. break;
  1323. case MFCINST_GOT_INST:
  1324. s5p_mfc_run_init_dec(ctx);
  1325. break;
  1326. case MFCINST_HEAD_PARSED:
  1327. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1328. mfc_debug(1, "head parsed\n");
  1329. break;
  1330. case MFCINST_RES_CHANGE_INIT:
  1331. s5p_mfc_run_res_change(ctx);
  1332. break;
  1333. case MFCINST_RES_CHANGE_FLUSH:
  1334. s5p_mfc_run_dec_frame(ctx, MFC_DEC_FRAME);
  1335. break;
  1336. case MFCINST_RES_CHANGE_END:
  1337. mfc_debug(2, "Finished remaining frames after resolution change\n");
  1338. ctx->capture_state = QUEUE_FREE;
  1339. mfc_debug(2, "Will re-init the codec\n");
  1340. s5p_mfc_run_init_dec(ctx);
  1341. break;
  1342. default:
  1343. ret = -EAGAIN;
  1344. }
  1345. } else if (ctx->type == MFCINST_ENCODER) {
  1346. switch (ctx->state) {
  1347. case MFCINST_FINISHING:
  1348. case MFCINST_RUNNING:
  1349. ret = s5p_mfc_run_enc_frame(ctx);
  1350. break;
  1351. case MFCINST_INIT:
  1352. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1353. ctx);
  1354. break;
  1355. case MFCINST_RETURN_INST:
  1356. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1357. ctx);
  1358. break;
  1359. case MFCINST_GOT_INST:
  1360. s5p_mfc_run_init_enc(ctx);
  1361. break;
  1362. default:
  1363. ret = -EAGAIN;
  1364. }
  1365. } else {
  1366. mfc_err("Invalid context type: %d\n", ctx->type);
  1367. ret = -EAGAIN;
  1368. }
  1369. if (ret) {
  1370. /* Free hardware lock */
  1371. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1372. mfc_err("Failed to unlock hardware\n");
  1373. /* This is in deed imporant, as no operation has been
  1374. * scheduled, reduce the clock count as no one will
  1375. * ever do this, because no interrupt related to this try_run
  1376. * will ever come from hardware. */
  1377. s5p_mfc_clock_off();
  1378. }
  1379. }
  1380. static void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq)
  1381. {
  1382. struct s5p_mfc_buf *b;
  1383. int i;
  1384. while (!list_empty(lh)) {
  1385. b = list_entry(lh->next, struct s5p_mfc_buf, list);
  1386. for (i = 0; i < b->b->num_planes; i++)
  1387. vb2_set_plane_payload(b->b, i, 0);
  1388. vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
  1389. list_del(&b->list);
  1390. }
  1391. }
  1392. static void s5p_mfc_clear_int_flags_v5(struct s5p_mfc_dev *dev)
  1393. {
  1394. mfc_write(dev, 0, S5P_FIMV_RISC_HOST_INT);
  1395. mfc_write(dev, 0, S5P_FIMV_RISC2HOST_CMD);
  1396. mfc_write(dev, 0xffff, S5P_FIMV_SI_RTN_CHID);
  1397. }
  1398. static int s5p_mfc_get_dspl_y_adr_v5(struct s5p_mfc_dev *dev)
  1399. {
  1400. return mfc_read(dev, S5P_FIMV_SI_DISPLAY_Y_ADR) << MFC_OFFSET_SHIFT;
  1401. }
  1402. static int s5p_mfc_get_dec_y_adr_v5(struct s5p_mfc_dev *dev)
  1403. {
  1404. return mfc_read(dev, S5P_FIMV_SI_DECODE_Y_ADR) << MFC_OFFSET_SHIFT;
  1405. }
  1406. static int s5p_mfc_get_dspl_status_v5(struct s5p_mfc_dev *dev)
  1407. {
  1408. return mfc_read(dev, S5P_FIMV_SI_DISPLAY_STATUS);
  1409. }
  1410. static int s5p_mfc_get_dec_status_v5(struct s5p_mfc_dev *dev)
  1411. {
  1412. return mfc_read(dev, S5P_FIMV_SI_DECODE_STATUS);
  1413. }
  1414. static int s5p_mfc_get_dec_frame_type_v5(struct s5p_mfc_dev *dev)
  1415. {
  1416. return mfc_read(dev, S5P_FIMV_DECODE_FRAME_TYPE) &
  1417. S5P_FIMV_DECODE_FRAME_MASK;
  1418. }
  1419. static int s5p_mfc_get_disp_frame_type_v5(struct s5p_mfc_ctx *ctx)
  1420. {
  1421. return (s5p_mfc_read_info_v5(ctx, DISP_PIC_FRAME_TYPE) >>
  1422. S5P_FIMV_SHARED_DISP_FRAME_TYPE_SHIFT) &
  1423. S5P_FIMV_DECODE_FRAME_MASK;
  1424. }
  1425. static int s5p_mfc_get_consumed_stream_v5(struct s5p_mfc_dev *dev)
  1426. {
  1427. return mfc_read(dev, S5P_FIMV_SI_CONSUMED_BYTES);
  1428. }
  1429. static int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev)
  1430. {
  1431. int reason;
  1432. reason = mfc_read(dev, S5P_FIMV_RISC2HOST_CMD) &
  1433. S5P_FIMV_RISC2HOST_CMD_MASK;
  1434. switch (reason) {
  1435. case S5P_FIMV_R2H_CMD_OPEN_INSTANCE_RET:
  1436. reason = S5P_MFC_R2H_CMD_OPEN_INSTANCE_RET;
  1437. break;
  1438. case S5P_FIMV_R2H_CMD_CLOSE_INSTANCE_RET:
  1439. reason = S5P_MFC_R2H_CMD_CLOSE_INSTANCE_RET;
  1440. break;
  1441. case S5P_FIMV_R2H_CMD_SEQ_DONE_RET:
  1442. reason = S5P_MFC_R2H_CMD_SEQ_DONE_RET;
  1443. break;
  1444. case S5P_FIMV_R2H_CMD_FRAME_DONE_RET:
  1445. reason = S5P_MFC_R2H_CMD_FRAME_DONE_RET;
  1446. break;
  1447. case S5P_FIMV_R2H_CMD_SLICE_DONE_RET:
  1448. reason = S5P_MFC_R2H_CMD_SLICE_DONE_RET;
  1449. break;
  1450. case S5P_FIMV_R2H_CMD_SYS_INIT_RET:
  1451. reason = S5P_MFC_R2H_CMD_SYS_INIT_RET;
  1452. break;
  1453. case S5P_FIMV_R2H_CMD_FW_STATUS_RET:
  1454. reason = S5P_MFC_R2H_CMD_FW_STATUS_RET;
  1455. break;
  1456. case S5P_FIMV_R2H_CMD_SLEEP_RET:
  1457. reason = S5P_MFC_R2H_CMD_SLEEP_RET;
  1458. break;
  1459. case S5P_FIMV_R2H_CMD_WAKEUP_RET:
  1460. reason = S5P_MFC_R2H_CMD_WAKEUP_RET;
  1461. break;
  1462. case S5P_FIMV_R2H_CMD_INIT_BUFFERS_RET:
  1463. reason = S5P_MFC_R2H_CMD_INIT_BUFFERS_RET;
  1464. break;
  1465. case S5P_FIMV_R2H_CMD_ENC_COMPLETE_RET:
  1466. reason = S5P_MFC_R2H_CMD_COMPLETE_SEQ_RET;
  1467. break;
  1468. case S5P_FIMV_R2H_CMD_ERR_RET:
  1469. reason = S5P_MFC_R2H_CMD_ERR_RET;
  1470. break;
  1471. default:
  1472. reason = S5P_MFC_R2H_CMD_EMPTY;
  1473. }
  1474. return reason;
  1475. }
  1476. static int s5p_mfc_get_int_err_v5(struct s5p_mfc_dev *dev)
  1477. {
  1478. return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG2);
  1479. }
  1480. static int s5p_mfc_err_dec_v5(unsigned int err)
  1481. {
  1482. return (err & S5P_FIMV_ERR_DEC_MASK) >> S5P_FIMV_ERR_DEC_SHIFT;
  1483. }
  1484. static int s5p_mfc_err_dspl_v5(unsigned int err)
  1485. {
  1486. return (err & S5P_FIMV_ERR_DSPL_MASK) >> S5P_FIMV_ERR_DSPL_SHIFT;
  1487. }
  1488. static int s5p_mfc_get_img_width_v5(struct s5p_mfc_dev *dev)
  1489. {
  1490. return mfc_read(dev, S5P_FIMV_SI_HRESOL);
  1491. }
  1492. static int s5p_mfc_get_img_height_v5(struct s5p_mfc_dev *dev)
  1493. {
  1494. return mfc_read(dev, S5P_FIMV_SI_VRESOL);
  1495. }
  1496. static int s5p_mfc_get_dpb_count_v5(struct s5p_mfc_dev *dev)
  1497. {
  1498. return mfc_read(dev, S5P_FIMV_SI_BUF_NUMBER);
  1499. }
  1500. static int s5p_mfc_get_mv_count_v5(struct s5p_mfc_dev *dev)
  1501. {
  1502. /* NOP */
  1503. return -1;
  1504. }
  1505. static int s5p_mfc_get_inst_no_v5(struct s5p_mfc_dev *dev)
  1506. {
  1507. return mfc_read(dev, S5P_FIMV_RISC2HOST_ARG1);
  1508. }
  1509. static int s5p_mfc_get_enc_strm_size_v5(struct s5p_mfc_dev *dev)
  1510. {
  1511. return mfc_read(dev, S5P_FIMV_ENC_SI_STRM_SIZE);
  1512. }
  1513. static int s5p_mfc_get_enc_slice_type_v5(struct s5p_mfc_dev *dev)
  1514. {
  1515. return mfc_read(dev, S5P_FIMV_ENC_SI_SLICE_TYPE);
  1516. }
  1517. static int s5p_mfc_get_enc_dpb_count_v5(struct s5p_mfc_dev *dev)
  1518. {
  1519. return -1;
  1520. }
  1521. static int s5p_mfc_get_enc_pic_count_v5(struct s5p_mfc_dev *dev)
  1522. {
  1523. return mfc_read(dev, S5P_FIMV_ENC_SI_PIC_CNT);
  1524. }
  1525. static int s5p_mfc_get_sei_avail_status_v5(struct s5p_mfc_ctx *ctx)
  1526. {
  1527. return s5p_mfc_read_info_v5(ctx, FRAME_PACK_SEI_AVAIL);
  1528. }
  1529. static int s5p_mfc_get_mvc_num_views_v5(struct s5p_mfc_dev *dev)
  1530. {
  1531. return -1;
  1532. }
  1533. static int s5p_mfc_get_mvc_view_id_v5(struct s5p_mfc_dev *dev)
  1534. {
  1535. return -1;
  1536. }
  1537. static unsigned int s5p_mfc_get_pic_type_top_v5(struct s5p_mfc_ctx *ctx)
  1538. {
  1539. return s5p_mfc_read_info_v5(ctx, PIC_TIME_TOP);
  1540. }
  1541. static unsigned int s5p_mfc_get_pic_type_bot_v5(struct s5p_mfc_ctx *ctx)
  1542. {
  1543. return s5p_mfc_read_info_v5(ctx, PIC_TIME_BOT);
  1544. }
  1545. static unsigned int s5p_mfc_get_crop_info_h_v5(struct s5p_mfc_ctx *ctx)
  1546. {
  1547. return s5p_mfc_read_info_v5(ctx, CROP_INFO_H);
  1548. }
  1549. static unsigned int s5p_mfc_get_crop_info_v_v5(struct s5p_mfc_ctx *ctx)
  1550. {
  1551. return s5p_mfc_read_info_v5(ctx, CROP_INFO_V);
  1552. }
  1553. /* Initialize opr function pointers for MFC v5 */
  1554. static struct s5p_mfc_hw_ops s5p_mfc_ops_v5 = {
  1555. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v5,
  1556. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v5,
  1557. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v5,
  1558. .release_codec_buffers = s5p_mfc_release_codec_buffers_v5,
  1559. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v5,
  1560. .release_instance_buffer = s5p_mfc_release_instance_buffer_v5,
  1561. .alloc_dev_context_buffer = s5p_mfc_alloc_dev_context_buffer_v5,
  1562. .release_dev_context_buffer = s5p_mfc_release_dev_context_buffer_v5,
  1563. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v5,
  1564. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v5,
  1565. .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v5,
  1566. .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v5,
  1567. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v5,
  1568. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v5,
  1569. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v5,
  1570. .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v5,
  1571. .init_decode = s5p_mfc_init_decode_v5,
  1572. .init_encode = s5p_mfc_init_encode_v5,
  1573. .encode_one_frame = s5p_mfc_encode_one_frame_v5,
  1574. .try_run = s5p_mfc_try_run_v5,
  1575. .cleanup_queue = s5p_mfc_cleanup_queue_v5,
  1576. .clear_int_flags = s5p_mfc_clear_int_flags_v5,
  1577. .write_info = s5p_mfc_write_info_v5,
  1578. .read_info = s5p_mfc_read_info_v5,
  1579. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v5,
  1580. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v5,
  1581. .get_dspl_status = s5p_mfc_get_dspl_status_v5,
  1582. .get_dec_status = s5p_mfc_get_dec_status_v5,
  1583. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v5,
  1584. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v5,
  1585. .get_consumed_stream = s5p_mfc_get_consumed_stream_v5,
  1586. .get_int_reason = s5p_mfc_get_int_reason_v5,
  1587. .get_int_err = s5p_mfc_get_int_err_v5,
  1588. .err_dec = s5p_mfc_err_dec_v5,
  1589. .err_dspl = s5p_mfc_err_dspl_v5,
  1590. .get_img_width = s5p_mfc_get_img_width_v5,
  1591. .get_img_height = s5p_mfc_get_img_height_v5,
  1592. .get_dpb_count = s5p_mfc_get_dpb_count_v5,
  1593. .get_mv_count = s5p_mfc_get_mv_count_v5,
  1594. .get_inst_no = s5p_mfc_get_inst_no_v5,
  1595. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v5,
  1596. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v5,
  1597. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v5,
  1598. .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v5,
  1599. .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v5,
  1600. .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v5,
  1601. .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v5,
  1602. .get_pic_type_top = s5p_mfc_get_pic_type_top_v5,
  1603. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v5,
  1604. .get_crop_info_h = s5p_mfc_get_crop_info_h_v5,
  1605. .get_crop_info_v = s5p_mfc_get_crop_info_v_v5,
  1606. };
  1607. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v5(void)
  1608. {
  1609. return &s5p_mfc_ops_v5;
  1610. }