Merge tag 'iversion-v4.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton...
[linux-2.6-block.git] / arch / arm / mach-s3c24xx / pm-s3c2412.c
CommitLineData
84b21701
KK
1// SPDX-License-Identifier: GPL-2.0
2//
3// Copyright (c) 2006 Simtec Electronics
4// Ben Dooks <ben@simtec.co.uk>
5//
6// http://armlinux.simtec.co.uk/.
4b053e7a
BD
7
8#include <linux/kernel.h>
9#include <linux/types.h>
10#include <linux/interrupt.h>
11#include <linux/list.h>
12#include <linux/timer.h>
13#include <linux/init.h>
4a858cfc 14#include <linux/device.h>
bb072c3c 15#include <linux/syscore_ops.h>
4b053e7a 16#include <linux/platform_device.h>
fced80c7 17#include <linux/io.h>
4b053e7a 18
dc8fc7ed 19#include <asm/cacheflush.h>
4b053e7a
BD
20#include <asm/irq.h>
21
b4353784 22#include <mach/hardware.h>
a09e64fb 23#include <mach/regs-gpio.h>
4b053e7a 24
a2b7ba9c
BD
25#include <plat/cpu.h>
26#include <plat/pm.h>
59295708 27#include <plat/wakeup-mask.h>
4b053e7a 28
b4353784 29#include "regs-dsc.h"
14cce0e7 30#include "s3c2412-power.h"
b4353784 31
33234951
BD
32extern void s3c2412_sleep_enter(void);
33
29cb3cd2 34static int s3c2412_cpu_suspend(unsigned long arg)
4b053e7a
BD
35{
36 unsigned long tmp;
37
38 /* set our standby method to sleep */
39
40 tmp = __raw_readl(S3C2412_PWRCFG);
41 tmp |= S3C2412_PWRCFG_STANDBYWFI_SLEEP;
42 __raw_writel(tmp, S3C2412_PWRCFG);
43
33234951 44 s3c2412_sleep_enter();
29cb3cd2 45
d3fcacf5
AK
46 pr_info("Failed to suspend the system\n");
47 return 1; /* Aborting suspend */
4b053e7a
BD
48}
49
59295708 50/* mapping of interrupts to parts of the wakeup mask */
7264ebd9 51static const struct samsung_wakeup_mask wake_irqs[] = {
59295708
HS
52 { .irq = IRQ_RTC, .bit = S3C2412_PWRCFG_RTC_MASKIRQ, },
53};
54
4b053e7a
BD
55static void s3c2412_pm_prepare(void)
56{
59295708
HS
57 samsung_sync_wakemask(S3C2412_PWRCFG,
58 wake_irqs, ARRAY_SIZE(wake_irqs));
4b053e7a
BD
59}
60
04511a6f 61static int s3c2412_pm_add(struct device *dev, struct subsys_interface *sif)
4b053e7a
BD
62{
63 pm_cpu_prep = s3c2412_pm_prepare;
64 pm_cpu_sleep = s3c2412_cpu_suspend;
65
66 return 0;
67}
68
69static struct sleep_save s3c2412_sleep[] = {
70 SAVE_ITEM(S3C2412_DSC0),
71 SAVE_ITEM(S3C2412_DSC1),
72 SAVE_ITEM(S3C2413_GPJDAT),
73 SAVE_ITEM(S3C2413_GPJCON),
74 SAVE_ITEM(S3C2413_GPJUP),
75
76 /* save the PWRCFG to get back to original sleep method */
77
78 SAVE_ITEM(S3C2412_PWRCFG),
79
80 /* save the sleep configuration anyway, just in case these
81 * get damaged during wakeup */
82
83 SAVE_ITEM(S3C2412_GPBSLPCON),
84 SAVE_ITEM(S3C2412_GPCSLPCON),
85 SAVE_ITEM(S3C2412_GPDSLPCON),
4b053e7a
BD
86 SAVE_ITEM(S3C2412_GPFSLPCON),
87 SAVE_ITEM(S3C2412_GPGSLPCON),
88 SAVE_ITEM(S3C2412_GPHSLPCON),
89 SAVE_ITEM(S3C2413_GPJSLPCON),
90};
91
4a858cfc
KS
92static struct subsys_interface s3c2412_pm_interface = {
93 .name = "s3c2412_pm",
94 .subsys = &s3c2412_subsys,
95 .add_dev = s3c2412_pm_add,
bb072c3c
RW
96};
97
98static __init int s3c2412_pm_init(void)
99{
ea04018e 100 return subsys_interface_register(&s3c2412_pm_interface);
bb072c3c
RW
101}
102
103arch_initcall(s3c2412_pm_init);
104
105static int s3c2412_pm_suspend(void)
4b053e7a 106{
6419711a 107 s3c_pm_do_save(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
4b053e7a
BD
108 return 0;
109}
110
bb072c3c 111static void s3c2412_pm_resume(void)
4b053e7a
BD
112{
113 unsigned long tmp;
114
115 tmp = __raw_readl(S3C2412_PWRCFG);
116 tmp &= ~S3C2412_PWRCFG_STANDBYWFI_MASK;
117 tmp |= S3C2412_PWRCFG_STANDBYWFI_IDLE;
118 __raw_writel(tmp, S3C2412_PWRCFG);
119
6419711a 120 s3c_pm_do_restore(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
4b053e7a
BD
121}
122
bb072c3c 123struct syscore_ops s3c2412_pm_syscore_ops = {
4b053e7a
BD
124 .suspend = s3c2412_pm_suspend,
125 .resume = s3c2412_pm_resume,
126};