]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/parisc/gsc.c
Merge branch 'tip/perf/urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/roste...
[net-next-2.6.git] / drivers / parisc / gsc.c
CommitLineData
1da177e4
LT
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>
1da177e4
LT
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>
1da177e4
LT
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
37int 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
52int 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
71EXPORT_SYMBOL(gsc_alloc_irq);
72EXPORT_SYMBOL(gsc_claim_irq);
73
74/* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
7d12e780 75irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
1da177e4
LT
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];
7d12e780 89 __do_IRQ(irq);
1da177e4
LT
90 irr &= ~(1 << local_irq);
91 } while (irr);
92
93 return IRQ_HANDLED;
94}
95
96int 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
108static void gsc_asic_disable_irq(unsigned int irq)
109{
08678b08
YL
110 struct irq_desc *desc = irq_to_desc(irq);
111 struct gsc_asic *irq_dev = desc->chip_data;
1da177e4
LT
112 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
113 u32 imr;
114
a8043ecb 115 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
1da177e4
LT
116 irq_dev->name, imr);
117
118 /* Disable the IRQ line by clearing the bit in the IMR */
119 imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
120 imr &= ~(1 << local_irq);
121 gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
122}
123
124static void gsc_asic_enable_irq(unsigned int irq)
125{
08678b08
YL
126 struct irq_desc *desc = irq_to_desc(irq);
127 struct gsc_asic *irq_dev = desc->chip_data;
1da177e4
LT
128 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
129 u32 imr;
130
a8043ecb 131 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
1da177e4
LT
132 irq_dev->name, imr);
133
134 /* Enable the IRQ line by setting the bit in the IMR */
135 imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
136 imr |= 1 << local_irq;
137 gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
138 /*
139 * FIXME: read IPR to make sure the IRQ isn't already pending.
140 * If so, we need to read IRR and manually call do_irq().
141 */
142}
143
144static unsigned int gsc_asic_startup_irq(unsigned int irq)
145{
146 gsc_asic_enable_irq(irq);
147 return 0;
148}
149
dfe07565 150static struct irq_chip gsc_asic_interrupt_type = {
d0608b54 151 .name = "GSC-ASIC",
1da177e4
LT
152 .startup = gsc_asic_startup_irq,
153 .shutdown = gsc_asic_disable_irq,
154 .enable = gsc_asic_enable_irq,
155 .disable = gsc_asic_disable_irq,
156 .ack = no_ack_irq,
157 .end = no_end_irq,
158};
159
dfe07565 160int gsc_assign_irq(struct irq_chip *type, void *data)
1da177e4
LT
161{
162 static int irq = GSC_IRQ_BASE;
08678b08 163 struct irq_desc *desc;
1da177e4
LT
164
165 if (irq > GSC_IRQ_MAX)
166 return NO_IRQ;
167
08678b08
YL
168 desc = irq_to_desc(irq);
169 desc->chip = type;
170 desc->chip_data = data;
1da177e4
LT
171 return irq++;
172}
173
174void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
175{
176 int irq = asic->global_irq[local_irq];
177
178 if (irq <= 0) {
179 irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
180 if (irq == NO_IRQ)
181 return;
182
183 asic->global_irq[local_irq] = irq;
184 }
185 *irqp = irq;
186}
187
bfe4f4f8
JB
188struct gsc_fixup_struct {
189 void (*choose_irq)(struct parisc_device *, void *);
190 void *ctrl;
191};
192
193static int gsc_fixup_irqs_callback(struct device *dev, void *data)
56583747 194{
bfe4f4f8
JB
195 struct parisc_device *padev = to_parisc_device(dev);
196 struct gsc_fixup_struct *gf = data;
197
198 /* work-around for 715/64 and others which have parent
199 at path [5] and children at path [5/0/x] */
200 if (padev->id.hw_type == HPHW_FAULTY)
201 gsc_fixup_irqs(padev, gf->ctrl, gf->choose_irq);
202 gf->choose_irq(padev, gf->ctrl);
203
204 return 0;
56583747
MW
205}
206
1da177e4
LT
207void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
208 void (*choose_irq)(struct parisc_device *, void *))
209{
bfe4f4f8
JB
210 struct gsc_fixup_struct data = {
211 .choose_irq = choose_irq,
212 .ctrl = ctrl,
213 };
214
215 device_for_each_child(&parent->dev, &data, gsc_fixup_irqs_callback);
1da177e4
LT
216}
217
218int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
219{
220 struct resource *res;
221 int i;
222
223 gsc_asic->gsc = parent;
224
225 /* Initialise local irq -> global irq mapping */
226 for (i = 0; i < 32; i++) {
227 gsc_asic->global_irq[i] = NO_IRQ;
228 }
229
230 /* allocate resource region */
231 res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
232 if (res) {
233 res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
234 }
235
236#if 0
237 printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
238 parent->irq, gsc_asic->eim);
239 if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
240 printk(" IMR is non-zero! (0x%x)",
241 gsc_readl(gsc_asic->hpa + OFFSET_IMR));
242 printk("\n");
243#endif
244
245 return 0;
246}
247
248extern struct parisc_driver lasi_driver;
249extern struct parisc_driver asp_driver;
250extern struct parisc_driver wax_driver;
251
252void __init gsc_init(void)
253{
254#ifdef CONFIG_GSC_LASI
255 register_parisc_driver(&lasi_driver);
256 register_parisc_driver(&asp_driver);
257#endif
258#ifdef CONFIG_GSC_WAX
259 register_parisc_driver(&wax_driver);
260#endif
261}