2 * This file contains the power_save function for 6xx & 7xxx CPUs
3 * rewritten in assembler
5 * Warning ! This code assumes that if your machine has a 750fx
6 * it will have PLL 1 set to low speed mode (used during NAP/DOZE).
7 * if this is not the case some additional changes will have to
8 * be done to check a runtime var (a bit like powersave-nap)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #include <linux/config.h>
17 #include <linux/threads.h>
18 #include <asm/processor.h>
20 #include <asm/cputable.h>
21 #include <asm/thread_info.h>
22 #include <asm/ppc_asm.h>
23 #include <asm/offsets.h>
30 * Init idle, called at early CPU setup time from head.S for each CPU
31 * Make sure no rest of NAP mode remains in HID0, save default
32 * values for some CPU specific registers. Called with r24
33 * containing CPU number and r3 reloc offset
35 _GLOBAL(init_idle_6xx)
38 rlwinm r4,r4,0,10,8 /* Clear NAP */
41 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
48 addis r6,r5, nap_save_msscr0@ha
49 stw r4,nap_save_msscr0@l(r6)
50 END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
53 addis r6,r5,nap_save_hid1@ha
54 stw r4,nap_save_hid1@l(r6)
55 END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
59 * Here is the power_save_6xx function. This could eventually be
60 * split into several functions & changing the function pointer
61 * depending on the various features.
64 /* Check if we can nap or doze, put HID0 mask in r3
69 END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)
71 /* We must dynamically check for the NAP feature as it
72 * can be cleared by CPU init after the fixups are done
74 lis r4,cur_cpu_spec@ha
75 lwz r4,cur_cpu_spec@l(r4)
76 lwz r4,CPU_SPEC_FEATURES(r4)
77 andi. r0,r4,CPU_FTR_CAN_NAP
79 /* Now check if user or arch enabled NAP mode */
80 lis r4,powersave_nap@ha
81 lwz r4,powersave_nap@l(r4)
86 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
95 /* Check current_thread_info()->flags */
98 andi. r0,r4,_TIF_NEED_RESCHED
100 mtmsr r7 /* out of line this ? */
103 /* Some pre-nap cleanups needed on some CPUs */
104 andis. r0,r3,HID0_NAP@h
107 /* Disable L2 prefetch on some 745x and try to ensure
108 * L2 prefetch engines are idle. As explained by errata
109 * text, we can't be sure they are, we just hope very hard
110 * that well be enough (sic !). At least I noticed Apple
111 * doesn't even bother doing the dcbf's here...
124 END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
126 lis r6,nap_enter_count@ha
127 lwz r4,nap_enter_count@l(r6)
129 stw r4,nap_enter_count@l(r6)
133 /* Go to low speed mode on some 750FX */
134 lis r4,powersave_lowspeed@ha
135 lwz r4,powersave_lowspeed@l(r4)
142 END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
144 /* Go to NAP or DOZE now */
146 lis r5,(HID0_NAP|HID0_SLEEP)@h
148 oris r5,r5,HID0_DOZE@h
149 END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)
153 oris r4,r4,HID0_DPM@h /* that should be done once for all */
154 END_FTR_SECTION_IFCLR(CPU_FTR_NO_DPM)
159 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
160 ori r7,r7,MSR_EE /* Could be ommited (already set) */
170 * Return from NAP/DOZE mode, restore some CPU specific registers,
171 * we are called with DR/IR still off and r2 containing physical
172 * address of current.
174 _GLOBAL(power_save_6xx_restore)
176 rlwinm. r11,r11,0,10,8 /* Clear NAP & copy NAP bit !state to cr1 EQ */
177 cror 4*cr1+eq,4*cr0+eq,4*cr0+eq
179 rlwinm r11,r11,0,9,7 /* Clear DOZE */
180 END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)
185 lis r11,(nap_return_count-KERNELBASE)@ha
186 lwz r9,nap_return_count@l(r11)
188 stw r9,nap_return_count@l(r11)
196 /* Todo make sure all these are in the same page
197 * and load r22 (@ha part + CPU offset) only once
201 addis r9,r11,(nap_save_msscr0-KERNELBASE)@ha
202 lwz r9,nap_save_msscr0@l(r9)
203 mtspr SPRN_MSSCR0, r9
207 END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
209 addis r9,r11,(nap_save_hid1-KERNELBASE)@ha
210 lwz r9,nap_save_hid1@l(r9)
212 END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
213 b transfer_to_handler_cont
217 _GLOBAL(nap_save_msscr0)
220 _GLOBAL(nap_save_hid1)
223 _GLOBAL(powersave_nap)
225 _GLOBAL(powersave_lowspeed)
229 _GLOBAL(nap_enter_count)
231 _GLOBAL(nap_return_count)