sde_hw_sspp.c 39 KB

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