mpc85xx_sleep.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2014 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/immap_85xx.h>
  8. #include "sleep.h"
  9. DECLARE_GLOBAL_DATA_PTR;
  10. void __weak board_mem_sleep_setup(void)
  11. {
  12. }
  13. void __weak board_sleep_prepare(void)
  14. {
  15. }
  16. bool is_warm_boot(void)
  17. {
  18. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  19. if (in_be32(&gur->scrtsr[0]) & DCFG_CCSR_CRSTSR_WDRFR)
  20. return 1;
  21. return 0;
  22. }
  23. void fsl_dp_disable_console(void)
  24. {
  25. gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
  26. }
  27. /*
  28. * When wakeup from deep sleep, the first 128 bytes space
  29. * will be used to do DDR training which corrupts the data
  30. * in there. This function will restore them.
  31. */
  32. static void dp_ddr_restore(void)
  33. {
  34. volatile u64 *src, *dst;
  35. int i;
  36. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_MPC85xx_SCFG;
  37. /* get the address of ddr date from SPARECR3 */
  38. src = (u64 *)in_be32(&scfg->sparecr[2]);
  39. dst = (u64 *)CONFIG_SYS_SDRAM_BASE;
  40. for (i = 0; i < DDR_BUFF_LEN / 8; i++)
  41. *dst++ = *src++;
  42. flush_dcache();
  43. }
  44. static void dp_resume_prepare(void)
  45. {
  46. dp_ddr_restore();
  47. board_sleep_prepare();
  48. l2cache_init();
  49. #if defined(CONFIG_RAMBOOT_PBL)
  50. disable_cpc_sram();
  51. #endif
  52. enable_cpc();
  53. }
  54. int fsl_dp_resume(void)
  55. {
  56. u32 start_addr;
  57. void (*kernel_resume)(void);
  58. struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_MPC85xx_SCFG;
  59. if (!is_warm_boot())
  60. return 0;
  61. dp_resume_prepare();
  62. /* Get the entry address and jump to kernel */
  63. start_addr = in_be32(&scfg->sparecr[1]);
  64. debug("Entry address is 0x%08x\n", start_addr);
  65. kernel_resume = (void (*)(void))start_addr;
  66. kernel_resume();
  67. return 0;
  68. }