sde_hw_sspp.c 37 KB

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