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>
13 * (C) Copyright 2003 Grant Grundler <grundler parisc-linux org>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * The initial version of this is by Martin Peterson. Alex deVries
21 * has spent a bit of time trying to coax it into working.
23 * Major changes to get basic interrupt infrastructure working to
24 * hopefully be able to support all SuperIO devices. Currently
25 * works with serial. -- John Marvin <jsm@fc.hp.com>
31 * Function 0 is an IDE controller. It is identical to a PC87415 IDE
32 * controller (and identifies itself as such).
34 * Function 1 is a "Legacy I/O" controller. Under this function is a
35 * whole mess of legacy I/O peripherals. Of course, HP hasn't enabled
36 * all the functionality in hardware, but the following is available:
38 * Two 16550A compatible serial controllers
39 * An IEEE 1284 compatible parallel port
40 * A floppy disk controller
42 * Function 2 is a USB controller.
44 * We must be incredibly careful during initialization. Since all
45 * interrupts are routed through function 1 (which is not allowed by
46 * the PCI spec), we need to program the PICs on the legacy I/O port
47 * *before* we attempt to set up IDE and USB. @#$!&
49 * According to HP, devices are only enabled by firmware if they have
50 * a physical device connected.
52 * Configuration register bits:
53 * 0x5A: FDC, SP1, IDE1, SP2, IDE2, PAR, Reserved, P92
54 * 0x5B: RTC, 8259, 8254, DMA1, DMA2, KBC, P61, APM
58 #include <linux/errno.h>
59 #include <linux/init.h>
60 #include <linux/module.h>
61 #include <linux/types.h>
62 #include <linux/interrupt.h>
63 #include <linux/ioport.h>
64 #include <linux/serial.h>
65 #include <linux/pci.h>
66 #include <linux/ioport.h>
67 #include <linux/parport.h>
68 #include <linux/parport_pc.h>
69 #include <linux/termios.h>
70 #include <linux/tty.h>
71 #include <linux/serial_core.h>
72 #include <linux/delay.h>
73 #include <linux/ide.h>
75 #include <asm/hardware.h>
77 #include <asm/superio.h>
79 #define SUPERIO_IDE_MAX_RETRIES 25
81 static struct superio_device sio_dev;
84 #undef DEBUG_SUPERIO_INIT
86 #ifdef DEBUG_SUPERIO_INIT
87 #define DBG_INIT(x...) printk(x)
89 #define DBG_INIT(x...)
93 superio_interrupt(int irq, void *devp, struct pt_regs *regs)
95 struct superio_device *sio = (struct superio_device *)devp;
99 /* Poll the 8259 to see if there's an interrupt. */
100 outb (OCW3_POLL,IC_PIC1+0);
102 results = inb(IC_PIC1+0);
104 if ((results & 0x80) == 0) {
106 /* HACK: need to investigate why this happens if SMP enabled */
107 BUG(); /* This shouldn't happen */
112 /* Check to see which device is interrupting */
114 local_irq = results & 0x0f;
116 if (local_irq == 2 || local_irq > 7) {
117 printk(KERN_ERR "SuperIO: slave interrupted!\n");
122 if (local_irq == 7) {
124 /* Could be spurious. Check in service bits */
126 outb(OCW3_ISR,IC_PIC1+0);
127 results = inb(IC_PIC1+0);
128 if ((results & 0x80) == 0) { /* if ISR7 not set: spurious */
129 printk(KERN_WARNING "SuperIO: spurious interrupt!\n");
134 /* Call the appropriate device's interrupt */
135 do_irq(&sio->irq_region->action[local_irq],
136 sio->irq_region->data.irqbase + local_irq,
141 outb((OCW2_SEOI|local_irq),IC_PIC1 + 0);
145 /* Initialize Super I/O device */
147 static void __devinit
148 superio_init(struct superio_device *sio)
150 struct pci_dev *pdev = sio->lio_pdev;
153 if (sio->suckyio_irq_enabled)
157 if (!sio->usb_pdev) BUG();
159 /* use the IRQ iosapic found for USB INT D... */
160 pdev->irq = sio->usb_pdev->irq;
162 /* ...then properly fixup the USB to point at suckyio PIC */
163 sio->usb_pdev->irq = superio_fixup_irq(sio->usb_pdev);
165 printk (KERN_INFO "SuperIO: Found NS87560 Legacy I/O device at %s (IRQ %i) \n",
166 pci_name(pdev),pdev->irq);
168 pci_read_config_dword (pdev, SIO_SP1BAR, &sio->sp1_base);
170 printk (KERN_INFO "SuperIO: Serial port 1 at 0x%x\n", sio->sp1_base);
172 pci_read_config_dword (pdev, SIO_SP2BAR, &sio->sp2_base);
174 printk (KERN_INFO "SuperIO: Serial port 2 at 0x%x\n", sio->sp2_base);
176 pci_read_config_dword (pdev, SIO_PPBAR, &sio->pp_base);
178 printk (KERN_INFO "SuperIO: Parallel port at 0x%x\n", sio->pp_base);
180 pci_read_config_dword (pdev, SIO_FDCBAR, &sio->fdc_base);
182 printk (KERN_INFO "SuperIO: Floppy controller at 0x%x\n", sio->fdc_base);
183 pci_read_config_dword (pdev, SIO_ACPIBAR, &sio->acpi_base);
184 sio->acpi_base &= ~1;
185 printk (KERN_INFO "SuperIO: ACPI at 0x%x\n", sio->acpi_base);
187 request_region (IC_PIC1, 0x1f, "pic1");
188 request_region (IC_PIC2, 0x1f, "pic2");
189 request_region (sio->acpi_base, 0x1f, "acpi");
191 /* Enable the legacy I/O function */
192 pci_read_config_word (pdev, PCI_COMMAND, &word);
193 word |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_IO;
194 pci_write_config_word (pdev, PCI_COMMAND, word);
196 pci_set_master (pdev);
197 pci_enable_device(pdev);
200 * Next project is programming the onboard interrupt controllers.
201 * PDC hasn't done this for us, since it's using polled I/O.
203 * XXX Use dword writes to avoid bugs in Elroy or Suckyio Config
204 * space access. PCI is by nature a 32-bit bus and config
205 * space can be sensitive to that.
212 TRIGGER_1 == 0x82 USB & IDE level triggered, rest to edge
214 pci_write_config_dword (pdev, 0x64, 0x82000000U);
217 TRIGGER_2 == 0x00 all edge triggered (not used)
218 CFG_IR_SER == 0x43 SerPort1 = IRQ3, SerPort2 = IRQ4
219 CFG_IR_PF == 0x65 ParPort = IRQ5, FloppyCtlr = IRQ6
220 CFG_IR_IDE == 0x07 IDE1 = IRQ7, reserved
222 pci_write_config_dword (pdev, TRIGGER_2, 0x07654300U);
226 CFG_IR_INTCD == 0x10 USB = IRQ1
230 pci_write_config_dword (pdev, CFG_IR_INTAB, 0x00001000U);
233 CFG_IR_USB == 0x00 not used. USB is connected to INTD.
234 CFG_IR_ACPI == 0x00 not used.
235 DMA Priority == 0x4c88 Power on default value. NFC.
237 pci_write_config_dword (pdev, CFG_IR_USB, 0x4c880000U);
239 /* PIC1 Initialization Command Word register programming */
240 outb (0x11,IC_PIC1+0); /* ICW1: ICW4 write req | ICW1 */
241 outb (0x00,IC_PIC1+1); /* ICW2: interrupt vector table - not used */
242 outb (0x04,IC_PIC1+1); /* ICW3: Cascade */
243 outb (0x01,IC_PIC1+1); /* ICW4: x86 mode */
245 /* PIC1 Program Operational Control Words */
246 outb (0xff,IC_PIC1+1); /* OCW1: Mask all interrupts */
247 outb (0xc2,IC_PIC1+0); /* OCW2: priority (3-7,0-2) */
249 /* PIC2 Initialization Command Word register programming */
250 outb (0x11,IC_PIC2+0); /* ICW1: ICW4 write req | ICW1 */
251 outb (0x00,IC_PIC2+1); /* ICW2: N/A */
252 outb (0x02,IC_PIC2+1); /* ICW3: Slave ID code */
253 outb (0x01,IC_PIC2+1); /* ICW4: x86 mode */
255 /* Program Operational Control Words */
256 outb (0xff,IC_PIC1+1); /* OCW1: Mask all interrupts */
257 outb (0x68,IC_PIC1+0); /* OCW3: OCW3 select | ESMM | SMM */
259 /* Write master mask reg */
260 outb (0xff,IC_PIC1+1);
262 /* Setup USB power regulation */
263 outb(1, sio->acpi_base + USB_REG_CR);
264 if (inb(sio->acpi_base + USB_REG_CR) & 1)
265 printk(KERN_INFO "SuperIO: USB regulator enabled\n");
267 printk(KERN_ERR "USB regulator not initialized!\n");
269 if (request_irq(pdev->irq, superio_interrupt, SA_INTERRUPT,
270 "SuperIO", (void *)sio)) {
272 printk(KERN_ERR "SuperIO: could not get irq\n");
277 sio->suckyio_irq_enabled = 1;
282 superio_disable_irq(void *dev, int local_irq)
286 if ((local_irq < 1) || (local_irq == 2) || (local_irq > 7)) {
287 printk(KERN_ERR "SuperIO: Illegal irq number.\n");
295 r8 |= (1 << local_irq);
300 superio_enable_irq(void *dev, int local_irq)
304 if ((local_irq < 1) || (local_irq == 2) || (local_irq > 7)) {
305 printk(KERN_ERR "SuperIO: Illegal irq number (%d).\n", local_irq);
310 /* Unmask interrupt */
312 r8 &= ~(1 << local_irq);
318 superio_mask_irq(void *dev, int local_irq)
324 superio_unmask_irq(void *dev, int local_irq)
329 static struct irq_region_ops superio_irq_ops = {
330 .disable_irq = superio_disable_irq,
331 .enable_irq = superio_enable_irq,
332 .mask_irq = superio_mask_irq,
333 .unmask_irq = superio_unmask_irq
336 #ifdef DEBUG_SUPERIO_INIT
337 static unsigned short expected_device[3] = {
338 PCI_DEVICE_ID_NS_87415,
339 PCI_DEVICE_ID_NS_87560_LIO,
340 PCI_DEVICE_ID_NS_87560_USB
344 int superio_fixup_irq(struct pci_dev *pcidev)
348 #ifdef DEBUG_SUPERIO_INIT
350 fn = PCI_FUNC(pcidev->devfn);
352 /* Verify the function number matches the expected device id. */
353 if (expected_device[fn] != pcidev->device) {
357 printk("superio_fixup_irq(%s) ven 0x%x dev 0x%x from %p\n",
359 pcidev->vendor, pcidev->device,
360 __builtin_return_address(0));
363 if (!sio_dev.irq_region) {
364 /* Allocate an irq region for SuperIO devices */
365 sio_dev.irq_region = alloc_irq_region(SUPERIO_NIRQS,
367 "SuperIO", (void *) &sio_dev);
368 if (!sio_dev.irq_region) {
369 printk(KERN_WARNING "SuperIO: alloc_irq_region failed\n");
375 * We don't allocate a SuperIO irq for the legacy IO function,
376 * since it is a "bridge". Instead, we will allocate irq's for
377 * each legacy device as they are initialized.
380 switch(pcidev->device) {
381 case PCI_DEVICE_ID_NS_87415: /* Function 0 */
384 case PCI_DEVICE_ID_NS_87560_LIO: /* Function 1 */
385 sio_dev.lio_pdev = pcidev; /* save for superio_init() */
387 case PCI_DEVICE_ID_NS_87560_USB: /* Function 2 */
388 sio_dev.usb_pdev = pcidev; /* save for superio_init() */
397 return(sio_dev.irq_region->data.irqbase + local_irq);
400 static struct uart_port serial[] = {
405 .uartclk = 115200*16,
412 .uartclk = 115200*16,
418 superio_serial_init(void)
420 #ifdef CONFIG_SERIAL_8250
422 extern void serial8250_console_init(void); /* drivers/serial/8250.c */
424 if (!sio_dev.irq_region)
425 return; /* superio not present */
428 printk(KERN_WARNING "SuperIO: Could not get memory for serial struct.\n");
432 serial[0].iobase = sio_dev.sp1_base;
433 serial[0].irq = sio_dev.irq_region->data.irqbase + SP1_IRQ;
435 retval = early_serial_setup(&serial[0]);
437 printk(KERN_WARNING "SuperIO: Register Serial #0 failed.\n");
441 serial8250_console_init();
443 serial[1].iobase = sio_dev.sp2_base;
444 serial[1].irq = sio_dev.irq_region->data.irqbase + SP2_IRQ;
445 retval = early_serial_setup(&serial[1]);
448 printk(KERN_WARNING "SuperIO: Register Serial #1 failed.\n");
449 #endif /* CONFIG_SERIAL_8250 */
453 static void __devinit
454 superio_parport_init(void)
456 #ifdef CONFIG_PARPORT_PC
457 if (!parport_pc_probe_port(sio_dev.pp_base,
459 sio_dev.irq_region->data.irqbase + PAR_IRQ,
460 PARPORT_DMA_NONE /* dma */,
461 NULL /*struct pci_dev* */) )
463 printk(KERN_WARNING "SuperIO: Probing parallel port failed.\n");
464 #endif /* CONFIG_PARPORT_PC */
468 static u8 superio_ide_inb (unsigned long port);
469 static unsigned long superio_ide_status[2];
470 static unsigned long superio_ide_select[2];
471 static unsigned long superio_ide_dma_status[2];
473 void superio_fixup_pci(struct pci_dev *pdev)
478 pci_write_config_byte(pdev, PCI_CLASS_PROG, pdev->class);
480 pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
481 printk("PCI: Enabled native mode for NS87415 (pif=0x%x)\n", prog);
484 /* Because of a defect in Super I/O, all reads of the PCI DMA status
485 * registers, IDE status register and the IDE select register need to be
488 static u8 superio_ide_inb (unsigned long port)
490 if (port == superio_ide_status[0] ||
491 port == superio_ide_status[1] ||
492 port == superio_ide_select[0] ||
493 port == superio_ide_select[1] ||
494 port == superio_ide_dma_status[0] ||
495 port == superio_ide_dma_status[1]) {
497 int retries = SUPERIO_IDE_MAX_RETRIES;
499 /* printk(" [ reading port 0x%x with retry ] ", port); */
505 } while (tmp == 0 && retries-- > 0);
513 void __init superio_ide_init_iops (struct hwif_s *hwif)
517 struct pci_dev *pdev = hwif->pci_dev;
518 u8 port = hwif->channel;
520 base = pci_resource_start(pdev, port * 2) & ~3;
521 dmabase = pci_resource_start(pdev, 4) & ~3;
523 superio_ide_status[port] = base + IDE_STATUS_OFFSET;
524 superio_ide_select[port] = base + IDE_SELECT_OFFSET;
525 superio_ide_dma_status[port] = dmabase + (!port ? 2 : 0xa);
527 /* Clear error/interrupt, enable dma */
528 tmp = superio_ide_inb(superio_ide_dma_status[port]);
529 outb(tmp | 0x66, superio_ide_dma_status[port]);
531 /* We need to override inb to workaround a SuperIO errata */
532 hwif->INB = superio_ide_inb;
535 static int __devinit superio_probe(struct pci_dev *dev, const struct pci_device_id *id)
539 ** superio_probe(00:0e.0) ven 0x100b dev 0x2 sv 0x0 sd 0x0 class 0x1018a
540 ** superio_probe(00:0e.1) ven 0x100b dev 0xe sv 0x0 sd 0x0 class 0x68000
541 ** superio_probe(00:0e.2) ven 0x100b dev 0x12 sv 0x0 sd 0x0 class 0xc0310
543 DBG_INIT("superio_probe(%s) ven 0x%x dev 0x%x sv 0x%x sd 0x%x class 0x%x\n",
545 dev->vendor, dev->device,
546 dev->subsystem_vendor, dev->subsystem_device,
549 superio_init(&sio_dev);
551 if (dev->device == PCI_DEVICE_ID_NS_87560_LIO) { /* Function 1 */
552 superio_parport_init();
553 superio_serial_init();
554 /* REVISIT XXX : superio_fdc_init() ? */
556 } else if (dev->device == PCI_DEVICE_ID_NS_87415) { /* Function 0 */
557 DBG_INIT("superio_probe: ignoring IDE 87415\n");
558 } else if (dev->device == PCI_DEVICE_ID_NS_87560_USB) { /* Function 2 */
559 DBG_INIT("superio_probe: ignoring USB OHCI controller\n");
561 DBG_INIT("superio_probe: WTF? Fire Extinguisher?\n");
564 /* Let appropriate other driver claim this device. */
568 static struct pci_device_id superio_tbl[] = {
569 { PCI_VENDOR_ID_NS, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
573 static struct pci_driver superio_driver = {
575 .id_table = superio_tbl,
576 .probe = superio_probe,
579 static int __init superio_modinit(void)
581 return pci_module_init(&superio_driver);
584 static void __exit superio_exit(void)
586 pci_unregister_driver(&superio_driver);
590 module_init(superio_modinit);
591 module_exit(superio_exit);