sde_hw_sspp.c 43 KB

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