sde_hw_sspp.c 38 KB

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