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/config.h>
33 #include <linux/types.h>
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/ioport.h>
37 #include <linux/pci.h>
38 #include <linux/hdreg.h>
39 #include <linux/ide.h>
40 #include <linux/init.h>
41 #include <linux/delay.h>
45 #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
46 #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
48 /* Seagate Barracuda ATA IV Family drives in UDMA mode 5
49 * can overrun their FIFOs when used with the CSB5 */
50 static const char *svwks_bad_ata100[] = {
58 static u8 svwks_revision = 0;
59 static struct pci_dev *isa_dev;
61 static int check_in_drive_lists (ide_drive_t *drive, const char **list)
64 if (!strcmp(*list++, drive->id->model))
69 static u8 svwks_ratemask (ide_drive_t *drive)
71 struct pci_dev *dev = HWIF(drive)->pci_dev;
75 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
77 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
79 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
82 pci_read_config_dword(isa_dev, 0x64, ®);
85 * Don't enable UDMA on disk devices for the moment
87 if(drive->media == ide_disk)
89 /* Check the OSB4 DMA33 enable bit */
90 return ((reg & 0x00004000) == 0x00004000) ? 1 : 0;
91 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
93 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
95 pci_read_config_byte(dev, 0x5A, &btr);
97 if (!eighty_ninty_three(drive))
98 mode = min(mode, (u8)1);
99 /* If someone decides to do UDMA133 on CSB5 the same
100 issue will bite so be inclusive */
101 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
104 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
105 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
106 (!(PCI_FUNC(dev->devfn) & 1)))
111 static u8 svwks_csb_check (struct pci_dev *dev)
113 switch (dev->device) {
114 case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
115 case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
116 case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
117 case PCI_DEVICE_ID_SERVERWORKS_HT1000IDE:
124 static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
126 static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
127 static const u8 dma_modes[] = { 0x77, 0x21, 0x20 };
128 static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
129 static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
130 static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
132 ide_hwif_t *hwif = HWIF(drive);
133 struct pci_dev *dev = hwif->pci_dev;
135 u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
136 u8 unit = (drive->select.b.unit & 0x01);
137 u8 csb5 = svwks_csb_check(dev);
138 u8 ultra_enable = 0, ultra_timing = 0;
139 u8 dma_timing = 0, pio_timing = 0;
142 if (xferspeed == 255) /* PIO auto-tuning */
143 speed = XFER_PIO_0 + pio;
145 speed = ide_rate_filter(svwks_ratemask(drive), xferspeed);
147 /* If we are about to put a disk into UDMA mode we screwed up.
148 Our code assumes we never _ever_ do this on an OSB4 */
150 if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 &&
151 drive->media == ide_disk && speed >= XFER_UDMA_0)
154 pci_read_config_byte(dev, drive_pci[drive->dn], &pio_timing);
155 pci_read_config_byte(dev, drive_pci2[drive->dn], &dma_timing);
156 pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
157 pci_read_config_word(dev, 0x4A, &csb5_pio);
158 pci_read_config_byte(dev, 0x54, &ultra_enable);
160 /* Per Specified Design by OEM, and ASIC Architect */
161 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
162 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
163 if (!drive->init_speed) {
164 u8 dma_stat = hwif->INB(hwif->dma_status);
167 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
168 ((dma_stat & (1<<(5+unit))) == (1<<(5+unit)))) {
169 drive->current_speed = drive->init_speed = XFER_UDMA_0 + udma_modes[(ultra_timing >> (4*unit)) & ~(0xF0)];
171 } else if ((dma_timing) &&
172 ((dma_stat&(1<<(5+unit)))==(1<<(5+unit)))) {
173 u8 dmaspeed = dma_timing;
176 if ((dmaspeed & 0x20) == 0x20)
177 dmaspeed = XFER_MW_DMA_2;
178 else if ((dmaspeed & 0x21) == 0x21)
179 dmaspeed = XFER_MW_DMA_1;
180 else if ((dmaspeed & 0x77) == 0x77)
181 dmaspeed = XFER_MW_DMA_0;
184 drive->current_speed = drive->init_speed = dmaspeed;
186 } else if (pio_timing) {
187 u8 piospeed = pio_timing;
190 if ((piospeed & 0x20) == 0x20)
191 piospeed = XFER_PIO_4;
192 else if ((piospeed & 0x22) == 0x22)
193 piospeed = XFER_PIO_3;
194 else if ((piospeed & 0x34) == 0x34)
195 piospeed = XFER_PIO_2;
196 else if ((piospeed & 0x47) == 0x47)
197 piospeed = XFER_PIO_1;
198 else if ((piospeed & 0x5d) == 0x5d)
199 piospeed = XFER_PIO_0;
201 goto oem_setup_failed;
202 drive->current_speed = drive->init_speed = piospeed;
212 ultra_timing &= ~(0x0F << (4*unit));
213 ultra_enable &= ~(0x01 << drive->dn);
214 csb5_pio &= ~(0x0F << (4*drive->dn));
222 pio_timing |= pio_modes[speed - XFER_PIO_0];
223 csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn));
229 pio_timing |= pio_modes[pio];
230 csb5_pio |= (pio << (4*drive->dn));
231 dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
240 pio_timing |= pio_modes[pio];
241 csb5_pio |= (pio << (4*drive->dn));
242 dma_timing |= dma_modes[2];
243 ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
244 ultra_enable |= (0x01 << drive->dn);
249 pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
251 pci_write_config_word(dev, 0x4A, csb5_pio);
253 pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
254 pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
255 pci_write_config_byte(dev, 0x54, ultra_enable);
257 return (ide_config_drive_speed(drive, speed));
260 static void config_chipset_for_pio (ide_drive_t *drive)
262 u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
263 u16 xfer_pio = drive->id->eide_pio_modes;
264 u8 timing, speed, pio;
266 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
271 if (drive->id->eide_pio_iordy > 0)
274 drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
277 xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
278 (drive->id->eide_pio_modes & 2) ? 0x04 :
279 (drive->id->eide_pio_modes & 1) ? 0x03 :
280 (drive->id->tPIO & 2) ? 0x02 :
281 (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
283 timing = (xfer_pio >= pio) ? xfer_pio : pio;
286 case 4: speed = XFER_PIO_4;break;
287 case 3: speed = XFER_PIO_3;break;
288 case 2: speed = XFER_PIO_2;break;
289 case 1: speed = XFER_PIO_1;break;
291 speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
294 (void) svwks_tune_chipset(drive, speed);
295 drive->current_speed = speed;
298 static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
301 (void) svwks_tune_chipset(drive, 255);
303 (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
306 static int config_chipset_for_dma (ide_drive_t *drive)
308 u8 speed = ide_dma_speed(drive, svwks_ratemask(drive));
311 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
313 (void) svwks_tune_chipset(drive, speed);
314 return ide_dma_enable(drive);
317 static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
319 ide_hwif_t *hwif = HWIF(drive);
320 struct hd_driveid *id = drive->id;
322 drive->init_speed = 0;
324 if ((id->capability & 1) && drive->autodma) {
326 if (ide_use_dma(drive)) {
327 if (config_chipset_for_dma(drive))
328 return hwif->ide_dma_on(drive);
333 } else if ((id->capability & 8) || (id->field_valid & 2)) {
335 config_chipset_for_pio(drive);
336 // hwif->tuneproc(drive, 5);
337 return hwif->ide_dma_off_quietly(drive);
339 /* IORDY not supported */
343 /* This can go soon */
345 static int svwks_ide_dma_end (ide_drive_t *drive)
347 return __ide_dma_end(drive);
350 static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
355 /* save revision id to determine DMA capability */
356 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
358 /* force Master Latency Timer value to 64 PCICLKs */
359 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
361 /* OSB4 : South Bridge and IDE */
362 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
363 isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
364 PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
366 pci_read_config_dword(isa_dev, 0x64, ®);
367 reg &= ~0x00002000; /* disable 600ns interrupt mask */
368 if(!(reg & 0x00004000))
369 printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name);
370 reg |= 0x00004000; /* enable UDMA/33 support */
371 pci_write_config_dword(isa_dev, 0x64, reg);
375 /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
376 else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
377 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
378 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
380 /* Third Channel Test */
381 if (!(PCI_FUNC(dev->devfn) & 1)) {
382 struct pci_dev * findev = NULL;
384 findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
385 PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
387 pci_read_config_dword(findev, 0x4C, ®4c);
388 reg4c &= ~0x000007FF;
391 pci_write_config_dword(findev, 0x4C, reg4c);
393 outb_p(0x06, 0x0c00);
394 dev->irq = inb_p(0x0c01);
396 struct pci_dev * findev = NULL;
399 findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
400 PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
402 pci_read_config_byte(findev, 0x41, ®41);
404 pci_write_config_byte(findev, 0x41, reg41);
407 * This is a device pin issue on CSB6.
408 * Since there will be a future raid mode,
409 * early versions of the chipset require the
410 * interrupt pin to be set, and it is a compatibility
413 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
416 // pci_read_config_dword(dev, 0x40, &pioreg)
417 // pci_write_config_dword(dev, 0x40, 0x99999999);
418 // pci_read_config_dword(dev, 0x44, &dmareg);
419 // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF);
420 /* setup the UDMA Control register
422 * 1. clear bit 6 to enable DMA
423 * 2. enable DMA modes with bits 0-1
427 * 11 : udma2/udma4/udma5
429 pci_read_config_byte(dev, 0x5A, &btr);
431 if (!(PCI_FUNC(dev->devfn) & 1))
434 btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
435 pci_write_config_byte(dev, 0x5A, btr);
437 /* Setup HT1000 SouthBridge Controller - Single Channel Only */
438 else if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) {
439 pci_read_config_byte(dev, 0x5A, &btr);
442 pci_write_config_byte(dev, 0x5A, btr);
448 static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
453 /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits
454 * of the subsystem device ID indicate presence of an 80-pin cable.
455 * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
456 * Bit 15 set = secondary IDE channel has 80-pin cable.
457 * Bit 14 clear = primary IDE channel does not have 80-pin cable.
458 * Bit 14 set = primary IDE channel has 80-pin cable.
460 static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
462 struct pci_dev *dev = hwif->pci_dev;
463 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
464 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
465 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
466 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE))
467 return ((1 << (hwif->channel + 14)) &
468 dev->subsystem_device) ? 1 : 0;
472 /* Sun Cobalt Alpine hardware avoids the 80-pin cable
473 * detect issue by attaching the drives directly to the board.
474 * This check follows the Dell precedent (how scary is that?!)
476 * WARNING: this only works on Alpine hardware!
478 static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
480 struct pci_dev *dev = hwif->pci_dev;
481 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
482 dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
483 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
484 return ((1 << (hwif->channel + 14)) &
485 dev->subsystem_device) ? 1 : 0;
489 static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
491 struct pci_dev *dev = hwif->pci_dev;
494 if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
495 return ata66_svwks_svwks (hwif);
498 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
499 return ata66_svwks_dell (hwif);
502 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
503 return ata66_svwks_cobalt (hwif);
505 /* Per Specified Design by OEM, and ASIC Architect */
506 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
507 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2))
513 static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
518 hwif->irq = hwif->channel ? 15 : 14;
520 hwif->tuneproc = &svwks_tune_drive;
521 hwif->speedproc = &svwks_tune_chipset;
525 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
526 hwif->ultra_mask = 0x3f;
528 hwif->mwdma_mask = 0x07;
532 if (!hwif->dma_base) {
533 hwif->drives[0].autotune = 1;
534 hwif->drives[1].autotune = 1;
538 hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
539 if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
540 hwif->ide_dma_end = &svwks_ide_dma_end;
541 else if (!(hwif->udma_four))
542 hwif->udma_four = ata66_svwks(hwif);
546 dma_stat = hwif->INB(hwif->dma_status);
547 hwif->drives[0].autodma = (dma_stat & 0x20);
548 hwif->drives[1].autodma = (dma_stat & 0x40);
549 hwif->drives[0].autotune = (!(dma_stat & 0x20));
550 hwif->drives[1].autotune = (!(dma_stat & 0x40));
554 * We allow the BM-DMA driver to only work on enabled interfaces.
556 static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
558 struct pci_dev *dev = hwif->pci_dev;
560 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
561 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
562 (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
565 ide_setup_dma(hwif, dmabase, 8);
568 static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
570 return ide_setup_pci_device(dev, d);
573 static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
575 if (!(PCI_FUNC(dev->devfn) & 1)) {
576 d->bootable = NEVER_BOARD;
577 if (dev->resource[0].start == 0x01f1)
578 d->bootable = ON_BOARD;
581 d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
582 dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
583 (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2;
585 return ide_setup_pci_device(dev, d);
588 static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
590 .name = "SvrWks OSB4",
591 .init_setup = init_setup_svwks,
592 .init_chipset = init_chipset_svwks,
593 .init_hwif = init_hwif_svwks,
596 .bootable = ON_BOARD,
598 .name = "SvrWks CSB5",
599 .init_setup = init_setup_svwks,
600 .init_chipset = init_chipset_svwks,
601 .init_hwif = init_hwif_svwks,
602 .init_dma = init_dma_svwks,
605 .bootable = ON_BOARD,
607 .name = "SvrWks CSB6",
608 .init_setup = init_setup_csb6,
609 .init_chipset = init_chipset_svwks,
610 .init_hwif = init_hwif_svwks,
611 .init_dma = init_dma_svwks,
614 .bootable = ON_BOARD,
616 .name = "SvrWks CSB6",
617 .init_setup = init_setup_csb6,
618 .init_chipset = init_chipset_svwks,
619 .init_hwif = init_hwif_svwks,
620 .init_dma = init_dma_svwks,
621 .channels = 1, /* 2 */
623 .bootable = ON_BOARD,
625 .name = "SvrWks HT1000",
626 .init_setup = init_setup_svwks,
627 .init_chipset = init_chipset_svwks,
628 .init_hwif = init_hwif_svwks,
629 .init_dma = init_dma_svwks,
630 .channels = 1, /* 2 */
632 .bootable = ON_BOARD,
637 * svwks_init_one - called when a OSB/CSB is found
638 * @dev: the svwks device
639 * @id: the matching pci id
641 * Called when the PCI registration layer (or the IDE initialization)
642 * finds a device matching our IDE device tables.
645 static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
647 ide_pci_device_t *d = &serverworks_chipsets[id->driver_data];
649 return d->init_setup(dev, d);
652 static struct pci_device_id svwks_pci_tbl[] = {
653 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0},
654 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 1},
655 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2},
656 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 3},
657 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 4},
660 MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
662 static struct pci_driver driver = {
663 .name = "Serverworks_IDE",
664 .id_table = svwks_pci_tbl,
665 .probe = svwks_init_one,
668 static int svwks_ide_init(void)
670 return ide_pci_register_driver(&driver);
673 module_init(svwks_ide_init);
675 MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick");
676 MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
677 MODULE_LICENSE("GPL");