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> |
| 22 | #include <linux/irq.h> |
| 23 | #include <linux/sched.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/kernel_stat.h> |
| 27 | |
| 28 | #include <asm/bootinfo.h> |
Ralf Baechle | a5ccfe5c1 | 2007-10-14 23:49:33 +0100 | [diff] [blame^] | 29 | #include <asm/irq_cpu.h> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 30 | #include <asm/lasat/lasatint.h> |
| 31 | #include <asm/time.h> |
| 32 | #include <asm/gdb-stub.h> |
| 33 | |
| 34 | static volatile int *lasat_int_status; |
| 35 | static volatile int *lasat_int_mask; |
| 36 | static volatile int lasat_int_mask_shift; |
| 37 | |
| 38 | void disable_lasat_irq(unsigned int irq_nr) |
| 39 | { |
| 40 | *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift; |
| 41 | } |
| 42 | |
| 43 | void enable_lasat_irq(unsigned int irq_nr) |
| 44 | { |
| 45 | *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift; |
| 46 | } |
| 47 | |
| 48 | static struct irq_chip lasat_irq_type = { |
| 49 | .name = "Lasat", |
| 50 | .ack = disable_lasat_irq, |
| 51 | .mask = disable_lasat_irq, |
| 52 | .mask_ack = disable_lasat_irq, |
| 53 | .unmask = enable_lasat_irq, |
| 54 | }; |
| 55 | |
| 56 | static inline int ls1bit32(unsigned int x) |
| 57 | { |
| 58 | int b = 31, s; |
| 59 | |
| 60 | s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s; |
| 61 | s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s; |
| 62 | s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s; |
| 63 | s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s; |
| 64 | s = 1; if (x << 1 == 0) s = 0; b -= s; |
| 65 | |
| 66 | return b; |
| 67 | } |
| 68 | |
| 69 | static unsigned long (*get_int_status)(void); |
| 70 | |
| 71 | static unsigned long get_int_status_100(void) |
| 72 | { |
| 73 | return *lasat_int_status & *lasat_int_mask; |
| 74 | } |
| 75 | |
| 76 | static unsigned long get_int_status_200(void) |
| 77 | { |
| 78 | unsigned long int_status; |
| 79 | |
| 80 | int_status = *lasat_int_status; |
| 81 | int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff; |
| 82 | return int_status; |
| 83 | } |
| 84 | |
| 85 | asmlinkage void plat_irq_dispatch(void) |
| 86 | { |
| 87 | unsigned long int_status; |
| 88 | unsigned int cause = read_c0_cause(); |
| 89 | int irq; |
| 90 | |
| 91 | if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */ |
Ralf Baechle | a5ccfe5c1 | 2007-10-14 23:49:33 +0100 | [diff] [blame^] | 92 | do_IRQ(7); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | |
| 96 | int_status = get_int_status(); |
| 97 | |
| 98 | /* if int_status == 0, then the interrupt has already been cleared */ |
| 99 | if (int_status) { |
Ralf Baechle | a5ccfe5c1 | 2007-10-14 23:49:33 +0100 | [diff] [blame^] | 100 | irq = LASATINT_BASE + ls1bit32(int_status); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 101 | |
| 102 | do_IRQ(irq); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void __init arch_init_irq(void) |
| 107 | { |
| 108 | int i; |
| 109 | |
| 110 | switch (mips_machtype) { |
| 111 | case MACH_LASAT_100: |
| 112 | lasat_int_status = (void *)LASAT_INT_STATUS_REG_100; |
| 113 | lasat_int_mask = (void *)LASAT_INT_MASK_REG_100; |
| 114 | lasat_int_mask_shift = LASATINT_MASK_SHIFT_100; |
| 115 | get_int_status = get_int_status_100; |
| 116 | *lasat_int_mask = 0; |
| 117 | break; |
| 118 | case MACH_LASAT_200: |
| 119 | lasat_int_status = (void *)LASAT_INT_STATUS_REG_200; |
| 120 | lasat_int_mask = (void *)LASAT_INT_MASK_REG_200; |
| 121 | lasat_int_mask_shift = LASATINT_MASK_SHIFT_200; |
| 122 | get_int_status = get_int_status_200; |
| 123 | *lasat_int_mask &= 0xffff; |
| 124 | break; |
| 125 | default: |
| 126 | panic("arch_init_irq: mips_machtype incorrect"); |
| 127 | } |
| 128 | |
Ralf Baechle | a5ccfe5c1 | 2007-10-14 23:49:33 +0100 | [diff] [blame^] | 129 | mips_cpu_irq_init(); |
| 130 | for (i = LASATINT_BASE; i <= LASATINT_END; i++) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 131 | set_irq_chip_and_handler(i, &lasat_irq_type, handle_level_irq); |
| 132 | } |