2 * drivers/base/power/sysfs.c - sysfs entries for device PM
5 #include <linux/device.h>
6 #include <linux/string.h>
7 #include <linux/pm_runtime.h>
11 * control - Report/change current runtime PM setting of the device
13 * Runtime power management of a device can be blocked with the help of
14 * this attribute. All devices have one of the following two values for
15 * the power/control file:
17 * + "auto\n" to allow the device to be power managed at run time;
18 * + "on\n" to prevent the device from being power managed at run time;
20 * The default for all devices is "auto", which means that devices may be
21 * subject to automatic power management, depending on their drivers.
22 * Changing this attribute to "on" prevents the driver from power managing
23 * the device at run time. Doing that while the device is suspended causes
26 * wakeup - Report/change current wakeup option for device
28 * Some devices support "wakeup" events, which are hardware signals
29 * used to activate devices from suspended or low power states. Such
30 * devices have one of three values for the sysfs power/wakeup file:
32 * + "enabled\n" to issue the events;
33 * + "disabled\n" not to do so; or
34 * + "\n" for temporary or permanent inability to issue wakeup.
36 * (For example, unconfigured USB devices can't issue wakeups.)
38 * Familiar examples of devices that can issue wakeup events include
39 * keyboards and mice (both PS2 and USB styles), power buttons, modems,
40 * "Wake-On-LAN" Ethernet links, GPIO lines, and more. Some events
41 * will wake the entire system from a suspend state; others may just
42 * wake up the device (if the system as a whole is already active).
43 * Some wakeup events use normal IRQ lines; other use special out
46 * It is the responsibility of device drivers to enable (or disable)
47 * wakeup signaling as part of changing device power states, respecting
48 * the policy choices provided through the driver model.
50 * Devices may not be able to generate wakeup events from all power
51 * states. Also, the events may be ignored in some configurations;
52 * for example, they might need help from other devices that aren't
53 * active, or which may have wakeup disabled. Some drivers rely on
54 * wakeup events internally (unless they are disabled), keeping
55 * their hardware in low power modes whenever they're unused. This
56 * saves runtime power, without requiring system-wide sleep states.
58 * async - Report/change current async suspend setting for the device
60 * Asynchronous suspend and resume of the device during system-wide power
61 * state transitions can be enabled by writing "enabled" to this file.
62 * Analogously, if "disabled" is written to this file, the device will be
63 * suspended and resumed synchronously.
65 * All devices have one of the following two values for power/async:
67 * + "enabled\n" to permit the asynchronous suspend/resume of the device;
68 * + "disabled\n" to forbid it;
70 * NOTE: It generally is unsafe to permit the asynchronous suspend/resume
71 * of a device unless it is certain that all of the PM dependencies of the
72 * device are known to the PM core. However, for some devices this
73 * attribute is set to "enabled" by bus type code or device drivers and in
74 * that cases it should be safe to leave the default value.
77 static const char enabled
[] = "enabled";
78 static const char disabled
[] = "disabled";
80 #ifdef CONFIG_PM_RUNTIME
81 static const char ctrl_auto
[] = "auto";
82 static const char ctrl_on
[] = "on";
84 static ssize_t
control_show(struct device
*dev
, struct device_attribute
*attr
,
87 return sprintf(buf
, "%s\n",
88 dev
->power
.runtime_auto
? ctrl_auto
: ctrl_on
);
91 static ssize_t
control_store(struct device
* dev
, struct device_attribute
*attr
,
92 const char * buf
, size_t n
)
97 cp
= memchr(buf
, '\n', n
);
100 if (len
== sizeof ctrl_auto
- 1 && strncmp(buf
, ctrl_auto
, len
) == 0)
101 pm_runtime_allow(dev
);
102 else if (len
== sizeof ctrl_on
- 1 && strncmp(buf
, ctrl_on
, len
) == 0)
103 pm_runtime_forbid(dev
);
109 static DEVICE_ATTR(control
, 0644, control_show
, control_store
);
113 wake_show(struct device
* dev
, struct device_attribute
*attr
, char * buf
)
115 return sprintf(buf
, "%s\n", device_can_wakeup(dev
)
116 ? (device_may_wakeup(dev
) ? enabled
: disabled
)
121 wake_store(struct device
* dev
, struct device_attribute
*attr
,
122 const char * buf
, size_t n
)
127 if (!device_can_wakeup(dev
))
130 cp
= memchr(buf
, '\n', n
);
133 if (len
== sizeof enabled
- 1
134 && strncmp(buf
, enabled
, sizeof enabled
- 1) == 0)
135 device_set_wakeup_enable(dev
, 1);
136 else if (len
== sizeof disabled
- 1
137 && strncmp(buf
, disabled
, sizeof disabled
- 1) == 0)
138 device_set_wakeup_enable(dev
, 0);
144 static DEVICE_ATTR(wakeup
, 0644, wake_show
, wake_store
);
146 #ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
147 static ssize_t
async_show(struct device
*dev
, struct device_attribute
*attr
,
150 return sprintf(buf
, "%s\n",
151 device_async_suspend_enabled(dev
) ? enabled
: disabled
);
154 static ssize_t
async_store(struct device
*dev
, struct device_attribute
*attr
,
155 const char *buf
, size_t n
)
160 cp
= memchr(buf
, '\n', n
);
163 if (len
== sizeof enabled
- 1 && strncmp(buf
, enabled
, len
) == 0)
164 device_enable_async_suspend(dev
);
165 else if (len
== sizeof disabled
- 1 && strncmp(buf
, disabled
, len
) == 0)
166 device_disable_async_suspend(dev
);
172 static DEVICE_ATTR(async
, 0644, async_show
, async_store
);
173 #endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
175 static struct attribute
* power_attrs
[] = {
176 #ifdef CONFIG_PM_RUNTIME
177 &dev_attr_control
.attr
,
179 &dev_attr_wakeup
.attr
,
180 #ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
181 &dev_attr_async
.attr
,
185 static struct attribute_group pm_attr_group
= {
187 .attrs
= power_attrs
,
190 int dpm_sysfs_add(struct device
* dev
)
192 return sysfs_create_group(&dev
->kobj
, &pm_attr_group
);
195 void dpm_sysfs_remove(struct device
* dev
)
197 sysfs_remove_group(&dev
->kobj
, &pm_attr_group
);