pm.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * arch/sh/kernel/cpu/shmobile/pm.c
  3. *
  4. * Power management support code for SuperH Mobile
  5. *
  6. * Copyright (C) 2009 Magnus Damm
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/io.h>
  15. #include <linux/suspend.h>
  16. #include <asm/suspend.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/cacheflush.h>
  19. /*
  20. * Notifier lists for pre/post sleep notification
  21. */
  22. ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
  23. ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);
  24. /*
  25. * Sleep modes available on SuperH Mobile:
  26. *
  27. * Sleep mode is just plain "sleep" instruction
  28. * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
  29. * Standby Self-Refresh mode is above plus stopped clocks
  30. */
  31. #define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
  32. #define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
  33. #define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
  34. #define SUSP_MODE_RSTANDBY (SUSP_SH_RSTANDBY | SUSP_SH_MMU | SUSP_SH_SF)
  35. /*
  36. * U-standby mode is unsupported since it needs bootloader hacks
  37. */
  38. #ifdef CONFIG_CPU_SUBTYPE_SH7724
  39. #define RAM_BASE 0xfd800000 /* RSMEM */
  40. #else
  41. #define RAM_BASE 0xe5200000 /* ILRAM */
  42. #endif
  43. void sh_mobile_call_standby(unsigned long mode)
  44. {
  45. void *onchip_mem = (void *)RAM_BASE;
  46. struct sh_sleep_data *sdp = onchip_mem;
  47. void (*standby_onchip_mem)(unsigned long, unsigned long);
  48. /* code located directly after data structure */
  49. standby_onchip_mem = (void *)(sdp + 1);
  50. atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
  51. mode, NULL);
  52. /* flush the caches if MMU flag is set */
  53. if (mode & SUSP_SH_MMU)
  54. flush_cache_all();
  55. /* Let assembly snippet in on-chip memory handle the rest */
  56. standby_onchip_mem(mode, RAM_BASE);
  57. atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
  58. mode, NULL);
  59. }
  60. extern char sh_mobile_sleep_enter_start;
  61. extern char sh_mobile_sleep_enter_end;
  62. extern char sh_mobile_sleep_resume_start;
  63. extern char sh_mobile_sleep_resume_end;
  64. unsigned long sh_mobile_sleep_supported = SUSP_SH_SLEEP;
  65. void sh_mobile_register_self_refresh(unsigned long flags,
  66. void *pre_start, void *pre_end,
  67. void *post_start, void *post_end)
  68. {
  69. void *onchip_mem = (void *)RAM_BASE;
  70. void *vp;
  71. struct sh_sleep_data *sdp;
  72. int n;
  73. /* part 0: data area */
  74. sdp = onchip_mem;
  75. sdp->addr.stbcr = 0xa4150020; /* STBCR */
  76. sdp->addr.bar = 0xa4150040; /* BAR */
  77. sdp->addr.pteh = 0xff000000; /* PTEH */
  78. sdp->addr.ptel = 0xff000004; /* PTEL */
  79. sdp->addr.ttb = 0xff000008; /* TTB */
  80. sdp->addr.tea = 0xff00000c; /* TEA */
  81. sdp->addr.mmucr = 0xff000010; /* MMUCR */
  82. sdp->addr.ptea = 0xff000034; /* PTEA */
  83. sdp->addr.pascr = 0xff000070; /* PASCR */
  84. sdp->addr.irmcr = 0xff000078; /* IRMCR */
  85. sdp->addr.ccr = 0xff00001c; /* CCR */
  86. sdp->addr.ramcr = 0xff000074; /* RAMCR */
  87. vp = sdp + 1;
  88. /* part 1: common code to enter sleep mode */
  89. n = &sh_mobile_sleep_enter_end - &sh_mobile_sleep_enter_start;
  90. memcpy(vp, &sh_mobile_sleep_enter_start, n);
  91. vp += roundup(n, 4);
  92. /* part 2: board specific code to enter self-refresh mode */
  93. n = pre_end - pre_start;
  94. memcpy(vp, pre_start, n);
  95. sdp->sf_pre = (unsigned long)vp;
  96. vp += roundup(n, 4);
  97. /* part 3: board specific code to resume from self-refresh mode */
  98. n = post_end - post_start;
  99. memcpy(vp, post_start, n);
  100. sdp->sf_post = (unsigned long)vp;
  101. vp += roundup(n, 4);
  102. /* part 4: common code to resume from sleep mode */
  103. WARN_ON(vp > (onchip_mem + 0x600));
  104. vp = onchip_mem + 0x600; /* located at interrupt vector */
  105. n = &sh_mobile_sleep_resume_end - &sh_mobile_sleep_resume_start;
  106. memcpy(vp, &sh_mobile_sleep_resume_start, n);
  107. sdp->resume = (unsigned long)vp;
  108. sh_mobile_sleep_supported |= flags;
  109. }
  110. static int sh_pm_enter(suspend_state_t state)
  111. {
  112. if (!(sh_mobile_sleep_supported & SUSP_MODE_STANDBY_SF))
  113. return -ENXIO;
  114. local_irq_disable();
  115. set_bl_bit();
  116. sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
  117. local_irq_disable();
  118. clear_bl_bit();
  119. return 0;
  120. }
  121. static struct platform_suspend_ops sh_pm_ops = {
  122. .enter = sh_pm_enter,
  123. .valid = suspend_valid_only_mem,
  124. };
  125. static int __init sh_pm_init(void)
  126. {
  127. suspend_set_ops(&sh_pm_ops);
  128. sh_mobile_setup_cpuidle();
  129. return 0;
  130. }
  131. late_initcall(sh_pm_init);