diff options
Diffstat (limited to 'drivers/base/power/sysfs.c')
-rw-r--r-- | drivers/base/power/sysfs.c | 98 |
1 files changed, 78 insertions, 20 deletions
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index a4c33bc51257..e56b4388fe61 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <linux/string.h> | 6 | #include <linux/string.h> |
7 | #include <linux/pm_runtime.h> | 7 | #include <linux/pm_runtime.h> |
8 | #include <asm/atomic.h> | 8 | #include <asm/atomic.h> |
9 | #include <linux/jiffies.h> | ||
9 | #include "power.h" | 10 | #include "power.h" |
10 | 11 | ||
11 | /* | 12 | /* |
@@ -73,6 +74,8 @@ | |||
73 | * device are known to the PM core. However, for some devices this | 74 | * device are known to the PM core. However, for some devices this |
74 | * attribute is set to "enabled" by bus type code or device drivers and in | 75 | * attribute is set to "enabled" by bus type code or device drivers and in |
75 | * that cases it should be safe to leave the default value. | 76 | * that cases it should be safe to leave the default value. |
77 | * | ||
78 | * wakeup_count - Report the number of wakeup events related to the device | ||
76 | */ | 79 | */ |
77 | 80 | ||
78 | static const char enabled[] = "enabled"; | 81 | static const char enabled[] = "enabled"; |
@@ -108,6 +111,65 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr, | |||
108 | } | 111 | } |
109 | 112 | ||
110 | static DEVICE_ATTR(control, 0644, control_show, control_store); | 113 | static DEVICE_ATTR(control, 0644, control_show, control_store); |
114 | |||
115 | static ssize_t rtpm_active_time_show(struct device *dev, | ||
116 | struct device_attribute *attr, char *buf) | ||
117 | { | ||
118 | int ret; | ||
119 | spin_lock_irq(&dev->power.lock); | ||
120 | update_pm_runtime_accounting(dev); | ||
121 | ret = sprintf(buf, "%i\n", jiffies_to_msecs(dev->power.active_jiffies)); | ||
122 | spin_unlock_irq(&dev->power.lock); | ||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | static DEVICE_ATTR(runtime_active_time, 0444, rtpm_active_time_show, NULL); | ||
127 | |||
128 | static ssize_t rtpm_suspended_time_show(struct device *dev, | ||
129 | struct device_attribute *attr, char *buf) | ||
130 | { | ||
131 | int ret; | ||
132 | spin_lock_irq(&dev->power.lock); | ||
133 | update_pm_runtime_accounting(dev); | ||
134 | ret = sprintf(buf, "%i\n", | ||
135 | jiffies_to_msecs(dev->power.suspended_jiffies)); | ||
136 | spin_unlock_irq(&dev->power.lock); | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | static DEVICE_ATTR(runtime_suspended_time, 0444, rtpm_suspended_time_show, NULL); | ||
141 | |||
142 | static ssize_t rtpm_status_show(struct device *dev, | ||
143 | struct device_attribute *attr, char *buf) | ||
144 | { | ||
145 | const char *p; | ||
146 | |||
147 | if (dev->power.runtime_error) { | ||
148 | p = "error\n"; | ||
149 | } else if (dev->power.disable_depth) { | ||
150 | p = "unsupported\n"; | ||
151 | } else { | ||
152 | switch (dev->power.runtime_status) { | ||
153 | case RPM_SUSPENDED: | ||
154 | p = "suspended\n"; | ||
155 | break; | ||
156 | case RPM_SUSPENDING: | ||
157 | p = "suspending\n"; | ||
158 | break; | ||
159 | case RPM_RESUMING: | ||
160 | p = "resuming\n"; | ||
161 | break; | ||
162 | case RPM_ACTIVE: | ||
163 | p = "active\n"; | ||
164 | break; | ||
165 | default: | ||
166 | return -EIO; | ||
167 | } | ||
168 | } | ||
169 | return sprintf(buf, p); | ||
170 | } | ||
171 | |||
172 | static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); | ||
111 | #endif | 173 | #endif |
112 | 174 | ||
113 | static ssize_t | 175 | static ssize_t |
@@ -144,6 +206,16 @@ wake_store(struct device * dev, struct device_attribute *attr, | |||
144 | 206 | ||
145 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | 207 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); |
146 | 208 | ||
209 | #ifdef CONFIG_PM_SLEEP | ||
210 | static ssize_t wakeup_count_show(struct device *dev, | ||
211 | struct device_attribute *attr, char *buf) | ||
212 | { | ||
213 | return sprintf(buf, "%lu\n", dev->power.wakeup_count); | ||
214 | } | ||
215 | |||
216 | static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL); | ||
217 | #endif | ||
218 | |||
147 | #ifdef CONFIG_PM_ADVANCED_DEBUG | 219 | #ifdef CONFIG_PM_ADVANCED_DEBUG |
148 | #ifdef CONFIG_PM_RUNTIME | 220 | #ifdef CONFIG_PM_RUNTIME |
149 | 221 | ||
@@ -172,27 +244,8 @@ static ssize_t rtpm_enabled_show(struct device *dev, | |||
172 | return sprintf(buf, "enabled\n"); | 244 | return sprintf(buf, "enabled\n"); |
173 | } | 245 | } |
174 | 246 | ||
175 | static ssize_t rtpm_status_show(struct device *dev, | ||
176 | struct device_attribute *attr, char *buf) | ||
177 | { | ||
178 | if (dev->power.runtime_error) | ||
179 | return sprintf(buf, "error\n"); | ||
180 | switch (dev->power.runtime_status) { | ||
181 | case RPM_SUSPENDED: | ||
182 | return sprintf(buf, "suspended\n"); | ||
183 | case RPM_SUSPENDING: | ||
184 | return sprintf(buf, "suspending\n"); | ||
185 | case RPM_RESUMING: | ||
186 | return sprintf(buf, "resuming\n"); | ||
187 | case RPM_ACTIVE: | ||
188 | return sprintf(buf, "active\n"); | ||
189 | } | ||
190 | return -EIO; | ||
191 | } | ||
192 | |||
193 | static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL); | 247 | static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL); |
194 | static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL); | 248 | static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL); |
195 | static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); | ||
196 | static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL); | 249 | static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL); |
197 | 250 | ||
198 | #endif | 251 | #endif |
@@ -228,14 +281,19 @@ static DEVICE_ATTR(async, 0644, async_show, async_store); | |||
228 | static struct attribute * power_attrs[] = { | 281 | static struct attribute * power_attrs[] = { |
229 | #ifdef CONFIG_PM_RUNTIME | 282 | #ifdef CONFIG_PM_RUNTIME |
230 | &dev_attr_control.attr, | 283 | &dev_attr_control.attr, |
284 | &dev_attr_runtime_status.attr, | ||
285 | &dev_attr_runtime_suspended_time.attr, | ||
286 | &dev_attr_runtime_active_time.attr, | ||
231 | #endif | 287 | #endif |
232 | &dev_attr_wakeup.attr, | 288 | &dev_attr_wakeup.attr, |
289 | #ifdef CONFIG_PM_SLEEP | ||
290 | &dev_attr_wakeup_count.attr, | ||
291 | #endif | ||
233 | #ifdef CONFIG_PM_ADVANCED_DEBUG | 292 | #ifdef CONFIG_PM_ADVANCED_DEBUG |
234 | &dev_attr_async.attr, | 293 | &dev_attr_async.attr, |
235 | #ifdef CONFIG_PM_RUNTIME | 294 | #ifdef CONFIG_PM_RUNTIME |
236 | &dev_attr_runtime_usage.attr, | 295 | &dev_attr_runtime_usage.attr, |
237 | &dev_attr_runtime_active_kids.attr, | 296 | &dev_attr_runtime_active_kids.attr, |
238 | &dev_attr_runtime_status.attr, | ||
239 | &dev_attr_runtime_enabled.attr, | 297 | &dev_attr_runtime_enabled.attr, |
240 | #endif | 298 | #endif |
241 | #endif | 299 | #endif |