sde_hw_sspp.c 37 KB

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