PM / devfreq: register governors with devfreq framework

With the new registration functions, governors can be now
registered with devfreq framework.

NOTE: generates 'discards qualifiers from pointer target type'
build warnings, which the next patche in this series fixes

Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: 83116e66a232184f733ecf09a41817cf893ede98
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I834003ee27fea4524a232b20c7d724fb0f0fa129
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / OPP: Initialize OPP table from device tree

With a lot of devices booting from device tree nowadays, it requires
that OPP table can be initialized from device tree.  The patch adds
a helper function of_init_opp_table together with a binding doc for
that purpose.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Git-commit: b496dfbc94ab86f970ef0167eaabe51f930aa5fb
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ic6919b0c58774c2e97151f0eaeef325f3f83f93e
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / OPP: RCU reclaim

synchronize_rcu() blocks the caller of opp_enable/disbale
for a complete grace period. This blocking duration prevents
any intensive use of the functions. Replace synchronize_rcu()
by call_rcu() which will call our function for freeing the old
opp element.

The duration of opp_enable() and opp_disable() will be no more
dependant of the grace period.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: dde8437d06560366d8988c92b5774039ec703864
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I0732cbef840ff5f26b0be55697abd99741fce7aa
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / OPP: Export symbols for module usage.

Export the OPP functions for use by driver modules.

Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

[nm@ti.com: expansion of functions exported]
Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Liam Girdwood <lrg@ti.com>
Acked-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: 80126ce7aeb4e187429681ef8a7785b7dcd7a348
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ic55436f62564ff634dbbbfb8ef75a54470d5eff2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / OPP: predictable fail results for opp_find* functions, v2

Currently the opp_find* functions return -ENODEV when:
a) it cant find a device (e.g. request for an OPP search on device
   which was not registered)
b) When it cant find a match for the search strategy used

This makes life a little in-efficient for users such as devfreq
to make reasonable judgement before switching search strategies.

So, standardize the return results as following:
 -EINVAL for bad pointer parameters
 -ENODEV when device cannot be found
 -ERANGE when search fails

This has the following benefit for devfreq implementation:
The search fails when an unregistered device pointer is provided.
This is a trigger to change the search direction and search for
a better fit, however, if we cannot differentiate between a valid
search range failure Vs an unregistered device, second search goes
through the same fail return condition. This can be avoided by
appropriate handling of error return code.

With this change, we also fix devfreq for the improved search
strategy with updated error code.

Signed-off-by: Nishanth Menon <nm@ti.com>
Reviewed-by: Kevin Hilman <khilman@ti.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: 0779726cc265805d0f7c7dd1d791fa4076b31a9a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I95c9d1aaf7ad8dbaff77ab3d57a7b8fe8d599764
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / OPP: using kfree_rcu() to simplify the code

The callback function of call_rcu() just calls a kfree(), so we
can use kfree_rcu() instead of call_rcu() + callback function.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: ea83f81b489be3be268ed7fabfe8dd94bdc45a29
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I90fd70a0c98666269e7fb7b11b7fd5132ede2db1
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: Use devm_* functions in exynos4_bus.c

devm_* functions are device managed functions and make cleanup code
simpler and smaller.
devm_kzalloc and devm_regulator_get functions are used.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
[renamed the patch title by MyungJoo Ham]
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: d7895052d97cde63b34e5185da28052384fa8564
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ifb83c1e6b3b065e6fe51409ca316524ca93aa7f9
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: map devfreq drivers to governor using name

Allow devfreq drivers to register a preferred governor name
and when the devfreq governor loads itself at a later point
required drivers are managed appropriately, at the time of
unload of a devfreq governor, stop managing those drivers
as well.

Since the governor structures do not need to be exposed
anymore, remove the definitions and make them static

NOTE: devfreq_list_lock is now used to protect governor
start and stop - as this allows us to protect governors and
devfreq with the proper dependencies as needed.

As part of this change, change the registration of exynos
bus driver to request for ondemand using the governor name.

Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Signed-off-by: Nishanth Menon <nm@ti.com>
[Merge conflict resolved by MyungJoo Ham]
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: 1b5c1be2c88e8445a20fa1929e26c37e7ca8c926
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ib6a240bba7b284a02e502c489768bb1ea133c65d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: governors: add GPL module license and allow module build

Add GPL module license and remove the static build
restrictions for building governors. This allows governors now
to be loaded on a need basis and reloaded independently of kernel
build

Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: eff607fdb1f787da1fedf46ab6e64adc2afd1c5a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ic56a5ff4f770d372672266a5f0c245b466bb558a
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: allow sysfs governor node to switch governor

This allows us to select governor runtime from the
default configuration without having to rebuild kernel
or the devfreq driver using the sysfs node:
/sys/class/devfreq/.../governor
cat of the governor will return valid governor
and an echo 'governor_name'>governor will switch
governor

Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Signed-off-by: Nishanth Menon <nm@ti.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: 0359d1afe4013d1a216908b6be4c6695a1db6fd6
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I7a62cc211f23a795d419bc1f31651687088e6e50
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: Add sysfs node to expose available governors

Now that governor list can be variable, knowing the available governors
is useful to be able to select a governor using relevant sysfs node.

Cc: Rajagopal Venkat <rajagopal.venkat@linaro.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Kevin Hilman <khilman@ti.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: 50a5b33e0159f8783ef617cdb9d5fbb6a3955b6f
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I2b1ec9b9897d94e2efd8dc2e6dfa00d3c91d9f70
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: exynos4_bus.c: Fixed an alignment of the func call args.

I fixed the following check item (via checkpatch.pl --strict option):
CHECK: Alignment should match open parenthesis

Signed-off-by: Sangho Yi <antiroot@gmail.com>
[Merge conflict resolved]
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: dce9dc3a24f03b054dae02ef5cf1df7e97a8f558
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I362e4909db7a358641c49490331e1e9da1b734fa
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: missing rcu_read_lock() added for find_device_opp()

opp_get_notifier() uses find_device_opp(), which requires to
held rcu_read_lock. In order to keep the notifier-header
valid, we have added rcu_read_lock().

Reported-by: Kees Cook <keescook@chromium.org>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: 389baed01edd298c9622c6e28de5e7e250c8767d
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I26a225ffa03003faa3f24822759548f6679ee591
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: Fix incorrect argument in error message

'g' is cast to the error return code. Hence gives the following error
which is fixed by this patch.

drivers/devfreq/devfreq.c:645 devfreq_remove_governor() error:
'g' dereferencing possible ERR_PTR()

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: b9e1c8e821e7768d5b8629ad7748456af6feece3
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I134a794ed4fa48bfb76e4ebbc1408038eb72cd08
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: Fix return value in devfreq_remove_governor()

Use the value obtained from the function instead of -EINVAL.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Git-commit: f9c08e2acbbed19ecafc82e4549b7040cc549216
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ib82c998e0872fcc18b9cbc64bf98a97b374378b0
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: remove compiler error with module governors (2)

Governors compiled as modules may use these functions.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit:  6dcdd8e3cadd8dfcfe63d231631d70e2670970f9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: Ia16309c731948f96ffb0e4b4bd6b5b3468c89587
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: add locking documentation for recommended_opp

OPP pointers are protected by RCU locks, the pointer validity is
permissible only under the section of rcu_read_lock to rcu_read_unlock

Add documentation to the effect.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: bcb27549f4185ca7d0168e201931613706ef2b83
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I2c0336d9941f2e1ddb42d97342c95cd61c96af44
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
PM / devfreq: exynos4_bus: honor RCU lock usage

OPP pointers cannot be expected to be valid beyond the boundary
of rcu_read_lock and rcu_read_unlock. Unfortunately, the current
exynos4 busfreq driver does not honor the usage constraint and stores
the OPP pointer in struct busfreq_data. This could potentially
become invalid later such as: across devfreq opp change decisions,
resulting in unpredictable behavior.

To fix this, we introduce a busfreq specific busfreq_opp_info
structure which is used to handle OPP information. OPP information
is de-referenced to voltage and frequency pairs as needed into
busfreq_opp_info structure and used as needed.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Git-commit: 8fa938acb318378463987b04be083dc2467e0480
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Change-Id: I24c020e729470eadde3c0a0460226dee7f1d537a
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>