ls102xa_psci.c 6.4 KB

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