s5p_mfc_opr_v6.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  1. /*
  2. * drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
  3. *
  4. * Samsung MFC (Multi Function Codec - FIMV) driver
  5. * This file contains hw related functions.
  6. *
  7. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  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. #undef DEBUG
  15. #include <linux/delay.h>
  16. #include <linux/mm.h>
  17. #include <linux/io.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/firmware.h>
  20. #include <linux/err.h>
  21. #include <linux/sched.h>
  22. #include <linux/dma-mapping.h>
  23. #include <asm/cacheflush.h>
  24. #include "s5p_mfc_common.h"
  25. #include "s5p_mfc_cmd.h"
  26. #include "s5p_mfc_intr.h"
  27. #include "s5p_mfc_pm.h"
  28. #include "s5p_mfc_debug.h"
  29. #include "s5p_mfc_opr.h"
  30. #include "s5p_mfc_opr_v6.h"
  31. /* #define S5P_MFC_DEBUG_REGWRITE */
  32. #ifdef S5P_MFC_DEBUG_REGWRITE
  33. #undef writel
  34. #define writel(v, r) \
  35. do { \
  36. pr_err("MFCWRITE(%p): %08x\n", r, (unsigned int)v); \
  37. __raw_writel(v, r); \
  38. } while (0)
  39. #endif /* S5P_MFC_DEBUG_REGWRITE */
  40. #define IS_MFCV6_V2(dev) (!IS_MFCV7_PLUS(dev) && dev->fw_ver == MFC_FW_V2)
  41. /* Allocate temporary buffers for decoding */
  42. static int s5p_mfc_alloc_dec_temp_buffers_v6(struct s5p_mfc_ctx *ctx)
  43. {
  44. /* NOP */
  45. return 0;
  46. }
  47. /* Release temproary buffers for decoding */
  48. static void s5p_mfc_release_dec_desc_buffer_v6(struct s5p_mfc_ctx *ctx)
  49. {
  50. /* NOP */
  51. }
  52. /* Allocate codec buffers */
  53. static int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  54. {
  55. struct s5p_mfc_dev *dev = ctx->dev;
  56. unsigned int mb_width, mb_height;
  57. int ret;
  58. mb_width = MB_WIDTH(ctx->img_width);
  59. mb_height = MB_HEIGHT(ctx->img_height);
  60. if (ctx->type == MFCINST_DECODER) {
  61. mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
  62. ctx->luma_size, ctx->chroma_size, ctx->mv_size);
  63. mfc_debug(2, "Totals bufs: %d\n", ctx->total_dpb_count);
  64. } else if (ctx->type == MFCINST_ENCODER) {
  65. if (IS_MFCV8(dev))
  66. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  67. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V8(mb_width, mb_height),
  68. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  69. else
  70. ctx->tmv_buffer_size = S5P_FIMV_NUM_TMV_BUFFERS_V6 *
  71. ALIGN(S5P_FIMV_TMV_BUFFER_SIZE_V6(mb_width, mb_height),
  72. S5P_FIMV_TMV_BUFFER_ALIGN_V6);
  73. ctx->luma_dpb_size = ALIGN((mb_width * mb_height) *
  74. S5P_FIMV_LUMA_MB_TO_PIXEL_V6,
  75. S5P_FIMV_LUMA_DPB_BUFFER_ALIGN_V6);
  76. ctx->chroma_dpb_size = ALIGN((mb_width * mb_height) *
  77. S5P_FIMV_CHROMA_MB_TO_PIXEL_V6,
  78. S5P_FIMV_CHROMA_DPB_BUFFER_ALIGN_V6);
  79. if (IS_MFCV8(dev))
  80. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V8(
  81. ctx->img_width, ctx->img_height,
  82. mb_width, mb_height),
  83. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  84. else
  85. ctx->me_buffer_size = ALIGN(S5P_FIMV_ME_BUFFER_SIZE_V6(
  86. ctx->img_width, ctx->img_height,
  87. mb_width, mb_height),
  88. S5P_FIMV_ME_BUFFER_ALIGN_V6);
  89. mfc_debug(2, "recon luma size: %zu chroma size: %zu\n",
  90. ctx->luma_dpb_size, ctx->chroma_dpb_size);
  91. } else {
  92. return -EINVAL;
  93. }
  94. /* Codecs have different memory requirements */
  95. switch (ctx->codec_mode) {
  96. case S5P_MFC_CODEC_H264_DEC:
  97. case S5P_MFC_CODEC_H264_MVC_DEC:
  98. if (IS_MFCV8(dev))
  99. ctx->scratch_buf_size =
  100. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V8(
  101. mb_width,
  102. mb_height);
  103. else
  104. ctx->scratch_buf_size =
  105. S5P_FIMV_SCRATCH_BUF_SIZE_H264_DEC_V6(
  106. mb_width,
  107. mb_height);
  108. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  109. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  110. ctx->bank1.size =
  111. ctx->scratch_buf_size +
  112. (ctx->mv_count * ctx->mv_size);
  113. break;
  114. case S5P_MFC_CODEC_MPEG4_DEC:
  115. if (IS_MFCV7_PLUS(dev)) {
  116. ctx->scratch_buf_size =
  117. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V7(
  118. mb_width,
  119. mb_height);
  120. } else {
  121. ctx->scratch_buf_size =
  122. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_DEC_V6(
  123. mb_width,
  124. mb_height);
  125. }
  126. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  127. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  128. ctx->bank1.size = ctx->scratch_buf_size;
  129. break;
  130. case S5P_MFC_CODEC_VC1RCV_DEC:
  131. case S5P_MFC_CODEC_VC1_DEC:
  132. ctx->scratch_buf_size =
  133. S5P_FIMV_SCRATCH_BUF_SIZE_VC1_DEC_V6(
  134. mb_width,
  135. mb_height);
  136. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  137. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  138. ctx->bank1.size = ctx->scratch_buf_size;
  139. break;
  140. case S5P_MFC_CODEC_MPEG2_DEC:
  141. ctx->bank1.size = 0;
  142. ctx->bank2.size = 0;
  143. break;
  144. case S5P_MFC_CODEC_H263_DEC:
  145. ctx->scratch_buf_size =
  146. S5P_FIMV_SCRATCH_BUF_SIZE_H263_DEC_V6(
  147. mb_width,
  148. mb_height);
  149. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  150. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  151. ctx->bank1.size = ctx->scratch_buf_size;
  152. break;
  153. case S5P_MFC_CODEC_VP8_DEC:
  154. if (IS_MFCV8(dev))
  155. ctx->scratch_buf_size =
  156. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V8(
  157. mb_width,
  158. mb_height);
  159. else
  160. ctx->scratch_buf_size =
  161. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_DEC_V6(
  162. mb_width,
  163. mb_height);
  164. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  165. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  166. ctx->bank1.size = ctx->scratch_buf_size;
  167. break;
  168. case S5P_MFC_CODEC_H264_ENC:
  169. if (IS_MFCV8(dev))
  170. ctx->scratch_buf_size =
  171. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V8(
  172. mb_width,
  173. mb_height);
  174. else
  175. ctx->scratch_buf_size =
  176. S5P_FIMV_SCRATCH_BUF_SIZE_H264_ENC_V6(
  177. mb_width,
  178. mb_height);
  179. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  180. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  181. ctx->bank1.size =
  182. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  183. (ctx->pb_count * (ctx->luma_dpb_size +
  184. ctx->chroma_dpb_size + ctx->me_buffer_size));
  185. ctx->bank2.size = 0;
  186. break;
  187. case S5P_MFC_CODEC_MPEG4_ENC:
  188. case S5P_MFC_CODEC_H263_ENC:
  189. ctx->scratch_buf_size =
  190. S5P_FIMV_SCRATCH_BUF_SIZE_MPEG4_ENC_V6(
  191. mb_width,
  192. mb_height);
  193. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  194. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  195. ctx->bank1.size =
  196. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  197. (ctx->pb_count * (ctx->luma_dpb_size +
  198. ctx->chroma_dpb_size + ctx->me_buffer_size));
  199. ctx->bank2.size = 0;
  200. break;
  201. case S5P_MFC_CODEC_VP8_ENC:
  202. if (IS_MFCV8(dev))
  203. ctx->scratch_buf_size =
  204. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V8(
  205. mb_width,
  206. mb_height);
  207. else
  208. ctx->scratch_buf_size =
  209. S5P_FIMV_SCRATCH_BUF_SIZE_VP8_ENC_V7(
  210. mb_width,
  211. mb_height);
  212. ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
  213. S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
  214. ctx->bank1.size =
  215. ctx->scratch_buf_size + ctx->tmv_buffer_size +
  216. (ctx->pb_count * (ctx->luma_dpb_size +
  217. ctx->chroma_dpb_size + ctx->me_buffer_size));
  218. ctx->bank2.size = 0;
  219. break;
  220. default:
  221. break;
  222. }
  223. /* Allocate only if memory from bank 1 is necessary */
  224. if (ctx->bank1.size > 0) {
  225. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
  226. if (ret) {
  227. mfc_err("Failed to allocate Bank1 memory\n");
  228. return ret;
  229. }
  230. BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  231. }
  232. return 0;
  233. }
  234. /* Release buffers allocated for codec */
  235. static void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
  236. {
  237. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
  238. }
  239. /* Allocate memory for instance data buffer */
  240. static int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  241. {
  242. struct s5p_mfc_dev *dev = ctx->dev;
  243. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  244. int ret;
  245. mfc_debug_enter();
  246. switch (ctx->codec_mode) {
  247. case S5P_MFC_CODEC_H264_DEC:
  248. case S5P_MFC_CODEC_H264_MVC_DEC:
  249. ctx->ctx.size = buf_size->h264_dec_ctx;
  250. break;
  251. case S5P_MFC_CODEC_MPEG4_DEC:
  252. case S5P_MFC_CODEC_H263_DEC:
  253. case S5P_MFC_CODEC_VC1RCV_DEC:
  254. case S5P_MFC_CODEC_VC1_DEC:
  255. case S5P_MFC_CODEC_MPEG2_DEC:
  256. case S5P_MFC_CODEC_VP8_DEC:
  257. ctx->ctx.size = buf_size->other_dec_ctx;
  258. break;
  259. case S5P_MFC_CODEC_H264_ENC:
  260. ctx->ctx.size = buf_size->h264_enc_ctx;
  261. break;
  262. case S5P_MFC_CODEC_MPEG4_ENC:
  263. case S5P_MFC_CODEC_H263_ENC:
  264. case S5P_MFC_CODEC_VP8_ENC:
  265. ctx->ctx.size = buf_size->other_enc_ctx;
  266. break;
  267. default:
  268. ctx->ctx.size = 0;
  269. mfc_err("Codec type(%d) should be checked!\n", ctx->codec_mode);
  270. break;
  271. }
  272. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
  273. if (ret) {
  274. mfc_err("Failed to allocate instance buffer\n");
  275. return ret;
  276. }
  277. memset(ctx->ctx.virt, 0, ctx->ctx.size);
  278. wmb();
  279. mfc_debug_leave();
  280. return 0;
  281. }
  282. /* Release instance buffer */
  283. static void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
  284. {
  285. s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
  286. }
  287. /* Allocate context buffers for SYS_INIT */
  288. static int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  289. {
  290. struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
  291. int ret;
  292. mfc_debug_enter();
  293. dev->ctx_buf.size = buf_size->dev_ctx;
  294. ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
  295. if (ret) {
  296. mfc_err("Failed to allocate device context buffer\n");
  297. return ret;
  298. }
  299. memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
  300. wmb();
  301. mfc_debug_leave();
  302. return 0;
  303. }
  304. /* Release context buffers for SYS_INIT */
  305. static void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
  306. {
  307. s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
  308. }
  309. static int calc_plane(int width, int height)
  310. {
  311. int mbX, mbY;
  312. mbX = DIV_ROUND_UP(width, S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  313. mbY = DIV_ROUND_UP(height, S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6);
  314. if (width * height < S5P_FIMV_MAX_FRAME_SIZE_V6)
  315. mbY = (mbY + 1) / 2 * 2;
  316. return (mbX * S5P_FIMV_NUM_PIXELS_IN_MB_COL_V6) *
  317. (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6);
  318. }
  319. static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx)
  320. {
  321. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6);
  322. ctx->buf_height = ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN_V6);
  323. mfc_debug(2, "SEQ Done: Movie dimensions %dx%d,\n"
  324. "buffer dimensions: %dx%d\n", ctx->img_width,
  325. ctx->img_height, ctx->buf_width, ctx->buf_height);
  326. ctx->luma_size = calc_plane(ctx->img_width, ctx->img_height);
  327. ctx->chroma_size = calc_plane(ctx->img_width, (ctx->img_height >> 1));
  328. if (IS_MFCV8(ctx->dev)) {
  329. /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/
  330. ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  331. ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8;
  332. }
  333. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  334. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  335. ctx->mv_size = S5P_MFC_DEC_MV_SIZE_V6(ctx->img_width,
  336. ctx->img_height);
  337. ctx->mv_size = ALIGN(ctx->mv_size, 16);
  338. } else {
  339. ctx->mv_size = 0;
  340. }
  341. }
  342. static void s5p_mfc_enc_calc_src_size_v6(struct s5p_mfc_ctx *ctx)
  343. {
  344. unsigned int mb_width, mb_height;
  345. mb_width = MB_WIDTH(ctx->img_width);
  346. mb_height = MB_HEIGHT(ctx->img_height);
  347. ctx->buf_width = ALIGN(ctx->img_width, S5P_FIMV_NV12M_HALIGN_V6);
  348. ctx->luma_size = ALIGN((mb_width * mb_height) * 256, 256);
  349. ctx->chroma_size = ALIGN((mb_width * mb_height) * 128, 256);
  350. /* MFCv7 needs pad bytes for Luma and Chroma */
  351. if (IS_MFCV7_PLUS(ctx->dev)) {
  352. ctx->luma_size += MFC_LUMA_PAD_BYTES_V7;
  353. ctx->chroma_size += MFC_CHROMA_PAD_BYTES_V7;
  354. }
  355. }
  356. /* Set registers for decoding stream buffer */
  357. static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  358. int buf_addr, unsigned int start_num_byte,
  359. unsigned int strm_size)
  360. {
  361. struct s5p_mfc_dev *dev = ctx->dev;
  362. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  363. struct s5p_mfc_buf_size *buf_size = dev->variant->buf_size;
  364. mfc_debug_enter();
  365. mfc_debug(2, "inst_no: %d, buf_addr: 0x%08x,\n"
  366. "buf_size: 0x%08x (%d)\n",
  367. ctx->inst_no, buf_addr, strm_size, strm_size);
  368. writel(strm_size, mfc_regs->d_stream_data_size);
  369. writel(buf_addr, mfc_regs->d_cpb_buffer_addr);
  370. writel(buf_size->cpb, mfc_regs->d_cpb_buffer_size);
  371. writel(start_num_byte, mfc_regs->d_cpb_buffer_offset);
  372. mfc_debug_leave();
  373. return 0;
  374. }
  375. /* Set decoding frame buffer */
  376. static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
  377. {
  378. unsigned int frame_size, i;
  379. unsigned int frame_size_ch, frame_size_mv;
  380. struct s5p_mfc_dev *dev = ctx->dev;
  381. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  382. size_t buf_addr1;
  383. int buf_size1;
  384. int align_gap;
  385. buf_addr1 = ctx->bank1.dma;
  386. buf_size1 = ctx->bank1.size;
  387. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  388. mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
  389. mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay);
  390. writel(ctx->total_dpb_count, mfc_regs->d_num_dpb);
  391. writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size);
  392. writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size);
  393. writel(buf_addr1, mfc_regs->d_scratch_buffer_addr);
  394. writel(ctx->scratch_buf_size, mfc_regs->d_scratch_buffer_size);
  395. if (IS_MFCV8(dev)) {
  396. writel(ctx->img_width,
  397. mfc_regs->d_first_plane_dpb_stride_size);
  398. writel(ctx->img_width,
  399. mfc_regs->d_second_plane_dpb_stride_size);
  400. }
  401. buf_addr1 += ctx->scratch_buf_size;
  402. buf_size1 -= ctx->scratch_buf_size;
  403. if (ctx->codec_mode == S5P_FIMV_CODEC_H264_DEC ||
  404. ctx->codec_mode == S5P_FIMV_CODEC_H264_MVC_DEC){
  405. writel(ctx->mv_size, mfc_regs->d_mv_buffer_size);
  406. writel(ctx->mv_count, mfc_regs->d_num_mv);
  407. }
  408. frame_size = ctx->luma_size;
  409. frame_size_ch = ctx->chroma_size;
  410. frame_size_mv = ctx->mv_size;
  411. mfc_debug(2, "Frame size: %d ch: %d mv: %d\n",
  412. frame_size, frame_size_ch, frame_size_mv);
  413. for (i = 0; i < ctx->total_dpb_count; i++) {
  414. /* Bank2 */
  415. mfc_debug(2, "Luma %d: %zx\n", i,
  416. ctx->dst_bufs[i].cookie.raw.luma);
  417. writel(ctx->dst_bufs[i].cookie.raw.luma,
  418. mfc_regs->d_first_plane_dpb + i * 4);
  419. mfc_debug(2, "\tChroma %d: %zx\n", i,
  420. ctx->dst_bufs[i].cookie.raw.chroma);
  421. writel(ctx->dst_bufs[i].cookie.raw.chroma,
  422. mfc_regs->d_second_plane_dpb + i * 4);
  423. }
  424. if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
  425. ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) {
  426. for (i = 0; i < ctx->mv_count; i++) {
  427. /* To test alignment */
  428. align_gap = buf_addr1;
  429. buf_addr1 = ALIGN(buf_addr1, 16);
  430. align_gap = buf_addr1 - align_gap;
  431. buf_size1 -= align_gap;
  432. mfc_debug(2, "\tBuf1: %zx, size: %d\n",
  433. buf_addr1, buf_size1);
  434. writel(buf_addr1, mfc_regs->d_mv_buffer + i * 4);
  435. buf_addr1 += frame_size_mv;
  436. buf_size1 -= frame_size_mv;
  437. }
  438. }
  439. mfc_debug(2, "Buf1: %zu, buf_size1: %d (frames %d)\n",
  440. buf_addr1, buf_size1, ctx->total_dpb_count);
  441. if (buf_size1 < 0) {
  442. mfc_debug(2, "Not enough memory has been allocated.\n");
  443. return -ENOMEM;
  444. }
  445. writel(ctx->inst_no, mfc_regs->instance_id);
  446. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  447. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  448. mfc_debug(2, "After setting buffers.\n");
  449. return 0;
  450. }
  451. /* Set registers for encoding stream buffer */
  452. static int s5p_mfc_set_enc_stream_buffer_v6(struct s5p_mfc_ctx *ctx,
  453. unsigned long addr, unsigned int size)
  454. {
  455. struct s5p_mfc_dev *dev = ctx->dev;
  456. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  457. writel(addr, mfc_regs->e_stream_buffer_addr); /* 16B align */
  458. writel(size, mfc_regs->e_stream_buffer_size);
  459. mfc_debug(2, "stream buf addr: 0x%08lx, size: 0x%d\n",
  460. addr, size);
  461. return 0;
  462. }
  463. static void s5p_mfc_set_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  464. unsigned long y_addr, unsigned long c_addr)
  465. {
  466. struct s5p_mfc_dev *dev = ctx->dev;
  467. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  468. writel(y_addr, mfc_regs->e_source_first_plane_addr);
  469. writel(c_addr, mfc_regs->e_source_second_plane_addr);
  470. mfc_debug(2, "enc src y buf addr: 0x%08lx\n", y_addr);
  471. mfc_debug(2, "enc src c buf addr: 0x%08lx\n", c_addr);
  472. }
  473. static void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
  474. unsigned long *y_addr, unsigned long *c_addr)
  475. {
  476. struct s5p_mfc_dev *dev = ctx->dev;
  477. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  478. unsigned long enc_recon_y_addr, enc_recon_c_addr;
  479. *y_addr = readl(mfc_regs->e_encoded_source_first_plane_addr);
  480. *c_addr = readl(mfc_regs->e_encoded_source_second_plane_addr);
  481. enc_recon_y_addr = readl(mfc_regs->e_recon_luma_dpb_addr);
  482. enc_recon_c_addr = readl(mfc_regs->e_recon_chroma_dpb_addr);
  483. mfc_debug(2, "recon y addr: 0x%08lx\n", enc_recon_y_addr);
  484. mfc_debug(2, "recon c addr: 0x%08lx\n", enc_recon_c_addr);
  485. }
  486. /* Set encoding ref & codec buffer */
  487. static int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
  488. {
  489. struct s5p_mfc_dev *dev = ctx->dev;
  490. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  491. size_t buf_addr1;
  492. int i, buf_size1;
  493. mfc_debug_enter();
  494. buf_addr1 = ctx->bank1.dma;
  495. buf_size1 = ctx->bank1.size;
  496. mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
  497. for (i = 0; i < ctx->pb_count; i++) {
  498. writel(buf_addr1, mfc_regs->e_luma_dpb + (4 * i));
  499. buf_addr1 += ctx->luma_dpb_size;
  500. writel(buf_addr1, mfc_regs->e_chroma_dpb + (4 * i));
  501. buf_addr1 += ctx->chroma_dpb_size;
  502. writel(buf_addr1, mfc_regs->e_me_buffer + (4 * i));
  503. buf_addr1 += ctx->me_buffer_size;
  504. buf_size1 -= (ctx->luma_dpb_size + ctx->chroma_dpb_size +
  505. ctx->me_buffer_size);
  506. }
  507. writel(buf_addr1, mfc_regs->e_scratch_buffer_addr);
  508. writel(ctx->scratch_buf_size, mfc_regs->e_scratch_buffer_size);
  509. buf_addr1 += ctx->scratch_buf_size;
  510. buf_size1 -= ctx->scratch_buf_size;
  511. writel(buf_addr1, mfc_regs->e_tmv_buffer0);
  512. buf_addr1 += ctx->tmv_buffer_size >> 1;
  513. writel(buf_addr1, mfc_regs->e_tmv_buffer1);
  514. buf_addr1 += ctx->tmv_buffer_size >> 1;
  515. buf_size1 -= ctx->tmv_buffer_size;
  516. mfc_debug(2, "Buf1: %zu, buf_size1: %d (ref frames %d)\n",
  517. buf_addr1, buf_size1, ctx->pb_count);
  518. if (buf_size1 < 0) {
  519. mfc_debug(2, "Not enough memory has been allocated.\n");
  520. return -ENOMEM;
  521. }
  522. writel(ctx->inst_no, mfc_regs->instance_id);
  523. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  524. S5P_FIMV_CH_INIT_BUFS_V6, NULL);
  525. mfc_debug_leave();
  526. return 0;
  527. }
  528. static int s5p_mfc_set_slice_mode(struct s5p_mfc_ctx *ctx)
  529. {
  530. struct s5p_mfc_dev *dev = ctx->dev;
  531. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  532. /* multi-slice control */
  533. /* multi-slice MB number or bit size */
  534. writel(ctx->slice_mode, mfc_regs->e_mslice_mode);
  535. if (ctx->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  536. writel(ctx->slice_size.mb, mfc_regs->e_mslice_size_mb);
  537. } else if (ctx->slice_mode ==
  538. V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  539. writel(ctx->slice_size.bits, mfc_regs->e_mslice_size_bits);
  540. } else {
  541. writel(0x0, mfc_regs->e_mslice_size_mb);
  542. writel(0x0, mfc_regs->e_mslice_size_bits);
  543. }
  544. return 0;
  545. }
  546. static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx)
  547. {
  548. struct s5p_mfc_dev *dev = ctx->dev;
  549. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  550. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  551. unsigned int reg = 0;
  552. mfc_debug_enter();
  553. /* width */
  554. writel(ctx->img_width, mfc_regs->e_frame_width); /* 16 align */
  555. /* height */
  556. writel(ctx->img_height, mfc_regs->e_frame_height); /* 16 align */
  557. /* cropped width */
  558. writel(ctx->img_width, mfc_regs->e_cropped_frame_width);
  559. /* cropped height */
  560. writel(ctx->img_height, mfc_regs->e_cropped_frame_height);
  561. /* cropped offset */
  562. writel(0x0, mfc_regs->e_frame_crop_offset);
  563. /* pictype : IDR period */
  564. reg = 0;
  565. reg |= p->gop_size & 0xFFFF;
  566. writel(reg, mfc_regs->e_gop_config);
  567. /* multi-slice control */
  568. /* multi-slice MB number or bit size */
  569. ctx->slice_mode = p->slice_mode;
  570. reg = 0;
  571. if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB) {
  572. reg |= (0x1 << 3);
  573. writel(reg, mfc_regs->e_enc_options);
  574. ctx->slice_size.mb = p->slice_mb;
  575. } else if (p->slice_mode == V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES) {
  576. reg |= (0x1 << 3);
  577. writel(reg, mfc_regs->e_enc_options);
  578. ctx->slice_size.bits = p->slice_bit;
  579. } else {
  580. reg &= ~(0x1 << 3);
  581. writel(reg, mfc_regs->e_enc_options);
  582. }
  583. s5p_mfc_set_slice_mode(ctx);
  584. /* cyclic intra refresh */
  585. writel(p->intra_refresh_mb, mfc_regs->e_ir_size);
  586. reg = readl(mfc_regs->e_enc_options);
  587. if (p->intra_refresh_mb == 0)
  588. reg &= ~(0x1 << 4);
  589. else
  590. reg |= (0x1 << 4);
  591. writel(reg, mfc_regs->e_enc_options);
  592. /* 'NON_REFERENCE_STORE_ENABLE' for debugging */
  593. reg = readl(mfc_regs->e_enc_options);
  594. reg &= ~(0x1 << 9);
  595. writel(reg, mfc_regs->e_enc_options);
  596. /* memory structure cur. frame */
  597. if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12M) {
  598. /* 0: Linear, 1: 2D tiled*/
  599. reg = readl(mfc_regs->e_enc_options);
  600. reg &= ~(0x1 << 7);
  601. writel(reg, mfc_regs->e_enc_options);
  602. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  603. writel(0x0, mfc_regs->pixel_format);
  604. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV21M) {
  605. /* 0: Linear, 1: 2D tiled*/
  606. reg = readl(mfc_regs->e_enc_options);
  607. reg &= ~(0x1 << 7);
  608. writel(reg, mfc_regs->e_enc_options);
  609. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  610. writel(0x1, mfc_regs->pixel_format);
  611. } else if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16) {
  612. /* 0: Linear, 1: 2D tiled*/
  613. reg = readl(mfc_regs->e_enc_options);
  614. reg |= (0x1 << 7);
  615. writel(reg, mfc_regs->e_enc_options);
  616. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  617. writel(0x0, mfc_regs->pixel_format);
  618. }
  619. /* memory structure recon. frame */
  620. /* 0: Linear, 1: 2D tiled */
  621. reg = readl(mfc_regs->e_enc_options);
  622. reg |= (0x1 << 8);
  623. writel(reg, mfc_regs->e_enc_options);
  624. /* padding control & value */
  625. writel(0x0, mfc_regs->e_padding_ctrl);
  626. if (p->pad) {
  627. reg = 0;
  628. /** enable */
  629. reg |= (1 << 31);
  630. /** cr value */
  631. reg |= ((p->pad_cr & 0xFF) << 16);
  632. /** cb value */
  633. reg |= ((p->pad_cb & 0xFF) << 8);
  634. /** y value */
  635. reg |= p->pad_luma & 0xFF;
  636. writel(reg, mfc_regs->e_padding_ctrl);
  637. }
  638. /* rate control config. */
  639. reg = 0;
  640. /* frame-level rate control */
  641. reg |= ((p->rc_frame & 0x1) << 9);
  642. writel(reg, mfc_regs->e_rc_config);
  643. /* bit rate */
  644. if (p->rc_frame)
  645. writel(p->rc_bitrate,
  646. mfc_regs->e_rc_bit_rate);
  647. else
  648. writel(1, mfc_regs->e_rc_bit_rate);
  649. /* reaction coefficient */
  650. if (p->rc_frame) {
  651. if (p->rc_reaction_coeff < TIGHT_CBR_MAX) /* tight CBR */
  652. writel(1, mfc_regs->e_rc_mode);
  653. else /* loose CBR */
  654. writel(2, mfc_regs->e_rc_mode);
  655. }
  656. /* seq header ctrl */
  657. reg = readl(mfc_regs->e_enc_options);
  658. reg &= ~(0x1 << 2);
  659. reg |= ((p->seq_hdr_mode & 0x1) << 2);
  660. /* frame skip mode */
  661. reg &= ~(0x3);
  662. reg |= (p->frame_skip_mode & 0x3);
  663. writel(reg, mfc_regs->e_enc_options);
  664. /* 'DROP_CONTROL_ENABLE', disable */
  665. reg = readl(mfc_regs->e_rc_config);
  666. reg &= ~(0x1 << 10);
  667. writel(reg, mfc_regs->e_rc_config);
  668. /* setting for MV range [16, 256] */
  669. reg = (p->mv_h_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  670. writel(reg, mfc_regs->e_mv_hor_range);
  671. reg = (p->mv_v_range & S5P_FIMV_E_MV_RANGE_V6_MASK);
  672. writel(reg, mfc_regs->e_mv_ver_range);
  673. writel(0x0, mfc_regs->e_frame_insertion);
  674. writel(0x0, mfc_regs->e_roi_buffer_addr);
  675. writel(0x0, mfc_regs->e_param_change);
  676. writel(0x0, mfc_regs->e_rc_roi_ctrl);
  677. writel(0x0, mfc_regs->e_picture_tag);
  678. writel(0x0, mfc_regs->e_bit_count_enable);
  679. writel(0x0, mfc_regs->e_max_bit_count);
  680. writel(0x0, mfc_regs->e_min_bit_count);
  681. writel(0x0, mfc_regs->e_metadata_buffer_addr);
  682. writel(0x0, mfc_regs->e_metadata_buffer_size);
  683. mfc_debug_leave();
  684. return 0;
  685. }
  686. static int s5p_mfc_set_enc_params_h264(struct s5p_mfc_ctx *ctx)
  687. {
  688. struct s5p_mfc_dev *dev = ctx->dev;
  689. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  690. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  691. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  692. unsigned int reg = 0;
  693. int i;
  694. mfc_debug_enter();
  695. s5p_mfc_set_enc_params(ctx);
  696. /* pictype : number of B */
  697. reg = readl(mfc_regs->e_gop_config);
  698. reg &= ~(0x3 << 16);
  699. reg |= ((p->num_b_frame & 0x3) << 16);
  700. writel(reg, mfc_regs->e_gop_config);
  701. /* profile & level */
  702. reg = 0;
  703. /** level */
  704. reg |= ((p_h264->level & 0xFF) << 8);
  705. /** profile - 0 ~ 3 */
  706. reg |= p_h264->profile & 0x3F;
  707. writel(reg, mfc_regs->e_picture_profile);
  708. /* rate control config. */
  709. reg = readl(mfc_regs->e_rc_config);
  710. /** macroblock level rate control */
  711. reg &= ~(0x1 << 8);
  712. reg |= ((p->rc_mb & 0x1) << 8);
  713. writel(reg, mfc_regs->e_rc_config);
  714. /** frame QP */
  715. reg &= ~(0x3F);
  716. reg |= p_h264->rc_frame_qp & 0x3F;
  717. writel(reg, mfc_regs->e_rc_config);
  718. /* max & min value of QP */
  719. reg = 0;
  720. /** max QP */
  721. reg |= ((p_h264->rc_max_qp & 0x3F) << 8);
  722. /** min QP */
  723. reg |= p_h264->rc_min_qp & 0x3F;
  724. writel(reg, mfc_regs->e_rc_qp_bound);
  725. /* other QPs */
  726. writel(0x0, mfc_regs->e_fixed_picture_qp);
  727. if (!p->rc_frame && !p->rc_mb) {
  728. reg = 0;
  729. reg |= ((p_h264->rc_b_frame_qp & 0x3F) << 16);
  730. reg |= ((p_h264->rc_p_frame_qp & 0x3F) << 8);
  731. reg |= p_h264->rc_frame_qp & 0x3F;
  732. writel(reg, mfc_regs->e_fixed_picture_qp);
  733. }
  734. /* frame rate */
  735. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  736. reg = 0;
  737. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  738. reg |= p->rc_framerate_denom & 0xFFFF;
  739. writel(reg, mfc_regs->e_rc_frame_rate);
  740. }
  741. /* vbv buffer size */
  742. if (p->frame_skip_mode ==
  743. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  744. writel(p_h264->cpb_size & 0xFFFF,
  745. mfc_regs->e_vbv_buffer_size);
  746. if (p->rc_frame)
  747. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  748. }
  749. /* interlace */
  750. reg = 0;
  751. reg |= ((p_h264->interlace & 0x1) << 3);
  752. writel(reg, mfc_regs->e_h264_options);
  753. /* height */
  754. if (p_h264->interlace) {
  755. writel(ctx->img_height >> 1,
  756. mfc_regs->e_frame_height); /* 32 align */
  757. /* cropped height */
  758. writel(ctx->img_height >> 1,
  759. mfc_regs->e_cropped_frame_height);
  760. }
  761. /* loop filter ctrl */
  762. reg = readl(mfc_regs->e_h264_options);
  763. reg &= ~(0x3 << 1);
  764. reg |= ((p_h264->loop_filter_mode & 0x3) << 1);
  765. writel(reg, mfc_regs->e_h264_options);
  766. /* loopfilter alpha offset */
  767. if (p_h264->loop_filter_alpha < 0) {
  768. reg = 0x10;
  769. reg |= (0xFF - p_h264->loop_filter_alpha) + 1;
  770. } else {
  771. reg = 0x00;
  772. reg |= (p_h264->loop_filter_alpha & 0xF);
  773. }
  774. writel(reg, mfc_regs->e_h264_lf_alpha_offset);
  775. /* loopfilter beta offset */
  776. if (p_h264->loop_filter_beta < 0) {
  777. reg = 0x10;
  778. reg |= (0xFF - p_h264->loop_filter_beta) + 1;
  779. } else {
  780. reg = 0x00;
  781. reg |= (p_h264->loop_filter_beta & 0xF);
  782. }
  783. writel(reg, mfc_regs->e_h264_lf_beta_offset);
  784. /* entropy coding mode */
  785. reg = readl(mfc_regs->e_h264_options);
  786. reg &= ~(0x1);
  787. reg |= p_h264->entropy_mode & 0x1;
  788. writel(reg, mfc_regs->e_h264_options);
  789. /* number of ref. picture */
  790. reg = readl(mfc_regs->e_h264_options);
  791. reg &= ~(0x1 << 7);
  792. reg |= (((p_h264->num_ref_pic_4p - 1) & 0x1) << 7);
  793. writel(reg, mfc_regs->e_h264_options);
  794. /* 8x8 transform enable */
  795. reg = readl(mfc_regs->e_h264_options);
  796. reg &= ~(0x3 << 12);
  797. reg |= ((p_h264->_8x8_transform & 0x3) << 12);
  798. writel(reg, mfc_regs->e_h264_options);
  799. /* macroblock adaptive scaling features */
  800. writel(0x0, mfc_regs->e_mb_rc_config);
  801. if (p->rc_mb) {
  802. reg = 0;
  803. /** dark region */
  804. reg |= ((p_h264->rc_mb_dark & 0x1) << 3);
  805. /** smooth region */
  806. reg |= ((p_h264->rc_mb_smooth & 0x1) << 2);
  807. /** static region */
  808. reg |= ((p_h264->rc_mb_static & 0x1) << 1);
  809. /** high activity region */
  810. reg |= p_h264->rc_mb_activity & 0x1;
  811. writel(reg, mfc_regs->e_mb_rc_config);
  812. }
  813. /* aspect ratio VUI */
  814. readl(mfc_regs->e_h264_options);
  815. reg &= ~(0x1 << 5);
  816. reg |= ((p_h264->vui_sar & 0x1) << 5);
  817. writel(reg, mfc_regs->e_h264_options);
  818. writel(0x0, mfc_regs->e_aspect_ratio);
  819. writel(0x0, mfc_regs->e_extended_sar);
  820. if (p_h264->vui_sar) {
  821. /* aspect ration IDC */
  822. reg = 0;
  823. reg |= p_h264->vui_sar_idc & 0xFF;
  824. writel(reg, mfc_regs->e_aspect_ratio);
  825. if (p_h264->vui_sar_idc == 0xFF) {
  826. /* extended SAR */
  827. reg = 0;
  828. reg |= (p_h264->vui_ext_sar_width & 0xFFFF) << 16;
  829. reg |= p_h264->vui_ext_sar_height & 0xFFFF;
  830. writel(reg, mfc_regs->e_extended_sar);
  831. }
  832. }
  833. /* intra picture period for H.264 open GOP */
  834. /* control */
  835. readl(mfc_regs->e_h264_options);
  836. reg &= ~(0x1 << 4);
  837. reg |= ((p_h264->open_gop & 0x1) << 4);
  838. writel(reg, mfc_regs->e_h264_options);
  839. /* value */
  840. writel(0x0, mfc_regs->e_h264_i_period);
  841. if (p_h264->open_gop) {
  842. reg = 0;
  843. reg |= p_h264->open_gop_size & 0xFFFF;
  844. writel(reg, mfc_regs->e_h264_i_period);
  845. }
  846. /* 'WEIGHTED_BI_PREDICTION' for B is disable */
  847. readl(mfc_regs->e_h264_options);
  848. reg &= ~(0x3 << 9);
  849. writel(reg, mfc_regs->e_h264_options);
  850. /* 'CONSTRAINED_INTRA_PRED_ENABLE' is disable */
  851. readl(mfc_regs->e_h264_options);
  852. reg &= ~(0x1 << 14);
  853. writel(reg, mfc_regs->e_h264_options);
  854. /* ASO */
  855. readl(mfc_regs->e_h264_options);
  856. reg &= ~(0x1 << 6);
  857. reg |= ((p_h264->aso & 0x1) << 6);
  858. writel(reg, mfc_regs->e_h264_options);
  859. /* hier qp enable */
  860. readl(mfc_regs->e_h264_options);
  861. reg &= ~(0x1 << 8);
  862. reg |= ((p_h264->open_gop & 0x1) << 8);
  863. writel(reg, mfc_regs->e_h264_options);
  864. reg = 0;
  865. if (p_h264->hier_qp && p_h264->hier_qp_layer) {
  866. reg |= (p_h264->hier_qp_type & 0x1) << 0x3;
  867. reg |= p_h264->hier_qp_layer & 0x7;
  868. writel(reg, mfc_regs->e_h264_num_t_layer);
  869. /* QP value for each layer */
  870. for (i = 0; i < p_h264->hier_qp_layer &&
  871. i < ARRAY_SIZE(p_h264->hier_qp_layer_qp); i++) {
  872. writel(p_h264->hier_qp_layer_qp[i],
  873. mfc_regs->e_h264_hierarchical_qp_layer0
  874. + i * 4);
  875. }
  876. }
  877. /* number of coding layer should be zero when hierarchical is disable */
  878. writel(reg, mfc_regs->e_h264_num_t_layer);
  879. /* frame packing SEI generation */
  880. readl(mfc_regs->e_h264_options);
  881. reg &= ~(0x1 << 25);
  882. reg |= ((p_h264->sei_frame_packing & 0x1) << 25);
  883. writel(reg, mfc_regs->e_h264_options);
  884. if (p_h264->sei_frame_packing) {
  885. reg = 0;
  886. /** current frame0 flag */
  887. reg |= ((p_h264->sei_fp_curr_frame_0 & 0x1) << 2);
  888. /** arrangement type */
  889. reg |= p_h264->sei_fp_arrangement_type & 0x3;
  890. writel(reg, mfc_regs->e_h264_frame_packing_sei_info);
  891. }
  892. if (p_h264->fmo) {
  893. switch (p_h264->fmo_map_type) {
  894. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES:
  895. if (p_h264->fmo_slice_grp > 4)
  896. p_h264->fmo_slice_grp = 4;
  897. for (i = 0; i < (p_h264->fmo_slice_grp & 0xF); i++)
  898. writel(p_h264->fmo_run_len[i] - 1,
  899. mfc_regs->e_h264_fmo_run_length_minus1_0
  900. + i * 4);
  901. break;
  902. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES:
  903. if (p_h264->fmo_slice_grp > 4)
  904. p_h264->fmo_slice_grp = 4;
  905. break;
  906. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN:
  907. case V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN:
  908. if (p_h264->fmo_slice_grp > 2)
  909. p_h264->fmo_slice_grp = 2;
  910. writel(p_h264->fmo_chg_dir & 0x1,
  911. mfc_regs->e_h264_fmo_slice_grp_change_dir);
  912. /* the valid range is 0 ~ number of macroblocks -1 */
  913. writel(p_h264->fmo_chg_rate,
  914. mfc_regs->e_h264_fmo_slice_grp_change_rate_minus1);
  915. break;
  916. default:
  917. mfc_err("Unsupported map type for FMO: %d\n",
  918. p_h264->fmo_map_type);
  919. p_h264->fmo_map_type = 0;
  920. p_h264->fmo_slice_grp = 1;
  921. break;
  922. }
  923. writel(p_h264->fmo_map_type,
  924. mfc_regs->e_h264_fmo_slice_grp_map_type);
  925. writel(p_h264->fmo_slice_grp - 1,
  926. mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  927. } else {
  928. writel(0, mfc_regs->e_h264_fmo_num_slice_grp_minus1);
  929. }
  930. mfc_debug_leave();
  931. return 0;
  932. }
  933. static int s5p_mfc_set_enc_params_mpeg4(struct s5p_mfc_ctx *ctx)
  934. {
  935. struct s5p_mfc_dev *dev = ctx->dev;
  936. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  937. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  938. struct s5p_mfc_mpeg4_enc_params *p_mpeg4 = &p->codec.mpeg4;
  939. unsigned int reg = 0;
  940. mfc_debug_enter();
  941. s5p_mfc_set_enc_params(ctx);
  942. /* pictype : number of B */
  943. reg = readl(mfc_regs->e_gop_config);
  944. reg &= ~(0x3 << 16);
  945. reg |= ((p->num_b_frame & 0x3) << 16);
  946. writel(reg, mfc_regs->e_gop_config);
  947. /* profile & level */
  948. reg = 0;
  949. /** level */
  950. reg |= ((p_mpeg4->level & 0xFF) << 8);
  951. /** profile - 0 ~ 1 */
  952. reg |= p_mpeg4->profile & 0x3F;
  953. writel(reg, mfc_regs->e_picture_profile);
  954. /* rate control config. */
  955. reg = readl(mfc_regs->e_rc_config);
  956. /** macroblock level rate control */
  957. reg &= ~(0x1 << 8);
  958. reg |= ((p->rc_mb & 0x1) << 8);
  959. writel(reg, mfc_regs->e_rc_config);
  960. /** frame QP */
  961. reg &= ~(0x3F);
  962. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  963. writel(reg, mfc_regs->e_rc_config);
  964. /* max & min value of QP */
  965. reg = 0;
  966. /** max QP */
  967. reg |= ((p_mpeg4->rc_max_qp & 0x3F) << 8);
  968. /** min QP */
  969. reg |= p_mpeg4->rc_min_qp & 0x3F;
  970. writel(reg, mfc_regs->e_rc_qp_bound);
  971. /* other QPs */
  972. writel(0x0, mfc_regs->e_fixed_picture_qp);
  973. if (!p->rc_frame && !p->rc_mb) {
  974. reg = 0;
  975. reg |= ((p_mpeg4->rc_b_frame_qp & 0x3F) << 16);
  976. reg |= ((p_mpeg4->rc_p_frame_qp & 0x3F) << 8);
  977. reg |= p_mpeg4->rc_frame_qp & 0x3F;
  978. writel(reg, mfc_regs->e_fixed_picture_qp);
  979. }
  980. /* frame rate */
  981. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  982. reg = 0;
  983. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  984. reg |= p->rc_framerate_denom & 0xFFFF;
  985. writel(reg, mfc_regs->e_rc_frame_rate);
  986. }
  987. /* vbv buffer size */
  988. if (p->frame_skip_mode ==
  989. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  990. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  991. if (p->rc_frame)
  992. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  993. }
  994. /* Disable HEC */
  995. writel(0x0, mfc_regs->e_mpeg4_options);
  996. writel(0x0, mfc_regs->e_mpeg4_hec_period);
  997. mfc_debug_leave();
  998. return 0;
  999. }
  1000. static int s5p_mfc_set_enc_params_h263(struct s5p_mfc_ctx *ctx)
  1001. {
  1002. struct s5p_mfc_dev *dev = ctx->dev;
  1003. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1004. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1005. struct s5p_mfc_mpeg4_enc_params *p_h263 = &p->codec.mpeg4;
  1006. unsigned int reg = 0;
  1007. mfc_debug_enter();
  1008. s5p_mfc_set_enc_params(ctx);
  1009. /* profile & level */
  1010. reg = 0;
  1011. /** profile */
  1012. reg |= (0x1 << 4);
  1013. writel(reg, mfc_regs->e_picture_profile);
  1014. /* rate control config. */
  1015. reg = readl(mfc_regs->e_rc_config);
  1016. /** macroblock level rate control */
  1017. reg &= ~(0x1 << 8);
  1018. reg |= ((p->rc_mb & 0x1) << 8);
  1019. writel(reg, mfc_regs->e_rc_config);
  1020. /** frame QP */
  1021. reg &= ~(0x3F);
  1022. reg |= p_h263->rc_frame_qp & 0x3F;
  1023. writel(reg, mfc_regs->e_rc_config);
  1024. /* max & min value of QP */
  1025. reg = 0;
  1026. /** max QP */
  1027. reg |= ((p_h263->rc_max_qp & 0x3F) << 8);
  1028. /** min QP */
  1029. reg |= p_h263->rc_min_qp & 0x3F;
  1030. writel(reg, mfc_regs->e_rc_qp_bound);
  1031. /* other QPs */
  1032. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1033. if (!p->rc_frame && !p->rc_mb) {
  1034. reg = 0;
  1035. reg |= ((p_h263->rc_b_frame_qp & 0x3F) << 16);
  1036. reg |= ((p_h263->rc_p_frame_qp & 0x3F) << 8);
  1037. reg |= p_h263->rc_frame_qp & 0x3F;
  1038. writel(reg, mfc_regs->e_fixed_picture_qp);
  1039. }
  1040. /* frame rate */
  1041. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1042. reg = 0;
  1043. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1044. reg |= p->rc_framerate_denom & 0xFFFF;
  1045. writel(reg, mfc_regs->e_rc_frame_rate);
  1046. }
  1047. /* vbv buffer size */
  1048. if (p->frame_skip_mode ==
  1049. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1050. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1051. if (p->rc_frame)
  1052. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1053. }
  1054. mfc_debug_leave();
  1055. return 0;
  1056. }
  1057. static int s5p_mfc_set_enc_params_vp8(struct s5p_mfc_ctx *ctx)
  1058. {
  1059. struct s5p_mfc_dev *dev = ctx->dev;
  1060. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1061. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1062. struct s5p_mfc_vp8_enc_params *p_vp8 = &p->codec.vp8;
  1063. unsigned int reg = 0;
  1064. unsigned int val = 0;
  1065. mfc_debug_enter();
  1066. s5p_mfc_set_enc_params(ctx);
  1067. /* pictype : number of B */
  1068. reg = readl(mfc_regs->e_gop_config);
  1069. reg &= ~(0x3 << 16);
  1070. reg |= ((p->num_b_frame & 0x3) << 16);
  1071. writel(reg, mfc_regs->e_gop_config);
  1072. /* profile - 0 ~ 3 */
  1073. reg = p_vp8->profile & 0x3;
  1074. writel(reg, mfc_regs->e_picture_profile);
  1075. /* rate control config. */
  1076. reg = readl(mfc_regs->e_rc_config);
  1077. /** macroblock level rate control */
  1078. reg &= ~(0x1 << 8);
  1079. reg |= ((p->rc_mb & 0x1) << 8);
  1080. writel(reg, mfc_regs->e_rc_config);
  1081. /* frame rate */
  1082. if (p->rc_frame && p->rc_framerate_num && p->rc_framerate_denom) {
  1083. reg = 0;
  1084. reg |= ((p->rc_framerate_num & 0xFFFF) << 16);
  1085. reg |= p->rc_framerate_denom & 0xFFFF;
  1086. writel(reg, mfc_regs->e_rc_frame_rate);
  1087. }
  1088. /* frame QP */
  1089. reg &= ~(0x7F);
  1090. reg |= p_vp8->rc_frame_qp & 0x7F;
  1091. writel(reg, mfc_regs->e_rc_config);
  1092. /* other QPs */
  1093. writel(0x0, mfc_regs->e_fixed_picture_qp);
  1094. if (!p->rc_frame && !p->rc_mb) {
  1095. reg = 0;
  1096. reg |= ((p_vp8->rc_p_frame_qp & 0x7F) << 8);
  1097. reg |= p_vp8->rc_frame_qp & 0x7F;
  1098. writel(reg, mfc_regs->e_fixed_picture_qp);
  1099. }
  1100. /* max QP */
  1101. reg = ((p_vp8->rc_max_qp & 0x7F) << 8);
  1102. /* min QP */
  1103. reg |= p_vp8->rc_min_qp & 0x7F;
  1104. writel(reg, mfc_regs->e_rc_qp_bound);
  1105. /* vbv buffer size */
  1106. if (p->frame_skip_mode ==
  1107. V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT) {
  1108. writel(p->vbv_size & 0xFFFF, mfc_regs->e_vbv_buffer_size);
  1109. if (p->rc_frame)
  1110. writel(p->vbv_delay, mfc_regs->e_vbv_init_delay);
  1111. }
  1112. /* VP8 specific params */
  1113. reg = 0;
  1114. reg |= (p_vp8->imd_4x4 & 0x1) << 10;
  1115. switch (p_vp8->num_partitions) {
  1116. case V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION:
  1117. val = 0;
  1118. break;
  1119. case V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS:
  1120. val = 2;
  1121. break;
  1122. case V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS:
  1123. val = 4;
  1124. break;
  1125. case V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS:
  1126. val = 8;
  1127. break;
  1128. }
  1129. reg |= (val & 0xF) << 3;
  1130. reg |= (p_vp8->num_ref & 0x2);
  1131. writel(reg, mfc_regs->e_vp8_options);
  1132. mfc_debug_leave();
  1133. return 0;
  1134. }
  1135. /* Initialize decoding */
  1136. static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
  1137. {
  1138. struct s5p_mfc_dev *dev = ctx->dev;
  1139. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1140. unsigned int reg = 0;
  1141. int fmo_aso_ctrl = 0;
  1142. mfc_debug_enter();
  1143. mfc_debug(2, "InstNo: %d/%d\n", ctx->inst_no,
  1144. S5P_FIMV_CH_SEQ_HEADER_V6);
  1145. mfc_debug(2, "BUFs: %08x %08x %08x\n",
  1146. readl(mfc_regs->d_cpb_buffer_addr),
  1147. readl(mfc_regs->d_cpb_buffer_addr),
  1148. readl(mfc_regs->d_cpb_buffer_addr));
  1149. /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
  1150. reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
  1151. if (ctx->display_delay_enable) {
  1152. reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
  1153. writel(ctx->display_delay, mfc_regs->d_display_delay);
  1154. }
  1155. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev)) {
  1156. writel(reg, mfc_regs->d_dec_options);
  1157. reg = 0;
  1158. }
  1159. /* Setup loop filter, for decoding this is only valid for MPEG4 */
  1160. if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_DEC) {
  1161. mfc_debug(2, "Set loop filter to: %d\n",
  1162. ctx->loop_filter_mpeg4);
  1163. reg |= (ctx->loop_filter_mpeg4 <<
  1164. S5P_FIMV_D_OPT_LF_CTRL_SHIFT_V6);
  1165. }
  1166. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV12MT_16X16)
  1167. reg |= (0x1 << S5P_FIMV_D_OPT_TILE_MODE_SHIFT_V6);
  1168. if (IS_MFCV7_PLUS(dev) || IS_MFCV6_V2(dev))
  1169. writel(reg, mfc_regs->d_init_buffer_options);
  1170. else
  1171. writel(reg, mfc_regs->d_dec_options);
  1172. /* 0: NV12(CbCr), 1: NV21(CrCb) */
  1173. if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_NV21M)
  1174. writel(0x1, mfc_regs->pixel_format);
  1175. else
  1176. writel(0x0, mfc_regs->pixel_format);
  1177. /* sei parse */
  1178. writel(ctx->sei_fp_parse & 0x1, mfc_regs->d_sei_enable);
  1179. writel(ctx->inst_no, mfc_regs->instance_id);
  1180. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1181. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1182. mfc_debug_leave();
  1183. return 0;
  1184. }
  1185. static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
  1186. {
  1187. struct s5p_mfc_dev *dev = ctx->dev;
  1188. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1189. if (flush) {
  1190. dev->curr_ctx = ctx->num;
  1191. writel(ctx->inst_no, mfc_regs->instance_id);
  1192. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1193. S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
  1194. }
  1195. }
  1196. /* Decode a single frame */
  1197. static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx,
  1198. enum s5p_mfc_decode_arg last_frame)
  1199. {
  1200. struct s5p_mfc_dev *dev = ctx->dev;
  1201. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1202. writel(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower);
  1203. writel(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable);
  1204. writel(ctx->inst_no, mfc_regs->instance_id);
  1205. /* Issue different commands to instance basing on whether it
  1206. * is the last frame or not. */
  1207. switch (last_frame) {
  1208. case 0:
  1209. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1210. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1211. break;
  1212. case 1:
  1213. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1214. S5P_FIMV_CH_LAST_FRAME_V6, NULL);
  1215. break;
  1216. default:
  1217. mfc_err("Unsupported last frame arg.\n");
  1218. return -EINVAL;
  1219. }
  1220. mfc_debug(2, "Decoding a usual frame.\n");
  1221. return 0;
  1222. }
  1223. static int s5p_mfc_init_encode_v6(struct s5p_mfc_ctx *ctx)
  1224. {
  1225. struct s5p_mfc_dev *dev = ctx->dev;
  1226. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1227. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1228. s5p_mfc_set_enc_params_h264(ctx);
  1229. else if (ctx->codec_mode == S5P_MFC_CODEC_MPEG4_ENC)
  1230. s5p_mfc_set_enc_params_mpeg4(ctx);
  1231. else if (ctx->codec_mode == S5P_MFC_CODEC_H263_ENC)
  1232. s5p_mfc_set_enc_params_h263(ctx);
  1233. else if (ctx->codec_mode == S5P_MFC_CODEC_VP8_ENC)
  1234. s5p_mfc_set_enc_params_vp8(ctx);
  1235. else {
  1236. mfc_err("Unknown codec for encoding (%x).\n",
  1237. ctx->codec_mode);
  1238. return -EINVAL;
  1239. }
  1240. /* Set stride lengths for v7 & above */
  1241. if (IS_MFCV7_PLUS(dev)) {
  1242. writel(ctx->img_width, mfc_regs->e_source_first_plane_stride);
  1243. writel(ctx->img_width, mfc_regs->e_source_second_plane_stride);
  1244. }
  1245. writel(ctx->inst_no, mfc_regs->instance_id);
  1246. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1247. S5P_FIMV_CH_SEQ_HEADER_V6, NULL);
  1248. return 0;
  1249. }
  1250. static int s5p_mfc_h264_set_aso_slice_order_v6(struct s5p_mfc_ctx *ctx)
  1251. {
  1252. struct s5p_mfc_dev *dev = ctx->dev;
  1253. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1254. struct s5p_mfc_enc_params *p = &ctx->enc_params;
  1255. struct s5p_mfc_h264_enc_params *p_h264 = &p->codec.h264;
  1256. int i;
  1257. if (p_h264->aso) {
  1258. for (i = 0; i < ARRAY_SIZE(p_h264->aso_slice_order); i++) {
  1259. writel(p_h264->aso_slice_order[i],
  1260. mfc_regs->e_h264_aso_slice_order_0 + i * 4);
  1261. }
  1262. }
  1263. return 0;
  1264. }
  1265. /* Encode a single frame */
  1266. static int s5p_mfc_encode_one_frame_v6(struct s5p_mfc_ctx *ctx)
  1267. {
  1268. struct s5p_mfc_dev *dev = ctx->dev;
  1269. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1270. mfc_debug(2, "++\n");
  1271. /* memory structure cur. frame */
  1272. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1273. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1274. s5p_mfc_set_slice_mode(ctx);
  1275. writel(ctx->inst_no, mfc_regs->instance_id);
  1276. s5p_mfc_hw_call_void(dev->mfc_cmds, cmd_host2risc, dev,
  1277. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1278. mfc_debug(2, "--\n");
  1279. return 0;
  1280. }
  1281. static inline int s5p_mfc_get_new_ctx(struct s5p_mfc_dev *dev)
  1282. {
  1283. unsigned long flags;
  1284. int new_ctx;
  1285. int cnt;
  1286. spin_lock_irqsave(&dev->condlock, flags);
  1287. mfc_debug(2, "Previous context: %d (bits %08lx)\n", dev->curr_ctx,
  1288. dev->ctx_work_bits);
  1289. new_ctx = (dev->curr_ctx + 1) % MFC_NUM_CONTEXTS;
  1290. cnt = 0;
  1291. while (!test_bit(new_ctx, &dev->ctx_work_bits)) {
  1292. new_ctx = (new_ctx + 1) % MFC_NUM_CONTEXTS;
  1293. cnt++;
  1294. if (cnt > MFC_NUM_CONTEXTS) {
  1295. /* No contexts to run */
  1296. spin_unlock_irqrestore(&dev->condlock, flags);
  1297. return -EAGAIN;
  1298. }
  1299. }
  1300. spin_unlock_irqrestore(&dev->condlock, flags);
  1301. return new_ctx;
  1302. }
  1303. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1304. {
  1305. struct s5p_mfc_dev *dev = ctx->dev;
  1306. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1307. dev->curr_ctx = ctx->num;
  1308. s5p_mfc_decode_one_frame_v6(ctx, MFC_DEC_LAST_FRAME);
  1309. }
  1310. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1311. {
  1312. struct s5p_mfc_dev *dev = ctx->dev;
  1313. struct s5p_mfc_buf *temp_vb;
  1314. unsigned long flags;
  1315. int last_frame = 0;
  1316. if (ctx->state == MFCINST_FINISHING) {
  1317. last_frame = MFC_DEC_LAST_FRAME;
  1318. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1319. dev->curr_ctx = ctx->num;
  1320. s5p_mfc_clean_ctx_int_flags(ctx);
  1321. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1322. return 0;
  1323. }
  1324. spin_lock_irqsave(&dev->irqlock, flags);
  1325. /* Frames are being decoded */
  1326. if (list_empty(&ctx->src_queue)) {
  1327. mfc_debug(2, "No src buffers.\n");
  1328. spin_unlock_irqrestore(&dev->irqlock, flags);
  1329. return -EAGAIN;
  1330. }
  1331. /* Get the next source buffer */
  1332. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1333. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1334. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1335. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
  1336. ctx->consumed_stream,
  1337. temp_vb->b->v4l2_planes[0].bytesused);
  1338. spin_unlock_irqrestore(&dev->irqlock, flags);
  1339. dev->curr_ctx = ctx->num;
  1340. if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
  1341. last_frame = 1;
  1342. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1343. ctx->state = MFCINST_FINISHING;
  1344. }
  1345. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1346. return 0;
  1347. }
  1348. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1349. {
  1350. struct s5p_mfc_dev *dev = ctx->dev;
  1351. unsigned long flags;
  1352. struct s5p_mfc_buf *dst_mb;
  1353. struct s5p_mfc_buf *src_mb;
  1354. unsigned long src_y_addr, src_c_addr, dst_addr;
  1355. /*
  1356. unsigned int src_y_size, src_c_size;
  1357. */
  1358. unsigned int dst_size;
  1359. spin_lock_irqsave(&dev->irqlock, flags);
  1360. if (list_empty(&ctx->src_queue)) {
  1361. mfc_debug(2, "no src buffers.\n");
  1362. spin_unlock_irqrestore(&dev->irqlock, flags);
  1363. return -EAGAIN;
  1364. }
  1365. if (list_empty(&ctx->dst_queue)) {
  1366. mfc_debug(2, "no dst buffers.\n");
  1367. spin_unlock_irqrestore(&dev->irqlock, flags);
  1368. return -EAGAIN;
  1369. }
  1370. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1371. src_mb->flags |= MFC_BUF_FLAG_USED;
  1372. src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
  1373. src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
  1374. mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
  1375. mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
  1376. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1377. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1378. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1379. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1380. dst_size = vb2_plane_size(dst_mb->b, 0);
  1381. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1382. spin_unlock_irqrestore(&dev->irqlock, flags);
  1383. dev->curr_ctx = ctx->num;
  1384. s5p_mfc_encode_one_frame_v6(ctx);
  1385. return 0;
  1386. }
  1387. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1388. {
  1389. struct s5p_mfc_dev *dev = ctx->dev;
  1390. unsigned long flags;
  1391. struct s5p_mfc_buf *temp_vb;
  1392. /* Initializing decoding - parsing header */
  1393. spin_lock_irqsave(&dev->irqlock, flags);
  1394. mfc_debug(2, "Preparing to init decoding.\n");
  1395. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1396. mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
  1397. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1398. vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
  1399. temp_vb->b->v4l2_planes[0].bytesused);
  1400. spin_unlock_irqrestore(&dev->irqlock, flags);
  1401. dev->curr_ctx = ctx->num;
  1402. s5p_mfc_init_decode_v6(ctx);
  1403. }
  1404. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1405. {
  1406. struct s5p_mfc_dev *dev = ctx->dev;
  1407. unsigned long flags;
  1408. struct s5p_mfc_buf *dst_mb;
  1409. unsigned long dst_addr;
  1410. unsigned int dst_size;
  1411. spin_lock_irqsave(&dev->irqlock, flags);
  1412. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1413. dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
  1414. dst_size = vb2_plane_size(dst_mb->b, 0);
  1415. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1416. spin_unlock_irqrestore(&dev->irqlock, flags);
  1417. dev->curr_ctx = ctx->num;
  1418. s5p_mfc_init_encode_v6(ctx);
  1419. }
  1420. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1421. {
  1422. struct s5p_mfc_dev *dev = ctx->dev;
  1423. int ret;
  1424. /* Header was parsed now start processing
  1425. * First set the output frame buffers
  1426. * s5p_mfc_alloc_dec_buffers(ctx); */
  1427. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1428. mfc_err("It seems that not all destionation buffers were\n"
  1429. "mmaped.MFC requires that all destination are mmaped\n"
  1430. "before starting processing.\n");
  1431. return -EAGAIN;
  1432. }
  1433. dev->curr_ctx = ctx->num;
  1434. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1435. if (ret) {
  1436. mfc_err("Failed to alloc frame mem.\n");
  1437. ctx->state = MFCINST_ERROR;
  1438. }
  1439. return ret;
  1440. }
  1441. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1442. {
  1443. struct s5p_mfc_dev *dev = ctx->dev;
  1444. int ret;
  1445. dev->curr_ctx = ctx->num;
  1446. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1447. if (ret) {
  1448. mfc_err("Failed to alloc frame mem.\n");
  1449. ctx->state = MFCINST_ERROR;
  1450. }
  1451. return ret;
  1452. }
  1453. /* Try running an operation on hardware */
  1454. static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1455. {
  1456. struct s5p_mfc_ctx *ctx;
  1457. int new_ctx;
  1458. unsigned int ret = 0;
  1459. mfc_debug(1, "Try run dev: %p\n", dev);
  1460. /* Check whether hardware is not running */
  1461. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1462. /* This is perfectly ok, the scheduled ctx should wait */
  1463. mfc_debug(1, "Couldn't lock HW.\n");
  1464. return;
  1465. }
  1466. /* Choose the context to run */
  1467. new_ctx = s5p_mfc_get_new_ctx(dev);
  1468. if (new_ctx < 0) {
  1469. /* No contexts to run */
  1470. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1471. mfc_err("Failed to unlock hardware.\n");
  1472. return;
  1473. }
  1474. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1475. return;
  1476. }
  1477. mfc_debug(1, "New context: %d\n", new_ctx);
  1478. ctx = dev->ctx[new_ctx];
  1479. mfc_debug(1, "Seting new context to %p\n", ctx);
  1480. /* Got context to run in ctx */
  1481. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1482. ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
  1483. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1484. /* Last frame has already been sent to MFC
  1485. * Now obtaining frames from MFC buffer */
  1486. s5p_mfc_clock_on();
  1487. s5p_mfc_clean_ctx_int_flags(ctx);
  1488. if (ctx->type == MFCINST_DECODER) {
  1489. switch (ctx->state) {
  1490. case MFCINST_FINISHING:
  1491. s5p_mfc_run_dec_last_frames(ctx);
  1492. break;
  1493. case MFCINST_RUNNING:
  1494. ret = s5p_mfc_run_dec_frame(ctx);
  1495. break;
  1496. case MFCINST_INIT:
  1497. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1498. ctx);
  1499. break;
  1500. case MFCINST_RETURN_INST:
  1501. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1502. ctx);
  1503. break;
  1504. case MFCINST_GOT_INST:
  1505. s5p_mfc_run_init_dec(ctx);
  1506. break;
  1507. case MFCINST_HEAD_PARSED:
  1508. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1509. break;
  1510. case MFCINST_FLUSH:
  1511. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  1512. break;
  1513. case MFCINST_RES_CHANGE_INIT:
  1514. s5p_mfc_run_dec_last_frames(ctx);
  1515. break;
  1516. case MFCINST_RES_CHANGE_FLUSH:
  1517. s5p_mfc_run_dec_last_frames(ctx);
  1518. break;
  1519. case MFCINST_RES_CHANGE_END:
  1520. mfc_debug(2, "Finished remaining frames after resolution change.\n");
  1521. ctx->capture_state = QUEUE_FREE;
  1522. mfc_debug(2, "Will re-init the codec`.\n");
  1523. s5p_mfc_run_init_dec(ctx);
  1524. break;
  1525. default:
  1526. ret = -EAGAIN;
  1527. }
  1528. } else if (ctx->type == MFCINST_ENCODER) {
  1529. switch (ctx->state) {
  1530. case MFCINST_FINISHING:
  1531. case MFCINST_RUNNING:
  1532. ret = s5p_mfc_run_enc_frame(ctx);
  1533. break;
  1534. case MFCINST_INIT:
  1535. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1536. ctx);
  1537. break;
  1538. case MFCINST_RETURN_INST:
  1539. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1540. ctx);
  1541. break;
  1542. case MFCINST_GOT_INST:
  1543. s5p_mfc_run_init_enc(ctx);
  1544. break;
  1545. case MFCINST_HEAD_PRODUCED:
  1546. ret = s5p_mfc_run_init_enc_buffers(ctx);
  1547. break;
  1548. default:
  1549. ret = -EAGAIN;
  1550. }
  1551. } else {
  1552. mfc_err("invalid context type: %d\n", ctx->type);
  1553. ret = -EAGAIN;
  1554. }
  1555. if (ret) {
  1556. /* Free hardware lock */
  1557. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1558. mfc_err("Failed to unlock hardware.\n");
  1559. /* This is in deed imporant, as no operation has been
  1560. * scheduled, reduce the clock count as no one will
  1561. * ever do this, because no interrupt related to this try_run
  1562. * will ever come from hardware. */
  1563. s5p_mfc_clock_off();
  1564. }
  1565. }
  1566. static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
  1567. {
  1568. struct s5p_mfc_buf *b;
  1569. int i;
  1570. while (!list_empty(lh)) {
  1571. b = list_entry(lh->next, struct s5p_mfc_buf, list);
  1572. for (i = 0; i < b->b->num_planes; i++)
  1573. vb2_set_plane_payload(b->b, i, 0);
  1574. vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
  1575. list_del(&b->list);
  1576. }
  1577. }
  1578. static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
  1579. {
  1580. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1581. writel(0, mfc_regs->risc2host_command);
  1582. writel(0, mfc_regs->risc2host_int);
  1583. }
  1584. static void s5p_mfc_write_info_v6(struct s5p_mfc_ctx *ctx, unsigned int data,
  1585. unsigned int ofs)
  1586. {
  1587. s5p_mfc_clock_on();
  1588. writel(data, (void *)((unsigned long)ofs));
  1589. s5p_mfc_clock_off();
  1590. }
  1591. static unsigned int
  1592. s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned long ofs)
  1593. {
  1594. int ret;
  1595. s5p_mfc_clock_on();
  1596. ret = readl((void *)ofs);
  1597. s5p_mfc_clock_off();
  1598. return ret;
  1599. }
  1600. static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
  1601. {
  1602. return readl(dev->mfc_regs->d_display_first_plane_addr);
  1603. }
  1604. static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
  1605. {
  1606. return readl(dev->mfc_regs->d_decoded_first_plane_addr);
  1607. }
  1608. static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
  1609. {
  1610. return readl(dev->mfc_regs->d_display_status);
  1611. }
  1612. static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
  1613. {
  1614. return readl(dev->mfc_regs->d_decoded_status);
  1615. }
  1616. static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
  1617. {
  1618. return readl(dev->mfc_regs->d_decoded_frame_type) &
  1619. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1620. }
  1621. static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
  1622. {
  1623. struct s5p_mfc_dev *dev = ctx->dev;
  1624. return readl(dev->mfc_regs->d_display_frame_type) &
  1625. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1626. }
  1627. static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
  1628. {
  1629. return readl(dev->mfc_regs->d_decoded_nal_size);
  1630. }
  1631. static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
  1632. {
  1633. return readl(dev->mfc_regs->risc2host_command) &
  1634. S5P_FIMV_RISC2HOST_CMD_MASK;
  1635. }
  1636. static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
  1637. {
  1638. return readl(dev->mfc_regs->error_code);
  1639. }
  1640. static int s5p_mfc_err_dec_v6(unsigned int err)
  1641. {
  1642. return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
  1643. }
  1644. static int s5p_mfc_err_dspl_v6(unsigned int err)
  1645. {
  1646. return (err & S5P_FIMV_ERR_DSPL_MASK_V6) >> S5P_FIMV_ERR_DSPL_SHIFT_V6;
  1647. }
  1648. static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
  1649. {
  1650. return readl(dev->mfc_regs->d_display_frame_width);
  1651. }
  1652. static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
  1653. {
  1654. return readl(dev->mfc_regs->d_display_frame_height);
  1655. }
  1656. static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
  1657. {
  1658. return readl(dev->mfc_regs->d_min_num_dpb);
  1659. }
  1660. static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
  1661. {
  1662. return readl(dev->mfc_regs->d_min_num_mv);
  1663. }
  1664. static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
  1665. {
  1666. return readl(dev->mfc_regs->ret_instance_id);
  1667. }
  1668. static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
  1669. {
  1670. return readl(dev->mfc_regs->e_num_dpb);
  1671. }
  1672. static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
  1673. {
  1674. return readl(dev->mfc_regs->e_stream_size);
  1675. }
  1676. static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
  1677. {
  1678. return readl(dev->mfc_regs->e_slice_type);
  1679. }
  1680. static int s5p_mfc_get_enc_pic_count_v6(struct s5p_mfc_dev *dev)
  1681. {
  1682. return readl(dev->mfc_regs->e_picture_count);
  1683. }
  1684. static int s5p_mfc_get_sei_avail_status_v6(struct s5p_mfc_ctx *ctx)
  1685. {
  1686. struct s5p_mfc_dev *dev = ctx->dev;
  1687. return readl(dev->mfc_regs->d_frame_pack_sei_avail);
  1688. }
  1689. static int s5p_mfc_get_mvc_num_views_v6(struct s5p_mfc_dev *dev)
  1690. {
  1691. return readl(dev->mfc_regs->d_mvc_num_views);
  1692. }
  1693. static int s5p_mfc_get_mvc_view_id_v6(struct s5p_mfc_dev *dev)
  1694. {
  1695. return readl(dev->mfc_regs->d_mvc_view_id);
  1696. }
  1697. static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
  1698. {
  1699. return s5p_mfc_read_info_v6(ctx,
  1700. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_top);
  1701. }
  1702. static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
  1703. {
  1704. return s5p_mfc_read_info_v6(ctx,
  1705. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
  1706. }
  1707. static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
  1708. {
  1709. return s5p_mfc_read_info_v6(ctx,
  1710. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info1);
  1711. }
  1712. static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
  1713. {
  1714. return s5p_mfc_read_info_v6(ctx,
  1715. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info2);
  1716. }
  1717. static struct s5p_mfc_regs mfc_regs;
  1718. /* Initialize registers for MFC v6 onwards */
  1719. const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
  1720. {
  1721. memset(&mfc_regs, 0, sizeof(mfc_regs));
  1722. #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
  1723. #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
  1724. /* codec common registers */
  1725. R(risc_on, S5P_FIMV_RISC_ON_V6);
  1726. R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
  1727. R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
  1728. R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
  1729. R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
  1730. R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
  1731. R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
  1732. R(firmware_version, S5P_FIMV_FW_VERSION_V6);
  1733. R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
  1734. R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
  1735. R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
  1736. R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
  1737. R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
  1738. R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
  1739. R(error_code, S5P_FIMV_ERROR_CODE_V6);
  1740. /* decoder registers */
  1741. R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
  1742. R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
  1743. R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
  1744. R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
  1745. R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
  1746. R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
  1747. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
  1748. R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
  1749. R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
  1750. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
  1751. R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
  1752. R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
  1753. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
  1754. R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
  1755. R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
  1756. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
  1757. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
  1758. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
  1759. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
  1760. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
  1761. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1762. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
  1763. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1764. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
  1765. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
  1766. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
  1767. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
  1768. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
  1769. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
  1770. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
  1771. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
  1772. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
  1773. R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
  1774. R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
  1775. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
  1776. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
  1777. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
  1778. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
  1779. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
  1780. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
  1781. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
  1782. R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
  1783. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
  1784. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
  1785. /* encoder registers */
  1786. R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
  1787. R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
  1788. R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
  1789. R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  1790. R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
  1791. R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
  1792. R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
  1793. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  1794. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  1795. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  1796. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
  1797. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
  1798. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
  1799. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
  1800. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
  1801. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
  1802. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
  1803. R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
  1804. R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
  1805. R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
  1806. R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
  1807. R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
  1808. R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
  1809. R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
  1810. R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
  1811. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
  1812. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
  1813. R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
  1814. R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
  1815. R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
  1816. R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
  1817. R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
  1818. R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
  1819. R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
  1820. R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  1821. R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  1822. R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
  1823. R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
  1824. R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
  1825. R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
  1826. R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
  1827. R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
  1828. R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
  1829. R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
  1830. R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
  1831. R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
  1832. R(e_encoded_source_first_plane_addr,
  1833. S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
  1834. R(e_encoded_source_second_plane_addr,
  1835. S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
  1836. R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
  1837. R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
  1838. R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
  1839. R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
  1840. R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
  1841. R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
  1842. R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
  1843. R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
  1844. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
  1845. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
  1846. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
  1847. R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
  1848. R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
  1849. R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
  1850. R(e_h264_fmo_slice_grp_map_type,
  1851. S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
  1852. R(e_h264_fmo_num_slice_grp_minus1,
  1853. S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  1854. R(e_h264_fmo_slice_grp_change_dir,
  1855. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
  1856. R(e_h264_fmo_slice_grp_change_rate_minus1,
  1857. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
  1858. R(e_h264_fmo_run_length_minus1_0,
  1859. S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
  1860. R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
  1861. R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  1862. R(e_h264_hierarchical_qp_layer0,
  1863. S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
  1864. R(e_h264_frame_packing_sei_info,
  1865. S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
  1866. if (!IS_MFCV7_PLUS(dev))
  1867. goto done;
  1868. /* Initialize registers used in MFC v7+ */
  1869. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
  1870. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
  1871. R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
  1872. R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
  1873. R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
  1874. R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
  1875. R(e_encoded_source_first_plane_addr,
  1876. S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
  1877. R(e_encoded_source_second_plane_addr,
  1878. S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
  1879. R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
  1880. if (!IS_MFCV8(dev))
  1881. goto done;
  1882. /* Initialize registers used in MFC v8 only.
  1883. * Also, over-write the registers which have
  1884. * a different offset for MFC v8. */
  1885. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
  1886. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
  1887. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
  1888. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
  1889. R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
  1890. R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
  1891. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
  1892. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
  1893. R(d_first_plane_dpb_stride_size,
  1894. S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
  1895. R(d_second_plane_dpb_stride_size,
  1896. S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
  1897. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
  1898. R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
  1899. R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
  1900. R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
  1901. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
  1902. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
  1903. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
  1904. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
  1905. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
  1906. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
  1907. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
  1908. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
  1909. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
  1910. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
  1911. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
  1912. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
  1913. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
  1914. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
  1915. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
  1916. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
  1917. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
  1918. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
  1919. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
  1920. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
  1921. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
  1922. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
  1923. /* encoder registers */
  1924. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
  1925. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
  1926. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
  1927. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
  1928. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
  1929. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
  1930. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
  1931. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
  1932. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
  1933. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
  1934. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
  1935. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
  1936. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
  1937. done:
  1938. return &mfc_regs;
  1939. #undef S5P_MFC_REG_ADDR
  1940. #undef R
  1941. }
  1942. /* Initialize opr function pointers for MFC v6 */
  1943. static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
  1944. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
  1945. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
  1946. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
  1947. .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
  1948. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
  1949. .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
  1950. .alloc_dev_context_buffer =
  1951. s5p_mfc_alloc_dev_context_buffer_v6,
  1952. .release_dev_context_buffer =
  1953. s5p_mfc_release_dev_context_buffer_v6,
  1954. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
  1955. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
  1956. .set_dec_stream_buffer = s5p_mfc_set_dec_stream_buffer_v6,
  1957. .set_dec_frame_buffer = s5p_mfc_set_dec_frame_buffer_v6,
  1958. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
  1959. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
  1960. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
  1961. .set_enc_ref_buffer = s5p_mfc_set_enc_ref_buffer_v6,
  1962. .init_decode = s5p_mfc_init_decode_v6,
  1963. .init_encode = s5p_mfc_init_encode_v6,
  1964. .encode_one_frame = s5p_mfc_encode_one_frame_v6,
  1965. .try_run = s5p_mfc_try_run_v6,
  1966. .cleanup_queue = s5p_mfc_cleanup_queue_v6,
  1967. .clear_int_flags = s5p_mfc_clear_int_flags_v6,
  1968. .write_info = s5p_mfc_write_info_v6,
  1969. .read_info = s5p_mfc_read_info_v6,
  1970. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
  1971. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
  1972. .get_dspl_status = s5p_mfc_get_dspl_status_v6,
  1973. .get_dec_status = s5p_mfc_get_dec_status_v6,
  1974. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
  1975. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
  1976. .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
  1977. .get_int_reason = s5p_mfc_get_int_reason_v6,
  1978. .get_int_err = s5p_mfc_get_int_err_v6,
  1979. .err_dec = s5p_mfc_err_dec_v6,
  1980. .err_dspl = s5p_mfc_err_dspl_v6,
  1981. .get_img_width = s5p_mfc_get_img_width_v6,
  1982. .get_img_height = s5p_mfc_get_img_height_v6,
  1983. .get_dpb_count = s5p_mfc_get_dpb_count_v6,
  1984. .get_mv_count = s5p_mfc_get_mv_count_v6,
  1985. .get_inst_no = s5p_mfc_get_inst_no_v6,
  1986. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
  1987. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
  1988. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
  1989. .get_enc_pic_count = s5p_mfc_get_enc_pic_count_v6,
  1990. .get_sei_avail_status = s5p_mfc_get_sei_avail_status_v6,
  1991. .get_mvc_num_views = s5p_mfc_get_mvc_num_views_v6,
  1992. .get_mvc_view_id = s5p_mfc_get_mvc_view_id_v6,
  1993. .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
  1994. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
  1995. .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
  1996. .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
  1997. };
  1998. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
  1999. {
  2000. return &s5p_mfc_ops_v6;
  2001. }