blob: 8b06193d4a5e9f1aa42cfae570a5499be86ee4a5 [file] [log] [blame]
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +02001#include <linux/pm_qos.h>
2
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +02003static inline void device_pm_init_common(struct device *dev)
4{
Rafael J. Wysockibed2b422012-08-06 01:45:11 +02005 if (!dev->power.early_init) {
6 spin_lock_init(&dev->power.lock);
Rafael J. Wysocki37530f22013-03-04 14:22:57 +01007 dev->power.qos = NULL;
Rafael J. Wysockibed2b422012-08-06 01:45:11 +02008 dev->power.early_init = true;
9 }
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +020010}
11
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010012#ifdef CONFIG_PM
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020013
Rafael J. Wysockibed2b422012-08-06 01:45:11 +020014static inline void pm_runtime_early_init(struct device *dev)
15{
16 dev->power.disable_depth = 1;
17 device_pm_init_common(dev);
18}
19
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020020extern void pm_runtime_init(struct device *dev);
Ulf Hansson5de85b9d2015-11-18 11:48:39 +010021extern void pm_runtime_reinit(struct device *dev);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020022extern void pm_runtime_remove(struct device *dev);
23
Tony Lindgren4990d4f2015-05-18 15:40:29 -070024struct wake_irq {
25 struct device *dev;
26 int irq;
27 bool dedicated_irq:1;
28};
29
30extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
31extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
32
33#ifdef CONFIG_PM_SLEEP
34
35extern int device_wakeup_attach_irq(struct device *dev,
36 struct wake_irq *wakeirq);
37extern void device_wakeup_detach_irq(struct device *dev);
38extern void device_wakeup_arm_wake_irqs(void);
39extern void device_wakeup_disarm_wake_irqs(void);
40
41#else
42
43static inline int
44device_wakeup_attach_irq(struct device *dev,
45 struct wake_irq *wakeirq)
46{
47 return 0;
48}
49
50static inline void device_wakeup_detach_irq(struct device *dev)
51{
52}
53
54static inline void device_wakeup_arm_wake_irqs(void)
55{
56}
57
58static inline void device_wakeup_disarm_wake_irqs(void)
59{
60}
61
62#endif /* CONFIG_PM_SLEEP */
63
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010064/*
65 * sysfs.c
66 */
67
68extern int dpm_sysfs_add(struct device *dev);
69extern void dpm_sysfs_remove(struct device *dev);
70extern void rpm_sysfs_remove(struct device *dev);
71extern int wakeup_sysfs_add(struct device *dev);
72extern void wakeup_sysfs_remove(struct device *dev);
73extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
74extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
75extern int pm_qos_sysfs_add_flags(struct device *dev);
76extern void pm_qos_sysfs_remove_flags(struct device *dev);
Mika Westerberg13b2c4a2015-07-27 18:03:56 +030077extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
78extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010079
80#else /* CONFIG_PM */
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020081
Rafael J. Wysockibed2b422012-08-06 01:45:11 +020082static inline void pm_runtime_early_init(struct device *dev)
83{
84 device_pm_init_common(dev);
85}
86
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020087static inline void pm_runtime_init(struct device *dev) {}
Ulf Hansson5de85b9d2015-11-18 11:48:39 +010088static inline void pm_runtime_reinit(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020089static inline void pm_runtime_remove(struct device *dev) {}
90
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010091static inline int dpm_sysfs_add(struct device *dev) { return 0; }
92static inline void dpm_sysfs_remove(struct device *dev) {}
93static inline void rpm_sysfs_remove(struct device *dev) {}
94static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
95static inline void wakeup_sysfs_remove(struct device *dev) {}
96static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
97static inline void pm_qos_sysfs_remove(struct device *dev) {}
98
Tony Lindgren4990d4f2015-05-18 15:40:29 -070099static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
100{
101}
102
103static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
104{
105}
106
Rafael J. Wysockid30d8192014-11-27 22:38:05 +0100107#endif
Alan Stern3b98aea2008-08-07 13:06:12 -0400108
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200109#ifdef CONFIG_PM_SLEEP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100111/* kernel/power/main.c */
112extern int pm_async_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100114/* drivers/base/power/main.c */
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200115extern struct list_head dpm_list; /* The active device list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Daniel Drakedec13c12007-11-21 14:55:18 -0800117static inline struct device *to_device(struct list_head *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Alan Sterncd59abf2007-09-21 15:36:56 -0400119 return container_of(entry, struct device, power.entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200122extern void device_pm_sleep_init(struct device *dev);
Alan Stern3b98aea2008-08-07 13:06:12 -0400123extern void device_pm_add(struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124extern void device_pm_remove(struct device *);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100125extern void device_pm_move_before(struct device *, struct device *);
126extern void device_pm_move_after(struct device *, struct device *);
127extern void device_pm_move_last(struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200129#else /* !CONFIG_PM_SLEEP */
130
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200131static inline void device_pm_sleep_init(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200132
Rafael J. Wysocki37530f22013-03-04 14:22:57 +0100133static inline void device_pm_add(struct device *dev) {}
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200134
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200135static inline void device_pm_remove(struct device *dev)
136{
137 pm_runtime_remove(dev);
138}
Daniel Drakedec13c12007-11-21 14:55:18 -0800139
Cornelia Huckffa6a702009-03-04 12:44:00 +0100140static inline void device_pm_move_before(struct device *deva,
141 struct device *devb) {}
142static inline void device_pm_move_after(struct device *deva,
143 struct device *devb) {}
144static inline void device_pm_move_last(struct device *dev) {}
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100145
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200146#endif /* !CONFIG_PM_SLEEP */
Daniel Drakedec13c12007-11-21 14:55:18 -0800147
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200148static inline void device_pm_init(struct device *dev)
149{
150 device_pm_init_common(dev);
151 device_pm_sleep_init(dev);
152 pm_runtime_init(dev);
153}