Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Shared interrupt handling code for IPR and INTC2 types of IRQs. |
| 3 | * |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 4 | * Copyright (C) 2007, 2008 Magnus Damm |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 5 | * |
| 6 | * Based on intc2.c and ipr.c |
| 7 | * |
| 8 | * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi |
| 9 | * Copyright (C) 2000 Kazumoto Kojima |
| 10 | * Copyright (C) 2001 David J. Mckay (david.mckay@st.com) |
| 11 | * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp> |
| 12 | * Copyright (C) 2005, 2006 Paul Mundt |
| 13 | * |
| 14 | * This file is subject to the terms and conditions of the GNU General Public |
| 15 | * License. See the file "COPYING" in the main directory of this archive |
| 16 | * for more details. |
| 17 | */ |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/interrupt.h> |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 23 | #include <linux/bootmem.h> |
Paul Mundt | bbfbd8b | 2008-10-01 16:13:54 +0900 | [diff] [blame] | 24 | #include <linux/sh_intc.h> |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 25 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 26 | #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \ |
| 27 | ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \ |
| 28 | ((addr_e) << 16) | ((addr_d << 24))) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 29 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 30 | #define _INTC_SHIFT(h) (h & 0x1f) |
| 31 | #define _INTC_WIDTH(h) ((h >> 5) & 0xf) |
| 32 | #define _INTC_FN(h) ((h >> 9) & 0xf) |
| 33 | #define _INTC_MODE(h) ((h >> 13) & 0x7) |
| 34 | #define _INTC_ADDR_E(h) ((h >> 16) & 0xff) |
| 35 | #define _INTC_ADDR_D(h) ((h >> 24) & 0xff) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 36 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 37 | struct intc_handle_int { |
| 38 | unsigned int irq; |
| 39 | unsigned long handle; |
| 40 | }; |
| 41 | |
| 42 | struct intc_desc_int { |
| 43 | unsigned long *reg; |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 44 | #ifdef CONFIG_SMP |
| 45 | unsigned long *smp; |
| 46 | #endif |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 47 | unsigned int nr_reg; |
| 48 | struct intc_handle_int *prio; |
| 49 | unsigned int nr_prio; |
| 50 | struct intc_handle_int *sense; |
| 51 | unsigned int nr_sense; |
| 52 | struct irq_chip chip; |
| 53 | }; |
| 54 | |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 55 | #ifdef CONFIG_SMP |
| 56 | #define IS_SMP(x) x.smp |
| 57 | #define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c)) |
| 58 | #define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1) |
| 59 | #else |
| 60 | #define IS_SMP(x) 0 |
| 61 | #define INTC_REG(d, x, c) (d->reg[(x)]) |
| 62 | #define SMP_NR(d, x) 1 |
| 63 | #endif |
| 64 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 65 | static unsigned int intc_prio_level[NR_IRQS]; /* for now */ |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 66 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 67 | static unsigned long ack_handle[NR_IRQS]; |
| 68 | #endif |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 69 | |
| 70 | static inline struct intc_desc_int *get_intc_desc(unsigned int irq) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 71 | { |
| 72 | struct irq_chip *chip = get_irq_chip(irq); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 73 | return (void *)((char *)chip - offsetof(struct intc_desc_int, chip)); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline unsigned int set_field(unsigned int value, |
| 77 | unsigned int field_value, |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 78 | unsigned int handle) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 79 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 80 | unsigned int width = _INTC_WIDTH(handle); |
| 81 | unsigned int shift = _INTC_SHIFT(handle); |
| 82 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 83 | value &= ~(((1 << width) - 1) << shift); |
| 84 | value |= field_value << shift; |
| 85 | return value; |
| 86 | } |
| 87 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 88 | static void write_8(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 89 | { |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 90 | __raw_writeb(set_field(0, data, h), addr); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 91 | } |
| 92 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 93 | static void write_16(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 94 | { |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 95 | __raw_writew(set_field(0, data, h), addr); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 96 | } |
| 97 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 98 | static void write_32(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 99 | { |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 100 | __raw_writel(set_field(0, data, h), addr); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 101 | } |
| 102 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 103 | static void modify_8(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 104 | { |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 105 | unsigned long flags; |
| 106 | local_irq_save(flags); |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 107 | __raw_writeb(set_field(__raw_readb(addr), data, h), addr); |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 108 | local_irq_restore(flags); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 111 | static void modify_16(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 112 | { |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 113 | unsigned long flags; |
| 114 | local_irq_save(flags); |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 115 | __raw_writew(set_field(__raw_readw(addr), data, h), addr); |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 116 | local_irq_restore(flags); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 119 | static void modify_32(unsigned long addr, unsigned long h, unsigned long data) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 120 | { |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 121 | unsigned long flags; |
| 122 | local_irq_save(flags); |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 123 | __raw_writel(set_field(__raw_readl(addr), data, h), addr); |
Magnus Damm | 4370fe1 | 2008-04-24 21:53:07 +0900 | [diff] [blame] | 124 | local_irq_restore(flags); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 125 | } |
| 126 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 127 | enum { REG_FN_ERR = 0, REG_FN_WRITE_BASE = 1, REG_FN_MODIFY_BASE = 5 }; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 128 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 129 | static void (*intc_reg_fns[])(unsigned long addr, |
| 130 | unsigned long h, |
| 131 | unsigned long data) = { |
| 132 | [REG_FN_WRITE_BASE + 0] = write_8, |
| 133 | [REG_FN_WRITE_BASE + 1] = write_16, |
| 134 | [REG_FN_WRITE_BASE + 3] = write_32, |
| 135 | [REG_FN_MODIFY_BASE + 0] = modify_8, |
| 136 | [REG_FN_MODIFY_BASE + 1] = modify_16, |
| 137 | [REG_FN_MODIFY_BASE + 3] = modify_32, |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 138 | }; |
| 139 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 140 | enum { MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */ |
| 141 | MODE_MASK_REG, /* Bit(s) set -> interrupt disabled */ |
| 142 | MODE_DUAL_REG, /* Two registers, set bit to enable / disable */ |
| 143 | MODE_PRIO_REG, /* Priority value written to enable interrupt */ |
| 144 | MODE_PCLR_REG, /* Above plus all bits set to disable interrupt */ |
| 145 | }; |
| 146 | |
| 147 | static void intc_mode_field(unsigned long addr, |
| 148 | unsigned long handle, |
| 149 | void (*fn)(unsigned long, |
| 150 | unsigned long, |
| 151 | unsigned long), |
| 152 | unsigned int irq) |
| 153 | { |
| 154 | fn(addr, handle, ((1 << _INTC_WIDTH(handle)) - 1)); |
| 155 | } |
| 156 | |
| 157 | static void intc_mode_zero(unsigned long addr, |
| 158 | unsigned long handle, |
| 159 | void (*fn)(unsigned long, |
| 160 | unsigned long, |
| 161 | unsigned long), |
| 162 | unsigned int irq) |
| 163 | { |
| 164 | fn(addr, handle, 0); |
| 165 | } |
| 166 | |
| 167 | static void intc_mode_prio(unsigned long addr, |
| 168 | unsigned long handle, |
| 169 | void (*fn)(unsigned long, |
| 170 | unsigned long, |
| 171 | unsigned long), |
| 172 | unsigned int irq) |
| 173 | { |
| 174 | fn(addr, handle, intc_prio_level[irq]); |
| 175 | } |
| 176 | |
| 177 | static void (*intc_enable_fns[])(unsigned long addr, |
| 178 | unsigned long handle, |
| 179 | void (*fn)(unsigned long, |
| 180 | unsigned long, |
| 181 | unsigned long), |
| 182 | unsigned int irq) = { |
| 183 | [MODE_ENABLE_REG] = intc_mode_field, |
| 184 | [MODE_MASK_REG] = intc_mode_zero, |
| 185 | [MODE_DUAL_REG] = intc_mode_field, |
| 186 | [MODE_PRIO_REG] = intc_mode_prio, |
| 187 | [MODE_PCLR_REG] = intc_mode_prio, |
| 188 | }; |
| 189 | |
| 190 | static void (*intc_disable_fns[])(unsigned long addr, |
| 191 | unsigned long handle, |
| 192 | void (*fn)(unsigned long, |
| 193 | unsigned long, |
| 194 | unsigned long), |
| 195 | unsigned int irq) = { |
| 196 | [MODE_ENABLE_REG] = intc_mode_zero, |
| 197 | [MODE_MASK_REG] = intc_mode_field, |
| 198 | [MODE_DUAL_REG] = intc_mode_field, |
| 199 | [MODE_PRIO_REG] = intc_mode_zero, |
| 200 | [MODE_PCLR_REG] = intc_mode_field, |
| 201 | }; |
| 202 | |
| 203 | static inline void _intc_enable(unsigned int irq, unsigned long handle) |
| 204 | { |
| 205 | struct intc_desc_int *d = get_intc_desc(irq); |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 206 | unsigned long addr; |
| 207 | unsigned int cpu; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 208 | |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 209 | for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) { |
| 210 | addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu); |
| 211 | intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\ |
| 212 | [_INTC_FN(handle)], irq); |
| 213 | } |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 214 | } |
| 215 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 216 | static void intc_enable(unsigned int irq) |
| 217 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 218 | _intc_enable(irq, (unsigned long)get_irq_chip_data(irq)); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static void intc_disable(unsigned int irq) |
| 222 | { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 223 | struct intc_desc_int *d = get_intc_desc(irq); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 224 | unsigned long handle = (unsigned long) get_irq_chip_data(irq); |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 225 | unsigned long addr; |
| 226 | unsigned int cpu; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 227 | |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 228 | for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) { |
| 229 | addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu); |
| 230 | intc_disable_fns[_INTC_MODE(handle)](addr, handle,intc_reg_fns\ |
| 231 | [_INTC_FN(handle)], irq); |
| 232 | } |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 233 | } |
| 234 | |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 235 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 236 | static void intc_mask_ack(unsigned int irq) |
| 237 | { |
| 238 | struct intc_desc_int *d = get_intc_desc(irq); |
| 239 | unsigned long handle = ack_handle[irq]; |
| 240 | unsigned long addr; |
| 241 | |
| 242 | intc_disable(irq); |
| 243 | |
| 244 | /* read register and write zero only to the assocaited bit */ |
| 245 | |
| 246 | if (handle) { |
| 247 | addr = INTC_REG(d, _INTC_ADDR_D(handle), 0); |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 248 | switch (_INTC_FN(handle)) { |
| 249 | case REG_FN_MODIFY_BASE + 0: /* 8bit */ |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 250 | __raw_readb(addr); |
| 251 | __raw_writeb(0xff ^ set_field(0, 1, handle), addr); |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 252 | break; |
| 253 | case REG_FN_MODIFY_BASE + 1: /* 16bit */ |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 254 | __raw_readw(addr); |
| 255 | __raw_writew(0xffff ^ set_field(0, 1, handle), addr); |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 256 | break; |
| 257 | case REG_FN_MODIFY_BASE + 3: /* 32bit */ |
Paul Mundt | 62429e0 | 2008-10-01 15:19:10 +0900 | [diff] [blame] | 258 | __raw_readl(addr); |
| 259 | __raw_writel(0xffffffff ^ set_field(0, 1, handle), addr); |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 260 | break; |
| 261 | default: |
| 262 | BUG(); |
| 263 | break; |
| 264 | } |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | #endif |
| 268 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 269 | static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp, |
| 270 | unsigned int nr_hp, |
| 271 | unsigned int irq) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 272 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 273 | int i; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 274 | |
Magnus Damm | 3d37d94 | 2007-08-17 00:50:44 +0900 | [diff] [blame] | 275 | /* this doesn't scale well, but... |
| 276 | * |
| 277 | * this function should only be used for cerain uncommon |
| 278 | * operations such as intc_set_priority() and intc_set_sense() |
| 279 | * and in those rare cases performance doesn't matter that much. |
| 280 | * keeping the memory footprint low is more important. |
| 281 | * |
| 282 | * one rather simple way to speed this up and still keep the |
| 283 | * memory footprint down is to make sure the array is sorted |
| 284 | * and then perform a bisect to lookup the irq. |
| 285 | */ |
| 286 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 287 | for (i = 0; i < nr_hp; i++) { |
| 288 | if ((hp + i)->irq != irq) |
| 289 | continue; |
| 290 | |
| 291 | return hp + i; |
| 292 | } |
| 293 | |
| 294 | return NULL; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 295 | } |
| 296 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 297 | int intc_set_priority(unsigned int irq, unsigned int prio) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 298 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 299 | struct intc_desc_int *d = get_intc_desc(irq); |
| 300 | struct intc_handle_int *ihp; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 301 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 302 | if (!intc_prio_level[irq] || prio <= 1) |
| 303 | return -EINVAL; |
| 304 | |
| 305 | ihp = intc_find_irq(d->prio, d->nr_prio, irq); |
| 306 | if (ihp) { |
Magnus Damm | 3d37d94 | 2007-08-17 00:50:44 +0900 | [diff] [blame] | 307 | if (prio >= (1 << _INTC_WIDTH(ihp->handle))) |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 308 | return -EINVAL; |
| 309 | |
| 310 | intc_prio_level[irq] = prio; |
| 311 | |
| 312 | /* |
| 313 | * only set secondary masking method directly |
| 314 | * primary masking method is using intc_prio_level[irq] |
| 315 | * priority level will be set during next enable() |
| 316 | */ |
| 317 | |
Magnus Damm | 3d37d94 | 2007-08-17 00:50:44 +0900 | [diff] [blame] | 318 | if (_INTC_FN(ihp->handle) != REG_FN_ERR) |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 319 | _intc_enable(irq, ihp->handle); |
| 320 | } |
| 321 | return 0; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | #define VALID(x) (x | 0x80) |
| 325 | |
| 326 | static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = { |
| 327 | [IRQ_TYPE_EDGE_FALLING] = VALID(0), |
| 328 | [IRQ_TYPE_EDGE_RISING] = VALID(1), |
| 329 | [IRQ_TYPE_LEVEL_LOW] = VALID(2), |
Magnus Damm | 720be99 | 2008-04-24 21:47:15 +0900 | [diff] [blame] | 330 | /* SH7706, SH7707 and SH7709 do not support high level triggered */ |
| 331 | #if !defined(CONFIG_CPU_SUBTYPE_SH7706) && \ |
| 332 | !defined(CONFIG_CPU_SUBTYPE_SH7707) && \ |
| 333 | !defined(CONFIG_CPU_SUBTYPE_SH7709) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 334 | [IRQ_TYPE_LEVEL_HIGH] = VALID(3), |
Magnus Damm | 720be99 | 2008-04-24 21:47:15 +0900 | [diff] [blame] | 335 | #endif |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | static int intc_set_sense(unsigned int irq, unsigned int type) |
| 339 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 340 | struct intc_desc_int *d = get_intc_desc(irq); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 341 | unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK]; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 342 | struct intc_handle_int *ihp; |
| 343 | unsigned long addr; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 344 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 345 | if (!value) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 346 | return -EINVAL; |
| 347 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 348 | ihp = intc_find_irq(d->sense, d->nr_sense, irq); |
| 349 | if (ihp) { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 350 | addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 351 | intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 352 | } |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 353 | return 0; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 354 | } |
| 355 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 356 | static unsigned int __init intc_get_reg(struct intc_desc_int *d, |
| 357 | unsigned long address) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 358 | { |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 359 | unsigned int k; |
| 360 | |
| 361 | for (k = 0; k < d->nr_reg; k++) { |
| 362 | if (d->reg[k] == address) |
| 363 | return k; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | BUG(); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 367 | return 0; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 368 | } |
| 369 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 370 | static intc_enum __init intc_grp_id(struct intc_desc *desc, |
| 371 | intc_enum enum_id) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 372 | { |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 373 | struct intc_group *g = desc->groups; |
| 374 | unsigned int i, j; |
| 375 | |
| 376 | for (i = 0; g && enum_id && i < desc->nr_groups; i++) { |
| 377 | g = desc->groups + i; |
| 378 | |
| 379 | for (j = 0; g->enum_ids[j]; j++) { |
| 380 | if (g->enum_ids[j] != enum_id) |
| 381 | continue; |
| 382 | |
| 383 | return g->enum_id; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 390 | static unsigned int __init intc_mask_data(struct intc_desc *desc, |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 391 | struct intc_desc_int *d, |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 392 | intc_enum enum_id, int do_grps) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 393 | { |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 394 | struct intc_mask_reg *mr = desc->mask_regs; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 395 | unsigned int i, j, fn, mode; |
| 396 | unsigned long reg_e, reg_d; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 397 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 398 | for (i = 0; mr && enum_id && i < desc->nr_mask_regs; i++) { |
| 399 | mr = desc->mask_regs + i; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 400 | |
| 401 | for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) { |
| 402 | if (mr->enum_ids[j] != enum_id) |
| 403 | continue; |
| 404 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 405 | if (mr->set_reg && mr->clr_reg) { |
| 406 | fn = REG_FN_WRITE_BASE; |
| 407 | mode = MODE_DUAL_REG; |
| 408 | reg_e = mr->clr_reg; |
| 409 | reg_d = mr->set_reg; |
| 410 | } else { |
| 411 | fn = REG_FN_MODIFY_BASE; |
| 412 | if (mr->set_reg) { |
| 413 | mode = MODE_ENABLE_REG; |
| 414 | reg_e = mr->set_reg; |
| 415 | reg_d = mr->set_reg; |
| 416 | } else { |
| 417 | mode = MODE_MASK_REG; |
| 418 | reg_e = mr->clr_reg; |
| 419 | reg_d = mr->clr_reg; |
| 420 | } |
Magnus Damm | 51da642 | 2007-08-03 14:25:32 +0900 | [diff] [blame] | 421 | } |
| 422 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 423 | fn += (mr->reg_width >> 3) - 1; |
| 424 | return _INTC_MK(fn, mode, |
| 425 | intc_get_reg(d, reg_e), |
| 426 | intc_get_reg(d, reg_d), |
| 427 | 1, |
| 428 | (mr->reg_width - 1) - j); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 432 | if (do_grps) |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 433 | return intc_mask_data(desc, d, intc_grp_id(desc, enum_id), 0); |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 434 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | static unsigned int __init intc_prio_data(struct intc_desc *desc, |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 439 | struct intc_desc_int *d, |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 440 | intc_enum enum_id, int do_grps) |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 441 | { |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 442 | struct intc_prio_reg *pr = desc->prio_regs; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 443 | unsigned int i, j, fn, mode, bit; |
| 444 | unsigned long reg_e, reg_d; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 445 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 446 | for (i = 0; pr && enum_id && i < desc->nr_prio_regs; i++) { |
| 447 | pr = desc->prio_regs + i; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 448 | |
| 449 | for (j = 0; j < ARRAY_SIZE(pr->enum_ids); j++) { |
| 450 | if (pr->enum_ids[j] != enum_id) |
| 451 | continue; |
| 452 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 453 | if (pr->set_reg && pr->clr_reg) { |
| 454 | fn = REG_FN_WRITE_BASE; |
| 455 | mode = MODE_PCLR_REG; |
| 456 | reg_e = pr->set_reg; |
| 457 | reg_d = pr->clr_reg; |
| 458 | } else { |
| 459 | fn = REG_FN_MODIFY_BASE; |
| 460 | mode = MODE_PRIO_REG; |
| 461 | if (!pr->set_reg) |
| 462 | BUG(); |
| 463 | reg_e = pr->set_reg; |
| 464 | reg_d = pr->set_reg; |
| 465 | } |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 466 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 467 | fn += (pr->reg_width >> 3) - 1; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 468 | |
roel kluin | b21a910 | 2008-09-09 23:02:43 +0200 | [diff] [blame] | 469 | BUG_ON((j + 1) * pr->field_width > pr->reg_width); |
| 470 | |
| 471 | bit = pr->reg_width - ((j + 1) * pr->field_width); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 472 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 473 | return _INTC_MK(fn, mode, |
| 474 | intc_get_reg(d, reg_e), |
| 475 | intc_get_reg(d, reg_d), |
| 476 | pr->field_width, bit); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 480 | if (do_grps) |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 481 | return intc_prio_data(desc, d, intc_grp_id(desc, enum_id), 0); |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 482 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 486 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 487 | static unsigned int __init intc_ack_data(struct intc_desc *desc, |
| 488 | struct intc_desc_int *d, |
| 489 | intc_enum enum_id) |
| 490 | { |
| 491 | struct intc_mask_reg *mr = desc->ack_regs; |
| 492 | unsigned int i, j, fn, mode; |
| 493 | unsigned long reg_e, reg_d; |
| 494 | |
| 495 | for (i = 0; mr && enum_id && i < desc->nr_ack_regs; i++) { |
| 496 | mr = desc->ack_regs + i; |
| 497 | |
| 498 | for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) { |
| 499 | if (mr->enum_ids[j] != enum_id) |
| 500 | continue; |
| 501 | |
| 502 | fn = REG_FN_MODIFY_BASE; |
| 503 | mode = MODE_ENABLE_REG; |
| 504 | reg_e = mr->set_reg; |
| 505 | reg_d = mr->set_reg; |
| 506 | |
| 507 | fn += (mr->reg_width >> 3) - 1; |
| 508 | return _INTC_MK(fn, mode, |
| 509 | intc_get_reg(d, reg_e), |
| 510 | intc_get_reg(d, reg_d), |
| 511 | 1, |
| 512 | (mr->reg_width - 1) - j); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | #endif |
| 519 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 520 | static unsigned int __init intc_sense_data(struct intc_desc *desc, |
| 521 | struct intc_desc_int *d, |
| 522 | intc_enum enum_id) |
| 523 | { |
| 524 | struct intc_sense_reg *sr = desc->sense_regs; |
| 525 | unsigned int i, j, fn, bit; |
| 526 | |
| 527 | for (i = 0; sr && enum_id && i < desc->nr_sense_regs; i++) { |
| 528 | sr = desc->sense_regs + i; |
| 529 | |
| 530 | for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) { |
| 531 | if (sr->enum_ids[j] != enum_id) |
| 532 | continue; |
| 533 | |
| 534 | fn = REG_FN_MODIFY_BASE; |
| 535 | fn += (sr->reg_width >> 3) - 1; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 536 | |
roel kluin | b21a910 | 2008-09-09 23:02:43 +0200 | [diff] [blame] | 537 | BUG_ON((j + 1) * sr->field_width > sr->reg_width); |
| 538 | |
| 539 | bit = sr->reg_width - ((j + 1) * sr->field_width); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 540 | |
| 541 | return _INTC_MK(fn, 0, intc_get_reg(d, sr->reg), |
| 542 | 0, sr->field_width, bit); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static void __init intc_register_irq(struct intc_desc *desc, |
| 550 | struct intc_desc_int *d, |
| 551 | intc_enum enum_id, |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 552 | unsigned int irq) |
| 553 | { |
Magnus Damm | 3d37d94 | 2007-08-17 00:50:44 +0900 | [diff] [blame] | 554 | struct intc_handle_int *hp; |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 555 | unsigned int data[2], primary; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 556 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 557 | /* Prefer single interrupt source bitmap over other combinations: |
| 558 | * 1. bitmap, single interrupt source |
| 559 | * 2. priority, single interrupt source |
| 560 | * 3. bitmap, multiple interrupt sources (groups) |
| 561 | * 4. priority, multiple interrupt sources (groups) |
| 562 | */ |
| 563 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 564 | data[0] = intc_mask_data(desc, d, enum_id, 0); |
| 565 | data[1] = intc_prio_data(desc, d, enum_id, 0); |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 566 | |
| 567 | primary = 0; |
| 568 | if (!data[0] && data[1]) |
| 569 | primary = 1; |
| 570 | |
Magnus Damm | bdaa6e8 | 2009-02-24 22:58:57 +0900 | [diff] [blame^] | 571 | if (!data[0] && !data[1]) |
| 572 | pr_warning("intc: missing unique irq mask for 0x%04x\n", |
| 573 | irq2evt(irq)); |
| 574 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 575 | data[0] = data[0] ? data[0] : intc_mask_data(desc, d, enum_id, 1); |
| 576 | data[1] = data[1] ? data[1] : intc_prio_data(desc, d, enum_id, 1); |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 577 | |
| 578 | if (!data[primary]) |
| 579 | primary ^= 1; |
| 580 | |
| 581 | BUG_ON(!data[primary]); /* must have primary masking method */ |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 582 | |
| 583 | disable_irq_nosync(irq); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 584 | set_irq_chip_and_handler_name(irq, &d->chip, |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 585 | handle_level_irq, "level"); |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 586 | set_irq_chip_data(irq, (void *)data[primary]); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 587 | |
Magnus Damm | 7f3edee | 2008-01-10 14:08:55 +0900 | [diff] [blame] | 588 | /* set priority level |
| 589 | * - this needs to be at least 2 for 5-bit priorities on 7780 |
| 590 | */ |
| 591 | intc_prio_level[irq] = 2; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 592 | |
Magnus Damm | 680c459 | 2007-07-20 12:09:29 +0900 | [diff] [blame] | 593 | /* enable secondary masking method if present */ |
| 594 | if (data[!primary]) |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 595 | _intc_enable(irq, data[!primary]); |
| 596 | |
| 597 | /* add irq to d->prio list if priority is available */ |
| 598 | if (data[1]) { |
Magnus Damm | 3d37d94 | 2007-08-17 00:50:44 +0900 | [diff] [blame] | 599 | hp = d->prio + d->nr_prio; |
| 600 | hp->irq = irq; |
| 601 | hp->handle = data[1]; |
| 602 | |
| 603 | if (primary) { |
| 604 | /* |
| 605 | * only secondary priority should access registers, so |
| 606 | * set _INTC_FN(h) = REG_FN_ERR for intc_set_priority() |
| 607 | */ |
| 608 | |
| 609 | hp->handle &= ~_INTC_MK(0x0f, 0, 0, 0, 0, 0); |
| 610 | hp->handle |= _INTC_MK(REG_FN_ERR, 0, 0, 0, 0, 0); |
| 611 | } |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 612 | d->nr_prio++; |
| 613 | } |
| 614 | |
| 615 | /* add irq to d->sense list if sense is available */ |
| 616 | data[0] = intc_sense_data(desc, d, enum_id); |
| 617 | if (data[0]) { |
| 618 | (d->sense + d->nr_sense)->irq = irq; |
| 619 | (d->sense + d->nr_sense)->handle = data[0]; |
| 620 | d->nr_sense++; |
| 621 | } |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 622 | |
| 623 | /* irq should be disabled by default */ |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 624 | d->chip.mask(irq); |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 625 | |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 626 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 627 | if (desc->ack_regs) |
| 628 | ack_handle[irq] = intc_ack_data(desc, d, enum_id); |
| 629 | #endif |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 630 | } |
| 631 | |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 632 | static unsigned int __init save_reg(struct intc_desc_int *d, |
| 633 | unsigned int cnt, |
| 634 | unsigned long value, |
| 635 | unsigned int smp) |
| 636 | { |
| 637 | if (value) { |
| 638 | d->reg[cnt] = value; |
| 639 | #ifdef CONFIG_SMP |
| 640 | d->smp[cnt] = smp; |
| 641 | #endif |
| 642 | return 1; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
Magnus Damm | bdaa6e8 | 2009-02-24 22:58:57 +0900 | [diff] [blame^] | 648 | static unsigned char *intc_evt2irq_table; |
| 649 | |
| 650 | unsigned int intc_evt2irq(unsigned int vector) |
| 651 | { |
| 652 | unsigned int irq = evt2irq(vector); |
| 653 | |
| 654 | if (intc_evt2irq_table && intc_evt2irq_table[irq]) |
| 655 | irq = intc_evt2irq_table[irq]; |
| 656 | |
| 657 | return irq; |
| 658 | } |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 659 | |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 660 | void __init register_intc_controller(struct intc_desc *desc) |
| 661 | { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 662 | unsigned int i, k, smp; |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 663 | struct intc_desc_int *d; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 664 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 665 | d = alloc_bootmem(sizeof(*d)); |
| 666 | |
| 667 | d->nr_reg = desc->mask_regs ? desc->nr_mask_regs * 2 : 0; |
| 668 | d->nr_reg += desc->prio_regs ? desc->nr_prio_regs * 2 : 0; |
| 669 | d->nr_reg += desc->sense_regs ? desc->nr_sense_regs : 0; |
| 670 | |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 671 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 672 | d->nr_reg += desc->ack_regs ? desc->nr_ack_regs : 0; |
| 673 | #endif |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 674 | d->reg = alloc_bootmem(d->nr_reg * sizeof(*d->reg)); |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 675 | #ifdef CONFIG_SMP |
| 676 | d->smp = alloc_bootmem(d->nr_reg * sizeof(*d->smp)); |
| 677 | #endif |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 678 | k = 0; |
| 679 | |
| 680 | if (desc->mask_regs) { |
| 681 | for (i = 0; i < desc->nr_mask_regs; i++) { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 682 | smp = IS_SMP(desc->mask_regs[i]); |
| 683 | k += save_reg(d, k, desc->mask_regs[i].set_reg, smp); |
| 684 | k += save_reg(d, k, desc->mask_regs[i].clr_reg, smp); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | if (desc->prio_regs) { |
| 689 | d->prio = alloc_bootmem(desc->nr_vectors * sizeof(*d->prio)); |
| 690 | |
| 691 | for (i = 0; i < desc->nr_prio_regs; i++) { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 692 | smp = IS_SMP(desc->prio_regs[i]); |
| 693 | k += save_reg(d, k, desc->prio_regs[i].set_reg, smp); |
| 694 | k += save_reg(d, k, desc->prio_regs[i].clr_reg, smp); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | if (desc->sense_regs) { |
| 699 | d->sense = alloc_bootmem(desc->nr_vectors * sizeof(*d->sense)); |
| 700 | |
| 701 | for (i = 0; i < desc->nr_sense_regs; i++) { |
Magnus Damm | f18d533 | 2007-09-21 18:16:42 +0900 | [diff] [blame] | 702 | k += save_reg(d, k, desc->sense_regs[i].reg, 0); |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 706 | d->chip.name = desc->name; |
| 707 | d->chip.mask = intc_disable; |
| 708 | d->chip.unmask = intc_enable; |
| 709 | d->chip.mask_ack = intc_disable; |
| 710 | d->chip.set_type = intc_set_sense; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 711 | |
Yoshihiro Shimoda | 6bdfb22 | 2008-07-04 12:37:12 +0900 | [diff] [blame] | 712 | #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A) |
Magnus Damm | d58876e | 2008-04-24 21:36:34 +0900 | [diff] [blame] | 713 | if (desc->ack_regs) { |
| 714 | for (i = 0; i < desc->nr_ack_regs; i++) |
| 715 | k += save_reg(d, k, desc->ack_regs[i].set_reg, 0); |
| 716 | |
| 717 | d->chip.mask_ack = intc_mask_ack; |
| 718 | } |
| 719 | #endif |
| 720 | |
| 721 | BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */ |
| 722 | |
Magnus Damm | bdaa6e8 | 2009-02-24 22:58:57 +0900 | [diff] [blame^] | 723 | /* keep the first vector only if same enum is used multiple times */ |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 724 | for (i = 0; i < desc->nr_vectors; i++) { |
| 725 | struct intc_vect *vect = desc->vectors + i; |
Magnus Damm | bdaa6e8 | 2009-02-24 22:58:57 +0900 | [diff] [blame^] | 726 | int first_irq = evt2irq(vect->vect); |
| 727 | |
| 728 | if (!vect->enum_id) |
| 729 | continue; |
| 730 | |
| 731 | for (k = i + 1; k < desc->nr_vectors; k++) { |
| 732 | struct intc_vect *vect2 = desc->vectors + k; |
| 733 | |
| 734 | if (vect->enum_id != vect2->enum_id) |
| 735 | continue; |
| 736 | |
| 737 | vect2->enum_id = 0; |
| 738 | |
| 739 | if (!intc_evt2irq_table) |
| 740 | intc_evt2irq_table = alloc_bootmem(NR_IRQS); |
| 741 | |
| 742 | if (!intc_evt2irq_table) { |
| 743 | pr_warning("intc: cannot allocate evt2irq!\n"); |
| 744 | continue; |
| 745 | } |
| 746 | |
| 747 | intc_evt2irq_table[evt2irq(vect2->vect)] = first_irq; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | /* register the vectors one by one */ |
| 752 | for (i = 0; i < desc->nr_vectors; i++) { |
| 753 | struct intc_vect *vect = desc->vectors + i; |
| 754 | |
| 755 | if (!vect->enum_id) |
| 756 | continue; |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 757 | |
Magnus Damm | 73505b4 | 2007-08-12 15:26:12 +0900 | [diff] [blame] | 758 | intc_register_irq(desc, d, vect->enum_id, evt2irq(vect->vect)); |
Magnus Damm | 02ab3f7 | 2007-07-18 17:25:09 +0900 | [diff] [blame] | 759 | } |
| 760 | } |