pm.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. extern void at91_pm_set_standby(void (*at91_standby)(void));
  17. /*
  18. * The AT91RM9200 goes into self-refresh mode with this command, and will
  19. * terminate self-refresh automatically on the next SDRAM access.
  20. *
  21. * Self-refresh mode is exited as soon as a memory access is made, but we don't
  22. * know for sure when that happens. However, we need to restore the low-power
  23. * mode if it was enabled before going idle. Restoring low-power mode while
  24. * still in self-refresh is "not recommended", but seems to work.
  25. */
  26. static inline void at91rm9200_standby(void)
  27. {
  28. u32 lpr = at91_ramc_read(0, AT91RM9200_SDRAMC_LPR);
  29. asm volatile(
  30. "b 1f\n\t"
  31. ".align 5\n\t"
  32. "1: mcr p15, 0, %0, c7, c10, 4\n\t"
  33. " str %0, [%1, %2]\n\t"
  34. " str %3, [%1, %4]\n\t"
  35. " mcr p15, 0, %0, c7, c0, 4\n\t"
  36. " str %5, [%1, %2]"
  37. :
  38. : "r" (0), "r" (AT91_BASE_SYS), "r" (AT91RM9200_SDRAMC_LPR),
  39. "r" (1), "r" (AT91RM9200_SDRAMC_SRR),
  40. "r" (lpr));
  41. }
  42. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  43. * remember.
  44. */
  45. static inline void at91_ddr_standby(void)
  46. {
  47. /* Those two values allow us to delay self-refresh activation
  48. * to the maximum. */
  49. u32 lpr0, lpr1 = 0;
  50. u32 saved_lpr0, saved_lpr1 = 0;
  51. if (at91_ramc_base[1]) {
  52. saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
  53. lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
  54. lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  55. }
  56. saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
  57. lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
  58. lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  59. /* self-refresh mode now */
  60. at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
  61. if (at91_ramc_base[1])
  62. at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
  63. cpu_do_idle();
  64. at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
  65. if (at91_ramc_base[1])
  66. at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
  67. }
  68. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  69. * remember.
  70. */
  71. static inline void at91sam9_sdram_standby(void)
  72. {
  73. u32 lpr0, lpr1 = 0;
  74. u32 saved_lpr0, saved_lpr1 = 0;
  75. if (at91_ramc_base[1]) {
  76. saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
  77. lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
  78. lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  79. }
  80. saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
  81. lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
  82. lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  83. /* self-refresh mode now */
  84. at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
  85. if (at91_ramc_base[1])
  86. at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
  87. cpu_do_idle();
  88. at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
  89. if (at91_ramc_base[1])
  90. at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
  91. }
  92. #endif