2 * linux/drivers/ide/pci/serverworks.c Version 0.8 25 Ebr 2003
4 * Copyright (C) 1998-2000 Michel Aubry
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
6 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
7 * Portions copyright (c) 2001 Sun Microsystems
10 * RCC/ServerWorks IDE driver for Linux
12 * OSB4: `Open South Bridge' IDE Interface (fn 1)
13 * supports UDMA mode 2 (33 MB/s)
15 * CSB5: `Champion South Bridge' IDE Interface (fn 1)
16 * all revisions support UDMA mode 4 (66 MB/s)
17 * revision A2.0 and up support UDMA mode 5 (100 MB/s)
19 * *** The CSB5 does not provide ANY register ***
20 * *** to detect 80-conductor cable presence. ***
22 * CSB6: `Champion South Bridge' IDE Interface (optional: third channel)
24 * HT1000: AKA BCM5785 - Hypertransport Southbridge for Opteron systems. IDE
25 * controller same as the CSB6. Single channel ATA100 only.
28 * Available under NDA only. Errata info very hard to get.
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/ioport.h>
36 #include <linux/pci.h>
37 #include <linux/hdreg.h>
38 #include <linux/ide.h>
39 #include <linux/init.h>
40 #include <linux/delay.h>
44 #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
45 #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
47 /* Seagate Barracuda ATA IV Family drives in UDMA mode 5
48 * can overrun their FIFOs when used with the CSB5 */
49 static const char *svwks_bad_ata100[] = {
57 static u8 svwks_revision = 0;
58 static struct pci_dev *isa_dev;
60 static int check_in_drive_lists (ide_drive_t *drive, const char **list)
63 if (!strcmp(*list++, drive->id->model))
68 static u8 svwks_udma_filter(ide_drive_t *drive)
70 struct pci_dev *dev = HWIF(drive)->pci_dev;
74 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
76 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
78 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
81 pci_read_config_dword(isa_dev, 0x64, ®);
84 * Don't enable UDMA on disk devices for the moment
86 if(drive->media == ide_disk)
88 /* Check the OSB4 DMA33 enable bit */
89 return ((reg & 0x00004000) == 0x00004000) ? 0x07 : 0;
90 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
92 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
94 pci_read_config_byte(dev, 0x5A, &btr);
97 /* If someone decides to do UDMA133 on CSB5 the same
98 issue will bite so be inclusive */
99 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
103 case 2: mask = 0x1f; break;
104 case 1: mask = 0x07; break;
105 default: mask = 0x00; break;
108 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
109 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
110 (!(PCI_FUNC(dev->devfn) & 1)))
116 static u8 svwks_csb_check (struct pci_dev *dev)
118 switch (dev->device) {
119 case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
120 case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
121 case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
122 case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
129 static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
131 static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
132 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 };
133 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
134 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
135 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
137 ide_hwif_t *hwif = HWIF(drive);
138 struct pci_dev *dev = hwif->pci_dev;
140 u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
141 u8 unit = (drive->select.b.unit & 0x01);
142 u8 csb5 = svwks_csb_check(dev);
143 u8 ultra_enable = 0, ultra_timing = 0;
144 u8 dma_timing = 0, pio_timing = 0;
147 if (xferspeed == 255) /* PIO auto-tuning */
148 speed = XFER_PIO_0 + pio;
150 speed = ide_rate_filter(drive, xferspeed);
152 /* If we are about to put a disk into UDMA mode we screwed up.
153 Our code assumes we never _ever_ do this on an OSB4 */
155 if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 &&
156 drive->media == ide_disk && speed >= XFER_UDMA_0)
159 pci_read_config_byte(dev, drive_pci[drive->dn], &pio_timing);
160 pci_read_config_byte(dev, drive_pci2[drive->dn], &dma_timing);
161 pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
162 pci_read_config_word(dev, 0x4A, &csb5_pio);
163 pci_read_config_byte(dev, 0x54, &ultra_enable);
165 /* Per Specified Design by OEM, and ASIC Architect */
166 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
167 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
168 if (!drive->init_speed) {
169 u8 dma_stat = inb(hwif->dma_status);
172 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
173 ((dma_stat & (1<<(5+unit))) == (1<<(5+unit)))) {
174 drive->current_speed = drive->init_speed = XFER_UDMA_0 + udma_modes[(ultra_timing >> (4*unit)) & ~(0xF0)];
176 } else if ((dma_timing) &&
177 ((dma_stat&(1<<(5+unit)))==(1<<(5+unit)))) {
178 u8 dmaspeed = dma_timing;
181 if ((dmaspeed & 0x20) == 0x20)
182 dmaspeed = XFER_MW_DMA_2;
183 else if ((dmaspeed & 0x21) == 0x21)
184 dmaspeed = XFER_MW_DMA_1;
185 else if ((dmaspeed & 0x77) == 0x77)
186 dmaspeed = XFER_MW_DMA_0;
189 drive->current_speed = drive->init_speed = dmaspeed;
191 } else if (pio_timing) {
192 u8 piospeed = pio_timing;
195 if ((piospeed & 0x20) == 0x20)
196 piospeed = XFER_PIO_4;
197 else if ((piospeed & 0x22) == 0x22)
198 piospeed = XFER_PIO_3;
199 else if ((piospeed & 0x34) == 0x34)
200 piospeed = XFER_PIO_2;
201 else if ((piospeed & 0x47) == 0x47)
202 piospeed = XFER_PIO_1;
203 else if ((piospeed & 0x5d) == 0x5d)
204 piospeed = XFER_PIO_0;
206 goto oem_setup_failed;
207 drive->current_speed = drive->init_speed = piospeed;
217 ultra_timing &= ~(0x0F << (4*unit));
218 ultra_enable &= ~(0x01 << drive->dn);
219 csb5_pio &= ~(0x0F << (4*drive->dn));
227 pio_timing |= pio_modes[speed - XFER_PIO_0];
228 csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn));
234 pio_timing |= pio_modes[pio];
235 csb5_pio |= (pio << (4*drive->dn));
236 dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
245 pio_timing |= pio_modes[pio];
246 csb5_pio |= (pio << (4*drive->dn));
247 dma_timing |= dma_modes[2];
248 ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
249 ultra_enable |= (0x01 << drive->dn);
254 pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
256 pci_write_config_word(dev, 0x4A, csb5_pio);
258 pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
259 pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
260 pci_write_config_byte(dev, 0x54, ultra_enable);
262 return (ide_config_drive_speed(drive, speed));
265 static void config_chipset_for_pio (ide_drive_t *drive)
267 u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
268 u16 xfer_pio = drive->id->eide_pio_modes;
269 u8 timing, speed, pio;
271 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
276 if (drive->id->eide_pio_iordy > 0)
279 drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
282 xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
283 (drive->id->eide_pio_modes & 2) ? 0x04 :
284 (drive->id->eide_pio_modes & 1) ? 0x03 :
285 (drive->id->tPIO & 2) ? 0x02 :
286 (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
288 timing = (xfer_pio >= pio) ? xfer_pio : pio;
291 case 4: speed = XFER_PIO_4;break;
292 case 3: speed = XFER_PIO_3;break;
293 case 2: speed = XFER_PIO_2;break;
294 case 1: speed = XFER_PIO_1;break;
296 speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
299 (void) svwks_tune_chipset(drive, speed);
300 drive->current_speed = speed;
303 static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
306 (void) svwks_tune_chipset(drive, 255);
308 (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
311 static int config_chipset_for_dma (ide_drive_t *drive)
313 u8 speed = ide_max_dma_mode(drive);
316 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
318 (void) svwks_tune_chipset(drive, speed);
319 return ide_dma_enable(drive);
322 static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
324 drive->init_speed = 0;
326 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
329 if (ide_use_fast_pio(drive))
330 config_chipset_for_pio(drive);
335 static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
340 /* save revision id to determine DMA capability */
341 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
343 /* force Master Latency Timer value to 64 PCICLKs */
344 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
346 /* OSB4 : South Bridge and IDE */
347 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
348 isa_dev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
349 PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
351 pci_read_config_dword(isa_dev, 0x64, ®);
352 reg &= ~0x00002000; /* disable 600ns interrupt mask */
353 if(!(reg & 0x00004000))
354 printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name);
355 reg |= 0x00004000; /* enable UDMA/33 support */
356 pci_write_config_dword(isa_dev, 0x64, reg);
360 /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
361 else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
362 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
363 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
365 /* Third Channel Test */
366 if (!(PCI_FUNC(dev->devfn) & 1)) {
367 struct pci_dev * findev = NULL;
369 findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
370 PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
372 pci_read_config_dword(findev, 0x4C, ®4c);
373 reg4c &= ~0x000007FF;
376 pci_write_config_dword(findev, 0x4C, reg4c);
379 outb_p(0x06, 0x0c00);
380 dev->irq = inb_p(0x0c01);
382 struct pci_dev * findev = NULL;
385 findev = pci_get_device(PCI_VENDOR_ID_SERVERWORKS,
386 PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
388 pci_read_config_byte(findev, 0x41, ®41);
390 pci_write_config_byte(findev, 0x41, reg41);
394 * This is a device pin issue on CSB6.
395 * Since there will be a future raid mode,
396 * early versions of the chipset require the
397 * interrupt pin to be set, and it is a compatibility
400 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
403 // pci_read_config_dword(dev, 0x40, &pioreg)
404 // pci_write_config_dword(dev, 0x40, 0x99999999);
405 // pci_read_config_dword(dev, 0x44, &dmareg);
406 // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF);
407 /* setup the UDMA Control register
409 * 1. clear bit 6 to enable DMA
410 * 2. enable DMA modes with bits 0-1
414 * 11 : udma2/udma4/udma5
416 pci_read_config_byte(dev, 0x5A, &btr);
418 if (!(PCI_FUNC(dev->devfn) & 1))
421 btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
422 pci_write_config_byte(dev, 0x5A, btr);
424 /* Setup HT1000 SouthBridge Controller - Single Channel Only */
425 else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) {
426 pci_read_config_byte(dev, 0x5A, &btr);
429 pci_write_config_byte(dev, 0x5A, btr);
435 static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
440 /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits
441 * of the subsystem device ID indicate presence of an 80-pin cable.
442 * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
443 * Bit 15 set = secondary IDE channel has 80-pin cable.
444 * Bit 14 clear = primary IDE channel does not have 80-pin cable.
445 * Bit 14 set = primary IDE channel has 80-pin cable.
447 static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
449 struct pci_dev *dev = hwif->pci_dev;
450 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
451 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
452 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
453 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE))
454 return ((1 << (hwif->channel + 14)) &
455 dev->subsystem_device) ? 1 : 0;
459 /* Sun Cobalt Alpine hardware avoids the 80-pin cable
460 * detect issue by attaching the drives directly to the board.
461 * This check follows the Dell precedent (how scary is that?!)
463 * WARNING: this only works on Alpine hardware!
465 static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
467 struct pci_dev *dev = hwif->pci_dev;
468 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
469 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
470 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
471 return ((1 << (hwif->channel + 14)) &
472 dev->subsystem_device) ? 1 : 0;
476 static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
478 struct pci_dev *dev = hwif->pci_dev;
481 if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
482 return ata66_svwks_svwks (hwif);
485 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
486 return ata66_svwks_dell (hwif);
489 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
490 return ata66_svwks_cobalt (hwif);
492 /* Per Specified Design by OEM, and ASIC Architect */
493 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
494 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2))
500 static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
505 hwif->irq = hwif->channel ? 15 : 14;
507 hwif->tuneproc = &svwks_tune_drive;
508 hwif->speedproc = &svwks_tune_chipset;
509 hwif->udma_filter = &svwks_udma_filter;
513 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
514 hwif->ultra_mask = 0x3f;
516 hwif->mwdma_mask = 0x07;
520 if (!hwif->dma_base) {
521 hwif->drives[0].autotune = 1;
522 hwif->drives[1].autotune = 1;
526 hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
527 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
528 if (!hwif->udma_four)
529 hwif->udma_four = ata66_svwks(hwif);
534 dma_stat = inb(hwif->dma_status);
535 hwif->drives[0].autodma = (dma_stat & 0x20);
536 hwif->drives[1].autodma = (dma_stat & 0x40);
537 hwif->drives[0].autotune = (!(dma_stat & 0x20));
538 hwif->drives[1].autotune = (!(dma_stat & 0x40));
541 static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
543 return ide_setup_pci_device(dev, d);
546 static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
548 if (!(PCI_FUNC(dev->devfn) & 1)) {
549 d->bootable = NEVER_BOARD;
550 if (dev->resource[0].start == 0x01f1)
551 d->bootable = ON_BOARD;
554 d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
555 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
556 (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2;
558 return ide_setup_pci_device(dev, d);
561 static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
563 .name = "SvrWks OSB4",
564 .init_setup = init_setup_svwks,
565 .init_chipset = init_chipset_svwks,
566 .init_hwif = init_hwif_svwks,
569 .bootable = ON_BOARD,
571 .name = "SvrWks CSB5",
572 .init_setup = init_setup_svwks,
573 .init_chipset = init_chipset_svwks,
574 .init_hwif = init_hwif_svwks,
577 .bootable = ON_BOARD,
579 .name = "SvrWks CSB6",
580 .init_setup = init_setup_csb6,
581 .init_chipset = init_chipset_svwks,
582 .init_hwif = init_hwif_svwks,
585 .bootable = ON_BOARD,
587 .name = "SvrWks CSB6",
588 .init_setup = init_setup_csb6,
589 .init_chipset = init_chipset_svwks,
590 .init_hwif = init_hwif_svwks,
591 .channels = 1, /* 2 */
593 .bootable = ON_BOARD,
595 .name = "SvrWks HT1000",
596 .init_setup = init_setup_svwks,
597 .init_chipset = init_chipset_svwks,
598 .init_hwif = init_hwif_svwks,
599 .channels = 1, /* 2 */
601 .bootable = ON_BOARD,
606 * svwks_init_one - called when a OSB/CSB is found
607 * @dev: the svwks device
608 * @id: the matching pci id
610 * Called when the PCI registration layer (or the IDE initialization)
611 * finds a device matching our IDE device tables.
614 static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
616 ide_pci_device_t *d = &serverworks_chipsets[id->driver_data];
618 return d->init_setup(dev, d);
621 static struct pci_device_id svwks_pci_tbl[] = {
622 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
623 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
624 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
625 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
626 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
629 MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
631 static struct pci_driver driver = {
632 .name = "Serverworks_IDE",
633 .id_table = svwks_pci_tbl,
634 .probe = svwks_init_one,
637 static int __init svwks_ide_init(void)
639 return ide_pci_register_driver(&driver);
642 module_init(svwks_ide_init);
644 MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick");
645 MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
646 MODULE_LICENSE("GPL");