sde_hw_ctl.c 32 KB

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