blob: 6a9604477c9ee50aac9d4e95fa4d6ad5b3c39baf [file] [log] [blame]
Krzysztof Kozlowski84b21702017-12-25 20:54:32 +01001// 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/.
Ben Dooks4b053e72006-09-22 15:42:18 +01007
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>
Kay Sievers4a858cf2011-12-21 16:01:38 -080014#include <linux/device.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020015#include <linux/syscore_ops.h>
Ben Dooks4b053e72006-09-22 15:42:18 +010016#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010017#include <linux/io.h>
Ben Dooks4b053e72006-09-22 15:42:18 +010018
Ben Dooksdc8fc7e2009-04-28 10:06:00 +010019#include <asm/cacheflush.h>
Ben Dooks4b053e72006-09-22 15:42:18 +010020#include <asm/irq.h>
21
Arnd Bergmannb2a587c2020-08-06 20:20:47 +020022#include <mach/irqs.h>
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020023#include "regs-gpio.h"
Ben Dooks4b053e72006-09-22 15:42:18 +010024
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020025#include "cpu.h"
26#include "pm.h"
27#include "wakeup-mask.h"
Ben Dooks4b053e72006-09-22 15:42:18 +010028
Arnd Bergmann71b91142019-09-02 17:47:55 +020029#include "regs-dsc-s3c24xx.h"
Kukjin Kim14cce0e2013-02-01 21:49:35 -080030#include "s3c2412-power.h"
Kukjin Kimb4353782013-01-02 14:01:09 -080031
Ben Dooks33234952007-12-23 03:09:34 +010032extern void s3c2412_sleep_enter(void);
33
Russell King29cb3cd2011-07-02 09:54:01 +010034static int s3c2412_cpu_suspend(unsigned long arg)
Ben Dooks4b053e72006-09-22 15:42:18 +010035{
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
Ben Dooks33234952007-12-23 03:09:34 +010044 s3c2412_sleep_enter();
Russell King29cb3cd2011-07-02 09:54:01 +010045
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080046 pr_info("Failed to suspend the system\n");
47 return 1; /* Aborting suspend */
Ben Dooks4b053e72006-09-22 15:42:18 +010048}
49
Heiko Stuebner59295702013-02-12 10:09:10 -080050/* mapping of interrupts to parts of the wakeup mask */
Krzysztof Kozlowski7264ebd2016-12-10 15:47:37 +020051static const struct samsung_wakeup_mask wake_irqs[] = {
Heiko Stuebner59295702013-02-12 10:09:10 -080052 { .irq = IRQ_RTC, .bit = S3C2412_PWRCFG_RTC_MASKIRQ, },
53};
54
Ben Dooks4b053e72006-09-22 15:42:18 +010055static void s3c2412_pm_prepare(void)
56{
Heiko Stuebner59295702013-02-12 10:09:10 -080057 samsung_sync_wakemask(S3C2412_PWRCFG,
58 wake_irqs, ARRAY_SIZE(wake_irqs));
Ben Dooks4b053e72006-09-22 15:42:18 +010059}
60
Heiko Stuebner04511a62012-01-27 15:35:25 +090061static int s3c2412_pm_add(struct device *dev, struct subsys_interface *sif)
Ben Dooks4b053e72006-09-22 15:42:18 +010062{
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),
Ben Dooks4b053e72006-09-22 15:42:18 +010086 SAVE_ITEM(S3C2412_GPFSLPCON),
87 SAVE_ITEM(S3C2412_GPGSLPCON),
88 SAVE_ITEM(S3C2412_GPHSLPCON),
89 SAVE_ITEM(S3C2413_GPJSLPCON),
90};
91
Kay Sievers4a858cf2011-12-21 16:01:38 -080092static struct subsys_interface s3c2412_pm_interface = {
93 .name = "s3c2412_pm",
94 .subsys = &s3c2412_subsys,
95 .add_dev = s3c2412_pm_add,
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020096};
97
98static __init int s3c2412_pm_init(void)
99{
Kukjin Kimea040182012-01-06 16:08:09 +0900100 return subsys_interface_register(&s3c2412_pm_interface);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200101}
102
103arch_initcall(s3c2412_pm_init);
104
105static int s3c2412_pm_suspend(void)
Ben Dooks4b053e72006-09-22 15:42:18 +0100106{
Ben Dooks64197112008-12-12 00:24:06 +0000107 s3c_pm_do_save(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
Ben Dooks4b053e72006-09-22 15:42:18 +0100108 return 0;
109}
110
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200111static void s3c2412_pm_resume(void)
Ben Dooks4b053e72006-09-22 15:42:18 +0100112{
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
Ben Dooks64197112008-12-12 00:24:06 +0000120 s3c_pm_do_restore(s3c2412_sleep, ARRAY_SIZE(s3c2412_sleep));
Ben Dooks4b053e72006-09-22 15:42:18 +0100121}
122
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200123struct syscore_ops s3c2412_pm_syscore_ops = {
Ben Dooks4b053e72006-09-22 15:42:18 +0100124 .suspend = s3c2412_pm_suspend,
125 .resume = s3c2412_pm_resume,
126};