| 1 | /*
|
|---|
| 2 | * pm.h - Power management interface
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 2000 Andrew Henroid
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, write to the Free Software
|
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #ifndef _LINUX_PM_H
|
|---|
| 22 | #define _LINUX_PM_H
|
|---|
| 23 |
|
|---|
| 24 | #include <linux/list.h>
|
|---|
| 25 | #include <asm/atomic.h>
|
|---|
| 26 | #include <linux/workqueue.h>
|
|---|
| 27 |
|
|---|
| 28 | enum rpm_status {
|
|---|
| 29 | RPM_ACTIVE = 0,
|
|---|
| 30 | RPM_RESUMING,
|
|---|
| 31 | RPM_SUSPENDED,
|
|---|
| 32 | RPM_SUSPENDING,
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | typedef struct pm_message {
|
|---|
| 36 | int event;
|
|---|
| 37 | } pm_message_t;
|
|---|
| 38 |
|
|---|
| 39 | /*
|
|---|
| 40 | * Power management requests
|
|---|
| 41 | */
|
|---|
| 42 | enum
|
|---|
| 43 | {
|
|---|
| 44 | PM_SUSPEND, /* enter D1-D3 */
|
|---|
| 45 | PM_RESUME, /* enter D0 */
|
|---|
| 46 |
|
|---|
| 47 | PM_SAVE_STATE, /* save device's state */
|
|---|
| 48 |
|
|---|
| 49 | /* enable wake-on */
|
|---|
| 50 | PM_SET_WAKEUP,
|
|---|
| 51 |
|
|---|
| 52 | /* bus resource management */
|
|---|
| 53 | PM_GET_RESOURCES,
|
|---|
| 54 | PM_SET_RESOURCES,
|
|---|
| 55 |
|
|---|
| 56 | /* base station management */
|
|---|
| 57 | PM_EJECT,
|
|---|
| 58 | PM_LOCK,
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | typedef int pm_request_t;
|
|---|
| 62 |
|
|---|
| 63 | /*
|
|---|
| 64 | * Device types
|
|---|
| 65 | */
|
|---|
| 66 | enum
|
|---|
| 67 | {
|
|---|
| 68 | PM_UNKNOWN_DEV = 0, /* generic */
|
|---|
| 69 | PM_SYS_DEV, /* system device (fan, KB controller, ...) */
|
|---|
| 70 | PM_PCI_DEV, /* PCI device */
|
|---|
| 71 | PM_USB_DEV, /* USB device */
|
|---|
| 72 | PM_SCSI_DEV, /* SCSI device */
|
|---|
| 73 | PM_ISA_DEV, /* ISA device */
|
|---|
| 74 | PM_MTD_DEV, /* Memory Technology Device */
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | typedef int pm_dev_t;
|
|---|
| 78 |
|
|---|
| 79 | /*
|
|---|
| 80 | * System device hardware ID (PnP) values
|
|---|
| 81 | */
|
|---|
| 82 | enum
|
|---|
| 83 | {
|
|---|
| 84 | PM_SYS_UNKNOWN = 0x00000000, /* generic */
|
|---|
| 85 | PM_SYS_KBC = 0x41d00303, /* keyboard controller */
|
|---|
| 86 | PM_SYS_COM = 0x41d00500, /* serial port */
|
|---|
| 87 | PM_SYS_IRDA = 0x41d00510, /* IRDA controller */
|
|---|
| 88 | PM_SYS_FDC = 0x41d00700, /* floppy controller */
|
|---|
| 89 | PM_SYS_VGA = 0x41d00900, /* VGA controller */
|
|---|
| 90 | PM_SYS_PCMCIA = 0x41d00e00, /* PCMCIA controller */
|
|---|
| 91 | };
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | * Device identifier
|
|---|
| 95 | */
|
|---|
| 96 | #define PM_PCI_ID(dev) ((dev)->bus->number << 16 | (dev)->devfn)
|
|---|
| 97 |
|
|---|
| 98 | /*
|
|---|
| 99 | * Request handler callback
|
|---|
| 100 | */
|
|---|
| 101 | struct pm_dev;
|
|---|
| 102 |
|
|---|
| 103 | typedef int (*pm_callback)(struct pm_dev *dev, pm_request_t rqst, void *data);
|
|---|
| 104 |
|
|---|
| 105 | /*
|
|---|
| 106 | * Dynamic device information
|
|---|
| 107 | */
|
|---|
| 108 | struct pm_dev
|
|---|
| 109 | {
|
|---|
| 110 | pm_dev_t type;
|
|---|
| 111 | unsigned long id;
|
|---|
| 112 | pm_callback callback;
|
|---|
| 113 | void *data;
|
|---|
| 114 |
|
|---|
| 115 | unsigned long flags;
|
|---|
| 116 | unsigned long state;
|
|---|
| 117 | unsigned long prev_state;
|
|---|
| 118 |
|
|---|
| 119 | struct list_head entry;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | #ifdef CONFIG_PM
|
|---|
| 123 |
|
|---|
| 124 | extern int pm_active;
|
|---|
| 125 |
|
|---|
| 126 | #define PM_IS_ACTIVE() (pm_active != 0)
|
|---|
| 127 |
|
|---|
| 128 | /*
|
|---|
| 129 | * Register a device with power management
|
|---|
| 130 | */
|
|---|
| 131 | struct pm_dev *pm_register(pm_dev_t type,
|
|---|
| 132 | unsigned long id,
|
|---|
| 133 | pm_callback callback);
|
|---|
| 134 |
|
|---|
| 135 | /*
|
|---|
| 136 | * Unregister a device with power management
|
|---|
| 137 | */
|
|---|
| 138 | void pm_unregister(struct pm_dev *dev);
|
|---|
| 139 |
|
|---|
| 140 | /*
|
|---|
| 141 | * Unregister all devices with matching callback
|
|---|
| 142 | */
|
|---|
| 143 | void pm_unregister_all(pm_callback callback);
|
|---|
| 144 |
|
|---|
| 145 | /*
|
|---|
| 146 | * Send a request to a single device
|
|---|
| 147 | */
|
|---|
| 148 | int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data);
|
|---|
| 149 |
|
|---|
| 150 | /*
|
|---|
| 151 | * Send a request to all devices
|
|---|
| 152 | */
|
|---|
| 153 | int pm_send_all(pm_request_t rqst, void *data);
|
|---|
| 154 |
|
|---|
| 155 | /*
|
|---|
| 156 | * Find a device
|
|---|
| 157 | */
|
|---|
| 158 | struct pm_dev *pm_find(pm_dev_t type, struct pm_dev *from);
|
|---|
| 159 |
|
|---|
| 160 | static inline void pm_access(struct pm_dev *dev) {}
|
|---|
| 161 | static inline void pm_dev_idle(struct pm_dev *dev) {}
|
|---|
| 162 |
|
|---|
| 163 | #else /* CONFIG_PM */
|
|---|
| 164 |
|
|---|
| 165 | #define PM_IS_ACTIVE() 0
|
|---|
| 166 |
|
|---|
| 167 | static inline struct pm_dev *pm_register(pm_dev_t type,
|
|---|
| 168 | unsigned long id,
|
|---|
| 169 | pm_callback callback)
|
|---|
| 170 | {
|
|---|
| 171 | return 0;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | static inline void pm_unregister(struct pm_dev *dev) {}
|
|---|
| 175 |
|
|---|
| 176 | static inline void pm_unregister_all(pm_callback callback) {}
|
|---|
| 177 |
|
|---|
| 178 | static inline int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data)
|
|---|
| 179 | {
|
|---|
| 180 | return 0;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | static inline int pm_send_all(pm_request_t rqst, void *data)
|
|---|
| 184 | {
|
|---|
| 185 | return 0;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | static inline struct pm_dev *pm_find(pm_dev_t type, struct pm_dev *from)
|
|---|
| 189 | {
|
|---|
| 190 | return 0;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | static inline void pm_access(struct pm_dev *dev) {}
|
|---|
| 194 | static inline void pm_dev_idle(struct pm_dev *dev) {}
|
|---|
| 195 |
|
|---|
| 196 | #endif /* CONFIG_PM */
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | /*
|
|---|
| 200 | * Callbacks for platform drivers to implement.
|
|---|
| 201 | */
|
|---|
| 202 | extern void (*pm_idle)(void);
|
|---|
| 203 | extern void (*pm_power_off)(void);
|
|---|
| 204 |
|
|---|
| 205 | enum {
|
|---|
| 206 | PM_SUSPEND_ON,
|
|---|
| 207 | PM_SUSPEND_STANDBY,
|
|---|
| 208 | PM_SUSPEND_MEM,
|
|---|
| 209 | PM_SUSPEND_DISK,
|
|---|
| 210 | PM_SUSPEND_MAX,
|
|---|
| 211 | };
|
|---|
| 212 |
|
|---|
| 213 | enum {
|
|---|
| 214 | PM_DISK_FIRMWARE = 1,
|
|---|
| 215 | PM_DISK_PLATFORM,
|
|---|
| 216 | PM_DISK_SHUTDOWN,
|
|---|
| 217 | PM_DISK_REBOOT,
|
|---|
| 218 | PM_DISK_MAX,
|
|---|
| 219 | };
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 | struct pm_ops {
|
|---|
| 223 | u32 pm_disk_mode;
|
|---|
| 224 | int (*prepare)(u32 state);
|
|---|
| 225 | int (*enter)(u32 state);
|
|---|
| 226 | int (*finish)(u32 state);
|
|---|
| 227 | };
|
|---|
| 228 |
|
|---|
| 229 | extern void pm_set_ops(struct pm_ops *);
|
|---|
| 230 |
|
|---|
| 231 | extern int pm_suspend(u32 state);
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 | /*
|
|---|
| 235 | * Device power management
|
|---|
| 236 | */
|
|---|
| 237 |
|
|---|
| 238 | struct device;
|
|---|
| 239 |
|
|---|
| 240 | struct dev_pm_info {
|
|---|
| 241 | unsigned int async_suspend:1;
|
|---|
| 242 | bool is_prepared:1; /* Owned by the PM core */
|
|---|
| 243 | u32 power_state;
|
|---|
| 244 | u8 * saved_state;
|
|---|
| 245 | atomic_t pm_users;
|
|---|
| 246 | struct device * pm_parent;
|
|---|
| 247 | struct list_head entry;
|
|---|
| 248 | enum rpm_status runtime_status;
|
|---|
| 249 | unsigned int runtime_auto:1;
|
|---|
| 250 | };
|
|---|
| 251 |
|
|---|
| 252 | extern void device_pm_set_parent(struct device * dev, struct device * parent);
|
|---|
| 253 |
|
|---|
| 254 | extern int device_suspend(u32 state);
|
|---|
| 255 | extern int device_power_down(u32 state);
|
|---|
| 256 | extern void device_power_up(void);
|
|---|
| 257 | extern void device_resume(void);
|
|---|
| 258 |
|
|---|
| 259 | struct dev_pm_ops {
|
|---|
| 260 | int (*prepare)(struct device *dev);
|
|---|
| 261 | void (*complete)(struct device *dev);
|
|---|
| 262 | int (*suspend)(struct device *dev);
|
|---|
| 263 | int (*resume)(struct device *dev);
|
|---|
| 264 | int (*freeze)(struct device *dev);
|
|---|
| 265 | int (*thaw)(struct device *dev);
|
|---|
| 266 | int (*poweroff)(struct device *dev);
|
|---|
| 267 | int (*restore)(struct device *dev);
|
|---|
| 268 | int (*suspend_late)(struct device *dev);
|
|---|
| 269 | int (*resume_early)(struct device *dev);
|
|---|
| 270 | int (*freeze_late)(struct device *dev);
|
|---|
| 271 | int (*thaw_early)(struct device *dev);
|
|---|
| 272 | int (*poweroff_late)(struct device *dev);
|
|---|
| 273 | int (*restore_early)(struct device *dev);
|
|---|
| 274 | int (*suspend_noirq)(struct device *dev);
|
|---|
| 275 | int (*resume_noirq)(struct device *dev);
|
|---|
| 276 | int (*freeze_noirq)(struct device *dev);
|
|---|
| 277 | int (*thaw_noirq)(struct device *dev);
|
|---|
| 278 | int (*poweroff_noirq)(struct device *dev);
|
|---|
| 279 | int (*restore_noirq)(struct device *dev);
|
|---|
| 280 | int (*runtime_suspend)(struct device *dev);
|
|---|
| 281 | int (*runtime_resume)(struct device *dev);
|
|---|
| 282 | int (*runtime_idle)(struct device *dev);
|
|---|
| 283 | };
|
|---|
| 284 |
|
|---|
| 285 | #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
|
|---|
| 286 | .suspend = suspend_fn, \
|
|---|
| 287 | .resume = resume_fn, \
|
|---|
| 288 | .freeze = suspend_fn, \
|
|---|
| 289 | .thaw = resume_fn, \
|
|---|
| 290 | .poweroff = suspend_fn, \
|
|---|
| 291 | .restore = resume_fn,
|
|---|
| 292 |
|
|---|
| 293 | /*
|
|---|
| 294 | * Use this if you want to use the same suspend and resume callbacks for suspend
|
|---|
| 295 | * to RAM and hibernation.
|
|---|
| 296 | */
|
|---|
| 297 | #define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
|
|---|
| 298 | const struct dev_pm_ops name = { \
|
|---|
| 299 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 | #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
|
|---|
| 304 | const struct dev_pm_ops name = { \
|
|---|
| 305 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
|
|---|
| 309 | .runtime_suspend = suspend_fn, \
|
|---|
| 310 | .runtime_resume = resume_fn, \
|
|---|
| 311 | .runtime_idle = idle_fn,
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 | /*
|
|---|
| 315 | * Power domains provide callbacks that are executed during system suspend,
|
|---|
| 316 | * hibernation, system resume and during runtime PM transitions along with
|
|---|
| 317 | * subsystem-level and driver-level callbacks.
|
|---|
| 318 | */
|
|---|
| 319 | struct dev_pm_domain {
|
|---|
| 320 | struct dev_pm_ops ops;
|
|---|
| 321 | };
|
|---|
| 322 |
|
|---|
| 323 | #define PM_EVENT_INVALID (-1)
|
|---|
| 324 | #define PM_EVENT_ON 0x0000
|
|---|
| 325 | #define PM_EVENT_FREEZE 0x0001
|
|---|
| 326 | #define PM_EVENT_SUSPEND 0x0002
|
|---|
| 327 | #define PM_EVENT_HIBERNATE 0x0004
|
|---|
| 328 | #define PM_EVENT_QUIESCE 0x0008
|
|---|
| 329 | #define PM_EVENT_RESUME 0x0010
|
|---|
| 330 | #define PM_EVENT_THAW 0x0020
|
|---|
| 331 | #define PM_EVENT_RESTORE 0x0040
|
|---|
| 332 | #define PM_EVENT_RECOVER 0x0080
|
|---|
| 333 | #define PM_EVENT_USER 0x0100
|
|---|
| 334 | #define PM_EVENT_REMOTE 0x0200
|
|---|
| 335 | #define PM_EVENT_AUTO 0x0400
|
|---|
| 336 |
|
|---|
| 337 | #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
|
|---|
| 338 | #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
|
|---|
| 339 | #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
|
|---|
| 340 | #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
|
|---|
| 341 | #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
|
|---|
| 342 | #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
|
|---|
| 343 |
|
|---|
| 344 | #define PMSG_FREEZE 3
|
|---|
| 345 | #define PMSG_SUSPEND 3
|
|---|
| 346 | #define PMSG_ON 0
|
|---|
| 347 | #define PMSG_RESUME 0
|
|---|
| 348 | #define PMSG_THAW 0
|
|---|
| 349 | #define PMSG_RESTORE 0
|
|---|
| 350 | #define pm_sleep_ptr(_ptr) _ptr
|
|---|
| 351 | #endif /* _LINUX_PM_H */
|
|---|