ide: add IDE_HFLAG_SERIALIZE_DMA host flag
[safe/jmp/linux-2.6] / drivers / ide / pci / alim15x3.c
index 0b65a2c..5261f30 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * linux/drivers/ide/pci/alim15x3.c            Version 0.29    Sep 16 2007
- *
  *  Copyright (C) 1998-2000 Michel Aubry, Maintainer
  *  Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
  *  Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
@@ -33,7 +31,6 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/hdreg.h>
 #include <linux/ide.h>
 #include <linux/init.h>
@@ -293,7 +290,7 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
 static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
        ide_hwif_t *hwif = HWIF(drive);
-       struct pci_dev *dev = hwif->pci_dev;
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        int s_time, a_time, c_time;
        u8 s_clc, a_clc, r_clc;
        unsigned long flags;
@@ -396,7 +393,7 @@ static u8 ali_udma_filter(ide_drive_t *drive)
 static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev     = to_pci_dev(hwif->dev);
        u8 speed1               = speed;
        u8 unit                 = (drive->select.b.unit & 0x01);
        u8 tmpbyte              = 0x00;
@@ -613,7 +610,7 @@ static int ali_cable_override(struct pci_dev *pdev)
 }
 
 /**
- *     ata66_ali15x3   -       check for UDMA 66 support
+ *     ali_cable_detect        -       cable detection
  *     @hwif: IDE interface
  *
  *     This checks if the controller and the cable are capable
@@ -623,9 +620,9 @@ static int ali_cable_override(struct pci_dev *pdev)
  *     FIXME: frobs bits that are not defined on newer ALi devicea
  */
 
-static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif)
+static u8 __devinit ali_cable_detect(ide_hwif_t *hwif)
 {
-       struct pci_dev *dev     = hwif->pci_dev;
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        unsigned long flags;
        u8 cbl = ATA_CBL_PATA40, tmpbyte;
 
@@ -664,17 +661,10 @@ static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif)
  
 static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
 {
-       hwif->set_pio_mode = &ali_set_pio_mode;
-       hwif->set_dma_mode = &ali_set_dma_mode;
-       hwif->udma_filter = &ali_udma_filter;
-
        if (hwif->dma_base == 0)
                return;
 
        hwif->dma_setup = &ali15x3_dma_setup;
-
-       if (hwif->cbl != ATA_CBL_PATA40_SHORT)
-               hwif->cbl = ata66_ali15x3(hwif);
 }
 
 /**
@@ -688,12 +678,13 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
 
 static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
 {
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
        u8 ideic, inmir;
        s8 irq_routing_table[] = { -1,  9, 3, 10, 4,  5, 7,  6,
                                      1, 11, 0, 12, 0, 14, 0, 15 };
        int irq = -1;
 
-       if (hwif->pci_dev->device == PCI_DEVICE_ID_AL_M5229)
+       if (dev->device == PCI_DEVICE_ID_AL_M5229)
                hwif->irq = hwif->channel ? 15 : 14;
 
        if (isa_dev) {
@@ -732,28 +723,47 @@ static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
 /**
  *     init_dma_ali15x3        -       set up DMA on ALi15x3
  *     @hwif: IDE interface
- *     @dmabase: DMA interface base PCI address
+ *     @d: IDE port info
  *
- *     Set up the DMA functionality on the ALi 15x3. For the ALi
- *     controllers this is generic so we can let the generic code do
- *     the actual work.
+ *     Set up the DMA functionality on the ALi 15x3.
  */
 
-static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
+static int __devinit init_dma_ali15x3(ide_hwif_t *hwif,
+                                     const struct ide_port_info *d)
 {
-       if (m5229_revision < 0x20)
-               return;
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+       unsigned long base = ide_pci_dma_base(hwif, d);
+
+       if (base == 0 || ide_pci_set_master(dev, d->name) < 0)
+               return -1;
+
        if (!hwif->channel)
-               outb(inb(dmabase + 2) & 0x60, dmabase + 2);
-       ide_setup_dma(hwif, dmabase);
+               outb(inb(base + 2) & 0x60, base + 2);
+
+       printk(KERN_INFO "    %s: BM-DMA at 0x%04lx-0x%04lx\n",
+                        hwif->name, base, base + 7);
+
+       if (ide_allocate_dma_engine(hwif))
+               return -1;
+
+       ide_setup_dma(hwif, base);
+
+       return 0;
 }
 
+static const struct ide_port_ops ali_port_ops = {
+       .set_pio_mode           = ali_set_pio_mode,
+       .set_dma_mode           = ali_set_dma_mode,
+       .udma_filter            = ali_udma_filter,
+       .cable_detect           = ali_cable_detect,
+};
+
 static const struct ide_port_info ali15x3_chipset __devinitdata = {
        .name           = "ALI15X3",
        .init_chipset   = init_chipset_ali15x3,
        .init_hwif      = init_hwif_ali15x3,
        .init_dma       = init_dma_ali15x3,
-       .host_flags     = IDE_HFLAG_BOOTABLE,
+       .port_ops       = &ali_port_ops,
        .pio_mask       = ATA_PIO5,
        .swdma_mask     = ATA_SWDMA2,
        .mwdma_mask     = ATA_MWDMA2,
@@ -796,6 +806,10 @@ static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_dev
                        d.udma_mask = ATA_UDMA5;
                else
                        d.udma_mask = ATA_UDMA6;
+       } else {
+               d.host_flags |= IDE_HFLAG_NO_DMA;
+
+               d.mwdma_mask = d.swdma_mask = 0;
        }
 
        if (idx == 0)