162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * BRIEF MODULE DESCRIPTION 362306a36Sopenharmony_ci * Au1xx0 Power Management routines. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2001, 2008 MontaVista Software Inc. 662306a36Sopenharmony_ci * Author: MontaVista Software, Inc. <source@mvista.com> 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Some of the routines are right out of init/main.c, whose 962306a36Sopenharmony_ci * copyrights apply here. 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 1262306a36Sopenharmony_ci * under the terms of the GNU General Public License as published by the 1362306a36Sopenharmony_ci * Free Software Foundation; either version 2 of the License, or (at your 1462306a36Sopenharmony_ci * option) any later version. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 1762306a36Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1862306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 1962306a36Sopenharmony_ci * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2062306a36Sopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2162306a36Sopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2262306a36Sopenharmony_ci * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 2362306a36Sopenharmony_ci * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2462306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2562306a36Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License along 2862306a36Sopenharmony_ci * with this program; if not, write to the Free Software Foundation, Inc., 2962306a36Sopenharmony_ci * 675 Mass Ave, Cambridge, MA 02139, USA. 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#include <linux/pm.h> 3362306a36Sopenharmony_ci#include <linux/sysctl.h> 3462306a36Sopenharmony_ci#include <linux/jiffies.h> 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#include <linux/uaccess.h> 3762306a36Sopenharmony_ci#include <asm/mach-au1x00/au1000.h> 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * We need to save/restore a bunch of core registers that are 4162306a36Sopenharmony_ci * either volatile or reset to some state across a processor sleep. 4262306a36Sopenharmony_ci * If reading a register doesn't provide a proper result for a 4362306a36Sopenharmony_ci * later restore, we have to provide a function for loading that 4462306a36Sopenharmony_ci * register and save a copy. 4562306a36Sopenharmony_ci * 4662306a36Sopenharmony_ci * We only have to save/restore registers that aren't otherwise 4762306a36Sopenharmony_ci * done as part of a driver pm_* function. 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistatic unsigned int sleep_sys_clocks[5]; 5062306a36Sopenharmony_cistatic unsigned int sleep_sys_pinfunc; 5162306a36Sopenharmony_cistatic unsigned int sleep_static_memctlr[4][3]; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistatic void save_core_regs(void) 5562306a36Sopenharmony_ci{ 5662306a36Sopenharmony_ci /* Clocks and PLLs. */ 5762306a36Sopenharmony_ci sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0); 5862306a36Sopenharmony_ci sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1); 5962306a36Sopenharmony_ci sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC); 6062306a36Sopenharmony_ci sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL); 6162306a36Sopenharmony_ci sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL); 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci /* pin mux config */ 6462306a36Sopenharmony_ci sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci /* Save the static memory controller configuration. */ 6762306a36Sopenharmony_ci sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0); 6862306a36Sopenharmony_ci sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0); 6962306a36Sopenharmony_ci sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0); 7062306a36Sopenharmony_ci sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1); 7162306a36Sopenharmony_ci sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1); 7262306a36Sopenharmony_ci sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1); 7362306a36Sopenharmony_ci sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2); 7462306a36Sopenharmony_ci sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2); 7562306a36Sopenharmony_ci sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2); 7662306a36Sopenharmony_ci sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3); 7762306a36Sopenharmony_ci sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3); 7862306a36Sopenharmony_ci sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3); 7962306a36Sopenharmony_ci} 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_cistatic void restore_core_regs(void) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci /* restore clock configuration. Writing CPUPLL last will 8462306a36Sopenharmony_ci * stall a bit and stabilize other clocks (unless this is 8562306a36Sopenharmony_ci * one of those Au1000 with a write-only PLL, where we dont 8662306a36Sopenharmony_ci * have a valid value) 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0); 8962306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1); 9062306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC); 9162306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL); 9262306a36Sopenharmony_ci if (!au1xxx_cpu_has_pll_wo()) 9362306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci /* Restore the static memory controller configuration. */ 9862306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0); 9962306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0); 10062306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0); 10162306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1); 10262306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1); 10362306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1); 10462306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2); 10562306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2); 10662306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2); 10762306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3); 10862306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3); 10962306a36Sopenharmony_ci alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3); 11062306a36Sopenharmony_ci} 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_civoid au_sleep(void) 11362306a36Sopenharmony_ci{ 11462306a36Sopenharmony_ci save_core_regs(); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci switch (alchemy_get_cputype()) { 11762306a36Sopenharmony_ci case ALCHEMY_CPU_AU1000: 11862306a36Sopenharmony_ci case ALCHEMY_CPU_AU1500: 11962306a36Sopenharmony_ci case ALCHEMY_CPU_AU1100: 12062306a36Sopenharmony_ci alchemy_sleep_au1000(); 12162306a36Sopenharmony_ci break; 12262306a36Sopenharmony_ci case ALCHEMY_CPU_AU1550: 12362306a36Sopenharmony_ci case ALCHEMY_CPU_AU1200: 12462306a36Sopenharmony_ci alchemy_sleep_au1550(); 12562306a36Sopenharmony_ci break; 12662306a36Sopenharmony_ci case ALCHEMY_CPU_AU1300: 12762306a36Sopenharmony_ci alchemy_sleep_au1300(); 12862306a36Sopenharmony_ci break; 12962306a36Sopenharmony_ci } 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci restore_core_regs(); 13262306a36Sopenharmony_ci} 133