2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002
4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
6 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
7 * compiled into the kernel if you have more than one card installed.
8 * Note that BIOS v1.29 is reported to fix the problem. Since this is
9 * safe chipset tuning, including this support is harmless
11 * Promise Ultra66 cards with BIOS v1.11 this
12 * compiled into the kernel if you have more than one card installed.
14 * Promise Ultra100 cards.
16 * The latest chipset code will support the following ::
17 * Three Ultra33 controllers and 12 drives.
18 * 8 are UDMA supported and 4 are limited to DMA mode 2 multi-word.
19 * The 8/4 ratio is a BIOS code limit by promise.
21 * UNLESS you enable "CONFIG_PDC202XX_BURST"
26 * Portions Copyright (C) 1999 Promise Technology, Inc.
27 * Author: Frank Tiernan (frankt@promise.com)
28 * Released under terms of General Public License
31 #include <linux/config.h>
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/delay.h>
36 #include <linux/timer.h>
38 #include <linux/ioport.h>
39 #include <linux/blkdev.h>
40 #include <linux/hdreg.h>
41 #include <linux/interrupt.h>
42 #include <linux/pci.h>
43 #include <linux/init.h>
44 #include <linux/ide.h>
49 #include "pdc202xx_old.h"
51 #define PDC202_DEBUG_CABLE 0
53 #if defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS)
54 #include <linux/stat.h>
55 #include <linux/proc_fs.h>
57 static u8 pdc202xx_proc = 0;
58 #define PDC202_MAX_DEVS 5
59 static struct pci_dev *pdc202_devs[PDC202_MAX_DEVS];
60 static int n_pdc202_devs;
62 static char * pdc202xx_info (char *buf, struct pci_dev *dev)
66 unsigned long bibma = pci_resource_start(dev, 4);
67 u32 reg60h = 0, reg64h = 0, reg68h = 0, reg6ch = 0;
68 u16 reg50h = 0, pmask = (1<<10), smask = (1<<11);
72 * at that point bibma+0x2 et bibma+0xa are byte registers
75 u8 c0 = inb_p((u16)bibma + 0x02);
76 u8 c1 = inb_p((u16)bibma + 0x0a);
78 u8 sc11 = inb_p((u16)bibma + 0x11);
79 u8 sc1a = inb_p((u16)bibma + 0x1a);
80 u8 sc1b = inb_p((u16)bibma + 0x1b);
81 u8 sc1c = inb_p((u16)bibma + 0x1c);
82 u8 sc1d = inb_p((u16)bibma + 0x1d);
83 u8 sc1e = inb_p((u16)bibma + 0x1e);
84 u8 sc1f = inb_p((u16)bibma + 0x1f);
86 pci_read_config_word(dev, 0x50, ®50h);
87 pci_read_config_dword(dev, 0x60, ®60h);
88 pci_read_config_dword(dev, 0x64, ®64h);
89 pci_read_config_dword(dev, 0x68, ®68h);
90 pci_read_config_dword(dev, 0x6c, ®6ch);
92 p += sprintf(p, "\n ");
94 case PCI_DEVICE_ID_PROMISE_20267:
95 p += sprintf(p, "Ultra100"); break;
96 case PCI_DEVICE_ID_PROMISE_20265:
97 p += sprintf(p, "Ultra100 on M/B"); break;
98 case PCI_DEVICE_ID_PROMISE_20263:
99 p += sprintf(p, "FastTrak 66"); break;
100 case PCI_DEVICE_ID_PROMISE_20262:
101 p += sprintf(p, "Ultra66"); break;
102 case PCI_DEVICE_ID_PROMISE_20246:
103 p += sprintf(p, "Ultra33");
107 p += sprintf(p, "Ultra Series"); break;
109 p += sprintf(p, " Chipset.\n");
111 p += sprintf(p, "------------------------------- General Status "
112 "---------------------------------\n");
113 p += sprintf(p, "Burst Mode : %sabled\n",
114 (sc1f & 0x01) ? "en" : "dis");
115 p += sprintf(p, "Host Mode : %s\n",
116 (sc1f & 0x08) ? "Tri-Stated" : "Normal");
117 p += sprintf(p, "Bus Clocking : %s\n",
118 ((sc1f & 0xC0) == 0xC0) ? "100 External" :
119 ((sc1f & 0x80) == 0x80) ? "66 External" :
120 ((sc1f & 0x40) == 0x40) ? "33 External" : "33 PCI Internal");
121 p += sprintf(p, "IO pad select : %s mA\n",
122 ((sc1c & 0x03) == 0x03) ? "10" :
123 ((sc1c & 0x02) == 0x02) ? "8" :
124 ((sc1c & 0x01) == 0x01) ? "6" :
125 ((sc1c & 0x00) == 0x00) ? "4" : "??");
126 SPLIT_BYTE(sc1e, hi, lo);
127 p += sprintf(p, "Status Polling Period : %d\n", hi);
128 p += sprintf(p, "Interrupt Check Status Polling Delay : %d\n", lo);
129 p += sprintf(p, "--------------- Primary Channel "
130 "---------------- Secondary Channel "
132 p += sprintf(p, " %s %s\n",
133 (c0&0x80)?"disabled":"enabled ",
134 (c1&0x80)?"disabled":"enabled ");
135 p += sprintf(p, "66 Clocking %s %s\n",
136 (sc11&0x02)?"enabled ":"disabled",
137 (sc11&0x08)?"enabled ":"disabled");
138 p += sprintf(p, " Mode %s Mode %s\n",
139 (sc1a & 0x01) ? "MASTER" : "PCI ",
140 (sc1b & 0x01) ? "MASTER" : "PCI ");
141 p += sprintf(p, " %s %s\n",
142 (sc1d & 0x08) ? "Error " :
143 ((sc1d & 0x05) == 0x05) ? "Not My INTR " :
144 (sc1d & 0x04) ? "Interrupting" :
145 (sc1d & 0x02) ? "FIFO Full " :
146 (sc1d & 0x01) ? "FIFO Empty " : "????????????",
147 (sc1d & 0x80) ? "Error " :
148 ((sc1d & 0x50) == 0x50) ? "Not My INTR " :
149 (sc1d & 0x40) ? "Interrupting" :
150 (sc1d & 0x20) ? "FIFO Full " :
151 (sc1d & 0x10) ? "FIFO Empty " : "????????????");
152 p += sprintf(p, "--------------- drive0 --------- drive1 "
153 "-------- drive0 ---------- drive1 ------\n");
154 p += sprintf(p, "DMA enabled: %s %s "
156 (c0&0x20)?"yes":"no ", (c0&0x40)?"yes":"no ",
157 (c1&0x20)?"yes":"no ", (c1&0x40)?"yes":"no ");
158 p += sprintf(p, "DMA Mode: %s %s "
160 pdc202xx_ultra_verbose(reg60h, (reg50h & pmask)),
161 pdc202xx_ultra_verbose(reg64h, (reg50h & pmask)),
162 pdc202xx_ultra_verbose(reg68h, (reg50h & smask)),
163 pdc202xx_ultra_verbose(reg6ch, (reg50h & smask)));
164 p += sprintf(p, "PIO Mode: %s %s "
166 pdc202xx_pio_verbose(reg60h),
167 pdc202xx_pio_verbose(reg64h),
168 pdc202xx_pio_verbose(reg68h),
169 pdc202xx_pio_verbose(reg6ch));
171 p += sprintf(p, "--------------- Can ATAPI DMA ---------------\n");
176 static int pdc202xx_get_info (char *buffer, char **addr, off_t offset, int count)
181 for (i = 0; i < n_pdc202_devs; i++) {
182 struct pci_dev *dev = pdc202_devs[i];
183 p = pdc202xx_info(buffer, dev);
185 /* p - buffer must be less than 4k! */
186 len = (p - buffer) - offset;
187 *addr = buffer + offset;
189 return len > count ? count : len;
191 #endif /* defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS) */
194 static u8 pdc202xx_ratemask (ide_drive_t *drive)
198 switch(HWIF(drive)->pci_dev->device) {
199 case PCI_DEVICE_ID_PROMISE_20267:
200 case PCI_DEVICE_ID_PROMISE_20265:
203 case PCI_DEVICE_ID_PROMISE_20263:
204 case PCI_DEVICE_ID_PROMISE_20262:
207 case PCI_DEVICE_ID_PROMISE_20246:
212 if (!eighty_ninty_three(drive))
213 mode = min(mode, (u8)1);
217 static int check_in_drive_lists (ide_drive_t *drive, const char **list)
219 struct hd_driveid *id = drive->id;
221 if (pdc_quirk_drives == list) {
223 if (strstr(id->model, *list++)) {
229 if (!strcmp(*list++,id->model)) {
237 static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
239 ide_hwif_t *hwif = HWIF(drive);
240 struct pci_dev *dev = hwif->pci_dev;
241 u8 drive_pci = 0x60 + (drive->dn << 2);
242 u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed);
246 u8 TA = 0, TB = 0, TC = 0;
248 if ((drive->media != ide_disk) && (speed < XFER_SW_DMA_0))
251 pci_read_config_dword(dev, drive_pci, &drive_conf);
252 pci_read_config_byte(dev, (drive_pci), &AP);
253 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
254 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
255 pci_read_config_byte(dev, (drive_pci)|0x03, &DP);
257 if (speed < XFER_SW_DMA_0) {
258 if ((AP & 0x0F) || (BP & 0x07)) {
259 /* clear PIO modes of lower 8421 bits of A Register */
260 pci_write_config_byte(dev, (drive_pci), AP &~0x0F);
261 pci_read_config_byte(dev, (drive_pci), &AP);
263 /* clear PIO modes of lower 421 bits of B Register */
264 pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0x07);
265 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
267 pci_read_config_byte(dev, (drive_pci), &AP);
268 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
271 if ((BP & 0xF0) && (CP & 0x0F)) {
272 /* clear DMA modes of upper 842 bits of B Register */
273 /* clear PIO forced mode upper 1 bit of B Register */
274 pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0xF0);
275 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
277 /* clear DMA modes of lower 8421 bits of C Register */
278 pci_write_config_byte(dev, (drive_pci)|0x02, CP &~0x0F);
279 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
283 pci_read_config_byte(dev, (drive_pci), &AP);
284 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
285 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
288 case XFER_UDMA_6: speed = XFER_UDMA_5;
290 case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
291 case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
293 case XFER_UDMA_1: TB = 0x40; TC = 0x02; break;
295 case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
296 case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
298 case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break;
299 case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break;
300 case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break;
301 case XFER_PIO_4: TA = 0x01; TB = 0x04; break;
302 case XFER_PIO_3: TA = 0x02; TB = 0x06; break;
303 case XFER_PIO_2: TA = 0x03; TB = 0x08; break;
304 case XFER_PIO_1: TA = 0x05; TB = 0x0C; break;
306 default: TA = 0x09; TB = 0x13; break;
309 if (speed < XFER_SW_DMA_0) {
310 pci_write_config_byte(dev, (drive_pci), AP|TA);
311 pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
313 pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB);
314 pci_write_config_byte(dev, (drive_pci)|0x02, CP|TC);
317 #if PDC202XX_DECODE_REGISTER_INFO
318 pci_read_config_byte(dev, (drive_pci), &AP);
319 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
320 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
321 pci_read_config_byte(dev, (drive_pci)|0x03, &DP);
323 decode_registers(REG_A, AP);
324 decode_registers(REG_B, BP);
325 decode_registers(REG_C, CP);
326 decode_registers(REG_D, DP);
327 #endif /* PDC202XX_DECODE_REGISTER_INFO */
328 #if PDC202XX_DEBUG_DRIVE_INFO
329 printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
330 drive->name, ide_xfer_verbose(speed),
331 drive->dn, drive_conf);
332 pci_read_config_dword(dev, drive_pci, &drive_conf);
333 printk("0x%08x\n", drive_conf);
334 #endif /* PDC202XX_DEBUG_DRIVE_INFO */
336 return (ide_config_drive_speed(drive, speed));
341 * 960, 480, 390, 300, 240, 180, 120, 90, 60
342 * 180, 150, 120, 90, 60
344 * 180, 120, 90, 90, 90, 60, 30
345 * 11, 5, 4, 3, 2, 1, 0
347 static void config_chipset_for_pio (ide_drive_t *drive, u8 pio)
351 if (pio == 5) pio = 4;
352 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
354 pdc202xx_tune_chipset(drive, speed);
357 static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
359 u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10);
360 pci_read_config_word(hwif->pci_dev, 0x50, &CIS);
361 return ((u8)(CIS & mask));
365 * Set the control register to use the 66MHz system
366 * clock for UDMA 3/4/5 mode operation when necessary.
368 * It may also be possible to leave the 66MHz clock on
369 * and readjust the timing parameters.
371 static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
373 unsigned long clock_reg = hwif->dma_master + 0x11;
374 u8 clock = hwif->INB(clock_reg);
376 hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
379 static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
381 unsigned long clock_reg = hwif->dma_master + 0x11;
382 u8 clock = hwif->INB(clock_reg);
384 hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
387 static int config_chipset_for_dma (ide_drive_t *drive)
389 struct hd_driveid *id = drive->id;
390 ide_hwif_t *hwif = HWIF(drive);
391 struct pci_dev *dev = hwif->pci_dev;
393 u8 drive_pci = 0x60 + (drive->dn << 2);
394 u8 test1 = 0, test2 = 0, speed = -1;
395 u8 AP = 0, cable = 0;
397 u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
398 (id->dma_ultra & 0x0008)) ? 1 : 0;
400 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
401 cable = pdc202xx_old_cable_detect(hwif);
405 if (ultra_66 && cable) {
406 printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary");
407 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
410 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
411 pdc_old_disable_66MHz_clock(drive->hwif);
413 drive_pci = 0x60 + (drive->dn << 2);
414 pci_read_config_dword(dev, drive_pci, &drive_conf);
415 if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))
418 pci_read_config_byte(dev, drive_pci, &test1);
419 if (!(test1 & SYNC_ERRDY_EN)) {
420 if (drive->select.b.unit & 0x01) {
421 pci_read_config_byte(dev, drive_pci - 4, &test2);
422 if ((test2 & SYNC_ERRDY_EN) &&
423 !(test1 & SYNC_ERRDY_EN)) {
424 pci_write_config_byte(dev, drive_pci,
425 test1|SYNC_ERRDY_EN);
428 pci_write_config_byte(dev, drive_pci,
429 test1|SYNC_ERRDY_EN);
435 if (drive->media == ide_disk) {
436 pci_read_config_byte(dev, (drive_pci), &AP);
437 if (id->capability & 4) /* IORDY_EN */
438 pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);
439 pci_read_config_byte(dev, (drive_pci), &AP);
440 if (drive->media == ide_disk) /* PREFETCH_EN */
441 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
444 speed = ide_dma_speed(drive, pdc202xx_ratemask(drive));
447 /* restore original pci-config space */
448 pci_write_config_dword(dev, drive_pci, drive_conf);
449 hwif->tuneproc(drive, 5);
453 (void) hwif->speedproc(drive, speed);
454 return ide_dma_enable(drive);
457 static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
459 ide_hwif_t *hwif = HWIF(drive);
460 struct hd_driveid *id = drive->id;
462 drive->init_speed = 0;
464 if (id && (id->capability & 1) && drive->autodma) {
465 /* Consult the list of known "bad" drives */
466 if (__ide_dma_bad_drive(drive))
468 if (id->field_valid & 4) {
469 if (id->dma_ultra & hwif->ultra_mask) {
470 /* Force if Capable UltraDMA */
471 int dma = config_chipset_for_dma(drive);
472 if ((id->field_valid & 2) && !dma)
475 } else if (id->field_valid & 2) {
477 if ((id->dma_mword & hwif->mwdma_mask) ||
478 (id->dma_1word & hwif->swdma_mask)) {
479 /* Force if Capable regular DMA modes */
480 if (!config_chipset_for_dma(drive))
483 } else if (__ide_dma_good_drive(drive) &&
484 (id->eide_dma_time < 150)) {
486 /* Consult the list of known "good" drives */
487 if (!config_chipset_for_dma(drive))
492 return hwif->ide_dma_on(drive);
493 } else if ((id->capability & 8) || (id->field_valid & 2)) {
496 hwif->tuneproc(drive, 5);
497 return hwif->ide_dma_off_quietly(drive);
499 /* IORDY not supported */
503 static int pdc202xx_quirkproc (ide_drive_t *drive)
505 return ((int) check_in_drive_lists(drive, pdc_quirk_drives));
508 static int pdc202xx_old_ide_dma_begin(ide_drive_t *drive)
510 if (drive->current_speed > XFER_UDMA_2)
511 pdc_old_enable_66MHz_clock(drive->hwif);
512 if (drive->addressing == 1) {
513 struct request *rq = HWGROUP(drive)->rq;
514 ide_hwif_t *hwif = HWIF(drive);
515 // struct pci_dev *dev = hwif->pci_dev;
516 // unsgned long high_16 = pci_resource_start(dev, 4);
517 unsigned long high_16 = hwif->dma_master;
518 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
520 u8 clock = hwif->INB(high_16 + 0x11);
522 hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11);
523 word_count = (rq->nr_sectors << 8);
524 word_count = (rq_data_dir(rq) == READ) ?
525 word_count | 0x05000000 :
526 word_count | 0x06000000;
527 hwif->OUTL(word_count, atapi_reg);
529 return __ide_dma_begin(drive);
532 static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
534 if (drive->addressing == 1) {
535 ide_hwif_t *hwif = HWIF(drive);
536 // unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4);
537 unsigned long high_16 = hwif->dma_master;
538 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
541 hwif->OUTL(0, atapi_reg); /* zero out extra */
542 clock = hwif->INB(high_16 + 0x11);
543 hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11);
545 if (drive->current_speed > XFER_UDMA_2)
546 pdc_old_disable_66MHz_clock(drive->hwif);
547 return __ide_dma_end(drive);
550 static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
552 ide_hwif_t *hwif = HWIF(drive);
553 // struct pci_dev *dev = hwif->pci_dev;
554 // unsigned long high_16 = pci_resource_start(dev, 4);
555 unsigned long high_16 = hwif->dma_master;
556 u8 dma_stat = hwif->INB(hwif->dma_status);
557 u8 sc1d = hwif->INB((high_16 + 0x001d));
560 if ((sc1d & 0x50) == 0x50)
562 else if ((sc1d & 0x40) == 0x40)
563 return (dma_stat & 4) == 4;
565 if ((sc1d & 0x05) == 0x05)
567 else if ((sc1d & 0x04) == 0x04)
568 return (dma_stat & 4) == 4;
571 return (dma_stat & 4) == 4; /* return 1 if INTR asserted */
574 static int pdc202xx_ide_dma_lostirq(ide_drive_t *drive)
576 if (HWIF(drive)->resetproc != NULL)
577 HWIF(drive)->resetproc(drive);
578 return __ide_dma_lostirq(drive);
581 static int pdc202xx_ide_dma_timeout(ide_drive_t *drive)
583 if (HWIF(drive)->resetproc != NULL)
584 HWIF(drive)->resetproc(drive);
585 return __ide_dma_timeout(drive);
588 static void pdc202xx_reset_host (ide_hwif_t *hwif)
590 #ifdef CONFIG_BLK_DEV_IDEDMA
591 // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel));
592 unsigned long high_16 = hwif->dma_master;
593 #else /* !CONFIG_BLK_DEV_IDEDMA */
594 unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4);
595 #endif /* CONFIG_BLK_DEV_IDEDMA */
596 u8 udma_speed_flag = hwif->INB(high_16|0x001f);
598 hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f));
600 hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f));
601 mdelay(2000); /* 2 seconds ?! */
603 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
604 hwif->channel ? "Secondary" : "Primary");
607 void pdc202xx_reset (ide_drive_t *drive)
609 ide_hwif_t *hwif = HWIF(drive);
610 ide_hwif_t *mate = hwif->mate;
612 pdc202xx_reset_host(hwif);
613 pdc202xx_reset_host(mate);
616 * FIXME: Have to kick all the drives again :-/
617 * What a pain in the ACE!
621 for (hunit = 0; hunit < MAX_DRIVES; ++hunit) {
622 ide_drive_t *hdrive = &hwif->drives[hunit];
623 if (hdrive->present) {
624 if (hwif->ide_dma_check)
625 hwif->ide_dma_check(hdrive);
627 hwif->tuneproc(hdrive, 5);
633 for (munit = 0; munit < MAX_DRIVES; ++munit) {
634 ide_drive_t *mdrive = &mate->drives[munit];
635 if (mdrive->present) {
636 if (mate->ide_dma_check)
637 mate->ide_dma_check(mdrive);
639 mate->tuneproc(mdrive, 5);
644 hwif->tuneproc(drive, 5);
649 * Since SUN Cobalt is attempting to do this operation, I should disclose
650 * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date
651 * HOTSWAP ATA Infrastructure.
653 static int pdc202xx_tristate (ide_drive_t * drive, int state)
655 ide_hwif_t *hwif = HWIF(drive);
656 // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel));
657 unsigned long high_16 = hwif->dma_master;
658 u8 sc1f = hwif->INB(high_16|0x001f);
663 // hwif->bus_state = state;
666 hwif->OUTB(sc1f | 0x08, (high_16|0x001f));
668 hwif->OUTB(sc1f & ~0x08, (high_16|0x001f));
673 static unsigned int __init init_chipset_pdc202xx (struct pci_dev *dev, const char *name)
675 if (dev->resource[PCI_ROM_RESOURCE].start) {
676 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
677 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
678 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n",
679 name, dev->resource[PCI_ROM_RESOURCE].start);
682 #if defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS)
683 pdc202_devs[n_pdc202_devs++] = dev;
685 if (!pdc202xx_proc) {
687 ide_pci_create_host_proc("pdc202xx", pdc202xx_get_info);
689 #endif /* DISPLAY_PDC202XX_TIMINGS && CONFIG_PROC_FS */
692 * software reset - this is required because the bios
693 * will set UDMA timing on if the hdd supports it. The
694 * user may want to turn udma off. A bug in the pdc20262
695 * is that it cannot handle a downgrade in timing from
696 * UDMA to DMA. Disk accesses after issuing a set
697 * feature command will result in errors. A software
698 * reset leaves the timing registers intact,
699 * but resets the drives.
702 if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) ||
703 (dev->device == PCI_DEVICE_ID_PROMISE_20265) ||
704 (dev->device == PCI_DEVICE_ID_PROMISE_20263) ||
705 (dev->device == PCI_DEVICE_ID_PROMISE_20262)) {
706 unsigned long high_16 = pci_resource_start(dev, 4);
707 byte udma_speed_flag = inb(high_16 + 0x001f);
708 outb(udma_speed_flag | 0x10, high_16 + 0x001f);
710 outb(udma_speed_flag & ~0x10, high_16 + 0x001f);
711 mdelay(2000); /* 2 seconds ?! */
718 static void __init init_hwif_pdc202xx (ide_hwif_t *hwif)
721 hwif->tuneproc = &config_chipset_for_pio;
722 hwif->quirkproc = &pdc202xx_quirkproc;
724 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
725 hwif->busproc = &pdc202xx_tristate;
726 hwif->resetproc = &pdc202xx_reset;
729 hwif->speedproc = &pdc202xx_tune_chipset;
731 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
733 hwif->ultra_mask = 0x3f;
734 hwif->mwdma_mask = 0x07;
735 hwif->swdma_mask = 0x07;
737 hwif->ide_dma_check = &pdc202xx_config_drive_xfer_rate;
738 hwif->ide_dma_lostirq = &pdc202xx_ide_dma_lostirq;
739 hwif->ide_dma_timeout = &pdc202xx_ide_dma_timeout;
741 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) {
742 if (!(hwif->udma_four))
743 hwif->udma_four = (pdc202xx_old_cable_detect(hwif)) ? 0 : 1;
744 hwif->ide_dma_begin = &pdc202xx_old_ide_dma_begin;
745 hwif->ide_dma_end = &pdc202xx_old_ide_dma_end;
747 hwif->ide_dma_test_irq = &pdc202xx_old_ide_dma_test_irq;
751 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
752 #if PDC202_DEBUG_CABLE
753 printk(KERN_DEBUG "%s: %s-pin cable\n",
754 hwif->name, hwif->udma_four ? "80" : "40");
755 #endif /* PDC202_DEBUG_CABLE */
758 static void __init init_dma_pdc202xx (ide_hwif_t *hwif, unsigned long dmabase)
760 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
763 ide_setup_dma(hwif, dmabase, 8);
767 udma_speed_flag = hwif->INB((dmabase|0x1f));
768 primary_mode = hwif->INB((dmabase|0x1a));
769 secondary_mode = hwif->INB((dmabase|0x1b));
770 printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
772 "Secondary %s Mode.\n", hwif->cds->name,
773 (udma_speed_flag & 1) ? "EN" : "DIS",
774 (primary_mode & 1) ? "MASTER" : "PCI",
775 (secondary_mode & 1) ? "MASTER" : "PCI" );
777 #ifdef CONFIG_PDC202XX_BURST
778 if (!(udma_speed_flag & 1)) {
779 printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
780 hwif->cds->name, udma_speed_flag,
781 (udma_speed_flag|1));
782 hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f));
784 (hwif->INB(dmabase|0x1f)&1) ? "":"IN");
786 #endif /* CONFIG_PDC202XX_BURST */
787 #ifdef CONFIG_PDC202XX_MASTER
788 if (!(primary_mode & 1)) {
789 printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT "
790 "0x%02x -> 0x%02x ", hwif->cds->name,
791 primary_mode, (primary_mode|1));
792 hwif->OUTB(primary_mode|1, (dmabase|0x1a));
794 (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI");
797 if (!(secondary_mode & 1)) {
798 printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT "
799 "0x%02x -> 0x%02x ", hwif->cds->name,
800 secondary_mode, (secondary_mode|1));
801 hwif->OUTB(secondary_mode|1, (dmabase|0x1b));
803 (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI");
805 #endif /* CONFIG_PDC202XX_MASTER */
807 ide_setup_dma(hwif, dmabase, 8);
810 static void __init init_setup_pdc202ata4 (struct pci_dev *dev, ide_pci_device_t *d)
812 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
813 u8 irq = 0, irq2 = 0;
814 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
816 pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2);
818 pci_write_config_byte(dev,
819 (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
820 printk(KERN_INFO "%s: pci-config space interrupt "
821 "mirror fixed.\n", d->name);
826 if (dev->device == PCI_DEVICE_ID_PROMISE_20262)
827 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
828 (tmp & e->mask) != e->val))
830 if (d->enablebits[0].reg != d->enablebits[1].reg) {
831 d->enablebits[0].reg = d->enablebits[1].reg;
832 d->enablebits[0].mask = d->enablebits[1].mask;
833 d->enablebits[0].val = d->enablebits[1].val;
837 ide_setup_pci_device(dev, d);
840 static void __init init_setup_pdc20265 (struct pci_dev *dev, ide_pci_device_t *d)
842 if ((dev->bus->self) &&
843 (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) &&
844 ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) ||
845 (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) {
846 printk(KERN_INFO "ide: Skipping Promise PDC20265 "
847 "attached to I2O RAID controller.\n");
855 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
856 (tmp & e->mask) != e->val))
858 if (d->enablebits[0].reg != d->enablebits[1].reg) {
859 d->enablebits[0].reg = d->enablebits[1].reg;
860 d->enablebits[0].mask = d->enablebits[1].mask;
861 d->enablebits[0].val = d->enablebits[1].val;
866 ide_setup_pci_device(dev, d);
869 static void __init init_setup_pdc202xx (struct pci_dev *dev, ide_pci_device_t *d)
871 ide_setup_pci_device(dev, d);
875 * pdc202xx_init_one - called when a PDC202xx is found
876 * @dev: the pdc202xx device
877 * @id: the matching pci id
879 * Called when the PCI registration layer (or the IDE initialization)
880 * finds a device matching our IDE device tables.
883 static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
885 ide_pci_device_t *d = &pdc202xx_chipsets[id->driver_data];
887 if (dev->device != d->device)
889 d->init_setup(dev, d);
893 static struct pci_device_id pdc202xx_pci_tbl[] = {
894 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
895 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20262, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
896 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
897 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20265, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
898 { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20267, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
901 MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
903 static struct pci_driver driver = {
904 .name = "Promise Old IDE",
905 .id_table = pdc202xx_pci_tbl,
906 .probe = pdc202xx_init_one,
909 static int pdc202xx_ide_init(void)
911 return ide_pci_register_driver(&driver);
914 module_init(pdc202xx_ide_init);
916 MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
917 MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
918 MODULE_LICENSE("GPL");