Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2001 MontaVista Software Inc. |
| 3 | * Author: MontaVista Software, Inc. |
| 4 | * ahennessy@mvista.com |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | * |
| 10 | * Copyright (C) 2000-2001 Toshiba Corporation |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 20 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 23 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 24 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License along |
| 29 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 30 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 31 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/sched.h> |
| 34 | #include <linux/types.h> |
| 35 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/io.h> |
| 38 | #include <asm/mipsregs.h> |
| 39 | #include <asm/system.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/processor.h> |
Atsushi Nemoto | 22b1d70 | 2008-07-11 00:31:36 +0900 | [diff] [blame] | 42 | #include <asm/txx9/jmr3927.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #if JMR3927_IRQ_END > NR_IRQS |
| 45 | #error JMR3927_IRQ_END > NR_IRQS |
| 46 | #endif |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static unsigned char irc_level[TX3927_NUM_IR] = { |
| 49 | 5, 5, 5, 5, 5, 5, /* INT[5:0] */ |
| 50 | 7, 7, /* SIO */ |
| 51 | 5, 5, 5, 0, 0, /* DMA, PIO, PCI */ |
| 52 | 6, 6, 6 /* TMR */ |
| 53 | }; |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* |
| 56 | * CP0_STATUS is a thread's resource (saved/restored on context switch). |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 57 | * So disable_irq/enable_irq MUST handle IOC/IRC registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | */ |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 59 | static void mask_irq_ioc(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | /* 0: mask */ |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 62 | unsigned int irq_nr = irq - JMR3927_IRQ_IOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR); |
| 64 | unsigned int bit = 1 << irq_nr; |
| 65 | jmr3927_ioc_reg_out(imask & ~bit, JMR3927_IOC_INTM_ADDR); |
| 66 | /* flush write buffer */ |
| 67 | (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR); |
| 68 | } |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 69 | static void unmask_irq_ioc(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | /* 0: mask */ |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 72 | unsigned int irq_nr = irq - JMR3927_IRQ_IOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR); |
| 74 | unsigned int bit = 1 << irq_nr; |
| 75 | jmr3927_ioc_reg_out(imask | bit, JMR3927_IOC_INTM_ADDR); |
| 76 | /* flush write buffer */ |
| 77 | (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR); |
| 78 | } |
| 79 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 80 | asmlinkage void plat_irq_dispatch(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 82 | unsigned long cp0_cause = read_c0_cause(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | int irq; |
| 84 | |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 85 | if ((cp0_cause & CAUSEF_IP7) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | return; |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 87 | irq = (cp0_cause >> CAUSEB_IP2) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 89 | do_IRQ(irq + JMR3927_IRQ_IRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 92 | static irqreturn_t jmr3927_ioc_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | unsigned char istat = jmr3927_ioc_reg_in(JMR3927_IOC_INTS2_ADDR); |
| 95 | int i; |
| 96 | |
| 97 | for (i = 0; i < JMR3927_NR_IRQ_IOC; i++) { |
| 98 | if (istat & (1 << i)) { |
| 99 | irq = JMR3927_IRQ_IOC + i; |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 100 | do_IRQ(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
Sergei Shtylylov | 702a96a | 2005-11-18 22:20:31 +0300 | [diff] [blame] | 103 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static struct irqaction ioc_action = { |
Thomas Gleixner | 4e45171 | 2007-08-28 09:03:01 +0000 | [diff] [blame] | 107 | .handler = jmr3927_ioc_interrupt, |
| 108 | .mask = CPU_MASK_NONE, |
| 109 | .name = "IOC", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame^] | 112 | #ifdef CONFIG_PCI |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 113 | static irqreturn_t jmr3927_pcierr_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | printk(KERN_WARNING "PCI error interrupt (irq 0x%x).\n", irq); |
| 116 | printk(KERN_WARNING "pcistat:%02x, lbstat:%04lx\n", |
| 117 | tx3927_pcicptr->pcistat, tx3927_pcicptr->lbstat); |
Sergei Shtylylov | 702a96a | 2005-11-18 22:20:31 +0300 | [diff] [blame] | 118 | |
| 119 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | static struct irqaction pcierr_action = { |
Thomas Gleixner | 4e45171 | 2007-08-28 09:03:01 +0000 | [diff] [blame] | 122 | .handler = jmr3927_pcierr_interrupt, |
| 123 | .mask = CPU_MASK_NONE, |
| 124 | .name = "PCI error", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; |
Atsushi Nemoto | 89d63fe | 2008-07-11 00:33:08 +0900 | [diff] [blame^] | 126 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 128 | static void __init jmr3927_irq_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | void __init arch_init_irq(void) |
| 131 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Now, interrupt control disabled, */ |
| 133 | /* all IRC interrupts are masked, */ |
| 134 | /* all IRC interrupt mode are Low Active. */ |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* mask all IOC interrupts */ |
| 137 | jmr3927_ioc_reg_out(0, JMR3927_IOC_INTM_ADDR); |
| 138 | /* setup IOC interrupt mode (SOFT:High Active, Others:Low Active) */ |
| 139 | jmr3927_ioc_reg_out(JMR3927_IOC_INTF_SOFT, JMR3927_IOC_INTP_ADDR); |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* clear PCI Soft interrupts */ |
| 142 | jmr3927_ioc_reg_out(0, JMR3927_IOC_INTS1_ADDR); |
| 143 | /* clear PCI Reset interrupts */ |
| 144 | jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR); |
| 145 | |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 146 | jmr3927_irq_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* setup IOC interrupt 1 (PCI, MODEM) */ |
| 149 | setup_irq(JMR3927_IRQ_IOCINT, &ioc_action); |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #ifdef CONFIG_PCI |
| 152 | setup_irq(JMR3927_IRQ_IRC_PCI, &pcierr_action); |
| 153 | #endif |
| 154 | |
| 155 | /* enable all CPU interrupt bits. */ |
| 156 | set_c0_status(ST0_IM); /* IE bit is still 0. */ |
| 157 | } |
| 158 | |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 159 | static struct irq_chip jmr3927_irq_ioc = { |
| 160 | .name = "jmr3927_ioc", |
| 161 | .ack = mask_irq_ioc, |
| 162 | .mask = mask_irq_ioc, |
| 163 | .mask_ack = mask_irq_ioc, |
| 164 | .unmask = unmask_irq_ioc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 167 | static void __init jmr3927_irq_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
| 169 | u32 i; |
| 170 | |
Atsushi Nemoto | c87abd7 | 2007-08-02 23:36:02 +0900 | [diff] [blame] | 171 | txx9_irq_init(TX3927_IRC_REG); |
| 172 | for (i = 0; i < TXx9_MAX_IR; i++) |
| 173 | txx9_irq_set_pri(i, irc_level[i]); |
Atsushi Nemoto | 2127435 | 2007-03-15 00:58:28 +0900 | [diff] [blame] | 174 | for (i = JMR3927_IRQ_IOC; i < JMR3927_IRQ_IOC + JMR3927_NR_IRQ_IOC; i++) |
| 175 | set_irq_chip_and_handler(i, &jmr3927_irq_ioc, handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |