gpc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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_aipstz.h>
  17. #include <imx_sip_svc.h>
  18. #include <platform_def.h>
  19. #define CCGR(x) (0x4000 + (x) * 0x10)
  20. #define IMR_NUM U(5)
  21. struct imx_noc_setting {
  22. uint32_t domain_id;
  23. uint32_t start;
  24. uint32_t end;
  25. uint32_t prioriy;
  26. uint32_t mode;
  27. uint32_t socket_qos_en;
  28. };
  29. enum clk_type {
  30. CCM_ROOT_SLICE,
  31. CCM_CCGR,
  32. };
  33. struct clk_setting {
  34. uint32_t offset;
  35. uint32_t val;
  36. enum clk_type type;
  37. };
  38. enum pu_domain_id {
  39. /* hsio ss */
  40. HSIOMIX,
  41. PCIE_PHY,
  42. USB1_PHY,
  43. USB2_PHY,
  44. MLMIX,
  45. AUDIOMIX,
  46. /* gpu ss */
  47. GPUMIX,
  48. GPU2D,
  49. GPU3D,
  50. /* vpu ss */
  51. VPUMIX,
  52. VPU_G1,
  53. VPU_G2,
  54. VPU_H1,
  55. /* media ss */
  56. MEDIAMIX,
  57. MEDIAMIX_ISPDWP,
  58. MIPI_PHY1,
  59. MIPI_PHY2,
  60. /* HDMI ss */
  61. HDMIMIX,
  62. HDMI_PHY,
  63. DDRMIX,
  64. MAX_DOMAINS,
  65. };
  66. /* PU domain, add some hole to minimize the uboot change */
  67. static struct imx_pwr_domain pu_domains[MAX_DOMAINS] = {
  68. [MIPI_PHY1] = IMX_PD_DOMAIN(MIPI_PHY1, false),
  69. [PCIE_PHY] = IMX_PD_DOMAIN(PCIE_PHY, false),
  70. [USB1_PHY] = IMX_PD_DOMAIN(USB1_PHY, true),
  71. [USB2_PHY] = IMX_PD_DOMAIN(USB2_PHY, true),
  72. [MLMIX] = IMX_MIX_DOMAIN(MLMIX, false),
  73. [AUDIOMIX] = IMX_MIX_DOMAIN(AUDIOMIX, false),
  74. [GPU2D] = IMX_PD_DOMAIN(GPU2D, false),
  75. [GPUMIX] = IMX_MIX_DOMAIN(GPUMIX, false),
  76. [VPUMIX] = IMX_MIX_DOMAIN(VPUMIX, false),
  77. [GPU3D] = IMX_PD_DOMAIN(GPU3D, false),
  78. [MEDIAMIX] = IMX_MIX_DOMAIN(MEDIAMIX, false),
  79. [VPU_G1] = IMX_PD_DOMAIN(VPU_G1, false),
  80. [VPU_G2] = IMX_PD_DOMAIN(VPU_G2, false),
  81. [VPU_H1] = IMX_PD_DOMAIN(VPU_H1, false),
  82. [HDMIMIX] = IMX_MIX_DOMAIN(HDMIMIX, false),
  83. [HDMI_PHY] = IMX_PD_DOMAIN(HDMI_PHY, false),
  84. [MIPI_PHY2] = IMX_PD_DOMAIN(MIPI_PHY2, false),
  85. [HSIOMIX] = IMX_MIX_DOMAIN(HSIOMIX, false),
  86. [MEDIAMIX_ISPDWP] = IMX_PD_DOMAIN(MEDIAMIX_ISPDWP, false),
  87. };
  88. static struct imx_noc_setting noc_setting[] = {
  89. {MLMIX, 0x180, 0x180, 0x80000303, 0x0, 0x0},
  90. {AUDIOMIX, 0x200, 0x200, 0x80000303, 0x0, 0x0},
  91. {AUDIOMIX, 0x280, 0x480, 0x80000404, 0x0, 0x0},
  92. {GPUMIX, 0x500, 0x580, 0x80000303, 0x0, 0x0},
  93. {HDMIMIX, 0x600, 0x680, 0x80000202, 0x0, 0x1},
  94. {HDMIMIX, 0x700, 0x700, 0x80000505, 0x0, 0x0},
  95. {HSIOMIX, 0x780, 0x900, 0x80000303, 0x0, 0x0},
  96. {MEDIAMIX, 0x980, 0xb80, 0x80000202, 0x0, 0x1},
  97. {MEDIAMIX_ISPDWP, 0xc00, 0xd00, 0x80000505, 0x0, 0x0},
  98. {VPU_G1, 0xd80, 0xd80, 0x80000303, 0x0, 0x0},
  99. {VPU_G2, 0xe00, 0xe00, 0x80000303, 0x0, 0x0},
  100. {VPU_H1, 0xe80, 0xe80, 0x80000303, 0x0, 0x0}
  101. };
  102. static struct clk_setting hsiomix_clk[] = {
  103. { 0x8380, 0x0, CCM_ROOT_SLICE },
  104. { 0x44d0, 0x0, CCM_CCGR },
  105. { 0x45c0, 0x0, CCM_CCGR },
  106. };
  107. static struct aipstz_cfg aipstz5[] = {
  108. {IMX_AIPSTZ5, 0x77777777, 0x77777777, .opacr = {0x0, 0x0, 0x0, 0x0, 0x0}, },
  109. {0},
  110. };
  111. static unsigned int pu_domain_status;
  112. static void imx_noc_qos(unsigned int domain_id)
  113. {
  114. unsigned int i;
  115. uint32_t hurry;
  116. if (domain_id == HDMIMIX) {
  117. mmio_write_32(IMX_HDMI_CTL_BASE + TX_CONTROL1, 0x22018);
  118. mmio_write_32(IMX_HDMI_CTL_BASE + TX_CONTROL1, 0x22010);
  119. /* set GPR to make lcdif read hurry level 0x7 */
  120. hurry = mmio_read_32(IMX_HDMI_CTL_BASE + TX_CONTROL0);
  121. hurry |= 0x00077000;
  122. mmio_write_32(IMX_HDMI_CTL_BASE + TX_CONTROL0, hurry);
  123. }
  124. if (domain_id == MEDIAMIX) {
  125. /* handle mediamix special */
  126. mmio_write_32(IMX_MEDIAMIX_CTL_BASE + RSTn_CSR, 0x1FFFFFF);
  127. mmio_write_32(IMX_MEDIAMIX_CTL_BASE + CLK_EN_CSR, 0x1FFFFFF);
  128. mmio_write_32(IMX_MEDIAMIX_CTL_BASE + RST_DIV, 0x40030000);
  129. /* set GPR to make lcdif read hurry level 0x7 */
  130. hurry = mmio_read_32(IMX_MEDIAMIX_CTL_BASE + LCDIF_ARCACHE_CTRL);
  131. hurry |= 0xfc00;
  132. mmio_write_32(IMX_MEDIAMIX_CTL_BASE + LCDIF_ARCACHE_CTRL, hurry);
  133. /* set GPR to make isi write hurry level 0x7 */
  134. hurry = mmio_read_32(IMX_MEDIAMIX_CTL_BASE + ISI_CACHE_CTRL);
  135. hurry |= 0x1ff00000;
  136. mmio_write_32(IMX_MEDIAMIX_CTL_BASE + ISI_CACHE_CTRL, hurry);
  137. }
  138. /* set MIX NoC */
  139. for (i = 0; i < ARRAY_SIZE(noc_setting); i++) {
  140. if (noc_setting[i].domain_id == domain_id) {
  141. udelay(50);
  142. uint32_t offset = noc_setting[i].start;
  143. while (offset <= noc_setting[i].end) {
  144. mmio_write_32(IMX_NOC_BASE + offset + 0x8, noc_setting[i].prioriy);
  145. mmio_write_32(IMX_NOC_BASE + offset + 0xc, noc_setting[i].mode);
  146. mmio_write_32(IMX_NOC_BASE + offset + 0x18, noc_setting[i].socket_qos_en);
  147. offset += 0x80;
  148. }
  149. }
  150. }
  151. }
  152. void imx_gpc_pm_domain_enable(uint32_t domain_id, bool on)
  153. {
  154. struct imx_pwr_domain *pwr_domain = &pu_domains[domain_id];
  155. unsigned int i;
  156. /* validate the domain id */
  157. if (domain_id >= MAX_DOMAINS) {
  158. return;
  159. }
  160. if (domain_id == HSIOMIX) {
  161. for (i = 0; i < ARRAY_SIZE(hsiomix_clk); i++) {
  162. hsiomix_clk[i].val = mmio_read_32(IMX_CCM_BASE + hsiomix_clk[i].offset);
  163. mmio_setbits_32(IMX_CCM_BASE + hsiomix_clk[i].offset,
  164. hsiomix_clk[i].type == CCM_ROOT_SLICE ? BIT(28) : 0x3);
  165. }
  166. }
  167. if (on) {
  168. if (pwr_domain->need_sync) {
  169. pu_domain_status |= (1 << domain_id);
  170. }
  171. if (domain_id == HDMIMIX) {
  172. /* assert the reset */
  173. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_RESET_CTL0, 0x0);
  174. /* enable all th function clock */
  175. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL0, 0xFFFFFFFF);
  176. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL1, 0x7ffff87e);
  177. }
  178. /* clear the PGC bit */
  179. mmio_clrbits_32(IMX_GPC_BASE + pwr_domain->pgc_offset, 0x1);
  180. /* power up the domain */
  181. mmio_setbits_32(IMX_GPC_BASE + PU_PGC_UP_TRG, pwr_domain->pwr_req);
  182. /* wait for power request done */
  183. while (mmio_read_32(IMX_GPC_BASE + PU_PGC_UP_TRG) & pwr_domain->pwr_req)
  184. ;
  185. if (domain_id == HDMIMIX) {
  186. /* wait for memory repair done for HDMIMIX */
  187. while (!(mmio_read_32(IMX_SRC_BASE + 0x94) & BIT(8)))
  188. ;
  189. /* disable all the function clock */
  190. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL0, 0x0);
  191. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL1, 0x0);
  192. /* deassert the reset */
  193. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_RESET_CTL0, 0xffffffff);
  194. /* enable all the clock again */
  195. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL0, 0xFFFFFFFF);
  196. mmio_write_32(IMX_HDMI_CTL_BASE + RTX_CLK_CTL1, 0x7ffff87e);
  197. }
  198. if (domain_id == HSIOMIX) {
  199. /* enable HSIOMIX clock */
  200. mmio_write_32(IMX_HSIOMIX_CTL_BASE, 0x2);
  201. }
  202. /* handle the ADB400 sync */
  203. if (pwr_domain->need_sync) {
  204. /* clear adb power down request */
  205. mmio_setbits_32(IMX_GPC_BASE + GPC_PU_PWRHSK, pwr_domain->adb400_sync);
  206. /* wait for adb power request ack */
  207. while (!(mmio_read_32(IMX_GPC_BASE + GPC_PU_PWRHSK) & pwr_domain->adb400_ack))
  208. ;
  209. }
  210. imx_noc_qos(domain_id);
  211. /* AIPS5 config is lost when audiomix is off, so need to re-init it */
  212. if (domain_id == AUDIOMIX) {
  213. imx_aipstz_init(aipstz5);
  214. }
  215. } else {
  216. if (pwr_domain->always_on) {
  217. return;
  218. }
  219. if (pwr_domain->need_sync) {
  220. pu_domain_status &= ~(1 << domain_id);
  221. }
  222. /* handle the ADB400 sync */
  223. if (pwr_domain->need_sync) {
  224. /* set adb power down request */
  225. mmio_clrbits_32(IMX_GPC_BASE + GPC_PU_PWRHSK, pwr_domain->adb400_sync);
  226. /* wait for adb power request ack */
  227. while ((mmio_read_32(IMX_GPC_BASE + GPC_PU_PWRHSK) & pwr_domain->adb400_ack))
  228. ;
  229. }
  230. /* set the PGC bit */
  231. mmio_setbits_32(IMX_GPC_BASE + pwr_domain->pgc_offset, 0x1);
  232. /*
  233. * leave the G1, G2, H1 power domain on until VPUMIX power off,
  234. * otherwise system will hang due to VPUMIX ACK
  235. */
  236. if (domain_id == VPU_H1 || domain_id == VPU_G1 || domain_id == VPU_G2) {
  237. return;
  238. }
  239. if (domain_id == VPUMIX) {
  240. mmio_write_32(IMX_GPC_BASE + PU_PGC_DN_TRG, VPU_G1_PWR_REQ |
  241. VPU_G2_PWR_REQ | VPU_H1_PWR_REQ);
  242. while (mmio_read_32(IMX_GPC_BASE + PU_PGC_DN_TRG) & (VPU_G1_PWR_REQ |
  243. VPU_G2_PWR_REQ | VPU_H1_PWR_REQ))
  244. ;
  245. }
  246. /* power down the domain */
  247. mmio_setbits_32(IMX_GPC_BASE + PU_PGC_DN_TRG, pwr_domain->pwr_req);
  248. /* wait for power request done */
  249. while (mmio_read_32(IMX_GPC_BASE + PU_PGC_DN_TRG) & pwr_domain->pwr_req)
  250. ;
  251. if (domain_id == HDMIMIX) {
  252. /* disable all the clocks of HDMIMIX */
  253. mmio_write_32(IMX_HDMI_CTL_BASE + 0x40, 0x0);
  254. mmio_write_32(IMX_HDMI_CTL_BASE + 0x50, 0x0);
  255. }
  256. }
  257. if (domain_id == HSIOMIX) {
  258. for (i = 0; i < ARRAY_SIZE(hsiomix_clk); i++) {
  259. mmio_write_32(IMX_CCM_BASE + hsiomix_clk[i].offset, hsiomix_clk[i].val);
  260. }
  261. }
  262. }
  263. void imx_gpc_init(void)
  264. {
  265. uint32_t val;
  266. unsigned int i;
  267. /* mask all the wakeup irq by default */
  268. for (i = 0; i < IMR_NUM; i++) {
  269. mmio_write_32(IMX_GPC_BASE + IMR1_CORE0_A53 + i * 4, ~0x0);
  270. mmio_write_32(IMX_GPC_BASE + IMR1_CORE1_A53 + i * 4, ~0x0);
  271. mmio_write_32(IMX_GPC_BASE + IMR1_CORE2_A53 + i * 4, ~0x0);
  272. mmio_write_32(IMX_GPC_BASE + IMR1_CORE3_A53 + i * 4, ~0x0);
  273. mmio_write_32(IMX_GPC_BASE + IMR1_CORE0_M4 + i * 4, ~0x0);
  274. }
  275. val = mmio_read_32(IMX_GPC_BASE + LPCR_A53_BSC);
  276. /* use GIC wake_request to wakeup C0~C3 from LPM */
  277. val |= CORE_WKUP_FROM_GIC;
  278. /* clear the MASTER0 LPM handshake */
  279. val &= ~MASTER0_LPM_HSK;
  280. mmio_write_32(IMX_GPC_BASE + LPCR_A53_BSC, val);
  281. /* clear MASTER1 & MASTER2 mapping in CPU0(A53) */
  282. mmio_clrbits_32(IMX_GPC_BASE + MST_CPU_MAPPING, (MASTER1_MAPPING |
  283. MASTER2_MAPPING));
  284. /* set all mix/PU in A53 domain */
  285. mmio_write_32(IMX_GPC_BASE + PGC_CPU_0_1_MAPPING, 0x3fffff);
  286. /*
  287. * Set the CORE & SCU power up timing:
  288. * SW = 0x1, SW2ISO = 0x1;
  289. * the CPU CORE and SCU power up timing counter
  290. * is drived by 32K OSC, each domain's power up
  291. * latency is (SW + SW2ISO) / 32768
  292. */
  293. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(0) + 0x4, 0x401);
  294. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(1) + 0x4, 0x401);
  295. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(2) + 0x4, 0x401);
  296. mmio_write_32(IMX_GPC_BASE + COREx_PGC_PCR(3) + 0x4, 0x401);
  297. mmio_write_32(IMX_GPC_BASE + PLAT_PGC_PCR + 0x4, 0x401);
  298. mmio_write_32(IMX_GPC_BASE + PGC_SCU_TIMING,
  299. (0x59 << TMC_TMR_SHIFT) | 0x5B | (0x2 << TRC1_TMC_SHIFT));
  300. /* set DUMMY PDN/PUP ACK by default for A53 domain */
  301. mmio_write_32(IMX_GPC_BASE + PGC_ACK_SEL_A53,
  302. A53_DUMMY_PUP_ACK | A53_DUMMY_PDN_ACK);
  303. /* clear DSM by default */
  304. val = mmio_read_32(IMX_GPC_BASE + SLPCR);
  305. val &= ~SLPCR_EN_DSM;
  306. /* enable the fast wakeup wait/stop mode */
  307. val |= SLPCR_A53_FASTWUP_WAIT_MODE;
  308. val |= SLPCR_A53_FASTWUP_STOP_MODE;
  309. /* clear the RBC */
  310. val &= ~(0x3f << SLPCR_RBC_COUNT_SHIFT);
  311. /* set the STBY_COUNT to 0x5, (128 * 30)us */
  312. val &= ~(0x7 << SLPCR_STBY_COUNT_SHFT);
  313. val |= (0x5 << SLPCR_STBY_COUNT_SHFT);
  314. mmio_write_32(IMX_GPC_BASE + SLPCR, val);
  315. /*
  316. * USB PHY power up needs to make sure RESET bit in SRC is clear,
  317. * otherwise, the PU power up bit in GPC will NOT self-cleared.
  318. * only need to do it once.
  319. */
  320. mmio_clrbits_32(IMX_SRC_BASE + SRC_OTG1PHY_SCR, 0x1);
  321. mmio_clrbits_32(IMX_SRC_BASE + SRC_OTG2PHY_SCR, 0x1);
  322. /* enable all clocks by default */
  323. for (i = 0; i < 101; i++) {
  324. mmio_write_32(IMX_CCM_BASE + CCGR(i), 0x3);
  325. }
  326. /* Depending on SKU, we may be lacking e.g. a VPU and shouldn't
  327. * access that domain here, because that would lockup the SoC.
  328. * Other i.MX8M variants don't initialize any power domains, but
  329. * for 8MP we have been enabling the USB power domains since the
  330. * beginning and stopping to do this now may render systems
  331. * unrecoverable. So we'll keep initializing just the USB power
  332. * domains instead of all of them like before.
  333. */
  334. imx_gpc_pm_domain_enable(HSIOMIX, true);
  335. imx_gpc_pm_domain_enable(USB1_PHY, true);
  336. imx_gpc_pm_domain_enable(USB2_PHY, true);
  337. }