sde_hw_sspp.c 38 KB

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