sde_hw_ctl.c 35 KB

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