msm: cpr: Use regulator_get_voltage to get the voltage at PMIC

CPR driver was caching the last set voltage into the calibrated_uV,
which is wrong in the current configuration since the another entity
like DCVS driver could change the voltage by directly setting the
GO bit and appropriate performance level which could be different
from what was set by last regulator_set_voltage. Due to this
CPR recommendations could get adjusted at the wrong voltage. So
always the read the voltage through the regulator_get_voltage
API to get the voltage at the PMIC, rather than caching the values
in the CPR driver.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit 18a226c32921fda7f9edcc14b02d7b5d0b657acf)

Change-Id: I508b1113a4a4ddb794651d1d4efa231fe7c9ccbb
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: cpr: Clear the auto NACK down interrupt bit in freq. transition

CPR driver enables the auto NACK down interrupt bit right now
when the CPR suggests the voltage less than the Vmin limit
specified by the driver. It only gets re-enabled if we receive
the one UP interrupt. This may not work in the case when
the freq. transition happens where the DCVS driver sets
the new voltage and CPR suggests the correct down voltage
recommendation, so clear the NACK down enable bit during
the post change phase of the freq. transition.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit c43d1123046b2ae26da9c0d9644c625170342bf1)

Change-Id: I1bcd3d5f093dfd2cc284ae7b8e8342748cc47573
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: cpr: Add separate Vmin, Vmax for nominal and turbo frequencies

To have maximum power savings it is important to have separate
Vmin and Vmax defined for the nominal and turbo frequency ranges.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit db64ae9cc896f239acf783a6291e0680dfeebd3c)

Change-Id: Ibb93584b85454e667517a28439634e1715a61315
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/devices-msm7x27a.c
msm: cpr: Move suspend & resume to syscore hooks.

It is possible that CPUFREQ notifiers gets called as soon
as we come out of the PC and interrupts gets enabled. It is
required that CPR access gets enabled through CPR resume
before the CPUFREQ notifiers gets processed otherwise
we will fault on accessing the CPR registers. Move the
PM hooks to syscore operations so that CPR resume gets
called very early.

CRs-Fixed: 400357
CRs-Fixed: 399738
Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit 59024b4537e758d832471eaa01e0e21c036cf9ec)

Change-Id: Ida2e03911d9200ac4eb0efd94fd710499d178c62
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Protect the exported CPR functions when CPR is disabled

Exported CPR functions like suspend, resume, enable and disable
needs to be checked against the enable flag and return from them
if CPR is disabled using kernel command line.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit eec9214e1eb6c48f87889dbbacac7f897e43fa87)

Change-Id: I9be691385a50a82374da1f8e2bc1edf030ceffbe
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Update the CPR enable flag if probe fails

CPR probe could fail due to other checks and allocation
failures. CPR exports few functions like enable/disable/suspend/
resume functions so it is necessary to maintain the enable
flag to reflect the same status.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit 37b39980271300c11db394cf8d2630bdf13ecd0a)

Change-Id: I6f51ca2351f026bb23fe62deaaa0b15b9c0fa36e
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Use NOTIFY_OK to return the success from notifier callback

0x0 return code points to NOTIFY_DONE which means the Don't care
condition, which is used while returning from the notifier callback
with conditions which doesn't suit. If we are returning success
from the notifier then it should be NOTIFY_OK.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit c389e6f54a8981d37cab9612d749a680a6d75387)

Change-Id: Ic95fdabb37e5c30b6377424064aef44ff02af1a6
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Add margin and range for step quot

Based on chip characterization data, it is good to add some
margin on top of calculated step quot to help reduce the
number of CPR interrupts. The present value suggested is 3.
Further, if the step quot is outside range, clamp it to the
maximum permitted value.

Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
(cherry picked from commit bef2196a46c0e63a6ecc76f2fc2b6f06fe132382)

Change-Id: Ib00fa1fa6c51f632adc0c321809a4dcad7183526
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Tweak quot equation for better accuracy

The quot calculation can be made more accurate by doing
division last.

Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
(cherry picked from commit 549c7220ba08c4c510bc47d2ce1a6d7353c659d6)

Change-Id: Ice5d354796dad409b0e10d1f8fbcdee585eae90d
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/devices-msm7x27a.c
msm: cpr: Allow setting previous voltage after frequency transition

As per the regulator framework, regulator_set_voltage is a no-op if
the new voltage is same as the previous. Use regulator_sync_voltage
instead, which forcefully applies the same voltage. This is required
as there is a possibility of the voltage being changed by an external
source without the knowledge of the regulator framework.

Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
(cherry picked from commit 5323ddc592fcd5c870d9c4e432aecd918d5c0c2b)

Change-Id: Ib235b7d5e540a7adecc019a3042af302c3824e35
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/msm_cpr.c
msm: cpr: Avoid adding a step up to voltage set during config

The calibrated voltage could be at times set at the Vmax.
Avoid adding an extra step to this voltage to always
stay within permissible range of PMIC.

Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
(cherry picked from commit ff3b8bb3781d16c51db0b5c7bfa0ec6ea76bc84c)

Change-Id: Ica6a4da511b7cf5d944ecc13f97bd6bf850f15b3
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Add selective debug message logging

Add some verbose logging in some of the functions fordebugging.
Also, enable selective debug prints by configuring the debug_mask
module parameter. The debug prints are divided into 3
categories -
CONFIG (0x1) - Enable prints in configuration data
STEPS (0x2)- Enable prints in up/down interrupts
FREQ_TRANS (0x4) - Enable prints in frequency transitions

Individual category debug prints can be enabled by writing
into the module parameter at runtime.

Example:
Enable frequency transition debug messages
	echo 0x4 > /sys/module/msm_cpr/parameters/debug_mask

Change-Id: Ib52b613eebb1a57e48b9f950f5fbc84d9e08135d
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Allow CPR syscore resume/suspend to work without private data

The syscore suspend & resume hooks won't be able to access
the CPR private data rotated in the driver through dev_set_drvdata
and dev_get_drvdata. Let the hooks access the CPR instance.

Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
(cherry picked from commit 45e6fc241dad9c96153f51b24610b19db0caca2b)

Change-Id: I53dbd4753ea0e33bf00da9b718accfbb54f9bbbd
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Remove syscore ops from CPR

Remove syscore operations from CPR, since the suspend and resume
of CPR will be done from the PM driver.

Change-Id: I213d21b1051bdef2cf1ffe0101149f8f2a28b759
Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
msm: cpr: Update config as per new data

Update the values of down threshold, Vmin, delay as per
latest chip characterization data

Change-Id: Ieeacf3708ebbf85f8ff535a014d36a7b7de8b901
Signed-off-by: Kaushal Kumar <kaushalk@codeaurora.org>
Signed-off-by: Gopal Goberu <ggober@codeaurora.org>