dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 1 | /* |
| 2 | * arch/mips/emma2rh/markeins/irq.c |
| 3 | * This file defines the irq handler for EMMA2RH. |
| 4 | * |
| 5 | * Copyright (C) NEC Electronics Corporation 2004-2006 |
| 6 | * |
| 7 | * This file is based on the arch/mips/ddb5xxx/ddb5477/irq.c |
| 8 | * |
| 9 | * Copyright 2001 MontaVista Software Inc. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/irq.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/ptrace.h> |
| 30 | #include <linux/delay.h> |
| 31 | |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 32 | #include <asm/irq_cpu.h> |
| 33 | #include <asm/system.h> |
| 34 | #include <asm/mipsregs.h> |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 35 | #include <asm/addrspace.h> |
| 36 | #include <asm/bootinfo.h> |
| 37 | |
Shinya Kuribayashi | d91f2cb | 2008-10-24 01:30:20 +0900 | [diff] [blame] | 38 | #include <asm/emma/emma2rh.h> |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 39 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 40 | /* number of total irqs supported by EMMA2RH */ |
| 41 | #define NUM_EMMA2RH_IRQ 96 |
| 42 | |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 43 | /* |
| 44 | * IRQ mapping |
| 45 | * |
| 46 | * 0-7: 8 CPU interrupts |
| 47 | * 0 - software interrupt 0 |
| 48 | * 1 - software interrupt 1 |
| 49 | * 2 - most Vrc5477 interrupts are routed to this pin |
| 50 | * 3 - (optional) some other interrupts routed to this pin for debugg |
| 51 | * 4 - not used |
| 52 | * 5 - not used |
| 53 | * 6 - not used |
| 54 | * 7 - cpu timer (used by default) |
| 55 | * |
| 56 | */ |
| 57 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 58 | static void emma2rh_irq_enable(unsigned int irq) |
| 59 | { |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 60 | u32 reg_value; |
| 61 | u32 reg_bitmask; |
| 62 | u32 reg_index; |
| 63 | |
| 64 | irq -= EMMA2RH_IRQ_BASE; |
| 65 | |
| 66 | reg_index = EMMA2RH_BHIF_INT_EN_0 + |
| 67 | (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32); |
| 68 | reg_value = emma2rh_in32(reg_index); |
| 69 | reg_bitmask = 0x1 << (irq % 32); |
| 70 | emma2rh_out32(reg_index, reg_value | reg_bitmask); |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void emma2rh_irq_disable(unsigned int irq) |
| 74 | { |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 75 | u32 reg_value; |
| 76 | u32 reg_bitmask; |
| 77 | u32 reg_index; |
| 78 | |
| 79 | irq -= EMMA2RH_IRQ_BASE; |
| 80 | |
| 81 | reg_index = EMMA2RH_BHIF_INT_EN_0 + |
| 82 | (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32); |
| 83 | reg_value = emma2rh_in32(reg_index); |
| 84 | reg_bitmask = 0x1 << (irq % 32); |
| 85 | emma2rh_out32(reg_index, reg_value & ~reg_bitmask); |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | struct irq_chip emma2rh_irq_controller = { |
| 89 | .name = "emma2rh_irq", |
| 90 | .ack = emma2rh_irq_disable, |
| 91 | .mask = emma2rh_irq_disable, |
| 92 | .mask_ack = emma2rh_irq_disable, |
| 93 | .unmask = emma2rh_irq_enable, |
| 94 | }; |
| 95 | |
| 96 | void emma2rh_irq_init(void) |
| 97 | { |
| 98 | u32 i; |
| 99 | |
| 100 | for (i = 0; i < NUM_EMMA2RH_IRQ; i++) |
| 101 | set_irq_chip_and_handler(EMMA2RH_IRQ_BASE + i, |
| 102 | &emma2rh_irq_controller, |
| 103 | handle_level_irq); |
| 104 | } |
| 105 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 106 | static void emma2rh_sw_irq_enable(unsigned int irq) |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 107 | { |
| 108 | u32 reg; |
| 109 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 110 | irq -= EMMA2RH_SW_IRQ_BASE; |
| 111 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 112 | reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN); |
| 113 | reg |= 1 << irq; |
| 114 | emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg); |
| 115 | } |
| 116 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 117 | static void emma2rh_sw_irq_disable(unsigned int irq) |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 118 | { |
| 119 | u32 reg; |
| 120 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 121 | irq -= EMMA2RH_SW_IRQ_BASE; |
| 122 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 123 | reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN); |
| 124 | reg &= ~(1 << irq); |
| 125 | emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg); |
| 126 | } |
| 127 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 128 | struct irq_chip emma2rh_sw_irq_controller = { |
| 129 | .name = "emma2rh_sw_irq", |
| 130 | .ack = emma2rh_sw_irq_disable, |
| 131 | .mask = emma2rh_sw_irq_disable, |
| 132 | .mask_ack = emma2rh_sw_irq_disable, |
| 133 | .unmask = emma2rh_sw_irq_enable, |
| 134 | }; |
| 135 | |
| 136 | void emma2rh_sw_irq_init(void) |
| 137 | { |
| 138 | u32 i; |
| 139 | |
| 140 | for (i = 0; i < NUM_EMMA2RH_IRQ_SW; i++) |
| 141 | set_irq_chip_and_handler(EMMA2RH_SW_IRQ_BASE + i, |
| 142 | &emma2rh_sw_irq_controller, |
| 143 | handle_level_irq); |
| 144 | } |
| 145 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 146 | static void emma2rh_gpio_irq_enable(unsigned int irq) |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 147 | { |
| 148 | u32 reg; |
| 149 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 150 | irq -= EMMA2RH_GPIO_IRQ_BASE; |
| 151 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 152 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 153 | reg |= 1 << irq; |
| 154 | emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg); |
| 155 | } |
| 156 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 157 | static void emma2rh_gpio_irq_disable(unsigned int irq) |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 158 | { |
| 159 | u32 reg; |
| 160 | |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 161 | irq -= EMMA2RH_GPIO_IRQ_BASE; |
| 162 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 163 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 164 | reg &= ~(1 << irq); |
| 165 | emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg); |
| 166 | } |
| 167 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 168 | static void emma2rh_gpio_irq_ack(unsigned int irq) |
| 169 | { |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 170 | u32 reg; |
| 171 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 172 | irq -= EMMA2RH_GPIO_IRQ_BASE; |
| 173 | emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq)); |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 174 | |
| 175 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 176 | reg &= ~(1 << irq); |
| 177 | emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg); |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void emma2rh_gpio_irq_end(unsigned int irq) |
| 181 | { |
Shinya Kuribayashi | 49618d6 | 2008-10-24 01:35:59 +0900 | [diff] [blame^] | 182 | u32 reg; |
| 183 | |
| 184 | if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) { |
| 185 | |
| 186 | irq -= EMMA2RH_GPIO_IRQ_BASE; |
| 187 | |
| 188 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 189 | reg |= 1 << irq; |
| 190 | emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg); |
| 191 | } |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | struct irq_chip emma2rh_gpio_irq_controller = { |
| 195 | .name = "emma2rh_gpio_irq", |
| 196 | .ack = emma2rh_gpio_irq_ack, |
| 197 | .mask = emma2rh_gpio_irq_disable, |
| 198 | .mask_ack = emma2rh_gpio_irq_ack, |
| 199 | .unmask = emma2rh_gpio_irq_enable, |
| 200 | .end = emma2rh_gpio_irq_end, |
| 201 | }; |
| 202 | |
| 203 | void emma2rh_gpio_irq_init(void) |
| 204 | { |
| 205 | u32 i; |
| 206 | |
| 207 | for (i = 0; i < NUM_EMMA2RH_IRQ_GPIO; i++) |
| 208 | set_irq_chip(EMMA2RH_GPIO_IRQ_BASE + i, |
| 209 | &emma2rh_gpio_irq_controller); |
| 210 | } |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 211 | |
| 212 | static struct irqaction irq_cascade = { |
| 213 | .handler = no_action, |
| 214 | .flags = 0, |
| 215 | .mask = CPU_MASK_NONE, |
| 216 | .name = "cascade", |
| 217 | .dev_id = NULL, |
| 218 | .next = NULL, |
| 219 | }; |
| 220 | |
Shinya Kuribayashi | 9ae9fd7 | 2008-10-24 01:32:40 +0900 | [diff] [blame] | 221 | /* |
| 222 | * the first level int-handler will jump here if it is a emma2rh irq |
| 223 | */ |
| 224 | void emma2rh_irq_dispatch(void) |
| 225 | { |
| 226 | u32 intStatus; |
| 227 | u32 bitmask; |
| 228 | u32 i; |
| 229 | |
| 230 | intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) & |
| 231 | emma2rh_in32(EMMA2RH_BHIF_INT_EN_0); |
| 232 | |
| 233 | #ifdef EMMA2RH_SW_CASCADE |
| 234 | if (intStatus & |
| 235 | (1 << ((EMMA2RH_SW_CASCADE - EMMA2RH_IRQ_INT0) & (32 - 1)))) { |
| 236 | u32 swIntStatus; |
| 237 | swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT) |
| 238 | & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN); |
| 239 | for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) { |
| 240 | if (swIntStatus & bitmask) { |
| 241 | do_IRQ(EMMA2RH_SW_IRQ_BASE + i); |
| 242 | return; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | #endif |
| 247 | |
| 248 | for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) { |
| 249 | if (intStatus & bitmask) { |
| 250 | do_IRQ(EMMA2RH_IRQ_BASE + i); |
| 251 | return; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) & |
| 256 | emma2rh_in32(EMMA2RH_BHIF_INT_EN_1); |
| 257 | |
| 258 | #ifdef EMMA2RH_GPIO_CASCADE |
| 259 | if (intStatus & |
| 260 | (1 << ((EMMA2RH_GPIO_CASCADE - EMMA2RH_IRQ_INT0) & (32 - 1)))) { |
| 261 | u32 gpioIntStatus; |
| 262 | gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST) |
| 263 | & emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 264 | for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) { |
| 265 | if (gpioIntStatus & bitmask) { |
| 266 | do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i); |
| 267 | return; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | #endif |
| 272 | |
| 273 | for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) { |
| 274 | if (intStatus & bitmask) { |
| 275 | do_IRQ(EMMA2RH_IRQ_BASE + i); |
| 276 | return; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) & |
| 281 | emma2rh_in32(EMMA2RH_BHIF_INT_EN_2); |
| 282 | |
| 283 | for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) { |
| 284 | if (intStatus & bitmask) { |
| 285 | do_IRQ(EMMA2RH_IRQ_BASE + i); |
| 286 | return; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 291 | void __init arch_init_irq(void) |
| 292 | { |
| 293 | u32 reg; |
| 294 | |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 295 | /* by default, interrupts are disabled. */ |
| 296 | emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0); |
| 297 | emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0); |
| 298 | emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0); |
| 299 | emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0); |
| 300 | emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0); |
| 301 | emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0); |
| 302 | emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0); |
| 303 | |
| 304 | clear_c0_status(0xff00); |
| 305 | set_c0_status(0x0400); |
| 306 | |
| 307 | #define GPIO_PCI (0xf<<15) |
| 308 | /* setup GPIO interrupt for PCI interface */ |
| 309 | /* direction input */ |
| 310 | reg = emma2rh_in32(EMMA2RH_GPIO_DIR); |
| 311 | emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI); |
| 312 | /* disable interrupt */ |
| 313 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK); |
| 314 | emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI); |
| 315 | /* level triggerd */ |
| 316 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE); |
| 317 | emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI); |
| 318 | reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A); |
| 319 | emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI)); |
| 320 | /* interrupt clear */ |
| 321 | emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI); |
| 322 | |
| 323 | /* init all controllers */ |
Shinya Kuribayashi | 9b6c04b | 2008-10-24 01:31:16 +0900 | [diff] [blame] | 324 | emma2rh_irq_init(); |
Shinya Kuribayashi | 68ed1ca | 2008-10-24 01:31:43 +0900 | [diff] [blame] | 325 | emma2rh_sw_irq_init(); |
Shinya Kuribayashi | fcb3cfe | 2008-10-24 01:32:11 +0900 | [diff] [blame] | 326 | emma2rh_gpio_irq_init(); |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 327 | mips_cpu_irq_init(); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 328 | |
| 329 | /* setup cascade interrupts */ |
| 330 | setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade); |
| 331 | setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade); |
| 332 | setup_irq(CPU_IRQ_BASE + CPU_EMMA2RH_CASCADE, &irq_cascade); |
| 333 | } |
| 334 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 335 | asmlinkage void plat_irq_dispatch(void) |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 336 | { |
Thiemo Seufer | 119537c | 2007-03-19 00:13:37 +0000 | [diff] [blame] | 337 | unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM; |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 338 | |
| 339 | if (pending & STATUSF_IP7) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 340 | do_IRQ(CPU_IRQ_BASE + 7); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 341 | else if (pending & STATUSF_IP2) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 342 | emma2rh_irq_dispatch(); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 343 | else if (pending & STATUSF_IP1) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 344 | do_IRQ(CPU_IRQ_BASE + 1); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 345 | else if (pending & STATUSF_IP0) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 346 | do_IRQ(CPU_IRQ_BASE + 0); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 347 | else |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 348 | spurious_interrupt(); |
dmitry pervushin | 355c471 | 2006-05-21 14:53:06 +0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |