s5p_mfc_opr_v5.c 52 KB

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