s5p_mfc_opr_v6.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224
  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_generic_buf(dev, BANK_L_CTX, &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_generic_buf(ctx->dev, &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, BANK_L_CTX, &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, &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, BANK_L_CTX, &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, &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: %zx, 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(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%x\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 y_addr: 0x%08lx\n", enc_recon_y_addr, *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(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(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(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(dev->mfc_cmds, cmd_host2risc, dev,
  1210. S5P_FIMV_CH_FRAME_START_V6, NULL);
  1211. break;
  1212. case 1:
  1213. s5p_mfc_hw_call(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(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. int cmd;
  1271. mfc_debug(2, "++\n");
  1272. /* memory structure cur. frame */
  1273. if (ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
  1274. s5p_mfc_h264_set_aso_slice_order_v6(ctx);
  1275. s5p_mfc_set_slice_mode(ctx);
  1276. if (ctx->state != MFCINST_FINISHING)
  1277. cmd = S5P_FIMV_CH_FRAME_START_V6;
  1278. else
  1279. cmd = S5P_FIMV_CH_LAST_FRAME_V6;
  1280. writel(ctx->inst_no, mfc_regs->instance_id);
  1281. s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev, cmd, NULL);
  1282. mfc_debug(2, "--\n");
  1283. return 0;
  1284. }
  1285. static inline void s5p_mfc_run_dec_last_frames(struct s5p_mfc_ctx *ctx)
  1286. {
  1287. struct s5p_mfc_dev *dev = ctx->dev;
  1288. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1289. dev->curr_ctx = ctx->num;
  1290. s5p_mfc_decode_one_frame_v6(ctx, MFC_DEC_LAST_FRAME);
  1291. }
  1292. static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
  1293. {
  1294. struct s5p_mfc_dev *dev = ctx->dev;
  1295. struct s5p_mfc_buf *temp_vb;
  1296. int last_frame = 0;
  1297. if (ctx->state == MFCINST_FINISHING) {
  1298. last_frame = MFC_DEC_LAST_FRAME;
  1299. s5p_mfc_set_dec_stream_buffer_v6(ctx, 0, 0, 0);
  1300. dev->curr_ctx = ctx->num;
  1301. s5p_mfc_clean_ctx_int_flags(ctx);
  1302. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1303. return 0;
  1304. }
  1305. /* Frames are being decoded */
  1306. if (list_empty(&ctx->src_queue)) {
  1307. mfc_debug(2, "No src buffers.\n");
  1308. return -EAGAIN;
  1309. }
  1310. /* Get the next source buffer */
  1311. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1312. temp_vb->flags |= MFC_BUF_FLAG_USED;
  1313. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1314. vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
  1315. ctx->consumed_stream,
  1316. temp_vb->b->vb2_buf.planes[0].bytesused);
  1317. dev->curr_ctx = ctx->num;
  1318. if (temp_vb->b->vb2_buf.planes[0].bytesused == 0) {
  1319. last_frame = 1;
  1320. mfc_debug(2, "Setting ctx->state to FINISHING\n");
  1321. ctx->state = MFCINST_FINISHING;
  1322. }
  1323. s5p_mfc_decode_one_frame_v6(ctx, last_frame);
  1324. return 0;
  1325. }
  1326. static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
  1327. {
  1328. struct s5p_mfc_dev *dev = ctx->dev;
  1329. struct s5p_mfc_buf *dst_mb;
  1330. struct s5p_mfc_buf *src_mb;
  1331. unsigned long src_y_addr, src_c_addr, dst_addr;
  1332. /*
  1333. unsigned int src_y_size, src_c_size;
  1334. */
  1335. unsigned int dst_size;
  1336. if (list_empty(&ctx->src_queue) && ctx->state != MFCINST_FINISHING) {
  1337. mfc_debug(2, "no src buffers.\n");
  1338. return -EAGAIN;
  1339. }
  1340. if (list_empty(&ctx->dst_queue)) {
  1341. mfc_debug(2, "no dst buffers.\n");
  1342. return -EAGAIN;
  1343. }
  1344. if (list_empty(&ctx->src_queue)) {
  1345. /* send null frame */
  1346. s5p_mfc_set_enc_frame_buffer_v6(ctx, 0, 0);
  1347. src_mb = NULL;
  1348. } else {
  1349. src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1350. src_mb->flags |= MFC_BUF_FLAG_USED;
  1351. if (src_mb->b->vb2_buf.planes[0].bytesused == 0) {
  1352. s5p_mfc_set_enc_frame_buffer_v6(ctx, 0, 0);
  1353. ctx->state = MFCINST_FINISHING;
  1354. } else {
  1355. src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0);
  1356. src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1);
  1357. mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
  1358. mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
  1359. s5p_mfc_set_enc_frame_buffer_v6(ctx, src_y_addr, src_c_addr);
  1360. if (src_mb->flags & MFC_BUF_FLAG_EOS)
  1361. ctx->state = MFCINST_FINISHING;
  1362. }
  1363. }
  1364. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1365. dst_mb->flags |= MFC_BUF_FLAG_USED;
  1366. dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
  1367. dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
  1368. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1369. dev->curr_ctx = ctx->num;
  1370. s5p_mfc_encode_one_frame_v6(ctx);
  1371. return 0;
  1372. }
  1373. static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
  1374. {
  1375. struct s5p_mfc_dev *dev = ctx->dev;
  1376. struct s5p_mfc_buf *temp_vb;
  1377. /* Initializing decoding - parsing header */
  1378. mfc_debug(2, "Preparing to init decoding.\n");
  1379. temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
  1380. mfc_debug(2, "Header size: %d\n", temp_vb->b->vb2_buf.planes[0].bytesused);
  1381. s5p_mfc_set_dec_stream_buffer_v6(ctx,
  1382. vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0), 0,
  1383. temp_vb->b->vb2_buf.planes[0].bytesused);
  1384. dev->curr_ctx = ctx->num;
  1385. s5p_mfc_init_decode_v6(ctx);
  1386. }
  1387. static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
  1388. {
  1389. struct s5p_mfc_dev *dev = ctx->dev;
  1390. struct s5p_mfc_buf *dst_mb;
  1391. unsigned long dst_addr;
  1392. unsigned int dst_size;
  1393. dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
  1394. dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
  1395. dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
  1396. s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
  1397. dev->curr_ctx = ctx->num;
  1398. s5p_mfc_init_encode_v6(ctx);
  1399. }
  1400. static inline int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
  1401. {
  1402. struct s5p_mfc_dev *dev = ctx->dev;
  1403. int ret;
  1404. /* Header was parsed now start processing
  1405. * First set the output frame buffers
  1406. * s5p_mfc_alloc_dec_buffers(ctx); */
  1407. if (ctx->capture_state != QUEUE_BUFS_MMAPED) {
  1408. mfc_err("It seems that not all destionation buffers were\n"
  1409. "mmaped.MFC requires that all destination are mmaped\n"
  1410. "before starting processing.\n");
  1411. return -EAGAIN;
  1412. }
  1413. dev->curr_ctx = ctx->num;
  1414. ret = s5p_mfc_set_dec_frame_buffer_v6(ctx);
  1415. if (ret) {
  1416. mfc_err("Failed to alloc frame mem.\n");
  1417. ctx->state = MFCINST_ERROR;
  1418. }
  1419. return ret;
  1420. }
  1421. static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
  1422. {
  1423. struct s5p_mfc_dev *dev = ctx->dev;
  1424. int ret;
  1425. dev->curr_ctx = ctx->num;
  1426. ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
  1427. if (ret) {
  1428. mfc_err("Failed to alloc frame mem.\n");
  1429. ctx->state = MFCINST_ERROR;
  1430. }
  1431. return ret;
  1432. }
  1433. /* Try running an operation on hardware */
  1434. static void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
  1435. {
  1436. struct s5p_mfc_ctx *ctx;
  1437. int new_ctx;
  1438. unsigned int ret = 0;
  1439. mfc_debug(1, "Try run dev: %p\n", dev);
  1440. /* Check whether hardware is not running */
  1441. if (test_and_set_bit(0, &dev->hw_lock) != 0) {
  1442. /* This is perfectly ok, the scheduled ctx should wait */
  1443. mfc_debug(1, "Couldn't lock HW.\n");
  1444. return;
  1445. }
  1446. /* Choose the context to run */
  1447. new_ctx = s5p_mfc_get_new_ctx(dev);
  1448. if (new_ctx < 0) {
  1449. /* No contexts to run */
  1450. if (test_and_clear_bit(0, &dev->hw_lock) == 0) {
  1451. mfc_err("Failed to unlock hardware.\n");
  1452. return;
  1453. }
  1454. mfc_debug(1, "No ctx is scheduled to be run.\n");
  1455. return;
  1456. }
  1457. mfc_debug(1, "New context: %d\n", new_ctx);
  1458. ctx = dev->ctx[new_ctx];
  1459. mfc_debug(1, "Setting new context to %p\n", ctx);
  1460. /* Got context to run in ctx */
  1461. mfc_debug(1, "ctx->dst_queue_cnt=%d ctx->dpb_count=%d ctx->src_queue_cnt=%d\n",
  1462. ctx->dst_queue_cnt, ctx->pb_count, ctx->src_queue_cnt);
  1463. mfc_debug(1, "ctx->state=%d\n", ctx->state);
  1464. /* Last frame has already been sent to MFC
  1465. * Now obtaining frames from MFC buffer */
  1466. s5p_mfc_clock_on();
  1467. s5p_mfc_clean_ctx_int_flags(ctx);
  1468. if (ctx->type == MFCINST_DECODER) {
  1469. switch (ctx->state) {
  1470. case MFCINST_FINISHING:
  1471. s5p_mfc_run_dec_last_frames(ctx);
  1472. break;
  1473. case MFCINST_RUNNING:
  1474. ret = s5p_mfc_run_dec_frame(ctx);
  1475. break;
  1476. case MFCINST_INIT:
  1477. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1478. ctx);
  1479. break;
  1480. case MFCINST_RETURN_INST:
  1481. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1482. ctx);
  1483. break;
  1484. case MFCINST_GOT_INST:
  1485. s5p_mfc_run_init_dec(ctx);
  1486. break;
  1487. case MFCINST_HEAD_PARSED:
  1488. ret = s5p_mfc_run_init_dec_buffers(ctx);
  1489. break;
  1490. case MFCINST_FLUSH:
  1491. s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
  1492. break;
  1493. case MFCINST_RES_CHANGE_INIT:
  1494. s5p_mfc_run_dec_last_frames(ctx);
  1495. break;
  1496. case MFCINST_RES_CHANGE_FLUSH:
  1497. s5p_mfc_run_dec_last_frames(ctx);
  1498. break;
  1499. case MFCINST_RES_CHANGE_END:
  1500. mfc_debug(2, "Finished remaining frames after resolution change.\n");
  1501. ctx->capture_state = QUEUE_FREE;
  1502. mfc_debug(2, "Will re-init the codec`.\n");
  1503. s5p_mfc_run_init_dec(ctx);
  1504. break;
  1505. default:
  1506. ret = -EAGAIN;
  1507. }
  1508. } else if (ctx->type == MFCINST_ENCODER) {
  1509. switch (ctx->state) {
  1510. case MFCINST_FINISHING:
  1511. case MFCINST_RUNNING:
  1512. ret = s5p_mfc_run_enc_frame(ctx);
  1513. break;
  1514. case MFCINST_INIT:
  1515. ret = s5p_mfc_hw_call(dev->mfc_cmds, open_inst_cmd,
  1516. ctx);
  1517. break;
  1518. case MFCINST_RETURN_INST:
  1519. ret = s5p_mfc_hw_call(dev->mfc_cmds, close_inst_cmd,
  1520. ctx);
  1521. break;
  1522. case MFCINST_GOT_INST:
  1523. s5p_mfc_run_init_enc(ctx);
  1524. break;
  1525. case MFCINST_HEAD_PRODUCED:
  1526. ret = s5p_mfc_run_init_enc_buffers(ctx);
  1527. break;
  1528. default:
  1529. ret = -EAGAIN;
  1530. }
  1531. } else {
  1532. mfc_err("invalid context type: %d\n", ctx->type);
  1533. ret = -EAGAIN;
  1534. }
  1535. if (ret) {
  1536. /* Free hardware lock */
  1537. if (test_and_clear_bit(0, &dev->hw_lock) == 0)
  1538. mfc_err("Failed to unlock hardware.\n");
  1539. /* This is in deed imporant, as no operation has been
  1540. * scheduled, reduce the clock count as no one will
  1541. * ever do this, because no interrupt related to this try_run
  1542. * will ever come from hardware. */
  1543. s5p_mfc_clock_off();
  1544. }
  1545. }
  1546. static void s5p_mfc_clear_int_flags_v6(struct s5p_mfc_dev *dev)
  1547. {
  1548. const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs;
  1549. writel(0, mfc_regs->risc2host_command);
  1550. writel(0, mfc_regs->risc2host_int);
  1551. }
  1552. static unsigned int
  1553. s5p_mfc_read_info_v6(struct s5p_mfc_ctx *ctx, unsigned long ofs)
  1554. {
  1555. int ret;
  1556. s5p_mfc_clock_on();
  1557. ret = readl((void __iomem *)ofs);
  1558. s5p_mfc_clock_off();
  1559. return ret;
  1560. }
  1561. static int s5p_mfc_get_dspl_y_adr_v6(struct s5p_mfc_dev *dev)
  1562. {
  1563. return readl(dev->mfc_regs->d_display_first_plane_addr);
  1564. }
  1565. static int s5p_mfc_get_dec_y_adr_v6(struct s5p_mfc_dev *dev)
  1566. {
  1567. return readl(dev->mfc_regs->d_decoded_first_plane_addr);
  1568. }
  1569. static int s5p_mfc_get_dspl_status_v6(struct s5p_mfc_dev *dev)
  1570. {
  1571. return readl(dev->mfc_regs->d_display_status);
  1572. }
  1573. static int s5p_mfc_get_dec_status_v6(struct s5p_mfc_dev *dev)
  1574. {
  1575. return readl(dev->mfc_regs->d_decoded_status);
  1576. }
  1577. static int s5p_mfc_get_dec_frame_type_v6(struct s5p_mfc_dev *dev)
  1578. {
  1579. return readl(dev->mfc_regs->d_decoded_frame_type) &
  1580. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1581. }
  1582. static int s5p_mfc_get_disp_frame_type_v6(struct s5p_mfc_ctx *ctx)
  1583. {
  1584. struct s5p_mfc_dev *dev = ctx->dev;
  1585. return readl(dev->mfc_regs->d_display_frame_type) &
  1586. S5P_FIMV_DECODE_FRAME_MASK_V6;
  1587. }
  1588. static int s5p_mfc_get_consumed_stream_v6(struct s5p_mfc_dev *dev)
  1589. {
  1590. return readl(dev->mfc_regs->d_decoded_nal_size);
  1591. }
  1592. static int s5p_mfc_get_int_reason_v6(struct s5p_mfc_dev *dev)
  1593. {
  1594. return readl(dev->mfc_regs->risc2host_command) &
  1595. S5P_FIMV_RISC2HOST_CMD_MASK;
  1596. }
  1597. static int s5p_mfc_get_int_err_v6(struct s5p_mfc_dev *dev)
  1598. {
  1599. return readl(dev->mfc_regs->error_code);
  1600. }
  1601. static int s5p_mfc_err_dec_v6(unsigned int err)
  1602. {
  1603. return (err & S5P_FIMV_ERR_DEC_MASK_V6) >> S5P_FIMV_ERR_DEC_SHIFT_V6;
  1604. }
  1605. static int s5p_mfc_get_img_width_v6(struct s5p_mfc_dev *dev)
  1606. {
  1607. return readl(dev->mfc_regs->d_display_frame_width);
  1608. }
  1609. static int s5p_mfc_get_img_height_v6(struct s5p_mfc_dev *dev)
  1610. {
  1611. return readl(dev->mfc_regs->d_display_frame_height);
  1612. }
  1613. static int s5p_mfc_get_dpb_count_v6(struct s5p_mfc_dev *dev)
  1614. {
  1615. return readl(dev->mfc_regs->d_min_num_dpb);
  1616. }
  1617. static int s5p_mfc_get_mv_count_v6(struct s5p_mfc_dev *dev)
  1618. {
  1619. return readl(dev->mfc_regs->d_min_num_mv);
  1620. }
  1621. static int s5p_mfc_get_inst_no_v6(struct s5p_mfc_dev *dev)
  1622. {
  1623. return readl(dev->mfc_regs->ret_instance_id);
  1624. }
  1625. static int s5p_mfc_get_enc_dpb_count_v6(struct s5p_mfc_dev *dev)
  1626. {
  1627. return readl(dev->mfc_regs->e_num_dpb);
  1628. }
  1629. static int s5p_mfc_get_enc_strm_size_v6(struct s5p_mfc_dev *dev)
  1630. {
  1631. return readl(dev->mfc_regs->e_stream_size);
  1632. }
  1633. static int s5p_mfc_get_enc_slice_type_v6(struct s5p_mfc_dev *dev)
  1634. {
  1635. return readl(dev->mfc_regs->e_slice_type);
  1636. }
  1637. static unsigned int s5p_mfc_get_pic_type_top_v6(struct s5p_mfc_ctx *ctx)
  1638. {
  1639. return s5p_mfc_read_info_v6(ctx,
  1640. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_top);
  1641. }
  1642. static unsigned int s5p_mfc_get_pic_type_bot_v6(struct s5p_mfc_ctx *ctx)
  1643. {
  1644. return s5p_mfc_read_info_v6(ctx,
  1645. (__force unsigned long) ctx->dev->mfc_regs->d_ret_picture_tag_bot);
  1646. }
  1647. static unsigned int s5p_mfc_get_crop_info_h_v6(struct s5p_mfc_ctx *ctx)
  1648. {
  1649. return s5p_mfc_read_info_v6(ctx,
  1650. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info1);
  1651. }
  1652. static unsigned int s5p_mfc_get_crop_info_v_v6(struct s5p_mfc_ctx *ctx)
  1653. {
  1654. return s5p_mfc_read_info_v6(ctx,
  1655. (__force unsigned long) ctx->dev->mfc_regs->d_display_crop_info2);
  1656. }
  1657. static struct s5p_mfc_regs mfc_regs;
  1658. /* Initialize registers for MFC v6 onwards */
  1659. const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev)
  1660. {
  1661. memset(&mfc_regs, 0, sizeof(mfc_regs));
  1662. #define S5P_MFC_REG_ADDR(dev, reg) ((dev)->regs_base + (reg))
  1663. #define R(m, r) mfc_regs.m = S5P_MFC_REG_ADDR(dev, r)
  1664. /* codec common registers */
  1665. R(risc_on, S5P_FIMV_RISC_ON_V6);
  1666. R(risc2host_int, S5P_FIMV_RISC2HOST_INT_V6);
  1667. R(host2risc_int, S5P_FIMV_HOST2RISC_INT_V6);
  1668. R(risc_base_address, S5P_FIMV_RISC_BASE_ADDRESS_V6);
  1669. R(mfc_reset, S5P_FIMV_MFC_RESET_V6);
  1670. R(host2risc_command, S5P_FIMV_HOST2RISC_CMD_V6);
  1671. R(risc2host_command, S5P_FIMV_RISC2HOST_CMD_V6);
  1672. R(firmware_version, S5P_FIMV_FW_VERSION_V6);
  1673. R(instance_id, S5P_FIMV_INSTANCE_ID_V6);
  1674. R(codec_type, S5P_FIMV_CODEC_TYPE_V6);
  1675. R(context_mem_addr, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
  1676. R(context_mem_size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
  1677. R(pixel_format, S5P_FIMV_PIXEL_FORMAT_V6);
  1678. R(ret_instance_id, S5P_FIMV_RET_INSTANCE_ID_V6);
  1679. R(error_code, S5P_FIMV_ERROR_CODE_V6);
  1680. /* decoder registers */
  1681. R(d_crc_ctrl, S5P_FIMV_D_CRC_CTRL_V6);
  1682. R(d_dec_options, S5P_FIMV_D_DEC_OPTIONS_V6);
  1683. R(d_display_delay, S5P_FIMV_D_DISPLAY_DELAY_V6);
  1684. R(d_sei_enable, S5P_FIMV_D_SEI_ENABLE_V6);
  1685. R(d_min_num_dpb, S5P_FIMV_D_MIN_NUM_DPB_V6);
  1686. R(d_min_num_mv, S5P_FIMV_D_MIN_NUM_MV_V6);
  1687. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V6);
  1688. R(d_num_dpb, S5P_FIMV_D_NUM_DPB_V6);
  1689. R(d_num_mv, S5P_FIMV_D_NUM_MV_V6);
  1690. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V6);
  1691. R(d_first_plane_dpb_size, S5P_FIMV_D_LUMA_DPB_SIZE_V6);
  1692. R(d_second_plane_dpb_size, S5P_FIMV_D_CHROMA_DPB_SIZE_V6);
  1693. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V6);
  1694. R(d_first_plane_dpb, S5P_FIMV_D_LUMA_DPB_V6);
  1695. R(d_second_plane_dpb, S5P_FIMV_D_CHROMA_DPB_V6);
  1696. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V6);
  1697. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V6);
  1698. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V6);
  1699. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V6);
  1700. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V6);
  1701. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V6);
  1702. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V6);
  1703. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V6);
  1704. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V6);
  1705. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V6);
  1706. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V6);
  1707. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V6);
  1708. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_LUMA_ADDR_V6);
  1709. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_CHROMA_ADDR_V6);
  1710. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V6);
  1711. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V6);
  1712. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V6);
  1713. R(d_display_aspect_ratio, S5P_FIMV_D_DISPLAY_ASPECT_RATIO_V6);
  1714. R(d_display_extended_ar, S5P_FIMV_D_DISPLAY_EXTENDED_AR_V6);
  1715. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V6);
  1716. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_LUMA_ADDR_V6);
  1717. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_CHROMA_ADDR_V6);
  1718. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V6);
  1719. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V6);
  1720. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V6);
  1721. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V6);
  1722. R(d_h264_info, S5P_FIMV_D_H264_INFO_V6);
  1723. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V6);
  1724. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V6);
  1725. /* encoder registers */
  1726. R(e_frame_width, S5P_FIMV_E_FRAME_WIDTH_V6);
  1727. R(e_frame_height, S5P_FIMV_E_FRAME_HEIGHT_V6);
  1728. R(e_cropped_frame_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6);
  1729. R(e_cropped_frame_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6);
  1730. R(e_frame_crop_offset, S5P_FIMV_E_FRAME_CROP_OFFSET_V6);
  1731. R(e_enc_options, S5P_FIMV_E_ENC_OPTIONS_V6);
  1732. R(e_picture_profile, S5P_FIMV_E_PICTURE_PROFILE_V6);
  1733. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V6);
  1734. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V6);
  1735. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V6);
  1736. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V6);
  1737. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V6);
  1738. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V6);
  1739. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V6);
  1740. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V6);
  1741. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V6);
  1742. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V6);
  1743. R(e_num_dpb, S5P_FIMV_E_NUM_DPB_V6);
  1744. R(e_luma_dpb, S5P_FIMV_E_LUMA_DPB_V6);
  1745. R(e_chroma_dpb, S5P_FIMV_E_CHROMA_DPB_V6);
  1746. R(e_me_buffer, S5P_FIMV_E_ME_BUFFER_V6);
  1747. R(e_scratch_buffer_addr, S5P_FIMV_E_SCRATCH_BUFFER_ADDR_V6);
  1748. R(e_scratch_buffer_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE_V6);
  1749. R(e_tmv_buffer0, S5P_FIMV_E_TMV_BUFFER0_V6);
  1750. R(e_tmv_buffer1, S5P_FIMV_E_TMV_BUFFER1_V6);
  1751. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_LUMA_ADDR_V6);
  1752. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_CHROMA_ADDR_V6);
  1753. R(e_stream_buffer_addr, S5P_FIMV_E_STREAM_BUFFER_ADDR_V6);
  1754. R(e_stream_buffer_size, S5P_FIMV_E_STREAM_BUFFER_SIZE_V6);
  1755. R(e_roi_buffer_addr, S5P_FIMV_E_ROI_BUFFER_ADDR_V6);
  1756. R(e_param_change, S5P_FIMV_E_PARAM_CHANGE_V6);
  1757. R(e_ir_size, S5P_FIMV_E_IR_SIZE_V6);
  1758. R(e_gop_config, S5P_FIMV_E_GOP_CONFIG_V6);
  1759. R(e_mslice_mode, S5P_FIMV_E_MSLICE_MODE_V6);
  1760. R(e_mslice_size_mb, S5P_FIMV_E_MSLICE_SIZE_MB_V6);
  1761. R(e_mslice_size_bits, S5P_FIMV_E_MSLICE_SIZE_BITS_V6);
  1762. R(e_frame_insertion, S5P_FIMV_E_FRAME_INSERTION_V6);
  1763. R(e_rc_frame_rate, S5P_FIMV_E_RC_FRAME_RATE_V6);
  1764. R(e_rc_bit_rate, S5P_FIMV_E_RC_BIT_RATE_V6);
  1765. R(e_rc_roi_ctrl, S5P_FIMV_E_RC_ROI_CTRL_V6);
  1766. R(e_picture_tag, S5P_FIMV_E_PICTURE_TAG_V6);
  1767. R(e_bit_count_enable, S5P_FIMV_E_BIT_COUNT_ENABLE_V6);
  1768. R(e_max_bit_count, S5P_FIMV_E_MAX_BIT_COUNT_V6);
  1769. R(e_min_bit_count, S5P_FIMV_E_MIN_BIT_COUNT_V6);
  1770. R(e_metadata_buffer_addr, S5P_FIMV_E_METADATA_BUFFER_ADDR_V6);
  1771. R(e_metadata_buffer_size, S5P_FIMV_E_METADATA_BUFFER_SIZE_V6);
  1772. R(e_encoded_source_first_plane_addr,
  1773. S5P_FIMV_E_ENCODED_SOURCE_LUMA_ADDR_V6);
  1774. R(e_encoded_source_second_plane_addr,
  1775. S5P_FIMV_E_ENCODED_SOURCE_CHROMA_ADDR_V6);
  1776. R(e_stream_size, S5P_FIMV_E_STREAM_SIZE_V6);
  1777. R(e_slice_type, S5P_FIMV_E_SLICE_TYPE_V6);
  1778. R(e_picture_count, S5P_FIMV_E_PICTURE_COUNT_V6);
  1779. R(e_ret_picture_tag, S5P_FIMV_E_RET_PICTURE_TAG_V6);
  1780. R(e_recon_luma_dpb_addr, S5P_FIMV_E_RECON_LUMA_DPB_ADDR_V6);
  1781. R(e_recon_chroma_dpb_addr, S5P_FIMV_E_RECON_CHROMA_DPB_ADDR_V6);
  1782. R(e_mpeg4_options, S5P_FIMV_E_MPEG4_OPTIONS_V6);
  1783. R(e_mpeg4_hec_period, S5P_FIMV_E_MPEG4_HEC_PERIOD_V6);
  1784. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V6);
  1785. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V6);
  1786. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V6);
  1787. R(e_h264_lf_alpha_offset, S5P_FIMV_E_H264_LF_ALPHA_OFFSET_V6);
  1788. R(e_h264_lf_beta_offset, S5P_FIMV_E_H264_LF_BETA_OFFSET_V6);
  1789. R(e_h264_i_period, S5P_FIMV_E_H264_I_PERIOD_V6);
  1790. R(e_h264_fmo_slice_grp_map_type,
  1791. S5P_FIMV_E_H264_FMO_SLICE_GRP_MAP_TYPE_V6);
  1792. R(e_h264_fmo_num_slice_grp_minus1,
  1793. S5P_FIMV_E_H264_FMO_NUM_SLICE_GRP_MINUS1_V6);
  1794. R(e_h264_fmo_slice_grp_change_dir,
  1795. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_DIR_V6);
  1796. R(e_h264_fmo_slice_grp_change_rate_minus1,
  1797. S5P_FIMV_E_H264_FMO_SLICE_GRP_CHANGE_RATE_MINUS1_V6);
  1798. R(e_h264_fmo_run_length_minus1_0,
  1799. S5P_FIMV_E_H264_FMO_RUN_LENGTH_MINUS1_0_V6);
  1800. R(e_h264_aso_slice_order_0, S5P_FIMV_E_H264_ASO_SLICE_ORDER_0_V6);
  1801. R(e_h264_num_t_layer, S5P_FIMV_E_H264_NUM_T_LAYER_V6);
  1802. R(e_h264_hierarchical_qp_layer0,
  1803. S5P_FIMV_E_H264_HIERARCHICAL_QP_LAYER0_V6);
  1804. R(e_h264_frame_packing_sei_info,
  1805. S5P_FIMV_E_H264_FRAME_PACKING_SEI_INFO_V6);
  1806. if (!IS_MFCV7_PLUS(dev))
  1807. goto done;
  1808. /* Initialize registers used in MFC v7+ */
  1809. R(e_source_first_plane_addr, S5P_FIMV_E_SOURCE_FIRST_ADDR_V7);
  1810. R(e_source_second_plane_addr, S5P_FIMV_E_SOURCE_SECOND_ADDR_V7);
  1811. R(e_source_third_plane_addr, S5P_FIMV_E_SOURCE_THIRD_ADDR_V7);
  1812. R(e_source_first_plane_stride, S5P_FIMV_E_SOURCE_FIRST_STRIDE_V7);
  1813. R(e_source_second_plane_stride, S5P_FIMV_E_SOURCE_SECOND_STRIDE_V7);
  1814. R(e_source_third_plane_stride, S5P_FIMV_E_SOURCE_THIRD_STRIDE_V7);
  1815. R(e_encoded_source_first_plane_addr,
  1816. S5P_FIMV_E_ENCODED_SOURCE_FIRST_ADDR_V7);
  1817. R(e_encoded_source_second_plane_addr,
  1818. S5P_FIMV_E_ENCODED_SOURCE_SECOND_ADDR_V7);
  1819. R(e_vp8_options, S5P_FIMV_E_VP8_OPTIONS_V7);
  1820. if (!IS_MFCV8(dev))
  1821. goto done;
  1822. /* Initialize registers used in MFC v8 only.
  1823. * Also, over-write the registers which have
  1824. * a different offset for MFC v8. */
  1825. R(d_stream_data_size, S5P_FIMV_D_STREAM_DATA_SIZE_V8);
  1826. R(d_cpb_buffer_addr, S5P_FIMV_D_CPB_BUFFER_ADDR_V8);
  1827. R(d_cpb_buffer_size, S5P_FIMV_D_CPB_BUFFER_SIZE_V8);
  1828. R(d_cpb_buffer_offset, S5P_FIMV_D_CPB_BUFFER_OFFSET_V8);
  1829. R(d_first_plane_dpb_size, S5P_FIMV_D_FIRST_PLANE_DPB_SIZE_V8);
  1830. R(d_second_plane_dpb_size, S5P_FIMV_D_SECOND_PLANE_DPB_SIZE_V8);
  1831. R(d_scratch_buffer_addr, S5P_FIMV_D_SCRATCH_BUFFER_ADDR_V8);
  1832. R(d_scratch_buffer_size, S5P_FIMV_D_SCRATCH_BUFFER_SIZE_V8);
  1833. R(d_first_plane_dpb_stride_size,
  1834. S5P_FIMV_D_FIRST_PLANE_DPB_STRIDE_SIZE_V8);
  1835. R(d_second_plane_dpb_stride_size,
  1836. S5P_FIMV_D_SECOND_PLANE_DPB_STRIDE_SIZE_V8);
  1837. R(d_mv_buffer_size, S5P_FIMV_D_MV_BUFFER_SIZE_V8);
  1838. R(d_num_mv, S5P_FIMV_D_NUM_MV_V8);
  1839. R(d_first_plane_dpb, S5P_FIMV_D_FIRST_PLANE_DPB_V8);
  1840. R(d_second_plane_dpb, S5P_FIMV_D_SECOND_PLANE_DPB_V8);
  1841. R(d_mv_buffer, S5P_FIMV_D_MV_BUFFER_V8);
  1842. R(d_init_buffer_options, S5P_FIMV_D_INIT_BUFFER_OPTIONS_V8);
  1843. R(d_available_dpb_flag_lower, S5P_FIMV_D_AVAILABLE_DPB_FLAG_LOWER_V8);
  1844. R(d_slice_if_enable, S5P_FIMV_D_SLICE_IF_ENABLE_V8);
  1845. R(d_display_first_plane_addr, S5P_FIMV_D_DISPLAY_FIRST_PLANE_ADDR_V8);
  1846. R(d_display_second_plane_addr, S5P_FIMV_D_DISPLAY_SECOND_PLANE_ADDR_V8);
  1847. R(d_decoded_first_plane_addr, S5P_FIMV_D_DECODED_FIRST_PLANE_ADDR_V8);
  1848. R(d_decoded_second_plane_addr, S5P_FIMV_D_DECODED_SECOND_PLANE_ADDR_V8);
  1849. R(d_display_status, S5P_FIMV_D_DISPLAY_STATUS_V8);
  1850. R(d_decoded_status, S5P_FIMV_D_DECODED_STATUS_V8);
  1851. R(d_decoded_frame_type, S5P_FIMV_D_DECODED_FRAME_TYPE_V8);
  1852. R(d_display_frame_type, S5P_FIMV_D_DISPLAY_FRAME_TYPE_V8);
  1853. R(d_decoded_nal_size, S5P_FIMV_D_DECODED_NAL_SIZE_V8);
  1854. R(d_display_frame_width, S5P_FIMV_D_DISPLAY_FRAME_WIDTH_V8);
  1855. R(d_display_frame_height, S5P_FIMV_D_DISPLAY_FRAME_HEIGHT_V8);
  1856. R(d_frame_pack_sei_avail, S5P_FIMV_D_FRAME_PACK_SEI_AVAIL_V8);
  1857. R(d_mvc_num_views, S5P_FIMV_D_MVC_NUM_VIEWS_V8);
  1858. R(d_mvc_view_id, S5P_FIMV_D_MVC_VIEW_ID_V8);
  1859. R(d_ret_picture_tag_top, S5P_FIMV_D_RET_PICTURE_TAG_TOP_V8);
  1860. R(d_ret_picture_tag_bot, S5P_FIMV_D_RET_PICTURE_TAG_BOT_V8);
  1861. R(d_display_crop_info1, S5P_FIMV_D_DISPLAY_CROP_INFO1_V8);
  1862. R(d_display_crop_info2, S5P_FIMV_D_DISPLAY_CROP_INFO2_V8);
  1863. /* encoder registers */
  1864. R(e_padding_ctrl, S5P_FIMV_E_PADDING_CTRL_V8);
  1865. R(e_rc_config, S5P_FIMV_E_RC_CONFIG_V8);
  1866. R(e_rc_mode, S5P_FIMV_E_RC_RPARAM_V8);
  1867. R(e_mv_hor_range, S5P_FIMV_E_MV_HOR_RANGE_V8);
  1868. R(e_mv_ver_range, S5P_FIMV_E_MV_VER_RANGE_V8);
  1869. R(e_rc_qp_bound, S5P_FIMV_E_RC_QP_BOUND_V8);
  1870. R(e_fixed_picture_qp, S5P_FIMV_E_FIXED_PICTURE_QP_V8);
  1871. R(e_vbv_buffer_size, S5P_FIMV_E_VBV_BUFFER_SIZE_V8);
  1872. R(e_vbv_init_delay, S5P_FIMV_E_VBV_INIT_DELAY_V8);
  1873. R(e_mb_rc_config, S5P_FIMV_E_MB_RC_CONFIG_V8);
  1874. R(e_aspect_ratio, S5P_FIMV_E_ASPECT_RATIO_V8);
  1875. R(e_extended_sar, S5P_FIMV_E_EXTENDED_SAR_V8);
  1876. R(e_h264_options, S5P_FIMV_E_H264_OPTIONS_V8);
  1877. done:
  1878. return &mfc_regs;
  1879. #undef S5P_MFC_REG_ADDR
  1880. #undef R
  1881. }
  1882. /* Initialize opr function pointers for MFC v6 */
  1883. static struct s5p_mfc_hw_ops s5p_mfc_ops_v6 = {
  1884. .alloc_dec_temp_buffers = s5p_mfc_alloc_dec_temp_buffers_v6,
  1885. .release_dec_desc_buffer = s5p_mfc_release_dec_desc_buffer_v6,
  1886. .alloc_codec_buffers = s5p_mfc_alloc_codec_buffers_v6,
  1887. .release_codec_buffers = s5p_mfc_release_codec_buffers_v6,
  1888. .alloc_instance_buffer = s5p_mfc_alloc_instance_buffer_v6,
  1889. .release_instance_buffer = s5p_mfc_release_instance_buffer_v6,
  1890. .alloc_dev_context_buffer =
  1891. s5p_mfc_alloc_dev_context_buffer_v6,
  1892. .release_dev_context_buffer =
  1893. s5p_mfc_release_dev_context_buffer_v6,
  1894. .dec_calc_dpb_size = s5p_mfc_dec_calc_dpb_size_v6,
  1895. .enc_calc_src_size = s5p_mfc_enc_calc_src_size_v6,
  1896. .set_enc_stream_buffer = s5p_mfc_set_enc_stream_buffer_v6,
  1897. .set_enc_frame_buffer = s5p_mfc_set_enc_frame_buffer_v6,
  1898. .get_enc_frame_buffer = s5p_mfc_get_enc_frame_buffer_v6,
  1899. .try_run = s5p_mfc_try_run_v6,
  1900. .clear_int_flags = s5p_mfc_clear_int_flags_v6,
  1901. .get_dspl_y_adr = s5p_mfc_get_dspl_y_adr_v6,
  1902. .get_dec_y_adr = s5p_mfc_get_dec_y_adr_v6,
  1903. .get_dspl_status = s5p_mfc_get_dspl_status_v6,
  1904. .get_dec_status = s5p_mfc_get_dec_status_v6,
  1905. .get_dec_frame_type = s5p_mfc_get_dec_frame_type_v6,
  1906. .get_disp_frame_type = s5p_mfc_get_disp_frame_type_v6,
  1907. .get_consumed_stream = s5p_mfc_get_consumed_stream_v6,
  1908. .get_int_reason = s5p_mfc_get_int_reason_v6,
  1909. .get_int_err = s5p_mfc_get_int_err_v6,
  1910. .err_dec = s5p_mfc_err_dec_v6,
  1911. .get_img_width = s5p_mfc_get_img_width_v6,
  1912. .get_img_height = s5p_mfc_get_img_height_v6,
  1913. .get_dpb_count = s5p_mfc_get_dpb_count_v6,
  1914. .get_mv_count = s5p_mfc_get_mv_count_v6,
  1915. .get_inst_no = s5p_mfc_get_inst_no_v6,
  1916. .get_enc_strm_size = s5p_mfc_get_enc_strm_size_v6,
  1917. .get_enc_slice_type = s5p_mfc_get_enc_slice_type_v6,
  1918. .get_enc_dpb_count = s5p_mfc_get_enc_dpb_count_v6,
  1919. .get_pic_type_top = s5p_mfc_get_pic_type_top_v6,
  1920. .get_pic_type_bot = s5p_mfc_get_pic_type_bot_v6,
  1921. .get_crop_info_h = s5p_mfc_get_crop_info_h_v6,
  1922. .get_crop_info_v = s5p_mfc_get_crop_info_v_v6,
  1923. };
  1924. struct s5p_mfc_hw_ops *s5p_mfc_init_hw_ops_v6(void)
  1925. {
  1926. return &s5p_mfc_ops_v6;
  1927. }