sde_hw_sspp.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2020, 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. #define SDE_FETCH_CONFIG_RESET_VALUE 0x00000087
  14. /* SDE_SSPP_SRC */
  15. #define SSPP_SRC_SIZE 0x00
  16. #define SSPP_SRC_XY 0x08
  17. #define SSPP_OUT_SIZE 0x0c
  18. #define SSPP_OUT_XY 0x10
  19. #define SSPP_SRC0_ADDR 0x14
  20. #define SSPP_SRC1_ADDR 0x18
  21. #define SSPP_SRC2_ADDR 0x1C
  22. #define SSPP_SRC3_ADDR 0x20
  23. #define SSPP_SRC_YSTRIDE0 0x24
  24. #define SSPP_SRC_YSTRIDE1 0x28
  25. #define SSPP_SRC_FORMAT 0x30
  26. #define SSPP_SRC_UNPACK_PATTERN 0x34
  27. #define SSPP_SRC_OP_MODE 0x38
  28. /* SSPP_MULTIRECT*/
  29. #define SSPP_SRC_SIZE_REC1 0x16C
  30. #define SSPP_SRC_XY_REC1 0x168
  31. #define SSPP_OUT_SIZE_REC1 0x160
  32. #define SSPP_OUT_XY_REC1 0x164
  33. #define SSPP_SRC_FORMAT_REC1 0x174
  34. #define SSPP_SRC_UNPACK_PATTERN_REC1 0x178
  35. #define SSPP_SRC_OP_MODE_REC1 0x17C
  36. #define SSPP_MULTIRECT_OPMODE 0x170
  37. #define SSPP_SRC_CONSTANT_COLOR_REC1 0x180
  38. #define SSPP_EXCL_REC_SIZE_REC1 0x184
  39. #define SSPP_EXCL_REC_XY_REC1 0x188
  40. #define SSPP_UIDLE_CTRL_VALUE 0x1f0
  41. #define SSPP_UIDLE_CTRL_VALUE_REC1 0x1f4
  42. /* SSPP_DGM */
  43. #define SSPP_DGM_OP_MODE 0x804
  44. #define SSPP_DGM_OP_MODE_REC1 0x1804
  45. #define SSPP_GAMUT_UNMULT_MODE 0x1EA0
  46. #define MDSS_MDP_OP_DEINTERLACE BIT(22)
  47. #define MDSS_MDP_OP_DEINTERLACE_ODD BIT(23)
  48. #define MDSS_MDP_OP_IGC_ROM_1 BIT(18)
  49. #define MDSS_MDP_OP_IGC_ROM_0 BIT(17)
  50. #define MDSS_MDP_OP_IGC_EN BIT(16)
  51. #define MDSS_MDP_OP_FLIP_UD BIT(14)
  52. #define MDSS_MDP_OP_FLIP_LR BIT(13)
  53. #define MDSS_MDP_OP_SPLIT_ORDER BIT(4)
  54. #define MDSS_MDP_OP_BWC_EN BIT(0)
  55. #define MDSS_MDP_OP_PE_OVERRIDE BIT(31)
  56. #define MDSS_MDP_OP_BWC_LOSSLESS (0 << 1)
  57. #define MDSS_MDP_OP_BWC_Q_HIGH (1 << 1)
  58. #define MDSS_MDP_OP_BWC_Q_MED (2 << 1)
  59. #define SSPP_SRC_CONSTANT_COLOR 0x3c
  60. #define SSPP_EXCL_REC_CTL 0x40
  61. #define SSPP_UBWC_STATIC_CTRL 0x44
  62. #define SSPP_FETCH_CONFIG 0x48
  63. #define SSPP_PRE_DOWN_SCALE 0x50
  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;
  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. opmode = SDE_REG_READ(c, op_mode_off + idx);
  279. opmode &= ~(MDSS_MDP_OP_FLIP_LR | MDSS_MDP_OP_FLIP_UD |
  280. MDSS_MDP_OP_BWC_EN | MDSS_MDP_OP_PE_OVERRIDE);
  281. if (flags & SDE_SSPP_FLIP_LR)
  282. opmode |= MDSS_MDP_OP_FLIP_LR;
  283. if (flags & SDE_SSPP_FLIP_UD)
  284. opmode |= MDSS_MDP_OP_FLIP_UD;
  285. chroma_samp = fmt->chroma_sample;
  286. if (flags & SDE_SSPP_SOURCE_ROTATED_90) {
  287. if (chroma_samp == SDE_CHROMA_H2V1)
  288. chroma_samp = SDE_CHROMA_H1V2;
  289. else if (chroma_samp == SDE_CHROMA_H1V2)
  290. chroma_samp = SDE_CHROMA_H2V1;
  291. }
  292. src_format = (chroma_samp << 23) | (fmt->fetch_planes << 19) |
  293. (fmt->bits[C3_ALPHA] << 6) | (fmt->bits[C2_R_Cr] << 4) |
  294. (fmt->bits[C1_B_Cb] << 2) | (fmt->bits[C0_G_Y] << 0);
  295. if (flags & SDE_SSPP_ROT_90)
  296. src_format |= BIT(11); /* ROT90 */
  297. if (fmt->alpha_enable && fmt->fetch_planes == SDE_PLANE_INTERLEAVED)
  298. src_format |= BIT(8); /* SRCC3_EN */
  299. if (flags & SDE_SSPP_SOLID_FILL)
  300. src_format |= BIT(22);
  301. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  302. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  303. src_format |= ((fmt->unpack_count - 1) << 12) |
  304. (fmt->unpack_tight << 17) |
  305. (fmt->unpack_align_msb << 18) |
  306. ((fmt->bpp - 1) << 9);
  307. if ((flags & SDE_SSPP_ROT_90) && test_bit(SDE_SSPP_INLINE_CONST_CLR,
  308. &ctx->cap->features))
  309. const_color_en = false;
  310. if (fmt->fetch_mode != SDE_FETCH_LINEAR) {
  311. if (SDE_FORMAT_IS_UBWC(fmt))
  312. opmode |= MDSS_MDP_OP_BWC_EN;
  313. src_format |= (fmt->fetch_mode & 3) << 30; /*FRAME_FORMAT */
  314. SDE_REG_WRITE(c, SSPP_FETCH_CONFIG,
  315. SDE_FETCH_CONFIG_RESET_VALUE |
  316. ctx->mdp->highest_bank_bit << 18);
  317. if (IS_UBWC_40_SUPPORTED(ctx->catalog->ubwc_version)) {
  318. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  319. SDE_FORMAT_IS_YUV(fmt) ? 0 : BIT(30));
  320. } else if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_version)) {
  321. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  322. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  323. alpha_en_mask | (ctx->mdp->ubwc_swizzle & 0x1) |
  324. BIT(8) | (ctx->mdp->highest_bank_bit << 4));
  325. } else if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_version)) {
  326. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  327. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  328. alpha_en_mask | (ctx->mdp->ubwc_swizzle) |
  329. (ctx->mdp->highest_bank_bit << 4));
  330. } else if (IS_UBWC_30_SUPPORTED(ctx->catalog->ubwc_version)) {
  331. color_en_mask = const_color_en ? BIT(30) : 0;
  332. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  333. color_en_mask | (ctx->mdp->ubwc_swizzle) |
  334. (ctx->mdp->highest_bank_bit << 4));
  335. }
  336. }
  337. opmode |= MDSS_MDP_OP_PE_OVERRIDE;
  338. /* if this is YUV pixel format, enable CSC */
  339. if (SDE_FORMAT_IS_YUV(fmt))
  340. src_format |= BIT(15);
  341. if (SDE_FORMAT_IS_DX(fmt))
  342. src_format |= BIT(14);
  343. /* update scaler opmode, if appropriate */
  344. if (test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  345. _sspp_setup_opmode(ctx, VIG_OP_CSC_EN | VIG_OP_CSC_SRC_DATAFMT,
  346. SDE_FORMAT_IS_YUV(fmt));
  347. else if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features))
  348. _sspp_setup_csc10_opmode(ctx,
  349. VIG_CSC_10_EN | VIG_CSC_10_SRC_DATAFMT,
  350. SDE_FORMAT_IS_YUV(fmt));
  351. SDE_REG_WRITE(c, format_off + idx, src_format);
  352. SDE_REG_WRITE(c, unpack_pat_off + idx, unpack);
  353. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  354. /* clear previous UBWC error */
  355. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS + idx, BIT(31));
  356. }
  357. static void sde_hw_sspp_clear_ubwc_error(struct sde_hw_pipe *ctx)
  358. {
  359. struct sde_hw_blk_reg_map *c;
  360. c = &ctx->hw;
  361. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  362. }
  363. static u32 sde_hw_sspp_get_ubwc_error(struct sde_hw_pipe *ctx)
  364. {
  365. struct sde_hw_blk_reg_map *c;
  366. u32 reg_code;
  367. c = &ctx->hw;
  368. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  369. return reg_code;
  370. }
  371. static void sde_hw_sspp_setup_secure(struct sde_hw_pipe *ctx,
  372. enum sde_sspp_multirect_index rect_mode,
  373. bool enable)
  374. {
  375. struct sde_hw_blk_reg_map *c;
  376. u32 secure = 0, secure_bit_mask;
  377. u32 idx;
  378. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  379. return;
  380. c = &ctx->hw;
  381. if ((rect_mode == SDE_SSPP_RECT_SOLO)
  382. || (rect_mode == SDE_SSPP_RECT_0))
  383. secure_bit_mask =
  384. (rect_mode == SDE_SSPP_RECT_SOLO) ? 0xF : 0x5;
  385. else
  386. secure_bit_mask = 0xA;
  387. secure = SDE_REG_READ(c, SSPP_SRC_ADDR_SW_STATUS + idx);
  388. if (enable)
  389. secure |= secure_bit_mask;
  390. else
  391. secure &= ~secure_bit_mask;
  392. SDE_REG_WRITE(c, SSPP_SRC_ADDR_SW_STATUS + idx, secure);
  393. /* multiple planes share same sw_status register */
  394. wmb();
  395. }
  396. static void sde_hw_sspp_setup_pe_config(struct sde_hw_pipe *ctx,
  397. struct sde_hw_pixel_ext *pe_ext)
  398. {
  399. struct sde_hw_blk_reg_map *c;
  400. u8 color;
  401. u32 lr_pe[4], tb_pe[4], tot_req_pixels[4];
  402. const u32 bytemask = 0xff;
  403. const u32 shortmask = 0xffff;
  404. u32 idx;
  405. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !pe_ext)
  406. return;
  407. c = &ctx->hw;
  408. /* program SW pixel extension override for all pipes*/
  409. for (color = 0; color < SDE_MAX_PLANES; color++) {
  410. /* color 2 has the same set of registers as color 1 */
  411. if (color == 2)
  412. continue;
  413. lr_pe[color] = ((pe_ext->right_ftch[color] & bytemask) << 24)|
  414. ((pe_ext->right_rpt[color] & bytemask) << 16)|
  415. ((pe_ext->left_ftch[color] & bytemask) << 8)|
  416. (pe_ext->left_rpt[color] & bytemask);
  417. tb_pe[color] = ((pe_ext->btm_ftch[color] & bytemask) << 24)|
  418. ((pe_ext->btm_rpt[color] & bytemask) << 16)|
  419. ((pe_ext->top_ftch[color] & bytemask) << 8)|
  420. (pe_ext->top_rpt[color] & bytemask);
  421. tot_req_pixels[color] = (((pe_ext->roi_h[color] +
  422. pe_ext->num_ext_pxls_top[color] +
  423. pe_ext->num_ext_pxls_btm[color]) & shortmask) << 16) |
  424. ((pe_ext->roi_w[color] +
  425. pe_ext->num_ext_pxls_left[color] +
  426. pe_ext->num_ext_pxls_right[color]) & shortmask);
  427. }
  428. /* color 0 */
  429. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_LR + idx, lr_pe[0]);
  430. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_TB + idx, tb_pe[0]);
  431. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_REQ_PIXELS + idx,
  432. tot_req_pixels[0]);
  433. /* color 1 and color 2 */
  434. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_LR + idx, lr_pe[1]);
  435. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_TB + idx, tb_pe[1]);
  436. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS + idx,
  437. tot_req_pixels[1]);
  438. /* color 3 */
  439. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_LR + idx, lr_pe[3]);
  440. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_TB + idx, lr_pe[3]);
  441. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_REQ_PIXELS + idx,
  442. tot_req_pixels[3]);
  443. }
  444. static void _sde_hw_sspp_setup_scaler(struct sde_hw_pipe *ctx,
  445. struct sde_hw_pipe_cfg *sspp,
  446. struct sde_hw_pixel_ext *pe,
  447. void *scaler_cfg)
  448. {
  449. struct sde_hw_blk_reg_map *c;
  450. int config_h = 0x0;
  451. int config_v = 0x0;
  452. u32 idx;
  453. (void)sspp;
  454. (void)scaler_cfg;
  455. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !pe)
  456. return;
  457. c = &ctx->hw;
  458. /* enable scaler(s) if valid filter set */
  459. if (pe->horz_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  460. config_h |= pe->horz_filter[SDE_SSPP_COMP_0] << 8;
  461. if (pe->horz_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  462. config_h |= pe->horz_filter[SDE_SSPP_COMP_1_2] << 12;
  463. if (pe->horz_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  464. config_h |= pe->horz_filter[SDE_SSPP_COMP_3] << 16;
  465. if (config_h)
  466. config_h |= BIT(0);
  467. if (pe->vert_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  468. config_v |= pe->vert_filter[SDE_SSPP_COMP_0] << 10;
  469. if (pe->vert_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  470. config_v |= pe->vert_filter[SDE_SSPP_COMP_1_2] << 14;
  471. if (pe->vert_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  472. config_v |= pe->vert_filter[SDE_SSPP_COMP_3] << 18;
  473. if (config_v)
  474. config_v |= BIT(1);
  475. SDE_REG_WRITE(c, SCALE_CONFIG + idx, config_h | config_v);
  476. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_X + idx,
  477. pe->init_phase_x[SDE_SSPP_COMP_0]);
  478. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_Y + idx,
  479. pe->init_phase_y[SDE_SSPP_COMP_0]);
  480. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_X + idx,
  481. pe->phase_step_x[SDE_SSPP_COMP_0]);
  482. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_Y + idx,
  483. pe->phase_step_y[SDE_SSPP_COMP_0]);
  484. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_X + idx,
  485. pe->init_phase_x[SDE_SSPP_COMP_1_2]);
  486. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_Y + idx,
  487. pe->init_phase_y[SDE_SSPP_COMP_1_2]);
  488. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_X + idx,
  489. pe->phase_step_x[SDE_SSPP_COMP_1_2]);
  490. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_Y + idx,
  491. pe->phase_step_y[SDE_SSPP_COMP_1_2]);
  492. }
  493. static void _sde_hw_sspp_setup_scaler3(struct sde_hw_pipe *ctx,
  494. struct sde_hw_pipe_cfg *sspp,
  495. struct sde_hw_pixel_ext *pe,
  496. void *scaler_cfg)
  497. {
  498. u32 idx;
  499. struct sde_hw_scaler3_cfg *scaler3_cfg = scaler_cfg;
  500. (void)pe;
  501. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED3, &idx) || !sspp
  502. || !scaler3_cfg || !ctx || !ctx->cap || !ctx->cap->sblk)
  503. return;
  504. sde_hw_setup_scaler3(&ctx->hw, scaler3_cfg,
  505. ctx->cap->sblk->scaler_blk.version, idx, sspp->layout.format);
  506. }
  507. static void sde_hw_sspp_setup_pre_downscale(struct sde_hw_pipe *ctx,
  508. struct sde_hw_inline_pre_downscale_cfg *pre_down)
  509. {
  510. u32 idx, val;
  511. if (!ctx || !pre_down || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  512. return;
  513. val = pre_down->pre_downscale_x_0 |
  514. (pre_down->pre_downscale_x_1 << 4) |
  515. (pre_down->pre_downscale_y_0 << 8) |
  516. (pre_down->pre_downscale_y_1 << 12);
  517. SDE_REG_WRITE(&ctx->hw, SSPP_PRE_DOWN_SCALE + idx, val);
  518. }
  519. static u32 _sde_hw_sspp_get_scaler3_ver(struct sde_hw_pipe *ctx)
  520. {
  521. u32 idx;
  522. if (!ctx || _sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED3, &idx))
  523. return 0;
  524. return sde_hw_get_scaler3_ver(&ctx->hw, idx);
  525. }
  526. /**
  527. * sde_hw_sspp_setup_rects()
  528. */
  529. static void sde_hw_sspp_setup_rects(struct sde_hw_pipe *ctx,
  530. struct sde_hw_pipe_cfg *cfg,
  531. enum sde_sspp_multirect_index rect_index)
  532. {
  533. struct sde_hw_blk_reg_map *c;
  534. u32 src_size, src_xy, dst_size, dst_xy, ystride0, ystride1;
  535. u32 src_size_off, src_xy_off, out_size_off, out_xy_off;
  536. u32 decimation = 0;
  537. u32 idx;
  538. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !cfg)
  539. return;
  540. c = &ctx->hw;
  541. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0) {
  542. src_size_off = SSPP_SRC_SIZE;
  543. src_xy_off = SSPP_SRC_XY;
  544. out_size_off = SSPP_OUT_SIZE;
  545. out_xy_off = SSPP_OUT_XY;
  546. } else {
  547. src_size_off = SSPP_SRC_SIZE_REC1;
  548. src_xy_off = SSPP_SRC_XY_REC1;
  549. out_size_off = SSPP_OUT_SIZE_REC1;
  550. out_xy_off = SSPP_OUT_XY_REC1;
  551. }
  552. /* src and dest rect programming */
  553. src_xy = (cfg->src_rect.y << 16) | (cfg->src_rect.x);
  554. src_size = (cfg->src_rect.h << 16) | (cfg->src_rect.w);
  555. dst_xy = (cfg->dst_rect.y << 16) | (cfg->dst_rect.x);
  556. dst_size = (cfg->dst_rect.h << 16) | (cfg->dst_rect.w);
  557. if (rect_index == SDE_SSPP_RECT_SOLO) {
  558. ystride0 = (cfg->layout.plane_pitch[0]) |
  559. (cfg->layout.plane_pitch[1] << 16);
  560. ystride1 = (cfg->layout.plane_pitch[2]) |
  561. (cfg->layout.plane_pitch[3] << 16);
  562. } else {
  563. ystride0 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE0 + idx);
  564. ystride1 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE1 + idx);
  565. if (rect_index == SDE_SSPP_RECT_0) {
  566. ystride0 = (ystride0 & 0xFFFF0000) |
  567. (cfg->layout.plane_pitch[0] & 0x0000FFFF);
  568. ystride1 = (ystride1 & 0xFFFF0000)|
  569. (cfg->layout.plane_pitch[2] & 0x0000FFFF);
  570. } else {
  571. ystride0 = (ystride0 & 0x0000FFFF) |
  572. ((cfg->layout.plane_pitch[0] << 16) &
  573. 0xFFFF0000);
  574. ystride1 = (ystride1 & 0x0000FFFF) |
  575. ((cfg->layout.plane_pitch[2] << 16) &
  576. 0xFFFF0000);
  577. }
  578. }
  579. /* program scaler, phase registers, if pipes supporting scaling */
  580. if (ctx->cap->features & SDE_SSPP_SCALER) {
  581. /* program decimation */
  582. decimation = ((1 << cfg->horz_decimation) - 1) << 8;
  583. decimation |= ((1 << cfg->vert_decimation) - 1);
  584. }
  585. /* rectangle register programming */
  586. SDE_REG_WRITE(c, src_size_off + idx, src_size);
  587. SDE_REG_WRITE(c, src_xy_off + idx, src_xy);
  588. SDE_REG_WRITE(c, out_size_off + idx, dst_size);
  589. SDE_REG_WRITE(c, out_xy_off + idx, dst_xy);
  590. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE0 + idx, ystride0);
  591. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE1 + idx, ystride1);
  592. SDE_REG_WRITE(c, SSPP_DECIMATION_CONFIG + idx, decimation);
  593. }
  594. /**
  595. * _sde_hw_sspp_setup_excl_rect() - set exclusion rect configs
  596. * @ctx: Pointer to pipe context
  597. * @excl_rect: Exclusion rect configs
  598. */
  599. static void _sde_hw_sspp_setup_excl_rect(struct sde_hw_pipe *ctx,
  600. struct sde_rect *excl_rect,
  601. enum sde_sspp_multirect_index rect_index)
  602. {
  603. struct sde_hw_blk_reg_map *c;
  604. u32 size, xy;
  605. u32 idx;
  606. u32 reg_xy, reg_size;
  607. u32 excl_ctrl = BIT(0);
  608. u32 enable_bit;
  609. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !excl_rect)
  610. return;
  611. if (rect_index == SDE_SSPP_RECT_0 || rect_index == SDE_SSPP_RECT_SOLO) {
  612. reg_xy = SSPP_EXCL_REC_XY;
  613. reg_size = SSPP_EXCL_REC_SIZE;
  614. enable_bit = BIT(0);
  615. } else {
  616. reg_xy = SSPP_EXCL_REC_XY_REC1;
  617. reg_size = SSPP_EXCL_REC_SIZE_REC1;
  618. enable_bit = BIT(1);
  619. }
  620. c = &ctx->hw;
  621. xy = (excl_rect->y << 16) | (excl_rect->x);
  622. size = (excl_rect->h << 16) | (excl_rect->w);
  623. /* Set if multi-rect disabled, read+modify only if multi-rect enabled */
  624. if (rect_index != SDE_SSPP_RECT_SOLO)
  625. excl_ctrl = SDE_REG_READ(c, SSPP_EXCL_REC_CTL + idx);
  626. if (!size) {
  627. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  628. excl_ctrl & ~enable_bit);
  629. } else {
  630. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  631. excl_ctrl | enable_bit);
  632. SDE_REG_WRITE(c, reg_size + idx, size);
  633. SDE_REG_WRITE(c, reg_xy + idx, xy);
  634. }
  635. }
  636. static void sde_hw_sspp_setup_sourceaddress(struct sde_hw_pipe *ctx,
  637. struct sde_hw_pipe_cfg *cfg,
  638. enum sde_sspp_multirect_index rect_mode)
  639. {
  640. int i;
  641. u32 idx;
  642. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  643. return;
  644. if (rect_mode == SDE_SSPP_RECT_SOLO) {
  645. for (i = 0; i < ARRAY_SIZE(cfg->layout.plane_addr); i++)
  646. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx + i * 0x4,
  647. cfg->layout.plane_addr[i]);
  648. } else if (rect_mode == SDE_SSPP_RECT_0) {
  649. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx,
  650. cfg->layout.plane_addr[0]);
  651. SDE_REG_WRITE(&ctx->hw, SSPP_SRC2_ADDR + idx,
  652. cfg->layout.plane_addr[2]);
  653. } else {
  654. SDE_REG_WRITE(&ctx->hw, SSPP_SRC1_ADDR + idx,
  655. cfg->layout.plane_addr[0]);
  656. SDE_REG_WRITE(&ctx->hw, SSPP_SRC3_ADDR + idx,
  657. cfg->layout.plane_addr[2]);
  658. }
  659. }
  660. u32 sde_hw_sspp_get_source_addr(struct sde_hw_pipe *ctx, bool is_virtual)
  661. {
  662. u32 idx;
  663. u32 offset = 0;
  664. if (!ctx || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  665. return 0;
  666. offset = is_virtual ? (SSPP_SRC1_ADDR + idx) : (SSPP_SRC0_ADDR + idx);
  667. return SDE_REG_READ(&ctx->hw, offset);
  668. }
  669. static void sde_hw_sspp_setup_csc(struct sde_hw_pipe *ctx,
  670. struct sde_csc_cfg *data)
  671. {
  672. u32 idx;
  673. bool csc10 = false;
  674. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC, &idx) || !data)
  675. return;
  676. if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features)) {
  677. idx += CSC_10BIT_OFFSET;
  678. csc10 = true;
  679. }
  680. sde_hw_csc_setup(&ctx->hw, idx, data, csc10);
  681. }
  682. static void sde_hw_sspp_setup_sharpening(struct sde_hw_pipe *ctx,
  683. struct sde_hw_sharp_cfg *cfg)
  684. {
  685. struct sde_hw_blk_reg_map *c;
  686. u32 idx;
  687. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !cfg ||
  688. !test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features))
  689. return;
  690. c = &ctx->hw;
  691. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx, cfg->strength);
  692. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x4, cfg->edge_thr);
  693. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x8, cfg->smooth_thr);
  694. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0xC, cfg->noise_thr);
  695. }
  696. static void sde_hw_sspp_setup_solidfill(struct sde_hw_pipe *ctx, u32 color, enum
  697. sde_sspp_multirect_index rect_index)
  698. {
  699. u32 idx;
  700. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  701. return;
  702. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0)
  703. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR + idx, color);
  704. else
  705. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR_REC1 + idx,
  706. color);
  707. }
  708. static void sde_hw_sspp_setup_qos_lut(struct sde_hw_pipe *ctx,
  709. struct sde_hw_pipe_qos_cfg *cfg)
  710. {
  711. u32 idx;
  712. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  713. return;
  714. SDE_REG_WRITE(&ctx->hw, SSPP_DANGER_LUT + idx, cfg->danger_lut);
  715. SDE_REG_WRITE(&ctx->hw, SSPP_SAFE_LUT + idx, cfg->safe_lut);
  716. if (ctx->cap && test_bit(SDE_PERF_SSPP_QOS_8LVL,
  717. &ctx->cap->perf_features)) {
  718. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_0 + idx, cfg->creq_lut);
  719. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_1 + idx,
  720. cfg->creq_lut >> 32);
  721. } else {
  722. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT + idx, cfg->creq_lut);
  723. }
  724. }
  725. static void sde_hw_sspp_setup_qos_ctrl(struct sde_hw_pipe *ctx,
  726. struct sde_hw_pipe_qos_cfg *cfg)
  727. {
  728. u32 idx;
  729. u32 qos_ctrl = 0;
  730. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  731. return;
  732. if (cfg->vblank_en) {
  733. qos_ctrl |= ((cfg->creq_vblank &
  734. SSPP_QOS_CTRL_CREQ_VBLANK_MASK) <<
  735. SSPP_QOS_CTRL_CREQ_VBLANK_OFF);
  736. qos_ctrl |= ((cfg->danger_vblank &
  737. SSPP_QOS_CTRL_DANGER_VBLANK_MASK) <<
  738. SSPP_QOS_CTRL_DANGER_VBLANK_OFF);
  739. qos_ctrl |= SSPP_QOS_CTRL_VBLANK_EN;
  740. }
  741. if (cfg->danger_safe_en)
  742. qos_ctrl |= SSPP_QOS_CTRL_DANGER_SAFE_EN;
  743. SDE_REG_WRITE(&ctx->hw, SSPP_QOS_CTRL + idx, qos_ctrl);
  744. }
  745. static void sde_hw_sspp_setup_ts_prefill(struct sde_hw_pipe *ctx,
  746. struct sde_hw_pipe_ts_cfg *cfg,
  747. enum sde_sspp_multirect_index index)
  748. {
  749. u32 idx;
  750. u32 ts_offset, ts_prefill_offset;
  751. u32 ts_count = 0, ts_bytes = 0;
  752. const struct sde_sspp_cfg *cap;
  753. if (!ctx || !cfg || !ctx->cap)
  754. return;
  755. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  756. return;
  757. cap = ctx->cap;
  758. if ((index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) &&
  759. test_bit(SDE_PERF_SSPP_TS_PREFILL,
  760. &cap->perf_features)) {
  761. ts_offset = SSPP_TRAFFIC_SHAPER;
  762. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_PREFILL;
  763. } else if (index == SDE_SSPP_RECT_1 &&
  764. test_bit(SDE_PERF_SSPP_TS_PREFILL_REC1,
  765. &cap->perf_features)) {
  766. ts_offset = SSPP_TRAFFIC_SHAPER_REC1;
  767. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_REC1_PREFILL;
  768. } else {
  769. pr_err("%s: unexpected idx:%d\n", __func__, index);
  770. return;
  771. }
  772. if (cfg->time) {
  773. u64 temp = DIV_ROUND_UP_ULL(TS_CLK * 1000000ULL, cfg->time);
  774. ts_bytes = temp * cfg->size;
  775. if (ts_bytes > SSPP_TRAFFIC_SHAPER_BPC_MAX)
  776. ts_bytes = SSPP_TRAFFIC_SHAPER_BPC_MAX;
  777. }
  778. if (ts_bytes) {
  779. ts_count = DIV_ROUND_UP_ULL(cfg->size, ts_bytes);
  780. ts_bytes |= BIT(31) | BIT(27);
  781. }
  782. SDE_REG_WRITE(&ctx->hw, ts_offset, ts_bytes);
  783. SDE_REG_WRITE(&ctx->hw, ts_prefill_offset, ts_count);
  784. }
  785. static void sde_hw_sspp_setup_cdp(struct sde_hw_pipe *ctx,
  786. struct sde_hw_pipe_cdp_cfg *cfg,
  787. enum sde_sspp_multirect_index index)
  788. {
  789. u32 idx;
  790. u32 cdp_cntl = 0;
  791. u32 cdp_cntl_offset = 0;
  792. if (!ctx || !cfg)
  793. return;
  794. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  795. return;
  796. if (index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) {
  797. cdp_cntl_offset = SSPP_CDP_CNTL;
  798. } else if (index == SDE_SSPP_RECT_1) {
  799. cdp_cntl_offset = SSPP_CDP_CNTL_REC1;
  800. } else {
  801. pr_err("%s: unexpected idx:%d\n", __func__, index);
  802. return;
  803. }
  804. if (cfg->enable)
  805. cdp_cntl |= BIT(0);
  806. if (cfg->ubwc_meta_enable)
  807. cdp_cntl |= BIT(1);
  808. if (cfg->tile_amortize_enable)
  809. cdp_cntl |= BIT(2);
  810. if (cfg->preload_ahead == SDE_SSPP_CDP_PRELOAD_AHEAD_64)
  811. cdp_cntl |= BIT(3);
  812. SDE_REG_WRITE(&ctx->hw, cdp_cntl_offset, cdp_cntl);
  813. }
  814. static void sde_hw_sspp_setup_sys_cache(struct sde_hw_pipe *ctx,
  815. struct sde_hw_pipe_sc_cfg *cfg)
  816. {
  817. u32 idx, val;
  818. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  819. return;
  820. if (!cfg)
  821. return;
  822. val = SDE_REG_READ(&ctx->hw, SSPP_SYS_CACHE_MODE + idx);
  823. if (cfg->flags & SSPP_SYS_CACHE_EN_FLAG)
  824. val = (val & ~BIT(15)) | ((cfg->rd_en & 0x1) << 15);
  825. if (cfg->flags & SSPP_SYS_CACHE_SCID)
  826. val = (val & ~0x1F00) | ((cfg->rd_scid & 0x1f) << 8);
  827. if (cfg->flags & SSPP_SYS_CACHE_OP_MODE)
  828. val = (val & ~0xC0000) | ((cfg->op_mode & 0x3) << 18);
  829. if (cfg->flags & SSPP_SYS_CACHE_OP_TYPE)
  830. val = (val & ~0xF) | ((cfg->rd_op_type & 0xf) << 0);
  831. if (cfg->flags & SSPP_SYS_CACHE_NO_ALLOC)
  832. val = (val & ~0x10) | ((cfg->rd_noallocate & 0x1) << 4);
  833. SDE_REG_WRITE(&ctx->hw, SSPP_SYS_CACHE_MODE + idx, val);
  834. }
  835. static void sde_hw_sspp_setup_uidle(struct sde_hw_pipe *ctx,
  836. struct sde_hw_pipe_uidle_cfg *cfg,
  837. enum sde_sspp_multirect_index index)
  838. {
  839. u32 idx, val;
  840. u32 offset;
  841. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  842. return;
  843. if (index == SDE_SSPP_RECT_1)
  844. offset = SSPP_UIDLE_CTRL_VALUE_REC1;
  845. else
  846. offset = SSPP_UIDLE_CTRL_VALUE;
  847. val = SDE_REG_READ(&ctx->hw, offset + idx);
  848. val = (val & ~BIT(31)) | (cfg->enable ? 0x0 : BIT(31));
  849. val = (val & ~0xFF00000) | (cfg->fal_allowed_threshold << 20);
  850. val = (val & ~0xF0000) | (cfg->fal10_exit_threshold << 16);
  851. val = (val & ~0xF00) | (cfg->fal10_threshold << 8);
  852. val = (val & ~0xF) | (cfg->fal1_threshold << 0);
  853. SDE_REG_WRITE(&ctx->hw, offset + idx, val);
  854. }
  855. static void _setup_layer_ops_colorproc(struct sde_hw_pipe *c,
  856. unsigned long features, bool is_virtual_pipe)
  857. {
  858. int ret = 0;
  859. if (is_virtual_pipe) {
  860. features &=
  861. ~(BIT(SDE_SSPP_VIG_IGC) | BIT(SDE_SSPP_VIG_GAMUT));
  862. c->cap->features = features;
  863. }
  864. if (test_bit(SDE_SSPP_HSIC, &features)) {
  865. if (c->cap->sblk->hsic_blk.version ==
  866. (SDE_COLOR_PROCESS_VER(0x1, 0x7))) {
  867. c->ops.setup_pa_hue = sde_setup_pipe_pa_hue_v1_7;
  868. c->ops.setup_pa_sat = sde_setup_pipe_pa_sat_v1_7;
  869. c->ops.setup_pa_val = sde_setup_pipe_pa_val_v1_7;
  870. c->ops.setup_pa_cont = sde_setup_pipe_pa_cont_v1_7;
  871. }
  872. }
  873. if (test_bit(SDE_SSPP_MEMCOLOR, &features)) {
  874. if (c->cap->sblk->memcolor_blk.version ==
  875. (SDE_COLOR_PROCESS_VER(0x1, 0x7)))
  876. c->ops.setup_pa_memcolor =
  877. sde_setup_pipe_pa_memcol_v1_7;
  878. }
  879. if (test_bit(SDE_SSPP_VIG_GAMUT, &features)) {
  880. if (c->cap->sblk->gamut_blk.version ==
  881. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  882. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  883. c->idx);
  884. if (!ret)
  885. c->ops.setup_vig_gamut =
  886. reg_dmav1_setup_vig_gamutv5;
  887. else
  888. c->ops.setup_vig_gamut = NULL;
  889. }
  890. if (c->cap->sblk->gamut_blk.version ==
  891. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  892. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  893. c->idx);
  894. if (!ret)
  895. c->ops.setup_vig_gamut =
  896. reg_dmav1_setup_vig_gamutv6;
  897. else
  898. c->ops.setup_vig_gamut = NULL;
  899. } else if (c->cap->sblk->gamut_blk.version ==
  900. (SDE_COLOR_PROCESS_VER(0x6, 0x1))) {
  901. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  902. c->idx);
  903. if (!ret)
  904. c->ops.setup_vig_gamut =
  905. reg_dmav2_setup_vig_gamutv61;
  906. else
  907. c->ops.setup_vig_gamut = NULL;
  908. }
  909. }
  910. if (test_bit(SDE_SSPP_VIG_IGC, &features)) {
  911. if (c->cap->sblk->igc_blk[0].version ==
  912. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  913. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  914. c->idx);
  915. if (!ret)
  916. c->ops.setup_vig_igc =
  917. reg_dmav1_setup_vig_igcv5;
  918. else
  919. c->ops.setup_vig_igc = NULL;
  920. }
  921. if (c->cap->sblk->igc_blk[0].version ==
  922. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  923. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  924. c->idx);
  925. if (!ret)
  926. c->ops.setup_vig_igc =
  927. reg_dmav1_setup_vig_igcv6;
  928. else
  929. c->ops.setup_vig_igc = NULL;
  930. }
  931. }
  932. if (test_bit(SDE_SSPP_DMA_IGC, &features)) {
  933. if (c->cap->sblk->igc_blk[0].version ==
  934. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  935. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_IGC,
  936. c->idx);
  937. if (!ret)
  938. c->ops.setup_dma_igc =
  939. reg_dmav1_setup_dma_igcv5;
  940. else
  941. c->ops.setup_dma_igc = NULL;
  942. }
  943. }
  944. if (test_bit(SDE_SSPP_DMA_GC, &features)) {
  945. if (c->cap->sblk->gc_blk[0].version ==
  946. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  947. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_GC,
  948. c->idx);
  949. if (!ret)
  950. c->ops.setup_dma_gc =
  951. reg_dmav1_setup_dma_gcv5;
  952. else
  953. c->ops.setup_dma_gc = NULL;
  954. }
  955. }
  956. }
  957. static void sde_hw_sspp_setup_inverse_pma(struct sde_hw_pipe *ctx,
  958. enum sde_sspp_multirect_index index, u32 enable)
  959. {
  960. u32 op_mode = 0;
  961. if (!ctx || (index == SDE_SSPP_RECT_1))
  962. return;
  963. if (enable)
  964. op_mode |= BIT(0);
  965. SDE_REG_WRITE(&ctx->hw, SSPP_GAMUT_UNMULT_MODE, op_mode);
  966. }
  967. static void sde_hw_sspp_setup_dgm_inverse_pma(struct sde_hw_pipe *ctx,
  968. enum sde_sspp_multirect_index index, u32 enable)
  969. {
  970. u32 offset = SSPP_DGM_OP_MODE;
  971. u32 op_mode = 0;
  972. if (!ctx)
  973. return;
  974. if (index == SDE_SSPP_RECT_1)
  975. offset = SSPP_DGM_OP_MODE_REC1;
  976. op_mode = SDE_REG_READ(&ctx->hw, offset);
  977. if (enable)
  978. op_mode |= BIT(0);
  979. else
  980. op_mode &= ~BIT(0);
  981. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  982. }
  983. static void sde_hw_sspp_setup_dgm_csc(struct sde_hw_pipe *ctx,
  984. enum sde_sspp_multirect_index index, struct sde_csc_cfg *data)
  985. {
  986. u32 idx = 0;
  987. u32 offset;
  988. u32 op_mode = 0;
  989. const struct sde_sspp_sub_blks *sblk;
  990. if (!ctx || !ctx->cap || !ctx->cap->sblk)
  991. return;
  992. sblk = ctx->cap->sblk;
  993. if (index == SDE_SSPP_RECT_1)
  994. idx = 1;
  995. offset = sblk->dgm_csc_blk[idx].base;
  996. if (data) {
  997. op_mode |= BIT(0);
  998. sde_hw_csc_matrix_coeff_setup(&ctx->hw,
  999. offset + CSC_10BIT_OFFSET, data, DGM_CSC_MATRIX_SHIFT);
  1000. }
  1001. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1002. }
  1003. static void _setup_layer_ops(struct sde_hw_pipe *c,
  1004. unsigned long features, unsigned long perf_features,
  1005. bool is_virtual_pipe)
  1006. {
  1007. int ret;
  1008. if (test_bit(SDE_SSPP_SRC, &features)) {
  1009. c->ops.setup_format = sde_hw_sspp_setup_format;
  1010. c->ops.setup_rects = sde_hw_sspp_setup_rects;
  1011. c->ops.setup_sourceaddress = sde_hw_sspp_setup_sourceaddress;
  1012. c->ops.get_sourceaddress = sde_hw_sspp_get_source_addr;
  1013. c->ops.setup_solidfill = sde_hw_sspp_setup_solidfill;
  1014. c->ops.setup_pe = sde_hw_sspp_setup_pe_config;
  1015. c->ops.setup_secure_address = sde_hw_sspp_setup_secure;
  1016. c->ops.set_src_split_order = sde_hw_sspp_set_src_split_order;
  1017. }
  1018. if (test_bit(SDE_SSPP_EXCL_RECT, &features))
  1019. c->ops.setup_excl_rect = _sde_hw_sspp_setup_excl_rect;
  1020. if (test_bit(SDE_PERF_SSPP_QOS, &features)) {
  1021. c->ops.setup_qos_lut =
  1022. sde_hw_sspp_setup_qos_lut;
  1023. c->ops.setup_qos_ctrl = sde_hw_sspp_setup_qos_ctrl;
  1024. }
  1025. if (test_bit(SDE_PERF_SSPP_TS_PREFILL, &perf_features))
  1026. c->ops.setup_ts_prefill = sde_hw_sspp_setup_ts_prefill;
  1027. if (test_bit(SDE_SSPP_CSC, &features) ||
  1028. test_bit(SDE_SSPP_CSC_10BIT, &features))
  1029. c->ops.setup_csc = sde_hw_sspp_setup_csc;
  1030. if (test_bit(SDE_SSPP_DGM_CSC, &features))
  1031. c->ops.setup_dgm_csc = sde_hw_sspp_setup_dgm_csc;
  1032. if (test_bit(SDE_SSPP_SCALER_QSEED2, &features)) {
  1033. c->ops.setup_sharpening = sde_hw_sspp_setup_sharpening;
  1034. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler;
  1035. }
  1036. if (sde_hw_sspp_multirect_enabled(c->cap))
  1037. c->ops.setup_multirect = sde_hw_sspp_setup_multirect;
  1038. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  1039. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features)) {
  1040. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler3;
  1041. c->ops.get_scaler_ver = _sde_hw_sspp_get_scaler3_ver;
  1042. c->ops.setup_scaler_lut = is_qseed3_rev_qseed3lite(
  1043. c->catalog) ? reg_dmav1_setup_scaler3lite_lut
  1044. : reg_dmav1_setup_scaler3_lut;
  1045. ret = reg_dmav1_init_sspp_op_v4(is_qseed3_rev_qseed3lite(
  1046. c->catalog) ? SDE_SSPP_SCALER_QSEED3LITE
  1047. : SDE_SSPP_SCALER_QSEED3, c->idx);
  1048. if (!ret)
  1049. c->ops.setup_scaler = reg_dmav1_setup_vig_qseed3;
  1050. }
  1051. if (test_bit(SDE_SSPP_PREDOWNSCALE, &features))
  1052. c->ops.setup_pre_downscale = sde_hw_sspp_setup_pre_downscale;
  1053. if (test_bit(SDE_PERF_SSPP_SYS_CACHE, &perf_features))
  1054. c->ops.setup_sys_cache = sde_hw_sspp_setup_sys_cache;
  1055. if (test_bit(SDE_PERF_SSPP_CDP, &perf_features))
  1056. c->ops.setup_cdp = sde_hw_sspp_setup_cdp;
  1057. if (test_bit(SDE_PERF_SSPP_UIDLE, &perf_features))
  1058. c->ops.setup_uidle = sde_hw_sspp_setup_uidle;
  1059. _setup_layer_ops_colorproc(c, features, is_virtual_pipe);
  1060. if (test_bit(SDE_SSPP_DGM_INVERSE_PMA, &features))
  1061. c->ops.setup_inverse_pma = sde_hw_sspp_setup_dgm_inverse_pma;
  1062. else if (test_bit(SDE_SSPP_INVERSE_PMA, &features))
  1063. c->ops.setup_inverse_pma = sde_hw_sspp_setup_inverse_pma;
  1064. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error;
  1065. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error;
  1066. }
  1067. static struct sde_sspp_cfg *_sspp_offset(enum sde_sspp sspp,
  1068. void __iomem *addr,
  1069. struct sde_mdss_cfg *catalog,
  1070. struct sde_hw_blk_reg_map *b)
  1071. {
  1072. int i;
  1073. struct sde_sspp_cfg *cfg;
  1074. if ((sspp < SSPP_MAX) && catalog && addr && b) {
  1075. for (i = 0; i < catalog->sspp_count; i++) {
  1076. if (sspp == catalog->sspp[i].id) {
  1077. b->base_off = addr;
  1078. b->blk_off = catalog->sspp[i].base;
  1079. b->length = catalog->sspp[i].len;
  1080. b->hwversion = catalog->hwversion;
  1081. b->log_mask = SDE_DBG_MASK_SSPP;
  1082. /* Only shallow copy is needed */
  1083. cfg = kmemdup(&catalog->sspp[i], sizeof(*cfg),
  1084. GFP_KERNEL);
  1085. if (!cfg)
  1086. return ERR_PTR(-ENOMEM);
  1087. return cfg;
  1088. }
  1089. }
  1090. }
  1091. return ERR_PTR(-ENOMEM);
  1092. }
  1093. static struct sde_hw_blk_ops sde_hw_ops = {
  1094. .start = NULL,
  1095. .stop = NULL,
  1096. };
  1097. struct sde_hw_pipe *sde_hw_sspp_init(enum sde_sspp idx,
  1098. void __iomem *addr, struct sde_mdss_cfg *catalog,
  1099. bool is_virtual_pipe)
  1100. {
  1101. struct sde_hw_pipe *hw_pipe;
  1102. struct sde_sspp_cfg *cfg;
  1103. int rc;
  1104. if (!addr || !catalog)
  1105. return ERR_PTR(-EINVAL);
  1106. hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
  1107. if (!hw_pipe)
  1108. return ERR_PTR(-ENOMEM);
  1109. cfg = _sspp_offset(idx, addr, catalog, &hw_pipe->hw);
  1110. if (IS_ERR_OR_NULL(cfg)) {
  1111. kfree(hw_pipe);
  1112. return ERR_PTR(-EINVAL);
  1113. }
  1114. /* Assign ops */
  1115. hw_pipe->catalog = catalog;
  1116. hw_pipe->mdp = &catalog->mdp[0];
  1117. hw_pipe->idx = idx;
  1118. hw_pipe->cap = cfg;
  1119. _setup_layer_ops(hw_pipe, hw_pipe->cap->features,
  1120. hw_pipe->cap->perf_features, is_virtual_pipe);
  1121. if (hw_pipe->ops.get_scaler_ver) {
  1122. sde_init_scaler_blk(&hw_pipe->cap->sblk->scaler_blk,
  1123. hw_pipe->ops.get_scaler_ver(hw_pipe));
  1124. }
  1125. rc = sde_hw_blk_init(&hw_pipe->base, SDE_HW_BLK_SSPP, idx, &sde_hw_ops);
  1126. if (rc) {
  1127. SDE_ERROR("failed to init hw blk %d\n", rc);
  1128. goto blk_init_error;
  1129. }
  1130. if (!is_virtual_pipe)
  1131. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  1132. hw_pipe->hw.blk_off,
  1133. hw_pipe->hw.blk_off + hw_pipe->hw.length,
  1134. hw_pipe->hw.xin_id);
  1135. if (cfg->sblk->scaler_blk.len && !is_virtual_pipe)
  1136. sde_dbg_reg_register_dump_range(SDE_DBG_NAME,
  1137. cfg->sblk->scaler_blk.name,
  1138. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base,
  1139. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base +
  1140. cfg->sblk->scaler_blk.len,
  1141. hw_pipe->hw.xin_id);
  1142. return hw_pipe;
  1143. blk_init_error:
  1144. kzfree(hw_pipe);
  1145. return ERR_PTR(rc);
  1146. }
  1147. void sde_hw_sspp_destroy(struct sde_hw_pipe *ctx)
  1148. {
  1149. if (ctx) {
  1150. sde_hw_blk_destroy(&ctx->base);
  1151. reg_dmav1_deinit_sspp_ops(ctx->idx);
  1152. kfree(ctx->cap);
  1153. }
  1154. kfree(ctx);
  1155. }