2 * Interrupt management for most GSC and related devices.
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
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.
16 #include <linux/bitops.h>
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>
22 #include <linux/slab.h>
23 #include <linux/types.h>
25 #include <asm/hardware.h>
33 #define DEBPRINTK printk
35 #define DEBPRINTK(x,...)
38 int gsc_alloc_irq(struct gsc_irq *i)
40 int irq = txn_alloc_irq(GSC_EIM_WIDTH);
42 printk("cannot get irq\n");
46 i->txn_addr = txn_alloc_addr(irq);
47 i->txn_data = txn_alloc_data(irq);
53 int gsc_claim_irq(struct gsc_irq *i, int irq)
57 irq += CPU_IRQ_BASE; /* virtualize the IRQ first */
59 irq = txn_claim_irq(irq);
61 printk("cannot claim irq %d\n", c);
65 i->txn_addr = txn_alloc_addr(irq);
66 i->txn_data = txn_alloc_data(irq);
72 EXPORT_SYMBOL(gsc_alloc_irq);
73 EXPORT_SYMBOL(gsc_claim_irq);
75 /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
76 irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
79 struct gsc_asic *gsc_asic = dev;
81 irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR);
85 DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr);
88 int local_irq = __ffs(irr);
89 unsigned int irq = gsc_asic->global_irq[local_irq];
91 irr &= ~(1 << local_irq);
97 int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit)
101 for (local_irq = 0; local_irq < limit; local_irq++) {
102 if (global_irqs[local_irq] == irq)
109 static void gsc_asic_disable_irq(unsigned int irq)
111 struct irq_desc *desc = irq_to_desc(irq);
112 struct gsc_asic *irq_dev = desc->chip_data;
113 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
116 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
119 /* Disable the IRQ line by clearing the bit in the IMR */
120 imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
121 imr &= ~(1 << local_irq);
122 gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
125 static void gsc_asic_enable_irq(unsigned int irq)
127 struct irq_desc *desc = irq_to_desc(irq);
128 struct gsc_asic *irq_dev = desc->chip_data;
129 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
132 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
135 /* Enable the IRQ line by setting the bit in the IMR */
136 imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
137 imr |= 1 << local_irq;
138 gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
140 * FIXME: read IPR to make sure the IRQ isn't already pending.
141 * If so, we need to read IRR and manually call do_irq().
145 static unsigned int gsc_asic_startup_irq(unsigned int irq)
147 gsc_asic_enable_irq(irq);
151 static struct irq_chip gsc_asic_interrupt_type = {
152 .typename = "GSC-ASIC",
153 .startup = gsc_asic_startup_irq,
154 .shutdown = gsc_asic_disable_irq,
155 .enable = gsc_asic_enable_irq,
156 .disable = gsc_asic_disable_irq,
161 int gsc_assign_irq(struct irq_chip *type, void *data)
163 static int irq = GSC_IRQ_BASE;
164 struct irq_desc *desc;
166 if (irq > GSC_IRQ_MAX)
169 desc = irq_to_desc(irq);
171 desc->chip_data = data;
175 void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
177 int irq = asic->global_irq[local_irq];
180 irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
184 asic->global_irq[local_irq] = irq;
189 struct gsc_fixup_struct {
190 void (*choose_irq)(struct parisc_device *, void *);
194 static int gsc_fixup_irqs_callback(struct device *dev, void *data)
196 struct parisc_device *padev = to_parisc_device(dev);
197 struct gsc_fixup_struct *gf = data;
199 /* work-around for 715/64 and others which have parent
200 at path [5] and children at path [5/0/x] */
201 if (padev->id.hw_type == HPHW_FAULTY)
202 gsc_fixup_irqs(padev, gf->ctrl, gf->choose_irq);
203 gf->choose_irq(padev, gf->ctrl);
208 void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
209 void (*choose_irq)(struct parisc_device *, void *))
211 struct gsc_fixup_struct data = {
212 .choose_irq = choose_irq,
216 device_for_each_child(&parent->dev, &data, gsc_fixup_irqs_callback);
219 int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
221 struct resource *res;
224 gsc_asic->gsc = parent;
226 /* Initialise local irq -> global irq mapping */
227 for (i = 0; i < 32; i++) {
228 gsc_asic->global_irq[i] = NO_IRQ;
231 /* allocate resource region */
232 res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
234 res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
238 printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
239 parent->irq, gsc_asic->eim);
240 if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
241 printk(" IMR is non-zero! (0x%x)",
242 gsc_readl(gsc_asic->hpa + OFFSET_IMR));
249 extern struct parisc_driver lasi_driver;
250 extern struct parisc_driver asp_driver;
251 extern struct parisc_driver wax_driver;
253 void __init gsc_init(void)
255 #ifdef CONFIG_GSC_LASI
256 register_parisc_driver(&lasi_driver);
257 register_parisc_driver(&asp_driver);
259 #ifdef CONFIG_GSC_WAX
260 register_parisc_driver(&wax_driver);