Lines Matching refs:ws
83 void wakeup_source_prepare(struct wakeup_source *ws, const char *name) in wakeup_source_prepare() argument
85 if (ws) { in wakeup_source_prepare()
86 memset(ws, 0, sizeof(*ws)); in wakeup_source_prepare()
87 ws->name = name; in wakeup_source_prepare()
98 struct wakeup_source *ws; in wakeup_source_create() local
100 ws = kmalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
101 if (!ws) in wakeup_source_create()
104 wakeup_source_prepare(ws, name ? kstrdup_const(name, GFP_KERNEL) : NULL); in wakeup_source_create()
105 return ws; in wakeup_source_create()
116 void wakeup_source_drop(struct wakeup_source *ws) in wakeup_source_drop() argument
118 if (!ws) in wakeup_source_drop()
121 del_timer_sync(&ws->timer); in wakeup_source_drop()
122 __pm_relax(ws); in wakeup_source_drop()
129 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
135 if (ws->event_count) { in wakeup_source_record()
137 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
140 ws->prevent_sleep_time); in wakeup_source_record()
142 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
143 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
144 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
145 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
146 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
147 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
148 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
160 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
162 if (!ws) in wakeup_source_destroy()
165 wakeup_source_drop(ws); in wakeup_source_destroy()
166 wakeup_source_record(ws); in wakeup_source_destroy()
167 kfree_const(ws->name); in wakeup_source_destroy()
168 kfree(ws); in wakeup_source_destroy()
176 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
180 if (WARN_ON(!ws)) in wakeup_source_add()
183 spin_lock_init(&ws->lock); in wakeup_source_add()
184 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
185 ws->active = false; in wakeup_source_add()
188 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
197 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
201 if (WARN_ON(!ws)) in wakeup_source_remove()
205 list_del_rcu(&ws->entry); in wakeup_source_remove()
217 struct wakeup_source *ws; in wakeup_source_register() local
219 ws = wakeup_source_create(name); in wakeup_source_register()
220 if (ws) in wakeup_source_register()
221 wakeup_source_add(ws); in wakeup_source_register()
223 return ws; in wakeup_source_register()
231 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
233 if (ws) { in wakeup_source_unregister()
234 wakeup_source_remove(ws); in wakeup_source_unregister()
235 wakeup_source_destroy(ws); in wakeup_source_unregister()
247 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
254 dev->power.wakeup = ws; in device_wakeup_attach()
269 struct wakeup_source *ws; in device_wakeup_enable() local
278 ws = wakeup_source_register(dev_name(dev)); in device_wakeup_enable()
279 if (!ws) in device_wakeup_enable()
282 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
284 wakeup_source_unregister(ws); in device_wakeup_enable()
304 struct wakeup_source *ws; in device_wakeup_attach_irq() local
306 ws = dev->power.wakeup; in device_wakeup_attach_irq()
307 if (!ws) in device_wakeup_attach_irq()
310 if (ws->wakeirq) in device_wakeup_attach_irq()
313 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
326 struct wakeup_source *ws; in device_wakeup_detach_irq() local
328 ws = dev->power.wakeup; in device_wakeup_detach_irq()
329 if (ws) in device_wakeup_detach_irq()
330 ws->wakeirq = NULL; in device_wakeup_detach_irq()
340 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
344 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
345 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
356 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
360 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
361 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
373 struct wakeup_source *ws; in device_wakeup_detach() local
376 ws = dev->power.wakeup; in device_wakeup_detach()
379 return ws; in device_wakeup_detach()
391 struct wakeup_source *ws; in device_wakeup_disable() local
396 ws = device_wakeup_detach(dev); in device_wakeup_disable()
397 wakeup_source_unregister(ws); in device_wakeup_disable()
477 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
483 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
522 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
526 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
530 ws->active = true; in wakeup_source_activate()
531 ws->active_count++; in wakeup_source_activate()
532 ws->last_time = ktime_get(); in wakeup_source_activate()
533 if (ws->autosleep_enabled) in wakeup_source_activate()
534 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
539 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
547 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
549 ws->event_count++; in wakeup_source_report_event()
552 ws->wakeup_count++; in wakeup_source_report_event()
554 if (!ws->active) in wakeup_source_report_event()
555 wakeup_source_activate(ws); in wakeup_source_report_event()
567 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
571 if (!ws) in __pm_stay_awake()
574 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
576 wakeup_source_report_event(ws, false); in __pm_stay_awake()
577 del_timer(&ws->timer); in __pm_stay_awake()
578 ws->timer_expires = 0; in __pm_stay_awake()
580 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
609 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
611 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
612 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
615 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
627 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
633 ws->relax_count++; in wakeup_source_deactivate()
643 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
644 ws->relax_count--; in wakeup_source_deactivate()
648 ws->active = false; in wakeup_source_deactivate()
651 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
652 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
653 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
654 ws->max_time = duration; in wakeup_source_deactivate()
656 ws->last_time = now; in wakeup_source_deactivate()
657 del_timer(&ws->timer); in wakeup_source_deactivate()
658 ws->timer_expires = 0; in wakeup_source_deactivate()
660 if (ws->autosleep_enabled) in wakeup_source_deactivate()
661 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
668 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
684 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
688 if (!ws) in __pm_relax()
691 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
692 if (ws->active) in __pm_relax()
693 wakeup_source_deactivate(ws); in __pm_relax()
694 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
727 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
730 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
732 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
733 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
734 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
735 ws->expire_count++; in pm_wakeup_timer_fn()
738 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
754 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
759 if (!ws) in pm_wakeup_ws_event()
762 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
764 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
767 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
775 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
776 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
777 ws->timer_expires = expires; in pm_wakeup_ws_event()
781 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
808 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
813 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
814 if (ws->active) { in pm_print_active_wakeup_sources()
815 pr_debug("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
819 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
821 last_activity_ws = ws; in pm_print_active_wakeup_sources()
959 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
964 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
965 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
966 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
967 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
968 if (ws->active) { in pm_wakep_autosleep_enabled()
970 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
972 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
975 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
989 struct wakeup_source *ws) in print_wakeup_source_stats() argument
998 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1000 total_time = ws->total_time; in print_wakeup_source_stats()
1001 max_time = ws->max_time; in print_wakeup_source_stats()
1002 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1003 active_count = ws->active_count; in print_wakeup_source_stats()
1004 if (ws->active) { in print_wakeup_source_stats()
1007 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1012 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1014 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1020 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1021 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1023 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1026 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1034 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1045 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1047 return ws; in wakeup_sources_stats_seq_start()
1056 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1061 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1062 next_ws = ws; in wakeup_sources_stats_seq_next()
1083 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1085 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()