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.

Change-Id: I23bb057ffec2630b9fe826da9cbd4edff08d3889
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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

Change-Id: Ie8d5a691defb825955b240c1b304e04f0a21499a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
mako: msm: dcvs: rearrange platform data
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.

Change-Id: I96e123eb49cdd564564e5fe12531407406eafa0c
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
mako: msm: dcvs: Add thermal interfaces
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.

Change-Id: Ic687d92825f253aa3e23e4bcaf3c96d5879d4b43
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: I67a7d437f68749f43c26b95ae73f436890326019
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: I40a9cee43e486e7983381022a16d240b7fd2f4c1
Signed-off-by: Jeff Ohlstein <johlstei@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.

Change-Id: I298c7438fe4850e028bd920808ac180918641c10
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: If2bc47822d70f97f502df857f01b81134ce669ea
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: Ie0d7ec8e74400fb31c7d0a33c0d4520fca658c29
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: Ifb33fac9cdde8535e274b7c91534dc44cc19dbe7
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: I0e5bb1fe8d127e5841ee9916dad5c3fd64815228
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
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.

Change-Id: I0cb71b200450290dea17f9fd9197a2749bb9a752
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8064.c
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.

Change-Id: Ia056b8b1fcca8ebd356fa0484148c3ade54026fc
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
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.

Change-Id: Ia9d0b9aa70328fe355ea020f68100c38f2129c2d
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
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.

Change-Id: I911d2a4b0e5373b9702606d52e6392490a85b435
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: I1736f4befec02249eae969694c7b7696dc9cdb9d
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
msm: dcvs: cleanup debug prints

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

Change-Id: I35efbac9cc04f400cbee6a693c4d747d0545091b
Signed-off-by: Abhijeet Dharmapurikar <adharmap@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.

Change-Id: Iedbd8a3fce0cf52aca1b5d6ad3cc8d779df6ebc5
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>