Skip to contentSkip to conversation

can: c_can: Move pm_runtime_enable/disable calls to common code

PATCH In review AnilKumar Ch 3 participants 6 messages Sep 13, 2012 CAN network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: c_can: Move pm_runtime_enable/disable calls to common code

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

This patch is tested on AM335x-EVM and cleanly applies on linux-can master

 drivers/net/can/c_can/c_can.c          |   18 +++++++++++++++++-
 drivers/net/can/c_can/c_can_platform.c |    5 -----
 2 files changed, 17 insertions(+), 6 deletions(-)
drivers/net/can/c_can/c_can.c +17 -1
index aa6c5eb..e472975 100644
@@ -1155,10 +1155,23 @@ static const struct net_device_ops c_can_netdev_ops = {
 
 int register_c_can_dev(struct net_device *dev)
 {
+	int ret;
+	struct c_can_priv *priv = netdev_priv(dev);
+
+	if (priv->device)
+		pm_runtime_enable(priv->device);
+
 	dev->flags |= IFF_ECHO;	/* we support local echo */
 	dev->netdev_ops = &c_can_netdev_ops;
 
-	return register_candev(dev);
+	ret = register_candev(dev);
+	if (ret) {
+		if (priv->device)
+			pm_runtime_disable(priv->device);
+		return ret;
+	}
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(register_c_can_dev);
 
@@ -1170,6 +1183,9 @@ void unregister_c_can_dev(struct net_device *dev)
 	c_can_enable_all_interrupts(priv, DISABLE_ALL_INTERRUPTS);
 
 	unregister_candev(dev);
+
+	if (priv->device)
+		pm_runtime_disable(priv->device);
 }
 EXPORT_SYMBOL_GPL(unregister_c_can_dev);
 
drivers/net/can/c_can/c_can_platform.c +0 -5
index c351975..491101a 100644
@@ -32,7 +32,6 @@
 #include <linux/clk.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/pm_runtime.h>
 #include <linux/pinctrl/consumer.h>
 
 #include <linux/can/dev.h>
@@ -185,8 +184,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 		goto exit_free_device;
 	}
 
-	pm_runtime_enable(&pdev->dev);
-
 	dev->irq = irq;
 	priv->base = addr;
 	priv->device = &pdev->dev;
@@ -209,7 +206,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 
 exit_clear_drvdata:
 	platform_set_drvdata(pdev, NULL);
-	pm_runtime_disable(&pdev->dev);
 exit_free_device:
 	free_c_can_dev(dev);
 exit_iounmap:
@@ -239,7 +235,6 @@ static int __devexit c_can_plat_remove(struct platform_device *pdev)
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(mem->start, resource_size(mem));
 
-	pm_runtime_disable(&pdev->dev);
 	clk_put(priv->priv);
 
 	return 0;
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 8 lines · AnilKumar Ch

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

Quoted 7 lines

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

This patch is tested on AM335x-EVM and cleanly applies on linux-can master

I'll squash this into "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller".

Quoted 10 lines
 drivers/net/can/c_can/c_can.c          |   18 +++++++++++++++++-
 drivers/net/can/c_can/c_can_platform.c |    5 -----
 2 files changed, 17 insertions(+), 6 deletions(-)
drivers/net/can/c_can/c_can.c +0 -0
index aa6c5eb..e472975 100644

drivers/net/can/c_can/c_can.c static const struct net_device_ops c_can_netdev_ops = { · line 1162

Quoted 8 lines
drivers/net/can/c_can/c_can.c +5 -0
@@ -1155,10 +1155,23 @@ static const struct net_device_ops c_can_netdev_ops = {
 
 int register_c_can_dev(struct net_device *dev)
 {
+	int ret;
+	struct c_can_priv *priv = netdev_priv(dev);
+
+	if (priv->device)
+		pm_runtime_enable(priv->device);

I'll add a static inline for these two new function, too.

Quoted 48 lines
drivers/net/can/c_can/c_can.c +12 -1
+
 	dev->flags |= IFF_ECHO;	/* we support local echo */
 	dev->netdev_ops = &c_can_netdev_ops;
 
-	return register_candev(dev);
+	ret = register_candev(dev);
+	if (ret) {
+		if (priv->device)
+			pm_runtime_disable(priv->device);
+		return ret;
+	}
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(register_c_can_dev);
 
@@ -1170,6 +1183,9 @@ void unregister_c_can_dev(struct net_device *dev)
 	c_can_enable_all_interrupts(priv, DISABLE_ALL_INTERRUPTS);
 
 	unregister_candev(dev);
+
+	if (priv->device)
+		pm_runtime_disable(priv->device);
 }
 EXPORT_SYMBOL_GPL(unregister_c_can_dev);
 
drivers/net/can/c_can/c_can_platform.c +0 -3
index c351975..491101a 100644
@@ -32,7 +32,6 @@
 #include <linux/clk.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/pm_runtime.h>
 #include <linux/pinctrl/consumer.h>
 
 #include <linux/can/dev.h>
@@ -185,8 +184,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 		goto exit_free_device;
 	}
 
-	pm_runtime_enable(&pdev->dev);
-
 	dev->irq = irq;
 	priv->base = addr;
 	priv->device = &pdev->dev;

drivers/net/can/c_can/c_can_platform.c static int __devinit c_can_plat_probe(struct platform_device *pdev) · line 212

Quoted 4 lines
drivers/net/can/c_can/c_can_platform.c +0 -1
@@ -209,7 +206,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 
 exit_clear_drvdata:
 	platform_set_drvdata(pdev, NULL);
-	pm_runtime_disable(&pdev->dev);

When squaahsing both patches we see still some changes here, I'll fix that, too.

drivers/net/can/c_can/c_can_platform.c static int __devexit c_can_plat_remove(struct platform_device *pdev) · line 240

Quoted 12 lines
drivers/net/can/c_can/c_can_platform.c +0 -1
 exit_free_device:
 	free_c_can_dev(dev);
 exit_iounmap:
@@ -239,7 +235,6 @@ static int __devexit c_can_plat_remove(struct platform_device *pdev)
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(mem->start, resource_size(mem));
 
-	pm_runtime_disable(&pdev->dev);
 	clk_put(priv->priv);
 
 	return 0;

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#2 lore raw

Marc,

Quoted 30 lines · Marc Kleine-Budde
Quoted 8 lines · AnilKumar Ch

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

Quoted 7 lines

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

This patch is tested on AM335x-EVM and cleanly applies on linux-can master

I'll squash this into "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller".

Quoted 11 lines
 drivers/net/can/c_can/c_can.c          |   18 +++++++++++++++++-
 drivers/net/can/c_can/c_can_platform.c |    5 -----
 2 files changed, 17 insertions(+), 6 deletions(-)
drivers/net/can/c_can/c_can.c +0 -0
index aa6c5eb..e472975 100644
@@ -1155,10 +1155,23 @@ static const struct net_device_ops c_can_netdev_ops = {
 
Quoted 9 lines

drivers/net/can/c_can/c_can.c static const struct net_device_ops c_can_netdev_ops = { · line 1162

Quoted 7 lines
drivers/net/can/c_can/c_can.c +5 -0
 int register_c_can_dev(struct net_device *dev)
 {
+	int ret;
+	struct c_can_priv *priv = netdev_priv(dev);
+
+	if (priv->device)
+		pm_runtime_enable(priv->device);

I'll add a static inline for these two new function, too.

My bad, this should be my first change.

Quoted 50 lines
Quoted 50 lines
drivers/net/can/c_can/c_can.c +12 -1
+
 	dev->flags |= IFF_ECHO;	/* we support local echo */
 	dev->netdev_ops = &c_can_netdev_ops;
 
-	return register_candev(dev);
+	ret = register_candev(dev);
+	if (ret) {
+		if (priv->device)
+			pm_runtime_disable(priv->device);
+		return ret;
+	}
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(register_c_can_dev);
 
@@ -1170,6 +1183,9 @@ void unregister_c_can_dev(struct net_device *dev)
 	c_can_enable_all_interrupts(priv, DISABLE_ALL_INTERRUPTS);
 
 	unregister_candev(dev);
+
+	if (priv->device)
+		pm_runtime_disable(priv->device);
 }
 EXPORT_SYMBOL_GPL(unregister_c_can_dev);
 
drivers/net/can/c_can/c_can_platform.c +0 -3
index c351975..491101a 100644
@@ -32,7 +32,6 @@
 #include <linux/clk.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/pm_runtime.h>
 #include <linux/pinctrl/consumer.h>
 
 #include <linux/can/dev.h>
@@ -185,8 +184,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 		goto exit_free_device;
 	}
 
-	pm_runtime_enable(&pdev->dev);
-
 	dev->irq = irq;
 	priv->base = addr;
 	priv->device = &pdev->dev;
@@ -209,7 +206,6 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 
Quoted 6 lines

drivers/net/can/c_can/c_can_platform.c static int __devinit c_can_plat_probe(struct platform_device *pdev) · line 212

Quoted 3 lines
drivers/net/can/c_can/c_can_platform.c +0 -1
 exit_clear_drvdata:
 	platform_set_drvdata(pdev, NULL);
-	pm_runtime_disable(&pdev->dev);

When squaahsing both patches we see still some changes here, I'll fix that, too.

Thanks Marc

Thanks
AnilKumar

#3 lore raw
In reply to AnilKumar Ch
Quoted 4 lines · AnilKumar Ch

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

Quoted 8 lines

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

This looks better, but in addition, you can get rid of the runtime PM helper functions you added (the ones that check for priv->device) and call the pm_runtime_get/put APIs directly.

Kevin

#4 lore raw
Quoted 10 lines · Kevin Hilman
Quoted 8 lines · AnilKumar Ch

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

Quoted 8 lines
Quoted 4 lines

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

This looks better, but in addition, you can get rid of the runtime PM helper functions you added (the ones that check for priv->device) and call the pm_runtime_get/put APIs directly.

But priv->device might be NULL. AFAICS pm_runtime_get() is not safe to be called with a NULL pointer.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#5 lore raw
Quoted 16 lines · Marc Kleine-Budde
Quoted 15 lines · Kevin Hilman
Quoted 12 lines · AnilKumar Ch

Move pm_runtime_enable/disable calls to c_can.c driver. Current implementation is such that platform driver is doing pm_runtime enable/disable and core driver is doing put_sync/get_sync.

PM runtime calls should be invoked if there is a valid device pointer from platform driver so moving enable/disable calls to core driver.

---
Incorporated Kevin's comments on "can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller" patch.

Quoted 6 lines
Quoted 3 lines

This looks better, but in addition, you can get rid of the runtime PM helper functions you added (the ones that check for priv->device) and call the pm_runtime_get/put APIs directly.

But priv->device might be NULL. AFAICS pm_runtime_get() is not safe to be called with a NULL pointer.

Yes, you're right. Guess there's not a clean way to get rid of those helpers.

Sorry for the noise,

Kevin