sde_hw_sspp.c 40 KB

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