sde_hw_sspp.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include "sde_hwio.h"
  8. #include "sde_hw_catalog.h"
  9. #include "sde_hw_lm.h"
  10. #include "sde_hw_sspp.h"
  11. #include "sde_hw_color_processing.h"
  12. #include "sde_dbg.h"
  13. #include "sde_kms.h"
  14. #include "sde_hw_reg_dma_v1_color_proc.h"
  15. #include "sde_hw_vbif.h"
  16. #define SDE_FETCH_CONFIG_RESET_VALUE 0x00000087
  17. /* SDE_SSPP_SRC */
  18. #define SSPP_SRC_SIZE 0x00
  19. #define SSPP_SRC_XY 0x08
  20. #define SSPP_OUT_SIZE 0x0c
  21. #define SSPP_OUT_XY 0x10
  22. #define SSPP_SRC0_ADDR 0x14
  23. #define SSPP_SRC1_ADDR 0x18
  24. #define SSPP_SRC2_ADDR 0x1C
  25. #define SSPP_SRC3_ADDR 0x20
  26. #define SSPP_SRC_YSTRIDE0 0x24
  27. #define SSPP_SRC_YSTRIDE1 0x28
  28. #define SSPP_SRC_FORMAT 0x30
  29. #define SSPP_SRC_UNPACK_PATTERN 0x34
  30. #define SSPP_SRC_OP_MODE 0x38
  31. /* SSPP_MULTIRECT*/
  32. #define SSPP_SRC_SIZE_REC1 0x16C
  33. #define SSPP_SRC_XY_REC1 0x168
  34. #define SSPP_OUT_SIZE_REC1 0x160
  35. #define SSPP_OUT_XY_REC1 0x164
  36. #define SSPP_SRC_FORMAT_REC1 0x174
  37. #define SSPP_SRC_UNPACK_PATTERN_REC1 0x178
  38. #define SSPP_SRC_OP_MODE_REC1 0x17C
  39. #define SSPP_MULTIRECT_OPMODE 0x170
  40. #define SSPP_SRC_CONSTANT_COLOR_REC1 0x180
  41. #define SSPP_EXCL_REC_SIZE_REC1 0x184
  42. #define SSPP_EXCL_REC_XY_REC1 0x188
  43. #define SSPP_LINE_INSERTION_CTRL_REC1 0x1E4
  44. #define SSPP_LINE_INSERTION_OUT_SIZE_REC1 0x1EC
  45. #define SSPP_UIDLE_CTRL_VALUE 0x1f0
  46. #define SSPP_UIDLE_CTRL_VALUE_REC1 0x1f4
  47. #define SSPP_FILL_LEVEL_SCALE 0x1f8
  48. /* SSPP_DGM */
  49. #define SSPP_DGM_0 0x9F0
  50. #define SSPP_DGM_1 0x19F0
  51. #define SSPP_DGM_SIZE 0x420
  52. #define SSPP_DGM_CSC_0 0x800
  53. #define SSPP_DGM_CSC_1 0x1800
  54. #define SSPP_DGM_CSC_SIZE 0xFC
  55. #define VIG_GAMUT_SIZE 0x1CC
  56. #define MDSS_MDP_OP_DEINTERLACE BIT(22)
  57. #define MDSS_MDP_OP_DEINTERLACE_ODD BIT(23)
  58. #define MDSS_MDP_OP_IGC_ROM_1 BIT(18)
  59. #define MDSS_MDP_OP_IGC_ROM_0 BIT(17)
  60. #define MDSS_MDP_OP_IGC_EN BIT(16)
  61. #define MDSS_MDP_OP_FLIP_UD BIT(14)
  62. #define MDSS_MDP_OP_FLIP_LR BIT(13)
  63. #define MDSS_MDP_OP_SPLIT_ORDER BIT(4)
  64. #define MDSS_MDP_OP_BWC_EN BIT(0)
  65. #define MDSS_MDP_OP_PE_OVERRIDE BIT(31)
  66. #define MDSS_MDP_OP_BWC_LOSSLESS (0 << 1)
  67. #define MDSS_MDP_OP_BWC_Q_HIGH (1 << 1)
  68. #define MDSS_MDP_OP_BWC_Q_MED (2 << 1)
  69. #define SSPP_SRC_CONSTANT_COLOR 0x3c
  70. #define SSPP_EXCL_REC_CTL 0x40
  71. #define SSPP_UBWC_STATIC_CTRL 0x44
  72. #define SSPP_FETCH_CONFIG 0x48
  73. #define SSPP_PRE_DOWN_SCALE 0x50
  74. #define SSPP_DANGER_LUT 0x60
  75. #define SSPP_SAFE_LUT 0x64
  76. #define SSPP_CREQ_LUT 0x68
  77. #define SSPP_QOS_CTRL 0x6C
  78. #define SSPP_DECIMATION_CONFIG 0xB4
  79. #define SSPP_SRC_ADDR_SW_STATUS 0x70
  80. #define SSPP_CREQ_LUT_0 0x74
  81. #define SSPP_CREQ_LUT_1 0x78
  82. #define SSPP_UBWC_STATS_ROI 0x7C
  83. #define SSPP_UBWC_STATS_DATA 0x80
  84. #define SSPP_UBWC_STATS_ROI_REC1 0xB4
  85. #define SSPP_UBWC_STATS_DATA_REC1 0xB8
  86. #define SSPP_SW_PIX_EXT_C0_LR 0x100
  87. #define SSPP_SW_PIX_EXT_C0_TB 0x104
  88. #define SSPP_SW_PIX_EXT_C0_REQ_PIXELS 0x108
  89. #define SSPP_SW_PIX_EXT_C1C2_LR 0x110
  90. #define SSPP_SW_PIX_EXT_C1C2_TB 0x114
  91. #define SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS 0x118
  92. #define SSPP_SW_PIX_EXT_C3_LR 0x120
  93. #define SSPP_SW_PIX_EXT_C3_TB 0x124
  94. #define SSPP_SW_PIX_EXT_C3_REQ_PIXELS 0x128
  95. #define SSPP_META_ERROR_STATUS 0X12C
  96. #define SSPP_TRAFFIC_SHAPER 0x130
  97. #define SSPP_CDP_CNTL 0x134
  98. #define SSPP_UBWC_ERROR_STATUS 0x138
  99. #define SSPP_CDP_CNTL_REC1 0x13c
  100. #define SSPP_TRAFFIC_SHAPER_PREFILL 0x150
  101. #define SSPP_TRAFFIC_SHAPER_REC1_PREFILL 0x154
  102. #define SSPP_TRAFFIC_SHAPER_REC1 0x158
  103. #define SSPP_EXCL_REC_SIZE 0x1B4
  104. #define SSPP_EXCL_REC_XY 0x1B8
  105. #define SSPP_UBWC_STATIC_CTRL_REC1 0x1C0
  106. #define SSPP_UBWC_ERROR_STATUS_REC1 0x1C8
  107. #define SSPP_META_ERROR_STATUS_REC1 0x1C4
  108. #define SSPP_VIG_OP_MODE 0x0
  109. #define SSPP_VIG_CSC_10_OP_MODE 0x0
  110. #define SSPP_TRAFFIC_SHAPER_BPC_MAX 0xFF
  111. #define SSPP_CLK_CTRL 0x330
  112. #define SSPP_CLK_STATUS 0x334
  113. #define SSPP_LINE_INSERTION_CTRL 0x1E0
  114. #define SSPP_LINE_INSERTION_OUT_SIZE 0x1E8
  115. /* SSPP_QOS_CTRL */
  116. #define SSPP_QOS_CTRL_VBLANK_EN BIT(16)
  117. #define SSPP_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  118. #define SSPP_QOS_CTRL_DANGER_VBLANK_MASK 0x3
  119. #define SSPP_QOS_CTRL_DANGER_VBLANK_OFF 4
  120. #define SSPP_QOS_CTRL_CREQ_VBLANK_MASK 0x3
  121. #define SSPP_QOS_CTRL_CREQ_VBLANK_OFF 20
  122. #define SSPP_SYS_CACHE_MODE 0x1BC
  123. #define SSPP_SBUF_STATUS_PLANE0 0x1C0
  124. #define SSPP_SBUF_STATUS_PLANE1 0x1C4
  125. #define SSPP_SBUF_STATUS_PLANE_EMPTY BIT(16)
  126. /* SDE_SSPP_SCALER_QSEED2 */
  127. #define SCALE_CONFIG 0x04
  128. #define COMP0_3_PHASE_STEP_X 0x10
  129. #define COMP0_3_PHASE_STEP_Y 0x14
  130. #define COMP1_2_PHASE_STEP_X 0x18
  131. #define COMP1_2_PHASE_STEP_Y 0x1c
  132. #define COMP0_3_INIT_PHASE_X 0x20
  133. #define COMP0_3_INIT_PHASE_Y 0x24
  134. #define COMP1_2_INIT_PHASE_X 0x28
  135. #define COMP1_2_INIT_PHASE_Y 0x2C
  136. #define VIG_0_QSEED2_SHARP 0x30
  137. /*
  138. * Definitions for ViG op modes
  139. */
  140. #define VIG_OP_CSC_DST_DATAFMT BIT(19)
  141. #define VIG_OP_CSC_SRC_DATAFMT BIT(18)
  142. #define VIG_OP_CSC_EN BIT(17)
  143. #define VIG_OP_MEM_PROT_CONT BIT(15)
  144. #define VIG_OP_MEM_PROT_VAL BIT(14)
  145. #define VIG_OP_MEM_PROT_SAT BIT(13)
  146. #define VIG_OP_MEM_PROT_HUE BIT(12)
  147. #define VIG_OP_HIST BIT(8)
  148. #define VIG_OP_SKY_COL BIT(7)
  149. #define VIG_OP_FOIL BIT(6)
  150. #define VIG_OP_SKIN_COL BIT(5)
  151. #define VIG_OP_PA_EN BIT(4)
  152. #define VIG_OP_PA_SAT_ZERO_EXP BIT(2)
  153. #define VIG_OP_MEM_PROT_BLEND BIT(1)
  154. /*
  155. * Definitions for CSC 10 op modes
  156. */
  157. #define VIG_CSC_10_SRC_DATAFMT BIT(1)
  158. #define VIG_CSC_10_EN BIT(0)
  159. #define CSC_10BIT_OFFSET 4
  160. #define DGM_CSC_MATRIX_SHIFT 0
  161. /* traffic shaper clock in Hz */
  162. #define TS_CLK 19200000
  163. static inline int _sspp_subblk_offset(struct sde_hw_pipe *ctx,
  164. int s_id,
  165. u32 *idx)
  166. {
  167. int rc = 0;
  168. const struct sde_sspp_sub_blks *sblk;
  169. if (!ctx)
  170. return -EINVAL;
  171. sblk = ctx->cap->sblk;
  172. switch (s_id) {
  173. case SDE_SSPP_SRC:
  174. *idx = sblk->src_blk.base;
  175. break;
  176. case SDE_SSPP_SCALER_QSEED2:
  177. case SDE_SSPP_SCALER_QSEED3:
  178. *idx = sblk->scaler_blk.base;
  179. break;
  180. case SDE_SSPP_CSC:
  181. case SDE_SSPP_CSC_10BIT:
  182. *idx = sblk->csc_blk.base;
  183. break;
  184. case SDE_SSPP_HSIC:
  185. *idx = sblk->hsic_blk.base;
  186. break;
  187. case SDE_SSPP_PCC:
  188. *idx = sblk->pcc_blk.base;
  189. break;
  190. case SDE_SSPP_MEMCOLOR:
  191. *idx = sblk->memcolor_blk.base;
  192. break;
  193. default:
  194. rc = -EINVAL;
  195. }
  196. return rc;
  197. }
  198. static void sde_hw_sspp_update_multirect(struct sde_hw_pipe *ctx,
  199. bool enable,
  200. enum sde_sspp_multirect_index index,
  201. enum sde_sspp_multirect_mode mode)
  202. {
  203. u32 mode_mask;
  204. u32 idx;
  205. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  206. return;
  207. if (index == SDE_SSPP_RECT_SOLO) {
  208. /**
  209. * if rect index is RECT_SOLO, we cannot expect a
  210. * virtual plane sharing the same SSPP id. So we go
  211. * and disable multirect
  212. */
  213. mode_mask = 0;
  214. } else {
  215. mode_mask = SDE_REG_READ(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx);
  216. if (enable)
  217. mode_mask |= index;
  218. else
  219. mode_mask &= ~index;
  220. if (enable && (mode == SDE_SSPP_MULTIRECT_TIME_MX))
  221. mode_mask |= BIT(2);
  222. else
  223. mode_mask &= ~BIT(2);
  224. }
  225. SDE_REG_WRITE(&ctx->hw, SSPP_MULTIRECT_OPMODE + idx, mode_mask);
  226. }
  227. static void _sspp_setup_opmode(struct sde_hw_pipe *ctx,
  228. u32 mask, u8 en)
  229. {
  230. u32 idx;
  231. u32 opmode;
  232. if (!test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features) ||
  233. _sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) ||
  234. !test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  235. return;
  236. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_OP_MODE + idx);
  237. if (en)
  238. opmode |= mask;
  239. else
  240. opmode &= ~mask;
  241. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_OP_MODE + idx, opmode);
  242. }
  243. static void _sspp_setup_csc10_opmode(struct sde_hw_pipe *ctx,
  244. u32 mask, u8 en)
  245. {
  246. u32 idx;
  247. u32 opmode;
  248. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC_10BIT, &idx))
  249. return;
  250. opmode = SDE_REG_READ(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx);
  251. if (en)
  252. opmode |= mask;
  253. else
  254. opmode &= ~mask;
  255. SDE_REG_WRITE(&ctx->hw, SSPP_VIG_CSC_10_OP_MODE + idx, opmode);
  256. }
  257. static void sde_hw_sspp_set_src_split_order(struct sde_hw_pipe *ctx,
  258. enum sde_sspp_multirect_index rect_mode, bool enable)
  259. {
  260. struct sde_hw_blk_reg_map *c;
  261. u32 opmode, idx, op_mode_off;
  262. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  263. return;
  264. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0)
  265. op_mode_off = SSPP_SRC_OP_MODE;
  266. else
  267. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  268. c = &ctx->hw;
  269. opmode = SDE_REG_READ(c, op_mode_off + idx);
  270. if (enable)
  271. opmode |= MDSS_MDP_OP_SPLIT_ORDER;
  272. else
  273. opmode &= ~MDSS_MDP_OP_SPLIT_ORDER;
  274. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  275. }
  276. static void sde_hw_sspp_setup_ubwc(struct sde_hw_pipe *ctx, struct sde_hw_blk_reg_map *c,
  277. const struct sde_format *fmt, bool const_alpha_en, bool const_color_en,
  278. enum sde_sspp_multirect_index rect_mode)
  279. {
  280. u32 alpha_en_mask = 0, color_en_mask = 0, ubwc_ctrl_off;
  281. SDE_REG_WRITE(c, SSPP_FETCH_CONFIG,
  282. SDE_FETCH_CONFIG_RESET_VALUE |
  283. ctx->mdp->highest_bank_bit << 18);
  284. if ((rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0) ||
  285. !test_bit(SDE_SSPP_UBWC_STATS, &ctx->cap->features))
  286. ubwc_ctrl_off = SSPP_UBWC_STATIC_CTRL;
  287. else
  288. ubwc_ctrl_off = SSPP_UBWC_STATIC_CTRL_REC1;
  289. if (IS_UBWC_40_SUPPORTED(ctx->catalog->ubwc_rev)) {
  290. SDE_REG_WRITE(c, ubwc_ctrl_off, SDE_FORMAT_IS_YUV(fmt) ? 0 : BIT(30));
  291. } else if (IS_UBWC_30_SUPPORTED(ctx->catalog->ubwc_rev)) {
  292. color_en_mask = const_color_en ? BIT(30) : 0;
  293. SDE_REG_WRITE(c, ubwc_ctrl_off,
  294. color_en_mask | (ctx->mdp->ubwc_swizzle) |
  295. (ctx->mdp->highest_bank_bit << 4));
  296. } else if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_rev)) {
  297. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  298. SDE_REG_WRITE(c, ubwc_ctrl_off,
  299. alpha_en_mask | (ctx->mdp->ubwc_swizzle) |
  300. (ctx->mdp->highest_bank_bit << 4));
  301. } else if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_rev)) {
  302. alpha_en_mask = const_alpha_en ? BIT(31) : 0;
  303. SDE_REG_WRITE(c, ubwc_ctrl_off,
  304. alpha_en_mask | (ctx->mdp->ubwc_swizzle & 0x1) |
  305. BIT(8) | (ctx->mdp->highest_bank_bit << 4));
  306. }
  307. }
  308. /**
  309. * Setup source pixel format, flip,
  310. */
  311. static void sde_hw_sspp_setup_format(struct sde_hw_pipe *ctx,
  312. const struct sde_format *fmt,
  313. bool const_alpha_en, u32 flags,
  314. enum sde_sspp_multirect_index rect_mode)
  315. {
  316. struct sde_hw_blk_reg_map *c;
  317. u32 chroma_samp, unpack, src_format;
  318. u32 opmode = 0;
  319. u32 op_mode_off, unpack_pat_off, format_off;
  320. u32 idx;
  321. bool const_color_en = true;
  322. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !fmt)
  323. return;
  324. if (rect_mode == SDE_SSPP_RECT_SOLO || rect_mode == SDE_SSPP_RECT_0) {
  325. op_mode_off = SSPP_SRC_OP_MODE;
  326. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN;
  327. format_off = SSPP_SRC_FORMAT;
  328. } else {
  329. op_mode_off = SSPP_SRC_OP_MODE_REC1;
  330. unpack_pat_off = SSPP_SRC_UNPACK_PATTERN_REC1;
  331. format_off = SSPP_SRC_FORMAT_REC1;
  332. }
  333. c = &ctx->hw;
  334. opmode = SDE_REG_READ(c, op_mode_off + idx);
  335. opmode &= ~(MDSS_MDP_OP_FLIP_LR | MDSS_MDP_OP_FLIP_UD |
  336. MDSS_MDP_OP_BWC_EN | MDSS_MDP_OP_PE_OVERRIDE);
  337. if (flags & SDE_SSPP_FLIP_LR)
  338. opmode |= MDSS_MDP_OP_FLIP_LR;
  339. if (flags & SDE_SSPP_FLIP_UD)
  340. opmode |= MDSS_MDP_OP_FLIP_UD;
  341. chroma_samp = fmt->chroma_sample;
  342. if (flags & SDE_SSPP_SOURCE_ROTATED_90) {
  343. if (chroma_samp == SDE_CHROMA_H2V1)
  344. chroma_samp = SDE_CHROMA_H1V2;
  345. else if (chroma_samp == SDE_CHROMA_H1V2)
  346. chroma_samp = SDE_CHROMA_H2V1;
  347. }
  348. src_format = (chroma_samp << 23) | (fmt->fetch_planes << 19) |
  349. (fmt->bits[C3_ALPHA] << 6) | (fmt->bits[C2_R_Cr] << 4) |
  350. (fmt->bits[C1_B_Cb] << 2) | (fmt->bits[C0_G_Y] << 0);
  351. if (flags & SDE_SSPP_ROT_90)
  352. src_format |= BIT(11); /* ROT90 */
  353. if (fmt->alpha_enable && fmt->fetch_planes == SDE_PLANE_INTERLEAVED)
  354. src_format |= BIT(8); /* SRCC3_EN */
  355. if (flags & SDE_SSPP_SOLID_FILL)
  356. src_format |= BIT(22);
  357. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  358. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  359. src_format |= ((fmt->unpack_count - 1) << 12) |
  360. (fmt->unpack_tight << 17) |
  361. (fmt->unpack_align_msb << 18);
  362. if (SDE_FORMAT_IS_FP16(fmt)) {
  363. src_format |= BIT(16) | BIT(10) | BIT(9);
  364. } else if (fmt->bpp <= 4) {
  365. src_format |= ((fmt->bpp - 1) << 9);
  366. } else if (fmt->bpp <= 8) {
  367. src_format |= BIT(16) | ((fmt->bpp - 5) << 9);
  368. }
  369. if ((flags & SDE_SSPP_ROT_90) && test_bit(SDE_SSPP_INLINE_CONST_CLR,
  370. &ctx->cap->features))
  371. const_color_en = false;
  372. if (fmt->fetch_mode != SDE_FETCH_LINEAR) {
  373. if (SDE_FORMAT_IS_UBWC(fmt))
  374. opmode |= MDSS_MDP_OP_BWC_EN;
  375. src_format |= (fmt->fetch_mode & 3) << 30; /*FRAME_FORMAT */
  376. sde_hw_sspp_setup_ubwc(ctx, c, fmt, const_alpha_en, const_color_en, rect_mode);
  377. }
  378. opmode |= MDSS_MDP_OP_PE_OVERRIDE;
  379. /* if this is YUV pixel format, enable CSC */
  380. if (SDE_FORMAT_IS_YUV(fmt))
  381. src_format |= BIT(15);
  382. if (SDE_FORMAT_IS_DX(fmt))
  383. src_format |= BIT(14);
  384. /* update scaler opmode, if appropriate */
  385. if (test_bit(SDE_SSPP_CSC, &ctx->cap->features))
  386. _sspp_setup_opmode(ctx, VIG_OP_CSC_EN | VIG_OP_CSC_SRC_DATAFMT,
  387. SDE_FORMAT_IS_YUV(fmt));
  388. else if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features))
  389. _sspp_setup_csc10_opmode(ctx,
  390. VIG_CSC_10_EN | VIG_CSC_10_SRC_DATAFMT,
  391. SDE_FORMAT_IS_YUV(fmt));
  392. SDE_REG_WRITE(c, format_off + idx, src_format);
  393. SDE_REG_WRITE(c, unpack_pat_off + idx, unpack);
  394. SDE_REG_WRITE(c, op_mode_off + idx, opmode);
  395. /* clear previous UBWC error */
  396. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS + idx, BIT(31));
  397. }
  398. static void sde_hw_sspp_clear_ubwc_error(struct sde_hw_pipe *ctx,
  399. enum sde_sspp_multirect_index multirect_index)
  400. {
  401. struct sde_hw_blk_reg_map *c;
  402. c = &ctx->hw;
  403. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  404. }
  405. static u32 sde_hw_sspp_get_ubwc_error(struct sde_hw_pipe *ctx,
  406. enum sde_sspp_multirect_index multirect_index)
  407. {
  408. struct sde_hw_blk_reg_map *c;
  409. u32 reg_code;
  410. c = &ctx->hw;
  411. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  412. return reg_code;
  413. }
  414. static void sde_hw_sspp_clear_ubwc_error_v1(struct sde_hw_pipe *ctx,
  415. enum sde_sspp_multirect_index multirect_index)
  416. {
  417. struct sde_hw_blk_reg_map *c;
  418. c = &ctx->hw;
  419. if (multirect_index == SDE_SSPP_RECT_1)
  420. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS_REC1, BIT(31));
  421. else
  422. SDE_REG_WRITE(c, SSPP_UBWC_ERROR_STATUS, BIT(31));
  423. }
  424. static u32 sde_hw_sspp_get_ubwc_error_v1(struct sde_hw_pipe *ctx,
  425. enum sde_sspp_multirect_index multirect_index)
  426. {
  427. struct sde_hw_blk_reg_map *c;
  428. u32 reg_code;
  429. c = &ctx->hw;
  430. if (multirect_index == SDE_SSPP_RECT_1)
  431. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS_REC1);
  432. else
  433. reg_code = SDE_REG_READ(c, SSPP_UBWC_ERROR_STATUS);
  434. return reg_code;
  435. }
  436. static void sde_hw_sspp_clear_meta_error(struct sde_hw_pipe *ctx,
  437. enum sde_sspp_multirect_index multirect_index)
  438. {
  439. struct sde_hw_blk_reg_map *c;
  440. c = &ctx->hw;
  441. if (multirect_index == SDE_SSPP_RECT_1)
  442. SDE_REG_WRITE(c, SSPP_META_ERROR_STATUS_REC1, BIT(31));
  443. else
  444. SDE_REG_WRITE(c, SSPP_META_ERROR_STATUS, BIT(31));
  445. }
  446. static u32 sde_hw_sspp_get_meta_error(struct sde_hw_pipe *ctx,
  447. enum sde_sspp_multirect_index multirect_index)
  448. {
  449. struct sde_hw_blk_reg_map *c;
  450. u32 reg_code;
  451. c = &ctx->hw;
  452. if (multirect_index == SDE_SSPP_RECT_1)
  453. reg_code = SDE_REG_READ(c, SSPP_META_ERROR_STATUS_REC1);
  454. else
  455. reg_code = SDE_REG_READ(c, SSPP_META_ERROR_STATUS);
  456. return reg_code;
  457. }
  458. static void sde_hw_sspp_ubwc_stats_set_roi(struct sde_hw_pipe *ctx,
  459. enum sde_sspp_multirect_index multirect_index,
  460. struct sde_drm_ubwc_stats_roi *roi)
  461. {
  462. struct sde_hw_blk_reg_map *c;
  463. u32 idx, ctrl_off, roi_off;
  464. u32 ctrl_val = 0, roi_val = 0;
  465. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  466. return;
  467. if (multirect_index == SDE_SSPP_RECT_SOLO || multirect_index == SDE_SSPP_RECT_0) {
  468. ctrl_off = SSPP_UBWC_STATIC_CTRL + idx;
  469. roi_off = SSPP_UBWC_STATS_ROI + idx;
  470. } else {
  471. ctrl_off = SSPP_UBWC_STATIC_CTRL_REC1 + idx;
  472. roi_off = SSPP_UBWC_STATS_ROI_REC1 + idx;
  473. }
  474. c = &ctx->hw;
  475. ctrl_val = SDE_REG_READ(c, ctrl_off);
  476. if (roi) {
  477. ctrl_val |= BIT(24);
  478. if (roi->y_coord0) {
  479. ctrl_val |= BIT(25);
  480. roi_val |= roi->y_coord0;
  481. if (roi->y_coord1) {
  482. ctrl_val |= BIT(26);
  483. roi_val |= (roi->y_coord1) << 0x10;
  484. }
  485. }
  486. } else {
  487. ctrl_val &= ~(BIT(24) | BIT(25) | BIT(26));
  488. }
  489. SDE_REG_WRITE(c, ctrl_off, ctrl_val);
  490. SDE_REG_WRITE(c, roi_off, roi_val);
  491. }
  492. static void sde_hw_sspp_ubwc_stats_get_data(struct sde_hw_pipe *ctx,
  493. enum sde_sspp_multirect_index multirect_index,
  494. struct sde_drm_ubwc_stats_data *data)
  495. {
  496. struct sde_hw_blk_reg_map *c;
  497. u32 idx, value = 0;
  498. int i;
  499. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  500. return;
  501. if (multirect_index == SDE_SSPP_RECT_SOLO || multirect_index == SDE_SSPP_RECT_0)
  502. idx += SSPP_UBWC_STATS_DATA;
  503. else
  504. idx += SSPP_UBWC_STATS_DATA_REC1;
  505. c = &ctx->hw;
  506. for (i = 0; i < UBWC_STATS_MAX_ROI; i++) {
  507. value = SDE_REG_READ(c, idx);
  508. data->worst_bw[i] = value & 0xFFFF;
  509. data->worst_bw_y_coord[i] = (value >> 0x10) & 0xFFFF;
  510. data->total_bw[i] = SDE_REG_READ(c, idx + 4);
  511. idx += 8;
  512. }
  513. }
  514. static void sde_hw_sspp_setup_secure(struct sde_hw_pipe *ctx,
  515. enum sde_sspp_multirect_index rect_mode,
  516. bool enable)
  517. {
  518. struct sde_hw_blk_reg_map *c;
  519. u32 secure = 0, secure_bit_mask;
  520. u32 idx;
  521. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  522. return;
  523. c = &ctx->hw;
  524. if ((rect_mode == SDE_SSPP_RECT_SOLO)
  525. || (rect_mode == SDE_SSPP_RECT_0))
  526. secure_bit_mask =
  527. (rect_mode == SDE_SSPP_RECT_SOLO) ? 0xF : 0x5;
  528. else
  529. secure_bit_mask = 0xA;
  530. secure = SDE_REG_READ(c, SSPP_SRC_ADDR_SW_STATUS + idx);
  531. if (enable)
  532. secure |= secure_bit_mask;
  533. else
  534. secure &= ~secure_bit_mask;
  535. SDE_REG_WRITE(c, SSPP_SRC_ADDR_SW_STATUS + idx, secure);
  536. /* multiple planes share same sw_status register */
  537. wmb();
  538. }
  539. static void sde_hw_sspp_setup_pe_config(struct sde_hw_pipe *ctx,
  540. struct sde_hw_pixel_ext *pe_ext)
  541. {
  542. struct sde_hw_blk_reg_map *c;
  543. u8 color;
  544. u32 lr_pe[4], tb_pe[4], tot_req_pixels[4];
  545. const u32 bytemask = 0xff;
  546. const u32 shortmask = 0xffff;
  547. u32 idx;
  548. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !pe_ext)
  549. return;
  550. c = &ctx->hw;
  551. /* program SW pixel extension override for all pipes*/
  552. for (color = 0; color < SDE_MAX_PLANES; color++) {
  553. /* color 2 has the same set of registers as color 1 */
  554. if (color == 2)
  555. continue;
  556. lr_pe[color] = ((pe_ext->right_ftch[color] & bytemask) << 24)|
  557. ((pe_ext->right_rpt[color] & bytemask) << 16)|
  558. ((pe_ext->left_ftch[color] & bytemask) << 8)|
  559. (pe_ext->left_rpt[color] & bytemask);
  560. tb_pe[color] = ((pe_ext->btm_ftch[color] & bytemask) << 24)|
  561. ((pe_ext->btm_rpt[color] & bytemask) << 16)|
  562. ((pe_ext->top_ftch[color] & bytemask) << 8)|
  563. (pe_ext->top_rpt[color] & bytemask);
  564. tot_req_pixels[color] = (((pe_ext->roi_h[color] +
  565. pe_ext->num_ext_pxls_top[color] +
  566. pe_ext->num_ext_pxls_btm[color]) & shortmask) << 16) |
  567. ((pe_ext->roi_w[color] +
  568. pe_ext->num_ext_pxls_left[color] +
  569. pe_ext->num_ext_pxls_right[color]) & shortmask);
  570. }
  571. /* color 0 */
  572. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_LR + idx, lr_pe[0]);
  573. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_TB + idx, tb_pe[0]);
  574. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C0_REQ_PIXELS + idx,
  575. tot_req_pixels[0]);
  576. /* color 1 and color 2 */
  577. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_LR + idx, lr_pe[1]);
  578. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_TB + idx, tb_pe[1]);
  579. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C1C2_REQ_PIXELS + idx,
  580. tot_req_pixels[1]);
  581. /* color 3 */
  582. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_LR + idx, lr_pe[3]);
  583. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_TB + idx, tb_pe[3]);
  584. SDE_REG_WRITE(c, SSPP_SW_PIX_EXT_C3_REQ_PIXELS + idx,
  585. tot_req_pixels[3]);
  586. }
  587. static void _sde_hw_sspp_setup_scaler(struct sde_hw_pipe *ctx,
  588. struct sde_hw_pipe_cfg *sspp,
  589. struct sde_hw_pixel_ext *pe,
  590. void *scaler_cfg)
  591. {
  592. struct sde_hw_blk_reg_map *c;
  593. int config_h = 0x0;
  594. int config_v = 0x0;
  595. u32 idx;
  596. (void)sspp;
  597. (void)scaler_cfg;
  598. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !pe)
  599. return;
  600. c = &ctx->hw;
  601. /* enable scaler(s) if valid filter set */
  602. if (pe->horz_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  603. config_h |= pe->horz_filter[SDE_SSPP_COMP_0] << 8;
  604. if (pe->horz_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  605. config_h |= pe->horz_filter[SDE_SSPP_COMP_1_2] << 12;
  606. if (pe->horz_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  607. config_h |= pe->horz_filter[SDE_SSPP_COMP_3] << 16;
  608. if (config_h)
  609. config_h |= BIT(0);
  610. if (pe->vert_filter[SDE_SSPP_COMP_0] < SDE_SCALE_FILTER_MAX)
  611. config_v |= pe->vert_filter[SDE_SSPP_COMP_0] << 10;
  612. if (pe->vert_filter[SDE_SSPP_COMP_1_2] < SDE_SCALE_FILTER_MAX)
  613. config_v |= pe->vert_filter[SDE_SSPP_COMP_1_2] << 14;
  614. if (pe->vert_filter[SDE_SSPP_COMP_3] < SDE_SCALE_FILTER_MAX)
  615. config_v |= pe->vert_filter[SDE_SSPP_COMP_3] << 18;
  616. if (config_v)
  617. config_v |= BIT(1);
  618. SDE_REG_WRITE(c, SCALE_CONFIG + idx, config_h | config_v);
  619. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_X + idx,
  620. pe->init_phase_x[SDE_SSPP_COMP_0]);
  621. SDE_REG_WRITE(c, COMP0_3_INIT_PHASE_Y + idx,
  622. pe->init_phase_y[SDE_SSPP_COMP_0]);
  623. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_X + idx,
  624. pe->phase_step_x[SDE_SSPP_COMP_0]);
  625. SDE_REG_WRITE(c, COMP0_3_PHASE_STEP_Y + idx,
  626. pe->phase_step_y[SDE_SSPP_COMP_0]);
  627. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_X + idx,
  628. pe->init_phase_x[SDE_SSPP_COMP_1_2]);
  629. SDE_REG_WRITE(c, COMP1_2_INIT_PHASE_Y + idx,
  630. pe->init_phase_y[SDE_SSPP_COMP_1_2]);
  631. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_X + idx,
  632. pe->phase_step_x[SDE_SSPP_COMP_1_2]);
  633. SDE_REG_WRITE(c, COMP1_2_PHASE_STEP_Y + idx,
  634. pe->phase_step_y[SDE_SSPP_COMP_1_2]);
  635. }
  636. static void _sde_hw_sspp_setup_scaler3(struct sde_hw_pipe *ctx,
  637. struct sde_hw_pipe_cfg *sspp,
  638. struct sde_hw_pixel_ext *pe,
  639. void *scaler_cfg)
  640. {
  641. u32 idx;
  642. bool de_lpf_en = false;
  643. struct sde_hw_scaler3_cfg *scaler3_cfg = scaler_cfg;
  644. (void)pe;
  645. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED3, &idx) || !sspp
  646. || !scaler3_cfg || !ctx || !ctx->cap || !ctx->cap->sblk)
  647. return;
  648. if (test_bit(SDE_SSPP_SCALER_DE_LPF_BLEND, &ctx->cap->features))
  649. de_lpf_en = true;
  650. sde_hw_setup_scaler3(&ctx->hw, scaler3_cfg,
  651. ctx->cap->sblk->scaler_blk.version, idx, sspp->layout.format, de_lpf_en);
  652. }
  653. static void sde_hw_sspp_setup_pre_downscale(struct sde_hw_pipe *ctx,
  654. struct sde_hw_inline_pre_downscale_cfg *pre_down)
  655. {
  656. u32 idx, val;
  657. if (!ctx || !pre_down || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  658. return;
  659. val = pre_down->pre_downscale_x_0 |
  660. (pre_down->pre_downscale_x_1 << 4) |
  661. (pre_down->pre_downscale_y_0 << 8) |
  662. (pre_down->pre_downscale_y_1 << 12);
  663. SDE_REG_WRITE(&ctx->hw, SSPP_PRE_DOWN_SCALE + idx, val);
  664. }
  665. /**
  666. * sde_hw_sspp_setup_rects()
  667. */
  668. static void sde_hw_sspp_setup_rects(struct sde_hw_pipe *ctx,
  669. struct sde_hw_pipe_cfg *cfg,
  670. enum sde_sspp_multirect_index rect_index)
  671. {
  672. struct sde_hw_blk_reg_map *c;
  673. u32 src_size, src_xy, dst_size, dst_xy, ystride0, ystride1;
  674. u32 src_size_off, src_xy_off, out_size_off, out_xy_off;
  675. u32 decimation = 0;
  676. u32 idx;
  677. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !cfg)
  678. return;
  679. c = &ctx->hw;
  680. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0) {
  681. src_size_off = SSPP_SRC_SIZE;
  682. src_xy_off = SSPP_SRC_XY;
  683. out_size_off = SSPP_OUT_SIZE;
  684. out_xy_off = SSPP_OUT_XY;
  685. } else {
  686. src_size_off = SSPP_SRC_SIZE_REC1;
  687. src_xy_off = SSPP_SRC_XY_REC1;
  688. out_size_off = SSPP_OUT_SIZE_REC1;
  689. out_xy_off = SSPP_OUT_XY_REC1;
  690. }
  691. /* src and dest rect programming */
  692. src_xy = (cfg->src_rect.y << 16) | (cfg->src_rect.x);
  693. src_size = (cfg->src_rect.h << 16) | (cfg->src_rect.w);
  694. dst_xy = (cfg->dst_rect.y << 16) | (cfg->dst_rect.x);
  695. dst_size = (cfg->dst_rect.h << 16) | (cfg->dst_rect.w);
  696. if (rect_index == SDE_SSPP_RECT_SOLO) {
  697. ystride0 = (cfg->layout.plane_pitch[0]) |
  698. (cfg->layout.plane_pitch[1] << 16);
  699. ystride1 = (cfg->layout.plane_pitch[2]) |
  700. (cfg->layout.plane_pitch[3] << 16);
  701. } else {
  702. ystride0 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE0 + idx);
  703. ystride1 = SDE_REG_READ(c, SSPP_SRC_YSTRIDE1 + idx);
  704. if (rect_index == SDE_SSPP_RECT_0) {
  705. ystride0 = (ystride0 & 0xFFFF0000) |
  706. (cfg->layout.plane_pitch[0] & 0x0000FFFF);
  707. ystride1 = (ystride1 & 0xFFFF0000)|
  708. (cfg->layout.plane_pitch[2] & 0x0000FFFF);
  709. } else {
  710. ystride0 = (ystride0 & 0x0000FFFF) |
  711. ((cfg->layout.plane_pitch[0] << 16) &
  712. 0xFFFF0000);
  713. ystride1 = (ystride1 & 0x0000FFFF) |
  714. ((cfg->layout.plane_pitch[2] << 16) &
  715. 0xFFFF0000);
  716. }
  717. }
  718. /* program scaler, phase registers, if pipes supporting scaling */
  719. if (ctx->cap->features & SDE_SSPP_SCALER) {
  720. /* program decimation */
  721. decimation = ((1 << cfg->horz_decimation) - 1) << 8;
  722. decimation |= ((1 << cfg->vert_decimation) - 1);
  723. }
  724. /* rectangle register programming */
  725. SDE_REG_WRITE(c, src_size_off + idx, src_size);
  726. SDE_REG_WRITE(c, src_xy_off + idx, src_xy);
  727. SDE_REG_WRITE(c, out_size_off + idx, dst_size);
  728. SDE_REG_WRITE(c, out_xy_off + idx, dst_xy);
  729. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE0 + idx, ystride0);
  730. SDE_REG_WRITE(c, SSPP_SRC_YSTRIDE1 + idx, ystride1);
  731. SDE_REG_WRITE(c, SSPP_DECIMATION_CONFIG + idx, decimation);
  732. }
  733. /**
  734. * _sde_hw_sspp_setup_excl_rect() - set exclusion rect configs
  735. * @ctx: Pointer to pipe context
  736. * @excl_rect: Exclusion rect configs
  737. */
  738. static void _sde_hw_sspp_setup_excl_rect(struct sde_hw_pipe *ctx,
  739. struct sde_rect *excl_rect,
  740. enum sde_sspp_multirect_index rect_index)
  741. {
  742. struct sde_hw_blk_reg_map *c;
  743. u32 size, xy;
  744. u32 idx;
  745. u32 reg_xy, reg_size;
  746. u32 excl_ctrl = BIT(0);
  747. u32 enable_bit;
  748. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !excl_rect)
  749. return;
  750. if (rect_index == SDE_SSPP_RECT_0 || rect_index == SDE_SSPP_RECT_SOLO) {
  751. reg_xy = SSPP_EXCL_REC_XY;
  752. reg_size = SSPP_EXCL_REC_SIZE;
  753. enable_bit = BIT(0);
  754. } else {
  755. reg_xy = SSPP_EXCL_REC_XY_REC1;
  756. reg_size = SSPP_EXCL_REC_SIZE_REC1;
  757. enable_bit = BIT(1);
  758. }
  759. c = &ctx->hw;
  760. xy = (excl_rect->y << 16) | (excl_rect->x);
  761. size = (excl_rect->h << 16) | (excl_rect->w);
  762. /* Set if multi-rect disabled, read+modify only if multi-rect enabled */
  763. if (rect_index != SDE_SSPP_RECT_SOLO)
  764. excl_ctrl = SDE_REG_READ(c, SSPP_EXCL_REC_CTL + idx);
  765. if (!size) {
  766. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  767. excl_ctrl & ~enable_bit);
  768. } else {
  769. SDE_REG_WRITE(c, SSPP_EXCL_REC_CTL + idx,
  770. excl_ctrl | enable_bit);
  771. SDE_REG_WRITE(c, reg_size + idx, size);
  772. SDE_REG_WRITE(c, reg_xy + idx, xy);
  773. }
  774. }
  775. static void sde_hw_sspp_setup_sourceaddress(struct sde_hw_pipe *ctx,
  776. struct sde_hw_pipe_cfg *cfg,
  777. enum sde_sspp_multirect_index rect_mode)
  778. {
  779. int i;
  780. u32 idx;
  781. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  782. return;
  783. if (rect_mode == SDE_SSPP_RECT_SOLO) {
  784. for (i = 0; i < ARRAY_SIZE(cfg->layout.plane_addr); i++)
  785. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx + i * 0x4,
  786. cfg->layout.plane_addr[i]);
  787. } else if (rect_mode == SDE_SSPP_RECT_0) {
  788. SDE_REG_WRITE(&ctx->hw, SSPP_SRC0_ADDR + idx,
  789. cfg->layout.plane_addr[0]);
  790. SDE_REG_WRITE(&ctx->hw, SSPP_SRC2_ADDR + idx,
  791. cfg->layout.plane_addr[2]);
  792. } else {
  793. SDE_REG_WRITE(&ctx->hw, SSPP_SRC1_ADDR + idx,
  794. cfg->layout.plane_addr[0]);
  795. SDE_REG_WRITE(&ctx->hw, SSPP_SRC3_ADDR + idx,
  796. cfg->layout.plane_addr[2]);
  797. }
  798. }
  799. u32 sde_hw_sspp_get_source_addr(struct sde_hw_pipe *ctx, bool is_virtual)
  800. {
  801. u32 idx;
  802. u32 offset = 0;
  803. if (!ctx || _sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  804. return 0;
  805. offset = is_virtual ? (SSPP_SRC1_ADDR + idx) : (SSPP_SRC0_ADDR + idx);
  806. return SDE_REG_READ(&ctx->hw, offset);
  807. }
  808. static void sde_hw_sspp_setup_csc(struct sde_hw_pipe *ctx,
  809. struct sde_csc_cfg *data)
  810. {
  811. u32 idx;
  812. bool csc10 = false;
  813. if (_sspp_subblk_offset(ctx, SDE_SSPP_CSC, &idx) || !data)
  814. return;
  815. if (test_bit(SDE_SSPP_CSC_10BIT, &ctx->cap->features)) {
  816. idx += CSC_10BIT_OFFSET;
  817. csc10 = true;
  818. }
  819. sde_hw_csc_setup(&ctx->hw, idx, data, csc10);
  820. }
  821. static void sde_hw_sspp_setup_sharpening(struct sde_hw_pipe *ctx,
  822. struct sde_hw_sharp_cfg *cfg)
  823. {
  824. struct sde_hw_blk_reg_map *c;
  825. u32 idx;
  826. if (_sspp_subblk_offset(ctx, SDE_SSPP_SCALER_QSEED2, &idx) || !cfg ||
  827. !test_bit(SDE_SSPP_SCALER_QSEED2, &ctx->cap->features))
  828. return;
  829. c = &ctx->hw;
  830. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx, cfg->strength);
  831. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x4, cfg->edge_thr);
  832. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0x8, cfg->smooth_thr);
  833. SDE_REG_WRITE(c, VIG_0_QSEED2_SHARP + idx + 0xC, cfg->noise_thr);
  834. }
  835. static void sde_hw_sspp_setup_solidfill(struct sde_hw_pipe *ctx, u32 color, enum
  836. sde_sspp_multirect_index rect_index)
  837. {
  838. u32 idx;
  839. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  840. return;
  841. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0)
  842. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR + idx, color);
  843. else
  844. SDE_REG_WRITE(&ctx->hw, SSPP_SRC_CONSTANT_COLOR_REC1 + idx,
  845. color);
  846. }
  847. static void sde_hw_sspp_setup_qos_lut(struct sde_hw_pipe *ctx,
  848. struct sde_hw_pipe_qos_cfg *cfg)
  849. {
  850. u32 idx;
  851. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  852. return;
  853. SDE_REG_WRITE(&ctx->hw, SSPP_DANGER_LUT + idx, cfg->danger_lut);
  854. SDE_REG_WRITE(&ctx->hw, SSPP_SAFE_LUT + idx, cfg->safe_lut);
  855. if (ctx->cap && test_bit(SDE_PERF_SSPP_QOS_8LVL,
  856. &ctx->cap->perf_features)) {
  857. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_0 + idx, cfg->creq_lut);
  858. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT_1 + idx,
  859. cfg->creq_lut >> 32);
  860. } else {
  861. SDE_REG_WRITE(&ctx->hw, SSPP_CREQ_LUT + idx, cfg->creq_lut);
  862. }
  863. }
  864. static void sde_hw_sspp_setup_qos_ctrl(struct sde_hw_pipe *ctx,
  865. struct sde_hw_pipe_qos_cfg *cfg)
  866. {
  867. u32 idx;
  868. u32 qos_ctrl = 0;
  869. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  870. return;
  871. if (cfg->vblank_en) {
  872. qos_ctrl |= ((cfg->creq_vblank &
  873. SSPP_QOS_CTRL_CREQ_VBLANK_MASK) <<
  874. SSPP_QOS_CTRL_CREQ_VBLANK_OFF);
  875. qos_ctrl |= ((cfg->danger_vblank &
  876. SSPP_QOS_CTRL_DANGER_VBLANK_MASK) <<
  877. SSPP_QOS_CTRL_DANGER_VBLANK_OFF);
  878. qos_ctrl |= SSPP_QOS_CTRL_VBLANK_EN;
  879. }
  880. if (cfg->danger_safe_en)
  881. qos_ctrl |= SSPP_QOS_CTRL_DANGER_SAFE_EN;
  882. SDE_REG_WRITE(&ctx->hw, SSPP_QOS_CTRL + idx, qos_ctrl);
  883. }
  884. static void sde_hw_sspp_setup_ts_prefill(struct sde_hw_pipe *ctx,
  885. struct sde_hw_pipe_ts_cfg *cfg,
  886. enum sde_sspp_multirect_index index)
  887. {
  888. u32 idx;
  889. u32 ts_offset, ts_prefill_offset;
  890. u32 ts_count = 0, ts_bytes = 0;
  891. const struct sde_sspp_cfg *cap;
  892. if (!ctx || !cfg || !ctx->cap)
  893. return;
  894. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  895. return;
  896. cap = ctx->cap;
  897. if ((index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) &&
  898. test_bit(SDE_PERF_SSPP_TS_PREFILL,
  899. &cap->perf_features)) {
  900. ts_offset = SSPP_TRAFFIC_SHAPER;
  901. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_PREFILL;
  902. } else if (index == SDE_SSPP_RECT_1 &&
  903. test_bit(SDE_PERF_SSPP_TS_PREFILL_REC1,
  904. &cap->perf_features)) {
  905. ts_offset = SSPP_TRAFFIC_SHAPER_REC1;
  906. ts_prefill_offset = SSPP_TRAFFIC_SHAPER_REC1_PREFILL;
  907. } else {
  908. pr_err("%s: unexpected idx:%d\n", __func__, index);
  909. return;
  910. }
  911. if (cfg->time) {
  912. ts_count = DIV_ROUND_UP_ULL(TS_CLK * cfg->time, 1000000ULL);
  913. ts_bytes = DIV_ROUND_UP_ULL(cfg->size, ts_count);
  914. if (ts_bytes > SSPP_TRAFFIC_SHAPER_BPC_MAX)
  915. ts_bytes = SSPP_TRAFFIC_SHAPER_BPC_MAX;
  916. }
  917. if (ts_count)
  918. ts_bytes |= BIT(31) | BIT(27);
  919. SDE_REG_WRITE(&ctx->hw, ts_offset, ts_bytes);
  920. SDE_REG_WRITE(&ctx->hw, ts_prefill_offset, ts_count);
  921. }
  922. static void sde_hw_sspp_setup_cdp(struct sde_hw_pipe *ctx,
  923. struct sde_hw_pipe_cdp_cfg *cfg,
  924. enum sde_sspp_multirect_index index)
  925. {
  926. u32 idx;
  927. u32 cdp_cntl = 0;
  928. u32 cdp_cntl_offset = 0;
  929. if (!ctx || !cfg)
  930. return;
  931. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  932. return;
  933. if (index == SDE_SSPP_RECT_SOLO || index == SDE_SSPP_RECT_0) {
  934. cdp_cntl_offset = SSPP_CDP_CNTL;
  935. } else if (index == SDE_SSPP_RECT_1) {
  936. cdp_cntl_offset = SSPP_CDP_CNTL_REC1;
  937. } else {
  938. pr_err("%s: unexpected idx:%d\n", __func__, index);
  939. return;
  940. }
  941. if (cfg->enable)
  942. cdp_cntl |= BIT(0);
  943. if (cfg->ubwc_meta_enable)
  944. cdp_cntl |= BIT(1);
  945. if (cfg->tile_amortize_enable)
  946. cdp_cntl |= BIT(2);
  947. if (cfg->preload_ahead == SDE_SSPP_CDP_PRELOAD_AHEAD_64)
  948. cdp_cntl |= BIT(3);
  949. SDE_REG_WRITE(&ctx->hw, cdp_cntl_offset, cdp_cntl);
  950. }
  951. static void sde_hw_sspp_setup_sys_cache(struct sde_hw_pipe *ctx,
  952. struct sde_hw_pipe_sc_cfg *cfg)
  953. {
  954. u32 idx, val;
  955. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  956. return;
  957. if (!cfg)
  958. return;
  959. val = SDE_REG_READ(&ctx->hw, SSPP_SYS_CACHE_MODE + idx);
  960. if (cfg->flags & SYS_CACHE_EN_FLAG)
  961. val = (val & ~BIT(15)) | ((cfg->rd_en & 0x1) << 15);
  962. if (cfg->flags & SYS_CACHE_SCID)
  963. val = (val & ~0x1F00) | ((cfg->rd_scid & 0x1f) << 8);
  964. if (cfg->flags & SYS_CACHE_OP_MODE)
  965. val = (val & ~0xC0000) | ((cfg->op_mode & 0x3) << 18);
  966. if (cfg->flags & SYS_CACHE_OP_TYPE)
  967. val = (val & ~0xF) | ((cfg->rd_op_type & 0xf) << 0);
  968. if (cfg->flags & SYS_CACHE_NO_ALLOC)
  969. val = (val & ~0x10) | ((cfg->rd_noallocate & 0x1) << 4);
  970. SDE_REG_WRITE(&ctx->hw, SSPP_SYS_CACHE_MODE + idx, val);
  971. }
  972. static void sde_hw_sspp_setup_uidle_fill_scale(struct sde_hw_pipe *ctx,
  973. struct sde_hw_pipe_uidle_cfg *cfg)
  974. {
  975. u32 idx, fill_lvl;
  976. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  977. return;
  978. /* duplicate the v1 scale values for V2 and fal10 exit */
  979. fill_lvl = cfg->fill_level_scale & 0xF;
  980. fill_lvl |= (cfg->fill_level_scale & 0xF) << 8;
  981. fill_lvl |= (cfg->fill_level_scale & 0xF) << 16;
  982. SDE_REG_WRITE(&ctx->hw, SSPP_FILL_LEVEL_SCALE + idx, fill_lvl);
  983. }
  984. static void sde_hw_sspp_setup_uidle(struct sde_hw_pipe *ctx,
  985. struct sde_hw_pipe_uidle_cfg *cfg,
  986. enum sde_sspp_multirect_index index)
  987. {
  988. u32 idx, val;
  989. u32 offset;
  990. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx))
  991. return;
  992. if (index == SDE_SSPP_RECT_1)
  993. offset = SSPP_UIDLE_CTRL_VALUE_REC1;
  994. else
  995. offset = SSPP_UIDLE_CTRL_VALUE;
  996. val = SDE_REG_READ(&ctx->hw, offset + idx);
  997. val = (val & ~BIT(31)) | (cfg->enable ? 0x0 : BIT(31));
  998. val = (val & ~0xFF00000) | (cfg->fal_allowed_threshold << 20);
  999. val = (val & ~0xF0000) | (cfg->fal10_exit_threshold << 16);
  1000. val = (val & ~0xF00) | (cfg->fal10_threshold << 8);
  1001. val = (val & ~0xF) | (cfg->fal1_threshold << 0);
  1002. SDE_REG_WRITE(&ctx->hw, offset + idx, val);
  1003. }
  1004. static void _setup_layer_ops_colorproc(struct sde_hw_pipe *c,
  1005. unsigned long features, bool is_virtual_pipe)
  1006. {
  1007. int ret = 0;
  1008. if (is_virtual_pipe) {
  1009. features &=
  1010. ~(BIT(SDE_SSPP_VIG_IGC) | BIT(SDE_SSPP_VIG_GAMUT));
  1011. c->cap->features = features;
  1012. }
  1013. if (test_bit(SDE_SSPP_HSIC, &features)) {
  1014. if (c->cap->sblk->hsic_blk.version ==
  1015. (SDE_COLOR_PROCESS_VER(0x1, 0x7))) {
  1016. c->ops.setup_pa_hue = sde_setup_pipe_pa_hue_v1_7;
  1017. c->ops.setup_pa_sat = sde_setup_pipe_pa_sat_v1_7;
  1018. c->ops.setup_pa_val = sde_setup_pipe_pa_val_v1_7;
  1019. c->ops.setup_pa_cont = sde_setup_pipe_pa_cont_v1_7;
  1020. }
  1021. }
  1022. if (test_bit(SDE_SSPP_MEMCOLOR, &features)) {
  1023. if (c->cap->sblk->memcolor_blk.version ==
  1024. (SDE_COLOR_PROCESS_VER(0x1, 0x7)))
  1025. c->ops.setup_pa_memcolor =
  1026. sde_setup_pipe_pa_memcol_v1_7;
  1027. }
  1028. if (test_bit(SDE_SSPP_VIG_GAMUT, &features)) {
  1029. if (c->cap->sblk->gamut_blk.version ==
  1030. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1031. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1032. c->idx);
  1033. if (!ret)
  1034. c->ops.setup_vig_gamut =
  1035. reg_dmav1_setup_vig_gamutv5;
  1036. else
  1037. c->ops.setup_vig_gamut = NULL;
  1038. }
  1039. if (c->cap->sblk->gamut_blk.version ==
  1040. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  1041. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1042. c->idx);
  1043. if (!ret)
  1044. c->ops.setup_vig_gamut =
  1045. reg_dmav1_setup_vig_gamutv6;
  1046. else
  1047. c->ops.setup_vig_gamut = NULL;
  1048. } else if (c->cap->sblk->gamut_blk.version ==
  1049. (SDE_COLOR_PROCESS_VER(0x6, 0x1))) {
  1050. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_GAMUT,
  1051. c->idx);
  1052. if (!ret)
  1053. c->ops.setup_vig_gamut =
  1054. reg_dmav2_setup_vig_gamutv61;
  1055. else
  1056. c->ops.setup_vig_gamut = NULL;
  1057. }
  1058. }
  1059. if (test_bit(SDE_SSPP_VIG_IGC, &features)) {
  1060. if (c->cap->sblk->igc_blk[0].version ==
  1061. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1062. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  1063. c->idx);
  1064. if (!ret)
  1065. c->ops.setup_vig_igc =
  1066. reg_dmav1_setup_vig_igcv5;
  1067. else
  1068. c->ops.setup_vig_igc = NULL;
  1069. }
  1070. if (c->cap->sblk->igc_blk[0].version ==
  1071. (SDE_COLOR_PROCESS_VER(0x6, 0x0))) {
  1072. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_VIG_IGC,
  1073. c->idx);
  1074. if (!ret)
  1075. c->ops.setup_vig_igc =
  1076. reg_dmav1_setup_vig_igcv6;
  1077. else
  1078. c->ops.setup_vig_igc = NULL;
  1079. }
  1080. }
  1081. if (test_bit(SDE_SSPP_DMA_IGC, &features)) {
  1082. if (c->cap->sblk->igc_blk[0].version ==
  1083. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1084. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_IGC,
  1085. c->idx);
  1086. if (!ret)
  1087. c->ops.setup_dma_igc =
  1088. reg_dmav1_setup_dma_igcv5;
  1089. else
  1090. c->ops.setup_dma_igc = NULL;
  1091. }
  1092. }
  1093. if (test_bit(SDE_SSPP_DMA_GC, &features)) {
  1094. if (c->cap->sblk->gc_blk[0].version ==
  1095. (SDE_COLOR_PROCESS_VER(0x5, 0x0))) {
  1096. ret = reg_dmav1_init_sspp_op_v4(SDE_SSPP_DMA_GC,
  1097. c->idx);
  1098. if (!ret)
  1099. c->ops.setup_dma_gc =
  1100. reg_dmav1_setup_dma_gcv5;
  1101. else
  1102. c->ops.setup_dma_gc = NULL;
  1103. }
  1104. }
  1105. if (test_bit(SDE_SSPP_FP16_IGC, &features) &&
  1106. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_igc_blk[0].version))
  1107. c->ops.setup_fp16_igc = sde_setup_fp16_igcv1;
  1108. if (test_bit(SDE_SSPP_FP16_GC, &features) &&
  1109. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_gc_blk[0].version))
  1110. c->ops.setup_fp16_gc = sde_setup_fp16_gcv1;
  1111. if (test_bit(SDE_SSPP_FP16_CSC, &features) &&
  1112. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_csc_blk[0].version))
  1113. c->ops.setup_fp16_csc = sde_setup_fp16_cscv1;
  1114. if (test_bit(SDE_SSPP_FP16_UNMULT, &features) &&
  1115. IS_SDE_CP_VER_1_0(c->cap->sblk->fp16_unmult_blk[0].version))
  1116. c->ops.setup_fp16_unmult = sde_setup_fp16_unmultv1;
  1117. }
  1118. static void sde_hw_sspp_setup_inverse_pma(struct sde_hw_pipe *ctx,
  1119. enum sde_sspp_multirect_index index, u32 enable)
  1120. {
  1121. u32 op_mode = 0;
  1122. u32 offset;
  1123. if (!ctx || (index == SDE_SSPP_RECT_1))
  1124. return;
  1125. offset = ctx->cap->sblk->unmult_offset[0];
  1126. if (enable)
  1127. op_mode |= BIT(0);
  1128. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1129. }
  1130. static void sde_hw_sspp_setup_dgm_inverse_pma(struct sde_hw_pipe *ctx,
  1131. enum sde_sspp_multirect_index index, u32 enable)
  1132. {
  1133. u32 offset;
  1134. u32 op_mode = 0;
  1135. if (!ctx)
  1136. return;
  1137. if (index == SDE_SSPP_RECT_1)
  1138. offset = ctx->cap->sblk->unmult_offset[1];
  1139. else
  1140. offset = ctx->cap->sblk->unmult_offset[0];
  1141. op_mode = SDE_REG_READ(&ctx->hw, offset);
  1142. if (enable)
  1143. op_mode |= BIT(0);
  1144. else
  1145. op_mode &= ~BIT(0);
  1146. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1147. }
  1148. static void sde_hw_sspp_setup_dgm_csc(struct sde_hw_pipe *ctx,
  1149. enum sde_sspp_multirect_index index, struct sde_csc_cfg *data)
  1150. {
  1151. u32 idx = 0;
  1152. u32 offset;
  1153. u32 op_mode = 0;
  1154. const struct sde_sspp_sub_blks *sblk;
  1155. if (!ctx || !ctx->cap || !ctx->cap->sblk)
  1156. return;
  1157. sblk = ctx->cap->sblk;
  1158. if (index == SDE_SSPP_RECT_1)
  1159. idx = 1;
  1160. offset = sblk->dgm_csc_blk[idx].base;
  1161. if (data) {
  1162. op_mode |= BIT(0);
  1163. sde_hw_csc_matrix_coeff_setup(&ctx->hw,
  1164. offset + CSC_10BIT_OFFSET, data, DGM_CSC_MATRIX_SHIFT);
  1165. }
  1166. SDE_REG_WRITE(&ctx->hw, offset, op_mode);
  1167. }
  1168. static bool sde_hw_sspp_setup_clk_force_ctrl(struct sde_hw_blk_reg_map *hw,
  1169. enum sde_clk_ctrl_type clk_ctrl, bool enable)
  1170. {
  1171. u32 reg_val, new_val;
  1172. if (!hw)
  1173. return false;
  1174. if (!SDE_CLK_CTRL_SSPP_VALID(clk_ctrl))
  1175. return false;
  1176. reg_val = SDE_REG_READ(hw, SSPP_CLK_CTRL);
  1177. if (enable)
  1178. new_val = reg_val | BIT(0);
  1179. else
  1180. new_val = reg_val & ~BIT(0);
  1181. SDE_REG_WRITE(hw, SSPP_CLK_CTRL, new_val);
  1182. wmb(); /* ensure write finished before progressing */
  1183. return !(reg_val & BIT(0));
  1184. }
  1185. static int sde_hw_sspp_get_clk_ctrl_status(struct sde_hw_blk_reg_map *hw,
  1186. enum sde_clk_ctrl_type clk_ctrl, bool *status)
  1187. {
  1188. if (!hw)
  1189. return -EINVAL;
  1190. if (!SDE_CLK_CTRL_SSPP_VALID(clk_ctrl))
  1191. return -EINVAL;
  1192. *status = SDE_REG_READ(hw, SSPP_CLK_STATUS) & BIT(0);
  1193. return 0;
  1194. }
  1195. static void sde_hw_sspp_setup_line_insertion(struct sde_hw_pipe *ctx,
  1196. enum sde_sspp_multirect_index rect_index,
  1197. struct sde_hw_pipe_line_insertion_cfg *cfg)
  1198. {
  1199. struct sde_hw_blk_reg_map *c;
  1200. u32 ctl_off = 0, size_off = 0, ctl_val = 0;
  1201. u32 idx;
  1202. if (_sspp_subblk_offset(ctx, SDE_SSPP_SRC, &idx) || !cfg)
  1203. return;
  1204. c = &ctx->hw;
  1205. if (rect_index == SDE_SSPP_RECT_SOLO || rect_index == SDE_SSPP_RECT_0) {
  1206. ctl_off = SSPP_LINE_INSERTION_CTRL;
  1207. size_off = SSPP_LINE_INSERTION_OUT_SIZE;
  1208. } else {
  1209. ctl_off = SSPP_LINE_INSERTION_CTRL_REC1;
  1210. size_off = SSPP_LINE_INSERTION_OUT_SIZE_REC1;
  1211. }
  1212. if (cfg->enable)
  1213. ctl_val = BIT(31) |
  1214. (cfg->dummy_lines << 16) |
  1215. (cfg->first_active_lines << 8) |
  1216. (cfg->active_lines);
  1217. SDE_REG_WRITE(c, ctl_off, ctl_val);
  1218. SDE_REG_WRITE(c, size_off, cfg->dst_h << 16);
  1219. }
  1220. static void _setup_layer_ops(struct sde_hw_pipe *c,
  1221. unsigned long features, unsigned long perf_features,
  1222. bool is_virtual_pipe)
  1223. {
  1224. int ret;
  1225. if (test_bit(SDE_SSPP_SRC, &features)) {
  1226. c->ops.setup_format = sde_hw_sspp_setup_format;
  1227. c->ops.setup_rects = sde_hw_sspp_setup_rects;
  1228. c->ops.setup_sourceaddress = sde_hw_sspp_setup_sourceaddress;
  1229. c->ops.get_sourceaddress = sde_hw_sspp_get_source_addr;
  1230. c->ops.setup_solidfill = sde_hw_sspp_setup_solidfill;
  1231. c->ops.setup_pe = sde_hw_sspp_setup_pe_config;
  1232. c->ops.setup_secure_address = sde_hw_sspp_setup_secure;
  1233. c->ops.set_src_split_order = sde_hw_sspp_set_src_split_order;
  1234. }
  1235. if (test_bit(SDE_SSPP_EXCL_RECT, &features))
  1236. c->ops.setup_excl_rect = _sde_hw_sspp_setup_excl_rect;
  1237. if (test_bit(SDE_PERF_SSPP_QOS, &features)) {
  1238. c->ops.setup_qos_lut =
  1239. sde_hw_sspp_setup_qos_lut;
  1240. c->ops.setup_qos_ctrl = sde_hw_sspp_setup_qos_ctrl;
  1241. }
  1242. if (test_bit(SDE_PERF_SSPP_TS_PREFILL, &perf_features))
  1243. c->ops.setup_ts_prefill = sde_hw_sspp_setup_ts_prefill;
  1244. if (test_bit(SDE_SSPP_CSC, &features) ||
  1245. test_bit(SDE_SSPP_CSC_10BIT, &features))
  1246. c->ops.setup_csc = sde_hw_sspp_setup_csc;
  1247. if (test_bit(SDE_SSPP_DGM_CSC, &features))
  1248. c->ops.setup_dgm_csc = sde_hw_sspp_setup_dgm_csc;
  1249. if (test_bit(SDE_SSPP_SCALER_QSEED2, &features)) {
  1250. c->ops.setup_sharpening = sde_hw_sspp_setup_sharpening;
  1251. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler;
  1252. }
  1253. if (sde_hw_sspp_multirect_enabled(c->cap))
  1254. c->ops.update_multirect = sde_hw_sspp_update_multirect;
  1255. if (test_bit(SDE_SSPP_SCALER_QSEED3, &features) ||
  1256. test_bit(SDE_SSPP_SCALER_QSEED3LITE, &features)) {
  1257. c->ops.setup_scaler = _sde_hw_sspp_setup_scaler3;
  1258. c->ops.setup_scaler_lut = is_qseed3_rev_qseed3lite(
  1259. c->catalog) ? reg_dmav1_setup_scaler3lite_lut
  1260. : reg_dmav1_setup_scaler3_lut;
  1261. ret = reg_dmav1_init_sspp_op_v4(is_qseed3_rev_qseed3lite(
  1262. c->catalog) ? SDE_SSPP_SCALER_QSEED3LITE
  1263. : SDE_SSPP_SCALER_QSEED3, c->idx);
  1264. if (!ret)
  1265. c->ops.setup_scaler = reg_dmav1_setup_vig_qseed3;
  1266. }
  1267. if (test_bit(SDE_SSPP_MULTIRECT_ERROR, &features)) {
  1268. c->ops.get_meta_error = sde_hw_sspp_get_meta_error;
  1269. c->ops.clear_meta_error = sde_hw_sspp_clear_meta_error;
  1270. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error_v1;
  1271. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error_v1;
  1272. } else {
  1273. c->ops.get_ubwc_error = sde_hw_sspp_get_ubwc_error;
  1274. c->ops.clear_ubwc_error = sde_hw_sspp_clear_ubwc_error;
  1275. }
  1276. if (test_bit(SDE_SSPP_PREDOWNSCALE, &features))
  1277. c->ops.setup_pre_downscale = sde_hw_sspp_setup_pre_downscale;
  1278. if (test_bit(SDE_PERF_SSPP_SYS_CACHE, &perf_features))
  1279. c->ops.setup_sys_cache = sde_hw_sspp_setup_sys_cache;
  1280. if (test_bit(SDE_PERF_SSPP_CDP, &perf_features))
  1281. c->ops.setup_cdp = sde_hw_sspp_setup_cdp;
  1282. if (test_bit(SDE_PERF_SSPP_UIDLE, &perf_features)) {
  1283. c->ops.setup_uidle = sde_hw_sspp_setup_uidle;
  1284. if (test_bit(SDE_PERF_SSPP_UIDLE_FILL_LVL_SCALE, &perf_features))
  1285. c->ops.setup_uidle_fill_scale = sde_hw_sspp_setup_uidle_fill_scale;
  1286. }
  1287. _setup_layer_ops_colorproc(c, features, is_virtual_pipe);
  1288. if (test_bit(SDE_SSPP_DGM_INVERSE_PMA, &features))
  1289. c->ops.setup_inverse_pma = sde_hw_sspp_setup_dgm_inverse_pma;
  1290. else if (test_bit(SDE_SSPP_INVERSE_PMA, &features))
  1291. c->ops.setup_inverse_pma = sde_hw_sspp_setup_inverse_pma;
  1292. if (test_bit(SDE_SSPP_UBWC_STATS, &features)) {
  1293. c->ops.set_ubwc_stats_roi = sde_hw_sspp_ubwc_stats_set_roi;
  1294. c->ops.get_ubwc_stats_data = sde_hw_sspp_ubwc_stats_get_data;
  1295. }
  1296. if (test_bit(SDE_SSPP_LINE_INSERTION, &features))
  1297. c->ops.setup_line_insertion = sde_hw_sspp_setup_line_insertion;
  1298. }
  1299. static struct sde_sspp_cfg *_sspp_offset(enum sde_sspp sspp,
  1300. void __iomem *addr,
  1301. struct sde_mdss_cfg *catalog,
  1302. struct sde_hw_blk_reg_map *b)
  1303. {
  1304. int i;
  1305. struct sde_sspp_cfg *cfg;
  1306. if ((sspp < SSPP_MAX) && catalog && addr && b) {
  1307. for (i = 0; i < catalog->sspp_count; i++) {
  1308. if (sspp == catalog->sspp[i].id) {
  1309. b->base_off = addr;
  1310. b->blk_off = catalog->sspp[i].base;
  1311. b->length = catalog->sspp[i].len;
  1312. b->hw_rev = catalog->hw_rev;
  1313. b->log_mask = SDE_DBG_MASK_SSPP;
  1314. /* Only shallow copy is needed */
  1315. cfg = kmemdup(&catalog->sspp[i], sizeof(*cfg),
  1316. GFP_KERNEL);
  1317. if (!cfg)
  1318. return ERR_PTR(-ENOMEM);
  1319. return cfg;
  1320. }
  1321. }
  1322. }
  1323. return ERR_PTR(-ENOMEM);
  1324. }
  1325. struct sde_hw_pipe *sde_hw_sspp_init(enum sde_sspp idx,
  1326. void __iomem *addr, struct sde_mdss_cfg *catalog,
  1327. bool is_virtual_pipe, struct sde_vbif_clk_client *clk_client)
  1328. {
  1329. struct sde_hw_pipe *hw_pipe;
  1330. struct sde_sspp_cfg *cfg;
  1331. if (!addr || !catalog)
  1332. return ERR_PTR(-EINVAL);
  1333. hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
  1334. if (!hw_pipe)
  1335. return ERR_PTR(-ENOMEM);
  1336. cfg = _sspp_offset(idx, addr, catalog, &hw_pipe->hw);
  1337. if (IS_ERR_OR_NULL(cfg)) {
  1338. kfree(hw_pipe);
  1339. return ERR_PTR(-EINVAL);
  1340. }
  1341. /* Assign ops */
  1342. hw_pipe->catalog = catalog;
  1343. hw_pipe->mdp = &catalog->mdp[0];
  1344. hw_pipe->idx = idx;
  1345. hw_pipe->cap = cfg;
  1346. _setup_layer_ops(hw_pipe, hw_pipe->cap->features,
  1347. hw_pipe->cap->perf_features, is_virtual_pipe);
  1348. if (catalog->qseed_hw_rev)
  1349. sde_init_scaler_blk(&hw_pipe->cap->sblk->scaler_blk,
  1350. catalog->qseed_hw_rev);
  1351. if (!is_virtual_pipe) {
  1352. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name,
  1353. hw_pipe->hw.blk_off,
  1354. hw_pipe->hw.blk_off + hw_pipe->hw.length,
  1355. hw_pipe->hw.xin_id);
  1356. if (test_bit(SDE_SSPP_DGM_CSC, &hw_pipe->cap->features)) {
  1357. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "CSC_0",
  1358. hw_pipe->hw.blk_off + SSPP_DGM_CSC_0,
  1359. hw_pipe->hw.blk_off + SSPP_DGM_CSC_0 + SSPP_DGM_CSC_SIZE,
  1360. hw_pipe->hw.xin_id);
  1361. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "CSC_1",
  1362. hw_pipe->hw.blk_off + SSPP_DGM_CSC_1,
  1363. hw_pipe->hw.blk_off + SSPP_DGM_CSC_1 + SSPP_DGM_CSC_SIZE,
  1364. hw_pipe->hw.xin_id);
  1365. }
  1366. if (test_bit(SDE_SSPP_DMA_IGC, &hw_pipe->cap->features)) {
  1367. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "DGM_0",
  1368. hw_pipe->hw.blk_off + SSPP_DGM_0,
  1369. hw_pipe->hw.blk_off + SSPP_DGM_0 + SSPP_DGM_SIZE,
  1370. hw_pipe->hw.xin_id);
  1371. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, "DGM_1",
  1372. hw_pipe->hw.blk_off + SSPP_DGM_1,
  1373. hw_pipe->hw.blk_off + SSPP_DGM_1 + SSPP_DGM_SIZE,
  1374. hw_pipe->hw.xin_id);
  1375. }
  1376. if (test_bit(SDE_SSPP_VIG_GAMUT, &hw_pipe->cap->features)) {
  1377. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->sblk->gamut_blk.name,
  1378. hw_pipe->hw.blk_off + cfg->sblk->gamut_blk.base,
  1379. hw_pipe->hw.blk_off + cfg->sblk->gamut_blk.base + VIG_GAMUT_SIZE,
  1380. hw_pipe->hw.xin_id);
  1381. }
  1382. }
  1383. if (cfg->sblk->scaler_blk.len && !is_virtual_pipe)
  1384. sde_dbg_reg_register_dump_range(SDE_DBG_NAME,
  1385. cfg->sblk->scaler_blk.name,
  1386. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base,
  1387. hw_pipe->hw.blk_off + cfg->sblk->scaler_blk.base +
  1388. cfg->sblk->scaler_blk.len,
  1389. hw_pipe->hw.xin_id);
  1390. if (test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, catalog->features)) {
  1391. if (SDE_CLK_CTRL_SSPP_VALID(cfg->clk_ctrl)) {
  1392. clk_client->hw = &hw_pipe->hw;
  1393. clk_client->clk_ctrl = cfg->clk_ctrl;
  1394. clk_client->ops.get_clk_ctrl_status = sde_hw_sspp_get_clk_ctrl_status;
  1395. clk_client->ops.setup_clk_force_ctrl = sde_hw_sspp_setup_clk_force_ctrl;
  1396. } else {
  1397. SDE_ERROR("invalid sspp clk ctrl type %d\n", cfg->clk_ctrl);
  1398. }
  1399. }
  1400. return hw_pipe;
  1401. }
  1402. void sde_hw_sspp_destroy(struct sde_hw_pipe *ctx)
  1403. {
  1404. if (ctx) {
  1405. reg_dmav1_deinit_sspp_ops(ctx->idx);
  1406. kfree(ctx->cap);
  1407. }
  1408. kfree(ctx);
  1409. }