msm: pm: Support for Krait Retention

Introduce a new low power state for Krait, retention.
This state will lower the voltage to the Krait core to
retention voltage in addition to clock gating. This state
will be in between WFI and Standalone power collapse in
terms of time overhead and power savings.

Change-Id: I6b1f0a0d2e4954a705a047fd4a07f4dd1fb3518a
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
(cherry picked from commit d27ca4a7526a890f9d2979acefda3561e49d2e66)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
(cherry picked from commit 3af7249c36ab53923fdf216df3b3ba2c7f847851)

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: avs: Add API to restore the AVSCSR register

During power collapse, the AVSCSR register is always enabled and never
restored. This could result in AVS getting enabled on resume, when the
core is running at a frequency that doesn't support AVS.

Add new API, avs_enable, which restores the AVSCSR register based on the
saved AVSCSR register. Update the avs_disable API, to return the
AVSCSR register value prior to disabling the AVS.

(cherry picked from commit ad138da17fe08d46412d56b84309c5d17f7d5931)

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

Change-Id: I2bd2e1d6aea058e0f44c474da6c3121654f1236e
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: pm: Adjust for events with hard wakeups

Get the next event and setup a new timer to expire
earlier than the next event after accounting for the
latency of the low power state being entered. This
will ensure that the core is active to handle the event
when it arrives.

(cherry picked from commit dc318fd0c3d04f7af9720af50c0eb0c6ed2653e9)
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>

Change-Id: I6609a886df227c68ce78e270ef7d235e07725d44
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: pm-8x60: save and restore CP15 registers

To prevent the Krait core configuration from being indvertently changed
when doing L2 power collapse, save a few CP15 registers and restore them
back after coming out of power collapse. This needs to be done after
switching the Krait from active freq to QSB clock source.

Before doing power collapse, the core0 clock switches over to QSB. However,
QSB can run at any frequency and the voltage required for that
frequency, needs to be ensured when coming out power collapse. If the
QSB clock at resume, is a higher frequency at than the QSB clock was at
collapse, then we may run the risk of running at higher clock with a
lower voltage.

Hence, switch to 1.0 V (safe vdd) when going into PC (after switching to
QSB clock source) and the SPM would resume at 1.0V. After the core
starts running, restore the CP15 registers and switch to the previously
saved active voltage, before switching clocks to the active frequency.

This is applicable only for APQ8064.

Change-Id: I75a70f5e07bd581fc8028bed79de7ee796f4c411
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: pm-8x60: Fix bug where device enter low power mode

An incorrect ordering in the check of allowed modes, results in
standalone power collapse not getting selected when the secondary
cores are online.

Change-Id: Idc7177b78bd0ce7563cc27afbf6c12d3bc1f9f9a
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Revert "msm: pm-8x60: save and restore CP15 registers"

This reverts commit 3ed57e2152880a5703375d230cc272781bbfae9d.
msm: dcvs: change tz buffer to 32KB - https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=commitdiff;h=3edb5de258e187af999aafc35dc9588d980d3cbf

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
auto_hotplug.c: reduce sampling periods from 20 to 15.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
board: mako: add support for retention power state on mako's board. Borrow touch values from Harsh.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
mm: writeback: every 500ms the writeback daemon kicks in and flushes the dirty pages into disk. Thats not very pleasant for performance and *maybe* battery. This patch disables the writeback function while the screen is on, and enables it back when the screen is off to flush all the dirty pages. In my real world usage testing I notice a slight bump in smoothness and performance while using the device.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Add missing file needed for one of the Krait Retention patches.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>