Revert "PM: allow for usage_count > 0 in pm_runtime_get()"

This reverts commit 4d94493687b964e9554a889a87e3ce09ef654bfa.
Revert "CONFIG_PM_OPS -> CONFIG_PM"

This reverts commit b18450c8359d5b8fbe908f6159bf6d67ac1bf302.
Revert "PM: Introduce generic prepare and complete callbacks for subsystems"

This reverts commit 74086c82d8e84b5d6886a5bafdb50eda38dd57e7.
Revert "PM / Runtime: Generic resume shouldn't set RPM_ACTIVE unconditionally"

This reverts commit 8fc0208ac0af5523e8d2229a931df0a736d38313.
Revert "PM / Runtime: Lenient generic runtime pm callbacks"

This reverts commit 073bc5904776275ef8b8fdd0b7f1079f9d22c0f8.
Revert "PM: Provide generic subsystem-level callbacks"

This reverts commit 79bdb4b80f927357f269a90011b4902698fbe618.
Revert "PM: Use pm_runtime_put_sync in system resume"

This reverts commit c1c8593c35907ada4b29a66dbabf9c9868b8dab2.
PM / Runtime: Use deferred_resume flag in pm_request_resume

This patch (as1307) adds a small optimization to
__pm_request_resume().  If the device is currently being suspended,
there's no need to queue a work routine to resume it.  Setting the
deferred_resume flag will suffice.  (There's also a minor improvement
to the function's code layout: An unnecessary "else" is removed.)

Also, the patch clarifies the usage of the deferred_resume flag.  It
is meaningful only while a suspend is in progress, so it should be
cleared just before a suspend starts, not just after one ends.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM / Runtime: Ensure timer_expires is nonzero in pm_schedule_suspend()

The runtime PM core code assumes that dev->power.timer_expires is
nonzero when the timer is scheduled, but it may become zero
incidentally in pm_schedule_suspend().  Prevent this from happening
by bumping dev->power.timer_expires up to 1 if it's 0 before calling
mod_timer().

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Reported-by: Alan Stern <stern@rowland.harvard.edu>
PM / Runtime: Remove unnecessary braces in __pm_runtime_set_status()

Some braces in __pm_runtime_set_status() are not necessary, so
remove them.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: allow for usage_count > 0 in pm_runtime_get()

This patch (as1308c) fixes __pm_runtime_get().  Currently the routine
will resume a device if the prior usage count was 0.  But this isn't
right; thanks to pm_runtime_get_noresume() the usage count can be
positive even while the device is suspended.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: Add initcall_debug style timing for suspend/resume

In order to diagnose overall suspend/resume times, we need
basic instrumentation to break down the total time into per
device timing, similar to initcall_debug.

This patch adds the basic timing instrumentation, needed
for a scritps/bootgraph.pl equivalent or humans.
The bootgraph.pl program is still a work in progress, but
is far enough along to know that this patch is sufficient.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Conflicts:
	drivers/base/power/main.c
PM: Remove unnecessary goto from device_resume_noirq()

In device_resume_noirq() there is the 'End' label and the associated
goto statement that aren't strictly necessary, so rework the code to
get rid of them.  Also modify device_suspend_noirq() so that it looks
completely analogous to device_resume_noirq().

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: rwsem.h need not be included into main.c

It is not necessary to include <linux/rwsem.h> into
drivers/base/power/main.c, so don't do that.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: Make the initcall_debug style timing for suspend/resume complete

Commit f2511774863487e61b56a97da07ebf8dd61d7836
(PM: Add initcall_debug style timing for suspend/resume) introduced
basic timing instrumentation, needed for a scritps/bootgraph.pl
equivalent or humans, but it missed the fact that bus types and
device classes which haven't been switched to using struct dev_pm_ops
objects yet need special handling.  As a result, the suspend/resume
timing information is only available for devices whose bus types or
device classes use struct dev_pm_ops objects, so the majority of
devices is not covered.

Fix this by adding basic suspend/resume timing instrumentation for
devices whose bus types and device classes still don't use struct
dev_pm_ops objects for power management.  To reduce code duplication
move the timing code to helper functions.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: Measure device suspend and resume times

Measure and print the time of suspending and resuming all devices.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM: Use pm_runtime_put_sync in system resume

This patch (as1317) fixes a bug in the PM core.  When a device is
resumed following a system sleep, the core decrements the device's
runtime PM usage counter but doesn't issue an idle notification if the
counter reaches 0.  This could prevent an otherwise unused device from
being runtime-suspended again after the system sleep.

The fix is to call pm_runtime_put_sync() instead of
pm_runtime_put_noidle().

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
PM / Runtime: Use device type and device class callbacks

The power management of some devices is handled through device types
and device classes rather than through bus types.  Since these
devices may also benefit from using the run-time power management
core, extend it so that the device type and device class run-time PM
callbacks can be taken into consideration by it if the bus type
callback is not defined.

Update the run-time PM core documentation to reflect this change.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Conflicts:
	Documentation/power/runtime_pm.txt
PM / Runtime: Add sysfs switch for disabling device run-time PM

Add new device sysfs attribute, power/control, allowing the user
space to block the run-time power management of the devices.  If this
attribute is set to "on", the driver of the device won't be able to power
manage it at run time (without breaking the rules) and the device will
always be in the full power state (except when the entire system goes
into a sleep state).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Alan Stern <stern@rowland.harvard.edu>

Conflicts:
	include/linux/pm.h
PM: Add parent information to timing messages

Add parent information to the messages printed by the suspend/resume
core when initcall_debug is set.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>