2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* BRIEF MODULE DESCRIPTION
|
2008-05-01 02:18:41 +07:00
|
|
|
* Au1xx0 Power Management routines.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2008-05-01 02:18:41 +07:00
|
|
|
* Copyright 2001, 2008 MontaVista Software Inc.
|
|
|
|
* Author: MontaVista Software, Inc. <source@mvista.com>
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Some of the routines are right out of init/main.c, whose
|
|
|
|
* copyrights apply here.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
|
|
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2008-04-24 01:43:55 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/sysctl.h>
|
2005-07-19 14:05:36 +07:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-12-25 02:46:01 +07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/mach-au1x00/au1000.h>
|
|
|
|
|
2008-05-01 02:18:41 +07:00
|
|
|
/*
|
|
|
|
* We need to save/restore a bunch of core registers that are
|
2005-04-17 05:20:36 +07:00
|
|
|
* either volatile or reset to some state across a processor sleep.
|
|
|
|
* If reading a register doesn't provide a proper result for a
|
|
|
|
* later restore, we have to provide a function for loading that
|
|
|
|
* register and save a copy.
|
|
|
|
*
|
|
|
|
* We only have to save/restore registers that aren't otherwise
|
|
|
|
* done as part of a driver pm_* function.
|
|
|
|
*/
|
2008-12-21 15:26:25 +07:00
|
|
|
static unsigned int sleep_sys_clocks[5];
|
|
|
|
static unsigned int sleep_sys_pinfunc;
|
|
|
|
static unsigned int sleep_static_memctlr[4][3];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
2008-05-01 02:18:41 +07:00
|
|
|
static void save_core_regs(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-05-01 02:18:41 +07:00
|
|
|
/* Clocks and PLLs. */
|
2014-07-23 21:36:24 +07:00
|
|
|
sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0);
|
|
|
|
sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1);
|
|
|
|
sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC);
|
|
|
|
sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL);
|
|
|
|
sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-12-21 15:26:25 +07:00
|
|
|
/* pin mux config */
|
2014-07-23 21:36:24 +07:00
|
|
|
sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-05-01 02:18:41 +07:00
|
|
|
/* Save the static memory controller configuration. */
|
2014-07-23 21:36:25 +07:00
|
|
|
sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0);
|
|
|
|
sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0);
|
|
|
|
sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0);
|
|
|
|
sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1);
|
|
|
|
sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1);
|
|
|
|
sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1);
|
|
|
|
sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2);
|
|
|
|
sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2);
|
|
|
|
sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2);
|
|
|
|
sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3);
|
|
|
|
sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3);
|
|
|
|
sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-05-01 02:18:41 +07:00
|
|
|
static void restore_core_regs(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-12-21 15:26:25 +07:00
|
|
|
/* restore clock configuration. Writing CPUPLL last will
|
|
|
|
* stall a bit and stabilize other clocks (unless this is
|
|
|
|
* one of those Au1000 with a write-only PLL, where we dont
|
|
|
|
* have a valid value)
|
|
|
|
*/
|
2014-07-23 21:36:24 +07:00
|
|
|
alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0);
|
|
|
|
alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1);
|
|
|
|
alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC);
|
|
|
|
alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL);
|
2008-12-21 15:26:25 +07:00
|
|
|
if (!au1xxx_cpu_has_pll_wo())
|
2014-07-23 21:36:24 +07:00
|
|
|
alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL);
|
2008-12-21 15:26:25 +07:00
|
|
|
|
2014-07-23 21:36:24 +07:00
|
|
|
alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
|
2008-12-21 15:26:25 +07:00
|
|
|
|
2008-05-01 02:18:41 +07:00
|
|
|
/* Restore the static memory controller configuration. */
|
2014-07-23 21:36:25 +07:00
|
|
|
alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3);
|
|
|
|
alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-12-21 15:26:25 +07:00
|
|
|
void au_sleep(void)
|
|
|
|
{
|
2011-08-02 20:50:58 +07:00
|
|
|
save_core_regs();
|
|
|
|
|
|
|
|
switch (alchemy_get_cputype()) {
|
|
|
|
case ALCHEMY_CPU_AU1000:
|
|
|
|
case ALCHEMY_CPU_AU1500:
|
|
|
|
case ALCHEMY_CPU_AU1100:
|
|
|
|
alchemy_sleep_au1000();
|
|
|
|
break;
|
|
|
|
case ALCHEMY_CPU_AU1550:
|
|
|
|
case ALCHEMY_CPU_AU1200:
|
|
|
|
alchemy_sleep_au1550();
|
|
|
|
break;
|
2011-11-02 02:03:30 +07:00
|
|
|
case ALCHEMY_CPU_AU1300:
|
|
|
|
alchemy_sleep_au1300();
|
|
|
|
break;
|
2010-05-25 00:42:52 +07:00
|
|
|
}
|
2011-08-02 20:50:58 +07:00
|
|
|
|
|
|
|
restore_core_regs();
|
2008-12-21 15:26:25 +07:00
|
|
|
}
|