/*1* This file contains the power_save function for 6xx & 7xxx CPUs2* rewritten in assembler3*4* Warning ! This code assumes that if your machine has a 750fx5* it will have PLL 1 set to low speed mode (used during NAP/DOZE).6* if this is not the case some additional changes will have to7* be done to check a runtime var (a bit like powersave-nap)8*9* This program is free software; you can redistribute it and/or10* modify it under the terms of the GNU General Public License11* as published by the Free Software Foundation; either version12* 2 of the License, or (at your option) any later version.13*/1415#include <linux/threads.h>16#include <asm/reg.h>17#include <asm/page.h>18#include <asm/cputable.h>19#include <asm/thread_info.h>20#include <asm/ppc_asm.h>21#include <asm/asm-offsets.h>2223.text2425/*26* Init idle, called at early CPU setup time from head.S for each CPU27* Make sure no rest of NAP mode remains in HID0, save default28* values for some CPU specific registers. Called with r2429* containing CPU number and r3 reloc offset30*/31_GLOBAL(init_idle_6xx)32BEGIN_FTR_SECTION33mfspr r4,SPRN_HID034rlwinm r4,r4,0,10,8 /* Clear NAP */35mtspr SPRN_HID0, r436b 1f37END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)38blr391:40slwi r5,r24,241add r5,r5,r342BEGIN_FTR_SECTION43mfspr r4,SPRN_MSSCR044addis r6,r5, nap_save_msscr0@ha45stw r4,nap_save_msscr0@l(r6)46END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)47BEGIN_FTR_SECTION48mfspr r4,SPRN_HID149addis r6,r5,nap_save_hid1@ha50stw r4,nap_save_hid1@l(r6)51END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)52blr5354/*55* Here is the power_save_6xx function. This could eventually be56* split into several functions & changing the function pointer57* depending on the various features.58*/59_GLOBAL(ppc6xx_idle)60/* Check if we can nap or doze, put HID0 mask in r361*/62lis r3, 063BEGIN_FTR_SECTION64lis r3,HID0_DOZE@h65END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)66BEGIN_FTR_SECTION67/* We must dynamically check for the NAP feature as it68* can be cleared by CPU init after the fixups are done69*/70lis r4,cur_cpu_spec@ha71lwz r4,cur_cpu_spec@l(r4)72lwz r4,CPU_SPEC_FEATURES(r4)73andi. r0,r4,CPU_FTR_CAN_NAP74beq 1f75/* Now check if user or arch enabled NAP mode */76lis r4,powersave_nap@ha77lwz r4,powersave_nap@l(r4)78cmpwi 0,r4,079beq 1f80lis r3,HID0_NAP@h811:82END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)83cmpwi 0,r3,084beqlr8586/* Some pre-nap cleanups needed on some CPUs */87andis. r0,r3,HID0_NAP@h88beq 2f89BEGIN_FTR_SECTION90/* Disable L2 prefetch on some 745x and try to ensure91* L2 prefetch engines are idle. As explained by errata92* text, we can't be sure they are, we just hope very hard93* that well be enough (sic !). At least I noticed Apple94* doesn't even bother doing the dcbf's here...95*/96mfspr r4,SPRN_MSSCR097rlwinm r4,r4,0,0,2998sync99mtspr SPRN_MSSCR0,r4100sync101isync102lis r4,KERNELBASE@h103dcbf 0,r4104dcbf 0,r4105dcbf 0,r4106dcbf 0,r4107END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)1082:109BEGIN_FTR_SECTION110/* Go to low speed mode on some 750FX */111lis r4,powersave_lowspeed@ha112lwz r4,powersave_lowspeed@l(r4)113cmpwi 0,r4,0114beq 1f115mfspr r4,SPRN_HID1116oris r4,r4,0x0001117mtspr SPRN_HID1,r41181:119END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)120121/* Go to NAP or DOZE now */122mfspr r4,SPRN_HID0123lis r5,(HID0_NAP|HID0_SLEEP)@h124BEGIN_FTR_SECTION125oris r5,r5,HID0_DOZE@h126END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)127andc r4,r4,r5128or r4,r4,r3129BEGIN_FTR_SECTION130oris r4,r4,HID0_DPM@h /* that should be done once for all */131END_FTR_SECTION_IFCLR(CPU_FTR_NO_DPM)132mtspr SPRN_HID0,r4133BEGIN_FTR_SECTION134DSSALL135sync136END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)137rlwinm r9,r1,0,0,31-THREAD_SHIFT /* current thread_info */138lwz r8,TI_LOCAL_FLAGS(r9) /* set napping bit */139ori r8,r8,_TLF_NAPPING /* so when we take an exception */140stw r8,TI_LOCAL_FLAGS(r9) /* it will return to our caller */141mfmsr r7142ori r7,r7,MSR_EE143oris r7,r7,MSR_POW@h1441: sync145mtmsr r7146isync147b 1b148149/*150* Return from NAP/DOZE mode, restore some CPU specific registers,151* we are called with DR/IR still off and r2 containing physical152* address of current. R11 points to the exception frame (physical153* address). We have to preserve r10.154*/155_GLOBAL(power_save_ppc32_restore)156lwz r9,_LINK(r11) /* interrupted in ppc6xx_idle: */157stw r9,_NIP(r11) /* make it do a blr */158159#ifdef CONFIG_SMP160rlwinm r12,r11,0,0,31-THREAD_SHIFT161lwz r11,TI_CPU(r12) /* get cpu number * 4 */162slwi r11,r11,2163#else164li r11,0165#endif166/* Todo make sure all these are in the same page167* and load r11 (@ha part + CPU offset) only once168*/169BEGIN_FTR_SECTION170mfspr r9,SPRN_HID0171andis. r9,r9,HID0_NAP@h172beq 1f173addis r9,r11,(nap_save_msscr0-KERNELBASE)@ha174lwz r9,nap_save_msscr0@l(r9)175mtspr SPRN_MSSCR0, r9176sync177isync1781:179END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)180BEGIN_FTR_SECTION181addis r9,r11,(nap_save_hid1-KERNELBASE)@ha182lwz r9,nap_save_hid1@l(r9)183mtspr SPRN_HID1, r9184END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)185b transfer_to_handler_cont186187.data188189_GLOBAL(nap_save_msscr0)190.space 4*NR_CPUS191192_GLOBAL(nap_save_hid1)193.space 4*NR_CPUS194195_GLOBAL(powersave_lowspeed)196.long 0197198199