Skip to contentSkip to conversation

can: m_can: Add PM Runtime Support

PATCH Superseded Franklin S Cooper Jr 3 participants 6 messages Jul 19, 2017 – Jul 24, 2017

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover can: m_can: Add PM Runtime Support

Add PM runtime support to the MCAN driver. To support devices that don't use PM runtime leave the original clk calls in the driver. Perhaps in the future when it makes sense we can remove these non pm runtime clk calls.

Franklin S Cooper Jr (3):
can: m_can: Make hclk optional
can: m_can: Update documentation to indicate that hclk may be optional
can: m_can: Add PM Runtime

 .../devicetree/bindings/net/can/m_can.txt          |  3 ++-
 drivers/net/can/m_can/m_can.c                      | 22 ++++++++++++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
Signature · 1 line
2.10.0
#1 lore raw

PATCH 1/3 can: m_can: Make hclk optional

Hclk is the MCAN's interface clock. However, for OMAP based devices such as DRA7 SoC family the interface clock is handled by hwmod. Therefore, this interface clock is managed by hwmod driver via pm_runtime_get and pm_runtime_put calls. Therefore, this interface clock isn't defined in DT and thus the driver shouldn't fail if this clock isn't found.

---
 drivers/net/can/m_can/m_can.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +7 -2
index f4947a7..7fe9145 100644
@@ -1568,8 +1568,13 @@ static int m_can_plat_probe(struct platform_device *pdev)
 	hclk = devm_clk_get(&pdev->dev, "hclk");
 	cclk = devm_clk_get(&pdev->dev, "cclk");
 
-	if (IS_ERR(hclk) || IS_ERR(cclk)) {
-		dev_err(&pdev->dev, "no clock found\n");
+	if (IS_ERR(hclk)) {
+		dev_warn(&pdev->dev, "can't find hclk\n");
+		hclk = 0;
+	}
+
+	if (IS_ERR(cclk)) {
+		dev_err(&pdev->dev, "cclk could not be found\n");
 		ret = -ENODEV;
 		goto failed_ret;
 	}
Signature · 6 lines
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/3 can: m_can: Update documentation to indicate that hclk may be optional

In reply to Franklin S Cooper Jr

Update the documentation to reflect that hclk is now an optional clock.

---
 Documentation/devicetree/bindings/net/can/m_can.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/can/m_can.txt +2 -1
index 9e33177..2a0fe5b 100644
@@ -12,7 +12,8 @@ Required properties:
 - interrupt-names	: Should contain "int0" and "int1"
 - clocks		: Clocks used by controller, should be host clock
 			  and CAN clock.
-- clock-names		: Should contain "hclk" and "cclk"
+- clock-names		: Should contain "hclk" and "cclk". For some socs hclk
+			  may be optional.
 - pinctrl-<n>		: Pinctrl states as described in bindings/pinctrl/pinctrl-bindings.txt
 - pinctrl-names 	: Names corresponding to the numbered pinctrl states
 - bosch,mram-cfg	: Message RAM configuration data.
Signature · 1 line
2.10.0
#5 lore raw

PATCH 3/3 can: m_can: Add PM Runtime

In reply to Franklin S Cooper Jr

Add support for PM Runtime which is the new way to handle managing clocks. However, to avoid breaking SoCs not using PM_RUNTIME leave the old clk management approach in place.

PM_RUNTIME is required by OMAP based devices to handle clock management. Therefore, this allows future Texas Instruments SoCs that have the MCAN IP to work with this driver.

---
 drivers/net/can/m_can/m_can.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/can/m_can/m_can.c +13 -0
index 7fe9145..eb45cd5 100644
@@ -23,6 +23,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/iopoll.h>
 #include <linux/can/dev.h>
 
@@ -633,11 +634,15 @@ static int m_can_clk_start(struct m_can_priv *priv)
 	if (err)
 		clk_disable_unprepare(priv->hclk);
 
+	pm_runtime_get_sync(priv->device);
+
 	return err;
 }
 
 static void m_can_clk_stop(struct m_can_priv *priv)
 {
+	pm_runtime_put_sync(priv->device);
+
 	clk_disable_unprepare(priv->cclk);
 	clk_disable_unprepare(priv->hclk);
 }
@@ -1582,6 +1587,8 @@ static int m_can_plat_probe(struct platform_device *pdev)
 	/* Enable clocks. Necessary to read Core Release in order to determine
 	 * M_CAN version
 	 */
+	pm_runtime_enable(&pdev->dev);
+
 	ret = clk_prepare_enable(hclk);
 	if (ret)
 		goto disable_hclk_ret;
@@ -1626,6 +1633,8 @@ static int m_can_plat_probe(struct platform_device *pdev)
 	 */
 	tx_fifo_size = mram_config_vals[7];
 
+	pm_runtime_get_sync(&pdev->dev);
+
 	/* allocate the m_can device */
 	dev = alloc_m_can_dev(pdev, addr, tx_fifo_size);
 	if (!dev) {
@@ -1670,6 +1679,7 @@ static int m_can_plat_probe(struct platform_device *pdev)
 disable_hclk_ret:
 	clk_disable_unprepare(hclk);
 failed_ret:
+	pm_runtime_put_sync(&pdev->dev);
 	return ret;
 }
 
@@ -1726,6 +1736,9 @@ static int m_can_plat_remove(struct platform_device *pdev)
 	struct net_device *dev = platform_get_drvdata(pdev);
 
 	unregister_m_can_dev(dev);
+
+	pm_runtime_disable(&pdev->dev);
+
 	platform_set_drvdata(pdev, NULL);
 
 	free_m_can_dev(dev);
Signature · 1 line
2.10.0
#2 lore raw

Re: [PATCH 1/3] can: m_can: Make hclk optional

In reply to Franklin S Cooper Jr

Hello!

Quoted 16 lines · Franklin S Cooper Jr

Hclk is the MCAN's interface clock. However, for OMAP based devices such as DRA7 SoC family the interface clock is handled by hwmod. Therefore, this interface clock is managed by hwmod driver via pm_runtime_get and pm_runtime_put calls. Therefore, this interface clock isn't defined in DT and thus the driver shouldn't fail if this clock isn't found.

---
  drivers/net/can/m_can/m_can.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +0 -0
index f4947a7..7fe9145 100644

drivers/net/can/m_can/m_can.c static int m_can_plat_probe(struct platform_device *pdev) · line 1573

Quoted 8 lines
drivers/net/can/m_can/m_can.c +3 -2
@@ -1568,8 +1568,13 @@ static int m_can_plat_probe(struct platform_device *pdev)
  	hclk = devm_clk_get(&pdev->dev, "hclk");
  	cclk = devm_clk_get(&pdev->dev, "cclk");
 
-	if (IS_ERR(hclk) || IS_ERR(cclk)) {
-		dev_err(&pdev->dev, "no clock found\n");
+	if (IS_ERR(hclk)) {
+		dev_warn(&pdev->dev, "can't find hclk\n");
+		hclk = 0;

s/0/NULL/.

[...]

MBR, Sergei

maintainer Acked-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] can: m_can: Update documentation to indicate that hclk may be optional

In reply to Franklin S Cooper Jr
Quoted 6 lines · Franklin S Cooper Jr

Update the documentation to reflect that hclk is now an optional clock.

---
 Documentation/devicetree/bindings/net/can/m_can.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)