2 * linux/arch/arm/mach-mmp/irq.c
4 * Generic IRQ handling, GPIO IRQ demultiplexing, etc.
5 * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd.
7 * Author: Bin Yang <bin.yang@marvell.com>
8 * Haojian Zhuang <haojian.zhuang@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/irq.h>
18 #include <linux/irqdomain.h>
20 #include <linux/ioport.h>
21 #include <linux/of_address.h>
22 #include <linux/of_irq.h>
24 #include <mach/irqs.h>
26 #ifdef CONFIG_CPU_MMP2
27 #include <mach/pm-mmp2.h>
29 #ifdef CONFIG_CPU_PXA910
30 #include <mach/pm-pxa910.h>
37 struct icu_chip_data
{
39 unsigned int virq_base
;
40 unsigned int cascade_irq
;
41 void __iomem
*reg_status
;
42 void __iomem
*reg_mask
;
43 unsigned int conf_enable
;
44 unsigned int conf_disable
;
45 unsigned int conf_mask
;
46 unsigned int clr_mfp_irq_base
;
47 unsigned int clr_mfp_hwirq
;
48 struct irq_domain
*domain
;
51 struct mmp_intc_conf
{
52 unsigned int conf_enable
;
53 unsigned int conf_disable
;
54 unsigned int conf_mask
;
57 void __iomem
*mmp_icu_base
;
58 static struct icu_chip_data icu_data
[MAX_ICU_NR
];
59 static int max_icu_nr
;
61 extern void mmp2_clear_pmic_int(void);
63 static void icu_mask_ack_irq(struct irq_data
*d
)
65 struct irq_domain
*domain
= d
->domain
;
66 struct icu_chip_data
*data
= (struct icu_chip_data
*)domain
->host_data
;
70 hwirq
= d
->irq
- data
->virq_base
;
71 if (data
== &icu_data
[0]) {
72 r
= readl_relaxed(mmp_icu_base
+ (hwirq
<< 2));
73 r
&= ~data
->conf_mask
;
74 r
|= data
->conf_disable
;
75 writel_relaxed(r
, mmp_icu_base
+ (hwirq
<< 2));
77 #ifdef CONFIG_CPU_MMP2
78 if ((data
->virq_base
== data
->clr_mfp_irq_base
)
79 && (hwirq
== data
->clr_mfp_hwirq
))
80 mmp2_clear_pmic_int();
82 r
= readl_relaxed(data
->reg_mask
) | (1 << hwirq
);
83 writel_relaxed(r
, data
->reg_mask
);
87 static void icu_mask_irq(struct irq_data
*d
)
89 struct irq_domain
*domain
= d
->domain
;
90 struct icu_chip_data
*data
= (struct icu_chip_data
*)domain
->host_data
;
94 hwirq
= d
->irq
- data
->virq_base
;
95 if (data
== &icu_data
[0]) {
96 r
= readl_relaxed(mmp_icu_base
+ (hwirq
<< 2));
97 r
&= ~data
->conf_mask
;
98 r
|= data
->conf_disable
;
99 writel_relaxed(r
, mmp_icu_base
+ (hwirq
<< 2));
101 r
= readl_relaxed(data
->reg_mask
) | (1 << hwirq
);
102 writel_relaxed(r
, data
->reg_mask
);
106 static void icu_unmask_irq(struct irq_data
*d
)
108 struct irq_domain
*domain
= d
->domain
;
109 struct icu_chip_data
*data
= (struct icu_chip_data
*)domain
->host_data
;
113 hwirq
= d
->irq
- data
->virq_base
;
114 if (data
== &icu_data
[0]) {
115 r
= readl_relaxed(mmp_icu_base
+ (hwirq
<< 2));
116 r
&= ~data
->conf_mask
;
117 r
|= data
->conf_enable
;
118 writel_relaxed(r
, mmp_icu_base
+ (hwirq
<< 2));
120 r
= readl_relaxed(data
->reg_mask
) & ~(1 << hwirq
);
121 writel_relaxed(r
, data
->reg_mask
);
125 static struct irq_chip icu_irq_chip
= {
127 .irq_mask
= icu_mask_irq
,
128 .irq_mask_ack
= icu_mask_ack_irq
,
129 .irq_unmask
= icu_unmask_irq
,
132 static void icu_mux_irq_demux(unsigned int irq
, struct irq_desc
*desc
)
134 struct irq_domain
*domain
;
135 struct icu_chip_data
*data
;
137 unsigned long mask
, status
, n
;
139 for (i
= 1; i
< max_icu_nr
; i
++) {
140 if (irq
== icu_data
[i
].cascade_irq
) {
141 domain
= icu_data
[i
].domain
;
142 data
= (struct icu_chip_data
*)domain
->host_data
;
146 if (i
>= max_icu_nr
) {
147 pr_err("Spurious irq %d in MMP INTC\n", irq
);
151 mask
= readl_relaxed(data
->reg_mask
);
153 status
= readl_relaxed(data
->reg_status
) & ~mask
;
156 for_each_set_bit(n
, &status
, BITS_PER_LONG
) {
157 generic_handle_irq(icu_data
[i
].virq_base
+ n
);
162 static int mmp_irq_domain_map(struct irq_domain
*d
, unsigned int irq
,
165 irq_set_chip_and_handler(irq
, &icu_irq_chip
, handle_level_irq
);
166 set_irq_flags(irq
, IRQF_VALID
);
170 static int mmp_irq_domain_xlate(struct irq_domain
*d
, struct device_node
*node
,
171 const u32
*intspec
, unsigned int intsize
,
172 unsigned long *out_hwirq
,
173 unsigned int *out_type
)
175 *out_hwirq
= intspec
[0];
179 const struct irq_domain_ops mmp_irq_domain_ops
= {
180 .map
= mmp_irq_domain_map
,
181 .xlate
= mmp_irq_domain_xlate
,
184 static struct mmp_intc_conf mmp_conf
= {
190 static struct mmp_intc_conf mmp2_conf
= {
197 void __init
icu_init_irq(void)
202 mmp_icu_base
= ioremap(0xd4282000, 0x1000);
203 icu_data
[0].conf_enable
= mmp_conf
.conf_enable
;
204 icu_data
[0].conf_disable
= mmp_conf
.conf_disable
;
205 icu_data
[0].conf_mask
= mmp_conf
.conf_mask
;
206 icu_data
[0].nr_irqs
= 64;
207 icu_data
[0].virq_base
= 0;
208 icu_data
[0].domain
= irq_domain_add_legacy(NULL
, 64, 0, 0,
209 &irq_domain_simple_ops
,
211 for (irq
= 0; irq
< 64; irq
++) {
212 icu_mask_irq(irq_get_irq_data(irq
));
213 irq_set_chip_and_handler(irq
, &icu_irq_chip
, handle_level_irq
);
214 set_irq_flags(irq
, IRQF_VALID
);
216 irq_set_default_host(icu_data
[0].domain
);
217 #ifdef CONFIG_CPU_PXA910
218 icu_irq_chip
.irq_set_wake
= pxa910_set_wake
;
223 void __init
mmp2_init_icu(void)
228 mmp_icu_base
= ioremap(0xd4282000, 0x1000);
229 icu_data
[0].conf_enable
= mmp2_conf
.conf_enable
;
230 icu_data
[0].conf_disable
= mmp2_conf
.conf_disable
;
231 icu_data
[0].conf_mask
= mmp2_conf
.conf_mask
;
232 icu_data
[0].nr_irqs
= 64;
233 icu_data
[0].virq_base
= 0;
234 icu_data
[0].domain
= irq_domain_add_legacy(NULL
, 64, 0, 0,
235 &irq_domain_simple_ops
,
237 icu_data
[1].reg_status
= mmp_icu_base
+ 0x150;
238 icu_data
[1].reg_mask
= mmp_icu_base
+ 0x168;
239 icu_data
[1].clr_mfp_irq_base
= IRQ_MMP2_PMIC_BASE
;
240 icu_data
[1].clr_mfp_hwirq
= IRQ_MMP2_PMIC
- IRQ_MMP2_PMIC_BASE
;
241 icu_data
[1].nr_irqs
= 2;
242 icu_data
[1].cascade_irq
= 4;
243 icu_data
[1].virq_base
= IRQ_MMP2_PMIC_BASE
;
244 icu_data
[1].domain
= irq_domain_add_legacy(NULL
, icu_data
[1].nr_irqs
,
245 icu_data
[1].virq_base
, 0,
246 &irq_domain_simple_ops
,
248 icu_data
[2].reg_status
= mmp_icu_base
+ 0x154;
249 icu_data
[2].reg_mask
= mmp_icu_base
+ 0x16c;
250 icu_data
[2].nr_irqs
= 2;
251 icu_data
[2].cascade_irq
= 5;
252 icu_data
[2].virq_base
= IRQ_MMP2_RTC_BASE
;
253 icu_data
[2].domain
= irq_domain_add_legacy(NULL
, icu_data
[2].nr_irqs
,
254 icu_data
[2].virq_base
, 0,
255 &irq_domain_simple_ops
,
257 icu_data
[3].reg_status
= mmp_icu_base
+ 0x180;
258 icu_data
[3].reg_mask
= mmp_icu_base
+ 0x17c;
259 icu_data
[3].nr_irqs
= 3;
260 icu_data
[3].cascade_irq
= 9;
261 icu_data
[3].virq_base
= IRQ_MMP2_KEYPAD_BASE
;
262 icu_data
[3].domain
= irq_domain_add_legacy(NULL
, icu_data
[3].nr_irqs
,
263 icu_data
[3].virq_base
, 0,
264 &irq_domain_simple_ops
,
266 icu_data
[4].reg_status
= mmp_icu_base
+ 0x158;
267 icu_data
[4].reg_mask
= mmp_icu_base
+ 0x170;
268 icu_data
[4].nr_irqs
= 5;
269 icu_data
[4].cascade_irq
= 17;
270 icu_data
[4].virq_base
= IRQ_MMP2_TWSI_BASE
;
271 icu_data
[4].domain
= irq_domain_add_legacy(NULL
, icu_data
[4].nr_irqs
,
272 icu_data
[4].virq_base
, 0,
273 &irq_domain_simple_ops
,
275 icu_data
[5].reg_status
= mmp_icu_base
+ 0x15c;
276 icu_data
[5].reg_mask
= mmp_icu_base
+ 0x174;
277 icu_data
[5].nr_irqs
= 15;
278 icu_data
[5].cascade_irq
= 35;
279 icu_data
[5].virq_base
= IRQ_MMP2_MISC_BASE
;
280 icu_data
[5].domain
= irq_domain_add_legacy(NULL
, icu_data
[5].nr_irqs
,
281 icu_data
[5].virq_base
, 0,
282 &irq_domain_simple_ops
,
284 icu_data
[6].reg_status
= mmp_icu_base
+ 0x160;
285 icu_data
[6].reg_mask
= mmp_icu_base
+ 0x178;
286 icu_data
[6].nr_irqs
= 2;
287 icu_data
[6].cascade_irq
= 51;
288 icu_data
[6].virq_base
= IRQ_MMP2_MIPI_HSI1_BASE
;
289 icu_data
[6].domain
= irq_domain_add_legacy(NULL
, icu_data
[6].nr_irqs
,
290 icu_data
[6].virq_base
, 0,
291 &irq_domain_simple_ops
,
293 icu_data
[7].reg_status
= mmp_icu_base
+ 0x188;
294 icu_data
[7].reg_mask
= mmp_icu_base
+ 0x184;
295 icu_data
[7].nr_irqs
= 2;
296 icu_data
[7].cascade_irq
= 55;
297 icu_data
[7].virq_base
= IRQ_MMP2_MIPI_HSI0_BASE
;
298 icu_data
[7].domain
= irq_domain_add_legacy(NULL
, icu_data
[7].nr_irqs
,
299 icu_data
[7].virq_base
, 0,
300 &irq_domain_simple_ops
,
302 for (irq
= 0; irq
< IRQ_MMP2_MUX_END
; irq
++) {
303 icu_mask_irq(irq_get_irq_data(irq
));
305 case IRQ_MMP2_PMIC_MUX
:
306 case IRQ_MMP2_RTC_MUX
:
307 case IRQ_MMP2_KEYPAD_MUX
:
308 case IRQ_MMP2_TWSI_MUX
:
309 case IRQ_MMP2_MISC_MUX
:
310 case IRQ_MMP2_MIPI_HSI1_MUX
:
311 case IRQ_MMP2_MIPI_HSI0_MUX
:
312 irq_set_chip(irq
, &icu_irq_chip
);
313 irq_set_chained_handler(irq
, icu_mux_irq_demux
);
316 irq_set_chip_and_handler(irq
, &icu_irq_chip
,
320 set_irq_flags(irq
, IRQF_VALID
);
322 irq_set_default_host(icu_data
[0].domain
);
323 #ifdef CONFIG_CPU_MMP2
324 icu_irq_chip
.irq_set_wake
= mmp2_set_wake
;
329 static const struct of_device_id intc_ids
[] __initconst
= {
330 { .compatible
= "mrvl,mmp-intc", .data
= &mmp_conf
},
331 { .compatible
= "mrvl,mmp2-intc", .data
= &mmp2_conf
},
335 static const struct of_device_id mmp_mux_irq_match
[] __initconst
= {
336 { .compatible
= "mrvl,mmp2-mux-intc" },
340 int __init
mmp2_mux_init(struct device_node
*parent
)
342 struct device_node
*node
;
343 const struct of_device_id
*of_id
;
345 int i
, irq_base
, ret
, irq
;
346 u32 nr_irqs
, mfp_irq
;
350 for (i
= 1; i
< MAX_ICU_NR
; i
++) {
351 node
= of_find_matching_node(node
, mmp_mux_irq_match
);
354 of_id
= of_match_node(&mmp_mux_irq_match
[0], node
);
355 ret
= of_property_read_u32(node
, "mrvl,intc-nr-irqs",
358 pr_err("Not found mrvl,intc-nr-irqs property\n");
362 ret
= of_address_to_resource(node
, 0, &res
);
364 pr_err("Not found reg property\n");
368 icu_data
[i
].reg_status
= mmp_icu_base
+ res
.start
;
369 ret
= of_address_to_resource(node
, 1, &res
);
371 pr_err("Not found reg property\n");
375 icu_data
[i
].reg_mask
= mmp_icu_base
+ res
.start
;
376 icu_data
[i
].cascade_irq
= irq_of_parse_and_map(node
, 0);
377 if (!icu_data
[i
].cascade_irq
) {
382 irq_base
= irq_alloc_descs(-1, 0, nr_irqs
, 0);
384 pr_err("Failed to allocate IRQ numbers for mux intc\n");
388 if (!of_property_read_u32(node
, "mrvl,clr-mfp-irq",
390 icu_data
[i
].clr_mfp_irq_base
= irq_base
;
391 icu_data
[i
].clr_mfp_hwirq
= mfp_irq
;
393 irq_set_chained_handler(icu_data
[i
].cascade_irq
,
395 icu_data
[i
].nr_irqs
= nr_irqs
;
396 icu_data
[i
].virq_base
= irq_base
;
397 icu_data
[i
].domain
= irq_domain_add_legacy(node
, nr_irqs
,
401 for (irq
= irq_base
; irq
< irq_base
+ nr_irqs
; irq
++)
402 icu_mask_irq(irq_get_irq_data(irq
));
412 void __init
mmp_dt_irq_init(void)
414 struct device_node
*node
;
415 const struct of_device_id
*of_id
;
416 struct mmp_intc_conf
*conf
;
417 int nr_irqs
, irq_base
, ret
, irq
;
419 node
= of_find_matching_node(NULL
, intc_ids
);
421 pr_err("Failed to find interrupt controller in arch-mmp\n");
424 of_id
= of_match_node(intc_ids
, node
);
427 ret
= of_property_read_u32(node
, "mrvl,intc-nr-irqs", &nr_irqs
);
429 pr_err("Not found mrvl,intc-nr-irqs property\n");
433 mmp_icu_base
= of_iomap(node
, 0);
435 pr_err("Failed to get interrupt controller register\n");
439 irq_base
= irq_alloc_descs(-1, 0, nr_irqs
- NR_IRQS_LEGACY
, 0);
441 pr_err("Failed to allocate IRQ numbers\n");
443 } else if (irq_base
!= NR_IRQS_LEGACY
) {
444 pr_err("ICU's irqbase should be started from 0\n");
447 icu_data
[0].conf_enable
= conf
->conf_enable
;
448 icu_data
[0].conf_disable
= conf
->conf_disable
;
449 icu_data
[0].conf_mask
= conf
->conf_mask
;
450 icu_data
[0].nr_irqs
= nr_irqs
;
451 icu_data
[0].virq_base
= 0;
452 icu_data
[0].domain
= irq_domain_add_legacy(node
, nr_irqs
, 0, 0,
455 irq_set_default_host(icu_data
[0].domain
);
456 for (irq
= 0; irq
< nr_irqs
; irq
++)
457 icu_mask_irq(irq_get_irq_data(irq
));
461 iounmap(mmp_icu_base
);