cmd640: manage I/O resources in driver
[safe/jmp/linux-2.6] / drivers / ide / pci / via82cxxx.c
index 5f13f3a..bbd17be 100644 (file)
@@ -1,7 +1,4 @@
 /*
- *
- * Version 3.49
- *
  * VIA IDE driver for Linux. Supported southbridges:
  *
  *   vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b,
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/ide.h>
 #include <linux/dmi.h>
 
-#include <asm/io.h>
-
 #ifdef CONFIG_PPC_CHRP
 #include <asm/processor.h>
 #endif
@@ -121,8 +114,8 @@ struct via82cxxx_dev
 
 static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
 {
-       struct pci_dev *dev = hwif->pci_dev;
-       struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev);
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       struct via82cxxx_dev *vdev = pci_get_drvdata(dev);
        u8 t;
 
        if (~vdev->via_config->flags & VIA_BAD_AST) {
@@ -159,8 +152,10 @@ static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
 
 static void via_set_drive(ide_drive_t *drive, const u8 speed)
 {
-       ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1);
-       struct via82cxxx_dev *vdev = pci_get_drvdata(drive->hwif->pci_dev);
+       ide_hwif_t *hwif = drive->hwif;
+       ide_drive_t *peer = hwif->drives + (~drive->dn & 1);
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       struct via82cxxx_dev *vdev = pci_get_drvdata(dev);
        struct ide_timing t, p;
        unsigned int T, UT;
 
@@ -408,7 +403,7 @@ static int via_cable_override(struct pci_dev *pdev)
 
 static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif)
 {
-       struct pci_dev *pdev = hwif->pci_dev;
+       struct pci_dev *pdev = to_pci_dev(hwif->dev);
        struct via82cxxx_dev *vdev = pci_get_drvdata(pdev);
 
        if (via_cable_override(pdev))
@@ -420,77 +415,35 @@ static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif)
                return ATA_CBL_PATA40;
 }
 
-static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
-{
-       struct via82cxxx_dev *vdev = pci_get_drvdata(hwif->pci_dev);
-       int i;
-
-       hwif->autodma = 0;
-
-       hwif->set_pio_mode = &via_set_pio_mode;
-       hwif->set_dma_mode = &via_set_drive;
-
-#ifdef CONFIG_PPC_CHRP
-       if(machine_is(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 = (vdev->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 = vdev->via_config->udma_mask;
-       hwif->mwdma_mask = 0x07;
-       hwif->swdma_mask = 0x07;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = via82cxxx_cable_detect(hwif);
-
-       if (!noautodma)
-               hwif->autodma = 1;
-       hwif->drives[0].autodma = hwif->autodma;
-       hwif->drives[1].autodma = hwif->autodma;
-}
+static const struct ide_port_ops via_port_ops = {
+       .set_pio_mode           = via_set_pio_mode,
+       .set_dma_mode           = via_set_drive,
+       .cable_detect           = via82cxxx_cable_detect,
+};
 
-static ide_pci_device_t via82cxxx_chipsets[] __devinitdata = {
-       {       /* 0 */
-               .name           = "VP_IDE",
-               .init_chipset   = init_chipset_via82cxxx,
-               .init_hwif      = init_hwif_via82cxxx,
-               .autodma        = NOAUTODMA,
-               .enablebits     = {{0x40,0x02,0x02}, {0x40,0x01,0x01}},
-               .bootable       = ON_BOARD,
-               .host_flags     = IDE_HFLAG_PIO_NO_BLACKLIST
-                               | IDE_HFLAG_PIO_NO_DOWNGRADE
-                               | IDE_HFLAG_POST_SET_MODE,
-               .pio_mask       = ATA_PIO5,
-       },{     /* 1 */
-               .name           = "VP_IDE",
-               .init_chipset   = init_chipset_via82cxxx,
-               .init_hwif      = init_hwif_via82cxxx,
-               .autodma        = AUTODMA,
-               .enablebits     = {{0x00,0x00,0x00}, {0x00,0x00,0x00}},
-               .bootable       = ON_BOARD,
-               .host_flags     = IDE_HFLAG_PIO_NO_BLACKLIST
-                               | IDE_HFLAG_PIO_NO_DOWNGRADE
-                               | IDE_HFLAG_POST_SET_MODE,
-               .pio_mask       = ATA_PIO5,
-       }
+static const struct ide_port_info via82cxxx_chipset __devinitdata = {
+       .name           = "VP_IDE",
+       .init_chipset   = init_chipset_via82cxxx,
+       .enablebits     = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
+       .port_ops       = &via_port_ops,
+       .host_flags     = IDE_HFLAG_PIO_NO_BLACKLIST |
+                         IDE_HFLAG_ABUSE_SET_DMA_MODE |
+                         IDE_HFLAG_POST_SET_MODE |
+                         IDE_HFLAG_IO_32BIT,
+       .pio_mask       = ATA_PIO5,
+       .swdma_mask     = ATA_SWDMA2,
+       .mwdma_mask     = ATA_MWDMA2,
 };
 
 static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
        struct pci_dev *isa = NULL;
        struct via_isa_bridge *via_config;
+       u8 idx = id->driver_data;
+       struct ide_port_info d;
+
+       d = via82cxxx_chipset;
+
        /*
         * Find the ISA bridge and check we know what it is.
         */
@@ -500,12 +453,29 @@ static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_i
                printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n");
                return -ENODEV;
        }
-       return ide_setup_pci_device(dev, &via82cxxx_chipsets[id->driver_data]);
+
+       if (idx == 0)
+               d.host_flags |= IDE_HFLAG_NO_AUTODMA;
+       else
+               d.enablebits[1].reg = d.enablebits[0].reg = 0;
+
+       if ((via_config->flags & VIA_NO_UNMASK) == 0)
+               d.host_flags |= IDE_HFLAG_UNMASK_IRQS;
+
+#ifdef CONFIG_PPC_CHRP
+       if (machine_is(chrp) && _chrp_type == _CHRP_Pegasos)
+               d.host_flags |= IDE_HFLAG_FORCE_LEGACY_IRQS;
+#endif
+
+       d.udma_mask = via_config->udma_mask;
+
+       return ide_setup_pci_device(dev, &d);
 }
 
 static const struct pci_device_id via_pci_tbl[] = {
        { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C576_1),  0 },
        { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C586_1),  0 },
+       { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_CX700_IDE), 0 },
        { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_6410),      1 },
        { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_SATA_EIDE), 1 },
        { 0, },