blob: 998fa6b230844391b023b5ba8d4f0a22f9c645b0 [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);
21extern void pm_runtime_remove(struct device *dev);
22
Tony Lindgren4990d4f2015-05-18 15:40:29 -070023struct wake_irq {
24 struct device *dev;
25 int irq;
26 bool dedicated_irq:1;
27};
28
29extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
30extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
31
32#ifdef CONFIG_PM_SLEEP
33
34extern int device_wakeup_attach_irq(struct device *dev,
35 struct wake_irq *wakeirq);
36extern void device_wakeup_detach_irq(struct device *dev);
37extern void device_wakeup_arm_wake_irqs(void);
38extern void device_wakeup_disarm_wake_irqs(void);
39
40#else
41
42static inline int
43device_wakeup_attach_irq(struct device *dev,
44 struct wake_irq *wakeirq)
45{
46 return 0;
47}
48
49static inline void device_wakeup_detach_irq(struct device *dev)
50{
51}
52
53static inline void device_wakeup_arm_wake_irqs(void)
54{
55}
56
57static inline void device_wakeup_disarm_wake_irqs(void)
58{
59}
60
61#endif /* CONFIG_PM_SLEEP */
62
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010063/*
64 * sysfs.c
65 */
66
67extern int dpm_sysfs_add(struct device *dev);
68extern void dpm_sysfs_remove(struct device *dev);
69extern void rpm_sysfs_remove(struct device *dev);
70extern int wakeup_sysfs_add(struct device *dev);
71extern void wakeup_sysfs_remove(struct device *dev);
72extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
73extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
74extern int pm_qos_sysfs_add_flags(struct device *dev);
75extern void pm_qos_sysfs_remove_flags(struct device *dev);
Mika Westerberg13b2c4a2015-07-27 18:03:56 +030076extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
77extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010078
79#else /* CONFIG_PM */
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020080
Rafael J. Wysockibed2b422012-08-06 01:45:11 +020081static inline void pm_runtime_early_init(struct device *dev)
82{
83 device_pm_init_common(dev);
84}
85
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020086static inline void pm_runtime_init(struct device *dev) {}
87static inline void pm_runtime_remove(struct device *dev) {}
88
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010089static inline int dpm_sysfs_add(struct device *dev) { return 0; }
90static inline void dpm_sysfs_remove(struct device *dev) {}
91static inline void rpm_sysfs_remove(struct device *dev) {}
92static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
93static inline void wakeup_sysfs_remove(struct device *dev) {}
94static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
95static inline void pm_qos_sysfs_remove(struct device *dev) {}
96
Tony Lindgren4990d4f2015-05-18 15:40:29 -070097static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
98{
99}
100
101static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
102{
103}
104
Rafael J. Wysockid30d8192014-11-27 22:38:05 +0100105#endif
Alan Stern3b98aea2008-08-07 13:06:12 -0400106
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200107#ifdef CONFIG_PM_SLEEP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100109/* kernel/power/main.c */
110extern int pm_async_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100112/* drivers/base/power/main.c */
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200113extern struct list_head dpm_list; /* The active device list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Daniel Drakedec13c12007-11-21 14:55:18 -0800115static inline struct device *to_device(struct list_head *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Alan Sterncd59abf2007-09-21 15:36:56 -0400117 return container_of(entry, struct device, power.entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200120extern void device_pm_sleep_init(struct device *dev);
Alan Stern3b98aea2008-08-07 13:06:12 -0400121extern void device_pm_add(struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122extern void device_pm_remove(struct device *);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100123extern void device_pm_move_before(struct device *, struct device *);
124extern void device_pm_move_after(struct device *, struct device *);
125extern void device_pm_move_last(struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200127#else /* !CONFIG_PM_SLEEP */
128
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200129static inline void device_pm_sleep_init(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200130
Rafael J. Wysocki37530f22013-03-04 14:22:57 +0100131static inline void device_pm_add(struct device *dev) {}
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200132
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200133static inline void device_pm_remove(struct device *dev)
134{
135 pm_runtime_remove(dev);
136}
Daniel Drakedec13c12007-11-21 14:55:18 -0800137
Cornelia Huckffa6a702009-03-04 12:44:00 +0100138static inline void device_pm_move_before(struct device *deva,
139 struct device *devb) {}
140static inline void device_pm_move_after(struct device *deva,
141 struct device *devb) {}
142static inline void device_pm_move_last(struct device *dev) {}
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100143
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200144#endif /* !CONFIG_PM_SLEEP */
Daniel Drakedec13c12007-11-21 14:55:18 -0800145
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200146static inline void device_pm_init(struct device *dev)
147{
148 device_pm_init_common(dev);
149 device_pm_sleep_init(dev);
150 pm_runtime_init(dev);
151}