GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / parisc / gsc.c
blob31391192834123a7698ff759772e013fe4caea85
1 /*
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/types.h>
24 #include <asm/hardware.h>
25 #include <asm/io.h>
27 #include "gsc.h"
29 #undef DEBUG
31 #ifdef DEBUG
32 #define DEBPRINTK printk
33 #else
34 #define DEBPRINTK(x,...)
35 #endif
37 int gsc_alloc_irq(struct gsc_irq *i)
39 int irq = txn_alloc_irq(GSC_EIM_WIDTH);
40 if (irq < 0) {
41 printk("cannot get irq\n");
42 return irq;
45 i->txn_addr = txn_alloc_addr(irq);
46 i->txn_data = txn_alloc_data(irq);
47 i->irq = irq;
49 return irq;
52 int gsc_claim_irq(struct gsc_irq *i, int irq)
54 int c = irq;
56 irq += CPU_IRQ_BASE; /* virtualize the IRQ first */
58 irq = txn_claim_irq(irq);
59 if (irq < 0) {
60 printk("cannot claim irq %d\n", c);
61 return irq;
64 i->txn_addr = txn_alloc_addr(irq);
65 i->txn_data = txn_alloc_data(irq);
66 i->irq = irq;
68 return irq;
71 EXPORT_SYMBOL(gsc_alloc_irq);
72 EXPORT_SYMBOL(gsc_claim_irq);
74 /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
75 irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
77 unsigned long irr;
78 struct gsc_asic *gsc_asic = dev;
80 irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR);
81 if (irr == 0)
82 return IRQ_NONE;
84 DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr);
86 do {
87 int local_irq = __ffs(irr);
88 unsigned int irq = gsc_asic->global_irq[local_irq];
89 __do_IRQ(irq);
90 irr &= ~(1 << local_irq);
91 } while (irr);
93 return IRQ_HANDLED;
96 int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit)
98 int local_irq;
100 for (local_irq = 0; local_irq < limit; local_irq++) {
101 if (global_irqs[local_irq] == irq)
102 return local_irq;
105 return NO_IRQ;
108 static void gsc_asic_disable_irq(unsigned int irq)
110 struct irq_desc *desc = irq_to_desc(irq);
111 struct gsc_asic *irq_dev = desc->chip_data;
112 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
113 u32 imr;
115 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
116 irq_dev->name, imr);
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);
124 static void gsc_asic_enable_irq(unsigned int irq)
126 struct irq_desc *desc = irq_to_desc(irq);
127 struct gsc_asic *irq_dev = desc->chip_data;
128 int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
129 u32 imr;
131 DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
132 irq_dev->name, imr);
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);
140 static unsigned int gsc_asic_startup_irq(unsigned int irq)
142 gsc_asic_enable_irq(irq);
143 return 0;
146 static struct irq_chip gsc_asic_interrupt_type = {
147 .name = "GSC-ASIC",
148 .startup = gsc_asic_startup_irq,
149 .shutdown = gsc_asic_disable_irq,
150 .enable = gsc_asic_enable_irq,
151 .disable = gsc_asic_disable_irq,
152 .ack = no_ack_irq,
153 .end = no_end_irq,
156 int gsc_assign_irq(struct irq_chip *type, void *data)
158 static int irq = GSC_IRQ_BASE;
159 struct irq_desc *desc;
161 if (irq > GSC_IRQ_MAX)
162 return NO_IRQ;
164 desc = irq_to_desc(irq);
165 desc->chip = type;
166 desc->chip_data = data;
167 return irq++;
170 void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
172 int irq = asic->global_irq[local_irq];
174 if (irq <= 0) {
175 irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
176 if (irq == NO_IRQ)
177 return;
179 asic->global_irq[local_irq] = irq;
181 *irqp = irq;
184 struct gsc_fixup_struct {
185 void (*choose_irq)(struct parisc_device *, void *);
186 void *ctrl;
189 static int gsc_fixup_irqs_callback(struct device *dev, void *data)
191 struct parisc_device *padev = to_parisc_device(dev);
192 struct gsc_fixup_struct *gf = data;
194 if (padev->id.hw_type == HPHW_FAULTY)
195 gsc_fixup_irqs(padev, gf->ctrl, gf->choose_irq);
196 gf->choose_irq(padev, gf->ctrl);
198 return 0;
201 void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
202 void (*choose_irq)(struct parisc_device *, void *))
204 struct gsc_fixup_struct data = {
205 .choose_irq = choose_irq,
206 .ctrl = ctrl,
209 device_for_each_child(&parent->dev, &data, gsc_fixup_irqs_callback);
212 int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
214 struct resource *res;
215 int i;
217 gsc_asic->gsc = parent;
219 /* Initialise local irq -> global irq mapping */
220 for (i = 0; i < 32; i++) {
221 gsc_asic->global_irq[i] = NO_IRQ;
224 /* allocate resource region */
225 res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
226 if (res) {
227 res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
231 return 0;
234 extern struct parisc_driver lasi_driver;
235 extern struct parisc_driver asp_driver;
236 extern struct parisc_driver wax_driver;
238 void __init gsc_init(void)
240 #ifdef CONFIG_GSC_LASI
241 register_parisc_driver(&lasi_driver);
242 register_parisc_driver(&asp_driver);
243 #endif
244 #ifdef CONFIG_GSC_WAX
245 register_parisc_driver(&wax_driver);
246 #endif