Lines Matching refs:ws
87 struct wakeup_source *ws;
91 ws = kzalloc(sizeof(*ws), GFP_KERNEL);
92 if (!ws)
98 ws->name = ws_name;
103 ws->id = id;
105 return ws;
108 kfree_const(ws->name);
110 kfree(ws);
119 static void wakeup_source_record(struct wakeup_source *ws)
125 if (ws->event_count) {
127 ktime_add(deleted_ws.total_time, ws->total_time);
130 ws->prevent_sleep_time);
132 ktime_compare(deleted_ws.max_time, ws->max_time) > 0 ?
133 deleted_ws.max_time : ws->max_time;
134 deleted_ws.event_count += ws->event_count;
135 deleted_ws.active_count += ws->active_count;
136 deleted_ws.relax_count += ws->relax_count;
137 deleted_ws.expire_count += ws->expire_count;
138 deleted_ws.wakeup_count += ws->wakeup_count;
144 static void wakeup_source_free(struct wakeup_source *ws)
146 ida_free(&wakeup_ida, ws->id);
147 kfree_const(ws->name);
148 kfree(ws);
153 * @ws: Wakeup source to destroy.
157 void wakeup_source_destroy(struct wakeup_source *ws)
159 if (!ws)
162 __pm_relax(ws);
163 wakeup_source_record(ws);
164 wakeup_source_free(ws);
170 * @ws: Wakeup source object to add to the list.
172 void wakeup_source_add(struct wakeup_source *ws)
176 if (WARN_ON(!ws))
179 spin_lock_init(&ws->lock);
180 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
181 ws->active = false;
184 list_add_rcu(&ws->entry, &wakeup_sources);
191 * @ws: Wakeup source object to remove from the list.
193 void wakeup_source_remove(struct wakeup_source *ws)
197 if (WARN_ON(!ws))
201 list_del_rcu(&ws->entry);
205 del_timer_sync(&ws->timer);
210 ws->timer.function = NULL;
222 struct wakeup_source *ws;
225 ws = wakeup_source_create(name);
226 if (ws) {
228 ret = wakeup_source_sysfs_add(dev, ws);
230 wakeup_source_free(ws);
234 wakeup_source_add(ws);
236 return ws;
242 * @ws: Wakeup source object to unregister.
244 void wakeup_source_unregister(struct wakeup_source *ws)
246 if (ws) {
247 wakeup_source_remove(ws);
248 if (ws->dev)
249 wakeup_source_sysfs_remove(ws);
251 wakeup_source_destroy(ws);
296 * @ws: Previous wakeup source object
301 struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws)
305 return list_next_or_null_rcu(ws_head, &ws->entry,
313 * @ws: Wakeup source object to attach to @dev.
317 static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
324 dev->power.wakeup = ws;
339 struct wakeup_source *ws;
348 ws = wakeup_source_register(dev, dev_name(dev));
349 if (!ws)
352 ret = device_wakeup_attach(dev, ws);
354 wakeup_source_unregister(ws);
374 struct wakeup_source *ws;
376 ws = dev->power.wakeup;
377 if (!ws)
380 if (ws->wakeirq)
383 ws->wakeirq = wakeirq;
396 struct wakeup_source *ws;
398 ws = dev->power.wakeup;
399 if (ws)
400 ws->wakeirq = NULL;
410 struct wakeup_source *ws;
414 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry)
415 dev_pm_arm_wake_irq(ws->wakeirq);
426 struct wakeup_source *ws;
430 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry)
431 dev_pm_disarm_wake_irq(ws->wakeirq);
443 struct wakeup_source *ws;
446 ws = dev->power.wakeup;
449 return ws;
461 struct wakeup_source *ws;
466 ws = device_wakeup_detach(dev);
467 wakeup_source_unregister(ws);
545 * @ws: Wakeup source to be validated.
547 static bool wakeup_source_not_registered(struct wakeup_source *ws)
553 return ws->timer.function != pm_wakeup_timer_fn;
586 * @ws: Wakeup source to handle.
588 * Update the @ws' statistics and, if @ws has just been activated, notify the PM
592 static void wakeup_source_activate(struct wakeup_source *ws)
596 if (WARN_ONCE(wakeup_source_not_registered(ws),
600 ws->active = true;
601 ws->active_count++;
602 ws->last_time = ktime_get();
603 if (ws->autosleep_enabled)
604 ws->start_prevent_time = ws->last_time;
609 trace_wakeup_source_activate(ws->name, cec);
614 * @ws: Wakeup source to report the event for.
617 static void wakeup_source_report_event(struct wakeup_source *ws, bool hard)
619 ws->event_count++;
622 ws->wakeup_count++;
624 if (!ws->active)
625 wakeup_source_activate(ws);
633 * @ws: Wakeup source object associated with the source of the event.
637 void __pm_stay_awake(struct wakeup_source *ws)
641 if (!ws)
644 spin_lock_irqsave(&ws->lock, flags);
646 wakeup_source_report_event(ws, false);
647 del_timer(&ws->timer);
648 ws->timer_expires = 0;
650 spin_unlock_irqrestore(&ws->lock, flags);
679 static void update_prevent_sleep_time(struct wakeup_source *ws, ktime_t now)
681 ktime_t delta = ktime_sub(now, ws->start_prevent_time);
682 ws->prevent_sleep_time = ktime_add(ws->prevent_sleep_time, delta);
685 static inline void update_prevent_sleep_time(struct wakeup_source *ws,
691 * @ws: Wakeup source to handle.
693 * Update the @ws' statistics and notify the PM core that the wakeup source has
697 static void wakeup_source_deactivate(struct wakeup_source *ws)
703 ws->relax_count++;
709 * will set ws->active. Then, ws->active may be cleared immediately
711 * case ws->relax_count will be different from ws->active_count.
713 if (ws->relax_count != ws->active_count) {
714 ws->relax_count--;
718 ws->active = false;
721 duration = ktime_sub(now, ws->last_time);
722 ws->total_time = ktime_add(ws->total_time, duration);
723 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time))
724 ws->max_time = duration;
726 ws->last_time = now;
727 del_timer(&ws->timer);
728 ws->timer_expires = 0;
730 if (ws->autosleep_enabled)
731 update_prevent_sleep_time(ws, now);
738 trace_wakeup_source_deactivate(ws->name, cec);
747 * @ws: Wakeup source object associated with the source of the event.
754 void __pm_relax(struct wakeup_source *ws)
758 if (!ws)
761 spin_lock_irqsave(&ws->lock, flags);
762 if (ws->active)
763 wakeup_source_deactivate(ws);
764 spin_unlock_irqrestore(&ws->lock, flags);
797 struct wakeup_source *ws = from_timer(ws, t, timer);
800 spin_lock_irqsave(&ws->lock, flags);
802 if (ws->active && ws->timer_expires
803 && time_after_eq(jiffies, ws->timer_expires)) {
804 wakeup_source_deactivate(ws);
805 ws->expire_count++;
808 spin_unlock_irqrestore(&ws->lock, flags);
813 * @ws: Wakeup source object associated with the event source.
817 * Notify the PM core of a wakeup event whose source is @ws that will take
818 * approximately @msec milliseconds to be processed by the kernel. If @ws is
819 * not active, activate it. If @msec is nonzero, set up the @ws' timer to
824 void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard)
829 if (!ws)
832 spin_lock_irqsave(&ws->lock, flags);
834 wakeup_source_report_event(ws, hard);
837 wakeup_source_deactivate(ws);
845 if (!ws->timer_expires || time_after(expires, ws->timer_expires)) {
846 mod_timer(&ws->timer, expires);
847 ws->timer_expires = expires;
851 spin_unlock_irqrestore(&ws->lock, flags);
878 struct wakeup_source *ws;
883 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
884 if (ws->active) {
885 pm_pr_dbg("active wakeup source: %s\n", ws->name);
889 ktime_to_ns(ws->last_time) >
891 last_activity_ws = ws;
1055 struct wakeup_source *ws;
1060 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
1061 spin_lock_irq(&ws->lock);
1062 if (ws->autosleep_enabled != set) {
1063 ws->autosleep_enabled = set;
1064 if (ws->active) {
1066 ws->start_prevent_time = now;
1068 update_prevent_sleep_time(ws, now);
1071 spin_unlock_irq(&ws->lock);
1080 * @ws: Wakeup source object to print the statistics for.
1083 struct wakeup_source *ws)
1092 spin_lock_irqsave(&ws->lock, flags);
1094 total_time = ws->total_time;
1095 max_time = ws->max_time;
1096 prevent_sleep_time = ws->prevent_sleep_time;
1097 active_count = ws->active_count;
1098 if (ws->active) {
1101 active_time = ktime_sub(now, ws->last_time);
1106 if (ws->autosleep_enabled)
1108 ktime_sub(now, ws->start_prevent_time));
1114 ws->name, active_count, ws->event_count,
1115 ws->wakeup_count, ws->expire_count,
1117 ktime_to_ms(max_time), ktime_to_ms(ws->last_time),
1120 spin_unlock_irqrestore(&ws->lock, flags);
1128 struct wakeup_source *ws;
1139 list_for_each_entry_rcu_locked(ws, &wakeup_sources, entry) {
1141 return ws;
1150 struct wakeup_source *ws = v;
1155 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) {
1156 next_ws = ws;
1180 struct wakeup_source *ws = v;
1182 print_wakeup_source_stats(m, ws);