sde_hw_ctl.c 34 KB

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