Simple GPU Algorithm: Initial coding for devfreq based Adreno Drivers
This is an open source user configurable simple GPU Control Algorithm used to
replace the closed sourced Qualcomm TrustZone GPU controller

Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: renderbroken <zkennedy87@gmail.com>
SIMPLE GPU ALGORITHM: Fix stuck on low GPU greq after adding more GPu STEPS!

After commit https://github.com/dorimanx/Dorimanx-LG-G2-D802-Kernel/commit/f13203708dd07220ca5c1892c0110b9deef31386 and https://github.com/dorimanx/Dorimanx-LG-G2-D802-Kernel/commit/07264550123b131dff09eb17f76c3e3729786a9a
With msm adreno tz gov and simple_gpu_activate set to 1
i was stuck on 100Mhz as new steps changed the logic.

on idle before patch:
level is 6
bus.num = 4 and it's static!
bin.busy_time = 1000~8000 but only if it's set as (unsigned int)priv->bin.busy_time !!!

on idle after patch!
level is 6
bus.num = 6 STATIC!
bin.busy_time = 1000~8000 so we can check > ramp_up_threshold

@faux123 this why freq was not going UP with msm adreno tz when using this mod.
when mode was OFF. freq was going up as should.

but using this mode i can hold the freq longer on high freq. and that is COOl.
DTSI: add 320/200Mhz GPU FREQ + Allow to be idle on 200Mhz + boost.
msm: kgsl: Remove io_fraction as it is no longer used

io_fraction was originally used as a way to influence the CPU
frequency governor.  Due to governor updates and timing changes
no targets use io_fraction now and there is no plan to do so in
the future.

Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
arm/dt: msm8974-gpu: Enable qcom bus-control
msm8974: Add GPU frequency steps (533 + 650)Mhz :) Thanks @neobuddy89

*Fixed show low OFF freq (27Mhz) then GPU is in SLAMBER mode (off/waiting).
*Fixed thermal pwr level preventing of using max 650Mhz
This also allowed to use higher GPU FREQ as 450Mhz on HIGH temp.
before we got only 320/389 max on > 70c
This added +3~5C to max TEMP. so i see 77C~78C with high 3D pressure.
MSM THERMAL, rules! and keep the CPU safe. :) no problem.
*Allowed IDLE/INIT GPU Freq to 100Mhz. was 200. this will reduce battery usage.
*Tuned BUS freq power for all GPu freqs.
GPUFREQ: Allow higher bus-freq on all high GPU freqs.
power: make sync on suspend optional

On embedded devices with built-in batteries, it is not so
important to sync the file systems before suspend.  The chance
of losing power during suspend are no greater than they are
when the system is awake.  The sync operations can greatly
increase suspend latency when the system has accrued many dirty
pages and/or the target storage devices are not particularly
fast.

This commit adds a kernel config option to allow file system
sync in the suspend and earlysuspend paths to be disabled.  It is
enabled by default.  It also exposes two command line options to
control this feature: suspendsync and earlysuspendsync.

Signed-off-by: Russ Knize <Russ.Knize@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/614512
SLTApproved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Igor Kovalenko <igork@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
[neo: Disabled by default.]
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>

Dorimanx Note:
Added ONE time sync when screen goes OFF just in case.
function static int enter_state(suspend_state_t state)
is executed many times during long suspend, on every cpu wakeup
so now we will not SYNC filesystem each time, there is not need for that.

This should save little battery power, and reduce suspend cpu time.
Asynchronous Fsync: initial extraction of Async Fsync from HTC

Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:

	drivers/mmc/core/mmc.c
FAST CHARGE: new hack to allow detect any USB cable as ORIGINAL Cable.

This allow faster file transfer USB 2.0 and can help with faster charging.
FAST CHARGE: Ver 1.4 added new controls to bypass ROM thermal control.

If i want to use Intelli thermal i cant get more than 300ma! as no one
telling to kernel to allow high charge power.

by doing:
echo 1600 > /sys/module/smb349_charger/parameters/smb349_thermal_mitigation

so the smb349_thermal_mitigation stay 300ma

now kernel will use fake charge mA value to boost smb349_thermal_mitigation
when USB is connected.

and if battery will be over 55c it's will set 300mA max till cooldown.

here some examples switching max mA in STweaks in manual mode:

<3>smb349_set_thermal_chg_current_set: thermal-engine set chg current to 500
<3>LGE charging scenario : state 0 -> 0(0-0), temp=34, volt=4180, BTM=0, charger=1, cur_set=500/500, chg_cur = 199
<3>smb349_set_thermal_chg_current_set: thermal-engine set chg current to 1600
<3>LGE charging scenario : state 0 -> 0(0-0), temp=36, volt=4057, BTM=0, charger=1, cur_set=1600/1600, chg_cur = 117
<3>smb349_set_thermal_chg_current_set: thermal-engine set chg current to 1800
<3>LGE charging scenario : state 0 -> 0(0-0), temp=33, volt=4201, BTM=0, charger=1, cur_set=1800/1600, chg_cur = 244
Revert USB CABLE Hack, it's not working as needed.
FORCE FAST CHARGE: bump to v1.5 Cleanups + FIX, now it's WORKS
BATTERY POWER: fixed bugged function that i added long time ago.

*We do not need to update the thermal_mitigation each battery update.
it's creating not needed work non stop on charge.
*When current_now is below 300ma then set thermal_mitigation to 300
in order to maintain stable connection to device over USB. no disconnects.
*If battery is LOW and ROM we connected strong charger, then each time ROM
Theraml update the smb349_thermal_mitigation check what we want to have based
on fast charge profile. and update it and not what ROM thermal want.
*Check if battery overheatted or 55C and drop thermal_mitigation to 300
to cool it and preserve.
FORCE FAST CHARGE: V1.6 allow kernel control for smb349_thermal_mitigation

*ROM thermal driver controlling the smb349_thermal_mitigation that lock
max charge from charger/usb to what ROM thermal decide.
Well that is not always good for us :)

*If we connect USB from PC, we will get 500ma charge limit as USB
cant give us more any way. prevent force fast charge to set higher.

*If battery is overheatted or at >= 98% limit charge to 300ma to prevent
battery damage.

*ROM thermal is slow in detecting allowed mA limit, so we use kernel
power connector detection function to update smb349_thermal_mitigation
limit current.

again only if no high temp and battery below 98%

*Also allow USER to set limit using force fast charge interface when using
charger! on USB it's will charge max 500 as should.
FORCE FAST CHARGE: v1.7 auto reload force on power plug/unplug.

*Some users report that they must disable and enable the
force fast charge to get high charge power. or they stuck at 300mA

For me all was OK as is. but i am nice dev, so here is auto reload
when Unplugged, force fast charge set to disabled.
and when plugged back to enabled, if was enabled.

From LOG:

PLUG PC USB:
<6>msm-dwc3 msm_dwc3: chg_type = USB_SDP_CHARGER
<6>dwc3 f9200000.dwc3: Avail curr from USB = 500
<6>dwc3 f9200000.dwc3: Power plugged, FFC is set to = 2
<6>smb349_input_current_limit_set: input current limit=1800 setting 09
<6>msm_otg_notify_power_supply: power_supply_get_by_name(usb)
<6>smb349_is_charger_present: DC is present. DC_IN volt:4841060

UNPLUG:
<3>android_work: sent uevent USB_STATE=DISCONNECTED
<6>dwc3 f9200000.dwc3: Avail curr from USB = 0
<6>dwc3 f9200000.dwc3: Power Unplugged, FFC is set to = 0
<3>smb349_is_charger_present: DC is missing.
<6>smb349_input_current_limit_set: input current limit=2000 setting 0a
<6>msm_otg_notify_power_supply: power_supply_get_by_name(usb)
<3>smb349_is_charger_present: DC is missing.
Defconfig testing
BATTERY CHARGER: When PC USB connected. limit to 370mA.

*Usb chaarge never pass 370ma any way. but when driver set to 500
USB connection with PC, reset on higher drain. and reconnect.
Stop it by reducing max mA on USB to 370.

*Split pr info by 2, and add requested mittigation.
Do not update thermal mitigation when SMB349_VZW_FAST_CHG used for VS980
FORCE FAST CHARGE: V1.8 new fixes and options.

*Fixed fast charge to 1200 when using FFC ON, was stuck on 300ma!
*Added Ability to charge on MAX 300ma as requested by my user.
*Corrected 1500ma to 1600ma to make it more standard current.
*Rised USB max mA from 370 to 400mA. as we need more 100 for stable MTP
link from PC to Phone.