2 * Copyright 2011-2013 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
14 #include <linux/irq.h>
16 #include <linux/of_address.h>
17 #include <linux/of_irq.h>
18 #include <linux/irqchip/arm-gic.h>
21 #define GPC_IMR1 0x008
22 #define GPC_PGC_CPU_PDN 0x2a0
26 static void __iomem *gpc_base;
27 static u32 gpc_wake_irqs[IMR_NUM];
28 static u32 gpc_saved_imrs[IMR_NUM];
30 void imx_gpc_pre_suspend(void)
32 void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
35 /* Tell GPC to power off ARM core when suspend */
36 writel_relaxed(0x1, gpc_base + GPC_PGC_CPU_PDN);
38 for (i = 0; i < IMR_NUM; i++) {
39 gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
40 writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4);
44 void imx_gpc_post_resume(void)
46 void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
49 /* Keep ARM core powered on for other low-power modes */
50 writel_relaxed(0x0, gpc_base + GPC_PGC_CPU_PDN);
52 for (i = 0; i < IMR_NUM; i++)
53 writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
56 static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
58 unsigned int idx = d->irq / 32 - 1;
61 /* Sanity check for SPI irq */
65 mask = 1 << d->irq % 32;
66 gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
67 gpc_wake_irqs[idx] & ~mask;
72 void imx_gpc_mask_all(void)
74 void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
77 for (i = 0; i < IMR_NUM; i++) {
78 gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
79 writel_relaxed(~0, reg_imr1 + i * 4);
84 void imx_gpc_restore_all(void)
86 void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
89 for (i = 0; i < IMR_NUM; i++)
90 writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
93 static void imx_gpc_irq_unmask(struct irq_data *d)
98 /* Sanity check for SPI irq */
102 reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
103 val = readl_relaxed(reg);
104 val &= ~(1 << d->irq % 32);
105 writel_relaxed(val, reg);
108 static void imx_gpc_irq_mask(struct irq_data *d)
113 /* Sanity check for SPI irq */
117 reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
118 val = readl_relaxed(reg);
119 val |= 1 << (d->irq % 32);
120 writel_relaxed(val, reg);
123 void __init imx_gpc_init(void)
125 struct device_node *np;
128 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
129 gpc_base = of_iomap(np, 0);
132 /* Initially mask all interrupts */
133 for (i = 0; i < IMR_NUM; i++)
134 writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
136 /* Register GPC as the secondary interrupt controller behind GIC */
137 gic_arch_extn.irq_mask = imx_gpc_irq_mask;
138 gic_arch_extn.irq_unmask = imx_gpc_irq_unmask;
139 gic_arch_extn.irq_set_wake = imx_gpc_irq_set_wake;