pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /*
  19. * Notifier lists for pre/post sleep notification
  20. */
  21. ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
  22. ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);
  23. /*
  24. * Sleep modes available on SuperH Mobile:
  25. *
  26. * Sleep mode is just plain "sleep" instruction
  27. * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
  28. * Standby Self-Refresh mode is above plus stopped clocks
  29. */
  30. #define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
  31. #define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
  32. #define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
  33. /*
  34. * The following modes are not there yet:
  35. *
  36. * R-standby mode is unsupported, but will be added in the future
  37. * U-standby mode is low priority since it needs bootloader hacks
  38. */
  39. #define ILRAM_BASE 0xe5200000
  40. void sh_mobile_call_standby(unsigned long mode)
  41. {
  42. void *onchip_mem = (void *)ILRAM_BASE;
  43. struct sh_sleep_data *sdp = onchip_mem;
  44. void (*standby_onchip_mem)(unsigned long, unsigned long);
  45. /* code located directly after data structure */
  46. standby_onchip_mem = (void *)(sdp + 1);
  47. atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
  48. mode, NULL);
  49. /* Let assembly snippet in on-chip memory handle the rest */
  50. standby_onchip_mem(mode, ILRAM_BASE);
  51. atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
  52. mode, NULL);
  53. }
  54. extern char sh_mobile_sleep_enter_start;
  55. extern char sh_mobile_sleep_enter_end;
  56. extern char sh_mobile_sleep_resume_start;
  57. extern char sh_mobile_sleep_resume_end;
  58. unsigned long sh_mobile_sleep_supported = SUSP_SH_SLEEP;
  59. void sh_mobile_register_self_refresh(unsigned long flags,
  60. void *pre_start, void *pre_end,
  61. void *post_start, void *post_end)
  62. {
  63. void *onchip_mem = (void *)ILRAM_BASE;
  64. void *vp;
  65. struct sh_sleep_data *sdp;
  66. int n;
  67. /* part 0: data area */
  68. sdp = onchip_mem;
  69. sdp->addr.stbcr = 0xa4150020; /* STBCR */
  70. vp = sdp + 1;
  71. /* part 1: common code to enter sleep mode */
  72. n = &sh_mobile_sleep_enter_end - &sh_mobile_sleep_enter_start;
  73. memcpy(vp, &sh_mobile_sleep_enter_start, n);
  74. vp += roundup(n, 4);
  75. /* part 2: board specific code to enter self-refresh mode */
  76. n = pre_end - pre_start;
  77. memcpy(vp, pre_start, n);
  78. sdp->sf_pre = (unsigned long)vp;
  79. vp += roundup(n, 4);
  80. /* part 3: board specific code to resume from self-refresh mode */
  81. n = post_end - post_start;
  82. memcpy(vp, post_start, n);
  83. sdp->sf_post = (unsigned long)vp;
  84. vp += roundup(n, 4);
  85. /* part 4: common code to resume from sleep mode */
  86. WARN_ON(vp > (onchip_mem + 0x600));
  87. vp = onchip_mem + 0x600; /* located at interrupt vector */
  88. n = &sh_mobile_sleep_resume_end - &sh_mobile_sleep_resume_start;
  89. memcpy(vp, &sh_mobile_sleep_resume_start, n);
  90. sh_mobile_sleep_supported |= flags;
  91. }
  92. static int sh_pm_enter(suspend_state_t state)
  93. {
  94. if (!(sh_mobile_sleep_supported & SUSP_MODE_STANDBY_SF))
  95. return -ENXIO;
  96. local_irq_disable();
  97. set_bl_bit();
  98. sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
  99. local_irq_disable();
  100. clear_bl_bit();
  101. return 0;
  102. }
  103. static struct platform_suspend_ops sh_pm_ops = {
  104. .enter = sh_pm_enter,
  105. .valid = suspend_valid_only_mem,
  106. };
  107. static int __init sh_pm_init(void)
  108. {
  109. suspend_set_ops(&sh_pm_ops);
  110. sh_mobile_setup_cpuidle();
  111. return 0;
  112. }
  113. late_initcall(sh_pm_init);