Path: blob/master/arch/mips/alchemy/common/power.c
10818 views
/*1* BRIEF MODULE DESCRIPTION2* Au1xx0 Power Management routines.3*4* Copyright 2001, 2008 MontaVista Software Inc.5* Author: MontaVista Software, Inc. <[email protected]>6*7* Some of the routines are right out of init/main.c, whose8* copyrights apply here.9*10* This program is free software; you can redistribute it and/or modify it11* under the terms of the GNU General Public License as published by the12* Free Software Foundation; either version 2 of the License, or (at your13* option) any later version.14*15* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED16* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF17* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN18* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF21* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON22* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*26* You should have received a copy of the GNU General Public License along27* with this program; if not, write to the Free Software Foundation, Inc.,28* 675 Mass Ave, Cambridge, MA 02139, USA.29*/3031#include <linux/init.h>32#include <linux/pm.h>33#include <linux/sysctl.h>34#include <linux/jiffies.h>3536#include <asm/uaccess.h>37#include <asm/mach-au1x00/au1000.h>3839#ifdef CONFIG_PM4041/*42* We need to save/restore a bunch of core registers that are43* either volatile or reset to some state across a processor sleep.44* If reading a register doesn't provide a proper result for a45* later restore, we have to provide a function for loading that46* register and save a copy.47*48* We only have to save/restore registers that aren't otherwise49* done as part of a driver pm_* function.50*/51static unsigned int sleep_usb[2];52static unsigned int sleep_sys_clocks[5];53static unsigned int sleep_sys_pinfunc;54static unsigned int sleep_static_memctlr[4][3];555657static void save_core_regs(void)58{59#ifndef CONFIG_SOC_AU120060/* Shutdown USB host/device. */61sleep_usb[0] = au_readl(USB_HOST_CONFIG);6263/* There appears to be some undocumented reset register.... */64au_writel(0, 0xb0100004);65au_sync();66au_writel(0, USB_HOST_CONFIG);67au_sync();6869sleep_usb[1] = au_readl(USBD_ENABLE);70au_writel(0, USBD_ENABLE);71au_sync();7273#else /* AU1200 */7475/* enable access to OTG mmio so we can save OTG CAP/MUX.76* FIXME: write an OTG driver and move this stuff there!77*/78au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4);79au_sync();80sleep_usb[0] = au_readl(0xb4020020); /* OTG_CAP */81sleep_usb[1] = au_readl(0xb4020024); /* OTG_MUX */82#endif8384/* Clocks and PLLs. */85sleep_sys_clocks[0] = au_readl(SYS_FREQCTRL0);86sleep_sys_clocks[1] = au_readl(SYS_FREQCTRL1);87sleep_sys_clocks[2] = au_readl(SYS_CLKSRC);88sleep_sys_clocks[3] = au_readl(SYS_CPUPLL);89sleep_sys_clocks[4] = au_readl(SYS_AUXPLL);9091/* pin mux config */92sleep_sys_pinfunc = au_readl(SYS_PINFUNC);9394/* Save the static memory controller configuration. */95sleep_static_memctlr[0][0] = au_readl(MEM_STCFG0);96sleep_static_memctlr[0][1] = au_readl(MEM_STTIME0);97sleep_static_memctlr[0][2] = au_readl(MEM_STADDR0);98sleep_static_memctlr[1][0] = au_readl(MEM_STCFG1);99sleep_static_memctlr[1][1] = au_readl(MEM_STTIME1);100sleep_static_memctlr[1][2] = au_readl(MEM_STADDR1);101sleep_static_memctlr[2][0] = au_readl(MEM_STCFG2);102sleep_static_memctlr[2][1] = au_readl(MEM_STTIME2);103sleep_static_memctlr[2][2] = au_readl(MEM_STADDR2);104sleep_static_memctlr[3][0] = au_readl(MEM_STCFG3);105sleep_static_memctlr[3][1] = au_readl(MEM_STTIME3);106sleep_static_memctlr[3][2] = au_readl(MEM_STADDR3);107}108109static void restore_core_regs(void)110{111/* restore clock configuration. Writing CPUPLL last will112* stall a bit and stabilize other clocks (unless this is113* one of those Au1000 with a write-only PLL, where we dont114* have a valid value)115*/116au_writel(sleep_sys_clocks[0], SYS_FREQCTRL0);117au_writel(sleep_sys_clocks[1], SYS_FREQCTRL1);118au_writel(sleep_sys_clocks[2], SYS_CLKSRC);119au_writel(sleep_sys_clocks[4], SYS_AUXPLL);120if (!au1xxx_cpu_has_pll_wo())121au_writel(sleep_sys_clocks[3], SYS_CPUPLL);122au_sync();123124au_writel(sleep_sys_pinfunc, SYS_PINFUNC);125au_sync();126127#ifndef CONFIG_SOC_AU1200128au_writel(sleep_usb[0], USB_HOST_CONFIG);129au_writel(sleep_usb[1], USBD_ENABLE);130au_sync();131#else132/* enable access to OTG memory */133au_writel(au_readl(USB_MSR_BASE + 4) | (1 << 6), USB_MSR_BASE + 4);134au_sync();135136/* restore OTG caps and port mux. */137au_writel(sleep_usb[0], 0xb4020020 + 0); /* OTG_CAP */138au_sync();139au_writel(sleep_usb[1], 0xb4020020 + 4); /* OTG_MUX */140au_sync();141#endif142143/* Restore the static memory controller configuration. */144au_writel(sleep_static_memctlr[0][0], MEM_STCFG0);145au_writel(sleep_static_memctlr[0][1], MEM_STTIME0);146au_writel(sleep_static_memctlr[0][2], MEM_STADDR0);147au_writel(sleep_static_memctlr[1][0], MEM_STCFG1);148au_writel(sleep_static_memctlr[1][1], MEM_STTIME1);149au_writel(sleep_static_memctlr[1][2], MEM_STADDR1);150au_writel(sleep_static_memctlr[2][0], MEM_STCFG2);151au_writel(sleep_static_memctlr[2][1], MEM_STTIME2);152au_writel(sleep_static_memctlr[2][2], MEM_STADDR2);153au_writel(sleep_static_memctlr[3][0], MEM_STCFG3);154au_writel(sleep_static_memctlr[3][1], MEM_STTIME3);155au_writel(sleep_static_memctlr[3][2], MEM_STADDR3);156}157158void au_sleep(void)159{160int cpuid = alchemy_get_cputype();161if (cpuid != ALCHEMY_CPU_UNKNOWN) {162save_core_regs();163if (cpuid <= ALCHEMY_CPU_AU1500)164alchemy_sleep_au1000();165else if (cpuid <= ALCHEMY_CPU_AU1200)166alchemy_sleep_au1550();167restore_core_regs();168}169}170171#endif /* CONFIG_PM */172173174