msm: thermal: Add IOCTL interface support to Kernel Thermal Monitor

Kernel Thermal Monitor exposes an IOCTL dev interface, which can
be used for user space cpu frequency mitigation.

CRs-Fixed: 538981
Change-Id: Idb8b836970f7d5d029fea606aaa4f7958c982f68
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Add support for requesting optimum current for CX rail

Add support for KTM to request for an optimum current value for
CX rail, when the temperature reaches a preset threshold.

During boot-up, KTM monitors the temperature and makes
a request for optimum current.
After boot-up thermal-engine monitors the temperature
and requests for optimum current value through KTM's
sysfs nodes.

CRs-Fixed: 574569
Change-Id: I9fa184e4921f440ef5b5539dc9573527140f2207
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
ARM: dts: msm: Add CX regulator Phandle to MDP node

The Phandle might change for different
versions of the msm8974 chip. Add the proper
Phandle of CX regulator to 8974 v2 and
8974pro versions.

Change-Id: Ifce120fcb349360e36c4ea74bcaf5ea14e1dece5
Signed-off-by: Chandan Uddaraju <chandanu@codeaurora.org>
ARM: dts: msm: Add krait-regulator-pmic devices to support the gang leader

Add entries to describe the gang leader and its associated peripherals.

On 8974v1, 8974v2, and 8974pro-ab based devices, PMIC 8841 SMPS 5
regulator is the gang leader.

On 8974pro-ac PMIC 8084 SMPS 8 regulator is the gang leader.

Change-Id: I67e2aea81743ab1f463cca8961d7700e48dc6283
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
ARM: dts: msm: 8974 V2 specific regulator setting

Regulator settings are moved from general sensor
dtsi to 8974 V2 specific ones. This change applies to
8974 cdp, fluid, liquid and mtp.
After this change, camera vote for automode applies
in V2 only but not PRO.

Change-Id: I5108526bf0e978ad2022ac13597f7eda5f5f92d9
Signed-off-by: Xu Han <hanxu@codeaurora.org>
msm: mdss: Configure minimum voltage for CX power rail

For smart panels, we observe abnormal waveforms
and unexpected voltage spikes on DSI data lanes
when the cx power rail goes to minimum voltage.
Vote for the cx regulator in mdp driver and control
the voltage to avoid frame shifting.

Change-Id: I7ec9e29a4972373775406fa29a5037fd43fef315
Signed-off-by: Chandan Uddaraju <chandanu@codeaurora.org>
msm: mdss: Add battery FET regulator usage

During idle power-collapse using smart-panel, when PMIC chip goes to
sleep, it puts battery FET (batfet) to low power mode (LPM) which allows
less than 100mA current to be drawn. Since smart-panel is in self-refresh
mode, it can still draw more than 100mA current causing PMIC and MSM
reset. To fix this issue, batfet has to be kept in high power mode (HPM).
In order to keep batfet in HPM, display driver enables batfet regulator
whenever display panel is on.

Change-Id: I2f3d9f20fcf86b3147ac7396d56f93bfc08377c7
Signed-off-by: Shalabh Jain <shalabhj@codeaurora.org>
msm: mdss: Detach mdss iommu on static screen

Detach mdss iommu on static screen and re-attach
on next commit to allow full power collapse of MDSS.
IOMMU driver keeps its vote for bus bandwidth for as
long as the MDP driver is attached to the IOMMU.
When MDP detaches from the IOMMU, IOMMU driver will
remove its vote for bus bandwidth.

Change-Id: I1e5c5c50bc157c3ebfc63e198e4608dad820a288
Signed-off-by: Pawan Kumar <pavaku@codeaurora.org>
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
ARM: dts: msm: Add KTM hotplug feature for msm8974

Add entry for hotplug threshold. Set hotplug threshold and threshold
hysteresis to 110degC and 90degC respectively.

Add cpu sensors mapping.

CRs-Fixed: 515110
Change-Id: I86335b0e5d19894ada82ee8a2113ed0940276aad
Signed-off-by: Jennifer Liu <chihning@codeaurora.org>
ARM: dts: msm: Enable emergency frequency mitigation for MSM8974

Specify the frequency mitigation threshold and the max frequency
to which KTM should mitigate the cpu. This mitigation is enabled
only for cpu 0, but can be extended to other cpu's by modifying
the cpu mask.

CRs-Fixed: 538981
Change-Id: I062d7a048961ffa77bfb52e19c78a9a31e9894e7
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
arm: dts: Fix incorrectly named cpu mode.

The standalone pc mode was incorrectly marked as spc instead of
standalone-pc

Change-Id: Ia6485ff20a7d123f76d1149c16611d5f526d3c3b
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: sps: Fix error case handling in probe function

Fix possible NULL pointer dereference in the probe
function by adding proper error case handling for
clk errors.

CRs-fixed: 583991
Change-Id: Ief54cc28487e5559a893fa2f4c57148e76bd1acb
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
msm: devfreq_cpubw: Add devfreq driver for CPU to DDR bandwidth voting

This driver registers itself as a devfreq device that allows devfreq
governors to make CPU to DDR IB/AB bandwidth votes. This driver allows the
governors to be agnostic of the bandwidth voting APIs, the number of CPU
master ports or DDR slave ports, the actual port numbers, the system
topology, the available DDR frequencies, etc.

Change-Id: If055ddd580afd41f9668b111e6c09a047488b2e0
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
(cherry picked from commit cadc893a7512ad8b5bc257062f2cebaf7ae49a55)
ARM: dts: msm: Move parameters to device tree for 8226

Add parameters for the clock-a7 device.

Change-Id: I94a9620b46bcbe30bd277f0213b176ccb9cbe509
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>

Conflicts:
	arch/arm/boot/dts/msm8226-v2-pm.dtsi
devfreq: Add MSM CPUfreq governor

The MSM CPUfreq devfreq governor determines the CPU to DDR bandwidth vote
based on the current CPU frequency of all the active CPUs.

This functionality used to be a part of the MSM CPUfreq driver that
directly voted for the CPU to DDR bandwidth using MSM bus scaling APIs.
This refactor decouples CPU to DDR BW scaling from CPU frequency and allows
switch between various CPU BW governors.

The bandwidth values in the msm-cpufreq table have to be updated since the
new CPU BW driver does the MBps to Bps conversion correctly. The MSM
CPUfreq driver used to do * 1000 * 1000 to convert from MBps to Bps instead
of doing * 1024 * 1024.

Change-Id: I184f09d628a1b27d52506d2f760d65831f1a1110
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
(cherry picked from commit 4bbc993b178bca1969f2e4b122a32e0e589ee839)
devfreq: Add CPUBW HW monitor governor

The CPUBW HW monitor devfreq governor uses the Krait L2 PM counters to
determine the bandwidth needed by the Krait CPU subsystem. This governor
can be used in conjunction with the CPUBW devfreq device to dynamically
scale the DDR frequency based on the demand/actual usage from the Krait CPU
subsystem. Since this governor uses the Krait L2 PM counters it can
conflict with certain profiling tools.

The Krait L2 performance monitor counters have the capability to count the
no. of read/write transactions going out the master ports. They also have
the capability to raise interrupts when they overflow. This driver uses
those counters to determine the true usage of DDR from the Krait processor
subsystem and then recommends CPU DDR BW votes based on the measured values
and the following tunable parameters.

The driver provides various tunables that allow it to be tuned more in
favor of power or performance:

- io_percent: The percentage of the CPU time that can be spent waiting on
  memory I/O. Lower value is better performance and worse power.

- sample_ms: The sampling period in milliseconds. This only affects the
  sampling period when DDR use is ramping down or is increasing very slowly
  (See tolerance_percent).

- tolerance_percent: The minimum increase in DDR use, compared to previous
  sample, that will trigger an IRQ to immediately bump up the bandwidth
  vote. It's expressed as a percentage of the previous sampled DDR use.

- decay_rate: The parameter controls the rate at which the history is
  forgotten when ramping down. This is expressed as a percentage of history
  to be forgotten.  So 100% means ignore history, 0% mean never forget the
  historical max. The default 90% means forget 90% of history each time.

- guard_band_mbps: This is a margin that's added to the measured BW (and
  hence also the Bus BW votes) that's present to account for the time it
  takes to ramp up the DDR BW while the CPU continues to use the DDR.

- bw_step: All BW votes are rounded up to multiples of bw_step. The default
  value is 200 MB/s that turns out to ~25 or 12.5 MHz based on the SoC. A
  smaller value would mean more frequent bus BW changes. A higher value
  would mean less frequent BW vote updates, but also means at times an
  unnecessarily higher BW vote (due to the rounding up).

Change-Id: I88629a3e545cdca7160af8f8ca616ecc949d9947
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
(cherry picked from commit 6cad047fc7d8cf005b9ae588c3eba30e1cfeee40)
ARM: dts: msm: Add kraitbw-l2pm device for 8974

This device provides the hardware details needed by the kraitbw_l2pm
devfreq governor to measure the DDR usage from the Krait CPU subsystem and
the IRQ that's needed to react quickly to usage changes.

Change-Id: I778a36839c9b2279ab2d912715cd7eba091fe25f
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
(cherry picked from commit c5a2aad3989bedeb995ee9c8681b1c71f04f5052)
Revert "msm: cpubw-krait: Vote for Krait-DDR bandwidth by monitoring transactions."

This reverts commit 591fbb26b1f60bc26fa8657213440e4c1391516c.

The functionality provided by this reverted commit is now provided by
multiple drivers that hook into the devfreq framework.

Change-Id: Ibb019f3df4188ac358270556a3a92729af98a3ef
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
(cherry picked from commit adc1609caa5691de1c6ff2bd69276a6ce49f50f5)
msm: smd: Use irq_set_affinity() API instead of the callback in irqchip.

When affinity is set by directly accessing the function pointer via
irqchip, the irq doesn't get migrated during hotplug and could result in
spurious wakeup of offlined cores. Switch to using irq_set_affinity
which ensures that the irq gets migrated during hotplug.

Change-Id: If700323f636d4ee4978b5e168077514e4d142cb9
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
(cherry picked from commit 00e4ba3a54e92cbb8f8353b8db38dd681332d2fe)
ARM: dts: msm: Update 8974Pro PVS table to config v1

Update 2.5GHz and 2.3GHz RC1 tables to latest voltage plan.
Added PVS config version property.

Change-Id: I7344e81485246191c518f7d644c401ca1934e800
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>