blob: 0d2e101e4f158c60b88f66db966d5047b2dc05ed [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/base/power/main.c - Where the driver meets power management.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 * This file is released under the GPLv2
8 *
9 *
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.
14 *
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.
20 */
21
22#include <linux/config.h>
23#include <linux/device.h>
24#include "power.h"
25
26LIST_HEAD(dpm_active);
27LIST_HEAD(dpm_off);
28LIST_HEAD(dpm_off_irq);
29
30DECLARE_MUTEX(dpm_sem);
31DECLARE_MUTEX(dpm_list_sem);
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/**
34 * device_pm_set_parent - Specify power dependency.
35 * @dev: Device who needs power.
36 * @parent: Device that supplies power.
37 *
38 * This function is used to manually describe a power-dependency
39 * relationship. It may be used to specify a transversal relationship
40 * (where the power supplier is not the physical (or electrical)
41 * ancestor of a specific device.
42 * The effect of this is that the supplier will not be powered down
43 * before the power dependent.
44 */
45
46void device_pm_set_parent(struct device * dev, struct device * parent)
47{
David Brownelle9b7bd42005-09-22 22:30:48 -070048 put_device(dev->power.pm_parent);
49 dev->power.pm_parent = get_device(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51EXPORT_SYMBOL_GPL(device_pm_set_parent);
52
53int device_pm_add(struct device * dev)
54{
55 int error;
56
57 pr_debug("PM: Adding info for %s:%s\n",
58 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 down(&dpm_list_sem);
60 list_add_tail(&dev->power.entry, &dpm_active);
61 device_pm_set_parent(dev, dev->parent);
62 if ((error = dpm_sysfs_add(dev)))
63 list_del(&dev->power.entry);
64 up(&dpm_list_sem);
65 return error;
66}
67
68void device_pm_remove(struct device * dev)
69{
70 pr_debug("PM: Removing info for %s:%s\n",
71 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
72 down(&dpm_list_sem);
73 dpm_sysfs_remove(dev);
David Brownelle9b7bd42005-09-22 22:30:48 -070074 put_device(dev->power.pm_parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 list_del_init(&dev->power.entry);
76 up(&dpm_list_sem);
77}
78
79