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
7 * Description: Blackfin power management
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
15 * Copyright 2004-2008 Analog Devices Inc.
17 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
35 #include <linux/suspend.h>
36 #include <linux/sched.h>
37 #include <linux/proc_fs.h>
39 #include <linux/irq.h>
45 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_H
46 #define WAKEUP_TYPE PM_WAKE_HIGH
49 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_L
50 #define WAKEUP_TYPE PM_WAKE_LOW
53 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_F
54 #define WAKEUP_TYPE PM_WAKE_FALLING
57 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_R
58 #define WAKEUP_TYPE PM_WAKE_RISING
61 #ifdef CONFIG_PM_WAKEUP_GPIO_POLAR_EDGE_B
62 #define WAKEUP_TYPE PM_WAKE_BOTH_EDGES
66 void bfin_pm_suspend_standby_enter(void)
70 #ifdef CONFIG_PM_WAKEUP_BY_GPIO
71 gpio_pm_wakeup_request(CONFIG_PM_WAKEUP_GPIO_NUMBER
, WAKEUP_TYPE
);
74 local_irq_save_hw(flags
);
75 bfin_pm_standby_setup();
77 #ifdef CONFIG_PM_BFIN_SLEEP_DEEPER
78 sleep_deeper(bfin_sic_iwr
[0], bfin_sic_iwr
[1], bfin_sic_iwr
[2]);
80 sleep_mode(bfin_sic_iwr
[0], bfin_sic_iwr
[1], bfin_sic_iwr
[2]);
83 bfin_pm_standby_restore();
86 bfin_write_SIC_IWR0(IWR_DISABLE_ALL
);
88 /* BF52x system reset does not properly reset SIC_IWR1 which
89 * will screw up the bootrom as it relies on MDMA0/1 waking it
90 * up from IDLE instructions. See this report for more info:
91 * http://blackfin.uclinux.org/gf/tracker/4323
94 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
96 bfin_write_SIC_IWR1(IWR_DISABLE_ALL
);
99 bfin_write_SIC_IWR2(IWR_DISABLE_ALL
);
102 bfin_write_SIC_IWR(IWR_DISABLE_ALL
);
105 local_irq_restore_hw(flags
);
108 int bf53x_suspend_l1_mem(unsigned char *memptr
)
110 dma_memcpy(memptr
, (const void *) L1_CODE_START
, L1_CODE_LENGTH
);
111 dma_memcpy(memptr
+ L1_CODE_LENGTH
, (const void *) L1_DATA_A_START
,
113 dma_memcpy(memptr
+ L1_CODE_LENGTH
+ L1_DATA_A_LENGTH
,
114 (const void *) L1_DATA_B_START
, L1_DATA_B_LENGTH
);
115 memcpy(memptr
+ L1_CODE_LENGTH
+ L1_DATA_A_LENGTH
+
116 L1_DATA_B_LENGTH
, (const void *) L1_SCRATCH_START
,
122 int bf53x_resume_l1_mem(unsigned char *memptr
)
124 dma_memcpy((void *) L1_CODE_START
, memptr
, L1_CODE_LENGTH
);
125 dma_memcpy((void *) L1_DATA_A_START
, memptr
+ L1_CODE_LENGTH
,
127 dma_memcpy((void *) L1_DATA_B_START
, memptr
+ L1_CODE_LENGTH
+
128 L1_DATA_A_LENGTH
, L1_DATA_B_LENGTH
);
129 memcpy((void *) L1_SCRATCH_START
, memptr
+ L1_CODE_LENGTH
+
130 L1_DATA_A_LENGTH
+ L1_DATA_B_LENGTH
, L1_SCRATCH_LENGTH
);
135 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
136 static void flushinv_all_dcache(void)
138 u32 way
, bank
, subbank
, set
;
140 u32 dmem_ctl
= bfin_read_DMEM_CONTROL();
142 for (bank
= 0; bank
< 2; ++bank
) {
143 if (!(dmem_ctl
& (1 << (DMC1_P
- bank
))))
146 for (way
= 0; way
< 2; ++way
)
147 for (subbank
= 0; subbank
< 4; ++subbank
)
148 for (set
= 0; set
< 64; ++set
) {
150 bfin_write_DTEST_COMMAND(
157 status
= bfin_read_DTEST_DATA0();
159 /* only worry about valid/dirty entries */
160 if ((status
& 0x3) != 0x3)
163 /* construct the address using the tag */
164 addr
= (status
& 0xFFFFC800) | (subbank
<< 12) | (set
<< 5);
167 __asm__
__volatile__("FLUSHINV[%0];" : : "a"(addr
));
173 static inline void dcache_disable(void)
175 #ifdef CONFIG_BFIN_DCACHE
178 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
179 flushinv_all_dcache();
182 ctrl
= bfin_read_DMEM_CONTROL();
184 bfin_write_DMEM_CONTROL(ctrl
);
189 static inline void dcache_enable(void)
191 #ifdef CONFIG_BFIN_DCACHE
194 ctrl
= bfin_read_DMEM_CONTROL();
196 bfin_write_DMEM_CONTROL(ctrl
);
201 static inline void icache_disable(void)
203 #ifdef CONFIG_BFIN_ICACHE
206 ctrl
= bfin_read_IMEM_CONTROL();
208 bfin_write_IMEM_CONTROL(ctrl
);
213 static inline void icache_enable(void)
215 #ifdef CONFIG_BFIN_ICACHE
218 ctrl
= bfin_read_IMEM_CONTROL();
220 bfin_write_IMEM_CONTROL(ctrl
);
225 int bfin_pm_suspend_mem_enter(void)
230 unsigned char *memptr
= kmalloc(L1_CODE_LENGTH
+ L1_DATA_A_LENGTH
231 + L1_DATA_B_LENGTH
+ L1_SCRATCH_LENGTH
,
234 if (memptr
== NULL
) {
235 panic("bf53x_suspend_l1_mem malloc failed");
239 wakeup
= bfin_read_VR_CTL() & ~FREQ
;
242 #ifdef CONFIG_PM_BFIN_WAKE_PH6
245 #ifdef CONFIG_PM_BFIN_WAKE_GP
249 local_irq_save_hw(flags
);
251 ret
= blackfin_dma_suspend();
254 local_irq_restore_hw(flags
);
259 bfin_gpio_pm_hibernate_suspend();
263 bf53x_suspend_l1_mem(memptr
);
265 do_hibernate(wakeup
| vr_wakeup
); /* Goodbye */
267 bf53x_resume_l1_mem(memptr
);
272 bfin_gpio_pm_hibernate_restore();
273 blackfin_dma_resume();
275 local_irq_restore_hw(flags
);
282 * bfin_pm_valid - Tell the PM core that we only support the standby sleep
284 * @state: suspend state we're checking.
287 static int bfin_pm_valid(suspend_state_t state
)
289 return (state
== PM_SUSPEND_STANDBY
290 #if !(defined(BF533_FAMILY) || defined(CONFIG_BF561))
293 * If we enter Hibernate the SCKE Pin is driven Low,
294 * so that the SDRAM enters Self Refresh Mode.
295 * However when the reset sequence that follows hibernate
296 * state is executed, SCKE is driven High, taking the
297 * SDRAM out of Self Refresh.
299 * If you reconfigure and access the SDRAM "very quickly",
300 * you are likely to avoid errors, otherwise the SDRAM
301 * start losing its contents.
302 * An external HW workaround is possible using logic gates.
304 || state
== PM_SUSPEND_MEM
310 * bfin_pm_enter - Actually enter a sleep state.
311 * @state: State we're entering.
314 static int bfin_pm_enter(suspend_state_t state
)
317 case PM_SUSPEND_STANDBY
:
318 bfin_pm_suspend_standby_enter();
321 bfin_pm_suspend_mem_enter();
330 struct platform_suspend_ops bfin_pm_ops
= {
331 .enter
= bfin_pm_enter
,
332 .valid
= bfin_pm_valid
,
335 static int __init
bfin_pm_init(void)
337 suspend_set_ops(&bfin_pm_ops
);
341 __initcall(bfin_pm_init
);