Skip to contentSkip to conversation

PCI: rcar: Use runtime PM to control controller clock

PATCH Superseded Marek Vasut 2 participants 6 messages Mar 18, 2018 – Apr 9, 2018

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 PCI: rcar: Use runtime PM to control controller clock

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +12 -28
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;
 
+	pm_runtime_enable(pcie->dev);
+	err = pm_runtime_get_sync(pcie->dev);
+	if (err < 0) {
+		dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+		goto err_pm_disable;
+	}
+
 	err = rcar_pcie_get_resources(pcie);
 	if (err < 0) {
 		dev_err(dev, "failed to request resources: %d\n", err);
-		goto err_free_resource_list;
+		goto err_pm_put;
 	}
 
 	err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
 	if (err)
-		goto err_free_resource_list;
-
-	pm_runtime_enable(dev);
-	err = pm_runtime_get_sync(dev);
-	if (err < 0) {
-		dev_err(dev, "pm_runtime_get_sync failed\n");
-		goto err_pm_disable;
-	}
+		goto err_pm_put;
 
 	/* Failure to get a link might just be that no cards are inserted */
 	hw_init_fn = of_device_get_match_data(dev);
@@ -1171,13 +1158,10 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_put:
 	pm_runtime_put(dev);
-
 err_pm_disable:
 	pm_runtime_disable(dev);
-
-err_free_resource_list:
-	pci_free_resource_list(&pcie->resources);
 err_free_bridge:
+	pci_free_resource_list(&pcie->resources);
 	pci_free_host_bridge(bridge);
 
 	return err;
Signature · 1 line
2.16.2
#1 lore raw
Quoted 74 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +2 -15
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
 	return err;
 }

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1112

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;

This error path now calls pci_free_resource_list() and in this case the path is taken if rcar_pcie_parse_request_of_pci_ranges() fails. Is that ok?

Quoted 47 lines
drivers/pci/host/pcie-rcar.c +10 -13
+	pm_runtime_enable(pcie->dev);
+	err = pm_runtime_get_sync(pcie->dev);
+	if (err < 0) {
+		dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+		goto err_pm_disable;
+	}
+
 	err = rcar_pcie_get_resources(pcie);
 	if (err < 0) {
 		dev_err(dev, "failed to request resources: %d\n", err);
-		goto err_free_resource_list;
+		goto err_pm_put;
 	}
 
 	err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
 	if (err)
-		goto err_free_resource_list;
-
-	pm_runtime_enable(dev);
-	err = pm_runtime_get_sync(dev);
-	if (err < 0) {
-		dev_err(dev, "pm_runtime_get_sync failed\n");
-		goto err_pm_disable;
-	}
+		goto err_pm_put;
 
 	/* Failure to get a link might just be that no cards are inserted */
 	hw_init_fn = of_device_get_match_data(dev);
@@ -1171,13 +1158,10 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_put:
 	pm_runtime_put(dev);
-
 err_pm_disable:
 	pm_runtime_disable(dev);
-
-err_free_resource_list:
-	pci_free_resource_list(&pcie->resources);
 err_free_bridge:
+	pci_free_resource_list(&pcie->resources);
 	pci_free_host_bridge(bridge);
 
 	return err;
Signature · 1 line
2.16.2
#2 lore raw
Quoted 72 lines · Simon Horman
Quoted 71 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +2 -15
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
Quoted 9 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1112

Quoted 5 lines
drivers/pci/host/pcie-rcar.c +0 -0
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;

This error path now calls pci_free_resource_list() and in this case the path is taken if rcar_pcie_parse_request_of_pci_ranges() fails. Is that ok?

I think so, or did I miss something obvious?

Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw
Quoted 83 lines · Marek Vasut
Quoted 72 lines · Simon Horman
Quoted 71 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +2 -15
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
Quoted 9 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1112

Quoted 5 lines
drivers/pci/host/pcie-rcar.c +0 -0
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;

This error path now calls pci_free_resource_list() and in this case the path is taken if rcar_pcie_parse_request_of_pci_ranges() fails. Is that ok?

Quoted 1 line

I think so, or did I miss something obvious?

I feel that I am the one missing something obvious. But here is what I am worried about:

1. rcar_pcie_probe() calls rcar_pcie_parse_request_of_pci_ranges()
2. rcar_pcie_parse_request_of_pci_ranges() calls devm_request_pci_bus_resources() but that fails so pci_free_resource_list() is called and an error is returned.
3. rcar_pcie_probe() branches to err_free_bridge and calls pci_free_resource_list() again.

Quoted 5 lines
Signature · 3 lines
-- 
Best regards,
Marek Vasut
#4 lore raw
Quoted 89 lines · Simon Horman
Quoted 83 lines · Marek Vasut
Quoted 72 lines · Simon Horman
Quoted 71 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +2 -15
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
Quoted 9 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1112

Quoted 5 lines
drivers/pci/host/pcie-rcar.c +0 -0
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;

This error path now calls pci_free_resource_list() and in this case the path is taken if rcar_pcie_parse_request_of_pci_ranges() fails. Is that ok?

Quoted 1 line

I think so, or did I miss something obvious?

I feel that I am the one missing something obvious. But here is what I am worried about:

Quoted 6 lines

1. rcar_pcie_probe() calls rcar_pcie_parse_request_of_pci_ranges()
2. rcar_pcie_parse_request_of_pci_ranges() calls devm_request_pci_bus_resources() but that fails so pci_free_resource_list() is called and an error is returned.
3. rcar_pcie_probe() branches to err_free_bridge and calls pci_free_resource_list() again.

I see what you mean now, thanks for the details explanation.

So the change needed here is to move pci_free_resource_list(&pcie->resources); above err_free_bridge, so it's not called twice, right ?

Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw
Quoted 97 lines · Marek Vasut
Quoted 89 lines · Simon Horman
Quoted 83 lines · Marek Vasut
Quoted 72 lines · Simon Horman
Quoted 71 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next

---
 drivers/pci/host/pcie-rcar.c | 40 ++++++++++++----------------------------
 1 file changed, 12 insertions(+), 28 deletions(-)
drivers/pci/host/pcie-rcar.c +2 -15
index b4c4aad2cf66..93d59f15c589 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
Quoted 9 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1112

Quoted 5 lines
drivers/pci/host/pcie-rcar.c +0 -0
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;

This error path now calls pci_free_resource_list() and in this case the path is taken if rcar_pcie_parse_request_of_pci_ranges() fails. Is that ok?

Quoted 1 line

I think so, or did I miss something obvious?

I feel that I am the one missing something obvious. But here is what I am worried about:

Quoted 6 lines

1. rcar_pcie_probe() calls rcar_pcie_parse_request_of_pci_ranges()
2. rcar_pcie_parse_request_of_pci_ranges() calls devm_request_pci_bus_resources() but that fails so pci_free_resource_list() is called and an error is returned.
3. rcar_pcie_probe() branches to err_free_bridge and calls pci_free_resource_list() again.

Quoted 5 lines

I see what you mean now, thanks for the details explanation.

So the change needed here is to move pci_free_resource_list(&pcie->resources); above err_free_bridge, so it's not called twice, right ?

Yes, I think so.