arm_sleep.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2014 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #ifndef CONFIG_ARMV7_NONSEC
  9. #error " Deep sleep needs non-secure mode support. "
  10. #else
  11. #include <asm/secure.h>
  12. #endif
  13. #include <asm/armv7.h>
  14. #if defined(CONFIG_LS102XA)
  15. #include <asm/arch/immap_ls102xa.h>
  16. #endif
  17. #include "sleep.h"
  18. #ifdef CONFIG_U_QE
  19. #include <fsl_qe.h>
  20. #endif
  21. DECLARE_GLOBAL_DATA_PTR;
  22. void __weak board_mem_sleep_setup(void)
  23. {
  24. }
  25. void __weak board_sleep_prepare(void)
  26. {
  27. }
  28. bool is_warm_boot(void)
  29. {
  30. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  31. if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
  32. return 1;
  33. return 0;
  34. }
  35. void fsl_dp_disable_console(void)
  36. {
  37. gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
  38. }
  39. /*
  40. * When wakeup from deep sleep, the first 128 bytes space
  41. * will be used to do DDR training which corrupts the data
  42. * in there. This function will restore them.
  43. */
  44. static void dp_ddr_restore(void)
  45. {
  46. u64 *src, *dst;
  47. int i;
  48. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  49. /* get the address of ddr date from SPARECR3 */
  50. src = (u64 *)in_le32(&scfg->sparecr[2]);
  51. dst = (u64 *)CONFIG_SYS_SDRAM_BASE;
  52. for (i = 0; i < DDR_BUFF_LEN / 8; i++)
  53. *dst++ = *src++;
  54. }
  55. #if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_LS102XA)
  56. void ls1_psci_resume_fixup(void)
  57. {
  58. u32 tmp;
  59. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  60. #ifdef QIXIS_BASE
  61. void *qixis_base = (void *)QIXIS_BASE;
  62. /* Pull on PCIe RST# */
  63. out_8(qixis_base + QIXIS_RST_FORCE_3, 0);
  64. /* disable deep sleep signals in FPGA */
  65. tmp = in_8(qixis_base + QIXIS_PWR_CTL2);
  66. tmp &= ~QIXIS_PWR_CTL2_PCTL;
  67. out_8(qixis_base + QIXIS_PWR_CTL2, tmp);
  68. #endif
  69. /* Disable wakeup interrupt during deep sleep */
  70. out_be32(&scfg->pmcintecr, 0);
  71. /* Clear PMC interrupt status */
  72. out_be32(&scfg->pmcintsr, 0xffffffff);
  73. /* Disable Warm Device Reset */
  74. tmp = in_be32(&scfg->dpslpcr);
  75. tmp &= ~SCFG_DPSLPCR_WDRR_EN;
  76. out_be32(&scfg->dpslpcr, tmp);
  77. }
  78. #endif
  79. static void dp_resume_prepare(void)
  80. {
  81. dp_ddr_restore();
  82. board_sleep_prepare();
  83. armv7_init_nonsec();
  84. #ifdef CONFIG_U_QE
  85. u_qe_resume();
  86. #endif
  87. #if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_LS102XA)
  88. ls1_psci_resume_fixup();
  89. #endif
  90. }
  91. int fsl_dp_resume(void)
  92. {
  93. u32 start_addr;
  94. void (*kernel_resume)(void);
  95. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
  96. if (!is_warm_boot())
  97. return 0;
  98. dp_resume_prepare();
  99. /* Get the entry address and jump to kernel */
  100. start_addr = in_le32(&scfg->sparecr[3]);
  101. debug("Entry address is 0x%08x\n", start_addr);
  102. kernel_resume = (void (*)(void))start_addr;
  103. secure_ram_addr(_do_nonsec_entry)(kernel_resume, 0, 0, 0);
  104. return 0;
  105. }