2 * Enter and leave deep sleep state on MPC83xx
4 * Copyright (c) 2006-2008 Freescale Semiconductor, Inc.
5 * Author: Scott Wood <scottwood@freescale.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
13 #include <asm/ppc_asm.h>
15 #include <asm/asm-offsets.h>
17 #define SS_MEMSAVE 0x00 /* First 8 bytes of RAM */
18 #define SS_HID 0x08 /* 3 HIDs */
19 #define SS_IABR 0x14 /* 2 IABRs */
21 #define SS_DABR 0x20 /* 2 DABRs */
24 #define SS_SR 0x30 /* 16 segment registers */
29 #define SS_SPRG 0x80 /* 4 SPRGs */
30 #define SS_DBAT 0x90 /* 8 DBATs */
31 #define SS_IBAT 0xd0 /* 8 IBATs */
34 #define SS_GPREG 0x11c /* r12-r31 */
35 #define STATE_SAVE_SIZE 0x16c
40 mpc83xx_sleep_save_area:
41 .space STATE_SAVE_SIZE
48 /* r3 = physical address of IMMR */
49 _GLOBAL(mpc83xx_enter_deep_sleep)
51 stw r3, immrbase@l(r4)
53 /* The first 2 words of memory are used to communicate with the
54 * bootloader, to tell it how to resume.
56 * The first word is the magic number 0xf5153ae5, and the second
57 * is the pointer to mpc83xx_deep_resume.
59 * The original content of these two words is saved in SS_MEMSAVE.
62 lis r3, mpc83xx_sleep_save_area@h
63 ori r3, r3, mpc83xx_sleep_save_area@l
69 stw r5, SS_MEMSAVE+0(r3)
70 stw r6, SS_MEMSAVE+4(r3)
100 stw r4, SS_SPRG+0(r3)
101 stw r5, SS_SPRG+4(r3)
102 stw r6, SS_SPRG+8(r3)
103 stw r7, SS_SPRG+12(r3)
106 mfspr r4, SPRN_DBAT0U
107 mfspr r5, SPRN_DBAT0L
108 mfspr r6, SPRN_DBAT1U
109 mfspr r7, SPRN_DBAT1L
111 stw r4, SS_DBAT+0x00(r3)
112 stw r5, SS_DBAT+0x04(r3)
113 stw r6, SS_DBAT+0x08(r3)
114 stw r7, SS_DBAT+0x0c(r3)
116 mfspr r4, SPRN_DBAT2U
117 mfspr r5, SPRN_DBAT2L
118 mfspr r6, SPRN_DBAT3U
119 mfspr r7, SPRN_DBAT3L
121 stw r4, SS_DBAT+0x10(r3)
122 stw r5, SS_DBAT+0x14(r3)
123 stw r6, SS_DBAT+0x18(r3)
124 stw r7, SS_DBAT+0x1c(r3)
126 mfspr r4, SPRN_DBAT4U
127 mfspr r5, SPRN_DBAT4L
128 mfspr r6, SPRN_DBAT5U
129 mfspr r7, SPRN_DBAT5L
131 stw r4, SS_DBAT+0x20(r3)
132 stw r5, SS_DBAT+0x24(r3)
133 stw r6, SS_DBAT+0x28(r3)
134 stw r7, SS_DBAT+0x2c(r3)
136 mfspr r4, SPRN_DBAT6U
137 mfspr r5, SPRN_DBAT6L
138 mfspr r6, SPRN_DBAT7U
139 mfspr r7, SPRN_DBAT7L
141 stw r4, SS_DBAT+0x30(r3)
142 stw r5, SS_DBAT+0x34(r3)
143 stw r6, SS_DBAT+0x38(r3)
144 stw r7, SS_DBAT+0x3c(r3)
146 mfspr r4, SPRN_IBAT0U
147 mfspr r5, SPRN_IBAT0L
148 mfspr r6, SPRN_IBAT1U
149 mfspr r7, SPRN_IBAT1L
151 stw r4, SS_IBAT+0x00(r3)
152 stw r5, SS_IBAT+0x04(r3)
153 stw r6, SS_IBAT+0x08(r3)
154 stw r7, SS_IBAT+0x0c(r3)
156 mfspr r4, SPRN_IBAT2U
157 mfspr r5, SPRN_IBAT2L
158 mfspr r6, SPRN_IBAT3U
159 mfspr r7, SPRN_IBAT3L
161 stw r4, SS_IBAT+0x10(r3)
162 stw r5, SS_IBAT+0x14(r3)
163 stw r6, SS_IBAT+0x18(r3)
164 stw r7, SS_IBAT+0x1c(r3)
166 mfspr r4, SPRN_IBAT4U
167 mfspr r5, SPRN_IBAT4L
168 mfspr r6, SPRN_IBAT5U
169 mfspr r7, SPRN_IBAT5L
171 stw r4, SS_IBAT+0x20(r3)
172 stw r5, SS_IBAT+0x24(r3)
173 stw r6, SS_IBAT+0x28(r3)
174 stw r7, SS_IBAT+0x2c(r3)
176 mfspr r4, SPRN_IBAT6U
177 mfspr r5, SPRN_IBAT6L
178 mfspr r6, SPRN_IBAT7U
179 mfspr r7, SPRN_IBAT7L
181 stw r4, SS_IBAT+0x30(r3)
182 stw r5, SS_IBAT+0x34(r3)
183 stw r6, SS_IBAT+0x38(r3)
184 stw r7, SS_IBAT+0x3c(r3)
205 stmw r12, SS_GPREG(r3)
215 /* Disable machine checks and critical exceptions */
217 rlwinm r4, r4, 0, ~MSR_CE
218 rlwinm r4, r4, 0, ~MSR_ME
222 #define TMP_VIRT_IMMR 0xf0000000
223 #define DEFAULT_IMMR_VALUE 0xff400000
224 #define IMMRBAR_BASE 0x0000
227 lwz r4, immrbase@l(r4)
229 /* Use DBAT0 to address the current IMMR space */
232 mtspr SPRN_DBAT0L, r4
233 lis r8, TMP_VIRT_IMMR@h
234 ori r4, r8, 0x001e /* 1 MByte accessable from Kernel Space only */
235 mtspr SPRN_DBAT0U, r4
238 /* Use DBAT1 to address the original IMMR space */
240 lis r4, DEFAULT_IMMR_VALUE@h
242 mtspr SPRN_DBAT1L, r4
243 lis r9, (TMP_VIRT_IMMR + 0x01000000)@h
244 ori r4, r9, 0x001e /* 1 MByte accessable from Kernel Space only */
245 mtspr SPRN_DBAT1U, r4
248 /* Use DBAT2 to address the beginning of RAM. This isn't done
249 * using the normal virtual mapping, because with page debugging
250 * enabled it will be read-only.
254 mtspr SPRN_DBAT2L, r4
256 ori r4, r4, 0x001e /* 1 MByte accessable from Kernel Space only */
257 mtspr SPRN_DBAT2U, r4
260 /* Flush the cache with our BAT, as there will be TLB misses
261 * otherwise if page debugging is enabled, and these misses
262 * will disturb the PLRU algorithm.
265 bl __flush_disable_L1
267 /* Keep the i-cache enabled, so the hack below for low-boot
278 lis r7, mpc83xx_deep_resume@h
279 ori r7, r7, mpc83xx_deep_resume@l
296 /* Rev 1 of the 8313 has problems with wakeup events that are
297 * pending during the transition to deep sleep state (such as if
298 * the PCI host sets the state to D3 and then D0 in rapid
299 * succession). This check shrinks the race window somewhat.
301 * See erratum PCI23, though the problem is not limited
307 bne- mpc83xx_deep_resume
309 /* Move IMMR back to the default location, following the
310 * procedure specified in the MPC8313 manual.
312 lwz r4, IMMRBAR_BASE(r8)
314 lis r4, DEFAULT_IMMR_VALUE@h
315 stw r4, IMMRBAR_BASE(r8)
319 lwz r4, IMMRBAR_BASE(r9)
323 /* Check the Reset Configuration Word to see whether flash needs
324 * to be mapped at a low address or a high address.
328 andis. r4, r4, 0x0400
338 rlwinm r5, r5, 0, ~(HID0_DOZE | HID0_NAP)
339 oris r5, r5, HID0_SLEEP@h
344 oris r5, r5, MSR_POW@h
346 /* Enable the flash mapping at the appropriate address. This
347 * mapping will override the RAM mapping if booting low, so there's
348 * no need to disable the latter. This must be done inside the same
349 * cache line as setting MSR_POW, so that no instruction fetches
350 * from RAM happen after the flash mapping is turned on.
368 rlwinm r4, r4, 0, ~(MSR_IR | MSR_DR)
376 lis r3, mpc83xx_sleep_save_area@h
377 ori r3, r3, mpc83xx_sleep_save_area@l
380 lwz r5, SS_MEMSAVE+0(r3)
381 lwz r6, SS_MEMSAVE+4(r3)
394 lwz r4, SS_IABR+0(r3)
395 lwz r5, SS_IABR+4(r3)
397 lwz r7, SS_DABR+0(r3)
398 lwz r8, SS_DABR+4(r3)
416 lwz r4, SS_DBAT+0x00(r3)
417 lwz r5, SS_DBAT+0x04(r3)
418 lwz r6, SS_DBAT+0x08(r3)
419 lwz r7, SS_DBAT+0x0c(r3)
421 mtspr SPRN_DBAT0U, r4
422 mtspr SPRN_DBAT0L, r5
423 mtspr SPRN_DBAT1U, r6
424 mtspr SPRN_DBAT1L, r7
426 lwz r4, SS_DBAT+0x10(r3)
427 lwz r5, SS_DBAT+0x14(r3)
428 lwz r6, SS_DBAT+0x18(r3)
429 lwz r7, SS_DBAT+0x1c(r3)
431 mtspr SPRN_DBAT2U, r4
432 mtspr SPRN_DBAT2L, r5
433 mtspr SPRN_DBAT3U, r6
434 mtspr SPRN_DBAT3L, r7
436 lwz r4, SS_DBAT+0x20(r3)
437 lwz r5, SS_DBAT+0x24(r3)
438 lwz r6, SS_DBAT+0x28(r3)
439 lwz r7, SS_DBAT+0x2c(r3)
441 mtspr SPRN_DBAT4U, r4
442 mtspr SPRN_DBAT4L, r5
443 mtspr SPRN_DBAT5U, r6
444 mtspr SPRN_DBAT5L, r7
446 lwz r4, SS_DBAT+0x30(r3)
447 lwz r5, SS_DBAT+0x34(r3)
448 lwz r6, SS_DBAT+0x38(r3)
449 lwz r7, SS_DBAT+0x3c(r3)
451 mtspr SPRN_DBAT6U, r4
452 mtspr SPRN_DBAT6L, r5
453 mtspr SPRN_DBAT7U, r6
454 mtspr SPRN_DBAT7L, r7
456 lwz r4, SS_IBAT+0x00(r3)
457 lwz r5, SS_IBAT+0x04(r3)
458 lwz r6, SS_IBAT+0x08(r3)
459 lwz r7, SS_IBAT+0x0c(r3)
461 mtspr SPRN_IBAT0U, r4
462 mtspr SPRN_IBAT0L, r5
463 mtspr SPRN_IBAT1U, r6
464 mtspr SPRN_IBAT1L, r7
466 lwz r4, SS_IBAT+0x10(r3)
467 lwz r5, SS_IBAT+0x14(r3)
468 lwz r6, SS_IBAT+0x18(r3)
469 lwz r7, SS_IBAT+0x1c(r3)
471 mtspr SPRN_IBAT2U, r4
472 mtspr SPRN_IBAT2L, r5
473 mtspr SPRN_IBAT3U, r6
474 mtspr SPRN_IBAT3L, r7
476 lwz r4, SS_IBAT+0x20(r3)
477 lwz r5, SS_IBAT+0x24(r3)
478 lwz r6, SS_IBAT+0x28(r3)
479 lwz r7, SS_IBAT+0x2c(r3)
481 mtspr SPRN_IBAT4U, r4
482 mtspr SPRN_IBAT4L, r5
483 mtspr SPRN_IBAT5U, r6
484 mtspr SPRN_IBAT5L, r7
486 lwz r4, SS_IBAT+0x30(r3)
487 lwz r5, SS_IBAT+0x34(r3)
488 lwz r6, SS_IBAT+0x38(r3)
489 lwz r7, SS_IBAT+0x3c(r3)
491 mtspr SPRN_IBAT6U, r4
492 mtspr SPRN_IBAT6L, r5
493 mtspr SPRN_IBAT7U, r6
494 mtspr SPRN_IBAT7L, r7
496 lwz r4, SS_SPRG+0(r3)
497 lwz r5, SS_SPRG+4(r3)
498 lwz r6, SS_SPRG+8(r3)
499 lwz r7, SS_SPRG+12(r3)
527 lmw r12, SS_GPREG(r3)
529 /* Kick decrementer */