Lines Matching refs:ws

87 	struct wakeup_source *ws;  in wakeup_source_create()  local
91 ws = kzalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
92 if (!ws) in wakeup_source_create()
98 ws->name = ws_name; in wakeup_source_create()
103 ws->id = id; in wakeup_source_create()
105 return ws; in wakeup_source_create()
108 kfree_const(ws->name); in wakeup_source_create()
110 kfree(ws); in wakeup_source_create()
119 static void wakeup_source_record(struct wakeup_source *ws) in wakeup_source_record() argument
125 if (ws->event_count) { in wakeup_source_record()
127 ktime_add(deleted_ws.total_time, ws->total_time); in wakeup_source_record()
130 ws->prevent_sleep_time); in wakeup_source_record()
132 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ? in wakeup_source_record()
133 deleted_ws.max_time : ws->max_time; in wakeup_source_record()
134 deleted_ws.event_count += ws->event_count; in wakeup_source_record()
135 deleted_ws.active_count += ws->active_count; in wakeup_source_record()
136 deleted_ws.relax_count += ws->relax_count; in wakeup_source_record()
137 deleted_ws.expire_count += ws->expire_count; in wakeup_source_record()
138 deleted_ws.wakeup_count += ws->wakeup_count; in wakeup_source_record()
144 static void wakeup_source_free(struct wakeup_source *ws) in wakeup_source_free() argument
146 ida_free(&wakeup_ida, ws->id); in wakeup_source_free()
147 kfree_const(ws->name); in wakeup_source_free()
148 kfree(ws); in wakeup_source_free()
157 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
159 if (!ws) in wakeup_source_destroy()
162 __pm_relax(ws); in wakeup_source_destroy()
163 wakeup_source_record(ws); in wakeup_source_destroy()
164 wakeup_source_free(ws); in wakeup_source_destroy()
172 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
176 if (WARN_ON(!ws)) in wakeup_source_add()
179 spin_lock_init(&ws->lock); in wakeup_source_add()
180 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); in wakeup_source_add()
181 ws->active = false; in wakeup_source_add()
184 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
193 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
197 if (WARN_ON(!ws)) in wakeup_source_remove()
201 list_del_rcu(&ws->entry); in wakeup_source_remove()
205 del_timer_sync(&ws->timer); in wakeup_source_remove()
210 ws->timer.function = NULL; in wakeup_source_remove()
222 struct wakeup_source *ws; in wakeup_source_register() local
225 ws = wakeup_source_create(name); in wakeup_source_register()
226 if (ws) { in wakeup_source_register()
228 ret = wakeup_source_sysfs_add(dev, ws); in wakeup_source_register()
230 wakeup_source_free(ws); in wakeup_source_register()
234 wakeup_source_add(ws); in wakeup_source_register()
236 return ws; in wakeup_source_register()
244 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
246 if (ws) { in wakeup_source_unregister()
247 wakeup_source_remove(ws); in wakeup_source_unregister()
248 if (ws->dev) in wakeup_source_unregister()
249 wakeup_source_sysfs_remove(ws); in wakeup_source_unregister()
251 wakeup_source_destroy(ws); in wakeup_source_unregister()
301 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws) in wakeup_sources_walk_next() argument
305 return list_next_or_null_rcu(ws_head, &ws->entry, in wakeup_sources_walk_next()
317 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
324 dev->power.wakeup = ws; in device_wakeup_attach()
339 struct wakeup_source *ws; in device_wakeup_enable() local
348 ws = wakeup_source_register(dev, dev_name(dev)); in device_wakeup_enable()
349 if (!ws) in device_wakeup_enable()
352 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
354 wakeup_source_unregister(ws); in device_wakeup_enable()
374 struct wakeup_source *ws; in device_wakeup_attach_irq() local
376 ws = dev->power.wakeup; in device_wakeup_attach_irq()
377 if (!ws) in device_wakeup_attach_irq()
380 if (ws->wakeirq) in device_wakeup_attach_irq()
383 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
396 struct wakeup_source *ws; in device_wakeup_detach_irq() local
398 ws = dev->power.wakeup; in device_wakeup_detach_irq()
399 if (ws) in device_wakeup_detach_irq()
400 ws->wakeirq = NULL; in device_wakeup_detach_irq()
410 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
414 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_arm_wake_irqs()
415 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
426 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
430 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) in device_wakeup_disarm_wake_irqs()
431 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
443 struct wakeup_source *ws; in device_wakeup_detach() local
446 ws = dev->power.wakeup; in device_wakeup_detach()
449 return ws; in device_wakeup_detach()
461 struct wakeup_source *ws; in device_wakeup_disable() local
466 ws = device_wakeup_detach(dev); in device_wakeup_disable()
467 wakeup_source_unregister(ws); in device_wakeup_disable()
518 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
524 return ws->timer.function != pm_wakeup_timer_fn; in wakeup_source_not_registered()
563 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
567 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
571 ws->active = true; in wakeup_source_activate()
572 ws->active_count++; in wakeup_source_activate()
573 ws->last_time = ktime_get(); in wakeup_source_activate()
574 if (ws->autosleep_enabled) in wakeup_source_activate()
575 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
580 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
588 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard) in wakeup_source_report_event() argument
590 ws->event_count++; in wakeup_source_report_event()
593 ws->wakeup_count++; in wakeup_source_report_event()
595 if (!ws->active) in wakeup_source_report_event()
596 wakeup_source_activate(ws); in wakeup_source_report_event()
608 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
612 if (!ws) in __pm_stay_awake()
615 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
617 wakeup_source_report_event(ws, false); in __pm_stay_awake()
618 del_timer(&ws->timer); in __pm_stay_awake()
619 ws->timer_expires = 0; in __pm_stay_awake()
621 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
650 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
652 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
653 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
656 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
668 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
674 ws->relax_count++; in wakeup_source_deactivate()
684 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
685 ws->relax_count--; in wakeup_source_deactivate()
689 ws->active = false; in wakeup_source_deactivate()
692 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
693 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
694 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
695 ws->max_time = duration; in wakeup_source_deactivate()
697 ws->last_time = now; in wakeup_source_deactivate()
698 del_timer(&ws->timer); in wakeup_source_deactivate()
699 ws->timer_expires = 0; in wakeup_source_deactivate()
701 if (ws->autosleep_enabled) in wakeup_source_deactivate()
702 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
709 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
725 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
729 if (!ws) in __pm_relax()
732 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
733 if (ws->active) in __pm_relax()
734 wakeup_source_deactivate(ws); in __pm_relax()
735 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
768 struct wakeup_source *ws = from_timer(ws, t, timer); in pm_wakeup_timer_fn() local
771 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
773 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
774 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
775 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
776 ws->expire_count++; in pm_wakeup_timer_fn()
779 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
795 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) in pm_wakeup_ws_event() argument
800 if (!ws) in pm_wakeup_ws_event()
803 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_ws_event()
805 wakeup_source_report_event(ws, hard); in pm_wakeup_ws_event()
808 wakeup_source_deactivate(ws); in pm_wakeup_ws_event()
816 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in pm_wakeup_ws_event()
817 mod_timer(&ws->timer, expires); in pm_wakeup_ws_event()
818 ws->timer_expires = expires; in pm_wakeup_ws_event()
822 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_ws_event()
849 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
854 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
855 if (ws->active) { in pm_print_active_wakeup_sources()
856 pm_pr_dbg("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
860 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
862 last_activity_ws = ws; in pm_print_active_wakeup_sources()
1029 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
1034 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
1035 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1036 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
1037 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
1038 if (ws->active) { in pm_wakep_autosleep_enabled()
1040 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
1042 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
1045 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
1057 struct wakeup_source *ws) in print_wakeup_source_stats() argument
1066 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
1068 total_time = ws->total_time; in print_wakeup_source_stats()
1069 max_time = ws->max_time; in print_wakeup_source_stats()
1070 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
1071 active_count = ws->active_count; in print_wakeup_source_stats()
1072 if (ws->active) { in print_wakeup_source_stats()
1075 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1080 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1082 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1088 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1089 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1091 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1094 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1102 struct wakeup_source *ws; in wakeup_sources_stats_seq_start() local
1113 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_start()
1115 return ws; in wakeup_sources_stats_seq_start()
1124 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_next() local
1129 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) { in wakeup_sources_stats_seq_next()
1130 next_ws = ws; in wakeup_sources_stats_seq_next()
1154 struct wakeup_source *ws = v; in wakeup_sources_stats_seq_show() local
1156 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_seq_show()