Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 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 |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 7 | * Description: Blackfin power management |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 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 |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 15 | * Copyright 2004-2008 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 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 | |
Rafael J. Wysocki | 95d9ffb | 2007-10-18 03:04:39 -0700 | [diff] [blame] | 35 | #include <linux/suspend.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 36 | #include <linux/sched.h> |
| 37 | #include <linux/proc_fs.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 38 | #include <linux/io.h> |
| 39 | #include <linux/irq.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 40 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 41 | #include <asm/dpmc.h> |
Michael Hennerich | fd92348 | 2007-06-11 16:39:40 +0800 | [diff] [blame] | 42 | #include <asm/gpio.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 43 | |
| 44 | #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_H |
| 45 | #define WAKEUP_TYPE PM_WAKE_HIGH |
| 46 | #endif |
| 47 | |
| 48 | #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_L |
| 49 | #define WAKEUP_TYPE PM_WAKE_LOW |
| 50 | #endif |
| 51 | |
| 52 | #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_F |
| 53 | #define WAKEUP_TYPE PM_WAKE_FALLING |
| 54 | #endif |
| 55 | |
| 56 | #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_R |
| 57 | #define WAKEUP_TYPE PM_WAKE_RISING |
| 58 | #endif |
| 59 | |
| 60 | #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_B |
| 61 | #define WAKEUP_TYPE PM_WAKE_BOTH_EDGES |
| 62 | #endif |
| 63 | |
| 64 | void bfin_pm_suspend_standby_enter(void) |
| 65 | { |
| 66 | #ifdef CONFIG_PM_WAKEUP_BY_GPIO |
| 67 | gpio_pm_wakeup_request(CONFIG_PM_WAKEUP_GPIO_NUMBER, WAKEUP_TYPE); |
| 68 | #endif |
| 69 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 70 | u32 flags; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 71 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 72 | local_irq_save(flags); |
| 73 | bfin_pm_setup(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 74 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 75 | #ifdef CONFIG_PM_BFIN_SLEEP_DEEPER |
| 76 | sleep_deeper(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]); |
Sonic Zhang | fb5f004 | 2007-12-23 23:02:13 +0800 | [diff] [blame] | 77 | #else |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 78 | sleep_mode(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]); |
Sonic Zhang | fb5f004 | 2007-12-23 23:02:13 +0800 | [diff] [blame] | 79 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 80 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 81 | bfin_pm_restore(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 82 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 83 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) |
Sonic Zhang | fb5f004 | 2007-12-23 23:02:13 +0800 | [diff] [blame] | 84 | bfin_write_SIC_IWR0(IWR_ENABLE_ALL); |
| 85 | bfin_write_SIC_IWR1(IWR_ENABLE_ALL); |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 86 | # ifdef CONFIG_BF54x |
Sonic Zhang | fb5f004 | 2007-12-23 23:02:13 +0800 | [diff] [blame] | 87 | bfin_write_SIC_IWR2(IWR_ENABLE_ALL); |
Sonic Zhang | fb5f004 | 2007-12-23 23:02:13 +0800 | [diff] [blame] | 88 | # endif |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame^] | 89 | #else |
| 90 | bfin_write_SIC_IWR(IWR_ENABLE_ALL); |
| 91 | #endif |
| 92 | |
| 93 | local_irq_restore(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 96 | /* |
Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 97 | * bfin_pm_valid - Tell the PM core that we only support the standby sleep |
| 98 | * state |
| 99 | * @state: suspend state we're checking. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 100 | * |
| 101 | */ |
Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 102 | static int bfin_pm_valid(suspend_state_t state) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 103 | { |
Rafael J. Wysocki | e6c5eb9 | 2007-10-18 03:04:41 -0700 | [diff] [blame] | 104 | return (state == PM_SUSPEND_STANDBY); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * bfin_pm_enter - Actually enter a sleep state. |
| 109 | * @state: State we're entering. |
| 110 | * |
| 111 | */ |
| 112 | static int bfin_pm_enter(suspend_state_t state) |
| 113 | { |
| 114 | switch (state) { |
| 115 | case PM_SUSPEND_STANDBY: |
| 116 | bfin_pm_suspend_standby_enter(); |
| 117 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 118 | |
Bryan Wu | 9d7b667 | 2007-05-21 18:09:37 +0800 | [diff] [blame] | 119 | case PM_SUSPEND_MEM: |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 120 | return -ENOTSUPP; |
| 121 | |
| 122 | default: |
| 123 | return -EINVAL; |
| 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 129 | struct platform_suspend_ops bfin_pm_ops = { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 130 | .enter = bfin_pm_enter, |
Michael Hennerich | 4bbd10f | 2007-08-27 17:29:10 +0800 | [diff] [blame] | 131 | .valid = bfin_pm_valid, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static int __init bfin_pm_init(void) |
| 135 | { |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 136 | suspend_set_ops(&bfin_pm_ops); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | __initcall(bfin_pm_init); |