Lines Matching refs:ws
76 void wakeup_source_prepare(struct wakeup_source *ws, const char *name) in wakeup_source_prepare() argument
78 if (ws) { in wakeup_source_prepare()
79 memset(ws, 0, sizeof(*ws)); in wakeup_source_prepare()
80 ws->name = name; in wakeup_source_prepare()
91 struct wakeup_source *ws; in wakeup_source_create() local
93 ws = kmalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
94 if (!ws) in wakeup_source_create()
97 wakeup_source_prepare(ws, name ? kstrdup_const(name, GFP_KERNEL) : NULL); in wakeup_source_create()
98 return ws; in wakeup_source_create()
109 void wakeup_source_drop(struct wakeup_source *ws) in wakeup_source_drop() argument
111 if (!ws) in wakeup_source_drop()
114 del_timer_sync(&ws->timer); in wakeup_source_drop()
115 __pm_relax(ws); in wakeup_source_drop()
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()
153 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
155 if (!ws) in wakeup_source_destroy()
158 wakeup_source_drop(ws); in wakeup_source_destroy()
159 wakeup_source_record(ws); in wakeup_source_destroy()
160 kfree_const(ws->name); in wakeup_source_destroy()
161 kfree(ws); in wakeup_source_destroy()
169 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
173 if (WARN_ON(!ws)) in wakeup_source_add()
176 spin_lock_init(&ws->lock); in wakeup_source_add()
177 setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws); in wakeup_source_add()
178 ws->active = false; in wakeup_source_add()
179 ws->last_time = ktime_get(); in wakeup_source_add()
182 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
191 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
195 if (WARN_ON(!ws)) in wakeup_source_remove()
199 list_del_rcu(&ws->entry); in wakeup_source_remove()
211 struct wakeup_source *ws; in wakeup_source_register() local
213 ws = wakeup_source_create(name); in wakeup_source_register()
214 if (ws) in wakeup_source_register()
215 wakeup_source_add(ws); in wakeup_source_register()
217 return ws; in wakeup_source_register()
225 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
227 if (ws) { in wakeup_source_unregister()
228 wakeup_source_remove(ws); in wakeup_source_unregister()
229 wakeup_source_destroy(ws); in wakeup_source_unregister()
241 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
248 dev->power.wakeup = ws; in device_wakeup_attach()
261 struct wakeup_source *ws; in device_wakeup_enable() local
267 ws = wakeup_source_register(dev_name(dev)); in device_wakeup_enable()
268 if (!ws) in device_wakeup_enable()
271 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
273 wakeup_source_unregister(ws); in device_wakeup_enable()
293 struct wakeup_source *ws; in device_wakeup_attach_irq() local
295 ws = dev->power.wakeup; in device_wakeup_attach_irq()
296 if (!ws) { in device_wakeup_attach_irq()
301 if (ws->wakeirq) in device_wakeup_attach_irq()
304 ws->wakeirq = wakeirq; in device_wakeup_attach_irq()
318 struct wakeup_source *ws; in device_wakeup_detach_irq() local
320 ws = dev->power.wakeup; in device_wakeup_detach_irq()
321 if (ws) in device_wakeup_detach_irq()
322 ws->wakeirq = NULL; in device_wakeup_detach_irq()
332 struct wakeup_source *ws; in device_wakeup_arm_wake_irqs() local
335 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in device_wakeup_arm_wake_irqs()
336 if (ws->wakeirq) in device_wakeup_arm_wake_irqs()
337 dev_pm_arm_wake_irq(ws->wakeirq); in device_wakeup_arm_wake_irqs()
349 struct wakeup_source *ws; in device_wakeup_disarm_wake_irqs() local
352 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in device_wakeup_disarm_wake_irqs()
353 if (ws->wakeirq) in device_wakeup_disarm_wake_irqs()
354 dev_pm_disarm_wake_irq(ws->wakeirq); in device_wakeup_disarm_wake_irqs()
367 struct wakeup_source *ws; in device_wakeup_detach() local
370 ws = dev->power.wakeup; in device_wakeup_detach()
373 return ws; in device_wakeup_detach()
385 struct wakeup_source *ws; in device_wakeup_disable() local
390 ws = device_wakeup_detach(dev); in device_wakeup_disable()
391 if (ws) in device_wakeup_disable()
392 wakeup_source_unregister(ws); in device_wakeup_disable()
476 static bool wakeup_source_not_registered(struct wakeup_source *ws) in wakeup_source_not_registered() argument
482 return ws->timer.function != pm_wakeup_timer_fn || in wakeup_source_not_registered()
483 ws->timer.data != (unsigned long)ws; in wakeup_source_not_registered()
522 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
526 if (WARN_ONCE(wakeup_source_not_registered(ws), in wakeup_source_activate()
536 ws->active = true; in wakeup_source_activate()
537 ws->active_count++; in wakeup_source_activate()
538 ws->last_time = ktime_get(); in wakeup_source_activate()
539 if (ws->autosleep_enabled) in wakeup_source_activate()
540 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
545 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
552 static void wakeup_source_report_event(struct wakeup_source *ws) in wakeup_source_report_event() argument
554 ws->event_count++; in wakeup_source_report_event()
557 ws->wakeup_count++; in wakeup_source_report_event()
559 if (!ws->active) in wakeup_source_report_event()
560 wakeup_source_activate(ws); in wakeup_source_report_event()
569 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
573 if (!ws) in __pm_stay_awake()
576 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
578 wakeup_source_report_event(ws); in __pm_stay_awake()
579 del_timer(&ws->timer); in __pm_stay_awake()
580 ws->timer_expires = 0; in __pm_stay_awake()
582 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
611 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
613 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
614 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
617 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
629 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
635 ws->relax_count++; in wakeup_source_deactivate()
645 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
646 ws->relax_count--; in wakeup_source_deactivate()
650 ws->active = false; in wakeup_source_deactivate()
653 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
654 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
655 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
656 ws->max_time = duration; in wakeup_source_deactivate()
658 ws->last_time = now; in wakeup_source_deactivate()
659 del_timer(&ws->timer); in wakeup_source_deactivate()
660 ws->timer_expires = 0; in wakeup_source_deactivate()
662 if (ws->autosleep_enabled) in wakeup_source_deactivate()
663 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
670 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
686 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
690 if (!ws) in __pm_relax()
693 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
694 if (ws->active) in __pm_relax()
695 wakeup_source_deactivate(ws); in __pm_relax()
696 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
729 struct wakeup_source *ws = (struct wakeup_source *)data; in pm_wakeup_timer_fn() local
732 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
734 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
735 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
736 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
737 ws->expire_count++; in pm_wakeup_timer_fn()
740 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
755 void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) in __pm_wakeup_event() argument
760 if (!ws) in __pm_wakeup_event()
763 spin_lock_irqsave(&ws->lock, flags); in __pm_wakeup_event()
765 wakeup_source_report_event(ws); in __pm_wakeup_event()
768 wakeup_source_deactivate(ws); in __pm_wakeup_event()
776 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in __pm_wakeup_event()
777 mod_timer(&ws->timer, expires); in __pm_wakeup_event()
778 ws->timer_expires = expires; in __pm_wakeup_event()
782 spin_unlock_irqrestore(&ws->lock, flags); in __pm_wakeup_event()
809 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
814 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
815 if (ws->active) { in pm_print_active_wakeup_sources()
816 pr_info("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
820 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
822 last_activity_ws = ws; in pm_print_active_wakeup_sources()
954 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
958 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
959 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
960 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
961 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
962 if (ws->active) { in pm_wakep_autosleep_enabled()
964 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
966 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
969 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
983 struct wakeup_source *ws) in print_wakeup_source_stats() argument
992 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
994 total_time = ws->total_time; in print_wakeup_source_stats()
995 max_time = ws->max_time; in print_wakeup_source_stats()
996 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
997 active_count = ws->active_count; in print_wakeup_source_stats()
998 if (ws->active) { in print_wakeup_source_stats()
1001 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
1006 if (ws->autosleep_enabled) in print_wakeup_source_stats()
1008 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
1014 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
1015 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
1017 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
1020 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
1031 struct wakeup_source *ws; in wakeup_sources_stats_show() local
1038 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in wakeup_sources_stats_show()
1039 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_show()