sde_hw_ctl.c 34 KB

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