linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: rcar-gen2: Ensure the mandatory clock is enabled
@ 2019-03-22 16:11 Gareth Williams
  2019-03-22 19:14 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Gareth Williams @ 2019-03-22 16:11 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas
  Cc: Phil Edworthy, linux-pci, linux-renesas-soc, linux-kernel,
	Gareth Williams

From: Phil Edworthy <phil.edworthy@renesas.com>

All SoC devices that use this driver have a module stop clock associated
with it that we must ensure is enabled. All SoCs enabled this clock
by default, so I guess no one noticed that the driver didn't enable it.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Signed-off-by: Gareth Williams <gareth.williams.jx@renesas.com>
---
Note: This change was tested on RZN1 and R-Car M2 hardware. NULL is
passed to devm_clk_get for backwards compatibility reasons with R-Car gen2
devices which do not name the clock.

DTS files for Renesas devices that use this driver have been checked to
ensure they specify a clock and do not name that clock.  
---
 drivers/pci/controller/pci-rcar-gen2.c | 35 +++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pci-rcar-gen2.c b/drivers/pci/controller/pci-rcar-gen2.c
index 326171c..4c94860 100644
--- a/drivers/pci/controller/pci-rcar-gen2.c
+++ b/drivers/pci/controller/pci-rcar-gen2.c
@@ -8,6 +8,7 @@
  * Author: Valentine Barshak <valentine.barshak@cogentembedded.com>
  */
 
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -95,6 +96,7 @@
 
 struct rcar_pci_priv {
 	struct device *dev;
+	struct clk *clk;
 	void __iomem *reg;
 	struct resource mem_res;
 	struct resource *cfg_res;
@@ -340,6 +342,8 @@ static int rcar_pci_probe(struct platform_device *pdev)
 	void __iomem *reg;
 	struct hw_pci hw;
 	void *hw_private[1];
+	struct clk *clk;
+	int ret;
 
 	cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	reg = devm_ioremap_resource(dev, cfg_res);
@@ -376,7 +380,6 @@ static int rcar_pci_probe(struct platform_device *pdev)
 
 	if (dev->of_node) {
 		struct resource busnr;
-		int ret;
 
 		ret = of_pci_parse_bus_range(dev->of_node, &busnr);
 		if (ret < 0) {
@@ -397,6 +400,14 @@ static int rcar_pci_probe(struct platform_device *pdev)
 		priv->busnr = pdev->id;
 	}
 
+	clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		return ret;
+	priv->clk = clk;
+
 	hw_private[0] = priv;
 	memset(&hw, 0, sizeof(hw));
 	hw.nr_controllers = ARRAY_SIZE(hw_private);
@@ -409,6 +420,27 @@ static int rcar_pci_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int __maybe_unused pci_rcar_gen2_suspend_noirq(struct device *dev)
+{
+	struct rcar_pci_priv *priv = dev_get_drvdata(dev);
+
+	clk_disable_unprepare(priv->clk);
+	return 0;
+}
+
+static int __maybe_unused pci_rcar_gen2_resume_noirq(struct device *dev)
+{
+	struct rcar_pci_priv *priv = dev_get_drvdata(dev);
+
+	clk_prepare_enable(priv->clk);
+	return 0;
+}
+
+static const struct dev_pm_ops pci_rcar_gen2_pm_ops = {
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pci_rcar_gen2_suspend_noirq,
+				      pci_rcar_gen2_resume_noirq)
+};
+
 static const struct of_device_id rcar_pci_of_match[] = {
 	{ .compatible = "renesas,pci-r8a7790", },
 	{ .compatible = "renesas,pci-r8a7791", },
@@ -422,6 +454,7 @@ static struct platform_driver rcar_pci_driver = {
 		.name = "pci-rcar-gen2",
 		.suppress_bind_attrs = true,
 		.of_match_table = rcar_pci_of_match,
+		.pm = &pci_rcar_gen2_pm_ops,
 	},
 	.probe = rcar_pci_probe,
 };
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-25  9:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 16:11 [PATCH] PCI: rcar-gen2: Ensure the mandatory clock is enabled Gareth Williams
2019-03-22 19:14 ` Geert Uytterhoeven
2019-03-25  9:49   ` Gareth Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).