Lines Matching refs:ws

83 	struct wakeup_source *ws;  in wakeup_source_create()  local
87 ws = kzalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
88 if (!ws) in wakeup_source_create()
94 ws->name = ws_name; in wakeup_source_create()
99 ws->id = id; in wakeup_source_create()
101 return ws; in wakeup_source_create()
104 kfree_const(ws->name); in wakeup_source_create()
106 kfree(ws); in wakeup_source_create()
115 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
121 if (ws->event_count) { in wakeup_source_record()
123 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
126 ws->prevent_sleep_time); in wakeup_source_record()
128 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
129 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
130 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
131 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
132 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
133 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
134 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
140 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
142 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
143 kfree_const(ws->name); in wakeup_source_free()
144 kfree(ws); in wakeup_source_free()
153 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
155 if (!ws) in wakeup_source_destroy()
158 __pm_relax(ws); in wakeup_source_destroy()
159 wakeup_source_record(ws); in wakeup_source_destroy()
160 wakeup_source_free(ws); in wakeup_source_destroy()
168 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
172 if (WARN_ON(!ws)) in wakeup_source_add()
175 spin_lock_init(&ws->lock); in wakeup_source_add()
176 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
177 ws->active = false; in wakeup_source_add()
180 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
189 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
193 if (WARN_ON(!ws)) in wakeup_source_remove()
197 list_del_rcu(&ws->entry); in wakeup_source_remove()
201 del_timer_sync(&ws->timer); in wakeup_source_remove()
206 ws->timer.function = NULL; in wakeup_source_remove()
218 struct wakeup_source *ws; in wakeup_source_register() local
221 ws = wakeup_source_create(name); in wakeup_source_register()
222 if (ws) { in wakeup_source_register()
224 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
226 wakeup_source_free(ws); in wakeup_source_register()
230 wakeup_source_add(ws); in wakeup_source_register()
232 return ws; in wakeup_source_register()
240 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
242 if (ws) { in wakeup_source_unregister()
243 wakeup_source_remove(ws); in wakeup_source_unregister()
244 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
245 wakeup_source_destroy(ws); in wakeup_source_unregister()
257 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
264 dev->power.wakeup = ws; in device_wakeup_attach()
279 struct wakeup_source *ws; in device_wakeup_enable() local
288 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
289 if (!ws) in device_wakeup_enable()
292 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
294 wakeup_source_unregister(ws); in device_wakeup_enable()
314 struct wakeup_source *ws; in device_wakeup_attach_irq() local
316 ws = dev->power.wakeup; in device_wakeup_attach_irq()
317 if (!ws) in device_wakeup_attach_irq()
320 if (ws->wakeirq) in device_wakeup_attach_irq()
323 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
336 struct wakeup_source *ws; in device_wakeup_detach_irq() local
338 ws = dev->power.wakeup; in device_wakeup_detach_irq()
339 if (ws) in device_wakeup_detach_irq()
340 ws->wakeirq = NULL; in device_wakeup_detach_irq()
350 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
354 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
355 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
366 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
370 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
371 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
383 struct wakeup_source *ws; in device_wakeup_detach() local
386 ws = dev->power.wakeup; in device_wakeup_detach()
389 return ws; in device_wakeup_detach()
401 struct wakeup_source *ws; in device_wakeup_disable() local
406 ws = device_wakeup_detach(dev); in device_wakeup_disable()
407 wakeup_source_unregister(ws); in device_wakeup_disable()
487 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
493 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
532 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
536 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
540 ws->active = true; in wakeup_source_activate()
541 ws->active_count++; in wakeup_source_activate()
542 ws->last_time = ktime_get(); in wakeup_source_activate()
543 if (ws->autosleep_enabled) in wakeup_source_activate()
544 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
549 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
557 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
559 ws->event_count++; in wakeup_source_report_event()
562 ws->wakeup_count++; in wakeup_source_report_event()
564 if (!ws->active) in wakeup_source_report_event()
565 wakeup_source_activate(ws); in wakeup_source_report_event()
577 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
581 if (!ws) in __pm_stay_awake()
584 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
586 wakeup_source_report_event(ws, false); in __pm_stay_awake()
587 del_timer(&ws->timer); in __pm_stay_awake()
588 ws->timer_expires = 0; in __pm_stay_awake()
590 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
619 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
621 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
622 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
625 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
637 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
643 ws->relax_count++; in wakeup_source_deactivate()
653 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
654 ws->relax_count--; in wakeup_source_deactivate()
658 ws->active = false; in wakeup_source_deactivate()
661 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
662 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
663 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
664 ws->max_time = duration; in wakeup_source_deactivate()
666 ws->last_time = now; in wakeup_source_deactivate()
667 del_timer(&ws->timer); in wakeup_source_deactivate()
668 ws->timer_expires = 0; in wakeup_source_deactivate()
670 if (ws->autosleep_enabled) in wakeup_source_deactivate()
671 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
678 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
694 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
698 if (!ws) in __pm_relax()
701 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
702 if (ws->active) in __pm_relax()
703 wakeup_source_deactivate(ws); in __pm_relax()
704 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
737 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
740 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
742 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
743 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
744 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
745 ws->expire_count++; in pm_wakeup_timer_fn()
748 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
764 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
769 if (!ws) in pm_wakeup_ws_event()
772 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
774 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
777 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
785 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
786 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
787 ws->timer_expires = expires; in pm_wakeup_ws_event()
791 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
818 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
823 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
824 if (ws->active) { in pm_print_active_wakeup_sources()
825 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
829 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
831 last_activity_ws = ws; in pm_print_active_wakeup_sources()
969 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
974 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
975 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
976 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
977 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
978 if (ws->active) { in pm_wakep_autosleep_enabled()
980 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
982 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
985 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
997 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1006 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1008 total_time = ws->total_time; in print_wakeup_source_stats()
1009 max_time = ws->max_time; in print_wakeup_source_stats()
1010 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1011 active_count = ws->active_count; in print_wakeup_source_stats()
1012 if (ws->active) { in print_wakeup_source_stats()
1015 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1020 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1022 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1028 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1029 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1031 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1034 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1042 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1053 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1055 return ws; in wakeup_sources_stats_seq_start()
1064 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1069 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1070 next_ws = ws; in wakeup_sources_stats_seq_next()
1091 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1093 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()