Skip to contentSkip to conversation

ahci: platform support for suspend/resume

PATCH In review Brian Norris 4 participants 7 messages Nov 18, 2011 – Dec 15, 2011

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

PATCH v2 1/1 ahci: platform support for suspend/resume

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

---
Based on:
git://github.com/jgarzik/libata-dev.git ALL

v2: * supports AHCI suspend/resume even when pdata, pdata->suspend, or
pdata->resume are not supplied
* use dev_get_platdata() consistently

 drivers/ata/ahci_platform.c   |   68 +++++++++++++++++++++++++++++++++++++++++
 include/linux/ahci_platform.h |    2 +
 2 files changed, 70 insertions(+), 0 deletions(-)
drivers/ata/ahci_platform.c +68 -0
index 43b8758..48be4e1 100644
@@ -202,6 +202,71 @@ static int __devexit ahci_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int ahci_suspend(struct device *dev)
+{
+	struct ahci_platform_data *pdata = dev_get_platdata(dev);
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
+	u32 ctl;
+	int rc;
+
+	if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
+		dev_err(dev, "firmware update required for suspend/resume\n");
+		return -EIO;
+	}
+
+	/*
+	 * 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 */
+
+	rc = ata_host_suspend(host, PMSG_SUSPEND);
+	if (rc)
+		return rc;
+
+	if (pdata && pdata->suspend)
+		return pdata->suspend(dev);
+	return 0;
+}
+
+static int ahci_resume(struct device *dev)
+{
+	struct ahci_platform_data *pdata = dev_get_platdata(dev);
+	struct ata_host *host = dev_get_drvdata(dev);
+	int rc;
+
+	if (pdata && pdata->resume) {
+		rc = pdata->resume(dev);
+		if (rc)
+			return rc;
+	}
+
+	if (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;
+}
+
+static struct dev_pm_ops ahci_pm_ops = {
+	.suspend		= &ahci_suspend,
+	.resume			= &ahci_resume,
+};
+#endif
+
 static const struct of_device_id ahci_of_match[] = {
 	{ .compatible = "calxeda,hb-ahci", },
 	{},
@@ -214,6 +279,9 @@ static struct platform_driver ahci_driver = {
 		.name = "ahci",
 		.owner = THIS_MODULE,
 		.of_match_table = ahci_of_match,
+#ifdef CONFIG_PM
+		.pm = &ahci_pm_ops,
+#endif
 	},
 	.id_table	= ahci_devtype,
 };
include/linux/ahci_platform.h +2 -0
index be3d9a7..73a2500 100644
@@ -23,6 +23,8 @@ struct ata_port_info;
 struct ahci_platform_data {
 	int (*init)(struct device *dev, void __iomem *addr);
 	void (*exit)(struct device *dev);
+	int (*suspend)(struct device *dev);
+	int (*resume)(struct device *dev);
 	const struct ata_port_info *ata_port_info;
 	unsigned int force_port_map;
 	unsigned int mask_port_map;
Signature · 1 line
1.7.5.4
#2 lore raw
Quoted 8 lines · Felipe Balbi
Quoted 5 lines · Brian Norris

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

Thanks for the review, Felipe.

What's the status on this? There have been no comments for almost a month. Can it be merged?

Brian

#3 lore raw
Quoted 6 lines · Brian Norris
Quoted 5 lines · Felipe Balbi
Quoted 4 lines · Brian Norris

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks for the review, Felipe.

What's the status on this? There have been no comments for almost a month. Can it be merged?

FWIW, the patch looks quite useful. Hope this will help:

Thanks!

Signature · 2 lines
Anton Vorontsov
Email: [email protected]
#4 lore raw
In reply to Brian Norris
Quoted 6 lines · Brian Norris
Quoted 5 lines · Felipe Balbi
Quoted 4 lines · Brian Norris

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks for the review, Felipe.

What's the status on this? There have been no comments for almost a month. Can it be merged?

The previous version was queued, but did not apply to upstream (I emailed a comment at the time). Hopefully this one works...

#5 lore raw
In reply to Brian Norris
Quoted 6 lines · Brian Norris
Quoted 5 lines · Felipe Balbi
Quoted 4 lines · Brian Norris

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks for the review, Felipe.

What's the status on this? There have been no comments for almost a month. Can it be merged?

The previous version was queued, but did not apply to upstream (I emailed a comment at the time). Hopefully this one works...

#6 lore raw
Quoted 16 lines · Jeff Garzik
Quoted 15 lines · Brian Norris
Quoted 11 lines · Felipe Balbi
Quoted 6 lines · Brian Norris

Add platform hooks for custom suspend() and resume() functions. The generic suspend/resume code in drivers/ata/ahci_platform.c is adapted from the PCI version in drivers/ata/ahci.c.

Quoted 8 lines
Quoted 4 lines

Thanks for the review, Felipe.

What's the status on this? There have been no comments for almost a month. Can it be merged?

The previous version was queued, but did not apply to upstream (I emailed a comment at the time).  Hopefully this one works...

I never saw a comment that it did not apply. Anyway, by my own tests, this version applies safely to either Linus' repository or your libata-dev/NEXT branch.

Brian