pm.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * AT91 Power Management
  3. *
  4. * Copyright (C) 2005 David Brownell
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef __ARCH_ARM_MACH_AT91_PM
  12. #define __ARCH_ARM_MACH_AT91_PM
  13. #include <asm/proc-fns.h>
  14. #include <mach/at91_ramc.h>
  15. #include <mach/at91rm9200_sdramc.h>
  16. #ifdef CONFIG_PM
  17. extern void at91_pm_set_standby(void (*at91_standby)(void));
  18. #else
  19. static inline void at91_pm_set_standby(void (*at91_standby)(void)) { }
  20. #endif
  21. /*
  22. * The AT91RM9200 goes into self-refresh mode with this command, and will
  23. * terminate self-refresh automatically on the next SDRAM access.
  24. *
  25. * Self-refresh mode is exited as soon as a memory access is made, but we don't
  26. * know for sure when that happens. However, we need to restore the low-power
  27. * mode if it was enabled before going idle. Restoring low-power mode while
  28. * still in self-refresh is "not recommended", but seems to work.
  29. */
  30. static inline void at91rm9200_standby(void)
  31. {
  32. u32 lpr = at91_ramc_read(0, AT91RM9200_SDRAMC_LPR);
  33. asm volatile(
  34. "b 1f\n\t"
  35. ".align 5\n\t"
  36. "1: mcr p15, 0, %0, c7, c10, 4\n\t"
  37. " str %0, [%1, %2]\n\t"
  38. " str %3, [%1, %4]\n\t"
  39. " mcr p15, 0, %0, c7, c0, 4\n\t"
  40. " str %5, [%1, %2]"
  41. :
  42. : "r" (0), "r" (AT91_BASE_SYS), "r" (AT91RM9200_SDRAMC_LPR),
  43. "r" (1), "r" (AT91RM9200_SDRAMC_SRR),
  44. "r" (lpr));
  45. }
  46. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  47. * remember.
  48. */
  49. static inline void at91_ddr_standby(void)
  50. {
  51. /* Those two values allow us to delay self-refresh activation
  52. * to the maximum. */
  53. u32 lpr0, lpr1 = 0;
  54. u32 saved_lpr0, saved_lpr1 = 0;
  55. if (at91_ramc_base[1]) {
  56. saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
  57. lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
  58. lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  59. }
  60. saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
  61. lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
  62. lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  63. /* self-refresh mode now */
  64. at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
  65. if (at91_ramc_base[1])
  66. at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
  67. cpu_do_idle();
  68. at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
  69. if (at91_ramc_base[1])
  70. at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
  71. }
  72. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  73. * remember.
  74. */
  75. static inline void at91sam9_sdram_standby(void)
  76. {
  77. u32 lpr0, lpr1 = 0;
  78. u32 saved_lpr0, saved_lpr1 = 0;
  79. if (at91_ramc_base[1]) {
  80. saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
  81. lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
  82. lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  83. }
  84. saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
  85. lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
  86. lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  87. /* self-refresh mode now */
  88. at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
  89. if (at91_ramc_base[1])
  90. at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
  91. cpu_do_idle();
  92. at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
  93. if (at91_ramc_base[1])
  94. at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
  95. }
  96. #endif