Lines Matching refs:ws
67 void wakeup_source_prepare(struct wakeup_source *ws, const char *name) in wakeup_source_prepare() argument
69 if (ws) { in wakeup_source_prepare()
70 memset(ws, 0, sizeof(*ws)); in wakeup_source_prepare()
71 ws->name = name; in wakeup_source_prepare()
82 struct wakeup_source *ws; in wakeup_source_create() local
84 ws = kmalloc(sizeof(*ws), GFP_KERNEL); in wakeup_source_create()
85 if (!ws) in wakeup_source_create()
88 wakeup_source_prepare(ws, name ? kstrdup(name, GFP_KERNEL) : NULL); in wakeup_source_create()
89 return ws; in wakeup_source_create()
100 void wakeup_source_drop(struct wakeup_source *ws) in wakeup_source_drop() argument
102 if (!ws) in wakeup_source_drop()
105 del_timer_sync(&ws->timer); in wakeup_source_drop()
106 __pm_relax(ws); in wakeup_source_drop()
116 void wakeup_source_destroy(struct wakeup_source *ws) in wakeup_source_destroy() argument
118 if (!ws) in wakeup_source_destroy()
121 wakeup_source_drop(ws); in wakeup_source_destroy()
122 kfree(ws->name); in wakeup_source_destroy()
123 kfree(ws); in wakeup_source_destroy()
131 void wakeup_source_add(struct wakeup_source *ws) in wakeup_source_add() argument
135 if (WARN_ON(!ws)) in wakeup_source_add()
138 spin_lock_init(&ws->lock); in wakeup_source_add()
139 setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws); in wakeup_source_add()
140 ws->active = false; in wakeup_source_add()
141 ws->last_time = ktime_get(); in wakeup_source_add()
144 list_add_rcu(&ws->entry, &wakeup_sources); in wakeup_source_add()
153 void wakeup_source_remove(struct wakeup_source *ws) in wakeup_source_remove() argument
157 if (WARN_ON(!ws)) in wakeup_source_remove()
161 list_del_rcu(&ws->entry); in wakeup_source_remove()
173 struct wakeup_source *ws; in wakeup_source_register() local
175 ws = wakeup_source_create(name); in wakeup_source_register()
176 if (ws) in wakeup_source_register()
177 wakeup_source_add(ws); in wakeup_source_register()
179 return ws; in wakeup_source_register()
187 void wakeup_source_unregister(struct wakeup_source *ws) in wakeup_source_unregister() argument
189 if (ws) { in wakeup_source_unregister()
190 wakeup_source_remove(ws); in wakeup_source_unregister()
191 wakeup_source_destroy(ws); in wakeup_source_unregister()
203 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws) in device_wakeup_attach() argument
210 dev->power.wakeup = ws; in device_wakeup_attach()
223 struct wakeup_source *ws; in device_wakeup_enable() local
229 ws = wakeup_source_register(dev_name(dev)); in device_wakeup_enable()
230 if (!ws) in device_wakeup_enable()
233 ret = device_wakeup_attach(dev, ws); in device_wakeup_enable()
235 wakeup_source_unregister(ws); in device_wakeup_enable()
249 struct wakeup_source *ws; in device_wakeup_detach() local
252 ws = dev->power.wakeup; in device_wakeup_detach()
255 return ws; in device_wakeup_detach()
267 struct wakeup_source *ws; in device_wakeup_disable() local
272 ws = device_wakeup_detach(dev); in device_wakeup_disable()
273 if (ws) in device_wakeup_disable()
274 wakeup_source_unregister(ws); in device_wakeup_disable()
390 static void wakeup_source_activate(struct wakeup_source *ws) in wakeup_source_activate() argument
400 ws->active = true; in wakeup_source_activate()
401 ws->active_count++; in wakeup_source_activate()
402 ws->last_time = ktime_get(); in wakeup_source_activate()
403 if (ws->autosleep_enabled) in wakeup_source_activate()
404 ws->start_prevent_time = ws->last_time; in wakeup_source_activate()
409 trace_wakeup_source_activate(ws->name, cec); in wakeup_source_activate()
416 static void wakeup_source_report_event(struct wakeup_source *ws) in wakeup_source_report_event() argument
418 ws->event_count++; in wakeup_source_report_event()
421 ws->wakeup_count++; in wakeup_source_report_event()
423 if (!ws->active) in wakeup_source_report_event()
424 wakeup_source_activate(ws); in wakeup_source_report_event()
433 void __pm_stay_awake(struct wakeup_source *ws) in __pm_stay_awake() argument
437 if (!ws) in __pm_stay_awake()
440 spin_lock_irqsave(&ws->lock, flags); in __pm_stay_awake()
442 wakeup_source_report_event(ws); in __pm_stay_awake()
443 del_timer(&ws->timer); in __pm_stay_awake()
444 ws->timer_expires = 0; in __pm_stay_awake()
446 spin_unlock_irqrestore(&ws->lock, flags); in __pm_stay_awake()
475 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now) in update_prevent_sleep_time() argument
477 ktime_t delta = ktime_sub(now, ws->start_prevent_time); in update_prevent_sleep_time()
478 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta); in update_prevent_sleep_time()
481 static inline void update_prevent_sleep_time(struct wakeup_source *ws, in update_prevent_sleep_time() argument
493 static void wakeup_source_deactivate(struct wakeup_source *ws) in wakeup_source_deactivate() argument
499 ws->relax_count++; in wakeup_source_deactivate()
509 if (ws->relax_count != ws->active_count) { in wakeup_source_deactivate()
510 ws->relax_count--; in wakeup_source_deactivate()
514 ws->active = false; in wakeup_source_deactivate()
517 duration = ktime_sub(now, ws->last_time); in wakeup_source_deactivate()
518 ws->total_time = ktime_add(ws->total_time, duration); in wakeup_source_deactivate()
519 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time)) in wakeup_source_deactivate()
520 ws->max_time = duration; in wakeup_source_deactivate()
522 ws->last_time = now; in wakeup_source_deactivate()
523 del_timer(&ws->timer); in wakeup_source_deactivate()
524 ws->timer_expires = 0; in wakeup_source_deactivate()
526 if (ws->autosleep_enabled) in wakeup_source_deactivate()
527 update_prevent_sleep_time(ws, now); in wakeup_source_deactivate()
534 trace_wakeup_source_deactivate(ws->name, cec); in wakeup_source_deactivate()
550 void __pm_relax(struct wakeup_source *ws) in __pm_relax() argument
554 if (!ws) in __pm_relax()
557 spin_lock_irqsave(&ws->lock, flags); in __pm_relax()
558 if (ws->active) in __pm_relax()
559 wakeup_source_deactivate(ws); in __pm_relax()
560 spin_unlock_irqrestore(&ws->lock, flags); in __pm_relax()
593 struct wakeup_source *ws = (struct wakeup_source *)data; in pm_wakeup_timer_fn() local
596 spin_lock_irqsave(&ws->lock, flags); in pm_wakeup_timer_fn()
598 if (ws->active && ws->timer_expires in pm_wakeup_timer_fn()
599 && time_after_eq(jiffies, ws->timer_expires)) { in pm_wakeup_timer_fn()
600 wakeup_source_deactivate(ws); in pm_wakeup_timer_fn()
601 ws->expire_count++; in pm_wakeup_timer_fn()
604 spin_unlock_irqrestore(&ws->lock, flags); in pm_wakeup_timer_fn()
619 void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) in __pm_wakeup_event() argument
624 if (!ws) in __pm_wakeup_event()
627 spin_lock_irqsave(&ws->lock, flags); in __pm_wakeup_event()
629 wakeup_source_report_event(ws); in __pm_wakeup_event()
632 wakeup_source_deactivate(ws); in __pm_wakeup_event()
640 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) { in __pm_wakeup_event()
641 mod_timer(&ws->timer, expires); in __pm_wakeup_event()
642 ws->timer_expires = expires; in __pm_wakeup_event()
646 spin_unlock_irqrestore(&ws->lock, flags); in __pm_wakeup_event()
673 struct wakeup_source *ws; in pm_print_active_wakeup_sources() local
678 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_print_active_wakeup_sources()
679 if (ws->active) { in pm_print_active_wakeup_sources()
680 pr_info("active wakeup source: %s\n", ws->name); in pm_print_active_wakeup_sources()
684 ktime_to_ns(ws->last_time) > in pm_print_active_wakeup_sources()
686 last_activity_ws = ws; in pm_print_active_wakeup_sources()
809 struct wakeup_source *ws; in pm_wakep_autosleep_enabled() local
813 list_for_each_entry_rcu(ws, &wakeup_sources, entry) { in pm_wakep_autosleep_enabled()
814 spin_lock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
815 if (ws->autosleep_enabled != set) { in pm_wakep_autosleep_enabled()
816 ws->autosleep_enabled = set; in pm_wakep_autosleep_enabled()
817 if (ws->active) { in pm_wakep_autosleep_enabled()
819 ws->start_prevent_time = now; in pm_wakep_autosleep_enabled()
821 update_prevent_sleep_time(ws, now); in pm_wakep_autosleep_enabled()
824 spin_unlock_irq(&ws->lock); in pm_wakep_autosleep_enabled()
838 struct wakeup_source *ws) in print_wakeup_source_stats() argument
847 spin_lock_irqsave(&ws->lock, flags); in print_wakeup_source_stats()
849 total_time = ws->total_time; in print_wakeup_source_stats()
850 max_time = ws->max_time; in print_wakeup_source_stats()
851 prevent_sleep_time = ws->prevent_sleep_time; in print_wakeup_source_stats()
852 active_count = ws->active_count; in print_wakeup_source_stats()
853 if (ws->active) { in print_wakeup_source_stats()
856 active_time = ktime_sub(now, ws->last_time); in print_wakeup_source_stats()
861 if (ws->autosleep_enabled) in print_wakeup_source_stats()
863 ktime_sub(now, ws->start_prevent_time)); in print_wakeup_source_stats()
869 ws->name, active_count, ws->event_count, in print_wakeup_source_stats()
870 ws->wakeup_count, ws->expire_count, in print_wakeup_source_stats()
872 ktime_to_ms(max_time), ktime_to_ms(ws->last_time), in print_wakeup_source_stats()
875 spin_unlock_irqrestore(&ws->lock, flags); in print_wakeup_source_stats()
886 struct wakeup_source *ws; in wakeup_sources_stats_show() local
893 list_for_each_entry_rcu(ws, &wakeup_sources, entry) in wakeup_sources_stats_show()
894 print_wakeup_source_stats(m, ws); in wakeup_sources_stats_show()