Fix incorrect detection of many headsets(stock rom affected too)
Add option to reboot into LAF mode
arm: add own hotplug driver

Simple SMP hotplug driver, based on @franciscofranco implementation.

For now without the suspend/resume logic, since this needs
to be redone.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: delete deprecated earlysuspend handler

There is no proper support of earlysuspend in this kernel,
so better delete this stuff until there is a better option
available.
Also adjusting a few tunables.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: add tunable sysfs entries

Allowing to change the current sampling_rate as well
as the first threshold (single core) and second threshold
(all cores).
Actual path will be: /sys/kernel/hotplug_control

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: remove single_core_load and all_core_load

Those sysfs caused instability, which is something i don't want.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: delay initial workqueue start

By delaying it a bit, we workaround some kind of
race condition. Enabling effectively four cores
during boot might be a good idea anyway.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: fix core 4 would eventually not go down

We only check if our current cpu is online, not thinking about
which position it might be currently. This would result in a very
long uptime for the fourth cpu even when there is zero load.

The solution is actually pretty simple; we just check every case
and offline accordingly to that. Also reducing the overhead of the
driver a bit and cleaning up unneeded stuff.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: add back suspend/resume logic

Using @faux123 powersuspend driver here to get the same
functionality like with androids earlysuspend handlers.

This will effectively turn all cpus (except 0) off during
screen off and turn on the second cpu when screen is on
again.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: add sysfs for first threshold

And doing some random cleanups.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: add simple debug option

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: fix cpus won't offline when zero load

If the workload drops immediatly down to zero and the
counters were basically resetted to 0, each onlined
cpu won't go offline until the next workload.

Fix this with a simple greater-equals.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: optimize put_cpu_down() and sampling rates

The code might seem to be more complex, but it should be
more efficient then the previous one. Each case gets handled
very surely.

Also changing the behaviour of the sampling rates. The tunable
is now a multiplier of HZ to ensure consitency. This fixes
also a bug where the sampling rate could go wild in some cases.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: use power efficient workqueue for suspend

Since the last commits, this seems to be the right way to enter
into earlysuspend/lateresume.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: reduce overhead for avg load

Before this patch when we did our load calculations, we could
end up in some sort of faked data. We would calculate the load
for all cpus 2^2^2 times (in the best case with only two cpus
online). When all cpus are online we would end up in some sort
of strange data.

Also introduce a new tunable min_online_time which sets
the minimum amount of time for a cpu to stay online.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: fix compile derp

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: add a tunable for all_cpus_threshold

Previously adding a tunable for this parameter would end up in
some sort of deadlock as soon as the device enters deepsleep.
This is now avoided by allocating the right amount of memory
for the hotplug data.
Since the hotplug driver is enabled by default and shouldn't be
replaced by userspace we don't need to bother about freeing up the
memory.

This commit also contains a big cleanup for various things.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: fix missing bits

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: reduce the amount of calculations

In a standard scenario we increase (or decrease) the load-counter
for each cpu two times in one sample rate. Clearly thats not the
point, because for ony sampling rate there should be only one
decision made for a cpu (increase or decrease).

Also fixing a bug with the average load;

       load  load-history
  cpu0:  100         100
  cpu1:   50           0
  cpu2:  100         100
  cpu3: (off)        100
  ------------------------
  avg(real)    :    83,3
  avg(previous):    87,5

When the load drops in cpu0/1 another core would get offlined,
but we won't clear the history for this core. By fixing this we
should end up with a small battery life increase for light usage.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
hotplug: take care of short load spikes

 * In case we have some sort of load spikes we could
   save some calculation time and boost cpus directly
   online. In this case this will save a full three
   sampling rates. It will only kick in if the current
   load is 100% a during two samplings.

 * Also adding a wrapper function for cpu_up() which
   takes care of the basic stuff

Signed-off-by: Blechd0se <alex.christ@hotmail.de>