]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
PM / Domains: add setter for dev.pm_domain
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Thu, 7 Jan 2016 15:46:13 +0000 (16:46 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 8 Jan 2016 00:12:06 +0000 (01:12 +0100)
Adds a function that sets the pointer to dev_pm_domain in struct device
and that warns if the device has already finished probing. The reason
why we want to enforce that is because in the general case that can
cause problems and also that we can simplify code quite a bit if we can
always assume that.

This patch also changes all current code that directly sets the
dev.pm_domain pointer.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
arch/arm/mach-omap2/omap_device.c
drivers/acpi/acpi_lpss.c
drivers/acpi/device_pm.c
drivers/base/power/clock_ops.c
drivers/base/power/common.c
drivers/base/power/domain.c
drivers/gpu/vga/vga_switcheroo.c
drivers/misc/mei/pci-me.c
drivers/misc/mei/pci-txe.c
include/linux/pm_domain.h

index 72ebc4c16bae7e55a69775b02bfc534b9c56fda4..220822bcfe3fd92d7fd94751860e71bcd3464132 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/io.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
 #include <linux/notifier.h>
@@ -168,7 +169,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
                        r->name = dev_name(&pdev->dev);
        }
 
-       pdev->dev.pm_domain = &omap_device_pm_domain;
+       dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);
 
        if (device_active) {
                omap_device_enable(pdev);
@@ -180,7 +181,7 @@ static int omap_device_build_from_dt(struct platform_device *pdev)
 odbfd_exit:
        /* if data/we are at fault.. load up a fail handler */
        if (ret)
-               pdev->dev.pm_domain = &omap_device_fail_pm_domain;
+               dev_pm_domain_set(&pdev->dev, &omap_device_fail_pm_domain);
 
        return ret;
 }
@@ -701,7 +702,7 @@ int omap_device_register(struct platform_device *pdev)
 {
        pr_debug("omap_device: %s: registering\n", pdev->name);
 
-       pdev->dev.pm_domain = &omap_device_pm_domain;
+       dev_pm_domain_set(&pdev->dev, &omap_device_pm_domain);
        return platform_device_add(pdev);
 }
 
index 047281a6ae11f175c67d7d2035fceed702bb78e5..c570b1d9f09480ecec5513d3cfe61d33c26c81b5 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/clk-lpss.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/delay.h>
 
@@ -875,13 +876,14 @@ static int acpi_lpss_platform_notify(struct notifier_block *nb,
 
        switch (action) {
        case BUS_NOTIFY_BIND_DRIVER:
-               pdev->dev.pm_domain = &acpi_lpss_pm_domain;
+               dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
                break;
        case BUS_NOTIFY_DRIVER_NOT_BOUND:
        case BUS_NOTIFY_UNBOUND_DRIVER:
                pdev->dev.pm_domain = NULL;
                break;
        case BUS_NOTIFY_ADD_DEVICE:
+               dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
                if (pdata->dev_desc->flags & LPSS_LTR)
                        return sysfs_create_group(&pdev->dev.kobj,
                                                  &lpss_attr_group);
@@ -889,6 +891,7 @@ static int acpi_lpss_platform_notify(struct notifier_block *nb,
        case BUS_NOTIFY_DEL_DEVICE:
                if (pdata->dev_desc->flags & LPSS_LTR)
                        sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
+               dev_pm_domain_set(&pdev->dev, NULL);
                break;
        default:
                break;
index 08a02cdc737c193d608970b6eec0b45781137d76..cd2c3d6d40e03fbc70ef802dd82c4e1ae36c7ef3 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/export.h>
 #include <linux/mutex.h>
 #include <linux/pm_qos.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 
 #include "internal.h"
@@ -1059,7 +1060,7 @@ static void acpi_dev_pm_detach(struct device *dev, bool power_off)
        struct acpi_device *adev = ACPI_COMPANION(dev);
 
        if (adev && dev->pm_domain == &acpi_general_pm_domain) {
-               dev->pm_domain = NULL;
+               dev_pm_domain_set(dev, NULL);
                acpi_remove_pm_notifier(adev);
                if (power_off) {
                        /*
@@ -1111,7 +1112,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
                return -EBUSY;
 
        acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
-       dev->pm_domain = &acpi_general_pm_domain;
+       dev_pm_domain_set(dev, &acpi_general_pm_domain);
        if (power_on) {
                acpi_dev_pm_full_power(adev);
                acpi_device_wakeup(adev, ACPI_STATE_S0, false);
index c39b8617280feff712096e6699ffe6d4f3db13f8..272a52ebafc09d0c4a3d974b6ca0bf16aef5e612 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/clkdev.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 
 #ifdef CONFIG_PM_CLK
@@ -348,7 +349,7 @@ static int pm_clk_notify(struct notifier_block *nb,
                if (error)
                        break;
 
-               dev->pm_domain = clknb->pm_domain;
+               dev_pm_domain_set(dev, clknb->pm_domain);
                if (clknb->con_ids[0]) {
                        for (con_id = clknb->con_ids; *con_id; con_id++)
                                pm_clk_add(dev, *con_id);
@@ -361,7 +362,7 @@ static int pm_clk_notify(struct notifier_block *nb,
                if (dev->pm_domain != clknb->pm_domain)
                        break;
 
-               dev->pm_domain = NULL;
+               dev_pm_domain_set(dev, NULL);
                pm_clk_destroy(dev);
                break;
        }
index f48e33385b3e136029c6770505a3dcee3d313e86..02812bcabcac7985be4ed3421d2b4eb2c65846f6 100644 (file)
@@ -128,3 +128,24 @@ void dev_pm_domain_detach(struct device *dev, bool power_off)
                dev->pm_domain->detach(dev, power_off);
 }
 EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
+
+/**
+ * dev_pm_domain_set - Set PM domain of a device.
+ * @dev: Device whose PM domain is to be set.
+ * @pd: PM domain to be set, or NULL.
+ *
+ * Sets the PM domain the device belongs to. The PM domain of a device needs
+ * to be set before its probe finishes (it's bound to a driver).
+ *
+ * This function must be called with the device lock held.
+ */
+void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
+{
+       if (dev->pm_domain == pd)
+               return;
+
+       WARN(device_is_bound(dev),
+            "PM domains can only be changed for unbound devices\n");
+       dev->pm_domain = pd;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_set);
index 167418e73445a4f69b372f9205f65ca43f525c9d..abbac6fe8fd50dadedac2f6aa63137b61188c8ef 100644 (file)
@@ -1177,10 +1177,11 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
        }
 
        dev->power.subsys_data->domain_data = &gpd_data->base;
-       dev->pm_domain = &genpd->domain;
 
        spin_unlock_irq(&dev->power.lock);
 
+       dev_pm_domain_set(dev, &genpd->domain);
+
        return gpd_data;
 
  err_free:
@@ -1194,9 +1195,10 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
 static void genpd_free_dev_data(struct device *dev,
                                struct generic_pm_domain_data *gpd_data)
 {
+       dev_pm_domain_set(dev, NULL);
+
        spin_lock_irq(&dev->power.lock);
 
-       dev->pm_domain = NULL;
        dev->power.subsys_data->domain_data = NULL;
 
        spin_unlock_irq(&dev->power.lock);
index 41edd5a3f10097e8c030b076397fec389448319d..7b95ed2fb49bb44fa281669c1e471b0211a452ae 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
@@ -918,17 +919,17 @@ int vga_switcheroo_init_domain_pm_ops(struct device *dev,
                domain->ops.runtime_suspend = vga_switcheroo_runtime_suspend;
                domain->ops.runtime_resume = vga_switcheroo_runtime_resume;
 
-               dev->pm_domain = domain;
+               dev_pm_domain_set(dev, domain);
                return 0;
        }
-       dev->pm_domain = NULL;
+       dev_pm_domain_set(dev, NULL);
        return -EINVAL;
 }
 EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_ops);
 
 void vga_switcheroo_fini_domain_pm_ops(struct device *dev)
 {
-       dev->pm_domain = NULL;
+       dev_pm_domain_set(dev, NULL);
 }
 EXPORT_SYMBOL(vga_switcheroo_fini_domain_pm_ops);
 
@@ -989,10 +990,10 @@ vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev,
                domain->ops.runtime_resume =
                        vga_switcheroo_runtime_resume_hdmi_audio;
 
-               dev->pm_domain = domain;
+               dev_pm_domain_set(dev, domain);
                return 0;
        }
-       dev->pm_domain = NULL;
+       dev_pm_domain_set(dev, NULL);
        return -EINVAL;
 }
 EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_optimus_hdmi_audio);
index 27678d8154e074ea698952832aac64bb843032f9..75fc9c688df8fc6fac004c78d8067061eff70749 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/jiffies.h>
 #include <linux/interrupt.h>
 
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 
 #include <linux/mei.h>
@@ -436,7 +437,7 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev)
                dev->pg_domain.ops.runtime_resume = mei_me_pm_runtime_resume;
                dev->pg_domain.ops.runtime_idle = mei_me_pm_runtime_idle;
 
-               pdev->dev.pm_domain = &dev->pg_domain;
+               dev_pm_domain_set(&pdev->dev, &dev->pg_domain);
        }
 }
 
@@ -448,7 +449,7 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev)
 static inline void mei_me_unset_pm_domain(struct mei_device *dev)
 {
        /* stop using pm callbacks if any */
-       dev->dev->pm_domain = NULL;
+       dev_pm_domain_set(dev->dev, NULL);
 }
 
 static const struct dev_pm_ops mei_me_pm_ops = {
index 0882c02019072bbdd43db49811ae86fc86d4ff52..71f8a747571756b0941a82f0ee6af99247464744 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/jiffies.h>
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 
 #include <linux/mei.h>
@@ -388,7 +389,7 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev)
                dev->pg_domain.ops.runtime_resume = mei_txe_pm_runtime_resume;
                dev->pg_domain.ops.runtime_idle = mei_txe_pm_runtime_idle;
 
-               pdev->dev.pm_domain = &dev->pg_domain;
+               dev_pm_domain_set(&pdev->dev, &dev->pg_domain);
        }
 }
 
@@ -400,7 +401,7 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev)
 static inline void mei_txe_unset_pm_domain(struct mei_device *dev)
 {
        /* stop using pm callbacks if any */
-       dev->dev->pm_domain = NULL;
+       dev_pm_domain_set(dev->dev, NULL);
 }
 
 static const struct dev_pm_ops mei_txe_pm_ops = {
index ba4ced38efae0c9249a97ea57c0cccd1ac37e7f7..db21d3995f7e339f7f7f7f1adf21536c7b9a4e8b 100644 (file)
@@ -240,12 +240,15 @@ static inline int of_genpd_add_provider_onecell(struct device_node *np,
 #ifdef CONFIG_PM
 extern int dev_pm_domain_attach(struct device *dev, bool power_on);
 extern void dev_pm_domain_detach(struct device *dev, bool power_off);
+extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
 #else
 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
 {
        return -ENODEV;
 }
 static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
+static inline void dev_pm_domain_set(struct device *dev,
+                                    struct dev_pm_domain *pd) {}
 #endif
 
 #endif /* _LINUX_PM_DOMAIN_H */