[PATCH v4 2/3] drivercore: Bind/unbind power domain on probe/remove

Tomasz Figa t.figa at samsung.com
Thu May 8 05:45:08 PDT 2014

On a number of platforms, devices are part of controllable power
domains, which need to be enabled before such devices can be accessed
and may be powered down when the device is idle to save some power.
This means that on systems that support power domain control using
generic power domains subsystem, it is necessary to add device to its
power domain before binding a driver to it and remove it from its power
domain after its driver is unbound to make sure that an unused device
does not affect power domain state.

Since this is not limited to particular busses and specific
archs/platforms, it is more convenient to do the above directly in
driver core, just as done with pinctrl default configuration. This patch
adds necessary code to really_probe() and __device_release_driver() to
achieve this and maintain consistent stack-like ordering of operations
happening when binding and unbinding a driver.

Signed-off-by: Tomasz Figa <t.figa at samsung.com>
Reviewed-by: Stephen Boyd <sboyd at codeaurora.org>
Reviewed-by: Philipp Zabel <philipp.zabel at gmail.com>
[on i.MX6 GK802]
Tested-by: Philipp Zabel <philipp.zabel at gmail.com>
Reviewed-by: Mark Brown <broonie at linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson at linaro.org>
 drivers/base/dd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 62ec61e..9489b3a 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -23,6 +23,7 @@
 #include <linux/kthread.h>
 #include <linux/wait.h>
 #include <linux/async.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/pinctrl/devinfo.h>
@@ -287,6 +288,11 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	dev->driver = drv;
+	/* If using genpd, bind power domain now before probing */
+	ret = genpd_bind_domain(dev);
+	if (ret)
+		goto probe_failed;
 	/* If using pinctrl, bind pins now before probing */
 	ret = pinctrl_bind_pins(dev);
 	if (ret)
@@ -317,6 +323,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
+	genpd_unbind_domain(dev);
 	dev->driver = NULL;
 	dev_set_drvdata(dev, NULL);
@@ -530,7 +537,7 @@ static void __device_release_driver(struct device *dev)
+		genpd_unbind_domain(dev);

More information about the linux-arm-kernel mailing list