0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_PM_WAKEUP_H
0010 #define _LINUX_PM_WAKEUP_H
0011
0012 #ifndef _DEVICE_H_
0013 # error "please don't include this file directly"
0014 #endif
0015
0016 #include <linux/types.h>
0017
0018 struct wake_irq;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 struct wakeup_source {
0044 const char *name;
0045 int id;
0046 struct list_head entry;
0047 spinlock_t lock;
0048 struct wake_irq *wakeirq;
0049 struct timer_list timer;
0050 unsigned long timer_expires;
0051 ktime_t total_time;
0052 ktime_t max_time;
0053 ktime_t last_time;
0054 ktime_t start_prevent_time;
0055 ktime_t prevent_sleep_time;
0056 unsigned long event_count;
0057 unsigned long active_count;
0058 unsigned long relax_count;
0059 unsigned long expire_count;
0060 unsigned long wakeup_count;
0061 struct device *dev;
0062 bool active:1;
0063 bool autosleep_enabled:1;
0064 };
0065
0066 #define for_each_wakeup_source(ws) \
0067 for ((ws) = wakeup_sources_walk_start(); \
0068 (ws); \
0069 (ws) = wakeup_sources_walk_next((ws)))
0070
0071 #ifdef CONFIG_PM_SLEEP
0072
0073
0074
0075
0076
0077 static inline bool device_can_wakeup(struct device *dev)
0078 {
0079 return dev->power.can_wakeup;
0080 }
0081
0082 static inline bool device_may_wakeup(struct device *dev)
0083 {
0084 return dev->power.can_wakeup && !!dev->power.wakeup;
0085 }
0086
0087 static inline bool device_wakeup_path(struct device *dev)
0088 {
0089 return dev->power.wakeup_path;
0090 }
0091
0092 static inline void device_set_wakeup_path(struct device *dev)
0093 {
0094 dev->power.wakeup_path = true;
0095 }
0096
0097
0098 extern struct wakeup_source *wakeup_source_create(const char *name);
0099 extern void wakeup_source_destroy(struct wakeup_source *ws);
0100 extern void wakeup_source_add(struct wakeup_source *ws);
0101 extern void wakeup_source_remove(struct wakeup_source *ws);
0102 extern struct wakeup_source *wakeup_source_register(struct device *dev,
0103 const char *name);
0104 extern void wakeup_source_unregister(struct wakeup_source *ws);
0105 extern int wakeup_sources_read_lock(void);
0106 extern void wakeup_sources_read_unlock(int idx);
0107 extern struct wakeup_source *wakeup_sources_walk_start(void);
0108 extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);
0109 extern int device_wakeup_enable(struct device *dev);
0110 extern int device_wakeup_disable(struct device *dev);
0111 extern void device_set_wakeup_capable(struct device *dev, bool capable);
0112 extern int device_set_wakeup_enable(struct device *dev, bool enable);
0113 extern void __pm_stay_awake(struct wakeup_source *ws);
0114 extern void pm_stay_awake(struct device *dev);
0115 extern void __pm_relax(struct wakeup_source *ws);
0116 extern void pm_relax(struct device *dev);
0117 extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard);
0118 extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard);
0119
0120 #else
0121
0122 static inline void device_set_wakeup_capable(struct device *dev, bool capable)
0123 {
0124 dev->power.can_wakeup = capable;
0125 }
0126
0127 static inline bool device_can_wakeup(struct device *dev)
0128 {
0129 return dev->power.can_wakeup;
0130 }
0131
0132 static inline struct wakeup_source *wakeup_source_create(const char *name)
0133 {
0134 return NULL;
0135 }
0136
0137 static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
0138
0139 static inline void wakeup_source_add(struct wakeup_source *ws) {}
0140
0141 static inline void wakeup_source_remove(struct wakeup_source *ws) {}
0142
0143 static inline struct wakeup_source *wakeup_source_register(struct device *dev,
0144 const char *name)
0145 {
0146 return NULL;
0147 }
0148
0149 static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
0150
0151 static inline int device_wakeup_enable(struct device *dev)
0152 {
0153 dev->power.should_wakeup = true;
0154 return 0;
0155 }
0156
0157 static inline int device_wakeup_disable(struct device *dev)
0158 {
0159 dev->power.should_wakeup = false;
0160 return 0;
0161 }
0162
0163 static inline int device_set_wakeup_enable(struct device *dev, bool enable)
0164 {
0165 dev->power.should_wakeup = enable;
0166 return 0;
0167 }
0168
0169 static inline bool device_may_wakeup(struct device *dev)
0170 {
0171 return dev->power.can_wakeup && dev->power.should_wakeup;
0172 }
0173
0174 static inline bool device_wakeup_path(struct device *dev)
0175 {
0176 return false;
0177 }
0178
0179 static inline void device_set_wakeup_path(struct device *dev) {}
0180
0181 static inline void __pm_stay_awake(struct wakeup_source *ws) {}
0182
0183 static inline void pm_stay_awake(struct device *dev) {}
0184
0185 static inline void __pm_relax(struct wakeup_source *ws) {}
0186
0187 static inline void pm_relax(struct device *dev) {}
0188
0189 static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
0190 unsigned int msec, bool hard) {}
0191
0192 static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
0193 bool hard) {}
0194
0195 #endif
0196
0197 static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
0198 {
0199 return pm_wakeup_ws_event(ws, msec, false);
0200 }
0201
0202 static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
0203 {
0204 return pm_wakeup_dev_event(dev, msec, false);
0205 }
0206
0207 static inline void pm_wakeup_hard_event(struct device *dev)
0208 {
0209 return pm_wakeup_dev_event(dev, 0, true);
0210 }
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 static inline int device_init_wakeup(struct device *dev, bool enable)
0224 {
0225 if (enable) {
0226 device_set_wakeup_capable(dev, true);
0227 return device_wakeup_enable(dev);
0228 } else {
0229 device_wakeup_disable(dev);
0230 device_set_wakeup_capable(dev, false);
0231 return 0;
0232 }
0233 }
0234
0235 #endif