ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / parisc / wax.c
1 /*
2  *      WAX Device Driver
3  *
4  *      (c) Copyright 2000 The Puffin Group Inc.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      by Helge Deller <deller@gmx.de>
12  */
13
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ioport.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/types.h>
22
23 #include <asm/io.h>
24 #include <asm/hardware.h>
25 #include <asm/irq.h>
26
27 #include "gsc.h"
28
29 #define WAX_GSC_IRQ     7       /* Hardcoded Interrupt for GSC */
30 #define WAX_GSC_NMI_IRQ 29
31
32 static int wax_choose_irq(struct parisc_device *dev)
33 {
34         int irq = -1;
35
36         switch (dev->id.sversion) {
37                 case 0x73:      irq = 30; break; /* HIL */
38                 case 0x8c:      irq = 25; break; /* RS232 */
39                 case 0x90:      irq = 21; break; /* WAX EISA BA */
40         }
41
42         return irq;
43 }
44
45 static void __init
46 wax_init_irq(struct busdevice *wax)
47 {
48         unsigned long base = wax->hpa;
49
50         /* Stop WAX barking for a bit */
51         gsc_writel(0x00000000, base+OFFSET_IMR);
52
53         /* clear pending interrupts */
54         (volatile u32) gsc_readl(base+OFFSET_IRR);
55
56         /* We're not really convinced we want to reset the onboard
57          * devices. Firmware does it for us...
58          */
59
60         /* Resets */
61 //      gsc_writel(0xFFFFFFFF, base+0x1000); /* HIL */
62 //      gsc_writel(0xFFFFFFFF, base+0x2000); /* RS232-B on Wax */
63         
64         /* Ok we hit it on the head with a hammer, our Dog is now
65         ** comatose and muzzled.  Devices will now unmask WAX
66         ** interrupts as they are registered as irq's in the WAX range.
67         */
68 }
69
70 int __init
71 wax_init_chip(struct parisc_device *dev)
72 {
73         struct busdevice *wax;
74         struct gsc_irq gsc_irq;
75         int irq, ret;
76
77         wax = kmalloc(sizeof(struct busdevice), GFP_KERNEL);
78         if (!wax)
79                 return -ENOMEM;
80
81         wax->name = "Wax";
82         wax->hpa = dev->hpa;
83
84         wax->version = 0;   /* gsc_readb(wax->hpa+WAX_VER); */
85         printk(KERN_INFO "%s at 0x%lx found.\n", wax->name, wax->hpa);
86
87         /* Stop wax hissing for a bit */
88         wax_init_irq(wax);
89
90         /* the IRQ wax should use */
91         irq = gsc_claim_irq(&gsc_irq, WAX_GSC_IRQ);
92         if (irq < 0) {
93                 printk(KERN_ERR "%s(): cannot get GSC irq\n",
94                                 __FUNCTION__);
95                 kfree(wax);
96                 return -EBUSY;
97         }
98
99         ret = request_irq(gsc_irq.irq, busdev_barked, 0, "wax", wax);
100         if (ret < 0) {
101                 kfree(wax);
102                 return ret;
103         }
104
105         /* Save this for debugging later */
106         wax->parent_irq = gsc_irq.irq;
107         wax->eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
108
109         /* enable IRQ's for devices below WAX */
110         gsc_writel(wax->eim, wax->hpa + OFFSET_IAR);
111
112         /* Done init'ing, register this driver */
113         ret = gsc_common_irqsetup(dev, wax);
114         if (ret) {
115                 kfree(wax);
116                 return ret;
117         }
118
119         fixup_child_irqs(dev, wax->busdev_region->data.irqbase,
120                         wax_choose_irq);
121         /* On 715-class machines, Wax EISA is a sibling of Wax, not a child. */
122         if (dev->parent->id.hw_type != HPHW_IOA) {
123                 fixup_child_irqs(dev->parent, wax->busdev_region->data.irqbase,
124                                 wax_choose_irq);
125         }
126
127         return ret;
128 }
129
130 static struct parisc_device_id wax_tbl[] = {
131         { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008e },
132         { 0, }
133 };
134
135 MODULE_DEVICE_TABLE(parisc, wax_tbl);
136
137 struct parisc_driver wax_driver = {
138         .name =         "Wax",
139         .id_table =     wax_tbl,
140         .probe =        wax_init_chip,
141 };