pm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * File: arch/blackfin/mach-common/pm.c
  3. * Based on: arm/mach-omap/pm.c
  4. * Author: Cliff Brake <cbrake@accelent.com> Copyright (c) 2001
  5. *
  6. * Created: 2001
  7. * Description: Power management for the bfin
  8. *
  9. * Modified: Nicolas Pitre - PXA250 support
  10. * Copyright (c) 2002 Monta Vista Software, Inc.
  11. * David Singleton - OMAP1510
  12. * Copyright (c) 2002 Monta Vista Software, Inc.
  13. * Dirk Behme <dirk.behme@de.bosch.com> - OMAP1510/1610
  14. * Copyright 2004
  15. * Copyright 2004-2006 Analog Devices Inc.
  16. *
  17. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, see the file COPYING, or write
  31. * to the Free Software Foundation, Inc.,
  32. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  33. */
  34. #include <linux/pm.h>
  35. #include <linux/sched.h>
  36. #include <linux/proc_fs.h>
  37. #include <asm/io.h>
  38. #include <asm/dpmc.h>
  39. #include <asm/irq.h>
  40. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_H
  41. #define WAKEUP_TYPE PM_WAKE_HIGH
  42. #endif
  43. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_L
  44. #define WAKEUP_TYPE PM_WAKE_LOW
  45. #endif
  46. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_F
  47. #define WAKEUP_TYPE PM_WAKE_FALLING
  48. #endif
  49. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_R
  50. #define WAKEUP_TYPE PM_WAKE_RISING
  51. #endif
  52. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_B
  53. #define WAKEUP_TYPE PM_WAKE_BOTH_EDGES
  54. #endif
  55. void bfin_pm_suspend_standby_enter(void)
  56. {
  57. #ifdef CONFIG_PM_WAKEUP_BY_GPIO
  58. gpio_pm_wakeup_request(CONFIG_PM_WAKEUP_GPIO_NUMBER, WAKEUP_TYPE);
  59. #endif
  60. #if defined(CONFIG_PM_WAKEUP_BY_GPIO) || defined(CONFIG_PM_WAKEUP_GPIO_API)
  61. {
  62. u32 flags;
  63. local_irq_save(flags);
  64. sleep_deeper(gpio_pm_setup()); /*Goto Sleep*/
  65. gpio_pm_restore();
  66. bfin_write_SIC_IWR(IWR_ENABLE_ALL);
  67. local_irq_restore(flags);
  68. }
  69. #endif
  70. #if defined(CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR)
  71. sleep_deeper(CONFIG_PM_WAKEUP_SIC_IWR);
  72. bfin_write_SIC_IWR(IWR_ENABLE_ALL);
  73. #endif /* CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR */
  74. }
  75. /*
  76. * bfin_pm_prepare - Do preliminary suspend work.
  77. * @state: suspend state we're entering.
  78. *
  79. */
  80. static int bfin_pm_prepare(suspend_state_t state)
  81. {
  82. int error = 0;
  83. switch (state) {
  84. case PM_SUSPEND_STANDBY:
  85. break;
  86. case PM_SUSPEND_MEM:
  87. return -ENOTSUPP;
  88. case PM_SUSPEND_DISK:
  89. return -ENOTSUPP;
  90. default:
  91. return -EINVAL;
  92. }
  93. return error;
  94. }
  95. /*
  96. * bfin_pm_enter - Actually enter a sleep state.
  97. * @state: State we're entering.
  98. *
  99. */
  100. static int bfin_pm_enter(suspend_state_t state)
  101. {
  102. switch (state) {
  103. case PM_SUSPEND_STANDBY:
  104. bfin_pm_suspend_standby_enter();
  105. break;
  106. case PM_SUSPEND_MEM:
  107. return -ENOTSUPP;
  108. case PM_SUSPEND_DISK:
  109. return -ENOTSUPP;
  110. default:
  111. return -EINVAL;
  112. }
  113. return 0;
  114. }
  115. /*
  116. * bfin_pm_finish - Finish up suspend sequence.
  117. * @state: State we're coming out of.
  118. *
  119. * This is called after we wake back up (or if entering the sleep state
  120. * failed).
  121. */
  122. static int bfin_pm_finish(suspend_state_t state)
  123. {
  124. switch (state) {
  125. case PM_SUSPEND_STANDBY:
  126. break;
  127. case PM_SUSPEND_MEM:
  128. return -ENOTSUPP;
  129. case PM_SUSPEND_DISK:
  130. return -ENOTSUPP;
  131. default:
  132. return -EINVAL;
  133. }
  134. return 0;
  135. }
  136. struct pm_ops bfin_pm_ops = {
  137. .pm_disk_mode = PM_DISK_PLATFORM,
  138. .prepare = bfin_pm_prepare,
  139. .enter = bfin_pm_enter,
  140. .finish = bfin_pm_finish,
  141. };
  142. static int __init bfin_pm_init(void)
  143. {
  144. pm_set_ops(&bfin_pm_ops);
  145. return 0;
  146. }
  147. __initcall(bfin_pm_init);