]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/ata/libata-core.c
Merge tag 'kmemleak' of git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/linux
[karo-tx-linux.git] / drivers / ata / libata-core.c
index 04c208e3cec6205f554655801c9a694720b0dd1c..11c9aea4f4f7ea93a50fdc4b3547323d3728738d 100644 (file)
@@ -66,6 +66,7 @@
 #include <asm/byteorder.h>
 #include <linux/cdrom.h>
 #include <linux/ratelimit.h>
+#include <linux/pm_runtime.h>
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -3248,10 +3249,10 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
                ata_force_xfermask(dev);
 
                pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
-               dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
 
                if (libata_dma_mask & mode_mask)
-                       dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
+                       dma_mask = ata_pack_xfermask(0, dev->mwdma_mask,
+                                                    dev->udma_mask);
                else
                        dma_mask = 0;
 
@@ -5280,12 +5281,24 @@ static int ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
 
 #define to_ata_port(d) container_of(d, struct ata_port, tdev)
 
-static int ata_port_suspend_common(struct device *dev)
+static int ata_port_suspend_common(struct device *dev, pm_message_t mesg)
 {
        struct ata_port *ap = to_ata_port(dev);
+       unsigned int ehi_flags = ATA_EHI_QUIET;
        int rc;
 
-       rc = ata_port_request_pm(ap, PMSG_SUSPEND, 0, ATA_EHI_QUIET, 1);
+       /*
+        * On some hardware, device fails to respond after spun down
+        * for suspend.  As the device won't be used before being
+        * resumed, we don't need to touch the device.  Ask EH to skip
+        * the usual stuff and proceed directly to suspend.
+        *
+        * http://thread.gmane.org/gmane.linux.ide/46764
+        */
+       if (mesg.event == PM_EVENT_SUSPEND)
+               ehi_flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_NO_RECOVERY;
+
+       rc = ata_port_request_pm(ap, mesg, 0, ehi_flags, 1);
        return rc;
 }
 
@@ -5294,10 +5307,26 @@ static int ata_port_suspend(struct device *dev)
        if (pm_runtime_suspended(dev))
                return 0;
 
-       return ata_port_suspend_common(dev);
+       return ata_port_suspend_common(dev, PMSG_SUSPEND);
 }
 
-static int ata_port_resume(struct device *dev)
+static int ata_port_do_freeze(struct device *dev)
+{
+       if (pm_runtime_suspended(dev))
+               pm_runtime_resume(dev);
+
+       return ata_port_suspend_common(dev, PMSG_FREEZE);
+}
+
+static int ata_port_poweroff(struct device *dev)
+{
+       if (pm_runtime_suspended(dev))
+               return 0;
+
+       return ata_port_suspend_common(dev, PMSG_HIBERNATE);
+}
+
+static int ata_port_resume_common(struct device *dev)
 {
        struct ata_port *ap = to_ata_port(dev);
        int rc;
@@ -5307,9 +5336,36 @@ static int ata_port_resume(struct device *dev)
        return rc;
 }
 
+static int ata_port_resume(struct device *dev)
+{
+       int rc;
+
+       rc = ata_port_resume_common(dev);
+       if (!rc) {
+               pm_runtime_disable(dev);
+               pm_runtime_set_active(dev);
+               pm_runtime_enable(dev);
+       }
+
+       return rc;
+}
+
+static int ata_port_runtime_idle(struct device *dev)
+{
+       return pm_runtime_suspend(dev);
+}
+
 static const struct dev_pm_ops ata_port_pm_ops = {
        .suspend = ata_port_suspend,
        .resume = ata_port_resume,
+       .freeze = ata_port_do_freeze,
+       .thaw = ata_port_resume,
+       .poweroff = ata_port_poweroff,
+       .restore = ata_port_resume,
+
+       .runtime_suspend = ata_port_suspend,
+       .runtime_resume = ata_port_resume_common,
+       .runtime_idle = ata_port_runtime_idle,
 };
 
 /**