diff options
| author | Rafael J. Wysocki <rjw@sisk.pl> | 2011-07-15 17:59:25 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rjw@sisk.pl> | 2011-07-15 17:59:25 -0400 |
| commit | 7ae033cc0dfce68d8e0c83aca60837cf2bf0d2e6 (patch) | |
| tree | 91bb3b8ae2790c7fef06b1832a7df61ae496a77a | |
| parent | ba1389d74f34c0c6e95cc135a332cd29c29d9c20 (diff) | |
| parent | c8c9fda5069456eb9e0e403c19764b2e257802e1 (diff) | |
Merge branch 'pm-runtime' into for-linus
* pm-runtime:
OMAP: PM: disable idle on suspend for GPIO and UART
OMAP: PM: omap_device: add API to disable idle on suspend
OMAP: PM: omap_device: add system PM methods for PM domain handling
OMAP: PM: omap_device: conditionally use PM domain runtime helpers
PM / Runtime: Add new helper function: pm_runtime_status_suspended()
PM / Runtime: Consistent utilization of deferred_resume
PM / Runtime: Prevent runtime_resume from racing with probe
PM / Runtime: Replace "run-time" with "runtime" in documentation
PM / Runtime: Improve documentation of enable, disable and barrier
PM: Limit race conditions between runtime PM and system sleep (v2)
PCI / PM: Detect early wakeup in pci_pm_prepare()
PM / Runtime: Return special error code if runtime PM is disabled
PM / Runtime: Update documentation of interactions with system sleep
| -rw-r--r-- | Documentation/power/devices.txt | 6 | ||||
| -rw-r--r-- | Documentation/power/runtime_pm.txt | 197 | ||||
| -rw-r--r-- | arch/arm/mach-omap2/gpio.c | 2 | ||||
| -rw-r--r-- | arch/arm/mach-omap2/serial.c | 1 | ||||
| -rw-r--r-- | arch/arm/plat-omap/include/plat/omap_device.h | 9 | ||||
| -rw-r--r-- | arch/arm/plat-omap/omap_device.c | 49 | ||||
| -rw-r--r-- | drivers/base/power/main.c | 35 | ||||
| -rw-r--r-- | drivers/base/power/runtime.c | 77 | ||||
| -rw-r--r-- | drivers/base/power/sysfs.c | 6 | ||||
| -rw-r--r-- | drivers/pci/pci-driver.c | 18 | ||||
| -rw-r--r-- | drivers/scsi/scsi_pm.c | 8 | ||||
| -rw-r--r-- | include/linux/pm_runtime.h | 6 |
12 files changed, 277 insertions, 137 deletions
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt index 85c6f980b642..3384d5996be2 100644 --- a/Documentation/power/devices.txt +++ b/Documentation/power/devices.txt | |||
| @@ -604,7 +604,7 @@ state temporarily, for example so that its system wakeup capability can be | |||
| 604 | disabled. This all depends on the hardware and the design of the subsystem and | 604 | disabled. This all depends on the hardware and the design of the subsystem and |
| 605 | device driver in question. | 605 | device driver in question. |
| 606 | 606 | ||
| 607 | During system-wide resume from a sleep state it's best to put devices into the | 607 | During system-wide resume from a sleep state it's easiest to put devices into |
| 608 | full-power state, as explained in Documentation/power/runtime_pm.txt. Refer to | 608 | the full-power state, as explained in Documentation/power/runtime_pm.txt. Refer |
| 609 | that document for more information regarding this particular issue as well as | 609 | to that document for more information regarding this particular issue as well as |
| 610 | for information on the device runtime power management framework in general. | 610 | for information on the device runtime power management framework in general. |
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index 4b011b171be4..14dd3c6ad97e 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt | |||
| @@ -1,39 +1,39 @@ | |||
| 1 | Run-time Power Management Framework for I/O Devices | 1 | Runtime Power Management Framework for I/O Devices |
| 2 | 2 | ||
| 3 | (C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | 3 | (C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
| 4 | (C) 2010 Alan Stern <stern@rowland.harvard.edu> | 4 | (C) 2010 Alan Stern <stern@rowland.harvard.edu> |
| 5 | 5 | ||
| 6 | 1. Introduction | 6 | 1. Introduction |
| 7 | 7 | ||
| 8 | Support for run-time power management (run-time PM) of I/O devices is provided | 8 | Support for runtime power management (runtime PM) of I/O devices is provided |
| 9 | at the power management core (PM core) level by means of: | 9 | at the power management core (PM core) level by means of: |
| 10 | 10 | ||
| 11 | * The power management workqueue pm_wq in which bus types and device drivers can | 11 | * The power management workqueue pm_wq in which bus types and device drivers can |
| 12 | put their PM-related work items. It is strongly recommended that pm_wq be | 12 | put their PM-related work items. It is strongly recommended that pm_wq be |
| 13 | used for queuing all work items related to run-time PM, because this allows | 13 | used for queuing all work items related to runtime PM, because this allows |
| 14 | them to be synchronized with system-wide power transitions (suspend to RAM, | 14 | them to be synchronized with system-wide power transitions (suspend to RAM, |
| 15 | hibernation and resume from system sleep states). pm_wq is declared in | 15 | hibernation and resume from system sleep states). pm_wq is declared in |
| 16 | include/linux/pm_runtime.h and defined in kernel/power/main.c. | 16 | include/linux/pm_runtime.h and defined in kernel/power/main.c. |
| 17 | 17 | ||
| 18 | * A number of run-time PM fields in the 'power' member of 'struct device' (which | 18 | * A number of runtime PM fields in the 'power' member of 'struct device' (which |
| 19 | is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can | 19 | is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can |
| 20 | be used for synchronizing run-time PM operations with one another. | 20 | be used for synchronizing runtime PM operations with one another. |
| 21 | 21 | ||
| 22 | * Three device run-time PM callbacks in 'struct dev_pm_ops' (defined in | 22 | * Three device runtime PM callbacks in 'struct dev_pm_ops' (defined in |
| 23 | include/linux/pm.h). | 23 | include/linux/pm.h). |
| 24 | 24 | ||
| 25 | * A set of helper functions defined in drivers/base/power/runtime.c that can be | 25 | * A set of helper functions defined in drivers/base/power/runtime.c that can be |
| 26 | used for carrying out run-time PM operations in such a way that the | 26 | used for carrying out runtime PM operations in such a way that the |
| 27 | synchronization between them is taken care of by the PM core. Bus types and | 27 | synchronization between them is taken care of by the PM core. Bus types and |
| 28 | device drivers are encouraged to use these functions. | 28 | device drivers are encouraged to use these functions. |
| 29 | 29 | ||
| 30 | The run-time PM callbacks present in 'struct dev_pm_ops', the device run-time PM | 30 | The runtime PM callbacks present in 'struct dev_pm_ops', the device runtime PM |
| 31 | fields of 'struct dev_pm_info' and the core helper functions provided for | 31 | fields of 'struct dev_pm_info' and the core helper functions provided for |
| 32 | run-time PM are described below. | 32 | runtime PM are described below. |
| 33 | 33 | ||
| 34 | 2. Device Run-time PM Callbacks | 34 | 2. Device Runtime PM Callbacks |
| 35 | 35 | ||
| 36 | There are three device run-time PM callbacks defined in 'struct dev_pm_ops': | 36 | There are three device runtime PM callbacks defined in 'struct dev_pm_ops': |
| 37 | 37 | ||
| 38 | struct dev_pm_ops { | 38 | struct dev_pm_ops { |
| 39 | ... | 39 | ... |
| @@ -72,11 +72,11 @@ knows what to do to handle the device). | |||
| 72 | not mean that the device has been put into a low power state. It is | 72 | not mean that the device has been put into a low power state. It is |
| 73 | supposed to mean, however, that the device will not process data and will | 73 | supposed to mean, however, that the device will not process data and will |
| 74 | not communicate with the CPU(s) and RAM until the subsystem-level resume | 74 | not communicate with the CPU(s) and RAM until the subsystem-level resume |
| 75 | callback is executed for it. The run-time PM status of a device after | 75 | callback is executed for it. The runtime PM status of a device after |
| 76 | successful execution of the subsystem-level suspend callback is 'suspended'. | 76 | successful execution of the subsystem-level suspend callback is 'suspended'. |
| 77 | 77 | ||
| 78 | * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, | 78 | * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, |
| 79 | the device's run-time PM status is 'active', which means that the device | 79 | the device's runtime PM status is 'active', which means that the device |
| 80 | _must_ be fully operational afterwards. | 80 | _must_ be fully operational afterwards. |
| 81 | 81 | ||
| 82 | * If the subsystem-level suspend callback returns an error code different | 82 | * If the subsystem-level suspend callback returns an error code different |
| @@ -104,7 +104,7 @@ the device). | |||
| 104 | 104 | ||
| 105 | * Once the subsystem-level resume callback has completed successfully, the PM | 105 | * Once the subsystem-level resume callback has completed successfully, the PM |
| 106 | core regards the device as fully operational, which means that the device | 106 | core regards the device as fully operational, which means that the device |
| 107 | _must_ be able to complete I/O operations as needed. The run-time PM status | 107 | _must_ be able to complete I/O operations as needed. The runtime PM status |
| 108 | of the device is then 'active'. | 108 | of the device is then 'active'. |
| 109 | 109 | ||
| 110 | * If the subsystem-level resume callback returns an error code, the PM core | 110 | * If the subsystem-level resume callback returns an error code, the PM core |
| @@ -130,7 +130,7 @@ device in that case. The value returned by this callback is ignored by the PM | |||
| 130 | core. | 130 | core. |
| 131 | 131 | ||
| 132 | The helper functions provided by the PM core, described in Section 4, guarantee | 132 | The helper functions provided by the PM core, described in Section 4, guarantee |
| 133 | that the following constraints are met with respect to the bus type's run-time | 133 | that the following constraints are met with respect to the bus type's runtime |
| 134 | PM callbacks: | 134 | PM callbacks: |
| 135 | 135 | ||
| 136 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute | 136 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute |
| @@ -142,7 +142,7 @@ PM callbacks: | |||
| 142 | 142 | ||
| 143 | (2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' | 143 | (2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' |
| 144 | devices (i.e. the PM core will only execute ->runtime_idle() or | 144 | devices (i.e. the PM core will only execute ->runtime_idle() or |
| 145 | ->runtime_suspend() for the devices the run-time PM status of which is | 145 | ->runtime_suspend() for the devices the runtime PM status of which is |
| 146 | 'active'). | 146 | 'active'). |
| 147 | 147 | ||
| 148 | (3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device | 148 | (3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device |
| @@ -151,7 +151,7 @@ PM callbacks: | |||
| 151 | flag of which is set. | 151 | flag of which is set. |
| 152 | 152 | ||
| 153 | (4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the | 153 | (4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the |
| 154 | PM core will only execute ->runtime_resume() for the devices the run-time | 154 | PM core will only execute ->runtime_resume() for the devices the runtime |
| 155 | PM status of which is 'suspended'). | 155 | PM status of which is 'suspended'). |
| 156 | 156 | ||
| 157 | Additionally, the helper functions provided by the PM core obey the following | 157 | Additionally, the helper functions provided by the PM core obey the following |
| @@ -171,9 +171,9 @@ rules: | |||
| 171 | scheduled requests to execute the other callbacks for the same device, | 171 | scheduled requests to execute the other callbacks for the same device, |
| 172 | except for scheduled autosuspends. | 172 | except for scheduled autosuspends. |
| 173 | 173 | ||
| 174 | 3. Run-time PM Device Fields | 174 | 3. Runtime PM Device Fields |
| 175 | 175 | ||
| 176 | The following device run-time PM fields are present in 'struct dev_pm_info', as | 176 | The following device runtime PM fields are present in 'struct dev_pm_info', as |
| 177 | defined in include/linux/pm.h: | 177 | defined in include/linux/pm.h: |
| 178 | 178 | ||
| 179 | struct timer_list suspend_timer; | 179 | struct timer_list suspend_timer; |
| @@ -205,7 +205,7 @@ defined in include/linux/pm.h: | |||
| 205 | 205 | ||
| 206 | unsigned int disable_depth; | 206 | unsigned int disable_depth; |
| 207 | - used for disabling the helper funcions (they work normally if this is | 207 | - used for disabling the helper funcions (they work normally if this is |
| 208 | equal to zero); the initial value of it is 1 (i.e. run-time PM is | 208 | equal to zero); the initial value of it is 1 (i.e. runtime PM is |
| 209 | initially disabled for all devices) | 209 | initially disabled for all devices) |
| 210 | 210 | ||
| 211 | unsigned int runtime_error; | 211 | unsigned int runtime_error; |
| @@ -229,10 +229,10 @@ defined in include/linux/pm.h: | |||
| 229 | suspend to complete; means "start a resume as soon as you've suspended" | 229 | suspend to complete; means "start a resume as soon as you've suspended" |
| 230 | 230 | ||
| 231 | unsigned int run_wake; | 231 | unsigned int run_wake; |
| 232 | - set if the device is capable of generating run-time wake-up events | 232 | - set if the device is capable of generating runtime wake-up events |
| 233 | 233 | ||
| 234 | enum rpm_status runtime_status; | 234 | enum rpm_status runtime_status; |
| 235 | - the run-time PM status of the device; this field's initial value is | 235 | - the runtime PM status of the device; this field's initial value is |
| 236 | RPM_SUSPENDED, which means that each device is initially regarded by the | 236 | RPM_SUSPENDED, which means that each device is initially regarded by the |
| 237 | PM core as 'suspended', regardless of its real hardware status | 237 | PM core as 'suspended', regardless of its real hardware status |
| 238 | 238 | ||
| @@ -243,7 +243,7 @@ defined in include/linux/pm.h: | |||
| 243 | and pm_runtime_forbid() helper functions | 243 | and pm_runtime_forbid() helper functions |
| 244 | 244 | ||
| 245 | unsigned int no_callbacks; | 245 | unsigned int no_callbacks; |
| 246 | - indicates that the device does not use the run-time PM callbacks (see | 246 | - indicates that the device does not use the runtime PM callbacks (see |
| 247 | Section 8); it may be modified only by the pm_runtime_no_callbacks() | 247 | Section 8); it may be modified only by the pm_runtime_no_callbacks() |
| 248 | helper function | 248 | helper function |
| 249 | 249 | ||
| @@ -270,16 +270,16 @@ defined in include/linux/pm.h: | |||
| 270 | 270 | ||
| 271 | All of the above fields are members of the 'power' member of 'struct device'. | 271 | All of the above fields are members of the 'power' member of 'struct device'. |
| 272 | 272 | ||
| 273 | 4. Run-time PM Device Helper Functions | 273 | 4. Runtime PM Device Helper Functions |
| 274 | 274 | ||
| 275 | The following run-time PM helper functions are defined in | 275 | The following runtime PM helper functions are defined in |
| 276 | drivers/base/power/runtime.c and include/linux/pm_runtime.h: | 276 | drivers/base/power/runtime.c and include/linux/pm_runtime.h: |
| 277 | 277 | ||
| 278 | void pm_runtime_init(struct device *dev); | 278 | void pm_runtime_init(struct device *dev); |
| 279 | - initialize the device run-time PM fields in 'struct dev_pm_info' | 279 | - initialize the device runtime PM fields in 'struct dev_pm_info' |
| 280 | 280 | ||
| 281 | void pm_runtime_remove(struct device *dev); | 281 | void pm_runtime_remove(struct device *dev); |
| 282 | - make sure that the run-time PM of the device will be disabled after | 282 | - make sure that the runtime PM of the device will be disabled after |
| 283 | removing the device from device hierarchy | 283 | removing the device from device hierarchy |
| 284 | 284 | ||
| 285 | int pm_runtime_idle(struct device *dev); | 285 | int pm_runtime_idle(struct device *dev); |
| @@ -289,9 +289,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 289 | 289 | ||
| 290 | int pm_runtime_suspend(struct device *dev); | 290 | int pm_runtime_suspend(struct device *dev); |
| 291 | - execute the subsystem-level suspend callback for the device; returns 0 on | 291 | - execute the subsystem-level suspend callback for the device; returns 0 on |
| 292 | success, 1 if the device's run-time PM status was already 'suspended', or | 292 | success, 1 if the device's runtime PM status was already 'suspended', or |
| 293 | error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt | 293 | error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt |
| 294 | to suspend the device again in future | 294 | to suspend the device again in future and -EACCES means that |
| 295 | 'power.disable_depth' is different from 0 | ||
| 295 | 296 | ||
| 296 | int pm_runtime_autosuspend(struct device *dev); | 297 | int pm_runtime_autosuspend(struct device *dev); |
| 297 | - same as pm_runtime_suspend() except that the autosuspend delay is taken | 298 | - same as pm_runtime_suspend() except that the autosuspend delay is taken |
| @@ -301,10 +302,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 301 | 302 | ||
| 302 | int pm_runtime_resume(struct device *dev); | 303 | int pm_runtime_resume(struct device *dev); |
| 303 | - execute the subsystem-level resume callback for the device; returns 0 on | 304 | - execute the subsystem-level resume callback for the device; returns 0 on |
| 304 | success, 1 if the device's run-time PM status was already 'active' or | 305 | success, 1 if the device's runtime PM status was already 'active' or |
| 305 | error code on failure, where -EAGAIN means it may be safe to attempt to | 306 | error code on failure, where -EAGAIN means it may be safe to attempt to |
| 306 | resume the device again in future, but 'power.runtime_error' should be | 307 | resume the device again in future, but 'power.runtime_error' should be |
| 307 | checked additionally | 308 | checked additionally, and -EACCES means that 'power.disable_depth' is |
| 309 | different from 0 | ||
| 308 | 310 | ||
| 309 | int pm_request_idle(struct device *dev); | 311 | int pm_request_idle(struct device *dev); |
| 310 | - submit a request to execute the subsystem-level idle callback for the | 312 | - submit a request to execute the subsystem-level idle callback for the |
| @@ -321,7 +323,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 321 | device in future, where 'delay' is the time to wait before queuing up a | 323 | device in future, where 'delay' is the time to wait before queuing up a |
| 322 | suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work | 324 | suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work |
| 323 | item is queued up immediately); returns 0 on success, 1 if the device's PM | 325 | item is queued up immediately); returns 0 on success, 1 if the device's PM |
| 324 | run-time status was already 'suspended', or error code if the request | 326 | runtime status was already 'suspended', or error code if the request |
| 325 | hasn't been scheduled (or queued up if 'delay' is 0); if the execution of | 327 | hasn't been scheduled (or queued up if 'delay' is 0); if the execution of |
| 326 | ->runtime_suspend() is already scheduled and not yet expired, the new | 328 | ->runtime_suspend() is already scheduled and not yet expired, the new |
| 327 | value of 'delay' will be used as the time to wait | 329 | value of 'delay' will be used as the time to wait |
| @@ -329,7 +331,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 329 | int pm_request_resume(struct device *dev); | 331 | int pm_request_resume(struct device *dev); |
| 330 | - submit a request to execute the subsystem-level resume callback for the | 332 | - submit a request to execute the subsystem-level resume callback for the |
| 331 | device (the request is represented by a work item in pm_wq); returns 0 on | 333 | device (the request is represented by a work item in pm_wq); returns 0 on |
| 332 | success, 1 if the device's run-time PM status was already 'active', or | 334 | success, 1 if the device's runtime PM status was already 'active', or |
| 333 | error code if the request hasn't been queued up | 335 | error code if the request hasn't been queued up |
| 334 | 336 | ||
| 335 | void pm_runtime_get_noresume(struct device *dev); | 337 | void pm_runtime_get_noresume(struct device *dev); |
| @@ -367,22 +369,32 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 367 | pm_runtime_autosuspend(dev) and return its result | 369 | pm_runtime_autosuspend(dev) and return its result |
| 368 | 370 | ||
| 369 | void pm_runtime_enable(struct device *dev); | 371 | void pm_runtime_enable(struct device *dev); |
| 370 | - enable the run-time PM helper functions to run the device bus type's | 372 | - decrement the device's 'power.disable_depth' field; if that field is equal |
| 371 | run-time PM callbacks described in Section 2 | 373 | to zero, the runtime PM helper functions can execute subsystem-level |
| 374 | callbacks described in Section 2 for the device | ||
| 372 | 375 | ||
| 373 | int pm_runtime_disable(struct device *dev); | 376 | int pm_runtime_disable(struct device *dev); |
| 374 | - prevent the run-time PM helper functions from running subsystem-level | 377 | - increment the device's 'power.disable_depth' field (if the value of that |
| 375 | run-time PM callbacks for the device, make sure that all of the pending | 378 | field was previously zero, this prevents subsystem-level runtime PM |
| 376 | run-time PM operations on the device are either completed or canceled; | 379 | callbacks from being run for the device), make sure that all of the pending |
| 380 | runtime PM operations on the device are either completed or canceled; | ||
| 377 | returns 1 if there was a resume request pending and it was necessary to | 381 | returns 1 if there was a resume request pending and it was necessary to |
| 378 | execute the subsystem-level resume callback for the device to satisfy that | 382 | execute the subsystem-level resume callback for the device to satisfy that |
| 379 | request, otherwise 0 is returned | 383 | request, otherwise 0 is returned |
| 380 | 384 | ||
| 385 | int pm_runtime_barrier(struct device *dev); | ||
| 386 | - check if there's a resume request pending for the device and resume it | ||
| 387 | (synchronously) in that case, cancel any other pending runtime PM requests | ||
| 388 | regarding it and wait for all runtime PM operations on it in progress to | ||
| 389 | complete; returns 1 if there was a resume request pending and it was | ||
| 390 | necessary to execute the subsystem-level resume callback for the device to | ||
| 391 | satisfy that request, otherwise 0 is returned | ||
| 392 | |||
| 381 | void pm_suspend_ignore_children(struct device *dev, bool enable); | 393 | void pm_suspend_ignore_children(struct device *dev, bool enable); |
| 382 | - set/unset the power.ignore_children flag of the device | 394 | - set/unset the power.ignore_children flag of the device |
| 383 | 395 | ||
| 384 | int pm_runtime_set_active(struct device *dev); | 396 | int pm_runtime_set_active(struct device *dev); |
| 385 | - clear the device's 'power.runtime_error' flag, set the device's run-time | 397 | - clear the device's 'power.runtime_error' flag, set the device's runtime |
| 386 | PM status to 'active' and update its parent's counter of 'active' | 398 | PM status to 'active' and update its parent's counter of 'active' |
| 387 | children as appropriate (it is only valid to use this function if | 399 | children as appropriate (it is only valid to use this function if |
| 388 | 'power.runtime_error' is set or 'power.disable_depth' is greater than | 400 | 'power.runtime_error' is set or 'power.disable_depth' is greater than |
| @@ -390,7 +402,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 390 | which is not active and the 'power.ignore_children' flag of which is unset | 402 | which is not active and the 'power.ignore_children' flag of which is unset |
| 391 | 403 | ||
| 392 | void pm_runtime_set_suspended(struct device *dev); | 404 | void pm_runtime_set_suspended(struct device *dev); |
| 393 | - clear the device's 'power.runtime_error' flag, set the device's run-time | 405 | - clear the device's 'power.runtime_error' flag, set the device's runtime |
| 394 | PM status to 'suspended' and update its parent's counter of 'active' | 406 | PM status to 'suspended' and update its parent's counter of 'active' |
| 395 | children as appropriate (it is only valid to use this function if | 407 | children as appropriate (it is only valid to use this function if |
| 396 | 'power.runtime_error' is set or 'power.disable_depth' is greater than | 408 | 'power.runtime_error' is set or 'power.disable_depth' is greater than |
| @@ -400,6 +412,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 400 | - return true if the device's runtime PM status is 'suspended' and its | 412 | - return true if the device's runtime PM status is 'suspended' and its |
| 401 | 'power.disable_depth' field is equal to zero, or false otherwise | 413 | 'power.disable_depth' field is equal to zero, or false otherwise |
| 402 | 414 | ||
| 415 | bool pm_runtime_status_suspended(struct device *dev); | ||
| 416 | - return true if the device's runtime PM status is 'suspended' | ||
| 417 | |||
| 403 | void pm_runtime_allow(struct device *dev); | 418 | void pm_runtime_allow(struct device *dev); |
| 404 | - set the power.runtime_auto flag for the device and decrease its usage | 419 | - set the power.runtime_auto flag for the device and decrease its usage |
| 405 | counter (used by the /sys/devices/.../power/control interface to | 420 | counter (used by the /sys/devices/.../power/control interface to |
| @@ -411,7 +426,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 411 | effectively prevent the device from being power managed at run time) | 426 | effectively prevent the device from being power managed at run time) |
| 412 | 427 | ||
| 413 | void pm_runtime_no_callbacks(struct device *dev); | 428 | void pm_runtime_no_callbacks(struct device *dev); |
| 414 | - set the power.no_callbacks flag for the device and remove the run-time | 429 | - set the power.no_callbacks flag for the device and remove the runtime |
| 415 | PM attributes from /sys/devices/.../power (or prevent them from being | 430 | PM attributes from /sys/devices/.../power (or prevent them from being |
| 416 | added when the device is registered) | 431 | added when the device is registered) |
| 417 | 432 | ||
| @@ -431,7 +446,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
| 431 | 446 | ||
| 432 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); | 447 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); |
| 433 | - set the power.autosuspend_delay value to 'delay' (expressed in | 448 | - set the power.autosuspend_delay value to 'delay' (expressed in |
| 434 | milliseconds); if 'delay' is negative then run-time suspends are | 449 | milliseconds); if 'delay' is negative then runtime suspends are |
| 435 | prevented | 450 | prevented |
| 436 | 451 | ||
| 437 | unsigned long pm_runtime_autosuspend_expiration(struct device *dev); | 452 | unsigned long pm_runtime_autosuspend_expiration(struct device *dev); |
| @@ -470,35 +485,35 @@ pm_runtime_resume() | |||
| 470 | pm_runtime_get_sync() | 485 | pm_runtime_get_sync() |
| 471 | pm_runtime_put_sync_suspend() | 486 | pm_runtime_put_sync_suspend() |
| 472 | 487 | ||
| 473 | 5. Run-time PM Initialization, Device Probing and Removal | 488 | 5. Runtime PM Initialization, Device Probing and Removal |
| 474 | 489 | ||
| 475 | Initially, the run-time PM is disabled for all devices, which means that the | 490 | Initially, the runtime PM is disabled for all devices, which means that the |
| 476 | majority of the run-time PM helper funtions described in Section 4 will return | 491 | majority of the runtime PM helper funtions described in Section 4 will return |
| 477 | -EAGAIN until pm_runtime_enable() is called for the device. | 492 | -EAGAIN until pm_runtime_enable() is called for the device. |
| 478 | 493 | ||
| 479 | In addition to that, the initial run-time PM status of all devices is | 494 | In addition to that, the initial runtime PM status of all devices is |
| 480 | 'suspended', but it need not reflect the actual physical state of the device. | 495 | 'suspended', but it need not reflect the actual physical state of the device. |
| 481 | Thus, if the device is initially active (i.e. it is able to process I/O), its | 496 | Thus, if the device is initially active (i.e. it is able to process I/O), its |
| 482 | run-time PM status must be changed to 'active', with the help of | 497 | runtime PM status must be changed to 'active', with the help of |
| 483 | pm_runtime_set_active(), before pm_runtime_enable() is called for the device. | 498 | pm_runtime_set_active(), before pm_runtime_enable() is called for the device. |
| 484 | 499 | ||
| 485 | However, if the device has a parent and the parent's run-time PM is enabled, | 500 | However, if the device has a parent and the parent's runtime PM is enabled, |
| 486 | calling pm_runtime_set_active() for the device will affect the parent, unless | 501 | calling pm_runtime_set_active() for the device will affect the parent, unless |
| 487 | the parent's 'power.ignore_children' flag is set. Namely, in that case the | 502 | the parent's 'power.ignore_children' flag is set. Namely, in that case the |
| 488 | parent won't be able to suspend at run time, using the PM core's helper | 503 | parent won't be able to suspend at run time, using the PM core's helper |
| 489 | functions, as long as the child's status is 'active', even if the child's | 504 | functions, as long as the child's status is 'active', even if the child's |
| 490 | run-time PM is still disabled (i.e. pm_runtime_enable() hasn't been called for | 505 | runtime PM is still disabled (i.e. pm_runtime_enable() hasn't been called for |
| 491 | the child yet or pm_runtime_disable() has been called for it). For this reason, | 506 | the child yet or pm_runtime_disable() has been called for it). For this reason, |
| 492 | once pm_runtime_set_active() has been called for the device, pm_runtime_enable() | 507 | once pm_runtime_set_active() has been called for the device, pm_runtime_enable() |
| 493 | should be called for it too as soon as reasonably possible or its run-time PM | 508 | should be called for it too as soon as reasonably possible or its runtime PM |
| 494 | status should be changed back to 'suspended' with the help of | 509 | status should be changed back to 'suspended' with the help of |
| 495 | pm_runtime_set_suspended(). | 510 | pm_runtime_set_suspended(). |
| 496 | 511 | ||
| 497 | If the default initial run-time PM status of the device (i.e. 'suspended') | 512 | If the default initial runtime PM status of the device (i.e. 'suspended') |
| 498 | reflects the actual state of the device, its bus type's or its driver's | 513 | reflects the actual state of the device, its bus type's or its driver's |
| 499 | ->probe() callback will likely need to wake it up using one of the PM core's | 514 | ->probe() callback will likely need to wake it up using one of the PM core's |
| 500 | helper functions described in Section 4. In that case, pm_runtime_resume() | 515 | helper functions described in Section 4. In that case, pm_runtime_resume() |
| 501 | should be used. Of course, for this purpose the device's run-time PM has to be | 516 | should be used. Of course, for this purpose the device's runtime PM has to be |
| 502 | enabled earlier by calling pm_runtime_enable(). | 517 | enabled earlier by calling pm_runtime_enable(). |
| 503 | 518 | ||
| 504 | If the device bus type's or driver's ->probe() callback runs | 519 | If the device bus type's or driver's ->probe() callback runs |
| @@ -529,33 +544,33 @@ The user space can effectively disallow the driver of the device to power manage | |||
| 529 | it at run time by changing the value of its /sys/devices/.../power/control | 544 | it at run time by changing the value of its /sys/devices/.../power/control |
| 530 | attribute to "on", which causes pm_runtime_forbid() to be called. In principle, | 545 | attribute to "on", which causes pm_runtime_forbid() to be called. In principle, |
| 531 | this mechanism may also be used by the driver to effectively turn off the | 546 | this mechanism may also be used by the driver to effectively turn off the |
| 532 | run-time power management of the device until the user space turns it on. | 547 | runtime power management of the device until the user space turns it on. |
| 533 | Namely, during the initialization the driver can make sure that the run-time PM | 548 | Namely, during the initialization the driver can make sure that the runtime PM |
| 534 | status of the device is 'active' and call pm_runtime_forbid(). It should be | 549 | status of the device is 'active' and call pm_runtime_forbid(). It should be |
| 535 | noted, however, that if the user space has already intentionally changed the | 550 | noted, however, that if the user space has already intentionally changed the |
| 536 | value of /sys/devices/.../power/control to "auto" to allow the driver to power | 551 | value of /sys/devices/.../power/control to "auto" to allow the driver to power |
| 537 | manage the device at run time, the driver may confuse it by using | 552 | manage the device at run time, the driver may confuse it by using |
| 538 | pm_runtime_forbid() this way. | 553 | pm_runtime_forbid() this way. |
| 539 | 554 | ||
| 540 | 6. Run-time PM and System Sleep | 555 | 6. Runtime PM and System Sleep |
| 541 | 556 | ||
| 542 | Run-time PM and system sleep (i.e., system suspend and hibernation, also known | 557 | Runtime PM and system sleep (i.e., system suspend and hibernation, also known |
| 543 | as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of | 558 | as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of |
| 544 | ways. If a device is active when a system sleep starts, everything is | 559 | ways. If a device is active when a system sleep starts, everything is |
| 545 | straightforward. But what should happen if the device is already suspended? | 560 | straightforward. But what should happen if the device is already suspended? |
| 546 | 561 | ||
| 547 | The device may have different wake-up settings for run-time PM and system sleep. | 562 | The device may have different wake-up settings for runtime PM and system sleep. |
| 548 | For example, remote wake-up may be enabled for run-time suspend but disallowed | 563 | For example, remote wake-up may be enabled for runtime suspend but disallowed |
| 549 | for system sleep (device_may_wakeup(dev) returns 'false'). When this happens, | 564 | for system sleep (device_may_wakeup(dev) returns 'false'). When this happens, |
| 550 | the subsystem-level system suspend callback is responsible for changing the | 565 | the subsystem-level system suspend callback is responsible for changing the |
| 551 | device's wake-up setting (it may leave that to the device driver's system | 566 | device's wake-up setting (it may leave that to the device driver's system |
| 552 | suspend routine). It may be necessary to resume the device and suspend it again | 567 | suspend routine). It may be necessary to resume the device and suspend it again |
| 553 | in order to do so. The same is true if the driver uses different power levels | 568 | in order to do so. The same is true if the driver uses different power levels |
| 554 | or other settings for run-time suspend and system sleep. | 569 | or other settings for runtime suspend and system sleep. |
| 555 | 570 | ||
| 556 | During system resume, devices generally should be brought back to full power, | 571 | During system resume, the simplest approach is to bring all devices back to full |
| 557 | even if they were suspended before the system sleep began. There are several | 572 | power, even if they had been suspended before the system suspend began. There |
| 558 | reasons for this, including: | 573 | are several reasons for this, including: |
| 559 | 574 | ||
| 560 | * The device might need to switch power levels, wake-up settings, etc. | 575 | * The device might need to switch power levels, wake-up settings, etc. |
| 561 | 576 | ||
| @@ -570,18 +585,50 @@ reasons for this, including: | |||
| 570 | * The device might need to be reset. | 585 | * The device might need to be reset. |
| 571 | 586 | ||
| 572 | * Even though the device was suspended, if its usage counter was > 0 then most | 587 | * Even though the device was suspended, if its usage counter was > 0 then most |
| 573 | likely it would need a run-time resume in the near future anyway. | 588 | likely it would need a runtime resume in the near future anyway. |
| 574 | 589 | ||
| 575 | * Always going back to full power is simplest. | 590 | If the device had been suspended before the system suspend began and it's |
| 576 | 591 | brought back to full power during resume, then its runtime PM status will have | |
| 577 | If the device was suspended before the sleep began, then its run-time PM status | 592 | to be updated to reflect the actual post-system sleep status. The way to do |
| 578 | will have to be updated to reflect the actual post-system sleep status. The way | 593 | this is: |
| 579 | to do this is: | ||
| 580 | 594 | ||
| 581 | pm_runtime_disable(dev); | 595 | pm_runtime_disable(dev); |
| 582 | pm_runtime_set_active(dev); | 596 | pm_runtime_set_active(dev); |
| 583 | pm_runtime_enable(dev); | 597 | pm_runtime_enable(dev); |
| 584 | 598 | ||
| 599 | The PM core always increments the runtime usage counter before calling the | ||
| 600 | ->suspend() callback and decrements it after calling the ->resume() callback. | ||
| 601 | Hence disabling runtime PM temporarily like this will not cause any runtime | ||
| 602 | suspend attempts to be permanently lost. If the usage count goes to zero | ||
| 603 | following the return of the ->resume() callback, the ->runtime_idle() callback | ||
| 604 | will be invoked as usual. | ||
| 605 | |||
| 606 | On some systems, however, system sleep is not entered through a global firmware | ||
| 607 | or hardware operation. Instead, all hardware components are put into low-power | ||
| 608 | states directly by the kernel in a coordinated way. Then, the system sleep | ||
| 609 | state effectively follows from the states the hardware components end up in | ||
| 610 | and the system is woken up from that state by a hardware interrupt or a similar | ||
| 611 | mechanism entirely under the kernel's control. As a result, the kernel never | ||
| 612 | gives control away and the states of all devices during resume are precisely | ||
| 613 | known to it. If that is the case and none of the situations listed above takes | ||
| 614 | place (in particular, if the system is not waking up from hibernation), it may | ||
| 615 | be more efficient to leave the devices that had been suspended before the system | ||
| 616 | suspend began in the suspended state. | ||
| 617 | |||
| 618 | The PM core does its best to reduce the probability of race conditions between | ||
| 619 | the runtime PM and system suspend/resume (and hibernation) callbacks by carrying | ||
| 620 | out the following operations: | ||
| 621 | |||
| 622 | * During system suspend it calls pm_runtime_get_noresume() and | ||
| 623 | pm_runtime_barrier() for every device right before executing the | ||
| 624 | subsystem-level .suspend() callback for it. In addition to that it calls | ||
| 625 | pm_runtime_disable() for every device right after executing the | ||
| 626 | subsystem-level .suspend() callback for it. | ||
| 627 | |||
| 628 | * During system resume it calls pm_runtime_enable() and pm_runtime_put_sync() | ||
| 629 | for every device right before and right after executing the subsystem-level | ||
| 630 | .resume() callback for it, respectively. | ||
| 631 | |||
| 585 | 7. Generic subsystem callbacks | 632 | 7. Generic subsystem callbacks |
| 586 | 633 | ||
| 587 | Subsystems may wish to conserve code space by using the set of generic power | 634 | Subsystems may wish to conserve code space by using the set of generic power |
| @@ -666,8 +713,8 @@ the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its | |||
| 666 | dev_pm_ops structure pointer. | 713 | dev_pm_ops structure pointer. |
| 667 | 714 | ||
| 668 | Device drivers that wish to use the same function as a system suspend, freeze, | 715 | Device drivers that wish to use the same function as a system suspend, freeze, |
| 669 | poweroff and run-time suspend callback, and similarly for system resume, thaw, | 716 | poweroff and runtime suspend callback, and similarly for system resume, thaw, |
| 670 | restore, and run-time resume, can achieve this with the help of the | 717 | restore, and runtime resume, can achieve this with the help of the |
| 671 | UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its | 718 | UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its |
| 672 | last argument to NULL). | 719 | last argument to NULL). |
| 673 | 720 | ||
| @@ -677,7 +724,7 @@ Some "devices" are only logical sub-devices of their parent and cannot be | |||
| 677 | power-managed on their own. (The prototype example is a USB interface. Entire | 724 | power-managed on their own. (The prototype example is a USB interface. Entire |
| 678 | USB devices can go into low-power mode or send wake-up requests, but neither is | 725 | USB devices can go into low-power mode or send wake-up requests, but neither is |
| 679 | possible for individual interfaces.) The drivers for these devices have no | 726 | possible for individual interfaces.) The drivers for these devices have no |
| 680 | need of run-time PM callbacks; if the callbacks did exist, ->runtime_suspend() | 727 | need of runtime PM callbacks; if the callbacks did exist, ->runtime_suspend() |
| 681 | and ->runtime_resume() would always return 0 without doing anything else and | 728 | and ->runtime_resume() would always return 0 without doing anything else and |
| 682 | ->runtime_idle() would always call pm_runtime_suspend(). | 729 | ->runtime_idle() would always call pm_runtime_suspend(). |
| 683 | 730 | ||
| @@ -685,7 +732,7 @@ Subsystems can tell the PM core about these devices by calling | |||
| 685 | pm_runtime_no_callbacks(). This should be done after the device structure is | 732 | pm_runtime_no_callbacks(). This should be done after the device structure is |
| 686 | initialized and before it is registered (although after device registration is | 733 | initialized and before it is registered (although after device registration is |
| 687 | also okay). The routine will set the device's power.no_callbacks flag and | 734 | also okay). The routine will set the device's power.no_callbacks flag and |
| 688 | prevent the non-debugging run-time PM sysfs attributes from being created. | 735 | prevent the non-debugging runtime PM sysfs attributes from being created. |
| 689 | 736 | ||
| 690 | When power.no_callbacks is set, the PM core will not invoke the | 737 | When power.no_callbacks is set, the PM core will not invoke the |
| 691 | ->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks. | 738 | ->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks. |
| @@ -693,7 +740,7 @@ Instead it will assume that suspends and resumes always succeed and that idle | |||
| 693 | devices should be suspended. | 740 | devices should be suspended. |
| 694 | 741 | ||
| 695 | As a consequence, the PM core will never directly inform the device's subsystem | 742 | As a consequence, the PM core will never directly inform the device's subsystem |
| 696 | or driver about run-time power changes. Instead, the driver for the device's | 743 | or driver about runtime power changes. Instead, the driver for the device's |
| 697 | parent must take responsibility for telling the device's driver when the | 744 | parent must take responsibility for telling the device's driver when the |
| 698 | parent's power state changes. | 745 | parent's power state changes. |
| 699 | 746 | ||
| @@ -704,13 +751,13 @@ A device should be put in a low-power state only when there's some reason to | |||
| 704 | think it will remain in that state for a substantial time. A common heuristic | 751 | think it will remain in that state for a substantial time. A common heuristic |
| 705 | says that a device which hasn't been used for a while is liable to remain | 752 | says that a device which hasn't been used for a while is liable to remain |
| 706 | unused; following this advice, drivers should not allow devices to be suspended | 753 | unused; following this advice, drivers should not allow devices to be suspended |
| 707 | at run-time until they have been inactive for some minimum period. Even when | 754 | at runtime until they have been inactive for some minimum period. Even when |
| 708 | the heuristic ends up being non-optimal, it will still prevent devices from | 755 | the heuristic ends up being non-optimal, it will still prevent devices from |
| 709 | "bouncing" too rapidly between low-power and full-power states. | 756 | "bouncing" too rapidly between low-power and full-power states. |
| 710 | 757 | ||
| 711 | The term "autosuspend" is an historical remnant. It doesn't mean that the | 758 | The term "autosuspend" is an historical remnant. It doesn't mean that the |
| 712 | device is automatically suspended (the subsystem or driver still has to call | 759 | device is automatically suspended (the subsystem or driver still has to call |
| 713 | the appropriate PM routines); rather it means that run-time suspends will | 760 | the appropriate PM routines); rather it means that runtime suspends will |
| 714 | automatically be delayed until the desired period of inactivity has elapsed. | 761 | automatically be delayed until the desired period of inactivity has elapsed. |
| 715 | 762 | ||
| 716 | Inactivity is determined based on the power.last_busy field. Drivers should | 763 | Inactivity is determined based on the power.last_busy field. Drivers should |
diff --git a/arch/arm/mach-omap2/gpio.c b/arch/arm/mach-omap2/gpio.c index 9529842ae054..48e5eced6b51 100644 --- a/arch/arm/mach-omap2/gpio.c +++ b/arch/arm/mach-omap2/gpio.c | |||
| @@ -87,6 +87,8 @@ static int omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) | |||
| 87 | return PTR_ERR(od); | 87 | return PTR_ERR(od); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | omap_device_disable_idle_on_suspend(od); | ||
| 91 | |||
| 90 | gpio_bank_count++; | 92 | gpio_bank_count++; |
| 91 | return 0; | 93 | return 0; |
| 92 | } | 94 | } |
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c index 1ac361b7b8cb..466fc722fa0f 100644 --- a/arch/arm/mach-omap2/serial.c +++ b/arch/arm/mach-omap2/serial.c | |||
| @@ -805,6 +805,7 @@ void __init omap_serial_init_port(struct omap_board_data *bdata) | |||
| 805 | WARN(IS_ERR(od), "Could not build omap_device for %s: %s.\n", | 805 | WARN(IS_ERR(od), "Could not build omap_device for %s: %s.\n", |
| 806 | name, oh->name); | 806 | name, oh->name); |
| 807 | 807 | ||
| 808 | omap_device_disable_idle_on_suspend(od); | ||
| 808 | oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt); | 809 | oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt); |
| 809 | 810 | ||
| 810 | uart->irq = oh->mpu_irqs[0].irq; | 811 | uart->irq = oh->mpu_irqs[0].irq; |
diff --git a/arch/arm/plat-omap/include/plat/omap_device.h b/arch/arm/plat-omap/include/plat/omap_device.h index e4c349ff9fd8..ee405b36df4b 100644 --- a/arch/arm/plat-omap/include/plat/omap_device.h +++ b/arch/arm/plat-omap/include/plat/omap_device.h | |||
| @@ -44,6 +44,10 @@ extern struct device omap_device_parent; | |||
| 44 | #define OMAP_DEVICE_STATE_IDLE 2 | 44 | #define OMAP_DEVICE_STATE_IDLE 2 |
| 45 | #define OMAP_DEVICE_STATE_SHUTDOWN 3 | 45 | #define OMAP_DEVICE_STATE_SHUTDOWN 3 |
| 46 | 46 | ||
| 47 | /* omap_device.flags values */ | ||
| 48 | #define OMAP_DEVICE_SUSPENDED BIT(0) | ||
| 49 | #define OMAP_DEVICE_NO_IDLE_ON_SUSPEND BIT(1) | ||
| 50 | |||
| 47 | /** | 51 | /** |
| 48 | * struct omap_device - omap_device wrapper for platform_devices | 52 | * struct omap_device - omap_device wrapper for platform_devices |
| 49 | * @pdev: platform_device | 53 | * @pdev: platform_device |
| @@ -73,6 +77,7 @@ struct omap_device { | |||
| 73 | s8 pm_lat_level; | 77 | s8 pm_lat_level; |
| 74 | u8 hwmods_cnt; | 78 | u8 hwmods_cnt; |
| 75 | u8 _state; | 79 | u8 _state; |
| 80 | u8 flags; | ||
| 76 | }; | 81 | }; |
| 77 | 82 | ||
| 78 | /* Device driver interface (call via platform_data fn ptrs) */ | 83 | /* Device driver interface (call via platform_data fn ptrs) */ |
| @@ -117,6 +122,10 @@ int omap_device_enable_hwmods(struct omap_device *od); | |||
| 117 | int omap_device_disable_clocks(struct omap_device *od); | 122 | int omap_device_disable_clocks(struct omap_device *od); |
| 118 | int omap_device_enable_clocks(struct omap_device *od); | 123 | int omap_device_enable_clocks(struct omap_device *od); |
| 119 | 124 | ||
| 125 | static inline void omap_device_disable_idle_on_suspend(struct omap_device *od) | ||
| 126 | { | ||
| 127 | od->flags |= OMAP_DEVICE_NO_IDLE_ON_SUSPEND; | ||
| 128 | } | ||
| 120 | 129 | ||
| 121 | /* | 130 | /* |
| 122 | * Entries should be kept in latency order ascending | 131 | * Entries should be kept in latency order ascending |
diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c index d21579b2c11e..2526fa312b8a 100644 --- a/arch/arm/plat-omap/omap_device.c +++ b/arch/arm/plat-omap/omap_device.c | |||
| @@ -537,6 +537,7 @@ int omap_early_device_register(struct omap_device *od) | |||
| 537 | return 0; | 537 | return 0; |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | #ifdef CONFIG_PM_RUNTIME | ||
| 540 | static int _od_runtime_suspend(struct device *dev) | 541 | static int _od_runtime_suspend(struct device *dev) |
| 541 | { | 542 | { |
| 542 | struct platform_device *pdev = to_platform_device(dev); | 543 | struct platform_device *pdev = to_platform_device(dev); |
| @@ -563,13 +564,55 @@ static int _od_runtime_resume(struct device *dev) | |||
| 563 | 564 | ||
| 564 | return pm_generic_runtime_resume(dev); | 565 | return pm_generic_runtime_resume(dev); |
| 565 | } | 566 | } |
| 567 | #endif | ||
| 568 | |||
| 569 | #ifdef CONFIG_SUSPEND | ||
| 570 | static int _od_suspend_noirq(struct device *dev) | ||
| 571 | { | ||
| 572 | struct platform_device *pdev = to_platform_device(dev); | ||
| 573 | struct omap_device *od = to_omap_device(pdev); | ||
| 574 | int ret; | ||
| 575 | |||
| 576 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) | ||
| 577 | return pm_generic_suspend_noirq(dev); | ||
| 578 | |||
| 579 | ret = pm_generic_suspend_noirq(dev); | ||
| 580 | |||
| 581 | if (!ret && !pm_runtime_status_suspended(dev)) { | ||
| 582 | if (pm_generic_runtime_suspend(dev) == 0) { | ||
| 583 | omap_device_idle(pdev); | ||
| 584 | od->flags |= OMAP_DEVICE_SUSPENDED; | ||
| 585 | } | ||
| 586 | } | ||
| 587 | |||
| 588 | return ret; | ||
| 589 | } | ||
| 590 | |||
| 591 | static int _od_resume_noirq(struct device *dev) | ||
| 592 | { | ||
| 593 | struct platform_device *pdev = to_platform_device(dev); | ||
| 594 | struct omap_device *od = to_omap_device(pdev); | ||
| 595 | |||
| 596 | if (od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND) | ||
| 597 | return pm_generic_resume_noirq(dev); | ||
| 598 | |||
| 599 | if ((od->flags & OMAP_DEVICE_SUSPENDED) && | ||
| 600 | !pm_runtime_status_suspended(dev)) { | ||
| 601 | od->flags &= ~OMAP_DEVICE_SUSPENDED; | ||
| 602 | omap_device_enable(pdev); | ||
| 603 | pm_generic_runtime_resume(dev); | ||
| 604 | } | ||
| 605 | |||
| 606 | return pm_generic_resume_noirq(dev); | ||
| 607 | } | ||
| 608 | #endif | ||
| 566 | 609 | ||
| 567 | static struct dev_pm_domain omap_device_pm_domain = { | 610 | static struct dev_pm_domain omap_device_pm_domain = { |
| 568 | .ops = { | 611 | .ops = { |
| 569 | .runtime_suspend = _od_runtime_suspend, | 612 | SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume, |
| 570 | .runtime_idle = _od_runtime_idle, | 613 | _od_runtime_idle) |
| 571 | .runtime_resume = _od_runtime_resume, | ||
| 572 | USE_PLATFORM_PM_SLEEP_OPS | 614 | USE_PLATFORM_PM_SLEEP_OPS |
| 615 | SET_SYSTEM_SLEEP_PM_OPS(_od_suspend_noirq, _od_resume_noirq) | ||
| 573 | } | 616 | } |
| 574 | }; | 617 | }; |
| 575 | 618 | ||
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 85b591a5429a..a85459126bc6 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
| @@ -505,6 +505,7 @@ static int legacy_resume(struct device *dev, int (*cb)(struct device *dev)) | |||
| 505 | static int device_resume(struct device *dev, pm_message_t state, bool async) | 505 | static int device_resume(struct device *dev, pm_message_t state, bool async) |
| 506 | { | 506 | { |
| 507 | int error = 0; | 507 | int error = 0; |
| 508 | bool put = false; | ||
| 508 | 509 | ||
| 509 | TRACE_DEVICE(dev); | 510 | TRACE_DEVICE(dev); |
| 510 | TRACE_RESUME(0); | 511 | TRACE_RESUME(0); |
| @@ -521,6 +522,9 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
| 521 | if (!dev->power.is_suspended) | 522 | if (!dev->power.is_suspended) |
| 522 | goto Unlock; | 523 | goto Unlock; |
| 523 | 524 | ||
| 525 | pm_runtime_enable(dev); | ||
| 526 | put = true; | ||
| 527 | |||
| 524 | if (dev->pm_domain) { | 528 | if (dev->pm_domain) { |
| 525 | pm_dev_dbg(dev, state, "power domain "); | 529 | pm_dev_dbg(dev, state, "power domain "); |
| 526 | error = pm_op(dev, &dev->pm_domain->ops, state); | 530 | error = pm_op(dev, &dev->pm_domain->ops, state); |
| @@ -563,6 +567,10 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
| 563 | complete_all(&dev->power.completion); | 567 | complete_all(&dev->power.completion); |
| 564 | 568 | ||
| 565 | TRACE_RESUME(error); | 569 | TRACE_RESUME(error); |
| 570 | |||
| 571 | if (put) | ||
| 572 | pm_runtime_put_sync(dev); | ||
| 573 | |||
| 566 | return error; | 574 | return error; |
| 567 | } | 575 | } |
| 568 | 576 | ||
| @@ -843,16 +851,22 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
| 843 | int error = 0; | 851 | int error = 0; |
| 844 | 852 | ||
| 845 | dpm_wait_for_children(dev, async); | 853 | dpm_wait_for_children(dev, async); |
| 846 | device_lock(dev); | ||
| 847 | 854 | ||
| 848 | if (async_error) | 855 | if (async_error) |
| 849 | goto Unlock; | 856 | return 0; |
| 857 | |||
| 858 | pm_runtime_get_noresume(dev); | ||
| 859 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
| 860 | pm_wakeup_event(dev, 0); | ||
| 850 | 861 | ||
| 851 | if (pm_wakeup_pending()) { | 862 | if (pm_wakeup_pending()) { |
| 863 | pm_runtime_put_sync(dev); | ||
| 852 | async_error = -EBUSY; | 864 | async_error = -EBUSY; |
| 853 | goto Unlock; | 865 | return 0; |
| 854 | } | 866 | } |
| 855 | 867 | ||
| 868 | device_lock(dev); | ||
| 869 | |||
| 856 | if (dev->pm_domain) { | 870 | if (dev->pm_domain) { |
| 857 | pm_dev_dbg(dev, state, "power domain "); | 871 | pm_dev_dbg(dev, state, "power domain "); |
| 858 | error = pm_op(dev, &dev->pm_domain->ops, state); | 872 | error = pm_op(dev, &dev->pm_domain->ops, state); |
| @@ -890,12 +904,15 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
| 890 | End: | 904 | End: |
| 891 | dev->power.is_suspended = !error; | 905 | dev->power.is_suspended = !error; |
| 892 | 906 | ||
| 893 | Unlock: | ||
| 894 | device_unlock(dev); | 907 | device_unlock(dev); |
| 895 | complete_all(&dev->power.completion); | 908 | complete_all(&dev->power.completion); |
| 896 | 909 | ||
| 897 | if (error) | 910 | if (error) { |
| 911 | pm_runtime_put_sync(dev); | ||
| 898 | async_error = error; | 912 | async_error = error; |
| 913 | } else if (dev->power.is_suspended) { | ||
| 914 | __pm_runtime_disable(dev, false); | ||
| 915 | } | ||
| 899 | 916 | ||
| 900 | return error; | 917 | return error; |
| 901 | } | 918 | } |
| @@ -1035,13 +1052,7 @@ int dpm_prepare(pm_message_t state) | |||
| 1035 | get_device(dev); | 1052 | get_device(dev); |
| 1036 | mutex_unlock(&dpm_list_mtx); | 1053 | mutex_unlock(&dpm_list_mtx); |
| 1037 | 1054 | ||
| 1038 | pm_runtime_get_noresume(dev); | 1055 | error = device_prepare(dev, state); |
| 1039 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
| 1040 | pm_wakeup_event(dev, 0); | ||
| 1041 | |||
| 1042 | pm_runtime_put_sync(dev); | ||
| 1043 | error = pm_wakeup_pending() ? | ||
| 1044 | -EBUSY : device_prepare(dev, state); | ||
| 1045 | 1056 | ||
| 1046 | mutex_lock(&dpm_list_mtx); | 1057 | mutex_lock(&dpm_list_mtx); |
| 1047 | if (error) { | 1058 | if (error) { |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 5f5c4236f006..8dc247c974af 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * drivers/base/power/runtime.c - Helper functions for device run-time PM | 2 | * drivers/base/power/runtime.c - Helper functions for device runtime PM |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | 4 | * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
| 5 | * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu> | 5 | * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu> |
| @@ -135,8 +135,9 @@ static int rpm_check_suspend_allowed(struct device *dev) | |||
| 135 | 135 | ||
| 136 | if (dev->power.runtime_error) | 136 | if (dev->power.runtime_error) |
| 137 | retval = -EINVAL; | 137 | retval = -EINVAL; |
| 138 | else if (atomic_read(&dev->power.usage_count) > 0 | 138 | else if (dev->power.disable_depth > 0) |
| 139 | || dev->power.disable_depth > 0) | 139 | retval = -EACCES; |
| 140 | else if (atomic_read(&dev->power.usage_count) > 0) | ||
| 140 | retval = -EAGAIN; | 141 | retval = -EAGAIN; |
| 141 | else if (!pm_children_suspended(dev)) | 142 | else if (!pm_children_suspended(dev)) |
| 142 | retval = -EBUSY; | 143 | retval = -EBUSY; |
| @@ -158,7 +159,7 @@ static int rpm_check_suspend_allowed(struct device *dev) | |||
| 158 | * @dev: Device to notify the bus type about. | 159 | * @dev: Device to notify the bus type about. |
| 159 | * @rpmflags: Flag bits. | 160 | * @rpmflags: Flag bits. |
| 160 | * | 161 | * |
| 161 | * Check if the device's run-time PM status allows it to be suspended. If | 162 | * Check if the device's runtime PM status allows it to be suspended. If |
| 162 | * another idle notification has been started earlier, return immediately. If | 163 | * another idle notification has been started earlier, return immediately. If |
| 163 | * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise | 164 | * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise |
| 164 | * run the ->runtime_idle() callback directly. | 165 | * run the ->runtime_idle() callback directly. |
| @@ -262,15 +263,15 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev) | |||
| 262 | spin_lock_irq(&dev->power.lock); | 263 | spin_lock_irq(&dev->power.lock); |
| 263 | } | 264 | } |
| 264 | dev->power.runtime_error = retval; | 265 | dev->power.runtime_error = retval; |
| 265 | return retval; | 266 | return retval != -EACCES ? retval : -EIO; |
| 266 | } | 267 | } |
| 267 | 268 | ||
| 268 | /** | 269 | /** |
| 269 | * rpm_suspend - Carry out run-time suspend of given device. | 270 | * rpm_suspend - Carry out runtime suspend of given device. |
| 270 | * @dev: Device to suspend. | 271 | * @dev: Device to suspend. |
| 271 | * @rpmflags: Flag bits. | 272 | * @rpmflags: Flag bits. |
| 272 | * | 273 | * |
| 273 | * Check if the device's run-time PM status allows it to be suspended. If | 274 | * Check if the device's runtime PM status allows it to be suspended. If |
| 274 | * another suspend has been started earlier, either return immediately or wait | 275 | * another suspend has been started earlier, either return immediately or wait |
| 275 | * for it to finish, depending on the RPM_NOWAIT and RPM_ASYNC flags. Cancel a | 276 | * for it to finish, depending on the RPM_NOWAIT and RPM_ASYNC flags. Cancel a |
| 276 | * pending idle notification. If the RPM_ASYNC flag is set then queue a | 277 | * pending idle notification. If the RPM_ASYNC flag is set then queue a |
| @@ -388,7 +389,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
| 388 | retval = rpm_callback(callback, dev); | 389 | retval = rpm_callback(callback, dev); |
| 389 | if (retval) { | 390 | if (retval) { |
| 390 | __update_runtime_status(dev, RPM_ACTIVE); | 391 | __update_runtime_status(dev, RPM_ACTIVE); |
| 391 | dev->power.deferred_resume = 0; | 392 | dev->power.deferred_resume = false; |
| 392 | if (retval == -EAGAIN || retval == -EBUSY) | 393 | if (retval == -EAGAIN || retval == -EBUSY) |
| 393 | dev->power.runtime_error = 0; | 394 | dev->power.runtime_error = 0; |
| 394 | else | 395 | else |
| @@ -429,11 +430,11 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
| 429 | } | 430 | } |
| 430 | 431 | ||
| 431 | /** | 432 | /** |
| 432 | * rpm_resume - Carry out run-time resume of given device. | 433 | * rpm_resume - Carry out runtime resume of given device. |
| 433 | * @dev: Device to resume. | 434 | * @dev: Device to resume. |
| 434 | * @rpmflags: Flag bits. | 435 | * @rpmflags: Flag bits. |
| 435 | * | 436 | * |
| 436 | * Check if the device's run-time PM status allows it to be resumed. Cancel | 437 | * Check if the device's runtime PM status allows it to be resumed. Cancel |
| 437 | * any scheduled or pending requests. If another resume has been started | 438 | * any scheduled or pending requests. If another resume has been started |
| 438 | * earlier, either return immediately or wait for it to finish, depending on the | 439 | * earlier, either return immediately or wait for it to finish, depending on the |
| 439 | * RPM_NOWAIT and RPM_ASYNC flags. Similarly, if there's a suspend running in | 440 | * RPM_NOWAIT and RPM_ASYNC flags. Similarly, if there's a suspend running in |
| @@ -458,7 +459,7 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
| 458 | if (dev->power.runtime_error) | 459 | if (dev->power.runtime_error) |
| 459 | retval = -EINVAL; | 460 | retval = -EINVAL; |
| 460 | else if (dev->power.disable_depth > 0) | 461 | else if (dev->power.disable_depth > 0) |
| 461 | retval = -EAGAIN; | 462 | retval = -EACCES; |
| 462 | if (retval) | 463 | if (retval) |
| 463 | goto out; | 464 | goto out; |
| 464 | 465 | ||
| @@ -550,7 +551,7 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
| 550 | 551 | ||
| 551 | spin_lock(&parent->power.lock); | 552 | spin_lock(&parent->power.lock); |
| 552 | /* | 553 | /* |
| 553 | * We can resume if the parent's run-time PM is disabled or it | 554 | * We can resume if the parent's runtime PM is disabled or it |
| 554 | * is set to ignore children. | 555 | * is set to ignore children. |
| 555 | */ | 556 | */ |
| 556 | if (!parent->power.disable_depth | 557 | if (!parent->power.disable_depth |
| @@ -614,11 +615,11 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
| 614 | } | 615 | } |
| 615 | 616 | ||
| 616 | /** | 617 | /** |
| 617 | * pm_runtime_work - Universal run-time PM work function. | 618 | * pm_runtime_work - Universal runtime PM work function. |
| 618 | * @work: Work structure used for scheduling the execution of this function. | 619 | * @work: Work structure used for scheduling the execution of this function. |
| 619 | * | 620 | * |
| 620 | * Use @work to get the device object the work is to be done for, determine what | 621 | * Use @work to get the device object the work is to be done for, determine what |
| 621 | * is to be done and execute the appropriate run-time PM function. | 622 | * is to be done and execute the appropriate runtime PM function. |
| 622 | */ | 623 | */ |
| 623 | static void pm_runtime_work(struct work_struct *work) | 624 | static void pm_runtime_work(struct work_struct *work) |
| 624 | { | 625 | { |
| @@ -717,7 +718,7 @@ int pm_schedule_suspend(struct device *dev, unsigned int delay) | |||
| 717 | EXPORT_SYMBOL_GPL(pm_schedule_suspend); | 718 | EXPORT_SYMBOL_GPL(pm_schedule_suspend); |
| 718 | 719 | ||
| 719 | /** | 720 | /** |
| 720 | * __pm_runtime_idle - Entry point for run-time idle operations. | 721 | * __pm_runtime_idle - Entry point for runtime idle operations. |
| 721 | * @dev: Device to send idle notification for. | 722 | * @dev: Device to send idle notification for. |
| 722 | * @rpmflags: Flag bits. | 723 | * @rpmflags: Flag bits. |
| 723 | * | 724 | * |
| @@ -746,7 +747,7 @@ int __pm_runtime_idle(struct device *dev, int rpmflags) | |||
| 746 | EXPORT_SYMBOL_GPL(__pm_runtime_idle); | 747 | EXPORT_SYMBOL_GPL(__pm_runtime_idle); |
| 747 | 748 | ||
| 748 | /** | 749 | /** |
| 749 | * __pm_runtime_suspend - Entry point for run-time put/suspend operations. | 750 | * __pm_runtime_suspend - Entry point for runtime put/suspend operations. |
| 750 | * @dev: Device to suspend. | 751 | * @dev: Device to suspend. |
| 751 | * @rpmflags: Flag bits. | 752 | * @rpmflags: Flag bits. |
| 752 | * | 753 | * |
| @@ -775,7 +776,7 @@ int __pm_runtime_suspend(struct device *dev, int rpmflags) | |||
| 775 | EXPORT_SYMBOL_GPL(__pm_runtime_suspend); | 776 | EXPORT_SYMBOL_GPL(__pm_runtime_suspend); |
| 776 | 777 | ||
| 777 | /** | 778 | /** |
| 778 | * __pm_runtime_resume - Entry point for run-time resume operations. | 779 | * __pm_runtime_resume - Entry point for runtime resume operations. |
| 779 | * @dev: Device to resume. | 780 | * @dev: Device to resume. |
| 780 | * @rpmflags: Flag bits. | 781 | * @rpmflags: Flag bits. |
| 781 | * | 782 | * |
| @@ -801,11 +802,11 @@ int __pm_runtime_resume(struct device *dev, int rpmflags) | |||
| 801 | EXPORT_SYMBOL_GPL(__pm_runtime_resume); | 802 | EXPORT_SYMBOL_GPL(__pm_runtime_resume); |
| 802 | 803 | ||
| 803 | /** | 804 | /** |
| 804 | * __pm_runtime_set_status - Set run-time PM status of a device. | 805 | * __pm_runtime_set_status - Set runtime PM status of a device. |
| 805 | * @dev: Device to handle. | 806 | * @dev: Device to handle. |
| 806 | * @status: New run-time PM status of the device. | 807 | * @status: New runtime PM status of the device. |
| 807 | * | 808 | * |
| 808 | * If run-time PM of the device is disabled or its power.runtime_error field is | 809 | * If runtime PM of the device is disabled or its power.runtime_error field is |
| 809 | * different from zero, the status may be changed either to RPM_ACTIVE, or to | 810 | * different from zero, the status may be changed either to RPM_ACTIVE, or to |
| 810 | * RPM_SUSPENDED, as long as that reflects the actual state of the device. | 811 | * RPM_SUSPENDED, as long as that reflects the actual state of the device. |
| 811 | * However, if the device has a parent and the parent is not active, and the | 812 | * However, if the device has a parent and the parent is not active, and the |
| @@ -851,7 +852,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) | |||
| 851 | 852 | ||
| 852 | /* | 853 | /* |
| 853 | * It is invalid to put an active child under a parent that is | 854 | * It is invalid to put an active child under a parent that is |
| 854 | * not active, has run-time PM enabled and the | 855 | * not active, has runtime PM enabled and the |
| 855 | * 'power.ignore_children' flag unset. | 856 | * 'power.ignore_children' flag unset. |
| 856 | */ | 857 | */ |
| 857 | if (!parent->power.disable_depth | 858 | if (!parent->power.disable_depth |
| @@ -885,7 +886,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_set_status); | |||
| 885 | * @dev: Device to handle. | 886 | * @dev: Device to handle. |
| 886 | * | 887 | * |
| 887 | * Flush all pending requests for the device from pm_wq and wait for all | 888 | * Flush all pending requests for the device from pm_wq and wait for all |
| 888 | * run-time PM operations involving the device in progress to complete. | 889 | * runtime PM operations involving the device in progress to complete. |
| 889 | * | 890 | * |
| 890 | * Should be called under dev->power.lock with interrupts disabled. | 891 | * Should be called under dev->power.lock with interrupts disabled. |
| 891 | */ | 892 | */ |
| @@ -933,7 +934,7 @@ static void __pm_runtime_barrier(struct device *dev) | |||
| 933 | * Prevent the device from being suspended by incrementing its usage counter and | 934 | * Prevent the device from being suspended by incrementing its usage counter and |
| 934 | * if there's a pending resume request for the device, wake the device up. | 935 | * if there's a pending resume request for the device, wake the device up. |
| 935 | * Next, make sure that all pending requests for the device have been flushed | 936 | * Next, make sure that all pending requests for the device have been flushed |
| 936 | * from pm_wq and wait for all run-time PM operations involving the device in | 937 | * from pm_wq and wait for all runtime PM operations involving the device in |
| 937 | * progress to complete. | 938 | * progress to complete. |
| 938 | * | 939 | * |
| 939 | * Return value: | 940 | * Return value: |
| @@ -963,18 +964,18 @@ int pm_runtime_barrier(struct device *dev) | |||
| 963 | EXPORT_SYMBOL_GPL(pm_runtime_barrier); | 964 | EXPORT_SYMBOL_GPL(pm_runtime_barrier); |
| 964 | 965 | ||
| 965 | /** | 966 | /** |
| 966 | * __pm_runtime_disable - Disable run-time PM of a device. | 967 | * __pm_runtime_disable - Disable runtime PM of a device. |
| 967 | * @dev: Device to handle. | 968 | * @dev: Device to handle. |
| 968 | * @check_resume: If set, check if there's a resume request for the device. | 969 | * @check_resume: If set, check if there's a resume request for the device. |
| 969 | * | 970 | * |
| 970 | * Increment power.disable_depth for the device and if was zero previously, | 971 | * Increment power.disable_depth for the device and if was zero previously, |
| 971 | * cancel all pending run-time PM requests for the device and wait for all | 972 | * cancel all pending runtime PM requests for the device and wait for all |
| 972 | * operations in progress to complete. The device can be either active or | 973 | * operations in progress to complete. The device can be either active or |
| 973 | * suspended after its run-time PM has been disabled. | 974 | * suspended after its runtime PM has been disabled. |
| 974 | * | 975 | * |
| 975 | * If @check_resume is set and there's a resume request pending when | 976 | * If @check_resume is set and there's a resume request pending when |
| 976 | * __pm_runtime_disable() is called and power.disable_depth is zero, the | 977 | * __pm_runtime_disable() is called and power.disable_depth is zero, the |
| 977 | * function will wake up the device before disabling its run-time PM. | 978 | * function will wake up the device before disabling its runtime PM. |
| 978 | */ | 979 | */ |
| 979 | void __pm_runtime_disable(struct device *dev, bool check_resume) | 980 | void __pm_runtime_disable(struct device *dev, bool check_resume) |
| 980 | { | 981 | { |
| @@ -987,7 +988,7 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) | |||
| 987 | 988 | ||
| 988 | /* | 989 | /* |
| 989 | * Wake up the device if there's a resume request pending, because that | 990 | * Wake up the device if there's a resume request pending, because that |
| 990 | * means there probably is some I/O to process and disabling run-time PM | 991 | * means there probably is some I/O to process and disabling runtime PM |
| 991 | * shouldn't prevent the device from processing the I/O. | 992 | * shouldn't prevent the device from processing the I/O. |
| 992 | */ | 993 | */ |
| 993 | if (check_resume && dev->power.request_pending | 994 | if (check_resume && dev->power.request_pending |
| @@ -1012,7 +1013,7 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) | |||
| 1012 | EXPORT_SYMBOL_GPL(__pm_runtime_disable); | 1013 | EXPORT_SYMBOL_GPL(__pm_runtime_disable); |
| 1013 | 1014 | ||
| 1014 | /** | 1015 | /** |
| 1015 | * pm_runtime_enable - Enable run-time PM of a device. | 1016 | * pm_runtime_enable - Enable runtime PM of a device. |
| 1016 | * @dev: Device to handle. | 1017 | * @dev: Device to handle. |
| 1017 | */ | 1018 | */ |
| 1018 | void pm_runtime_enable(struct device *dev) | 1019 | void pm_runtime_enable(struct device *dev) |
| @@ -1031,7 +1032,7 @@ void pm_runtime_enable(struct device *dev) | |||
| 1031 | EXPORT_SYMBOL_GPL(pm_runtime_enable); | 1032 | EXPORT_SYMBOL_GPL(pm_runtime_enable); |
| 1032 | 1033 | ||
| 1033 | /** | 1034 | /** |
| 1034 | * pm_runtime_forbid - Block run-time PM of a device. | 1035 | * pm_runtime_forbid - Block runtime PM of a device. |
| 1035 | * @dev: Device to handle. | 1036 | * @dev: Device to handle. |
| 1036 | * | 1037 | * |
| 1037 | * Increase the device's usage count and clear its power.runtime_auto flag, | 1038 | * Increase the device's usage count and clear its power.runtime_auto flag, |
| @@ -1054,7 +1055,7 @@ void pm_runtime_forbid(struct device *dev) | |||
| 1054 | EXPORT_SYMBOL_GPL(pm_runtime_forbid); | 1055 | EXPORT_SYMBOL_GPL(pm_runtime_forbid); |
| 1055 | 1056 | ||
| 1056 | /** | 1057 | /** |
| 1057 | * pm_runtime_allow - Unblock run-time PM of a device. | 1058 | * pm_runtime_allow - Unblock runtime PM of a device. |
| 1058 | * @dev: Device to handle. | 1059 | * @dev: Device to handle. |
| 1059 | * | 1060 | * |
| 1060 | * Decrease the device's usage count and set its power.runtime_auto flag. | 1061 | * Decrease the device's usage count and set its power.runtime_auto flag. |
| @@ -1075,12 +1076,12 @@ void pm_runtime_allow(struct device *dev) | |||
| 1075 | EXPORT_SYMBOL_GPL(pm_runtime_allow); | 1076 | EXPORT_SYMBOL_GPL(pm_runtime_allow); |
| 1076 | 1077 | ||
| 1077 | /** | 1078 | /** |
| 1078 | * pm_runtime_no_callbacks - Ignore run-time PM callbacks for a device. | 1079 | * pm_runtime_no_callbacks - Ignore runtime PM callbacks for a device. |
| 1079 | * @dev: Device to handle. | 1080 | * @dev: Device to handle. |
| 1080 | * | 1081 | * |
| 1081 | * Set the power.no_callbacks flag, which tells the PM core that this | 1082 | * Set the power.no_callbacks flag, which tells the PM core that this |
| 1082 | * device is power-managed through its parent and has no run-time PM | 1083 | * device is power-managed through its parent and has no runtime PM |
| 1083 | * callbacks of its own. The run-time sysfs attributes will be removed. | 1084 | * callbacks of its own. The runtime sysfs attributes will be removed. |
| 1084 | */ | 1085 | */ |
| 1085 | void pm_runtime_no_callbacks(struct device *dev) | 1086 | void pm_runtime_no_callbacks(struct device *dev) |
| 1086 | { | 1087 | { |
| @@ -1156,8 +1157,8 @@ static void update_autosuspend(struct device *dev, int old_delay, int old_use) | |||
| 1156 | * @delay: Value of the new delay in milliseconds. | 1157 | * @delay: Value of the new delay in milliseconds. |
| 1157 | * | 1158 | * |
| 1158 | * Set the device's power.autosuspend_delay value. If it changes to negative | 1159 | * Set the device's power.autosuspend_delay value. If it changes to negative |
| 1159 | * and the power.use_autosuspend flag is set, prevent run-time suspends. If it | 1160 | * and the power.use_autosuspend flag is set, prevent runtime suspends. If it |
| 1160 | * changes the other way, allow run-time suspends. | 1161 | * changes the other way, allow runtime suspends. |
| 1161 | */ | 1162 | */ |
| 1162 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay) | 1163 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay) |
| 1163 | { | 1164 | { |
| @@ -1177,7 +1178,7 @@ EXPORT_SYMBOL_GPL(pm_runtime_set_autosuspend_delay); | |||
| 1177 | * @dev: Device to handle. | 1178 | * @dev: Device to handle. |
| 1178 | * @use: New value for use_autosuspend. | 1179 | * @use: New value for use_autosuspend. |
| 1179 | * | 1180 | * |
| 1180 | * Set the device's power.use_autosuspend flag, and allow or prevent run-time | 1181 | * Set the device's power.use_autosuspend flag, and allow or prevent runtime |
| 1181 | * suspends as needed. | 1182 | * suspends as needed. |
| 1182 | */ | 1183 | */ |
| 1183 | void __pm_runtime_use_autosuspend(struct device *dev, bool use) | 1184 | void __pm_runtime_use_autosuspend(struct device *dev, bool use) |
| @@ -1194,7 +1195,7 @@ void __pm_runtime_use_autosuspend(struct device *dev, bool use) | |||
| 1194 | EXPORT_SYMBOL_GPL(__pm_runtime_use_autosuspend); | 1195 | EXPORT_SYMBOL_GPL(__pm_runtime_use_autosuspend); |
| 1195 | 1196 | ||
| 1196 | /** | 1197 | /** |
| 1197 | * pm_runtime_init - Initialize run-time PM fields in given device object. | 1198 | * pm_runtime_init - Initialize runtime PM fields in given device object. |
| 1198 | * @dev: Device object to initialize. | 1199 | * @dev: Device object to initialize. |
| 1199 | */ | 1200 | */ |
| 1200 | void pm_runtime_init(struct device *dev) | 1201 | void pm_runtime_init(struct device *dev) |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index a9f5b8979611..942d6a7c9ae1 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
| @@ -116,12 +116,14 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr, | |||
| 116 | cp = memchr(buf, '\n', n); | 116 | cp = memchr(buf, '\n', n); |
| 117 | if (cp) | 117 | if (cp) |
| 118 | len = cp - buf; | 118 | len = cp - buf; |
| 119 | device_lock(dev); | ||
| 119 | if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) | 120 | if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) |
| 120 | pm_runtime_allow(dev); | 121 | pm_runtime_allow(dev); |
| 121 | else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) | 122 | else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) |
| 122 | pm_runtime_forbid(dev); | 123 | pm_runtime_forbid(dev); |
| 123 | else | 124 | else |
| 124 | return -EINVAL; | 125 | n = -EINVAL; |
| 126 | device_unlock(dev); | ||
| 125 | return n; | 127 | return n; |
| 126 | } | 128 | } |
| 127 | 129 | ||
| @@ -205,7 +207,9 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, | |||
| 205 | if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) | 207 | if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) |
| 206 | return -EINVAL; | 208 | return -EINVAL; |
| 207 | 209 | ||
| 210 | device_lock(dev); | ||
| 208 | pm_runtime_set_autosuspend_delay(dev, delay); | 211 | pm_runtime_set_autosuspend_delay(dev, delay); |
| 212 | device_unlock(dev); | ||
| 209 | return n; | 213 | return n; |
| 210 | } | 214 | } |
| 211 | 215 | ||
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 46767c53917a..12d1e81a8abe 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
| 19 | #include <linux/cpu.h> | 19 | #include <linux/cpu.h> |
| 20 | #include <linux/pm_runtime.h> | 20 | #include <linux/pm_runtime.h> |
| 21 | #include <linux/suspend.h> | ||
| 21 | #include "pci.h" | 22 | #include "pci.h" |
| 22 | 23 | ||
| 23 | struct pci_dynid { | 24 | struct pci_dynid { |
| @@ -616,6 +617,21 @@ static int pci_pm_prepare(struct device *dev) | |||
| 616 | int error = 0; | 617 | int error = 0; |
| 617 | 618 | ||
| 618 | /* | 619 | /* |
| 620 | * If a PCI device configured to wake up the system from sleep states | ||
| 621 | * has been suspended at run time and there's a resume request pending | ||
| 622 | * for it, this is equivalent to the device signaling wakeup, so the | ||
| 623 | * system suspend operation should be aborted. | ||
| 624 | */ | ||
| 625 | pm_runtime_get_noresume(dev); | ||
| 626 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
| 627 | pm_wakeup_event(dev, 0); | ||
| 628 | |||
| 629 | if (pm_wakeup_pending()) { | ||
| 630 | pm_runtime_put_sync(dev); | ||
| 631 | return -EBUSY; | ||
| 632 | } | ||
| 633 | |||
| 634 | /* | ||
| 619 | * PCI devices suspended at run time need to be resumed at this | 635 | * PCI devices suspended at run time need to be resumed at this |
| 620 | * point, because in general it is necessary to reconfigure them for | 636 | * point, because in general it is necessary to reconfigure them for |
| 621 | * system suspend. Namely, if the device is supposed to wake up the | 637 | * system suspend. Namely, if the device is supposed to wake up the |
| @@ -624,7 +640,7 @@ static int pci_pm_prepare(struct device *dev) | |||
| 624 | * system from the sleep state, we'll have to prevent it from signaling | 640 | * system from the sleep state, we'll have to prevent it from signaling |
| 625 | * wake-up. | 641 | * wake-up. |
| 626 | */ | 642 | */ |
| 627 | pm_runtime_get_sync(dev); | 643 | pm_runtime_resume(dev); |
| 628 | 644 | ||
| 629 | if (drv && drv->pm && drv->pm->prepare) | 645 | if (drv && drv->pm && drv->pm->prepare) |
| 630 | error = drv->pm->prepare(dev); | 646 | error = drv->pm->prepare(dev); |
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index d70e91ae60af..d82a023a9015 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c | |||
| @@ -144,9 +144,9 @@ int scsi_autopm_get_device(struct scsi_device *sdev) | |||
| 144 | int err; | 144 | int err; |
| 145 | 145 | ||
| 146 | err = pm_runtime_get_sync(&sdev->sdev_gendev); | 146 | err = pm_runtime_get_sync(&sdev->sdev_gendev); |
| 147 | if (err < 0) | 147 | if (err < 0 && err !=-EACCES) |
| 148 | pm_runtime_put_sync(&sdev->sdev_gendev); | 148 | pm_runtime_put_sync(&sdev->sdev_gendev); |
| 149 | else if (err > 0) | 149 | else |
| 150 | err = 0; | 150 | err = 0; |
| 151 | return err; | 151 | return err; |
| 152 | } | 152 | } |
| @@ -173,9 +173,9 @@ int scsi_autopm_get_host(struct Scsi_Host *shost) | |||
| 173 | int err; | 173 | int err; |
| 174 | 174 | ||
| 175 | err = pm_runtime_get_sync(&shost->shost_gendev); | 175 | err = pm_runtime_get_sync(&shost->shost_gendev); |
| 176 | if (err < 0) | 176 | if (err < 0 && err !=-EACCES) |
| 177 | pm_runtime_put_sync(&shost->shost_gendev); | 177 | pm_runtime_put_sync(&shost->shost_gendev); |
| 178 | else if (err > 0) | 178 | else |
| 179 | err = 0; | 179 | err = 0; |
| 180 | return err; | 180 | return err; |
| 181 | } | 181 | } |
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index dfb8539ed686..daac05d751b2 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h | |||
| @@ -82,6 +82,11 @@ static inline bool pm_runtime_suspended(struct device *dev) | |||
| 82 | && !dev->power.disable_depth; | 82 | && !dev->power.disable_depth; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | static inline bool pm_runtime_status_suspended(struct device *dev) | ||
| 86 | { | ||
| 87 | return dev->power.runtime_status == RPM_SUSPENDED; | ||
| 88 | } | ||
| 89 | |||
| 85 | static inline bool pm_runtime_enabled(struct device *dev) | 90 | static inline bool pm_runtime_enabled(struct device *dev) |
| 86 | { | 91 | { |
| 87 | return !dev->power.disable_depth; | 92 | return !dev->power.disable_depth; |
| @@ -130,6 +135,7 @@ static inline void pm_runtime_put_noidle(struct device *dev) {} | |||
| 130 | static inline bool device_run_wake(struct device *dev) { return false; } | 135 | static inline bool device_run_wake(struct device *dev) { return false; } |
| 131 | static inline void device_set_run_wake(struct device *dev, bool enable) {} | 136 | static inline void device_set_run_wake(struct device *dev, bool enable) {} |
| 132 | static inline bool pm_runtime_suspended(struct device *dev) { return false; } | 137 | static inline bool pm_runtime_suspended(struct device *dev) { return false; } |
| 138 | static inline bool pm_runtime_status_suspended(struct device *dev) { return false; } | ||
| 133 | static inline bool pm_runtime_enabled(struct device *dev) { return false; } | 139 | static inline bool pm_runtime_enabled(struct device *dev) { return false; } |
| 134 | 140 | ||
| 135 | static inline int pm_generic_runtime_idle(struct device *dev) { return 0; } | 141 | static inline int pm_generic_runtime_idle(struct device *dev) { return 0; } |
