pm.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 at91sam9g45_standby(void)
  46. {
  47. /* Those two values allow us to delay self-refresh activation
  48. * to the maximum. */
  49. u32 lpr0, lpr1;
  50. u32 saved_lpr0, saved_lpr1;
  51. saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
  52. lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
  53. lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  54. saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
  55. lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
  56. lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  57. /* self-refresh mode now */
  58. at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
  59. at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
  60. cpu_do_idle();
  61. at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
  62. at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
  63. }
  64. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  65. * remember.
  66. */
  67. static inline void at91sam9263_standby(void)
  68. {
  69. u32 lpr0, lpr1;
  70. u32 saved_lpr0, saved_lpr1;
  71. saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
  72. lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
  73. lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  74. saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
  75. lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
  76. lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  77. /* self-refresh mode now */
  78. at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
  79. at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
  80. cpu_do_idle();
  81. at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
  82. at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
  83. }
  84. static inline void at91sam9_standby(void)
  85. {
  86. u32 saved_lpr, lpr;
  87. saved_lpr = at91_ramc_read(0, AT91_SDRAMC_LPR);
  88. lpr = saved_lpr & ~AT91_SDRAMC_LPCB;
  89. at91_ramc_write(0, AT91_SDRAMC_LPR, lpr |
  90. AT91_SDRAMC_LPCB_SELF_REFRESH);
  91. cpu_do_idle();
  92. at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr);
  93. }
  94. #endif