ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / parisc / lasi.c
1 /*
2  *      LASI Device Driver
3  *
4  *      (c) Copyright 1999 Red Hat Software
5  *      Portions (c) Copyright 1999 The Puffin Group Inc.
6  *      Portions (c) Copyright 1999 Hewlett-Packard
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  *      by Alan Cox <alan@redhat.com> and 
14  *         Alex deVries <adevries@thepuffingroup.com> 
15  */
16
17 #include <linux/errno.h>
18 #include <linux/init.h>
19 #include <linux/irq.h>
20 #include <linux/slab.h>
21 #include <linux/module.h>
22 #include <linux/pm.h>
23 #include <linux/slab.h>
24 #include <linux/types.h>
25
26 #include <asm/io.h>
27 #include <asm/hardware.h>
28 #include <asm/led.h>
29
30 #include "gsc.h"
31
32
33 #define LASI_VER        0xC008  /* LASI Version */
34
35 #define LASI_IO_CONF    0x7FFFE /* LASI primary configuration register */
36 #define LASI_IO_CONF2   0x7FFFF /* LASI secondary configuration register */
37
38 static int lasi_choose_irq(struct parisc_device *dev)
39 {
40         int irq;
41
42         /*
43         ** "irq" bits below are numbered relative to most significant bit.
44         */
45         switch (dev->id.sversion) {
46                 case 0x74:      irq = 24; break; /* Centronics */
47                 case 0x7B:      irq = 18; break; /* Audio */
48                 case 0x81:      irq = 17; break; /* Lasi itself */
49                 case 0x82:      irq = 22; break; /* SCSI */
50                 case 0x83:      irq = 11; break; /* Floppy */
51                 case 0x84:      irq =  5; break; /* PS/2 Keyboard */
52                 case 0x87:      irq = 13; break; /* ISDN */
53                 case 0x8A:      irq = 23; break; /* LAN */
54                 case 0x8C:      irq = 26; break; /* RS232 */
55                 case 0x8D:      irq = (dev->hw_path == 13) ? 15 : 14;
56                                                 break; /* Telephone */
57                 default:        irq = -1; break; /* unknown */
58         }
59
60         return irq;
61 }
62
63 static void __init
64 lasi_init_irq(struct busdevice *this_lasi)
65 {
66         unsigned long lasi_base = this_lasi->hpa;
67
68         /* Stop LASI barking for a bit */
69         gsc_writel(0x00000000, lasi_base+OFFSET_IMR);
70
71         /* clear pending interrupts */
72         gsc_readl(lasi_base+OFFSET_IRR);
73
74         /* We're not really convinced we want to reset the onboard
75          * devices. Firmware does it for us...
76          */
77
78         /* Resets */
79         /* gsc_writel(0xFFFFFFFF, lasi_base+0x2000);*/  /* Parallel */
80         if(pdc_add_valid(lasi_base+0x4004) == PDC_OK)
81                 gsc_writel(0xFFFFFFFF, lasi_base+0x4004);       /* Audio */
82         /* gsc_writel(0xFFFFFFFF, lasi_base+0x5000);*/  /* Serial */ 
83         /* gsc_writel(0xFFFFFFFF, lasi_base+0x6000);*/  /* SCSI */
84         gsc_writel(0xFFFFFFFF, lasi_base+0x7000);       /* LAN */
85         gsc_writel(0xFFFFFFFF, lasi_base+0x8000);       /* Keyboard */
86         gsc_writel(0xFFFFFFFF, lasi_base+0xA000);       /* FDC */
87         
88         /* Ok we hit it on the head with a hammer, our Dog is now
89         ** comatose and muzzled.  Devices will now unmask LASI
90         ** interrupts as they are registered as irq's in the LASI range.
91         */
92         /* XXX: I thought it was `awks that got `it on the `ead with an
93          * `ammer.  -- willy
94          */
95 }
96
97
98 /*
99    ** lasi_led_init()
100    ** 
101    ** lasi_led_init() initializes the LED controller on the LASI.
102    **
103    ** Since Mirage and Electra machines use a different LED
104    ** address register, we need to check for these machines 
105    ** explicitly.
106  */
107
108 #ifndef CONFIG_CHASSIS_LCD_LED
109
110 #define lasi_led_init(x)        /* nothing */
111
112 #else
113
114 void __init lasi_led_init(unsigned long lasi_hpa)
115 {
116         unsigned long datareg;
117
118         switch (CPU_HVERSION) {
119         /* Gecko machines have only one single LED, which can be permanently 
120            turned on by writing a zero into the power control register. */ 
121         case 0x600:             /* Gecko (712/60) */
122         case 0x601:             /* Gecko (712/80) */
123         case 0x602:             /* Gecko (712/100) */
124         case 0x603:             /* Anole 64 (743/64) */
125         case 0x604:             /* Anole 100 (743/100) */
126         case 0x605:             /* Gecko (712/120) */
127                 datareg = lasi_hpa + 0x0000C000;
128                 gsc_writeb(0, datareg);
129                 return; /* no need to register the LED interrupt-function */  
130
131         /* Mirage and Electra machines need special offsets */
132         case 0x60A:             /* Mirage Jr (715/64) */
133         case 0x60B:             /* Mirage 100 */
134         case 0x60C:             /* Mirage 100+ */
135         case 0x60D:             /* Electra 100 */
136         case 0x60E:             /* Electra 120 */
137                 datareg = lasi_hpa - 0x00020000;
138                 break;
139
140         default:
141                 datareg = lasi_hpa + 0x0000C000;
142                 break;
143         }
144
145         register_led_driver(DISPLAY_MODEL_LASI, LED_CMD_REG_NONE, (char *)datareg);
146 }
147 #endif
148
149 /*
150  * lasi_power_off
151  *
152  * Function for lasi to turn off the power.  This is accomplished by setting a
153  * 1 to PWR_ON_L in the Power Control Register
154  * 
155  */
156
157 static unsigned long lasi_power_off_hpa;
158
159 static void lasi_power_off(void)
160 {
161         unsigned long datareg;
162
163         /* calculate addr of the Power Control Register */
164         datareg = lasi_power_off_hpa + 0x0000C000;
165
166         /* Power down the machine */
167         gsc_writel(0x02, datareg);
168 }
169
170 int __init
171 lasi_init_chip(struct parisc_device *dev)
172 {
173         struct busdevice *lasi;
174         struct gsc_irq gsc_irq;
175         int irq, ret;
176
177         lasi = kmalloc(sizeof(struct busdevice), GFP_KERNEL);
178         if (!lasi)
179                 return -ENOMEM;
180
181         lasi->name = "Lasi";
182         lasi->hpa = dev->hpa;
183
184         /* Check the 4-bit (yes, only 4) version register */
185         lasi->version = gsc_readl(lasi->hpa + LASI_VER) & 0xf;
186         printk(KERN_INFO "%s version %d at 0x%lx found.\n",
187                 lasi->name, lasi->version, lasi->hpa);
188
189         /* initialize the chassis LEDs really early */ 
190         lasi_led_init(lasi->hpa);
191
192         /* Stop LASI barking for a bit */
193         lasi_init_irq(lasi);
194
195         /* the IRQ lasi should use */
196         irq = gsc_alloc_irq(&gsc_irq);
197         if (irq < 0) {
198                 printk(KERN_ERR "%s(): cannot get GSC irq\n",
199                                 __FUNCTION__);
200                 kfree(lasi);
201                 return -EBUSY;
202         }
203
204         ret = request_irq(gsc_irq.irq, busdev_barked, 0, "lasi", lasi);
205         if (ret < 0) {
206                 kfree(lasi);
207                 return ret;
208         }
209
210         /* Save this for debugging later */
211         lasi->parent_irq = gsc_irq.irq;
212         lasi->eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
213
214         /* enable IRQ's for devices below LASI */
215         gsc_writel(lasi->eim, lasi->hpa + OFFSET_IAR);
216
217         /* Done init'ing, register this driver */
218         ret = gsc_common_irqsetup(dev, lasi);
219         if (ret) {
220                 kfree(lasi);
221                 return ret;
222         }    
223
224         fixup_child_irqs(dev, lasi->busdev_region->data.irqbase,
225                         lasi_choose_irq);
226
227         /* initialize the power off function */
228         /* FIXME: Record the LASI HPA for the power off function.  This should
229          * ensure that only the first LASI (the one controlling the power off)
230          * should set the HPA here */
231         lasi_power_off_hpa = lasi->hpa;
232         pm_power_off = lasi_power_off;
233         
234         return ret;
235 }
236
237 static struct parisc_device_id lasi_tbl[] = {
238         { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00081 },
239         { 0, }
240 };
241
242 struct parisc_driver lasi_driver = {
243         .name =         "Lasi",
244         .id_table =     lasi_tbl,
245         .probe =        lasi_init_chip,
246 };