Lines Matching refs:ws

82 	struct wakeup_source *ws;  in wakeup_source_create()  local
86 ws = kzalloc_obj(*ws); in wakeup_source_create()
87 if (!ws) in wakeup_source_create()
93 ws->name = ws_name; in wakeup_source_create()
98 ws->id = id; in wakeup_source_create()
100 return ws; in wakeup_source_create()
103 kfree_const(ws->name); in wakeup_source_create()
105 kfree(ws); in wakeup_source_create()
113 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
119 if (ws->event_count) { in wakeup_source_record()
121 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
124 ws->prevent_sleep_time); in wakeup_source_record()
126 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
127 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
128 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
129 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
130 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
131 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
132 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
138 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
140 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
141 kfree_const(ws->name); in wakeup_source_free()
142 kfree(ws); in wakeup_source_free()
151 static void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
153 if (!ws) in wakeup_source_destroy()
156 __pm_relax(ws); in wakeup_source_destroy()
157 wakeup_source_record(ws); in wakeup_source_destroy()
158 wakeup_source_free(ws); in wakeup_source_destroy()
165 static void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
169 if (WARN_ON(!ws)) in wakeup_source_add()
172 spin_lock_init(&ws->lock); in wakeup_source_add()
173 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
174 ws->active = false; in wakeup_source_add()
177 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
185 static void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
189 if (WARN_ON(!ws)) in wakeup_source_remove()
196 timer_shutdown_sync(&ws->timer); in wakeup_source_remove()
199 list_del_rcu(&ws->entry); in wakeup_source_remove()
212 struct wakeup_source *ws; in wakeup_source_register() local
215 ws = wakeup_source_create(name); in wakeup_source_register()
216 if (ws) { in wakeup_source_register()
218 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
220 wakeup_source_free(ws); in wakeup_source_register()
224 wakeup_source_add(ws); in wakeup_source_register()
226 return ws; in wakeup_source_register()
234 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
236 if (ws) { in wakeup_source_unregister()
237 wakeup_source_remove(ws); in wakeup_source_unregister()
238 if (ws->dev) in wakeup_source_unregister()
239 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
241 wakeup_source_destroy(ws); in wakeup_source_unregister()
289 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws) in wakeup_sources_walk_next() argument
293 return list_next_or_null_rcu(ws_head, &ws->entry, in wakeup_sources_walk_next()
305 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
312 dev->power.wakeup = ws; in device_wakeup_attach()
327 struct wakeup_source *ws; in device_wakeup_enable() local
336 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
337 if (!ws) in device_wakeup_enable()
340 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
342 wakeup_source_unregister(ws); in device_wakeup_enable()
362 struct wakeup_source *ws; in device_wakeup_attach_irq() local
364 ws = dev->power.wakeup; in device_wakeup_attach_irq()
365 if (!ws) in device_wakeup_attach_irq()
368 if (ws->wakeirq) in device_wakeup_attach_irq()
371 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
384 struct wakeup_source *ws; in device_wakeup_detach_irq() local
386 ws = dev->power.wakeup; in device_wakeup_detach_irq()
387 if (ws) in device_wakeup_detach_irq()
388 ws->wakeirq = NULL; in device_wakeup_detach_irq()
398 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
402 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
403 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
414 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
418 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
419 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
431 struct wakeup_source *ws; in device_wakeup_detach() local
434 ws = dev->power.wakeup; in device_wakeup_detach()
437 return ws; in device_wakeup_detach()
449 struct wakeup_source *ws; in device_wakeup_disable() local
454 ws = device_wakeup_detach(dev); in device_wakeup_disable()
455 wakeup_source_unregister(ws); in device_wakeup_disable()
509 static bool wakeup_source_not_usable(struct wakeup_source *ws) in wakeup_source_not_usable() argument
515 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_usable()
554 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
558 if (WARN_ONCE(wakeup_source_not_usable(ws), "unusable wakeup source\n")) in wakeup_source_activate()
561 ws->active = true; in wakeup_source_activate()
562 ws->active_count++; in wakeup_source_activate()
563 ws->last_time = ktime_get(); in wakeup_source_activate()
564 if (ws->autosleep_enabled) in wakeup_source_activate()
565 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
570 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
578 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
580 ws->event_count++; in wakeup_source_report_event()
583 ws->wakeup_count++; in wakeup_source_report_event()
585 if (!ws->active) in wakeup_source_report_event()
586 wakeup_source_activate(ws); in wakeup_source_report_event()
598 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
602 if (!ws) in __pm_stay_awake()
605 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
607 wakeup_source_report_event(ws, false); in __pm_stay_awake()
608 timer_delete(&ws->timer); in __pm_stay_awake()
609 ws->timer_expires = 0; in __pm_stay_awake()
611 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
640 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
642 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
643 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
646 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
658 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
664 ws->relax_count++; in wakeup_source_deactivate()
674 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
675 ws->relax_count--; in wakeup_source_deactivate()
679 ws->active = false; in wakeup_source_deactivate()
682 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
683 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
684 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
685 ws->max_time = duration; in wakeup_source_deactivate()
687 ws->last_time = now; in wakeup_source_deactivate()
688 timer_delete(&ws->timer); in wakeup_source_deactivate()
689 ws->timer_expires = 0; in wakeup_source_deactivate()
691 if (ws->autosleep_enabled) in wakeup_source_deactivate()
692 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
699 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
715 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
719 if (!ws) in __pm_relax()
722 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
723 if (ws->active) in __pm_relax()
724 wakeup_source_deactivate(ws); in __pm_relax()
725 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
758 struct wakeup_source *ws = timer_container_of(ws, t, timer); in pm_wakeup_timer_fn() local
761 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
763 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
764 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
765 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
766 ws->expire_count++; in pm_wakeup_timer_fn()
769 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
785 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
790 if (!ws) in pm_wakeup_ws_event()
793 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
795 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
798 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
806 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
807 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
808 ws->timer_expires = expires; in pm_wakeup_ws_event()
812 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
839 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
844 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
845 if (ws->active) { in pm_print_active_wakeup_sources()
846 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
850 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
852 last_activity_ws = ws; in pm_print_active_wakeup_sources()
1019 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
1024 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
1025 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1026 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
1027 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
1028 if (ws->active) { in pm_wakep_autosleep_enabled()
1030 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
1032 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
1035 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1047 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1056 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1058 total_time = ws->total_time; in print_wakeup_source_stats()
1059 max_time = ws->max_time; in print_wakeup_source_stats()
1060 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1061 active_count = ws->active_count; in print_wakeup_source_stats()
1062 if (ws->active) { in print_wakeup_source_stats()
1065 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1070 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1072 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1078 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1079 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1081 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1084 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1092 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1103 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1105 return ws; in wakeup_sources_stats_seq_start()
1114 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1119 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1120 next_ws = ws; in wakeup_sources_stats_seq_next()
1144 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1146 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()