diff options
| -rw-r--r-- | Documentation/power/runtime_pm.txt | 65 | ||||
| -rw-r--r-- | drivers/base/power/Makefile | 1 | ||||
| -rw-r--r-- | drivers/base/power/generic_ops.c | 233 | ||||
| -rw-r--r-- | include/linux/pm.h | 51 | ||||
| -rw-r--r-- | include/linux/pm_runtime.h | 6 |
5 files changed, 350 insertions, 6 deletions
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index f19370641684..ab00eeddecaf 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt | |||
| @@ -335,6 +335,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 335 | 'power.runtime_error' is set or 'power.disable_depth' is greater than | 335 | 'power.runtime_error' is set or 'power.disable_depth' is greater than |
| 336 | zero) | 336 | zero) |
| 337 | 337 | ||
| 338 | bool pm_runtime_suspended(struct device *dev); | ||
| 339 | - return true if the device's runtime PM status is 'suspended', or false | ||
| 340 | otherwise | ||
| 341 | |||
| 338 | void pm_runtime_allow(struct device *dev); | 342 | void pm_runtime_allow(struct device *dev); |
| 339 | - set the power.runtime_auto flag for the device and decrease its usage | 343 | - set the power.runtime_auto flag for the device and decrease its usage |
| 340 | counter (used by the /sys/devices/.../power/control interface to | 344 | counter (used by the /sys/devices/.../power/control interface to |
| @@ -459,3 +463,64 @@ The PM core always increments the run-time usage counter before calling the | |||
| 459 | ->prepare() callback and decrements it after calling the ->complete() callback. | 463 | ->prepare() callback and decrements it after calling the ->complete() callback. |
| 460 | Hence disabling run-time PM temporarily like this will not cause any run-time | 464 | Hence disabling run-time PM temporarily like this will not cause any run-time |
| 461 | suspend callbacks to be lost. | 465 | suspend callbacks to be lost. |
| 466 | |||
| 467 | 7. Generic subsystem callbacks | ||
| 468 | |||
| 469 | Subsystems may wish to conserve code space by using the set of generic power | ||
| 470 | management callbacks provided by the PM core, defined in | ||
| 471 | driver/base/power/generic_ops.c: | ||
| 472 | |||
| 473 | int pm_generic_runtime_idle(struct device *dev); | ||
| 474 | - invoke the ->runtime_idle() callback provided by the driver of this | ||
| 475 | device, if defined, and call pm_runtime_suspend() for this device if the | ||
| 476 | return value is 0 or the callback is not defined | ||
| 477 | |||
| 478 | int pm_generic_runtime_suspend(struct device *dev); | ||
| 479 | - invoke the ->runtime_suspend() callback provided by the driver of this | ||
| 480 | device and return its result, or return -EINVAL if not defined | ||
| 481 | |||
| 482 | int pm_generic_runtime_resume(struct device *dev); | ||
| 483 | - invoke the ->runtime_resume() callback provided by the driver of this | ||
| 484 | device and return its result, or return -EINVAL if not defined | ||
| 485 | |||
| 486 | int pm_generic_suspend(struct device *dev); | ||
| 487 | - if the device has not been suspended at run time, invoke the ->suspend() | ||
| 488 | callback provided by its driver and return its result, or return 0 if not | ||
| 489 | defined | ||
| 490 | |||
| 491 | int pm_generic_resume(struct device *dev); | ||
| 492 | - invoke the ->resume() callback provided by the driver of this device and, | ||
| 493 | if successful, change the device's runtime PM status to 'active' | ||
| 494 | |||
| 495 | int pm_generic_freeze(struct device *dev); | ||
| 496 | - if the device has not been suspended at run time, invoke the ->freeze() | ||
| 497 | callback provided by its driver and return its result, or return 0 if not | ||
| 498 | defined | ||
| 499 | |||
| 500 | int pm_generic_thaw(struct device *dev); | ||
| 501 | - if the device has not been suspended at run time, invoke the ->thaw() | ||
| 502 | callback provided by its driver and return its result, or return 0 if not | ||
| 503 | defined | ||
| 504 | |||
| 505 | int pm_generic_poweroff(struct device *dev); | ||
| 506 | - if the device has not been suspended at run time, invoke the ->poweroff() | ||
| 507 | callback provided by its driver and return its result, or return 0 if not | ||
| 508 | defined | ||
| 509 | |||
| 510 | int pm_generic_restore(struct device *dev); | ||
| 511 | - invoke the ->restore() callback provided by the driver of this device and, | ||
| 512 | if successful, change the device's runtime PM status to 'active' | ||
| 513 | |||
| 514 | These functions can be assigned to the ->runtime_idle(), ->runtime_suspend(), | ||
| 515 | ->runtime_resume(), ->suspend(), ->resume(), ->freeze(), ->thaw(), ->poweroff(), | ||
| 516 | or ->restore() callback pointers in the subsystem-level dev_pm_ops structures. | ||
| 517 | |||
| 518 | If a subsystem wishes to use all of them at the same time, it can simply assign | ||
| 519 | the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its | ||
| 520 | dev_pm_ops structure pointer. | ||
| 521 | |||
| 522 | Device drivers that wish to use the same function as a system suspend, freeze, | ||
| 523 | poweroff and run-time suspend callback, and similarly for system resume, thaw, | ||
| 524 | restore, and run-time resume, can achieve this with the help of the | ||
| 525 | UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its | ||
| 526 | last argument to NULL). | ||
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 3ce3519e8f30..89de75325cea 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | obj-$(CONFIG_PM) += sysfs.o | 1 | obj-$(CONFIG_PM) += sysfs.o |
| 2 | obj-$(CONFIG_PM_SLEEP) += main.o | 2 | obj-$(CONFIG_PM_SLEEP) += main.o |
| 3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o | 3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o |
| 4 | obj-$(CONFIG_PM_OPS) += generic_ops.o | ||
| 4 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o | 5 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o |
| 5 | 6 | ||
| 6 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG | 7 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG |
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c new file mode 100644 index 000000000000..4b29d4981253 --- /dev/null +++ b/drivers/base/power/generic_ops.c | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | /* | ||
| 2 | * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems | ||
| 3 | * | ||
| 4 | * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | ||
| 5 | * | ||
| 6 | * This file is released under the GPLv2. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/pm.h> | ||
| 10 | #include <linux/pm_runtime.h> | ||
| 11 | |||
| 12 | #ifdef CONFIG_PM_RUNTIME | ||
| 13 | /** | ||
| 14 | * pm_generic_runtime_idle - Generic runtime idle callback for subsystems. | ||
| 15 | * @dev: Device to handle. | ||
| 16 | * | ||
| 17 | * If PM operations are defined for the @dev's driver and they include | ||
| 18 | * ->runtime_idle(), execute it and return its error code, if nonzero. | ||
| 19 | * Otherwise, execute pm_runtime_suspend() for the device and return 0. | ||
| 20 | */ | ||
| 21 | int pm_generic_runtime_idle(struct device *dev) | ||
| 22 | { | ||
| 23 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 24 | |||
| 25 | if (pm && pm->runtime_idle) { | ||
| 26 | int ret = pm->runtime_idle(dev); | ||
| 27 | if (ret) | ||
| 28 | return ret; | ||
| 29 | } | ||
| 30 | |||
| 31 | pm_runtime_suspend(dev); | ||
| 32 | return 0; | ||
| 33 | } | ||
| 34 | EXPORT_SYMBOL_GPL(pm_generic_runtime_idle); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems. | ||
| 38 | * @dev: Device to suspend. | ||
| 39 | * | ||
| 40 | * If PM operations are defined for the @dev's driver and they include | ||
| 41 | * ->runtime_suspend(), execute it and return its error code. Otherwise, | ||
| 42 | * return -EINVAL. | ||
| 43 | */ | ||
| 44 | int pm_generic_runtime_suspend(struct device *dev) | ||
| 45 | { | ||
| 46 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 47 | int ret; | ||
| 48 | |||
| 49 | ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : -EINVAL; | ||
| 50 | |||
| 51 | return ret; | ||
| 52 | } | ||
| 53 | EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * pm_generic_runtime_resume - Generic runtime resume callback for subsystems. | ||
| 57 | * @dev: Device to resume. | ||
| 58 | * | ||
| 59 | * If PM operations are defined for the @dev's driver and they include | ||
| 60 | * ->runtime_resume(), execute it and return its error code. Otherwise, | ||
| 61 | * return -EINVAL. | ||
| 62 | */ | ||
| 63 | int pm_generic_runtime_resume(struct device *dev) | ||
| 64 | { | ||
| 65 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 66 | int ret; | ||
| 67 | |||
| 68 | ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : -EINVAL; | ||
| 69 | |||
| 70 | return ret; | ||
| 71 | } | ||
| 72 | EXPORT_SYMBOL_GPL(pm_generic_runtime_resume); | ||
| 73 | #endif /* CONFIG_PM_RUNTIME */ | ||
| 74 | |||
| 75 | #ifdef CONFIG_PM_SLEEP | ||
| 76 | /** | ||
| 77 | * __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. | ||
| 78 | * @dev: Device to handle. | ||
| 79 | * @event: PM transition of the system under way. | ||
| 80 | * | ||
| 81 | * If the device has not been suspended at run time, execute the | ||
| 82 | * suspend/freeze/poweroff/thaw callback provided by its driver, if defined, and | ||
| 83 | * return its error code. Otherwise, return zero. | ||
| 84 | */ | ||
| 85 | static int __pm_generic_call(struct device *dev, int event) | ||
| 86 | { | ||
| 87 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
| 88 | int (*callback)(struct device *); | ||
| 89 | |||
| 90 | if (!pm || pm_runtime_suspended(dev)) | ||
| 91 | return 0; | ||
| 92 | |||
| 93 | switch (event) { | ||
| 94 | |||
