blob: 1525f8a3841b946889d6553ca799d2550afb8f10 [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
Florian Fainelli7b933422013-06-18 16:55:40 +000030#ifdef CONFIG_BCM63XX_CPU_3368
31#define irq_stat_reg PERF_IRQSTAT_3368_REG
32#define irq_mask_reg PERF_IRQMASK_3368_REG
33#define irq_bits 32
34#define is_ext_irq_cascaded 0
35#define ext_irq_start 0
36#define ext_irq_end 0
37#define ext_irq_count 4
38#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_3368
39#define ext_irq_cfg_reg2 0
40#endif
Jonas Gorskie5766ae2012-07-24 16:33:12 +020041#ifdef CONFIG_BCM63XX_CPU_6328
42#define irq_stat_reg PERF_IRQSTAT_6328_REG
43#define irq_mask_reg PERF_IRQMASK_6328_REG
44#define irq_bits 64
45#define is_ext_irq_cascaded 1
46#define ext_irq_start (BCM_6328_EXT_IRQ0 - IRQ_INTERNAL_BASE)
47#define ext_irq_end (BCM_6328_EXT_IRQ3 - IRQ_INTERNAL_BASE)
48#define ext_irq_count 4
49#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6328
50#define ext_irq_cfg_reg2 0
51#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +010052#ifdef CONFIG_BCM63XX_CPU_6338
53#define irq_stat_reg PERF_IRQSTAT_6338_REG
54#define irq_mask_reg PERF_IRQMASK_6338_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 Bizon62248922011-11-04 19:09:34 +010059#define ext_irq_count 4
60#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6338
61#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010062#endif
63#ifdef CONFIG_BCM63XX_CPU_6345
64#define irq_stat_reg PERF_IRQSTAT_6345_REG
65#define irq_mask_reg PERF_IRQMASK_6345_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 Bizon64eaea42012-07-13 07:46:03 +000070#define ext_irq_count 4
71#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6345
Maxime Bizon62248922011-11-04 19:09:34 +010072#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010073#endif
74#ifdef CONFIG_BCM63XX_CPU_6348
75#define irq_stat_reg PERF_IRQSTAT_6348_REG
76#define irq_mask_reg PERF_IRQMASK_6348_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 0
79#define ext_irq_start 0
80#define ext_irq_end 0
Maxime Bizon62248922011-11-04 19:09:34 +010081#define ext_irq_count 4
82#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6348
83#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010084#endif
85#ifdef CONFIG_BCM63XX_CPU_6358
86#define irq_stat_reg PERF_IRQSTAT_6358_REG
87#define irq_mask_reg PERF_IRQMASK_6358_REG
Maxime Bizon71a43922011-11-04 19:09:33 +010088#define irq_bits 32
Maxime Bizon37c42a72011-11-04 19:09:32 +010089#define is_ext_irq_cascaded 1
90#define ext_irq_start (BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE)
91#define ext_irq_end (BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE)
Maxime Bizon62248922011-11-04 19:09:34 +010092#define ext_irq_count 4
93#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6358
94#define ext_irq_cfg_reg2 0
Maxime Bizonf61cced2011-11-04 19:09:31 +010095#endif
Jonas Gorski2c8aaf72013-03-21 14:03:17 +000096#ifdef CONFIG_BCM63XX_CPU_6362
97#define irq_stat_reg PERF_IRQSTAT_6362_REG
98#define irq_mask_reg PERF_IRQMASK_6362_REG
99#define irq_bits 64
100#define is_ext_irq_cascaded 1
101#define ext_irq_start (BCM_6362_EXT_IRQ0 - IRQ_INTERNAL_BASE)
102#define ext_irq_end (BCM_6362_EXT_IRQ3 - IRQ_INTERNAL_BASE)
103#define ext_irq_count 4
104#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6362
105#define ext_irq_cfg_reg2 0
106#endif
Maxime Bizon04712f32011-11-04 19:09:35 +0100107#ifdef CONFIG_BCM63XX_CPU_6368
108#define irq_stat_reg PERF_IRQSTAT_6368_REG
109#define irq_mask_reg PERF_IRQMASK_6368_REG
110#define irq_bits 64
111#define is_ext_irq_cascaded 1
112#define ext_irq_start (BCM_6368_EXT_IRQ0 - IRQ_INTERNAL_BASE)
113#define ext_irq_end (BCM_6368_EXT_IRQ5 - IRQ_INTERNAL_BASE)
114#define ext_irq_count 6
115#define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6368
116#define ext_irq_cfg_reg2 PERF_EXTIRQ_CFG_REG2_6368
117#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +0100118
Maxime Bizon71a43922011-11-04 19:09:33 +0100119#if irq_bits == 32
120#define dispatch_internal __dispatch_internal
121#define internal_irq_mask __internal_irq_mask_32
122#define internal_irq_unmask __internal_irq_unmask_32
123#else
124#define dispatch_internal __dispatch_internal_64
125#define internal_irq_mask __internal_irq_mask_64
126#define internal_irq_unmask __internal_irq_unmask_64
127#endif
Maxime Bizonf61cced2011-11-04 19:09:31 +0100128
129#define irq_stat_addr (bcm63xx_regset_address(RSET_PERF) + irq_stat_reg)
130#define irq_mask_addr (bcm63xx_regset_address(RSET_PERF) + irq_mask_reg)
131
132static inline void bcm63xx_init_irq(void)
133{
134}
135#else /* ! BCMCPU_RUNTIME_DETECT */
136
137static u32 irq_stat_addr, irq_mask_addr;
138static void (*dispatch_internal)(void);
Maxime Bizon37c42a72011-11-04 19:09:32 +0100139static int is_ext_irq_cascaded;
Maxime Bizon62248922011-11-04 19:09:34 +0100140static unsigned int ext_irq_count;
Maxime Bizon37c42a72011-11-04 19:09:32 +0100141static unsigned int ext_irq_start, ext_irq_end;
Maxime Bizon62248922011-11-04 19:09:34 +0100142static unsigned int ext_irq_cfg_reg1, ext_irq_cfg_reg2;
Maxime Bizon71a43922011-11-04 19:09:33 +0100143static void (*internal_irq_mask)(unsigned int irq);
144static void (*internal_irq_unmask)(unsigned int irq);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100145
146static void bcm63xx_init_irq(void)
147{
Maxime Bizon71a43922011-11-04 19:09:33 +0100148 int irq_bits;
149
Maxime Bizonf61cced2011-11-04 19:09:31 +0100150 irq_stat_addr = bcm63xx_regset_address(RSET_PERF);
151 irq_mask_addr = bcm63xx_regset_address(RSET_PERF);
152
153 switch (bcm63xx_get_cpu_id()) {
Florian Fainelli7b933422013-06-18 16:55:40 +0000154 case BCM3368_CPU_ID:
155 irq_stat_addr += PERF_IRQSTAT_3368_REG;
156 irq_mask_addr += PERF_IRQMASK_3368_REG;
157 irq_bits = 32;
158 ext_irq_count = 4;
159 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_3368;
160 break;
Jonas Gorskie5766ae2012-07-24 16:33:12 +0200161 case BCM6328_CPU_ID:
162 irq_stat_addr += PERF_IRQSTAT_6328_REG;
163 irq_mask_addr += PERF_IRQMASK_6328_REG;
164 irq_bits = 64;
165 ext_irq_count = 4;
166 is_ext_irq_cascaded = 1;
167 ext_irq_start = BCM_6328_EXT_IRQ0 - IRQ_INTERNAL_BASE;
168 ext_irq_end = BCM_6328_EXT_IRQ3 - IRQ_INTERNAL_BASE;
169 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6328;
170 break;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100171 case BCM6338_CPU_ID:
172 irq_stat_addr += PERF_IRQSTAT_6338_REG;
173 irq_mask_addr += PERF_IRQMASK_6338_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100174 irq_bits = 32;
Maxime Bizon64eaea42012-07-13 07:46:03 +0000175 ext_irq_count = 4;
176 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6338;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100177 break;
178 case BCM6345_CPU_ID:
179 irq_stat_addr += PERF_IRQSTAT_6345_REG;
180 irq_mask_addr += PERF_IRQMASK_6345_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100181 irq_bits = 32;
Maxime Bizon64eaea42012-07-13 07:46:03 +0000182 ext_irq_count = 4;
183 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6345;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100184 break;
185 case BCM6348_CPU_ID:
186 irq_stat_addr += PERF_IRQSTAT_6348_REG;
187 irq_mask_addr += PERF_IRQMASK_6348_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100188 irq_bits = 32;
Maxime Bizon62248922011-11-04 19:09:34 +0100189 ext_irq_count = 4;
190 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6348;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100191 break;
192 case BCM6358_CPU_ID:
193 irq_stat_addr += PERF_IRQSTAT_6358_REG;
194 irq_mask_addr += PERF_IRQMASK_6358_REG;
Maxime Bizon71a43922011-11-04 19:09:33 +0100195 irq_bits = 32;
Maxime Bizon62248922011-11-04 19:09:34 +0100196 ext_irq_count = 4;
Maxime Bizon37c42a72011-11-04 19:09:32 +0100197 is_ext_irq_cascaded = 1;
198 ext_irq_start = BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE;
199 ext_irq_end = BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100200 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6358;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100201 break;
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000202 case BCM6362_CPU_ID:
203 irq_stat_addr += PERF_IRQSTAT_6362_REG;
204 irq_mask_addr += PERF_IRQMASK_6362_REG;
205 irq_bits = 64;
206 ext_irq_count = 4;
207 is_ext_irq_cascaded = 1;
208 ext_irq_start = BCM_6362_EXT_IRQ0 - IRQ_INTERNAL_BASE;
209 ext_irq_end = BCM_6362_EXT_IRQ3 - IRQ_INTERNAL_BASE;
210 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6362;
211 break;
Maxime Bizon04712f32011-11-04 19:09:35 +0100212 case BCM6368_CPU_ID:
213 irq_stat_addr += PERF_IRQSTAT_6368_REG;
214 irq_mask_addr += PERF_IRQMASK_6368_REG;
215 irq_bits = 64;
216 ext_irq_count = 6;
217 is_ext_irq_cascaded = 1;
218 ext_irq_start = BCM_6368_EXT_IRQ0 - IRQ_INTERNAL_BASE;
219 ext_irq_end = BCM_6368_EXT_IRQ5 - IRQ_INTERNAL_BASE;
220 ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6368;
221 ext_irq_cfg_reg2 = PERF_EXTIRQ_CFG_REG2_6368;
222 break;
Maxime Bizonf61cced2011-11-04 19:09:31 +0100223 default:
224 BUG();
225 }
226
Maxime Bizon71a43922011-11-04 19:09:33 +0100227 if (irq_bits == 32) {
228 dispatch_internal = __dispatch_internal;
229 internal_irq_mask = __internal_irq_mask_32;
230 internal_irq_unmask = __internal_irq_unmask_32;
231 } else {
232 dispatch_internal = __dispatch_internal_64;
233 internal_irq_mask = __internal_irq_mask_64;
234 internal_irq_unmask = __internal_irq_unmask_64;
235 }
Maxime Bizonf61cced2011-11-04 19:09:31 +0100236}
237#endif /* ! BCMCPU_RUNTIME_DETECT */
238
Maxime Bizon62248922011-11-04 19:09:34 +0100239static inline u32 get_ext_irq_perf_reg(int irq)
240{
241 if (irq < 4)
242 return ext_irq_cfg_reg1;
243 return ext_irq_cfg_reg2;
244}
245
Maxime Bizonf61cced2011-11-04 19:09:31 +0100246static inline void handle_internal(int intbit)
247{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100248 if (is_ext_irq_cascaded &&
249 intbit >= ext_irq_start && intbit <= ext_irq_end)
250 do_IRQ(intbit - ext_irq_start + IRQ_EXTERNAL_BASE);
251 else
252 do_IRQ(intbit + IRQ_INTERNAL_BASE);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100253}
254
Maxime Bizone7300d02009-08-18 13:23:37 +0100255/*
256 * dispatch internal devices IRQ (uart, enet, watchdog, ...). do not
257 * prioritize any interrupt relatively to another. the static counter
258 * will resume the loop where it ended the last time we left this
259 * function.
260 */
Maxime Bizonf61cced2011-11-04 19:09:31 +0100261static void __dispatch_internal(void)
Maxime Bizone7300d02009-08-18 13:23:37 +0100262{
263 u32 pending;
264 static int i;
265
Maxime Bizonf61cced2011-11-04 19:09:31 +0100266 pending = bcm_readl(irq_stat_addr) & bcm_readl(irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100267
268 if (!pending)
269 return ;
270
271 while (1) {
272 int to_call = i;
273
274 i = (i + 1) & 0x1f;
275 if (pending & (1 << to_call)) {
Maxime Bizonf61cced2011-11-04 19:09:31 +0100276 handle_internal(to_call);
Maxime Bizone7300d02009-08-18 13:23:37 +0100277 break;
278 }
279 }
280}
281
Maxime Bizon71a43922011-11-04 19:09:33 +0100282static void __dispatch_internal_64(void)
283{
284 u64 pending;
285 static int i;
286
287 pending = bcm_readq(irq_stat_addr) & bcm_readq(irq_mask_addr);
288
289 if (!pending)
290 return ;
291
292 while (1) {
293 int to_call = i;
294
295 i = (i + 1) & 0x3f;
296 if (pending & (1ull << to_call)) {
297 handle_internal(to_call);
298 break;
299 }
300 }
301}
302
Maxime Bizone7300d02009-08-18 13:23:37 +0100303asmlinkage void plat_irq_dispatch(void)
304{
305 u32 cause;
306
307 do {
308 cause = read_c0_cause() & read_c0_status() & ST0_IM;
309
310 if (!cause)
311 break;
312
313 if (cause & CAUSEF_IP7)
314 do_IRQ(7);
Kevin Cernekee937ad102013-06-03 14:39:34 +0000315 if (cause & CAUSEF_IP0)
316 do_IRQ(0);
317 if (cause & CAUSEF_IP1)
318 do_IRQ(1);
Maxime Bizone7300d02009-08-18 13:23:37 +0100319 if (cause & CAUSEF_IP2)
Maxime Bizonf61cced2011-11-04 19:09:31 +0100320 dispatch_internal();
Maxime Bizon37c42a72011-11-04 19:09:32 +0100321 if (!is_ext_irq_cascaded) {
322 if (cause & CAUSEF_IP3)
323 do_IRQ(IRQ_EXT_0);
324 if (cause & CAUSEF_IP4)
325 do_IRQ(IRQ_EXT_1);
326 if (cause & CAUSEF_IP5)
327 do_IRQ(IRQ_EXT_2);
328 if (cause & CAUSEF_IP6)
329 do_IRQ(IRQ_EXT_3);
330 }
Maxime Bizone7300d02009-08-18 13:23:37 +0100331 } while (1);
332}
333
334/*
335 * internal IRQs operations: only mask/unmask on PERF irq mask
336 * register.
337 */
Maxime Bizon71a43922011-11-04 19:09:33 +0100338static void __internal_irq_mask_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_mask_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
356static void __internal_irq_unmask_32(unsigned int irq)
Maxime Bizone7300d02009-08-18 13:23:37 +0100357{
358 u32 mask;
359
Maxime Bizonf61cced2011-11-04 19:09:31 +0100360 mask = bcm_readl(irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100361 mask |= (1 << irq);
Maxime Bizonf61cced2011-11-04 19:09:31 +0100362 bcm_writel(mask, irq_mask_addr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100363}
364
Maxime Bizon71a43922011-11-04 19:09:33 +0100365static void __internal_irq_unmask_64(unsigned int irq)
366{
367 u64 mask;
368
369 mask = bcm_readq(irq_mask_addr);
370 mask |= (1ull << irq);
371 bcm_writeq(mask, irq_mask_addr);
372}
373
Maxime Bizon37c42a72011-11-04 19:09:32 +0100374static void bcm63xx_internal_irq_mask(struct irq_data *d)
375{
376 internal_irq_mask(d->irq - IRQ_INTERNAL_BASE);
377}
378
379static void bcm63xx_internal_irq_unmask(struct irq_data *d)
380{
381 internal_irq_unmask(d->irq - IRQ_INTERNAL_BASE);
382}
383
Maxime Bizone7300d02009-08-18 13:23:37 +0100384/*
385 * external IRQs operations: mask/unmask and clear on PERF external
386 * irq control register.
387 */
Thomas Gleixner93f29362011-03-23 21:08:47 +0000388static void bcm63xx_external_irq_mask(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);
Maxime Bizon37c42a72011-11-04 19:09:32 +0100402 if (is_ext_irq_cascaded)
403 internal_irq_mask(irq + ext_irq_start);
Maxime Bizone7300d02009-08-18 13:23:37 +0100404}
405
Thomas Gleixner93f29362011-03-23 21:08:47 +0000406static void bcm63xx_external_irq_unmask(struct irq_data *d)
Maxime Bizone7300d02009-08-18 13:23:37 +0100407{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100408 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100409 u32 reg, regaddr;
Maxime Bizone7300d02009-08-18 13:23:37 +0100410
Maxime Bizon62248922011-11-04 19:09:34 +0100411 regaddr = get_ext_irq_perf_reg(irq);
412 reg = bcm_perf_readl(regaddr);
413
414 if (BCMCPU_IS_6348())
415 reg |= EXTIRQ_CFG_MASK_6348(irq % 4);
416 else
417 reg |= EXTIRQ_CFG_MASK(irq % 4);
418
419 bcm_perf_writel(reg, regaddr);
420
Maxime Bizon37c42a72011-11-04 19:09:32 +0100421 if (is_ext_irq_cascaded)
422 internal_irq_unmask(irq + ext_irq_start);
Maxime Bizone7300d02009-08-18 13:23:37 +0100423}
424
Thomas Gleixner93f29362011-03-23 21:08:47 +0000425static void bcm63xx_external_irq_clear(struct irq_data *d)
Maxime Bizone7300d02009-08-18 13:23:37 +0100426{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100427 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100428 u32 reg, regaddr;
Maxime Bizone7300d02009-08-18 13:23:37 +0100429
Maxime Bizon62248922011-11-04 19:09:34 +0100430 regaddr = get_ext_irq_perf_reg(irq);
431 reg = bcm_perf_readl(regaddr);
432
433 if (BCMCPU_IS_6348())
434 reg |= EXTIRQ_CFG_CLEAR_6348(irq % 4);
435 else
436 reg |= EXTIRQ_CFG_CLEAR(irq % 4);
437
438 bcm_perf_writel(reg, regaddr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100439}
440
Thomas Gleixner93f29362011-03-23 21:08:47 +0000441static int bcm63xx_external_irq_set_type(struct irq_data *d,
Maxime Bizone7300d02009-08-18 13:23:37 +0100442 unsigned int flow_type)
443{
Maxime Bizon37c42a72011-11-04 19:09:32 +0100444 unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
Maxime Bizon62248922011-11-04 19:09:34 +0100445 u32 reg, regaddr;
446 int levelsense, sense, bothedge;
Maxime Bizone7300d02009-08-18 13:23:37 +0100447
448 flow_type &= IRQ_TYPE_SENSE_MASK;
449
450 if (flow_type == IRQ_TYPE_NONE)
451 flow_type = IRQ_TYPE_LEVEL_LOW;
452
Maxime Bizon62248922011-11-04 19:09:34 +0100453 levelsense = sense = bothedge = 0;
Maxime Bizone7300d02009-08-18 13:23:37 +0100454 switch (flow_type) {
455 case IRQ_TYPE_EDGE_BOTH:
Maxime Bizon62248922011-11-04 19:09:34 +0100456 bothedge = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100457 break;
458
459 case IRQ_TYPE_EDGE_RISING:
Maxime Bizon62248922011-11-04 19:09:34 +0100460 sense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100461 break;
462
463 case IRQ_TYPE_EDGE_FALLING:
Maxime Bizone7300d02009-08-18 13:23:37 +0100464 break;
465
466 case IRQ_TYPE_LEVEL_HIGH:
Maxime Bizon62248922011-11-04 19:09:34 +0100467 levelsense = 1;
468 sense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100469 break;
470
471 case IRQ_TYPE_LEVEL_LOW:
Maxime Bizon62248922011-11-04 19:09:34 +0100472 levelsense = 1;
Maxime Bizone7300d02009-08-18 13:23:37 +0100473 break;
474
475 default:
476 printk(KERN_ERR "bogus flow type combination given !\n");
477 return -EINVAL;
478 }
Maxime Bizon62248922011-11-04 19:09:34 +0100479
480 regaddr = get_ext_irq_perf_reg(irq);
481 reg = bcm_perf_readl(regaddr);
482 irq %= 4;
483
Maxime Bizon58e380a2012-07-13 07:46:05 +0000484 switch (bcm63xx_get_cpu_id()) {
485 case BCM6348_CPU_ID:
Maxime Bizon62248922011-11-04 19:09:34 +0100486 if (levelsense)
487 reg |= EXTIRQ_CFG_LEVELSENSE_6348(irq);
488 else
489 reg &= ~EXTIRQ_CFG_LEVELSENSE_6348(irq);
490 if (sense)
491 reg |= EXTIRQ_CFG_SENSE_6348(irq);
492 else
493 reg &= ~EXTIRQ_CFG_SENSE_6348(irq);
494 if (bothedge)
495 reg |= EXTIRQ_CFG_BOTHEDGE_6348(irq);
496 else
497 reg &= ~EXTIRQ_CFG_BOTHEDGE_6348(irq);
Maxime Bizon58e380a2012-07-13 07:46:05 +0000498 break;
Maxime Bizon62248922011-11-04 19:09:34 +0100499
Florian Fainelli7b933422013-06-18 16:55:40 +0000500 case BCM3368_CPU_ID:
Maxime Bizon58e380a2012-07-13 07:46:05 +0000501 case BCM6328_CPU_ID:
502 case BCM6338_CPU_ID:
503 case BCM6345_CPU_ID:
504 case BCM6358_CPU_ID:
Jonas Gorski2c8aaf72013-03-21 14:03:17 +0000505 case BCM6362_CPU_ID:
Maxime Bizon58e380a2012-07-13 07:46:05 +0000506 case BCM6368_CPU_ID:
Maxime Bizon62248922011-11-04 19:09:34 +0100507 if (levelsense)
508 reg |= EXTIRQ_CFG_LEVELSENSE(irq);
509 else
510 reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
511 if (sense)
512 reg |= EXTIRQ_CFG_SENSE(irq);
513 else
514 reg &= ~EXTIRQ_CFG_SENSE(irq);
515 if (bothedge)
516 reg |= EXTIRQ_CFG_BOTHEDGE(irq);
517 else
518 reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
Maxime Bizon58e380a2012-07-13 07:46:05 +0000519 break;
520 default:
521 BUG();
Maxime Bizon62248922011-11-04 19:09:34 +0100522 }
523
524 bcm_perf_writel(reg, regaddr);
Maxime Bizone7300d02009-08-18 13:23:37 +0100525
Thomas Gleixner93f29362011-03-23 21:08:47 +0000526 irqd_set_trigger_type(d, flow_type);
527 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
528 __irq_set_handler_locked(d->irq, handle_level_irq);
529 else
530 __irq_set_handler_locked(d->irq, handle_edge_irq);
Maxime Bizone7300d02009-08-18 13:23:37 +0100531
Thomas Gleixner93f29362011-03-23 21:08:47 +0000532 return IRQ_SET_MASK_OK_NOCOPY;
Maxime Bizone7300d02009-08-18 13:23:37 +0100533}
534
535static struct irq_chip bcm63xx_internal_irq_chip = {
536 .name = "bcm63xx_ipic",
Thomas Gleixner93f29362011-03-23 21:08:47 +0000537 .irq_mask = bcm63xx_internal_irq_mask,
538 .irq_unmask = bcm63xx_internal_irq_unmask,
Maxime Bizone7300d02009-08-18 13:23:37 +0100539};
540
541static struct irq_chip bcm63xx_external_irq_chip = {
542 .name = "bcm63xx_epic",
Thomas Gleixner93f29362011-03-23 21:08:47 +0000543 .irq_ack = bcm63xx_external_irq_clear,
Maxime Bizone7300d02009-08-18 13:23:37 +0100544
Thomas Gleixner93f29362011-03-23 21:08:47 +0000545 .irq_mask = bcm63xx_external_irq_mask,
546 .irq_unmask = bcm63xx_external_irq_unmask,
Maxime Bizone7300d02009-08-18 13:23:37 +0100547
Thomas Gleixner93f29362011-03-23 21:08:47 +0000548 .irq_set_type = bcm63xx_external_irq_set_type,
Maxime Bizone7300d02009-08-18 13:23:37 +0100549};
550
551static struct irqaction cpu_ip2_cascade_action = {
552 .handler = no_action,
553 .name = "cascade_ip2",
Wu Zhangjin5a4a4ad2011-07-23 12:41:24 +0000554 .flags = IRQF_NO_THREAD,
Maxime Bizone7300d02009-08-18 13:23:37 +0100555};
556
Maxime Bizon37c42a72011-11-04 19:09:32 +0100557static struct irqaction cpu_ext_cascade_action = {
558 .handler = no_action,
559 .name = "cascade_extirq",
560 .flags = IRQF_NO_THREAD,
561};
562
Maxime Bizone7300d02009-08-18 13:23:37 +0100563void __init arch_init_irq(void)
564{
565 int i;
566
Maxime Bizonf61cced2011-11-04 19:09:31 +0100567 bcm63xx_init_irq();
Maxime Bizone7300d02009-08-18 13:23:37 +0100568 mips_cpu_irq_init();
569 for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200570 irq_set_chip_and_handler(i, &bcm63xx_internal_irq_chip,
Maxime Bizone7300d02009-08-18 13:23:37 +0100571 handle_level_irq);
572
Maxime Bizon62248922011-11-04 19:09:34 +0100573 for (i = IRQ_EXTERNAL_BASE; i < IRQ_EXTERNAL_BASE + ext_irq_count; ++i)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200574 irq_set_chip_and_handler(i, &bcm63xx_external_irq_chip,
Maxime Bizone7300d02009-08-18 13:23:37 +0100575 handle_edge_irq);
576
Maxime Bizon37c42a72011-11-04 19:09:32 +0100577 if (!is_ext_irq_cascaded) {
Maxime Bizon62248922011-11-04 19:09:34 +0100578 for (i = 3; i < 3 + ext_irq_count; ++i)
Maxime Bizon37c42a72011-11-04 19:09:32 +0100579 setup_irq(MIPS_CPU_IRQ_BASE + i, &cpu_ext_cascade_action);
580 }
581
582 setup_irq(MIPS_CPU_IRQ_BASE + 2, &cpu_ip2_cascade_action);
Maxime Bizone7300d02009-08-18 13:23:37 +0100583}