ide: add IDE_HFLAG_CLEAR_SIMPLEX host flag
[pandora-kernel.git] / drivers / ide / pci / serverworks.c
index 49ec0ac..bf01c38 100644 (file)
@@ -97,6 +97,7 @@ static u8 svwks_udma_filter(ide_drive_t *drive)
                        mode = 2;
 
                switch(mode) {
+               case 3:  mask = 0x3f; break;
                case 2:  mask = 0x1f; break;
                case 1:  mask = 0x07; break;
                default: mask = 0x00; break;
@@ -157,57 +158,24 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
        u8 ultra_enable  = 0, ultra_timing = 0, dma_timing = 0;
 
-       /* If we are about to put a disk into UDMA mode we screwed up.
-          Our code assumes we never _ever_ do this on an OSB4 */
-          
-       if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 &&
-               drive->media == ide_disk && speed >= XFER_UDMA_0)
-                       BUG();
-
        pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
        pci_read_config_byte(dev, 0x54, &ultra_enable);
 
        ultra_timing    &= ~(0x0F << (4*unit));
        ultra_enable    &= ~(0x01 << drive->dn);
 
-       switch(speed) {
-               case XFER_MW_DMA_2:
-               case XFER_MW_DMA_1:
-               case XFER_MW_DMA_0:
-                       dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
-                       break;
-
-               case XFER_UDMA_5:
-               case XFER_UDMA_4:
-               case XFER_UDMA_3:
-               case XFER_UDMA_2:
-               case XFER_UDMA_1:
-               case XFER_UDMA_0:
-                       dma_timing   |= dma_modes[2];
-                       ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
-                       ultra_enable |= (0x01 << drive->dn);
-               default:
-                       break;
-       }
+       if (speed >= XFER_UDMA_0) {
+               dma_timing   |= dma_modes[2];
+               ultra_timing |= (udma_modes[speed - XFER_UDMA_0] << (4 * unit));
+               ultra_enable |= (0x01 << drive->dn);
+       } else if (speed >= XFER_MW_DMA_0)
+               dma_timing   |= dma_modes[speed - XFER_MW_DMA_0];
 
        pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
        pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
        pci_write_config_byte(dev, 0x54, ultra_enable);
 }
 
-static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
-{
-       drive->init_speed = 0;
-
-       if (ide_tune_dma(drive))
-               return 0;
-
-       if (ide_use_fast_pio(drive))
-               ide_set_max_pio(drive);
-
-       return -1;
-}
-
 static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
 {
        unsigned int reg;
@@ -372,105 +340,65 @@ static u8 __devinit ata66_svwks(ide_hwif_t *hwif)
 
 static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
 {
-       if (!hwif->irq)
-               hwif->irq = hwif->channel ? 15 : 14;
-
        hwif->set_pio_mode = &svwks_set_pio_mode;
        hwif->set_dma_mode = &svwks_set_dma_mode;
        hwif->udma_filter = &svwks_udma_filter;
 
-       hwif->atapi_dma = 1;
-
-       if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
-               hwif->ultra_mask = 0x3f;
-
-       hwif->mwdma_mask = 0x07;
-
-       hwif->autodma = 0;
-
-       hwif->drives[0].autotune = 1;
-       hwif->drives[1].autotune = 1;
-
        if (!hwif->dma_base)
                return;
 
-       hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
        if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
                if (hwif->cbl != ATA_CBL_PATA40_SHORT)
                        hwif->cbl = ata66_svwks(hwif);
        }
-       if (!noautodma)
-               hwif->autodma = 1;
-
-       hwif->drives[0].autodma = hwif->drives[1].autodma = 1;
-}
-
-static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
-{
-       return ide_setup_pci_device(dev, d);
 }
 
-static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
-{
-       if (!(PCI_FUNC(dev->devfn) & 1)) {
-               d->bootable = NEVER_BOARD;
-               if (dev->resource[0].start == 0x01f1)
-                       d->bootable = ON_BOARD;
-       }
-
-       if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
-           dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
-           (!(PCI_FUNC(dev->devfn) & 1)))
-               d->host_flags |= IDE_HFLAG_SINGLE;
-       else
-               d->host_flags &= ~IDE_HFLAG_SINGLE;
+#define IDE_HFLAGS_SVWKS \
+       (IDE_HFLAG_LEGACY_IRQS | \
+        IDE_HFLAG_ABUSE_SET_DMA_MODE | \
+        IDE_HFLAG_BOOTABLE)
 
-       return ide_setup_pci_device(dev, d);
-}
-
-static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
+static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
        {       /* 0 */
                .name           = "SvrWks OSB4",
-               .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAGS_SVWKS,
                .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = 0x00, /* UDMA is problematic on OSB4 */
        },{     /* 1 */
                .name           = "SvrWks CSB5",
-               .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAGS_SVWKS,
                .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        },{     /* 2 */
                .name           = "SvrWks CSB6",
-               .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAGS_SVWKS,
                .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        },{     /* 3 */
                .name           = "SvrWks CSB6",
-               .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
-               .host_flags     = IDE_HFLAG_SINGLE,
+               .host_flags     = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE,
                .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        },{     /* 4 */
                .name           = "SvrWks HT1000",
-               .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
-               .host_flags     = IDE_HFLAG_SINGLE,
+               .host_flags     = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE,
                .pio_mask       = ATA_PIO4,
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        }
 };
 
@@ -485,17 +413,31 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
  
 static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       ide_pci_device_t *d = &serverworks_chipsets[id->driver_data];
+       struct ide_port_info d;
+       u8 idx = id->driver_data;
+
+       d = serverworks_chipsets[idx];
+
+       if (idx == 1)
+               d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
+       else if (idx == 2 || idx == 3) {
+               if ((PCI_FUNC(dev->devfn) & 1) == 0) {
+                       if (pci_resource_start(dev, 0) != 0x01f1)
+                               d.host_flags &= ~IDE_HFLAG_BOOTABLE;
+                       d.host_flags |= IDE_HFLAG_SINGLE;
+               } else
+                       d.host_flags &= ~IDE_HFLAG_SINGLE;
+       }
 
-       return d->init_setup(dev, d);
+       return ide_setup_pci_device(dev, &d);
 }
 
-static struct pci_device_id svwks_pci_tbl[] = {
-       { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
-       { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
-       { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
-       { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
+static const struct pci_device_id svwks_pci_tbl[] = {
+       { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE),   0 },
+       { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE),   1 },
+       { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE),   2 },
+       { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2),  3 },
+       { PCI_VDEVICE(SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 4 },
        { 0, },
 };
 MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);