diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-12-15 20:05:48 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-12-15 20:05:48 -0500 |
commit | c51a024e3913e9dbaf4dfcb9aaba825668a89ace (patch) | |
tree | 9772af495ced0bde0d3c58b6e6fb5b395b3afae9 /drivers/base/power/sysfs.c | |
parent | 3487972d7fa6c5143951436ada5933dcf0ec659d (diff) | |
parent | 34fb8f0ba9ceea88e116688f9f53e3802c38aafb (diff) |
Merge back PM core material for v4.16.
Diffstat (limited to 'drivers/base/power/sysfs.c')
-rw-r--r-- | drivers/base/power/sysfs.c | 182 |
1 files changed, 79 insertions, 103 deletions
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index e153e28b1857..0f651efc58a1 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -108,16 +108,10 @@ static ssize_t control_show(struct device *dev, struct device_attribute *attr, | |||
108 | static ssize_t control_store(struct device * dev, struct device_attribute *attr, | 108 | static ssize_t control_store(struct device * dev, struct device_attribute *attr, |
109 | const char * buf, size_t n) | 109 | const char * buf, size_t n) |
110 | { | 110 | { |
111 | char *cp; | ||
112 | int len = n; | ||
113 | |||
114 | cp = memchr(buf, '\n', n); | ||
115 | if (cp) | ||
116 | len = cp - buf; | ||
117 | device_lock(dev); | 111 | device_lock(dev); |
118 | if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) | 112 | if (sysfs_streq(buf, ctrl_auto)) |
119 | pm_runtime_allow(dev); | 113 | pm_runtime_allow(dev); |
120 | else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) | 114 | else if (sysfs_streq(buf, ctrl_on)) |
121 | pm_runtime_forbid(dev); | 115 | pm_runtime_forbid(dev); |
122 | else | 116 | else |
123 | n = -EINVAL; | 117 | n = -EINVAL; |
@@ -125,9 +119,9 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr, | |||
125 | return n; | 119 | return n; |
126 | } | 120 | } |
127 | 121 | ||
128 | static DEVICE_ATTR(control, 0644, control_show, control_store); | 122 | static DEVICE_ATTR_RW(control); |
129 | 123 | ||
130 | static ssize_t rtpm_active_time_show(struct device *dev, | 124 | static ssize_t runtime_active_time_show(struct device *dev, |
131 | struct device_attribute *attr, char *buf) | 125 | struct device_attribute *attr, char *buf) |
132 | { | 126 | { |
133 | int ret; | 127 | int ret; |
@@ -138,9 +132,9 @@ static ssize_t rtpm_active_time_show(struct device *dev, | |||
138 | return ret; | 132 | return ret; |
139 | } | 133 | } |
140 | 134 | ||
141 | static DEVICE_ATTR(runtime_active_time, 0444, rtpm_active_time_show, NULL); | 135 | static DEVICE_ATTR_RO(runtime_active_time); |
142 | 136 | ||
143 | static ssize_t rtpm_suspended_time_show(struct device *dev, | 137 | static ssize_t runtime_suspended_time_show(struct device *dev, |
144 | struct device_attribute *attr, char *buf) | 138 | struct device_attribute *attr, char *buf) |
145 | { | 139 | { |
146 | int ret; | 140 | int ret; |
@@ -152,9 +146,9 @@ static ssize_t rtpm_suspended_time_show(struct device *dev, | |||
152 | return ret; | 146 | return ret; |
153 | } | 147 | } |
154 | 148 | ||
155 | static DEVICE_ATTR(runtime_suspended_time, 0444, rtpm_suspended_time_show, NULL); | 149 | static DEVICE_ATTR_RO(runtime_suspended_time); |
156 | 150 | ||
157 | static ssize_t rtpm_status_show(struct device *dev, | 151 | static ssize_t runtime_status_show(struct device *dev, |
158 | struct device_attribute *attr, char *buf) | 152 | struct device_attribute *attr, char *buf) |
159 | { | 153 | { |
160 | const char *p; | 154 | const char *p; |
@@ -184,7 +178,7 @@ static ssize_t rtpm_status_show(struct device *dev, | |||
184 | return sprintf(buf, p); | 178 | return sprintf(buf, p); |
185 | } | 179 | } |
186 | 180 | ||
187 | static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); | 181 | static DEVICE_ATTR_RO(runtime_status); |
188 | 182 | ||
189 | static ssize_t autosuspend_delay_ms_show(struct device *dev, | 183 | static ssize_t autosuspend_delay_ms_show(struct device *dev, |
190 | struct device_attribute *attr, char *buf) | 184 | struct device_attribute *attr, char *buf) |
@@ -211,26 +205,25 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, | |||
211 | return n; | 205 | return n; |
212 | } | 206 | } |
213 | 207 | ||
214 | static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show, | 208 | static DEVICE_ATTR_RW(autosuspend_delay_ms); |
215 | autosuspend_delay_ms_store); | ||
216 | 209 | ||
217 | static ssize_t pm_qos_resume_latency_show(struct device *dev, | 210 | static ssize_t pm_qos_resume_latency_us_show(struct device *dev, |
218 | struct device_attribute *attr, | 211 | struct device_attribute *attr, |
219 | char *buf) | 212 | char *buf) |
220 | { | 213 | { |
221 | s32 value = dev_pm_qos_requested_resume_latency(dev); | 214 | s32 value = dev_pm_qos_requested_resume_latency(dev); |
222 | 215 | ||
223 | if (value == 0) | 216 | if (value == 0) |
224 | return sprintf(buf, "n/a\n"); | 217 | return sprintf(buf, "n/a\n"); |
225 | else if (value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT) | 218 | if (value == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT) |
226 | value = 0; | 219 | value = 0; |
227 | 220 | ||
228 | return sprintf(buf, "%d\n", value); | 221 | return sprintf(buf, "%d\n", value); |
229 | } | 222 | } |
230 | 223 | ||
231 | static ssize_t pm_qos_resume_latency_store(struct device *dev, | 224 | static ssize_t pm_qos_resume_latency_us_store(struct device *dev, |
232 | struct device_attribute *attr, | 225 | struct device_attribute *attr, |
233 | const char *buf, size_t n) | 226 | const char *buf, size_t n) |
234 | { | 227 | { |
235 | s32 value; | 228 | s32 value; |
236 | int ret; | 229 | int ret; |
@@ -245,7 +238,7 @@ static ssize_t pm_qos_resume_latency_store(struct device *dev, | |||
245 | 238 | ||
246 | if (value == 0) | 239 | if (value == 0) |
247 | value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; | 240 | value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; |
248 | } else if (!strcmp(buf, "n/a") || !strcmp(buf, "n/a\n")) { | 241 | } else if (sysfs_streq(buf, "n/a")) { |
249 | value = 0; | 242 | value = 0; |
250 | } else { | 243 | } else { |
251 | return -EINVAL; | 244 | return -EINVAL; |
@@ -256,26 +249,25 @@ static ssize_t pm_qos_resume_latency_store(struct device *dev, | |||
256 | return ret < 0 ? ret : n; | 249 | return ret < 0 ? ret : n; |
257 | } | 250 | } |
258 | 251 | ||
259 | static DEVICE_ATTR(pm_qos_resume_latency_us, 0644, | 252 | static DEVICE_ATTR_RW(pm_qos_resume_latency_us); |
260 | pm_qos_resume_latency_show, pm_qos_resume_latency_store); | ||
261 | 253 | ||
262 | static ssize_t pm_qos_latency_tolerance_show(struct device *dev, | 254 | static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev, |
263 | struct device_attribute *attr, | 255 | struct device_attribute *attr, |
264 | char *buf) | 256 | char *buf) |
265 | { | 257 | { |
266 | s32 value = dev_pm_qos_get_user_latency_tolerance(dev); | 258 | s32 value = dev_pm_qos_get_user_latency_tolerance(dev); |
267 | 259 | ||
268 | if (value < 0) | 260 | if (value < 0) |
269 | return sprintf(buf, "auto\n"); | 261 | return sprintf(buf, "auto\n"); |
270 | else if (value == PM_QOS_LATENCY_ANY) | 262 | if (value == PM_QOS_LATENCY_ANY) |
271 | return sprintf(buf, "any\n"); | 263 | return sprintf(buf, "any\n"); |
272 | 264 | ||
273 | return sprintf(buf, "%d\n", value); | 265 | return sprintf(buf, "%d\n", value); |
274 | } | 266 | } |
275 | 267 | ||
276 | static ssize_t pm_qos_latency_tolerance_store(struct device *dev, | 268 | static ssize_t pm_qos_latency_tolerance_us_store(struct device *dev, |
277 | struct device_attribute *attr, | 269 | struct device_attribute *attr, |
278 | const char *buf, size_t n) | 270 | const char *buf, size_t n) |
279 | { | 271 | { |
280 | s32 value; | 272 | s32 value; |
281 | int ret; | 273 | int ret; |
@@ -285,9 +277,9 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev, | |||
285 | if (value < 0) | 277 | if (value < 0) |
286 | return -EINVAL; | 278 | return -EINVAL; |
287 | } else { | 279 | } else { |
288 | if (!strcmp(buf, "auto") || !strcmp(buf, "auto\n")) | 280 | if (sysfs_streq(buf, "auto")) |
289 | value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT; | 281 | value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT; |
290 | else if (!strcmp(buf, "any") || !strcmp(buf, "any\n")) | 282 | else if (sysfs_streq(buf, "any")) |
291 | value = PM_QOS_LATENCY_ANY; | 283 | value = PM_QOS_LATENCY_ANY; |
292 | else | 284 | else |
293 | return -EINVAL; | 285 | return -EINVAL; |
@@ -296,8 +288,7 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev, | |||
296 | return ret < 0 ? ret : n; | 288 | return ret < 0 ? ret : n; |
297 | } | 289 | } |
298 | 290 | ||
299 | static DEVICE_ATTR(pm_qos_latency_tolerance_us, 0644, | 291 | static DEVICE_ATTR_RW(pm_qos_latency_tolerance_us); |
300 | pm_qos_latency_tolerance_show, pm_qos_latency_tolerance_store); | ||
301 | 292 | ||
302 | static ssize_t pm_qos_no_power_off_show(struct device *dev, | 293 | static ssize_t pm_qos_no_power_off_show(struct device *dev, |
303 | struct device_attribute *attr, | 294 | struct device_attribute *attr, |
@@ -323,49 +314,39 @@ static ssize_t pm_qos_no_power_off_store(struct device *dev, | |||
323 | return ret < 0 ? ret : n; | 314 | return ret < 0 ? ret : n; |
324 | } | 315 | } |
325 | 316 | ||
326 | static DEVICE_ATTR(pm_qos_no_power_off, 0644, | 317 | static DEVICE_ATTR_RW(pm_qos_no_power_off); |
327 | pm_qos_no_power_off_show, pm_qos_no_power_off_store); | ||
328 | 318 | ||
329 | #ifdef CONFIG_PM_SLEEP | 319 | #ifdef CONFIG_PM_SLEEP |
330 | static const char _enabled[] = "enabled"; | 320 | static const char _enabled[] = "enabled"; |
331 | static const char _disabled[] = "disabled"; | 321 | static const char _disabled[] = "disabled"; |
332 | 322 | ||
333 | static ssize_t | 323 | static ssize_t wakeup_show(struct device *dev, struct device_attribute *attr, |
334 | wake_show(struct device * dev, struct device_attribute *attr, char * buf) | 324 | char *buf) |
335 | { | 325 | { |
336 | return sprintf(buf, "%s\n", device_can_wakeup(dev) | 326 | return sprintf(buf, "%s\n", device_can_wakeup(dev) |
337 | ? (device_may_wakeup(dev) ? _enabled : _disabled) | 327 | ? (device_may_wakeup(dev) ? _enabled : _disabled) |
338 | : ""); | 328 | : ""); |
339 | } | 329 | } |
340 | 330 | ||
341 | static ssize_t | 331 | static ssize_t wakeup_store(struct device *dev, struct device_attribute *attr, |
342 | wake_store(struct device * dev, struct device_attribute *attr, | 332 | const char *buf, size_t n) |
343 | const char * buf, size_t n) | ||
344 | { | 333 | { |
345 | char *cp; | ||
346 | int len = n; | ||
347 | |||
348 | if (!device_can_wakeup(dev)) | 334 | if (!device_can_wakeup(dev)) |
349 | return -EINVAL; | 335 | return -EINVAL; |
350 | 336 | ||
351 | cp = memchr(buf, '\n', n); | 337 | if (sysfs_streq(buf, _enabled)) |
352 | if (cp) | ||
353 | len = cp - buf; | ||
354 | if (len == sizeof _enabled - 1 | ||
355 | && strncmp(buf, _enabled, sizeof _enabled - 1) == 0) | ||
356 | device_set_wakeup_enable(dev, 1); | 338 | device_set_wakeup_enable(dev, 1); |
357 | else if (len == sizeof _disabled - 1 | 339 | else if (sysfs_streq(buf, _disabled)) |
358 | && strncmp(buf, _disabled, sizeof _disabled - 1) == 0) | ||
359 | device_set_wakeup_enable(dev, 0); | 340 | device_set_wakeup_enable(dev, 0); |
360 | else | 341 | else |
361 | return -EINVAL; | 342 | return -EINVAL; |
362 | return n; | 343 | return n; |
363 | } | 344 | } |
364 | 345 | ||
365 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | 346 | static DEVICE_ATTR_RW(wakeup); |
366 | 347 | ||
367 | static ssize_t wakeup_count_show(struct device *dev, | 348 | static ssize_t wakeup_count_show(struct device *dev, |
368 | struct device_attribute *attr, char *buf) | 349 | struct device_attribute *attr, char *buf) |
369 | { | 350 | { |
370 | unsigned long count = 0; | 351 | unsigned long count = 0; |
371 | bool enabled = false; | 352 | bool enabled = false; |
@@ -379,10 +360,11 @@ static ssize_t wakeup_count_show(struct device *dev, | |||
379 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); | 360 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); |
380 | } | 361 | } |
381 | 362 | ||
382 | static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL); | 363 | static DEVICE_ATTR_RO(wakeup_count); |
383 | 364 | ||
384 | static ssize_t wakeup_active_count_show(struct device *dev, | 365 | static ssize_t wakeup_active_count_show(struct device *dev, |
385 | struct device_attribute *attr, char *buf) | 366 | struct device_attribute *attr, |
367 | char *buf) | ||
386 | { | 368 | { |
387 | unsigned long count = 0; | 369 | unsigned long count = 0; |
388 | bool enabled = false; | 370 | bool enabled = false; |
@@ -396,11 +378,11 @@ static ssize_t wakeup_active_count_show(struct device *dev, | |||
396 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); | 378 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); |
397 | } | 379 | } |
398 | 380 | ||
399 | static DEVICE_ATTR(wakeup_active_count, 0444, wakeup_active_count_show, NULL); | 381 | static DEVICE_ATTR_RO(wakeup_active_count); |
400 | 382 | ||
401 | static ssize_t wakeup_abort_count_show(struct device *dev, | 383 | static ssize_t wakeup_abort_count_show(struct device *dev, |
402 | struct device_attribute *attr, | 384 | struct device_attribute *attr, |
403 | char *buf) | 385 | char *buf) |
404 | { | 386 | { |
405 | unsigned long count = 0; | 387 | unsigned long count = 0; |
406 | bool enabled = false; | 388 | bool enabled = false; |
@@ -414,7 +396,7 @@ static ssize_t wakeup_abort_count_show(struct device *dev, | |||
414 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); | 396 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); |
415 | } | 397 | } |
416 | 398 | ||
417 | static DEVICE_ATTR(wakeup_abort_count, 0444, wakeup_abort_count_show, NULL); | 399 | static DEVICE_ATTR_RO(wakeup_abort_count); |
418 | 400 | ||
419 | static ssize_t wakeup_expire_count_show(struct device *dev, | 401 | static ssize_t wakeup_expire_count_show(struct device *dev, |
420 | struct device_attribute *attr, | 402 | struct device_attribute *attr, |
@@ -432,10 +414,10 @@ static ssize_t wakeup_expire_count_show(struct device *dev, | |||
432 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); | 414 | return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n"); |
433 | } | 415 | } |
434 | 416 | ||
435 | static DEVICE_ATTR(wakeup_expire_count, 0444, wakeup_expire_count_show, NULL); | 417 | static DEVICE_ATTR_RO(wakeup_expire_count); |
436 | 418 | ||
437 | static ssize_t wakeup_active_show(struct device *dev, | 419 | static ssize_t wakeup_active_show(struct device *dev, |
438 | struct device_attribute *attr, char *buf) | 420 | struct device_attribute *attr, char *buf) |
439 | { | 421 | { |
440 | unsigned int active = 0; | 422 | unsigned int active = 0; |
441 | bool enabled = false; | 423 | bool enabled = false; |
@@ -449,10 +431,11 @@ static ssize_t wakeup_active_show(struct device *dev, | |||
449 | return enabled ? sprintf(buf, "%u\n", active) : sprintf(buf, "\n"); | 431 | return enabled ? sprintf(buf, "%u\n", active) : sprintf(buf, "\n"); |
450 | } | 432 | } |
451 | 433 | ||
452 | static DEVICE_ATTR(wakeup_active, 0444, wakeup_active_show, NULL); | 434 | static DEVICE_ATTR_RO(wakeup_active); |
453 | 435 | ||
454 | static ssize_t wakeup_total_time_show(struct device *dev, | 436 | static ssize_t wakeup_total_time_ms_show(struct device *dev, |
455 | struct device_attribute *attr, char *buf) | 437 | struct device_attribute *attr, |
438 | char *buf) | ||
456 | { | 439 | { |
457 | s64 msec = 0; | 440 | s64 msec = 0; |
458 | bool enabled = false; | 441 | bool enabled = false; |
@@ -466,10 +449,10 @@ static ssize_t wakeup_total_time_show(struct device *dev, | |||
466 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); | 449 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); |
467 | } | 450 | } |
468 | 451 | ||
469 | static DEVICE_ATTR(wakeup_total_time_ms, 0444, wakeup_total_time_show, NULL); | 452 | static DEVICE_ATTR_RO(wakeup_total_time_ms); |
470 | 453 | ||
471 | static ssize_t wakeup_max_time_show(struct device *dev, | 454 | static ssize_t wakeup_max_time_ms_show(struct device *dev, |
472 | struct device_attribute *attr, char *buf) | 455 | struct device_attribute *attr, char *buf) |
473 | { | 456 | { |
474 | s64 msec = 0; | 457 | s64 msec = 0; |
475 | bool enabled = false; | 458 | bool enabled = false; |
@@ -483,10 +466,11 @@ static ssize_t wakeup_max_time_show(struct device *dev, | |||
483 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); | 466 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); |
484 | } | 467 | } |
485 | 468 | ||
486 | static DEVICE_ATTR(wakeup_max_time_ms, 0444, wakeup_max_time_show, NULL); | 469 | static DEVICE_ATTR_RO(wakeup_max_time_ms); |
487 | 470 | ||
488 | static ssize_t wakeup_last_time_show(struct device *dev, | 471 | static ssize_t wakeup_last_time_ms_show(struct device *dev, |
489 | struct device_attribute *attr, char *buf) | 472 | struct device_attribute *attr, |
473 | char *buf) | ||
490 | { | 474 | { |
491 | s64 msec = 0; | 475 | s64 msec = 0; |
492 | bool enabled = false; | 476 | bool enabled = false; |
@@ -500,12 +484,12 @@ static ssize_t wakeup_last_time_show(struct device *dev, | |||
500 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); | 484 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); |
501 | } | 485 | } |
502 | 486 | ||
503 | static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show, NULL); | 487 | static DEVICE_ATTR_RO(wakeup_last_time_ms); |
504 | 488 | ||
505 | #ifdef CONFIG_PM_AUTOSLEEP | 489 | #ifdef CONFIG_PM_AUTOSLEEP |
506 | static ssize_t wakeup_prevent_sleep_time_show(struct device *dev, | 490 | static ssize_t wakeup_prevent_sleep_time_ms_show(struct device *dev, |
507 | struct device_attribute *attr, | 491 | struct device_attribute *attr, |
508 | char *buf) | 492 | char *buf) |
509 | { | 493 | { |
510 | s64 msec = 0; | 494 | s64 msec = 0; |
511 | bool enabled = false; | 495 | bool enabled = false; |
@@ -519,40 +503,39 @@ static ssize_t wakeup_prevent_sleep_time_show(struct device *dev, | |||
519 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); | 503 | return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n"); |
520 | } | 504 | } |
521 | 505 | ||
522 | static DEVICE_ATTR(wakeup_prevent_sleep_time_ms, 0444, | 506 | static DEVICE_ATTR_RO(wakeup_prevent_sleep_time_ms); |
523 | wakeup_prevent_sleep_time_show, NULL); | ||
524 | #endif /* CONFIG_PM_AUTOSLEEP */ | 507 | #endif /* CONFIG_PM_AUTOSLEEP */ |
525 | #endif /* CONFIG_PM_SLEEP */ | 508 | #endif /* CONFIG_PM_SLEEP */ |
526 | 509 | ||
527 | #ifdef CONFIG_PM_ADVANCED_DEBUG | 510 | #ifdef CONFIG_PM_ADVANCED_DEBUG |
528 | static ssize_t rtpm_usagecount_show(struct device *dev, | 511 | static ssize_t runtime_usage_show(struct device *dev, |
529 | struct device_attribute *attr, char *buf) | 512 | struct device_attribute *attr, char *buf) |
530 | { | 513 | { |
531 | return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count)); | 514 | return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count)); |
532 | } | 515 | } |
516 | static DEVICE_ATTR_RO(runtime_usage); | ||
533 | 517 | ||
534 | static ssize_t rtpm_children_show(struct device *dev, | 518 | static ssize_t runtime_active_kids_show(struct device *dev, |
535 | struct device_attribute *attr, char *buf) | 519 | struct device_attribute *attr, |
520 | char *buf) | ||
536 | { | 521 | { |
537 | return sprintf(buf, "%d\n", dev->power.ignore_children ? | 522 | return sprintf(buf, "%d\n", dev->power.ignore_children ? |
538 | 0 : atomic_read(&dev->power.child_count)); | 523 | 0 : atomic_read(&dev->power.child_count)); |
539 | } | 524 | } |
525 | static DEVICE_ATTR_RO(runtime_active_kids); | ||
540 | 526 | ||
541 | static ssize_t rtpm_enabled_show(struct device *dev, | 527 | static ssize_t runtime_enabled_show(struct device *dev, |
542 | struct device_attribute *attr, char *buf) | 528 | struct device_attribute *attr, char *buf) |
543 | { | 529 | { |
544 | if ((dev->power.disable_depth) && (dev->power.runtime_auto == false)) | 530 | if (dev->power.disable_depth && (dev->power.runtime_auto == false)) |
545 | return sprintf(buf, "disabled & forbidden\n"); | 531 | return sprintf(buf, "disabled & forbidden\n"); |
546 | else if (dev->power.disable_depth) | 532 | if (dev->power.disable_depth) |
547 | return sprintf(buf, "disabled\n"); | 533 | return sprintf(buf, "disabled\n"); |
548 | else if (dev->power.runtime_auto == false) | 534 | if (dev->power.runtime_auto == false) |
549 | return sprintf(buf, "forbidden\n"); | 535 | return sprintf(buf, "forbidden\n"); |
550 | return sprintf(buf, "enabled\n"); | 536 | return sprintf(buf, "enabled\n"); |
551 | } | 537 | } |
552 | 538 | static DEVICE_ATTR_RO(runtime_enabled); | |
553 | static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL); | ||
554 | static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL); | ||
555 | static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL); | ||
556 | 539 | ||
557 | #ifdef CONFIG_PM_SLEEP | 540 | #ifdef CONFIG_PM_SLEEP |
558 | static ssize_t async_show(struct device *dev, struct device_attribute *attr, | 541 | static ssize_t async_show(struct device *dev, struct device_attribute *attr, |
@@ -566,23 +549,16 @@ static ssize_t async_show(struct device *dev, struct device_attribute *attr, | |||
566 | static ssize_t async_store(struct device *dev, struct device_attribute *attr, | 549 | static ssize_t async_store(struct device *dev, struct device_attribute *attr, |
567 | const char *buf, size_t n) | 550 | const char *buf, size_t n) |
568 | { | 551 | { |
569 | char *cp; | 552 | if (sysfs_streq(buf, _enabled)) |
570 | int len = n; | ||
571 | |||
572 | cp = memchr(buf, '\n', n); | ||
573 | if (cp) | ||
574 | len = cp - buf; | ||
575 | if (len == sizeof _enabled - 1 && strncmp(buf, _enabled, len) == 0) | ||
576 | device_enable_async_suspend(dev); | 553 | device_enable_async_suspend(dev); |
577 | else if (len == sizeof _disabled - 1 && | 554 | else if (sysfs_streq(buf, _disabled)) |
578 | strncmp(buf, _disabled, len) == 0) | ||
579 | device_disable_async_suspend(dev); | 555 | device_disable_async_suspend(dev); |
580 | else | 556 | else |
581 | return -EINVAL; | 557 | return -EINVAL; |
582 | return n; | 558 | return n; |
583 | } | 559 | } |
584 | 560 | ||
585 | static DEVICE_ATTR(async, 0644, async_show, async_store); | 561 | static DEVICE_ATTR_RW(async); |
586 | 562 | ||
587 | #endif /* CONFIG_PM_SLEEP */ | 563 | #endif /* CONFIG_PM_SLEEP */ |
588 | #endif /* CONFIG_PM_ADVANCED_DEBUG */ | 564 | #endif /* CONFIG_PM_ADVANCED_DEBUG */ |