]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - arch/blackfin/mach-common/pm.c
blackfin: bf60x: fix compiling warning
[linux-3.10.git] / arch / blackfin / mach-common / pm.c
1 /*
2  * Blackfin power management
3  *
4  * Copyright 2006-2009 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2
7  * based on arm/mach-omap/pm.c
8  *    Copyright 2001, Cliff Brake <cbrake@accelent.com> and others
9  */
10
11 #include <linux/suspend.h>
12 #include <linux/sched.h>
13 #include <linux/proc_fs.h>
14 #include <linux/slab.h>
15 #include <linux/io.h>
16 #include <linux/irq.h>
17
18 #include <asm/cplb.h>
19 #include <asm/gpio.h>
20 #include <asm/dma.h>
21 #include <asm/dpmc.h>
22 #include <asm/pm.h>
23
24 #ifdef CONFIG_BF60x
25 struct bfin_cpu_pm_fns *bfin_cpu_pm;
26 #endif
27
28 void bfin_pm_suspend_standby_enter(void)
29 {
30 #ifndef CONFIG_BF60x
31         bfin_pm_standby_setup();
32 #endif
33
34 #ifdef CONFIG_BF60x
35         bfin_cpu_pm->enter(PM_SUSPEND_STANDBY);
36 #else
37 # ifdef CONFIG_PM_BFIN_SLEEP_DEEPER
38         sleep_deeper(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]);
39 # else
40         sleep_mode(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]);
41 # endif
42 #endif
43
44 #ifndef CONFIG_BF60x
45         bfin_pm_standby_restore();
46 #endif
47
48 #ifndef CONFIG_BF60x
49 #ifdef SIC_IWR0
50         bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
51 # ifdef SIC_IWR1
52         /* BF52x system reset does not properly reset SIC_IWR1 which
53          * will screw up the bootrom as it relies on MDMA0/1 waking it
54          * up from IDLE instructions.  See this report for more info:
55          * http://blackfin.uclinux.org/gf/tracker/4323
56          */
57         if (ANOMALY_05000435)
58                 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
59         else
60                 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
61 # endif
62 # ifdef SIC_IWR2
63         bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
64 # endif
65 #else
66         bfin_write_SIC_IWR(IWR_DISABLE_ALL);
67 #endif
68
69 #endif
70 }
71
72 int bf53x_suspend_l1_mem(unsigned char *memptr)
73 {
74         dma_memcpy_nocache(memptr, (const void *) L1_CODE_START,
75                         L1_CODE_LENGTH);
76         dma_memcpy_nocache(memptr + L1_CODE_LENGTH,
77                         (const void *) L1_DATA_A_START, L1_DATA_A_LENGTH);
78         dma_memcpy_nocache(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH,
79                         (const void *) L1_DATA_B_START, L1_DATA_B_LENGTH);
80         memcpy(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH +
81                         L1_DATA_B_LENGTH, (const void *) L1_SCRATCH_START,
82                         L1_SCRATCH_LENGTH);
83
84         return 0;
85 }
86
87 int bf53x_resume_l1_mem(unsigned char *memptr)
88 {
89         dma_memcpy_nocache((void *) L1_CODE_START, memptr, L1_CODE_LENGTH);
90         dma_memcpy_nocache((void *) L1_DATA_A_START, memptr + L1_CODE_LENGTH,
91                         L1_DATA_A_LENGTH);
92         dma_memcpy_nocache((void *) L1_DATA_B_START, memptr + L1_CODE_LENGTH +
93                         L1_DATA_A_LENGTH, L1_DATA_B_LENGTH);
94         memcpy((void *) L1_SCRATCH_START, memptr + L1_CODE_LENGTH +
95                         L1_DATA_A_LENGTH + L1_DATA_B_LENGTH, L1_SCRATCH_LENGTH);
96
97         return 0;
98 }
99
100 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
101 # ifdef CONFIG_BF60x
102 __attribute__((l1_text))
103 # endif
104 static void flushinv_all_dcache(void)
105 {
106         register u32 way, bank, subbank, set;
107         register u32 status, addr;
108         u32 dmem_ctl = bfin_read_DMEM_CONTROL();
109
110         for (bank = 0; bank < 2; ++bank) {
111                 if (!(dmem_ctl & (1 << (DMC1_P - bank))))
112                         continue;
113
114                 for (way = 0; way < 2; ++way)
115                         for (subbank = 0; subbank < 4; ++subbank)
116                                 for (set = 0; set < 64; ++set) {
117
118                                         bfin_write_DTEST_COMMAND(
119                                                 way << 26 |
120                                                 bank << 23 |
121                                                 subbank << 16 |
122                                                 set << 5
123                                         );
124                                         CSYNC();
125                                         status = bfin_read_DTEST_DATA0();
126
127                                         /* only worry about valid/dirty entries */
128                                         if ((status & 0x3) != 0x3)
129                                                 continue;
130
131                                         /* construct the address using the tag */
132                                         addr = (status & 0xFFFFC800) | (subbank << 12) | (set << 5);
133
134                                         /* flush it */
135                                         __asm__ __volatile__("FLUSHINV[%0];" : : "a"(addr));
136                                 }
137         }
138 }
139 #endif
140
141 int bfin_pm_suspend_mem_enter(void)
142 {
143         int wakeup, ret;
144
145         unsigned char *memptr = kmalloc(L1_CODE_LENGTH + L1_DATA_A_LENGTH
146                                          + L1_DATA_B_LENGTH + L1_SCRATCH_LENGTH,
147                                           GFP_KERNEL);
148
149         if (memptr == NULL) {
150                 panic("bf53x_suspend_l1_mem malloc failed");
151                 return -ENOMEM;
152         }
153
154 #ifndef CONFIG_BF60x
155         wakeup = bfin_read_VR_CTL() & ~FREQ;
156 #else
157
158 #endif
159         wakeup |= SCKELOW;
160
161 #ifdef CONFIG_PM_BFIN_WAKE_PH6
162         wakeup |= PHYWE;
163 #endif
164 #ifdef CONFIG_PM_BFIN_WAKE_GP
165         wakeup |= GPWE;
166 #endif
167
168         ret = blackfin_dma_suspend();
169
170         if (ret) {
171                 kfree(memptr);
172                 return ret;
173         }
174
175         bfin_gpio_pm_hibernate_suspend();
176
177 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
178         flushinv_all_dcache();
179 #endif
180         _disable_dcplb();
181         _disable_icplb();
182         bf53x_suspend_l1_mem(memptr);
183
184 #ifndef CONFIG_BF60x
185         do_hibernate(wakeup | vr_wakeup);       /* See you later! */
186 #else
187         bfin_cpu_pm->enter(PM_SUSPEND_MEM);
188 #endif
189
190         bf53x_resume_l1_mem(memptr);
191
192         _enable_icplb();
193         _enable_dcplb();
194
195         bfin_gpio_pm_hibernate_restore();
196         blackfin_dma_resume();
197
198         kfree(memptr);
199
200         return 0;
201 }
202
203 /*
204  *      bfin_pm_valid - Tell the PM core that we only support the standby sleep
205  *                      state
206  *      @state:         suspend state we're checking.
207  *
208  */
209 static int bfin_pm_valid(suspend_state_t state)
210 {
211         return (state == PM_SUSPEND_STANDBY
212 #if !(defined(BF533_FAMILY) || defined(CONFIG_BF561))
213         /*
214          * On BF533/2/1:
215          * If we enter Hibernate the SCKE Pin is driven Low,
216          * so that the SDRAM enters Self Refresh Mode.
217          * However when the reset sequence that follows hibernate
218          * state is executed, SCKE is driven High, taking the
219          * SDRAM out of Self Refresh.
220          *
221          * If you reconfigure and access the SDRAM "very quickly",
222          * you are likely to avoid errors, otherwise the SDRAM
223          * start losing its contents.
224          * An external HW workaround is possible using logic gates.
225          */
226         || state == PM_SUSPEND_MEM
227 #endif
228         );
229 }
230
231 /*
232  *      bfin_pm_enter - Actually enter a sleep state.
233  *      @state:         State we're entering.
234  *
235  */
236 static int bfin_pm_enter(suspend_state_t state)
237 {
238         switch (state) {
239         case PM_SUSPEND_STANDBY:
240                 bfin_pm_suspend_standby_enter();
241                 break;
242         case PM_SUSPEND_MEM:
243                 bfin_pm_suspend_mem_enter();
244                 break;
245         default:
246                 return -EINVAL;
247         }
248
249         return 0;
250 }
251
252 static const struct platform_suspend_ops bfin_pm_ops = {
253         .enter = bfin_pm_enter,
254         .valid  = bfin_pm_valid,
255 };
256
257 static int __init bfin_pm_init(void)
258 {
259         suspend_set_ops(&bfin_pm_ops);
260         return 0;
261 }
262
263 __initcall(bfin_pm_init);