sde_hw_ctl.c 34 KB

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