Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / drivers / ide / pci / aec62xx.c
index 0d5f62c..7f4d185 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * linux/drivers/ide/pci/aec62xx.c             Version 0.24    May 24, 2007
+ * linux/drivers/ide/pci/aec62xx.c             Version 0.27    Sep 16, 2007
  *
  * Copyright (C) 1999-2002     Andre Hedrick <andre@linux-ide.org>
  * Copyright (C) 2007          MontaVista Software, Inc. <source@mvista.com>
@@ -87,7 +87,7 @@ static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entr
        return chipset_table->ultra_settings;
 }
 
-static int aec6210_tune_chipset(ide_drive_t *drive, const u8 speed)
+static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = hwif->pci_dev;
@@ -111,10 +111,9 @@ static int aec6210_tune_chipset(ide_drive_t *drive, const u8 speed)
        tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn))));
        pci_write_config_byte(dev, 0x54, tmp2);
        local_irq_restore(flags);
-       return(ide_config_drive_speed(drive, speed));
 }
 
-static int aec6260_tune_chipset(ide_drive_t *drive, const u8 speed)
+static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = hwif->pci_dev;
@@ -135,36 +134,11 @@ static int aec6260_tune_chipset(ide_drive_t *drive, const u8 speed)
        tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit))));
        pci_write_config_byte(dev, (0x44|hwif->channel), tmp2);
        local_irq_restore(flags);
-       return(ide_config_drive_speed(drive, speed));
 }
 
 static void aec_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
-       (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0);
-}
-
-static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
-{
-       if (ide_tune_dma(drive))
-               return 0;
-
-       if (ide_use_fast_pio(drive))
-               ide_set_max_pio(drive);
-
-       return -1;
-}
-
-static void aec62xx_dma_lost_irq (ide_drive_t *drive)
-{
-       switch (HWIF(drive)->pci_dev->device) {
-               case PCI_DEVICE_ID_ARTOP_ATP860:
-               case PCI_DEVICE_ID_ARTOP_ATP860R:
-               case PCI_DEVICE_ID_ARTOP_ATP865:
-               case PCI_DEVICE_ID_ARTOP_ATP865R:
-                       printk(" AEC62XX time out ");
-               default:
-                       break;
-       }
+       drive->hwif->set_dma_mode(drive, pio + XFER_PIO_0);
 }
 
 static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const char *name)
@@ -197,114 +171,83 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
 static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
 {
        struct pci_dev *dev     = hwif->pci_dev;
-       u8 reg54 = 0,  mask     = hwif->channel ? 0xf0 : 0x0f;
-       unsigned long flags;
 
        hwif->set_pio_mode = &aec_set_pio_mode;
 
-       if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
-               if(hwif->mate)
-                       hwif->mate->serialized = hwif->serialized = 1;
-               hwif->speedproc = &aec6210_tune_chipset;
-       } else
-               hwif->speedproc = &aec6260_tune_chipset;
+       if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
+               hwif->set_dma_mode = &aec6210_set_mode;
+       else
+               hwif->set_dma_mode = &aec6260_set_mode;
 
-       if (!hwif->dma_base) {
-               hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
+       if (hwif->dma_base == 0)
                return;
-       }
 
-       hwif->ultra_mask = hwif->cds->udma_mask;
-       hwif->mwdma_mask = 0x07;
-
-       hwif->ide_dma_check     = &aec62xx_config_drive_xfer_rate;
-       hwif->dma_lost_irq      = &aec62xx_dma_lost_irq;
+       if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
+               return;
 
-       if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
-               spin_lock_irqsave(&ide_lock, flags);
-               pci_read_config_byte (dev, 0x54, &reg54);
-               pci_write_config_byte(dev, 0x54, (reg54 & ~mask));
-               spin_unlock_irqrestore(&ide_lock, flags);
-       } else if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
+       if (hwif->cbl != ATA_CBL_PATA40_SHORT) {
                u8 ata66 = 0, mask = hwif->channel ? 0x02 : 0x01;
 
                pci_read_config_byte(hwif->pci_dev, 0x49, &ata66);
 
                hwif->cbl = (ata66 & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
        }
-
-       if (!noautodma)
-               hwif->autodma = 1;
-       hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
-}
-
-static int __devinit init_setup_aec62xx(struct pci_dev *dev, ide_pci_device_t *d)
-{
-       return ide_setup_pci_device(dev, d);
-}
-
-static int __devinit init_setup_aec6x80(struct pci_dev *dev, ide_pci_device_t *d)
-{
-       unsigned long dma_base = pci_resource_start(dev, 4);
-
-       if (inb(dma_base + 2) & 0x10) {
-               d->name = (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R) ?
-                         "AEC6880R" : "AEC6880";
-               d->udma_mask = 0x7f; /* udma0-6 */
-       }
-
-       return ide_setup_pci_device(dev, d);
 }
 
-static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
+static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
        {       /* 0 */
                .name           = "AEC6210",
-               .init_setup     = init_setup_aec62xx,
                .init_chipset   = init_chipset_aec62xx,
                .init_hwif      = init_hwif_aec62xx,
-               .autodma        = AUTODMA,
                .enablebits     = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
-               .bootable       = OFF_BOARD,
+               .host_flags     = IDE_HFLAG_SERIALIZE |
+                                 IDE_HFLAG_NO_ATAPI_DMA |
+                                 IDE_HFLAG_ABUSE_SET_DMA_MODE |
+                                 IDE_HFLAG_OFF_BOARD,
                .pio_mask       = ATA_PIO4,
-               .udma_mask      = 0x07, /* udma0-2 */
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA2,
        },{     /* 1 */
                .name           = "AEC6260",
-               .init_setup     = init_setup_aec62xx,
                .init_chipset   = init_chipset_aec62xx,
                .init_hwif      = init_hwif_aec62xx,
-               .autodma        = NOAUTODMA,
-               .bootable       = OFF_BOARD,
+               .host_flags     = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_NO_AUTODMA |
+                                 IDE_HFLAG_ABUSE_SET_DMA_MODE |
+                                 IDE_HFLAG_OFF_BOARD,
                .pio_mask       = ATA_PIO4,
-               .udma_mask      = 0x1f, /* udma0-4 */
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA4,
        },{     /* 2 */
                .name           = "AEC6260R",
-               .init_setup     = init_setup_aec62xx,
                .init_chipset   = init_chipset_aec62xx,
                .init_hwif      = init_hwif_aec62xx,
-               .autodma        = AUTODMA,
                .enablebits     = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
-               .bootable       = NEVER_BOARD,
+               .host_flags     = IDE_HFLAG_NO_ATAPI_DMA |
+                                 IDE_HFLAG_ABUSE_SET_DMA_MODE,
                .pio_mask       = ATA_PIO4,
-               .udma_mask      = 0x1f, /* udma0-4 */
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA4,
        },{     /* 3 */
                .name           = "AEC6280",
-               .init_setup     = init_setup_aec6x80,
                .init_chipset   = init_chipset_aec62xx,
                .init_hwif      = init_hwif_aec62xx,
-               .autodma        = AUTODMA,
-               .bootable       = OFF_BOARD,
+               .host_flags     = IDE_HFLAG_NO_ATAPI_DMA |
+                                 IDE_HFLAG_ABUSE_SET_DMA_MODE |
+                                 IDE_HFLAG_OFF_BOARD,
                .pio_mask       = ATA_PIO4,
-               .udma_mask      = 0x3f, /* udma0-5 */
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        },{     /* 4 */
                .name           = "AEC6280R",
-               .init_setup     = init_setup_aec6x80,
                .init_chipset   = init_chipset_aec62xx,
                .init_hwif      = init_hwif_aec62xx,
-               .autodma        = AUTODMA,
                .enablebits     = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
-               .bootable       = OFF_BOARD,
+               .host_flags     = IDE_HFLAG_NO_ATAPI_DMA |
+                                 IDE_HFLAG_ABUSE_SET_DMA_MODE |
+                                 IDE_HFLAG_OFF_BOARD,
                .pio_mask       = ATA_PIO4,
-               .udma_mask      = 0x3f, /* udma0-5 */
+               .mwdma_mask     = ATA_MWDMA2,
+               .udma_mask      = ATA_UDMA5,
        }
 };
 
@@ -317,22 +260,43 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
  *     finds a device matching our IDE device tables.
  *
  *     NOTE: since we're going to modify the 'name' field for AEC-6[26]80[R]
- *     chips, pass a local copy of 'struct pci_device_id' down the call chain.
+ *     chips, pass a local copy of 'struct ide_port_info' down the call chain.
  */
+
 static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       ide_pci_device_t d = aec62xx_chipsets[id->driver_data];
+       struct ide_port_info d;
+       u8 idx = id->driver_data;
+       int err;
+
+       err = pci_enable_device(dev);
+       if (err)
+               return err;
+
+       d = aec62xx_chipsets[idx];
+
+       if (idx == 3 || idx == 4) {
+               unsigned long dma_base = pci_resource_start(dev, 4);
+
+               if (inb(dma_base + 2) & 0x10) {
+                       d.name = (idx == 4) ? "AEC6880R" : "AEC6880";
+                       d.udma_mask = ATA_UDMA6;
+               }
+       }
+
+       err = ide_setup_pci_device(dev, &d);
+       if (err)
+               pci_disable_device(dev);
 
-       return d.init_setup(dev, &d);
+       return err;
 }
 
-static struct pci_device_id aec62xx_pci_tbl[] = {
-       { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-       { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860,   PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
-       { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
-       { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865,   PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
-       { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R,  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
+static const struct pci_device_id aec62xx_pci_tbl[] = {
+       { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF), 0 },
+       { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP860),   1 },
+       { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R),  2 },
+       { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP865),   3 },
+       { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R),  4 },
        { 0, },
 };
 MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);