diff options
Diffstat (limited to 'include/linux/pm.h')
| -rw-r--r-- | include/linux/pm.h | 136 |
1 files changed, 88 insertions, 48 deletions
diff --git a/include/linux/pm.h b/include/linux/pm.h index 198b8f9fe05e..dd9c7ab38270 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/spinlock.h> | 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/wait.h> | 27 | #include <linux/wait.h> |
| 28 | #include <linux/timer.h> | 28 | #include <linux/timer.h> |
| 29 | #include <linux/completion.h> | ||
| 29 | 30 | ||
| 30 | /* | 31 | /* |
| 31 | * Callbacks for platform drivers to implement. | 32 | * Callbacks for platform drivers to implement. |
| @@ -40,6 +41,12 @@ extern void (*pm_power_off_prepare)(void); | |||
| 40 | 41 | ||
| 41 | struct device; | 42 | struct device; |
| 42 | 43 | ||
| 44 | #ifdef CONFIG_PM | ||
| 45 | extern const char power_group_name[]; /* = "power" */ | ||
| 46 | #else | ||
| 47 | #define power_group_name NULL | ||
| 48 | #endif | ||
| 49 | |||
| 43 | typedef struct pm_message { | 50 | typedef struct pm_message { |
| 44 | int event; | 51 | int event; |
| 45 | } pm_message_t; | 52 | } pm_message_t; |
| @@ -214,20 +221,59 @@ struct dev_pm_ops { | |||
| 214 | int (*runtime_idle)(struct device *dev); | 221 | int (*runtime_idle)(struct device *dev); |
| 215 | }; | 222 | }; |
| 216 | 223 | ||
| 224 | #ifdef CONFIG_PM_SLEEP | ||
| 225 | #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ||
| 226 | .suspend = suspend_fn, \ | ||
| 227 | .resume = resume_fn, \ | ||
| 228 | .freeze = suspend_fn, \ | ||
| 229 | .thaw = resume_fn, \ | ||
| 230 | .poweroff = suspend_fn, \ | ||
| 231 | .restore = resume_fn, | ||
| 232 | #else | ||
| 233 | #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #ifdef CONFIG_PM_RUNTIME | ||
| 237 | #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ | ||
| 238 | .runtime_suspend = suspend_fn, \ | ||
| 239 | .runtime_resume = resume_fn, \ | ||
| 240 | .runtime_idle = idle_fn, | ||
| 241 | #else | ||
| 242 | #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) | ||
| 243 | #endif | ||
| 244 | |||
| 217 | /* | 245 | /* |
| 218 | * Use this if you want to use the same suspend and resume callbacks for suspend | 246 | * Use this if you want to use the same suspend and resume callbacks for suspend |
| 219 | * to RAM and hibernation. | 247 | * to RAM and hibernation. |
| 220 | */ | 248 | */ |
| 221 | #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ | 249 | #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ |
| 222 | const struct dev_pm_ops name = { \ | 250 | const struct dev_pm_ops name = { \ |
| 223 | .suspend = suspend_fn, \ | 251 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ |
| 224 | .resume = resume_fn, \ | 252 | } |
| 225 | .freeze = suspend_fn, \ | 253 | |
| 226 | .thaw = resume_fn, \ | 254 | /* |
| 227 | .poweroff = suspend_fn, \ | 255 | * Use this for defining a set of PM operations to be used in all situations |
| 228 | .restore = resume_fn, \ | 256 | * (sustem suspend, hibernation or runtime PM). |
| 257 | */ | ||
| 258 | #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \ | ||
| 259 | const struct dev_pm_ops name = { \ | ||
| 260 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ||
| 261 | SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ | ||
| 229 | } | 262 | } |
| 230 | 263 | ||
| 264 | /* | ||
| 265 | * Use this for subsystems (bus types, device types, device classes) that don't | ||
| 266 | * need any special suspend/resume handling in addition to invoking the PM | ||
| 267 | * callbacks provided by device drivers supporting both the system sleep PM and | ||
| 268 | * runtime PM, make the pm member point to generic_subsys_pm_ops. | ||
| 269 | */ | ||
| 270 | #ifdef CONFIG_PM_OPS | ||
| 271 | extern struct dev_pm_ops generic_subsys_pm_ops; | ||
| 272 | #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops) | ||
| 273 | #else | ||
| 274 | #define GENERIC_SUBSYS_PM_OPS NULL | ||
| 275 | #endif | ||
| 276 | |||
| 231 | /** | 277 | /** |
| 232 | * PM_EVENT_ messages | 278 | * PM_EVENT_ messages |
| 233 | * | 279 | * |
| @@ -321,45 +367,6 @@ const struct dev_pm_ops name = { \ | |||
| 321 | { .event = PM_EVENT_AUTO_RESUME, }) | 367 | { .event = PM_EVENT_AUTO_RESUME, }) |
| 322 | 368 | ||
| 323 | /** | 369 | /** |
| 324 | * Device power management states | ||
| 325 | * | ||
| 326 | * These state labels are used internally by the PM core to indicate the current | ||
| 327 | * status of a device with respect to the PM core operations. | ||
| 328 | * | ||
| 329 | * DPM_ON Device is regarded as operational. Set this way | ||
| 330 | * initially and when ->complete() is about to be called. | ||
| 331 | * Also set when ->prepare() fails. | ||
| 332 | * | ||
| 333 | * DPM_PREPARING Device is going to be prepared for a PM transition. Set | ||
| 334 | * when ->prepare() is about to be called. | ||
| 335 | * | ||
| 336 | * DPM_RESUMING Device is going to be resumed. Set when ->resume(), | ||
| 337 | * ->thaw(), or ->restore() is about to be called. | ||
| 338 | * | ||
| 339 | * DPM_SUSPENDING Device has been prepared for a power transition. Set | ||
| 340 | * when ->prepare() has just succeeded. | ||
| 341 | * | ||
| 342 | * DPM_OFF Device is regarded as inactive. Set immediately after | ||
| 343 | * ->suspend(), ->freeze(), or ->poweroff() has succeeded. | ||
| 344 | * Also set when ->resume()_noirq, ->thaw_noirq(), or | ||
| 345 | * ->restore_noirq() is about to be called. | ||
| 346 | * | ||
| 347 | * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after | ||
| 348 | * ->suspend_noirq(), ->freeze_noirq(), or | ||
| 349 | * ->poweroff_noirq() has just succeeded. | ||
| 350 | */ | ||
| 351 | |||
| 352 | enum dpm_state { | ||
| 353 | DPM_INVALID, | ||
| 354 | DPM_ON, | ||
| 355 | DPM_PREPARING, | ||
| 356 | DPM_RESUMING, | ||
| 357 | DPM_SUSPENDING, | ||
| 358 | DPM_OFF, | ||
| 359 | DPM_OFF_IRQ, | ||
| 360 | }; | ||
| 361 | |||
| 362 | /** | ||
| 363 | * Device run-time power management status. | 370 | * Device run-time power management status. |
| 364 | * | 371 | * |
| 365 | * These status labels are used internally by the PM core to indicate the | 372 | * These status labels are used internally by the PM core to indicate the |
| @@ -398,6 +405,9 @@ enum rpm_status { | |||
| 398 | * | 405 | * |
| 399 | * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback | 406 | * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback |
| 400 | * | 407 | * |
| 408 | * RPM_REQ_AUTOSUSPEND Same as RPM_REQ_SUSPEND, but not until the device has | ||
| 409 | * been inactive for as long as power.autosuspend_delay | ||
| 410 | * | ||
| 401 | * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback | 411 | * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback |
| 402 | */ | 412 | */ |
| 403 | 413 | ||
| @@ -405,23 +415,28 @@ enum rpm_request { | |||
| 405 | RPM_REQ_NONE = 0, | 415 | RPM_REQ_NONE = 0, |
| 406 | RPM_REQ_IDLE, | 416 | RPM_REQ_IDLE, |
| 407 | RPM_REQ_SUSPEND, | 417 | RPM_REQ_SUSPEND, |
| 418 | RPM_REQ_AUTOSUSPEND, | ||
| 408 | RPM_REQ_RESUME, | 419 | RPM_REQ_RESUME, |
| 409 | }; | 420 | }; |
| 410 | 421 | ||
| 422 | struct wakeup_source; | ||
| 423 | |||
| 411 | struct dev_pm_info { | 424 | struct dev_pm_info { |
| 412 | pm_message_t power_state; | 425 | pm_message_t power_state; |
| 413 | unsigned int can_wakeup:1; | 426 | unsigned int can_wakeup:1; |
| 414 | unsigned int should_wakeup:1; | 427 | unsigned int async_suspend:1; |
| 415 | enum dpm_state status; /* Owned by the PM core */ | 428 | unsigned int in_suspend:1; /* Owned by the PM core */ |
| 429 | spinlock_t lock; | ||
| 416 | #ifdef CONFIG_PM_SLEEP | 430 | #ifdef CONFIG_PM_SLEEP |
| 417 | struct list_head entry; | 431 | struct list_head entry; |
| 432 | struct completion completion; | ||
| 433 | struct wakeup_source *wakeup; | ||
| 418 | #endif | 434 | #endif |
| 419 | #ifdef CONFIG_PM_RUNTIME | 435 | #ifdef CONFIG_PM_RUNTIME |
| 420 | struct timer_list suspend_timer; | 436 | struct timer_list suspend_timer; |
| 421 | unsigned long timer_expires; | 437 | unsigned long timer_expires; |
| 422 | struct work_struct work; | 438 | struct work_struct work; |
| 423 | wait_queue_head_t wait_queue; | 439 | wait_queue_head_t wait_queue; |
| 424 | spinlock_t lock; | ||
| 425 | atomic_t usage_count; | 440 | atomic_t usage_count; |
| 426 | atomic_t child_count; | 441 | atomic_t child_count; |
| 427 | unsigned int disable_depth:3; | 442 | unsigned int disable_depth:3; |
| @@ -430,12 +445,25 @@ struct dev_pm_info { | |||
| 430 | unsigned int request_pending:1; | 445 | unsigned int request_pending:1; |
| 431 | unsigned int deferred_resume:1; | 446 | unsigned int deferred_resume:1; |
| 432 | unsigned int run_wake:1; | 447 | unsigned int run_wake:1; |
| 448 | unsigned int runtime_auto:1; | ||
| 449 | unsigned int no_callbacks:1; | ||
| 450 | unsigned int irq_safe:1; | ||
| 451 | unsigned int use_autosuspend:1; | ||
| 452 | unsigned int timer_autosuspends:1; | ||
| 433 | enum rpm_request request; | 453 | enum rpm_request request; |
| 434 | enum rpm_status runtime_status; | 454 | enum rpm_status runtime_status; |
| 435 | int runtime_error; | 455 | int runtime_error; |
| 456 | int autosuspend_delay; | ||
| 457 | unsigned long last_busy; | ||
| 458 | unsigned long active_jiffies; | ||
| 459 | unsigned long suspended_jiffies; | ||
| 460 | unsigned long accounting_timestamp; | ||
| 436 | #endif | 461 | #endif |
| 437 | }; | 462 | }; |
| 438 | 463 | ||
| 464 | extern void update_pm_runtime_accounting(struct device *dev); | ||
| 465 | |||
| 466 | |||
| 439 | /* | 467 | /* |
| 440 | * The PM_EVENT_ messages are also used by drivers implementing the legacy | 468 | * The PM_EVENT_ messages are also used by drivers implementing the legacy |
| 441 | * suspend framework, based on the ->suspend() and ->resume() callbacks common | 469 | * suspend framework, based on the ->suspend() and ->resume() callbacks common |
| @@ -508,6 +536,7 @@ extern void __suspend_report_result(const char *function, void *fn, int ret); | |||
| 508 | __suspend_report_result(__func__, fn, ret); \ | 536 | __suspend_report_result(__func__, fn, ret); \ |
| 509 | } while (0) | 537 | } while (0) |
| 510 | 538 | ||
| 539 | extern int device_pm_wait_for_dev(struct device *sub, struct device *dev); | ||
| 511 | #else /* !CONFIG_PM_SLEEP */ | 540 | #else /* !CONFIG_PM_SLEEP */ |
| 512 | 541 | ||
| 513 | #define device_pm_lock() do {} while (0) | 542 | #define device_pm_lock() do {} while (0) |
| @@ -520,6 +549,10 @@ static inline int dpm_suspend_start(pm_message_t state) | |||
| 520 | 549 | ||
| 521 | #define suspend_report_result(fn, ret) do {} while (0) | 550 | #define suspend_report_result(fn, ret) do {} while (0) |
| 522 | 551 | ||
| 552 | static inline int device_pm_wait_for_dev(struct device *a, struct device *b) | ||
| 553 | { | ||
| 554 | return 0; | ||
| 555 | } | ||
| 523 | #endif /* !CONFIG_PM_SLEEP */ | 556 | #endif /* !CONFIG_PM_SLEEP */ |
| 524 | 557 | ||
| 525 | /* How to reorder dpm_list after device_move() */ | 558 | /* How to reorder dpm_list after device_move() */ |
| @@ -539,4 +572,11 @@ extern unsigned int pm_flags; | |||
| 539 | #define PM_APM 1 | 572 | #define PM_APM 1 |
| 540 | #define PM_ACPI 2 | 573 | #define PM_ACPI 2 |
| 541 | 574 | ||
| 575 | extern int pm_generic_suspend(struct device *dev); | ||
| 576 | extern int pm_generic_resume(struct device *dev); | ||
| 577 | extern int pm_generic_freeze(struct device *dev); | ||
| 578 | extern int pm_generic_thaw(struct device *dev); | ||
| 579 | extern int pm_generic_restore(struct device *dev); | ||
| 580 | extern int pm_generic_poweroff(struct device *dev); | ||
| 581 | |||
| 542 | #endif /* _LINUX_PM_H */ | 582 | #endif /* _LINUX_PM_H */ |
