2005-04-17 02:20:36 +04:00
/* linux/arch/arm/mach-s3c2410/pm.c
*
2007-02-11 20:31:01 +03:00
* Copyright ( c ) 2006 Simtec Electronics
2005-04-17 02:20:36 +04:00
* Ben Dooks < ben @ simtec . co . uk >
*
2007-02-11 20:31:01 +03:00
* S3C2410 ( and compatible ) Power Manager ( Suspend - To - RAM ) support
2005-04-17 02:20:36 +04:00
*
* 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 program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* 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 . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include <linux/init.h>
# include <linux/suspend.h>
# include <linux/errno.h>
# include <linux/time.h>
2007-02-11 20:31:01 +03:00
# include <linux/sysdev.h>
2009-05-14 01:52:24 +04:00
# include <linux/gpio.h>
2008-09-06 15:10:45 +04:00
# include <linux/io.h>
2005-04-17 02:20:36 +04:00
2008-08-05 19:14:15 +04:00
# include <mach/hardware.h>
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
# include <asm/mach-types.h>
2005-04-17 02:20:36 +04:00
2008-08-05 19:14:15 +04:00
# include <mach/regs-gpio.h>
# include <mach/h1940.h>
2005-04-17 02:20:36 +04:00
2008-10-08 01:26:09 +04:00
# include <plat/cpu.h>
# include <plat/pm.h>
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
static void s3c2410_pm_prepare ( void )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
/* ensure at least GSTATUS3 has the resume address */
2005-04-17 02:20:36 +04:00
2008-12-12 03:24:19 +03:00
__raw_writel ( virt_to_phys ( s3c_cpu_resume ) , S3C2410_GSTATUS3 ) ;
2005-04-17 02:20:36 +04:00
2008-12-12 03:24:06 +03:00
S3C_PMDBG ( " GSTATUS3 0x%08x \n " , __raw_readl ( S3C2410_GSTATUS3 ) ) ;
S3C_PMDBG ( " GSTATUS4 0x%08x \n " , __raw_readl ( S3C2410_GSTATUS4 ) ) ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
if ( machine_is_h1940 ( ) ) {
void * base = phys_to_virt ( H1940_SUSPEND_CHECK ) ;
unsigned long ptr ;
unsigned long calc = 0 ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
/* generate check for the bootloader to check on resume */
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
for ( ptr = 0 ; ptr < 0x40000 ; ptr + = 0x400 )
calc + = __raw_readl ( base + ptr ) ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
__raw_writel ( calc , phys_to_virt ( H1940_SUSPEND_CHECKSUM ) ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
/* the RX3715 uses similar code and the same H1940 and the
* same offsets for resume and checksum pointers */
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
if ( machine_is_rx3715 ( ) ) {
void * base = phys_to_virt ( H1940_SUSPEND_CHECK ) ;
unsigned long ptr ;
unsigned long calc = 0 ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
/* generate check for the bootloader to check on resume */
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
for ( ptr = 0 ; ptr < 0x40000 ; ptr + = 0x4 )
calc + = __raw_readl ( base + ptr ) ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
__raw_writel ( calc , phys_to_virt ( H1940_SUSPEND_CHECKSUM ) ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
if ( machine_is_aml_m5900 ( ) )
2009-05-18 01:32:23 +04:00
s3c2410_gpio_setpin ( S3C2410_GPF ( 2 ) , 1 ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
static int s3c2410_pm_resume ( struct sys_device * dev )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
unsigned long tmp ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
/* unset the return-from-sleep flag, to ensure reset */
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
tmp = __raw_readl ( S3C2410_GSTATUS2 ) ;
tmp & = S3C2410_GSTATUS2_OFFRESET ;
__raw_writel ( tmp , S3C2410_GSTATUS2 ) ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
if ( machine_is_aml_m5900 ( ) )
2009-05-18 01:32:23 +04:00
s3c2410_gpio_setpin ( S3C2410_GPF ( 2 ) , 0 ) ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
static int s3c2410_pm_add ( struct sys_device * dev )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
pm_cpu_prep = s3c2410_pm_prepare ;
pm_cpu_sleep = s3c2410_cpu_suspend ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
# if defined(CONFIG_CPU_S3C2410)
static struct sysdev_driver s3c2410_pm_driver = {
. add = s3c2410_pm_add ,
. resume = s3c2410_pm_resume ,
} ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
/* register ourselves */
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
static int __init s3c2410_pm_drvinit ( void )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
return sysdev_driver_register ( & s3c2410_sysclass , & s3c2410_pm_driver ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
arch_initcall ( s3c2410_pm_drvinit ) ;
2009-07-31 02:23:38 +04:00
static struct sysdev_driver s3c2410a_pm_driver = {
. add = s3c2410_pm_add ,
. resume = s3c2410_pm_resume ,
} ;
static int __init s3c2410a_pm_drvinit ( void )
{
return sysdev_driver_register ( & s3c2410a_sysclass , & s3c2410a_pm_driver ) ;
}
arch_initcall ( s3c2410a_pm_drvinit ) ;
2007-02-11 20:31:01 +03:00
# endif
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
# if defined(CONFIG_CPU_S3C2440)
static struct sysdev_driver s3c2440_pm_driver = {
. add = s3c2410_pm_add ,
. resume = s3c2410_pm_resume ,
} ;
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
static int __init s3c2440_pm_drvinit ( void )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
return sysdev_driver_register ( & s3c2440_sysclass , & s3c2440_pm_driver ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
arch_initcall ( s3c2440_pm_drvinit ) ;
# endif
2005-04-17 02:20:36 +04:00
2007-02-11 20:31:01 +03:00
# if defined(CONFIG_CPU_S3C2442)
static struct sysdev_driver s3c2442_pm_driver = {
. add = s3c2410_pm_add ,
. resume = s3c2410_pm_resume ,
2005-04-17 02:20:36 +04:00
} ;
2007-02-11 20:31:01 +03:00
static int __init s3c2442_pm_drvinit ( void )
2005-04-17 02:20:36 +04:00
{
2007-02-11 20:31:01 +03:00
return sysdev_driver_register ( & s3c2442_sysclass , & s3c2442_pm_driver ) ;
2005-04-17 02:20:36 +04:00
}
2007-02-11 20:31:01 +03:00
arch_initcall ( s3c2442_pm_drvinit ) ;
# endif