sde_hw_ctl.c 36 KB

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