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