1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#include <linux/errno.h>
64#include <linux/init.h>
65#include <linux/module.h>
66#include <linux/types.h>
67#include <linux/interrupt.h>
68#include <linux/ioport.h>
69#include <linux/serial.h>
70#include <linux/pci.h>
71#include <linux/parport.h>
72#include <linux/parport_pc.h>
73#include <linux/termios.h>
74#include <linux/tty.h>
75#include <linux/serial_core.h>
76#include <linux/serial_8250.h>
77#include <linux/delay.h>
78
79#include <asm/io.h>
80#include <asm/hardware.h>
81#include <asm/superio.h>
82
83static struct superio_device sio_dev;
84
85
86#undef DEBUG_SUPERIO_INIT
87
88#ifdef DEBUG_SUPERIO_INIT
89#define DBG_INIT(x...) printk(x)
90#else
91#define DBG_INIT(x...)
92#endif
93
94#define SUPERIO "SuperIO"
95#define PFX SUPERIO ": "
96
97static irqreturn_t
98superio_interrupt(int parent_irq, void *devp)
99{
100 u8 results;
101 u8 local_irq;
102
103
104 outb (OCW3_POLL,IC_PIC1+0);
105
106 results = inb(IC_PIC1+0);
107
108
109
110
111
112
113 if ((results & 0x80) == 0) {
114
115
116
117
118 return IRQ_NONE;
119 }
120
121
122 local_irq = results & 0x0f;
123
124 if (local_irq == 2 || local_irq > 7) {
125 printk(KERN_ERR PFX "slave interrupted!\n");
126 return IRQ_HANDLED;
127 }
128
129 if (local_irq == 7) {
130
131
132
133 outb(OCW3_ISR,IC_PIC1+0);
134 results = inb(IC_PIC1+0);
135 if ((results & 0x80) == 0) {
136 printk(KERN_WARNING PFX "spurious interrupt!\n");
137 return IRQ_HANDLED;
138 }
139 }
140
141
142 __do_IRQ(local_irq);
143
144
145
146
147 outb((OCW2_SEOI|local_irq),IC_PIC1 + 0);
148 return IRQ_HANDLED;
149}
150
151
152static void
153superio_init(struct pci_dev *pcidev)
154{
155 struct superio_device *sio = &sio_dev;
156 struct pci_dev *pdev = sio->lio_pdev;
157 u16 word;
158 int ret;
159
160 if (sio->suckyio_irq_enabled)
161 return;
162
163 BUG_ON(!pdev);
164 BUG_ON(!sio->usb_pdev);
165
166
167 pdev->irq = sio->usb_pdev->irq;
168
169
170 sio->usb_pdev->irq = superio_fixup_irq(sio->usb_pdev);
171
172 printk(KERN_INFO PFX "Found NS87560 Legacy I/O device at %s (IRQ %i) \n",
173 pci_name(pdev), pdev->irq);
174
175 pci_read_config_dword (pdev, SIO_SP1BAR, &sio->sp1_base);
176 sio->sp1_base &= ~1;
177 printk(KERN_INFO PFX "Serial port 1 at 0x%x\n", sio->sp1_base);
178
179 pci_read_config_dword (pdev, SIO_SP2BAR, &sio->sp2_base);
180 sio->sp2_base &= ~1;
181 printk(KERN_INFO PFX "Serial port 2 at 0x%x\n", sio->sp2_base);
182
183 pci_read_config_dword (pdev, SIO_PPBAR, &sio->pp_base);
184 sio->pp_base &= ~1;
185 printk(KERN_INFO PFX "Parallel port at 0x%x\n", sio->pp_base);
186
187 pci_read_config_dword (pdev, SIO_FDCBAR, &sio->fdc_base);
188 sio->fdc_base &= ~1;
189 printk(KERN_INFO PFX "Floppy controller at 0x%x\n", sio->fdc_base);
190 pci_read_config_dword (pdev, SIO_ACPIBAR, &sio->acpi_base);
191 sio->acpi_base &= ~1;
192 printk(KERN_INFO PFX "ACPI at 0x%x\n", sio->acpi_base);
193
194 request_region (IC_PIC1, 0x1f, "pic1");
195 request_region (IC_PIC2, 0x1f, "pic2");
196 request_region (sio->acpi_base, 0x1f, "acpi");
197
198
199 pci_read_config_word (pdev, PCI_COMMAND, &word);
200 word |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_IO;
201 pci_write_config_word (pdev, PCI_COMMAND, word);
202
203 pci_set_master (pdev);
204 ret = pci_enable_device(pdev);
205 BUG_ON(ret < 0);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222 pci_write_config_dword (pdev, 0x64, 0x82000000U);
223
224
225
226
227
228
229
230 pci_write_config_dword (pdev, TRIGGER_2, 0x07654300U);
231
232
233
234
235
236
237
238 pci_write_config_dword (pdev, CFG_IR_INTAB, 0x00001000U);
239
240
241
242
243
244
245 pci_write_config_dword (pdev, CFG_IR_USB, 0x4c880000U);
246
247
248 outb (0x11,IC_PIC1+0);
249 outb (0x00,IC_PIC1+1);
250 outb (0x04,IC_PIC1+1);
251 outb (0x01,IC_PIC1+1);
252
253
254 outb (0xff,IC_PIC1+1);
255 outb (0xc2,IC_PIC1+0);
256
257
258 outb (0x11,IC_PIC2+0);
259 outb (0x00,IC_PIC2+1);
260 outb (0x02,IC_PIC2+1);
261 outb (0x01,IC_PIC2+1);
262
263
264 outb (0xff,IC_PIC1+1);
265 outb (0x68,IC_PIC1+0);
266
267
268 outb (0xff,IC_PIC1+1);
269
270
271 outb(1, sio->acpi_base + USB_REG_CR);
272 if (inb(sio->acpi_base + USB_REG_CR) & 1)
273 printk(KERN_INFO PFX "USB regulator enabled\n");
274 else
275 printk(KERN_ERR PFX "USB regulator not initialized!\n");
276
277 if (request_irq(pdev->irq, superio_interrupt, IRQF_DISABLED,
278 SUPERIO, (void *)sio)) {
279
280 printk(KERN_ERR PFX "could not get irq\n");
281 BUG();
282 return;
283 }
284
285 sio->suckyio_irq_enabled = 1;
286}
287DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87560_LIO, superio_init);
288
289static void superio_disable_irq(unsigned int irq)
290{
291 u8 r8;
292
293 if ((irq < 1) || (irq == 2) || (irq > 7)) {
294 printk(KERN_ERR PFX "Illegal irq number.\n");
295 BUG();
296 return;
297 }
298
299
300
301 r8 = inb(IC_PIC1+1);
302 r8 |= (1 << irq);
303 outb (r8,IC_PIC1+1);
304}
305
306static void superio_enable_irq(unsigned int irq)
307{
308 u8 r8;
309
310 if ((irq < 1) || (irq == 2) || (irq > 7)) {
311 printk(KERN_ERR PFX "Illegal irq number (%d).\n", irq);
312 BUG();
313 return;
314 }
315
316
317 r8 = inb(IC_PIC1+1);
318 r8 &= ~(1 << irq);
319 outb (r8,IC_PIC1+1);
320}
321
322static unsigned int superio_startup_irq(unsigned int irq)
323{
324 superio_enable_irq(irq);
325 return 0;
326}
327
328static struct hw_interrupt_type superio_interrupt_type = {
329 .typename = SUPERIO,
330 .startup = superio_startup_irq,
331 .shutdown = superio_disable_irq,
332 .enable = superio_enable_irq,
333 .disable = superio_disable_irq,
334 .ack = no_ack_irq,
335 .end = no_end_irq,
336};
337
338#ifdef DEBUG_SUPERIO_INIT
339static unsigned short expected_device[3] = {
340 PCI_DEVICE_ID_NS_87415,
341 PCI_DEVICE_ID_NS_87560_LIO,
342 PCI_DEVICE_ID_NS_87560_USB
343};
344#endif
345
346int superio_fixup_irq(struct pci_dev *pcidev)
347{
348 int local_irq, i;
349
350#ifdef DEBUG_SUPERIO_INIT
351 int fn;
352 fn = PCI_FUNC(pcidev->devfn);
353
354
355 if (expected_device[fn] != pcidev->device) {
356 BUG();
357 return -1;
358 }
359 printk("superio_fixup_irq(%s) ven 0x%x dev 0x%x from %p\n",
360 pci_name(pcidev),
361 pcidev->vendor, pcidev->device,
362 __builtin_return_address(0));
363#endif
364
365 for (i = 0; i < 16; i++) {
366 struct irq_desc *desc = irq_to_desc(i);
367
368 desc->chip = &superio_interrupt_type;
369 }
370
371
372
373
374
375
376
377 switch(pcidev->device) {
378 case PCI_DEVICE_ID_NS_87415:
379 local_irq = IDE_IRQ;
380 break;
381 case PCI_DEVICE_ID_NS_87560_LIO:
382 sio_dev.lio_pdev = pcidev;
383 return -1;
384 case PCI_DEVICE_ID_NS_87560_USB:
385 sio_dev.usb_pdev = pcidev;
386 local_irq = USB_IRQ;
387 break;
388 default:
389 local_irq = -1;
390 BUG();
391 break;
392 }
393
394 return local_irq;
395}
396
397static void __init superio_serial_init(void)
398{
399#ifdef CONFIG_SERIAL_8250
400 int retval;
401 struct uart_port serial_port;
402
403 memset(&serial_port, 0, sizeof(serial_port));
404 serial_port.iotype = UPIO_PORT;
405 serial_port.type = PORT_16550A;
406 serial_port.uartclk = 115200*16;
407 serial_port.fifosize = 16;
408
409
410 serial_port.iobase = sio_dev.sp1_base;
411 serial_port.irq = SP1_IRQ;
412 serial_port.line = 0;
413 retval = early_serial_setup(&serial_port);
414 if (retval < 0) {
415 printk(KERN_WARNING PFX "Register Serial #0 failed.\n");
416 return;
417 }
418
419
420 serial_port.iobase = sio_dev.sp2_base;
421 serial_port.irq = SP2_IRQ;
422 serial_port.line = 1;
423 retval = early_serial_setup(&serial_port);
424 if (retval < 0)
425 printk(KERN_WARNING PFX "Register Serial #1 failed.\n");
426#endif
427}
428
429
430static void __init superio_parport_init(void)
431{
432#ifdef CONFIG_PARPORT_PC
433 if (!parport_pc_probe_port(sio_dev.pp_base,
434 0 ,
435 PAR_IRQ,
436 PARPORT_DMA_NONE ,
437 NULL ),
438 0 )
439
440 printk(KERN_WARNING PFX "Probing parallel port failed.\n");
441#endif
442}
443
444
445static void superio_fixup_pci(struct pci_dev *pdev)
446{
447 u8 prog;
448
449 pdev->class |= 0x5;
450 pci_write_config_byte(pdev, PCI_CLASS_PROG, pdev->class);
451
452 pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
453 printk("PCI: Enabled native mode for NS87415 (pif=0x%x)\n", prog);
454}
455DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87415, superio_fixup_pci);
456
457
458static int __init
459superio_probe(struct pci_dev *dev, const struct pci_device_id *id)
460{
461 struct superio_device *sio = &sio_dev;
462
463
464
465
466
467
468 DBG_INIT("superio_probe(%s) ven 0x%x dev 0x%x sv 0x%x sd 0x%x class 0x%x\n",
469 pci_name(dev),
470 dev->vendor, dev->device,
471 dev->subsystem_vendor, dev->subsystem_device,
472 dev->class);
473
474 BUG_ON(!sio->suckyio_irq_enabled);
475
476 if (dev->device == PCI_DEVICE_ID_NS_87560_LIO) {
477 superio_parport_init();
478 superio_serial_init();
479
480 return 0;
481 } else if (dev->device == PCI_DEVICE_ID_NS_87415) {
482 DBG_INIT("superio_probe: ignoring IDE 87415\n");
483 } else if (dev->device == PCI_DEVICE_ID_NS_87560_USB) {
484 DBG_INIT("superio_probe: ignoring USB OHCI controller\n");
485 } else {
486 DBG_INIT("superio_probe: WTF? Fire Extinguisher?\n");
487 }
488
489
490 return -ENODEV;
491}
492
493static const struct pci_device_id superio_tbl[] = {
494 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87560_LIO) },
495 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87560_USB) },
496 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87415) },
497 { 0, }
498};
499
500static struct pci_driver superio_driver = {
501 .name = SUPERIO,
502 .id_table = superio_tbl,
503 .probe = superio_probe,
504};
505
506static int __init superio_modinit(void)
507{
508 return pci_register_driver(&superio_driver);
509}
510
511static void __exit superio_exit(void)
512{
513 pci_unregister_driver(&superio_driver);
514}
515
516module_init(superio_modinit);
517module_exit(superio_exit);
518