msm: Fix high load average from uninterruptible waits

 * The load average on all MSMs is currently hovering at around 14
   due to uninterruptible waits in various places.
 * Convert these waits to interruptible waits to bring the load
   back down to zero at idle.

Change-Id: I14bad4af135b1594e235e2252cb484cb34d91054
msm: thermal: Initialize per cpu variables during thermal init

Initializing the per cpu variables inside frequency/hotplug
probe function has a possibility that it may result in
uninitialized variables. So initialize the per cpu variables
in the thermal drivers init function.

Change-Id: I18e65a4bc2f5bba279d1971701ac0877a5391395
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Update thermal sysfs nodes permission

Update the permissions of the sysfs nodes exposed
by the kernel thermal monitor.

Change-Id: Ib211852e8af74d17fd5e40585af2f03aa3ae7920
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Disable hotplug monitor only if cpu-sensors < NR_CPUS

Some target variants have different core configuration but share
same dtsi bindings, hence it is not possible to configure differently
for these variants. Instead of checking number of cpus and number of
configured cpu-sensors are equal, check for atleast one cpu-sensor for
each cpu, ie cpu-sensors >= NR_CPUS at probe_cc.

Change-Id: Ie11107f780e24cc1e7879495ce0a1c0c5be412ab
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
msm: thermal: Handle zone ID and tsens ID to fetch temperature

Add a function, which can handle zone and tsens ID and get
current temperature.

Change-Id: I685852e8571c0609a32b0ce982ae70d0b59443fd
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm_thermal: Wait for thermal events in a loop

 * It's OK if we are interrupted, just continue.

Change-Id: I49b9855ea1637240b4d4e54489dc216e99eec23c
msm: thermal: Update to speed up bootup time

Update KTM driver to remove flush_scheduled_work that
would introduce bootup delay. This patch replaces
cancel_delayed_work with cancel_delayed_work_sync
to cancel a delayed work.

CRs-Fixed: 647439
Change-Id: Ie81278ca3a7a58f8f46463f7149b512bd07cbcbc
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
msm: thermal: Automate KTM's switch to interrupt mode

Add support to Kernel Thermal Monitor (KTM) to stop polling
the temperatures and switch to interrupt mode when the KTM
module init is called. This avoids KTM's dependency on
thermal-engine to notify when to switch to interrupt mode.

After switching to interrupt mode, the KTM spawns a
thermal monitor thread and registers temperature
thresholds for monitoring the vdd restriction.

CRs-Fixed: 567187
Change-Id: Ib1536c9fc32d3fc0ef2737818c39ca80c5d636d8
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Remove D tasks in kernel thermal monitor

Remove D tasks in kernel thermal monitor by moving
wait completion to its interruptible counterpart.
This will reduce the loadavg by 50 percent.

CRs-Fixed: 654474
Change-Id: I5fc82d83170b46393ac66ca354627341fc4b5296
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
msm: thermal: Update debug/error logs to be more informative

Update/Add debug and error logs to KTM to give more informative
logs for debugging. Updated the log signature for KTM to
print the module name and function name by default.
The new log signature looks like,
msm_thermal: <FUNCTION_NAME>: <LOG_MESSAGE>

Change-Id: Ie2e03cfaf8d4df5ea8ee51334d55a9de9ca4f75e
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Remove alarm support in KTM

Remove the alarm support from kernel thermal monitor(KTM).
Alternatively, the userspace processes uses POSIX timer
API's for alarm in msm-3.10 kernel.

CRs-Fixed: 538952
Change-Id: Ib57ebdef22c2d9f904b98287e5cf483fd3c7531f
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
msm: thermal: Add support for cpu temp limit recommendation for SoC

Add support in KTM to get SoC parts info by reading appropriate
efuse bits and recommend default cpu temperature limit based on
efuse value temperature map to userspace through sysfs interface
'/sys/module/msm_thermal/default_cpu_temp_limit'. Efuse data
to be read such as address, row number, starting bit number
of the row, number of bits for identifying parts etc, default core
temperature and efuse temperature value map are read from dt.
The default cpu temperature information is exported in the format
<temperature in degree celsius>.

Change-Id: Icbf43c3fd56e95d49a886d309e613d2fe146a506
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
msm: thermal: Add thermal reset feature to KTM

Add support for issuing a thermal reset from msm thermal driver.
The thermal driver is capable of monitoring all the tsens
temperatures and issuing a reset right from the boot.
The reset temperature can be given as input using devicetree.
Failure to do so will disable this feature for the target.

Change-Id: Iaf8f1764d4e4e3abb7e65f1d4397d895d195636d
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
ext4: limit the number of error prints

Use printk_ratelimit instead so as to avoid large number of prints
from the EXT4 in case of error.

Change-Id: Id160cda919429d9045f804876bc736ff87419860
Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org>
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
ext4: Add support for FIDTRIM, a best-effort ioctl for deep discard trim

* What
This provides an interface for issuing an FITRIM which uses the
secure discard instead of just a discard.
Only the eMMC command is "secure", and not how the FS uses it:
due to the fact that the FS might reassign a region somewhere else,
the original deleted data will not be affected by the "trim" which only
handles un-used regions.
So we'll just call it "deep discard", and note that this is a
"best effort" cleanup.

* Why
Once in a while, We want to be able to cleanup most of the unused blocks
after erasing a bunch of files.
We don't want to constantly secure-discard via a mount option.

From an eMMC spec perspective, it tells the device to really get rid of
all the data for the specified blocks and not just put them back into the
pool of free ones (unlike the normal TRIM). The eMMC spec says the
secure trim handling must make sure the data (and metadata) is not available
anymore. A simple TRIM doesn't clear the data, it just puts blocks in the
free pool.
JEDEC Standard No. 84-A441
  7.6.9 Secure Erase
  7.6.10 Secure Trim

From an FS perspective, it is acceptable to leave some data behind.
 - directory entries related to deleted files
 - databases entries related to deleted files
 - small-file data stored in inode extents
 - blocks held by the FS waiting to be re-used (mitigated by sync).
 - blocks reassigned by the FS prior to FIDTRIM.

Change-Id: I676a1404a80130d93930c84898360f2e6fb2f81e
Signed-off-by: Geremy Condra <gcondra@google.com>
Signed-off-by: JP Abgrall <jpa@google.com>
ARM: dts: msm: Enable thermal reset feature for MSM8974

Enable thermal reset feature for MSM8974, where the KTM does
a secure watchdog bite when the temperature of tsens reaches
the preset threshold.

Change-Id: I7f3e576ad7b7e7abef6ece0c64c90d09be180967
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>