Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/device.h> |
| 23 | #include "power.h" |
| 24 | |
| 25 | LIST_HEAD(dpm_active); |
| 26 | LIST_HEAD(dpm_off); |
| 27 | LIST_HEAD(dpm_off_irq); |
| 28 | |
| 29 | DECLARE_MUTEX(dpm_sem); |
| 30 | DECLARE_MUTEX(dpm_list_sem); |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /** |
| 33 | * device_pm_set_parent - Specify power dependency. |
| 34 | * @dev: Device who needs power. |
| 35 | * @parent: Device that supplies power. |
| 36 | * |
| 37 | * This function is used to manually describe a power-dependency |
| 38 | * relationship. It may be used to specify a transversal relationship |
| 39 | * (where the power supplier is not the physical (or electrical) |
| 40 | * ancestor of a specific device. |
| 41 | * The effect of this is that the supplier will not be powered down |
| 42 | * before the power dependent. |
| 43 | */ |
| 44 | |
| 45 | void device_pm_set_parent(struct device * dev, struct device * parent) |
| 46 | { |
David Brownell | e9b7bd4 | 2005-09-22 22:30:48 -0700 | [diff] [blame] | 47 | put_device(dev->power.pm_parent); |
| 48 | dev->power.pm_parent = get_device(parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | EXPORT_SYMBOL_GPL(device_pm_set_parent); |
| 51 | |
| 52 | int device_pm_add(struct device * dev) |
| 53 | { |
| 54 | int error; |
| 55 | |
| 56 | pr_debug("PM: Adding info for %s:%s\n", |
| 57 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | down(&dpm_list_sem); |
| 59 | list_add_tail(&dev->power.entry, &dpm_active); |
| 60 | device_pm_set_parent(dev, dev->parent); |
| 61 | if ((error = dpm_sysfs_add(dev))) |
| 62 | list_del(&dev->power.entry); |
| 63 | up(&dpm_list_sem); |
| 64 | return error; |
| 65 | } |
| 66 | |
| 67 | void device_pm_remove(struct device * dev) |
| 68 | { |
| 69 | pr_debug("PM: Removing info for %s:%s\n", |
| 70 | dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); |
| 71 | down(&dpm_list_sem); |
| 72 | dpm_sysfs_remove(dev); |
David Brownell | e9b7bd4 | 2005-09-22 22:30:48 -0700 | [diff] [blame] | 73 | put_device(dev->power.pm_parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | list_del_init(&dev->power.entry); |
| 75 | up(&dpm_list_sem); |
| 76 | } |
| 77 | |
| 78 | |