sde_hw_ctl.c 36 KB

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