powersuspend: new PM kernel driver for Android w/o early_suspend

Android early_suspend/late_resume PM kernel driver framework has been
deprecated by Google. This new powersuspend PM kernel driver is a replacement
for it and existing early_suspend drivers can be easily adapted to use this
new replacement driver

powersuspend: fix logci derps :p

Change-Id: I5a13c538e953fe0ca6d9b3918747d18a017cc077
Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: Josue Rivera <prbassplayer@gmail.com>
kernel/power/powersuspend: remove userspace dependency from powersuspend

make powersuspend not depend on a userspace initiator anymore, but use a hook
in autosleep instead.

Change-Id: I65e12627b0bdd0759d3c2464ba3cce079c639a2a
Signed-off-by: Paul Reioux <reioux@gmail.com>
kernel/power/powersuspend: add back userpace control w/ default kernel control

make kernel / userspace mode switchable

Change-Id: I53c2441663350206dfe794ca7ecb16ceb74c6f8d
Signed-off-by: Paul Reioux <reioux@gmail.com>
kernel/power/powersuspend: default to userspace for now

Change-Id: I07cde11f6ab107bdaf0651b570ca8ced59b2165a
Signed-off-by: Paul Reioux <reioux@gmail.com>
kernel/power/powersuspend: LCD screen on/off hooks (Yank555.lu)

- add an alternative hook for screen on / off detection in the display
  pannel driver
- sleeps  ~0.1s sooner, wakes up ~1s later then autosleep
- clean up source formatting a bit (Paul Reioux)

Change-Id: Id1886ddcf802eed90ffebb2668f781fcfb7f0f04
Signed-off-by: Paul Reioux <reioux@gmail.com>
Honami/Togari: Enable power suspend

Change-Id: I8e706ba5de0f86ce79d7e333c09e1bc041262ab7
Signed-off-by: Josue Rivera <prbassplayer@gmail.com>
cpufreq/cpufreq_intellidemand: intellidemand cpufreq
 governor (version 4.0)

Intellidemand is inspired by ondemand governor. Its main features are:

 - auto cpu hotplugging based on runnable thread average calculations
 - detection of browsing mode (long screen on activities with moderate run
   queue depth =< 45 )
 - limit max frequencies when in browsing mode to conserve battery for long
   duration tasks

Browsing State Determination:
 1- Browsing state is enabled as power-on default. Browsing state is disabled
    when run queue depth is > 45 (very high instantaneous spikes)

Browsing State Limit Max Freq Logic (sliding window algorithm):
 1- While Screen is ON > 3 min, and average load of the CPU is < 35%, then
    CPU Max frequencies will remain power-on default
 2- While Screen is On, if average CPU load > 35%, both CPUs max frequencies
    will be limited to a lower user configurable max value
 3- While Screen is On, After both CPUs' Max is limited to lowered max, when
    the average CPU load has dropped down to less than < 25%, then both CPUs
    Max freq will be restored to back to power-on default

Runnable Thread Auto-hotplug (fast hotplug / slow unplug algorithm):
 1- When average number of running thread is < threshold, 2nd cpu will be
    unplugged.
 2- When > threshold, 2nd cpu will be hotplugged.
 3- The logic applies a fast hotplug and slow unplug algorithm so 2nd core
    will stay enabled longer to help deal with performance spikes

changes from Ver 2.0 -> Ver 3.0:
  - remove GPU Busy dependency for browsing state detection (this will make
    the governor more portable to other platforms without specific GPU
    architecture knowledge)

dependencies:
  -- Qualcomm's run queue average logic (SOC independent logic)
  -- TI's runnable thread average logic (SOC independent logic)

forward ported to Linux 3.4 for use on S-800

Change-Id: I354af35bfa2856f77480339b2bd4cec86070419b
Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: Josue Rivera <prbassplayer@gmail.com>
intellidemand: Add boost pulse capability

Boost pulse increases UI performance by increasing CPU freq and
reduce sampling time.

forward ported for Linux 3.4 for use on Mako
Signed-off-by: faux123 <reioux@gmail.com>

Change-Id: Ic3197ba36267050ac60fa93a1c1dbb8a22602f47
intellidemand: add bug fixes

 - Fix crash input event handler on governor switch
 - Fix panic when setting sampling rate

Change-Id: Ie926be4537e65d25d93e4e287de638df96a52948
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: add a run queue persistence to determine browsing state

persistence will allow for better browsing state detection rather than just
purely based on run queue depth alone

Change-Id: I4356b44f1414470f5e1fae751f6732636c22a5f1
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: add minimum cpu performance lock

a minimum cpu frequency performance lock is add to ensure smooth
operations when only 1 core is active

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

Conflicts:
	drivers/cpufreq/Kconfig

Conflicts:

	drivers/cpufreq/Kconfig

Change-Id: I5f778c2357da07d632bed68a8250e49d2b836ab3
Intellidemand: update for quadcore operations. bump version to 4.0

Change-Id: I7644898c6b83adbdb460cced089aa47ed866212e
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: code derps clean up!

Change-Id: Ifd50b0d6612892c7b304f52e522d50f8c3e2270c
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: increase boost duration to 2.5 seconds from 1.5

Change-Id: I78322df672f2ab303ec7840bfcd49b09a2070c78
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: add eco mode (dual core operations) bump version to 4.1

Change-Id: Ib1f538a289d0d5ce4115f3f350d531809760f99c
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: tweak for not using min performance lock

Change-Id: Ica6af01e1df3e24c6d0d8c3ee0d11ce5a60630b4
Signed-off-by: faux123 <reioux@gmail.com>
Intellidemand: adjust the nr_run hysteresis for better UI response

Change-Id: I3fb7af7f239652c4c571d1caaf5568d14ba1690f
Signed-off-by: faux123 <reioux@gmail.com>
cpufreq: Avoid using smp_processor_id() in preemptible context

Even though this work item runs on only one cpu at a time (due to
queue_work_on()) it is possible for the work item to be preempted
and so use of smp_processor_id() is illegal.

BUG: using smp_processor_id() in preemptible [00000000]
code: kworker/3:1/4162 caller is dbs_refresh_callback+0xc/0x188
[<c00151b0>] (unwind_backtrace+0x0/0x120) from [<c0279058>]
(debug_smp_processor_id+0xbc/0xf0)
[<c0279058>] (debug_smp_processor_id+0xbc/0xf0) from [<c0454b54>]
(dbs_refresh_callback+0xc/0x188)
[<c0454b54>] (dbs_refresh_callback+0xc/0x188) from [<c0087290>]
(process_one_work+0x354/0x648)
[<c0087290>] (process_one_work+0x354/0x648) from [<c0089754>]
(worker_thread+0x1a8/0x2a8)
[<c0089754>] (worker_thread+0x1a8/0x2a8) from [<c008e480>]
(kthread+0x90/0xa0)
[<c008e480>] (kthread+0x90/0xa0) from [<c000f438>]
(kernel_thread_exit+0x0/0x8)

The intent of the code is to determine which CPU this work item
is running on, which we can easily do by passing that information
in a wrapper struct around the work struct. Do this so we avoid
this problem.

Change-Id: I05ca0ff2b3cbaa239930463ea0760e3e9d75145f
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
adapted for Intellidemand from CAF reference
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: Add support to consider other cpu load when scaling frequencies

Currently only current cpu load is considered when frequency scaling.
As a side effect of this when scheduler migrates a thread to a slower
core, the execution time increases unexpectedly.

The new algorithm not only considers current cpu load for frequency
scaling, but also takes into account load of other online cpus. The
treshold for this can be controlled using up_threshold_any_cpu_load.
When the up_threshold_any_cpu_load is crossed in any cpu then the
current cpu is set to sync_freq.

Also, when more than one cpu is online a two step ramp-up mechanism
is used. When the up_threshold_multi_core is crossed the cpu is ramped
up to optimal_freq which is less than policy->max and set to a power
friendly value.

Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>

intellidemand: Fix kernel warning in cpufreq_governor_dbs

GOV_STOP event destroys the timer_mutex and is not initialized back
upon GOV_START event.
The Kernel complains at mutex_lock(during GOV_LIMITS event) after
mutex_destroy.

[<c0014918>] (unwind_backtrace+0x0/0x11c)
[<c007c004>] (warn_slowpath_common+0x4c/0x64)
[<c007c034>] (warn_slowpath_null+0x18/0x1c)
[<c079eef8>] (__mutex_lock_slowpath+0x130/0x3c4)
[<c079f1ac>] (mutex_lock+0x20/0x3c) from [<c0540900>]
[<c0540900>] (cpufreq_governor_dbs+0x3c8/0x468)
[<c053d500>] (__cpufreq_governor+0x90/0xe0)
[<c053d774>] (__cpufreq_set_policy+0x224/0x258)
[<c053da58>] (cpufreq_add_dev_interface+0x2b0/0x308)
[<c053e784>] (cpufreq_add_dev+0x500/0x56c)
[<c079247c>] (cpufreq_cpu_callback+0x88/0x9c)
[<c07a2ca8>] (notifier_call_chain+0x38/0x68)
[<c007ded0>] (__cpu_notify+0x28/0x40)
[<c0790024>] (_cpu_up+0xe4/0x118)
[<c0790024>] (cpu_up+0x64/0x80)
[<c0765840>] (store_online+0x48/0x78)
[<c038d0c8>] (dev_attr_store+0x18/0x24)
[<c017be40>] (sysfs_write_file+0x108/0x13c)
[<c012cdfc>] (vfs_write+0xb0/0x128)
[<c012d034>](sys_write+0x38/0x64)

Change-Id: Ie2a796b17209243de731ccf2ab04b7f9e7048df8
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
Adapted for Intellidemand from CAF reference
Signed-off-by: faux123 <reioux@gmail.com>
intellidemand: give intellidemand's cpu_dbs_info its own name

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