ide: limit legacy VLB host drivers to alpha, x86 and mips
[safe/jmp/linux-2.6] / drivers / ide / ppc / pmac.c
index 13e2664..88619b5 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.
  *
@@ -81,7 +80,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 */
@@ -413,50 +411,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_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
 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) {
-               /* Probably a PCI interface... */
-               for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; ++i)
-                       hw->io_ports[i] = data_port + i - IDE_DATA_OFFSET;
-               hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
-               return;
-       }
-
-       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[IDE_DATA_OFFSET] + (x)))
 
 /*
  * Apply the timings of the proper unit (master/slave) to the shared
@@ -530,88 +493,12 @@ pmac_outbsync(ide_drive_t *drive, u8 value, unsigned long port)
 }
 
 /*
- * Send the SET_FEATURE IDE command to the drive and update drive->id with
- * the new state. We currently don't use the generic routine as it used to
- * cause various trouble, especially with older mediabays.
- * This code is sometimes triggering a spurrious interrupt though, I need
- * to sort that out sooner or later and see if I can finally get the
- * common version to work properly in all cases
- */
-static int
-pmac_ide_do_setfeature(ide_drive_t *drive, u8 command)
-{
-       ide_hwif_t *hwif = HWIF(drive);
-       int result;
-       u8 stat;
-       
-       disable_irq_nosync(hwif->irq);
-       udelay(1);
-       SELECT_DRIVE(drive);
-       SELECT_MASK(drive, 0);
-       udelay(1);
-       hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG);
-       hwif->OUTB(command, IDE_NSECTOR_REG);
-       hwif->OUTB(SETFEATURES_XFER, IDE_FEATURE_REG);
-       hwif->OUTBSYNC(drive, WIN_SETFEATURES, IDE_COMMAND_REG);
-       result = __ide_wait_stat(drive, drive->ready_stat,
-                                BUSY_STAT|DRQ_STAT|ERR_STAT,
-                                WAIT_CMD, &stat);
-       hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
-       if (result)
-               printk(KERN_ERR "%s: pmac_ide_do_setfeature disk not ready "
-                       "after SET_FEATURE !\n", drive->name);
-
-       SELECT_MASK(drive, 0);
-       if (result == 0) {
-               drive->id->dma_ultra &= ~0xFF00;
-               drive->id->dma_mword &= ~0x0F00;
-               drive->id->dma_1word &= ~0x0F00;
-               switch(command) {
-                       case XFER_UDMA_7:
-                               drive->id->dma_ultra |= 0x8080; break;
-                       case XFER_UDMA_6:
-                               drive->id->dma_ultra |= 0x4040; break;
-                       case XFER_UDMA_5:
-                               drive->id->dma_ultra |= 0x2020; break;
-                       case XFER_UDMA_4:
-                               drive->id->dma_ultra |= 0x1010; break;
-                       case XFER_UDMA_3:
-                               drive->id->dma_ultra |= 0x0808; break;
-                       case XFER_UDMA_2:
-                               drive->id->dma_ultra |= 0x0404; break;
-                       case XFER_UDMA_1:
-                               drive->id->dma_ultra |= 0x0202; break;
-                       case XFER_UDMA_0:
-                               drive->id->dma_ultra |= 0x0101; break;
-                       case XFER_MW_DMA_2:
-                               drive->id->dma_mword |= 0x0404; break;
-                       case XFER_MW_DMA_1:
-                               drive->id->dma_mword |= 0x0202; break;
-                       case XFER_MW_DMA_0:
-                               drive->id->dma_mword |= 0x0101; break;
-                       case XFER_SW_DMA_2:
-                               drive->id->dma_1word |= 0x0404; break;
-                       case XFER_SW_DMA_1:
-                               drive->id->dma_1word |= 0x0202; break;
-                       case XFER_SW_DMA_0:
-                               drive->id->dma_1word |= 0x0101; break;
-                       default: break;
-               }
-               if (!drive->init_speed)
-                       drive->init_speed = command;
-               drive->current_speed = command;
-       }
-       enable_irq(hwif->irq);
-       return result;
-}
-
-/*
  * Old tuning functions (called on hdparm -p), sets up drive PIO timings
  */
 static void
 pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
-       u32 *timings;
+       u32 *timings, t;
        unsigned accessTicks, recTicks;
        unsigned accessTime, recTime;
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -622,6 +509,7 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
                
        /* which drive is it ? */
        timings = &pmif->timings[drive->select.b.unit & 0x01];
+       t = *timings;
 
        cycle_time = ide_pio_cycle_time(drive, pio);
 
@@ -629,14 +517,14 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
        case controller_sh_ata6: {
                /* 133Mhz cell */
                u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time);
-               *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr;
+               t = (t & ~TR_133_PIOREG_PIO_MASK) | tr;
                break;
                }
        case controller_un_ata6:
        case controller_k2_ata6: {
                /* 100Mhz cell */
                u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time);
-               *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr;
+               t = (t & ~TR_100_PIOREG_PIO_MASK) | tr;
                break;
                }
        case controller_kl_ata4:
@@ -650,9 +538,9 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
                accessTicks = min(accessTicks, 0x1fU);
                recTicks = SYSCLK_TICKS_66(recTime);
                recTicks = min(recTicks, 0x1fU);
-               *timings = ((*timings) & ~TR_66_PIO_MASK) |
-                               (accessTicks << TR_66_PIO_ACCESS_SHIFT) |
-                               (recTicks << TR_66_PIO_RECOVERY_SHIFT);
+               t = (t & ~TR_66_PIO_MASK) |
+                       (accessTicks << TR_66_PIO_ACCESS_SHIFT) |
+                       (recTicks << TR_66_PIO_RECOVERY_SHIFT);
                break;
        default: {
                /* 33Mhz cell */
@@ -672,11 +560,11 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
                        recTicks--; /* guess, but it's only for PIO0, so... */
                        ebit = 1;
                }
-               *timings = ((*timings) & ~TR_33_PIO_MASK) |
+               t = (t & ~TR_33_PIO_MASK) |
                                (accessTicks << TR_33_PIO_ACCESS_SHIFT) |
                                (recTicks << TR_33_PIO_RECOVERY_SHIFT);
                if (ebit)
-                       *timings |= TR_33_PIO_E;
+                       t |= TR_33_PIO_E;
                break;
                }
        }
@@ -686,9 +574,7 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
                drive->name, pio,  *timings);
 #endif 
 
-       if (pmac_ide_do_setfeature(drive, XFER_PIO_0 + pio))
-               return;
-
+       *timings = t;
        pmac_ide_do_update_timings(drive);
 }
 
@@ -896,11 +782,7 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
 }
 #endif /* #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC */
 
-/* 
- * Speedproc. This function is called by the core to set any of the standard
- * DMA timing (MDMA or UDMA) to both the drive and the controller.
- */
-static int pmac_ide_tune_chipset(ide_drive_t *drive, const u8 speed)
+static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
 {
        int unit = (drive->select.b.unit & 0x01);
        int ret = 0;
@@ -914,52 +796,28 @@ static int pmac_ide_tune_chipset(ide_drive_t *drive, const u8 speed)
        tl[0] = *timings;
        tl[1] = *timings2;
 
-       switch(speed) {
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
-               case XFER_UDMA_6:
-               case XFER_UDMA_5:
-               case XFER_UDMA_4:
-               case XFER_UDMA_3:
-               case XFER_UDMA_2:
-               case XFER_UDMA_1:
-               case XFER_UDMA_0:
-                       if (pmif->kind == controller_kl_ata4)
-                               ret = set_timings_udma_ata4(&tl[0], speed);
-                       else if (pmif->kind == controller_un_ata6
-                                || pmif->kind == controller_k2_ata6)
-                               ret = set_timings_udma_ata6(&tl[0], &tl[1], speed);
-                       else if (pmif->kind == controller_sh_ata6)
-                               ret = set_timings_udma_shasta(&tl[0], &tl[1], speed);
-                       else
-                               ret = 1;
-                       break;
-               case XFER_MW_DMA_2:
-               case XFER_MW_DMA_1:
-               case XFER_MW_DMA_0:
-                       set_timings_mdma(drive, pmif->kind, &tl[0], &tl[1], speed);
-                       break;
-               case XFER_SW_DMA_2:
-               case XFER_SW_DMA_1:
-               case XFER_SW_DMA_0:
-                       return 1;
+       if (speed >= XFER_UDMA_0) {
+               if (pmif->kind == controller_kl_ata4)
+                       ret = set_timings_udma_ata4(&tl[0], speed);
+               else if (pmif->kind == controller_un_ata6
+                        || pmif->kind == controller_k2_ata6)
+                       ret = set_timings_udma_ata6(&tl[0], &tl[1], speed);
+               else if (pmif->kind == controller_sh_ata6)
+                       ret = set_timings_udma_shasta(&tl[0], &tl[1], speed);
+               else
+                       ret = -1;
+       } else
+               set_timings_mdma(drive, pmif->kind, &tl[0], &tl[1], speed);
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
-               default:
-                       ret = 1;
-       }
        if (ret)
-               return ret;
-
-       ret = pmac_ide_do_setfeature(drive, speed);
-       if (ret)
-               return ret;
+               return;
 
        /* Apply timings to controller */
        *timings = tl[0];
        *timings2 = tl[1];
 
        pmac_ide_do_update_timings(drive);      
-
-       return 0;
 }
 
 /*
@@ -997,58 +855,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
  */
@@ -1114,6 +920,17 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
        return 0;
 }
 
+static const struct ide_port_info pmac_port_info = {
+       .chipset                = ide_pmac,
+       .host_flags             = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
+                                 IDE_HFLAG_PIO_NO_DOWNGRADE |
+                                 IDE_HFLAG_POST_SET_MODE |
+                                 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 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
@@ -1121,28 +938,34 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
  * (it is kept in 2.4). This introduce an interface numbering change on some
  * rare machines unfortunately, but it's better this way.
  */
-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 };
+       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.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.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.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.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;
        }
@@ -1182,7 +1005,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)
@@ -1211,15 +1035,9 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        /* Tell common code _not_ to mess with resources */
        hwif->mmio = 1;
        hwif->hwif_data = pmif;
-       pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq);
-       memcpy(hwif->io_ports, hwif->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;
+       ide_init_port_hw(hwif, hw);
+       hwif->noprobe = pmif->mediabay;
        hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
-       hwif->drives[0].unmask = 1;
-       hwif->drives[1].unmask = 1;
-       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
@@ -1227,7 +1045,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
                hwif->selectproc = pmac_ide_kauai_selectproc;
        else
                hwif->selectproc = pmac_ide_selectproc;
-       hwif->speedproc = pmac_ide_tune_chipset;
+       hwif->set_dma_mode = pmac_ide_set_dma_mode;
 
        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,
@@ -1238,22 +1056,30 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
                hwif->noprobe = 0;
 #endif /* CONFIG_PMAC_MEDIABAY */
 
-       hwif->sg_max_nents = MAX_DCMDS;
-
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
+       if (pmif->cable_80 == 0)
+               d.udma_mask &= ATA_UDMA2;
        /* has a DBDMA controller channel */
-       if (pmif->dma_regs)
-               pmac_ide_setup_dma(pmif, hwif);
-#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+       if (pmif->dma_regs == 0 || pmac_ide_setup_dma(pmif, hwif) < 0)
+#endif
+               d.udma_mask = d.mwdma_mask = 0;
 
-       /* We probe the hwif now */
-       probe_hwif_init(hwif);
+       idx[0] = hwif->index;
 
-       ide_proc_register_port(hwif);
+       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[i] = base + i * 0x10;
+       hw->io_ports[8] = base + 0x160;
+}
+
 /*
  * Attach to a macio probed interface
  */
@@ -1266,6 +1092,7 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
        ide_hwif_t *hwif;
        pmac_ide_hwif_t *pmif;
        int i, rc;
+       hw_regs_t hw;
 
        i = 0;
        while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0
@@ -1307,8 +1134,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;
@@ -1326,17 +1152,22 @@ 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);
+                       macio_release_resource(mdev, 1);
+               }
                memset(pmif, 0, sizeof(*pmif));
                macio_release_resource(mdev, 0);
-               if (pmif->dma_regs)
-                       macio_release_resource(mdev, 1);
        }
 
        return rc;
@@ -1349,7 +1180,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;
@@ -1385,6 +1216,7 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        void __iomem *base;
        unsigned long rbase, rlen;
        int i, rc;
+       hw_regs_t hw;
 
        np = pci_device_to_OF_node(pdev);
        if (np == NULL) {
@@ -1417,8 +1249,7 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
                return -ENXIO;
        }
 
-       hwif->pci_dev = pdev;
-       hwif->gendev.parent = &pdev->dev;
+       hwif->dev = &pdev->dev;
        pmif->mdev = NULL;
        pmif->node = np;
 
@@ -1435,7 +1266,12 @@ 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);
@@ -1454,7 +1290,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;
@@ -1504,17 +1340,12 @@ static struct macio_driver pmac_ide_macio_driver =
        .resume         = pmac_ide_macio_resume,
 };
 
-static struct pci_device_id pmac_ide_pci_match[] = {
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_SH_ATA,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+static const struct pci_device_id pmac_ide_pci_match[] = {
+       { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA),    0 },
+       { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100),  0 },
+       { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100),    0 },
+       { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_SH_ATA),       0 },
+       { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA),    0 },
        {},
 };
 
@@ -1598,7 +1429,7 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
 
                if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) {
                        if (pmif->broken_dma_warn == 0) {
-                               printk(KERN_WARNING "%s: DMA on non aligned address,"
+                               printk(KERN_WARNING "%s: DMA on non aligned address, "
                                       "switching to PIO on Ohare chipset\n", drive->name);
                                pmif->broken_dma_warn = 1;
                        }
@@ -1622,7 +1453,7 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
                        cur_len -= tc;
                        ++table;
                }
-               sg++;
+               sg = sg_next(sg);
                i--;
        }
 
@@ -1638,11 +1469,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 */
 }
 
@@ -1651,44 +1481,14 @@ 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;
        }
 }
 
 /*
- * Check what is the best DMA timing setting for the drive and
- * call appropriate functions to apply it.
- */
-static int
-pmac_ide_dma_check(ide_drive_t *drive)
-{
-       int enable = 1;
-
-       drive->using_dma = 0;
-       
-       if (drive->media == ide_floppy)
-               enable = 0;
-       if ((drive->id->capability & 1) == 0 && !__ide_dma_good_drive(drive))
-               enable = 0;
-       if (__ide_dma_bad_drive(drive))
-               enable = 0;
-
-       if (enable) {
-               u8 mode = ide_max_dma_mode(drive);
-
-               if (mode && pmac_ide_tune_chipset(drive, mode) == 0)
-                       drive->using_dma = 1;
-       }
-       return 0;
-}
-
-/*
  * Prepare a DMA transfer. We build the DMA table, adjust the timings for
  * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
  */
@@ -1833,11 +1633,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)
 {
 }
 
@@ -1860,66 +1656,46 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
  * 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_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 {
+       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)
+               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->ide_dma_check = &pmac_ide_dma_check;
+       hwif->sg_max_nents = MAX_DCMDS;
+
+       hwif->dma_host_set = &pmac_ide_dma_host_set;
        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->atapi_dma = 1;
-       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;
 }
 
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+
+module_init(pmac_ide_probe);
+
+MODULE_LICENSE("GPL");