sde_hw_ctl.c 34 KB

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