sde_hw_sspp.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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_update_multirect(struct sde_hw_pipe *ctx,
  178. bool enable,
  179. enum sde_sspp_multirect_index index,
  180. enum sde_sspp_multirect_mode mode)
  181. {
  182. u32 mode_mask;
  183. u32 idx;
  184. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  185. return;
  186. if (index == SDE_SSPP_RECT_SOLO) {
  187. /**
  188. * if rect index is RECT_SOLO, we cannot expect a
  189. * virtual plane sharing the same SSPP id. So we go
  190. * and disable multirect
  191. */
  192. mode_mask = 0;
  193. } else {
  194. mode_mask = SDE_REG_READ(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx);
  195. if (enable)
  196. mode_mask |= index;
  197. else
  198. mode_mask &= ~index;
  199. if (enable && (mode == SDE_SSPP_MULTIRECT_TIME_MX))
  200. mode_mask |= BIT(2);
  201. else
  202. mode_mask &= ~BIT(2);
  203. }
  204. SDE_REG_WRITE(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx, mode_mask);
  205. }
  206. static void _sspp_setup_opmode(struct sde_hw_pipe *ctx,
  207. u32 mask, u8 en)
  208. {
  209. u32 idx;
  210. u32 opmode;
  211. if (!test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features) ||
  212. _sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) ||
  213. !test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  214. return;
  215. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_OP_MODE + idx);
  216. if (en)
  217. opmode |= mask;
  218. else
  219. opmode &= ~mask;
  220. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_OP_MODE + idx, opmode);
  221. }
  222. static void _sspp_setup_csc10_opmode(struct sde_hw_pipe *ctx,
  223. u32 mask, u8 en)
  224. {
  225. u32 idx;
  226. u32 opmode;
  227. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC_10BIT, &idx))
  228. return;
  229. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx);
  230. if (en)
  231. opmode |= mask;
  232. else
  233. opmode &= ~mask;
  234. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx, opmode);
  235. }
  236. static void sde_hw_sspp_set_src_split_order(struct sde_hw_pipe *ctx,
  237. enum sde_sspp_multirect_index rect_mode, bool enable)
  238. {
  239. struct sde_hw_blk_reg_map *c;
  240. u32 opmode, idx, op_mode_off;
  241. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  242. return;
  243. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0)
  244. op_mode_off = SSPP_SRC_OP_MODE;
  245. else
  246. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  247. c = &ctx->hw;
  248. opmode = SDE_REG_READ(c, op_mode_off + idx);
  249. if (enable)
  250. opmode |= MDSS_MDP_OP_SPLIT_ORDER;
  251. else
  252. opmode &= ~MDSS_MDP_OP_SPLIT_ORDER;
  253. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  254. }
  255. /**
  256. * Setup source pixel format, flip,
  257. */
  258. static void sde_hw_sspp_setup_format(struct sde_hw_pipe *ctx,
  259. const struct sde_format *fmt,
  260. bool const_alpha_en, u32 flags,
  261. enum sde_sspp_multirect_index rect_mode)
  262. {
  263. struct sde_hw_blk_reg_map *c;
  264. u32 chroma_samp, unpack, src_format;
  265. u32 opmode = 0;
  266. u32 alpha_en_mask = 0, color_en_mask = 0;
  267. u32 op_mode_off, unpack_pat_off, format_off;
  268. u32 idx;
  269. bool const_color_en = true;
  270. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !fmt)
  271. return;
  272. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0) {
  273. op_mode_off = SSPP_SRC_OP_MODE;
  274. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN;
  275. format_off = SSPP_SRC_FORMAT;
  276. } else {
  277. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  278. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN_REC1;
  279. format_off = SSPP_SRC_FORMAT_REC1;
  280. }
  281. c = &ctx->hw;
  282. opmode = SDE_REG_READ(c, op_mode_off + idx);
  283. opmode &= ~(MDSS_MDP_OP_FLIP_LR | MDSS_MDP_OP_FLIP_UD |
  284. MDSS_MDP_OP_BWC_EN | MDSS_MDP_OP_PE_OVERRIDE);
  285. if (flags & SDE_SSPP_FLIP_LR)
  286. opmode |= MDSS_MDP_OP_FLIP_LR;
  287. if (flags & SDE_SSPP_FLIP_UD)
  288. opmode |= MDSS_MDP_OP_FLIP_UD;
  289. chroma_samp = fmt->chroma_sample;
  290. if (flags & SDE_SSPP_SOURCE_ROTATED_90) {
  291. if (chroma_samp == SDE_CHROMA_H2V1)
  292. chroma_samp = SDE_CHROMA_H1V2;
  293. else if (chroma_samp == SDE_CHROMA_H1V2)
  294. chroma_samp = SDE_CHROMA_H2V1;
  295. }
  296. src_format = (chroma_samp << 23) | (fmt->fetch_planes << 19) |
  297. (fmt->bits[C3_ALPHA] << 6) | (fmt->bits[C2_R_Cr] << 4) |
  298. (fmt->bits[C1_B_Cb] << 2) | (fmt->bits[C0_G_Y] << 0);
  299. if (flags & SDE_SSPP_ROT_90)
  300. src_format |= BIT(11); /* ROT90 */
  301. if (fmt->alpha_enable && fmt->fetch_planes == SDE_PLANE_INTERLEAVED)
  302. src_format |= BIT(8); /* SRCC3_EN */
  303. if (flags & SDE_SSPP_SOLID_FILL)
  304. src_format |= BIT(22);
  305. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  306. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  307. src_format |= ((fmt->unpack_count - 1) << 12) |
  308. (fmt->unpack_tight << 17) |
  309. (fmt->unpack_align_msb << 18) |
  310. ((fmt->bpp - 1) << 9);
  311. if ((flags & SDE_SSPP_ROT_90) && test_bit(SDE_SSPP_INLINE_CONST_CLR,
  312. &ctx->cap->features))
  313. const_color_en = false;
  314. if (fmt->fetch_mode != SDE_FETCH_LINEAR) {
  315. if (SDE_FORMAT_IS_UBWC(fmt))
  316. opmode |= MDSS_MDP_OP_BWC_EN;
  317. src_format |= (fmt->fetch_mode & 3) << 30; /*FRAME_FORMAT */
  318. SDE_REG_WRITE(c, SSPP_FETCH_CONFIG,
  319. SDE_FETCH_CONFIG_RESET_VALUE |
  320. ctx->mdp->highest_bank_bit << 18);
  321. if (IS_UBWC_40_SUPPORTED(ctx->catalog->ubwc_version)) {
  322. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  323. SDE_FORMAT_IS_YUV(fmt) ? 0 : BIT(30));
  324. } else if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_version)) {
  325. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  326. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  327. alpha_en_mask | (ctx->mdp->ubwc_swizzle & 0x1) |
  328. BIT(8) | (ctx->mdp->highest_bank_bit << 4));
  329. } else if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_version)) {
  330. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  331. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  332. alpha_en_mask | (ctx->mdp->ubwc_swizzle) |
  333. (ctx->mdp->highest_bank_bit << 4));
  334. } else if (IS_UBWC_30_SUPPORTED(ctx->catalog->ubwc_version)) {
  335. color_en_mask = const_color_en ? BIT(30) : 0;
  336. SDE_REG_WRITE(c, SSPP_UBWC_STATIC_CTRL,
  337. color_en_mask | (ctx->mdp->ubwc_swizzle) |
  338. (ctx->mdp->highest_bank_bit << 4));
  339. }
  340. }
  341. opmode |= MDSS_MDP_OP_PE_OVERRIDE;
  342. /* if this is YUV pixel format, enable CSC */
  343. if (SDE_FORMAT_IS_YUV(fmt))
  344. src_format |= BIT(15);
  345. if (SDE_FORMAT_IS_DX(fmt))
  346. src_format |= BIT(14);
  347. /* update scaler opmode, if appropriate */
  348. if (test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  349. _sspp_setup_opmode(ctx, VIG_OP_CSC_EN | VIG_OP_CSC_SRC_DATAFMT,
  350. SDE_FORMAT_IS_YUV(fmt));
  351. else if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features))
  352. _sspp_setup_csc10_opmode(ctx,
  353. VIG_CSC_10_EN | VIG_CSC_10_SRC_DATAFMT,
  354. SDE_FORMAT_IS_YUV(fmt));
  355. SDE_REG_WRITE(c, format_off + idx, src_format);
  356. SDE_REG_WRITE(c, unpack_pat_off + idx, unpack);
  357. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  358. /* clear previous UBWC error */
  359. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS + idx, BIT(31));
  360. }
  361. static void sde_hw_sspp_clear_ubwc_error(struct sde_hw_pipe *ctx)
  362. {
  363. struct sde_hw_blk_reg_map *c;
  364. c = &ctx->hw;
  365. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  366. }
  367. static u32 sde_hw_sspp_get_ubwc_error(struct sde_hw_pipe *ctx)
  368. {
  369. struct sde_hw_blk_reg_map *c;
  370. u32 reg_code;
  371. c = &ctx->hw;
  372. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  373. return reg_code;
  374. }
  375. static void sde_hw_sspp_setup_secure(struct sde_hw_pipe *ctx,
  376. enum sde_sspp_multirect_index rect_mode,
  377. bool enable)
  378. {
  379. struct sde_hw_blk_reg_map *c;
  380. u32 secure = 0, secure_bit_mask;
  381. u32 idx;
  382. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  383. return;
  384. c = &ctx->hw;
  385. if ((rect_mode == SDE_SSPP_RECT_SOLO)
  386. || (rect_mode == SDE_SSPP_RECT_0))
  387. secure_bit_mask =
  388. (rect_mode == SDE_SSPP_RECT_SOLO) ? 0xF : 0x5;
  389. else
  390. secure_bit_mask = 0xA;
  391. secure = SDE_REG_READ(c, SSPP_SRC_ADDR_SW_STATUS + idx);
  392. if (enable)
  393. secure |= secure_bit_mask;
  394. else
  395. secure &= ~secure_bit_mask;
  396. SDE_REG_WRITE(c, SSPP_SRC_ADDR_SW_STATUS + idx, secure);
  397. /* multiple planes share same sw_status register */
  398. wmb();
  399. }
  400. static void sde_hw_sspp_setup_pe_config(struct sde_hw_pipe *ctx,
  401. struct sde_hw_pixel_ext *pe_ext)
  402. {
  403. struct sde_hw_blk_reg_map *c;
  404. u8 color;
  405. u32 lr_pe[4], tb_pe[4], tot_req_pixels[4];
  406. const u32 bytemask = 0xff;
  407. const u32 shortmask = 0xffff;
  408. u32 idx;
  409. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !pe_ext)
  410. return;
  411. c = &ctx->hw;
  412. /* program SW pixel extension override for all pipes*/
  413. for (color = 0; color < SDE_MAX_PLANES; color++) {
  414. /* color 2 has the same set of registers as color 1 */
  415. if (color == 2)
  416. continue;
  417. lr_pe[color] = ((pe_ext->right_ftch[color] & bytemask) << 24)|
  418. ((pe_ext->right_rpt[color] & bytemask) << 16)|
  419. ((pe_ext->left_ftch[color] & bytemask) << 8)|
  420. (pe_ext->left_rpt[color] & bytemask);
  421. tb_pe[color] = ((pe_ext->btm_ftch[color] & bytemask) << 24)|
  422. ((pe_ext->btm_rpt[color] & bytemask) << 16)|
  423. ((pe_ext->top_ftch[color] & bytemask) << 8)|
  424. (pe_ext->top_rpt[color] & bytemask);
  425. tot_req_pixels[color] = (((pe_ext->roi_h[color] +
  426. pe_ext->num_ext_pxls_top[color] +
  427. pe_ext->num_ext_pxls_btm[color]) & shortmask) << 16) |
  428. ((pe_ext->roi_w[color] +
  429. pe_ext->num_ext_pxls_left[color] +
  430. pe_ext->num_ext_pxls_right[color]) & shortmask);
  431. }
  432. /* color 0 */
  433. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_LR + idx, lr_pe[0]);
  434. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_TB + idx, tb_pe[0]);
  435. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_REQ_PIXELS + idx,
  436. tot_req_pixels[0]);
  437. /* color 1 and color 2 */
  438. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_LR + idx, lr_pe[1]);
  439. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_TB + idx, tb_pe[1]);
  440. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS + idx,
  441. tot_req_pixels[1]);
  442. /* color 3 */
  443. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_LR + idx, lr_pe[3]);
  444. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_TB + idx, lr_pe[3]);
  445. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_REQ_PIXELS + idx,
  446. tot_req_pixels[3]);
  447. }
  448. static void _sde_hw_sspp_setup_scaler(struct sde_hw_pipe *ctx,
  449. struct sde_hw_pipe_cfg *sspp,
  450. struct sde_hw_pixel_ext *pe,
  451. void *scaler_cfg)
  452. {
  453. struct sde_hw_blk_reg_map *c;
  454. int config_h = 0x0;
  455. int config_v = 0x0;
  456. u32 idx;
  457. (void)sspp;
  458. (void)scaler_cfg;
  459. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !pe)
  460. return;
  461. c = &ctx->hw;
  462. /* enable scaler(s) if valid filter set */
  463. if (pe->horz_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  464. config_h |= pe->horz_filter[SDE_SSPP_COMP_0] << 8;
  465. if (pe->horz_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  466. config_h |= pe->horz_filter[SDE_SSPP_COMP_1_2] << 12;
  467. if (pe->horz_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  468. config_h |= pe->horz_filter[SDE_SSPP_COMP_3] << 16;
  469. if (config_h)
  470. config_h |= BIT(0);
  471. if (pe->vert_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  472. config_v |= pe->vert_filter[SDE_SSPP_COMP_0] << 10;
  473. if (pe->vert_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  474. config_v |= pe->vert_filter[SDE_SSPP_COMP_1_2] << 14;
  475. if (pe->vert_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  476. config_v |= pe->vert_filter[SDE_SSPP_COMP_3] << 18;
  477. if (config_v)
  478. config_v |= BIT(1);
  479. SDE_REG_WRITE(c, SCALE_CONFIG + idx, config_h | config_v);
  480. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_X + idx,
  481. pe->init_phase_x[SDE_SSPP_COMP_0]);
  482. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_Y + idx,
  483. pe->init_phase_y[SDE_SSPP_COMP_0]);
  484. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_X + idx,
  485. pe->phase_step_x[SDE_SSPP_COMP_0]);
  486. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_Y + idx,
  487. pe->phase_step_y[SDE_SSPP_COMP_0]);
  488. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_X + idx,
  489. pe->init_phase_x[SDE_SSPP_COMP_1_2]);
  490. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_Y + idx,
  491. pe->init_phase_y[SDE_SSPP_COMP_1_2]);
  492. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_X + idx,
  493. pe->phase_step_x[SDE_SSPP_COMP_1_2]);
  494. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_Y + idx,
  495. pe->phase_step_y[SDE_SSPP_COMP_1_2]);
  496. }
  497. static void _sde_hw_sspp_setup_scaler3(struct sde_hw_pipe *ctx,
  498. struct sde_hw_pipe_cfg *sspp,
  499. struct sde_hw_pixel_ext *pe,
  500. void *scaler_cfg)
  501. {
  502. u32 idx;
  503. struct sde_hw_scaler3_cfg *scaler3_cfg = scaler_cfg;
  504. (void)pe;
  505. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED3, &idx) || !sspp
  506. || !scaler3_cfg || !ctx || !ctx->cap || !ctx->cap->sblk)
  507. return;
  508. sde_hw_setup_scaler3(&ctx->hw, scaler3_cfg,
  509. ctx->cap->sblk->scaler_blk.version, idx, sspp->layout.format);
  510. }
  511. static void sde_hw_sspp_setup_pre_downscale(struct sde_hw_pipe *ctx,
  512. struct sde_hw_inline_pre_downscale_cfg *pre_down)
  513. {
  514. u32 idx, val;
  515. if (!ctx || !pre_down || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  516. return;
  517. val = pre_down->pre_downscale_x_0 |
  518. (pre_down->pre_downscale_x_1 << 4) |
  519. (pre_down->pre_downscale_y_0 << 8) |
  520. (pre_down->pre_downscale_y_1 << 12);
  521. SDE_REG_WRITE(&ctx->hw, SSPP_PRE_DOWN_SCALE + idx, val);
  522. }
  523. /**
  524. * sde_hw_sspp_setup_rects()
  525. */
  526. static void sde_hw_sspp_setup_rects(struct sde_hw_pipe *ctx,
  527. struct sde_hw_pipe_cfg *cfg,
  528. enum sde_sspp_multirect_index rect_index)
  529. {
  530. struct sde_hw_blk_reg_map *c;
  531. u32 src_size, src_xy, dst_size, dst_xy, ystride0, ystride1;
  532. u32 src_size_off, src_xy_off, out_size_off, out_xy_off;
  533. u32 decimation = 0;
  534. u32 idx;
  535. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !cfg)
  536. return;
  537. c = &ctx->hw;
  538. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0) {
  539. src_size_off = SSPP_SRC_SIZE;
  540. src_xy_off = SSPP_SRC_XY;
  541. out_size_off = SSPP_OUT_SIZE;
  542. out_xy_off = SSPP_OUT_XY;
  543. } else {
  544. src_size_off = SSPP_SRC_SIZE_REC1;
  545. src_xy_off = SSPP_SRC_XY_REC1;
  546. out_size_off = SSPP_OUT_SIZE_REC1;
  547. out_xy_off = SSPP_OUT_XY_REC1;
  548. }
  549. /* src and dest rect programming */
  550. src_xy = (cfg->src_rect.y << 16) | (cfg->src_rect.x);
  551. src_size = (cfg->src_rect.h << 16) | (cfg->src_rect.w);
  552. dst_xy = (cfg->dst_rect.y << 16) | (cfg->dst_rect.x);
  553. dst_size = (cfg->dst_rect.h << 16) | (cfg->dst_rect.w);
  554. if (rect_index == SDE_SSPP_RECT_SOLO) {
  555. ystride0 = (cfg->layout.plane_pitch[0]) |
  556. (cfg->layout.plane_pitch[1] << 16);
  557. ystride1 = (cfg->layout.plane_pitch[2]) |
  558. (cfg->layout.plane_pitch[3] << 16);
  559. } else {
  560. ystride0 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE0 + idx);
  561. ystride1 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE1 + idx);
  562. if (rect_index == SDE_SSPP_RECT_0) {
  563. ystride0 = (ystride0 & 0xFFFF0000) |
  564. (cfg->layout.plane_pitch[0] & 0x0000FFFF);
  565. ystride1 = (ystride1 & 0xFFFF0000)|
  566. (cfg->layout.plane_pitch[2] & 0x0000FFFF);
  567. } else {
  568. ystride0 = (ystride0 & 0x0000FFFF) |
  569. ((cfg->layout.plane_pitch[0] << 16) &
  570. 0xFFFF0000);
  571. ystride1 = (ystride1 & 0x0000FFFF) |
  572. ((cfg->layout.plane_pitch[2] << 16) &
  573. 0xFFFF0000);
  574. }
  575. }
  576. /* program scaler, phase registers, if pipes supporting scaling */
  577. if (ctx->cap->features & SDE_SSPP_SCALER) {
  578. /* program decimation */
  579. decimation = ((1 << cfg->horz_decimation) - 1) << 8;
  580. decimation |= ((1 << cfg->vert_decimation) - 1);
  581. }
  582. /* rectangle register programming */
  583. SDE_REG_WRITE(c, src_size_off + idx, src_size);
  584. SDE_REG_WRITE(c, src_xy_off + idx, src_xy);
  585. SDE_REG_WRITE(c, out_size_off + idx, dst_size);
  586. SDE_REG_WRITE(c, out_xy_off + idx, dst_xy);
  587. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE0 + idx, ystride0);
  588. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE1 + idx, ystride1);
  589. SDE_REG_WRITE(c, SSPP_DECIMATION_CONFIG + idx, decimation);
  590. }
  591. /**
  592. * _sde_hw_sspp_setup_excl_rect() - set exclusion rect configs
  593. * @ctx: Pointer to pipe context
  594. * @excl_rect: Exclusion rect configs
  595. */
  596. static void _sde_hw_sspp_setup_excl_rect(struct sde_hw_pipe *ctx,
  597. struct sde_rect *excl_rect,
  598. enum sde_sspp_multirect_index rect_index)
  599. {
  600. struct sde_hw_blk_reg_map *c;
  601. u32 size, xy;
  602. u32 idx;
  603. u32 reg_xy, reg_size;
  604. u32 excl_ctrl = BIT(0);
  605. u32 enable_bit;
  606. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !excl_rect)
  607. return;
  608. if (rect_index == SDE_SSPP_RECT_0 || rect_index == SDE_SSPP_RECT_SOLO) {
  609. reg_xy = SSPP_EXCL_REC_XY;
  610. reg_size = SSPP_EXCL_REC_SIZE;
  611. enable_bit = BIT(0);
  612. } else {
  613. reg_xy = SSPP_EXCL_REC_XY_REC1;
  614. reg_size = SSPP_EXCL_REC_SIZE_REC1;
  615. enable_bit = BIT(1);
  616. }
  617. c = &ctx->hw;
  618. xy = (excl_rect->y << 16) | (excl_rect->x);
  619. size = (excl_rect->h << 16) | (excl_rect->w);
  620. /* Set if multi-rect disabled, read+modify only if multi-rect enabled */
  621. if (rect_index != SDE_SSPP_RECT_SOLO)
  622. excl_ctrl = SDE_REG_READ(c, SSPP_EXCL_REC_CTL + idx);
  623. if (!size) {
  624. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  625. excl_ctrl & ~enable_bit);
  626. } else {
  627. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  628. excl_ctrl | enable_bit);
  629. SDE_REG_WRITE(c, reg_size + idx, size);
  630. SDE_REG_WRITE(c, reg_xy + idx, xy);
  631. }
  632. }
  633. static void sde_hw_sspp_setup_sourceaddress(struct sde_hw_pipe *ctx,
  634. struct sde_hw_pipe_cfg *cfg,
  635. enum sde_sspp_multirect_index rect_mode)
  636. {
  637. int i;
  638. u32 idx;
  639. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  640. return;
  641. if (rect_mode == SDE_SSPP_RECT_SOLO) {
  642. for (i = 0; i < ARRAY_SIZE(cfg->layout.plane_addr); i++)
  643. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx + i * 0x4,
  644. cfg->layout.plane_addr[i]);
  645. } else if (rect_mode == SDE_SSPP_RECT_0) {
  646. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx,
  647. cfg->layout.plane_addr[0]);
  648. SDE_REG_WRITE(&ctx->hw, SSPP_SRC2_ADDR + idx,
  649. cfg->layout.plane_addr[2]);
  650. } else {
  651. SDE_REG_WRITE(&ctx->hw, SSPP_SRC1_ADDR + idx,
  652. cfg->layout.plane_addr[0]);
  653. SDE_REG_WRITE(&ctx->hw, SSPP_SRC3_ADDR + idx,
  654. cfg->layout.plane_addr[2]);
  655. }
  656. }
  657. u32 sde_hw_sspp_get_source_addr(struct sde_hw_pipe *ctx, bool is_virtual)
  658. {
  659. u32 idx;
  660. u32 offset = 0;
  661. if (!ctx || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  662. return 0;
  663. offset = is_virtual ? (SSPP_SRC1_ADDR + idx) : (SSPP_SRC0_ADDR + idx);
  664. return SDE_REG_READ(&ctx->hw, offset);
  665. }
  666. static void sde_hw_sspp_setup_csc(struct sde_hw_pipe *ctx,
  667. struct sde_csc_cfg *data)
  668. {
  669. u32 idx;
  670. bool csc10 = false;
  671. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC, &idx) || !data)
  672. return;
  673. if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features)) {
  674. idx += CSC_10BIT_OFFSET;
  675. csc10 = true;
  676. }
  677. sde_hw_csc_setup(&ctx->hw, idx, data, csc10);
  678. }
  679. static void sde_hw_sspp_setup_sharpening(struct sde_hw_pipe *ctx,
  680. struct sde_hw_sharp_cfg *cfg)
  681. {
  682. struct sde_hw_blk_reg_map *c;
  683. u32 idx;
  684. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !cfg ||
  685. !test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features))
  686. return;
  687. c = &ctx->hw;
  688. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx, cfg->strength);
  689. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x4, cfg->edge_thr);
  690. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x8, cfg->smooth_thr);
  691. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0xC, cfg->noise_thr);
  692. }
  693. static void sde_hw_sspp_setup_solidfill(struct sde_hw_pipe *ctx, u32 color, enum
  694. sde_sspp_multirect_index rect_index)
  695. {
  696. u32 idx;
  697. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  698. return;
  699. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0)
  700. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR + idx, color);
  701. else
  702. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR_REC1 + idx,
  703. color);
  704. }
  705. static void sde_hw_sspp_setup_qos_lut(struct sde_hw_pipe *ctx,
  706. struct sde_hw_pipe_qos_cfg *cfg)
  707. {
  708. u32 idx;
  709. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  710. return;
  711. SDE_REG_WRITE(&ctx->hw, SSPP_DANGER_LUT + idx, cfg->danger_lut);
  712. SDE_REG_WRITE(&ctx->hw, SSPP_SAFE_LUT + idx, cfg->safe_lut);
  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. } else if (c->cap->sblk->gamut_blk.version ==
  897. (SDE_COLOR_PROCESS_VER(0x6, 0x1))) {
  898. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  899. c->idx);
  900. if (!ret)
  901. c->ops.setup_vig_gamut =
  902. reg_dmav2_setup_vig_gamutv61;
  903. else
  904. c->ops.setup_vig_gamut = NULL;
  905. }
  906. }
  907. if (test_bit(SDE_SSPP_VIG_IGC, &features)) {
  908. if (c->cap->sblk->igc_blk[0].version ==
  909. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  910. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  911. c->idx);
  912. if (!ret)
  913. c->ops.setup_vig_igc =
  914. reg_dmav1_setup_vig_igcv5;
  915. else
  916. c->ops.setup_vig_igc = NULL;
  917. }
  918. if (c->cap->sblk->igc_blk[0].version ==
  919. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  920. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  921. c->idx);
  922. if (!ret)
  923. c->ops.setup_vig_igc =
  924. reg_dmav1_setup_vig_igcv6;
  925. else
  926. c->ops.setup_vig_igc = NULL;
  927. }
  928. }
  929. if (test_bit(SDE_SSPP_DMA_IGC, &features)) {
  930. if (c->cap->sblk->igc_blk[0].version ==
  931. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  932. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_IGC,
  933. c->idx);
  934. if (!ret)
  935. c->ops.setup_dma_igc =
  936. reg_dmav1_setup_dma_igcv5;
  937. else
  938. c->ops.setup_dma_igc = NULL;
  939. }
  940. }
  941. if (test_bit(SDE_SSPP_DMA_GC, &features)) {
  942. if (c->cap->sblk->gc_blk[0].version ==
  943. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  944. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_GC,
  945. c->idx);
  946. if (!ret)
  947. c->ops.setup_dma_gc =
  948. reg_dmav1_setup_dma_gcv5;
  949. else
  950. c->ops.setup_dma_gc = NULL;
  951. }
  952. }
  953. }
  954. static void sde_hw_sspp_setup_inverse_pma(struct sde_hw_pipe *ctx,
  955. enum sde_sspp_multirect_index index, u32 enable)
  956. {
  957. u32 op_mode = 0;
  958. if (!ctx || (index == SDE_SSPP_RECT_1))
  959. return;
  960. if (enable)
  961. op_mode |= BIT(0);
  962. SDE_REG_WRITE(&ctx->hw, SSPP_GAMUT_UNMULT_MODE, op_mode);
  963. }
  964. static void sde_hw_sspp_setup_dgm_inverse_pma(struct sde_hw_pipe *ctx,
  965. enum sde_sspp_multirect_index index, u32 enable)
  966. {
  967. u32 offset = SSPP_DGM_OP_MODE;
  968. u32 op_mode = 0;
  969. if (!ctx)
  970. return;
  971. if (index == SDE_SSPP_RECT_1)
  972. offset = SSPP_DGM_OP_MODE_REC1;
  973. op_mode = SDE_REG_READ(&ctx->hw, offset);
  974. if (enable)
  975. op_mode |= BIT(0);
  976. else
  977. op_mode &= ~BIT(0);
  978. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  979. }
  980. static void sde_hw_sspp_setup_dgm_csc(struct sde_hw_pipe *ctx,
  981. enum sde_sspp_multirect_index index, struct sde_csc_cfg *data)
  982. {
  983. u32 idx = 0;
  984. u32 offset;
  985. u32 op_mode = 0;
  986. const struct sde_sspp_sub_blks *sblk;
  987. if (!ctx || !ctx->cap || !ctx->cap->sblk)
  988. return;
  989. sblk = ctx->cap->sblk;
  990. if (index == SDE_SSPP_RECT_1)
  991. idx = 1;
  992. offset = sblk->dgm_csc_blk[idx].base;
  993. if (data) {
  994. op_mode |= BIT(0);
  995. sde_hw_csc_matrix_coeff_setup(&ctx->hw,
  996. offset + CSC_10BIT_OFFSET, data, DGM_CSC_MATRIX_SHIFT);
  997. }
  998. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  999. }
  1000. static void _setup_layer_ops(struct sde_hw_pipe *c,
  1001. unsigned long features, unsigned long perf_features,
  1002. bool is_virtual_pipe)
  1003. {
  1004. int ret;
  1005. if (test_bit(SDE_SSPP_SRC, &features)) {
  1006. c->ops.setup_format = sde_hw_sspp_setup_format;
  1007. c->ops.setup_rects = sde_hw_sspp_setup_rects;
  1008. c->ops.setup_sourceaddress = sde_hw_sspp_setup_sourceaddress;
  1009. c->ops.get_sourceaddress = sde_hw_sspp_get_source_addr;
  1010. c->ops.setup_solidfill = sde_hw_sspp_setup_solidfill;
  1011. c->ops.setup_pe = sde_hw_sspp_setup_pe_config;
  1012. c->ops.setup_secure_address = sde_hw_sspp_setup_secure;
  1013. c->ops.set_src_split_order = sde_hw_sspp_set_src_split_order;
  1014. }
  1015. if (test_bit(SDE_SSPP_EXCL_RECT, &features))
  1016. c->ops.setup_excl_rect = _sde_hw_sspp_setup_excl_rect;
  1017. if (test_bit(SDE_PERF_SSPP_QOS, &features)) {
  1018. c->ops.setup_qos_lut =
  1019. sde_hw_sspp_setup_qos_lut;
  1020. c->ops.setup_qos_ctrl = sde_hw_sspp_setup_qos_ctrl;
  1021. }
  1022. if (test_bit(SDE_PERF_SSPP_TS_PREFILL, &perf_features))
  1023. c->ops.setup_ts_prefill = sde_hw_sspp_setup_ts_prefill;
  1024. if (test_bit(SDE_SSPP_CSC, &features) ||
  1025. test_bit(SDE_SSPP_CSC_10BIT, &features))
  1026. c->ops.setup_csc = sde_hw_sspp_setup_csc;
  1027. if (test_bit(SDE_SSPP_DGM_CSC, &features))
  1028. c->ops.setup_dgm_csc = sde_hw_sspp_setup_dgm_csc;
  1029. if (test_bit(SDE_SSPP_SCALER_QSEED2, &features)) {
  1030. c->ops.setup_sharpening = sde_hw_sspp_setup_sharpening;
  1031. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler;
  1032. }
  1033. if (sde_hw_sspp_multirect_enabled(c->cap))
  1034. c->ops.update_multirect = sde_hw_sspp_update_multirect;
  1035. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  1036. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features)) {
  1037. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler3;
  1038. c->ops.setup_scaler_lut = is_qseed3_rev_qseed3lite(
  1039. c->catalog) ? reg_dmav1_setup_scaler3lite_lut
  1040. : reg_dmav1_setup_scaler3_lut;
  1041. ret = reg_dmav1_init_sspp_op_v4(is_qseed3_rev_qseed3lite(
  1042. c->catalog) ? SDE_SSPP_SCALER_QSEED3LITE
  1043. : SDE_SSPP_SCALER_QSEED3, c->idx);
  1044. if (!ret)
  1045. c->ops.setup_scaler = reg_dmav1_setup_vig_qseed3;
  1046. }
  1047. if (test_bit(SDE_SSPP_PREDOWNSCALE, &features))
  1048. c->ops.setup_pre_downscale = sde_hw_sspp_setup_pre_downscale;
  1049. if (test_bit(SDE_PERF_SSPP_SYS_CACHE, &perf_features))
  1050. c->ops.setup_sys_cache = sde_hw_sspp_setup_sys_cache;
  1051. if (test_bit(SDE_PERF_SSPP_CDP, &perf_features))
  1052. c->ops.setup_cdp = sde_hw_sspp_setup_cdp;
  1053. if (test_bit(SDE_PERF_SSPP_UIDLE, &perf_features))
  1054. c->ops.setup_uidle = sde_hw_sspp_setup_uidle;
  1055. _setup_layer_ops_colorproc(c, features, is_virtual_pipe);
  1056. if (test_bit(SDE_SSPP_DGM_INVERSE_PMA, &features))
  1057. c->ops.setup_inverse_pma = sde_hw_sspp_setup_dgm_inverse_pma;
  1058. else if (test_bit(SDE_SSPP_INVERSE_PMA, &features))
  1059. c->ops.setup_inverse_pma = sde_hw_sspp_setup_inverse_pma;
  1060. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error;
  1061. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error;
  1062. }
  1063. static struct sde_sspp_cfg *_sspp_offset(enum sde_sspp sspp,
  1064. void __iomem *addr,
  1065. struct sde_mdss_cfg *catalog,
  1066. struct sde_hw_blk_reg_map *b)
  1067. {
  1068. int i;
  1069. struct sde_sspp_cfg *cfg;
  1070. if ((sspp < SSPP_MAX) && catalog && addr && b) {
  1071. for (i = 0; i < catalog->sspp_count; i++) {
  1072. if (sspp == catalog->sspp[i].id) {
  1073. b->base_off = addr;
  1074. b->blk_off = catalog->sspp[i].base;
  1075. b->length = catalog->sspp[i].len;
  1076. b->hwversion = catalog->hwversion;
  1077. b->log_mask = SDE_DBG_MASK_SSPP;
  1078. /* Only shallow copy is needed */
  1079. cfg = kmemdup(&catalog->sspp[i], sizeof(*cfg),
  1080. GFP_KERNEL);
  1081. if (!cfg)
  1082. return ERR_PTR(-ENOMEM);
  1083. return cfg;
  1084. }
  1085. }
  1086. }
  1087. return ERR_PTR(-ENOMEM);
  1088. }
  1089. static struct sde_hw_blk_ops sde_hw_ops = {
  1090. .start = NULL,
  1091. .stop = NULL,
  1092. };
  1093. struct sde_hw_pipe *sde_hw_sspp_init(enum sde_sspp idx,
  1094. void __iomem *addr, struct sde_mdss_cfg *catalog,
  1095. bool is_virtual_pipe)
  1096. {
  1097. struct sde_hw_pipe *hw_pipe;
  1098. struct sde_sspp_cfg *cfg;
  1099. int rc;
  1100. if (!addr || !catalog)
  1101. return ERR_PTR(-EINVAL);
  1102. hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
  1103. if (!hw_pipe)
  1104. return ERR_PTR(-ENOMEM);
  1105. cfg = _sspp_offset(idx, addr, catalog, &hw_pipe->hw);
  1106. if (IS_ERR_OR_NULL(cfg)) {
  1107. kfree(hw_pipe);
  1108. return ERR_PTR(-EINVAL);
  1109. }
  1110. /* Assign ops */
  1111. hw_pipe->catalog = catalog;
  1112. hw_pipe->mdp = &catalog->mdp[0];
  1113. hw_pipe->idx = idx;
  1114. hw_pipe->cap = cfg;
  1115. _setup_layer_ops(hw_pipe, hw_pipe->cap->features,
  1116. hw_pipe->cap->perf_features, is_virtual_pipe);
  1117. if (catalog->qseed_hw_version)
  1118. sde_init_scaler_blk(&hw_pipe->cap->sblk->scaler_blk,
  1119. catalog->qseed_hw_version);
  1120. rc = sde_hw_blk_init(&hw_pipe->base, SDE_HW_BLK_SSPP, idx, &sde_hw_ops);
  1121. if (rc) {
  1122. SDE_ERROR("failed to init hw blk %d\n", rc);
  1123. goto blk_init_error;
  1124. }
  1125. if (!is_virtual_pipe)
  1126. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  1127. hw_pipe->hw.blk_off,
  1128. hw_pipe->hw.blk_off + hw_pipe->hw.length,
  1129. hw_pipe->hw.xin_id);
  1130. if (cfg->sblk->scaler_blk.len && !is_virtual_pipe)
  1131. sde_dbg_reg_register_dump_range(SDE_DBG_NAME,
  1132. cfg->sblk->scaler_blk.name,
  1133. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base,
  1134. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base +
  1135. cfg->sblk->scaler_blk.len,
  1136. hw_pipe->hw.xin_id);
  1137. return hw_pipe;
  1138. blk_init_error:
  1139. kzfree(hw_pipe);
  1140. return ERR_PTR(rc);
  1141. }
  1142. void sde_hw_sspp_destroy(struct sde_hw_pipe *ctx)
  1143. {
  1144. if (ctx) {
  1145. sde_hw_blk_destroy(&ctx->base);
  1146. reg_dmav1_deinit_sspp_ops(ctx->idx);
  1147. kfree(ctx->cap);
  1148. }
  1149. kfree(ctx);
  1150. }