1 /* National Semiconductor NS87560UBD Super I/O controller used in
2 * HP [BCJ]x000 workstations.
4 * This chip is a horrid piece of engineering, and National
5 * denies any knowledge of its existence. Thus no datasheet is
6 * available off www.national.com.
8 * (C) Copyright 2000 Linuxcare, Inc.
9 * (C) Copyright 2000 Linuxcare Canada, Inc.
10 * (C) Copyright 2000 Martin K. Petersen <mkp@linuxcare.com>
11 * (C) Copyright 2000 Alex deVries <alex@linuxcare.com>
12 * (C) Copyright 2001 John Marvin <jsm@fc.hp.com>
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * The initial version of this is by Martin Peterson. Alex deVries
20 * has spent a bit of time trying to coax it into working.
22 * Major changes to get basic interrupt infrastructure working to
23 * hopefully be able to support all SuperIO devices. Currently
24 * works with serial. -- John Marvin <jsm@fc.hp.com>
30 * Function 0 is an IDE controller. It is identical to a PC87415 IDE
31 * controller (and identifies itself as such).
33 * Function 1 is a "Legacy I/O" controller. Under this function is a
34 * whole mess of legacy I/O peripherals. Of course, HP hasn't enabled
35 * all the functionality in hardware, but the following is available:
37 * Two 16550A compatible serial controllers
38 * An IEEE 1284 compatible parallel port
39 * A floppy disk controller
41 * Function 2 is a USB controller.
43 * We must be incredibly careful during initialization. Since all
44 * interrupts are routed through function 1 (which is not allowed by
45 * the PCI spec), we need to program the PICs on the legacy I/O port
46 * *before* we attempt to set up IDE and USB. @#$!&
48 * According to HP, devices are only enabled by firmware if they have
49 * a physical device connected.
51 * Configuration register bits:
52 * 0x5A: FDC, SP1, IDE1, SP2, IDE2, PAR, Reserved, P92
53 * 0x5B: RTC, 8259, 8254, DMA1, DMA2, KBC, P61, APM
57 #include <linux/errno.h>
58 #include <linux/init.h>
59 #include <linux/module.h>
60 #include <linux/types.h>
61 #include <linux/interrupt.h>
62 #include <linux/ioport.h>
63 #include <linux/serial.h>
64 #include <linux/pci.h>
65 #include <linux/ioport.h>
66 #include <linux/parport.h>
67 #include <linux/parport_pc.h>
68 #include <linux/serial_reg.h>
70 #include <asm/hardware.h>
72 #include <asm/superio.h>
74 static struct superio_device sio_dev
= {
82 superio_inform_irq(int irq
)
84 if (sio_dev
.iosapic_irq
!= -1) {
85 printk(KERN_ERR
"SuperIO: superio_inform_irq called twice! (more than one SuperIO?)\n");
90 sio_dev
.iosapic_irq
= irq
;
94 superio_interrupt(int irq
, void *devp
, struct pt_regs
*regs
)
96 struct superio_device
*sio
= (struct superio_device
*)devp
;
100 /* Poll the 8259 to see if there's an interrupt. */
101 outb (OCW3_POLL
,IC_PIC1
+0);
103 results
= inb(IC_PIC1
+0);
105 if ((results
& 0x80) == 0) {
107 /* HACK: need to investigate why this happens if SMP enabled */
108 BUG(); /* This shouldn't happen */
113 /* Check to see which device is interrupting */
115 local_irq
= results
& 0x0f;
117 if (local_irq
== 2 || local_irq
> 7) {
118 printk(KERN_ERR
"SuperIO: slave interrupted!\n");
123 if (local_irq
== 7) {
125 /* Could be spurious. Check in service bits */
127 outb(OCW3_ISR
,IC_PIC1
+0);
128 results
= inb(IC_PIC1
+0);
129 if ((results
& 0x80) == 0) { /* if ISR7 not set: spurious */
130 printk(KERN_WARNING
"SuperIO: spurious interrupt!\n");
135 /* Call the appropriate device's interrupt */
137 do_irq(&sio
->irq_region
->action
[local_irq
],
138 sio
->irq_region
->data
.irqbase
+ local_irq
,
143 outb((OCW2_SEOI
|local_irq
),IC_PIC1
+ 0);
147 /* Initialize Super I/O device */
149 static void __devinit
150 superio_init(struct superio_device
*sio
)
152 struct pci_dev
*pdev
= sio
->lio_pdev
;
156 if (!pdev
|| sio
->iosapic_irq
== -1) {
157 printk(KERN_ERR
"All SuperIO functions not found!\n");
162 printk (KERN_INFO
"SuperIO: Found NS87560 Legacy I/O device at %s (IRQ %i) \n",
163 pci_name(pdev
),sio
->iosapic_irq
);
165 /* Find our I/O devices */
166 pci_read_config_word (pdev
, SIO_SP1BAR
, &sio
->sp1_base
);
168 printk (KERN_INFO
"SuperIO: Serial port 1 at 0x%x\n", sio
->sp1_base
);
170 pci_read_config_word (pdev
, SIO_SP2BAR
, &sio
->sp2_base
);
172 printk (KERN_INFO
"SuperIO: Serial port 2 at 0x%x\n", sio
->sp2_base
);
174 pci_read_config_word (pdev
, SIO_PPBAR
, &sio
->pp_base
);
176 printk (KERN_INFO
"SuperIO: Parallel port at 0x%x\n", sio
->pp_base
);
178 pci_read_config_word (pdev
, SIO_FDCBAR
, &sio
->fdc_base
);
180 printk (KERN_INFO
"SuperIO: Floppy controller at 0x%x\n", sio
->fdc_base
);
181 pci_read_config_word (pdev
, SIO_ACPIBAR
, &sio
->acpi_base
);
182 sio
->acpi_base
&= ~1;
183 printk (KERN_INFO
"SuperIO: ACPI at 0x%x\n", sio
->acpi_base
);
185 request_region (IC_PIC1
, 0x1f, "pic1");
186 request_region (IC_PIC2
, 0x1f, "pic2");
187 request_region (sio
->acpi_base
, 0x1f, "acpi");
189 /* Enable the legacy I/O function */
190 pci_read_config_word (pdev
, PCI_COMMAND
, &word
);
191 word
|= PCI_COMMAND_SERR
| PCI_COMMAND_PARITY
| PCI_COMMAND_IO
;
192 pci_write_config_word (pdev
, PCI_COMMAND
, word
);
193 pci_set_master (pdev
);
195 /* Next project is programming the onboard interrupt
196 * controllers. PDC hasn't done this for us, since it's using
200 /* Set PIC interrupts to edge triggered */
201 pci_write_config_byte (pdev
, TRIGGER_1
, 0x0);
202 pci_write_config_byte (pdev
, TRIGGER_2
, 0x0);
204 /* Disable all interrupt routing */
205 for (i
= IR_LOW
; i
< IR_HIGH
; i
++)
206 pci_write_config_byte (pdev
, i
, 0x0);
208 /* PIC1 Initialization Command Word register programming */
209 outb (0x11,IC_PIC1
+0); /* ICW1: ICW4 write req | ICW1 */
210 outb (0x00,IC_PIC1
+1); /* ICW2: N/A */
211 outb (0x04,IC_PIC1
+1); /* ICW3: Cascade */
212 outb (0x01,IC_PIC1
+1); /* ICW4: x86 mode */
214 /* PIC1 Program Operational Control Words */
215 outb (0xff,IC_PIC1
+1); /* OCW1: Mask all interrupts */
216 outb (0xc2,IC_PIC1
+0); /* OCW2: priority (3-7,0-2) */
218 /* PIC2 Initialization Command Word register programming */
219 outb (0x11,IC_PIC2
+0); /* ICW1: ICW4 write req | ICW1 */
220 outb (0x00,IC_PIC2
+1); /* ICW2: N/A */
221 outb (0x02,IC_PIC2
+1); /* ICW3: Slave ID code */
222 outb (0x01,IC_PIC2
+1); /* ICW4: x86 mode */
224 /* Program Operational Control Words */
225 outb (0xff,IC_PIC1
+1); /* OCW1: Mask all interrupts */
226 outb (0x68,IC_PIC1
+0); /* OCW3: OCW3 select | ESMM | SMM */
228 /* Write master mask reg */
230 outb (0xff,IC_PIC1
+1);
232 /* Set up interrupt routing */
234 pci_write_config_byte (pdev
, IR_USB
, 0x10); /* USB on IRQ1 */
235 pci_write_config_byte (pdev
, IR_SER
, 0x43); /* SP1 on IRQ3, SP2 on IRQ4 */
236 pci_write_config_byte (pdev
, IR_PFD
, 0x65); /* PAR on IRQ5, FDC on IRQ6 */
237 pci_write_config_byte (pdev
, IR_IDE
, 0x07); /* IDE1 on IRQ7 */
239 /* Set USB and IDE to level triggered interrupts, rest to edge */
240 pci_write_config_byte (pdev
, TRIGGER_1
, 0x82); /* IRQ 1 and 7 */
242 /* Setup USB power regulation */
243 outb(1, sio
->acpi_base
+ USB_REG_CR
);
244 if (inb(sio
->acpi_base
+ USB_REG_CR
) & 1)
245 printk(KERN_INFO
"SuperIO: USB regulator enabled\n");
247 printk(KERN_ERR
"USB regulator not initialized!\n");
249 pci_enable_device(pdev
);
251 if (request_irq(sio
->iosapic_irq
,superio_interrupt
,SA_INTERRUPT
,
252 "SuperIO",(void *)sio
)) {
254 printk(KERN_ERR
"SuperIO: could not get irq\n");
259 sio
->iosapic_irq_enabled
= 1;
264 superio_disable_irq(void *dev
, int local_irq
)
268 if ((local_irq
< 1) || (local_irq
== 2) || (local_irq
> 7)) {
269 printk(KERN_ERR
"SuperIO: Illegal irq number.\n");
277 r8
|= (1 << local_irq
);
282 superio_enable_irq(void *dev
, int local_irq
)
284 struct superio_device
*sio
= (struct superio_device
*)dev
;
287 if ((local_irq
< 1) || (local_irq
== 2) || (local_irq
> 7)) {
288 printk(KERN_ERR
"SuperIO: Illegal irq number.\n");
294 * It's possible that we haven't initialized the legacy IO
295 * function yet. If not, do it now.
298 if (!sio
->iosapic_irq_enabled
)
301 /* Unmask interrupt */
304 r8
&= ~(1 << local_irq
);
309 superio_mask_irq(void *dev
, int local_irq
)
315 superio_unmask_irq(void *dev
, int local_irq
)
320 static struct irq_region_ops superio_irq_ops
= {
321 .disable_irq
= superio_disable_irq
,
322 .enable_irq
= superio_enable_irq
,
323 .mask_irq
= superio_mask_irq
,
324 .unmask_irq
= superio_unmask_irq
328 static unsigned short expected_device
[3] = {
329 PCI_DEVICE_ID_NS_87415
,
330 PCI_DEVICE_ID_NS_87560_LIO
,
331 PCI_DEVICE_ID_NS_87560_USB
335 int superio_fixup_irq(struct pci_dev
*pcidev
)
341 fn
= PCI_FUNC(pcidev
->devfn
);
343 /* Verify the function number matches the expected device id. */
344 if (expected_device
[fn
] != pcidev
->device
) {
348 printk("superio_fixup_irq(%s) ven 0x%x dev 0x%x from %p\n",
350 pcidev
->vendor
, pcidev
->device
,
351 __builtin_return_address(0));
354 if (!sio_dev
.irq_region
) {
355 /* Allocate an irq region for SuperIO devices */
356 sio_dev
.irq_region
= alloc_irq_region(SUPERIO_NIRQS
,
358 "SuperIO", (void *) &sio_dev
);
359 if (!sio_dev
.irq_region
) {
360 printk(KERN_WARNING
"SuperIO: alloc_irq_region failed\n");
366 * We don't allocate a SuperIO irq for the legacy IO function,
367 * since it is a "bridge". Instead, we will allocate irq's for
368 * each legacy device as they are initialized.
371 switch(pcidev
->device
) {
372 case PCI_DEVICE_ID_NS_87415
: /* Function 0 */
375 case PCI_DEVICE_ID_NS_87560_LIO
: /* Function 1 */
376 sio_dev
.lio_pdev
= pcidev
; /* save for later initialization */
378 case PCI_DEVICE_ID_NS_87560_USB
: /* Function 2 */
387 return(sio_dev
.irq_region
->data
.irqbase
+ local_irq
);
391 superio_serial_init(void)
393 #ifdef CONFIG_SERIAL_8250
394 struct serial_struct
*serial
;
397 if (!sio_dev
.irq_region
)
398 return; /* superio not present */
400 if (!sio_dev
.iosapic_irq_enabled
)
401 superio_init(&sio_dev
);
403 serial
= kmalloc(2 * sizeof (struct serial_struct
), GFP_KERNEL
);
406 printk(KERN_WARNING
"SuperIO: Could not get memory for serial struct.\n");
410 memset(serial
, 0, 2 * sizeof (struct serial_struct
));
412 serial
->type
= PORT_16550A
;
414 serial
->port
= sio_dev
.sp1_base
;
415 serial
->port_high
= 0;
416 serial
->irq
= sio_dev
.irq_region
->data
.irqbase
+ SP1_IRQ
;
417 serial
->io_type
= SERIAL_IO_PORT
;
419 serial
->xmit_fifo_size
= 16;
420 serial
->custom_divisor
= 0;
421 serial
->baud_base
= 115200;
423 retval
= register_serial(serial
);
425 printk(KERN_WARNING
"SuperIO: Register Serial #0 failed.\n");
432 serial
->type
= PORT_16550A
;
434 serial
->port
= sio_dev
.sp2_base
;
435 serial
->port_high
= 0;
436 serial
->irq
= sio_dev
.irq_region
->data
.irqbase
+ SP2_IRQ
;
437 serial
->io_type
= SERIAL_IO_PORT
;
439 serial
->xmit_fifo_size
= 16;
440 serial
->custom_divisor
= 0;
441 serial
->baud_base
= 115200;
443 retval
= register_serial(serial
);
445 printk(KERN_WARNING
"SuperIO: Register Serial #1 failed.\n");
446 #endif /* CONFIG_SERIAL_8250 */
449 EXPORT_SYMBOL(superio_serial_init
);
452 #ifdef CONFIG_PARPORT_PC
454 superio_parport_init(void)
456 if (!sio_dev
.irq_region
)
457 return; /* superio not present */
459 if (!sio_dev
.iosapic_irq_enabled
)
460 superio_init(&sio_dev
);
462 if (!parport_pc_probe_port(sio_dev
.pp_base
,
464 sio_dev
.irq_region
->data
.irqbase
+ PAR_IRQ
,
465 PARPORT_DMA_NONE
/* dma */,
466 NULL
/*struct pci_dev* */))
468 printk(KERN_WARNING
"SuperIO: Probing parallel port failed.\n");
471 EXPORT_SYMBOL(superio_parport_init
);
472 #endif /* CONFIG_PARPORT_PC */
476 superio_get_ide_irq(void)
478 if (sio_dev
.irq_region
)
479 return sio_dev
.irq_region
->data
.irqbase
+ IDE_IRQ
;
484 EXPORT_SYMBOL(superio_get_ide_irq
);
486 static int __devinit
superio_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
489 printk("superio_probe(%s) ven 0x%x dev 0x%x sv 0x%x sd 0x%x class 0x%x\n",
491 dev
->vendor
, dev
->device
,
492 dev
->subsystem_vendor
, dev
->subsystem_device
,
495 ** superio_probe(00:0e.0) ven 0x100b dev 0x2 sv 0x0 sd 0x0 class 0x1018a
496 ** superio_probe(00:0e.1) ven 0x100b dev 0xe sv 0x0 sd 0x0 class 0x68000
497 ** superio_probe(00:0e.2) ven 0x100b dev 0x12 sv 0x0 sd 0x0 class 0xc0310
501 /* superio_fixup_irq(dev); */
503 if (dev
->device
== PCI_DEVICE_ID_NS_87560_LIO
) {
504 #ifdef CONFIG_PARPORT_PC
505 superio_parport_init();
507 #ifdef CONFIG_SERIAL_8250
508 superio_serial_init();
510 /* REVISIT : superio_fdc_init() ? */
513 /* don't claim this device; let whatever either driver
520 static struct pci_device_id superio_tbl
[] = {
521 { PCI_VENDOR_ID_NS
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
525 static struct pci_driver superio_driver
= {
527 .id_table
= superio_tbl
,
528 .probe
= superio_probe
,
531 static int __init
superio_modinit(void)
533 return pci_module_init(&superio_driver
);
536 static void __exit
superio_exit(void)
538 pci_unregister_driver(&superio_driver
);
541 /* Make late initcall to ensure the serial and tty layers are initialised
542 * before we start superio.
544 * FIXME: does this break the superio console?
546 late_initcall(superio_modinit
);
547 module_exit(superio_exit
);