msm: idle: Use ARM suspend/resume APIs to restore during warmboot

ARM generic cpu_suspend/resume APIs restore the necessary CP15 registers
to a known state when resuming from a reset state. Use of generic
suspend/resume APIs allows the msm warmboot code to not care about
restoring core registers used by ARM kernel. Also, the PM subsystem no
longer needs to allocate page table or uncached memory to save CPU
registers.

While at it convert most of the assembler code into respective C
function except for warmboot code that executes with MMU turned off.
Also, the idle subsystem no longer needs to manage a  page table or
uncached memory to save CPU registers.

Change-Id: I78a75d0a3c703390eec476199c7ca2786360e12a
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: Karthik Parsha <kparsha@codeaurora.org>
hammerhead: pm-8x60: Register sleep status driver before regulator

Change-Id: Id31df8b06d72baca048459b0c0385a37cde1395e
Revert "msm: lpm_levels: Adjust latency for Multi core cases"

This reverts commit b4e82b5c6ffac10efaae98213a57988ad424f2e7. The
performance and power benefits obtained with these changes were minimal
and hence removing this change.

Change-Id: I8495d4e7a669a5a0eb519e853eb0d45508a64c1a
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm: Rename pm-8x60.c to msm-pm.c

pm-8x60.c doesn't accurately reflect the current list of targets that
are supported. So renaming them to msm-pm.c to be more inline with the
msm chipsets.

Change-Id: Iefa8150885f8da136de7cba4a122ec901a171a02
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: rpm_stats: show master votes for xo/cxo sleep mode

RPM sleep stats structure has "client_votes" field. It
provides the information of masters who is preventing
the RPM from entering the associated sleep mode(xo/cxo).
Print client_votes info along with xo & vddmin stats.

CRs-fixed: 576283
Change-Id: Ia656add1b8ade7a92502058b8eb6a22516990b7a
Signed-off-by: Harry Yang <harryy@codeaurora.org>
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
msm: pm: Rearchitect power management code

The existing PM code relies on a levels table to determine the various
sleep modes including the system sleep states. Splitting them into cpu
and system/cluster specific levels is a more appropriate representation
of the existing system. As a part of this rearchitecture, the decision
to enter a low power mode is made within lpm_levels module. Unlike
earlier, the decision was split between pm-8x60 and lpm_levels.

To this effect, the lpm_levels directly registers with the cpuidle
driver instead of relying on a glue msm-cpuidle driver. The
functionality of the cpuidle driver was limited to calling into a PM
driver and without providing any additional functionality.

While at it, also remove any references to unused enums and
functionality.

Change-Id: I474cc85c6220473fdaa87e14e3b0a199e95d7eb7
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: clock-krait-8974: Change ref count behavior at boot

Set up the refcount of the L2 clock to be equal to the number of online
cores. This allows the clients of the CPU/L2 clocks that enable/disable
them to be agnostic of the no. of cores that are online.

For example, the CPU idle code can call clk_disable() on the L2 clock from
all the cores' idle path without having to figure out if it's the last
active core. If the core is the last core that's active, the ref count will
go from 1 to 0 and the clock would get disabled.

Also update cpufreq driver behavior to accomodate this change.

Change-Id: If253a85ad62f0a6a78452dafc7afe86bd112cf73
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: lpm_levels: Support for RPM PC on all cores

When more than one core is online, the current model prevent entering
idle power collapse on all cores and the deepest sleep mode that a
cpu could enter is standalone power collapse. To achieve better power
savings when several cores are online all the time, it is important for
multiple cores to enter a deeper system sleep state by configuring L2
and RPM.

Each core entering the deepest sleep mode increments a counter. The
last core to enter the deepest sleep mode will acquire a lock and will
be responsible for configuring the system low power mode.  cpus. The
last core going down will configure the system wide resources with the
lock held. If a core were to wakeup during this time, it would have to
wait for the lock to be released before it can continue to resume. The
last core releases the lock after configuring the system resources at
which point, the core that resumed from power collapse would reset the
system resources before continuing to run to ensure that the shared
resources are programmed for a safe state.

With this change the idle PC becomes more of a soft state where each
core identifies that its safe to enter a system sleep state. The
decision to enter a system sleep mode is based on the next wakeup event
across all cores. With not all cores encoutering latency associated with
system sleep modes, the residency of idle PC mode will be lower than
what it has been previously acheived. However, the residency of the
system sleep states should be unaffected.

Each core as its power collapsed disables the HFPLL and switches to
GFPLL in the event of a power collapse. During this time, each cores
removes its vote to keep L2 enabled. To ensure that there are enough
votes for keep L2 on, set the number of L2 votes to number of online
cpus in cpufreq.c

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

Conflicts:
	arch/arm/boot/dts/msm8226-v2-pm.dtsi
	arch/arm/boot/dts/msm8610-v1-pm.dtsi
	arch/arm/boot/dts/msm8974pro-pm.dtsi
msm: pm: Set affinity of PM irqs to next scheduled CPU

Modify the affinity of the interrupts associated with PM driver to the cpu
that will wakeup for the next expiring timer.

Change-Id: I6a1b25538a6d12bada3345a17b3ed4ff181ac089
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: pm: Disable cpu clk during retention

The CPU clock source MUXes cannot switch while a CPU is in
retention, but callers of acpuclock APIs may not known that
the CPU is in retention.

Fix issue by disabling the cpu clk before entering retention and
re-enable them on exit. This would temporarily switch the CPU to 300Mhz
and clk api would buffer any clock requests until the clk is enabled
when the core comes out of retention.

CRs-fixed: 535967
Change-Id: I103e41fc8ef78cd412b7860bf525ea9cd99ff283
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
msm: pm-stats: Move to seq_file and friends

In future kernels create_proc_entry() is going to be removed.
Let's modernize this code and use regular file operations and
seq_printf() to avoid experiencing compilation problems in future
kernels.

Change-Id: Ibeca64a8346d33e1b66b089990c17f1b1dbaf5db
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
msm: pm: add new stat variable for reporting suspend stats

Incorrectly reporting suspend stats because of moving timekeeping
logic to prepare/resume callbacks in suspend. Declared a new
global system_suspend stat variable for reporting suspend
stats and removed the suspend stats for each core.

CRs-fixed: 584850
Change-Id: Idead3cdb7b40ccca3fd91371a10378f4b5f72d95
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
msm: rpm-regulator-smd: limit current to RPM defined maximum

Modify the rpm_vreg_get_optimum_mode() function so that it
restricts the maximum current that can be sent for the 'ma' KVP
to the limit defined by the RPM.

Change-Id: I744e656c75a5e78a81df9c283a8f14a977c4c6ee
Signed-off-by: David Collins <collinsd@codeaurora.org>
msm: rpm-regulator-smd: remove incorrect rpm_regulator_get() unlock calls

The rpm_regulator_get() function calls rpm_vreg_unlock() in
failure paths after two kzalloc() calls.  However, there is no
corresponding rpm_vreg_lock() call before these calls.  Also, the
code being executed does not require mutual exclusion.  Thus,
remove the rpm_vreg_unlock() calls in order to avoid possible
locking problems if kzalloc() fails.

Change-Id: I0a0f2ffde5a6c54600a823e3ed12c3c47c3bac6a
Signed-off-by: David Collins <collinsd@codeaurora.org>
msm: acpuclock: Delete legacy acpuclock-krait drivers

The acpuclock-krait driver and the corresponding chip specific files have
been replaced with the clock-krait and clock-krait-8974 driver and
corresponding DT nodes. So, delete the unused files.

Change-Id: I193f0ae37940b537dec4fdfc2a3638d8cb0bcf0a
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>