Skip to contentSkip to conversation

J6/J6Eco: Add PM support to PCIe

PATCH Superseded Kishon Vijay Abraham I 5 participants 12 messages Jul 3, 2015 – Jul 23, 2015 PCI

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover J6/J6Eco: Add PM support to PCIe

This series adds PM support to pci-dra7xx so that PCI clocks can be disabled during suspend and enabled back during resume without affecting PCI functionality.

This series is dependent on [1] for proper PM functionality.

[1] -> http://newscentral.exsees.com/item/595269de5c35c59c386b91ce8efd9872-eedf6742bb6159c3b1a90625c4d43407

Kishon Vijay Abraham I (3):
PCI: host: pci-dra7xx: Disable pm_runtime if get_sync failure
PCI: host: pcie-designware: add support for suspend and resume
PCI: host: pci-dra7xx: add pm support to pci dra7xx

 drivers/pci/host/pci-dra7xx.c      |   78 +++++++++++++++++++++++++++++++++++-
 drivers/pci/host/pcie-designware.c |   20 +++++++++
 drivers/pci/host/pcie-designware.h |    2 +
 3 files changed, 99 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/3 PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure

Fix the error handling code in case pm_runtime_get_sync fails. Now when pm_runtime_get_sync fails pm_runtime_disable is invoked so that there is no unbalanced pm_runtime_enable calls.

---
 drivers/pci/host/pci-dra7xx.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/host/pci-dra7xx.c +3 -1
index 80db09e..d8b6d66 100644
@@ -384,7 +384,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 	ret = pm_runtime_get_sync(dev);
 	if (IS_ERR_VALUE(ret)) {
 		dev_err(dev, "pm_runtime_get_sync failed\n");
-		goto err_phy;
+		goto err_get_sync;
 	}
 
 	reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
@@ -401,6 +401,8 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 
 err_add_port:
 	pm_runtime_put(dev);
+
+err_get_sync:
 	pm_runtime_disable(dev);
 
 err_phy:
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/3 PCI: host: pcie-designware: add support for suspend and resume

In reply to Kishon Vijay Abraham I

Certain platforms require MSE bit to be cleared to set the master in standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe Controller Master Standby Behavior advises to use the clearing of the local MSE bit to set the master in standby. Without this some of the clocks do not idle).

Cleared the MSE bit on suspend and enabled it back on resume. This is required to get suspend/resume working.

---
 drivers/pci/host/pcie-designware.c |   20 ++++++++++++++++++++
 drivers/pci/host/pcie-designware.h |    2 ++
 2 files changed, 22 insertions(+)
drivers/pci/host/pcie-designware.c +20 -0
index 69486be..cfb2bd6 100644
@@ -811,6 +811,26 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
 }
 
+void dw_pcie_suspend_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* clear MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val &= ~PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
+void dw_pcie_resume_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* set MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val |= PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Designware PCIe host controller driver");
 MODULE_LICENSE("GPL v2");
drivers/pci/host/pcie-designware.h +2 -0
index d0bbd27..0df2dfa 100644
@@ -83,5 +83,7 @@ void dw_pcie_msi_init(struct pcie_port *pp);
 int dw_pcie_link_up(struct pcie_port *pp);
 void dw_pcie_setup_rc(struct pcie_port *pp);
 int dw_pcie_host_init(struct pcie_port *pp);
+void dw_pcie_suspend_rc(struct pcie_port *pp);
+void dw_pcie_resume_rc(struct pcie_port *pp);
 
 #endif /* _PCIE_DESIGNWARE_H */
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 3/3 PCI: host: pci-dra7xx: add pm support to pci dra7xx

In reply to Kishon Vijay Abraham I

Add PM support to pci-dra7xx so that PCI clocks can be disabled during suspend and enabled back during resume without affecting PCI functionality.

---
 drivers/pci/host/pci-dra7xx.c |   74 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
drivers/pci/host/pci-dra7xx.c +74 -0
index d8b6d66..1f5c039 100644
@@ -433,6 +433,79 @@ static int __exit dra7xx_pcie_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int dra7xx_pcie_suspend(struct device *dev)
+{
+	struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+	struct pcie_port *pp = &dra7xx->pp;
+
+	dw_pcie_suspend_rc(pp);
+
+	return 0;
+}
+
+static int dra7xx_pcie_resume(struct device *dev)
+{
+	struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+	struct pcie_port *pp = &dra7xx->pp;
+
+	dw_pcie_resume_rc(pp);
+
+	return 0;
+}
+static int dra7xx_pcie_suspend_noirq(struct device *dev)
+{
+	struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+	int count = dra7xx->phy_count;
+
+	while (count--) {
+		phy_power_off(dra7xx->phy[count]);
+		phy_exit(dra7xx->phy[count]);
+	}
+
+	return 0;
+}
+static int dra7xx_pcie_resume_noirq(struct device *dev)
+{
+	struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+	int phy_count = dra7xx->phy_count;
+	int ret;
+	int i;
+
+	for (i = 0; i < phy_count; i++) {
+		ret = phy_init(dra7xx->phy[i]);
+		if (ret < 0)
+			goto err_phy;
+
+		ret = phy_power_on(dra7xx->phy[i]);
+		if (ret < 0) {
+			phy_exit(dra7xx->phy[i]);
+			goto err_phy;
+		}
+	}
+
+	return 0;
+
+err_phy:
+	while (--i >= 0) {
+		phy_power_off(dra7xx->phy[i]);
+		phy_exit(dra7xx->phy[i]);
+	}
+
+	return ret;
+}
+
+static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+	.suspend_noirq = dra7xx_pcie_suspend_noirq,
+	.suspend = dra7xx_pcie_suspend,
+	.resume_noirq = dra7xx_pcie_resume_noirq,
+	.resume = dra7xx_pcie_resume,
+};
+#define DEV_PM_OPS	(&dra7xx_pcie_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
 static const struct of_device_id of_dra7xx_pcie_match[] = {
 	{ .compatible = "ti,dra7-pcie", },
 	{},
@@ -444,6 +517,7 @@ static struct platform_driver dra7xx_pcie_driver = {
 	.driver = {
 		.name	= "dra7-pcie",
 		.of_match_table = of_dra7xx_pcie_match,
+		.pm	= DEV_PM_OPS,
 	},
 };
 
Signature · 1 line
1.7.9.5
#10 lore raw

Re: [PATCH 3/3] PCI: host: pci-dra7xx: add pm support to pci dra7xx

Hi Kishon,

Quoted 18 lines · Kishon Vijay Abraham I

Add PM support to pci-dra7xx so that PCI clocks can be disabled during suspend and enabled back during resume without affecting PCI functionality.

---
  drivers/pci/host/pci-dra7xx.c |   74 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 74 insertions(+)
drivers/pci/host/pci-dra7xx.c +1 -0
index d8b6d66..1f5c039 100644
@@ -433,6 +433,79 @@ static int __exit dra7xx_pcie_remove(struct platform_device *pdev)
  	return 0;
  }
 
+#ifdef CONFIG_PM_SLEEP

[...]

drivers/pci/host/pci-dra7xx.c static int __exit dra7xx_pcie_remove(struct platform_device *pdev) · line 502

Quoted 6 lines
drivers/pci/host/pci-dra7xx.c +6 -0
+
+static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+	.suspend_noirq = dra7xx_pcie_suspend_noirq,
+	.suspend = dra7xx_pcie_suspend,
+	.resume_noirq = dra7xx_pcie_resume_noirq,
+	.resume = dra7xx_pcie_resume,

Could you use here SET_SYSTEM_SLEEP_PM_OPS()
and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS() macro, pls?

Quoted 18 lines
drivers/pci/host/pci-dra7xx.c +7 -0
+};
+#define DEV_PM_OPS	(&dra7xx_pcie_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
  static const struct of_device_id of_dra7xx_pcie_match[] = {
  	{ .compatible = "ti,dra7-pcie", },
  	{},
@@ -444,6 +517,7 @@ static struct platform_driver dra7xx_pcie_driver = {
  	.driver = {
  		.name	= "dra7-pcie",
  		.of_match_table = of_dra7xx_pcie_match,
+		.pm	= DEV_PM_OPS,
  	},
  };
 
Signature · 2 lines
regards,
-grygorii
#3 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

In reply to Kishon Vijay Abraham I

Hi Kishon,

Quoted 8 lines · Kishon Vijay Abraham I

Certain platforms require MSE bit to be cleared to set the master in standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe Controller Master Standby Behavior advises to use the clearing of the local MSE bit to set the master in standby. Without this some of the clocks do not idle).

Cleared the MSE bit on suspend and enabled it back on resume. This is required to get suspend/resume working.

Have you tested with a card having IO space memory as well. I think you might need to require clear and enable PCI_COMMAND_IO in suspend and resume respectively.

~Pratyush

#4 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

Hi Pratyush,

Quoted 9 lines · Pratyush Anand

Hi Kishon,

Quoted 6 lines · Kishon Vijay Abraham I

Certain platforms require MSE bit to be cleared to set the master in standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe Controller Master Standby Behavior advises to use the clearing of the local MSE bit to set the master in standby. Without this some of the clocks do not idle).

Quoted 4 lines
Quoted 2 lines

Cleared the MSE bit on suspend and enabled it back on resume. This is required to get suspend/resume working.

Have you tested with a card having IO space memory as well.

I don't have any cards with IO space memory. Do you have any suggestion for cards with IO space memory?

Quoted 2 lines

I think you might need to require clear and enable PCI_COMMAND_IO in suspend and resume respectively.

okay.

Thanks
Kishon

#11 lore raw

Re: [PATCH 3/3] PCI: host: pci-dra7xx: add pm support to pci dra7xx

In reply to Grygorii Strashko

Hi,

Quoted 24 lines · Grygorii Strashko

Hi Kishon,

Quoted 18 lines · Kishon Vijay Abraham I

Add PM support to pci-dra7xx so that PCI clocks can be disabled during suspend and enabled back during resume without affecting PCI functionality.

---
  drivers/pci/host/pci-dra7xx.c |   74 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 74 insertions(+)
drivers/pci/host/pci-dra7xx.c +1 -0
index d8b6d66..1f5c039 100644
@@ -433,6 +433,79 @@ static int __exit dra7xx_pcie_remove(struct platform_device *pdev)
  	return 0;
  }
 
+#ifdef CONFIG_PM_SLEEP

[...]

Quoted 9 lines

drivers/pci/host/pci-dra7xx.c static int __exit dra7xx_pcie_remove(struct platform_device *pdev) · line 502

Quoted 6 lines
drivers/pci/host/pci-dra7xx.c +6 -0
+
+static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+	.suspend_noirq = dra7xx_pcie_suspend_noirq,
+	.suspend = dra7xx_pcie_suspend,
+	.resume_noirq = dra7xx_pcie_resume_noirq,
+	.resume = dra7xx_pcie_resume,

Could you use here SET_SYSTEM_SLEEP_PM_OPS()
and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS() macro, pls?

sure!

Thanks
Kishon

#5 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

In reply to Kishon Vijay Abraham I

Hi Kishon,

On Fri, Jul 10, 2015 at 8:19 PM, Kishon Vijay Abraham I <[email protected]> wrote:

[...]

Quoted 4 lines
Quoted 1 line

Have you tested with a card having IO space memory as well.

I don't have any cards with IO space memory. Do you have any suggestion for cards with IO space memory?

Sorry, I never used it either :(
IIRC, then Tim and Marek (in cc) had reported long back with some issues of IO transaction
with SKY2 based card. They may let you know about exact card ID.

~Pratyush

#6 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

Quoted 1 line · Pratyush Anand

Hi Kishon,

Hi,

Quoted 7 lines

On Fri, Jul 10, 2015 at 8:19 PM, Kishon Vijay Abraham I <[email protected]> wrote:

[...]

Quoted 2 lines
Quoted 1 line

Have you tested with a card having IO space memory as well.

Quoted 7 lines
Quoted 2 lines

I don't have any cards with IO space memory. Do you have any suggestion for cards with IO space memory?

Sorry, I never used it either :(
IIRC, then Tim and Marek (in cc) had reported long back with some issues of IO transaction
with SKY2 based card. They may let you know about exact card ID.

That was Tim, I didn't ever try with SKY2 , sorry.

Best regards,
Marek Vasut

#7 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

In reply to Kishon Vijay Abraham I
Quoted 3 lines · Kishon Vijay Abraham I

Certain platforms require MSE bit to be cleared to set the master in standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe

This patch is a work-around specific for DRA7xx chips? If so, please move this patch to 'pci-dra7xx.c'.
I don't want to include chip-specific codes, because 'pcie-designware.c' is designed for including common codes.

Best regards,
Jingoo Han

Quoted 59 lines

Controller Master Standby Behavior advises to use the clearing of the local MSE bit to set the master in standby. Without this some of the clocks do not idle).

Cleared the MSE bit on suspend and enabled it back on resume. This is required to get suspend/resume working.

---
 drivers/pci/host/pcie-designware.c |   20 ++++++++++++++++++++
 drivers/pci/host/pcie-designware.h |    2 ++
 2 files changed, 22 insertions(+)
drivers/pci/host/pcie-designware.c +20 -0
index 69486be..cfb2bd6 100644
@@ -811,6 +811,26 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
 }
 
+void dw_pcie_suspend_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* clear MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val &= ~PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
+void dw_pcie_resume_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* set MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val |= PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Designware PCIe host controller driver");
 MODULE_LICENSE("GPL v2");
drivers/pci/host/pcie-designware.h +2 -1
index d0bbd27..0df2dfa 100644
@@ -83,5 +83,7 @@ void dw_pcie_msi_init(struct pcie_port *pp);
 int dw_pcie_link_up(struct pcie_port *pp);
 void dw_pcie_setup_rc(struct pcie_port *pp);
 int dw_pcie_host_init(struct pcie_port *pp);
+void dw_pcie_suspend_rc(struct pcie_port *pp);
+void dw_pcie_resume_rc(struct pcie_port *pp);
 
 #endif /* _PCIE_DESIGNWARE_H */
--

1.7.9.5

#8 lore raw

Re: [PATCH 2/3] PCI: host: pcie-designware: add support for suspend and resume

Hi,

Quoted 9 lines · Jingoo Han
Quoted 3 lines · Kishon Vijay Abraham I

Certain platforms require MSE bit to be cleared to set the master in standby mode. (In DRA7xx TRM_vE, section 24.9.4.5.2.2.1 PCIe

This patch is a work-around specific for DRA7xx chips? If so, please move this patch to 'pci-dra7xx.c'.
I don't want to include chip-specific codes, because 'pcie-designware.c' is designed for including common codes.

Alright. Will change it that way in the next version.

Thanks
Kishon

Quoted 64 lines

Best regards,
Jingoo Han

Quoted 59 lines

Controller Master Standby Behavior advises to use the clearing of the local MSE bit to set the master in standby. Without this some of the clocks do not idle).

Cleared the MSE bit on suspend and enabled it back on resume. This is required to get suspend/resume working.

---
 drivers/pci/host/pcie-designware.c |   20 ++++++++++++++++++++
 drivers/pci/host/pcie-designware.h |    2 ++
 2 files changed, 22 insertions(+)
drivers/pci/host/pcie-designware.c +20 -0
index 69486be..cfb2bd6 100644
@@ -811,6 +811,26 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
 }
 
+void dw_pcie_suspend_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* clear MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val &= ~PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
+void dw_pcie_resume_rc(struct pcie_port *pp)
+{
+	u32 val;
+
+	/* set MSE */
+	dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
+	val |= PCI_COMMAND_MEMORY;
+	dw_pcie_writel_rc(pp, val, PCI_COMMAND);
+}
+
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Designware PCIe host controller driver");
 MODULE_LICENSE("GPL v2");
drivers/pci/host/pcie-designware.h +2 -1
index d0bbd27..0df2dfa 100644
@@ -83,5 +83,7 @@ void dw_pcie_msi_init(struct pcie_port *pp);
 int dw_pcie_link_up(struct pcie_port *pp);
 void dw_pcie_setup_rc(struct pcie_port *pp);
 int dw_pcie_host_init(struct pcie_port *pp);
+void dw_pcie_suspend_rc(struct pcie_port *pp);
+void dw_pcie_resume_rc(struct pcie_port *pp);
 
 #endif /* _PCIE_DESIGNWARE_H */
--

1.7.9.5