libata: disable pdev on all suspend events
[powerpc.git] / drivers / ata / libata-core.c
index ed11ee4..b71a7ef 100644 (file)
@@ -93,6 +93,10 @@ static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
 module_param(ata_probe_timeout, int, 0444);
 MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
 
+int noacpi;
+module_param(noacpi, int, 0444);
+MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
 MODULE_LICENSE("GPL");
@@ -596,56 +600,14 @@ void ata_dev_disable(struct ata_device *dev)
 {
        if (ata_dev_enabled(dev) && ata_msg_drv(dev->ap)) {
                ata_dev_printk(dev, KERN_WARNING, "disabled\n");
+               ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 |
+                                            ATA_DNXFER_QUIET);
                dev->class++;
        }
 }
 
 /**
- *     ata_pio_devchk - PATA device presence detection
- *     @ap: ATA channel to examine
- *     @device: Device to examine (starting at zero)
- *
- *     This technique was originally described in
- *     Hale Landis's ATADRVR (www.ata-atapi.com), and
- *     later found its way into the ATA/ATAPI spec.
- *
- *     Write a pattern to the ATA shadow registers,
- *     and if a device is present, it will respond by
- *     correctly storing and echoing back the
- *     ATA shadow register contents.
- *
- *     LOCKING:
- *     caller.
- */
-
-static unsigned int ata_pio_devchk(struct ata_port *ap,
-                                  unsigned int device)
-{
-       struct ata_ioports *ioaddr = &ap->ioaddr;
-       u8 nsect, lbal;
-
-       ap->ops->dev_select(ap, device);
-
-       outb(0x55, ioaddr->nsect_addr);
-       outb(0xaa, ioaddr->lbal_addr);
-
-       outb(0xaa, ioaddr->nsect_addr);
-       outb(0x55, ioaddr->lbal_addr);
-
-       outb(0x55, ioaddr->nsect_addr);
-       outb(0xaa, ioaddr->lbal_addr);
-
-       nsect = inb(ioaddr->nsect_addr);
-       lbal = inb(ioaddr->lbal_addr);
-
-       if ((nsect == 0x55) && (lbal == 0xaa))
-               return 1;       /* we found a device */
-
-       return 0;               /* nothing found */
-}
-
-/**
- *     ata_mmio_devchk - PATA device presence detection
+ *     ata_devchk - PATA device presence detection
  *     @ap: ATA channel to examine
  *     @device: Device to examine (starting at zero)
  *
@@ -662,25 +624,24 @@ static unsigned int ata_pio_devchk(struct ata_port *ap,
  *     caller.
  */
 
-static unsigned int ata_mmio_devchk(struct ata_port *ap,
-                                   unsigned int device)
+static unsigned int ata_devchk(struct ata_port *ap, unsigned int device)
 {
        struct ata_ioports *ioaddr = &ap->ioaddr;
        u8 nsect, lbal;
 
        ap->ops->dev_select(ap, device);
 
-       writeb(0x55, (void __iomem *) ioaddr->nsect_addr);
-       writeb(0xaa, (void __iomem *) ioaddr->lbal_addr);
+       iowrite8(0x55, ioaddr->nsect_addr);
+       iowrite8(0xaa, ioaddr->lbal_addr);
 
-       writeb(0xaa, (void __iomem *) ioaddr->nsect_addr);
-       writeb(0x55, (void __iomem *) ioaddr->lbal_addr);
+       iowrite8(0xaa, ioaddr->nsect_addr);
+       iowrite8(0x55, ioaddr->lbal_addr);
 
-       writeb(0x55, (void __iomem *) ioaddr->nsect_addr);
-       writeb(0xaa, (void __iomem *) ioaddr->lbal_addr);
+       iowrite8(0x55, ioaddr->nsect_addr);
+       iowrite8(0xaa, ioaddr->lbal_addr);
 
-       nsect = readb((void __iomem *) ioaddr->nsect_addr);
-       lbal = readb((void __iomem *) ioaddr->lbal_addr);
+       nsect = ioread8(ioaddr->nsect_addr);
+       lbal = ioread8(ioaddr->lbal_addr);
 
        if ((nsect == 0x55) && (lbal == 0xaa))
                return 1;       /* we found a device */
@@ -688,27 +649,6 @@ static unsigned int ata_mmio_devchk(struct ata_port *ap,
        return 0;               /* nothing found */
 }
 
-/**
- *     ata_devchk - PATA device presence detection
- *     @ap: ATA channel to examine
- *     @device: Device to examine (starting at zero)
- *
- *     Dispatch ATA device presence detection, depending
- *     on whether we are using PIO or MMIO to talk to the
- *     ATA shadow registers.
- *
- *     LOCKING:
- *     caller.
- */
-
-static unsigned int ata_devchk(struct ata_port *ap,
-                                   unsigned int device)
-{
-       if (ap->flags & ATA_FLAG_MMIO)
-               return ata_mmio_devchk(ap, device);
-       return ata_pio_devchk(ap, device);
-}
-
 /**
  *     ata_dev_classify - determine device type based on ATA-spec signature
  *     @tf: ATA taskfile register set for device to be identified
@@ -770,7 +710,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
  *     Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
  */
 
-static unsigned int
+unsigned int
 ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err)
 {
        struct ata_taskfile tf;
@@ -926,11 +866,7 @@ void ata_std_dev_select (struct ata_port *ap, unsigned int device)
        else
                tmp = ATA_DEVICE_OBS | ATA_DEV1;
 
-       if (ap->flags & ATA_FLAG_MMIO) {
-               writeb(tmp, (void __iomem *) ap->ioaddr.device_addr);
-       } else {
-               outb(tmp, ap->ioaddr.device_addr);
-       }
+       iowrite8(tmp, ap->ioaddr.device_addr);
        ata_pause(ap);          /* needed; also flushes, for mmio */
 }
 
@@ -1480,7 +1416,16 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        }
 
        tf.protocol = ATA_PROT_PIO;
-       tf.flags |= ATA_TFLAG_POLLING; /* for polling presence detection */
+
+       /* Some devices choke if TF registers contain garbage.  Make
+        * sure those are properly initialized.
+        */
+       tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
+
+       /* Device presence detection is unreliable on some
+        * controllers.  Always poll IDENTIFY if available.
+        */
+       tf.flags |= ATA_TFLAG_POLLING;
 
        err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
                                     id, sizeof(id[0]) * ATA_ID_WORDS);
@@ -1610,6 +1555,8 @@ int ata_dev_configure(struct ata_device *dev)
        const u16 *id = dev->id;
        unsigned int xfer_mask;
        char revbuf[7];         /* XYZ-99\0 */
+       char fwrevbuf[ATA_ID_FW_REV_LEN+1];
+       char modelbuf[ATA_ID_PROD_LEN+1];
        int rc;
 
        if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
@@ -1623,6 +1570,16 @@ int ata_dev_configure(struct ata_device *dev)
                ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
                               __FUNCTION__, ap->id, dev->devno);
 
+       /* set _SDD */
+       rc = ata_acpi_push_id(ap, dev->devno);
+       if (rc) {
+               ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
+                       rc);
+       }
+
+       /* retrieve and execute the ATA task file of _GTF */
+       ata_acpi_exec_tfs(ap);
+
        /* print device capabilities */
        if (ata_msg_probe(ap))
                ata_dev_printk(dev, KERN_DEBUG,
@@ -1664,6 +1621,16 @@ int ata_dev_configure(struct ata_device *dev)
 
                dev->n_sectors = ata_id_n_sectors(id);
 
+               /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
+               ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
+                               sizeof(fwrevbuf));
+
+               ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD,
+                               sizeof(modelbuf));
+
+               if (dev->id[59] & 0x100)
+                       dev->multi_count = dev->id[59] & 0xff;
+
                if (ata_id_has_lba(id)) {
                        const char *lba_desc;
                        char ncq_desc[20];
@@ -1683,13 +1650,16 @@ int ata_dev_configure(struct ata_device *dev)
                        ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
 
                        /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info)
-                               ata_dev_printk(dev, KERN_INFO, "%s, "
-                                       "max %s, %Lu sectors: %s %s\n",
-                                       revbuf,
-                                       ata_mode_string(xfer_mask),
+                       if (ata_msg_drv(ap) && print_info) {
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "%s: %s, %s, max %s\n",
+                                       revbuf, modelbuf, fwrevbuf,
+                                       ata_mode_string(xfer_mask));
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "%Lu sectors, multi %u: %s %s\n",
                                        (unsigned long long)dev->n_sectors,
-                                       lba_desc, ncq_desc);
+                                       dev->multi_count, lba_desc, ncq_desc);
+                       }
                } else {
                        /* CHS */
 
@@ -1706,22 +1676,17 @@ int ata_dev_configure(struct ata_device *dev)
                        }
 
                        /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info)
-                               ata_dev_printk(dev, KERN_INFO, "%s, "
-                                       "max %s, %Lu sectors: CHS %u/%u/%u\n",
-                                       revbuf,
-                                       ata_mode_string(xfer_mask),
-                                       (unsigned long long)dev->n_sectors,
-                                       dev->cylinders, dev->heads,
-                                       dev->sectors);
-               }
-
-               if (dev->id[59] & 0x100) {
-                       dev->multi_count = dev->id[59] & 0xff;
-                       if (ata_msg_drv(ap) && print_info)
+                       if (ata_msg_drv(ap) && print_info) {
                                ata_dev_printk(dev, KERN_INFO,
-                                       "ata%u: dev %u multi count %u\n",
-                                       ap->id, dev->devno, dev->multi_count);
+                                       "%s: %s, %s, max %s\n",
+                                       revbuf, modelbuf, fwrevbuf,
+                                       ata_mode_string(xfer_mask));
+                               ata_dev_printk(dev, KERN_INFO, 
+                                       "%Lu sectors, multi %u, CHS %u/%u/%u\n",
+                                       (unsigned long long)dev->n_sectors,
+                                       dev->multi_count, dev->cylinders,
+                                       dev->heads, dev->sectors);
+                       }
                }
 
                dev->cdb_len = 16;
@@ -1815,7 +1780,7 @@ int ata_bus_probe(struct ata_port *ap)
 {
        unsigned int classes[ATA_MAX_DEVICES];
        int tries[ATA_MAX_DEVICES];
-       int i, rc, down_xfermask;
+       int i, rc;
        struct ata_device *dev;
 
        ata_port_probe(ap);
@@ -1824,8 +1789,6 @@ int ata_bus_probe(struct ata_port *ap)
                tries[i] = ATA_PROBE_MAX_TRIES;
 
  retry:
-       down_xfermask = 0;
-
        /* reset and determine device classes */
        ap->ops->phy_reset(ap);
 
@@ -1873,10 +1836,8 @@ int ata_bus_probe(struct ata_port *ap)
 
        /* configure transfer mode */
        rc = ata_set_mode(ap, &dev);
-       if (rc) {
-               down_xfermask = 1;
+       if (rc)
                goto fail;
-       }
 
        for (i = 0; i < ATA_MAX_DEVICES; i++)
                if (ata_dev_enabled(&ap->device[i]))
@@ -1888,25 +1849,29 @@ int ata_bus_probe(struct ata_port *ap)
        return -ENODEV;
 
  fail:
+       tries[dev->devno]--;
+
        switch (rc) {
        case -EINVAL:
-       case -ENODEV:
+               /* eeek, something went very wrong, give up */
                tries[dev->devno] = 0;
                break;
+
+       case -ENODEV:
+               /* give it just one more chance */
+               tries[dev->devno] = min(tries[dev->devno], 1);
        case -EIO:
-               sata_down_spd_limit(ap);
-               /* fall through */
-       default:
-               tries[dev->devno]--;
-               if (down_xfermask &&
-                   ata_down_xfermask_limit(dev, tries[dev->devno] == 1))
-                       tries[dev->devno] = 0;
+               if (tries[dev->devno] == 1) {
+                       /* This is the last chance, better to slow
+                        * down than lose it.
+                        */
+                       sata_down_spd_limit(ap);
+                       ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
+               }
        }
 
-       if (!tries[dev->devno]) {
-               ata_down_xfermask_limit(dev, 1);
+       if (!tries[dev->devno])
                ata_dev_disable(dev);
-       }
 
        goto retry;
 }
@@ -2337,7 +2302,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
 /**
  *     ata_down_xfermask_limit - adjust dev xfer masks downward
  *     @dev: Device to adjust xfer masks
- *     @force_pio0: Force PIO0
+ *     @sel: ATA_DNXFER_* selector
  *
  *     Adjust xfer masks of @dev downward.  Note that this function
  *     does not apply the change.  Invoking ata_set_mode() afterwards
@@ -2349,37 +2314,78 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
  *     RETURNS:
  *     0 on success, negative errno on failure
  */
-int ata_down_xfermask_limit(struct ata_device *dev, int force_pio0)
+int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel)
 {
-       unsigned long xfer_mask;
-       int highbit;
+       char buf[32];
+       unsigned int orig_mask, xfer_mask;
+       unsigned int pio_mask, mwdma_mask, udma_mask;
+       int quiet, highbit;
 
-       xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask,
-                                     dev->udma_mask);
+       quiet = !!(sel & ATA_DNXFER_QUIET);
+       sel &= ~ATA_DNXFER_QUIET;
 
-       if (!xfer_mask)
-               goto fail;
-       /* don't gear down to MWDMA from UDMA, go directly to PIO */
-       if (xfer_mask & ATA_MASK_UDMA)
-               xfer_mask &= ~ATA_MASK_MWDMA;
+       xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask,
+                                                 dev->mwdma_mask,
+                                                 dev->udma_mask);
+       ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask);
 
-       highbit = fls(xfer_mask) - 1;
-       xfer_mask &= ~(1 << highbit);
-       if (force_pio0)
-               xfer_mask &= 1 << ATA_SHIFT_PIO;
-       if (!xfer_mask)
-               goto fail;
+       switch (sel) {
+       case ATA_DNXFER_PIO:
+               highbit = fls(pio_mask) - 1;
+               pio_mask &= ~(1 << highbit);
+               break;
+
+       case ATA_DNXFER_DMA:
+               if (udma_mask) {
+                       highbit = fls(udma_mask) - 1;
+                       udma_mask &= ~(1 << highbit);
+                       if (!udma_mask)
+                               return -ENOENT;
+               } else if (mwdma_mask) {
+                       highbit = fls(mwdma_mask) - 1;
+                       mwdma_mask &= ~(1 << highbit);
+                       if (!mwdma_mask)
+                               return -ENOENT;
+               }
+               break;
+
+       case ATA_DNXFER_40C:
+               udma_mask &= ATA_UDMA_MASK_40C;
+               break;
+
+       case ATA_DNXFER_FORCE_PIO0:
+               pio_mask &= 1;
+       case ATA_DNXFER_FORCE_PIO:
+               mwdma_mask = 0;
+               udma_mask = 0;
+               break;
+
+       default:
+               BUG();
+       }
+
+       xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
+
+       if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask)
+               return -ENOENT;
+
+       if (!quiet) {
+               if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
+                       snprintf(buf, sizeof(buf), "%s:%s",
+                                ata_mode_string(xfer_mask),
+                                ata_mode_string(xfer_mask & ATA_MASK_PIO));
+               else
+                       snprintf(buf, sizeof(buf), "%s",
+                                ata_mode_string(xfer_mask));
+
+               ata_dev_printk(dev, KERN_WARNING,
+                              "limiting speed to %s\n", buf);
+       }
 
        ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
                            &dev->udma_mask);
 
-       ata_dev_printk(dev, KERN_WARNING, "limiting speed to %s\n",
-                      ata_mode_string(xfer_mask));
-
        return 0;
-
- fail:
-       return -EINVAL;
 }
 
 static int ata_dev_set_mode(struct ata_device *dev)
@@ -2393,6 +2399,10 @@ static int ata_dev_set_mode(struct ata_device *dev)
                dev->flags |= ATA_DFLAG_PIO;
 
        err_mask = ata_dev_set_xfermode(dev);
+       /* Old CFA may refuse this command, which is just fine */
+       if (dev->xfer_shift == ATA_SHIFT_PIO && ata_id_is_cfa(dev->id))
+               err_mask &= ~AC_ERR_DEV;
+
        if (err_mask) {
                ata_dev_printk(dev, KERN_ERR, "failed to set xfermode "
                               "(err_mask=0x%x)\n", err_mask);
@@ -2616,13 +2626,8 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
                u8 nsect, lbal;
 
                ap->ops->dev_select(ap, 1);
-               if (ap->flags & ATA_FLAG_MMIO) {
-                       nsect = readb((void __iomem *) ioaddr->nsect_addr);
-                       lbal = readb((void __iomem *) ioaddr->lbal_addr);
-               } else {
-                       nsect = inb(ioaddr->nsect_addr);
-                       lbal = inb(ioaddr->lbal_addr);
-               }
+               nsect = ioread8(ioaddr->nsect_addr);
+               lbal = ioread8(ioaddr->lbal_addr);
                if ((nsect == 1) && (lbal == 1))
                        break;
                if (time_after(jiffies, timeout)) {
@@ -2650,19 +2655,11 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
        DPRINTK("ata%u: bus reset via SRST\n", ap->id);
 
        /* software reset.  causes dev0 to be selected */
-       if (ap->flags & ATA_FLAG_MMIO) {
-               writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
-               udelay(20);     /* FIXME: flush */
-               writeb(ap->ctl | ATA_SRST, (void __iomem *) ioaddr->ctl_addr);
-               udelay(20);     /* FIXME: flush */
-               writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
-       } else {
-               outb(ap->ctl, ioaddr->ctl_addr);
-               udelay(10);
-               outb(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
-               udelay(10);
-               outb(ap->ctl, ioaddr->ctl_addr);
-       }
+       iowrite8(ap->ctl, ioaddr->ctl_addr);
+       udelay(20);     /* FIXME: flush */
+       iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
+       udelay(20);     /* FIXME: flush */
+       iowrite8(ap->ctl, ioaddr->ctl_addr);
 
        /* spec mandates ">= 2ms" before checking status.
         * We wait 150ms, because that was the magic delay used for
@@ -2747,8 +2744,7 @@ void ata_bus_reset(struct ata_port *ap)
                ap->device[1].class = ata_dev_try_classify(ap, 1, &err);
 
        /* re-enable interrupts */
-       if (ap->ioaddr.ctl_addr)        /* FIXME: hack. create a hook instead */
-               ata_irq_on(ap);
+       ap->ops->irq_on(ap);
 
        /* is double-select really necessary? */
        if (ap->device[1].class != ATA_DEV_NONE)
@@ -2763,10 +2759,7 @@ void ata_bus_reset(struct ata_port *ap)
 
        if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
                /* set up device control for ATA_FLAG_SATA_RESET */
-               if (ap->flags & ATA_FLAG_MMIO)
-                       writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
-               else
-                       outb(ap->ctl, ioaddr->ctl_addr);
+               iowrite8(ap->ctl, ioaddr->ctl_addr);
        }
 
        DPRINTK("EXIT\n");
@@ -3100,6 +3093,9 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
                return 0;
        }
 
+       /* wait a while before checking status, see SRST for more info */
+       msleep(150);
+
        if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
                ata_port_printk(ap, KERN_ERR,
                                "COMRESET failed (device not ready)\n");
@@ -3140,11 +3136,8 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
                sata_scr_write(ap, SCR_ERROR, serror);
 
        /* re-enable interrupts */
-       if (!ap->ops->error_handler) {
-               /* FIXME: hack. create a hook instead */
-               if (ap->ioaddr.ctl_addr)
-                       ata_irq_on(ap);
-       }
+       if (!ap->ops->error_handler)
+               ap->ops->irq_on(ap);
 
        /* is double-select really necessary? */
        if (classes[0] != ATA_DEV_NONE)
@@ -3159,12 +3152,8 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
        }
 
        /* set up device control */
-       if (ap->ioaddr.ctl_addr) {
-               if (ap->flags & ATA_FLAG_MMIO)
-                       writeb(ap->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
-               else
-                       outb(ap->ctl, ap->ioaddr.ctl_addr);
-       }
+       if (ap->ioaddr.ctl_addr)
+               iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
 
        DPRINTK("EXIT\n");
 }
@@ -3880,53 +3869,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
 }
 
 /**
- *     ata_mmio_data_xfer - Transfer data by MMIO
- *     @adev: device for this I/O
- *     @buf: data buffer
- *     @buflen: buffer length
- *     @write_data: read/write
- *
- *     Transfer data from/to the device data register by MMIO.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-
-void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
-                       unsigned int buflen, int write_data)
-{
-       struct ata_port *ap = adev->ap;
-       unsigned int i;
-       unsigned int words = buflen >> 1;
-       u16 *buf16 = (u16 *) buf;
-       void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr;
-
-       /* Transfer multiple of 2 bytes */
-       if (write_data) {
-               for (i = 0; i < words; i++)
-                       writew(le16_to_cpu(buf16[i]), mmio);
-       } else {
-               for (i = 0; i < words; i++)
-                       buf16[i] = cpu_to_le16(readw(mmio));
-       }
-
-       /* Transfer trailing 1 byte, if any. */
-       if (unlikely(buflen & 0x01)) {
-               u16 align_buf[1] = { 0 };
-               unsigned char *trailing_buf = buf + buflen - 1;
-
-               if (write_data) {
-                       memcpy(align_buf, trailing_buf, 1);
-                       writew(le16_to_cpu(align_buf[0]), mmio);
-               } else {
-                       align_buf[0] = cpu_to_le16(readw(mmio));
-                       memcpy(trailing_buf, align_buf, 1);
-               }
-       }
-}
-
-/**
- *     ata_pio_data_xfer - Transfer data by PIO
+ *     ata_data_xfer - Transfer data by PIO
  *     @adev: device to target
  *     @buf: data buffer
  *     @buflen: buffer length
@@ -3937,18 +3880,17 @@ void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
  *     LOCKING:
  *     Inherited from caller.
  */
-
-void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
-                      unsigned int buflen, int write_data)
+void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
+                  unsigned int buflen, int write_data)
 {
        struct ata_port *ap = adev->ap;
        unsigned int words = buflen >> 1;
 
        /* Transfer multiple of 2 bytes */
        if (write_data)
-               outsw(ap->ioaddr.data_addr, buf, words);
+               iowrite16_rep(ap->ioaddr.data_addr, buf, words);
        else
-               insw(ap->ioaddr.data_addr, buf, words);
+               ioread16_rep(ap->ioaddr.data_addr, buf, words);
 
        /* Transfer trailing 1 byte, if any. */
        if (unlikely(buflen & 0x01)) {
@@ -3957,16 +3899,16 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
 
                if (write_data) {
                        memcpy(align_buf, trailing_buf, 1);
-                       outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr);
+                       iowrite16(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr);
                } else {
-                       align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr));
+                       align_buf[0] = cpu_to_le16(ioread16(ap->ioaddr.data_addr));
                        memcpy(trailing_buf, align_buf, 1);
                }
        }
 }
 
 /**
- *     ata_pio_data_xfer_noirq - Transfer data by PIO
+ *     ata_data_xfer_noirq - Transfer data by PIO
  *     @adev: device to target
  *     @buf: data buffer
  *     @buflen: buffer length
@@ -3978,13 +3920,12 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
  *     LOCKING:
  *     Inherited from caller.
  */
-
-void ata_pio_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
-                                   unsigned int buflen, int write_data)
+void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
+                        unsigned int buflen, int write_data)
 {
        unsigned long flags;
        local_irq_save(flags);
-       ata_pio_data_xfer(adev, buf, buflen, write_data);
+       ata_data_xfer(adev, buf, buflen, write_data);
        local_irq_restore(flags);
 }
 
@@ -4307,7 +4248,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
                        qc = ata_qc_from_tag(ap, qc->tag);
                        if (qc) {
                                if (likely(!(qc->err_mask & AC_ERR_HSM))) {
-                                       ata_irq_on(ap);
+                                       ap->ops->irq_on(ap);
                                        ata_qc_complete(qc);
                                } else
                                        ata_port_freeze(ap);
@@ -4323,7 +4264,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
        } else {
                if (in_wq) {
                        spin_lock_irqsave(ap->lock, flags);
-                       ata_irq_on(ap);
+                       ap->ops->irq_on(ap);
                        ata_qc_complete(qc);
                        spin_unlock_irqrestore(ap->lock, flags);
                } else
@@ -5148,7 +5089,7 @@ idle_irq:
 
 #ifdef ATA_IRQ_TRAP
        if ((ap->stats.idle_irq % 1000) == 0) {
-               ata_irq_ack(ap, 0); /* debug trap */
+               ap->ops->irq_ack(ap, 0); /* debug trap */
                ata_port_printk(ap, KERN_WARNING, "irq trap\n");
                return 1;
        }
@@ -5770,7 +5711,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
        host->n_ports = ent->n_ports;
        host->irq = ent->irq;
        host->irq2 = ent->irq2;
-       host->mmio_base = ent->mmio_base;
+       host->iomap = ent->iomap;
        host->private_data = ent->private_data;
 
        /* register each port bound to this device */
@@ -5808,8 +5749,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
                                (ap->pio_mask << ATA_SHIFT_PIO);
 
                /* print per-port info to dmesg */
-               ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%lX "
-                               "ctl 0x%lX bmdma 0x%lX irq %d\n",
+               ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
+                               "ctl 0x%p bmdma 0x%p irq %d\n",
                                ap->flags & ATA_FLAG_SATA ? 'S' : 'P',
                                ata_mode_string(xfer_mode_mask),
                                ap->ioaddr.cmd_addr,
@@ -6007,11 +5948,7 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
 {
        struct ata_probe_ent *probe_ent;
 
-       /* XXX - the following if can go away once all LLDs are managed */
-       if (!list_empty(&dev->devres_head))
-               probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
-       else
-               probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
+       probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
        if (!probe_ent) {
                printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
                       kobject_name(&(dev->kobj)));
@@ -6117,11 +6054,10 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
 void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
        pci_save_state(pdev);
+       pci_disable_device(pdev);
 
-       if (mesg.event == PM_EVENT_SUSPEND) {
-               pci_disable_device(pdev);
+       if (mesg.event == PM_EVENT_SUSPEND)
                pci_set_power_state(pdev, PCI_D3hot);
-       }
 }
 
 int ata_pci_device_do_resume(struct pci_dev *pdev)
@@ -6328,9 +6264,8 @@ EXPORT_SYMBOL_GPL(ata_altstatus);
 EXPORT_SYMBOL_GPL(ata_exec_command);
 EXPORT_SYMBOL_GPL(ata_port_start);
 EXPORT_SYMBOL_GPL(ata_interrupt);
-EXPORT_SYMBOL_GPL(ata_mmio_data_xfer);
-EXPORT_SYMBOL_GPL(ata_pio_data_xfer);
-EXPORT_SYMBOL_GPL(ata_pio_data_xfer_noirq);
+EXPORT_SYMBOL_GPL(ata_data_xfer);
+EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
 EXPORT_SYMBOL_GPL(ata_qc_prep);
 EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
 EXPORT_SYMBOL_GPL(ata_bmdma_setup);
@@ -6410,3 +6345,8 @@ EXPORT_SYMBOL_GPL(ata_eh_thaw_port);
 EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
 EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
 EXPORT_SYMBOL_GPL(ata_do_eh);
+EXPORT_SYMBOL_GPL(ata_irq_on);
+EXPORT_SYMBOL_GPL(ata_dummy_irq_on);
+EXPORT_SYMBOL_GPL(ata_irq_ack);
+EXPORT_SYMBOL_GPL(ata_dummy_irq_ack);
+EXPORT_SYMBOL_GPL(ata_dev_try_classify);