blob: 921ed30b440cf2dca5a92807b67709798fa82b8f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * BRIEF MODULE DESCRIPTION
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +04003 * Au1xx0 Power Management routines.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +04005 * Copyright 2001, 2008 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc. <source@mvista.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * Some of the routines are right out of init/main.c, whose
9 * copyrights apply here.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
Sergei Shtylyovce28f942008-04-23 22:43:55 +040031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/sysctl.h>
Pete Popov3ce86ee2005-07-19 07:05:36 +000034#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/mach-au1x00/au1000.h>
38
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040039/*
40 * We need to save/restore a bunch of core registers that are
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * either volatile or reset to some state across a processor sleep.
42 * If reading a register doesn't provide a proper result for a
43 * later restore, we have to provide a function for loading that
44 * register and save a copy.
45 *
46 * We only have to save/restore registers that aren't otherwise
47 * done as part of a driver pm_* function.
48 */
Manuel Lauss564365b2008-12-21 09:26:25 +010049static unsigned int sleep_sys_clocks[5];
50static unsigned int sleep_sys_pinfunc;
51static unsigned int sleep_static_memctlr[4][3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040054static void save_core_regs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040056 /* Clocks and PLLs. */
Manuel Lauss1d09de72014-07-23 16:36:24 +020057 sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0);
58 sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1);
59 sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC);
60 sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL);
61 sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Manuel Lauss564365b2008-12-21 09:26:25 +010063 /* pin mux config */
Manuel Lauss1d09de72014-07-23 16:36:24 +020064 sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040066 /* Save the static memory controller configuration. */
Manuel Lauss9cf12162014-07-23 16:36:25 +020067 sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0);
68 sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0);
69 sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0);
70 sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1);
71 sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1);
72 sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1);
73 sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2);
74 sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2);
75 sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2);
76 sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3);
77 sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3);
78 sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040081static void restore_core_regs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Manuel Lauss564365b2008-12-21 09:26:25 +010083 /* restore clock configuration. Writing CPUPLL last will
84 * stall a bit and stabilize other clocks (unless this is
85 * one of those Au1000 with a write-only PLL, where we dont
86 * have a valid value)
87 */
Manuel Lauss1d09de72014-07-23 16:36:24 +020088 alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0);
89 alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1);
90 alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC);
91 alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL);
Manuel Lauss564365b2008-12-21 09:26:25 +010092 if (!au1xxx_cpu_has_pll_wo())
Manuel Lauss1d09de72014-07-23 16:36:24 +020093 alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Manuel Lauss1d09de72014-07-23 16:36:24 +020095 alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
Manuel Lauss564365b2008-12-21 09:26:25 +010096
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +040097 /* Restore the static memory controller configuration. */
Manuel Lauss9cf12162014-07-23 16:36:25 +020098 alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0);
99 alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0);
100 alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0);
101 alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1);
102 alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1);
103 alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1);
104 alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2);
105 alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2);
106 alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2);
107 alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3);
108 alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3);
109 alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Manuel Lauss564365b2008-12-21 09:26:25 +0100112void au_sleep(void)
113{
Manuel Lauss870168a2011-08-02 15:50:58 +0200114 save_core_regs();
115
116 switch (alchemy_get_cputype()) {
117 case ALCHEMY_CPU_AU1000:
118 case ALCHEMY_CPU_AU1500:
119 case ALCHEMY_CPU_AU1100:
120 alchemy_sleep_au1000();
121 break;
122 case ALCHEMY_CPU_AU1550:
123 case ALCHEMY_CPU_AU1200:
124 alchemy_sleep_au1550();
125 break;
Manuel Lauss809f36c2011-11-01 20:03:30 +0100126 case ALCHEMY_CPU_AU1300:
127 alchemy_sleep_au1300();
128 break;
Manuel Lauss2e93d1e2010-05-24 19:42:52 +0200129 }
Manuel Lauss870168a2011-08-02 15:50:58 +0200130
131 restore_core_regs();
Manuel Lauss564365b2008-12-21 09:26:25 +0100132}