📄 via82cxxx.c
字号:
ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); struct ide_timing t, p; unsigned int T, UT; if (speed != XFER_PIO_SLOW && speed != drive->current_speed) if (ide_config_drive_speed(drive, speed)) printk(KERN_WARNING "ide%d: Drive %d didn't " "accept speed setting. Oh, well.\n", drive->dn >> 1, drive->dn & 1); 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 (pio == 255) { via_set_drive(drive, ide_find_best_mode(drive, XFER_PIO | XFER_EPIO)); return; } via_set_drive(drive, XFER_PIO_0 + min_t(u8, 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) < 6))) { /* 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); /* * 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 (v & 3) { case 2: t |= 0x00; break; /* 16 on primary */ case 1: 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], pci_name(dev)); /* * 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_create_host_proc("via", via_get_info); 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;#if defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_PPC32) if(_machine == _MACH_chrp && _chrp_type == _CHRP_Pegasos) { hwif->irq = hwif->channel ? 15 : 14; }#endif 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_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;}static ide_pci_device_t via82cxxx_chipset __devinitdata = { .name = "VP_IDE", .init_chipset = init_chipset_via82cxxx, .init_hwif = init_hwif_via82cxxx, .channels = 2, .autodma = NOAUTODMA, .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, .bootable = ON_BOARD,};static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_id *id){ return ide_setup_pci_device(dev, &via82cxxx_chipset);}static struct pci_device_id via_pci_tbl[] = { { 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, 0}, { 0, },};MODULE_DEVICE_TABLE(pci, via_pci_tbl);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);}module_init(via_ide_init);MODULE_AUTHOR("Vojtech Pavlik, Michel Aubry, Jeff Garzik, Andre Hedrick");MODULE_DESCRIPTION("PCI driver module for VIA IDE");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -