2 * Promise TX2/TX4/TX2000/133 IDE driver
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 * linux/drivers/ide/pdc202xx.c Version 0.35 Mar. 30, 2002
11 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
12 * Portions Copyright (C) 1999 Promise Technology, Inc.
13 * Author: Frank Tiernan (frankt@promise.com)
14 * Released under terms of General Public License
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/delay.h>
22 #include <linux/timer.h>
24 #include <linux/ioport.h>
25 #include <linux/blkdev.h>
26 #include <linux/hdreg.h>
27 #include <linux/interrupt.h>
28 #include <linux/pci.h>
29 #include <linux/init.h>
30 #include <linux/ide.h>
35 #ifdef CONFIG_PPC_PMAC
37 #include <asm/pci-bridge.h>
40 #include "pdc202xx_new.h"
42 #define PDC202_DEBUG_CABLE 0
44 #if defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS)
45 #include <linux/stat.h>
46 #include <linux/proc_fs.h>
48 static u8 pdcnew_proc = 0;
49 #define PDC202_MAX_DEVS 5
50 static struct pci_dev *pdc202_devs[PDC202_MAX_DEVS];
51 static int n_pdc202_devs;
53 static char * pdcnew_info(char *buf, struct pci_dev *dev)
57 p += sprintf(p, "\n ");
59 case PCI_DEVICE_ID_PROMISE_20277:
60 p += sprintf(p, "SBFastTrak 133 Lite"); break;
61 case PCI_DEVICE_ID_PROMISE_20276:
62 p += sprintf(p, "MBFastTrak 133 Lite"); break;
63 case PCI_DEVICE_ID_PROMISE_20275:
64 p += sprintf(p, "MBUltra133"); break;
65 case PCI_DEVICE_ID_PROMISE_20271:
66 p += sprintf(p, "FastTrak TX2000"); break;
67 case PCI_DEVICE_ID_PROMISE_20270:
68 p += sprintf(p, "FastTrak LP/TX2/TX4"); break;
69 case PCI_DEVICE_ID_PROMISE_20269:
70 p += sprintf(p, "Ultra133 TX2"); break;
71 case PCI_DEVICE_ID_PROMISE_20268:
72 p += sprintf(p, "Ultra100 TX2"); break;
74 p += sprintf(p, "Ultra series"); break;
77 p += sprintf(p, " Chipset.\n");
81 static int pdcnew_get_info (char *buffer, char **addr, off_t offset, int count)
86 for (i = 0; i < n_pdc202_devs; i++) {
87 struct pci_dev *dev = pdc202_devs[i];
88 p = pdcnew_info(buffer, dev);
90 /* p - buffer must be less than 4k! */
91 len = (p - buffer) - offset;
92 *addr = buffer + offset;
94 return len > count ? count : len;
96 #endif /* defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS) */
99 static u8 pdcnew_ratemask (ide_drive_t *drive)
103 switch(HWIF(drive)->pci_dev->device) {
104 case PCI_DEVICE_ID_PROMISE_20277:
105 case PCI_DEVICE_ID_PROMISE_20276:
106 case PCI_DEVICE_ID_PROMISE_20275:
107 case PCI_DEVICE_ID_PROMISE_20271:
108 case PCI_DEVICE_ID_PROMISE_20269:
111 case PCI_DEVICE_ID_PROMISE_20270:
112 case PCI_DEVICE_ID_PROMISE_20268:
118 if (!eighty_ninty_three(drive))
119 mode = min(mode, (u8)1);
123 static int check_in_drive_lists (ide_drive_t *drive, const char **list)
125 struct hd_driveid *id = drive->id;
127 if (pdc_quirk_drives == list) {
129 if (strstr(id->model, *list++)) {
135 if (!strcmp(*list++,id->model)) {
143 static int pdcnew_new_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145 ide_hwif_t *hwif = HWIF(drive);
146 unsigned long indexreg = hwif->dma_vendor1;
147 unsigned long datareg = hwif->dma_vendor3;
149 u8 adj = (drive->dn%2) ? 0x08 : 0x00;
150 u8 speed = ide_rate_filter(pdcnew_ratemask(drive), xferspeed);
152 if (speed == XFER_UDMA_2) {
153 hwif->OUTB((thold + adj), indexreg);
154 hwif->OUTB((hwif->INB(datareg) & 0x7f), datareg);
160 case XFER_UDMA_6: set_ultra(0x1a, 0x01, 0xcb); break;
161 case XFER_UDMA_5: set_ultra(0x1a, 0x02, 0xcb); break;
162 case XFER_UDMA_4: set_ultra(0x1a, 0x03, 0xcd); break;
163 case XFER_UDMA_3: set_ultra(0x1a, 0x05, 0xcd); break;
164 case XFER_UDMA_2: set_ultra(0x2a, 0x07, 0xcd); break;
165 case XFER_UDMA_1: set_ultra(0x3a, 0x0a, 0xd0); break;
166 case XFER_UDMA_0: set_ultra(0x4a, 0x0f, 0xd5); break;
167 case XFER_MW_DMA_2: set_ata2(0x69, 0x25); break;
168 case XFER_MW_DMA_1: set_ata2(0x6b, 0x27); break;
169 case XFER_MW_DMA_0: set_ata2(0xdf, 0x5f); break;
170 case XFER_PIO_4: set_pio(0x23, 0x09, 0x25); break;
171 case XFER_PIO_3: set_pio(0x27, 0x0d, 0x35); break;
172 case XFER_PIO_2: set_pio(0x23, 0x26, 0x64); break;
173 case XFER_PIO_1: set_pio(0x46, 0x29, 0xa4); break;
174 case XFER_PIO_0: set_pio(0xfb, 0x2b, 0xac); break;
179 return (ide_config_drive_speed(drive, speed));
183 * 960, 480, 390, 300, 240, 180, 120, 90, 60
184 * 180, 150, 120, 90, 60
186 * 180, 120, 90, 90, 90, 60, 30
187 * 11, 5, 4, 3, 2, 1, 0
189 static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio)
193 if (pio == 5) pio = 4;
194 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
196 (void)pdcnew_new_tune_chipset(drive, speed);
199 static u8 pdcnew_new_cable_detect (ide_hwif_t *hwif)
201 hwif->OUTB(0x0b, hwif->dma_vendor1);
202 return ((u8)((hwif->INB(hwif->dma_vendor3) & 0x04)));
204 static int config_chipset_for_dma (ide_drive_t *drive)
206 struct hd_driveid *id = drive->id;
207 ide_hwif_t *hwif = HWIF(drive);
211 u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
212 (id->dma_ultra & 0x0008)) ? 1 : 0;
214 cable = pdcnew_new_cable_detect(hwif);
216 if (ultra_66 && cable) {
217 printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary");
218 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
221 if (drive->media != ide_disk)
223 if (id->capability & 4) { /* IORDY_EN & PREFETCH_EN */
224 hwif->OUTB((0x13 + ((drive->dn%2) ? 0x08 : 0x00)), hwif->dma_vendor1);
225 hwif->OUTB((hwif->INB(hwif->dma_vendor3)|0x03), hwif->dma_vendor3);
228 speed = ide_dma_speed(drive, pdcnew_ratemask(drive));
231 hwif->tuneproc(drive, 5);
235 (void) hwif->speedproc(drive, speed);
236 return ide_dma_enable(drive);
239 static int pdcnew_config_drive_xfer_rate (ide_drive_t *drive)
241 ide_hwif_t *hwif = HWIF(drive);
242 struct hd_driveid *id = drive->id;
244 drive->init_speed = 0;
246 if (id && (id->capability & 1) && drive->autodma) {
247 /* Consult the list of known "bad" drives */
248 if (__ide_dma_bad_drive(drive))
250 if (id->field_valid & 4) {
251 if (id->dma_ultra & hwif->ultra_mask) {
252 /* Force if Capable UltraDMA */
253 int dma = config_chipset_for_dma(drive);
254 if ((id->field_valid & 2) && !dma)
257 } else if (id->field_valid & 2) {
259 if ((id->dma_mword & hwif->mwdma_mask) ||
260 (id->dma_1word & hwif->swdma_mask)) {
261 /* Force if Capable regular DMA modes */
262 if (!config_chipset_for_dma(drive))
265 } else if (__ide_dma_good_drive(drive) &&
266 (id->eide_dma_time < 150)) {
268 /* Consult the list of known "good" drives */
269 if (!config_chipset_for_dma(drive))
274 return hwif->ide_dma_on(drive);
275 } else if ((id->capability & 8) || (id->field_valid & 2)) {
278 hwif->tuneproc(drive, 5);
279 return hwif->ide_dma_off_quietly(drive);
281 /* IORDY not supported */
285 static int pdcnew_quirkproc (ide_drive_t *drive)
287 return ((int) check_in_drive_lists(drive, pdc_quirk_drives));
290 static int pdcnew_ide_dma_lostirq(ide_drive_t *drive)
292 if (HWIF(drive)->resetproc != NULL)
293 HWIF(drive)->resetproc(drive);
294 return __ide_dma_lostirq(drive);
297 static int pdcnew_ide_dma_timeout(ide_drive_t *drive)
299 if (HWIF(drive)->resetproc != NULL)
300 HWIF(drive)->resetproc(drive);
301 return __ide_dma_timeout(drive);
304 static void pdcnew_new_reset (ide_drive_t *drive)
307 * Deleted this because it is redundant from the caller.
309 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
310 HWIF(drive)->channel ? "Secondary" : "Primary");
313 static void pdcnew_reset_host (ide_hwif_t *hwif)
315 // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel));
316 unsigned long high_16 = hwif->dma_master;
317 u8 udma_speed_flag = hwif->INB(high_16|0x001f);
319 hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f));
321 hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f));
322 mdelay(2000); /* 2 seconds ?! */
324 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
325 hwif->channel ? "Secondary" : "Primary");
328 void pdcnew_reset (ide_drive_t *drive)
330 ide_hwif_t *hwif = HWIF(drive);
331 ide_hwif_t *mate = hwif->mate;
333 pdcnew_reset_host(hwif);
334 pdcnew_reset_host(mate);
337 * FIXME: Have to kick all the drives again :-/
338 * What a pain in the ACE!
342 for (hunit = 0; hunit < MAX_DRIVES; ++hunit) {
343 ide_drive_t *hdrive = &hwif->drives[hunit];
344 if (hdrive->present) {
345 if (hwif->ide_dma_check)
346 hwif->ide_dma_check(hdrive);
348 hwif->tuneproc(hdrive, 5);
354 for (munit = 0; munit < MAX_DRIVES; ++munit) {
355 ide_drive_t *mdrive = &mate->drives[munit];
356 if (mdrive->present) {
357 if (mate->ide_dma_check)
358 mate->ide_dma_check(mdrive);
360 mate->tuneproc(mdrive, 5);
365 hwif->tuneproc(drive, 5);
369 #ifdef CONFIG_PPC_PMAC
370 static void __devinit apple_kiwi_init(struct pci_dev *pdev)
372 struct device_node *np = pci_device_to_OF_node(pdev);
373 unsigned int class_rev = 0;
377 if (np == NULL || !device_is_compatible(np, "kiwi-root"))
380 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev);
383 if (class_rev >= 0x03) {
384 /* Setup chip magic config stuff (from darwin) */
385 pci_read_config_byte(pdev, 0x40, &conf);
386 pci_write_config_byte(pdev, 0x40, conf | 0x01);
388 mmio = (unsigned long)ioremap(pci_resource_start(pdev, 5),
389 pci_resource_len(pdev, 5));
391 /* Setup some PLL stuffs */
392 switch (pdev->device) {
393 case PCI_DEVICE_ID_PROMISE_20270:
394 writew(0x0d2b, mmio + 0x1202);
397 case PCI_DEVICE_ID_PROMISE_20271:
398 writew(0x0826, mmio + 0x1202);
403 iounmap((void *)mmio);
405 #endif /* CONFIG_PPC_PMAC */
407 static unsigned int __init init_chipset_pdcnew (struct pci_dev *dev, const char *name)
409 if (dev->resource[PCI_ROM_RESOURCE].start) {
410 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
411 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
412 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n",
413 name, dev->resource[PCI_ROM_RESOURCE].start);
416 #ifdef CONFIG_PPC_PMAC
417 apple_kiwi_init(dev);
420 #if defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS)
421 pdc202_devs[n_pdc202_devs++] = dev;
425 ide_pci_create_host_proc("pdcnew", pdcnew_get_info);
427 #endif /* DISPLAY_PDC202XX_TIMINGS && CONFIG_PROC_FS */
432 static void __init init_hwif_pdc202new (ide_hwif_t *hwif)
436 hwif->tuneproc = &pdcnew_tune_drive;
437 hwif->quirkproc = &pdcnew_quirkproc;
438 hwif->speedproc = &pdcnew_new_tune_chipset;
439 hwif->resetproc = &pdcnew_new_reset;
441 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
443 hwif->ultra_mask = 0x7f;
444 hwif->mwdma_mask = 0x07;
446 hwif->ide_dma_check = &pdcnew_config_drive_xfer_rate;
447 hwif->ide_dma_lostirq = &pdcnew_ide_dma_lostirq;
448 hwif->ide_dma_timeout = &pdcnew_ide_dma_timeout;
449 if (!(hwif->udma_four))
450 hwif->udma_four = (pdcnew_new_cable_detect(hwif)) ? 0 : 1;
453 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
454 #if PDC202_DEBUG_CABLE
455 printk(KERN_DEBUG "%s: %s-pin cable\n",
456 hwif->name, hwif->udma_four ? "80" : "40");
457 #endif /* PDC202_DEBUG_CABLE */
460 static void __init init_setup_pdcnew (struct pci_dev *dev, ide_pci_device_t *d)
462 ide_setup_pci_device(dev, d);
465 static void __init init_setup_pdc20270 (struct pci_dev *dev, ide_pci_device_t *d)
467 struct pci_dev *findev = NULL;
469 if ((dev->bus->self &&
470 dev->bus->self->vendor == PCI_VENDOR_ID_DEC) &&
471 (dev->bus->self->device == PCI_DEVICE_ID_DEC_21150)) {
472 if (PCI_SLOT(dev->devfn) & 2) {
476 while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
477 if ((findev->vendor == dev->vendor) &&
478 (findev->device == dev->device) &&
479 (PCI_SLOT(findev->devfn) & 2)) {
480 if (findev->irq != dev->irq) {
481 findev->irq = dev->irq;
483 ide_setup_pci_devices(dev, findev, d);
488 ide_setup_pci_device(dev, d);
491 static void __init init_setup_pdc20276 (struct pci_dev *dev, ide_pci_device_t *d)
493 if ((dev->bus->self) &&
494 (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) &&
495 ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) ||
496 (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) {
497 printk(KERN_INFO "ide: Skipping Promise PDC20276 "
498 "attached to I2O RAID controller.\n");
501 ide_setup_pci_device(dev, d);
505 * pdc202new_init_one - called when a pdc202xx is found
506 * @dev: the pdc202new device
507 * @id: the matching pci id
509 * Called when the PCI registration layer (or the IDE initialization)
510 * finds a device matching our IDE device tables.
513 static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_device_id *id)
515 ide_pci_device_t *d = &pdcnew_chipsets[id->driver_data];
517 if (dev->device != d->device)
519 d->init_setup(dev, d);
523 static struct pci_device_id pdc202new_pci_tbl[] = {
524 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20268, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
525 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20269, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
526 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20270, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
527 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20271, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
528 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20275, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
529 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20276, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
530 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20277, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6},
533 MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
535 static struct pci_driver driver = {
536 .name = "Promise IDE",
537 .id_table = pdc202new_pci_tbl,
538 .probe = pdc202new_init_one,
541 static int pdc202new_ide_init(void)
543 return ide_pci_register_driver(&driver);
546 module_init(pdc202new_ide_init);
548 MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
549 MODULE_DESCRIPTION("PCI driver module for Promise PDC20268 and higher");
550 MODULE_LICENSE("GPL");