sde_hw_sspp.c 45 KB

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