sde_hw_ctl.c 33 KB

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