2 * TI Common Platform Interrupt Controller (cp_intc) driver
4 * Author: Steve Chen <schen@mvista.com>
5 * Copyright (C) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/irq.h>
16 #include <mach/cp_intc.h>
18 static void __iomem
*cp_intc_base
;
20 static inline unsigned int cp_intc_read(unsigned offset
)
22 return __raw_readl(cp_intc_base
+ offset
);
25 static inline void cp_intc_write(unsigned long value
, unsigned offset
)
27 __raw_writel(value
, cp_intc_base
+ offset
);
30 static void cp_intc_ack_irq(unsigned int irq
)
32 cp_intc_write(irq
, CP_INTC_SYS_STAT_IDX_CLR
);
35 /* Disable interrupt */
36 static void cp_intc_mask_irq(unsigned int irq
)
38 /* XXX don't know why we need to disable nIRQ here... */
39 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_CLR
);
40 cp_intc_write(irq
, CP_INTC_SYS_ENABLE_IDX_CLR
);
41 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET
);
44 /* Enable interrupt */
45 static void cp_intc_unmask_irq(unsigned int irq
)
47 cp_intc_write(irq
, CP_INTC_SYS_ENABLE_IDX_SET
);
50 static int cp_intc_set_irq_type(unsigned int irq
, unsigned int flow_type
)
52 unsigned reg
= BIT_WORD(irq
);
53 unsigned mask
= BIT_MASK(irq
);
54 unsigned polarity
= cp_intc_read(CP_INTC_SYS_POLARITY(reg
));
55 unsigned type
= cp_intc_read(CP_INTC_SYS_TYPE(reg
));
58 case IRQ_TYPE_EDGE_RISING
:
62 case IRQ_TYPE_EDGE_FALLING
:
66 case IRQ_TYPE_LEVEL_HIGH
:
70 case IRQ_TYPE_LEVEL_LOW
:
78 cp_intc_write(polarity
, CP_INTC_SYS_POLARITY(reg
));
79 cp_intc_write(type
, CP_INTC_SYS_TYPE(reg
));
85 * Faking this allows us to to work with suspend functions of
86 * generic drivers which call {enable|disable}_irq_wake for
87 * wake up interrupt sources (eg RTC on DA850).
89 static int cp_intc_set_wake(unsigned int irq
, unsigned int on
)
94 static struct irq_chip cp_intc_irq_chip
= {
96 .ack
= cp_intc_ack_irq
,
97 .mask
= cp_intc_mask_irq
,
98 .unmask
= cp_intc_unmask_irq
,
99 .set_type
= cp_intc_set_irq_type
,
100 .set_wake
= cp_intc_set_wake
,
103 void __init
cp_intc_init(void __iomem
*base
, unsigned short num_irq
,
106 unsigned num_reg
= BITS_TO_LONGS(num_irq
);
111 cp_intc_write(0, CP_INTC_GLOBAL_ENABLE
);
113 /* Disable all host interrupts */
114 cp_intc_write(0, CP_INTC_HOST_ENABLE(0));
116 /* Disable system interrupts */
117 for (i
= 0; i
< num_reg
; i
++)
118 cp_intc_write(~0, CP_INTC_SYS_ENABLE_CLR(i
));
120 /* Set to normal mode, no nesting, no priority hold */
121 cp_intc_write(0, CP_INTC_CTRL
);
122 cp_intc_write(0, CP_INTC_HOST_CTRL
);
124 /* Clear system interrupt status */
125 for (i
= 0; i
< num_reg
; i
++)
126 cp_intc_write(~0, CP_INTC_SYS_STAT_CLR(i
));
128 /* Enable nIRQ (what about nFIQ?) */
129 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET
);
132 * Priority is determined by host channel: lower channel number has
133 * higher priority i.e. channel 0 has highest priority and channel 31
134 * had the lowest priority.
136 num_reg
= (num_irq
+ 3) >> 2; /* 4 channels per register */
141 for (k
= i
= 0; i
< num_reg
; i
++) {
142 for (val
= j
= 0; j
< 4; j
++, k
++) {
145 val
|= irq_prio
[k
] << 24;
148 cp_intc_write(val
, CP_INTC_CHAN_MAP(i
));
152 * Default everything to channel 15 if priority not specified.
153 * Note that channel 0-1 are mapped to nFIQ and channels 2-31
154 * are mapped to nIRQ.
156 for (i
= 0; i
< num_reg
; i
++)
157 cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i
));
160 /* Set up genirq dispatching for cp_intc */
161 for (i
= 0; i
< num_irq
; i
++) {
162 set_irq_chip(i
, &cp_intc_irq_chip
);
163 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
164 set_irq_handler(i
, handle_edge_irq
);
167 /* Enable global interrupt */
168 cp_intc_write(1, CP_INTC_GLOBAL_ENABLE
);