Skip to content

Commit 0ac8524

Browse files
David Brownellgregkh
authored andcommitted
[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>
1 parent 2a7ff1f commit 0ac8524

3 files changed

Lines changed: 99 additions & 1 deletion

File tree

‎drivers/base/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void device_initialize(struct device *dev)
225225
klist_children_put);
226226
INIT_LIST_HEAD(&dev->dma_pools);
227227
init_MUTEX(&dev->sem);
228+
device_init_wakeup(dev, 0);
228229
}
229230

230231
/**

‎drivers/base/power/sysfs.c‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,81 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
4848
static DEVICE_ATTR(state, 0644, state_show, state_store);
4949

5050

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+
51123
static struct attribute * power_attrs[] = {
52124
&dev_attr_state.attr,
125+
&dev_attr_wakeup.attr,
53126
NULL,
54127
};
55128
static struct attribute_group pm_attr_group = {

‎include/linux/pm.h‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ typedef struct pm_message {
219219

220220
struct dev_pm_info {
221221
pm_message_t power_state;
222+
unsigned can_wakeup:1;
222223
#ifdef CONFIG_PM
224+
unsigned should_wakeup:1;
223225
pm_message_t prev_state;
224226
void * saved_state;
225227
atomic_t pm_users;
@@ -236,13 +238,35 @@ extern void device_resume(void);
236238

237239
#ifdef CONFIG_PM
238240
extern int device_suspend(pm_message_t state);
239-
#else
241+
242+
#define device_set_wakeup_enable(dev,val) \
243+
((dev)->power.should_wakeup = !!(val))
244+
#define device_may_wakeup(dev) \
245+
(device_can_wakeup(dev) && (dev)->power.should_wakeup)
246+
247+
#else /* !CONFIG_PM */
248+
240249
static inline int device_suspend(pm_message_t state)
241250
{
242251
return 0;
243252
}
253+
254+
#define device_set_wakeup_enable(dev,val) do{}while(0)
255+
#define device_may_wakeup(dev) (0)
256+
244257
#endif
245258

259+
/* changes to device_may_wakeup take effect on the next pm state change.
260+
* by default, devices should wakeup if they can.
261+
*/
262+
#define device_can_wakeup(dev) \
263+
((dev)->power.can_wakeup)
264+
#define device_init_wakeup(dev,val) \
265+
do { \
266+
device_can_wakeup(dev) = !!(val); \
267+
device_set_wakeup_enable(dev,val); \
268+
} while(0)
269+
246270
#endif /* __KERNEL__ */
247271

248272
#endif /* _LINUX_PM_H */

0 commit comments

Comments
 (0)