sde_hw_sspp.c 49 KB

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