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