Skip to contentSkip to conversation

ahci_platform: add suspend & resume support

PATCH In review JiSheng Zhang 3 participants 3 messages Oct 30, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ahci_platform: add suspend & resume support

---
 drivers/ata/ahci_platform.c |   54 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
drivers/ata/ahci_platform.c +54 -0
index c03277d..60ff9eb 100644
@@ -202,12 +202,66 @@ static int __devexit ahci_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int ahci_suspend(struct platform_device *pdev, pm_message_t mesg)
+{
+	struct ata_host *host = dev_get_drvdata(&pdev->dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
+	u32 ctl;
+
+	if (mesg.event & PM_EVENT_SLEEP) {
+		/* AHCI spec rev1.1 section 8.3.3:
+		 * Software must disable interrupts prior to requesting a
+		 * transition of the HBA to D3 state.
+		 */
+		ctl = readl(mmio + HOST_CTL);
+		ctl &= ~HOST_IRQ_EN;
+		writel(ctl, mmio + HOST_CTL);
+		readl(mmio + HOST_CTL); /* flush */
+	}
+
+	return ata_host_suspend(host, mesg);
+}
+
+static int ahci_resume(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ahci_platform_data *pdata = dev->platform_data;
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	int rc;
+
+	if (pdata && pdata->init) {
+		rc = pdata->init(dev, hpriv->mmio);
+		if (rc)
+			return rc;
+	}
+
+	if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
+		rc = ahci_reset_controller(host);
+		if (rc)
+			return rc;
+
+		ahci_init_controller(host);
+	}
+
+	ata_host_resume(host);
+
+	return 0;
+}
+#endif
+
 static struct platform_driver ahci_driver = {
 	.remove = __devexit_p(ahci_remove),
 	.driver = {
 		.name = "ahci",
 		.owner = THIS_MODULE,
 	},
+#ifdef CONFIG_PM
+	.suspend = ahci_suspend,
+	.resume = ahci_resume,
+#endif
 	.id_table	= ahci_devtype,
 };
 
Signature · 1 line
1.7.6.3
#1 lore raw

Adding linux-pm mailing list to CC, since this is PM related.

Quoted 77 lines · JiSheng Zhang
---
 drivers/ata/ahci_platform.c |   54 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
drivers/ata/ahci_platform.c +54 -0
index c03277d..60ff9eb 100644
@@ -202,12 +202,66 @@ static int __devexit ahci_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int ahci_suspend(struct platform_device *pdev, pm_message_t mesg)
+{
+	struct ata_host *host = dev_get_drvdata(&pdev->dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
+	u32 ctl;
+
+	if (mesg.event & PM_EVENT_SLEEP) {
+		/* AHCI spec rev1.1 section 8.3.3:
+		 * Software must disable interrupts prior to requesting a
+		 * transition of the HBA to D3 state.
+		 */
+		ctl = readl(mmio + HOST_CTL);
+		ctl &= ~HOST_IRQ_EN;
+		writel(ctl, mmio + HOST_CTL);
+		readl(mmio + HOST_CTL); /* flush */
+	}
+
+	return ata_host_suspend(host, mesg);
+}
+
+static int ahci_resume(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ahci_platform_data *pdata = dev->platform_data;
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	int rc;
+
+	if (pdata && pdata->init) {
+		rc = pdata->init(dev, hpriv->mmio);
+		if (rc)
+			return rc;
+	}
+
+	if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
+		rc = ahci_reset_controller(host);
+		if (rc)
+			return rc;
+
+		ahci_init_controller(host);
+	}
+
+	ata_host_resume(host);
+
+	return 0;
+}
+#endif
+
 static struct platform_driver ahci_driver = {
 	.remove = __devexit_p(ahci_remove),
 	.driver = {
 		.name = "ahci",
 		.owner = THIS_MODULE,
 	},
+#ifdef CONFIG_PM
+	.suspend = ahci_suspend,
+	.resume = ahci_resume,
+#endif
 	.id_table	= ahci_devtype,
 };
 
Signature · 4 lines
Regards,
Srivatsa S. Bhat  <[email protected]>
Linux Technology Center,
IBM India Systems and Technology Lab
#2 lore raw
In reply to JiSheng Zhang

Hello.

Quoted 10 lines · JiSheng Zhang
---
  drivers/ata/ahci_platform.c |   54 +++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 54 insertions(+), 0 deletions(-)
drivers/ata/ahci_platform.c +0 -0
index c03277d..60ff9eb 100644

drivers/ata/ahci_platform.c static int __devexit ahci_remove(struct platform_device *pdev) · line 208

Quoted 7 lines
drivers/ata/ahci_platform.c +4 -0
@@ -202,12 +202,66 @@ static int __devexit ahci_remove(struct platform_device *pdev)
  	return 0;
  }
 
+#ifdef CONFIG_PM
+static int ahci_suspend(struct platform_device *pdev, pm_message_t mesg)
+{
+	struct ata_host *host = dev_get_drvdata(&pdev->dev);

You can also call platform_get_drvdata(pdev).

drivers/ata/ahci_platform.c static int __devexit ahci_remove(struct platform_device *pdev) · line 230

Quoted 4 lines
drivers/ata/ahci_platform.c +4 -0
+static int ahci_resume(struct platform_device *pdev)
+{
+	struct device *dev =&pdev->dev;
+	struct ahci_platform_data *pdata = dev->platform_data;

There's dev_get_platdata().

WBR, Sergei