Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Interrupt management for most GSC and related devices. |
| 3 | * |
| 4 | * (c) Copyright 1999 Alex deVries for The Puffin Group |
| 5 | * (c) Copyright 1999 Grant Grundler for Hewlett-Packard |
| 6 | * (c) Copyright 1999 Matthew Wilcox |
| 7 | * (c) Copyright 2000 Helge Deller |
| 8 | * (c) Copyright 2001 Matthew Wilcox for Hewlett-Packard |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/ioport.h> |
| 21 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/types.h> |
| 23 | |
| 24 | #include <asm/hardware.h> |
| 25 | #include <asm/io.h> |
| 26 | |
| 27 | #include "gsc.h" |
| 28 | |
| 29 | #undef DEBUG |
| 30 | |
| 31 | #ifdef DEBUG |
| 32 | #define DEBPRINTK printk |
| 33 | #else |
| 34 | #define DEBPRINTK(x,...) |
| 35 | #endif |
| 36 | |
| 37 | int gsc_alloc_irq(struct gsc_irq *i) |
| 38 | { |
| 39 | int irq = txn_alloc_irq(GSC_EIM_WIDTH); |
| 40 | if (irq < 0) { |
| 41 | printk("cannot get irq\n"); |
| 42 | return irq; |
| 43 | } |
| 44 | |
| 45 | i->txn_addr = txn_alloc_addr(irq); |
| 46 | i->txn_data = txn_alloc_data(irq); |
| 47 | i->irq = irq; |
| 48 | |
| 49 | return irq; |
| 50 | } |
| 51 | |
| 52 | int gsc_claim_irq(struct gsc_irq *i, int irq) |
| 53 | { |
| 54 | int c = irq; |
| 55 | |
| 56 | irq += CPU_IRQ_BASE; /* virtualize the IRQ first */ |
| 57 | |
| 58 | irq = txn_claim_irq(irq); |
| 59 | if (irq < 0) { |
| 60 | printk("cannot claim irq %d\n", c); |
| 61 | return irq; |
| 62 | } |
| 63 | |
| 64 | i->txn_addr = txn_alloc_addr(irq); |
| 65 | i->txn_data = txn_alloc_data(irq); |
| 66 | i->irq = irq; |
| 67 | |
| 68 | return irq; |
| 69 | } |
| 70 | |
| 71 | EXPORT_SYMBOL(gsc_alloc_irq); |
| 72 | EXPORT_SYMBOL(gsc_claim_irq); |
| 73 | |
| 74 | /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 75 | irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
| 77 | unsigned long irr; |
| 78 | struct gsc_asic *gsc_asic = dev; |
| 79 | |
| 80 | irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR); |
| 81 | if (irr == 0) |
| 82 | return IRQ_NONE; |
| 83 | |
| 84 | DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr); |
| 85 | |
| 86 | do { |
| 87 | int local_irq = __ffs(irr); |
| 88 | unsigned int irq = gsc_asic->global_irq[local_irq]; |
Kyle McMartin | ba20085 | 2010-10-13 21:00:55 -0400 | [diff] [blame^] | 89 | generic_handle_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | irr &= ~(1 << local_irq); |
| 91 | } while (irr); |
| 92 | |
| 93 | return IRQ_HANDLED; |
| 94 | } |
| 95 | |
| 96 | int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit) |
| 97 | { |
| 98 | int local_irq; |
| 99 | |
| 100 | for (local_irq = 0; local_irq < limit; local_irq++) { |
| 101 | if (global_irqs[local_irq] == irq) |
| 102 | return local_irq; |
| 103 | } |
| 104 | |
| 105 | return NO_IRQ; |
| 106 | } |
| 107 | |
| 108 | static void gsc_asic_disable_irq(unsigned int irq) |
| 109 | { |
Kyle McMartin | ba20085 | 2010-10-13 21:00:55 -0400 | [diff] [blame^] | 110 | struct gsc_asic *irq_dev = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32); |
| 112 | u32 imr; |
| 113 | |
Harvey Harrison | a8043ec | 2008-05-14 16:21:56 -0700 | [diff] [blame] | 114 | DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | irq_dev->name, imr); |
| 116 | |
| 117 | /* Disable the IRQ line by clearing the bit in the IMR */ |
| 118 | imr = gsc_readl(irq_dev->hpa + OFFSET_IMR); |
| 119 | imr &= ~(1 << local_irq); |
| 120 | gsc_writel(imr, irq_dev->hpa + OFFSET_IMR); |
| 121 | } |
| 122 | |
| 123 | static void gsc_asic_enable_irq(unsigned int irq) |
| 124 | { |
Kyle McMartin | ba20085 | 2010-10-13 21:00:55 -0400 | [diff] [blame^] | 125 | struct gsc_asic *irq_dev = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32); |
| 127 | u32 imr; |
| 128 | |
Harvey Harrison | a8043ec | 2008-05-14 16:21:56 -0700 | [diff] [blame] | 129 | DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | irq_dev->name, imr); |
| 131 | |
| 132 | /* Enable the IRQ line by setting the bit in the IMR */ |
| 133 | imr = gsc_readl(irq_dev->hpa + OFFSET_IMR); |
| 134 | imr |= 1 << local_irq; |
| 135 | gsc_writel(imr, irq_dev->hpa + OFFSET_IMR); |
| 136 | /* |
| 137 | * FIXME: read IPR to make sure the IRQ isn't already pending. |
| 138 | * If so, we need to read IRR and manually call do_irq(). |
| 139 | */ |
| 140 | } |
| 141 | |
| 142 | static unsigned int gsc_asic_startup_irq(unsigned int irq) |
| 143 | { |
| 144 | gsc_asic_enable_irq(irq); |
| 145 | return 0; |
| 146 | } |
| 147 | |
Thomas Gleixner | dfe0756 | 2009-06-10 19:56:04 +0000 | [diff] [blame] | 148 | static struct irq_chip gsc_asic_interrupt_type = { |
Thomas Gleixner | d0608b5 | 2009-11-17 22:50:59 +0000 | [diff] [blame] | 149 | .name = "GSC-ASIC", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | .startup = gsc_asic_startup_irq, |
| 151 | .shutdown = gsc_asic_disable_irq, |
| 152 | .enable = gsc_asic_enable_irq, |
| 153 | .disable = gsc_asic_disable_irq, |
| 154 | .ack = no_ack_irq, |
| 155 | .end = no_end_irq, |
| 156 | }; |
| 157 | |
Thomas Gleixner | dfe0756 | 2009-06-10 19:56:04 +0000 | [diff] [blame] | 158 | int gsc_assign_irq(struct irq_chip *type, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | static int irq = GSC_IRQ_BASE; |
| 161 | |
| 162 | if (irq > GSC_IRQ_MAX) |
| 163 | return NO_IRQ; |
| 164 | |
Kyle McMartin | ba20085 | 2010-10-13 21:00:55 -0400 | [diff] [blame^] | 165 | set_irq_chip_and_handler(irq, type, parisc_do_IRQ); |
| 166 | set_irq_chip_data(irq, data); |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return irq++; |
| 169 | } |
| 170 | |
| 171 | void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp) |
| 172 | { |
| 173 | int irq = asic->global_irq[local_irq]; |
| 174 | |
| 175 | if (irq <= 0) { |
| 176 | irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic); |
| 177 | if (irq == NO_IRQ) |
| 178 | return; |
| 179 | |
| 180 | asic->global_irq[local_irq] = irq; |
| 181 | } |
| 182 | *irqp = irq; |
| 183 | } |
| 184 | |
James Bottomley | bfe4f4f | 2009-01-09 18:57:06 -0600 | [diff] [blame] | 185 | struct gsc_fixup_struct { |
| 186 | void (*choose_irq)(struct parisc_device *, void *); |
| 187 | void *ctrl; |
| 188 | }; |
| 189 | |
| 190 | static int gsc_fixup_irqs_callback(struct device *dev, void *data) |
Matthew Wilcox | 5658374 | 2005-10-21 22:33:38 -0400 | [diff] [blame] | 191 | { |
James Bottomley | bfe4f4f | 2009-01-09 18:57:06 -0600 | [diff] [blame] | 192 | struct parisc_device *padev = to_parisc_device(dev); |
| 193 | struct gsc_fixup_struct *gf = data; |
| 194 | |
| 195 | /* work-around for 715/64 and others which have parent |
| 196 | at path [5] and children at path [5/0/x] */ |
| 197 | if (padev->id.hw_type == HPHW_FAULTY) |
| 198 | gsc_fixup_irqs(padev, gf->ctrl, gf->choose_irq); |
| 199 | gf->choose_irq(padev, gf->ctrl); |
| 200 | |
| 201 | return 0; |
Matthew Wilcox | 5658374 | 2005-10-21 22:33:38 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl, |
| 205 | void (*choose_irq)(struct parisc_device *, void *)) |
| 206 | { |
James Bottomley | bfe4f4f | 2009-01-09 18:57:06 -0600 | [diff] [blame] | 207 | struct gsc_fixup_struct data = { |
| 208 | .choose_irq = choose_irq, |
| 209 | .ctrl = ctrl, |
| 210 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
James Bottomley | bfe4f4f | 2009-01-09 18:57:06 -0600 | [diff] [blame] | 212 | device_for_each_child(&parent->dev, &data, gsc_fixup_irqs_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic) |
| 216 | { |
| 217 | struct resource *res; |
| 218 | int i; |
| 219 | |
| 220 | gsc_asic->gsc = parent; |
| 221 | |
| 222 | /* Initialise local irq -> global irq mapping */ |
| 223 | for (i = 0; i < 32; i++) { |
| 224 | gsc_asic->global_irq[i] = NO_IRQ; |
| 225 | } |
| 226 | |
| 227 | /* allocate resource region */ |
| 228 | res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name); |
| 229 | if (res) { |
| 230 | res->flags = IORESOURCE_MEM; /* do not mark it busy ! */ |
| 231 | } |
| 232 | |
| 233 | #if 0 |
| 234 | printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name, |
| 235 | parent->irq, gsc_asic->eim); |
| 236 | if (gsc_readl(gsc_asic->hpa + OFFSET_IMR)) |
| 237 | printk(" IMR is non-zero! (0x%x)", |
| 238 | gsc_readl(gsc_asic->hpa + OFFSET_IMR)); |
| 239 | printk("\n"); |
| 240 | #endif |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | extern struct parisc_driver lasi_driver; |
| 246 | extern struct parisc_driver asp_driver; |
| 247 | extern struct parisc_driver wax_driver; |
| 248 | |
| 249 | void __init gsc_init(void) |
| 250 | { |
| 251 | #ifdef CONFIG_GSC_LASI |
| 252 | register_parisc_driver(&lasi_driver); |
| 253 | register_parisc_driver(&asp_driver); |
| 254 | #endif |
| 255 | #ifdef CONFIG_GSC_WAX |
| 256 | register_parisc_driver(&wax_driver); |
| 257 | #endif |
| 258 | } |