sde_hw_sspp.c 37 KB

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