Skip to contentSkip to conversation

PCI: rcar: Use runtime PM to control controller clock

PATCH Superseded Marek Vasut 2 participants 3 messages Nov 8, 2017 – Nov 10, 2017

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

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()

---
 drivers/pci/host/pcie-rcar.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)
drivers/pci/host/pcie-rcar.c +12 -25
index 12796eccb2be..1a7254ec16da 100644
@@ -145,7 +145,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;
 };
@@ -917,24 +916,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) {
@@ -956,8 +945,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;
 }
@@ -1125,6 +1112,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 	rcar_pcie_parse_request_of_pci_ranges(pcie);
 
+	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);
@@ -1135,13 +1129,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;
 
-	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;
-	}
-
 	/* Failure to get a link might just be that no cards are inserted */
 	hw_init_fn = of_device_get_match_data(dev);
 	err = hw_init_fn(pcie);
@@ -1173,13 +1160,13 @@ 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_bridge:
 	pci_free_host_bridge(bridge);
 	pci_free_resource_list(&pcie->resources);
 
+err_pm_disable:
+	pm_runtime_disable(dev);
+
 	return err;
 }
 
Signature · 1 line
2.11.0
#1 lore raw

Hi Marek,

Quoted 15 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.

drivers/pci/host/pcie-rcar.c +0 -0
@@ -1125,6 +1112,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
        rcar_pcie_parse_request_of_pci_ranges(pcie);
 

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

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
+       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);

(out of context)

                 goto err_free_bridge;

But that should do pm_runtime_put(), too.

Quoted 15 lines
drivers/pci/host/pcie-rcar.c +0 -7
@@ -1135,13 +1129,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
-       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;
-       }
-
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
        err = hw_init_fn(pcie);

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

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
@@ -1173,13 +1160,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 err_pm_put:
        pm_runtime_put(dev);

"err_pm_put" should be moved, too.

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

Quoted 12 lines
drivers/pci/host/pcie-rcar.c +3 -3
-err_pm_disable:
-       pm_runtime_disable(dev);
-
 err_free_bridge:
        pci_free_host_bridge(bridge);
        pci_free_resource_list(&pcie->resources);
 
+err_pm_disable:
+       pm_runtime_disable(dev);
+
        return err;
 }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
Quoted 1 line · Geert Uytterhoeven

Hi Marek,

Hi Geert,

Quoted 36 lines · Marek Vasut
Quoted 15 lines

From: Dien Pham <[email protected]>

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

drivers/pci/host/pcie-rcar.c +0 -0
@@ -1125,6 +1112,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
        rcar_pcie_parse_request_of_pci_ranges(pcie);
 

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

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
+       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);

(out of context)

                 goto err_free_bridge;

But that should do pm_runtime_put(), too.

Quoted 4 lines
drivers/pci/host/pcie-rcar.c +0 -0
@@ -1135,13 +1129,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
Quoted 15 lines

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

Quoted 13 lines
drivers/pci/host/pcie-rcar.c +0 -7
-       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;
-       }
-
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
        err = hw_init_fn(pcie);
@@ -1173,13 +1160,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 err_pm_put:
        pm_runtime_put(dev);

"err_pm_put" should be moved, too.

ACK. I combed through the probe function one more time and I hope I'll have it right in V3.

Quoted 6 lines

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

Quoted 6 lines
drivers/pci/host/pcie-rcar.c +0 -3
-err_pm_disable:
-       pm_runtime_disable(dev);
-
 err_free_bridge:
        pci_free_host_bridge(bridge);
        pci_free_resource_list(&pcie->resources);

^ IMO this should happen after pm_runtime_disable too , just to be consistent.

Quoted 5 lines
Quoted 5 lines
drivers/pci/host/pcie-rcar.c +3 -0
+err_pm_disable:
+       pm_runtime_disable(dev);
+
        return err;
 }

[...]

Signature · 2 lines
Best regards,
Marek Vasut