2015-07-31 12:25:23

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: [PATCH v5 0/3] dra7xx: 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.

Changes from v4:
*) Fixed a bug caused by sending incomplete patch.

Changes from v3:
*) Fix compilation errors when individual patches are applied

Changes from v2:
*) Used SET_SYSTEM_SLEEP_PM_OPS and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS for
populating PM ops.

Changes from v1:
*) Moved resetting and setting of MSE bit to pci-dra7xx.

The comment to reset and set ISE is not done now since I don't have a card
with IO space. Once I get to test that, I'll post a separate patch for
handling that.

Kishon Vijay Abraham I (3):
PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure
PCI: host: pci-dra7xx: add pm support to pci dra7xx
PCI: host: pci-dra7xx: Idle the module by disabling MSE bit

drivers/pci/host/pci-dra7xx.c | 95 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)

--
1.7.9.5


2015-07-31 12:25:25

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: [PATCH v5 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.

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
---
drivers/pci/host/pci-dra7xx.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index 80db09e..d8b6d66 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -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:
--
1.7.9.5

2015-07-31 12:25:27

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: [PATCH v5 2/3] PCI: host: pci-dra7xx: add pm support to pci dra7xx

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

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
---
drivers/pci/host/pci-dra7xx.c | 51 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index d8b6d66..08b999a 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -433,6 +433,56 @@ static int __exit dra7xx_pcie_remove(struct platform_device *pdev)
return 0;
}

+#ifdef CONFIG_PM_SLEEP
+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;
+}
+#endif
+
+static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
+ dra7xx_pcie_resume_noirq)
+};
+
static const struct of_device_id of_dra7xx_pcie_match[] = {
{ .compatible = "ti,dra7-pcie", },
{},
@@ -444,6 +494,7 @@ static struct platform_driver dra7xx_pcie_driver = {
.driver = {
.name = "dra7-pcie",
.of_match_table = of_dra7xx_pcie_match,
+ .pm = &dra7xx_pcie_pm_ops,
},
};

--
1.7.9.5

2015-07-31 12:25:30

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: [PATCH v5 3/3] PCI: host: pci-dra7xx: Idle the module by disabling MSE bit

DRA7xx 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.
Clearing MSE bit is required to get clocks to be idled after
suspend.

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
Signed-off-by: Sekhar Nori <[email protected]>
---
drivers/pci/host/pci-dra7xx.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)

diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
index 08b999a..3772aff 100644
--- a/drivers/pci/host/pci-dra7xx.c
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -83,6 +83,17 @@ static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset,
writel(value, pcie->base + offset);
}

+static inline u32 dra7xx_pcie_readl_rc(struct pcie_port *pp, u32 offset)
+{
+ return readl(pp->dbi_base + offset);
+}
+
+static inline void dra7xx_pcie_writel_rc(struct pcie_port *pp, u32 offset,
+ u32 value)
+{
+ writel(value, pp->dbi_base + offset);
+}
+
static int dra7xx_pcie_link_up(struct pcie_port *pp)
{
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
@@ -434,6 +445,34 @@ static int __exit dra7xx_pcie_remove(struct platform_device *pdev)
}

#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;
+ u32 val;
+
+ /* clear MSE */
+ val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
+ val &= ~PCI_COMMAND_MEMORY;
+ dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
+
+ return 0;
+}
+
+static int dra7xx_pcie_resume(struct device *dev)
+{
+ struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
+ struct pcie_port *pp = &dra7xx->pp;
+ u32 val;
+
+ /* set MSE */
+ val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
+ val |= PCI_COMMAND_MEMORY;
+ dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
+
+ return 0;
+}
+
static int dra7xx_pcie_suspend_noirq(struct device *dev)
{
struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
@@ -479,6 +518,7 @@ err_phy:
#endif

static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume)
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
dra7xx_pcie_resume_noirq)
};
--
1.7.9.5

2015-08-06 15:33:13

by Jingoo Han

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] dra7xx: Add PM support to PCIe

On Friday, July 31, 2015 9:25 PM, Kishon Vijay Abraham I wrote:
>
> 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.
>
> Changes from v4:
> *) Fixed a bug caused by sending incomplete patch.
>
> Changes from v3:
> *) Fix compilation errors when individual patches are applied
>
> Changes from v2:
> *) Used SET_SYSTEM_SLEEP_PM_OPS and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS for
> populating PM ops.
>
> Changes from v1:
> *) Moved resetting and setting of MSE bit to pci-dra7xx.
>
> The comment to reset and set ISE is not done now since I don't have a card
> with IO space. Once I get to test that, I'll post a separate patch for
> handling that.
>
> Kishon Vijay Abraham I (3):
> PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure
> PCI: host: pci-dra7xx: add pm support to pci dra7xx
> PCI: host: pci-dra7xx: Idle the module by disabling MSE bit

Hi Kishon,

Looks good! :-)

Reviewed-by: Jingoo Han <[email protected]>

Best regards,
Jingoo Han

>
> drivers/pci/host/pci-dra7xx.c | 95 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 94 insertions(+), 1 deletion(-)
>
> --
> 1.7.9.5

2015-08-11 20:52:12

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] dra7xx: Add PM support to PCIe

On Fri, Jul 31, 2015 at 05:55:09PM +0530, Kishon Vijay Abraham I wrote:
> 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.
>
> Changes from v4:
> *) Fixed a bug caused by sending incomplete patch.
>
> Changes from v3:
> *) Fix compilation errors when individual patches are applied
>
> Changes from v2:
> *) Used SET_SYSTEM_SLEEP_PM_OPS and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS for
> populating PM ops.
>
> Changes from v1:
> *) Moved resetting and setting of MSE bit to pci-dra7xx.
>
> The comment to reset and set ISE is not done now since I don't have a card
> with IO space. Once I get to test that, I'll post a separate patch for
> handling that.
>
> Kishon Vijay Abraham I (3):
> PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure
> PCI: host: pci-dra7xx: add pm support to pci dra7xx
> PCI: host: pci-dra7xx: Idle the module by disabling MSE bit
>
> drivers/pci/host/pci-dra7xx.c | 95 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 94 insertions(+), 1 deletion(-)

Applied with Jingoo's Reviewed-by to pci/host-dra7xx for v4.3, thanks!

I tweaked the changelogs as follows:


commit 0e2bdb0e7abf4b5170874e415ec42df547916dd3
Author: Kishon Vijay Abraham I <[email protected]>
Date: Fri Jul 31 17:55:10 2015 +0530

PCI: dra7xx: Disable pm_runtime on get_sync failure

Fix the error handling when pm_runtime_get_sync() fails.

If pm_runtime_get_sync() fails, call pm_runtime_disable() so there are no
unbalanced pm_runtime_enable() calls.

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Jingoo Han <[email protected]>

commit e52eb445ea1d97bf7fb92d2297e487a305392136
Author: Kishon Vijay Abraham I <[email protected]>
Date: Fri Jul 31 17:55:11 2015 +0530

PCI: dra7xx: Add PM support

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

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Jingoo Han <[email protected]>

commit 389c7094ec241ee8ebe358ba10fe392018692c8c
Author: Kishon Vijay Abraham I <[email protected]>
Date: Fri Jul 31 17:55:12 2015 +0530

PCI: dra7xx: Clear MSE bit during suspend so clocks will idle

DRA7xx requires the 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).

Clear the MSE bit on suspend and enable it on resume. Clearing MSE bit is
required to get clocks to be idled after suspend.

Signed-off-by: Kishon Vijay Abraham I <[email protected]>
Signed-off-by: Sekhar Nori <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Reviewed-by: Jingoo Han <[email protected]>

2015-08-12 05:41:00

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: Re: [PATCH v5 0/3] dra7xx: Add PM support to PCIe



On Wednesday 12 August 2015 02:22 AM, Bjorn Helgaas wrote:
> On Fri, Jul 31, 2015 at 05:55:09PM +0530, Kishon Vijay Abraham I wrote:
>> 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.
>>
>> Changes from v4:
>> *) Fixed a bug caused by sending incomplete patch.
>>
>> Changes from v3:
>> *) Fix compilation errors when individual patches are applied
>>
>> Changes from v2:
>> *) Used SET_SYSTEM_SLEEP_PM_OPS and SET_NOIRQ_SYSTEM_SLEEP_PM_OPS for
>> populating PM ops.
>>
>> Changes from v1:
>> *) Moved resetting and setting of MSE bit to pci-dra7xx.
>>
>> The comment to reset and set ISE is not done now since I don't have a card
>> with IO space. Once I get to test that, I'll post a separate patch for
>> handling that.
>>
>> Kishon Vijay Abraham I (3):
>> PCI: host: pci-dra7xx: Disable pm_runtime on get_sync failure
>> PCI: host: pci-dra7xx: add pm support to pci dra7xx
>> PCI: host: pci-dra7xx: Idle the module by disabling MSE bit
>>
>> drivers/pci/host/pci-dra7xx.c | 95 ++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 94 insertions(+), 1 deletion(-)
>
> Applied with Jingoo's Reviewed-by to pci/host-dra7xx for v4.3, thanks!
>
> I tweaked the changelogs as follows:
>
>
> commit 0e2bdb0e7abf4b5170874e415ec42df547916dd3
> Author: Kishon Vijay Abraham I <[email protected]>
> Date: Fri Jul 31 17:55:10 2015 +0530
>
> PCI: dra7xx: Disable pm_runtime on get_sync failure
>
> Fix the error handling when pm_runtime_get_sync() fails.
>
> If pm_runtime_get_sync() fails, call pm_runtime_disable() so there are no
> unbalanced pm_runtime_enable() calls.
>
> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
> Signed-off-by: Bjorn Helgaas <[email protected]>
> Reviewed-by: Jingoo Han <[email protected]>
>
> commit e52eb445ea1d97bf7fb92d2297e487a305392136
> Author: Kishon Vijay Abraham I <[email protected]>
> Date: Fri Jul 31 17:55:11 2015 +0530
>
> PCI: dra7xx: Add PM support
>
> Add PM support to pci-dra7xx so PCI clocks can be disabled during suspend
> and enabled during resume without affecting PCI functionality.
>
> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
> Signed-off-by: Bjorn Helgaas <[email protected]>
> Reviewed-by: Jingoo Han <[email protected]>
>
> commit 389c7094ec241ee8ebe358ba10fe392018692c8c
> Author: Kishon Vijay Abraham I <[email protected]>
> Date: Fri Jul 31 17:55:12 2015 +0530
>
> PCI: dra7xx: Clear MSE bit during suspend so clocks will idle
>
> DRA7xx requires the 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).
>
> Clear the MSE bit on suspend and enable it on resume. Clearing MSE bit is
> required to get clocks to be idled after suspend.
>
> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
> Signed-off-by: Sekhar Nori <[email protected]>
> Signed-off-by: Bjorn Helgaas <[email protected]>
> Reviewed-by: Jingoo Han <[email protected]>

Thanks Bjorn!

-Kishon