s5p_mfc_opr_v5.c 53 KB

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