Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mundt | a23ba43 | 2007-11-28 20:19:38 +0900 | [diff] [blame] | 2 | * arch/sh/kernel/cpu/irq/intc-sh5.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Paul Mundt | a23ba43 | 2007-11-28 20:19:38 +0900 | [diff] [blame] | 4 | * Interrupt Controller support for SH5 INTC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2000, 2001 Paolo Alberelli |
| 7 | * Copyright (C) 2003 Paul Mundt |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Per-interrupt selective. IRLM=0 (Fixed priority) is not |
| 10 | * supported being useless without a cascaded interrupt |
| 11 | * controller. |
| 12 | * |
Paul Mundt | a23ba43 | 2007-11-28 20:19:38 +0900 | [diff] [blame] | 13 | * This file is subject to the terms and conditions of the GNU General Public |
| 14 | * License. See the file "COPYING" in the main directory of this archive |
| 15 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
Paul Mundt | da9d510 | 2007-07-31 13:07:37 +0900 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/irq.h> |
Paul Mundt | 18bc813 | 2007-11-21 23:16:33 +0900 | [diff] [blame] | 20 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Paul Mundt | 18bc813 | 2007-11-21 23:16:33 +0900 | [diff] [blame] | 22 | #include <linux/bitops.h> |
Paul Mundt | f15cbe6 | 2008-07-29 08:09:44 +0900 | [diff] [blame] | 23 | #include <cpu/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * Maybe the generic Peripheral block could move to a more |
| 28 | * generic include file. INTC Block will be defined here |
| 29 | * and only here to make INTC self-contained in a single |
| 30 | * file. |
| 31 | */ |
| 32 | #define INTC_BLOCK_OFFSET 0x01000000 |
| 33 | |
| 34 | /* Base */ |
| 35 | #define INTC_BASE PHYS_PERIPHERAL_BLOCK + \ |
| 36 | INTC_BLOCK_OFFSET |
| 37 | |
| 38 | /* Address */ |
| 39 | #define INTC_ICR_SET (intc_virt + 0x0) |
| 40 | #define INTC_ICR_CLEAR (intc_virt + 0x8) |
| 41 | #define INTC_INTPRI_0 (intc_virt + 0x10) |
| 42 | #define INTC_INTSRC_0 (intc_virt + 0x50) |
| 43 | #define INTC_INTSRC_1 (intc_virt + 0x58) |
| 44 | #define INTC_INTREQ_0 (intc_virt + 0x60) |
| 45 | #define INTC_INTREQ_1 (intc_virt + 0x68) |
| 46 | #define INTC_INTENB_0 (intc_virt + 0x70) |
| 47 | #define INTC_INTENB_1 (intc_virt + 0x78) |
| 48 | #define INTC_INTDSB_0 (intc_virt + 0x80) |
| 49 | #define INTC_INTDSB_1 (intc_virt + 0x88) |
| 50 | |
| 51 | #define INTC_ICR_IRLM 0x1 |
| 52 | #define INTC_INTPRI_PREGS 8 /* 8 Priority Registers */ |
| 53 | #define INTC_INTPRI_PPREG 8 /* 8 Priorities per Register */ |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * Mapper between the vector ordinal and the IRQ number |
| 58 | * passed to kernel/device drivers. |
| 59 | */ |
| 60 | int intc_evt_to_irq[(0xE20/0x20)+1] = { |
| 61 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x000 - 0x0E0 */ |
| 62 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x100 - 0x1E0 */ |
| 63 | 0, 0, 0, 0, 0, 1, 0, 0, /* 0x200 - 0x2E0 */ |
| 64 | 2, 0, 0, 3, 0, 0, 0, -1, /* 0x300 - 0x3E0 */ |
| 65 | 32, 33, 34, 35, 36, 37, 38, -1, /* 0x400 - 0x4E0 */ |
| 66 | -1, -1, -1, 63, -1, -1, -1, -1, /* 0x500 - 0x5E0 */ |
| 67 | -1, -1, 18, 19, 20, 21, 22, -1, /* 0x600 - 0x6E0 */ |
| 68 | 39, 40, 41, 42, -1, -1, -1, -1, /* 0x700 - 0x7E0 */ |
| 69 | 4, 5, 6, 7, -1, -1, -1, -1, /* 0x800 - 0x8E0 */ |
| 70 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x900 - 0x9E0 */ |
| 71 | 12, 13, 14, 15, 16, 17, -1, -1, /* 0xA00 - 0xAE0 */ |
| 72 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0xB00 - 0xBE0 */ |
| 73 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0xC00 - 0xCE0 */ |
| 74 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0xD00 - 0xDE0 */ |
| 75 | -1, -1 /* 0xE00 - 0xE20 */ |
| 76 | }; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static unsigned long intc_virt; |
| 79 | |
| 80 | static unsigned int startup_intc_irq(unsigned int irq); |
| 81 | static void shutdown_intc_irq(unsigned int irq); |
| 82 | static void enable_intc_irq(unsigned int irq); |
| 83 | static void disable_intc_irq(unsigned int irq); |
| 84 | static void mask_and_ack_intc(unsigned int); |
| 85 | static void end_intc_irq(unsigned int irq); |
| 86 | |
Thomas Gleixner | d804983 | 2009-05-02 20:01:20 +0000 | [diff] [blame] | 87 | static struct irq_chip intc_irq_type = { |
Thomas Gleixner | c05e066 | 2005-09-10 00:26:44 -0700 | [diff] [blame] | 88 | .typename = "INTC", |
| 89 | .startup = startup_intc_irq, |
| 90 | .shutdown = shutdown_intc_irq, |
| 91 | .enable = enable_intc_irq, |
| 92 | .disable = disable_intc_irq, |
| 93 | .ack = mask_and_ack_intc, |
| 94 | .end = end_intc_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | static int irlm; /* IRL mode */ |
| 98 | |
| 99 | static unsigned int startup_intc_irq(unsigned int irq) |
| 100 | { |
| 101 | enable_intc_irq(irq); |
| 102 | return 0; /* never anything pending */ |
| 103 | } |
| 104 | |
| 105 | static void shutdown_intc_irq(unsigned int irq) |
| 106 | { |
| 107 | disable_intc_irq(irq); |
| 108 | } |
| 109 | |
| 110 | static void enable_intc_irq(unsigned int irq) |
| 111 | { |
| 112 | unsigned long reg; |
| 113 | unsigned long bitmask; |
| 114 | |
| 115 | if ((irq <= IRQ_IRL3) && (irlm == NO_PRIORITY)) |
| 116 | printk("Trying to use straight IRL0-3 with an encoding platform.\n"); |
| 117 | |
| 118 | if (irq < 32) { |
| 119 | reg = INTC_INTENB_0; |
| 120 | bitmask = 1 << irq; |
| 121 | } else { |
| 122 | reg = INTC_INTENB_1; |
| 123 | bitmask = 1 << (irq - 32); |
| 124 | } |
| 125 | |
| 126 | ctrl_outl(bitmask, reg); |
| 127 | } |
| 128 | |
| 129 | static void disable_intc_irq(unsigned int irq) |
| 130 | { |
| 131 | unsigned long reg; |
| 132 | unsigned long bitmask; |
| 133 | |
| 134 | if (irq < 32) { |
| 135 | reg = INTC_INTDSB_0; |
| 136 | bitmask = 1 << irq; |
| 137 | } else { |
| 138 | reg = INTC_INTDSB_1; |
| 139 | bitmask = 1 << (irq - 32); |
| 140 | } |
| 141 | |
| 142 | ctrl_outl(bitmask, reg); |
| 143 | } |
| 144 | |
| 145 | static void mask_and_ack_intc(unsigned int irq) |
| 146 | { |
| 147 | disable_intc_irq(irq); |
| 148 | } |
| 149 | |
| 150 | static void end_intc_irq(unsigned int irq) |
| 151 | { |
| 152 | enable_intc_irq(irq); |
| 153 | } |
| 154 | |
Paul Mundt | 18bc813 | 2007-11-21 23:16:33 +0900 | [diff] [blame] | 155 | void __init plat_irq_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 157 | unsigned long long __dummy0, __dummy1=~0x00000000100000f0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | unsigned long reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | int i; |
| 160 | |
Paul Mundt | 0fb849b | 2009-05-07 18:10:27 +0900 | [diff] [blame] | 161 | intc_virt = (unsigned long)ioremap_nocache(INTC_BASE, 1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (!intc_virt) { |
| 163 | panic("Unable to remap INTC\n"); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /* Set default: per-line enable/disable, priority driven ack/eoi */ |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 168 | for (i = 0; i < NR_INTC_IRQS; i++) |
Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 169 | set_irq_chip_and_handler(i, &intc_irq_type, handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | |
| 172 | /* Disable all interrupts and set all priorities to 0 to avoid trouble */ |
| 173 | ctrl_outl(-1, INTC_INTDSB_0); |
| 174 | ctrl_outl(-1, INTC_INTDSB_1); |
| 175 | |
| 176 | for (reg = INTC_INTPRI_0, i = 0; i < INTC_INTPRI_PREGS; i++, reg += 8) |
| 177 | ctrl_outl( NO_PRIORITY, reg); |
| 178 | |
| 179 | |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 180 | #ifdef CONFIG_SH_CAYMAN |
| 181 | { |
| 182 | unsigned long data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 184 | /* Set IRLM */ |
| 185 | /* If all the priorities are set to 'no priority', then |
| 186 | * assume we are using encoded mode. |
| 187 | */ |
| 188 | irlm = platform_int_priority[IRQ_IRL0] + |
| 189 | platform_int_priority[IRQ_IRL1] + |
| 190 | platform_int_priority[IRQ_IRL2] + |
| 191 | platform_int_priority[IRQ_IRL3]; |
| 192 | if (irlm == NO_PRIORITY) { |
| 193 | /* IRLM = 0 */ |
| 194 | reg = INTC_ICR_CLEAR; |
| 195 | i = IRQ_INTA; |
| 196 | printk("Trying to use encoded IRL0-3. IRLs unsupported.\n"); |
| 197 | } else { |
| 198 | /* IRLM = 1 */ |
| 199 | reg = INTC_ICR_SET; |
| 200 | i = IRQ_IRL0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 202 | ctrl_outl(INTC_ICR_IRLM, reg); |
| 203 | |
| 204 | /* Set interrupt priorities according to platform description */ |
| 205 | for (data = 0, reg = INTC_INTPRI_0; i < NR_INTC_IRQS; i++) { |
| 206 | data |= platform_int_priority[i] << |
| 207 | ((i % INTC_INTPRI_PPREG) * 4); |
| 208 | if ((i % INTC_INTPRI_PPREG) == (INTC_INTPRI_PPREG - 1)) { |
| 209 | /* Upon the 7th, set Priority Register */ |
| 210 | ctrl_outl(data, reg); |
| 211 | data = 0; |
| 212 | reg += 8; |
| 213 | } |
| 214 | } |
Adrian Bunk | 2beb0e2 | 2008-05-30 01:04:49 +0300 | [diff] [blame] | 215 | } |
Paul Mundt | a1dc4b5 | 2008-04-25 16:08:37 +0900 | [diff] [blame] | 216 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* |
| 219 | * And now let interrupts come in. |
| 220 | * sti() is not enough, we need to |
| 221 | * lower priority, too. |
| 222 | */ |
| 223 | __asm__ __volatile__("getcon " __SR ", %0\n\t" |
| 224 | "and %0, %1, %0\n\t" |
| 225 | "putcon %0, " __SR "\n\t" |
| 226 | : "=&r" (__dummy0) |
| 227 | : "r" (__dummy1)); |
| 228 | } |