gpc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright 2019-2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. #include <common/debug.h>
  10. #include <drivers/delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <lib/psci/psci.h>
  13. #include <lib/smccc.h>
  14. #include <services/std_svc.h>
  15. #include <gpc.h>
  16. #include <imx_sip_svc.h>
  17. #include <platform_def.h>
  18. #define CCGR(x) (0x4000 + (x) * 0x10)
  19. #define MIPI_PWR_REQ BIT(0)
  20. #define OTG1_PWR_REQ BIT(2)
  21. #define HSIOMIX_PWR_REQ BIT(4)
  22. #define GPUMIX_PWR_REQ BIT(7)
  23. #define DISPMIX_PWR_REQ BIT(10)
  24. #define HSIOMIX_ADB400_SYNC BIT(5)
  25. #define DISPMIX_ADB400_SYNC BIT(7)
  26. #define GPUMIX_ADB400_SYNC (0x5 << 9)
  27. #define HSIOMIX_ADB400_ACK BIT(23)
  28. #define DISPMIX_ADB400_ACK BIT(25)
  29. #define GPUMIX_ADB400_ACK (0x5 << 27)
  30. #define MIPI_PGC 0xc00
  31. #define OTG1_PGC 0xc80
  32. #define HSIOMIX_PGC 0xd00
  33. #define GPUMIX_PGC 0xdc0
  34. #define DISPMIX_PGC 0xe80
  35. enum pu_domain_id {
  36. HSIOMIX,
  37. OTG1 = 2,
  38. GPUMIX = 4,
  39. DISPMIX = 9,
  40. MIPI,
  41. };
  42. /* PU domain, add some hole to minimize the uboot change */
  43. static struct imx_pwr_domain pu_domains[11] = {
  44. [HSIOMIX] = IMX_MIX_DOMAIN(HSIOMIX, false),
  45. [OTG1] = IMX_PD_DOMAIN(OTG1, true),
  46. [GPUMIX] = IMX_MIX_DOMAIN(GPUMIX, false),
  47. [DISPMIX] = IMX_MIX_DOMAIN(DISPMIX, false),
  48. [MIPI] = IMX_PD_DOMAIN(MIPI, true),
  49. };
  50. static unsigned int pu_domain_status;
  51. void imx_gpc_pm_domain_enable(uint32_t domain_id, bool on)
  52. {
  53. if (domain_id > MIPI) {
  54. return;
  55. }
  56. struct imx_pwr_domain *pwr_domain = &pu_domains[domain_id];
  57. if (on) {
  58. if (pwr_domain->need_sync) {
  59. pu_domain_status |= (1 << domain_id);
  60. }
  61. /* HSIOMIX has no PU bit, so skip for it */
  62. if (domain_id != HSIOMIX) {
  63. /* clear the PGC bit */
  64. mmio_clrbits_32(IMX_GPC_BASE + pwr_domain->pgc_offset, 0x1);
  65. /* power up the domain */
  66. mmio_setbits_32(IMX_GPC_BASE + PU_PGC_UP_TRG, pwr_domain->pwr_req);
  67. /* wait for power request done */
  68. while (mmio_read_32(IMX_GPC_BASE + PU_PGC_UP_TRG) & pwr_domain->pwr_req) {
  69. ;
  70. }
  71. }
  72. if (domain_id == DISPMIX) {
  73. /* de-reset bus_blk clk and
  74. * enable bus_blk clk
  75. */
  76. mmio_write_32(0x32e28000, 0x100);
  77. mmio_write_32(0x32e28004, 0x100);
  78. }
  79. /* handle the ADB400 sync */
  80. if (pwr_domain->need_sync) {
  81. /* clear adb power down request */
  82. mmio_setbits_32(IMX_GPC_BASE + GPC_PU_PWRHSK, pwr_domain->adb400_sync);
  83. /* wait for adb power request ack */
  84. while (!(mmio_read_32(IMX_GPC_BASE + GPC_PU_PWRHSK) & pwr_domain->adb400_ack)) {
  85. ;
  86. }
  87. }
  88. } else {
  89. pu_domain_status &= ~(1 << domain_id);
  90. if (domain_id == OTG1) {
  91. return;
  92. }
  93. /* handle the ADB400 sync */
  94. if (pwr_domain->need_sync) {
  95. /* set adb power down request */
  96. mmio_clrbits_32(IMX_GPC_BASE + GPC_PU_PWRHSK, pwr_domain->adb400_sync);
  97. /* wait for adb power request ack */
  98. while ((mmio_read_32(IMX_GPC_BASE + GPC_PU_PWRHSK) & pwr_domain->adb400_ack)) {
  99. ;
  100. }
  101. }
  102. /* HSIOMIX has no PU bit, so skip for it */
  103. if (domain_id != HSIOMIX) {
  104. /* set the PGC bit */
  105. mmio_setbits_32(IMX_GPC_BASE + pwr_domain->pgc_offset, 0x1);
  106. /* power down the domain */
  107. mmio_setbits_32(IMX_GPC_BASE + PU_PGC_DN_TRG, pwr_domain->pwr_req);
  108. /* wait for power request done */
  109. while (mmio_read_32(IMX_GPC_BASE + PU_PGC_DN_TRG) & pwr_domain->pwr_req) {
  110. ;
  111. }
  112. }
  113. }
  114. }
  115. void imx_gpc_init(void)
  116. {
  117. unsigned int val;
  118. int i;
  119. /* mask all the wakeup irq by default */
  120. for (i = 0; i < 4; i++) {
  121. mmio_write_32(IMX_GPC_BASE + IMR1_CORE0_A53 + i * 4, ~0x0);
  122. mmio_write_32(IMX_GPC_BASE + IMR1_CORE1_A53 + i * 4, ~0x0);
  123. mmio_write_32(IMX_GPC_BASE + IMR1_CORE2_A53 + i * 4, ~0x0);
  124. mmio_write_32(IMX_GPC_BASE + IMR1_CORE3_A53 + i * 4, ~0x0);
  125. mmio_write_32(IMX_GPC_BASE + IMR1_CORE0_M4 + i * 4, ~0x0);
  126. }
  127. val = mmio_read_32(IMX_GPC_BASE + LPCR_A53_BSC);
  128. /* use GIC wake_request to wakeup C0~C3 from LPM */
  129. val |= CORE_WKUP_FROM_GIC;
  130. /* clear the MASTER0 LPM handshake */
  131. val &= ~MASTER0_LPM_HSK;
  132. mmio_write_32(IMX_GPC_BASE + LPCR_A53_BSC, val);
  133. /* clear MASTER1 & MASTER2 mapping in CPU0(A53) */
  134. mmio_clrbits_32(IMX_GPC_BASE + MST_CPU_MAPPING, (MASTER1_MAPPING |
  135. MASTER2_MAPPING));
  136. /* set all mix/PU in A53 domain */
  137. mmio_write_32(IMX_GPC_BASE + PGC_CPU_0_1_MAPPING, 0xffff);
  138. /*
  139. * Set the CORE & SCU power up timing:
  140. * SW = 0x1, SW2ISO = 0x1;
  141. * the CPU CORE and SCU power up timing counter
  142. * is drived by 32K OSC, each domain's power up
  143. * latency is (SW + SW2ISO) / 32768
  144. */
  145. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(0) + 0x4, 0x401);
  146. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(1) + 0x4, 0x401);
  147. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(2) + 0x4, 0x401);
  148. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(3) + 0x4, 0x401);
  149. mmio_write_32(IMX_GPC_BASE + PLAT_PGC_PCR + 0x4, 0x401);
  150. mmio_write_32(IMX_GPC_BASE + PGC_SCU_TIMING,
  151. (0x59 << TMC_TMR_SHIFT) | 0x5B | (0x2 << TRC1_TMC_SHIFT));
  152. /* set DUMMY PDN/PUP ACK by default for A53 domain */
  153. mmio_write_32(IMX_GPC_BASE + PGC_ACK_SEL_A53,
  154. A53_DUMMY_PUP_ACK | A53_DUMMY_PDN_ACK);
  155. /* clear DSM by default */
  156. val = mmio_read_32(IMX_GPC_BASE + SLPCR);
  157. val &= ~SLPCR_EN_DSM;
  158. /* enable the fast wakeup wait mode */
  159. val |= SLPCR_A53_FASTWUP_WAIT_MODE;
  160. /* clear the RBC */
  161. val &= ~(0x3f << SLPCR_RBC_COUNT_SHIFT);
  162. /* set the STBY_COUNT to 0x5, (128 * 30)us */
  163. val &= ~(0x7 << SLPCR_STBY_COUNT_SHFT);
  164. val |= (0x5 << SLPCR_STBY_COUNT_SHFT);
  165. mmio_write_32(IMX_GPC_BASE + SLPCR, val);
  166. /*
  167. * USB PHY power up needs to make sure RESET bit in SRC is clear,
  168. * otherwise, the PU power up bit in GPC will NOT self-cleared.
  169. * only need to do it once.
  170. */
  171. mmio_clrbits_32(IMX_SRC_BASE + SRC_OTG1PHY_SCR, 0x1);
  172. }