Merge branch 'linus' into tracing/mmiotrace
[firefly-linux-kernel-4.4.55.git] / drivers / ide / ppc / pmac.c
index 3dce80092fff0e32cb539cffc151337f047d4f79..ba2d58727964f2bfa6a527b683535035da2da3b1 100644 (file)
@@ -1,7 +1,6 @@
 /*
- * linux/drivers/ide/ppc/pmac.c
- *
  * Support for IDE interfaces on PowerMacs.
+ *
  * These IDE interfaces are memory-mapped and have a DBDMA channel
  * for doing DMA.
  *
@@ -60,7 +59,6 @@ typedef struct pmac_ide_hwif {
        int                             irq;
        int                             kind;
        int                             aapl_bus_id;
-       unsigned                        cable_80 : 1;
        unsigned                        mediabay : 1;
        unsigned                        broken_dma : 1;
        unsigned                        broken_dma_warn : 1;
@@ -80,9 +78,6 @@ typedef struct pmac_ide_hwif {
        
 } pmac_ide_hwif_t;
 
-static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
-static int pmac_ide_count;
-
 enum {
        controller_ohare,       /* OHare based */
        controller_heathrow,    /* Heathrow/Paddington */
@@ -413,45 +408,15 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
  */
 #define IDE_WAKEUP_DELAY       (1*HZ)
 
-static void pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
+static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *);
 static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
 static void pmac_ide_selectproc(ide_drive_t *drive);
 static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
 
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
 
-/*
- * N.B. this can't be an initfunc, because the media-bay task can
- * call ide_[un]register at any time.
- */
-void
-pmac_ide_init_hwif_ports(hw_regs_t *hw,
-                             unsigned long data_port, unsigned long ctrl_port,
-                             int *irq)
-{
-       int i, ix;
-
-       if (data_port == 0)
-               return;
-
-       for (ix = 0; ix < MAX_HWIFS; ++ix)
-               if (data_port == pmac_ide[ix].regbase)
-                       break;
-
-       if (ix >= MAX_HWIFS)
-               return;         /* not an IDE PMAC interface */
-
-       for (i = 0; i < 8; ++i)
-               hw->io_ports[i] = data_port + i * 0x10;
-       hw->io_ports[8] = data_port + 0x160;
-
-       if (irq != NULL)
-               *irq = pmac_ide[ix].irq;
-
-       hw->dev = &pmac_ide[ix].mdev->ofdev.dev;
-}
-
-#define PMAC_IDE_REG(x) ((void __iomem *)(IDE_DATA_REG+(x)))
+#define PMAC_IDE_REG(x) \
+       ((void __iomem *)((drive)->hwif->io_ports.data_addr + (x)))
 
 /*
  * Apply the timings of the proper unit (master/slave) to the shared
@@ -887,58 +852,6 @@ sanitize_timings(pmac_ide_hwif_t *pmif)
        pmif->timings[2] = pmif->timings[3] = value2;
 }
 
-unsigned long
-pmac_ide_get_base(int index)
-{
-       return pmac_ide[index].regbase;
-}
-
-int
-pmac_ide_check_base(unsigned long base)
-{
-       int ix;
-       
-       for (ix = 0; ix < MAX_HWIFS; ++ix)
-               if (base == pmac_ide[ix].regbase)
-                       return ix;
-       return -1;
-}
-
-int
-pmac_ide_get_irq(unsigned long base)
-{
-       int ix;
-
-       for (ix = 0; ix < MAX_HWIFS; ++ix)
-               if (base == pmac_ide[ix].regbase)
-                       return pmac_ide[ix].irq;
-       return 0;
-}
-
-static int ide_majors[] = { 3, 22, 33, 34, 56, 57 };
-
-dev_t __init
-pmac_find_ide_boot(char *bootdevice, int n)
-{
-       int i;
-       
-       /*
-        * Look through the list of IDE interfaces for this one.
-        */
-       for (i = 0; i < pmac_ide_count; ++i) {
-               char *name;
-               if (!pmac_ide[i].node || !pmac_ide[i].node->full_name)
-                       continue;
-               name = pmac_ide[i].node->full_name;
-               if (memcmp(name, bootdevice, n) == 0 && name[n] == 0) {
-                       /* XXX should cope with the 2nd drive as well... */
-                       return MKDEV(ide_majors[i], 0);
-               }
-       }
-
-       return 0;
-}
-
 /* Suspend call back, should be called after the child devices
  * have actually been suspended
  */
@@ -1004,37 +917,100 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
        return 0;
 }
 
+static u8 pmac_ide_cable_detect(ide_hwif_t *hwif)
+{
+       pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)ide_get_hwifdata(hwif);
+       struct device_node *np = pmif->node;
+       const char *cable = of_get_property(np, "cable-type", NULL);
+
+       /* Get cable type from device-tree. */
+       if (cable && !strncmp(cable, "80-", 3))
+               return ATA_CBL_PATA80;
+
+       /*
+        * G5's seem to have incorrect cable type in device-tree.
+        * Let's assume they have a 80 conductor cable, this seem
+        * to be always the case unless the user mucked around.
+        */
+       if (of_device_is_compatible(np, "K2-UATA") ||
+           of_device_is_compatible(np, "shasta-ata"))
+               return ATA_CBL_PATA80;
+
+       return ATA_CBL_PATA40;
+}
+
+static const struct ide_port_ops pmac_ide_ata6_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_kauai_selectproc,
+       .cable_detect           = pmac_ide_cable_detect,
+};
+
+static const struct ide_port_ops pmac_ide_ata4_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_selectproc,
+       .cable_detect           = pmac_ide_cable_detect,
+};
+
+static const struct ide_port_ops pmac_ide_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_selectproc,
+};
+
+static const struct ide_dma_ops pmac_dma_ops;
+
+static const struct ide_port_info pmac_port_info = {
+       .init_dma               = pmac_ide_init_dma,
+       .chipset                = ide_pmac,
+#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
+       .dma_ops                = &pmac_dma_ops,
+#endif
+       .port_ops               = &pmac_ide_port_ops,
+       .host_flags             = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
+                                 IDE_HFLAG_POST_SET_MODE |
+                                 IDE_HFLAG_MMIO |
+                                 IDE_HFLAG_UNMASK_IRQS,
+       .pio_mask               = ATA_PIO4,
+       .mwdma_mask             = ATA_MWDMA2,
+};
+
 /*
  * Setup, register & probe an IDE channel driven by this driver, this is
- * called by one of the 2 probe functions (macio or PCI). Note that a channel
- * that ends up beeing free of any device is not kept around by this driver
- * (it is kept in 2.4). This introduce an interface numbering change on some
- * rare machines unfortunately, but it's better this way.
+ * called by one of the 2 probe functions (macio or PCI).
  */
-static int
-pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
+static int __devinit
+pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
 {
        struct device_node *np = pmif->node;
        const int *bidp;
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
-       hw_regs_t hw;
+       struct ide_port_info d = pmac_port_info;
 
-       pmif->cable_80 = 0;
        pmif->broken_dma = pmif->broken_dma_warn = 0;
-       if (of_device_is_compatible(np, "shasta-ata"))
+       if (of_device_is_compatible(np, "shasta-ata")) {
                pmif->kind = controller_sh_ata6;
-       else if (of_device_is_compatible(np, "kauai-ata"))
+               d.port_ops = &pmac_ide_ata6_port_ops;
+               d.udma_mask = ATA_UDMA6;
+       } else if (of_device_is_compatible(np, "kauai-ata")) {
                pmif->kind = controller_un_ata6;
-       else if (of_device_is_compatible(np, "K2-UATA"))
+               d.port_ops = &pmac_ide_ata6_port_ops;
+               d.udma_mask = ATA_UDMA5;
+       } else if (of_device_is_compatible(np, "K2-UATA")) {
                pmif->kind = controller_k2_ata6;
-       else if (of_device_is_compatible(np, "keylargo-ata")) {
-               if (strcmp(np->name, "ata-4") == 0)
+               d.port_ops = &pmac_ide_ata6_port_ops;
+               d.udma_mask = ATA_UDMA5;
+       } else if (of_device_is_compatible(np, "keylargo-ata")) {
+               if (strcmp(np->name, "ata-4") == 0) {
                        pmif->kind = controller_kl_ata4;
-               else
+                       d.port_ops = &pmac_ide_ata4_port_ops;
+                       d.udma_mask = ATA_UDMA4;
+               } else
                        pmif->kind = controller_kl_ata3;
-       } else if (of_device_is_compatible(np, "heathrow-ata"))
+       } else if (of_device_is_compatible(np, "heathrow-ata")) {
                pmif->kind = controller_heathrow;
-       else {
+       else {
                pmif->kind = controller_ohare;
                pmif->broken_dma = 1;
        }
@@ -1042,22 +1018,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        bidp = of_get_property(np, "AAPL,bus-id", NULL);
        pmif->aapl_bus_id =  bidp ? *bidp : 0;
 
-       /* Get cable type from device-tree */
-       if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
-           || pmif->kind == controller_k2_ata6
-           || pmif->kind == controller_sh_ata6) {
-               const char* cable = of_get_property(np, "cable-type", NULL);
-               if (cable && !strncmp(cable, "80-", 3))
-                       pmif->cable_80 = 1;
-       }
-       /* G5's seem to have incorrect cable type in device-tree. Let's assume
-        * they have a 80 conductor cable, this seem to be always the case unless
-        * the user mucked around
-        */
-       if (of_device_is_compatible(np, "K2-UATA") ||
-           of_device_is_compatible(np, "shasta-ata"))
-               pmif->cable_80 = 1;
-
        /* On Kauai-type controllers, we make sure the FCR is correct */
        if (pmif->kauai_fcr)
                writel(KAUAI_FCR_UATA_MAGIC |
@@ -1074,7 +1034,8 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        if (np->parent && np->parent->name
            && strcasecmp(np->parent->name, "media-bay") == 0) {
 #ifdef CONFIG_PMAC_MEDIABAY
-               media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index);
+               media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq,
+                                       hwif);
 #endif /* CONFIG_PMAC_MEDIABAY */
                pmif->mediabay = 1;
                if (!bidp)
@@ -1100,57 +1061,41 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        default_hwif_mmiops(hwif);
                hwif->OUTBSYNC = pmac_outbsync;
 
-       /* Tell common code _not_ to mess with resources */
-       hwif->mmio = 1;
        hwif->hwif_data = pmif;
-       memset(&hw, 0, sizeof(hw));
-       pmac_ide_init_hwif_ports(&hw, pmif->regbase, 0, &hwif->irq);
-       memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports));
-       hwif->chipset = ide_pmac;
-       hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET] || pmif->mediabay;
-       hwif->hold = pmif->mediabay;
-       hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
-       hwif->drives[0].unmask = 1;
-       hwif->drives[1].unmask = 1;
-       hwif->drives[0].autotune = IDE_TUNE_AUTO;
-       hwif->drives[1].autotune = IDE_TUNE_AUTO;
-       hwif->host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
-                          IDE_HFLAG_PIO_NO_DOWNGRADE |
-                          IDE_HFLAG_POST_SET_MODE;
-       hwif->pio_mask = ATA_PIO4;
-       hwif->set_pio_mode = pmac_ide_set_pio_mode;
-       if (pmif->kind == controller_un_ata6
-           || pmif->kind == controller_k2_ata6
-           || pmif->kind == controller_sh_ata6)
-               hwif->selectproc = pmac_ide_kauai_selectproc;
-       else
-               hwif->selectproc = pmac_ide_selectproc;
-       hwif->set_dma_mode = pmac_ide_set_dma_mode;
+       ide_init_port_hw(hwif, hw);
 
        printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
               hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
               pmif->mediabay ? " (mediabay)" : "", hwif->irq);
-                       
-#ifdef CONFIG_PMAC_MEDIABAY
-       if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
-               hwif->noprobe = 0;
-#endif /* CONFIG_PMAC_MEDIABAY */
-
-       hwif->sg_max_nents = MAX_DCMDS;
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
-       /* has a DBDMA controller channel */
-       if (pmif->dma_regs)
-               pmac_ide_setup_dma(pmif, hwif);
-#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+       if (pmif->mediabay) {
+#ifdef CONFIG_PMAC_MEDIABAY
+               if (check_media_bay_by_base(pmif->regbase, MB_CD)) {
+#else
+               if (1) {
+#endif
+                       hwif->drives[0].noprobe = 1;
+                       hwif->drives[1].noprobe = 1;
+               }
+       }
 
        idx[0] = hwif->index;
 
-       ide_device_add(idx);
+       ide_device_add(idx, &d);
 
        return 0;
 }
 
+static void __devinit pmac_ide_init_ports(hw_regs_t *hw, unsigned long base)
+{
+       int i;
+
+       for (i = 0; i < 8; ++i)
+               hw->io_ports_array[i] = base + i * 0x10;
+
+       hw->io_ports.ctl_addr = base + 0x160;
+}
+
 /*
  * Attach to a macio probed interface
  */
@@ -1159,34 +1104,36 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
 {
        void __iomem *base;
        unsigned long regbase;
-       int irq;
        ide_hwif_t *hwif;
        pmac_ide_hwif_t *pmif;
-       int i, rc;
+       int irq, rc;
+       hw_regs_t hw;
 
-       i = 0;
-       while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0
-           || pmac_ide[i].node != NULL))
-               ++i;
-       if (i >= MAX_HWIFS) {
+       pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
+       if (pmif == NULL)
+               return -ENOMEM;
+
+       hwif = ide_find_port();
+       if (hwif == NULL) {
                printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
                printk(KERN_ERR "          %s\n", mdev->ofdev.node->full_name);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto out_free_pmif;
        }
 
-       pmif = &pmac_ide[i];
-       hwif = &ide_hwifs[i];
-
        if (macio_resource_count(mdev) == 0) {
-               printk(KERN_WARNING "ide%d: no address for %s\n",
-                      i, mdev->ofdev.node->full_name);
-               return -ENXIO;
+               printk(KERN_WARNING "ide-pmac: no address for %s\n",
+                                   mdev->ofdev.node->full_name);
+               rc = -ENXIO;
+               goto out_free_pmif;
        }
 
        /* Request memory resource for IO ports */
        if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
-               printk(KERN_ERR "ide%d: can't request mmio resource !\n", i);
-               return -EBUSY;
+               printk(KERN_ERR "ide-pmac: can't request MMIO resource for "
+                               "%s!\n", mdev->ofdev.node->full_name);
+               rc = -EBUSY;
+               goto out_free_pmif;
        }
                        
        /* XXX This is bogus. Should be fixed in the registry by checking
@@ -1195,8 +1142,8 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
         * where that happens though...
         */
        if (macio_irq_count(mdev) == 0) {
-               printk(KERN_WARNING "ide%d: no intrs for device %s, using 13\n",
-                       i, mdev->ofdev.node->full_name);
+               printk(KERN_WARNING "ide-pmac: no intrs for device %s, using "
+                                   "13\n", mdev->ofdev.node->full_name);
                irq = irq_create_mapping(NULL, 13);
        } else
                irq = macio_irq(mdev, 0);
@@ -1204,8 +1151,7 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
        base = ioremap(macio_resource_start(mdev, 0), 0x400);
        regbase = (unsigned long) base;
 
-       hwif->pci_dev = mdev->bus->pdev;
-       hwif->gendev.parent = &mdev->ofdev.dev;
+       hwif->dev = &mdev->bus->pdev->dev;
 
        pmif->mdev = mdev;
        pmif->node = mdev->ofdev.node;
@@ -1215,7 +1161,9 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
        if (macio_resource_count(mdev) >= 2) {
                if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
-                       printk(KERN_WARNING "ide%d: can't request DMA resource !\n", i);
+                       printk(KERN_WARNING "ide-pmac: can't request DMA "
+                                           "resource for %s!\n",
+                                           mdev->ofdev.node->full_name);
                else
                        pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000);
        } else
@@ -1223,20 +1171,29 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
        dev_set_drvdata(&mdev->ofdev.dev, hwif);
 
-       rc = pmac_ide_setup_device(pmif, hwif);
+       memset(&hw, 0, sizeof(hw));
+       pmac_ide_init_ports(&hw, pmif->regbase);
+       hw.irq = irq;
+       hw.dev = &mdev->ofdev.dev;
+
+       rc = pmac_ide_setup_device(pmif, hwif, &hw);
        if (rc != 0) {
                /* The inteface is released to the common IDE layer */
                dev_set_drvdata(&mdev->ofdev.dev, NULL);
                iounmap(base);
-               if (pmif->dma_regs)
+               if (pmif->dma_regs) {
                        iounmap(pmif->dma_regs);
-               memset(pmif, 0, sizeof(*pmif));
-               macio_release_resource(mdev, 0);
-               if (pmif->dma_regs)
                        macio_release_resource(mdev, 1);
+               }
+               macio_release_resource(mdev, 0);
+               kfree(pmif);
        }
 
        return rc;
+
+out_free_pmif:
+       kfree(pmif);
+       return rc;
 }
 
 static int
@@ -1246,7 +1203,7 @@ pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
        int             rc = 0;
 
        if (mesg.event != mdev->ofdev.dev.power.power_state.event
-                       && mesg.event == PM_EVENT_SUSPEND) {
+                       && (mesg.event & PM_EVENT_SLEEP)) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
                        mdev->ofdev.dev.power.power_state = mesg;
@@ -1281,41 +1238,43 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        pmac_ide_hwif_t *pmif;
        void __iomem *base;
        unsigned long rbase, rlen;
-       int i, rc;
+       int rc;
+       hw_regs_t hw;
 
        np = pci_device_to_OF_node(pdev);
        if (np == NULL) {
                printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
                return -ENODEV;
        }
-       i = 0;
-       while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0
-           || pmac_ide[i].node != NULL))
-               ++i;
-       if (i >= MAX_HWIFS) {
+
+       pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
+       if (pmif == NULL)
+               return -ENOMEM;
+
+       hwif = ide_find_port();
+       if (hwif == NULL) {
                printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
                printk(KERN_ERR "          %s\n", np->full_name);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto out_free_pmif;
        }
 
-       pmif = &pmac_ide[i];
-       hwif = &ide_hwifs[i];
-
        if (pci_enable_device(pdev)) {
-               printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n",
-                       i, np->full_name);
-               return -ENXIO;
+               printk(KERN_WARNING "ide-pmac: Can't enable PCI device for "
+                                   "%s\n", np->full_name);
+               rc = -ENXIO;
+               goto out_free_pmif;
        }
        pci_set_master(pdev);
                        
        if (pci_request_regions(pdev, "Kauai ATA")) {
-               printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n",
-                       i, np->full_name);
-               return -ENXIO;
+               printk(KERN_ERR "ide-pmac: Cannot obtain PCI resources for "
+                               "%s\n", np->full_name);
+               rc = -ENXIO;
+               goto out_free_pmif;
        }
 
-       hwif->pci_dev = pdev;
-       hwif->gendev.parent = &pdev->dev;
+       hwif->dev = &pdev->dev;
        pmif->mdev = NULL;
        pmif->node = np;
 
@@ -1332,16 +1291,25 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
 
        pci_set_drvdata(pdev, hwif);
 
-       rc = pmac_ide_setup_device(pmif, hwif);
+       memset(&hw, 0, sizeof(hw));
+       pmac_ide_init_ports(&hw, pmif->regbase);
+       hw.irq = pdev->irq;
+       hw.dev = &pdev->dev;
+
+       rc = pmac_ide_setup_device(pmif, hwif, &hw);
        if (rc != 0) {
                /* The inteface is released to the common IDE layer */
                pci_set_drvdata(pdev, NULL);
                iounmap(base);
-               memset(pmif, 0, sizeof(*pmif));
                pci_release_regions(pdev);
+               kfree(pmif);
        }
 
        return rc;
+
+out_free_pmif:
+       kfree(pmif);
+       return rc;
 }
 
 static int
@@ -1351,7 +1319,7 @@ pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
        int             rc = 0;
        
        if (mesg.event != pdev->dev.power.power_state.event
-                       && mesg.event == PM_EVENT_SUSPEND) {
+                       && (mesg.event & PM_EVENT_SLEEP)) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
                        pdev->dev.power.power_state = mesg;
@@ -1530,11 +1498,10 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
        }
 
        printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
- use_pio_instead:
-       pci_unmap_sg(hwif->pci_dev,
-                    hwif->sg_table,
-                    hwif->sg_nents,
-                    hwif->sg_dma_direction);
+
+use_pio_instead:
+       ide_destroy_dmatable(drive);
+
        return 0; /* revert to PIO for this request */
 }
 
@@ -1543,12 +1510,9 @@ static void
 pmac_ide_destroy_dmatable (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       struct pci_dev *dev = HWIF(drive)->pci_dev;
-       struct scatterlist *sg = hwif->sg_table;
-       int nents = hwif->sg_nents;
 
-       if (nents) {
-               pci_unmap_sg(dev, sg, nents, hwif->sg_dma_direction);
+       if (hwif->sg_nents) {
+               ide_destroy_dmatable(drive);
                hwif->sg_nents = 0;
        }
 }
@@ -1698,11 +1662,7 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
        return 1;
 }
 
-static void pmac_ide_dma_host_off(ide_drive_t *drive)
-{
-}
-
-static void pmac_ide_dma_host_on(ide_drive_t *drive)
+static void pmac_ide_dma_host_set(ide_drive_t *drive, int on)
 {
 }
 
@@ -1721,68 +1681,59 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
        printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
 }
 
+static const struct ide_dma_ops pmac_dma_ops = {
+       .dma_host_set           = pmac_ide_dma_host_set,
+       .dma_setup              = pmac_ide_dma_setup,
+       .dma_exec_cmd           = pmac_ide_dma_exec_cmd,
+       .dma_start              = pmac_ide_dma_start,
+       .dma_end                = pmac_ide_dma_end,
+       .dma_test_irq           = pmac_ide_dma_test_irq,
+       .dma_timeout            = ide_dma_timeout,
+       .dma_lost_irq           = pmac_ide_dma_lost_irq,
+};
+
 /*
  * Allocate the data structures needed for using DMA with an interface
  * and fill the proper list of functions pointers
  */
-static void __init 
-pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
+static int __devinit pmac_ide_init_dma(ide_hwif_t *hwif,
+                                      const struct ide_port_info *d)
 {
+       pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
+       struct pci_dev *dev = to_pci_dev(hwif->dev);
+
        /* We won't need pci_dev if we switch to generic consistent
         * DMA routines ...
         */
-       if (hwif->pci_dev == NULL)
-               return;
+       if (dev == NULL || pmif->dma_regs == 0)
+               return -ENODEV;
        /*
         * Allocate space for the DBDMA commands.
         * The +2 is +1 for the stop command and +1 to allow for
         * aligning the start address to a multiple of 16 bytes.
         */
        pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent(
-               hwif->pci_dev,
+               dev,
                (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
                &hwif->dmatable_dma);
        if (pmif->dma_table_cpu == NULL) {
                printk(KERN_ERR "%s: unable to allocate DMA command list\n",
                       hwif->name);
-               return;
+               return -ENOMEM;
        }
 
-       hwif->dma_off_quietly = &ide_dma_off_quietly;
-       hwif->ide_dma_on = &__ide_dma_on;
-       hwif->dma_setup = &pmac_ide_dma_setup;
-       hwif->dma_exec_cmd = &pmac_ide_dma_exec_cmd;
-       hwif->dma_start = &pmac_ide_dma_start;
-       hwif->ide_dma_end = &pmac_ide_dma_end;
-       hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
-       hwif->dma_host_off = &pmac_ide_dma_host_off;
-       hwif->dma_host_on = &pmac_ide_dma_host_on;
-       hwif->dma_timeout = &ide_dma_timeout;
-       hwif->dma_lost_irq = &pmac_ide_dma_lost_irq;
+       hwif->sg_max_nents = MAX_DCMDS;
 
-       switch(pmif->kind) {
-               case controller_sh_ata6:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x7f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               case controller_un_ata6:
-               case controller_k2_ata6:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x3f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               case controller_kl_ata4:
-                       hwif->ultra_mask = pmif->cable_80 ? 0x1f : 0x07;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-               default:
-                       hwif->ultra_mask = 0x00;
-                       hwif->mwdma_mask = 0x07;
-                       hwif->swdma_mask = 0x00;
-                       break;
-       }
+       return 0;
+}
+#else
+static int __devinit pmac_ide_init_dma(ide_hwif_t *hwif,
+                                      const struct ide_port_info *d)
+{
+       return -EOPNOTSUPP;
 }
-
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+
+module_init(pmac_ide_probe);
+
+MODULE_LICENSE("GPL");