2 * drivers/base/power/main.c - Where the driver meets power management.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
7 * This file is released under the GPLv2
10 * The driver model core calls device_pm_add() when a device is registered.
11 * This will intialize the embedded device_pm_info object in the device
12 * and add it to the list of power-controlled devices. sysfs entries for
13 * controlling device power management will also be added.
15 * A different set of lists than the global subsystem list are used to
16 * keep track of power info because we use different lists to hold
17 * devices based on what stage of the power management process they
18 * are in. The power domain dependencies may also differ from the
19 * ancestral dependencies that the subsystem list maintains.
22 #include <linux/device.h>
23 #include <linux/mutex.h>
27 LIST_HEAD(dpm_active);
29 LIST_HEAD(dpm_off_irq);
31 DEFINE_MUTEX(dpm_mtx);
32 DEFINE_MUTEX(dpm_list_mtx);
34 int (*platform_enable_wakeup)(struct device *dev, int is_on);
38 * device_pm_set_parent - Specify power dependency.
39 * @dev: Device who needs power.
40 * @parent: Device that supplies power.
42 * This function is used to manually describe a power-dependency
43 * relationship. It may be used to specify a transversal relationship
44 * (where the power supplier is not the physical (or electrical)
45 * ancestor of a specific device.
46 * The effect of this is that the supplier will not be powered down
47 * before the power dependent.
50 void device_pm_set_parent(struct device * dev, struct device * parent)
52 put_device(dev->power.pm_parent);
53 dev->power.pm_parent = get_device(parent);
55 EXPORT_SYMBOL_GPL(device_pm_set_parent);
57 int device_pm_add(struct device * dev)
61 pr_debug("PM: Adding info for %s:%s\n",
62 dev->bus ? dev->bus->name : "No Bus",
63 kobject_name(&dev->kobj));
64 mutex_lock(&dpm_list_mtx);
65 list_add_tail(&dev->power.entry, &dpm_active);
66 device_pm_set_parent(dev, dev->parent);
67 if ((error = dpm_sysfs_add(dev)))
68 list_del(&dev->power.entry);
69 mutex_unlock(&dpm_list_mtx);
73 void device_pm_remove(struct device * dev)
75 pr_debug("PM: Removing info for %s:%s\n",
76 dev->bus ? dev->bus->name : "No Bus",
77 kobject_name(&dev->kobj));
78 mutex_lock(&dpm_list_mtx);
79 dpm_sysfs_remove(dev);
80 put_device(dev->power.pm_parent);
81 list_del_init(&dev->power.entry);
82 mutex_unlock(&dpm_list_mtx);