blob: 7b3cc3c15b9d82eecfaf3ca7c9e66f7c1afcbc61 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/device.h>
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070023#include <linux/mutex.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "power.h"
26
27LIST_HEAD(dpm_active);
28LIST_HEAD(dpm_off);
29LIST_HEAD(dpm_off_irq);
30
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070031DEFINE_MUTEX(dpm_mtx);
32DEFINE_MUTEX(dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
David Brownell075c1772007-04-26 00:12:06 -070034int (*platform_enable_wakeup)(struct device *dev, int is_on);
35
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/**
38 * device_pm_set_parent - Specify power dependency.
39 * @dev: Device who needs power.
40 * @parent: Device that supplies power.
41 *
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.
48 */
49
50void device_pm_set_parent(struct device * dev, struct device * parent)
51{
David Brownelle9b7bd42005-09-22 22:30:48 -070052 put_device(dev->power.pm_parent);
53 dev->power.pm_parent = get_device(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55EXPORT_SYMBOL_GPL(device_pm_set_parent);
56
57int device_pm_add(struct device * dev)
58{
59 int error;
60
61 pr_debug("PM: Adding info for %s:%s\n",
Dmitry Torokhovc48ea602007-04-11 01:37:18 -040062 dev->bus ? dev->bus->name : "No Bus",
63 kobject_name(&dev->kobj));
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070064 mutex_lock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 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);
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070069 mutex_unlock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return error;
71}
72
73void device_pm_remove(struct device * dev)
74{
75 pr_debug("PM: Removing info for %s:%s\n",
Dmitry Torokhovc48ea602007-04-11 01:37:18 -040076 dev->bus ? dev->bus->name : "No Bus",
77 kobject_name(&dev->kobj));
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070078 mutex_lock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 dpm_sysfs_remove(dev);
David Brownelle9b7bd42005-09-22 22:30:48 -070080 put_device(dev->power.pm_parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 list_del_init(&dev->power.entry);
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070082 mutex_unlock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
85