Lines Matching refs:ws

90 	struct wakeup_source *ws;  in wakeup_source_create()  local
94 ws = kzalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
95 if (!ws) in wakeup_source_create()
101 ws->name = ws_name; in wakeup_source_create()
106 ws->id = id; in wakeup_source_create()
108 return ws; in wakeup_source_create()
111 kfree_const(ws->name); in wakeup_source_create()
113 kfree(ws); in wakeup_source_create()
122 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
128 if (ws->event_count) { in wakeup_source_record()
130 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
133 ws->prevent_sleep_time); in wakeup_source_record()
135 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
136 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
137 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
138 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
139 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
140 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
141 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
147 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
149 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
150 kfree_const(ws->name); in wakeup_source_free()
151 kfree(ws); in wakeup_source_free()
160 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
162 if (!ws) in wakeup_source_destroy()
165 __pm_relax(ws); in wakeup_source_destroy()
166 wakeup_source_record(ws); in wakeup_source_destroy()
167 wakeup_source_free(ws); in wakeup_source_destroy()
175 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
179 if (WARN_ON(!ws)) in wakeup_source_add()
182 spin_lock_init(&ws->lock); in wakeup_source_add()
183 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
184 ws->active = false; in wakeup_source_add()
187 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
196 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
200 if (WARN_ON(!ws)) in wakeup_source_remove()
204 list_del_rcu(&ws->entry); in wakeup_source_remove()
208 del_timer_sync(&ws->timer); in wakeup_source_remove()
213 ws->timer.function = NULL; in wakeup_source_remove()
225 struct wakeup_source *ws; in wakeup_source_register() local
228 ws = wakeup_source_create(name); in wakeup_source_register()
229 if (ws) { in wakeup_source_register()
231 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
233 wakeup_source_free(ws); in wakeup_source_register()
237 wakeup_source_add(ws); in wakeup_source_register()
239 return ws; in wakeup_source_register()
247 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
249 if (ws) { in wakeup_source_unregister()
250 wakeup_source_remove(ws); in wakeup_source_unregister()
251 if (ws->dev) in wakeup_source_unregister()
252 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
254 wakeup_source_destroy(ws); in wakeup_source_unregister()
304 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws) in wakeup_sources_walk_next() argument
308 return list_next_or_null_rcu(ws_head, &ws->entry, in wakeup_sources_walk_next()
320 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
327 dev->power.wakeup = ws; in device_wakeup_attach()
342 struct wakeup_source *ws; in device_wakeup_enable() local
351 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
352 if (!ws) in device_wakeup_enable()
355 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
357 wakeup_source_unregister(ws); in device_wakeup_enable()
377 struct wakeup_source *ws; in device_wakeup_attach_irq() local
379 ws = dev->power.wakeup; in device_wakeup_attach_irq()
380 if (!ws) in device_wakeup_attach_irq()
383 if (ws->wakeirq) in device_wakeup_attach_irq()
386 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
399 struct wakeup_source *ws; in device_wakeup_detach_irq() local
401 ws = dev->power.wakeup; in device_wakeup_detach_irq()
402 if (ws) in device_wakeup_detach_irq()
403 ws->wakeirq = NULL; in device_wakeup_detach_irq()
413 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
417 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
418 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
429 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
433 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
434 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
446 struct wakeup_source *ws; in device_wakeup_detach() local
449 ws = dev->power.wakeup; in device_wakeup_detach()
452 return ws; in device_wakeup_detach()
464 struct wakeup_source *ws; in device_wakeup_disable() local
469 ws = device_wakeup_detach(dev); in device_wakeup_disable()
470 wakeup_source_unregister(ws); in device_wakeup_disable()
550 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
556 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
595 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
599 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
603 ws->active = true; in wakeup_source_activate()
604 ws->active_count++; in wakeup_source_activate()
605 ws->last_time = ktime_get(); in wakeup_source_activate()
606 if (ws->autosleep_enabled) in wakeup_source_activate()
607 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
612 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
620 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
622 ws->event_count++; in wakeup_source_report_event()
625 ws->wakeup_count++; in wakeup_source_report_event()
627 if (!ws->active) in wakeup_source_report_event()
628 wakeup_source_activate(ws); in wakeup_source_report_event()
640 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
644 if (!ws) in __pm_stay_awake()
647 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
649 wakeup_source_report_event(ws, false); in __pm_stay_awake()
650 del_timer(&ws->timer); in __pm_stay_awake()
651 ws->timer_expires = 0; in __pm_stay_awake()
653 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
682 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
684 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
685 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
688 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
700 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
706 ws->relax_count++; in wakeup_source_deactivate()
716 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
717 ws->relax_count--; in wakeup_source_deactivate()
721 ws->active = false; in wakeup_source_deactivate()
724 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
725 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
726 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
727 ws->max_time = duration; in wakeup_source_deactivate()
729 ws->last_time = now; in wakeup_source_deactivate()
730 del_timer(&ws->timer); in wakeup_source_deactivate()
731 ws->timer_expires = 0; in wakeup_source_deactivate()
733 if (ws->autosleep_enabled) in wakeup_source_deactivate()
734 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
741 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
757 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
761 if (!ws) in __pm_relax()
764 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
765 if (ws->active) in __pm_relax()
766 wakeup_source_deactivate(ws); in __pm_relax()
767 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
800 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
803 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
805 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
806 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
807 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
808 ws->expire_count++; in pm_wakeup_timer_fn()
811 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
827 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
832 if (!ws) in pm_wakeup_ws_event()
835 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
837 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
840 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
848 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
849 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
850 ws->timer_expires = expires; in pm_wakeup_ws_event()
854 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
881 struct wakeup_source *ws, *last_active_ws = NULL; in pm_get_active_wakeup_sources() local
886 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_get_active_wakeup_sources()
887 if (ws->active && len < max) { in pm_get_active_wakeup_sources()
892 "%s ", ws->name); in pm_get_active_wakeup_sources()
896 ktime_to_ns(ws->last_time) > in pm_get_active_wakeup_sources()
898 last_active_ws = ws; in pm_get_active_wakeup_sources()
912 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
917 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
918 if (ws->active) { in pm_print_active_wakeup_sources()
919 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
923 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
925 last_activity_ws = ws; in pm_print_active_wakeup_sources()
1106 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
1111 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
1112 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1113 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
1114 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
1115 if (ws->active) { in pm_wakep_autosleep_enabled()
1117 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
1119 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
1122 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1134 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1143 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1145 total_time = ws->total_time; in print_wakeup_source_stats()
1146 max_time = ws->max_time; in print_wakeup_source_stats()
1147 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1148 active_count = ws->active_count; in print_wakeup_source_stats()
1149 if (ws->active) { in print_wakeup_source_stats()
1152 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1157 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1159 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1165 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1166 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1168 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1171 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1179 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1190 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1192 return ws; in wakeup_sources_stats_seq_start()
1201 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1206 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1207 next_ws = ws; in wakeup_sources_stats_seq_next()
1231 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1233 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()