sde_hw_ctl.c 33 KB

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