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>
15 #include <linux/irqchip.h>
17 #include <linux/of_address.h>
18 #include <linux/of_irq.h>
19 #include <linux/irqchip/arm-gic.h>
23 #define GPC_IMR1 0x008
24 #define GPC_PGC_CPU_PDN 0x2a0
25 #define GPC_PGC_CPU_PUPSCR 0x2a4
26 #define GPC_PGC_CPU_PDNSCR 0x2a8
27 #define GPC_PGC_SW2ISO_SHIFT 0x8
28 #define GPC_PGC_SW_SHIFT 0x0
31 #define GPC_MAX_IRQS (IMR_NUM * 32)
33 static void __iomem
*gpc_base
;
34 static u32 gpc_wake_irqs
[IMR_NUM
];
35 static u32 gpc_saved_imrs
[IMR_NUM
];
37 void imx_gpc_set_arm_power_up_timing(u32 sw2iso
, u32 sw
)
39 writel_relaxed((sw2iso
<< GPC_PGC_SW2ISO_SHIFT
) |
40 (sw
<< GPC_PGC_SW_SHIFT
), gpc_base
+ GPC_PGC_CPU_PUPSCR
);
43 void imx_gpc_set_arm_power_down_timing(u32 sw2iso
, u32 sw
)
45 writel_relaxed((sw2iso
<< GPC_PGC_SW2ISO_SHIFT
) |
46 (sw
<< GPC_PGC_SW_SHIFT
), gpc_base
+ GPC_PGC_CPU_PDNSCR
);
49 void imx_gpc_set_arm_power_in_lpm(bool power_off
)
51 writel_relaxed(power_off
, gpc_base
+ GPC_PGC_CPU_PDN
);
54 void imx_gpc_pre_suspend(bool arm_power_off
)
56 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
59 /* Tell GPC to power off ARM core when suspend */
61 imx_gpc_set_arm_power_in_lpm(arm_power_off
);
63 for (i
= 0; i
< IMR_NUM
; i
++) {
64 gpc_saved_imrs
[i
] = readl_relaxed(reg_imr1
+ i
* 4);
65 writel_relaxed(~gpc_wake_irqs
[i
], reg_imr1
+ i
* 4);
69 void imx_gpc_post_resume(void)
71 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
74 /* Keep ARM core powered on for other low-power modes */
75 imx_gpc_set_arm_power_in_lpm(false);
77 for (i
= 0; i
< IMR_NUM
; i
++)
78 writel_relaxed(gpc_saved_imrs
[i
], reg_imr1
+ i
* 4);
81 static int imx_gpc_irq_set_wake(struct irq_data
*d
, unsigned int on
)
83 unsigned int idx
= d
->hwirq
/ 32;
86 mask
= 1 << d
->hwirq
% 32;
87 gpc_wake_irqs
[idx
] = on
? gpc_wake_irqs
[idx
] | mask
:
88 gpc_wake_irqs
[idx
] & ~mask
;
91 * Do *not* call into the parent, as the GIC doesn't have any
97 void imx_gpc_mask_all(void)
99 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
102 for (i
= 0; i
< IMR_NUM
; i
++) {
103 gpc_saved_imrs
[i
] = readl_relaxed(reg_imr1
+ i
* 4);
104 writel_relaxed(~0, reg_imr1
+ i
* 4);
109 void imx_gpc_restore_all(void)
111 void __iomem
*reg_imr1
= gpc_base
+ GPC_IMR1
;
114 for (i
= 0; i
< IMR_NUM
; i
++)
115 writel_relaxed(gpc_saved_imrs
[i
], reg_imr1
+ i
* 4);
118 void imx_gpc_hwirq_unmask(unsigned int hwirq
)
123 reg
= gpc_base
+ GPC_IMR1
+ hwirq
/ 32 * 4;
124 val
= readl_relaxed(reg
);
125 val
&= ~(1 << hwirq
% 32);
126 writel_relaxed(val
, reg
);
129 void imx_gpc_hwirq_mask(unsigned int hwirq
)
134 reg
= gpc_base
+ GPC_IMR1
+ hwirq
/ 32 * 4;
135 val
= readl_relaxed(reg
);
136 val
|= 1 << (hwirq
% 32);
137 writel_relaxed(val
, reg
);
140 static void imx_gpc_irq_unmask(struct irq_data
*d
)
142 imx_gpc_hwirq_unmask(d
->hwirq
);
143 irq_chip_unmask_parent(d
);
146 static void imx_gpc_irq_mask(struct irq_data
*d
)
148 imx_gpc_hwirq_mask(d
->hwirq
);
149 irq_chip_mask_parent(d
);
152 static struct irq_chip imx_gpc_chip
= {
154 .irq_eoi
= irq_chip_eoi_parent
,
155 .irq_mask
= imx_gpc_irq_mask
,
156 .irq_unmask
= imx_gpc_irq_unmask
,
157 .irq_retrigger
= irq_chip_retrigger_hierarchy
,
158 .irq_set_wake
= imx_gpc_irq_set_wake
,
159 .irq_set_type
= irq_chip_set_type_parent
,
161 .irq_set_affinity
= irq_chip_set_affinity_parent
,
165 static int imx_gpc_domain_translate(struct irq_domain
*d
,
166 struct irq_fwspec
*fwspec
,
167 unsigned long *hwirq
,
170 if (is_of_node(fwspec
->fwnode
)) {
171 if (fwspec
->param_count
!= 3)
174 /* No PPI should point to this domain */
175 if (fwspec
->param
[0] != 0)
178 *hwirq
= fwspec
->param
[1];
179 *type
= fwspec
->param
[2];
186 static int imx_gpc_domain_alloc(struct irq_domain
*domain
,
188 unsigned int nr_irqs
, void *data
)
190 struct irq_fwspec
*fwspec
= data
;
191 struct irq_fwspec parent_fwspec
;
192 irq_hw_number_t hwirq
;
195 if (fwspec
->param_count
!= 3)
196 return -EINVAL
; /* Not GIC compliant */
197 if (fwspec
->param
[0] != 0)
198 return -EINVAL
; /* No PPI should point to this domain */
200 hwirq
= fwspec
->param
[1];
201 if (hwirq
>= GPC_MAX_IRQS
)
202 return -EINVAL
; /* Can't deal with this */
204 for (i
= 0; i
< nr_irqs
; i
++)
205 irq_domain_set_hwirq_and_chip(domain
, irq
+ i
, hwirq
+ i
,
206 &imx_gpc_chip
, NULL
);
208 parent_fwspec
= *fwspec
;
209 parent_fwspec
.fwnode
= domain
->parent
->fwnode
;
210 return irq_domain_alloc_irqs_parent(domain
, irq
, nr_irqs
,
214 static const struct irq_domain_ops imx_gpc_domain_ops
= {
215 .translate
= imx_gpc_domain_translate
,
216 .alloc
= imx_gpc_domain_alloc
,
217 .free
= irq_domain_free_irqs_common
,
220 static int __init
imx_gpc_init(struct device_node
*node
,
221 struct device_node
*parent
)
223 struct irq_domain
*parent_domain
, *domain
;
227 pr_err("%pOF: no parent, giving up\n", node
);
231 parent_domain
= irq_find_host(parent
);
232 if (!parent_domain
) {
233 pr_err("%pOF: unable to obtain parent domain\n", node
);
237 gpc_base
= of_iomap(node
, 0);
238 if (WARN_ON(!gpc_base
))
241 domain
= irq_domain_add_hierarchy(parent_domain
, 0, GPC_MAX_IRQS
,
242 node
, &imx_gpc_domain_ops
,
249 /* Initially mask all interrupts */
250 for (i
= 0; i
< IMR_NUM
; i
++)
251 writel_relaxed(~0, gpc_base
+ GPC_IMR1
+ i
* 4);
254 * Clear the OF_POPULATED flag set in of_irq_init so that
255 * later the GPC power domain driver will not be skipped.
257 of_node_clear_flag(node
, OF_POPULATED
);
261 IRQCHIP_DECLARE(imx_gpc
, "fsl,imx6q-gpc", imx_gpc_init
);
263 void __init
imx_gpc_check_dt(void)
265 struct device_node
*np
;
267 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx6q-gpc");
271 if (WARN_ON(!of_find_property(np
, "interrupt-controller", NULL
))) {
272 pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
274 /* map GPC, so that at least CPUidle and WARs keep working */
275 gpc_base
= of_iomap(np
, 0);