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/gsc.h>
27 #include <asm/hardware.h>
28 #include <asm/led.h>
29 #include <asm/pdc.h>
30 #include "busdevice.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
lasi_choose_irq(struct parisc_device * dev)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
lasi_init_irq(struct busdevice * this_lasi)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
81 if(pdc_add_valid(lasi_base+0x4004) == PDC_OK)
82 gsc_writel(0xFFFFFFFF, lasi_base+0x4004); /* Audio */
83
84 /* gsc_writel(0xFFFFFFFF, lasi_base+0x5000);*/ /* Serial */
85 /* gsc_writel(0xFFFFFFFF, lasi_base+0x6000);*/ /* SCSI */
86 gsc_writel(0xFFFFFFFF, lasi_base+0x7000); /* LAN */
87 gsc_writel(0xFFFFFFFF, lasi_base+0x8000); /* Keyboard */
88 gsc_writel(0xFFFFFFFF, lasi_base+0xA000); /* FDC */
89
90 /* Ok we hit it on the head with a hammer, our Dog is now
91 ** comatose and muzzled. Devices will now unmask LASI
92 ** interrupts as they are registered as irq's in the LASI range.
93 */
94 /* XXX: I thought it was `awks that got `it on the `ead with an
95 * `ammer. -- willy
96 */
97 }
98
99
100 /*
101 ** lasi_led_init()
102 **
103 ** lasi_led_init() initializes the LED controller on the LASI.
104 **
105 ** Since Mirage and Electra machines use a different LED
106 ** address register, we need to check for these machines
107 ** explicitly.
108 */
109
110 #ifndef CONFIG_CHASSIS_LCD_LED
111
112 #define lasi_led_init(x) /* nothing */
113
114 #else
115
lasi_led_init(unsigned long lasi_hpa)116 void __init lasi_led_init(unsigned long lasi_hpa)
117 {
118 unsigned long datareg;
119
120 switch (CPU_HVERSION) {
121 /* Gecko machines have only one single LED, which can be permanently
122 turned on by writing a zero into the power control register. */
123 case 0x600: /* Gecko (712/60) */
124 case 0x601: /* Gecko (712/80) */
125 case 0x602: /* Gecko (712/100) */
126 case 0x603: /* Anole 64 (743/64) */
127 case 0x604: /* Anole 100 (743/100) */
128 case 0x605: /* Gecko (712/120) */
129 datareg = lasi_hpa + 0x0000C000;
130 gsc_writeb(0, datareg);
131 return; /* no need to register the LED interrupt-function */
132
133 /* Mirage and Electra machines need special offsets */
134 case 0x60A: /* Mirage Jr (715/64) */
135 case 0x60B: /* Mirage 100 */
136 case 0x60C: /* Mirage 100+ */
137 case 0x60D: /* Electra 100 */
138 case 0x60E: /* Electra 120 */
139 datareg = lasi_hpa - 0x00020000;
140 break;
141
142 default:
143 datareg = lasi_hpa + 0x0000C000;
144 break;
145 } /* switch() */
146
147 register_led_driver(DISPLAY_MODEL_LASI, LED_CMD_REG_NONE, (char *)datareg);
148 }
149 #endif
150
151 /*
152 * lasi_power_off
153 *
154 * Function for lasi to turn off the power. This is accomplished by setting a
155 * 1 to PWR_ON_L in the Power Control Register
156 *
157 */
158
159 static unsigned long lasi_power_off_hpa;
160
lasi_power_off(void)161 static void lasi_power_off(void)
162 {
163 unsigned long datareg;
164
165 /* calculate addr of the Power Control Register */
166 datareg = lasi_power_off_hpa + 0x0000C000;
167
168 /* Power down the machine */
169 gsc_writel(0x02, datareg);
170 }
171
172 int __init
lasi_init_chip(struct parisc_device * dev)173 lasi_init_chip(struct parisc_device *dev)
174 {
175 struct busdevice *lasi;
176 struct gsc_irq gsc_irq;
177 int irq, ret;
178
179 lasi = kmalloc(sizeof(struct busdevice), GFP_KERNEL);
180 if (!lasi)
181 return -ENOMEM;
182
183 lasi->name = "Lasi";
184 lasi->hpa = dev->hpa;
185
186 /* Check the 4-bit (yes, only 4) version register */
187 lasi->version = gsc_readl(lasi->hpa + LASI_VER) & 0xf;
188 printk(KERN_INFO "%s version %d at 0x%lx found.\n",
189 lasi->name, lasi->version, lasi->hpa);
190
191 /* initialize the chassis LEDs really early */
192 lasi_led_init(lasi->hpa);
193
194 /* Stop LASI barking for a bit */
195 lasi_init_irq(lasi);
196
197 /* the IRQ lasi should use */
198 irq = gsc_alloc_irq(&gsc_irq);
199 if (irq < 0) {
200 printk(KERN_ERR "%s(): cannot get GSC irq\n",
201 __FUNCTION__);
202 kfree(lasi);
203 return -EBUSY;
204 }
205
206 ret = request_irq(gsc_irq.irq, busdev_barked, 0, "lasi", lasi);
207 if (ret < 0) {
208 kfree(lasi);
209 return ret;
210 }
211
212 /* Save this for debugging later */
213 lasi->parent_irq = gsc_irq.irq;
214 lasi->eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
215
216 /* enable IRQ's for devices below LASI */
217 gsc_writel(lasi->eim, lasi->hpa + OFFSET_IAR);
218
219 /* Done init'ing, register this driver */
220 ret = gsc_common_irqsetup(dev, lasi);
221 if (ret) {
222 kfree(lasi);
223 return ret;
224 }
225
226 fixup_child_irqs(dev, lasi->busdev_region->data.irqbase,
227 lasi_choose_irq);
228
229 /* initialize the power off function */
230 /* FIXME: Record the LASI HPA for the power off function. This should
231 * ensure that only the first LASI (the one controlling the power off)
232 * should set the HPA here */
233 lasi_power_off_hpa = lasi->hpa;
234 pm_power_off = lasi_power_off;
235
236 return ret;
237 }
238
239 static struct parisc_device_id lasi_tbl[] = {
240 { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00081 },
241 { 0, }
242 };
243
244 struct parisc_driver lasi_driver = {
245 name: "Lasi",
246 id_table: lasi_tbl,
247 probe: lasi_init_chip,
248 };
249