Lines Matching +full:power +full:- +full:source
2 * drivers/base/power/wakeup.c - System wakeup events framework
18 #include <trace/events/power.h>
20 #include "power.h"
47 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
76 * wakeup_source_prepare - Prepare a new wakeup source for initialization.
77 * @ws: Wakeup source to prepare.
78 * @name: Pointer to the name of the new wakeup source.
87 ws->name = name; in wakeup_source_prepare()
93 * wakeup_source_create - Create a struct wakeup_source object.
94 * @name: Name of the new wakeup source.
110 * wakeup_source_drop - Prepare a struct wakeup_source object for destruction.
111 * @ws: Wakeup source to prepare for destruction.
114 * be run in parallel with this function for the same wakeup source object.
134 if (ws->event_count) { in wakeup_source_record()
136 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
139 ws->prevent_sleep_time); in wakeup_source_record()
141 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
142 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
143 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
144 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
145 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
146 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
147 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
154 * wakeup_source_destroy - Destroy a struct wakeup_source object.
155 * @ws: Wakeup source to destroy.
157 * Use only for wakeup source objects created with wakeup_source_create().
166 kfree_const(ws->name); in wakeup_source_destroy()
172 * wakeup_source_add - Add given object to the list of wakeup sources.
173 * @ws: Wakeup source object to add to the list.
182 spin_lock_init(&ws->lock); in wakeup_source_add()
183 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
184 ws->active = false; in wakeup_source_add()
187 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
193 * wakeup_source_remove - Remove given object from the wakeup sources list.
194 * @ws: Wakeup source object to remove from the list.
204 list_del_rcu(&ws->entry); in wakeup_source_remove()
208 del_timer_sync(&ws->timer); in wakeup_source_remove()
211 * this wakeup source as not registered. in wakeup_source_remove()
213 ws->timer.function = NULL; in wakeup_source_remove()
218 * wakeup_source_register - Create wakeup source and add it to the list.
219 * @name: Name of the wakeup source to register.
234 * wakeup_source_unregister - Remove wakeup source from the list and remove it.
235 * @ws: Wakeup source object to unregister.
247 * device_wakeup_attach - Attach a wakeup source object to a device object.
249 * @ws: Wakeup source object to attach to @dev.
255 spin_lock_irq(&dev->power.lock); in device_wakeup_attach()
256 if (dev->power.wakeup) { in device_wakeup_attach()
257 spin_unlock_irq(&dev->power.lock); in device_wakeup_attach()
258 return -EEXIST; in device_wakeup_attach()
260 dev->power.wakeup = ws; in device_wakeup_attach()
261 if (dev->power.wakeirq) in device_wakeup_attach()
262 device_wakeup_attach_irq(dev, dev->power.wakeirq); in device_wakeup_attach()
263 spin_unlock_irq(&dev->power.lock); in device_wakeup_attach()
268 * device_wakeup_enable - Enable given device to be a wakeup source.
271 * Create a wakeup source object, register it and attach it to @dev.
278 if (!dev || !dev->power.can_wakeup) in device_wakeup_enable()
279 return -EINVAL; in device_wakeup_enable()
286 return -ENOMEM; in device_wakeup_enable()
297 * device_wakeup_attach_irq - Attach a wakeirq to a wakeup source
301 * Attach a device wakeirq to the wakeup source so the device
305 * Call under the device's power.lock lock.
312 ws = dev->power.wakeup; in device_wakeup_attach_irq()
316 if (ws->wakeirq) in device_wakeup_attach_irq()
319 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
323 * device_wakeup_detach_irq - Detach a wakeirq from a wakeup source
326 * Removes a device wakeirq from the wakeup source.
328 * Call under the device's power.lock lock.
334 ws = dev->power.wakeup; in device_wakeup_detach_irq()
336 ws->wakeirq = NULL; in device_wakeup_detach_irq()
351 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
367 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
372 * device_wakeup_detach - Detach a device's wakeup source object from it.
373 * @dev: Device to detach the wakeup source object from.
381 spin_lock_irq(&dev->power.lock); in device_wakeup_detach()
382 ws = dev->power.wakeup; in device_wakeup_detach()
383 dev->power.wakeup = NULL; in device_wakeup_detach()
384 spin_unlock_irq(&dev->power.lock); in device_wakeup_detach()
389 * device_wakeup_disable - Do not regard a device as a wakeup source any more.
392 * Detach the @dev's wakeup source object from it, unregister this wakeup source
399 if (!dev || !dev->power.can_wakeup) in device_wakeup_disable()
400 return -EINVAL; in device_wakeup_disable()
409 * device_set_wakeup_capable - Set/reset device wakeup capability flag.
413 * If @capable is set, set the @dev's power.can_wakeup flag and add its
414 * wakeup-related attributes to sysfs. Otherwise, unset the @dev's
415 * power.can_wakeup flag and remove its wakeup-related attributes from sysfs.
422 if (!!dev->power.can_wakeup == !!capable) in device_set_wakeup_capable()
425 dev->power.can_wakeup = capable; in device_set_wakeup_capable()
426 if (device_is_registered(dev) && !list_empty(&dev->power.entry)) { in device_set_wakeup_capable()
440 * device_init_wakeup - Device wakeup initialization.
445 * devices that everyone expects to be wakeup sources: keyboards, power buttons,
455 return -EINVAL; in device_init_wakeup()
470 * device_set_wakeup_enable - Enable or disable a device to wake up the system.
480 * wakeup_source_not_registered - validate the given wakeup source.
481 * @ws: Wakeup source to be validated.
486 * Use timer struct to check if the given source is initialized in wakeup_source_not_registered()
489 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
521 * wakup_source_activate - Mark given wakeup source as active.
522 * @ws: Wakeup source to handle.
533 "unregistered wakeup source\n")) in wakeup_source_activate()
536 ws->active = true; in wakeup_source_activate()
537 ws->active_count++; in wakeup_source_activate()
538 ws->last_time = ktime_get(); in wakeup_source_activate()
539 if (ws->autosleep_enabled) in wakeup_source_activate()
540 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
545 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
549 * wakeup_source_report_event - Report wakeup event using the given source.
550 * @ws: Wakeup source to report the event for.
551 * @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
555 ws->event_count++; in wakeup_source_report_event()
558 ws->wakeup_count++; in wakeup_source_report_event()
560 if (!ws->active) in wakeup_source_report_event()
568 * __pm_stay_awake - Notify the PM core of a wakeup event.
569 * @ws: Wakeup source object associated with the source of the event.
580 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
583 del_timer(&ws->timer); in __pm_stay_awake()
584 ws->timer_expires = 0; in __pm_stay_awake()
586 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
591 * pm_stay_awake - Notify the PM core that a wakeup event is being processed.
595 * __pm_stay_awake for the @dev's wakeup source object.
608 spin_lock_irqsave(&dev->power.lock, flags); in pm_stay_awake()
609 __pm_stay_awake(dev->power.wakeup); in pm_stay_awake()
610 spin_unlock_irqrestore(&dev->power.lock, flags); in pm_stay_awake()
617 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
618 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
626 * wakup_source_deactivate - Mark given wakeup source as inactive.
627 * @ws: Wakeup source to handle.
629 * Update the @ws' statistics and notify the PM core that the wakeup source has
639 ws->relax_count++; in wakeup_source_deactivate()
645 * will set ws->active. Then, ws->active may be cleared immediately in wakeup_source_deactivate()
647 * case ws->relax_count will be different from ws->active_count. in wakeup_source_deactivate()
649 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
650 ws->relax_count--; in wakeup_source_deactivate()
654 ws->active = false; in wakeup_source_deactivate()
657 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
658 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
659 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
660 ws->max_time = duration; in wakeup_source_deactivate()
662 ws->last_time = now; in wakeup_source_deactivate()
663 del_timer(&ws->timer); in wakeup_source_deactivate()
664 ws->timer_expires = 0; in wakeup_source_deactivate()
666 if (ws->autosleep_enabled) in wakeup_source_deactivate()
674 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
682 * __pm_relax - Notify the PM core that processing of a wakeup event has ended.
683 * @ws: Wakeup source object associated with the source of the event.
697 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
698 if (ws->active) in __pm_relax()
700 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
705 * pm_relax - Notify the PM core that processing of a wakeup event has ended.
708 * Execute __pm_relax() for the @dev's wakeup source object.
717 spin_lock_irqsave(&dev->power.lock, flags); in pm_relax()
718 __pm_relax(dev->power.wakeup); in pm_relax()
719 spin_unlock_irqrestore(&dev->power.lock, flags); in pm_relax()
724 * pm_wakeup_timer_fn - Delayed finalization of a wakeup event.
725 * @data: Address of the wakeup source object associated with the event source.
727 * Call wakeup_source_deactivate() for the wakeup source whose address is stored
736 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
738 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
739 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
741 ws->expire_count++; in pm_wakeup_timer_fn()
744 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
748 * pm_wakeup_ws_event - Notify the PM core of a wakeup event.
749 * @ws: Wakeup source object associated with the event source.
751 * @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
753 * Notify the PM core of a wakeup event whose source is @ws that will take
768 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
781 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
782 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
783 ws->timer_expires = expires; in pm_wakeup_ws_event()
787 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
792 * pm_wakeup_event - Notify the PM core of a wakeup event.
795 * @hard: If set, abort suspends in progress and wake up from suspend-to-idle.
797 * Call pm_wakeup_ws_event() for the @dev's wakeup source object.
806 spin_lock_irqsave(&dev->power.lock, flags); in pm_wakeup_dev_event()
807 pm_wakeup_ws_event(dev->power.wakeup, msec, hard); in pm_wakeup_dev_event()
808 spin_unlock_irqrestore(&dev->power.lock, flags); in pm_wakeup_dev_event()
820 if (ws->active) { in pm_print_active_wakeup_sources()
821 pr_debug("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
825 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
826 ktime_to_ns(last_activity_ws->last_time))) { in pm_print_active_wakeup_sources()
832 pr_debug("last active wakeup source: %s\n", in pm_print_active_wakeup_sources()
833 last_activity_ws->name); in pm_print_active_wakeup_sources()
839 * pm_wakeup_pending - Check if power transition in progress should be aborted.
897 * pm_get_wakeup_count - Read the number of registered wakeup events.
933 * pm_save_wakeup_count - Save the current number of registered wakeup events.
960 * pm_wakep_autosleep_enabled - Modify autosleep_enabled for all wakeup sources.
971 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
972 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
973 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
974 if (ws->active) { in pm_wakep_autosleep_enabled()
976 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
981 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
990 * print_wakeup_source_stats - Print wakeup source statistics information.
992 * @ws: Wakeup source object to print the statistics for.
1004 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1006 total_time = ws->total_time; in print_wakeup_source_stats()
1007 max_time = ws->max_time; in print_wakeup_source_stats()
1008 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1009 active_count = ws->active_count; in print_wakeup_source_stats()
1010 if (ws->active) { in print_wakeup_source_stats()
1013 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1018 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1020 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1025 seq_printf(m, "%-12s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t%lld\t\t%lld\t\t%lld\t\t%lld\t\t%lld\n", in print_wakeup_source_stats()
1026 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1027 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1029 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1032 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1042 int *srcuidx = m->private; in wakeup_sources_stats_seq_start()
1052 if (n-- <= 0) in wakeup_sources_stats_seq_start()
1077 int *srcuidx = m->private; in wakeup_sources_stats_seq_stop()
1083 * wakeup_sources_stats_seq_show - Print wakeup sources statistics information.