Lines Matching refs:ws

82 	struct wakeup_source *ws;  in wakeup_source_create()  local
86 ws = kzalloc(sizeof(*ws), GFP_KERNEL); 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()
114 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
120 if (ws->event_count) { in wakeup_source_record()
122 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
125 ws->prevent_sleep_time); in wakeup_source_record()
127 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
128 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
129 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
130 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
131 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
132 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
133 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
139 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
141 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
142 kfree_const(ws->name); in wakeup_source_free()
143 kfree(ws); in wakeup_source_free()
152 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
154 if (!ws) in wakeup_source_destroy()
157 __pm_relax(ws); in wakeup_source_destroy()
158 wakeup_source_record(ws); in wakeup_source_destroy()
159 wakeup_source_free(ws); in wakeup_source_destroy()
167 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
171 if (WARN_ON(!ws)) in wakeup_source_add()
174 spin_lock_init(&ws->lock); in wakeup_source_add()
175 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
176 ws->active = false; in wakeup_source_add()
179 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
188 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
192 if (WARN_ON(!ws)) in wakeup_source_remove()
196 list_del_rcu(&ws->entry); in wakeup_source_remove()
200 del_timer_sync(&ws->timer); in wakeup_source_remove()
205 ws->timer.function = NULL; in wakeup_source_remove()
217 struct wakeup_source *ws; in wakeup_source_register() local
220 ws = wakeup_source_create(name); in wakeup_source_register()
221 if (ws) { in wakeup_source_register()
223 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
225 wakeup_source_free(ws); in wakeup_source_register()
229 wakeup_source_add(ws); in wakeup_source_register()
231 return ws; in wakeup_source_register()
239 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
241 if (ws) { in wakeup_source_unregister()
242 wakeup_source_remove(ws); in wakeup_source_unregister()
243 if (ws->dev) in wakeup_source_unregister()
244 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
246 wakeup_source_destroy(ws); in wakeup_source_unregister()
296 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws) in wakeup_sources_walk_next() argument
300 return list_next_or_null_rcu(ws_head, &ws->entry, in wakeup_sources_walk_next()
312 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
319 dev->power.wakeup = ws; in device_wakeup_attach()
334 struct wakeup_source *ws; in device_wakeup_enable() local
343 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
344 if (!ws) in device_wakeup_enable()
347 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
349 wakeup_source_unregister(ws); in device_wakeup_enable()
369 struct wakeup_source *ws; in device_wakeup_attach_irq() local
371 ws = dev->power.wakeup; in device_wakeup_attach_irq()
372 if (!ws) in device_wakeup_attach_irq()
375 if (ws->wakeirq) in device_wakeup_attach_irq()
378 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
391 struct wakeup_source *ws; in device_wakeup_detach_irq() local
393 ws = dev->power.wakeup; in device_wakeup_detach_irq()
394 if (ws) in device_wakeup_detach_irq()
395 ws->wakeirq = NULL; in device_wakeup_detach_irq()
405 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
409 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
410 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
421 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
425 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
426 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
438 struct wakeup_source *ws; in device_wakeup_detach() local
441 ws = dev->power.wakeup; in device_wakeup_detach()
444 return ws; in device_wakeup_detach()
456 struct wakeup_source *ws; in device_wakeup_disable() local
461 ws = device_wakeup_detach(dev); in device_wakeup_disable()
462 wakeup_source_unregister(ws); in device_wakeup_disable()
513 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
519 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
558 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
562 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
566 ws->active = true; in wakeup_source_activate()
567 ws->active_count++; in wakeup_source_activate()
568 ws->last_time = ktime_get(); in wakeup_source_activate()
569 if (ws->autosleep_enabled) in wakeup_source_activate()
570 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
575 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
583 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
585 ws->event_count++; in wakeup_source_report_event()
588 ws->wakeup_count++; in wakeup_source_report_event()
590 if (!ws->active) in wakeup_source_report_event()
591 wakeup_source_activate(ws); in wakeup_source_report_event()
603 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
607 if (!ws) in __pm_stay_awake()
610 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
612 wakeup_source_report_event(ws, false); in __pm_stay_awake()
613 del_timer(&ws->timer); in __pm_stay_awake()
614 ws->timer_expires = 0; in __pm_stay_awake()
616 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
645 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
647 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
648 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
651 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
663 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
669 ws->relax_count++; in wakeup_source_deactivate()
679 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
680 ws->relax_count--; in wakeup_source_deactivate()
684 ws->active = false; in wakeup_source_deactivate()
687 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
688 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
689 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
690 ws->max_time = duration; in wakeup_source_deactivate()
692 ws->last_time = now; in wakeup_source_deactivate()
693 del_timer(&ws->timer); in wakeup_source_deactivate()
694 ws->timer_expires = 0; in wakeup_source_deactivate()
696 if (ws->autosleep_enabled) in wakeup_source_deactivate()
697 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
704 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
720 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
724 if (!ws) in __pm_relax()
727 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
728 if (ws->active) in __pm_relax()
729 wakeup_source_deactivate(ws); in __pm_relax()
730 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
763 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
766 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
768 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
769 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
770 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
771 ws->expire_count++; in pm_wakeup_timer_fn()
774 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
790 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
795 if (!ws) in pm_wakeup_ws_event()
798 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
800 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
803 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
811 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
812 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
813 ws->timer_expires = expires; in pm_wakeup_ws_event()
817 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
844 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
849 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
850 if (ws->active) { in pm_print_active_wakeup_sources()
851 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
855 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
857 last_activity_ws = ws; in pm_print_active_wakeup_sources()
1024 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
1029 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
1030 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1031 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
1032 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
1033 if (ws->active) { in pm_wakep_autosleep_enabled()
1035 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
1037 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
1040 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1052 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1061 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1063 total_time = ws->total_time; in print_wakeup_source_stats()
1064 max_time = ws->max_time; in print_wakeup_source_stats()
1065 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1066 active_count = ws->active_count; in print_wakeup_source_stats()
1067 if (ws->active) { in print_wakeup_source_stats()
1070 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1075 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1077 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1083 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1084 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1086 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1089 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1097 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1108 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1110 return ws; in wakeup_sources_stats_seq_start()
1119 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1124 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1125 next_ws = ws; in wakeup_sources_stats_seq_next()
1149 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1151 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()