Lines Matching refs:ws
86 struct wakeup_source *ws; in wakeup_source_create() local
90 ws = kzalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
91 if (!ws) in wakeup_source_create()
97 ws->name = ws_name; in wakeup_source_create()
102 ws->id = id; in wakeup_source_create()
104 return ws; in wakeup_source_create()
107 kfree_const(ws->name); in wakeup_source_create()
109 kfree(ws); in wakeup_source_create()
118 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
124 if (ws->event_count) { in wakeup_source_record()
126 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
129 ws->prevent_sleep_time); in wakeup_source_record()
131 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
132 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
133 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
134 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
135 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
136 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
137 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
143 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
145 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
146 kfree_const(ws->name); in wakeup_source_free()
147 kfree(ws); in wakeup_source_free()
156 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
158 if (!ws) in wakeup_source_destroy()
161 __pm_relax(ws); in wakeup_source_destroy()
162 wakeup_source_record(ws); in wakeup_source_destroy()
163 wakeup_source_free(ws); in wakeup_source_destroy()
171 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
175 if (WARN_ON(!ws)) in wakeup_source_add()
178 spin_lock_init(&ws->lock); in wakeup_source_add()
179 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
180 ws->active = false; in wakeup_source_add()
183 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
192 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
196 if (WARN_ON(!ws)) in wakeup_source_remove()
200 list_del_rcu(&ws->entry); in wakeup_source_remove()
204 del_timer_sync(&ws->timer); in wakeup_source_remove()
209 ws->timer.function = NULL; in wakeup_source_remove()
221 struct wakeup_source *ws; in wakeup_source_register() local
224 ws = wakeup_source_create(name); in wakeup_source_register()
225 if (ws) { in wakeup_source_register()
227 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
229 wakeup_source_free(ws); in wakeup_source_register()
233 wakeup_source_add(ws); in wakeup_source_register()
235 return ws; in wakeup_source_register()
243 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
245 if (ws) { in wakeup_source_unregister()
246 wakeup_source_remove(ws); in wakeup_source_unregister()
247 if (ws->dev) in wakeup_source_unregister()
248 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
250 wakeup_source_destroy(ws); in wakeup_source_unregister()
300 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws) in wakeup_sources_walk_next() argument
304 return list_next_or_null_rcu(ws_head, &ws->entry, in wakeup_sources_walk_next()
316 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
323 dev->power.wakeup = ws; in device_wakeup_attach()
338 struct wakeup_source *ws; in device_wakeup_enable() local
347 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
348 if (!ws) in device_wakeup_enable()
351 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
353 wakeup_source_unregister(ws); in device_wakeup_enable()
373 struct wakeup_source *ws; in device_wakeup_attach_irq() local
375 ws = dev->power.wakeup; in device_wakeup_attach_irq()
376 if (!ws) in device_wakeup_attach_irq()
379 if (ws->wakeirq) in device_wakeup_attach_irq()
382 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
395 struct wakeup_source *ws; in device_wakeup_detach_irq() local
397 ws = dev->power.wakeup; in device_wakeup_detach_irq()
398 if (ws) in device_wakeup_detach_irq()
399 ws->wakeirq = NULL; in device_wakeup_detach_irq()
409 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
413 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
414 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
425 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
429 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
430 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
442 struct wakeup_source *ws; in device_wakeup_detach() local
445 ws = dev->power.wakeup; in device_wakeup_detach()
448 return ws; in device_wakeup_detach()
460 struct wakeup_source *ws; in device_wakeup_disable() local
465 ws = device_wakeup_detach(dev); in device_wakeup_disable()
466 wakeup_source_unregister(ws); in device_wakeup_disable()
546 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
552 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
591 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
595 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
599 ws->active = true; in wakeup_source_activate()
600 ws->active_count++; in wakeup_source_activate()
601 ws->last_time = ktime_get(); in wakeup_source_activate()
602 if (ws->autosleep_enabled) in wakeup_source_activate()
603 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
608 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
616 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
618 ws->event_count++; in wakeup_source_report_event()
621 ws->wakeup_count++; in wakeup_source_report_event()
623 if (!ws->active) in wakeup_source_report_event()
624 wakeup_source_activate(ws); in wakeup_source_report_event()
636 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
640 if (!ws) in __pm_stay_awake()
643 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
645 wakeup_source_report_event(ws, false); in __pm_stay_awake()
646 del_timer(&ws->timer); in __pm_stay_awake()
647 ws->timer_expires = 0; in __pm_stay_awake()
649 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
678 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
680 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
681 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
684 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
696 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
702 ws->relax_count++; in wakeup_source_deactivate()
712 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
713 ws->relax_count--; in wakeup_source_deactivate()
717 ws->active = false; in wakeup_source_deactivate()
720 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
721 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
722 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
723 ws->max_time = duration; in wakeup_source_deactivate()
725 ws->last_time = now; in wakeup_source_deactivate()
726 del_timer(&ws->timer); in wakeup_source_deactivate()
727 ws->timer_expires = 0; in wakeup_source_deactivate()
729 if (ws->autosleep_enabled) in wakeup_source_deactivate()
730 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
737 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
753 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
757 if (!ws) in __pm_relax()
760 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
761 if (ws->active) in __pm_relax()
762 wakeup_source_deactivate(ws); in __pm_relax()
763 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
796 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
799 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
801 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
802 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
803 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
804 ws->expire_count++; in pm_wakeup_timer_fn()
807 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
823 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
828 if (!ws) in pm_wakeup_ws_event()
831 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
833 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
836 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
844 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
845 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
846 ws->timer_expires = expires; in pm_wakeup_ws_event()
850 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
877 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
882 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
883 if (ws->active) { in pm_print_active_wakeup_sources()
884 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
888 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
890 last_activity_ws = ws; in pm_print_active_wakeup_sources()
1028 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
1033 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
1034 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1035 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
1036 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
1037 if (ws->active) { in pm_wakep_autosleep_enabled()
1039 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
1041 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
1044 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1056 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1065 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1067 total_time = ws->total_time; in print_wakeup_source_stats()
1068 max_time = ws->max_time; in print_wakeup_source_stats()
1069 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1070 active_count = ws->active_count; in print_wakeup_source_stats()
1071 if (ws->active) { in print_wakeup_source_stats()
1074 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1079 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1081 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1087 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1088 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1090 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1093 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1101 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1112 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1114 return ws; in wakeup_sources_stats_seq_start()
1123 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1128 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1129 next_ws = ws; in wakeup_sources_stats_seq_next()
1153 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1155 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()