ide: add IDE_HFLAG_NO_{DMA,AUTODMA} host flags
[pandora-kernel.git] / drivers / ide / pci / serverworks.c
index ed04e0c..338eee8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * linux/drivers/ide/pci/serverworks.c         Version 0.20    Jun 3 2007
+ * linux/drivers/ide/pci/serverworks.c         Version 0.22    Jun 27 2007
  *
  * Copyright (C) 1998-2000 Michel Aubry
  * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
@@ -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;
@@ -123,23 +124,39 @@ static u8 svwks_csb_check (struct pci_dev *dev)
        }
        return 0;
 }
-static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
+
+static void svwks_set_pio_mode(ide_drive_t *drive, const u8 pio)
+{
+       static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
+       static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
+
+       struct pci_dev *dev = drive->hwif->pci_dev;
+
+       pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]);
+
+       if (svwks_csb_check(dev)) {
+               u16 csb_pio = 0;
+
+               pci_read_config_word(dev, 0x4a, &csb_pio);
+
+               csb_pio &= ~(0x0f << (4 * drive->dn));
+               csb_pio |= (pio << (4 * drive->dn));
+
+               pci_write_config_word(dev, 0x4a, csb_pio);
+       }
+}
+
+static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
 {
        static const u8 udma_modes[]            = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
        static const u8 dma_modes[]             = { 0x77, 0x21, 0x20 };
-       static const u8 pio_modes[]             = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
-       static const u8 drive_pci[]             = { 0x41, 0x40, 0x43, 0x42 };
        static const u8 drive_pci2[]            = { 0x45, 0x44, 0x47, 0x46 };
 
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = hwif->pci_dev;
-       u8 speed                = ide_rate_filter(drive, xferspeed);
-       u8 pio                  = ide_get_best_pio_mode(drive, 255, 4, NULL);
        u8 unit                 = (drive->select.b.unit & 0x01);
-       u8 csb5                 = svwks_csb_check(dev);
-       u8 ultra_enable         = 0, ultra_timing = 0;
-       u8 dma_timing           = 0, pio_timing = 0;
-       u16 csb5_pio            = 0;
+
+       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 */
@@ -149,31 +166,15 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
                        BUG();
 
        pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
-       pci_read_config_word(dev, 0x4A, &csb5_pio);
        pci_read_config_byte(dev, 0x54, &ultra_enable);
 
        ultra_timing    &= ~(0x0F << (4*unit));
        ultra_enable    &= ~(0x01 << drive->dn);
-       csb5_pio        &= ~(0x0F << (4*drive->dn));
 
        switch(speed) {
-               case XFER_PIO_4:
-               case XFER_PIO_3:
-               case XFER_PIO_2:
-               case XFER_PIO_1:
-               case XFER_PIO_0:
-                       pio_timing |= pio_modes[speed - XFER_PIO_0];
-                       csb5_pio   |= ((speed - XFER_PIO_0) << (4*drive->dn));
-                       break;
-
                case XFER_MW_DMA_2:
                case XFER_MW_DMA_1:
                case XFER_MW_DMA_0:
-                       /*
-                        * TODO: always setup PIO mode so this won't be needed
-                        */
-                       pio_timing |= pio_modes[pio];
-                       csb5_pio   |= (pio << (4*drive->dn));
                        dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
                        break;
 
@@ -183,11 +184,6 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
                case XFER_UDMA_2:
                case XFER_UDMA_1:
                case XFER_UDMA_0:
-                       /*
-                        * TODO: always setup PIO mode so this won't be needed
-                        */
-                       pio_timing   |= pio_modes[pio];
-                       csb5_pio     |= (pio << (4*drive->dn));
                        dma_timing   |= dma_modes[2];
                        ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
                        ultra_enable |= (0x01 << drive->dn);
@@ -195,34 +191,9 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
                        break;
        }
 
-       pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
-       if (csb5)
-               pci_write_config_word(dev, 0x4A, csb5_pio);
-
        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);
-
-       return (ide_config_drive_speed(drive, speed));
-}
-
-static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
-{
-       pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
-       (void)svwks_tune_chipset(drive, XFER_PIO_0 + pio);
-}
-
-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))
-               svwks_tune_drive(drive, 255);
-
-       return -1;
 }
 
 static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
@@ -389,43 +360,28 @@ static u8 __devinit ata66_svwks(ide_hwif_t *hwif)
 
 static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
 {
-       u8 dma_stat = 0;
-
        if (!hwif->irq)
                hwif->irq = hwif->channel ? 15 : 14;
 
-       hwif->tuneproc = &svwks_tune_drive;
-       hwif->speedproc = &svwks_tune_chipset;
+       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) {
-               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;
-
-       dma_stat = inb(hwif->dma_status);
-       hwif->drives[0].autodma = (dma_stat & 0x20);
-       hwif->drives[1].autodma = (dma_stat & 0x40);
-       hwif->drives[0].autotune = (!(dma_stat & 0x20));
-       hwif->drives[1].autotune = (!(dma_stat & 0x40));
 }
 
 static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
@@ -436,14 +392,18 @@ static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *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;
+                       d->host_flags |= IDE_HFLAG_BOOTABLE;
+               else
+                       d->host_flags &= ~IDE_HFLAG_BOOTABLE;
        }
 
-       d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
-                       dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
-                      (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2;
+       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;
 
        return ide_setup_pci_device(dev, d);
 }
@@ -454,41 +414,36 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
                .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .channels       = 2,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAG_BOOTABLE,
+               .pio_mask       = ATA_PIO4,
        },{     /* 1 */
                .name           = "SvrWks CSB5",
                .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .channels       = 2,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAG_BOOTABLE,
+               .pio_mask       = ATA_PIO4,
        },{     /* 2 */
                .name           = "SvrWks CSB6",
                .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .channels       = 2,
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAG_BOOTABLE,
+               .pio_mask       = ATA_PIO4,
        },{     /* 3 */
                .name           = "SvrWks CSB6",
                .init_setup     = init_setup_csb6,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .channels       = 1,    /* 2 */
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAG_SINGLE | IDE_HFLAG_BOOTABLE,
+               .pio_mask       = ATA_PIO4,
        },{     /* 4 */
                .name           = "SvrWks HT1000",
                .init_setup     = init_setup_svwks,
                .init_chipset   = init_chipset_svwks,
                .init_hwif      = init_hwif_svwks,
-               .channels       = 1,    /* 2 */
-               .autodma        = AUTODMA,
-               .bootable       = ON_BOARD,
+               .host_flags     = IDE_HFLAG_SINGLE | IDE_HFLAG_BOOTABLE,
+               .pio_mask       = ATA_PIO4,
        }
 };
 
@@ -508,12 +463,12 @@ static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device
        return d->init_setup(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);