OMAP4: EMIF: code cleanup and clarification

Removed unused fields of emif_regs structure and
functions that initialize or change them.

Also changed few names of emif_regs members
to match register names.

This made the code easier to understand and read
as well as made it a little bit faster

Change-Id: I0485a01b7f03e922b5a2e69bfb03c2ed941fcf3b
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
ARM: OMAP2+: clockdomain/hwmod: add workaround for EMU clockdomain idle problems

The idle status of the IP blocks and clocks inside the EMU clockdomain
isn't taken into account by the PRCM hardware when deciding whether
the clockdomain is idle.  Add a workaround flag in the clockdomain
code, CLKDM_MISSING_IDLE_REPORTING, to deal with this problem, and add
the code necessary to support it.

If CLKDM_MISSING_IDLE_REPORTING is set on a clockdomain, the
clockdomain will be forced active whenever an IP block inside that
clockdomain is in use, even if the clockdomain supports
hardware-supervised idle.  When the kernel indicates that the last
active IP block inside the clockdomain is no longer used, the
clockdomain will be forced idle, or, if that mode is not supported in
the hardware, it will be placed into hardware-supervised idle.

This patch is an equal collaboration with Jon Hunter
<jon-hunter@ti.com>.  Ming Lei <ming.lei@canonical.com>, Will Deacon
<will.deacon@arm.com>, Madhav Vij <mvij@ti.com>, Kevin Hilman
<khilman@ti.com>, Benoît Cousson <b-cousson@ti.com>, and Santosh
Shilimkar <santosh.shilimkar@ti.com> all made essential contributions
to the understanding of EMU clockdomain power management on OMAP.

[steven@steven676.net: squash in cf956d9 ("ARM: OMAP3: fix workaround
for EMU clockdomain")]

Signed-off-by: Paul Walmsley <paul@pwsan.com>
Cc: Jon Hunter <jon-hunter@ti.com>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Madhav Vij <mvij@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
Cc: Benoît Cousson <b-cousson@ti.com>
Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Tested-by: Jon Hunter <jon-hunter@ti.com>
[steven@steven676.net: backport to p-android-omap3-3.0]
OMAP4: DPLL cascading: remove unused CM_SHADOW_FREQ_CONFIG2

The value from CM_SHADOW_FREQ_CONFIG2 can't be applied because
GPMC is always active and can't be entered in idle state.

The GPMC is always active because on OMAP4, CPU accesses on
unmapped addresses are redirected to GPMC by L3 interconnect.
CPU is speculative nature and such accesses are possible which
can lead to indirect access to GPMC and if it's clock is
not running, it can result in hang/abort on the platform.
See path d60565948468b for more information.

Change-Id: Ia62d8bf8c59ac3a06445b6f5f9e08ad0c9369c5b
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
OMAP PM: Optimize cpufreq transition latency

Currently cpufreq transition latency value does not really reflect the actual
OMAP OPP transition delay. This patch has the actual latency value.
I did profile the DVFS latency on OMAP3430, OMAP3630 and OMAP4 for worstcase(MPU and Core together) and found that in none of these platforms, transiton value
goes beyong 10ms. Added a buffer of 20ms to avoid too frequent ondemand timer
expiry.
With this change, performance of ondemand governor is improved when tested
using cpufreqbench tool. Without this patch, cpufreq-bench reported ondemand
performance as 40% of performance governor, and with this patch it's around 70%
(using below procedure).

cpufreq-bench:
http://lwn.net/Articles/339862/
http://ftp.riken.go.jp/archives/Linux/suse/people/ckornacker/cpufreq-bench/

Command used for performance testing:
cpufreq-bench -l 50000 -s 100000 -x 50000 -y 100000 -g ondemand -r 5 -n 5 -v

Signed-off-by: Vishwanath BS <vishwanath.bs@ti.com>
Dug-out-from-archives-by: Keyodi <zeusomighty@hotmail.com>
Found-in: http://lists.linaro.org/pipermail/linaro-dev/2010-November/001636.html
[steven@steven676.net: make apply to p-android-omap3-3.0]

Conflicts:

	arch/arm/mach-omap2/omap2plus-cpufreq.c
Support asynchronous compaction in lowmemorykiller. (adapted from Steve Kondik's commit from N7 kernel)
Revert "Update zcache to 3.3 version."

This reverts commit 5fd6d2527ffa9c949075e47906181e206e8965fa.
Revert "Update android binder to 3.3 version."

This reverts commit ffca018f3cc105ed08a4f9840bb8c294e464c519.
Revert "Update zram to 3.3 version."

This reverts commit 9099751867d28fc5d942a2735ce58d9f3fd3f49a.
Added IO Tweaks. [Dennis <dsb9938@BuildBox.(none)>]
pull in 3 new CPU governors from franciscofranco kernel

Change-Id: I453551050e8392d95300e84f120d83487231e048

Conflicts:

	arch/arm/configs/otter_android_defconfig
Revert "Added IO Tweaks. [Dennis <dsb9938@BuildBox.(none)>]"

This reverts commit 63cff45e9ba0299759e8899e01ae10d46025fdf4.
Revert "pull in 3 new CPU governors from franciscofranco kernel"

This reverts commit 8ebe9fec644911ef60693edef0db885294b6e1ce.
Added CPUfreq governor 'lazy'.
(cherry picked from https://github.com/franciscofranco/Tuna_JB_pre1/commit/0c40cd419b9e9805d1764ee0e5be9135ce98a2bf)
Added CPUfreq governor 'wheatley'.
(cherry picked from https://github.com/franciscofranco/Tuna_JB_pre1/commit/4d1ab4a58fb4398546000bf8b207e1ea96b5be3f)
cpufreq: separate Interactive governor into two, one with static settings and another one with dynamic settings (it adjusts itself according to load). The new governor is called Dynamic Interactive.
(cherry picked from https://github.com/franciscofranco/Tuna_JB_pre1/commit/169de9e5f8786c4e959472ec25c3410e3fc0daa5)

Conflicts:

	drivers/cpufreq/cpufreq_interactive.c
Merge interactive governor code from franciscofranco kernel

commit f08871ec5c861fef4cd588e2479543e8a8c928a5
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Fri Nov 9 02:36:38 2012 +0000

    cpufreq: interactive: kick timer on idle exit past expiry - original patch: https://github.com/android/kernel_common/commit/9b29a6d49becf8caf0550373d84a1068c716e891

commit bbd4a79815aa35aa744bb02a73953a48b14cc093
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Fri Nov 9 02:33:20 2012 +0000

    cpufreq: interactive: use deferrable timer by default - original patch: https://github.com/android/kernel_common/commit/0697ab54cab34e099711ceb4b07b2dfc6b507f0d

commit 42063ff31d39b4a50523e427709c98c293619c6d
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Fri Nov 9 02:29:23 2012 +0000

    cpufreq: interactive: pin timers to associated CPU - original patch: https://github.com/android/kernel_common/commit/430d3d4539a0d441679ca32cc7c3876f97a07da6

commit ca6e7e7379837c26d1ddd3752e96ab56b3b5615c
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Mon Nov 5 15:57:51 2012 +0000

    cpufreq: interactive: decrease inpu_bost_freq to 537MHz.

    Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

commit bc4722e7ff1f757d629753920d2dff12592080f4
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Mon Oct 15 17:05:22 2012 +0100

    cpufreq: interactive: fix input_boost_freq type from u64 to unsigned int. Also get rid of boost option, its not needed and its mostly not used. Boostpulse calls cpufreq_interactive_boost when its activated (Tuna PowerHAL takes care of that).

    Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

commit b1e9a92f807f696e93a7bb94b2d22e36a4eaf97a
Author: Todd Poynor <toddpoynor@google.com>
Date:   Wed Oct 3 00:39:56 2012 -0700

    cpufreq: interactive: run at fraction of hispeed_freq when load is low

    When load is below go_hispeed_load, apply the percentage of CPU load to
    a max frequency of hispeed_freq instead of the max speed.  This avoids
    jumping too quickly to hispeed_freq when it is a relatively low
    percentage of max speed.  This also allows go_hispeed_load to be set to
    a high percentage relative to hispeed_freq (as a percentage of max speed,
    again useful when hispeed_freq is a low fraction of max speed), to cap
    larger loads at hispeed_freq.  For example, a load of 60% will typically
    move to 60% of hispeed_freq, not 60% of max speed.  This causes the
    governor to apply two different speed caps, depending on whether load is
    below or above go_hispeed_load.

    Also fix the type of hispeed_freq, which was u64, to match other
    speed data types (and avoid overhead and allow division).

    Change-Id: Ie2d0668be161c074aaad77db2037505431457b3a
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 355f3ba6b8fca9aa4b763a6b9f88b883df8fa7d8
Author: Todd Poynor <toddpoynor@google.com>
Date:   Mon Sep 24 18:03:58 2012 -0700

    cpufreq: interactive: always limit initial speed bump to hispeed

    First bump speed up to hispeed_freq whenever the current speed is below
    hispeed_freq, instead of only when the current speed is the minimum speed.
    The previous code made it too difficult to use hispeed_freq as a common
    intermediate speed on systems that frequently run at speeds between
    minimum and hispeed_freq.

    Change-Id: I04ec30bafabf5741e267ff289209b8c2d846824b
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 84fc996263697be1c0e351514893ccdef272dc74
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Tue Sep 25 19:17:19 2012 +0100

    cpufreq: interactive: add input_boost_freq entry. This entry is the frequency which the CPU will be boosted when the screen is touched. It's user configurable from userspace and it needs to match the entries in the frequency table.

    Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

commit c3177d8de748524119928f6cac3279c396a49457
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Tue Sep 25 19:05:12 2012 +0100

    cpufreq: interactive: change frequency up/down kernel thread priority. Now it has more priority than any user thread which should boost interactivity.

    Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

commit 169de9e5f8786c4e959472ec25c3410e3fc0daa5
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Thu Sep 20 18:54:14 2012 +0100

    cpufreq: separate Interactive governor into two, one with static settings and another one with dynamic settings (it adjusts itself according to load). The new governor is called Dynamic Interactive.

commit 3eeaed1f136fb875308c897547269ddc1dd79b64
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Sun Sep 9 04:05:51 2012 +0100

    cpufreq: interactive: fix compiling errors from the latest commits

commit 1b2504427e56927ce3a58f96d9f63879a42bfe69
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Sun Sep 9 04:01:58 2012 +0100

    cpufreq: interactive: remove input_boost handling - https://github.com/android/kernel_common/commit/4e27eb56e819745a1b184f278d7f3dd3887a456c

commit fcdcacf1b21a6fea102227431e355560d7241103
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Sun Sep 9 03:59:21 2012 +0100

    cpufreq: interactive: handle speed up and down in the realtime task - https://github.com/android/kernel_common/commit/f8aa05d96a0d18416d2627c493f7dc9bc5324901

commit 3bd8110aba8ae54c4429b05b7108e3974f282a67
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Sun Sep 9 03:45:18 2012 +0100

    cpufreq: interactive: keep freezer happy when not current governor - https://github.com/android/kernel_common/commit/5ff8407798f1d8c44f3165bc535676a2a897666b

commit c06658ed2c2a5f8cc3531a4b83acd54200311ed7
Author: franciscofranco <franciscofranco.1990@gmail.com>
Date:   Sun Sep 9 03:43:11 2012 +0100

    cpufreq: interactive: take idle notifications only when active - https://github.com/android/kernel_common/commit/22a51ab6e21de740c1b555f9a03626d28aaebdf3

commit c20ae50d4dd8e9ef0c4501012733405af2766b93
Author: Leonid Iziumtsev <x0153368@ti.com>
Date:   Wed Jul 25 14:46:52 2012 +0300

    cpufreq: interactive governor: Fix not uniform buf filling & memory corruption

    Each CPU has it's own load history buffer, but all they use shared
    <history_load_index> variable, this lead to not uniform filling
    of the cpu's circular buffers. Only about half of buffer is updated
    during each buffer rewriting cycle that obligate governor to use
    outdated data during freq tuning.

    Moreover access to <history_load_index> variable is not atomic, that
    create race conditions. Simultaneous increment could cause situation
    where such check:

            if (++history_load_index == sampling_periods)
                    history_load_index = 0;

    not safe and buffer overflow will not be prevented. That will lead
    to memory corruption.

    To avoid such problems this patch move buffer-index variable to
    <cpufreq_interactive_cpuinfo> structure, which is separate for each CPU.
    Also, buffer overflow checking will be paranoidly changed.

    Change-Id: I333a4462be17816372a7a57529811d87930058c0
    Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>
    (cherry picked from commit befb3fe3e38d88bc1872d99748c246c26406315d)

commit 20d522bb802ed338bcb3d94168cadbce8d52709e
Author: Nicole Chalhoub <n-chalhoub@ti.com>
Date:   Thu Apr 26 18:21:35 2012 +0200

    cpufreq: interactiver governor: Add a time view concept

    CPUFreq governors are always a tradeoff between power vs performance.
    For low power UCs we want to have a less reponsive cpufreq governor that
    does not respond or react to each load pick.
    However when scrolling on the screen or during webbrowsing we need a more
    responsive governor that interact or esponse to each load variation.

    To detect which kind of application we have, we'll rely on the history of
    the load. if the the average over the load history is high that means we
    need to be more responsive so we change the governor paramters in that
    direction.
    if the average over the load history is low thatmeans we are in low power
    UCs so we change the governor parameter to be less responsive

    Change-Id: Ifd55ac4cfbc1bd9eded4ae603b158054c6169e8c
    Signed-off-by: Nicole Chalhoub <n-chalhoub@ti.com>
    Signed-off-by: Taras Kondratiuk <taras@ti.com>
    (cherry picked from commit c9d2e290d40f629306ba4cd020be1d71ed5e1d23)

commit c12914672a97c8a6c3800d52a5c40ac06878d6db
Author: Todd Poynor <toddpoynor@google.com>
Date:   Thu May 10 23:28:06 2012 -0700

    cpufreq: interactive: restart above_hispeed_delay at each hispeed load

    Change-Id: I2e5b91d45e8806b0ab94ca2301ed671c9af9ab13
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 5702c9182d292356aba0f0dd6f2f230a7e53fa15
Author: Todd Poynor <toddpoynor@google.com>
Date:   Thu May 3 00:16:55 2012 -0700

    cpufreq: interactive: add boost pulse interface

    Change-Id: Icf1e86d2065cc8f0816ba9c6b065eb056d4e8249
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit fd8bc3774515bc6d2af3dfe567f902098cb0dea8
Author: Todd Poynor <toddpoynor@google.com>
Date:   Thu Apr 26 21:41:40 2012 -0700

    cpufreq: interactive: set floor for boosted speed

    Allow speed to drop to flooor frequency but not below, don't pin
    to speed at last boost.

    Change-Id: I0147c2b7a2e61ba16820605af6baaf09570be787
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 5d61d3a6e2103801565048202999423657b4430a
Author: Todd Poynor <toddpoynor@google.com>
Date:   Mon Apr 23 20:42:41 2012 -0700

    cpufreq: interactive: Add sysfs boost interface for hints from userspace

    The explicit hint on/off version.

    Change-Id: Ibf62b6d45bf6fb8c9c055b9bdaf074ce9374c04f
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 66510aa1148e3457e7d46e0a2582dac7c591b95d
Author: Todd Poynor <toddpoynor@google.com>
Date:   Mon Apr 23 21:22:45 2012 -0700

    cpufreq: interactive: remove unused target_validate_time_in_idle

    Change-Id: I37c5085b91318242612440dfd775ad762996612f
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 2e21b68cd68be556224aee775f67fbbb5d6870a6
Author: Todd Poynor <toddpoynor@google.com>
Date:   Mon Apr 2 17:17:14 2012 -0700

    cpufreq: interactive: Boost frequency on touchscreen input

    Based on previous patches by Tero Kristo <tero.kristo@nokia.com>,
    Brian Steuer <bsteuer@codeaurora.org>,
    David Ng <dave@codeaurora.org>,
    Antti P Miettinen <amiettinen@nvidia.com>, and
    Thomas Renninger <trenn@suse.de>

    Change-Id: Ic55fedcf6f9310f43a7022fb88e23b0392122769
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 85a03bc8bdd9cb45428c794fdec462eb4817ec67
Author: Todd Poynor <toddpoynor@google.com>
Date:   Fri Apr 20 13:18:32 2012 -0700

    cpufreq: Separate speed target revalidate time and initial set time

    Allow speed drop after min_sample_time elapses from last time
    the current speed was last re-validated as appropriate for
    current load / input boost.

    Allow speed bump after min_sample_time (or above_hispeed_delay)
    elapses from the time the current speed was originally set.

    Change-Id: Ic25687a7a53d25e6544c30c47d7ab6f27a47bee8
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 4e3800ea447962106a962f5279ea508edd6ca160
Author: Todd Poynor <toddpoynor@google.com>
Date:   Thu Apr 19 12:52:48 2012 -0700

    cpufreq: interactive: based hispeed bump on target freq, not actual

    For systems that set a common speed for all CPUs, checking current
    speed here could bypass the intermediate hispeed bump decision for
    this CPU when another CPU was already at hispeed.  This could
    result in an overly high setting (for all CPUs) in situations
    where all CPUs were about to drop to load levels that map to
    hispeed or below.

    Change-Id: I186f23dcfc5e2b6336cab8b0327f0c8a9a4482bc
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 801cb6260fb5cae3bbc513927b583447c38d9deb
Author: Todd Poynor <toddpoynor@google.com>
Date:   Tue Apr 17 17:39:34 2012 -0700

    cpufreq: interactive: adjust code and documentation to match

    Change-Id: If59c668d514a29febe5c35404fd9d01df8548eb1
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit c2ad521b982d949c5dfabe5ff257bb4f33ca8b51
Author: Todd Poynor <toddpoynor@google.com>
Date:   Fri Apr 13 20:18:02 2012 -0700

    cpufreq: interactive: configurable delay before raising above hispeed

    Change-Id: I4d6ac40b23a3790d48e30c37408284e9f955e8fa
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit e04e953b657d6e8b4f00b9e341370e339b1a0c97
Author: Todd Poynor <toddpoynor@google.com>
Date:   Fri Apr 6 19:59:36 2012 -0700

    cpufreq: interactive: don't drop speed if recently at higher load

    Apply min_sample_time to the last time the current target speed
    was originally requested or re-validated as appropriate for the
    current load, not to the time since the current speed was
    originally set.  Avoids periodic dips in speed during bursty
    loads.

    Change-Id: I250bda657985de60373f9897cc41f480664d51a1
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 1c41e01a514bc6b5136fd9040bed5137cfd712a8
Author: Todd Poynor <toddpoynor@google.com>
Date:   Fri Apr 6 19:50:12 2012 -0700

    cpufreq: interactive: set at least hispeed when above hispeed load

    If load is above go_hispeed_load, always go to at least hispeed_freq,
    even when reducing speed from a higher speed, not just when jumping
    up from minimum speed.  Avoids running at a lower than intended
    speed after a burst of even higher load.

    Change-Id: I5b9d2a15ba25ce609b21bac7c724265cf6838dee
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit e661e9ba37039c77f8e1faaa231d810f12ac0790
Author: Todd Poynor <toddpoynor@google.com>
Date:   Fri Apr 6 01:13:09 2012 -0700

    cpufreq: interactive: apply intermediate load to max speed not current

    Evaluate spikes in load (below go_hispeed_load) against the maximum
    speed supported by the device, not the current speed (which tends to
    make it too difficult to raise speed to intermediate levels until
    very busy).

    Change-Id: Ib937006abf8bedb60891a739acd733e89b732ae0
    Signed-off-by: Todd Poynor <toddpoynor@google.com>

commit 4d6f3d7209ffa828fad5d5495c1eb8c571d308ad
Author: Todd Poynor <toddpoynor@google.com>
Date:   Thu Feb 16 16:27:59 2012 -0800

    cpufreq interactive governor: event tracing

    Change-Id: Ic13614a3da2faa2d4bd215ca3eb7191614f0cf66
    Signed-off-by: Todd Poynor <toddpoynor@google.com>
Use glibc memcpy and memmove

(original patch: https://github.com/motley-git/kernel-Nexus4/commit/66fbd0ad6a5c37981062f8624839dd8854d65b68)