1 /* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16
3 * linux/drivers/ide/pci/cmd64x.c Version 1.30 Sept 10, 2002
5 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines.
6 * Note, this driver is not used at all on other systems because
7 * there the "BIOS" has done all of the following already.
8 * Due to massive hardware bugs, UltraDMA is only supported
9 * on the 646U2 and not on the 646U.
11 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
12 * Copyright (C) 1998 David S. Miller (davem@redhat.com)
14 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/pci.h>
21 #include <linux/delay.h>
22 #include <linux/hdreg.h>
23 #include <linux/ide.h>
24 #include <linux/init.h>
30 #if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS)
31 #include <linux/stat.h>
32 #include <linux/proc_fs.h>
34 static u8 cmd64x_proc = 0;
36 #define CMD_MAX_DEVS 5
38 static struct pci_dev *cmd_devs[CMD_MAX_DEVS];
39 static int n_cmd_devs;
41 static char * print_cmd64x_get_info (char *buf, struct pci_dev *dev, int index)
45 u8 reg53 = 0, reg54 = 0, reg55 = 0, reg56 = 0; /* primary */
46 u8 reg57 = 0, reg58 = 0, reg5b; /* secondary */
47 u8 reg72 = 0, reg73 = 0; /* primary */
48 u8 reg7a = 0, reg7b = 0; /* secondary */
49 u8 reg50 = 0, reg71 = 0; /* extra */
51 p += sprintf(p, "\nController: %d\n", index);
52 p += sprintf(p, "CMD%x Chipset.\n", dev->device);
53 (void) pci_read_config_byte(dev, CFR, ®50);
54 (void) pci_read_config_byte(dev, ARTTIM0, ®53);
55 (void) pci_read_config_byte(dev, DRWTIM0, ®54);
56 (void) pci_read_config_byte(dev, ARTTIM1, ®55);
57 (void) pci_read_config_byte(dev, DRWTIM1, ®56);
58 (void) pci_read_config_byte(dev, ARTTIM2, ®57);
59 (void) pci_read_config_byte(dev, DRWTIM2, ®58);
60 (void) pci_read_config_byte(dev, DRWTIM3, ®5b);
61 (void) pci_read_config_byte(dev, MRDMODE, ®71);
62 (void) pci_read_config_byte(dev, BMIDESR0, ®72);
63 (void) pci_read_config_byte(dev, UDIDETCR0, ®73);
64 (void) pci_read_config_byte(dev, BMIDESR1, ®7a);
65 (void) pci_read_config_byte(dev, UDIDETCR1, ®7b);
67 p += sprintf(p, "--------------- Primary Channel "
68 "---------------- Secondary Channel "
70 p += sprintf(p, " %sabled "
72 (reg72&0x80)?"dis":" en",
73 (reg7a&0x80)?"dis":" en");
74 p += sprintf(p, "--------------- drive0 "
75 "--------- drive1 -------- drive0 "
76 "---------- drive1 ------\n");
77 p += sprintf(p, "DMA enabled: %s %s"
79 (reg72&0x20)?"yes":"no ", (reg72&0x40)?"yes":"no ",
80 (reg7a&0x20)?"yes":"no ", (reg7a&0x40)?"yes":"no ");
82 p += sprintf(p, "DMA Mode: %s(%s) %s(%s)",
83 (reg72&0x20)?((reg73&0x01)?"UDMA":" DMA"):" PIO",
85 ((reg73&0x30)==0x30)?(((reg73&0x35)==0x35)?"3":"0"):
86 ((reg73&0x20)==0x20)?(((reg73&0x25)==0x25)?"3":"1"):
87 ((reg73&0x10)==0x10)?(((reg73&0x15)==0x15)?"4":"2"):
88 ((reg73&0x00)==0x00)?(((reg73&0x05)==0x05)?"5":"2"):
90 (reg72&0x40)?((reg73&0x02)?"UDMA":" DMA"):" PIO",
92 ((reg73&0xC0)==0xC0)?(((reg73&0xC5)==0xC5)?"3":"0"):
93 ((reg73&0x80)==0x80)?(((reg73&0x85)==0x85)?"3":"1"):
94 ((reg73&0x40)==0x40)?(((reg73&0x4A)==0x4A)?"4":"2"):
95 ((reg73&0x00)==0x00)?(((reg73&0x0A)==0x0A)?"5":"2"):
97 p += sprintf(p, " %s(%s) %s(%s)\n",
98 (reg7a&0x20)?((reg7b&0x01)?"UDMA":" DMA"):" PIO",
100 ((reg7b&0x30)==0x30)?(((reg7b&0x35)==0x35)?"3":"0"):
101 ((reg7b&0x20)==0x20)?(((reg7b&0x25)==0x25)?"3":"1"):
102 ((reg7b&0x10)==0x10)?(((reg7b&0x15)==0x15)?"4":"2"):
103 ((reg7b&0x00)==0x00)?(((reg7b&0x05)==0x05)?"5":"2"):
105 (reg7a&0x40)?((reg7b&0x02)?"UDMA":" DMA"):" PIO",
107 ((reg7b&0xC0)==0xC0)?(((reg7b&0xC5)==0xC5)?"3":"0"):
108 ((reg7b&0x80)==0x80)?(((reg7b&0x85)==0x85)?"3":"1"):
109 ((reg7b&0x40)==0x40)?(((reg7b&0x4A)==0x4A)?"4":"2"):
110 ((reg7b&0x00)==0x00)?(((reg7b&0x0A)==0x0A)?"5":"2"):
112 p += sprintf(p, "PIO Mode: %s %s"
115 p += sprintf(p, " %s %s\n",
116 (reg50 & CFR_INTR_CH0) ? "interrupting" : "polling ",
117 (reg57 & ARTTIM23_INTR_CH1) ? "interrupting" : "polling");
118 p += sprintf(p, " %s %s\n",
119 (reg71 & MRDMODE_INTR_CH0) ? "pending" : "clear ",
120 (reg71 & MRDMODE_INTR_CH1) ? "pending" : "clear");
121 p += sprintf(p, " %s %s\n",
122 (reg71 & MRDMODE_BLK_CH0) ? "blocked" : "enabled",
123 (reg71 & MRDMODE_BLK_CH1) ? "blocked" : "enabled");
128 static int cmd64x_get_info (char *buffer, char **addr, off_t offset, int count)
133 p += sprintf(p, "\n");
134 for (i = 0; i < n_cmd_devs; i++) {
135 struct pci_dev *dev = cmd_devs[i];
136 p = print_cmd64x_get_info(p, dev, i);
138 return p-buffer; /* => must be less than 4k! */
141 #endif /* defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) */
144 * Registers and masks for easy access by drive index:
147 static u8 prefetch_regs[4] = {CNTRL, CNTRL, ARTTIM23, ARTTIM23};
148 static u8 prefetch_masks[4] = {CNTRL_DIS_RA0, CNTRL_DIS_RA1, ARTTIM23_DIS_RA2, ARTTIM23_DIS_RA3};
152 * This routine writes the prepared setup/active/recovery counts
153 * for a drive into the cmd646 chipset registers to active them.
155 static void program_drive_counts (ide_drive_t *drive, int setup_count, int active_count, int recovery_count)
158 struct pci_dev *dev = HWIF(drive)->pci_dev;
159 ide_drive_t *drives = HWIF(drive)->drives;
161 static const u8 setup_counts[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0};
162 static const u8 recovery_counts[] =
163 {15, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0};
164 static const u8 arttim_regs[2][2] = {
165 { ARTTIM0, ARTTIM1 },
166 { ARTTIM23, ARTTIM23 }
168 static const u8 drwtim_regs[2][2] = {
169 { DRWTIM0, DRWTIM1 },
172 int channel = (int) HWIF(drive)->channel;
173 int slave = (drives != drive); /* Is this really the best way to determine this?? */
175 cmdprintk("program_drive_count parameters = s(%d),a(%d),r(%d),p(%d)\n",
176 setup_count, active_count, recovery_count, drive->present);
178 * Set up address setup count registers.
179 * Primary interface has individual count/timing registers for
180 * each drive. Secondary interface has one common set of registers,
181 * for address setup so we merge these timings, using the slowest
185 drive->drive_data = setup_count;
186 setup_count = max(drives[0].drive_data,
187 drives[1].drive_data);
188 cmdprintk("Secondary interface, setup_count = %d\n",
193 * Convert values to internal chipset representation
195 setup_count = (setup_count > 5) ? 0xc0 : (int) setup_counts[setup_count];
196 active_count &= 0xf; /* Remember, max value is 16 */
197 recovery_count = (int) recovery_counts[recovery_count];
199 cmdprintk("Final values = %d,%d,%d\n",
200 setup_count, active_count, recovery_count);
203 * Now that everything is ready, program the new timings
205 local_irq_save(flags);
207 * Program the address_setup clocks into ARTTIM reg,
208 * and then the active/recovery counts into the DRWTIM reg
210 (void) pci_read_config_byte(dev, arttim_regs[channel][slave], &temp_b);
211 (void) pci_write_config_byte(dev, arttim_regs[channel][slave],
212 ((u8) setup_count) | (temp_b & 0x3f));
213 (void) pci_write_config_byte(dev, drwtim_regs[channel][slave],
214 (u8) ((active_count << 4) | recovery_count));
215 cmdprintk ("Write %x to %x\n",
216 ((u8) setup_count) | (temp_b & 0x3f),
217 arttim_regs[channel][slave]);
218 cmdprintk ("Write %x to %x\n",
219 (u8) ((active_count << 4) | recovery_count),
220 drwtim_regs[channel][slave]);
221 local_irq_restore(flags);
225 * Attempts to set the interface PIO mode.
226 * The preferred method of selecting PIO modes (e.g. mode 4) is
227 * "echo 'piomode:4' > /proc/ide/hdx/settings". Special cases are
228 * 8: prefetch off, 9: prefetch on, 255: auto-select best mode.
229 * Called with 255 at boot time.
232 static void cmd64x_tuneproc (ide_drive_t *drive, u8 mode_wanted)
234 int setup_time, active_time, recovery_time;
235 int clock_time, pio_mode, cycle_time;
236 u8 recovery_count2, cycle_count;
237 int setup_count, active_count, recovery_count;
238 int bus_speed = system_bus_clock();
242 switch (mode_wanted) {
243 case 8: /* set prefetch off */
244 case 9: /* set prefetch on */
246 /*set_prefetch_mode(index, mode_wanted);*/
247 cmdprintk("%s: %sabled cmd640 prefetch\n",
248 drive->name, mode_wanted ? "en" : "dis");
252 mode_wanted = ide_get_best_pio_mode (drive, mode_wanted, 5, &d);
253 pio_mode = d.pio_mode;
254 cycle_time = d.cycle_time;
257 * I copied all this complicated stuff from cmd640.c and made a few
258 * minor changes. For now I am just going to pray that it is correct.
262 setup_time = ide_pio_timings[pio_mode].setup_time;
263 active_time = ide_pio_timings[pio_mode].active_time;
264 recovery_time = cycle_time - (setup_time + active_time);
265 clock_time = 1000 / bus_speed;
266 cycle_count = (cycle_time + clock_time - 1) / clock_time;
268 setup_count = (setup_time + clock_time - 1) / clock_time;
270 active_count = (active_time + clock_time - 1) / clock_time;
272 recovery_count = (recovery_time + clock_time - 1) / clock_time;
273 recovery_count2 = cycle_count - (setup_count + active_count);
274 if (recovery_count2 > recovery_count)
275 recovery_count = recovery_count2;
276 if (recovery_count > 16) {
277 active_count += recovery_count - 16;
280 if (active_count > 16)
281 active_count = 16; /* maximum allowed by cmd646 */
284 * In a perfect world, we might set the drive pio mode here
285 * (using WIN_SETFEATURE) before continuing.
287 * But we do not, because:
288 * 1) this is the wrong place to do it
289 * (proper is do_special() in ide.c)
290 * 2) in practice this is rarely, if ever, necessary
292 program_drive_counts (drive, setup_count, active_count, recovery_count);
294 cmdprintk("%s: selected cmd646 PIO mode%d : %d (%dns)%s, "
296 drive->name, pio_mode, mode_wanted, cycle_time,
297 d.overridden ? " (overriding vendor mode)" : "",
298 setup_count, active_count, recovery_count);
301 static u8 cmd64x_ratemask (ide_drive_t *drive)
303 struct pci_dev *dev = HWIF(drive)->pci_dev;
306 switch(dev->device) {
307 case PCI_DEVICE_ID_CMD_649:
310 case PCI_DEVICE_ID_CMD_648:
313 case PCI_DEVICE_ID_CMD_643:
316 case PCI_DEVICE_ID_CMD_646:
318 unsigned int class_rev = 0;
319 pci_read_config_dword(dev,
320 PCI_CLASS_REVISION, &class_rev);
323 * UltraDMA only supported on PCI646U and PCI646U2, which
324 * correspond to revisions 0x03, 0x05 and 0x07 respectively.
325 * Actually, although the CMD tech support people won't
326 * tell me the details, the 0x03 revision cannot support
327 * UDMA correctly without hardware modifications, and even
328 * then it only works with Quantum disks due to some
329 * hold time assumptions in the 646U part which are fixed
332 * So we only do UltraDMA on revision 0x05 and 0x07 chipsets.
345 if (!eighty_ninty_three(drive))
346 mode = min(mode, (u8)1);
350 static void config_cmd64x_chipset_for_pio (ide_drive_t *drive, u8 set_speed)
353 u8 set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL);
355 cmd64x_tuneproc(drive, set_pio);
356 speed = XFER_PIO_0 + set_pio;
358 (void) ide_config_drive_speed(drive, speed);
361 static void config_chipset_for_pio (ide_drive_t *drive, u8 set_speed)
363 config_cmd64x_chipset_for_pio(drive, set_speed);
366 static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
368 ide_hwif_t *hwif = HWIF(drive);
369 struct pci_dev *dev = hwif->pci_dev;
371 u8 unit = (drive->select.b.unit & 0x01);
372 u8 regU = 0, pciU = (hwif->channel) ? UDIDETCR1 : UDIDETCR0;
373 u8 regD = 0, pciD = (hwif->channel) ? BMIDESR1 : BMIDESR0;
375 u8 speed = ide_rate_filter(cmd64x_ratemask(drive), xferspeed);
377 if (speed > XFER_PIO_4) {
378 (void) pci_read_config_byte(dev, pciD, ®D);
379 (void) pci_read_config_byte(dev, pciU, ®U);
380 regD &= ~(unit ? 0x40 : 0x20);
381 regU &= ~(unit ? 0xCA : 0x35);
382 (void) pci_write_config_byte(dev, pciD, regD);
383 (void) pci_write_config_byte(dev, pciU, regU);
384 (void) pci_read_config_byte(dev, pciD, ®D);
385 (void) pci_read_config_byte(dev, pciU, ®U);
389 case XFER_UDMA_5: regU |= (unit ? 0x0A : 0x05); break;
390 case XFER_UDMA_4: regU |= (unit ? 0x4A : 0x15); break;
391 case XFER_UDMA_3: regU |= (unit ? 0x8A : 0x25); break;
392 case XFER_UDMA_2: regU |= (unit ? 0x42 : 0x11); break;
393 case XFER_UDMA_1: regU |= (unit ? 0x82 : 0x21); break;
394 case XFER_UDMA_0: regU |= (unit ? 0xC2 : 0x31); break;
395 case XFER_MW_DMA_2: regD |= (unit ? 0x40 : 0x10); break;
396 case XFER_MW_DMA_1: regD |= (unit ? 0x80 : 0x20); break;
397 case XFER_MW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break;
398 case XFER_SW_DMA_2: regD |= (unit ? 0x40 : 0x10); break;
399 case XFER_SW_DMA_1: regD |= (unit ? 0x80 : 0x20); break;
400 case XFER_SW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break;
401 case XFER_PIO_4: cmd64x_tuneproc(drive, 4); break;
402 case XFER_PIO_3: cmd64x_tuneproc(drive, 3); break;
403 case XFER_PIO_2: cmd64x_tuneproc(drive, 2); break;
404 case XFER_PIO_1: cmd64x_tuneproc(drive, 1); break;
405 case XFER_PIO_0: cmd64x_tuneproc(drive, 0); break;
411 if (speed > XFER_PIO_4) {
412 (void) pci_write_config_byte(dev, pciU, regU);
413 regD |= (unit ? 0x40 : 0x20);
414 (void) pci_write_config_byte(dev, pciD, regD);
417 return (ide_config_drive_speed(drive, speed));
420 static int config_chipset_for_dma (ide_drive_t *drive)
422 u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive));
424 config_chipset_for_pio(drive, !speed);
429 if(ide_set_xfer_rate(drive, speed))
432 if (!drive->init_speed)
433 drive->init_speed = speed;
435 return ide_dma_enable(drive);
438 static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
440 ide_hwif_t *hwif = HWIF(drive);
441 struct hd_driveid *id = drive->id;
443 if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) {
445 if (ide_use_dma(drive)) {
446 if (config_chipset_for_dma(drive))
447 return hwif->ide_dma_on(drive);
452 } else if ((id->capability & 8) || (id->field_valid & 2)) {
454 config_chipset_for_pio(drive, 1);
455 return hwif->ide_dma_off_quietly(drive);
457 /* IORDY not supported */
461 static int cmd64x_alt_dma_status (struct pci_dev *dev)
463 switch(dev->device) {
464 case PCI_DEVICE_ID_CMD_648:
465 case PCI_DEVICE_ID_CMD_649:
473 static int cmd64x_ide_dma_end (ide_drive_t *drive)
475 u8 dma_stat = 0, dma_cmd = 0;
476 ide_hwif_t *hwif = HWIF(drive);
477 struct pci_dev *dev = hwif->pci_dev;
479 drive->waiting_for_dma = 0;
480 /* read DMA command state */
481 dma_cmd = hwif->INB(hwif->dma_command);
483 hwif->OUTB((dma_cmd & ~1), hwif->dma_command);
485 dma_stat = hwif->INB(hwif->dma_status);
486 /* clear the INTR & ERROR bits */
487 hwif->OUTB(dma_stat|6, hwif->dma_status);
488 if (cmd64x_alt_dma_status(dev)) {
490 u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 :
492 u8 dma_reg = (hwif->channel) ? ARTTIM2 : CFR;
493 (void) pci_read_config_byte(dev, dma_reg, &dma_intr);
494 /* clear the INTR bit */
495 (void) pci_write_config_byte(dev, dma_reg, dma_intr|dma_mask);
497 /* purge DMA mappings */
498 ide_destroy_dmatable(drive);
499 /* verify good DMA status */
500 return (dma_stat & 7) != 4;
503 static int cmd64x_ide_dma_test_irq (ide_drive_t *drive)
505 ide_hwif_t *hwif = HWIF(drive);
506 struct pci_dev *dev = hwif->pci_dev;
507 u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 :
509 u8 dma_stat = hwif->INB(hwif->dma_status);
511 (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat);
513 printk("%s: dma_stat: 0x%02x dma_alt_stat: "
514 "0x%02x mask: 0x%02x\n", drive->name,
515 dma_stat, dma_alt_stat, mask);
517 if (!(dma_alt_stat & mask))
520 /* return 1 if INTR asserted */
521 if ((dma_stat & 4) == 4)
528 * ASUS P55T2P4D with CMD646 chipset revision 0x01 requires the old
529 * event order for DMA transfers.
532 static int cmd646_1_ide_dma_end (ide_drive_t *drive)
534 ide_hwif_t *hwif = HWIF(drive);
535 u8 dma_stat = 0, dma_cmd = 0;
537 drive->waiting_for_dma = 0;
539 dma_stat = hwif->INB(hwif->dma_status);
540 /* read DMA command state */
541 dma_cmd = hwif->INB(hwif->dma_command);
543 hwif->OUTB((dma_cmd & ~1), hwif->dma_command);
544 /* clear the INTR & ERROR bits */
545 hwif->OUTB(dma_stat|6, hwif->dma_status);
546 /* and free any DMA resources */
547 ide_destroy_dmatable(drive);
548 /* verify good DMA status */
549 return (dma_stat & 7) != 4;
552 static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const char *name)
557 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
561 if (dev->resource[PCI_ROM_RESOURCE].start) {
562 pci_write_config_byte(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
563 printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start);
567 switch(dev->device) {
568 case PCI_DEVICE_ID_CMD_643:
570 case PCI_DEVICE_ID_CMD_646:
571 printk(KERN_INFO "%s: chipset revision 0x%02X, ", name, class_rev);
575 printk("UltraDMA Capable");
578 printk("MultiWord DMA Force Limited");
582 printk("MultiWord DMA Limited, IRQ workaround enabled");
587 case PCI_DEVICE_ID_CMD_648:
588 case PCI_DEVICE_ID_CMD_649:
594 /* Set a good latency timer and cache line size value. */
595 (void) pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
596 /* FIXME: pci_set_master() to ensure a good latency timer value */
598 /* Setup interrupts. */
599 (void) pci_read_config_byte(dev, MRDMODE, &mrdmode);
601 (void) pci_write_config_byte(dev, MRDMODE, mrdmode);
603 /* Use MEMORY READ LINE for reads.
604 * NOTE: Although not mentioned in the PCI0646U specs,
605 * these bits are write only and won't be read
606 * back as set or not. The PCI0646U2 specs clarify
609 (void) pci_write_config_byte(dev, MRDMODE, mrdmode | 0x02);
611 /* Set reasonable active/recovery/address-setup values. */
612 (void) pci_write_config_byte(dev, ARTTIM0, 0x40);
613 (void) pci_write_config_byte(dev, DRWTIM0, 0x3f);
614 (void) pci_write_config_byte(dev, ARTTIM1, 0x40);
615 (void) pci_write_config_byte(dev, DRWTIM1, 0x3f);
617 (void) pci_write_config_byte(dev, ARTTIM23, 0x1c);
619 (void) pci_write_config_byte(dev, ARTTIM23, 0x5c);
621 (void) pci_write_config_byte(dev, DRWTIM23, 0x3f);
622 (void) pci_write_config_byte(dev, DRWTIM3, 0x3f);
624 (void) pci_write_config_byte(dev, UDIDETCR0, 0xf0);
625 #endif /* CONFIG_PPC */
627 #if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS)
629 cmd_devs[n_cmd_devs++] = dev;
633 ide_pci_create_host_proc("cmd64x", cmd64x_get_info);
635 #endif /* DISPLAY_CMD64X_TIMINGS && CONFIG_PROC_FS */
640 static unsigned int __devinit ata66_cmd64x(ide_hwif_t *hwif)
642 u8 ata66 = 0, mask = (hwif->channel) ? 0x02 : 0x01;
644 switch(hwif->pci_dev->device) {
645 case PCI_DEVICE_ID_CMD_643:
646 case PCI_DEVICE_ID_CMD_646:
651 pci_read_config_byte(hwif->pci_dev, BMIDECSR, &ata66);
652 return (ata66 & mask) ? 1 : 0;
655 static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
657 struct pci_dev *dev = hwif->pci_dev;
658 unsigned int class_rev;
661 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
664 hwif->tuneproc = &cmd64x_tuneproc;
665 hwif->speedproc = &cmd64x_tune_chipset;
667 if (!hwif->dma_base) {
668 hwif->drives[0].autotune = 1;
669 hwif->drives[1].autotune = 1;
675 hwif->ultra_mask = 0x3f;
676 hwif->mwdma_mask = 0x07;
677 hwif->swdma_mask = 0x07;
679 if (dev->device == PCI_DEVICE_ID_CMD_643)
680 hwif->ultra_mask = 0x80;
681 if (dev->device == PCI_DEVICE_ID_CMD_646)
682 hwif->ultra_mask = (class_rev > 0x04) ? 0x07 : 0x80;
683 if (dev->device == PCI_DEVICE_ID_CMD_648)
684 hwif->ultra_mask = 0x1f;
686 hwif->ide_dma_check = &cmd64x_config_drive_for_dma;
687 if (!(hwif->udma_four))
688 hwif->udma_four = ata66_cmd64x(hwif);
690 if (dev->device == PCI_DEVICE_ID_CMD_646) {
691 hwif->chipset = ide_cmd646;
692 if (class_rev == 0x01) {
693 hwif->ide_dma_end = &cmd646_1_ide_dma_end;
695 hwif->ide_dma_end = &cmd64x_ide_dma_end;
696 hwif->ide_dma_test_irq = &cmd64x_ide_dma_test_irq;
699 hwif->ide_dma_end = &cmd64x_ide_dma_end;
700 hwif->ide_dma_test_irq = &cmd64x_ide_dma_test_irq;
706 hwif->drives[0].autodma = hwif->autodma;
707 hwif->drives[1].autodma = hwif->autodma;
710 static int __devinit cmd64x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
712 ide_setup_pci_device(dev, &cmd64x_chipsets[id->driver_data]);
716 static struct pci_device_id cmd64x_pci_tbl[] = {
717 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_643, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
718 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
719 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_648, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
720 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
723 MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl);
725 static struct pci_driver driver = {
726 .name = "CMD64x_IDE",
727 .id_table = cmd64x_pci_tbl,
728 .probe = cmd64x_init_one,
731 static int cmd64x_ide_init(void)
733 return ide_pci_register_driver(&driver);
736 module_init(cmd64x_ide_init);
738 MODULE_AUTHOR("Eddie Dost, David Miller, Andre Hedrick");
739 MODULE_DESCRIPTION("PCI driver module for CMD64x IDE");
740 MODULE_LICENSE("GPL");