📄 via82cxxx.c
字号:
T = 1000000000 / via_clock; switch (via_config->flags & VIA_UDMA) { case VIA_UDMA_33: UT = T; break; case VIA_UDMA_66: UT = T/2; break; case VIA_UDMA_100: UT = T/3; break; case VIA_UDMA_133: UT = T/4; break; default: UT = T; } ide_timing_compute(drive, speed, &t, T, UT); if (peer->present) { ide_timing_compute(peer, peer->current_speed, &p, T, UT); ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); } via_set_speed(HWIF(drive)->pci_dev, drive->dn, &t); if (!drive->init_speed) drive->init_speed = speed; drive->current_speed = speed; return 0;}/** * via82cxxx_tune_drive - PIO setup * @drive: drive to set up * @pio: mode to use (255 for 'best possible') * * A callback from the upper layers for PIO-only tuning. */static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio){ if (!((via_enabled >> HWIF(drive)->channel) & 1)) return; if (pio == 255) { via_set_drive(drive, ide_find_best_mode(drive, XFER_PIO | XFER_EPIO)); return; } via_set_drive(drive, XFER_PIO_0 + MIN(pio, 5));}/** * via82cxxx_ide_dma_check - set up for DMA if possible * @drive: IDE drive to set up * * Set up the drive for the highest supported speed considering the * driver, controller and cable */ static int via82cxxx_ide_dma_check (ide_drive_t *drive){ u16 w80 = HWIF(drive)->udma_four; u16 speed = ide_find_best_mode(drive, XFER_PIO | XFER_EPIO | XFER_SWDMA | XFER_MWDMA | (via_config->flags & VIA_UDMA ? XFER_UDMA : 0) | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_66 ? XFER_UDMA_66 : 0) | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_100 ? XFER_UDMA_100 : 0) | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_133 ? XFER_UDMA_133 : 0)); via_set_drive(drive, speed); if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) return HWIF(drive)->ide_dma_on(drive); return HWIF(drive)->ide_dma_off_quietly(drive);}/** * init_chipset_via82cxxx - initialization handler * @dev: PCI device * @name: Name of interface * * The initialization callback. Here we determine the IDE chip type * and initialize its drive independent registers. */static unsigned int __init init_chipset_via82cxxx(struct pci_dev *dev, const char *name){ struct pci_dev *isa = NULL; u8 t, v; unsigned int u; int i; /* * Find the ISA bridge to see how good the IDE is. */ for (via_config = via_isa_bridges; via_config->id; via_config++) if ((isa = pci_find_device(PCI_VENDOR_ID_VIA + !!(via_config->flags & VIA_BAD_ID), via_config->id, NULL))) { pci_read_config_byte(isa, PCI_REVISION_ID, &t); if (t >= via_config->rev_min && t <= via_config->rev_max) break; } if (!via_config->id) { printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n"); return -ENODEV; } /* * Check 80-wire cable presence and setup Clk66. */ switch (via_config->flags & VIA_UDMA) { case VIA_UDMA_66: /* Enable Clk66 */ pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); pci_write_config_dword(dev, VIA_UDMA_TIMING, u|0x80008); for (i = 24; i >= 0; i -= 8) if (((u >> (i & 16)) & 8) && ((u >> i) & 0x20) && (((u >> i) & 7) < 2)) { /* * 2x PCI clock and * UDMA w/ < 3T/cycle */ via_80w |= (1 << (1 - (i >> 4))); } break; case VIA_UDMA_100: pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); for (i = 24; i >= 0; i -= 8) if (((u >> i) & 0x10) || (((u >> i) & 0x20) && (((u >> i) & 7) < 4))) { /* BIOS 80-wire bit or * UDMA w/ < 60ns/cycle */ via_80w |= (1 << (1 - (i >> 4))); } break; case VIA_UDMA_133: pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); for (i = 24; i >= 0; i -= 8) if (((u >> i) & 0x10) || (((u >> i) & 0x20) && (((u >> i) & 7) < 8))) { /* BIOS 80-wire bit or * UDMA w/ < 60ns/cycle */ via_80w |= (1 << (1 - (i >> 4))); } break; } /* Disable Clk66 */ if (via_config->flags & VIA_BAD_CLK66) { /* Would cause trouble on 596a and 686 */ pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); pci_write_config_dword(dev, VIA_UDMA_TIMING, u & ~0x80008); } /* * Check whether interfaces are enabled. */ pci_read_config_byte(dev, VIA_IDE_ENABLE, &v); via_enabled = ((v & 1) ? 2 : 0) | ((v & 2) ? 1 : 0); /* * Set up FIFO sizes and thresholds. */ pci_read_config_byte(dev, VIA_FIFO_CONFIG, &t); /* Disable PREQ# till DDACK# */ if (via_config->flags & VIA_BAD_PREQ) { /* Would crash on 586b rev 41 */ t &= 0x7f; } /* Fix FIFO split between channels */ if (via_config->flags & VIA_SET_FIFO) { t &= (t & 0x9f); switch (via_enabled) { case 1: t |= 0x00; break; /* 16 on primary */ case 2: t |= 0x60; break; /* 16 on secondary */ case 3: t |= 0x20; break; /* 8 pri 8 sec */ } } pci_write_config_byte(dev, VIA_FIFO_CONFIG, t); /* * Determine system bus clock. */ via_clock = system_bus_clock() * 1000; switch (via_clock) { case 33000: via_clock = 33333; break; case 37000: via_clock = 37500; break; case 41000: via_clock = 41666; break; } if (via_clock < 20000 || via_clock > 50000) { printk(KERN_WARNING "VP_IDE: User given PCI clock speed " "impossible (%d), using 33 MHz instead.\n", via_clock); printk(KERN_WARNING "VP_IDE: Use ide0=ata66 if you want " "to assume 80-wire cable.\n"); via_clock = 33333; } /* * Print the boot message. */ pci_read_config_byte(isa, PCI_REVISION_ID, &t); printk(KERN_INFO "VP_IDE: VIA %s (rev %02x) IDE %s " "controller on pci%s\n", via_config->name, t, via_dma[via_config->flags & VIA_UDMA], dev->slot_name); /* * Setup /proc/ide/via entry. */#if defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS) if (!via_proc) { via_base = pci_resource_start(dev, 4); bmide_dev = dev; isa_dev = isa; ide_pci_register_host_proc(&via_procs[0]); via_proc = 1; }#endif /* DISPLAY_VIA_TIMINGS && CONFIG_PROC_FS */ return 0;}static void __init init_hwif_via82cxxx(ide_hwif_t *hwif){ int i; hwif->autodma = 0; hwif->tuneproc = &via82cxxx_tune_drive; hwif->speedproc = &via_set_drive; for (i = 0; i < 2; i++) { hwif->drives[i].io_32bit = 1; hwif->drives[i].unmask = (via_config->flags & VIA_NO_UNMASK) ? 0 : 1; hwif->drives[i].autotune = 1; hwif->drives[i].dn = hwif->channel * 2 + i; } if (!hwif->dma_base) return; hwif->atapi_dma = 1; hwif->ultra_mask = 0x7f; hwif->mwdma_mask = 0x07; hwif->swdma_mask = 0x07; if (!(hwif->udma_four)) hwif->udma_four = ((via_enabled & via_80w) >> hwif->channel) & 1; hwif->ide_dma_check = &via82cxxx_ide_dma_check; if (!noautodma) hwif->autodma = 1; hwif->drives[0].autodma = hwif->autodma; hwif->drives[1].autodma = hwif->autodma;}/** * init_dma_via82cxxx - set up for IDE DMA * @hwif: IDE interface * @dmabase: DMA base address * * We allow the BM-DMA driver to only work on enabled interfaces. */static void __init init_dma_via82cxxx(ide_hwif_t *hwif, unsigned long dmabase){ if ((via_enabled >> hwif->channel) & 1) ide_setup_dma(hwif, dmabase, 8);}extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_id *id){ ide_pci_device_t *d = &via82cxxx_chipsets[id->driver_data]; if (dev->device != d->device) BUG(); ide_setup_pci_device(dev, d); MOD_INC_USE_COUNT; return 0;}static struct pci_device_id via_pci_tbl[] __devinitdata = { { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, { 0, },};static struct pci_driver driver = { .name = "VIA IDE", .id_table = via_pci_tbl, .probe = via_init_one,};static int via_ide_init(void){ return ide_pci_register_driver(&driver);}static void via_ide_exit(void){ ide_pci_unregister_driver(&driver);}module_init(via_ide_init);module_exit(via_ide_exit);MODULE_AUTHOR("Vojtech Pavlik, Michel Aubry, Jeff Garzik, Andre Hedrick");MODULE_DESCRIPTION("PCI driver module for VIA IDE");MODULE_LICENSE("GPL");EXPORT_NO_SYMBOLS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -