sde_hw_sspp.c 46 KB

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