PM / Sleep: Print name of wakeup source that aborts suspend

A driver or app may repeatedly request a wakeup source while the system
is attempting to enter suspend, which may indicate a bug or at least
point out a highly active system component that is responsible for
decreased battery life on a mobile device.  Even when the incidence
of suspend abort is not severe, identifying wakeup sources that
frequently abort suspend can be a useful clue for power management
analysis.

In some cases the existing stats can point out the offender where there is
an unexpectedly high activation count that stands out from the others, but
in other cases the wakeup source frequently taken just after the rest of
the system thinks its time to suspend might not stand out in the overall
stats.

It is also often useful to have information about what's been happening
recently, rather than totals of all activity for the system boot.

It's suggested to dump a line about which wakeup source
aborted suspend to aid analysis of these situations.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
PM / Runtime: Fix rpm_resume() return value for power.no_callbacks set

For devices whose power.no_callbacks flag is set, rpm_resume()
should return 1 if the device's parent is already active, so that
the callers of pm_runtime_get() don't think that they have to wait
for the device to resume (asynchronously) in that case (the core
won't queue up an asynchronous resume in that case, so there's
nothing to wait for anyway).

Modify the code accordingly (and make sure that an idle notification
will be queued up on success, even if 1 is to be returned).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
PM / Runtime: Clear power.deferred_resume on success in rpm_suspend()

The power.deferred_resume can only be set if the runtime PM status
of device is RPM_SUSPENDING and it should be cleared after its
status has been changed, regardless of whether or not the runtime
suspend has been successful.  However, it only is cleared on
suspend failure, while it may remain set on successful suspend and
is happily leaked to rpm_resume() executed in that case.

That shouldn't happen, so if power.deferred_resume is set in
rpm_suspend() after the status has been changed to RPM_SUSPENDED,
clear it before calling rpm_resume().  Then, it doesn't need to be
cleared before changing the status to RPM_SUSPENDING any more,
because it's always cleared after the status has been changed to
either RPM_SUSPENDED (on success) or RPM_ACTIVE (on failure).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
PM / Sleep: use resume event when call dpm_resume_early

When dpm_suspend_noirq fail, state is PMSG_SUSPEND,
should change to PMSG_RESUME when dpm_resume_early is called

Signed-off-by: Feng Hong <hongfeng@marvell.com>
Signed-off-by: Raul Xiong <xjian@marvell.com>
Signed-off-by: Neil Zhang <zhangwm@marvell.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
PM / QoS: fix wrong error-checking condition

dev_pm_qos_add_request() can return 0, 1, or a negative error code,
therefore the correct error test is "if (error < 0)." Checking just for
non-zero return code leads to erroneous setting of the req->dev pointer
to NULL, which then leads to a repeated call to
dev_pm_qos_add_ancestor_request() in st1232_ts_irq_handler(). This in turn
leads to an Oops, when the I2C host adapter is unloaded and reloaded again
because of the inconsistent state of its QoS request list.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
alarmtimer: implement minimum alarm interval for allowing suspend

alarmtimer suspend return -EBUSY if the next alarm will fire in less
than 2 seconds.  This allows one RTC seconds tick to occur subsequent
to this check before the alarm wakeup time is set, ensuring the wakeup
time is still in the future (assuming the RTC does not tick one more
second prior to setting the alarm).  If suspend is rejected, hold a
wakeup source for 2 seconds to process the alarm prior to reattempting
suspend.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ssr: Add notification to indicate a device restart

Send a 'soc_reset' notification to the drivers that have
registered for notifications about the subsystem when subsystem
restart has been called with the restart level set to SOC.
The drivers can then do the necessary cleanup/logging before a
kernel panic is trigerred.

Signed-off-by: Deepak Katragadda <dkatraga@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: subsystem-restart: Replace using wake lock APIs

Currently, the ssr framework uses the wake lock APIs. Instead,
use the power APIs directly.

Signed-off-by: Deepak Katragadda <dkatraga@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc: Migrate to wakeup sources from wake locks

Wakelock usage has been deprected. Update IPC Router to use wakeup
sources.

Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: smd_pkt: Remove incorrect use of smd_private.h

smd_private.h is an internal header file used to share private internal
details of the SMD driver to related components for the purposes of
debugging, segregating functionality, etc.  Nothing in smd_private.h
is intended to be exposed for client use, and including it in a file
should be a special exception, not a normal usecase.

The smd_pkt driver is using smd_private.h as a means to access the SMSM
public API.  Substitute the SMSM public api headers for the uses of
smd_private.h.

Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: smd_pkt: Replace wake locks with wakeup sources

Wake locks have been deprecated.

Remove deprecated wake lock calls and replace with wakeup sources and
power-management calls.

Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: smd: Replace wake locks with wakeup sources

Wake locks have been deprecated.

Remove deprecated wake lock calls and replace with wakeup sources and
power-management calls.

Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>