blob: 596bf9f284e56d0ee9663d6d7bb327ba6d3eb85e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kernel/power/main.c - PM subsystem core functionality.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
Nick Reuterb8678b32018-08-30 02:53:55 -05006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This file is released under the GPLv2
8 *
9 */
10
Paul Gortmaker6e5fdee2011-05-26 16:00:52 -040011#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/kobject.h>
13#include <linux/string.h>
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -070014#include <linux/resume-trace.h>
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020015#include <linux/workqueue.h>
Nick Reuterb8678b32018-08-30 02:53:55 -050016#include <linux/debugfs.h>
17#include <linux/seq_file.h>
18#include <linux/hrtimer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include "power.h"
Nick Reuterb8678b32018-08-30 02:53:55 -050021
22#define MAX_BUF 100
Amar Singhalac2a6d62012-02-27 17:40:31 -080023
Stephen Hemmingera6d70982006-12-06 20:34:35 -080024DEFINE_MUTEX(pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Rafael J. Wysockicd51e612011-02-11 00:04:52 +010026#ifdef CONFIG_PM_SLEEP
27
Alan Stern82525752007-11-19 23:49:18 +010028/* Routines for PM-transition notifications */
29
30static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
31
Nick Reuterb8678b32018-08-30 02:53:55 -050032static void touch_event_fn(struct work_struct *work);
33static DECLARE_WORK(touch_event_struct, touch_event_fn);
34
35static struct hrtimer tc_ev_timer;
36static int tc_ev_processed;
37static ktime_t touch_evt_timer_val;
38
Alan Stern82525752007-11-19 23:49:18 +010039int register_pm_notifier(struct notifier_block *nb)
40{
41 return blocking_notifier_chain_register(&pm_chain_head, nb);
42}
43EXPORT_SYMBOL_GPL(register_pm_notifier);
44
45int unregister_pm_notifier(struct notifier_block *nb)
46{
47 return blocking_notifier_chain_unregister(&pm_chain_head, nb);
48}
49EXPORT_SYMBOL_GPL(unregister_pm_notifier);
50
51int pm_notifier_call_chain(unsigned long val)
52{
Nick Reuterb8678b32018-08-30 02:53:55 -050053 int ret = blocking_notifier_call_chain(&pm_chain_head, val, NULL);
54
55 return notifier_to_errno(ret);
Alan Stern82525752007-11-19 23:49:18 +010056}
57
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +010058/* If set, devices may be suspended and resumed asynchronously. */
59int pm_async_enabled = 1;
60
61static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
62 char *buf)
63{
64 return sprintf(buf, "%d\n", pm_async_enabled);
65}
66
67static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
68 const char *buf, size_t n)
69{
70 unsigned long val;
71
72 if (strict_strtoul(buf, 10, &val))
73 return -EINVAL;
74
75 if (val > 1)
76 return -EINVAL;
77
78 pm_async_enabled = val;
79 return n;
80}
81
82power_attr(pm_async);
83
Nick Reuterb8678b32018-08-30 02:53:55 -050084static ssize_t
85touch_event_show(struct kobject *kobj,
86 struct kobj_attribute *attr, char *buf)
87{
88 if (tc_ev_processed == 0)
89 return snprintf(buf, strnlen("touch_event", MAX_BUF) + 1,
90 "touch_event");
91 else
92 return snprintf(buf, strnlen("null", MAX_BUF) + 1,
93 "null");
94}
95
96static ssize_t
97touch_event_store(struct kobject *kobj,
98 struct kobj_attribute *attr,
99 const char *buf, size_t n)
100{
101
102 hrtimer_cancel(&tc_ev_timer);
103 tc_ev_processed = 0;
104
105 /* set a timer to notify the userspace to stop processing
106 * touch event
107 */
108 hrtimer_start(&tc_ev_timer, touch_evt_timer_val, HRTIMER_MODE_REL);
109
110 /* wakeup the userspace poll */
111 sysfs_notify(kobj, NULL, "touch_event");
112
113 return n;
114}
115
116power_attr(touch_event);
117
118static ssize_t
119touch_event_timer_show(struct kobject *kobj,
120 struct kobj_attribute *attr, char *buf)
121{
122 return snprintf(buf, MAX_BUF, "%lld", touch_evt_timer_val.tv64);
123}
124
125static ssize_t
126touch_event_timer_store(struct kobject *kobj,
127 struct kobj_attribute *attr,
128 const char *buf, size_t n)
129{
130 unsigned long val;
131
132 if (strict_strtoul(buf, 10, &val))
133 return -EINVAL;
134
135 touch_evt_timer_val = ktime_set(0, val*1000);
136
137 return n;
138}
139
140power_attr(touch_event_timer);
141
142static void touch_event_fn(struct work_struct *work)
143{
144 /* wakeup the userspace poll */
145 tc_ev_processed = 1;
146 sysfs_notify(power_kobj, NULL, "touch_event");
147
148 return;
149}
150
151static enum hrtimer_restart tc_ev_stop(struct hrtimer *hrtimer)
152{
153
154 schedule_work(&touch_event_struct);
155
156 return HRTIMER_NORESTART;
157}
158
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100159#ifdef CONFIG_PM_DEBUG
160int pm_test_level = TEST_NONE;
161
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100162static const char * const pm_tests[__TEST_AFTER_LAST] = {
163 [TEST_NONE] = "none",
164 [TEST_CORE] = "core",
165 [TEST_CPUS] = "processors",
166 [TEST_PLATFORM] = "platform",
167 [TEST_DEVICES] = "devices",
168 [TEST_FREEZER] = "freezer",
169};
170
Rafael J. Wysocki039a75c2008-01-29 00:29:06 +0100171static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr,
172 char *buf)
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100173{
174 char *s = buf;
175 int level;
176
177 for (level = TEST_FIRST; level <= TEST_MAX; level++)
178 if (pm_tests[level]) {
179 if (level == pm_test_level)
180 s += sprintf(s, "[%s] ", pm_tests[level]);
181 else
182 s += sprintf(s, "%s ", pm_tests[level]);
183 }
184
185 if (s != buf)
186 /* convert the last space to a newline */
187 *(s-1) = '\n';
188
189 return (s - buf);
190}
191
Rafael J. Wysocki039a75c2008-01-29 00:29:06 +0100192static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
193 const char *buf, size_t n)
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100194{
195 const char * const *s;
196 int level;
197 char *p;
198 int len;
199 int error = -EINVAL;
200
201 p = memchr(buf, '\n', n);
202 len = p ? p - buf : n;
203
Nick Reuterb8678b32018-08-30 02:53:55 -0500204 lock_system_sleep();
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100205
206 level = TEST_FIRST;
207 for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
208 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
209 pm_test_level = level;
210 error = 0;
211 break;
212 }
213
Nick Reuterb8678b32018-08-30 02:53:55 -0500214 unlock_system_sleep();
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100215
216 return error ? error : n;
217}
218
219power_attr(pm_test);
Rafael J. Wysocki091d71e2009-01-17 00:10:45 +0100220#endif /* CONFIG_PM_DEBUG */
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100221
Nick Reuterb8678b32018-08-30 02:53:55 -0500222#ifdef CONFIG_DEBUG_FS
223static char *suspend_step_name(enum suspend_stat_step step)
224{
225 switch (step) {
226 case SUSPEND_FREEZE:
227 return "freeze";
228 case SUSPEND_PREPARE:
229 return "prepare";
230 case SUSPEND_SUSPEND:
231 return "suspend";
232 case SUSPEND_SUSPEND_NOIRQ:
233 return "suspend_noirq";
234 case SUSPEND_RESUME_NOIRQ:
235 return "resume_noirq";
236 case SUSPEND_RESUME:
237 return "resume";
238 default:
239 return "";
240 }
241}
242
243static int suspend_stats_show(struct seq_file *s, void *unused)
244{
245 int i, index, last_dev, last_errno, last_step;
246
247 last_dev = suspend_stats.last_failed_dev + REC_FAILED_NUM - 1;
248 last_dev %= REC_FAILED_NUM;
249 last_errno = suspend_stats.last_failed_errno + REC_FAILED_NUM - 1;
250 last_errno %= REC_FAILED_NUM;
251 last_step = suspend_stats.last_failed_step + REC_FAILED_NUM - 1;
252 last_step %= REC_FAILED_NUM;
253 seq_printf(s, "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n"
254 "%s: %d\n%s: %d\n%s: %d\n%s: %d\n%s: %d\n",
255 "success", suspend_stats.success,
256 "fail", suspend_stats.fail,
257 "failed_freeze", suspend_stats.failed_freeze,
258 "failed_prepare", suspend_stats.failed_prepare,
259 "failed_suspend", suspend_stats.failed_suspend,
260 "failed_suspend_late",
261 suspend_stats.failed_suspend_late,
262 "failed_suspend_noirq",
263 suspend_stats.failed_suspend_noirq,
264 "failed_resume", suspend_stats.failed_resume,
265 "failed_resume_early",
266 suspend_stats.failed_resume_early,
267 "failed_resume_noirq",
268 suspend_stats.failed_resume_noirq);
269 seq_printf(s, "failures:\n last_failed_dev:\t%-s\n",
270 suspend_stats.failed_devs[last_dev]);
271 for (i = 1; i < REC_FAILED_NUM; i++) {
272 index = last_dev + REC_FAILED_NUM - i;
273 index %= REC_FAILED_NUM;
274 seq_printf(s, "\t\t\t%-s\n",
275 suspend_stats.failed_devs[index]);
276 }
277 seq_printf(s, " last_failed_errno:\t%-d\n",
278 suspend_stats.errno[last_errno]);
279 for (i = 1; i < REC_FAILED_NUM; i++) {
280 index = last_errno + REC_FAILED_NUM - i;
281 index %= REC_FAILED_NUM;
282 seq_printf(s, "\t\t\t%-d\n",
283 suspend_stats.errno[index]);
284 }
285 seq_printf(s, " last_failed_step:\t%-s\n",
286 suspend_step_name(
287 suspend_stats.failed_steps[last_step]));
288 for (i = 1; i < REC_FAILED_NUM; i++) {
289 index = last_step + REC_FAILED_NUM - i;
290 index %= REC_FAILED_NUM;
291 seq_printf(s, "\t\t\t%-s\n",
292 suspend_step_name(
293 suspend_stats.failed_steps[index]));
294 }
295
296 return 0;
297}
298
299static int suspend_stats_open(struct inode *inode, struct file *file)
300{
301 return single_open(file, suspend_stats_show, NULL);
302}
303
304static const struct file_operations suspend_stats_operations = {
305 .open = suspend_stats_open,
306 .read = seq_read,
307 .llseek = seq_lseek,
308 .release = single_release,
309};
310
311static int __init pm_debugfs_init(void)
312{
313 debugfs_create_file("suspend_stats", S_IFREG | S_IRUGO,
314 NULL, NULL, &suspend_stats_operations);
315 return 0;
316}
317
318late_initcall(pm_debugfs_init);
319#endif /* CONFIG_DEBUG_FS */
320
Rafael J. Wysockica123102011-08-11 22:38:12 +0200321#endif /* CONFIG_PM_SLEEP */
322
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800323struct kobject *power_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325/**
326 * state - control system power state.
327 *
328 * show() returns what states are supported, which is hard-coded to
329 * 'standby' (Power-On Suspend), 'mem' (Suspend-to-RAM), and
330 * 'disk' (Suspend-to-Disk).
331 *
Nick Reuterb8678b32018-08-30 02:53:55 -0500332 * store() accepts one of those strings, translates it into the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 * proper enumerated value, and initiates a suspend transition.
334 */
Kay Sievers386f2752007-11-02 13:47:53 +0100335static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
336 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200338 char *s = buf;
339#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 for (i = 0; i < PM_SUSPEND_MAX; i++) {
Pavel Machek123d3c12005-11-29 19:34:37 -0800343 if (pm_states[i] && valid_state(i))
344 s += sprintf(s,"%s ", pm_states[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200346#endif
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200347#ifdef CONFIG_HIBERNATION
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700348 s += sprintf(s, "%s\n", "disk");
349#else
350 if (s != buf)
351 /* convert the last space to a newline */
352 *(s-1) = '\n';
353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return (s - buf);
355}
356
Kay Sievers386f2752007-11-02 13:47:53 +0100357static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
358 const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200360#ifdef CONFIG_SUSPEND
Arve Hjønnevågb0dc3432008-10-09 19:17:11 -0700361#ifdef CONFIG_EARLYSUSPEND
362 suspend_state_t state = PM_SUSPEND_ON;
363#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 suspend_state_t state = PM_SUSPEND_STANDBY;
Arve Hjønnevågb0dc3432008-10-09 19:17:11 -0700365#endif
Andreas Mohr3b364b82006-06-25 05:47:56 -0700366 const char * const *s;
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200367#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 int len;
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200370 int error = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 p = memchr(buf, '\n', n);
373 len = p ? p - buf : n;
374
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700375 /* First, check if we are requested to hibernate */
Rafael J. Wysocki8d98a692007-05-16 22:11:19 -0700376 if (len == 4 && !strncmp(buf, "disk", len)) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700377 error = hibernate();
Nick Reuterb8678b32018-08-30 02:53:55 -0500378 goto Exit;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700379 }
380
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200381#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
Nick Reuterb8678b32018-08-30 02:53:55 -0500383 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
shumash17b94be2016-01-10 16:44:51 -0700384#ifdef CONFIG_EARLYSUSPEND
Nick Reuterb8678b32018-08-30 02:53:55 -0500385 if (state == PM_SUSPEND_ON || valid_state(state)) {
386 error = 0;
387 request_suspend_state(state);
388 break;
389 }
shumash17b94be2016-01-10 16:44:51 -0700390#else
Nick Reuterb8678b32018-08-30 02:53:55 -0500391 error = pm_suspend(state);
shumash17b94be2016-01-10 16:44:51 -0700392#endif
Nick Reuterb8678b32018-08-30 02:53:55 -0500393 }
394 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200395#endif
396
397 Exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return error ? error : n;
399}
400
401power_attr(state);
402
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200403#ifdef CONFIG_PM_SLEEP
404/*
405 * The 'wakeup_count' attribute, along with the functions defined in
406 * drivers/base/power/wakeup.c, provides a means by which wakeup events can be
407 * handled in a non-racy way.
408 *
409 * If a wakeup event occurs when the system is in a sleep state, it simply is
410 * woken up. In turn, if an event that would wake the system up from a sleep
411 * state occurs when it is undergoing a transition to that sleep state, the
412 * transition should be aborted. Moreover, if such an event occurs when the
413 * system is in the working state, an attempt to start a transition to the
414 * given sleep state should fail during certain period after the detection of
415 * the event. Using the 'state' attribute alone is not sufficient to satisfy
416 * these requirements, because a wakeup event may occur exactly when 'state'
417 * is being written to and may be delivered to user space right before it is
418 * frozen, so the event will remain only partially processed until the system is
419 * woken up by another event. In particular, it won't cause the transition to
420 * a sleep state to be aborted.
421 *
422 * This difficulty may be overcome if user space uses 'wakeup_count' before
423 * writing to 'state'. It first should read from 'wakeup_count' and store
424 * the read value. Then, after carrying out its own preparations for the system
425 * transition to a sleep state, it should write the stored value to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300426 * 'wakeup_count'. If that fails, at least one wakeup event has occurred since
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200427 * 'wakeup_count' was read and 'state' should not be written to. Otherwise, it
428 * is allowed to write to 'state', but the transition will be aborted if there
429 * are any wakeup events detected after 'wakeup_count' was written to.
430 */
431
432static ssize_t wakeup_count_show(struct kobject *kobj,
433 struct kobj_attribute *attr,
434 char *buf)
435{
Rafael J. Wysocki074037e2010-09-22 22:09:10 +0200436 unsigned int val;
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200437
Rafael J. Wysocki074037e2010-09-22 22:09:10 +0200438 return pm_get_wakeup_count(&val) ? sprintf(buf, "%u\n", val) : -EINTR;
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200439}
440
441static ssize_t wakeup_count_store(struct kobject *kobj,
442 struct kobj_attribute *attr,
443 const char *buf, size_t n)
444{
Rafael J. Wysocki074037e2010-09-22 22:09:10 +0200445 unsigned int val;
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200446
Rafael J. Wysocki074037e2010-09-22 22:09:10 +0200447 if (sscanf(buf, "%u", &val) == 1) {
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200448 if (pm_save_wakeup_count(val))
449 return n;
450 }
451 return -EINVAL;
452}
453
454power_attr(wakeup_count);
455#endif /* CONFIG_PM_SLEEP */
456
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700457#ifdef CONFIG_PM_TRACE
458int pm_trace_enabled;
459
Kay Sievers386f2752007-11-02 13:47:53 +0100460static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
461 char *buf)
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700462{
463 return sprintf(buf, "%d\n", pm_trace_enabled);
464}
465
466static ssize_t
Kay Sievers386f2752007-11-02 13:47:53 +0100467pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
468 const char *buf, size_t n)
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700469{
470 int val;
471
472 if (sscanf(buf, "%d", &val) == 1) {
473 pm_trace_enabled = !!val;
474 return n;
475 }
476 return -EINVAL;
477}
478
479power_attr(pm_trace);
James Hogand33ac602010-10-12 00:00:25 +0200480
481static ssize_t pm_trace_dev_match_show(struct kobject *kobj,
482 struct kobj_attribute *attr,
483 char *buf)
484{
485 return show_trace_dev_match(buf, PAGE_SIZE);
486}
487
488static ssize_t
489pm_trace_dev_match_store(struct kobject *kobj, struct kobj_attribute *attr,
490 const char *buf, size_t n)
491{
492 return -EINVAL;
493}
494
495power_attr(pm_trace_dev_match);
496
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100497#endif /* CONFIG_PM_TRACE */
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700498
Arve Hjønnevåg025ff0a2008-10-09 21:01:46 -0700499#ifdef CONFIG_USER_WAKELOCK
500power_attr(wake_lock);
501power_attr(wake_unlock);
502#endif
503
Nick Reuterb8678b32018-08-30 02:53:55 -0500504static struct attribute *g[] = {
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700505 &state_attr.attr,
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100506#ifdef CONFIG_PM_TRACE
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700507 &pm_trace_attr.attr,
James Hogand33ac602010-10-12 00:00:25 +0200508 &pm_trace_dev_match_attr.attr,
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100509#endif
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100510#ifdef CONFIG_PM_SLEEP
511 &pm_async_attr.attr,
Rafael J. Wysockic125e962010-07-05 22:43:53 +0200512 &wakeup_count_attr.attr,
Nick Reuterb8678b32018-08-30 02:53:55 -0500513 &touch_event_attr.attr,
514 &touch_event_timer_attr.attr,
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100515#ifdef CONFIG_PM_DEBUG
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100516 &pm_test_attr.attr,
517#endif
Arve Hjønnevåg025ff0a2008-10-09 21:01:46 -0700518#ifdef CONFIG_USER_WAKELOCK
519 &wake_lock_attr.attr,
520 &wake_unlock_attr.attr,
521#endif
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100522#endif
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700523 NULL,
524};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526static struct attribute_group attr_group = {
527 .attrs = g,
528};
529
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200530#ifdef CONFIG_PM_RUNTIME
531struct workqueue_struct *pm_wq;
Alan Stern7b199ca2009-12-03 20:22:21 +0100532EXPORT_SYMBOL_GPL(pm_wq);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200533
534static int __init pm_start_workqueue(void)
535{
Tejun Heo58a69cb2011-02-16 09:25:31 +0100536 pm_wq = alloc_workqueue("pm", WQ_FREEZABLE, 0);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200537
538 return pm_wq ? 0 : -ENOMEM;
539}
540#else
541static inline int pm_start_workqueue(void) { return 0; }
542#endif
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544static int __init pm_init(void)
545{
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200546 int error = pm_start_workqueue();
547 if (error)
548 return error;
Rafael J. Wysockiac5c24ec2010-09-20 19:44:56 +0200549 hibernate_image_size_init();
Rafael J. Wysockiddeb6482011-05-15 11:38:48 +0200550 hibernate_reserved_size_init();
Nick Reuterb8678b32018-08-30 02:53:55 -0500551
552 touch_evt_timer_val = ktime_set(2, 0);
553 hrtimer_init(&tc_ev_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
554 tc_ev_timer.function = &tc_ev_stop;
555 tc_ev_processed = 1;
556
557
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800558 power_kobj = kobject_create_and_add("power", NULL);
559 if (!power_kobj)
Greg Kroah-Hartman039a5dc2007-11-01 10:39:50 -0700560 return -ENOMEM;
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800561 return sysfs_create_group(power_kobj, &attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
564core_initcall(pm_init);