ls102xa_psci.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2016 Freescale Semiconductor, Inc.
  4. * Author: Hongbo Zhang <hongbo.zhang@nxp.com>
  5. * This file implements LS102X platform PSCI SYSTEM-SUSPEND function
  6. */
  7. #include <config.h>
  8. #include <asm/io.h>
  9. #include <asm/psci.h>
  10. #include <asm/arch/immap_ls102xa.h>
  11. #include <fsl_immap.h>
  12. #include "fsl_epu.h"
  13. #define __secure __attribute__((section("._secure.text")))
  14. #define CCSR_GICD_CTLR 0x1000
  15. #define CCSR_GICC_CTLR 0x2000
  16. #define DCSR_RCPM_CG1CR0 0x31c
  17. #define DCSR_RCPM_CSTTACR0 0xb00
  18. #define DCFG_CRSTSR_WDRFR 0x8
  19. #define DDR_RESV_LEN 128
  20. #ifdef CONFIG_LS1_DEEP_SLEEP
  21. /*
  22. * DDR controller initialization training breaks the first 128 bytes of DDR,
  23. * save them so that the bootloader can restore them while resuming.
  24. */
  25. static void __secure ls1_save_ddr_head(void)
  26. {
  27. const char *src = (const char *)CONFIG_SYS_SDRAM_BASE;
  28. char *dest = (char *)(OCRAM_BASE_S_ADDR + OCRAM_S_SIZE - DDR_RESV_LEN);
  29. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  30. int i;
  31. out_le32(&scfg->sparecr[2], dest);
  32. for (i = 0; i < DDR_RESV_LEN; i++)
  33. *dest++ = *src++;
  34. }
  35. static void __secure ls1_fsm_setup(void)
  36. {
  37. void *dcsr_epu_base = (void *)(CONFIG_SYS_DCSRBAR + EPU_BLOCK_OFFSET);
  38. void *dcsr_rcpm_base = (void *)SYS_FSL_DCSR_RCPM_ADDR;
  39. out_be32(dcsr_rcpm_base + DCSR_RCPM_CSTTACR0, 0x00001001);
  40. out_be32(dcsr_rcpm_base + DCSR_RCPM_CG1CR0, 0x00000001);
  41. fsl_epu_setup((void *)dcsr_epu_base);
  42. /* Pull MCKE signal low before enabling deep sleep signal in FPGA */
  43. out_be32(dcsr_epu_base + EPECR0, 0x5);
  44. out_be32(dcsr_epu_base + EPSMCR15, 0x76300000);
  45. }
  46. static void __secure ls1_deepsleep_irq_cfg(void)
  47. {
  48. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  49. struct ccsr_rcpm __iomem *rcpm = (void *)CONFIG_SYS_FSL_RCPM_ADDR;
  50. u32 ippdexpcr0, ippdexpcr1, pmcintecr = 0;
  51. /* Mask interrupts from GIC */
  52. out_be32(&rcpm->nfiqoutr, 0x0ffffffff);
  53. out_be32(&rcpm->nirqoutr, 0x0ffffffff);
  54. /* Mask deep sleep wake-up interrupts while entering deep sleep */
  55. out_be32(&rcpm->dsimskr, 0x0ffffffff);
  56. ippdexpcr0 = in_be32(&rcpm->ippdexpcr0);
  57. /*
  58. * Workaround: There is bug of register ippdexpcr1, when read it always
  59. * returns zero, so its value is saved to a scrachpad register to be
  60. * read, that is why we don't read it from register ippdexpcr1 itself.
  61. */
  62. ippdexpcr1 = in_le32(&scfg->sparecr[7]);
  63. if (ippdexpcr0 & RCPM_IPPDEXPCR0_ETSEC)
  64. pmcintecr |= SCFG_PMCINTECR_ETSECRXG0 |
  65. SCFG_PMCINTECR_ETSECRXG1 |
  66. SCFG_PMCINTECR_ETSECERRG0 |
  67. SCFG_PMCINTECR_ETSECERRG1;
  68. if (ippdexpcr0 & RCPM_IPPDEXPCR0_GPIO)
  69. pmcintecr |= SCFG_PMCINTECR_GPIO;
  70. if (ippdexpcr1 & RCPM_IPPDEXPCR1_LPUART)
  71. pmcintecr |= SCFG_PMCINTECR_LPUART;
  72. if (ippdexpcr1 & RCPM_IPPDEXPCR1_FLEXTIMER)
  73. pmcintecr |= SCFG_PMCINTECR_FTM;
  74. /* Always set external IRQ pins as wakeup source */
  75. pmcintecr |= SCFG_PMCINTECR_IRQ0 | SCFG_PMCINTECR_IRQ1;
  76. out_be32(&scfg->pmcintlecr, 0);
  77. /* Clear PMC interrupt status */
  78. out_be32(&scfg->pmcintsr, 0xffffffff);
  79. /* Enable wakeup interrupt during deep sleep */
  80. out_be32(&scfg->pmcintecr, pmcintecr);
  81. }
  82. static void __secure ls1_delay(unsigned int loop)
  83. {
  84. while (loop--) {
  85. int i = 1000;
  86. while (i--)
  87. ;
  88. }
  89. }
  90. static void __secure ls1_start_fsm(void)
  91. {
  92. void *dcsr_epu_base = (void *)(CONFIG_SYS_DCSRBAR + EPU_BLOCK_OFFSET);
  93. void *ccsr_gic_base = (void *)SYS_FSL_GIC_ADDR;
  94. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  95. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  96. /* Set HRSTCR */
  97. setbits_be32(&scfg->hrstcr, 0x80000000);
  98. /* Place DDR controller in self refresh mode */
  99. setbits_be32(&ddr->sdram_cfg_2, 0x80000000);
  100. ls1_delay(2000);
  101. /* Set EVT4_B to lock the signal MCKE down */
  102. out_be32(dcsr_epu_base + EPECR0, 0x0);
  103. ls1_delay(2000);
  104. out_be32(ccsr_gic_base + CCSR_GICD_CTLR, 0x0);
  105. out_be32(ccsr_gic_base + CCSR_GICC_CTLR, 0x0);
  106. /* Enable all EPU Counters */
  107. setbits_be32(dcsr_epu_base + EPGCR, 0x80000000);
  108. /* Enable SCU15 */
  109. setbits_be32(dcsr_epu_base + EPECR15, 0x90000004);
  110. /* Enter WFI mode, and EPU FSM will start */
  111. __asm__ __volatile__ ("wfi" : : : "memory");
  112. /* NEVER ENTER HERE */
  113. while (1)
  114. ;
  115. }
  116. static void __secure ls1_deep_sleep(u32 entry_point)
  117. {
  118. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  119. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  120. struct ccsr_rcpm __iomem *rcpm = (void *)CONFIG_SYS_FSL_RCPM_ADDR;
  121. #ifdef QIXIS_BASE
  122. u32 tmp;
  123. void *qixis_base = (void *)QIXIS_BASE;
  124. #endif
  125. /* Enable cluster to enter the PCL10 state */
  126. out_be32(&scfg->clusterpmcr, SCFG_CLUSTERPMCR_WFIL2EN);
  127. /* Save the first 128 bytes of DDR data */
  128. ls1_save_ddr_head();
  129. /* Save the kernel resume entry */
  130. out_le32(&scfg->sparecr[3], entry_point);
  131. /* Request to put cluster 0 in PCL10 state */
  132. setbits_be32(&rcpm->clpcl10setr, RCPM_CLPCL10SETR_C0);
  133. /* Setup the registers of the EPU FSM for deep sleep */
  134. ls1_fsm_setup();
  135. #ifdef QIXIS_BASE
  136. /* Connect the EVENT button to IRQ in FPGA */
  137. tmp = in_8(qixis_base + QIXIS_CTL_SYS);
  138. tmp &= ~QIXIS_CTL_SYS_EVTSW_MASK;
  139. tmp |= QIXIS_CTL_SYS_EVTSW_IRQ;
  140. out_8(qixis_base + QIXIS_CTL_SYS, tmp);
  141. /* Enable deep sleep signals in FPGA */
  142. tmp = in_8(qixis_base + QIXIS_PWR_CTL2);
  143. tmp |= QIXIS_PWR_CTL2_PCTL;
  144. out_8(qixis_base + QIXIS_PWR_CTL2, tmp);
  145. /* Pull down PCIe RST# */
  146. tmp = in_8(qixis_base + QIXIS_RST_FORCE_3);
  147. tmp |= QIXIS_RST_FORCE_3_PCIESLOT1;
  148. out_8(qixis_base + QIXIS_RST_FORCE_3, tmp);
  149. #endif
  150. /* Enable Warm Device Reset */
  151. setbits_be32(&scfg->dpslpcr, SCFG_DPSLPCR_WDRR_EN);
  152. setbits_be32(&gur->crstsr, DCFG_CRSTSR_WDRFR);
  153. ls1_deepsleep_irq_cfg();
  154. psci_v7_flush_dcache_all();
  155. ls1_start_fsm();
  156. }
  157. #else
  158. static void __secure ls1_sleep(void)
  159. {
  160. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  161. struct ccsr_rcpm __iomem *rcpm = (void *)CONFIG_SYS_FSL_RCPM_ADDR;
  162. #ifdef QIXIS_BASE
  163. u32 tmp;
  164. void *qixis_base = (void *)QIXIS_BASE;
  165. /* Connect the EVENT button to IRQ in FPGA */
  166. tmp = in_8(qixis_base + QIXIS_CTL_SYS);
  167. tmp &= ~QIXIS_CTL_SYS_EVTSW_MASK;
  168. tmp |= QIXIS_CTL_SYS_EVTSW_IRQ;
  169. out_8(qixis_base + QIXIS_CTL_SYS, tmp);
  170. #endif
  171. /* Enable cluster to enter the PCL10 state */
  172. out_be32(&scfg->clusterpmcr, SCFG_CLUSTERPMCR_WFIL2EN);
  173. setbits_be32(&rcpm->powmgtcsr, RCPM_POWMGTCSR_LPM20_REQ);
  174. __asm__ __volatile__ ("wfi" : : : "memory");
  175. }
  176. #endif
  177. void __secure ls1_system_suspend(u32 fn, u32 entry_point, u32 context_id)
  178. {
  179. #ifdef CONFIG_LS1_DEEP_SLEEP
  180. ls1_deep_sleep(entry_point);
  181. #else
  182. ls1_sleep();
  183. #endif
  184. }