Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Carsten Langgaard, carstenl@mips.com |
| 3 | * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can distribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License (Version 2) as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 17 | * |
| 18 | * Routines for generic manipulation of the interrupts found on the |
| 19 | * Lasat boards. |
| 20 | */ |
| 21 | #include <linux/init.h> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 23 | #include <linux/irq.h> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 24 | |
| 25 | #include <asm/bootinfo.h> |
Ralf Baechle | a5ccfe5 | 2007-10-14 23:49:33 +0100 | [diff] [blame] | 26 | #include <asm/irq_cpu.h> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 27 | #include <asm/lasat/lasatint.h> |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 28 | |
| 29 | #include <irq.h> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 30 | |
| 31 | static volatile int *lasat_int_status; |
| 32 | static volatile int *lasat_int_mask; |
| 33 | static volatile int lasat_int_mask_shift; |
| 34 | |
| 35 | void disable_lasat_irq(unsigned int irq_nr) |
| 36 | { |
| 37 | *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift; |
| 38 | } |
| 39 | |
| 40 | void enable_lasat_irq(unsigned int irq_nr) |
| 41 | { |
| 42 | *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift; |
| 43 | } |
| 44 | |
| 45 | static struct irq_chip lasat_irq_type = { |
| 46 | .name = "Lasat", |
| 47 | .ack = disable_lasat_irq, |
| 48 | .mask = disable_lasat_irq, |
| 49 | .mask_ack = disable_lasat_irq, |
| 50 | .unmask = enable_lasat_irq, |
| 51 | }; |
| 52 | |
| 53 | static inline int ls1bit32(unsigned int x) |
| 54 | { |
| 55 | int b = 31, s; |
| 56 | |
| 57 | s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s; |
| 58 | s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s; |
| 59 | s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s; |
| 60 | s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s; |
| 61 | s = 1; if (x << 1 == 0) s = 0; b -= s; |
| 62 | |
| 63 | return b; |
| 64 | } |
| 65 | |
| 66 | static unsigned long (*get_int_status)(void); |
| 67 | |
| 68 | static unsigned long get_int_status_100(void) |
| 69 | { |
| 70 | return *lasat_int_status & *lasat_int_mask; |
| 71 | } |
| 72 | |
| 73 | static unsigned long get_int_status_200(void) |
| 74 | { |
| 75 | unsigned long int_status; |
| 76 | |
| 77 | int_status = *lasat_int_status; |
| 78 | int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff; |
| 79 | return int_status; |
| 80 | } |
| 81 | |
| 82 | asmlinkage void plat_irq_dispatch(void) |
| 83 | { |
| 84 | unsigned long int_status; |
| 85 | unsigned int cause = read_c0_cause(); |
| 86 | int irq; |
| 87 | |
| 88 | if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */ |
Ralf Baechle | a5ccfe5 | 2007-10-14 23:49:33 +0100 | [diff] [blame] | 89 | do_IRQ(7); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
| 93 | int_status = get_int_status(); |
| 94 | |
| 95 | /* if int_status == 0, then the interrupt has already been cleared */ |
| 96 | if (int_status) { |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 97 | irq = LASAT_IRQ_BASE + ls1bit32(int_status); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 98 | |
| 99 | do_IRQ(irq); |
| 100 | } |
| 101 | } |
| 102 | |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 103 | static struct irqaction cascade = { |
| 104 | .handler = no_action, |
| 105 | .mask = CPU_MASK_NONE, |
| 106 | .name = "cascade", |
| 107 | }; |
| 108 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 109 | void __init arch_init_irq(void) |
| 110 | { |
| 111 | int i; |
| 112 | |
| 113 | switch (mips_machtype) { |
| 114 | case MACH_LASAT_100: |
| 115 | lasat_int_status = (void *)LASAT_INT_STATUS_REG_100; |
| 116 | lasat_int_mask = (void *)LASAT_INT_MASK_REG_100; |
| 117 | lasat_int_mask_shift = LASATINT_MASK_SHIFT_100; |
| 118 | get_int_status = get_int_status_100; |
| 119 | *lasat_int_mask = 0; |
| 120 | break; |
| 121 | case MACH_LASAT_200: |
| 122 | lasat_int_status = (void *)LASAT_INT_STATUS_REG_200; |
| 123 | lasat_int_mask = (void *)LASAT_INT_MASK_REG_200; |
| 124 | lasat_int_mask_shift = LASATINT_MASK_SHIFT_200; |
| 125 | get_int_status = get_int_status_200; |
| 126 | *lasat_int_mask &= 0xffff; |
| 127 | break; |
| 128 | default: |
| 129 | panic("arch_init_irq: mips_machtype incorrect"); |
| 130 | } |
| 131 | |
Ralf Baechle | a5ccfe5 | 2007-10-14 23:49:33 +0100 | [diff] [blame] | 132 | mips_cpu_irq_init(); |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 133 | |
| 134 | for (i = LASAT_IRQ_BASE; i <= LASAT_IRQ_END; i++) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 135 | set_irq_chip_and_handler(i, &lasat_irq_type, handle_level_irq); |
Yoichi Yuasa | 89becf5 | 2007-11-09 18:42:35 +0900 | [diff] [blame] | 136 | |
| 137 | setup_irq(LASAT_CASCADE_IRQ, &cascade); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 138 | } |