msm: lpm_levels: Fix incorrect computation of next wakeup time

The next event timer wakeup was incorrectly computed when the hard timer
event doesn't exist. Fix by ensuring the next wakeup is computed only
when a timer event is valid

Change-Id: I40c1f372f84d8f43b2101e37dcfb592193d4b2e0
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: lpm_levels: update suspend stats counters and time

suspend stats in the debug pm stats are not getting updated as
suspend stats in the suspend wake path is missing. This change
will add and update the suspend stats in the suspend wake path.

Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: lpm_levels: fix incorrect mode select with next event time

Based on the next event timer value the best power mode will get
selected but there is a mismatch in calculation of selecting
the best mode. This change will fix that and selects the correct
mode based on the next wakeup time.

Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: lpm_levels: fix driver compilation issue

Assigning an unsinged long value to unsinged int is not
correct and it cause driver compilation failure. Fix by
assigning a proper value.

Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: lpm_levels: Perform system_unprepare only system low power mode

system_unprepare() needs to execute operations related to system
unprepare only when the CPU subsystem was scheduled for a system low
power mode by the last core that went down. On the last core down, its
possible that residency conditions for system low power mode weren't met
and the system was never programmed to enter a low power mode. In these
scenarios, the system_unprepare() needn't execute any of the unprepare
functionalities.

Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: lpm_levels: return new idle level to cpuidle framework

Need to return the new idle level to cpuidle framework
but just returned input value argument 'index' which is
not used actually at lpm_cpu_power_select().

Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
After long search and trace i did all i can and still got this on sus…
…pend!

So i have solved it for now by timekeeping_resume(); in case it's suspended
when someone that hiding GOOD from me!!! request it during suspend!!!
no idea who! as trace dont show any one else in path that i didnt patched...

Any way no problem now :)

<6>uei_irrc_suspend
<6>PM: suspend of devices complete after 53.084 msecs
<6>PM: late suspend of devices complete after 3.826 msecs
<6>PM: noirq suspend of devices complete after 4.961 msecs
<4>Disabling non-boot CPUs ...
<6>CPU0: msm_cpu_pm_enter_sleep mode:3
<4>------------[ cut here ]------------
<4>WARNING: at kernel/time/timekeeping.c:221 ktime_get+0x138/0x13c()
<4>Modules linked in: exfat
<4>[<c010d23c>] (unwind_backtrace) from [<c0194688>] (warn_slowpath_common+0x60/0x80)
<4>[<c0194688>] (warn_slowpath_common) from [<c019475c>] (warn_slowpath_null+0x1c/0x24)
<4>[<c019475c>] (warn_slowpath_null) from [<c01dd950>] (ktime_get+0x138/0x13c)
<4>[<c01dd950>] (ktime_get) from [<c011d814>] (hfpll_enable+0xdc/0x1b0)
<4>[<c011d814>] (hfpll_enable) from [<c011db20>] (set_speed+0x94/0xcc)
<4>[<c011db20>] (set_speed) from [<c011de18>] (acpuclk_krait_set_rate+0x2c0/0x694)
<4>[<c011de18>] (acpuclk_krait_set_rate) from [<c016ebd4>] (msm_pm_power_collapse+0x1d0/0x2b0)
<4>[<c016ebd4>] (msm_pm_power_collapse) from [<c016fce4>] (msm_cpu_pm_enter_sleep+0xdc/0x10c)
<4>[<c016fce4>] (msm_cpu_pm_enter_sleep) from [<c0173160>] (lpm_enter_low_power.constprop.7+0x270/0x674)
<4>[<c0173160>] (lpm_enter_low_power.constprop.7) from [<c0173768>] (lpm_suspend_enter+0x70/0x90)
<4>[<c0173768>] (lpm_suspend_enter) from [<c01dc048>] (suspend_devices_and_enter+0x3ac/0x418)
<4>[<c01dc048>] (suspend_devices_and_enter) from [<c01dc2a4>] (pm_suspend+0x1f0/0x288)
<4>[<c01dc2a4>] (pm_suspend) from [<c01dc8c8>] (try_to_suspend+0xa4/0xb8)
<4>[<c01dc8c8>] (try_to_suspend) from [<c01ac318>] (process_one_work+0x1a0/0x454)
<4>[<c01ac318>] (process_one_work) from [<c01acff4>] (worker_thread+0x19c/0x4e8)
<4>[<c01acff4>] (worker_thread) from [<c01b18ac>] (kthread+0xd4/0xec)
<4>[<c01b18ac>] (kthread) from [<c010748c>] (kernel_thread_exit+0x0/0x8)
<4>---[ end trace 4361d2dce7fe3785 ]---
<4>__qpnpint_handle_irq: 637 triggered [0x0, 0xdd,0x0] smb349_irq
<6>PM: noirq resume of devices complete after 3.485 msecs
<6>PM: early resume of devices complete after 0.940 msecs
<6>qup_i2c f9967000.i2c: i2c is runtime suspended status !!! try to runtime resume !!!
<6>qup_i2c f9923000.i2c: i2c is runtime suspended status !!! try to runtime resume !!!
<6>qup_i2c f9924000.i2c: i2c is runtime suspended status !!! try to runtime resume !!!
<6>uei_irrc_resume
Partial Revert of MY HACK for ktime_get on suspend. + fix.
*I suspect that my HACK made some mess in suspend control.
and may have been responsible for SODS. on screen OFF.

this partial revert of
3d33e22

and merge fix commit:
neobuddy89/hammerhead_kernel_caf@8852aa4

So far all GOOD. no dmesg logs on suspend and suspend working as should.
It should fix msm: lpm_levels: remove rpm handshake in l2_gdhs mode
Remove rpm handshake in l2_gdhs mode and adjust the
latency values for l2_gdhs mode. Add a new dt entry to
inform lpm_levels driver to send sleep votes to rpm.
msm: lpm_levels: remove debug print
remove a pr_info that was added for debug purpose. This is
causing excessive logging issues.

CRs-fixed: 589307
Change-Id: I1f7bcb5282b51734cb7bf30ff933d65714445cba
Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>
power: quickwakeup: initial driver
This driver allows clients to register code to be called upon wakeup
so that clients can perform specific checks and vote to drop the system
back into suspend without fully resuming if the wake reason was a special
quick wakeup event.

Propagation of (CR)

Change-Id: I791ff02f34b616e6da2b68efc2d4eb4449e5bbe7
Signed-off-by: James Wylder <jwylder1@motorola.com>
Signed-off-by: Jared Suttles <jsuttles@motorola.com>
Signed-off-by: Joe Swantek <w98568@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/611835
SLTApproved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Joseph Swantek <jswantek@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
msm: lpm: remove redundant assignment
Removed the redundant cpu level is assignment.

Change-Id: I1aecc4f3d1eb55cd9e057c82f63b8f145401c0fc
Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>