sde_hw_ctl.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  7. #include <linux/delay.h>
  8. #include "sde_hwio.h"
  9. #include "sde_hw_ctl.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #include "sde_reg_dma.h"
  13. #define CTL_LAYER(lm) \
  14. (((lm) == LM_5) ? (0x024) : (((lm) - LM_0) * 0x004))
  15. #define CTL_LAYER_EXT(lm) \
  16. (0x40 + (((lm) - LM_0) * 0x004))
  17. #define CTL_LAYER_EXT2(lm) \
  18. (0x70 + (((lm) - LM_0) * 0x004))
  19. #define CTL_LAYER_EXT3(lm) \
  20. (0xA0 + (((lm) - LM_0) * 0x004))
  21. #define CTL_LAYER_EXT4(lm) \
  22. (0xB8 + (((lm) - LM_0) * 0x004))
  23. #define CTL_TOP 0x014
  24. #define CTL_FLUSH 0x018
  25. #define CTL_START 0x01C
  26. #define CTL_PREPARE 0x0d0
  27. #define CTL_SW_RESET 0x030
  28. #define CTL_SW_RESET_OVERRIDE 0x060
  29. #define CTL_STATUS 0x064
  30. #define CTL_LAYER_EXTN_OFFSET 0x40
  31. #define CTL_ROT_TOP 0x0C0
  32. #define CTL_ROT_FLUSH 0x0C4
  33. #define CTL_ROT_START 0x0CC
  34. #define CTL_MERGE_3D_ACTIVE 0x0E4
  35. #define CTL_DSC_ACTIVE 0x0E8
  36. #define CTL_WB_ACTIVE 0x0EC
  37. #define CTL_CWB_ACTIVE 0x0F0
  38. #define CTL_INTF_ACTIVE 0x0F4
  39. #define CTL_CDM_ACTIVE 0x0F8
  40. #define CTL_FETCH_PIPE_ACTIVE 0x0FC
  41. #define CTL_MERGE_3D_FLUSH 0x100
  42. #define CTL_DSC_FLUSH 0x104
  43. #define CTL_WB_FLUSH 0x108
  44. #define CTL_CWB_FLUSH 0x10C
  45. #define CTL_INTF_FLUSH 0x110
  46. #define CTL_CDM_FLUSH 0x114
  47. #define CTL_PERIPH_FLUSH 0x128
  48. #define CTL_DSPP_0_FLUSH 0x13c
  49. #define CTL_INTF_MASTER 0x134
  50. #define CTL_UIDLE_ACTIVE 0x138
  51. #define CTL_MIXER_BORDER_OUT BIT(24)
  52. #define CTL_FLUSH_MASK_ROT BIT(27)
  53. #define CTL_FLUSH_MASK_CTL BIT(17)
  54. #define CTL_NUM_EXT 5
  55. #define CTL_SSPP_MAX_RECTS 2
  56. #define SDE_REG_RESET_TIMEOUT_US 2000
  57. #define SDE_REG_WAIT_RESET_TIMEOUT_US 100000
  58. #define UPDATE_MASK(m, idx, en) \
  59. ((m) = (en) ? ((m) | BIT((idx))) : ((m) & ~BIT((idx))))
  60. #define CTL_INVALID_BIT 0xffff
  61. #define VDC_IDX(i) ((i) + 16)
  62. #define UPDATE_ACTIVE(r, idx, en) UPDATE_MASK((r), (idx), (en))
  63. #define DNSC_BLUR_IDX(i) (i + 16)
  64. /**
  65. * List of SSPP bits in CTL_FLUSH
  66. */
  67. static const u32 sspp_tbl[SSPP_MAX] = { SDE_NONE, 0, 1, 2, 18, 11, 12, 24, 25, 13, 14};
  68. /**
  69. * List of layer mixer bits in CTL_FLUSH
  70. */
  71. static const u32 mixer_tbl[LM_MAX] = {SDE_NONE, 6, 7, 8, 9, 10, 20,
  72. SDE_NONE};
  73. /**
  74. * List of DSPP bits in CTL_FLUSH
  75. */
  76. static const u32 dspp_tbl[DSPP_MAX] = {SDE_NONE, 13, 14, 15, 21};
  77. /**
  78. * List of DSPP PA LUT bits in CTL_FLUSH
  79. */
  80. static const u32 dspp_pav_tbl[DSPP_MAX] = {SDE_NONE, 3, 4, 5, 19};
  81. /**
  82. * List of CDM LUT bits in CTL_FLUSH
  83. */
  84. static const u32 cdm_tbl[CDM_MAX] = {SDE_NONE, 26};
  85. /**
  86. * List of WB bits in CTL_FLUSH
  87. */
  88. static const u32 wb_tbl[WB_MAX] = {SDE_NONE, SDE_NONE, SDE_NONE, 16};
  89. /**
  90. * List of ROT bits in CTL_FLUSH
  91. */
  92. static const u32 rot_tbl[ROT_MAX] = {SDE_NONE, 27};
  93. /**
  94. * List of INTF bits in CTL_FLUSH
  95. */
  96. static const u32 intf_tbl[INTF_MAX] = {SDE_NONE, 31, 30, 29, 28};
  97. /**
  98. * Below definitions are for CTL supporting SDE_CTL_ACTIVE_CFG,
  99. * certain blocks have the individual flush control as well,
  100. * for such blocks flush is done by flushing individual control and
  101. * top level control.
  102. */
  103. /**
  104. * List of SSPP bits in CTL_FETCH_PIPE_ACTIVE
  105. */
  106. static const u32 fetch_tbl[SSPP_MAX] = {CTL_INVALID_BIT, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5};
  107. /**
  108. * list of WB bits in CTL_WB_FLUSH
  109. */
  110. static const u32 wb_flush_tbl[WB_MAX] = {SDE_NONE, SDE_NONE, 1, 2};
  111. /**
  112. * list of INTF bits in CTL_INTF_FLUSH
  113. */
  114. static const u32 intf_flush_tbl[INTF_MAX] = {SDE_NONE, 0, 1, 2, 3, 4, 5};
  115. /**
  116. * list of DSC bits in CTL_DSC_FLUSH
  117. */
  118. static const u32 dsc_flush_tbl[DSC_MAX] = {SDE_NONE, 0, 1, 2, 3, 4, 5};
  119. /**
  120. * list of VDC bits in CTL_DSC_FLUSH
  121. */
  122. static const u32 vdc_flush_tbl[DSC_MAX] = {SDE_NONE, 16, 17};
  123. /**
  124. * list of MERGE_3D bits in CTL_MERGE_3D_FLUSH
  125. */
  126. static const u32 merge_3d_tbl[MERGE_3D_MAX] = {SDE_NONE, 0, 1, 2};
  127. /**
  128. * list of CDM bits in CTL_CDM_FLUSH
  129. */
  130. static const u32 cdm_flush_tbl[CDM_MAX] = {SDE_NONE, 0};
  131. /**
  132. * list of CWB bits in CTL_CWB_FLUSH
  133. */
  134. static const u32 cwb_flush_tbl[CWB_MAX] = {SDE_NONE, SDE_NONE, 1, 2, 3,
  135. 4, 5};
  136. /**
  137. * list of CWB bits in CTL_CWB_FLUSH for dedicated cwb
  138. */
  139. static const u32 dcwb_flush_tbl[CWB_MAX] = {SDE_NONE, SDE_NONE, 0, 1};
  140. /**
  141. * list of DSPP sub-blk flush bits in CTL_DSPP_x_FLUSH
  142. */
  143. static const u32 dspp_sub_blk_flush_tbl[SDE_DSPP_MAX] = {
  144. [SDE_DSPP_IGC] = 2,
  145. [SDE_DSPP_PCC] = 4,
  146. [SDE_DSPP_GC] = 5,
  147. [SDE_DSPP_HSIC] = 0,
  148. [SDE_DSPP_MEMCOLOR] = 0,
  149. [SDE_DSPP_SIXZONE] = 0,
  150. [SDE_DSPP_GAMUT] = 3,
  151. [SDE_DSPP_DITHER] = 0,
  152. [SDE_DSPP_HIST] = 0,
  153. [SDE_DSPP_VLUT] = 1,
  154. [SDE_DSPP_AD] = 0,
  155. [SDE_DSPP_LTM] = 7,
  156. [SDE_DSPP_SPR] = 8,
  157. [SDE_DSPP_DEMURA] = 9,
  158. [SDE_DSPP_RC] = 10,
  159. [SDE_DSPP_SB] = 31,
  160. };
  161. /**
  162. * struct ctl_sspp_stage_reg_map: Describes bit layout for a sspp stage cfg
  163. * @ext: Index to indicate LAYER_x_EXT id for given sspp
  164. * @start: Start position of blend stage bits for given sspp
  165. * @bits: Number of bits from @start assigned for given sspp
  166. * @sec_bit_mask: Bitmask to add to LAYER_x_EXT1 for missing bit of sspp
  167. */
  168. struct ctl_sspp_stage_reg_map {
  169. u32 ext;
  170. u32 start;
  171. u32 bits;
  172. u32 sec_bit_mask;
  173. };
  174. /* list of ctl_sspp_stage_reg_map for all the sppp */
  175. static const struct ctl_sspp_stage_reg_map
  176. sspp_reg_cfg_tbl[SSPP_MAX][CTL_SSPP_MAX_RECTS] = {
  177. /* SSPP_NONE */{ {0, 0, 0, 0}, {0, 0, 0, 0} },
  178. /* SSPP_VIG0 */{ {0, 0, 3, BIT(0)}, {3, 0, 4, 0} },
  179. /* SSPP_VIG1 */{ {0, 3, 3, BIT(2)}, {3, 4, 4, 0} },
  180. /* SSPP_VIG2 */{ {0, 6, 3, BIT(4)}, {3, 8, 4, 0} },
  181. /* SSPP_VIG3 */{ {0, 26, 3, BIT(6)}, {3, 12, 4, 0} },
  182. /* SSPP_DMA0 */{ {0, 18, 3, BIT(16)}, {2, 8, 4, 0} },
  183. /* SSPP_DMA1 */{ {0, 21, 3, BIT(18)}, {2, 12, 4, 0} },
  184. /* SSPP_DMA2 */{ {2, 0, 4, 0}, {2, 16, 4, 0} },
  185. /* SSPP_DMA3 */{ {2, 4, 4, 0}, {2, 20, 4, 0} },
  186. /* SSPP_DMA4 */{ {4, 0, 4, 0}, {4, 8, 4, 0} },
  187. /* SSPP_DMA5 */{ {4, 4, 4, 0}, {4, 12, 4, 0} },
  188. };
  189. /**
  190. * Individual flush bit in CTL_FLUSH
  191. */
  192. #define WB_IDX 16
  193. #define DSC_IDX 22
  194. #define MERGE_3D_IDX 23
  195. #define CDM_IDX 26
  196. #define CWB_IDX 28
  197. #define DSPP_IDX 29
  198. #define PERIPH_IDX 30
  199. #define INTF_IDX 31
  200. /* struct ctl_hw_flush_cfg: Defines the active ctl hw flush config,
  201. * See enum ctl_hw_flush_type for types
  202. * @blk_max: Maximum hw idx
  203. * @flush_reg: Register with corresponding active ctl hw
  204. * @flush_idx: Corresponding index in ctl flush
  205. * @flush_mask_idx: Index of hw flush mask to use
  206. * @flush_tbl: Pointer to flush table
  207. */
  208. struct ctl_hw_flush_cfg {
  209. u32 blk_max;
  210. u32 flush_reg;
  211. u32 flush_idx;
  212. u32 flush_mask_idx;
  213. const u32 *flush_tbl;
  214. };
  215. static const struct ctl_hw_flush_cfg
  216. ctl_hw_flush_cfg_tbl_v1[SDE_HW_FLUSH_MAX] = {
  217. {WB_MAX, CTL_WB_FLUSH, WB_IDX, SDE_HW_FLUSH_WB,
  218. wb_flush_tbl}, /* SDE_HW_FLUSH_WB */
  219. {DSC_MAX, CTL_DSC_FLUSH, DSC_IDX, SDE_HW_FLUSH_DSC,
  220. dsc_flush_tbl}, /* SDE_HW_FLUSH_DSC */
  221. /* VDC is flushed to dsc, flush_reg = 0 so flush is done only once */
  222. {VDC_MAX, 0, DSC_IDX, SDE_HW_FLUSH_DSC,
  223. vdc_flush_tbl}, /* SDE_HW_FLUSH_VDC */
  224. {MERGE_3D_MAX, CTL_MERGE_3D_FLUSH, MERGE_3D_IDX, SDE_HW_FLUSH_MERGE_3D,
  225. merge_3d_tbl}, /* SDE_HW_FLUSH_MERGE_3D */
  226. {CDM_MAX, CTL_CDM_FLUSH, CDM_IDX, SDE_HW_FLUSH_CDM,
  227. cdm_flush_tbl}, /* SDE_HW_FLUSH_CDM */
  228. {CWB_MAX, CTL_CWB_FLUSH, CWB_IDX, SDE_HW_FLUSH_CWB,
  229. cwb_flush_tbl}, /* SDE_HW_FLUSH_CWB */
  230. {INTF_MAX, CTL_PERIPH_FLUSH, PERIPH_IDX, SDE_HW_FLUSH_PERIPH,
  231. intf_flush_tbl }, /* SDE_HW_FLUSH_PERIPH */
  232. {INTF_MAX, CTL_INTF_FLUSH, INTF_IDX, SDE_HW_FLUSH_INTF,
  233. intf_flush_tbl } /* SDE_HW_FLUSH_INTF */
  234. };
  235. static struct sde_ctl_cfg *_ctl_offset(enum sde_ctl ctl,
  236. struct sde_mdss_cfg *m,
  237. void __iomem *addr,
  238. struct sde_hw_blk_reg_map *b)
  239. {
  240. int i;
  241. for (i = 0; i < m->ctl_count; i++) {
  242. if (ctl == m->ctl[i].id) {
  243. b->base_off = addr;
  244. b->blk_off = m->ctl[i].base;
  245. b->length = m->ctl[i].len;
  246. b->hw_rev = m->hw_rev;
  247. b->log_mask = SDE_DBG_MASK_CTL;
  248. return &m->ctl[i];
  249. }
  250. }
  251. return ERR_PTR(-ENOMEM);
  252. }
  253. static int _mixer_stages(const struct sde_lm_cfg *mixer, int count,
  254. enum sde_lm lm)
  255. {
  256. int i;
  257. int stages = -EINVAL;
  258. for (i = 0; i < count; i++) {
  259. if (lm == mixer[i].id) {
  260. stages = mixer[i].sblk->maxblendstages;
  261. break;
  262. }
  263. }
  264. return stages;
  265. }
  266. static inline bool _is_dspp_flush_pending(struct sde_hw_ctl *ctx)
  267. {
  268. int i;
  269. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++) {
  270. if (ctx->flush.pending_dspp_flush_masks[i])
  271. return true;
  272. }
  273. return false;
  274. }
  275. static inline int sde_hw_ctl_trigger_start(struct sde_hw_ctl *ctx)
  276. {
  277. if (!ctx)
  278. return -EINVAL;
  279. SDE_REG_WRITE(&ctx->hw, CTL_START, 0x1);
  280. return 0;
  281. }
  282. static inline int sde_hw_ctl_get_start_state(struct sde_hw_ctl *ctx)
  283. {
  284. if (!ctx)
  285. return -EINVAL;
  286. return SDE_REG_READ(&ctx->hw, CTL_START);
  287. }
  288. static inline int sde_hw_ctl_trigger_pending(struct sde_hw_ctl *ctx)
  289. {
  290. if (!ctx)
  291. return -EINVAL;
  292. SDE_REG_WRITE(&ctx->hw, CTL_PREPARE, 0x1);
  293. return 0;
  294. }
  295. static inline int sde_hw_ctl_clear_pending_flush(struct sde_hw_ctl *ctx)
  296. {
  297. if (!ctx)
  298. return -EINVAL;
  299. memset(&ctx->flush, 0, sizeof(ctx->flush));
  300. return 0;
  301. }
  302. static inline int sde_hw_ctl_update_pending_flush(struct sde_hw_ctl *ctx,
  303. struct sde_ctl_flush_cfg *cfg)
  304. {
  305. if (!ctx || !cfg)
  306. return -EINVAL;
  307. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  308. return 0;
  309. }
  310. static int sde_hw_ctl_get_pending_flush(struct sde_hw_ctl *ctx,
  311. struct sde_ctl_flush_cfg *cfg)
  312. {
  313. if (!ctx || !cfg)
  314. return -EINVAL;
  315. memcpy(cfg, &ctx->flush, sizeof(*cfg));
  316. return 0;
  317. }
  318. static inline int sde_hw_ctl_trigger_flush(struct sde_hw_ctl *ctx)
  319. {
  320. if (!ctx)
  321. return -EINVAL;
  322. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  323. return 0;
  324. }
  325. static inline u32 sde_hw_ctl_get_flush_register(struct sde_hw_ctl *ctx)
  326. {
  327. struct sde_hw_blk_reg_map *c;
  328. u32 rot_op_mode;
  329. if (!ctx)
  330. return 0;
  331. c = &ctx->hw;
  332. rot_op_mode = SDE_REG_READ(c, CTL_ROT_TOP) & 0x3;
  333. /* rotate flush bit is undefined if offline mode, so ignore it */
  334. if (rot_op_mode == SDE_CTL_ROT_OP_MODE_OFFLINE)
  335. return SDE_REG_READ(c, CTL_FLUSH) & ~CTL_FLUSH_MASK_ROT;
  336. return SDE_REG_READ(c, CTL_FLUSH);
  337. }
  338. static inline void sde_hw_ctl_uidle_enable(struct sde_hw_ctl *ctx, bool enable)
  339. {
  340. u32 val;
  341. if (!ctx)
  342. return;
  343. val = SDE_REG_READ(&ctx->hw, CTL_UIDLE_ACTIVE);
  344. val = (val & ~BIT(0)) | (enable ? BIT(0) : 0);
  345. SDE_REG_WRITE(&ctx->hw, CTL_UIDLE_ACTIVE, val);
  346. }
  347. static inline int sde_hw_ctl_update_bitmask_sspp(struct sde_hw_ctl *ctx,
  348. enum sde_sspp sspp,
  349. bool enable)
  350. {
  351. if (!ctx)
  352. return -EINVAL;
  353. if (!(sspp > SSPP_NONE) || !(sspp < SSPP_MAX)) {
  354. SDE_ERROR("Unsupported pipe %d\n", sspp);
  355. return -EINVAL;
  356. }
  357. UPDATE_MASK(ctx->flush.pending_flush_mask, sspp_tbl[sspp], enable);
  358. return 0;
  359. }
  360. static inline int sde_hw_ctl_update_bitmask_mixer(struct sde_hw_ctl *ctx,
  361. enum sde_lm lm,
  362. bool enable)
  363. {
  364. if (!ctx)
  365. return -EINVAL;
  366. if (!(lm > SDE_NONE) || !(lm < LM_MAX)) {
  367. SDE_ERROR("Unsupported mixer %d\n", lm);
  368. return -EINVAL;
  369. }
  370. UPDATE_MASK(ctx->flush.pending_flush_mask, mixer_tbl[lm], enable);
  371. ctx->flush.pending_flush_mask |= CTL_FLUSH_MASK_CTL;
  372. return 0;
  373. }
  374. static inline int sde_hw_ctl_update_bitmask_dspp(struct sde_hw_ctl *ctx,
  375. enum sde_dspp dspp,
  376. bool enable)
  377. {
  378. if (!ctx)
  379. return -EINVAL;
  380. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  381. SDE_ERROR("Unsupported dspp %d\n", dspp);
  382. return -EINVAL;
  383. }
  384. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_tbl[dspp], enable);
  385. return 0;
  386. }
  387. static inline int sde_hw_ctl_update_bitmask_dspp_pavlut(struct sde_hw_ctl *ctx,
  388. enum sde_dspp dspp, bool enable)
  389. {
  390. if (!ctx)
  391. return -EINVAL;
  392. if (!(dspp > SDE_NONE) || !(dspp < DSPP_MAX)) {
  393. SDE_ERROR("Unsupported dspp %d\n", dspp);
  394. return -EINVAL;
  395. }
  396. UPDATE_MASK(ctx->flush.pending_flush_mask, dspp_pav_tbl[dspp], enable);
  397. return 0;
  398. }
  399. static inline int sde_hw_ctl_update_bitmask_cdm(struct sde_hw_ctl *ctx,
  400. enum sde_cdm cdm,
  401. bool enable)
  402. {
  403. if (!ctx)
  404. return -EINVAL;
  405. if (!(cdm > SDE_NONE) || !(cdm < CDM_MAX) || (cdm == CDM_1)) {
  406. SDE_ERROR("Unsupported cdm %d\n", cdm);
  407. return -EINVAL;
  408. }
  409. UPDATE_MASK(ctx->flush.pending_flush_mask, cdm_tbl[cdm], enable);
  410. return 0;
  411. }
  412. static inline int sde_hw_ctl_update_bitmask_wb(struct sde_hw_ctl *ctx,
  413. enum sde_wb wb, bool enable)
  414. {
  415. if (!ctx)
  416. return -EINVAL;
  417. if (!(wb > SDE_NONE) || !(wb < WB_MAX) ||
  418. (wb == WB_0) || (wb == WB_1)) {
  419. SDE_ERROR("Unsupported wb %d\n", wb);
  420. return -EINVAL;
  421. }
  422. UPDATE_MASK(ctx->flush.pending_flush_mask, wb_tbl[wb], enable);
  423. return 0;
  424. }
  425. static inline int sde_hw_ctl_update_bitmask_intf(struct sde_hw_ctl *ctx,
  426. enum sde_intf intf, bool enable)
  427. {
  428. if (!ctx)
  429. return -EINVAL;
  430. if (!(intf > SDE_NONE) || !(intf < INTF_MAX) || (intf > INTF_4)) {
  431. SDE_ERROR("Unsupported intf %d\n", intf);
  432. return -EINVAL;
  433. }
  434. UPDATE_MASK(ctx->flush.pending_flush_mask, intf_tbl[intf], enable);
  435. return 0;
  436. }
  437. static inline int sde_hw_ctl_update_bitmask(struct sde_hw_ctl *ctx,
  438. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  439. {
  440. int ret = 0;
  441. if (!ctx)
  442. return -EINVAL;
  443. switch (type) {
  444. case SDE_HW_FLUSH_CDM:
  445. ret = sde_hw_ctl_update_bitmask_cdm(ctx, blk_idx, enable);
  446. break;
  447. case SDE_HW_FLUSH_WB:
  448. ret = sde_hw_ctl_update_bitmask_wb(ctx, blk_idx, enable);
  449. break;
  450. case SDE_HW_FLUSH_INTF:
  451. ret = sde_hw_ctl_update_bitmask_intf(ctx, blk_idx, enable);
  452. break;
  453. default:
  454. break;
  455. }
  456. return ret;
  457. }
  458. static inline int sde_hw_ctl_update_bitmask_v1(struct sde_hw_ctl *ctx,
  459. enum ctl_hw_flush_type type, u32 blk_idx, bool enable)
  460. {
  461. const struct ctl_hw_flush_cfg *cfg;
  462. if (!ctx || !(type < SDE_HW_FLUSH_MAX))
  463. return -EINVAL;
  464. cfg = &ctl_hw_flush_cfg_tbl_v1[type];
  465. if ((blk_idx <= SDE_NONE) || (blk_idx >= cfg->blk_max)) {
  466. SDE_ERROR("Unsupported hw idx, type:%d, blk_idx:%d, blk_max:%d",
  467. type, blk_idx, cfg->blk_max);
  468. return -EINVAL;
  469. }
  470. UPDATE_MASK(ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx],
  471. cfg->flush_tbl[blk_idx], enable);
  472. if (ctx->flush.pending_hw_flush_mask[cfg->flush_mask_idx])
  473. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 1);
  474. else
  475. UPDATE_MASK(ctx->flush.pending_flush_mask, cfg->flush_idx, 0);
  476. return 0;
  477. }
  478. static inline void sde_hw_ctl_update_dnsc_blur_bitmask(struct sde_hw_ctl *ctx,
  479. u32 blk_idx, bool enable)
  480. {
  481. if (enable)
  482. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] |=
  483. BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  484. else
  485. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] &=
  486. ~BIT(DNSC_BLUR_IDX(blk_idx) - DNSC_BLUR_0);
  487. }
  488. static inline int sde_hw_ctl_update_pending_flush_v1(
  489. struct sde_hw_ctl *ctx,
  490. struct sde_ctl_flush_cfg *cfg)
  491. {
  492. int i = 0;
  493. if (!ctx || !cfg)
  494. return -EINVAL;
  495. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  496. ctx->flush.pending_hw_flush_mask[i] |=
  497. cfg->pending_hw_flush_mask[i];
  498. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++)
  499. ctx->flush.pending_dspp_flush_masks[i] |=
  500. cfg->pending_dspp_flush_masks[i];
  501. ctx->flush.pending_flush_mask |= cfg->pending_flush_mask;
  502. return 0;
  503. }
  504. static inline int sde_hw_ctl_update_bitmask_dspp_subblk(struct sde_hw_ctl *ctx,
  505. enum sde_dspp dspp, u32 sub_blk, bool enable)
  506. {
  507. if (!ctx || dspp < DSPP_0 || dspp >= DSPP_MAX ||
  508. sub_blk < SDE_DSPP_IGC || sub_blk >= SDE_DSPP_MAX) {
  509. SDE_ERROR("invalid args - ctx %s, dspp %d sub_block %d\n",
  510. ctx ? "valid" : "invalid", dspp, sub_blk);
  511. return -EINVAL;
  512. }
  513. UPDATE_MASK(ctx->flush.pending_dspp_flush_masks[dspp - DSPP_0],
  514. dspp_sub_blk_flush_tbl[sub_blk], enable);
  515. if (_is_dspp_flush_pending(ctx))
  516. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 1);
  517. else
  518. UPDATE_MASK(ctx->flush.pending_flush_mask, DSPP_IDX, 0);
  519. return 0;
  520. }
  521. static void sde_hw_ctl_set_fetch_pipe_active(struct sde_hw_ctl *ctx,
  522. unsigned long *fetch_active)
  523. {
  524. int i;
  525. u32 val = 0;
  526. if (fetch_active) {
  527. for (i = 0; i < SSPP_MAX; i++) {
  528. if (test_bit(i, fetch_active) &&
  529. fetch_tbl[i] != CTL_INVALID_BIT)
  530. val |= BIT(fetch_tbl[i]);
  531. }
  532. }
  533. SDE_REG_WRITE(&ctx->hw, CTL_FETCH_PIPE_ACTIVE, val);
  534. }
  535. static u32 sde_hw_ctl_get_active_fetch_pipes(struct sde_hw_ctl *ctx)
  536. {
  537. int i;
  538. u32 fetch_info, fetch_active = 0;
  539. if (!ctx) {
  540. DRM_ERROR("invalid args - ctx invalid\n");
  541. return 0;
  542. }
  543. fetch_info = SDE_REG_READ(&ctx->hw, CTL_FETCH_PIPE_ACTIVE);
  544. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  545. if (fetch_tbl[i] != CTL_INVALID_BIT &&
  546. fetch_info & BIT(fetch_tbl[i])) {
  547. fetch_active |= BIT(i);
  548. }
  549. }
  550. return fetch_active;
  551. }
  552. static inline void _sde_hw_ctl_write_dspp_flushes(struct sde_hw_ctl *ctx) {
  553. int i;
  554. bool has_dspp_flushes = ctx->caps->features &
  555. BIT(SDE_CTL_UNIFIED_DSPP_FLUSH);
  556. if (!has_dspp_flushes)
  557. return;
  558. for (i = 0; i < CTL_MAX_DSPP_COUNT; i++) {
  559. u32 pending = ctx->flush.pending_dspp_flush_masks[i];
  560. if (pending)
  561. SDE_REG_WRITE(&ctx->hw, CTL_DSPP_0_FLUSH + (i * 4),
  562. pending);
  563. }
  564. }
  565. static inline int sde_hw_ctl_trigger_flush_v1(struct sde_hw_ctl *ctx)
  566. {
  567. int i = 0;
  568. const struct ctl_hw_flush_cfg *cfg = &ctl_hw_flush_cfg_tbl_v1[0];
  569. if (!ctx)
  570. return -EINVAL;
  571. if (ctx->flush.pending_flush_mask & BIT(DSPP_IDX))
  572. _sde_hw_ctl_write_dspp_flushes(ctx);
  573. for (i = 0; i < SDE_HW_FLUSH_MAX; i++)
  574. if (cfg[i].flush_reg &&
  575. ctx->flush.pending_flush_mask &
  576. BIT(cfg[i].flush_idx))
  577. SDE_REG_WRITE(&ctx->hw,
  578. cfg[i].flush_reg,
  579. ctx->flush.pending_hw_flush_mask[i]);
  580. SDE_REG_WRITE(&ctx->hw, CTL_FLUSH, ctx->flush.pending_flush_mask);
  581. return 0;
  582. }
  583. static inline u32 sde_hw_ctl_get_intf_v1(struct sde_hw_ctl *ctx)
  584. {
  585. struct sde_hw_blk_reg_map *c;
  586. u32 intf_active;
  587. if (!ctx) {
  588. pr_err("Invalid input argument\n");
  589. return 0;
  590. }
  591. c = &ctx->hw;
  592. intf_active = SDE_REG_READ(c, CTL_INTF_ACTIVE);
  593. return intf_active;
  594. }
  595. static inline u32 sde_hw_ctl_get_intf(struct sde_hw_ctl *ctx)
  596. {
  597. struct sde_hw_blk_reg_map *c;
  598. u32 ctl_top;
  599. u32 intf_active = 0;
  600. if (!ctx) {
  601. pr_err("Invalid input argument\n");
  602. return 0;
  603. }
  604. c = &ctx->hw;
  605. ctl_top = SDE_REG_READ(c, CTL_TOP);
  606. intf_active = (ctl_top > 0) ?
  607. BIT(ctl_top - 1) : 0;
  608. return intf_active;
  609. }
  610. static u32 sde_hw_ctl_poll_reset_status(struct sde_hw_ctl *ctx, u32 timeout_us)
  611. {
  612. struct sde_hw_blk_reg_map *c;
  613. ktime_t timeout;
  614. u32 status;
  615. if (!ctx)
  616. return 0;
  617. c = &ctx->hw;
  618. timeout = ktime_add_us(ktime_get(), timeout_us);
  619. /*
  620. * it takes around 30us to have mdp finish resetting its ctl path
  621. * poll every 50us so that reset should be completed at 1st poll
  622. */
  623. do {
  624. status = SDE_REG_READ(c, CTL_SW_RESET);
  625. status &= 0x1;
  626. if (status)
  627. usleep_range(20, 50);
  628. } while (status && ktime_compare_safe(ktime_get(), timeout) < 0);
  629. return status;
  630. }
  631. static u32 sde_hw_ctl_get_reset_status(struct sde_hw_ctl *ctx)
  632. {
  633. if (!ctx)
  634. return 0;
  635. return (u32)SDE_REG_READ(&ctx->hw, CTL_SW_RESET);
  636. }
  637. static u32 sde_hw_ctl_get_scheduler_status(struct sde_hw_ctl *ctx)
  638. {
  639. if (!ctx)
  640. return INVALID_CTL_STATUS;
  641. return (u32)SDE_REG_READ(&ctx->hw, CTL_STATUS);
  642. }
  643. static int sde_hw_ctl_reset_control(struct sde_hw_ctl *ctx)
  644. {
  645. struct sde_hw_blk_reg_map *c;
  646. if (!ctx)
  647. return 0;
  648. c = &ctx->hw;
  649. pr_debug("issuing hw ctl reset for ctl:%d\n", ctx->idx);
  650. SDE_REG_WRITE(c, CTL_SW_RESET, 0x1);
  651. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_RESET_TIMEOUT_US))
  652. return -EINVAL;
  653. return 0;
  654. }
  655. static void sde_hw_ctl_hard_reset(struct sde_hw_ctl *ctx, bool enable)
  656. {
  657. struct sde_hw_blk_reg_map *c;
  658. if (!ctx)
  659. return;
  660. c = &ctx->hw;
  661. pr_debug("hw ctl hard reset for ctl:%d, %d\n",
  662. ctx->idx - CTL_0, enable);
  663. SDE_REG_WRITE(c, CTL_SW_RESET_OVERRIDE, enable);
  664. }
  665. static int sde_hw_ctl_wait_reset_status(struct sde_hw_ctl *ctx)
  666. {
  667. struct sde_hw_blk_reg_map *c;
  668. u32 status;
  669. if (!ctx)
  670. return 0;
  671. c = &ctx->hw;
  672. status = SDE_REG_READ(c, CTL_SW_RESET);
  673. status &= 0x01;
  674. if (!status)
  675. return 0;
  676. pr_debug("hw ctl reset is set for ctl:%d\n", ctx->idx);
  677. if (sde_hw_ctl_poll_reset_status(ctx, SDE_REG_WAIT_RESET_TIMEOUT_US)) {
  678. pr_err("hw recovery is not complete for ctl:%d\n", ctx->idx);
  679. return -EINVAL;
  680. }
  681. return 0;
  682. }
  683. static void sde_hw_ctl_clear_all_blendstages(struct sde_hw_ctl *ctx)
  684. {
  685. struct sde_hw_blk_reg_map *c;
  686. int i;
  687. if (!ctx)
  688. return;
  689. c = &ctx->hw;
  690. for (i = 0; i < ctx->mixer_count; i++) {
  691. int mixer_id = ctx->mixer_hw_caps[i].id;
  692. SDE_REG_WRITE(c, CTL_LAYER(mixer_id), 0);
  693. SDE_REG_WRITE(c, CTL_LAYER_EXT(mixer_id), 0);
  694. SDE_REG_WRITE(c, CTL_LAYER_EXT2(mixer_id), 0);
  695. SDE_REG_WRITE(c, CTL_LAYER_EXT3(mixer_id), 0);
  696. SDE_REG_WRITE(c, CTL_LAYER_EXT4(mixer_id), 0);
  697. }
  698. SDE_REG_WRITE(c, CTL_FETCH_PIPE_ACTIVE, 0);
  699. }
  700. static void _sde_hw_ctl_get_mixer_cfg(struct sde_hw_ctl *ctx,
  701. struct sde_hw_stage_cfg *stage_cfg, int stages, u32 *cfg)
  702. {
  703. int i, j, pipes_per_stage;
  704. const struct ctl_sspp_stage_reg_map *reg_map;
  705. if (test_bit(SDE_MIXER_SOURCESPLIT, &ctx->mixer_hw_caps->features))
  706. pipes_per_stage = PIPES_PER_STAGE;
  707. else
  708. pipes_per_stage = 1;
  709. for (i = 0; i <= stages; i++) {
  710. /* overflow to ext register if 'i + 1 > 7' */
  711. for (j = 0 ; j < pipes_per_stage; j++) {
  712. enum sde_sspp pipe = stage_cfg->stage[i][j];
  713. enum sde_sspp_multirect_index rect_index =
  714. stage_cfg->multirect_index[i][j];
  715. u32 mixer_value;
  716. if (!pipe || pipe >= SSPP_MAX || rect_index >= SDE_SSPP_RECT_MAX)
  717. continue;
  718. /* Handle multi rect enums */
  719. if (rect_index == SDE_SSPP_RECT_SOLO)
  720. rect_index = SDE_SSPP_RECT_0;
  721. reg_map = &sspp_reg_cfg_tbl[pipe][rect_index-1];
  722. if (!reg_map->bits)
  723. continue;
  724. mixer_value = (i + 1) & (BIT(reg_map->bits) - 1);
  725. cfg[reg_map->ext] |= (mixer_value << reg_map->start);
  726. if ((i + 1) > mixer_value)
  727. cfg[1] |= reg_map->sec_bit_mask;
  728. }
  729. }
  730. }
  731. static void sde_hw_ctl_setup_blendstage(struct sde_hw_ctl *ctx,
  732. enum sde_lm lm, struct sde_hw_stage_cfg *stage_cfg,
  733. bool disable_border)
  734. {
  735. struct sde_hw_blk_reg_map *c;
  736. u32 cfg[CTL_NUM_EXT] = { 0 };
  737. int stages;
  738. bool null_commit;
  739. if (!ctx)
  740. return;
  741. stages = _mixer_stages(ctx->mixer_hw_caps, ctx->mixer_count, lm);
  742. if (stages < 0)
  743. return;
  744. c = &ctx->hw;
  745. if (stage_cfg)
  746. _sde_hw_ctl_get_mixer_cfg(ctx, stage_cfg, stages, cfg);
  747. null_commit = (!cfg[0] && !cfg[1] && !cfg[2] && !cfg[3] && !cfg[4]);
  748. if (!disable_border && (null_commit || (stage_cfg && !stage_cfg->stage[0][0])))
  749. cfg[0] |= CTL_MIXER_BORDER_OUT;
  750. SDE_REG_WRITE(c, CTL_LAYER(lm), cfg[0]);
  751. SDE_REG_WRITE(c, CTL_LAYER_EXT(lm), cfg[1]);
  752. SDE_REG_WRITE(c, CTL_LAYER_EXT2(lm), cfg[2]);
  753. SDE_REG_WRITE(c, CTL_LAYER_EXT3(lm), cfg[3]);
  754. SDE_REG_WRITE(c, CTL_LAYER_EXT4(lm), cfg[4]);
  755. }
  756. static u32 sde_hw_ctl_get_staged_sspp(struct sde_hw_ctl *ctx, enum sde_lm lm,
  757. struct sde_sspp_index_info *info)
  758. {
  759. int i, j;
  760. u32 count = 0;
  761. u32 mask = 0;
  762. bool staged;
  763. u32 mixercfg[CTL_NUM_EXT];
  764. struct sde_hw_blk_reg_map *c;
  765. const struct ctl_sspp_stage_reg_map *sspp_cfg;
  766. if (!ctx || (lm >= LM_DCWB_DUMMY_0) || !info)
  767. return 0;
  768. c = &ctx->hw;
  769. mixercfg[0] = SDE_REG_READ(c, CTL_LAYER(lm));
  770. mixercfg[1] = SDE_REG_READ(c, CTL_LAYER_EXT(lm));
  771. mixercfg[2] = SDE_REG_READ(c, CTL_LAYER_EXT2(lm));
  772. mixercfg[3] = SDE_REG_READ(c, CTL_LAYER_EXT3(lm));
  773. mixercfg[4] = SDE_REG_READ(c, CTL_LAYER_EXT4(lm));
  774. if (mixercfg[0] & CTL_MIXER_BORDER_OUT)
  775. info->bordercolor = true;
  776. for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
  777. for (j = 0; j < CTL_SSPP_MAX_RECTS; j++) {
  778. sspp_cfg = &sspp_reg_cfg_tbl[i][j];
  779. if (!sspp_cfg->bits || sspp_cfg->ext >= CTL_NUM_EXT)
  780. continue;
  781. mask = ((0x1 << sspp_cfg->bits) - 1) << sspp_cfg->start;
  782. staged = mixercfg[sspp_cfg->ext] & mask;
  783. if (!staged)
  784. staged = mixercfg[1] & sspp_cfg->sec_bit_mask;
  785. if (staged) {
  786. if (j)
  787. set_bit(i, info->virt_pipes);
  788. else
  789. set_bit(i, info->pipes);
  790. count++;
  791. }
  792. }
  793. }
  794. return count;
  795. }
  796. static int sde_hw_ctl_intf_cfg_v1(struct sde_hw_ctl *ctx,
  797. struct sde_hw_intf_cfg_v1 *cfg)
  798. {
  799. struct sde_hw_blk_reg_map *c;
  800. u32 intf_active = 0;
  801. u32 wb_active = 0;
  802. u32 merge_3d_active = 0;
  803. u32 cwb_active = 0;
  804. u32 mode_sel = 0xf0000000;
  805. u32 cdm_active = 0;
  806. u32 intf_master = 0;
  807. u32 i;
  808. if (!ctx)
  809. return -EINVAL;
  810. c = &ctx->hw;
  811. for (i = 0; i < cfg->intf_count; i++) {
  812. if (cfg->intf[i])
  813. intf_active |= BIT(cfg->intf[i] - INTF_0);
  814. }
  815. if (cfg->intf_count > 1)
  816. intf_master = BIT(cfg->intf_master - INTF_0);
  817. else if (cfg->intf_count == 1)
  818. intf_master = BIT(cfg->intf[0] - INTF_0);
  819. for (i = 0; i < cfg->wb_count; i++) {
  820. if (cfg->wb[i])
  821. wb_active |= BIT(cfg->wb[i] - WB_0);
  822. }
  823. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  824. if (cfg->dnsc_blur[i])
  825. wb_active |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  826. }
  827. for (i = 0; i < cfg->merge_3d_count; i++) {
  828. if (cfg->merge_3d[i])
  829. merge_3d_active |= BIT(cfg->merge_3d[i] - MERGE_3D_0);
  830. }
  831. for (i = 0; i < cfg->cwb_count; i++) {
  832. if (cfg->cwb[i])
  833. cwb_active |= BIT(cfg->cwb[i] - CWB_0);
  834. }
  835. for (i = 0; i < cfg->cdm_count; i++) {
  836. if (cfg->cdm[i])
  837. cdm_active |= BIT(cfg->cdm[i] - CDM_0);
  838. }
  839. if (cfg->intf_mode_sel == SDE_CTL_MODE_SEL_CMD)
  840. mode_sel |= BIT(17);
  841. SDE_REG_WRITE(c, CTL_TOP, mode_sel);
  842. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  843. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  844. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  845. SDE_REG_WRITE(c, CTL_CDM_ACTIVE, cdm_active);
  846. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  847. SDE_REG_WRITE(c, CTL_INTF_MASTER, intf_master);
  848. return 0;
  849. }
  850. static int sde_hw_ctl_reset_post_disable(struct sde_hw_ctl *ctx,
  851. struct sde_hw_intf_cfg_v1 *cfg, u32 merge_3d_idx)
  852. {
  853. struct sde_hw_blk_reg_map *c;
  854. u32 intf_active = 0, wb_active = 0, merge_3d_active = 0;
  855. u32 intf_flush = 0, wb_flush = 0;
  856. u32 i;
  857. if (!ctx || !cfg) {
  858. SDE_ERROR("invalid hw_ctl or hw_intf blk\n");
  859. return -EINVAL;
  860. }
  861. c = &ctx->hw;
  862. for (i = 0; i < cfg->intf_count; i++) {
  863. if (cfg->intf[i]) {
  864. intf_active &= ~BIT(cfg->intf[i] - INTF_0);
  865. intf_flush |= BIT(cfg->intf[i] - INTF_0);
  866. }
  867. }
  868. for (i = 0; i < cfg->wb_count; i++) {
  869. if (cfg->wb[i]) {
  870. wb_active &= ~BIT(cfg->wb[i] - WB_0);
  871. wb_flush |= BIT(cfg->wb[i] - WB_0);
  872. }
  873. }
  874. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  875. if (cfg->dnsc_blur[i]) {
  876. wb_active &= ~BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  877. wb_flush |= BIT(DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0));
  878. }
  879. }
  880. if (merge_3d_idx) {
  881. /* disable and flush merge3d_blk */
  882. merge_3d_active &= ~BIT(merge_3d_idx - MERGE_3D_0);
  883. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_MERGE_3D] =
  884. BIT(merge_3d_idx - MERGE_3D_0);
  885. UPDATE_MASK(ctx->flush.pending_flush_mask, MERGE_3D_IDX, 1);
  886. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  887. }
  888. sde_hw_ctl_clear_all_blendstages(ctx);
  889. if (cfg->intf_count) {
  890. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_INTF] =
  891. intf_flush;
  892. UPDATE_MASK(ctx->flush.pending_flush_mask, INTF_IDX, 1);
  893. SDE_REG_WRITE(c, CTL_INTF_ACTIVE, intf_active);
  894. }
  895. if (cfg->wb_count) {
  896. ctx->flush.pending_hw_flush_mask[SDE_HW_FLUSH_WB] = wb_flush;
  897. UPDATE_MASK(ctx->flush.pending_flush_mask, WB_IDX, 1);
  898. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  899. }
  900. return 0;
  901. }
  902. static int sde_hw_ctl_update_intf_cfg(struct sde_hw_ctl *ctx,
  903. struct sde_hw_intf_cfg_v1 *cfg, bool enable)
  904. {
  905. int i;
  906. u32 cwb_active = 0;
  907. u32 merge_3d_active = 0;
  908. u32 wb_active = 0;
  909. u32 dsc_active = 0;
  910. u32 vdc_active = 0;
  911. struct sde_hw_blk_reg_map *c;
  912. if (!ctx)
  913. return -EINVAL;
  914. c = &ctx->hw;
  915. if (cfg->cwb_count) {
  916. cwb_active = SDE_REG_READ(c, CTL_CWB_ACTIVE);
  917. for (i = 0; i < cfg->cwb_count; i++) {
  918. if (cfg->cwb[i])
  919. UPDATE_ACTIVE(cwb_active,
  920. (cfg->cwb[i] - CWB_0),
  921. enable);
  922. }
  923. for (i = 0; i < cfg->wb_count; i++) {
  924. if (cfg->wb[i] && enable)
  925. wb_active |= BIT(cfg->wb[i] - WB_0);
  926. }
  927. SDE_REG_WRITE(c, CTL_CWB_ACTIVE, cwb_active);
  928. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  929. }
  930. if (cfg->dnsc_blur_count) {
  931. wb_active = SDE_REG_READ(c, CTL_WB_ACTIVE);
  932. for (i = 0; i < cfg->dnsc_blur_count; i++) {
  933. if (cfg->dnsc_blur[i])
  934. UPDATE_ACTIVE(wb_active,
  935. DNSC_BLUR_IDX(cfg->dnsc_blur[i] - DNSC_BLUR_0),
  936. enable);
  937. }
  938. SDE_REG_WRITE(c, CTL_WB_ACTIVE, wb_active);
  939. }
  940. if (cfg->merge_3d_count) {
  941. merge_3d_active = SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE);
  942. for (i = 0; i < cfg->merge_3d_count; i++) {
  943. if (cfg->merge_3d[i])
  944. UPDATE_ACTIVE(merge_3d_active,
  945. (cfg->merge_3d[i] - MERGE_3D_0),
  946. enable);
  947. }
  948. SDE_REG_WRITE(c, CTL_MERGE_3D_ACTIVE, merge_3d_active);
  949. }
  950. if (cfg->dsc_count) {
  951. dsc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  952. for (i = 0; i < cfg->dsc_count; i++) {
  953. if (cfg->dsc[i])
  954. UPDATE_ACTIVE(dsc_active,
  955. (cfg->dsc[i] - DSC_0), enable);
  956. }
  957. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, dsc_active);
  958. }
  959. if (cfg->vdc_count) {
  960. vdc_active = SDE_REG_READ(c, CTL_DSC_ACTIVE);
  961. for (i = 0; i < cfg->vdc_count; i++) {
  962. if (cfg->vdc[i])
  963. UPDATE_ACTIVE(vdc_active,
  964. VDC_IDX(cfg->vdc[i] - VDC_0), enable);
  965. }
  966. SDE_REG_WRITE(c, CTL_DSC_ACTIVE, vdc_active);
  967. }
  968. return 0;
  969. }
  970. static int sde_hw_ctl_intf_cfg(struct sde_hw_ctl *ctx,
  971. struct sde_hw_intf_cfg *cfg)
  972. {
  973. struct sde_hw_blk_reg_map *c;
  974. u32 intf_cfg = 0;
  975. if (!ctx)
  976. return -EINVAL;
  977. c = &ctx->hw;
  978. intf_cfg |= (cfg->intf & 0xF) << 4;
  979. if (cfg->wb)
  980. intf_cfg |= (cfg->wb & 0x3) + 2;
  981. if (cfg->mode_3d) {
  982. intf_cfg |= BIT(19);
  983. intf_cfg |= (cfg->mode_3d - 0x1) << 20;
  984. }
  985. switch (cfg->intf_mode_sel) {
  986. case SDE_CTL_MODE_SEL_VID:
  987. intf_cfg &= ~BIT(17);
  988. intf_cfg &= ~(0x3 << 15);
  989. break;
  990. case SDE_CTL_MODE_SEL_CMD:
  991. intf_cfg |= BIT(17);
  992. intf_cfg |= ((cfg->stream_sel & 0x3) << 15);
  993. break;
  994. default:
  995. pr_err("unknown interface type %d\n", cfg->intf_mode_sel);
  996. return -EINVAL;
  997. }
  998. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  999. return 0;
  1000. }
  1001. static void sde_hw_ctl_update_wb_cfg(struct sde_hw_ctl *ctx,
  1002. struct sde_hw_intf_cfg *cfg, bool enable)
  1003. {
  1004. struct sde_hw_blk_reg_map *c = &ctx->hw;
  1005. u32 intf_cfg = 0;
  1006. if (!cfg->wb)
  1007. return;
  1008. intf_cfg = SDE_REG_READ(c, CTL_TOP);
  1009. if (enable)
  1010. intf_cfg |= (cfg->wb & 0x3) + 2;
  1011. else
  1012. intf_cfg &= ~((cfg->wb & 0x3) + 2);
  1013. SDE_REG_WRITE(c, CTL_TOP, intf_cfg);
  1014. }
  1015. static inline u32 sde_hw_ctl_read_ctl_layers(struct sde_hw_ctl *ctx, int index)
  1016. {
  1017. struct sde_hw_blk_reg_map *c;
  1018. u32 ctl_top;
  1019. if (!ctx) {
  1020. pr_err("Invalid input argument\n");
  1021. return 0;
  1022. }
  1023. c = &ctx->hw;
  1024. ctl_top = SDE_REG_READ(c, CTL_LAYER(index));
  1025. pr_debug("Ctl_layer value = 0x%x\n", ctl_top);
  1026. return ctl_top;
  1027. }
  1028. static inline bool sde_hw_ctl_read_active_status(struct sde_hw_ctl *ctx,
  1029. enum sde_hw_blk_type blk, int index)
  1030. {
  1031. struct sde_hw_blk_reg_map *c;
  1032. if (!ctx) {
  1033. pr_err("Invalid input argument\n");
  1034. return 0;
  1035. }
  1036. c = &ctx->hw;
  1037. switch (blk) {
  1038. case SDE_HW_BLK_MERGE_3D:
  1039. return (SDE_REG_READ(c, CTL_MERGE_3D_ACTIVE) &
  1040. BIT(index - MERGE_3D_0)) ? true : false;
  1041. case SDE_HW_BLK_DSC:
  1042. return (SDE_REG_READ(c, CTL_DSC_ACTIVE) &
  1043. BIT(index - DSC_0)) ? true : false;
  1044. case SDE_HW_BLK_WB:
  1045. return (SDE_REG_READ(c, CTL_WB_ACTIVE) &
  1046. BIT(index - WB_0)) ? true : false;
  1047. case SDE_HW_BLK_CDM:
  1048. return (SDE_REG_READ(c, CTL_CDM_ACTIVE) &
  1049. BIT(index - CDM_0)) ? true : false;
  1050. case SDE_HW_BLK_INTF:
  1051. return (SDE_REG_READ(c, CTL_INTF_ACTIVE) &
  1052. BIT(index - INTF_0)) ? true : false;
  1053. default:
  1054. pr_err("unsupported blk %d\n", blk);
  1055. return false;
  1056. };
  1057. return false;
  1058. }
  1059. static int sde_hw_reg_dma_flush(struct sde_hw_ctl *ctx, bool blocking)
  1060. {
  1061. struct sde_hw_reg_dma_ops *ops = sde_reg_dma_get_ops();
  1062. if (!ctx)
  1063. return -EINVAL;
  1064. if (ops && ops->last_command)
  1065. return ops->last_command(ctx, DMA_CTL_QUEUE0,
  1066. (blocking ? REG_DMA_WAIT4_COMP : REG_DMA_NOWAIT));
  1067. return 0;
  1068. }
  1069. static void _setup_ctl_ops(struct sde_hw_ctl_ops *ops,
  1070. unsigned long cap)
  1071. {
  1072. if (cap & BIT(SDE_CTL_ACTIVE_CFG)) {
  1073. ops->update_pending_flush =
  1074. sde_hw_ctl_update_pending_flush_v1;
  1075. ops->trigger_flush = sde_hw_ctl_trigger_flush_v1;
  1076. ops->setup_intf_cfg_v1 = sde_hw_ctl_intf_cfg_v1;
  1077. ops->update_intf_cfg = sde_hw_ctl_update_intf_cfg;
  1078. ops->update_bitmask = sde_hw_ctl_update_bitmask_v1;
  1079. ops->update_dnsc_blur_bitmask = sde_hw_ctl_update_dnsc_blur_bitmask;
  1080. ops->get_ctl_intf = sde_hw_ctl_get_intf_v1;
  1081. ops->reset_post_disable = sde_hw_ctl_reset_post_disable;
  1082. ops->get_scheduler_status = sde_hw_ctl_get_scheduler_status;
  1083. ops->read_active_status = sde_hw_ctl_read_active_status;
  1084. ops->set_active_pipes = sde_hw_ctl_set_fetch_pipe_active;
  1085. ops->get_active_pipes = sde_hw_ctl_get_active_fetch_pipes;
  1086. } else {
  1087. ops->update_pending_flush = sde_hw_ctl_update_pending_flush;
  1088. ops->trigger_flush = sde_hw_ctl_trigger_flush;
  1089. ops->setup_intf_cfg = sde_hw_ctl_intf_cfg;
  1090. ops->update_bitmask = sde_hw_ctl_update_bitmask;
  1091. ops->get_ctl_intf = sde_hw_ctl_get_intf;
  1092. }
  1093. ops->clear_pending_flush = sde_hw_ctl_clear_pending_flush;
  1094. ops->get_pending_flush = sde_hw_ctl_get_pending_flush;
  1095. ops->get_flush_register = sde_hw_ctl_get_flush_register;
  1096. ops->trigger_start = sde_hw_ctl_trigger_start;
  1097. ops->trigger_pending = sde_hw_ctl_trigger_pending;
  1098. ops->read_ctl_layers = sde_hw_ctl_read_ctl_layers;
  1099. ops->update_wb_cfg = sde_hw_ctl_update_wb_cfg;
  1100. ops->reset = sde_hw_ctl_reset_control;
  1101. ops->get_reset = sde_hw_ctl_get_reset_status;
  1102. ops->hard_reset = sde_hw_ctl_hard_reset;
  1103. ops->wait_reset_status = sde_hw_ctl_wait_reset_status;
  1104. ops->clear_all_blendstages = sde_hw_ctl_clear_all_blendstages;
  1105. ops->setup_blendstage = sde_hw_ctl_setup_blendstage;
  1106. ops->get_staged_sspp = sde_hw_ctl_get_staged_sspp;
  1107. ops->update_bitmask_sspp = sde_hw_ctl_update_bitmask_sspp;
  1108. ops->update_bitmask_mixer = sde_hw_ctl_update_bitmask_mixer;
  1109. ops->reg_dma_flush = sde_hw_reg_dma_flush;
  1110. ops->get_start_state = sde_hw_ctl_get_start_state;
  1111. if (cap & BIT(SDE_CTL_UNIFIED_DSPP_FLUSH)) {
  1112. ops->update_bitmask_dspp_subblk =
  1113. sde_hw_ctl_update_bitmask_dspp_subblk;
  1114. } else {
  1115. ops->update_bitmask_dspp = sde_hw_ctl_update_bitmask_dspp;
  1116. ops->update_bitmask_dspp_pavlut =
  1117. sde_hw_ctl_update_bitmask_dspp_pavlut;
  1118. }
  1119. if (cap & BIT(SDE_CTL_UIDLE))
  1120. ops->uidle_enable = sde_hw_ctl_uidle_enable;
  1121. };
  1122. struct sde_hw_blk_reg_map *sde_hw_ctl_init(enum sde_ctl idx,
  1123. void __iomem *addr,
  1124. struct sde_mdss_cfg *m)
  1125. {
  1126. struct sde_hw_ctl *c;
  1127. struct sde_ctl_cfg *cfg;
  1128. c = kzalloc(sizeof(*c), GFP_KERNEL);
  1129. if (!c)
  1130. return ERR_PTR(-ENOMEM);
  1131. cfg = _ctl_offset(idx, m, addr, &c->hw);
  1132. if (IS_ERR_OR_NULL(cfg)) {
  1133. kfree(c);
  1134. pr_err("failed to create sde_hw_ctl %d\n", idx);
  1135. return ERR_PTR(-EINVAL);
  1136. }
  1137. c->caps = cfg;
  1138. _setup_ctl_ops(&c->ops, c->caps->features);
  1139. c->idx = idx;
  1140. c->mixer_count = m->mixer_count;
  1141. c->mixer_hw_caps = m->mixer;
  1142. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  1143. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  1144. return &c->hw;
  1145. }
  1146. void sde_hw_ctl_destroy(struct sde_hw_blk_reg_map *hw)
  1147. {
  1148. if (hw)
  1149. kfree(to_sde_hw_ctl(hw));
  1150. }