sde_hw_sspp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_lm.h"
  9. #include "sde_hw_sspp.h"
  10. #include "sde_hw_color_processing.h"
  11. #include "sde_dbg.h"
  12. #include "sde_kms.h"
  13. #include "sde_hw_reg_dma_v1_color_proc.h"
  14. #include "sde_hw_vbif.h"
  15. #define SDE_FETCH_CONFIG_RESET_VALUE 0x00000087
  16. /* SDE_SSPP_SRC */
  17. #define SSPP_SRC_SIZE 0x00
  18. #define SSPP_SRC_XY 0x08
  19. #define SSPP_OUT_SIZE 0x0c
  20. #define SSPP_OUT_XY 0x10
  21. #define SSPP_SRC0_ADDR 0x14
  22. #define SSPP_SRC1_ADDR 0x18
  23. #define SSPP_SRC2_ADDR 0x1C
  24. #define SSPP_SRC3_ADDR 0x20
  25. #define SSPP_SRC_YSTRIDE0 0x24
  26. #define SSPP_SRC_YSTRIDE1 0x28
  27. #define SSPP_SRC_FORMAT 0x30
  28. #define SSPP_SRC_UNPACK_PATTERN 0x34
  29. #define SSPP_SRC_OP_MODE 0x38
  30. /* SSPP_MULTIRECT*/
  31. #define SSPP_SRC_SIZE_REC1 0x16C
  32. #define SSPP_SRC_XY_REC1 0x168
  33. #define SSPP_OUT_SIZE_REC1 0x160
  34. #define SSPP_OUT_XY_REC1 0x164
  35. #define SSPP_SRC_FORMAT_REC1 0x174
  36. #define SSPP_SRC_UNPACK_PATTERN_REC1 0x178
  37. #define SSPP_SRC_OP_MODE_REC1 0x17C
  38. #define SSPP_MULTIRECT_OPMODE 0x170
  39. #define SSPP_SRC_CONSTANT_COLOR_REC1 0x180
  40. #define SSPP_EXCL_REC_SIZE_REC1 0x184
  41. #define SSPP_EXCL_REC_XY_REC1 0x188
  42. #define SSPP_UIDLE_CTRL_VALUE 0x1f0
  43. #define SSPP_UIDLE_CTRL_VALUE_REC1 0x1f4
  44. #define SSPP_FILL_LEVEL_SCALE 0x1f8
  45. /* SSPP_DGM */
  46. #define SSPP_DGM_0 0x9F0
  47. #define SSPP_DGM_1 0x19F0
  48. #define SSPP_DGM_SIZE 0x420
  49. #define SSPP_DGM_CSC_0 0x800
  50. #define SSPP_DGM_CSC_1 0x1800
  51. #define SSPP_DGM_CSC_SIZE 0xFC
  52. #define VIG_GAMUT_SIZE 0x1CC
  53. #define MDSS_MDP_OP_DEINTERLACE BIT(22)
  54. #define MDSS_MDP_OP_DEINTERLACE_ODD BIT(23)
  55. #define MDSS_MDP_OP_IGC_ROM_1 BIT(18)
  56. #define MDSS_MDP_OP_IGC_ROM_0 BIT(17)
  57. #define MDSS_MDP_OP_IGC_EN BIT(16)
  58. #define MDSS_MDP_OP_FLIP_UD BIT(14)
  59. #define MDSS_MDP_OP_FLIP_LR BIT(13)
  60. #define MDSS_MDP_OP_SPLIT_ORDER BIT(4)
  61. #define MDSS_MDP_OP_BWC_EN BIT(0)
  62. #define MDSS_MDP_OP_PE_OVERRIDE BIT(31)
  63. #define MDSS_MDP_OP_BWC_LOSSLESS (0 << 1)
  64. #define MDSS_MDP_OP_BWC_Q_HIGH (1 << 1)
  65. #define MDSS_MDP_OP_BWC_Q_MED (2 << 1)
  66. #define SSPP_SRC_CONSTANT_COLOR 0x3c
  67. #define SSPP_EXCL_REC_CTL 0x40
  68. #define SSPP_UBWC_STATIC_CTRL 0x44
  69. #define SSPP_FETCH_CONFIG 0x48
  70. #define SSPP_PRE_DOWN_SCALE 0x50
  71. #define SSPP_DANGER_LUT 0x60
  72. #define SSPP_SAFE_LUT 0x64
  73. #define SSPP_CREQ_LUT 0x68
  74. #define SSPP_QOS_CTRL 0x6C
  75. #define SSPP_DECIMATION_CONFIG 0xB4
  76. #define SSPP_SRC_ADDR_SW_STATUS 0x70
  77. #define SSPP_CREQ_LUT_0 0x74
  78. #define SSPP_CREQ_LUT_1 0x78
  79. #define SSPP_UBWC_STATS_ROI 0x7C
  80. #define SSPP_UBWC_STATS_DATA 0x80
  81. #define SSPP_UBWC_STATS_ROI_REC1 0xB4
  82. #define SSPP_UBWC_STATS_DATA_REC1 0xB8
  83. #define SSPP_SW_PIX_EXT_C0_LR 0x100
  84. #define SSPP_SW_PIX_EXT_C0_TB 0x104
  85. #define SSPP_SW_PIX_EXT_C0_REQ_PIXELS 0x108
  86. #define SSPP_SW_PIX_EXT_C1C2_LR 0x110
  87. #define SSPP_SW_PIX_EXT_C1C2_TB 0x114
  88. #define SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS 0x118
  89. #define SSPP_SW_PIX_EXT_C3_LR 0x120
  90. #define SSPP_SW_PIX_EXT_C3_TB 0x124
  91. #define SSPP_SW_PIX_EXT_C3_REQ_PIXELS 0x128
  92. #define SSPP_META_ERROR_STATUS 0X12C
  93. #define SSPP_TRAFFIC_SHAPER 0x130
  94. #define SSPP_CDP_CNTL 0x134
  95. #define SSPP_UBWC_ERROR_STATUS 0x138
  96. #define SSPP_CDP_CNTL_REC1 0x13c
  97. #define SSPP_TRAFFIC_SHAPER_PREFILL 0x150
  98. #define SSPP_TRAFFIC_SHAPER_REC1_PREFILL 0x154
  99. #define SSPP_TRAFFIC_SHAPER_REC1 0x158
  100. #define SSPP_EXCL_REC_SIZE 0x1B4
  101. #define SSPP_EXCL_REC_XY 0x1B8
  102. #define SSPP_UBWC_STATIC_CTRL_REC1 0x1C0
  103. #define SSPP_UBWC_ERROR_STATUS_REC1 0x1C8
  104. #define SSPP_META_ERROR_STATUS_REC1 0x1C4
  105. #define SSPP_VIG_OP_MODE 0x0
  106. #define SSPP_VIG_CSC_10_OP_MODE 0x0
  107. #define SSPP_TRAFFIC_SHAPER_BPC_MAX 0xFF
  108. #define SSPP_CLK_CTRL 0x330
  109. #define SSPP_CLK_STATUS 0x334
  110. /* SSPP_QOS_CTRL */
  111. #define SSPP_QOS_CTRL_VBLANK_EN BIT(16)
  112. #define SSPP_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  113. #define SSPP_QOS_CTRL_DANGER_VBLANK_MASK 0x3
  114. #define SSPP_QOS_CTRL_DANGER_VBLANK_OFF 4
  115. #define SSPP_QOS_CTRL_CREQ_VBLANK_MASK 0x3
  116. #define SSPP_QOS_CTRL_CREQ_VBLANK_OFF 20
  117. #define SSPP_SYS_CACHE_MODE 0x1BC
  118. #define SSPP_SBUF_STATUS_PLANE0 0x1C0
  119. #define SSPP_SBUF_STATUS_PLANE1 0x1C4
  120. #define SSPP_SBUF_STATUS_PLANE_EMPTY BIT(16)
  121. /* SDE_SSPP_SCALER_QSEED2 */
  122. #define SCALE_CONFIG 0x04
  123. #define COMP0_3_PHASE_STEP_X 0x10
  124. #define COMP0_3_PHASE_STEP_Y 0x14
  125. #define COMP1_2_PHASE_STEP_X 0x18
  126. #define COMP1_2_PHASE_STEP_Y 0x1c
  127. #define COMP0_3_INIT_PHASE_X 0x20
  128. #define COMP0_3_INIT_PHASE_Y 0x24
  129. #define COMP1_2_INIT_PHASE_X 0x28
  130. #define COMP1_2_INIT_PHASE_Y 0x2C
  131. #define VIG_0_QSEED2_SHARP 0x30
  132. /*
  133. * Definitions for ViG op modes
  134. */
  135. #define VIG_OP_CSC_DST_DATAFMT BIT(19)
  136. #define VIG_OP_CSC_SRC_DATAFMT BIT(18)
  137. #define VIG_OP_CSC_EN BIT(17)
  138. #define VIG_OP_MEM_PROT_CONT BIT(15)
  139. #define VIG_OP_MEM_PROT_VAL BIT(14)
  140. #define VIG_OP_MEM_PROT_SAT BIT(13)
  141. #define VIG_OP_MEM_PROT_HUE BIT(12)
  142. #define VIG_OP_HIST BIT(8)
  143. #define VIG_OP_SKY_COL BIT(7)
  144. #define VIG_OP_FOIL BIT(6)
  145. #define VIG_OP_SKIN_COL BIT(5)
  146. #define VIG_OP_PA_EN BIT(4)
  147. #define VIG_OP_PA_SAT_ZERO_EXP BIT(2)
  148. #define VIG_OP_MEM_PROT_BLEND BIT(1)
  149. /*
  150. * Definitions for CSC 10 op modes
  151. */
  152. #define VIG_CSC_10_SRC_DATAFMT BIT(1)
  153. #define VIG_CSC_10_EN BIT(0)
  154. #define CSC_10BIT_OFFSET 4
  155. #define DGM_CSC_MATRIX_SHIFT 0
  156. /* traffic shaper clock in Hz */
  157. #define TS_CLK 19200000
  158. static inline int _sspp_subblk_offset(struct sde_hw_pipe *ctx,
  159. int s_id,
  160. u32 *idx)
  161. {
  162. int rc = 0;
  163. const struct sde_sspp_sub_blks *sblk;
  164. if (!ctx)
  165. return -EINVAL;
  166. sblk = ctx->cap->sblk;
  167. switch (s_id) {
  168. case SDE_SSPP_SRC:
  169. *idx = sblk->src_blk.base;
  170. break;
  171. case SDE_SSPP_SCALER_QSEED2:
  172. case SDE_SSPP_SCALER_QSEED3:
  173. *idx = sblk->scaler_blk.base;
  174. break;
  175. case SDE_SSPP_CSC:
  176. case SDE_SSPP_CSC_10BIT:
  177. *idx = sblk->csc_blk.base;
  178. break;
  179. case SDE_SSPP_HSIC:
  180. *idx = sblk->hsic_blk.base;
  181. break;
  182. case SDE_SSPP_PCC:
  183. *idx = sblk->pcc_blk.base;
  184. break;
  185. case SDE_SSPP_MEMCOLOR:
  186. *idx = sblk->memcolor_blk.base;
  187. break;
  188. default:
  189. rc = -EINVAL;
  190. }
  191. return rc;
  192. }
  193. static void sde_hw_sspp_update_multirect(struct sde_hw_pipe *ctx,
  194. bool enable,
  195. enum sde_sspp_multirect_index index,
  196. enum sde_sspp_multirect_mode mode)
  197. {
  198. u32 mode_mask;
  199. u32 idx;
  200. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  201. return;
  202. if (index == SDE_SSPP_RECT_SOLO) {
  203. /**
  204. * if rect index is RECT_SOLO, we cannot expect a
  205. * virtual plane sharing the same SSPP id. So we go
  206. * and disable multirect
  207. */
  208. mode_mask = 0;
  209. } else {
  210. mode_mask = SDE_REG_READ(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx);
  211. if (enable)
  212. mode_mask |= index;
  213. else
  214. mode_mask &= ~index;
  215. if (enable && (mode == SDE_SSPP_MULTIRECT_TIME_MX))
  216. mode_mask |= BIT(2);
  217. else
  218. mode_mask &= ~BIT(2);
  219. }
  220. SDE_REG_WRITE(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx, mode_mask);
  221. }
  222. static void _sspp_setup_opmode(struct sde_hw_pipe *ctx,
  223. u32 mask, u8 en)
  224. {
  225. u32 idx;
  226. u32 opmode;
  227. if (!test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features) ||
  228. _sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) ||
  229. !test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  230. return;
  231. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_OP_MODE + idx);
  232. if (en)
  233. opmode |= mask;
  234. else
  235. opmode &= ~mask;
  236. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_OP_MODE + idx, opmode);
  237. }
  238. static void _sspp_setup_csc10_opmode(struct sde_hw_pipe *ctx,
  239. u32 mask, u8 en)
  240. {
  241. u32 idx;
  242. u32 opmode;
  243. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC_10BIT, &idx))
  244. return;
  245. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx);
  246. if (en)
  247. opmode |= mask;
  248. else
  249. opmode &= ~mask;
  250. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx, opmode);
  251. }
  252. static void sde_hw_sspp_set_src_split_order(struct sde_hw_pipe *ctx,
  253. enum sde_sspp_multirect_index rect_mode, bool enable)
  254. {
  255. struct sde_hw_blk_reg_map *c;
  256. u32 opmode, idx, op_mode_off;
  257. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  258. return;
  259. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0)
  260. op_mode_off = SSPP_SRC_OP_MODE;
  261. else
  262. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  263. c = &ctx->hw;
  264. opmode = SDE_REG_READ(c, op_mode_off + idx);
  265. if (enable)
  266. opmode |= MDSS_MDP_OP_SPLIT_ORDER;
  267. else
  268. opmode &= ~MDSS_MDP_OP_SPLIT_ORDER;
  269. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  270. }
  271. static void sde_hw_sspp_setup_ubwc(struct sde_hw_pipe *ctx, struct sde_hw_blk_reg_map *c,
  272. const struct sde_format *fmt, bool const_alpha_en, bool const_color_en,
  273. enum sde_sspp_multirect_index rect_mode)
  274. {
  275. u32 alpha_en_mask = 0, color_en_mask = 0, ubwc_ctrl_off;
  276. SDE_REG_WRITE(c, SSPP_FETCH_CONFIG,
  277. SDE_FETCH_CONFIG_RESET_VALUE |
  278. ctx->mdp->highest_bank_bit << 18);
  279. if ((rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0) ||
  280. !test_bit(SDE_SSPP_UBWC_STATS, &ctx->cap->features))
  281. ubwc_ctrl_off = SSPP_UBWC_STATIC_CTRL;
  282. else
  283. ubwc_ctrl_off = SSPP_UBWC_STATIC_CTRL_REC1;
  284. if (IS_UBWC_40_SUPPORTED(ctx->catalog->ubwc_rev)) {
  285. SDE_REG_WRITE(c, ubwc_ctrl_off, SDE_FORMAT_IS_YUV(fmt) ? 0 : BIT(30));
  286. } else if (IS_UBWC_30_SUPPORTED(ctx->catalog->ubwc_rev)) {
  287. color_en_mask = const_color_en ? BIT(30) : 0;
  288. SDE_REG_WRITE(c, ubwc_ctrl_off,
  289. color_en_mask | (ctx->mdp->ubwc_swizzle) |
  290. (ctx->mdp->highest_bank_bit << 4));
  291. } else if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_rev)) {
  292. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  293. SDE_REG_WRITE(c, ubwc_ctrl_off,
  294. alpha_en_mask | (ctx->mdp->ubwc_swizzle) |
  295. (ctx->mdp->highest_bank_bit << 4));
  296. } else if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_rev)) {
  297. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  298. SDE_REG_WRITE(c, ubwc_ctrl_off,
  299. alpha_en_mask | (ctx->mdp->ubwc_swizzle & 0x1) |
  300. BIT(8) | (ctx->mdp->highest_bank_bit << 4));
  301. }
  302. }
  303. /**
  304. * Setup source pixel format, flip,
  305. */
  306. static void sde_hw_sspp_setup_format(struct sde_hw_pipe *ctx,
  307. const struct sde_format *fmt,
  308. bool const_alpha_en, u32 flags,
  309. enum sde_sspp_multirect_index rect_mode)
  310. {
  311. struct sde_hw_blk_reg_map *c;
  312. u32 chroma_samp, unpack, src_format;
  313. u32 opmode = 0;
  314. u32 op_mode_off, unpack_pat_off, format_off;
  315. u32 idx;
  316. bool const_color_en = true;
  317. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !fmt)
  318. return;
  319. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0) {
  320. op_mode_off = SSPP_SRC_OP_MODE;
  321. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN;
  322. format_off = SSPP_SRC_FORMAT;
  323. } else {
  324. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  325. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN_REC1;
  326. format_off = SSPP_SRC_FORMAT_REC1;
  327. }
  328. c = &ctx->hw;
  329. opmode = SDE_REG_READ(c, op_mode_off + idx);
  330. opmode &= ~(MDSS_MDP_OP_FLIP_LR | MDSS_MDP_OP_FLIP_UD |
  331. MDSS_MDP_OP_BWC_EN | MDSS_MDP_OP_PE_OVERRIDE);
  332. if (flags & SDE_SSPP_FLIP_LR)
  333. opmode |= MDSS_MDP_OP_FLIP_LR;
  334. if (flags & SDE_SSPP_FLIP_UD)
  335. opmode |= MDSS_MDP_OP_FLIP_UD;
  336. chroma_samp = fmt->chroma_sample;
  337. if (flags & SDE_SSPP_SOURCE_ROTATED_90) {
  338. if (chroma_samp == SDE_CHROMA_H2V1)
  339. chroma_samp = SDE_CHROMA_H1V2;
  340. else if (chroma_samp == SDE_CHROMA_H1V2)
  341. chroma_samp = SDE_CHROMA_H2V1;
  342. }
  343. src_format = (chroma_samp << 23) | (fmt->fetch_planes << 19) |
  344. (fmt->bits[C3_ALPHA] << 6) | (fmt->bits[C2_R_Cr] << 4) |
  345. (fmt->bits[C1_B_Cb] << 2) | (fmt->bits[C0_G_Y] << 0);
  346. if (flags & SDE_SSPP_ROT_90)
  347. src_format |= BIT(11); /* ROT90 */
  348. if (fmt->alpha_enable && fmt->fetch_planes == SDE_PLANE_INTERLEAVED)
  349. src_format |= BIT(8); /* SRCC3_EN */
  350. if (flags & SDE_SSPP_SOLID_FILL)
  351. src_format |= BIT(22);
  352. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  353. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  354. src_format |= ((fmt->unpack_count - 1) << 12) |
  355. (fmt->unpack_tight << 17) |
  356. (fmt->unpack_align_msb << 18);
  357. if (SDE_FORMAT_IS_FP16(fmt)) {
  358. src_format |= BIT(16) | BIT(10) | BIT(9);
  359. } else if (fmt->bpp <= 4) {
  360. src_format |= ((fmt->bpp - 1) << 9);
  361. } else if (fmt->bpp <= 8) {
  362. src_format |= BIT(16) | ((fmt->bpp - 5) << 9);
  363. }
  364. if ((flags & SDE_SSPP_ROT_90) && test_bit(SDE_SSPP_INLINE_CONST_CLR,
  365. &ctx->cap->features))
  366. const_color_en = false;
  367. if (fmt->fetch_mode != SDE_FETCH_LINEAR) {
  368. if (SDE_FORMAT_IS_UBWC(fmt))
  369. opmode |= MDSS_MDP_OP_BWC_EN;
  370. src_format |= (fmt->fetch_mode & 3) << 30; /*FRAME_FORMAT */
  371. sde_hw_sspp_setup_ubwc(ctx, c, fmt, const_alpha_en, const_color_en, rect_mode);
  372. }
  373. opmode |= MDSS_MDP_OP_PE_OVERRIDE;
  374. /* if this is YUV pixel format, enable CSC */
  375. if (SDE_FORMAT_IS_YUV(fmt))
  376. src_format |= BIT(15);
  377. if (SDE_FORMAT_IS_DX(fmt))
  378. src_format |= BIT(14);
  379. /* update scaler opmode, if appropriate */
  380. if (test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  381. _sspp_setup_opmode(ctx, VIG_OP_CSC_EN | VIG_OP_CSC_SRC_DATAFMT,
  382. SDE_FORMAT_IS_YUV(fmt));
  383. else if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features))
  384. _sspp_setup_csc10_opmode(ctx,
  385. VIG_CSC_10_EN | VIG_CSC_10_SRC_DATAFMT,
  386. SDE_FORMAT_IS_YUV(fmt));
  387. SDE_REG_WRITE(c, format_off + idx, src_format);
  388. SDE_REG_WRITE(c, unpack_pat_off + idx, unpack);
  389. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  390. /* clear previous UBWC error */
  391. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS + idx, BIT(31));
  392. }
  393. static void sde_hw_sspp_clear_ubwc_error(struct sde_hw_pipe *ctx,
  394. enum sde_sspp_multirect_index multirect_index)
  395. {
  396. struct sde_hw_blk_reg_map *c;
  397. c = &ctx->hw;
  398. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  399. }
  400. static u32 sde_hw_sspp_get_ubwc_error(struct sde_hw_pipe *ctx,
  401. enum sde_sspp_multirect_index multirect_index)
  402. {
  403. struct sde_hw_blk_reg_map *c;
  404. u32 reg_code;
  405. c = &ctx->hw;
  406. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  407. return reg_code;
  408. }
  409. static void sde_hw_sspp_clear_ubwc_error_v1(struct sde_hw_pipe *ctx,
  410. enum sde_sspp_multirect_index multirect_index)
  411. {
  412. struct sde_hw_blk_reg_map *c;
  413. c = &ctx->hw;
  414. if (multirect_index == SDE_SSPP_RECT_1)
  415. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS_REC1, BIT(31));
  416. else
  417. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  418. }
  419. static u32 sde_hw_sspp_get_ubwc_error_v1(struct sde_hw_pipe *ctx,
  420. enum sde_sspp_multirect_index multirect_index)
  421. {
  422. struct sde_hw_blk_reg_map *c;
  423. u32 reg_code;
  424. c = &ctx->hw;
  425. if (multirect_index == SDE_SSPP_RECT_1)
  426. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS_REC1);
  427. else
  428. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  429. return reg_code;
  430. }
  431. static void sde_hw_sspp_clear_meta_error(struct sde_hw_pipe *ctx,
  432. enum sde_sspp_multirect_index multirect_index)
  433. {
  434. struct sde_hw_blk_reg_map *c;
  435. c = &ctx->hw;
  436. if (multirect_index == SDE_SSPP_RECT_1)
  437. SDE_REG_WRITE(c, SSPP_META_ERROR_STATUS_REC1, BIT(31));
  438. else
  439. SDE_REG_WRITE(c, SSPP_META_ERROR_STATUS, BIT(31));
  440. }
  441. static u32 sde_hw_sspp_get_meta_error(struct sde_hw_pipe *ctx,
  442. enum sde_sspp_multirect_index multirect_index)
  443. {
  444. struct sde_hw_blk_reg_map *c;
  445. u32 reg_code;
  446. c = &ctx->hw;
  447. if (multirect_index == SDE_SSPP_RECT_1)
  448. reg_code = SDE_REG_READ(c, SSPP_META_ERROR_STATUS_REC1);
  449. else
  450. reg_code = SDE_REG_READ(c, SSPP_META_ERROR_STATUS);
  451. return reg_code;
  452. }
  453. static void sde_hw_sspp_ubwc_stats_set_roi(struct sde_hw_pipe *ctx,
  454. enum sde_sspp_multirect_index multirect_index,
  455. struct sde_drm_ubwc_stats_roi *roi)
  456. {
  457. struct sde_hw_blk_reg_map *c;
  458. u32 idx, ctrl_off, roi_off;
  459. u32 ctrl_val = 0, roi_val = 0;
  460. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  461. return;
  462. if (multirect_index == SDE_SSPP_RECT_SOLO || multirect_index == SDE_SSPP_RECT_0) {
  463. ctrl_off = SSPP_UBWC_STATIC_CTRL + idx;
  464. roi_off = SSPP_UBWC_STATS_ROI + idx;
  465. } else {
  466. ctrl_off = SSPP_UBWC_STATIC_CTRL_REC1 + idx;
  467. roi_off = SSPP_UBWC_STATS_ROI_REC1 + idx;
  468. }
  469. c = &ctx->hw;
  470. ctrl_val = SDE_REG_READ(c, ctrl_off);
  471. if (roi) {
  472. ctrl_val |= BIT(24);
  473. if (roi->y_coord0) {
  474. ctrl_val |= BIT(25);
  475. roi_val |= roi->y_coord0;
  476. if (roi->y_coord1) {
  477. ctrl_val |= BIT(26);
  478. roi_val |= (roi->y_coord1) << 0x10;
  479. }
  480. }
  481. } else {
  482. ctrl_val &= ~(BIT(24) | BIT(25) | BIT(26));
  483. }
  484. SDE_REG_WRITE(c, ctrl_off, ctrl_val);
  485. SDE_REG_WRITE(c, roi_off, roi_val);
  486. }
  487. static void sde_hw_sspp_ubwc_stats_get_data(struct sde_hw_pipe *ctx,
  488. enum sde_sspp_multirect_index multirect_index,
  489. struct sde_drm_ubwc_stats_data *data)
  490. {
  491. struct sde_hw_blk_reg_map *c;
  492. u32 idx, value = 0;
  493. int i;
  494. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  495. return;
  496. if (multirect_index == SDE_SSPP_RECT_SOLO || multirect_index == SDE_SSPP_RECT_0)
  497. idx += SSPP_UBWC_STATS_DATA;
  498. else
  499. idx += SSPP_UBWC_STATS_DATA_REC1;
  500. c = &ctx->hw;
  501. for (i = 0; i < UBWC_STATS_MAX_ROI; i++) {
  502. value = SDE_REG_READ(c, idx);
  503. data->worst_bw[i] = value & 0xFFFF;
  504. data->worst_bw_y_coord[i] = (value >> 0x10) & 0xFFFF;
  505. data->total_bw[i] = SDE_REG_READ(c, idx + 4);
  506. idx += 8;
  507. }
  508. }
  509. static void sde_hw_sspp_setup_secure(struct sde_hw_pipe *ctx,
  510. enum sde_sspp_multirect_index rect_mode,
  511. bool enable)
  512. {
  513. struct sde_hw_blk_reg_map *c;
  514. u32 secure = 0, secure_bit_mask;
  515. u32 idx;
  516. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  517. return;
  518. c = &ctx->hw;
  519. if ((rect_mode == SDE_SSPP_RECT_SOLO)
  520. || (rect_mode == SDE_SSPP_RECT_0))
  521. secure_bit_mask =
  522. (rect_mode == SDE_SSPP_RECT_SOLO) ? 0xF : 0x5;
  523. else
  524. secure_bit_mask = 0xA;
  525. secure = SDE_REG_READ(c, SSPP_SRC_ADDR_SW_STATUS + idx);
  526. if (enable)
  527. secure |= secure_bit_mask;
  528. else
  529. secure &= ~secure_bit_mask;
  530. SDE_REG_WRITE(c, SSPP_SRC_ADDR_SW_STATUS + idx, secure);
  531. /* multiple planes share same sw_status register */
  532. wmb();
  533. }
  534. static void sde_hw_sspp_setup_pe_config(struct sde_hw_pipe *ctx,
  535. struct sde_hw_pixel_ext *pe_ext)
  536. {
  537. struct sde_hw_blk_reg_map *c;
  538. u8 color;
  539. u32 lr_pe[4], tb_pe[4], tot_req_pixels[4];
  540. const u32 bytemask = 0xff;
  541. const u32 shortmask = 0xffff;
  542. u32 idx;
  543. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !pe_ext)
  544. return;
  545. c = &ctx->hw;
  546. /* program SW pixel extension override for all pipes*/
  547. for (color = 0; color < SDE_MAX_PLANES; color++) {
  548. /* color 2 has the same set of registers as color 1 */
  549. if (color == 2)
  550. continue;
  551. lr_pe[color] = ((pe_ext->right_ftch[color] & bytemask) << 24)|
  552. ((pe_ext->right_rpt[color] & bytemask) << 16)|
  553. ((pe_ext->left_ftch[color] & bytemask) << 8)|
  554. (pe_ext->left_rpt[color] & bytemask);
  555. tb_pe[color] = ((pe_ext->btm_ftch[color] & bytemask) << 24)|
  556. ((pe_ext->btm_rpt[color] & bytemask) << 16)|
  557. ((pe_ext->top_ftch[color] & bytemask) << 8)|
  558. (pe_ext->top_rpt[color] & bytemask);
  559. tot_req_pixels[color] = (((pe_ext->roi_h[color] +
  560. pe_ext->num_ext_pxls_top[color] +
  561. pe_ext->num_ext_pxls_btm[color]) & shortmask) << 16) |
  562. ((pe_ext->roi_w[color] +
  563. pe_ext->num_ext_pxls_left[color] +
  564. pe_ext->num_ext_pxls_right[color]) & shortmask);
  565. }
  566. /* color 0 */
  567. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_LR + idx, lr_pe[0]);
  568. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_TB + idx, tb_pe[0]);
  569. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_REQ_PIXELS + idx,
  570. tot_req_pixels[0]);
  571. /* color 1 and color 2 */
  572. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_LR + idx, lr_pe[1]);
  573. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_TB + idx, tb_pe[1]);
  574. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS + idx,
  575. tot_req_pixels[1]);
  576. /* color 3 */
  577. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_LR + idx, lr_pe[3]);
  578. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_TB + idx, tb_pe[3]);
  579. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_REQ_PIXELS + idx,
  580. tot_req_pixels[3]);
  581. }
  582. static void _sde_hw_sspp_setup_scaler(struct sde_hw_pipe *ctx,
  583. struct sde_hw_pipe_cfg *sspp,
  584. struct sde_hw_pixel_ext *pe,
  585. void *scaler_cfg)
  586. {
  587. struct sde_hw_blk_reg_map *c;
  588. int config_h = 0x0;
  589. int config_v = 0x0;
  590. u32 idx;
  591. (void)sspp;
  592. (void)scaler_cfg;
  593. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !pe)
  594. return;
  595. c = &ctx->hw;
  596. /* enable scaler(s) if valid filter set */
  597. if (pe->horz_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  598. config_h |= pe->horz_filter[SDE_SSPP_COMP_0] << 8;
  599. if (pe->horz_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  600. config_h |= pe->horz_filter[SDE_SSPP_COMP_1_2] << 12;
  601. if (pe->horz_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  602. config_h |= pe->horz_filter[SDE_SSPP_COMP_3] << 16;
  603. if (config_h)
  604. config_h |= BIT(0);
  605. if (pe->vert_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  606. config_v |= pe->vert_filter[SDE_SSPP_COMP_0] << 10;
  607. if (pe->vert_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  608. config_v |= pe->vert_filter[SDE_SSPP_COMP_1_2] << 14;
  609. if (pe->vert_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  610. config_v |= pe->vert_filter[SDE_SSPP_COMP_3] << 18;
  611. if (config_v)
  612. config_v |= BIT(1);
  613. SDE_REG_WRITE(c, SCALE_CONFIG + idx, config_h | config_v);
  614. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_X + idx,
  615. pe->init_phase_x[SDE_SSPP_COMP_0]);
  616. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_Y + idx,
  617. pe->init_phase_y[SDE_SSPP_COMP_0]);
  618. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_X + idx,
  619. pe->phase_step_x[SDE_SSPP_COMP_0]);
  620. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_Y + idx,
  621. pe->phase_step_y[SDE_SSPP_COMP_0]);
  622. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_X + idx,
  623. pe->init_phase_x[SDE_SSPP_COMP_1_2]);
  624. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_Y + idx,
  625. pe->init_phase_y[SDE_SSPP_COMP_1_2]);
  626. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_X + idx,
  627. pe->phase_step_x[SDE_SSPP_COMP_1_2]);
  628. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_Y + idx,
  629. pe->phase_step_y[SDE_SSPP_COMP_1_2]);
  630. }
  631. static void _sde_hw_sspp_setup_scaler3(struct sde_hw_pipe *ctx,
  632. struct sde_hw_pipe_cfg *sspp,
  633. struct sde_hw_pixel_ext *pe,
  634. void *scaler_cfg)
  635. {
  636. u32 idx;
  637. bool de_lpf_en = false;
  638. struct sde_hw_scaler3_cfg *scaler3_cfg = scaler_cfg;
  639. (void)pe;
  640. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED3, &idx) || !sspp
  641. || !scaler3_cfg || !ctx || !ctx->cap || !ctx->cap->sblk)
  642. return;
  643. if (test_bit(SDE_SSPP_SCALER_DE_LPF_BLEND, &ctx->cap->features))
  644. de_lpf_en = true;
  645. sde_hw_setup_scaler3(&ctx->hw, scaler3_cfg,
  646. ctx->cap->sblk->scaler_blk.version, idx, sspp->layout.format, de_lpf_en);
  647. }
  648. static void sde_hw_sspp_setup_pre_downscale(struct sde_hw_pipe *ctx,
  649. struct sde_hw_inline_pre_downscale_cfg *pre_down)
  650. {
  651. u32 idx, val;
  652. if (!ctx || !pre_down || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  653. return;
  654. val = pre_down->pre_downscale_x_0 |
  655. (pre_down->pre_downscale_x_1 << 4) |
  656. (pre_down->pre_downscale_y_0 << 8) |
  657. (pre_down->pre_downscale_y_1 << 12);
  658. SDE_REG_WRITE(&ctx->hw, SSPP_PRE_DOWN_SCALE + idx, val);
  659. }
  660. /**
  661. * sde_hw_sspp_setup_rects()
  662. */
  663. static void sde_hw_sspp_setup_rects(struct sde_hw_pipe *ctx,
  664. struct sde_hw_pipe_cfg *cfg,
  665. enum sde_sspp_multirect_index rect_index)
  666. {
  667. struct sde_hw_blk_reg_map *c;
  668. u32 src_size, src_xy, dst_size, dst_xy, ystride0, ystride1;
  669. u32 src_size_off, src_xy_off, out_size_off, out_xy_off;
  670. u32 decimation = 0;
  671. u32 idx;
  672. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !cfg)
  673. return;
  674. c = &ctx->hw;
  675. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0) {
  676. src_size_off = SSPP_SRC_SIZE;
  677. src_xy_off = SSPP_SRC_XY;
  678. out_size_off = SSPP_OUT_SIZE;
  679. out_xy_off = SSPP_OUT_XY;
  680. } else {
  681. src_size_off = SSPP_SRC_SIZE_REC1;
  682. src_xy_off = SSPP_SRC_XY_REC1;
  683. out_size_off = SSPP_OUT_SIZE_REC1;
  684. out_xy_off = SSPP_OUT_XY_REC1;
  685. }
  686. /* src and dest rect programming */
  687. src_xy = (cfg->src_rect.y << 16) | (cfg->src_rect.x);
  688. src_size = (cfg->src_rect.h << 16) | (cfg->src_rect.w);
  689. dst_xy = (cfg->dst_rect.y << 16) | (cfg->dst_rect.x);
  690. dst_size = (cfg->dst_rect.h << 16) | (cfg->dst_rect.w);
  691. if (rect_index == SDE_SSPP_RECT_SOLO) {
  692. ystride0 = (cfg->layout.plane_pitch[0]) |
  693. (cfg->layout.plane_pitch[1] << 16);
  694. ystride1 = (cfg->layout.plane_pitch[2]) |
  695. (cfg->layout.plane_pitch[3] << 16);
  696. } else {
  697. ystride0 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE0 + idx);
  698. ystride1 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE1 + idx);
  699. if (rect_index == SDE_SSPP_RECT_0) {
  700. ystride0 = (ystride0 & 0xFFFF0000) |
  701. (cfg->layout.plane_pitch[0] & 0x0000FFFF);
  702. ystride1 = (ystride1 & 0xFFFF0000)|
  703. (cfg->layout.plane_pitch[2] & 0x0000FFFF);
  704. } else {
  705. ystride0 = (ystride0 & 0x0000FFFF) |
  706. ((cfg->layout.plane_pitch[0] << 16) &
  707. 0xFFFF0000);
  708. ystride1 = (ystride1 & 0x0000FFFF) |
  709. ((cfg->layout.plane_pitch[2] << 16) &
  710. 0xFFFF0000);
  711. }
  712. }
  713. /* program scaler, phase registers, if pipes supporting scaling */
  714. if (ctx->cap->features & SDE_SSPP_SCALER) {
  715. /* program decimation */
  716. decimation = ((1 << cfg->horz_decimation) - 1) << 8;
  717. decimation |= ((1 << cfg->vert_decimation) - 1);
  718. }
  719. /* rectangle register programming */
  720. SDE_REG_WRITE(c, src_size_off + idx, src_size);
  721. SDE_REG_WRITE(c, src_xy_off + idx, src_xy);
  722. SDE_REG_WRITE(c, out_size_off + idx, dst_size);
  723. SDE_REG_WRITE(c, out_xy_off + idx, dst_xy);
  724. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE0 + idx, ystride0);
  725. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE1 + idx, ystride1);
  726. SDE_REG_WRITE(c, SSPP_DECIMATION_CONFIG + idx, decimation);
  727. }
  728. /**
  729. * _sde_hw_sspp_setup_excl_rect() - set exclusion rect configs
  730. * @ctx: Pointer to pipe context
  731. * @excl_rect: Exclusion rect configs
  732. */
  733. static void _sde_hw_sspp_setup_excl_rect(struct sde_hw_pipe *ctx,
  734. struct sde_rect *excl_rect,
  735. enum sde_sspp_multirect_index rect_index)
  736. {
  737. struct sde_hw_blk_reg_map *c;
  738. u32 size, xy;
  739. u32 idx;
  740. u32 reg_xy, reg_size;
  741. u32 excl_ctrl = BIT(0);
  742. u32 enable_bit;
  743. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !excl_rect)
  744. return;
  745. if (rect_index == SDE_SSPP_RECT_0 || rect_index == SDE_SSPP_RECT_SOLO) {
  746. reg_xy = SSPP_EXCL_REC_XY;
  747. reg_size = SSPP_EXCL_REC_SIZE;
  748. enable_bit = BIT(0);
  749. } else {
  750. reg_xy = SSPP_EXCL_REC_XY_REC1;
  751. reg_size = SSPP_EXCL_REC_SIZE_REC1;
  752. enable_bit = BIT(1);
  753. }
  754. c = &ctx->hw;
  755. xy = (excl_rect->y << 16) | (excl_rect->x);
  756. size = (excl_rect->h << 16) | (excl_rect->w);
  757. /* Set if multi-rect disabled, read+modify only if multi-rect enabled */
  758. if (rect_index != SDE_SSPP_RECT_SOLO)
  759. excl_ctrl = SDE_REG_READ(c, SSPP_EXCL_REC_CTL + idx);
  760. if (!size) {
  761. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  762. excl_ctrl & ~enable_bit);
  763. } else {
  764. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  765. excl_ctrl | enable_bit);
  766. SDE_REG_WRITE(c, reg_size + idx, size);
  767. SDE_REG_WRITE(c, reg_xy + idx, xy);
  768. }
  769. }
  770. static void sde_hw_sspp_setup_sourceaddress(struct sde_hw_pipe *ctx,
  771. struct sde_hw_pipe_cfg *cfg,
  772. enum sde_sspp_multirect_index rect_mode)
  773. {
  774. int i;
  775. u32 idx;
  776. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  777. return;
  778. if (rect_mode == SDE_SSPP_RECT_SOLO) {
  779. for (i = 0; i < ARRAY_SIZE(cfg->layout.plane_addr); i++)
  780. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx + i * 0x4,
  781. cfg->layout.plane_addr[i]);
  782. } else if (rect_mode == SDE_SSPP_RECT_0) {
  783. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx,
  784. cfg->layout.plane_addr[0]);
  785. SDE_REG_WRITE(&ctx->hw, SSPP_SRC2_ADDR + idx,
  786. cfg->layout.plane_addr[2]);
  787. } else {
  788. SDE_REG_WRITE(&ctx->hw, SSPP_SRC1_ADDR + idx,
  789. cfg->layout.plane_addr[0]);
  790. SDE_REG_WRITE(&ctx->hw, SSPP_SRC3_ADDR + idx,
  791. cfg->layout.plane_addr[2]);
  792. }
  793. }
  794. u32 sde_hw_sspp_get_source_addr(struct sde_hw_pipe *ctx, bool is_virtual)
  795. {
  796. u32 idx;
  797. u32 offset = 0;
  798. if (!ctx || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  799. return 0;
  800. offset = is_virtual ? (SSPP_SRC1_ADDR + idx) : (SSPP_SRC0_ADDR + idx);
  801. return SDE_REG_READ(&ctx->hw, offset);
  802. }
  803. static void sde_hw_sspp_setup_csc(struct sde_hw_pipe *ctx,
  804. struct sde_csc_cfg *data)
  805. {
  806. u32 idx;
  807. bool csc10 = false;
  808. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC, &idx) || !data)
  809. return;
  810. if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features)) {
  811. idx += CSC_10BIT_OFFSET;
  812. csc10 = true;
  813. }
  814. sde_hw_csc_setup(&ctx->hw, idx, data, csc10);
  815. }
  816. static void sde_hw_sspp_setup_sharpening(struct sde_hw_pipe *ctx,
  817. struct sde_hw_sharp_cfg *cfg)
  818. {
  819. struct sde_hw_blk_reg_map *c;
  820. u32 idx;
  821. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !cfg ||
  822. !test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features))
  823. return;
  824. c = &ctx->hw;
  825. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx, cfg->strength);
  826. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x4, cfg->edge_thr);
  827. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x8, cfg->smooth_thr);
  828. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0xC, cfg->noise_thr);
  829. }
  830. static void sde_hw_sspp_setup_solidfill(struct sde_hw_pipe *ctx, u32 color, enum
  831. sde_sspp_multirect_index rect_index)
  832. {
  833. u32 idx;
  834. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  835. return;
  836. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0)
  837. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR + idx, color);
  838. else
  839. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR_REC1 + idx,
  840. color);
  841. }
  842. static void sde_hw_sspp_setup_qos_lut(struct sde_hw_pipe *ctx,
  843. struct sde_hw_pipe_qos_cfg *cfg)
  844. {
  845. u32 idx;
  846. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  847. return;
  848. SDE_REG_WRITE(&ctx->hw, SSPP_DANGER_LUT + idx, cfg->danger_lut);
  849. SDE_REG_WRITE(&ctx->hw, SSPP_SAFE_LUT + idx, cfg->safe_lut);
  850. if (ctx->cap && test_bit(SDE_PERF_SSPP_QOS_8LVL,
  851. &ctx->cap->perf_features)) {
  852. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_0 + idx, cfg->creq_lut);
  853. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_1 + idx,
  854. cfg->creq_lut >> 32);
  855. } else {
  856. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT + idx, cfg->creq_lut);
  857. }
  858. }
  859. static void sde_hw_sspp_setup_qos_ctrl(struct sde_hw_pipe *ctx,
  860. struct sde_hw_pipe_qos_cfg *cfg)
  861. {
  862. u32 idx;
  863. u32 qos_ctrl = 0;
  864. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  865. return;
  866. if (cfg->vblank_en) {
  867. qos_ctrl |= ((cfg->creq_vblank &
  868. SSPP_QOS_CTRL_CREQ_VBLANK_MASK) <<
  869. SSPP_QOS_CTRL_CREQ_VBLANK_OFF);
  870. qos_ctrl |= ((cfg->danger_vblank &
  871. SSPP_QOS_CTRL_DANGER_VBLANK_MASK) <<
  872. SSPP_QOS_CTRL_DANGER_VBLANK_OFF);
  873. qos_ctrl |= SSPP_QOS_CTRL_VBLANK_EN;
  874. }
  875. if (cfg->danger_safe_en)
  876. qos_ctrl |= SSPP_QOS_CTRL_DANGER_SAFE_EN;
  877. SDE_REG_WRITE(&ctx->hw, SSPP_QOS_CTRL + idx, qos_ctrl);
  878. }
  879. static void sde_hw_sspp_setup_ts_prefill(struct sde_hw_pipe *ctx,
  880. struct sde_hw_pipe_ts_cfg *cfg,
  881. enum sde_sspp_multirect_index index)
  882. {
  883. u32 idx;
  884. u32 ts_offset, ts_prefill_offset;
  885. u32 ts_count = 0, ts_bytes = 0;
  886. const struct sde_sspp_cfg *cap;
  887. if (!ctx || !cfg || !ctx->cap)
  888. return;
  889. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  890. return;
  891. cap = ctx->cap;
  892. if ((index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) &&
  893. test_bit(SDE_PERF_SSPP_TS_PREFILL,
  894. &cap->perf_features)) {
  895. ts_offset = SSPP_TRAFFIC_SHAPER;
  896. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_PREFILL;
  897. } else if (index == SDE_SSPP_RECT_1 &&
  898. test_bit(SDE_PERF_SSPP_TS_PREFILL_REC1,
  899. &cap->perf_features)) {
  900. ts_offset = SSPP_TRAFFIC_SHAPER_REC1;
  901. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_REC1_PREFILL;
  902. } else {
  903. pr_err("%s: unexpected idx:%d\n", __func__, index);
  904. return;
  905. }
  906. if (cfg->time) {
  907. ts_count = DIV_ROUND_UP_ULL(TS_CLK * cfg->time, 1000000ULL);
  908. ts_bytes = DIV_ROUND_UP_ULL(cfg->size, ts_count);
  909. if (ts_bytes > SSPP_TRAFFIC_SHAPER_BPC_MAX)
  910. ts_bytes = SSPP_TRAFFIC_SHAPER_BPC_MAX;
  911. }
  912. if (ts_count)
  913. ts_bytes |= BIT(31) | BIT(27);
  914. SDE_REG_WRITE(&ctx->hw, ts_offset, ts_bytes);
  915. SDE_REG_WRITE(&ctx->hw, ts_prefill_offset, ts_count);
  916. }
  917. static void sde_hw_sspp_setup_cdp(struct sde_hw_pipe *ctx,
  918. struct sde_hw_pipe_cdp_cfg *cfg,
  919. enum sde_sspp_multirect_index index)
  920. {
  921. u32 idx;
  922. u32 cdp_cntl = 0;
  923. u32 cdp_cntl_offset = 0;
  924. if (!ctx || !cfg)
  925. return;
  926. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  927. return;
  928. if (index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) {
  929. cdp_cntl_offset = SSPP_CDP_CNTL;
  930. } else if (index == SDE_SSPP_RECT_1) {
  931. cdp_cntl_offset = SSPP_CDP_CNTL_REC1;
  932. } else {
  933. pr_err("%s: unexpected idx:%d\n", __func__, index);
  934. return;
  935. }
  936. if (cfg->enable)
  937. cdp_cntl |= BIT(0);
  938. if (cfg->ubwc_meta_enable)
  939. cdp_cntl |= BIT(1);
  940. if (cfg->tile_amortize_enable)
  941. cdp_cntl |= BIT(2);
  942. if (cfg->preload_ahead == SDE_SSPP_CDP_PRELOAD_AHEAD_64)
  943. cdp_cntl |= BIT(3);
  944. SDE_REG_WRITE(&ctx->hw, cdp_cntl_offset, cdp_cntl);
  945. }
  946. static void sde_hw_sspp_setup_sys_cache(struct sde_hw_pipe *ctx,
  947. struct sde_hw_pipe_sc_cfg *cfg)
  948. {
  949. u32 idx, val;
  950. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  951. return;
  952. if (!cfg)
  953. return;
  954. val = SDE_REG_READ(&ctx->hw, SSPP_SYS_CACHE_MODE + idx);
  955. if (cfg->flags & SYS_CACHE_EN_FLAG)
  956. val = (val & ~BIT(15)) | ((cfg->rd_en & 0x1) << 15);
  957. if (cfg->flags & SYS_CACHE_SCID)
  958. val = (val & ~0x1F00) | ((cfg->rd_scid & 0x1f) << 8);
  959. if (cfg->flags & SYS_CACHE_OP_MODE)
  960. val = (val & ~0xC0000) | ((cfg->op_mode & 0x3) << 18);
  961. if (cfg->flags & SYS_CACHE_OP_TYPE)
  962. val = (val & ~0xF) | ((cfg->rd_op_type & 0xf) << 0);
  963. if (cfg->flags & SYS_CACHE_NO_ALLOC)
  964. val = (val & ~0x10) | ((cfg->rd_noallocate & 0x1) << 4);
  965. SDE_REG_WRITE(&ctx->hw, SSPP_SYS_CACHE_MODE + idx, val);
  966. }
  967. static void sde_hw_sspp_setup_uidle_fill_scale(struct sde_hw_pipe *ctx,
  968. struct sde_hw_pipe_uidle_cfg *cfg)
  969. {
  970. u32 idx, fill_lvl;
  971. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  972. return;
  973. /* duplicate the v1 scale values for V2 and fal10 exit */
  974. fill_lvl = cfg->fill_level_scale & 0xF;
  975. fill_lvl |= (cfg->fill_level_scale & 0xF) << 8;
  976. fill_lvl |= (cfg->fill_level_scale & 0xF) << 16;
  977. SDE_REG_WRITE(&ctx->hw, SSPP_FILL_LEVEL_SCALE + idx, fill_lvl);
  978. }
  979. static void sde_hw_sspp_setup_uidle(struct sde_hw_pipe *ctx,
  980. struct sde_hw_pipe_uidle_cfg *cfg,
  981. enum sde_sspp_multirect_index index)
  982. {
  983. u32 idx, val;
  984. u32 offset;
  985. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  986. return;
  987. if (index == SDE_SSPP_RECT_1)
  988. offset = SSPP_UIDLE_CTRL_VALUE_REC1;
  989. else
  990. offset = SSPP_UIDLE_CTRL_VALUE;
  991. val = SDE_REG_READ(&ctx->hw, offset + idx);
  992. val = (val & ~BIT(31)) | (cfg->enable ? 0x0 : BIT(31));
  993. val = (val & ~0xFF00000) | (cfg->fal_allowed_threshold << 20);
  994. val = (val & ~0xF0000) | (cfg->fal10_exit_threshold << 16);
  995. val = (val & ~0xF00) | (cfg->fal10_threshold << 8);
  996. val = (val & ~0xF) | (cfg->fal1_threshold << 0);
  997. SDE_REG_WRITE(&ctx->hw, offset + idx, val);
  998. }
  999. static void _setup_layer_ops_colorproc(struct sde_hw_pipe *c,
  1000. unsigned long features, bool is_virtual_pipe)
  1001. {
  1002. int ret = 0;
  1003. if (is_virtual_pipe) {
  1004. features &=
  1005. ~(BIT(SDE_SSPP_VIG_IGC) | BIT(SDE_SSPP_VIG_GAMUT));
  1006. c->cap->features = features;
  1007. }
  1008. if (test_bit(SDE_SSPP_HSIC, &features)) {
  1009. if (c->cap->sblk->hsic_blk.version ==
  1010. (SDE_COLOR_PROCESS_VER(0x1, 0x7))) {
  1011. c->ops.setup_pa_hue = sde_setup_pipe_pa_hue_v1_7;
  1012. c->ops.setup_pa_sat = sde_setup_pipe_pa_sat_v1_7;
  1013. c->ops.setup_pa_val = sde_setup_pipe_pa_val_v1_7;
  1014. c->ops.setup_pa_cont = sde_setup_pipe_pa_cont_v1_7;
  1015. }
  1016. }
  1017. if (test_bit(SDE_SSPP_MEMCOLOR, &features)) {
  1018. if (c->cap->sblk->memcolor_blk.version ==
  1019. (SDE_COLOR_PROCESS_VER(0x1, 0x7)))
  1020. c->ops.setup_pa_memcolor =
  1021. sde_setup_pipe_pa_memcol_v1_7;
  1022. }
  1023. if (test_bit(SDE_SSPP_VIG_GAMUT, &features)) {
  1024. if (c->cap->sblk->gamut_blk.version ==
  1025. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1026. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1027. c->idx);
  1028. if (!ret)
  1029. c->ops.setup_vig_gamut =
  1030. reg_dmav1_setup_vig_gamutv5;
  1031. else
  1032. c->ops.setup_vig_gamut = NULL;
  1033. }
  1034. if (c->cap->sblk->gamut_blk.version ==
  1035. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  1036. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1037. c->idx);
  1038. if (!ret)
  1039. c->ops.setup_vig_gamut =
  1040. reg_dmav1_setup_vig_gamutv6;
  1041. else
  1042. c->ops.setup_vig_gamut = NULL;
  1043. } else if (c->cap->sblk->gamut_blk.version ==
  1044. (SDE_COLOR_PROCESS_VER(0x6, 0x1))) {
  1045. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1046. c->idx);
  1047. if (!ret)
  1048. c->ops.setup_vig_gamut =
  1049. reg_dmav2_setup_vig_gamutv61;
  1050. else
  1051. c->ops.setup_vig_gamut = NULL;
  1052. }
  1053. }
  1054. if (test_bit(SDE_SSPP_VIG_IGC, &features)) {
  1055. if (c->cap->sblk->igc_blk[0].version ==
  1056. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1057. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  1058. c->idx);
  1059. if (!ret)
  1060. c->ops.setup_vig_igc =
  1061. reg_dmav1_setup_vig_igcv5;
  1062. else
  1063. c->ops.setup_vig_igc = NULL;
  1064. }
  1065. if (c->cap->sblk->igc_blk[0].version ==
  1066. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  1067. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  1068. c->idx);
  1069. if (!ret)
  1070. c->ops.setup_vig_igc =
  1071. reg_dmav1_setup_vig_igcv6;
  1072. else
  1073. c->ops.setup_vig_igc = NULL;
  1074. }
  1075. }
  1076. if (test_bit(SDE_SSPP_DMA_IGC, &features)) {
  1077. if (c->cap->sblk->igc_blk[0].version ==
  1078. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1079. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_IGC,
  1080. c->idx);
  1081. if (!ret)
  1082. c->ops.setup_dma_igc =
  1083. reg_dmav1_setup_dma_igcv5;
  1084. else
  1085. c->ops.setup_dma_igc = NULL;
  1086. }
  1087. }
  1088. if (test_bit(SDE_SSPP_DMA_GC, &features)) {
  1089. if (c->cap->sblk->gc_blk[0].version ==
  1090. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1091. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_GC,
  1092. c->idx);
  1093. if (!ret)
  1094. c->ops.setup_dma_gc =
  1095. reg_dmav1_setup_dma_gcv5;
  1096. else
  1097. c->ops.setup_dma_gc = NULL;
  1098. }
  1099. }
  1100. if (test_bit(SDE_SSPP_FP16_IGC, &features) &&
  1101. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_igc_blk[0].version))
  1102. c->ops.setup_fp16_igc = sde_setup_fp16_igcv1;
  1103. if (test_bit(SDE_SSPP_FP16_GC, &features) &&
  1104. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_gc_blk[0].version))
  1105. c->ops.setup_fp16_gc = sde_setup_fp16_gcv1;
  1106. if (test_bit(SDE_SSPP_FP16_CSC, &features) &&
  1107. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_csc_blk[0].version))
  1108. c->ops.setup_fp16_csc = sde_setup_fp16_cscv1;
  1109. if (test_bit(SDE_SSPP_FP16_UNMULT, &features) &&
  1110. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_unmult_blk[0].version))
  1111. c->ops.setup_fp16_unmult = sde_setup_fp16_unmultv1;
  1112. }
  1113. static void sde_hw_sspp_setup_inverse_pma(struct sde_hw_pipe *ctx,
  1114. enum sde_sspp_multirect_index index, u32 enable)
  1115. {
  1116. u32 op_mode = 0;
  1117. u32 offset;
  1118. if (!ctx || (index == SDE_SSPP_RECT_1))
  1119. return;
  1120. offset = ctx->cap->sblk->unmult_offset[0];
  1121. if (enable)
  1122. op_mode |= BIT(0);
  1123. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1124. }
  1125. static void sde_hw_sspp_setup_dgm_inverse_pma(struct sde_hw_pipe *ctx,
  1126. enum sde_sspp_multirect_index index, u32 enable)
  1127. {
  1128. u32 offset;
  1129. u32 op_mode = 0;
  1130. if (!ctx)
  1131. return;
  1132. if (index == SDE_SSPP_RECT_1)
  1133. offset = ctx->cap->sblk->unmult_offset[1];
  1134. else
  1135. offset = ctx->cap->sblk->unmult_offset[0];
  1136. op_mode = SDE_REG_READ(&ctx->hw, offset);
  1137. if (enable)
  1138. op_mode |= BIT(0);
  1139. else
  1140. op_mode &= ~BIT(0);
  1141. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1142. }
  1143. static void sde_hw_sspp_setup_dgm_csc(struct sde_hw_pipe *ctx,
  1144. enum sde_sspp_multirect_index index, struct sde_csc_cfg *data)
  1145. {
  1146. u32 idx = 0;
  1147. u32 offset;
  1148. u32 op_mode = 0;
  1149. const struct sde_sspp_sub_blks *sblk;
  1150. if (!ctx || !ctx->cap || !ctx->cap->sblk)
  1151. return;
  1152. sblk = ctx->cap->sblk;
  1153. if (index == SDE_SSPP_RECT_1)
  1154. idx = 1;
  1155. offset = sblk->dgm_csc_blk[idx].base;
  1156. if (data) {
  1157. op_mode |= BIT(0);
  1158. sde_hw_csc_matrix_coeff_setup(&ctx->hw,
  1159. offset + CSC_10BIT_OFFSET, data, DGM_CSC_MATRIX_SHIFT);
  1160. }
  1161. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1162. }
  1163. static bool sde_hw_sspp_setup_clk_force_ctrl(struct sde_hw_blk_reg_map *hw,
  1164. enum sde_clk_ctrl_type clk_ctrl, bool enable)
  1165. {
  1166. u32 reg_val, new_val;
  1167. if (!hw)
  1168. return false;
  1169. if (!SDE_CLK_CTRL_SSPP_VALID(clk_ctrl))
  1170. return false;
  1171. reg_val = SDE_REG_READ(hw, SSPP_CLK_CTRL);
  1172. if (enable)
  1173. new_val = reg_val | BIT(0);
  1174. else
  1175. new_val = reg_val & ~BIT(0);
  1176. SDE_REG_WRITE(hw, SSPP_CLK_CTRL, new_val);
  1177. wmb(); /* ensure write finished before progressing */
  1178. return !(reg_val & BIT(0));
  1179. }
  1180. static int sde_hw_sspp_get_clk_ctrl_status(struct sde_hw_blk_reg_map *hw,
  1181. enum sde_clk_ctrl_type clk_ctrl, bool *status)
  1182. {
  1183. if (!hw)
  1184. return -EINVAL;
  1185. if (!SDE_CLK_CTRL_SSPP_VALID(clk_ctrl))
  1186. return -EINVAL;
  1187. *status = SDE_REG_READ(hw, SSPP_CLK_STATUS) & BIT(0);
  1188. return 0;
  1189. }
  1190. static void _setup_layer_ops(struct sde_hw_pipe *c,
  1191. unsigned long features, unsigned long perf_features,
  1192. bool is_virtual_pipe)
  1193. {
  1194. int ret;
  1195. if (test_bit(SDE_SSPP_SRC, &features)) {
  1196. c->ops.setup_format = sde_hw_sspp_setup_format;
  1197. c->ops.setup_rects = sde_hw_sspp_setup_rects;
  1198. c->ops.setup_sourceaddress = sde_hw_sspp_setup_sourceaddress;
  1199. c->ops.get_sourceaddress = sde_hw_sspp_get_source_addr;
  1200. c->ops.setup_solidfill = sde_hw_sspp_setup_solidfill;
  1201. c->ops.setup_pe = sde_hw_sspp_setup_pe_config;
  1202. c->ops.setup_secure_address = sde_hw_sspp_setup_secure;
  1203. c->ops.set_src_split_order = sde_hw_sspp_set_src_split_order;
  1204. }
  1205. if (test_bit(SDE_SSPP_EXCL_RECT, &features))
  1206. c->ops.setup_excl_rect = _sde_hw_sspp_setup_excl_rect;
  1207. if (test_bit(SDE_PERF_SSPP_QOS, &features)) {
  1208. c->ops.setup_qos_lut =
  1209. sde_hw_sspp_setup_qos_lut;
  1210. c->ops.setup_qos_ctrl = sde_hw_sspp_setup_qos_ctrl;
  1211. }
  1212. if (test_bit(SDE_PERF_SSPP_TS_PREFILL, &perf_features))
  1213. c->ops.setup_ts_prefill = sde_hw_sspp_setup_ts_prefill;
  1214. if (test_bit(SDE_SSPP_CSC, &features) ||
  1215. test_bit(SDE_SSPP_CSC_10BIT, &features))
  1216. c->ops.setup_csc = sde_hw_sspp_setup_csc;
  1217. if (test_bit(SDE_SSPP_DGM_CSC, &features))
  1218. c->ops.setup_dgm_csc = sde_hw_sspp_setup_dgm_csc;
  1219. if (test_bit(SDE_SSPP_SCALER_QSEED2, &features)) {
  1220. c->ops.setup_sharpening = sde_hw_sspp_setup_sharpening;
  1221. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler;
  1222. }
  1223. if (sde_hw_sspp_multirect_enabled(c->cap))
  1224. c->ops.update_multirect = sde_hw_sspp_update_multirect;
  1225. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  1226. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features)) {
  1227. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler3;
  1228. c->ops.setup_scaler_lut = is_qseed3_rev_qseed3lite(
  1229. c->catalog) ? reg_dmav1_setup_scaler3lite_lut
  1230. : reg_dmav1_setup_scaler3_lut;
  1231. ret = reg_dmav1_init_sspp_op_v4(is_qseed3_rev_qseed3lite(
  1232. c->catalog) ? SDE_SSPP_SCALER_QSEED3LITE
  1233. : SDE_SSPP_SCALER_QSEED3, c->idx);
  1234. if (!ret)
  1235. c->ops.setup_scaler = reg_dmav1_setup_vig_qseed3;
  1236. }
  1237. if (test_bit(SDE_SSPP_MULTIRECT_ERROR, &features)) {
  1238. c->ops.get_meta_error = sde_hw_sspp_get_meta_error;
  1239. c->ops.clear_meta_error = sde_hw_sspp_clear_meta_error;
  1240. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error_v1;
  1241. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error_v1;
  1242. } else {
  1243. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error;
  1244. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error;
  1245. }
  1246. if (test_bit(SDE_SSPP_PREDOWNSCALE, &features))
  1247. c->ops.setup_pre_downscale = sde_hw_sspp_setup_pre_downscale;
  1248. if (test_bit(SDE_PERF_SSPP_SYS_CACHE, &perf_features))
  1249. c->ops.setup_sys_cache = sde_hw_sspp_setup_sys_cache;
  1250. if (test_bit(SDE_PERF_SSPP_CDP, &perf_features))
  1251. c->ops.setup_cdp = sde_hw_sspp_setup_cdp;
  1252. if (test_bit(SDE_PERF_SSPP_UIDLE, &perf_features)) {
  1253. c->ops.setup_uidle = sde_hw_sspp_setup_uidle;
  1254. if (test_bit(SDE_PERF_SSPP_UIDLE_FILL_LVL_SCALE, &perf_features))
  1255. c->ops.setup_uidle_fill_scale = sde_hw_sspp_setup_uidle_fill_scale;
  1256. }
  1257. _setup_layer_ops_colorproc(c, features, is_virtual_pipe);
  1258. if (test_bit(SDE_SSPP_DGM_INVERSE_PMA, &features))
  1259. c->ops.setup_inverse_pma = sde_hw_sspp_setup_dgm_inverse_pma;
  1260. else if (test_bit(SDE_SSPP_INVERSE_PMA, &features))
  1261. c->ops.setup_inverse_pma = sde_hw_sspp_setup_inverse_pma;
  1262. if (test_bit(SDE_SSPP_UBWC_STATS, &features)) {
  1263. c->ops.set_ubwc_stats_roi = sde_hw_sspp_ubwc_stats_set_roi;
  1264. c->ops.get_ubwc_stats_data = sde_hw_sspp_ubwc_stats_get_data;
  1265. }
  1266. }
  1267. static struct sde_sspp_cfg *_sspp_offset(enum sde_sspp sspp,
  1268. void __iomem *addr,
  1269. struct sde_mdss_cfg *catalog,
  1270. struct sde_hw_blk_reg_map *b)
  1271. {
  1272. int i;
  1273. struct sde_sspp_cfg *cfg;
  1274. if ((sspp < SSPP_MAX) && catalog && addr && b) {
  1275. for (i = 0; i < catalog->sspp_count; i++) {
  1276. if (sspp == catalog->sspp[i].id) {
  1277. b->base_off = addr;
  1278. b->blk_off = catalog->sspp[i].base;
  1279. b->length = catalog->sspp[i].len;
  1280. b->hw_rev = catalog->hw_rev;
  1281. b->log_mask = SDE_DBG_MASK_SSPP;
  1282. /* Only shallow copy is needed */
  1283. cfg = kmemdup(&catalog->sspp[i], sizeof(*cfg),
  1284. GFP_KERNEL);
  1285. if (!cfg)
  1286. return ERR_PTR(-ENOMEM);
  1287. return cfg;
  1288. }
  1289. }
  1290. }
  1291. return ERR_PTR(-ENOMEM);
  1292. }
  1293. struct sde_hw_pipe *sde_hw_sspp_init(enum sde_sspp idx,
  1294. void __iomem *addr, struct sde_mdss_cfg *catalog,
  1295. bool is_virtual_pipe, struct sde_vbif_clk_client *clk_client)
  1296. {
  1297. struct sde_hw_pipe *hw_pipe;
  1298. struct sde_sspp_cfg *cfg;
  1299. if (!addr || !catalog)
  1300. return ERR_PTR(-EINVAL);
  1301. hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
  1302. if (!hw_pipe)
  1303. return ERR_PTR(-ENOMEM);
  1304. cfg = _sspp_offset(idx, addr, catalog, &hw_pipe->hw);
  1305. if (IS_ERR_OR_NULL(cfg)) {
  1306. kfree(hw_pipe);
  1307. return ERR_PTR(-EINVAL);
  1308. }
  1309. /* Assign ops */
  1310. hw_pipe->catalog = catalog;
  1311. hw_pipe->mdp = &catalog->mdp[0];
  1312. hw_pipe->idx = idx;
  1313. hw_pipe->cap = cfg;
  1314. _setup_layer_ops(hw_pipe, hw_pipe->cap->features,
  1315. hw_pipe->cap->perf_features, is_virtual_pipe);
  1316. if (catalog->qseed_hw_rev)
  1317. sde_init_scaler_blk(&hw_pipe->cap->sblk->scaler_blk,
  1318. catalog->qseed_hw_rev);
  1319. if (!is_virtual_pipe) {
  1320. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  1321. hw_pipe->hw.blk_off,
  1322. hw_pipe->hw.blk_off + hw_pipe->hw.length,
  1323. hw_pipe->hw.xin_id);
  1324. if (test_bit(SDE_SSPP_DGM_CSC, &hw_pipe->cap->features)) {
  1325. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "CSC_0",
  1326. hw_pipe->hw.blk_off + SSPP_DGM_CSC_0,
  1327. hw_pipe->hw.blk_off + SSPP_DGM_CSC_0 + SSPP_DGM_CSC_SIZE,
  1328. hw_pipe->hw.xin_id);
  1329. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "CSC_1",
  1330. hw_pipe->hw.blk_off + SSPP_DGM_CSC_1,
  1331. hw_pipe->hw.blk_off + SSPP_DGM_CSC_1 + SSPP_DGM_CSC_SIZE,
  1332. hw_pipe->hw.xin_id);
  1333. }
  1334. if (test_bit(SDE_SSPP_DMA_IGC, &hw_pipe->cap->features)) {
  1335. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "DGM_0",
  1336. hw_pipe->hw.blk_off + SSPP_DGM_0,
  1337. hw_pipe->hw.blk_off + SSPP_DGM_0 + SSPP_DGM_SIZE,
  1338. hw_pipe->hw.xin_id);
  1339. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "DGM_1",
  1340. hw_pipe->hw.blk_off + SSPP_DGM_1,
  1341. hw_pipe->hw.blk_off + SSPP_DGM_1 + SSPP_DGM_SIZE,
  1342. hw_pipe->hw.xin_id);
  1343. }
  1344. if (test_bit(SDE_SSPP_VIG_GAMUT, &hw_pipe->cap->features)) {
  1345. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->sblk->gamut_blk.name,
  1346. hw_pipe->hw.blk_off + cfg->sblk->gamut_blk.base,
  1347. hw_pipe->hw.blk_off + cfg->sblk->gamut_blk.base + VIG_GAMUT_SIZE,
  1348. hw_pipe->hw.xin_id);
  1349. }
  1350. }
  1351. if (cfg->sblk->scaler_blk.len && !is_virtual_pipe)
  1352. sde_dbg_reg_register_dump_range(SDE_DBG_NAME,
  1353. cfg->sblk->scaler_blk.name,
  1354. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base,
  1355. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base +
  1356. cfg->sblk->scaler_blk.len,
  1357. hw_pipe->hw.xin_id);
  1358. if (test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, catalog->features)) {
  1359. if (SDE_CLK_CTRL_SSPP_VALID(cfg->clk_ctrl)) {
  1360. clk_client->hw = &hw_pipe->hw;
  1361. clk_client->clk_ctrl = cfg->clk_ctrl;
  1362. clk_client->ops.get_clk_ctrl_status = sde_hw_sspp_get_clk_ctrl_status;
  1363. clk_client->ops.setup_clk_force_ctrl = sde_hw_sspp_setup_clk_force_ctrl;
  1364. } else {
  1365. SDE_ERROR("invalid sspp clk ctrl type %d\n", cfg->clk_ctrl);
  1366. }
  1367. }
  1368. return hw_pipe;
  1369. }
  1370. void sde_hw_sspp_destroy(struct sde_hw_pipe *ctx)
  1371. {
  1372. if (ctx) {
  1373. reg_dmav1_deinit_sspp_ops(ctx->idx);
  1374. kfree(ctx->cap);
  1375. }
  1376. kfree(ctx);
  1377. }