msm: mpdecision: Add mpdecision driver code.

This driver is mainly responsible to convey the runqueue average and
iowait average values to the TZ periodically. The TZ returns the mask
of the cpu's that should be online and the slack timer.

The mpdecision code brings cpus up or down to match the online mask
from TZ. Also starts the slack timer as specified by TZ.

Upon expiry of the slack timer mpdecision calls TZ to get a new
mask and a new slack timer.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit a599de41a47b0b1a9f81a77227e16aff5a16a072)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit d2cf2db9632c3c2a33bc66ff61b2c2b758c10c86)

Change-Id: I30020fade79b61f86cbec52c90a1f5861a673a4c
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/Makefile
msm: dcvs: update the event enum in preparation for mpdecision.

The event numbers used to communicate with TZ have changed. Update
them here in preparation of mpdecision.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 0db555f69e8e5b5237f2c053fffeeec3926084a1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit deda7f0ef23aea568975ec73d4f54022f468adef)

Change-Id: I8a0bd62d06135714ce954c4cf6083523f5c1ca84
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: rearrange platform data.

This change
-removes the use of group id and instead introduces core type
-rearranges platform data, adds energy curve coefficients and power
 parameters
-allow for the energy params to be -ve numbers

The change also mandates updates to the msm8974-gpu.dtsi and the
associated binding documentation.

Also take this opportunity to remove devices for unsupported platform
- 8930 and 8960

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 4445166ad16be0c45b077bfb10487de355ed2e05)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 24d2351f6a5e7069e5d554dbc999280a69288c5d)

Change-Id: I5c65c0e65cc7652eee72c525f0db10e128061cf9
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: Add thermal interfaces.

The algorithm needs thermal inputs for all the cores. Create members in
the internal core_info strucutre and platform data/device tree to pass
in the sensors they use.

Update the dcvs code to notify the temperature to TZ.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fc7dca4c325725492af997fa282e07b9d03154d1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit eb478c5b7b55ea8a57e0336e4cf9979be935b289)

Change-Id: I505903eb8b9779f2065aebfab5b3f2aefc874200
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
cpufreq: msm: remove gov_mutex from stop.

The stop could end up calling set_frequency callback. The set_frequency
callback takes the same gov_mutex lock and we end up in a deadlock.

Fix this by removing the locks around stop.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 5106c477a747279dbf045eed5a6ab4f68ac3501c)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit e0fa1831db0c57a8be8d5471ee3382b0f8a9165e)

Change-Id: I306f9cd2c05ce1e9c4c36d22d16b775a42881f0d
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
cpufreq: msm: fix race in cpufreq.

__cpufreq_driver_target expects to be called with the rw semaphore
held. We are not doing this when the frequency is asked to be changed
by dcvs.

Use cpufreq_driver_target variant of that function which gets the
rw semaphore before setting the frequency.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 54fc08ea6d33c6c561167f369cba060fe33755c9)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit a63446bcd75909db632ffc8ff3c4e6a96c8593c5)

Change-Id: I33cdac0aaac7fb44acf6f9eb451a80ff94175c46
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: hide -13 errors when communicating with the secure side.

-13 errors from the secure side are benign, dont print an error when
that happens.

Signed-off-by: Jeff Ohlstein <johlstei@codeaurora.org>
(cherry picked from commit 3cb914d56d65b9ad1dea8d186f74d3a1bc760769)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit dee3d749bbf60315080a2fb455bf8b2bd0640f36)

Change-Id: Id22bad3f3ee88e4292b3155014e43aa043a5df12
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: prevent thread creations upon cpu hotplug insertions.

Numerous threads were seen created and left idle as cpu's were
hotplugged in and out. Avoid creating new threads unnecessarily.

Instead create just one thread when a core is registered and use
it later.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit e039aac0c0be7c0d914055224103e8f41821320d)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit dbbe1e71a6f1be2dee99104281ad47e6884891bc)

Change-Id: Ib1255f9df5b41fbb49d25fdd6d661ebfa7f7642b
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: get rid of the pending freq array.

Only one pending frequency should be set, there is no need to
maintain an array of intermediate requests.

Cleanup the code and remove new_freq[] array and the index to
it. Introduce pending_freq a single entity that carries the
latest frequency request. Use the core's cpu_lock to protect
it.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit bea1b7628356bd953a88596c556373a6ec355f94)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 32f01b8af255b565d5bcf1496a1aaea77250e205)

Change-Id: Ie939700f7f62e453638e73f489e729105e363d29
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: use wait_q.

It is cleaner to use wait_q mechanism instead of waking up the thread
and managing the scheduling flag ourselves.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 33bf417160e9340f2dd5f9f275e7e6021987bfe1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit de943e4aff2a26e0d21b208d85b5876c31bfda85)

Change-Id: I4316ee58633f7353197654074263466cdaa25778
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: update dcvs if the governor limits change.

We had seen issues where dcvs goes out of sync with the actual
freq the cpu is running at. The root cause was if the userspace
changes the limits on the governor, the governor ends up changing
the frequency without notifying dcvs.

Provide an api for the governor to call dcvs when a frequency change
happens.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 68c970e38fcb700d851301dbacc56da9387294c6)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit a7d720e513cfae2d3f9c03c25f2ce2f10c2e9de7)

Change-Id: I3f321df0270e997531d1a4cf3ee2251f86aef0bc
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: provide frequency set/get callbacks at registration.

There is no need to register a separate structure for setting and
getting frequency.

Simply pass function pointers to set and get callbacks when a
core is registered.

While at it rename the msm_dcvs_freq_sink_register/unregister to
msm_dcvs_freq_sink_start/stop to better reflect that those
apis are meant to do.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 69134111c2a24002d1995a05c99f84403ac6a7e8)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 52cb57c3c6bc1c0d08c1ae9eb5dd0ff1e1125a96)

Change-Id: Iee7aee1cbb2f33ed2852f1816ab62416b96fa7e6
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: remove idle notification registration.

Register the idle enable callback along with the core. The code
becomes cleaner and easy to update.

Importantly, the msm_dcvs_idle driver becomes useless. Remove it
and instead let the msm governor handle idle enabling and disabling.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit c1ed66c9035b4fbf240e46837d86a9a6442531f1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit b4f5c2274fa2180b53563f2db0922eef212c0fcd)

Change-Id: Ice039e608d45bdeb9b8b718e5fbbf82a698d584d
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/Makefile
msm: 8064: add board file structures for mpdecision and msm governor.

Add device structures in the board file for mpdecision and the msm
governor. This essentially probes mpdecision driver and the msm
governor driver. When enabled mpdecision communicates the run queue
average with TZ and obtains back a mask of which cpus should be
online. The msm governor communicates the frequencies of the cpus
with TZ and obtains newer frequency for that cpu.

Both combined they govern which cpus stay online and how fast they
run.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fb4a2f8e62af9cfa0852b16b2370f0d3df324e59)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 2015b46a54dbcae9439cec27dddee1916d3071f3)

Conflicts:

	arch/arm/mach-msm/board-8064.c

Change-Id: Ic720e88e110b320ef3ce1ae35901411202066951
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8064.c
	arch/arm/mach-msm/devices-8064.c
gproj: add board file structures for mpdecision and msm governor
msm: dcvs: split get_core in add/get_core.

There is currently only one function to add and get a core. Clean this
up by splitting that in two functions one for adding core and the other
for getting one.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fbd7ea63accf3624f2c80d4a638495817b634d3a)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit a7a1905ceeb345d31b4dedba2054b509eb4ba5f0)

Change-Id: Ieefc853f1b3e1c4dd84e253ccc0d54cf4d1fdb24
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: remove core name.

Currently core_name is used to identify which core the dcvs operates on.
Instead use a type and the type num while registration with dcvs and
return an id (dcvs_core_id) upon successfull registration.

The dcvs_core_id is used by the clients of msm_dcvs to call upon its
apis viz. freq_start, freq_stop, msm_dcvs_idle etc.

The dcvs inturn uses the type num passed in at registration time to
invoke apis on the clients viz. set_freq, get_freq, idle_enable.

This further cleans up the internal dcvs add_core and get_core
implementation. One need not pass around the core_name and use the type
instead.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 1bbc0321a6871e018c17da6f244b9df442faead6)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 09456d7d7618e6d0fc6b907b7af75268ea08a942)

Change-Id: Id27751a8ec8f5d3d386bbe7c7625ed56757b8bd7
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: cleanup debug prints.

The debug print mechanism is not much useful. Remove that code.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 0e1679b1ed8419f44c8976853f0070517f84cb14)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit fc7e8af6d5dee3744390220113483fec2e452081)

Change-Id: I5b574aa4bf2784f8cdfe065bb17ab8246d0d9e73
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: functions to start/stop/restart hrtimer.

The slack timer is supposed to be activated only when the core
is out of idle and that the governor for that core has started.
If any of the conditions is not met one should not activate
the slack timer.

To implement such a scheme, create two variables idle_entered,
and pending freq protected by their respective spinlocks
idle_state change_lock and pending_freq_lock. Whenever the
idle is entered or exited stop/start_slack_timer is called
which grabs the appropriate spinlocks and udpates the idle_entered
variable and starts and stops the hrtimer.

Moreover there are situations when a activated timer needs to
be restarted. This happens when a frequency is updated and a new
slack timer is received. We provide restart_slack_timer() callback
which cancels the hrtimer and restarts it only if the conditions
mentioned above are met.

There is also a situation when one has to forcefully cancel the timer
when the governor stops. Provide an api for that too. Note that one
cannot use stop_slack_timer becuase stop_slack_timer manipulates
idle_entered flag.

Also on related note, cleanup the code that handles pending_freq.
We get a new freq to set for a core when
- the slack timer expires
- when the governor starts when the cpu is brought back online
- when the cpu comes out of idle

Use pending_freq_lock to serialize updates to pending_freq.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit d6911b9e6d9cf51a8a7acc7363b424e325658e1f)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit ac4d9b3c58b998ecf6b83f5ae920eb47e5aef006)

Change-Id: I4db5b4de0c02bef62749c9e727a59171ae3f4ac0
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: dcvs: change tz buffer to 32KB.

Only around 32K of buffer is required for normal operation.
Request the scm buffer of 32kb from the contiguous area.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit dca26f7215b4bc0ae4e4c17948f96c63d7af5266)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 69e6a4d39b234cf02642337ecc6df5ef67b9b2c8)

Change-Id: Ie1c9997fdf79796458aacaa5d3169e24666fcac4
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>