sde_hw_ctl.c 32 KB

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