2 * Copyright 2011 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 <asm/hardware/gic.h>
20 #define GPC_IMR1 0x008
21 #define GPC_PGC_CPU_PDN 0x2a0
25 static void __iomem
*gpc_base
;
26 static u32 gpc_wake_irqs
[IMR_NUM
];
27 static u32 gpc_saved_imrs
[IMR_NUM
];
29 void imx_gpc_pre_suspend(void)
31 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
34 /* Tell GPC to power off ARM core when suspend */
35 writel_relaxed(0x1, gpc_base
+ GPC_PGC_CPU_PDN
);
37 for (i
= 0; i
< IMR_NUM
; i
++) {
38 gpc_saved_imrs
[i
] = readl_relaxed(reg_imr1
+ i
* 4);
39 writel_relaxed(~gpc_wake_irqs
[i
], reg_imr1
+ i
* 4);
43 void imx_gpc_post_resume(void)
45 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
48 /* Keep ARM core powered on for other low-power modes */
49 writel_relaxed(0x0, gpc_base
+ GPC_PGC_CPU_PDN
);
51 for (i
= 0; i
< IMR_NUM
; i
++)
52 writel_relaxed(gpc_saved_imrs
[i
], reg_imr1
+ i
* 4);
55 static int imx_gpc_irq_set_wake(struct irq_data
*d
, unsigned int on
)
57 unsigned int idx
= d
->irq
/ 32 - 1;
60 /* Sanity check for SPI irq */
64 mask
= 1 << d
->irq
% 32;
65 gpc_wake_irqs
[idx
] = on
? gpc_wake_irqs
[idx
] | mask
:
66 gpc_wake_irqs
[idx
] & ~mask
;
71 static void imx_gpc_irq_unmask(struct irq_data
*d
)
76 /* Sanity check for SPI irq */
80 reg
= gpc_base
+ GPC_IMR1
+ (d
->irq
/ 32 - 1) * 4;
81 val
= readl_relaxed(reg
);
82 val
&= ~(1 << d
->irq
% 32);
83 writel_relaxed(val
, reg
);
86 static void imx_gpc_irq_mask(struct irq_data
*d
)
91 /* Sanity check for SPI irq */
95 reg
= gpc_base
+ GPC_IMR1
+ (d
->irq
/ 32 - 1) * 4;
96 val
= readl_relaxed(reg
);
97 val
|= 1 << (d
->irq
% 32);
98 writel_relaxed(val
, reg
);
101 void __init
imx_gpc_init(void)
103 struct device_node
*np
;
105 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx6q-gpc");
106 gpc_base
= of_iomap(np
, 0);
109 /* Register GPC as the secondary interrupt controller behind GIC */
110 gic_arch_extn
.irq_mask
= imx_gpc_irq_mask
;
111 gic_arch_extn
.irq_unmask
= imx_gpc_irq_unmask
;
112 gic_arch_extn
.irq_set_wake
= imx_gpc_irq_set_wake
;