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/common.h>
17 #include <mach/cp_intc.h>
19 static inline unsigned int cp_intc_read(unsigned offset
)
21 return __raw_readl(davinci_intc_base
+ offset
);
24 static inline void cp_intc_write(unsigned long value
, unsigned offset
)
26 __raw_writel(value
, davinci_intc_base
+ offset
);
29 static void cp_intc_ack_irq(unsigned int irq
)
31 cp_intc_write(irq
, CP_INTC_SYS_STAT_IDX_CLR
);
34 /* Disable interrupt */
35 static void cp_intc_mask_irq(unsigned int irq
)
37 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_CLR
);
38 cp_intc_write(irq
, CP_INTC_SYS_ENABLE_IDX_CLR
);
39 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET
);
42 /* Enable interrupt */
43 static void cp_intc_unmask_irq(unsigned int irq
)
45 cp_intc_write(irq
, CP_INTC_SYS_ENABLE_IDX_SET
);
48 static int cp_intc_set_irq_type(unsigned int irq
, unsigned int flow_type
)
50 unsigned reg
= BIT_WORD(irq
);
51 unsigned mask
= BIT_MASK(irq
);
52 unsigned polarity
= cp_intc_read(CP_INTC_SYS_POLARITY(reg
));
53 unsigned type
= cp_intc_read(CP_INTC_SYS_TYPE(reg
));
56 case IRQ_TYPE_EDGE_RISING
:
60 case IRQ_TYPE_EDGE_FALLING
:
64 case IRQ_TYPE_LEVEL_HIGH
:
68 case IRQ_TYPE_LEVEL_LOW
:
76 cp_intc_write(polarity
, CP_INTC_SYS_POLARITY(reg
));
77 cp_intc_write(type
, CP_INTC_SYS_TYPE(reg
));
83 * Faking this allows us to to work with suspend functions of
84 * generic drivers which call {enable|disable}_irq_wake for
85 * wake up interrupt sources (eg RTC on DA850).
87 static int cp_intc_set_wake(unsigned int irq
, unsigned int on
)
92 static struct irq_chip cp_intc_irq_chip
= {
94 .ack
= cp_intc_ack_irq
,
95 .mask
= cp_intc_mask_irq
,
96 .unmask
= cp_intc_unmask_irq
,
97 .set_type
= cp_intc_set_irq_type
,
98 .set_wake
= cp_intc_set_wake
,
101 void __init
cp_intc_init(void)
103 unsigned long num_irq
= davinci_soc_info
.intc_irq_num
;
104 u8
*irq_prio
= davinci_soc_info
.intc_irq_prios
;
105 u32
*host_map
= davinci_soc_info
.intc_host_map
;
106 unsigned num_reg
= BITS_TO_LONGS(num_irq
);
109 davinci_intc_type
= DAVINCI_INTC_TYPE_CP_INTC
;
110 davinci_intc_base
= ioremap(davinci_soc_info
.intc_base
, SZ_8K
);
111 if (WARN_ON(!davinci_intc_base
))
114 cp_intc_write(0, CP_INTC_GLOBAL_ENABLE
);
116 /* Disable all host interrupts */
117 cp_intc_write(0, CP_INTC_HOST_ENABLE(0));
119 /* Disable system interrupts */
120 for (i
= 0; i
< num_reg
; i
++)
121 cp_intc_write(~0, CP_INTC_SYS_ENABLE_CLR(i
));
123 /* Set to normal mode, no nesting, no priority hold */
124 cp_intc_write(0, CP_INTC_CTRL
);
125 cp_intc_write(0, CP_INTC_HOST_CTRL
);
127 /* Clear system interrupt status */
128 for (i
= 0; i
< num_reg
; i
++)
129 cp_intc_write(~0, CP_INTC_SYS_STAT_CLR(i
));
131 /* Enable nIRQ (what about nFIQ?) */
132 cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET
);
135 * Priority is determined by host channel: lower channel number has
136 * higher priority i.e. channel 0 has highest priority and channel 31
137 * had the lowest priority.
139 num_reg
= (num_irq
+ 3) >> 2; /* 4 channels per register */
144 for (k
= i
= 0; i
< num_reg
; i
++) {
145 for (val
= j
= 0; j
< 4; j
++, k
++) {
148 val
|= irq_prio
[k
] << 24;
151 cp_intc_write(val
, CP_INTC_CHAN_MAP(i
));
155 * Default everything to channel 15 if priority not specified.
156 * Note that channel 0-1 are mapped to nFIQ and channels 2-31
157 * are mapped to nIRQ.
159 for (i
= 0; i
< num_reg
; i
++)
160 cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i
));
164 for (i
= 0; host_map
[i
] != -1; i
++)
165 cp_intc_write(host_map
[i
], CP_INTC_HOST_MAP(i
));
167 /* Set up genirq dispatching for cp_intc */
168 for (i
= 0; i
< num_irq
; i
++) {
169 set_irq_chip(i
, &cp_intc_irq_chip
);
170 set_irq_flags(i
, IRQF_VALID
| IRQF_PROBE
);
171 set_irq_handler(i
, handle_edge_irq
);
174 /* Enable global interrupt */
175 cp_intc_write(1, CP_INTC_GLOBAL_ENABLE
);