pm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/suspend.h>
  35. #include <linux/sched.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/io.h>
  38. #include <linux/irq.h>
  39. #include <asm/dpmc.h>
  40. #include <asm/gpio.h>
  41. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_H
  42. #define WAKEUP_TYPE PM_WAKE_HIGH
  43. #endif
  44. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_L
  45. #define WAKEUP_TYPE PM_WAKE_LOW
  46. #endif
  47. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_F
  48. #define WAKEUP_TYPE PM_WAKE_FALLING
  49. #endif
  50. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_R
  51. #define WAKEUP_TYPE PM_WAKE_RISING
  52. #endif
  53. #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_B
  54. #define WAKEUP_TYPE PM_WAKE_BOTH_EDGES
  55. #endif
  56. void bfin_pm_suspend_standby_enter(void)
  57. {
  58. #ifdef CONFIG_PM_WAKEUP_BY_GPIO
  59. gpio_pm_wakeup_request(CONFIG_PM_WAKEUP_GPIO_NUMBER, WAKEUP_TYPE);
  60. #endif
  61. #if defined(CONFIG_PM_WAKEUP_BY_GPIO) || defined(CONFIG_PM_WAKEUP_GPIO_API)
  62. {
  63. u32 flags;
  64. local_irq_save(flags);
  65. sleep_deeper(gpio_pm_setup()); /*Goto Sleep*/
  66. gpio_pm_restore();
  67. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x)
  68. bfin_write_SIC_IWR0(IWR_ENABLE_ALL);
  69. bfin_write_SIC_IWR1(IWR_ENABLE_ALL);
  70. # ifdef CONFIG_BF54x
  71. bfin_write_SIC_IWR2(IWR_ENABLE_ALL);
  72. # endif
  73. #else
  74. bfin_write_SIC_IWR(IWR_ENABLE_ALL);
  75. #endif
  76. local_irq_restore(flags);
  77. }
  78. #endif
  79. #if defined(CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR)
  80. sleep_deeper(CONFIG_PM_WAKEUP_SIC_IWR);
  81. # if defined(CONFIG_BF54x) || defined(CONFIG_BF52x)
  82. bfin_write_SIC_IWR0(IWR_ENABLE_ALL);
  83. bfin_write_SIC_IWR1(IWR_ENABLE_ALL);
  84. # ifdef CONFIG_BF54x
  85. bfin_write_SIC_IWR2(IWR_ENABLE_ALL);
  86. # endif
  87. # else
  88. bfin_write_SIC_IWR(IWR_ENABLE_ALL);
  89. # endif
  90. #endif /* CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR */
  91. }
  92. /*
  93. * bfin_pm_valid - Tell the PM core that we only support the standby sleep
  94. * state
  95. * @state: suspend state we're checking.
  96. *
  97. */
  98. static int bfin_pm_valid(suspend_state_t state)
  99. {
  100. return (state == PM_SUSPEND_STANDBY);
  101. }
  102. /*
  103. * bfin_pm_enter - Actually enter a sleep state.
  104. * @state: State we're entering.
  105. *
  106. */
  107. static int bfin_pm_enter(suspend_state_t state)
  108. {
  109. switch (state) {
  110. case PM_SUSPEND_STANDBY:
  111. bfin_pm_suspend_standby_enter();
  112. break;
  113. case PM_SUSPEND_MEM:
  114. return -ENOTSUPP;
  115. default:
  116. return -EINVAL;
  117. }
  118. return 0;
  119. }
  120. struct platform_suspend_ops bfin_pm_ops = {
  121. .enter = bfin_pm_enter,
  122. .valid = bfin_pm_valid,
  123. };
  124. static int __init bfin_pm_init(void)
  125. {
  126. suspend_set_ops(&bfin_pm_ops);
  127. return 0;
  128. }
  129. __initcall(bfin_pm_init);