blob: a84332aefc2da73aa3252877cf970efe9e2b9f77 [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 Hansson5de85b92015-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 Lindgren65f79682016-12-05 16:38:16 -080024#define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0)
25#define WAKE_IRQ_DEDICATED_MANAGED BIT(1)
26#define WAKE_IRQ_DEDICATED_MASK (WAKE_IRQ_DEDICATED_ALLOCATED | \
27 WAKE_IRQ_DEDICATED_MANAGED)
28
Tony Lindgren4990d4f2015-05-18 15:40:29 -070029struct wake_irq {
30 struct device *dev;
Tony Lindgren65f79682016-12-05 16:38:16 -080031 unsigned int status;
Tony Lindgren4990d4f2015-05-18 15:40:29 -070032 int irq;
Tony Lindgren4990d4f2015-05-18 15:40:29 -070033};
34
35extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
36extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
Tony Lindgren65f79682016-12-05 16:38:16 -080037extern void dev_pm_enable_wake_irq_check(struct device *dev,
38 bool can_change_status);
39extern void dev_pm_disable_wake_irq_check(struct device *dev);
Tony Lindgren4990d4f2015-05-18 15:40:29 -070040
41#ifdef CONFIG_PM_SLEEP
42
43extern int device_wakeup_attach_irq(struct device *dev,
44 struct wake_irq *wakeirq);
45extern void device_wakeup_detach_irq(struct device *dev);
46extern void device_wakeup_arm_wake_irqs(void);
47extern void device_wakeup_disarm_wake_irqs(void);
48
49#else
50
51static inline int
52device_wakeup_attach_irq(struct device *dev,
53 struct wake_irq *wakeirq)
54{
55 return 0;
56}
57
58static inline void device_wakeup_detach_irq(struct device *dev)
59{
60}
61
62static inline void device_wakeup_arm_wake_irqs(void)
63{
64}
65
66static inline void device_wakeup_disarm_wake_irqs(void)
67{
68}
69
70#endif /* CONFIG_PM_SLEEP */
71
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010072/*
73 * sysfs.c
74 */
75
76extern int dpm_sysfs_add(struct device *dev);
77extern void dpm_sysfs_remove(struct device *dev);
78extern void rpm_sysfs_remove(struct device *dev);
79extern int wakeup_sysfs_add(struct device *dev);
80extern void wakeup_sysfs_remove(struct device *dev);
81extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
82extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
83extern int pm_qos_sysfs_add_flags(struct device *dev);
84extern void pm_qos_sysfs_remove_flags(struct device *dev);
Mika Westerberg13b2c4a2015-07-27 18:03:56 +030085extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
86extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010087
88#else /* CONFIG_PM */
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020089
Rafael J. Wysockibed2b422012-08-06 01:45:11 +020090static inline void pm_runtime_early_init(struct device *dev)
91{
92 device_pm_init_common(dev);
93}
94
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020095static inline void pm_runtime_init(struct device *dev) {}
Ulf Hansson5de85b92015-11-18 11:48:39 +010096static inline void pm_runtime_reinit(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020097static inline void pm_runtime_remove(struct device *dev) {}
98
Rafael J. Wysockid30d8192014-11-27 22:38:05 +010099static inline int dpm_sysfs_add(struct device *dev) { return 0; }
100static inline void dpm_sysfs_remove(struct device *dev) {}
101static inline void rpm_sysfs_remove(struct device *dev) {}
102static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
103static inline void wakeup_sysfs_remove(struct device *dev) {}
104static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
105static inline void pm_qos_sysfs_remove(struct device *dev) {}
106
Tony Lindgren4990d4f2015-05-18 15:40:29 -0700107static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
108{
109}
110
111static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
112{
113}
114
Tony Lindgren65f79682016-12-05 16:38:16 -0800115static inline void dev_pm_enable_wake_irq_check(struct device *dev,
116 bool can_change_status)
117{
118}
119
120static inline void dev_pm_disable_wake_irq_check(struct device *dev)
121{
122}
123
Rafael J. Wysockid30d8192014-11-27 22:38:05 +0100124#endif
Alan Stern3b98aea2008-08-07 13:06:12 -0400125
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200126#ifdef CONFIG_PM_SLEEP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100128/* kernel/power/main.c */
129extern int pm_async_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Rafael J. Wysocki0e06b4a2010-01-23 22:25:15 +0100131/* drivers/base/power/main.c */
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200132extern struct list_head dpm_list; /* The active device list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Daniel Drakedec13c12007-11-21 14:55:18 -0800134static inline struct device *to_device(struct list_head *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Alan Sterncd59abf2007-09-21 15:36:56 -0400136 return container_of(entry, struct device, power.entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200139extern void device_pm_sleep_init(struct device *dev);
Alan Stern3b98aea2008-08-07 13:06:12 -0400140extern void device_pm_add(struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141extern void device_pm_remove(struct device *);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100142extern void device_pm_move_before(struct device *, struct device *);
143extern void device_pm_move_after(struct device *, struct device *);
144extern void device_pm_move_last(struct device *);
Tomeu Vizosoaa8e54b2016-01-07 16:46:14 +0100145extern void device_pm_check_callbacks(struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200147#else /* !CONFIG_PM_SLEEP */
148
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200149static inline void device_pm_sleep_init(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200150
Rafael J. Wysocki37530f22013-03-04 14:22:57 +0100151static inline void device_pm_add(struct device *dev) {}
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200152
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200153static inline void device_pm_remove(struct device *dev)
154{
155 pm_runtime_remove(dev);
156}
Daniel Drakedec13c12007-11-21 14:55:18 -0800157
Cornelia Huckffa6a702009-03-04 12:44:00 +0100158static inline void device_pm_move_before(struct device *deva,
159 struct device *devb) {}
160static inline void device_pm_move_after(struct device *deva,
161 struct device *devb) {}
162static inline void device_pm_move_last(struct device *dev) {}
Rafael J. Wysocki775b64d2008-01-12 20:40:46 +0100163
Tomeu Vizosoaa8e54b2016-01-07 16:46:14 +0100164static inline void device_pm_check_callbacks(struct device *dev) {}
165
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200166#endif /* !CONFIG_PM_SLEEP */
Daniel Drakedec13c12007-11-21 14:55:18 -0800167
Rafael J. Wysockie91c11b2012-08-06 01:44:28 +0200168static inline void device_pm_init(struct device *dev)
169{
170 device_pm_init_common(dev);
171 device_pm_sleep_init(dev);
172 pm_runtime_init(dev);
173}