xref: /openbmc/linux/drivers/base/power/power.h (revision f3539c12)
1 #include <linux/pm_qos.h>
2 
3 static inline void device_pm_init_common(struct device *dev)
4 {
5 	if (!dev->power.early_init) {
6 		spin_lock_init(&dev->power.lock);
7 		dev->power.qos = NULL;
8 		dev->power.early_init = true;
9 	}
10 }
11 
12 #ifdef CONFIG_PM
13 
14 static inline void pm_runtime_early_init(struct device *dev)
15 {
16 	dev->power.disable_depth = 1;
17 	device_pm_init_common(dev);
18 }
19 
20 extern void pm_runtime_init(struct device *dev);
21 extern void pm_runtime_reinit(struct device *dev);
22 extern void pm_runtime_remove(struct device *dev);
23 
24 struct wake_irq {
25 	struct device *dev;
26 	int irq;
27 	bool dedicated_irq:1;
28 };
29 
30 extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
31 extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
32 
33 #ifdef CONFIG_PM_SLEEP
34 
35 extern int device_wakeup_attach_irq(struct device *dev,
36 				    struct wake_irq *wakeirq);
37 extern void device_wakeup_detach_irq(struct device *dev);
38 extern void device_wakeup_arm_wake_irqs(void);
39 extern void device_wakeup_disarm_wake_irqs(void);
40 
41 #else
42 
43 static inline int
44 device_wakeup_attach_irq(struct device *dev,
45 			 struct wake_irq *wakeirq)
46 {
47 	return 0;
48 }
49 
50 static inline void device_wakeup_detach_irq(struct device *dev)
51 {
52 }
53 
54 static inline void device_wakeup_arm_wake_irqs(void)
55 {
56 }
57 
58 static inline void device_wakeup_disarm_wake_irqs(void)
59 {
60 }
61 
62 #endif /* CONFIG_PM_SLEEP */
63 
64 /*
65  * sysfs.c
66  */
67 
68 extern int dpm_sysfs_add(struct device *dev);
69 extern void dpm_sysfs_remove(struct device *dev);
70 extern void rpm_sysfs_remove(struct device *dev);
71 extern int wakeup_sysfs_add(struct device *dev);
72 extern void wakeup_sysfs_remove(struct device *dev);
73 extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
74 extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
75 extern int pm_qos_sysfs_add_flags(struct device *dev);
76 extern void pm_qos_sysfs_remove_flags(struct device *dev);
77 extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
78 extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
79 
80 #else /* CONFIG_PM */
81 
82 static inline void pm_runtime_early_init(struct device *dev)
83 {
84 	device_pm_init_common(dev);
85 }
86 
87 static inline void pm_runtime_init(struct device *dev) {}
88 static inline void pm_runtime_reinit(struct device *dev) {}
89 static inline void pm_runtime_remove(struct device *dev) {}
90 
91 static inline int dpm_sysfs_add(struct device *dev) { return 0; }
92 static inline void dpm_sysfs_remove(struct device *dev) {}
93 static inline void rpm_sysfs_remove(struct device *dev) {}
94 static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
95 static inline void wakeup_sysfs_remove(struct device *dev) {}
96 static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
97 static inline void pm_qos_sysfs_remove(struct device *dev) {}
98 
99 static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
100 {
101 }
102 
103 static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
104 {
105 }
106 
107 #endif
108 
109 #ifdef CONFIG_PM_SLEEP
110 
111 /* kernel/power/main.c */
112 extern int pm_async_enabled;
113 
114 /* drivers/base/power/main.c */
115 extern struct list_head dpm_list;	/* The active device list */
116 
117 static inline struct device *to_device(struct list_head *entry)
118 {
119 	return container_of(entry, struct device, power.entry);
120 }
121 
122 extern void device_pm_sleep_init(struct device *dev);
123 extern void device_pm_add(struct device *);
124 extern void device_pm_remove(struct device *);
125 extern void device_pm_move_before(struct device *, struct device *);
126 extern void device_pm_move_after(struct device *, struct device *);
127 extern void device_pm_move_last(struct device *);
128 extern void device_pm_check_callbacks(struct device *dev);
129 
130 #else /* !CONFIG_PM_SLEEP */
131 
132 static inline void device_pm_sleep_init(struct device *dev) {}
133 
134 static inline void device_pm_add(struct device *dev) {}
135 
136 static inline void device_pm_remove(struct device *dev)
137 {
138 	pm_runtime_remove(dev);
139 }
140 
141 static inline void device_pm_move_before(struct device *deva,
142 					 struct device *devb) {}
143 static inline void device_pm_move_after(struct device *deva,
144 					struct device *devb) {}
145 static inline void device_pm_move_last(struct device *dev) {}
146 
147 static inline void device_pm_check_callbacks(struct device *dev) {}
148 
149 #endif /* !CONFIG_PM_SLEEP */
150 
151 static inline void device_pm_init(struct device *dev)
152 {
153 	device_pm_init_common(dev);
154 	device_pm_sleep_init(dev);
155 	pm_runtime_init(dev);
156 }
157