s5p_mfc_opr_v5.c 53 KB

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