Merge branch 'master' of /home/trondmy/kernel/linux-2.6/ into merge_linus
[linux-2.6] / arch / arm / mach-s3c2410 / s3c2412-pm.c
1 /* linux/arch/arm/mach-s3c2410/s3c2412-pm.c
2  *
3  * Copyright (c) 2006 Simtec Electronics
4  *      Ben Dooks <ben@simtec.co.uk>
5  *
6  * http://armlinux.simtec.co.uk/.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11 */
12
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/interrupt.h>
16 #include <linux/list.h>
17 #include <linux/timer.h>
18 #include <linux/init.h>
19 #include <linux/sysdev.h>
20 #include <linux/platform_device.h>
21
22 #include <asm/hardware.h>
23 #include <asm/io.h>
24 #include <asm/irq.h>
25
26 #include <asm/arch/regs-power.h>
27 #include <asm/arch/regs-gpioj.h>
28 #include <asm/arch/regs-gpio.h>
29 #include <asm/arch/regs-dsc.h>
30
31 #include "cpu.h"
32 #include "pm.h"
33
34 #include "s3c2412.h"
35
36 static void s3c2412_cpu_suspend(void)
37 {
38         unsigned long tmp;
39
40         /* set our standby method to sleep */
41
42         tmp = __raw_readl(S3C2412_PWRCFG);
43         tmp |= S3C2412_PWRCFG_STANDBYWFI_SLEEP;
44         __raw_writel(tmp, S3C2412_PWRCFG);
45
46         /* issue the standby signal into the pm unit. Note, we
47          * issue a write-buffer drain just in case */
48
49         tmp = 0;
50
51         asm("b 1f\n\t"
52             ".align 5\n\t"
53             "1:\n\t"
54             "mcr p15, 0, %0, c7, c10, 4\n\t"
55             "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp));
56
57         /* we should never get past here */
58
59         panic("sleep resumed to originator?");
60 }
61
62 static void s3c2412_pm_prepare(void)
63 {
64 }
65
66 static int s3c2412_pm_add(struct sys_device *sysdev)
67 {
68         pm_cpu_prep = s3c2412_pm_prepare;
69         pm_cpu_sleep = s3c2412_cpu_suspend;
70
71         return 0;
72 }
73
74 static struct sleep_save s3c2412_sleep[] = {
75         SAVE_ITEM(S3C2412_DSC0),
76         SAVE_ITEM(S3C2412_DSC1),
77         SAVE_ITEM(S3C2413_GPJDAT),
78         SAVE_ITEM(S3C2413_GPJCON),
79         SAVE_ITEM(S3C2413_GPJUP),
80
81         /* save the PWRCFG to get back to original sleep method */
82
83         SAVE_ITEM(S3C2412_PWRCFG),
84
85         /* save the sleep configuration anyway, just in case these
86          * get damaged during wakeup */
87
88         SAVE_ITEM(S3C2412_GPBSLPCON),
89         SAVE_ITEM(S3C2412_GPCSLPCON),
90         SAVE_ITEM(S3C2412_GPDSLPCON),
91         SAVE_ITEM(S3C2412_GPESLPCON),
92         SAVE_ITEM(S3C2412_GPFSLPCON),
93         SAVE_ITEM(S3C2412_GPGSLPCON),
94         SAVE_ITEM(S3C2412_GPHSLPCON),
95         SAVE_ITEM(S3C2413_GPJSLPCON),
96 };
97
98 static int s3c2412_pm_suspend(struct sys_device *dev, pm_message_t state)
99 {
100         s3c2410_pm_do_save(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
101         return 0;
102 }
103
104 static int s3c2412_pm_resume(struct sys_device *dev)
105 {
106         unsigned long tmp;
107
108         tmp = __raw_readl(S3C2412_PWRCFG);
109         tmp &= ~S3C2412_PWRCFG_STANDBYWFI_MASK;
110         tmp |=  S3C2412_PWRCFG_STANDBYWFI_IDLE;
111         __raw_writel(tmp, S3C2412_PWRCFG);
112
113         s3c2410_pm_do_restore(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
114         return 0;
115 }
116
117 static struct sysdev_driver s3c2412_pm_driver = {
118         .add            = s3c2412_pm_add,
119         .suspend        = s3c2412_pm_suspend,
120         .resume         = s3c2412_pm_resume,
121 };
122
123 static __init int s3c2412_pm_init(void)
124 {
125         return sysdev_driver_register(&s3c2412_sysclass, &s3c2412_pm_driver);
126 }
127
128 arch_initcall(s3c2412_pm_init);