Lines Matching refs:ws

82 	struct wakeup_source *ws;
86 ws = kzalloc(sizeof(*ws), GFP_KERNEL);
87 if (!ws)
93 ws->name = ws_name;
98 ws->id = id;
100 return ws;
103 kfree_const(ws->name);
105 kfree(ws);
114 static void wakeup_source_record(struct wakeup_source *ws)
120 if (ws->event_count) {
122 ktime_add(deleted_ws.total_time, ws->total_time);
125 ws->prevent_sleep_time);
127 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ?
128 deleted_ws.max_time : ws->max_time;
129 deleted_ws.event_count += ws->event_count;
130 deleted_ws.active_count += ws->active_count;
131 deleted_ws.relax_count += ws->relax_count;
132 deleted_ws.expire_count += ws->expire_count;
133 deleted_ws.wakeup_count += ws->wakeup_count;
139 static void wakeup_source_free(struct wakeup_source *ws)
141 ida_free(&wakeup_ida, ws->id);
142 kfree_const(ws->name);
143 kfree(ws);
148 * @ws: Wakeup source to destroy.
152 void wakeup_source_destroy(struct wakeup_source *ws)
154 if (!ws)
157 __pm_relax(ws);
158 wakeup_source_record(ws);
159 wakeup_source_free(ws);
165 * @ws: Wakeup source object to add to the list.
167 void wakeup_source_add(struct wakeup_source *ws)
171 if (WARN_ON(!ws))
174 spin_lock_init(&ws->lock);
175 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
176 ws->active = false;
179 list_add_rcu(&ws->entry, &wakeup_sources);
186 * @ws: Wakeup source object to remove from the list.
188 void wakeup_source_remove(struct wakeup_source *ws)
192 if (WARN_ON(!ws))
196 list_del_rcu(&ws->entry);
200 del_timer_sync(&ws->timer);
205 ws->timer.function = NULL;
217 struct wakeup_source *ws;
220 ws = wakeup_source_create(name);
221 if (ws) {
223 ret = wakeup_source_sysfs_add(dev, ws);
225 wakeup_source_free(ws);
229 wakeup_source_add(ws);
231 return ws;
237 * @ws: Wakeup source object to unregister.
239 void wakeup_source_unregister(struct wakeup_source *ws)
241 if (ws) {
242 wakeup_source_remove(ws);
243 if (ws->dev)
244 wakeup_source_sysfs_remove(ws);
246 wakeup_source_destroy(ws);
291 * @ws: Previous wakeup source object
296 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws)
300 return list_next_or_null_rcu(ws_head, &ws->entry,
308 * @ws: Wakeup source object to attach to @dev.
312 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
319 dev->power.wakeup = ws;
334 struct wakeup_source *ws;
343 ws = wakeup_source_register(dev, dev_name(dev));
344 if (!ws)
347 ret = device_wakeup_attach(dev, ws);
349 wakeup_source_unregister(ws);
369 struct wakeup_source *ws;
371 ws = dev->power.wakeup;
372 if (!ws)
375 if (ws->wakeirq)
378 ws->wakeirq = wakeirq;
391 struct wakeup_source *ws;
393 ws = dev->power.wakeup;
394 if (ws)
395 ws->wakeirq = NULL;
405 struct wakeup_source *ws;
409 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry)
410 dev_pm_arm_wake_irq(ws->wakeirq);
421 struct wakeup_source *ws;
425 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry)
426 dev_pm_disarm_wake_irq(ws->wakeirq);
438 struct wakeup_source *ws;
441 ws = dev->power.wakeup;
444 return ws;
456 struct wakeup_source *ws;
461 ws = device_wakeup_detach(dev);
462 wakeup_source_unregister(ws);
511 * @ws: Wakeup source to be validated.
513 static bool wakeup_source_not_registered(struct wakeup_source *ws)
519 return ws->timer.function != pm_wakeup_timer_fn;
552 * @ws: Wakeup source to handle.
554 * Update the @ws' statistics and, if @ws has just been activated, notify the PM
558 static void wakeup_source_activate(struct wakeup_source *ws)
562 if (WARN_ONCE(wakeup_source_not_registered(ws),
566 ws->active = true;
567 ws->active_count++;
568 ws->last_time = ktime_get();
569 if (ws->autosleep_enabled)
570 ws->start_prevent_time = ws->last_time;
575 trace_wakeup_source_activate(ws->name, cec);
580 * @ws: Wakeup source to report the event for.
583 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard)
585 ws->event_count++;
588 ws->wakeup_count++;
590 if (!ws->active)
591 wakeup_source_activate(ws);
599 * @ws: Wakeup source object associated with the source of the event.
603 void __pm_stay_awake(struct wakeup_source *ws)
607 if (!ws)
610 spin_lock_irqsave(&ws->lock, flags);
612 wakeup_source_report_event(ws, false);
613 del_timer(&ws->timer);
614 ws->timer_expires = 0;
616 spin_unlock_irqrestore(&ws->lock, flags);
645 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now)
647 ktime_t delta = ktime_sub(now, ws->start_prevent_time);
648 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta);
651 static inline void update_prevent_sleep_time(struct wakeup_source *ws,
657 * @ws: Wakeup source to handle.
659 * Update the @ws' statistics and notify the PM core that the wakeup source has
663 static void wakeup_source_deactivate(struct wakeup_source *ws)
669 ws->relax_count++;
675 * will set ws->active. Then, ws->active may be cleared immediately
677 * case ws->relax_count will be different from ws->active_count.
679 if (ws->relax_count != ws->active_count) {
680 ws->relax_count--;
684 ws->active = false;
687 duration = ktime_sub(now, ws->last_time);
688 ws->total_time = ktime_add(ws->total_time, duration);
689 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time))
690 ws->max_time = duration;
692 ws->last_time = now;
693 del_timer(&ws->timer);
694 ws->timer_expires = 0;
696 if (ws->autosleep_enabled)
697 update_prevent_sleep_time(ws, now);
704 trace_wakeup_source_deactivate(ws->name, cec);
713 * @ws: Wakeup source object associated with the source of the event.
720 void __pm_relax(struct wakeup_source *ws)
724 if (!ws)
727 spin_lock_irqsave(&ws->lock, flags);
728 if (ws->active)
729 wakeup_source_deactivate(ws);
730 spin_unlock_irqrestore(&ws->lock, flags);
763 struct wakeup_source *ws = from_timer(ws, t, timer);
766 spin_lock_irqsave(&ws->lock, flags);
768 if (ws->active && ws->timer_expires
769 && time_after_eq(jiffies, ws->timer_expires)) {
770 wakeup_source_deactivate(ws);
771 ws->expire_count++;
774 spin_unlock_irqrestore(&ws->lock, flags);
779 * @ws: Wakeup source object associated with the event source.
783 * Notify the PM core of a wakeup event whose source is @ws that will take
784 * approximately @msec milliseconds to be processed by the kernel. If @ws is
785 * not active, activate it. If @msec is nonzero, set up the @ws' timer to
790 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard)
795 if (!ws)
798 spin_lock_irqsave(&ws->lock, flags);
800 wakeup_source_report_event(ws, hard);
803 wakeup_source_deactivate(ws);
811 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) {
812 mod_timer(&ws->timer, expires);
813 ws->timer_expires = expires;
817 spin_unlock_irqrestore(&ws->lock, flags);
844 struct wakeup_source *ws;
849 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
850 if (ws->active) {
851 pm_pr_dbg("active wakeup source: %s\n", ws->name);
855 ktime_to_ns(ws->last_time) >
857 last_activity_ws = ws;
1024 struct wakeup_source *ws;
1029 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
1030 spin_lock_irq(&ws->lock);
1031 if (ws->autosleep_enabled != set) {
1032 ws->autosleep_enabled = set;
1033 if (ws->active) {
1035 ws->start_prevent_time = now;
1037 update_prevent_sleep_time(ws, now);
1040 spin_unlock_irq(&ws->lock);
1049 * @ws: Wakeup source object to print the statistics for.
1052 struct wakeup_source *ws)
1061 spin_lock_irqsave(&ws->lock, flags);
1063 total_time = ws->total_time;
1064 max_time = ws->max_time;
1065 prevent_sleep_time = ws->prevent_sleep_time;
1066 active_count = ws->active_count;
1067 if (ws->active) {
1070 active_time = ktime_sub(now, ws->last_time);
1075 if (ws->autosleep_enabled)
1077 ktime_sub(now, ws->start_prevent_time));
1083 ws->name, active_count, ws->event_count,
1084 ws->wakeup_count, ws->expire_count,
1086 ktime_to_ms(max_time), ktime_to_ms(ws->last_time),
1089 spin_unlock_irqrestore(&ws->lock, flags);
1097 struct wakeup_source *ws;
1108 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
1110 return ws;
1119 struct wakeup_source *ws = v;
1124 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) {
1125 next_ws = ws;
1149 struct wakeup_source *ws = v;
1151 print_wakeup_source_stats(m, ws);