aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mmp/irq-mmp2.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-mmp/irq-mmp2.c')
-rw-r--r--arch/arm/mach-mmp/irq-mmp2.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/arch/arm/mach-mmp/irq-mmp2.c b/arch/arm/mach-mmp/irq-mmp2.c
new file mode 100644
index 000000000000..dcd36f4bc9de
--- /dev/null
+++ b/arch/arm/mach-mmp/irq-mmp2.c
@@ -0,0 +1,138 @@
1/*
2 * linux/arch/arm/mach-mmp/irq-mmp2.c
3 *
4 * Generic IRQ handling, GPIO IRQ demultiplexing, etc.
5 *
6 * Author: Haojian Zhuang <haojian.zhuang@marvell.com>
7 * Copyright: Marvell International Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/init.h>
15#include <linux/irq.h>
16#include <linux/io.h>
17
18#include <mach/regs-icu.h>
19
20#include "common.h"
21
22static void icu_mask_irq(unsigned int irq)
23{
24 uint32_t r = __raw_readl(ICU_INT_CONF(irq));
25
26 r &= ~ICU_INT_ROUTE_PJ4_IRQ;
27 __raw_writel(r, ICU_INT_CONF(irq));
28}
29
30static void icu_unmask_irq(unsigned int irq)
31{
32 uint32_t r = __raw_readl(ICU_INT_CONF(irq));
33
34 r |= ICU_INT_ROUTE_PJ4_IRQ;
35 __raw_writel(r, ICU_INT_CONF(irq));
36}
37
38static struct irq_chip icu_irq_chip = {
39 .name = "icu_irq",
40 .mask_ack = icu_mask_irq,
41 .unmask = icu_unmask_irq,
42};
43
44#define SECOND_IRQ_MASK(_name_, irq_base, prefix) \
45static void _name_##_mask_irq(unsigned int irq) \
46{ \
47 uint32_t r; \
48 r = __raw_readl(prefix##_MASK) | (1 << (irq - irq_base)); \
49 __raw_writel(r, prefix##_MASK); \
50}
51
52#define SECOND_IRQ_UNMASK(_name_, irq_base, prefix) \
53static void _name_##_unmask_irq(unsigned int irq) \
54{ \
55 uint32_t r; \
56 r = __raw_readl(prefix##_MASK) & ~(1 << (irq - irq_base)); \
57 __raw_writel(r, prefix##_MASK); \
58}
59
60#define SECOND_IRQ_DEMUX(_name_, irq_base, prefix) \
61static void _name_##_irq_demux(unsigned int irq, struct irq_desc *desc) \
62{ \
63 unsigned long status, mask, n; \
64 mask = __raw_readl(prefix##_MASK); \
65 while (1) { \
66 status = __raw_readl(prefix##_STATUS) & ~mask; \
67 if (status == 0) \
68 break; \
69 n = find_first_bit(&status, BITS_PER_LONG); \
70 while (n < BITS_PER_LONG) { \
71 generic_handle_irq(irq_base + n); \
72 n = find_next_bit(&status, BITS_PER_LONG, n+1); \
73 } \
74 } \
75}
76
77#define SECOND_IRQ_CHIP(_name_, irq_base, prefix) \
78SECOND_IRQ_MASK(_name_, irq_base, prefix) \
79SECOND_IRQ_UNMASK(_name_, irq_base, prefix) \
80SECOND_IRQ_DEMUX(_name_, irq_base, prefix) \
81static struct irq_chip _name_##_irq_chip = { \
82 .name = #_name_, \
83 .mask_ack = _name_##_mask_irq, \
84 .unmask = _name_##_unmask_irq, \
85}
86
87SECOND_IRQ_CHIP(pmic, IRQ_MMP2_PMIC_BASE, MMP2_ICU_INT4);
88SECOND_IRQ_CHIP(rtc, IRQ_MMP2_RTC_BASE, MMP2_ICU_INT5);
89SECOND_IRQ_CHIP(twsi, IRQ_MMP2_TWSI_BASE, MMP2_ICU_INT17);
90SECOND_IRQ_CHIP(misc, IRQ_MMP2_MISC_BASE, MMP2_ICU_INT35);
91SECOND_IRQ_CHIP(ssp, IRQ_MMP2_SSP_BASE, MMP2_ICU_INT51);
92
93static void init_mux_irq(struct irq_chip *chip, int start, int num)
94{
95 int irq;
96
97 for (irq = start; num > 0; irq++, num--) {
98 chip->mask_ack(irq);
99 set_irq_chip(irq, chip);
100 set_irq_flags(irq, IRQF_VALID);
101 set_irq_handler(irq, handle_level_irq);
102 }
103}
104
105void __init mmp2_init_irq(void)
106{
107 int irq;
108
109 for (irq = 0; irq < IRQ_MMP2_MUX_BASE; irq++) {
110 icu_mask_irq(irq);
111 set_irq_chip(irq, &icu_irq_chip);
112 set_irq_flags(irq, IRQF_VALID);
113
114 switch (irq) {
115 case IRQ_MMP2_PMIC_MUX:
116 case IRQ_MMP2_RTC_MUX:
117 case IRQ_MMP2_TWSI_MUX:
118 case IRQ_MMP2_MISC_MUX:
119 case IRQ_MMP2_SSP_MUX:
120 break;
121 default:
122 set_irq_handler(irq, handle_level_irq);
123 break;
124 }
125 }
126
127 init_mux_irq(&pmic_irq_chip, IRQ_MMP2_PMIC_BASE, 2);
128 init_mux_irq(&rtc_irq_chip, IRQ_MMP2_RTC_BASE, 2);
129 init_mux_irq(&twsi_irq_chip, IRQ_MMP2_TWSI_BASE, 5);
130 init_mux_irq(&misc_irq_chip, IRQ_MMP2_MISC_BASE, 15);
131 init_mux_irq(&ssp_irq_chip, IRQ_MMP2_SSP_BASE, 2);
132
133 set_irq_chained_handler(IRQ_MMP2_PMIC_MUX, pmic_irq_demux);
134 set_irq_chained_handler(IRQ_MMP2_RTC_MUX, rtc_irq_demux);
135 set_irq_chained_handler(IRQ_MMP2_TWSI_MUX, twsi_irq_demux);
136 set_irq_chained_handler(IRQ_MMP2_MISC_MUX, misc_irq_demux);
137 set_irq_chained_handler(IRQ_MMP2_SSP_MUX, ssp_irq_demux);
138}