blob: e76db9e4d504968fd774ca6fc877d3b462dda33a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070017#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>
24
25#include <asm/hardware.h>
26#include <asm/io.h>
27
28#include "gsc.h"
29
30#undef DEBUG
31
32#ifdef DEBUG
33#define DEBPRINTK printk
34#else
35#define DEBPRINTK(x,...)
36#endif
37
38int gsc_alloc_irq(struct gsc_irq *i)
39{
40 int irq = txn_alloc_irq(GSC_EIM_WIDTH);
41 if (irq < 0) {
42 printk("cannot get irq\n");
43 return irq;
44 }
45
46 i->txn_addr = txn_alloc_addr(irq);
47 i->txn_data = txn_alloc_data(irq);
48 i->irq = irq;
49
50 return irq;
51}
52
53int gsc_claim_irq(struct gsc_irq *i, int irq)
54{
55 int c = irq;
56
57 irq += CPU_IRQ_BASE; /* virtualize the IRQ first */
58
59 irq = txn_claim_irq(irq);
60 if (irq < 0) {
61 printk("cannot claim irq %d\n", c);
62 return irq;
63 }
64
65 i->txn_addr = txn_alloc_addr(irq);
66 i->txn_data = txn_alloc_data(irq);
67 i->irq = irq;
68
69 return irq;
70}
71
72EXPORT_SYMBOL(gsc_alloc_irq);
73EXPORT_SYMBOL(gsc_claim_irq);
74
75/* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
David Howells7d12e782006-10-05 14:55:46 +010076irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 unsigned long irr;
79 struct gsc_asic *gsc_asic = dev;
80
81 irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR);
82 if (irr == 0)
83 return IRQ_NONE;
84
85 DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr);
86
87 do {
88 int local_irq = __ffs(irr);
89 unsigned int irq = gsc_asic->global_irq[local_irq];
David Howells7d12e782006-10-05 14:55:46 +010090 __do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 irr &= ~(1 << local_irq);
92 } while (irr);
93
94 return IRQ_HANDLED;
95}
96
97int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit)
98{
99 int local_irq;
100
101 for (local_irq = 0; local_irq < limit; local_irq++) {
102 if (global_irqs[local_irq] == irq)
103 return local_irq;
104 }
105
106 return NO_IRQ;
107}
108
109static void gsc_asic_disable_irq(unsigned int irq)
110{
Yinghai Lu08678b02008-08-19 20:50:05 -0700111 struct irq_desc *desc = irq_to_desc(irq);
112 struct gsc_asic *irq_dev = desc->chip_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
114 u32 imr;
115
Harvey Harrisona8043ec2008-05-14 16:21:56 -0700116 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 irq_dev->name, imr);
118
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);
123}
124
125static void gsc_asic_enable_irq(unsigned int irq)
126{
Yinghai Lu08678b02008-08-19 20:50:05 -0700127 struct irq_desc *desc = irq_to_desc(irq);
128 struct gsc_asic *irq_dev = desc->chip_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
130 u32 imr;
131
Harvey Harrisona8043ec2008-05-14 16:21:56 -0700132 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 irq_dev->name, imr);
134
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);
139 /*
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().
142 */
143}
144
145static unsigned int gsc_asic_startup_irq(unsigned int irq)
146{
147 gsc_asic_enable_irq(irq);
148 return 0;
149}
150
151static struct hw_interrupt_type 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,
157 .ack = no_ack_irq,
158 .end = no_end_irq,
159};
160
161int gsc_assign_irq(struct hw_interrupt_type *type, void *data)
162{
163 static int irq = GSC_IRQ_BASE;
Yinghai Lu08678b02008-08-19 20:50:05 -0700164 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 if (irq > GSC_IRQ_MAX)
167 return NO_IRQ;
168
Yinghai Lu08678b02008-08-19 20:50:05 -0700169 desc = irq_to_desc(irq);
170 desc->chip = type;
171 desc->chip_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return irq++;
173}
174
175void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
176{
177 int irq = asic->global_irq[local_irq];
178
179 if (irq <= 0) {
180 irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
181 if (irq == NO_IRQ)
182 return;
183
184 asic->global_irq[local_irq] = irq;
185 }
186 *irqp = irq;
187}
188
Matthew Wilcox56583742005-10-21 22:33:38 -0400189static struct device *next_device(struct klist_iter *i)
190{
191 struct klist_node * n = klist_next(i);
192 return n ? container_of(n, struct device, knode_parent) : NULL;
193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
196 void (*choose_irq)(struct parisc_device *, void *))
197{
198 struct device *dev;
Matthew Wilcox56583742005-10-21 22:33:38 -0400199 struct klist_iter i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Matthew Wilcox56583742005-10-21 22:33:38 -0400201 klist_iter_init(&parent->dev.klist_children, &i);
202 while ((dev = next_device(&i))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 struct parisc_device *padev = to_parisc_device(dev);
204
205 /* work-around for 715/64 and others which have parent
206 at path [5] and children at path [5/0/x] */
207 if (padev->id.hw_type == HPHW_FAULTY)
208 return gsc_fixup_irqs(padev, ctrl, choose_irq);
209 choose_irq(padev, ctrl);
210 }
Matthew Wilcox56583742005-10-21 22:33:38 -0400211 klist_iter_exit(&i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
214int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
215{
216 struct resource *res;
217 int i;
218
219 gsc_asic->gsc = parent;
220
221 /* Initialise local irq -> global irq mapping */
222 for (i = 0; i < 32; i++) {
223 gsc_asic->global_irq[i] = NO_IRQ;
224 }
225
226 /* allocate resource region */
227 res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
228 if (res) {
229 res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
230 }
231
232#if 0
233 printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
234 parent->irq, gsc_asic->eim);
235 if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
236 printk(" IMR is non-zero! (0x%x)",
237 gsc_readl(gsc_asic->hpa + OFFSET_IMR));
238 printk("\n");
239#endif
240
241 return 0;
242}
243
244extern struct parisc_driver lasi_driver;
245extern struct parisc_driver asp_driver;
246extern struct parisc_driver wax_driver;
247
248void __init gsc_init(void)
249{
250#ifdef CONFIG_GSC_LASI
251 register_parisc_driver(&lasi_driver);
252 register_parisc_driver(&asp_driver);
253#endif
254#ifdef CONFIG_GSC_WAX
255 register_parisc_driver(&wax_driver);
256#endif
257}