5 #include <linux/device.h>
6 #include <linux/string.h>
7 #include <linux/export.h>
95 static const char enabled[] =
"enabled";
96 static const char disabled[] =
"disabled";
101 #ifdef CONFIG_PM_RUNTIME
102 static const char ctrl_auto[] =
"auto";
103 static const char ctrl_on[] =
"on";
109 dev->
power.runtime_auto ? ctrl_auto : ctrl_on);
113 const char *
buf,
size_t n)
118 cp =
memchr(buf,
'\n', n);
122 if (len ==
sizeof ctrl_auto - 1 &&
strncmp(buf, ctrl_auto, len) == 0)
124 else if (len ==
sizeof ctrl_on - 1 &&
strncmp(buf, ctrl_on, len) == 0)
138 spin_lock_irq(&dev->
power.lock);
141 spin_unlock_irq(&dev->
power.lock);
145 static DEVICE_ATTR(runtime_active_time, 0444, rtpm_active_time_show,
NULL);
151 spin_lock_irq(&dev->
power.lock);
155 spin_unlock_irq(&dev->
power.lock);
159 static DEVICE_ATTR(runtime_suspended_time, 0444, rtpm_suspended_time_show,
NULL);
166 if (dev->
power.runtime_error) {
168 }
else if (dev->
power.disable_depth) {
171 switch (dev->
power.runtime_status) {
196 if (!dev->
power.use_autosuspend)
198 return sprintf(buf,
"%d\n", dev->
power.autosuspend_delay);
201 static ssize_t autosuspend_delay_ms_store(
struct device *dev,
206 if (!dev->
power.use_autosuspend)
209 if (
strict_strtol(buf, 10, &delay) != 0 || delay != (
int) delay)
218 static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show,
219 autosuspend_delay_ms_store);
224 return sprintf(buf,
"%d\n", dev->
power.pq_req->node.prio);
229 const char *buf,
size_t n)
234 if (kstrtos32(buf, 0, &value))
241 return ret < 0 ? ret :
n;
245 pm_qos_latency_show, pm_qos_latency_store);
248 #ifdef CONFIG_PM_SLEEP
252 return sprintf(buf,
"%s\n", device_can_wakeup(dev)
253 ? (device_may_wakeup(dev) ?
enabled : disabled)
259 const char * buf,
size_t n)
264 if (!device_can_wakeup(dev))
267 cp =
memchr(buf,
'\n', n);
273 else if (len ==
sizeof disabled - 1
274 &&
strncmp(buf, disabled,
sizeof disabled - 1) == 0)
281 static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
286 unsigned long count = 0;
289 spin_lock_irq(&dev->
power.lock);
290 if (dev->
power.wakeup) {
291 count = dev->
power.wakeup->event_count;
294 spin_unlock_irq(&dev->
power.lock);
295 return enabled ?
sprintf(buf,
"%lu\n", count) : sprintf(buf,
"\n");
303 unsigned long count = 0;
304 bool enabled =
false;
306 spin_lock_irq(&dev->
power.lock);
307 if (dev->
power.wakeup) {
308 count = dev->
power.wakeup->active_count;
311 spin_unlock_irq(&dev->
power.lock);
312 return enabled ?
sprintf(buf,
"%lu\n", count) : sprintf(buf,
"\n");
315 static DEVICE_ATTR(wakeup_active_count, 0444, wakeup_active_count_show,
NULL);
321 unsigned long count = 0;
322 bool enabled =
false;
324 spin_lock_irq(&dev->
power.lock);
325 if (dev->
power.wakeup) {
326 count = dev->
power.wakeup->wakeup_count;
329 spin_unlock_irq(&dev->
power.lock);
330 return enabled ?
sprintf(buf,
"%lu\n", count) : sprintf(buf,
"\n");
333 static DEVICE_ATTR(wakeup_abort_count, 0444, wakeup_abort_count_show,
NULL);
339 unsigned long count = 0;
340 bool enabled =
false;
342 spin_lock_irq(&dev->
power.lock);
343 if (dev->
power.wakeup) {
344 count = dev->
power.wakeup->expire_count;
347 spin_unlock_irq(&dev->
power.lock);
348 return enabled ?
sprintf(buf,
"%lu\n", count) : sprintf(buf,
"\n");
351 static DEVICE_ATTR(wakeup_expire_count, 0444, wakeup_expire_count_show,
NULL);
357 bool enabled =
false;
359 spin_lock_irq(&dev->
power.lock);
360 if (dev->
power.wakeup) {
361 active = dev->
power.wakeup->active;
364 spin_unlock_irq(&dev->
power.lock);
365 return enabled ?
sprintf(buf,
"%u\n", active) : sprintf(buf,
"\n");
374 bool enabled =
false;
376 spin_lock_irq(&dev->
power.lock);
377 if (dev->
power.wakeup) {
378 msec = ktime_to_ms(dev->
power.wakeup->total_time);
381 spin_unlock_irq(&dev->
power.lock);
382 return enabled ?
sprintf(buf,
"%lld\n", msec) : sprintf(buf,
"\n");
385 static DEVICE_ATTR(wakeup_total_time_ms, 0444, wakeup_total_time_show,
NULL);
391 bool enabled =
false;
393 spin_lock_irq(&dev->
power.lock);
394 if (dev->
power.wakeup) {
395 msec = ktime_to_ms(dev->
power.wakeup->max_time);
398 spin_unlock_irq(&dev->
power.lock);
399 return enabled ?
sprintf(buf,
"%lld\n", msec) : sprintf(buf,
"\n");
402 static DEVICE_ATTR(wakeup_max_time_ms, 0444, wakeup_max_time_show,
NULL);
408 bool enabled =
false;
410 spin_lock_irq(&dev->
power.lock);
411 if (dev->
power.wakeup) {
412 msec = ktime_to_ms(dev->
power.wakeup->last_time);
415 spin_unlock_irq(&dev->
power.lock);
416 return enabled ?
sprintf(buf,
"%lld\n", msec) : sprintf(buf,
"\n");
419 static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show,
NULL);
421 #ifdef CONFIG_PM_AUTOSLEEP
422 static ssize_t wakeup_prevent_sleep_time_show(
struct device *dev,
427 bool enabled =
false;
429 spin_lock_irq(&dev->
power.lock);
430 if (dev->
power.wakeup) {
431 msec = ktime_to_ms(dev->
power.wakeup->prevent_sleep_time);
434 spin_unlock_irq(&dev->
power.lock);
435 return enabled ?
sprintf(buf,
"%lld\n", msec) : sprintf(buf,
"\n");
438 static DEVICE_ATTR(wakeup_prevent_sleep_time_ms, 0444,
439 wakeup_prevent_sleep_time_show,
NULL);
443 #ifdef CONFIG_PM_ADVANCED_DEBUG
444 #ifdef CONFIG_PM_RUNTIME
455 return sprintf(buf,
"%d\n", dev->
power.ignore_children ?
462 if ((dev->
power.disable_depth) && (dev->
power.runtime_auto ==
false))
463 return sprintf(buf,
"disabled & forbidden\n");
464 else if (dev->
power.disable_depth)
465 return sprintf(buf,
"disabled\n");
466 else if (dev->
power.runtime_auto ==
false)
467 return sprintf(buf,
"forbidden\n");
468 return sprintf(buf,
"enabled\n");
472 static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show,
NULL);
477 #ifdef CONFIG_PM_SLEEP
483 device_async_suspend_enabled(dev) ? enabled : disabled);
487 const char *buf,
size_t n)
492 cp =
memchr(buf,
'\n', n);
495 if (len ==
sizeof enabled - 1 &&
strncmp(buf, enabled, len) == 0)
496 device_enable_async_suspend(dev);
497 else if (len ==
sizeof disabled - 1 &&
strncmp(buf, disabled, len) == 0)
498 device_disable_async_suspend(dev);
509 static struct attribute *power_attrs[] = {
510 #ifdef CONFIG_PM_ADVANCED_DEBUG
511 #ifdef CONFIG_PM_SLEEP
512 &dev_attr_async.attr,
514 #ifdef CONFIG_PM_RUNTIME
515 &dev_attr_runtime_status.attr,
516 &dev_attr_runtime_usage.attr,
517 &dev_attr_runtime_active_kids.attr,
518 &dev_attr_runtime_enabled.attr,
525 .attrs = power_attrs,
528 static struct attribute *wakeup_attrs[] = {
529 #ifdef CONFIG_PM_SLEEP
530 &dev_attr_wakeup.attr,
531 &dev_attr_wakeup_count.attr,
532 &dev_attr_wakeup_active_count.attr,
533 &dev_attr_wakeup_abort_count.attr,
534 &dev_attr_wakeup_expire_count.attr,
535 &dev_attr_wakeup_active.attr,
536 &dev_attr_wakeup_total_time_ms.attr,
537 &dev_attr_wakeup_max_time_ms.attr,
538 &dev_attr_wakeup_last_time_ms.attr,
539 #ifdef CONFIG_PM_AUTOSLEEP
540 &dev_attr_wakeup_prevent_sleep_time_ms.attr,
547 .attrs = wakeup_attrs,
550 static struct attribute *runtime_attrs[] = {
551 #ifdef CONFIG_PM_RUNTIME
552 #ifndef CONFIG_PM_ADVANCED_DEBUG
553 &dev_attr_runtime_status.attr,
555 &dev_attr_control.attr,
556 &dev_attr_runtime_suspended_time.attr,
557 &dev_attr_runtime_active_time.attr,
558 &dev_attr_autosuspend_delay_ms.attr,
564 .attrs = runtime_attrs,
567 static struct attribute *pm_qos_attrs[] = {
568 #ifdef CONFIG_PM_RUNTIME
569 &dev_attr_pm_qos_resume_latency_us.attr,
575 .attrs = pm_qos_attrs,
586 if (pm_runtime_callbacks_present(dev)) {
592 if (device_can_wakeup(dev)) {
595 if (pm_runtime_callbacks_present(dev))
597 &pm_runtime_attr_group);