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