diff options
author | David Brownell <david-b@pacbell.net> | 2005-09-12 22:39:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 12:52:50 -0400 |
commit | 0ac85241ebc7bf6b86ab498960cc121d53ef69ae (patch) | |
tree | 8b5d9d5a3e475c49d771d1a4bd597ea561331ff7 /drivers/base | |
parent | 2a7ff1feda9f5cd6463744239ec5e661ee7d5f01 (diff) |
[PATCH] driver model wakeup flags
This is a refresh of an earlier patch to add "wakeup" support to the
PM core model. This provides per-device bus-neutral control of the
use of wakeup events.
* "struct device_pm_info" has two bits that are initialized as
part of setting up the enclosing struct device:
- "can_wakeup", reflecting hardware capabilities
- "may_wakeup", the policy setting (when CONFIG_PM)
* There's a writeable sysfs "wakeup" file, with one of two values:
- "enabled", when the policy is to allow wakeup
- "disabled", when the policy is not to allow it
- "" if the device can't currently issue wakeups
By default, wakeup is enabled on all devices that support it. If its
driver doesn't support it ... treat it as a bug. :)
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/core.c | 1 | ||||
-rw-r--r-- | drivers/base/power/sysfs.c | 73 |
2 files changed, 74 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 6ab73f5c799a..31109193e2c4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -225,6 +225,7 @@ void device_initialize(struct device *dev) | |||
225 | klist_children_put); | 225 | klist_children_put); |
226 | INIT_LIST_HEAD(&dev->dma_pools); | 226 | INIT_LIST_HEAD(&dev->dma_pools); |
227 | init_MUTEX(&dev->sem); | 227 | init_MUTEX(&dev->sem); |
228 | device_init_wakeup(dev, 0); | ||
228 | } | 229 | } |
229 | 230 | ||
230 | /** | 231 | /** |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index 8d04fb435c17..89c57875f3e5 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -48,8 +48,81 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
48 | static DEVICE_ATTR(state, 0644, state_show, state_store); | 48 | static DEVICE_ATTR(state, 0644, state_show, state_store); |
49 | 49 | ||
50 | 50 | ||
51 | /* | ||
52 | * wakeup - Report/change current wakeup option for device | ||
53 | * | ||
54 | * Some devices support "wakeup" events, which are hardware signals | ||
55 | * used to activate devices from suspended or low power states. Such | ||
56 | * devices have one of three values for the sysfs power/wakeup file: | ||
57 | * | ||
58 | * + "enabled\n" to issue the events; | ||
59 | * + "disabled\n" not to do so; or | ||
60 | * + "\n" for temporary or permanent inability to issue wakeup. | ||
61 | * | ||
62 | * (For example, unconfigured USB devices can't issue wakeups.) | ||
63 | * | ||
64 | * Familiar examples of devices that can issue wakeup events include | ||
65 | * keyboards and mice (both PS2 and USB styles), power buttons, modems, | ||
66 | * "Wake-On-LAN" Ethernet links, GPIO lines, and more. Some events | ||
67 | * will wake the entire system from a suspend state; others may just | ||
68 | * wake up the device (if the system as a whole is already active). | ||
69 | * Some wakeup events use normal IRQ lines; other use special out | ||
70 | * of band signaling. | ||
71 | * | ||
72 | * It is the responsibility of device drivers to enable (or disable) | ||
73 | * wakeup signaling as part of changing device power states, respecting | ||
74 | * the policy choices provided through the driver model. | ||
75 | * | ||
76 | * Devices may not be able to generate wakeup events from all power | ||
77 | * states. Also, the events may be ignored in some configurations; | ||
78 | * for example, they might need help from other devices that aren't | ||
79 | * active, or which may have wakeup disabled. Some drivers rely on | ||
80 | * wakeup events internally (unless they are disabled), keeping | ||
81 | * their hardware in low power modes whenever they're unused. This | ||
82 | * saves runtime power, without requiring system-wide sleep states. | ||
83 | */ | ||
84 | |||
85 | static const char enabled[] = "enabled"; | ||
86 | static const char disabled[] = "disabled"; | ||
87 | |||
88 | static ssize_t | ||
89 | wake_show(struct device * dev, struct device_attribute *attr, char * buf) | ||
90 | { | ||
91 | return sprintf(buf, "%s\n", device_can_wakeup(dev) | ||
92 | ? (device_may_wakeup(dev) ? enabled : disabled) | ||
93 | : ""); | ||
94 | } | ||
95 | |||
96 | static ssize_t | ||
97 | wake_store(struct device * dev, struct device_attribute *attr, | ||
98 | const char * buf, size_t n) | ||
99 | { | ||
100 | char *cp; | ||
101 | int len = n; | ||
102 | |||
103 | if (!device_can_wakeup(dev)) | ||
104 | return -EINVAL; | ||
105 | |||
106 | cp = memchr(buf, '\n', n); | ||
107 | if (cp) | ||
108 | len = cp - buf; | ||
109 | if (len == sizeof enabled - 1 | ||
110 | && strncmp(buf, enabled, sizeof enabled - 1) == 0) | ||
111 | device_set_wakeup_enable(dev, 1); | ||
112 | else if (len == sizeof disabled - 1 | ||
113 | && strncmp(buf, disabled, sizeof disabled - 1) == 0) | ||
114 | device_set_wakeup_enable(dev, 0); | ||
115 | else | ||
116 | return -EINVAL; | ||
117 | return n; | ||
118 | } | ||
119 | |||
120 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | ||
121 | |||
122 | |||
51 | static struct attribute * power_attrs[] = { | 123 | static struct attribute * power_attrs[] = { |
52 | &dev_attr_state.attr, | 124 | &dev_attr_state.attr, |
125 | &dev_attr_wakeup.attr, | ||
53 | NULL, | 126 | NULL, |
54 | }; | 127 | }; |
55 | static struct attribute_group pm_attr_group = { | 128 | static struct attribute_group pm_attr_group = { |