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>

Conflicts:
	Documentation/devicetree/bindings/arm/msm/pm-8x60.txt
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>

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
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: 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>

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
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>

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
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>

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
msm: pm-8x60: Use on_each_cpu instead of smp_call_function_many

The broadcast timer needs to be setup on all the online cores. As
smp_call_function_many doesn't execute the CPU invoking the call, switch
to using on_each_cpu. Also change the function prototype as it is called
only to turn on broadcast timers.

Change-Id: If7002d787d98b68cb229ebc40f3c817c5aefe1f1
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: Fix compile error due to incorrect include path

Trace header file location moved under <mach> to
fix cross compilations error.

Crs-fixed: 447863
Change-Id: Icb00dc6ebdba715ad1c432e2a8a9b34fcf3a08bd
Signed-off-by: Hanumant Singh <hanumant@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/include/mach/trace_msm_low_power.h
msm: pm-8x60: Fix incorrect computation of wakeup times

A incorrect computation of scheduled wakeup times, which is passed on to
RPM for wakeup from deep sleep modes, could result in the Core sleeping
for longer than intended during RPM assisted power collapse.

CRs-fixed: 488889
Change-Id: I26132c402e7839c3700b3d91514dd347dc1d478c
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm: add failed stats

for idle and supsend failed cases the stats
are not updated correctly, they are just added to
success bucket.

This patch is to log the failed stats separately.

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

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
msm: hotplug: wait for hotplug completion event from secondary core

Primary core has to wait for hotplug completion event from secondary
core to avoid race between ongoing hotplug and already queued online
event. This also prevent CPU_DEAD notifiers from executing before the
SPM has completed the collapse of the CPU. CPU DEAD notifiers executing
early have been attributed to MDD hardware block for the CPU being
turned off prematurely, resulting in crashes.
The patch also adds support for probing with device tree for 8974
targets.

Change-Id: Ibd35a7c56f42f156a643ca6d531509f019b2a3be
CRs-fixed: 438314
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/pm-8x60.c
msm: pm-8x60: Remove timeout waiting for cpu to power collapse

The delays in the CPU_DYING notication path could result in the core
initiating the hotplug to send out CPU_DEAD notifications after
msm_pm_wait_cpu_shutdown() times out. This could result in a unknown
resets when regulator/clocks are disabled in the CPU_DEAD path. To
prevent unknown resets, wait infinitely to enter power collapse but
throw a warning after the 1ms mark.

The platform_cpu_kill() path is also executed in the reboot path when a
core tries to stop secondary cores. In these cases, platform_cpu_kill
shouldn't wait infinitely for the secondary cores to power collapse. To
circumvent this scenario, track dying cpus as a part of the hotplug
notification and skip waiting for the core to power collpase during
reboot path.

Change-Id: I144e95a6d019e897381d2bca62ab50ecefd56b5b
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm-8x60: Increase warn timeout for sleep sts check

Arm cores take longer time to enter sleep. Wait for longer
time before warning until the CPU goes to sleep state.

Change-Id: I15caa8b2b2560aa68a4f4967c3364533234584b7
Signed-off-by: Priyanka Mathur <pmathur@codeaurora.org>
msm: pm: Fix broken bits

Change-Id: I71fa3901188706dd609f6bb5630976292a05c996