msm: tracing: Add ftrace support for LPM driver

Add trace event support to capture various parameters
of low power modes like power collapse, standalone power
collapse, retention and wfi during its entry and exit.

Change-Id: I0f8b918702ae47b354aa193aa7ef20b48110fb0f
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
msm: pm-8x60: Do not default to WFI when not enabled

Return MSM_PM_SLEEP_MODE_NOT_SELECTED in msm_pm_idle_prepare as the
default mode instead of WFI. Skip enter low power mode when this
mode is selected.

Change-Id: Id4a07ba1353b358726c81ed441e0327a9154de8a
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
msm: pm: Add API to enable/disable retention mode

On 8974 targets, retention mode voltage is controlled by the LDO
regulator, which in turn is powered through a ganged PMIC regulators. At
certain low voltage levels, the ganged PMIC will not be able to power
the LDO retention voltage. The regulator framework would invoke this
API to enable/disable retention mode in these scenarios.

When disabling retention modes, send a IPI to wakeup all online cores
out of idle, to ensure that no core is in a retention low power mode.
Also, disabled support for retention during suspend/hotplug operations
to ensure that a CPU isn't already in retention when the voltage is
lowered. This shouldn't have an effect on suspend, as the driver always
chooses the deepest sleep mode for suspend/hotplug.

Change-Id: I0af18168968c2aaf05ca99188d30762612c87de6
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Modify L2 management mechanism in power collapse

Modify the L2 cache flush mechanism during Power collapse. For targets
with external L2 and TZ, L2 can only be flushed and not disabled as this
a secure operation. For targets with external L2 and no TZ kernel can flush
and disable the L2 cache. The decision on which cache flush mechanism to
use is determined by the power collapse type being exercised on that
platform.
Also modify the usage of qtimer based on target specific configuration
instead of using a socinfo based API to determine CPU type.

Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Change-Id: Ib937c15782760cb81e19ac7093cb1c4fffd36afd
msm: pm-8x60: Merge msm_pm_idle_prepare into msm_pm_idle_enter

Modify LPM drivers to call msm_pm_idle_enter when idle. enter_sleep will
look at available time to sleep and the latencies of different low power
modes and decide the low power mode to enter. It returns the low power
mode enumeration back to cpuidle.

Change-Id: Icbdaa6604824ea7d10c27f2d932d47d354da425e
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
msm: pm-8x60: Use ktime_get for suspend stats

During suspend, the sched clock is stopped and the suspends ops
cannot rely on sched clock to report time spent in suspend. Use ktime
interface to determine the time spent in suspend.

Change-Id: Id244cd8d470c45c1edd408e98ccaf84d30c3e253
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Don't save or restore GIC,VFP state in power collapse

Don't save or restore the GIC,VFP registers when entering or exiting power
collapse. The GIC and VFP drivers already register for PM notifications and
do the respective save/restore thereby making these operations redundant in
pm-8x60 driver.

Change-Id: If9969f8052843b2c7c1417dfeceaab203c6453b5
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Revert "msm: pm-8x60: Merge msm_pm_idle_prepare into msm_pm_idle_enter"

This reverts commit 269e15494da6d37756e5c0253242dd72a3a28ebe. The
rs_limits flag isn't updated for the lowest power mode. It was fixed on
kernel 3.7 branch. Reverting this change would allow cherry-picking the
3.7 patch without any conflicts.

Change-Id: I7ac20b603bed34dc596eca9b3723b332e188d6d6
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Overhaul the low power management driver

Overhaul the pm-8x60 driver code to remove the target specific runtime
state machine variables out of the driver code into its own board
specific files.

IMEM debug PC counters specified by debug-pc-cntr used to have its own
binding. Now that pm-8x60 has other bindings, use pm-8x60 device tree
bindings to handle debug PC counters.

Change-Id: I4f16008098c9525d3543ba23a5f58ddc3a8f942d
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Support to do PC at the running core frequency

New version of SAW2 (>v2.1), support turning off/on HFPLL only if the
PLL was active when entering power collapse. This eliminates the need
to switch to a lower frequency running off global PLL, and then turn
off the HFPLL. Power collapse with RPM notification should be a tad
bit faster.

Change-Id: I65c607454bd6c9a6b6da94e3946760e581ac761b
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Fix bug where CPU doesn't enter PC

When Krait regulator disables retention mode, an incorrect ordering of
the switch case disables power collapse.

Change-Id: Ic58b0356530e9ecb10d379e2f99d14016bc251e4
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Debugfs node to read PC warmboot counters

Add debugfs to read warmboot counters from IMEM memory.

Sample output is as follows.
cat /sys/kernel/debug/pc_debug_counter
CPU0
        PC Entry Counter : 378
        Warmboot Entry Counter : 370
        PC Bailout Counter : 8
CPU1
        PC Entry Counter : 10
        Warmboot Entry Counter : 10
        PC Bailout Counter : 0
CPU2
        PC Entry Counter : 6
        Warmboot Entry Counter : 6
        PC Bailout Counter : 0
CPU3
        PC Entry Counter : 2
        Warmboot Entry Counter : 2
        PC Bailout Counter : 0

Change-Id: I245c80b88fee9bd6bef89fdcb4d0721622bd4d28
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Merge msm_pm_idle_prepare into msm_pm_idle_enter

Modify LPM drivers to call msm_pm_idle_enter when idle. enter_sleep will
look at available time to sleep and the latencies of different low power
modes and decide the low power mode to enter. It returns the low power
mode enumeration back to cpuidle.

Change-Id: I56717f2ba7a748b38d53b418381a01159055e7bd
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Remove enum from devicetree

Replace enums with strings in Device tree for pc-mode

Change-Id: If63212e07e42f7b0b9d4dd046ae52f0349901154
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
Revert "msm: pm-8x60: Use ktime_get for suspend stats"

This reverts commit 0664ee443041626fc7f7811616012444f6b20261. On 3.7
kernel, the sched_clock is stopped during suspend/resume and was
reporting time in suspend as zero. On 3.4 kernel, ktime_get() throws a
warning when invoked from suspend ops.

Change-Id: Id989da42a1c2600f9c09c527ffff7a8a1ac52090
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Disable premption in msm_pm_enable_retention

msm_pm_retention_enable() makes smp_call_function_many to ensure that
when a retention is disabled, the cores come out of its low power mode.
Per the smp_call_function_many documentations, preemption should be
disabled before invoking the API.

CRs-fixed: 463188
Change-Id: I4ae9137e8f8e821af729becd0e2d6e6886d5e787
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Add early return to msm_pm_enable_retention()

If retention is already disabled, it is not necessary to send IPIs to
the running CPUs to wake them up. Insert an early return for this
scenario to reduce overhead during Krait rail voltage scaling, which
calls this API on every voltage change.

Change-Id: I5db0bafae187ff8a68488e86d4787df9c45787e4
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
msm: pm-8x60: Use broadcast clockevent for idle wakeup

The architected timers loses its state in certain low power modes.
In these modes, migrate the timers to use the broadcast clockevents for
scheduled wakeups.

Change-Id: I414ea5a3dab69f5257da95a6847e3188f5efc6aa
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Fix comparison of unsigned variable against 0

Comparing unsigned variable 'count' against zero has no effect. Hence
remove them.

Change-Id: I4e03b33b6f193a56800074c3d1597cf0c52dc3e8
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Remove unused API msm_pm_set_max_sleep_time()

msm_pm_set_max_sleep_time() was used by rtc drivers to wake a system up
from suspend on targets that doesn't have a RTC hardware. The targets
that invoke pm-8x60 has dedicated rtc drivers and can rely them for
wakeup from suspend.

While at it also remove the max sleep limit imposed during idle sleep.
The code seems to have been ported over from older targets but the
targets with these limitations aren't supported by the pm-8x60 file.

Change-Id: I03a78f226b50aa24504537c81b9fc7fa00eca883
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>