xref: /openbmc/linux/arch/mips/alchemy/common/power.c (revision 9095bf25ea08135a5b74875dd0e3eeaddc4218a0)
1e8c7c482SRalf Baechle /*
2e8c7c482SRalf Baechle  * BRIEF MODULE DESCRIPTION
3e8c7c482SRalf Baechle  *	Au1xx0 Power Management routines.
4e8c7c482SRalf Baechle  *
5e8c7c482SRalf Baechle  * Copyright 2001, 2008 MontaVista Software Inc.
6e8c7c482SRalf Baechle  * Author: MontaVista Software, Inc. <source@mvista.com>
7e8c7c482SRalf Baechle  *
8e8c7c482SRalf Baechle  *  Some of the routines are right out of init/main.c, whose
9e8c7c482SRalf Baechle  *  copyrights apply here.
10e8c7c482SRalf Baechle  *
11e8c7c482SRalf Baechle  *  This program is free software; you can redistribute	 it and/or modify it
12e8c7c482SRalf Baechle  *  under  the terms of	 the GNU General  Public License as published by the
13e8c7c482SRalf Baechle  *  Free Software Foundation;  either version 2 of the	License, or (at your
14e8c7c482SRalf Baechle  *  option) any later version.
15e8c7c482SRalf Baechle  *
16e8c7c482SRalf Baechle  *  THIS  SOFTWARE  IS PROVIDED	  ``AS	IS'' AND   ANY	EXPRESS OR IMPLIED
17e8c7c482SRalf Baechle  *  WARRANTIES,	  INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
18e8c7c482SRalf Baechle  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
19e8c7c482SRalf Baechle  *  NO	EVENT  SHALL   THE AUTHOR  BE	 LIABLE FOR ANY	  DIRECT, INDIRECT,
20e8c7c482SRalf Baechle  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21e8c7c482SRalf Baechle  *  NOT LIMITED	  TO, PROCUREMENT OF  SUBSTITUTE GOODS	OR SERVICES; LOSS OF
22e8c7c482SRalf Baechle  *  USE, DATA,	OR PROFITS; OR	BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23e8c7c482SRalf Baechle  *  ANY THEORY OF LIABILITY, WHETHER IN	 CONTRACT, STRICT LIABILITY, OR TORT
24e8c7c482SRalf Baechle  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25e8c7c482SRalf Baechle  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26e8c7c482SRalf Baechle  *
27e8c7c482SRalf Baechle  *  You should have received a copy of the  GNU General Public License along
28e8c7c482SRalf Baechle  *  with this program; if not, write  to the Free Software Foundation, Inc.,
29e8c7c482SRalf Baechle  *  675 Mass Ave, Cambridge, MA 02139, USA.
30e8c7c482SRalf Baechle  */
31e8c7c482SRalf Baechle 
32e8c7c482SRalf Baechle #include <linux/pm.h>
33e8c7c482SRalf Baechle #include <linux/sysctl.h>
34e8c7c482SRalf Baechle #include <linux/jiffies.h>
35e8c7c482SRalf Baechle 
36*7c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
37e8c7c482SRalf Baechle #include <asm/mach-au1x00/au1000.h>
38e8c7c482SRalf Baechle 
39e8c7c482SRalf Baechle /*
40e8c7c482SRalf Baechle  * We need to save/restore a bunch of core registers that are
41e8c7c482SRalf Baechle  * either volatile or reset to some state across a processor sleep.
42e8c7c482SRalf Baechle  * If reading a register doesn't provide a proper result for a
43e8c7c482SRalf Baechle  * later restore, we have to provide a function for loading that
44e8c7c482SRalf Baechle  * register and save a copy.
45e8c7c482SRalf Baechle  *
46e8c7c482SRalf Baechle  * We only have to save/restore registers that aren't otherwise
47e8c7c482SRalf Baechle  * done as part of a driver pm_* function.
48e8c7c482SRalf Baechle  */
49564365b0SManuel Lauss static unsigned int sleep_sys_clocks[5];
50564365b0SManuel Lauss static unsigned int sleep_sys_pinfunc;
51e8c7c482SRalf Baechle static unsigned int sleep_static_memctlr[4][3];
52e8c7c482SRalf Baechle 
53e8c7c482SRalf Baechle 
save_core_regs(void)54e8c7c482SRalf Baechle static void save_core_regs(void)
55e8c7c482SRalf Baechle {
56e8c7c482SRalf Baechle 	/* Clocks and PLLs. */
571d09de7dSManuel Lauss 	sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0);
581d09de7dSManuel Lauss 	sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1);
591d09de7dSManuel Lauss 	sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC);
601d09de7dSManuel Lauss 	sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL);
611d09de7dSManuel Lauss 	sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL);
62e8c7c482SRalf Baechle 
63564365b0SManuel Lauss 	/* pin mux config */
641d09de7dSManuel Lauss 	sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
65e8c7c482SRalf Baechle 
66e8c7c482SRalf Baechle 	/* Save the static memory controller configuration. */
679cf12167SManuel Lauss 	sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0);
689cf12167SManuel Lauss 	sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0);
699cf12167SManuel Lauss 	sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0);
709cf12167SManuel Lauss 	sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1);
719cf12167SManuel Lauss 	sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1);
729cf12167SManuel Lauss 	sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1);
739cf12167SManuel Lauss 	sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2);
749cf12167SManuel Lauss 	sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2);
759cf12167SManuel Lauss 	sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2);
769cf12167SManuel Lauss 	sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3);
779cf12167SManuel Lauss 	sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3);
789cf12167SManuel Lauss 	sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3);
79e8c7c482SRalf Baechle }
80e8c7c482SRalf Baechle 
restore_core_regs(void)81e8c7c482SRalf Baechle static void restore_core_regs(void)
82e8c7c482SRalf Baechle {
83564365b0SManuel Lauss 	/* restore clock configuration.  Writing CPUPLL last will
84564365b0SManuel Lauss 	 * stall a bit and stabilize other clocks (unless this is
85564365b0SManuel Lauss 	 * one of those Au1000 with a write-only PLL, where we dont
86564365b0SManuel Lauss 	 * have a valid value)
87564365b0SManuel Lauss 	 */
881d09de7dSManuel Lauss 	alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0);
891d09de7dSManuel Lauss 	alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1);
901d09de7dSManuel Lauss 	alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC);
911d09de7dSManuel Lauss 	alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL);
92564365b0SManuel Lauss 	if (!au1xxx_cpu_has_pll_wo())
931d09de7dSManuel Lauss 		alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL);
94e8c7c482SRalf Baechle 
951d09de7dSManuel Lauss 	alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
96564365b0SManuel Lauss 
97e8c7c482SRalf Baechle 	/* Restore the static memory controller configuration. */
989cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0);
999cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0);
1009cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0);
1019cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1);
1029cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1);
1039cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1);
1049cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2);
1059cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2);
1069cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2);
1079cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3);
1089cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3);
1099cf12167SManuel Lauss 	alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3);
110e8c7c482SRalf Baechle }
111e8c7c482SRalf Baechle 
au_sleep(void)112564365b0SManuel Lauss void au_sleep(void)
113564365b0SManuel Lauss {
114564365b0SManuel Lauss 	save_core_regs();
115870168a0SManuel Lauss 
116870168a0SManuel Lauss 	switch (alchemy_get_cputype()) {
117870168a0SManuel Lauss 	case ALCHEMY_CPU_AU1000:
118870168a0SManuel Lauss 	case ALCHEMY_CPU_AU1500:
119870168a0SManuel Lauss 	case ALCHEMY_CPU_AU1100:
1202e93d1ecSManuel Lauss 		alchemy_sleep_au1000();
121870168a0SManuel Lauss 		break;
122870168a0SManuel Lauss 	case ALCHEMY_CPU_AU1550:
123870168a0SManuel Lauss 	case ALCHEMY_CPU_AU1200:
1242e93d1ecSManuel Lauss 		alchemy_sleep_au1550();
125870168a0SManuel Lauss 		break;
126809f36c6SManuel Lauss 	case ALCHEMY_CPU_AU1300:
127809f36c6SManuel Lauss 		alchemy_sleep_au1300();
128809f36c6SManuel Lauss 		break;
129564365b0SManuel Lauss 	}
130870168a0SManuel Lauss 
131870168a0SManuel Lauss 	restore_core_regs();
1322e93d1ecSManuel Lauss }
133