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/config.h>
18 #include <linux/errno.h>
19 #include <linux/init.h>
20 #include <linux/interrupt.h>
21 #include <linux/ioport.h>
22 #include <linux/slab.h>
23 #include <linux/types.h>
26 #include <asm/hardware.h>
30 #include "busdevice.h"
35 #define DEBPRINTK printk
37 #define DEBPRINTK(x,...)
40 int gsc_alloc_irq(struct gsc_irq *i)
42 int irq = txn_alloc_irq();
44 printk("cannot get irq\n");
48 i->txn_addr = txn_alloc_addr(irq);
49 i->txn_data = txn_alloc_data(irq, GSC_EIM_WIDTH);
56 int gsc_claim_irq(struct gsc_irq *i, int irq)
60 irq += IRQ_FROM_REGION(CPU_IRQ_REGION); /* virtualize the IRQ first */
62 irq = txn_claim_irq(irq);
64 printk("cannot claim irq %d\n", c);
68 i->txn_addr = txn_alloc_addr(irq);
69 i->txn_data = txn_alloc_data(irq, GSC_EIM_WIDTH);
76 /* IRQ bits must be numbered from Most Significant Bit */
77 #define GSC_FIX_IRQ(x) (31-(x))
78 #define GSC_MASK_IRQ(x) (1<<(GSC_FIX_IRQ(x)))
80 /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
81 void busdev_barked(int busdev_irq, void *dev, struct pt_regs *regs)
84 struct busdevice *busdev = (struct busdevice *) dev;
87 Don't need to protect OFFSET_IRR with spinlock since this is
88 the only place it's touched.
89 Protect busdev_region by disabling this region's interrupts,
90 modifying the region, and then re-enabling the region.
93 irq = gsc_readl(busdev->hpa+OFFSET_IRR);
95 printk(KERN_ERR "%s: barking without apparent reason.\n", busdev->name);
97 DEBPRINTK ("%s (0x%x) barked, mask=0x%x, irq=%d\n",
98 busdev->name, busdev->busdev_region->data.irqbase,
99 irq, GSC_FIX_IRQ(ffs(irq))+1 );
101 do_irq_mask(irq, busdev->busdev_region, regs);
106 busdev_disable_irq(void *irq_dev, int irq)
108 /* Disable the IRQ line by clearing the bit in the IMR */
109 u32 imr = gsc_readl(BUSDEV_DEV(irq_dev)->hpa+OFFSET_IMR);
110 imr &= ~(GSC_MASK_IRQ(irq));
112 DEBPRINTK( KERN_WARNING "%s(%p, %d) %s: IMR 0x%x\n",
113 __FUNCTION__, irq_dev, irq, BUSDEV_DEV(irq_dev)->name, imr);
115 gsc_writel(imr, BUSDEV_DEV(irq_dev)->hpa+OFFSET_IMR);
120 busdev_enable_irq(void *irq_dev, int irq)
122 /* Enable the IRQ line by setting the bit in the IMR */
123 unsigned long addr = BUSDEV_DEV(irq_dev)->hpa + OFFSET_IMR;
124 u32 imr = gsc_readl(addr);
125 imr |= GSC_MASK_IRQ(irq);
127 DEBPRINTK (KERN_WARNING "%s(%p, %d) %s: IMR 0x%x\n",
128 __FUNCTION__, irq_dev, irq, BUSDEV_DEV(irq_dev)->name, imr);
130 gsc_writel(imr, addr);
131 // gsc_writel(~0L, addr);
133 /* FIXME: read IPR to make sure the IRQ isn't already pending.
134 ** If so, we need to read IRR and manually call do_irq_mask().
135 ** This code should be shared with busdev_unmask_irq().
140 busdev_mask_irq(void *irq_dev, int irq)
142 /* FIXME: Clear the IMR bit in busdev for that IRQ */
146 busdev_unmask_irq(void *irq_dev, int irq)
148 /* FIXME: Read IPR. Set the IMR bit in busdev for that IRQ.
149 call do_irq_mask() if IPR is non-zero
153 struct irq_region_ops busdev_irq_ops = {
154 disable_irq: busdev_disable_irq,
155 enable_irq: busdev_enable_irq,
156 mask_irq: busdev_mask_irq,
157 unmask_irq: busdev_unmask_irq
161 int gsc_common_irqsetup(struct parisc_device *parent, struct busdevice *busdev)
163 struct resource *res;
165 busdev->gsc = parent;
167 /* the IRQs we simulate */
168 busdev->busdev_region = alloc_irq_region(32, &busdev_irq_ops,
169 busdev->name, busdev);
170 if (!busdev->busdev_region)
173 /* allocate resource region */
174 res = request_mem_region(busdev->hpa, 0x100000, busdev->name);
176 res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
180 printk(KERN_WARNING "%s IRQ %d EIM 0x%x", busdev->name,
181 busdev->parent_irq, busdev->eim);
182 if (gsc_readl(busdev->hpa + OFFSET_IMR))
183 printk(" IMR is non-zero! (0x%x)",
184 gsc_readl(busdev->hpa + OFFSET_IMR));
191 extern struct parisc_driver lasi_driver;
192 extern struct parisc_driver asp_driver;
193 extern struct parisc_driver wax_driver;
195 void __init gsc_init(void)
197 #ifdef CONFIG_GSC_LASI
198 register_parisc_driver(&lasi_driver);
199 register_parisc_driver(&asp_driver);
201 #ifdef CONFIG_GSC_WAX
202 register_parisc_driver(&wax_driver);