blob: 4a1e935bada1916e8459ab94a916148c8e7b0bf8 [file] [log] [blame]
Krzysztof Kozlowski28a196f2017-12-25 20:54:33 +01001// SPDX-License-Identifier: GPL-2.0
2//
3// Copyright 2008 Openmoko, Inc.
4// Copyright 2008 Simtec Electronics
5// Ben Dooks <ben@simtec.co.uk>
6// http://armlinux.simtec.co.uk/
7//
8// S3C64XX - Interrupt handling Power Management
Ben Dooks966bcc12008-12-12 00:24:32 +00009
Tomasz Figac836c902013-08-26 02:37:34 +090010/*
11 * NOTE: Code in this file is not used when booting with Device Tree support.
12 */
13
Ben Dooks966bcc12008-12-12 00:24:32 +000014#include <linux/kernel.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020015#include <linux/syscore_ops.h>
Ben Dooks966bcc12008-12-12 00:24:32 +000016#include <linux/interrupt.h>
17#include <linux/serial_core.h>
Tushar Behera334a1c72014-02-14 10:32:45 +090018#include <linux/serial_s3c.h>
Ben Dooks966bcc12008-12-12 00:24:32 +000019#include <linux/irq.h>
20#include <linux/io.h>
Tomasz Figac836c902013-08-26 02:37:34 +090021#include <linux/of.h>
Ben Dooks966bcc12008-12-12 00:24:32 +000022
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020023#include "map.h"
Ben Dooks966bcc12008-12-12 00:24:32 +000024
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020025#include "regs-gpio.h"
26#include "cpu.h"
27#include "pm.h"
Ben Dooks966bcc12008-12-12 00:24:32 +000028
29/* We handled all the IRQ types in this code, to save having to make several
30 * small files to handle each different type separately. Having the EINT_GRP
31 * code here shouldn't be as much bloat as the IRQ table space needed when
32 * they are enabled. The added benefit is we ensure that these registers are
33 * in the same state as we suspended.
34 */
35
36static struct sleep_save irq_save[] = {
37 SAVE_ITEM(S3C64XX_PRIORITY),
38 SAVE_ITEM(S3C64XX_EINT0CON0),
39 SAVE_ITEM(S3C64XX_EINT0CON1),
40 SAVE_ITEM(S3C64XX_EINT0FLTCON0),
41 SAVE_ITEM(S3C64XX_EINT0FLTCON1),
42 SAVE_ITEM(S3C64XX_EINT0FLTCON2),
43 SAVE_ITEM(S3C64XX_EINT0FLTCON3),
44 SAVE_ITEM(S3C64XX_EINT0MASK),
Ben Dooks966bcc12008-12-12 00:24:32 +000045};
46
47static struct irq_grp_save {
48 u32 fltcon;
49 u32 con;
50 u32 mask;
51} eint_grp_save[5];
52
Arnd Bergmann0443a652014-02-26 17:55:35 +010053#ifndef CONFIG_SERIAL_SAMSUNG_UARTS
54#define SERIAL_SAMSUNG_UARTS 0
55#else
56#define SERIAL_SAMSUNG_UARTS CONFIG_SERIAL_SAMSUNG_UARTS
57#endif
58
59static u32 irq_uart_mask[SERIAL_SAMSUNG_UARTS];
Ben Dooks966bcc12008-12-12 00:24:32 +000060
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020061static int s3c64xx_irq_pm_suspend(void)
Ben Dooks966bcc12008-12-12 00:24:32 +000062{
63 struct irq_grp_save *grp = eint_grp_save;
64 int i;
65
66 S3C_PMDBG("%s: suspending IRQs\n", __func__);
67
68 s3c_pm_do_save(irq_save, ARRAY_SIZE(irq_save));
69
Arnd Bergmann0443a652014-02-26 17:55:35 +010070 for (i = 0; i < SERIAL_SAMSUNG_UARTS; i++)
Ben Dooks966bcc12008-12-12 00:24:32 +000071 irq_uart_mask[i] = __raw_readl(S3C_VA_UARTx(i) + S3C64XX_UINTM);
72
73 for (i = 0; i < ARRAY_SIZE(eint_grp_save); i++, grp++) {
74 grp->con = __raw_readl(S3C64XX_EINT12CON + (i * 4));
75 grp->mask = __raw_readl(S3C64XX_EINT12MASK + (i * 4));
76 grp->fltcon = __raw_readl(S3C64XX_EINT12FLTCON + (i * 4));
77 }
78
79 return 0;
80}
81
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020082static void s3c64xx_irq_pm_resume(void)
Ben Dooks966bcc12008-12-12 00:24:32 +000083{
84 struct irq_grp_save *grp = eint_grp_save;
85 int i;
86
87 S3C_PMDBG("%s: resuming IRQs\n", __func__);
88
89 s3c_pm_do_restore(irq_save, ARRAY_SIZE(irq_save));
90
Arnd Bergmann0443a652014-02-26 17:55:35 +010091 for (i = 0; i < SERIAL_SAMSUNG_UARTS; i++)
Ben Dooks966bcc12008-12-12 00:24:32 +000092 __raw_writel(irq_uart_mask[i], S3C_VA_UARTx(i) + S3C64XX_UINTM);
93
94 for (i = 0; i < ARRAY_SIZE(eint_grp_save); i++, grp++) {
95 __raw_writel(grp->con, S3C64XX_EINT12CON + (i * 4));
96 __raw_writel(grp->mask, S3C64XX_EINT12MASK + (i * 4));
97 __raw_writel(grp->fltcon, S3C64XX_EINT12FLTCON + (i * 4));
98 }
99
100 S3C_PMDBG("%s: IRQ configuration restored\n", __func__);
Ben Dooks966bcc12008-12-12 00:24:32 +0000101}
102
Kukjin Kim5086c6c2012-01-21 11:32:42 +0900103static struct syscore_ops s3c64xx_irq_syscore_ops = {
Ben Dooks966bcc12008-12-12 00:24:32 +0000104 .suspend = s3c64xx_irq_pm_suspend,
105 .resume = s3c64xx_irq_pm_resume,
106};
107
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200108static __init int s3c64xx_syscore_init(void)
Ben Dooks966bcc12008-12-12 00:24:32 +0000109{
Tomasz Figac836c902013-08-26 02:37:34 +0900110 /* Appropriate drivers (pinctrl, uart) handle this when using DT. */
Arnd Bergmanna0e157a2015-02-27 20:31:51 +0100111 if (of_have_populated_dt() || !soc_is_s3c64xx())
Tomasz Figac836c902013-08-26 02:37:34 +0900112 return 0;
113
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200114 register_syscore_ops(&s3c64xx_irq_syscore_ops);
115
116 return 0;
Ben Dooks966bcc12008-12-12 00:24:32 +0000117}
118
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200119core_initcall(s3c64xx_syscore_init);