blob: d744606e19e90b8e4d8711dc85d682f1bfef7349 [file] [log] [blame]
Maxime Bizone7300d02009-08-18 13:23:37 +01001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2008 Nicolas Schichan <nschichan@freebox.fr>
8 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/interrupt.h>
13#include <linux/module.h>
David Howellsca4d3e672010-10-07 14:08:54 +010014#include <linux/irq.h>
Maxime Bizone7300d02009-08-18 13:23:37 +010015#include <asm/irq_cpu.h>
16#include <asm/mipsregs.h>
17#include <bcm63xx_cpu.h>
18#include <bcm63xx_regs.h>
19#include <bcm63xx_io.h>
20#include <bcm63xx_irq.h>
21
Maxime Bizonf61cced2011-11-04 19:09:31 +010022static void __dispatch_internal(void) __maybe_unused;
Maxime Bizon71a43922011-11-04 19:09:33 +010023static void __dispatch_internal_64(void) __maybe_unused;
24static void __internal_irq_mask_32(unsigned int irq) __maybe_unused;
25static void __internal_irq_mask_64(unsigned int irq) __maybe_unused;
26static void __internal_irq_unmask_32(unsigned int irq) __maybe_unused;
27static void __internal_irq_unmask_64(unsigned int irq) __maybe_unused;
Maxime Bizonf61cced2011-11-04 19:09:31 +010028
29#ifndef BCMCPU_RUNTIME_DETECT
Jonas Gorskie5766ae2012-07-24 16:33:12 +020030#ifdef CONFIG_BCM63XX_CPU_6328
31#define irq_stat_reg PERF_IRQSTAT_6328_REG
32#define irq_mask_reg PERF_IRQMASK_6328_REG
33#define irq_bits 64
34#define is_ext_irq_cascaded 1
35#define ext_irq_start (BCM_6328_EXT_IRQ0 - IRQ_INTERNAL_BASE)
36#define ext_irq_end (BCM_6328_EXT_IRQ3 - IRQ_INTERNAL_BASE)
37#define ext_irq_count 4
38#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6328
39#define ext_irq_cfg_reg2 0
40#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +010041#ifdef CONFIG_BCM63XX_CPU_6338
42#define irq_stat_reg PERF_IRQSTAT_6338_REG
43#define irq_mask_reg PERF_IRQMASK_6338_REG
Maxime Bizon71a43922011-11-04 19:09:33 +010044#define irq_bits 32
Maxime Bizon37c42a72011-11-04 19:09:32 +010045#define is_ext_irq_cascaded 0
46#define ext_irq_start 0
47#define ext_irq_end 0
Maxime Bizon62248922011-11-04 19:09:34 +010048#define ext_irq_count 4
49#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6338
50#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010051#endif
52#ifdef CONFIG_BCM63XX_CPU_6345
53#define irq_stat_reg PERF_IRQSTAT_6345_REG
54#define irq_mask_reg PERF_IRQMASK_6345_REG
Maxime Bizon71a43922011-11-04 19:09:33 +010055#define irq_bits 32
Maxime Bizon37c42a72011-11-04 19:09:32 +010056#define is_ext_irq_cascaded 0
57#define ext_irq_start 0
58#define ext_irq_end 0
Maxime Bizon64eaea42012-07-13 07:46:03 +000059#define ext_irq_count 4
60#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6345
Maxime Bizon62248922011-11-04 19:09:34 +010061#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010062#endif
63#ifdef CONFIG_BCM63XX_CPU_6348
64#define irq_stat_reg PERF_IRQSTAT_6348_REG
65#define irq_mask_reg PERF_IRQMASK_6348_REG
Maxime Bizon71a43922011-11-04 19:09:33 +010066#define irq_bits 32
Maxime Bizon37c42a72011-11-04 19:09:32 +010067#define is_ext_irq_cascaded 0
68#define ext_irq_start 0
69#define ext_irq_end 0
Maxime Bizon62248922011-11-04 19:09:34 +010070#define ext_irq_count 4
71#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6348
72#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010073#endif
74#ifdef CONFIG_BCM63XX_CPU_6358
75#define irq_stat_reg PERF_IRQSTAT_6358_REG
76#define irq_mask_reg PERF_IRQMASK_6358_REG
Maxime Bizon71a43922011-11-04 19:09:33 +010077#define irq_bits 32
Maxime Bizon37c42a72011-11-04 19:09:32 +010078#define is_ext_irq_cascaded 1
79#define ext_irq_start (BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE)
80#define ext_irq_end (BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE)
Maxime Bizon62248922011-11-04 19:09:34 +010081#define ext_irq_count 4
82#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6358
83#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010084#endif
Jonas Gorski2c8aaf72013-03-21 14:03:17 +000085#ifdef CONFIG_BCM63XX_CPU_6362
86#define irq_stat_reg PERF_IRQSTAT_6362_REG
87#define irq_mask_reg PERF_IRQMASK_6362_REG
88#define irq_bits 64
89#define is_ext_irq_cascaded 1
90#define ext_irq_start (BCM_6362_EXT_IRQ0 - IRQ_INTERNAL_BASE)
91#define ext_irq_end (BCM_6362_EXT_IRQ3 - IRQ_INTERNAL_BASE)
92#define ext_irq_count 4
93#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6362
94#define ext_irq_cfg_reg2 0
95#endif
Maxime Bizon04712f32011-11-04 19:09:35 +010096#ifdef CONFIG_BCM63XX_CPU_6368
97#define irq_stat_reg PERF_IRQSTAT_6368_REG
98#define irq_mask_reg PERF_IRQMASK_6368_REG
99#define irq_bits 64
100#define is_ext_irq_cascaded 1
101#define ext_irq_start (BCM_6368_EXT_IRQ0 - IRQ_INTERNAL_BASE)
102#define ext_irq_end (BCM_6368_EXT_IRQ5 - IRQ_INTERNAL_BASE)
103#define ext_irq_count 6
104#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6368
105#define ext_irq_cfg_reg2 PERF_EXTIRQ_CFG_REG2_6368
106#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +0100107
Maxime Bizon71a43922011-11-04 19:09:33 +0100108#if irq_bits == 32
109#define dispatch_internal __dispatch_internal
110#define internal_irq_mask __internal_irq_mask_32
111#define internal_irq_unmask __internal_irq_unmask_32
112#else
113#define dispatch_internal __dispatch_internal_64
114#define internal_irq_mask __internal_irq_mask_64
115#define internal_irq_unmask __internal_irq_unmask_64
116#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +0100117
118#define irq_stat_addr (bcm63xx_regset_address(RSET_PERF) + irq_stat_reg)
119#define irq_mask_addr (bcm63xx_regset_address(RSET_PERF) + irq_mask_reg)
120
121static inline void bcm63xx_init_irq(void)
122{
123}
124#else /* ! BCMCPU_RUNTIME_DETECT */
125
126static u32 irq_stat_addr, irq_mask_addr;
127static void (*dispatch_internal)(void);
Maxime Bizon37c42a72011-11-04 19:09:32 +0100128static int is_ext_irq_cascaded;
Maxime Bizon62248922011-11-04 19:09:34 +0100129static unsigned int ext_irq_count;
Maxime Bizon37c42a72011-11-04 19:09:32 +0100130static unsigned int ext_irq_start, ext_irq_end;
Maxime Bizon62248922011-11-04 19:09:34 +0100131static unsigned int ext_irq_cfg_reg1, ext_irq_cfg_reg2;
Maxime Bizon71a43922011-11-04 19:09:33 +0100132static void (*internal_irq_mask)(unsigned int irq);
133static void (*internal_irq_unmask)(unsigned int irq);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100134
135static void bcm63xx_init_irq(void)
136{
Maxime Bizon71a43922011-11-04 19:09:33 +0100137 int irq_bits;
138
Maxime Bizonf61cced2011-11-04 19:09:31 +0100139 irq_stat_addr = bcm63xx_regset_address(RSET_PERF);
140 irq_mask_addr = bcm63xx_regset_address(RSET_PERF);
141
142 switch (bcm63xx_get_cpu_id()) {
Jonas Gorskie5766ae2012-07-24 16:33:12 +0200143 case BCM6328_CPU_ID:
144 irq_stat_addr += PERF_IRQSTAT_6328_REG;
145 irq_mask_addr += PERF_IRQMASK_6328_REG;
146 irq_bits = 64;
147 ext_irq_count = 4;
148 is_ext_irq_cascaded = 1;
149 ext_irq_start = BCM_6328_EXT_IRQ0 - IRQ_INTERNAL_BASE;
150 ext_irq_end = BCM_6328_EXT_IRQ3 - IRQ_INTERNAL_BASE;
151 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6328;
152 break;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100153 case BCM6338_CPU_ID:
154 irq_stat_addr += PERF_IRQSTAT_6338_REG;
155 irq_mask_addr += PERF_IRQMASK_6338_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100156 irq_bits = 32;
Maxime Bizon64eaea42012-07-13 07:46:03 +0000157 ext_irq_count = 4;
158 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6338;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100159 break;
160 case BCM6345_CPU_ID:
161 irq_stat_addr += PERF_IRQSTAT_6345_REG;
162 irq_mask_addr += PERF_IRQMASK_6345_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100163 irq_bits = 32;
Maxime Bizon64eaea42012-07-13 07:46:03 +0000164 ext_irq_count = 4;
165 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6345;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100166 break;
167 case BCM6348_CPU_ID:
168 irq_stat_addr += PERF_IRQSTAT_6348_REG;
169 irq_mask_addr += PERF_IRQMASK_6348_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100170 irq_bits = 32;
Maxime Bizon62248922011-11-04 19:09:34 +0100171 ext_irq_count = 4;
172 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6348;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100173 break;
174 case BCM6358_CPU_ID:
175 irq_stat_addr += PERF_IRQSTAT_6358_REG;
176 irq_mask_addr += PERF_IRQMASK_6358_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100177 irq_bits = 32;
Maxime Bizon62248922011-11-04 19:09:34 +0100178 ext_irq_count = 4;
Maxime Bizon37c42a72011-11-04 19:09:32 +0100179 is_ext_irq_cascaded = 1;
180 ext_irq_start = BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE;
181 ext_irq_end = BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100182 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6358;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100183 break;
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000184 case BCM6362_CPU_ID:
185 irq_stat_addr += PERF_IRQSTAT_6362_REG;
186 irq_mask_addr += PERF_IRQMASK_6362_REG;
187 irq_bits = 64;
188 ext_irq_count = 4;
189 is_ext_irq_cascaded = 1;
190 ext_irq_start = BCM_6362_EXT_IRQ0 - IRQ_INTERNAL_BASE;
191 ext_irq_end = BCM_6362_EXT_IRQ3 - IRQ_INTERNAL_BASE;
192 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6362;
193 break;
Maxime Bizon04712f32011-11-04 19:09:35 +0100194 case BCM6368_CPU_ID:
195 irq_stat_addr += PERF_IRQSTAT_6368_REG;
196 irq_mask_addr += PERF_IRQMASK_6368_REG;
197 irq_bits = 64;
198 ext_irq_count = 6;
199 is_ext_irq_cascaded = 1;
200 ext_irq_start = BCM_6368_EXT_IRQ0 - IRQ_INTERNAL_BASE;
201 ext_irq_end = BCM_6368_EXT_IRQ5 - IRQ_INTERNAL_BASE;
202 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6368;
203 ext_irq_cfg_reg2 = PERF_EXTIRQ_CFG_REG2_6368;
204 break;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100205 default:
206 BUG();
207 }
208
Maxime Bizon71a43922011-11-04 19:09:33 +0100209 if (irq_bits == 32) {
210 dispatch_internal = __dispatch_internal;
211 internal_irq_mask = __internal_irq_mask_32;
212 internal_irq_unmask = __internal_irq_unmask_32;
213 } else {
214 dispatch_internal = __dispatch_internal_64;
215 internal_irq_mask = __internal_irq_mask_64;
216 internal_irq_unmask = __internal_irq_unmask_64;
217 }
Maxime Bizonf61cced2011-11-04 19:09:31 +0100218}
219#endif /* ! BCMCPU_RUNTIME_DETECT */
220
Maxime Bizon62248922011-11-04 19:09:34 +0100221static inline u32 get_ext_irq_perf_reg(int irq)
222{
223 if (irq < 4)
224 return ext_irq_cfg_reg1;
225 return ext_irq_cfg_reg2;
226}
227
Maxime Bizonf61cced2011-11-04 19:09:31 +0100228static inline void handle_internal(int intbit)
229{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100230 if (is_ext_irq_cascaded &&
231 intbit >= ext_irq_start && intbit <= ext_irq_end)
232 do_IRQ(intbit - ext_irq_start + IRQ_EXTERNAL_BASE);
233 else
234 do_IRQ(intbit + IRQ_INTERNAL_BASE);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100235}
236
Maxime Bizone7300d02009-08-18 13:23:37 +0100237/*
238 * dispatch internal devices IRQ (uart, enet, watchdog, ...). do not
239 * prioritize any interrupt relatively to another. the static counter
240 * will resume the loop where it ended the last time we left this
241 * function.
242 */
Maxime Bizonf61cced2011-11-04 19:09:31 +0100243static void __dispatch_internal(void)
Maxime Bizone7300d02009-08-18 13:23:37 +0100244{
245 u32 pending;
246 static int i;
247
Maxime Bizonf61cced2011-11-04 19:09:31 +0100248 pending = bcm_readl(irq_stat_addr) & bcm_readl(irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100249
250 if (!pending)
251 return ;
252
253 while (1) {
254 int to_call = i;
255
256 i = (i + 1) & 0x1f;
257 if (pending & (1 << to_call)) {
Maxime Bizonf61cced2011-11-04 19:09:31 +0100258 handle_internal(to_call);
Maxime Bizone7300d02009-08-18 13:23:37 +0100259 break;
260 }
261 }
262}
263
Maxime Bizon71a43922011-11-04 19:09:33 +0100264static void __dispatch_internal_64(void)
265{
266 u64 pending;
267 static int i;
268
269 pending = bcm_readq(irq_stat_addr) & bcm_readq(irq_mask_addr);
270
271 if (!pending)
272 return ;
273
274 while (1) {
275 int to_call = i;
276
277 i = (i + 1) & 0x3f;
278 if (pending & (1ull << to_call)) {
279 handle_internal(to_call);
280 break;
281 }
282 }
283}
284
Maxime Bizone7300d02009-08-18 13:23:37 +0100285asmlinkage void plat_irq_dispatch(void)
286{
287 u32 cause;
288
289 do {
290 cause = read_c0_cause() & read_c0_status() & ST0_IM;
291
292 if (!cause)
293 break;
294
295 if (cause & CAUSEF_IP7)
296 do_IRQ(7);
Kevin Cernekee937ad102013-06-03 14:39:34 +0000297 if (cause & CAUSEF_IP0)
298 do_IRQ(0);
299 if (cause & CAUSEF_IP1)
300 do_IRQ(1);
Maxime Bizone7300d02009-08-18 13:23:37 +0100301 if (cause & CAUSEF_IP2)
Maxime Bizonf61cced2011-11-04 19:09:31 +0100302 dispatch_internal();
Maxime Bizon37c42a72011-11-04 19:09:32 +0100303 if (!is_ext_irq_cascaded) {
304 if (cause & CAUSEF_IP3)
305 do_IRQ(IRQ_EXT_0);
306 if (cause & CAUSEF_IP4)
307 do_IRQ(IRQ_EXT_1);
308 if (cause & CAUSEF_IP5)
309 do_IRQ(IRQ_EXT_2);
310 if (cause & CAUSEF_IP6)
311 do_IRQ(IRQ_EXT_3);
312 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100313 } while (1);
314}
315
316/*
317 * internal IRQs operations: only mask/unmask on PERF irq mask
318 * register.
319 */
Maxime Bizon71a43922011-11-04 19:09:33 +0100320static void __internal_irq_mask_32(unsigned int irq)
Maxime Bizone7300d02009-08-18 13:23:37 +0100321{
322 u32 mask;
323
Maxime Bizonf61cced2011-11-04 19:09:31 +0100324 mask = bcm_readl(irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100325 mask &= ~(1 << irq);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100326 bcm_writel(mask, irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100327}
328
Maxime Bizon71a43922011-11-04 19:09:33 +0100329static void __internal_irq_mask_64(unsigned int irq)
330{
331 u64 mask;
332
333 mask = bcm_readq(irq_mask_addr);
334 mask &= ~(1ull << irq);
335 bcm_writeq(mask, irq_mask_addr);
336}
337
338static void __internal_irq_unmask_32(unsigned int irq)
Maxime Bizone7300d02009-08-18 13:23:37 +0100339{
340 u32 mask;
341
Maxime Bizonf61cced2011-11-04 19:09:31 +0100342 mask = bcm_readl(irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100343 mask |= (1 << irq);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100344 bcm_writel(mask, irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100345}
346
Maxime Bizon71a43922011-11-04 19:09:33 +0100347static void __internal_irq_unmask_64(unsigned int irq)
348{
349 u64 mask;
350
351 mask = bcm_readq(irq_mask_addr);
352 mask |= (1ull << irq);
353 bcm_writeq(mask, irq_mask_addr);
354}
355
Maxime Bizon37c42a72011-11-04 19:09:32 +0100356static void bcm63xx_internal_irq_mask(struct irq_data *d)
357{
358 internal_irq_mask(d->irq - IRQ_INTERNAL_BASE);
359}
360
361static void bcm63xx_internal_irq_unmask(struct irq_data *d)
362{
363 internal_irq_unmask(d->irq - IRQ_INTERNAL_BASE);
364}
365
Maxime Bizone7300d02009-08-18 13:23:37 +0100366/*
367 * external IRQs operations: mask/unmask and clear on PERF external
368 * irq control register.
369 */
Thomas Gleixner93f29362011-03-23 21:08:47 +0000370static void bcm63xx_external_irq_mask(struct irq_data *d)
Maxime Bizone7300d02009-08-18 13:23:37 +0100371{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100372 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100373 u32 reg, regaddr;
Maxime Bizone7300d02009-08-18 13:23:37 +0100374
Maxime Bizon62248922011-11-04 19:09:34 +0100375 regaddr = get_ext_irq_perf_reg(irq);
376 reg = bcm_perf_readl(regaddr);
377
378 if (BCMCPU_IS_6348())
379 reg &= ~EXTIRQ_CFG_MASK_6348(irq % 4);
380 else
381 reg &= ~EXTIRQ_CFG_MASK(irq % 4);
382
383 bcm_perf_writel(reg, regaddr);
Maxime Bizon37c42a72011-11-04 19:09:32 +0100384 if (is_ext_irq_cascaded)
385 internal_irq_mask(irq + ext_irq_start);
Maxime Bizone7300d02009-08-18 13:23:37 +0100386}
387
Thomas Gleixner93f29362011-03-23 21:08:47 +0000388static void bcm63xx_external_irq_unmask(struct irq_data *d)
Maxime Bizone7300d02009-08-18 13:23:37 +0100389{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100390 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100391 u32 reg, regaddr;
Maxime Bizone7300d02009-08-18 13:23:37 +0100392
Maxime Bizon62248922011-11-04 19:09:34 +0100393 regaddr = get_ext_irq_perf_reg(irq);
394 reg = bcm_perf_readl(regaddr);
395
396 if (BCMCPU_IS_6348())
397 reg |= EXTIRQ_CFG_MASK_6348(irq % 4);
398 else
399 reg |= EXTIRQ_CFG_MASK(irq % 4);
400
401 bcm_perf_writel(reg, regaddr);
402
Maxime Bizon37c42a72011-11-04 19:09:32 +0100403 if (is_ext_irq_cascaded)
404 internal_irq_unmask(irq + ext_irq_start);
Maxime Bizone7300d02009-08-18 13:23:37 +0100405}
406
Thomas Gleixner93f29362011-03-23 21:08:47 +0000407static void bcm63xx_external_irq_clear(struct irq_data *d)
Maxime Bizone7300d02009-08-18 13:23:37 +0100408{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100409 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100410 u32 reg, regaddr;
Maxime Bizone7300d02009-08-18 13:23:37 +0100411
Maxime Bizon62248922011-11-04 19:09:34 +0100412 regaddr = get_ext_irq_perf_reg(irq);
413 reg = bcm_perf_readl(regaddr);
414
415 if (BCMCPU_IS_6348())
416 reg |= EXTIRQ_CFG_CLEAR_6348(irq % 4);
417 else
418 reg |= EXTIRQ_CFG_CLEAR(irq % 4);
419
420 bcm_perf_writel(reg, regaddr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100421}
422
Thomas Gleixner93f29362011-03-23 21:08:47 +0000423static int bcm63xx_external_irq_set_type(struct irq_data *d,
Maxime Bizone7300d02009-08-18 13:23:37 +0100424 unsigned int flow_type)
425{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100426 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100427 u32 reg, regaddr;
428 int levelsense, sense, bothedge;
Maxime Bizone7300d02009-08-18 13:23:37 +0100429
430 flow_type &= IRQ_TYPE_SENSE_MASK;
431
432 if (flow_type == IRQ_TYPE_NONE)
433 flow_type = IRQ_TYPE_LEVEL_LOW;
434
Maxime Bizon62248922011-11-04 19:09:34 +0100435 levelsense = sense = bothedge = 0;
Maxime Bizone7300d02009-08-18 13:23:37 +0100436 switch (flow_type) {
437 case IRQ_TYPE_EDGE_BOTH:
Maxime Bizon62248922011-11-04 19:09:34 +0100438 bothedge = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100439 break;
440
441 case IRQ_TYPE_EDGE_RISING:
Maxime Bizon62248922011-11-04 19:09:34 +0100442 sense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100443 break;
444
445 case IRQ_TYPE_EDGE_FALLING:
Maxime Bizone7300d02009-08-18 13:23:37 +0100446 break;
447
448 case IRQ_TYPE_LEVEL_HIGH:
Maxime Bizon62248922011-11-04 19:09:34 +0100449 levelsense = 1;
450 sense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100451 break;
452
453 case IRQ_TYPE_LEVEL_LOW:
Maxime Bizon62248922011-11-04 19:09:34 +0100454 levelsense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100455 break;
456
457 default:
458 printk(KERN_ERR "bogus flow type combination given !\n");
459 return -EINVAL;
460 }
Maxime Bizon62248922011-11-04 19:09:34 +0100461
462 regaddr = get_ext_irq_perf_reg(irq);
463 reg = bcm_perf_readl(regaddr);
464 irq %= 4;
465
Maxime Bizon58e380a2012-07-13 07:46:05 +0000466 switch (bcm63xx_get_cpu_id()) {
467 case BCM6348_CPU_ID:
Maxime Bizon62248922011-11-04 19:09:34 +0100468 if (levelsense)
469 reg |= EXTIRQ_CFG_LEVELSENSE_6348(irq);
470 else
471 reg &= ~EXTIRQ_CFG_LEVELSENSE_6348(irq);
472 if (sense)
473 reg |= EXTIRQ_CFG_SENSE_6348(irq);
474 else
475 reg &= ~EXTIRQ_CFG_SENSE_6348(irq);
476 if (bothedge)
477 reg |= EXTIRQ_CFG_BOTHEDGE_6348(irq);
478 else
479 reg &= ~EXTIRQ_CFG_BOTHEDGE_6348(irq);
Maxime Bizon58e380a2012-07-13 07:46:05 +0000480 break;
Maxime Bizon62248922011-11-04 19:09:34 +0100481
Maxime Bizon58e380a2012-07-13 07:46:05 +0000482 case BCM6328_CPU_ID:
483 case BCM6338_CPU_ID:
484 case BCM6345_CPU_ID:
485 case BCM6358_CPU_ID:
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000486 case BCM6362_CPU_ID:
Maxime Bizon58e380a2012-07-13 07:46:05 +0000487 case BCM6368_CPU_ID:
Maxime Bizon62248922011-11-04 19:09:34 +0100488 if (levelsense)
489 reg |= EXTIRQ_CFG_LEVELSENSE(irq);
490 else
491 reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
492 if (sense)
493 reg |= EXTIRQ_CFG_SENSE(irq);
494 else
495 reg &= ~EXTIRQ_CFG_SENSE(irq);
496 if (bothedge)
497 reg |= EXTIRQ_CFG_BOTHEDGE(irq);
498 else
499 reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
Maxime Bizon58e380a2012-07-13 07:46:05 +0000500 break;
501 default:
502 BUG();
Maxime Bizon62248922011-11-04 19:09:34 +0100503 }
504
505 bcm_perf_writel(reg, regaddr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100506
Thomas Gleixner93f29362011-03-23 21:08:47 +0000507 irqd_set_trigger_type(d, flow_type);
508 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
509 __irq_set_handler_locked(d->irq, handle_level_irq);
510 else
511 __irq_set_handler_locked(d->irq, handle_edge_irq);
Maxime Bizone7300d02009-08-18 13:23:37 +0100512
Thomas Gleixner93f29362011-03-23 21:08:47 +0000513 return IRQ_SET_MASK_OK_NOCOPY;
Maxime Bizone7300d02009-08-18 13:23:37 +0100514}
515
516static struct irq_chip bcm63xx_internal_irq_chip = {
517 .name = "bcm63xx_ipic",
Thomas Gleixner93f29362011-03-23 21:08:47 +0000518 .irq_mask = bcm63xx_internal_irq_mask,
519 .irq_unmask = bcm63xx_internal_irq_unmask,
Maxime Bizone7300d02009-08-18 13:23:37 +0100520};
521
522static struct irq_chip bcm63xx_external_irq_chip = {
523 .name = "bcm63xx_epic",
Thomas Gleixner93f29362011-03-23 21:08:47 +0000524 .irq_ack = bcm63xx_external_irq_clear,
Maxime Bizone7300d02009-08-18 13:23:37 +0100525
Thomas Gleixner93f29362011-03-23 21:08:47 +0000526 .irq_mask = bcm63xx_external_irq_mask,
527 .irq_unmask = bcm63xx_external_irq_unmask,
Maxime Bizone7300d02009-08-18 13:23:37 +0100528
Thomas Gleixner93f29362011-03-23 21:08:47 +0000529 .irq_set_type = bcm63xx_external_irq_set_type,
Maxime Bizone7300d02009-08-18 13:23:37 +0100530};
531
532static struct irqaction cpu_ip2_cascade_action = {
533 .handler = no_action,
534 .name = "cascade_ip2",
Wu Zhangjin5a4a4ad2011-07-23 12:41:24 +0000535 .flags = IRQF_NO_THREAD,
Maxime Bizone7300d02009-08-18 13:23:37 +0100536};
537
Maxime Bizon37c42a72011-11-04 19:09:32 +0100538static struct irqaction cpu_ext_cascade_action = {
539 .handler = no_action,
540 .name = "cascade_extirq",
541 .flags = IRQF_NO_THREAD,
542};
543
Maxime Bizone7300d02009-08-18 13:23:37 +0100544void __init arch_init_irq(void)
545{
546 int i;
547
Maxime Bizonf61cced2011-11-04 19:09:31 +0100548 bcm63xx_init_irq();
Maxime Bizone7300d02009-08-18 13:23:37 +0100549 mips_cpu_irq_init();
550 for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200551 irq_set_chip_and_handler(i, &bcm63xx_internal_irq_chip,
Maxime Bizone7300d02009-08-18 13:23:37 +0100552 handle_level_irq);
553
Maxime Bizon62248922011-11-04 19:09:34 +0100554 for (i = IRQ_EXTERNAL_BASE; i < IRQ_EXTERNAL_BASE + ext_irq_count; ++i)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200555 irq_set_chip_and_handler(i, &bcm63xx_external_irq_chip,
Maxime Bizone7300d02009-08-18 13:23:37 +0100556 handle_edge_irq);
557
Maxime Bizon37c42a72011-11-04 19:09:32 +0100558 if (!is_ext_irq_cascaded) {
Maxime Bizon62248922011-11-04 19:09:34 +0100559 for (i = 3; i < 3 + ext_irq_count; ++i)
Maxime Bizon37c42a72011-11-04 19:09:32 +0100560 setup_irq(MIPS_CPU_IRQ_BASE + i, &cpu_ext_cascade_action);
561 }
562
563 setup_irq(MIPS_CPU_IRQ_BASE + 2, &cpu_ip2_cascade_action);
Maxime Bizone7300d02009-08-18 13:23:37 +0100564}