Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 1 | /* |
| 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 Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 14 | #include <linux/irq.h> |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 15 | #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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 22 | static void __dispatch_internal(void) __maybe_unused; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 23 | static void __dispatch_internal_64(void) __maybe_unused; |
| 24 | static void __internal_irq_mask_32(unsigned int irq) __maybe_unused; |
| 25 | static void __internal_irq_mask_64(unsigned int irq) __maybe_unused; |
| 26 | static void __internal_irq_unmask_32(unsigned int irq) __maybe_unused; |
| 27 | static void __internal_irq_unmask_64(unsigned int irq) __maybe_unused; |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 28 | |
| 29 | #ifndef BCMCPU_RUNTIME_DETECT |
Jonas Gorski | e5766ae | 2012-07-24 16:33:12 +0200 | [diff] [blame] | 30 | #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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 41 | #ifdef CONFIG_BCM63XX_CPU_6338 |
| 42 | #define irq_stat_reg PERF_IRQSTAT_6338_REG |
| 43 | #define irq_mask_reg PERF_IRQMASK_6338_REG |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 44 | #define irq_bits 32 |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 45 | #define is_ext_irq_cascaded 0 |
| 46 | #define ext_irq_start 0 |
| 47 | #define ext_irq_end 0 |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 48 | #define ext_irq_count 4 |
| 49 | #define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6338 |
| 50 | #define ext_irq_cfg_reg2 0 |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 51 | #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 Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 55 | #define irq_bits 32 |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 56 | #define is_ext_irq_cascaded 0 |
| 57 | #define ext_irq_start 0 |
| 58 | #define ext_irq_end 0 |
Maxime Bizon | 64eaea4 | 2012-07-13 07:46:03 +0000 | [diff] [blame] | 59 | #define ext_irq_count 4 |
| 60 | #define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6345 |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 61 | #define ext_irq_cfg_reg2 0 |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 62 | #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 Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 66 | #define irq_bits 32 |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 67 | #define is_ext_irq_cascaded 0 |
| 68 | #define ext_irq_start 0 |
| 69 | #define ext_irq_end 0 |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 70 | #define ext_irq_count 4 |
| 71 | #define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6348 |
| 72 | #define ext_irq_cfg_reg2 0 |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 73 | #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 Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 77 | #define irq_bits 32 |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 78 | #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 Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 81 | #define ext_irq_count 4 |
| 82 | #define ext_irq_cfg_reg1 PERF_EXTIRQ_CFG_REG_6358 |
| 83 | #define ext_irq_cfg_reg2 0 |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 84 | #endif |
Jonas Gorski | 2c8aaf7 | 2013-03-21 14:03:17 +0000 | [diff] [blame] | 85 | #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 Bizon | 04712f3 | 2011-11-04 19:09:35 +0100 | [diff] [blame] | 96 | #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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 107 | |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 108 | #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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 117 | |
| 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 | |
| 121 | static inline void bcm63xx_init_irq(void) |
| 122 | { |
| 123 | } |
| 124 | #else /* ! BCMCPU_RUNTIME_DETECT */ |
| 125 | |
| 126 | static u32 irq_stat_addr, irq_mask_addr; |
| 127 | static void (*dispatch_internal)(void); |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 128 | static int is_ext_irq_cascaded; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 129 | static unsigned int ext_irq_count; |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 130 | static unsigned int ext_irq_start, ext_irq_end; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 131 | static unsigned int ext_irq_cfg_reg1, ext_irq_cfg_reg2; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 132 | static void (*internal_irq_mask)(unsigned int irq); |
| 133 | static void (*internal_irq_unmask)(unsigned int irq); |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 134 | |
| 135 | static void bcm63xx_init_irq(void) |
| 136 | { |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 137 | int irq_bits; |
| 138 | |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 139 | 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 Gorski | e5766ae | 2012-07-24 16:33:12 +0200 | [diff] [blame] | 143 | 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 153 | case BCM6338_CPU_ID: |
| 154 | irq_stat_addr += PERF_IRQSTAT_6338_REG; |
| 155 | irq_mask_addr += PERF_IRQMASK_6338_REG; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 156 | irq_bits = 32; |
Maxime Bizon | 64eaea4 | 2012-07-13 07:46:03 +0000 | [diff] [blame] | 157 | ext_irq_count = 4; |
| 158 | ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6338; |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 159 | break; |
| 160 | case BCM6345_CPU_ID: |
| 161 | irq_stat_addr += PERF_IRQSTAT_6345_REG; |
| 162 | irq_mask_addr += PERF_IRQMASK_6345_REG; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 163 | irq_bits = 32; |
Maxime Bizon | 64eaea4 | 2012-07-13 07:46:03 +0000 | [diff] [blame] | 164 | ext_irq_count = 4; |
| 165 | ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6345; |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 166 | break; |
| 167 | case BCM6348_CPU_ID: |
| 168 | irq_stat_addr += PERF_IRQSTAT_6348_REG; |
| 169 | irq_mask_addr += PERF_IRQMASK_6348_REG; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 170 | irq_bits = 32; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 171 | ext_irq_count = 4; |
| 172 | ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6348; |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 173 | break; |
| 174 | case BCM6358_CPU_ID: |
| 175 | irq_stat_addr += PERF_IRQSTAT_6358_REG; |
| 176 | irq_mask_addr += PERF_IRQMASK_6358_REG; |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 177 | irq_bits = 32; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 178 | ext_irq_count = 4; |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 179 | 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 Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 182 | ext_irq_cfg_reg1 = PERF_EXTIRQ_CFG_REG_6358; |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 183 | break; |
Jonas Gorski | 2c8aaf7 | 2013-03-21 14:03:17 +0000 | [diff] [blame] | 184 | 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 Bizon | 04712f3 | 2011-11-04 19:09:35 +0100 | [diff] [blame] | 194 | 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 205 | default: |
| 206 | BUG(); |
| 207 | } |
| 208 | |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 209 | 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 218 | } |
| 219 | #endif /* ! BCMCPU_RUNTIME_DETECT */ |
| 220 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 221 | static 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 228 | static inline void handle_internal(int intbit) |
| 229 | { |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 230 | 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 237 | /* |
| 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 243 | static void __dispatch_internal(void) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 244 | { |
| 245 | u32 pending; |
| 246 | static int i; |
| 247 | |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 248 | pending = bcm_readl(irq_stat_addr) & bcm_readl(irq_mask_addr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 249 | |
| 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 Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 258 | handle_internal(to_call); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 259 | break; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 264 | static 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 Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 285 | asmlinkage 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 Cernekee | 937ad10 | 2013-06-03 14:39:34 +0000 | [diff] [blame^] | 297 | if (cause & CAUSEF_IP0) |
| 298 | do_IRQ(0); |
| 299 | if (cause & CAUSEF_IP1) |
| 300 | do_IRQ(1); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 301 | if (cause & CAUSEF_IP2) |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 302 | dispatch_internal(); |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 303 | 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 Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 313 | } while (1); |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * internal IRQs operations: only mask/unmask on PERF irq mask |
| 318 | * register. |
| 319 | */ |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 320 | static void __internal_irq_mask_32(unsigned int irq) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 321 | { |
| 322 | u32 mask; |
| 323 | |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 324 | mask = bcm_readl(irq_mask_addr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 325 | mask &= ~(1 << irq); |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 326 | bcm_writel(mask, irq_mask_addr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 329 | static 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 | |
| 338 | static void __internal_irq_unmask_32(unsigned int irq) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 339 | { |
| 340 | u32 mask; |
| 341 | |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 342 | mask = bcm_readl(irq_mask_addr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 343 | mask |= (1 << irq); |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 344 | bcm_writel(mask, irq_mask_addr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Maxime Bizon | 71a4392 | 2011-11-04 19:09:33 +0100 | [diff] [blame] | 347 | static 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 Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 356 | static void bcm63xx_internal_irq_mask(struct irq_data *d) |
| 357 | { |
| 358 | internal_irq_mask(d->irq - IRQ_INTERNAL_BASE); |
| 359 | } |
| 360 | |
| 361 | static void bcm63xx_internal_irq_unmask(struct irq_data *d) |
| 362 | { |
| 363 | internal_irq_unmask(d->irq - IRQ_INTERNAL_BASE); |
| 364 | } |
| 365 | |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 366 | /* |
| 367 | * external IRQs operations: mask/unmask and clear on PERF external |
| 368 | * irq control register. |
| 369 | */ |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 370 | static void bcm63xx_external_irq_mask(struct irq_data *d) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 371 | { |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 372 | unsigned int irq = d->irq - IRQ_EXTERNAL_BASE; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 373 | u32 reg, regaddr; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 374 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 375 | 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 Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 384 | if (is_ext_irq_cascaded) |
| 385 | internal_irq_mask(irq + ext_irq_start); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 388 | static void bcm63xx_external_irq_unmask(struct irq_data *d) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 389 | { |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 390 | unsigned int irq = d->irq - IRQ_EXTERNAL_BASE; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 391 | u32 reg, regaddr; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 392 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 393 | 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 Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 403 | if (is_ext_irq_cascaded) |
| 404 | internal_irq_unmask(irq + ext_irq_start); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 407 | static void bcm63xx_external_irq_clear(struct irq_data *d) |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 408 | { |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 409 | unsigned int irq = d->irq - IRQ_EXTERNAL_BASE; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 410 | u32 reg, regaddr; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 411 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 412 | 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 Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 421 | } |
| 422 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 423 | static int bcm63xx_external_irq_set_type(struct irq_data *d, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 424 | unsigned int flow_type) |
| 425 | { |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 426 | unsigned int irq = d->irq - IRQ_EXTERNAL_BASE; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 427 | u32 reg, regaddr; |
| 428 | int levelsense, sense, bothedge; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 429 | |
| 430 | flow_type &= IRQ_TYPE_SENSE_MASK; |
| 431 | |
| 432 | if (flow_type == IRQ_TYPE_NONE) |
| 433 | flow_type = IRQ_TYPE_LEVEL_LOW; |
| 434 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 435 | levelsense = sense = bothedge = 0; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 436 | switch (flow_type) { |
| 437 | case IRQ_TYPE_EDGE_BOTH: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 438 | bothedge = 1; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 439 | break; |
| 440 | |
| 441 | case IRQ_TYPE_EDGE_RISING: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 442 | sense = 1; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 443 | break; |
| 444 | |
| 445 | case IRQ_TYPE_EDGE_FALLING: |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 446 | break; |
| 447 | |
| 448 | case IRQ_TYPE_LEVEL_HIGH: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 449 | levelsense = 1; |
| 450 | sense = 1; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 451 | break; |
| 452 | |
| 453 | case IRQ_TYPE_LEVEL_LOW: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 454 | levelsense = 1; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 455 | break; |
| 456 | |
| 457 | default: |
| 458 | printk(KERN_ERR "bogus flow type combination given !\n"); |
| 459 | return -EINVAL; |
| 460 | } |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 461 | |
| 462 | regaddr = get_ext_irq_perf_reg(irq); |
| 463 | reg = bcm_perf_readl(regaddr); |
| 464 | irq %= 4; |
| 465 | |
Maxime Bizon | 58e380a | 2012-07-13 07:46:05 +0000 | [diff] [blame] | 466 | switch (bcm63xx_get_cpu_id()) { |
| 467 | case BCM6348_CPU_ID: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 468 | 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 Bizon | 58e380a | 2012-07-13 07:46:05 +0000 | [diff] [blame] | 480 | break; |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 481 | |
Maxime Bizon | 58e380a | 2012-07-13 07:46:05 +0000 | [diff] [blame] | 482 | case BCM6328_CPU_ID: |
| 483 | case BCM6338_CPU_ID: |
| 484 | case BCM6345_CPU_ID: |
| 485 | case BCM6358_CPU_ID: |
Jonas Gorski | 2c8aaf7 | 2013-03-21 14:03:17 +0000 | [diff] [blame] | 486 | case BCM6362_CPU_ID: |
Maxime Bizon | 58e380a | 2012-07-13 07:46:05 +0000 | [diff] [blame] | 487 | case BCM6368_CPU_ID: |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 488 | 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 Bizon | 58e380a | 2012-07-13 07:46:05 +0000 | [diff] [blame] | 500 | break; |
| 501 | default: |
| 502 | BUG(); |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | bcm_perf_writel(reg, regaddr); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 506 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 507 | 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 Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 512 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 513 | return IRQ_SET_MASK_OK_NOCOPY; |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static struct irq_chip bcm63xx_internal_irq_chip = { |
| 517 | .name = "bcm63xx_ipic", |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 518 | .irq_mask = bcm63xx_internal_irq_mask, |
| 519 | .irq_unmask = bcm63xx_internal_irq_unmask, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | static struct irq_chip bcm63xx_external_irq_chip = { |
| 523 | .name = "bcm63xx_epic", |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 524 | .irq_ack = bcm63xx_external_irq_clear, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 525 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 526 | .irq_mask = bcm63xx_external_irq_mask, |
| 527 | .irq_unmask = bcm63xx_external_irq_unmask, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 528 | |
Thomas Gleixner | 93f2936 | 2011-03-23 21:08:47 +0000 | [diff] [blame] | 529 | .irq_set_type = bcm63xx_external_irq_set_type, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | static struct irqaction cpu_ip2_cascade_action = { |
| 533 | .handler = no_action, |
| 534 | .name = "cascade_ip2", |
Wu Zhangjin | 5a4a4ad | 2011-07-23 12:41:24 +0000 | [diff] [blame] | 535 | .flags = IRQF_NO_THREAD, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 536 | }; |
| 537 | |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 538 | static struct irqaction cpu_ext_cascade_action = { |
| 539 | .handler = no_action, |
| 540 | .name = "cascade_extirq", |
| 541 | .flags = IRQF_NO_THREAD, |
| 542 | }; |
| 543 | |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 544 | void __init arch_init_irq(void) |
| 545 | { |
| 546 | int i; |
| 547 | |
Maxime Bizon | f61cced | 2011-11-04 19:09:31 +0100 | [diff] [blame] | 548 | bcm63xx_init_irq(); |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 549 | mips_cpu_irq_init(); |
| 550 | for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i) |
Thomas Gleixner | e4ec798 | 2011-03-27 15:19:28 +0200 | [diff] [blame] | 551 | irq_set_chip_and_handler(i, &bcm63xx_internal_irq_chip, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 552 | handle_level_irq); |
| 553 | |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 554 | for (i = IRQ_EXTERNAL_BASE; i < IRQ_EXTERNAL_BASE + ext_irq_count; ++i) |
Thomas Gleixner | e4ec798 | 2011-03-27 15:19:28 +0200 | [diff] [blame] | 555 | irq_set_chip_and_handler(i, &bcm63xx_external_irq_chip, |
Maxime Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 556 | handle_edge_irq); |
| 557 | |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 558 | if (!is_ext_irq_cascaded) { |
Maxime Bizon | 6224892 | 2011-11-04 19:09:34 +0100 | [diff] [blame] | 559 | for (i = 3; i < 3 + ext_irq_count; ++i) |
Maxime Bizon | 37c42a7 | 2011-11-04 19:09:32 +0100 | [diff] [blame] | 560 | 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 Bizon | e7300d0 | 2009-08-18 13:23:37 +0100 | [diff] [blame] | 564 | } |