summaryrefslogtreecommitdiff
path: root/drivers/base/power
AgeCommit message (Collapse)Author
2012-08-17PM: Need to wake_up_all when suspend failBH Hsieh
In rpm_suspend, when suspend fail, before going to reschedule another autosuspend, wake_up_all is required to avoid remote wakeup issues. Bug 1026169 Bug 1027598 Bug 1032565 Change-Id: Ieaf9282dae59b2cb343bf01aa2ba837a8cdc39c7 Signed-off-by: BH Hsieh <bhsieh@nvidia.com> Reviewed-on: http://git-master/r/122978 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Neil Patel <neilp@nvidia.com> Tested-by: Neil Patel <neilp@nvidia.com> Tested-by: Steve Lin <stlin@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Steve Lin <stlin@nvidia.com>
2011-11-30Merge branch 'korg-android-tegra-3.1' into after-upstream-androidDan Willemsen
Conflicts: arch/arm/mach-tegra/Kconfig arch/arm/mach-tegra/board-ventana.c drivers/misc/Kconfig drivers/video/tegra/dc/hdmi.c Signed-off-by: Dan Willemsen <dwillemsen@nvidia.com>
2011-11-30PM: remove redundant calculationvenu byravarasu
As max_num usage is not necessary, removing it. Change-Id: I7b668bbbf0d5a388c8ade017194958976c861ea3 Reviewed-on: http://git-master/r/60855 Tested-by: Venu Byravarasu <vbyravarasu@nvidia.com> Reviewed-by: Bitan Biswas <bbiswas@nvidia.com> Rebase-Id: R131970045a24c494f94de0a51eea6c73bdf994ea
2011-11-30PM: fix calculation mistake in roll-over casesvenu byravarasu
In case of jiffies roll over, delta is made zero. Hence fixing it, after taking roll over into consideration. Change-Id: I7dacaa12deafbd2bd20705948c0e18292b718aa4 Reviewed-on: http://git-master/r/60147 Reviewed-by: Varun Colbert <vcolbert@nvidia.com> Tested-by: Varun Colbert <vcolbert@nvidia.com> Rebase-Id: R0fa2027be53f95c16e11e8ea46c833c86182a3a9
2011-11-30PM: runtime: add might_sleep to PM runtime functionsColin Cross
The list of functions that can be called in atomic context is non-intuitive (pm_runtime_put_sync can not, but pm_runtime_put_sync_suspend can, if pm_runtime_irq_safe has been called?). The code is actively misleading - the entry points all start with spin_lock_irqsave, suggesting they are safe to call in atomic context, but may later enable interrupts. Add might_sleep_if to all the __pm_runtime_* entry points to enforce correct usage. Also add pm_runtime_put_sync_autosuspend to the list of functions that can be called in atomic context. Change-Id: Icac17a10d77c64d44bd2761a91a588dfd1d0c6f0 Signed-off-by: Colin Cross <ccross@android.com>
2011-11-30Revert "PM: Prevent waiting forever on asynchronous resume after abort"Colin Cross
This reverts commit fa92a3d6959546baa27e892188d3e9bb79c31741.
2011-11-30Revert "PM: Wait for completion of the parent resume before resuming"Colin Cross
This reverts commit a0f07aae54e87a9fad6d19c0e57398f54d858f06.
2011-11-30PM: Increase dpm suspend timeoutBenoit Goby
usbhid devices have a 10s timeout waiting for the out queue to clear. Increased the watchdog to 12s. Change-Id: I96368fca6dff98e4eba8aedb09c23be964c8f4b4 Signed-off-by: Benoit Goby <benoit@android.com>
2011-11-30PM: Change dpm watchdog to support async suspendBenoit Goby
Exclude from the watchdog the time spent waiting for children that are resumed asynchronously and time every devices, whether or not they resumed synchronously. Change-Id: I84209dfd5df72842e045096c906fd61e20e6d183 Signed-off-by: Benoit Goby <benoit@android.com>
2011-11-30PM: Dump suspend thread stack on dpm suspend timeoutBenoit Goby
When a driver takes more than 3 seconds to suspend, dump the suspend thread stack since BUG() might only dump the idle thread stack. Change-Id: If854db355fdcf3b773ea20b1b5e031def6d4b114 Signed-off-by: Benoit Goby <benoit@android.com>
2011-11-30PM: Wait for completion of the parent resume before resumingBenoit Goby
If the parent device is in the DPM_RESUMING state, resume might get called before the parent's resume has completed, because dpm_wait won't get called. This issue was introduced by: 3d46a3c PM: Prevent waiting forever on asynchronous resume after abort Wait for completion of the parent resume if the parent state is >= DPM_OFF or == DPM_RESUMING Signed-off-by: Benoit Goby <benoit@android.com> [dima: fixed to work on 2.6.38, use .in_suspend instead of .state] Signed-off-by: Dima Zavin <dima@android.com>
2011-11-30PM: Prevent waiting forever on asynchronous resume after abortColin Cross
Only wait on a parent device during resume if the parent device is suspended. Consider three drivers, A, B, and C. The parent of A is C, and C has async_suspend set. On boot, C->power.completion is initialized to 0. During the first suspend: suspend_devices_and_enter(...) dpm_resume(...) device_suspend(A) device_suspend(B) returns error, aborts suspend dpm_resume_end(...) dpm_resume(...) device_resume(A) dpm_wait(A->parent == C) wait_for_completion(C->power.completion) The wait_for_completion will never complete, because complete_all(C->power.completion) will only be called from device_suspend(C) or device_resume(C), neither of which is called if suspend is aborted before C. After a successful suspend->resume cycle, where B doesn't abort suspend, C->power.completion is left in the completed state by the call to device_resume(C), and the same call path will work if B aborts suspend. Signed-off-by: Colin Cross <ccross@android.com>
2011-11-30drivers: power: Add watchdog timer to catch drivers which lockup during suspend.San Mehat
Rather than hard-lock the kernel, we now BUG() when a driver takes > 3 seconds to suspend. If the underlying platform supports panic dumps, then the data can be collected for debug. Signed-off-by: San Mehat <san@google.com>
2011-11-11PM / Runtime: Automatically retry failed autosuspendsAlan Stern
commit 886486b792e4f6f96d4fbe8ec5bf20811cab7d6a upstream. Originally, the runtime PM core would send an idle notification whenever a suspend attempt failed. The idle callback routine could then schedule a delayed suspend for some time later. However this behavior was changed by commit f71648d73c1650b8b4aceb3856bebbde6daa3b86 (PM / Runtime: Remove idle notification after failing suspend). No notifications were sent, and there was no clear mechanism to retry failed suspends. This caused problems for the usbhid driver, because it fails autosuspend attempts as long as a key is being held down. Therefore this patch (as1492) adds a mechanism for retrying failed autosuspends. If the callback routine updates the last_busy field so that the next autosuspend expiration time is in the future, the autosuspend will automatically be rescheduled. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Tested-by: Henrik Rydberg <rydberg@euromail.se> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-09-26PM / Clocks: Do not acquire a mutex under a spinlockRafael J. Wysocki
Commit b7ab83e (PM: Use spinlock instead of mutex in clock management functions) introduced a regression causing clocks_mutex to be acquired under a spinlock. This happens because pm_clk_suspend() and pm_clk_resume() call pm_clk_acquire() under pcd->lock, but pm_clk_acquire() executes clk_get() which causes clocks_mutex to be acquired. Similarly, __pm_clk_remove(), executed under pcd->lock, calls clk_put(), which also causes clocks_mutex to be acquired. To fix those problems make pm_clk_add() call pm_clk_acquire(), so that pm_clk_suspend() and pm_clk_resume() don't have to do that. Change pm_clk_remove() and pm_clk_destroy() to separate modifications of the pcd->clock_list list from the actual removal of PM clock entry objects done by __pm_clk_remove(). Reported-and-tested-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-08-24PM: Use spinlock instead of mutex in clock management functionsRafael J. Wysocki
The lock member of struct pm_clk_data is of type struct mutex, which is a problem, because the suspend and resume routines defined in drivers/base/power/clock_ops.c cannot be executed with interrupts disabled for this reason. Modify struct pm_clk_data so that its lock member is a spinlock. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Magnus Damm <damm@opensource.se>
2011-08-14PM / Domains: Fix build for CONFIG_PM_RUNTIME unsetRafael J. Wysocki
Function genpd_queue_power_off_work() is not defined for CONFIG_PM_RUNTIME, so pm_genpd_poweroff_unused() causes a build error to happen in that case. Fix the problem by making pm_genpd_poweroff_unused() depend on CONFIG_PM_RUNTIME too. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-08-05PM / Runtime: Allow _put_sync() from interrupts-disabled contextKevin Hilman
Currently the use of pm_runtime_put_sync() is not safe from interrupts-disabled context because rpm_idle() will release the spinlock and enable interrupts for the idle callbacks. This enables interrupts during a time where interrupts were expected to be disabled, and can have strange side effects on drivers that expected interrupts to be disabled. This is not a bug since the documentation clearly states that only _put_sync_suspend() is safe in IRQ-safe mode. However, pm_runtime_put_sync() could be made safe when in IRQ-safe mode by releasing the spinlock but not re-enabling interrupts, which is what this patch aims to do. Problem was found when using some buggy drivers that set pm_runtime_irq_safe() and used _put_sync() in interrupts-disabled context. Reported-by: Colin Cross <ccross@google.com> Tested-by: Nishanth Menon <nm@ti.com> Signed-off-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-08-05PM / Domains: Fix pm_genpd_poweron()Rafael J. Wysocki
The local variable ret is defined twice in pm_genpd_poweron(), which causes this function to always return 0, even if the PM domain's .power_on() callback fails, in which case an error code should be returned. Remove the wrong second definition of ret and additionally remove an unnecessary definition of wait from pm_genpd_poweron(). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-26atomic: use <linux/atomic.h>Arun Sharma
This allows us to move duplicated code in <asm/atomic.h> (atomic_inc_not_zero() for now) to <linux/atomic.h> Signed-off-by: Arun Sharma <asharma@fb.com> Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: David Miller <davem@davemloft.net> Cc: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-07-26drivers/base/power/opp.c: fix dev_opp initial valueJonghwan Choi
Dev_opp initial value shoule be ERR_PTR(), IS_ERR() is used to check error. Signed-off-by: Jonghwan Choi <jhbird.choi@samsung.com> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-07-15Merge branch 'pm-runtime' into for-linusRafael J. Wysocki
* 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
2011-07-15Merge branch 'pm-domains' into for-linusRafael J. Wysocki
* pm-domains: (33 commits) ARM / shmobile: Return -EBUSY from A4LC power off if A3RV is active PM / Domains: Take .power_off() error code into account ARM / shmobile: Use genpd_queue_power_off_work() ARM / shmobile: Use pm_genpd_poweroff_unused() PM / Domains: Introduce function to power off all unused PM domains PM / Domains: Queue up power off work only if it is not pending PM / Domains: Improve handling of wakeup devices during system suspend PM / Domains: Do not restore all devices on power off error PM / Domains: Allow callbacks to execute all runtime PM helpers PM / Domains: Do not execute device callbacks under locks PM / Domains: Make failing pm_genpd_prepare() clean up properly PM / Domains: Set device state to "active" during system resume ARM: mach-shmobile: sh7372 A3RV requires A4LC PM / Domains: Export pm_genpd_poweron() in header ARM: mach-shmobile: sh7372 late pm domain off ARM: mach-shmobile: Runtime PM late init callback ARM: mach-shmobile: sh7372 D4 support ARM: mach-shmobile: sh7372 A4MP support ARM: mach-shmobile: sh7372: make sure that fsi is peripheral of spu2 ARM: mach-shmobile: sh7372 A3SG support ...
2011-07-15PM: Add "RTC" to PM trace time stamps to avoid confusionRafael J. Wysocki
Some users are apparently confused by dmesg output from read_magic_time(), which looks like "real" time and date. Add the "RTC" string to time stamps printed by read_magic_time() to avoid that confusion. Reported-by: Justin P. Mattock <justinmattock@gmail.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-15PM / OPP: Introduce function to free cpufreq tableNishanth Menon
cpufreq table allocated by opp_init_cpufreq_table is better freed by OPP layer itself. This allows future modifications to the table handling to be transparent to the users. Signed-off-by: Nishanth Menon <nm@ti.com> Acked-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-14PM / Domains: Take .power_off() error code into accountRafael J. Wysocki
Currently pm_genpd_poweroff() discards error codes returned by the PM domain's .power_off() callback, because it's safer to always regard the domain as inaccessible to drivers after a failing .power_off(). Still, there are situations in which the low-level code may want to indicate that it doesn't want to power off the domain, so allow it to do that by returning -EBUSY from .power_off(). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Magnus Damm <damm@opensource.se>
2011-07-14ARM / shmobile: Use genpd_queue_power_off_work()Rafael J. Wysocki
Make pd_power_down_a3rv() use genpd_queue_power_off_work() to queue up the powering off of the A4LC domain to avoid queuing it up when it is pending. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Magnus Damm <damm@opensource.se>
2011-07-13PM / Domains: Introduce function to power off all unused PM domainsRafael J. Wysocki
Add a new function pm_genpd_poweroff_unused() queuing up the execution of pm_genpd_poweroff() for every initialized generic PM domain. Calling it will cause every generic PM domain without devices in use to be powered off. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Magnus Damm <damm@opensource.se>
2011-07-12PM / Domains: Queue up power off work only if it is not pendingRafael J. Wysocki
In theory it is possible that pm_genpd_poweroff() for two different subdomains of the same parent domain will attempt to queue up the execution of pm_genpd_poweroff() for the parent twice in a row. This would lead to unpleasant consequences, so prevent it from happening by checking if genpd->power_off_work is pending before attempting to queue it up. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Improve handling of wakeup devices during system suspendRafael J. Wysocki
Kevin points out that if there's a device that can wake up the system from sleep states, but it doesn't generate wakeup signals by itself (they are generated on its behalf by other parts of the system) and it currently is not enabled to wake up the system (that is, device_may_wakeup() returns "false" for it), we may need to change its wakeup settings during system suspend (for example, the device might have been configured to signal remote wakeup from the system's working state, as needed by runtime PM). Therefore the generic PM domains code should invoke the system suspend callbacks provided by the device's driver, which it doesn't do if the PM domain is powered off during the system suspend's "prepare" stage. This is a valid point. Moreover, this code also should make sure that system wakeup devices that are enabled to wake up the system from sleep states and have to remain active for this purpose are not suspended while the system is in a sleep state. To avoid the above issues, make the generic PM domains' .prepare() routine, pm_genpd_prepare(), force runtime resume of devices whose system wakeup settings may need to be changed during system suspend or that should remain active while the system is in a sleep state to be able to wake it up from that state. Reported-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Do not restore all devices on power off errorRafael J. Wysocki
Since every device in a PM domain has its own need_restore flag, which is set by __pm_genpd_save_device(), there's no need to walk the domain's device list and restore all devices on an error from one of the drivers' .runtime_suspend() callbacks. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Allow callbacks to execute all runtime PM helpersRafael J. Wysocki
A deadlock may occur if one of the PM domains' .start_device() or .stop_device() callbacks or a device driver's .runtime_suspend() or .runtime_resume() callback executed by the core generic PM domain code uses a "wrong" runtime PM helper function. This happens, for example, if .runtime_resume() from one device's driver calls pm_runtime_resume() for another device in the same PM domain. A similar situation may take place if a device's parent is in the same PM domain, in which case the runtime PM framework may execute pm_genpd_runtime_resume() automatically for the parent (if it is suspended at the moment). This, of course, is undesirable, so the generic PM domains code should be modified to prevent it from happening. The runtime PM framework guarantees that pm_genpd_runtime_suspend() and pm_genpd_runtime_resume() won't be executed in parallel for the same device, so the generic PM domains code need not worry about those cases. Still, it needs to prevent the other possible race conditions between pm_genpd_runtime_suspend(), pm_genpd_runtime_resume(), pm_genpd_poweron() and pm_genpd_poweroff() from happening and it needs to avoid deadlocks at the same time. To this end, modify the generic PM domains code to relax synchronization rules so that: * pm_genpd_poweron() doesn't wait for the PM domain status to change from GPD_STATE_BUSY. If it finds that the status is not GPD_STATE_POWER_OFF, it returns without powering the domain on (it may modify the status depending on the circumstances). * pm_genpd_poweroff() returns as soon as it finds that the PM domain's status changed from GPD_STATE_BUSY after it's released the PM domain's lock. * pm_genpd_runtime_suspend() doesn't wait for the PM domain status to change from GPD_STATE_BUSY after executing the domain's .stop_device() callback and executes pm_genpd_poweroff() only if pm_genpd_runtime_resume() is not executed in parallel. * pm_genpd_runtime_resume() doesn't wait for the PM domain status to change from GPD_STATE_BUSY after executing pm_genpd_poweron() and sets the domain's status to GPD_STATE_BUSY and increments its counter of resuming devices (introduced by this change) immediately after acquiring the lock. The counter of resuming devices is then decremented after executing __pm_genpd_runtime_resume() for the device and the domain's status is reset to GPD_STATE_ACTIVE (unless there are more resuming devices in the domain, in which case the status remains GPD_STATE_BUSY). This way, for example, if a device driver's .runtime_resume() callback executes pm_runtime_resume() for another device in the same PM domain, pm_genpd_poweron() called by pm_genpd_runtime_resume() invoked by the runtime PM framework will not block and it will see that there's nothing to do for it. Next, the PM domain's lock will be acquired without waiting for its status to change from GPD_STATE_BUSY and the device driver's .runtime_resume() callback will be executed. In turn, if pm_runtime_suspend() is executed by one device driver's .runtime_resume() callback for another device in the same PM domain, pm_genpd_poweroff() executed by pm_genpd_runtime_suspend() invoked by the runtime PM framework as a result will notice that one of the devices in the domain is being resumed, so it will return immediately. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Do not execute device callbacks under locksRafael J. Wysocki
Currently, the .start_device() and .stop_device() callbacks from struct generic_pm_domain() as well as the device drivers' runtime PM callbacks used by the generic PM domains code are executed under the generic PM domain lock. This, unfortunately, is prone to deadlocks, for example if a device and its parent are boths members of the same PM domain. For this reason, it would be better if the PM domains code didn't execute device callbacks under the lock. Rework the locking in the generic PM domains code so that the lock is dropped for the execution of device callbacks. To this end, introduce PM domains states reflecting the current status of a PM domain and such that the PM domain lock cannot be acquired if the status is GPD_STATE_BUSY. Make threads attempting to acquire a PM domain's lock wait until the status changes to either GPD_STATE_ACTIVE or GPD_STATE_POWER_OFF. This change by itself doesn't fix the deadlock problem mentioned above, but the mechanism introduced by it will be used for for this purpose by a subsequent patch. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Make failing pm_genpd_prepare() clean up properlyRafael J. Wysocki
If pm_generic_prepare() in pm_genpd_prepare() returns error code, the PM domains counter of "prepared" devices should be decremented and its suspend_power_off flag should be reset if this counter drops down to zero. Otherwise, the PM domain runtime PM code will not handle the domain correctly (it will permanently think that system suspend is in progress). Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-12PM / Domains: Set device state to "active" during system resumeRafael J. Wysocki
The runtime PM status of devices in a power domain that is not powered off in pm_genpd_complete() should be set to "active", because those devices are operational at this point. Some of them may not be in use, though, so make pm_genpd_complete() call pm_runtime_idle() in addition to pm_runtime_set_active() for each of them. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-10PM / Domains: Export pm_genpd_poweron() in headerMagnus Damm
Allow SoC-specific code to call pm_genpd_poweron(). Signed-off-by: Magnus Damm <damm@opensource.se> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-08PM / Runtime: Consistent utilization of deferred_resumeShuoX Liu
dev->power.deferred_resume is used as a bool typically, so change one assignment to false from 0, like other places. Signed-off-by: ShuoX Liu <shuox.liu@intel.com>
2011-07-06PM / Runtime: Prevent runtime_resume from racing with probeAlan Stern
This patch (as1475) adds device_lock() and device_unlock() calls to the store methods for the power/control and power/autosuspend_delay_ms sysfs attribute files. We don't want badly timed writes to these files to cause runtime_resume callbacks to occur while a driver is being probed for a device. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-06PM / Runtime: Replace "run-time" with "runtime" in documentationRafael J. Wysocki
The runtime PM documentation and kerneldoc comments sometimes spell "runtime" with a dash (i.e. "run-time"). Replace all of those instances with "runtime" to make the naming consistent. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-06PM: Limit race conditions between runtime PM and system sleep (v2)Rafael J. Wysocki
One of the roles of the PM core is to prevent different PM callbacks executed for the same device object from racing with each other. Unfortunately, after commit e8665002477f0278f84f898145b1f141ba26ee26 (PM: Allow pm_runtime_suspend() to succeed during system suspend) runtime PM callbacks may be executed concurrently with system suspend/resume callbacks for the same device. The main reason for commit e8665002477f0278f84f898145b1f141ba26ee26 was that some subsystems and device drivers wanted to use runtime PM helpers, pm_runtime_suspend() and pm_runtime_put_sync() in particular, for carrying out the suspend of devices in their .suspend() callbacks. However, as it's been determined recently, there are multiple reasons not to do so, inlcuding: * The caller really doesn't control the runtime PM usage counters, because user space can access them through sysfs and effectively block runtime PM. That means using pm_runtime_suspend() or pm_runtime_get_sync() to suspend devices during system suspend may or may not work. * If a driver calls pm_runtime_suspend() from its .suspend() callback, it causes the subsystem's .runtime_suspend() callback to be executed, which leads to the call sequence: subsys->suspend(dev) driver->suspend(dev) pm_runtime_suspend(dev) subsys->runtime_suspend(dev) recursive from the subsystem's point of view. For some subsystems that may actually work (e.g. the platform bus type), but for some it will fail in a rather spectacular fashion (e.g. PCI). In each case it means a layering violation. * Both the subsystem and the driver can provide .suspend_noirq() callbacks for system suspend that can do whatever the .runtime_suspend() callbacks do just fine, so it really isn't necessary to call pm_runtime_suspend() during system suspend. * The runtime PM's handling of wakeup devices is usually different from the system suspend's one, so .runtime_suspend() may simply be inappropriate for system suspend. * System suspend is supposed to work even if CONFIG_PM_RUNTIME is unset. * The runtime PM workqueue is frozen before system suspend, so if whatever the driver is going to do during system suspend depends on it, that simply won't work. Still, there is a good reason to allow pm_runtime_resume() to succeed during system suspend and resume (for instance, some subsystems and device drivers may legitimately use it to ensure that their devices are in full-power states before suspending them). Moreover, there is no reason to prevent runtime PM callbacks from being executed in parallel with the system suspend/resume .prepare() and .complete() callbacks and the code removed by commit e8665002477f0278f84f898145b1f141ba26ee26 went too far in this respect. On the other hand, runtime PM callbacks, including .runtime_resume(), must not be executed during system suspend's "late" stage of suspending devices and during system resume's "early" device resume stage. Taking all of the above into consideration, make the PM core acquire a runtime PM reference to every device and resume it if there's a runtime PM resume request pending right before executing the subsystem-level .suspend() callback for it. Make the PM core drop references to all devices right after executing the subsystem-level .resume() callbacks for them. Additionally, make the PM core disable the runtime PM framework for all devices during system suspend, after executing the subsystem-level .suspend() callbacks for them, and enable the runtime PM framework for all devices during system resume, right before executing the subsystem-level .resume() callbacks for them. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM / Runtime: Return special error code if runtime PM is disabledRafael J. Wysocki
Some callers of pm_runtime_get_sync() and other runtime PM helper functions, scsi_autopm_get_host() and scsi_autopm_get_device() in particular, need to distinguish error codes returned when runtime PM is disabled (i.e. power.disable_depth is nonzero for the given device) from error codes returned in other situations. For this reason, make the runtime PM helper functions return -EACCES when power.disable_depth is nonzero and ensure that this error code won't be returned by them in any other circumstances. Modify scsi_autopm_get_host() and scsi_autopm_get_device() to check the error code returned by pm_runtime_get_sync() and ignore -EACCES. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-02PM: Rename clock management functionsRafael J. Wysocki
The common PM clock management functions may be used for system suspend/resume as well as for runtime PM, so rename them accordingly. Modify kerneldoc comments describing these functions and kernel messages printed by them, so that they refer to power management in general rather that to runtime PM. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM: Allow the clocks management code to be used during system suspendRafael J. Wysocki
The common clocks management code in drivers/base/power/clock_ops.c is going to be used during system-wide power transitions as well as for runtime PM, so it shouldn't depend on CONFIG_PM_RUNTIME. However, the suspend/resume functions provided by it for CONFIG_PM_RUNTIME unset, to be used during system-wide power transitions, should not behave in the same way as their counterparts defined for CONFIG_PM_RUNTIME set, because in that case the clocks are managed differently at run time. The names of the functions still contain the word "runtime" after this change, but that is going to be modified by a separate patch later. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM / Domains: Wakeup devices support for system sleep transitionsRafael J. Wysocki
There is the problem how to handle devices set up to wake up the system from sleep states during system-wide power transitions. In some cases, those devices can be turned off entirely, because the wakeup signals will be generated on their behalf anyway. In some other cases, they will generate wakeup signals if their clocks are stopped, but only if power is not removed from them. Finally, in some cases, they can only generate wakeup signals if power is not removed from them and their clocks are enabled. To allow platform-specific code to decide whether or not to put wakeup devices (and their PM domains) into low-power state during system-wide transitions, such as system suspend, introduce a new generic PM domain callback, .active_wakeup(), that will be used during the "noirq" phase of system suspend and hibernation (after image creation) to decide what to do with wakeup devices. Specifically, if this callback is present and returns "true", the generic PM domain code will not execute .stop_device() for the given wakeup device and its PM domain won't be powered off. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM / Domains: System-wide transitions support for generic domains (v5)Rafael J. Wysocki
Make generic PM domains support system-wide power transitions (system suspend and hibernation). Add suspend, resume, freeze, thaw, poweroff and restore callbacks to be associated with struct generic_pm_domain objects and make pm_genpd_init() use them as appropriate. The new callbacks do nothing for devices belonging to power domains that were powered down at run time (before the transition). For the other devices the action carried out depends on the type of the transition. During system suspend the power domain .suspend() callback executes pm_generic_suspend() for the device, while the PM domain .suspend_noirq() callback runs pm_generic_suspend_noirq() for it, stops it and eventually removes power from the PM domain it belongs to (after all devices in the domain have been stopped and its subdomains have been powered off). During system resume the PM domain .resume_noirq() callback restores power to the PM domain (when executed for it first time), starts the device and executes pm_generic_resume_noirq() for it, while the .resume() callback executes pm_generic_resume() for the device. Finally, the .complete() callback executes pm_runtime_idle() for the device which should put it back into the suspended state if its runtime PM usage count is equal to zero at that time. The actions carried out during hibernation and resume from it are analogous to the ones described above. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM / Domains: Move code from under #ifdef CONFIG_PM_RUNTIME (v2)Rafael J. Wysocki
There is some code in drivers/base/power/domain.c that will be useful for both runtime PM and system-wide power transitions, so make it depend on CONFIG_PM instead of CONFIG_PM_RUNTIME. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM: Introduce generic "noirq" callback routines for subsystems (v2)Rafael J. Wysocki
Introduce generic "noirq" power management callback routines for subsystems in addition to the "regular" generic PM callback routines. The new routines will be used, among other things, for implementing system-wide PM transitions support for generic PM domains. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2011-07-02PM / Domains: Support for generic I/O PM domains (v8)Rafael J. Wysocki
Introduce common headers, helper functions and callbacks allowing platforms to use simple generic power domains for runtime power management. Introduce struct generic_pm_domain to be used for representing power domains that each contain a number of devices and may be parent domains or subdomains with respect to other power domains. Among other things, this structure includes callbacks to be provided by platforms for performing specific tasks related to power management (i.e. ->stop_device() may disable a device's clocks, while ->start_device() may enable them, ->power_off() is supposed to remove power from the entire power domain and ->power_on() is supposed to restore it). Introduce functions that can be used as power domain runtime PM callbacks, pm_genpd_runtime_suspend() and pm_genpd_runtime_resume(), as well as helper functions for the initialization of a power domain represented by a struct generic_power_domain object, adding a device to or removing a device from it and adding or removing subdomains. Introduce configuration option CONFIG_PM_GENERIC_DOMAINS to be selected by the platforms that want to use the new code. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Reviewed-by: Kevin Hilman <khilman@ti.com>
2011-07-02PM / Domains: Rename struct dev_power_domain to struct dev_pm_domainRafael J. Wysocki
The naming convention used by commit 7538e3db6e015e890825fbd9f86599b (PM: Add support for device power domains), which introduced the struct dev_power_domain type for representing device power domains, evidently confuses some developers who tend to think that objects of this type must correspond to "power domains" as defined by hardware, which is not the case. Namely, at the kernel level, a struct dev_power_domain object can represent arbitrary set of devices that are mutually dependent power management-wise and need not belong to one hardware power domain. To avoid that confusion, rename struct dev_power_domain to struct dev_pm_domain and rename the related pointers in struct device and struct pm_clk_notifier_block from pwr_domain to pm_domain. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Kevin Hilman <khilman@ti.com>
2011-06-21PM / Runtime: Handle clocks correctly if CONFIG_PM_RUNTIME is unsetRafael J. Wysocki
Commit 85eb8c8d0b0900c073b0e6f89979ac9c439ade1a (PM / Runtime: Generic clock manipulation rountines for runtime PM (v6)) converted the shmobile platform to using generic code for runtime PM clock management, but it changed the behavior for CONFIG_PM_RUNTIME unset incorrectly. Specifically, for CONFIG_PM_RUNTIME unset pm_runtime_clk_notify() should enable clocks for action equal to BUS_NOTIFY_BIND_DRIVER and it should disable them for action equal to BUS_NOTIFY_UNBOUND_DRIVER (instead of BUS_NOTIFY_ADD_DEVICE and BUS_NOTIFY_DEL_DEVICE, respectively). Make this function behave as appropriate. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Magnus Damm <damm@opensource.se>