kernel/main: fix calling sysfs_notify from atomic context

Sysfs_notify takes a mutex and therefore cannot be called from atomic
context like interrupt handler in this case. Use a workqueue to schedule
the work instead.

Change-Id: I0a5230fe379aa51f1065df4af9b27f471aa22440
Signed-off-by: Amar Singhal <asinghal@codeaurora.org>
(cherry picked from commit 97d68a8b69e87480c436dd8365b438c3d18fed47)

Conflicts:

	kernel/power/main.c
PM: Enable early suspend through /sys/power/state

If EARLYSUSPEND is enabled then writes to /sys/power/state no longer
blocks, and the kernel will try to enter the requested state every
time no wakelocks are held. Write "on" to resume normal operation.

Change-Id: Icbe3c6fe6f5e0f4a3f948f1495546690ac9fd6e6
(cherry picked from commit 219955f707852f68f5118a515fc43ad067728ab9)
earlysuspend: add verbose debug flag

when enabled, prints out the function of each handler as they are called

Change-Id: I5ed251867e0e3aa3cd05f030ff3579808cedd0c2
Signed-off-by: Erik Gilling <konkers@android.com>
(cherry picked from commit fec502d9a18bbe8045c67bd4f9d3a1ade4e78555)
power: fix lcd resume taking long time with an ongoing file copy

This fixes the issue where LCD takes a long time to come back up
since the execution of backlight on and late_resume works by the
suspend worker thread is delayed due to one (or more) of the
sys_sync calls in early_suspend and suspend paths taking a long
time (sometimes 15sec or more) for the below reported scenario(s):

Scenario 1 (copy with usb connected):
1. plug usb
2. adb shell
3. busybox cp /sdcard/file1 /sdcard/file2 (copy >= 100MB file1
   in sdcard/emmc to file2 in sdcard/emmc)
4. press end key to suspend
5. press end key again and it takes a long time for LCD to come
   back up

Scenario 2 (background copy):
1. plug usb
2. adb shell
3. busybox cp /sdcard/file1 /sdcard/file2 & (copy >= 100MB file1
   in sdcard/emmc to file2 in sdcard/emmc)
4. disconnect usb
5. press end key to suspend
6. press end key again and it takes a long time for LCD to come
   back up

A more common form of Scenario 2 is for the user to just use the
copy function on the UI to copy large file(s).

We address this by moving sys_sync calls to a separate workqueue
and having a timeout polling based mechanism to bail out of suspend
in case of user invoking a wakeup event (like end key press) while
we are waiting for the sys_sync completion at the synchronization
point in suspend worker thread context.

CRs-Fixed: 283994
Change-Id: I6b54af8432e58fd5442817b7388ce2e0b83354b6
Signed-off-by: Pratik Patel <pratikp@codeaurora.org>
(cherry picked from commit 8564b5ebeafa2be276e0004d7d32bd101642fb3d)

Conflicts:

	kernel/power/process.c
framebuffer: add a pollable sysfs entry for display status

Wakeup the userspace poll on change of display status. The
userspace then may take action to change the
power/performance characteristics of the device.

Change-Id: I9bd11f3d895d3d83230104f5d8dcd1deeaa754cd
Signed-off-by: Amar Singhal <asinghal@codeaurora.org>
(cherry picked from commit 2fb0354486e2d7b8d73622cbdbb941748a921240)
power: fix suspend_sys_sync_wait()

Since the workqueue code deletes the work before executing it,
checking for no work item being currently queued to the workqueue
is not sufficient to guarantee that all the works have finished
execution.

Use a counter to guarantee that all the pending suspend_sys_sync()
works have finished execution before returning from
suspend_sys_sync_wait().

CRs-Fixed: 293595
Signed-off-by: Pratik Patel <pratikp@codeaurora.org>

Conflicts:

	kernel/power/wakelock.c
(cherry picked from commit 529461b70c7dc20b0371e54a63844edae905d7a2)

Conflicts:

	kernel/power/wakelock.c

Change-Id: I501743b6b76e492e1598df83ebc1178835ae8405
power: wakelocks: fix buffer overflow in print_wake_locks

Change-Id: Ic944e3b3d3bc53eddc6fd0963565fd072cac373c
Signed-off-by: Erik Gilling <konkers@android.com>
(cherry picked from commit 10f0138c56a31a39c2a123af5af95cf8fd5de1ac)
power: wakelock: use get_xtime_and_monotonic_and_sleep_offset in get_expired_time

Change-Id: I6ebe6b954b2ff328d46898d683650dafb9c4fe74
Signed-off-by: Erik Gilling <konkers@android.com>
(cherry picked from commit 28e23cf73c26d2bb13451804e328797a55f471e4)

Conflicts:

	kernel/power/wakelock.c
PM: Backoff suspend if repeated attempts fail

Change-Id: I32289676d95a307ea3aa5e78f6c126ca979c0fec
Signed-off-by: Todd Poynor <toddpoynor@google.com>
(cherry picked from commit 7013f4976374ea75cb35446393be7bdc37bf607f)

Conflicts:

	kernel/power/wakelock.c
PM: wakelocks: Use seq_file for /proc/wakelocks so we can get more than 3K of stats.

Change-Id: I42ed8bea639684f7a8a95b2057516764075c6b01
Signed-off-by: Arve Hjønnevåg <arve@android.com>
(cherry picked from commit 1b0749512f76005ce41607472e6f36411fa96649)
power: Prevent spinlock recursion when wake_unlock() is called

Signed-off-by: Mike Chan <mike@android.com>
(cherry picked from commit 97a0a74383d19a1a43ffca81271894ba3edc07b6)
power: wakelock: Print active wakelocks when has_wake_lock() is called

When DEBUG_SUSPEND is enabled print active wakelocks when we check
if there are any active wakelocks.

In print_active_locks(), print expired wakelocks if DEBUG_EXPIRE is enabled

Change-Id: Ib1cb795555e71ff23143a2bac7c8a58cbce16547
Signed-off-by: Mike Chan <mike@android.com>
(cherry picked from commit af62b25adba1fe01c91aa88c95d1584371ab2bf9)
PM: wakelocks: Don't report wake up wakelock if suspend aborted

If the wakelock driver aborts suspend due to an already-held
wakelock, don't report the next wakelock held as the "wake up
wakelock".

Change-Id: I582ffbb87a3c361739a77d839a0c62921cff11a6
Signed-off-by: Todd Poynor <toddpoynor@google.com>
(cherry picked from commit ed27e538aa97278e26a6c00f14f6e2e076a1a2ae)
wakelock: Fix operator precedence bug

Change-Id: I21366ace371d1b8f4684ddbe4ea8d555a926ac21
Signed-off-by: Colin Cross <ccross@google.com>
(cherry picked from commit 0c7841ce3e0a90bab630f671992348dafb022558)
PM: wakelocks: Display wakelocks preventing suspend by default

Use DEBUG_WAKEUP flag to show wakelocks that abort suspend, in
addition to showing wakelocks held during system resume.
DEBUG_WAKEUP is enabled by default.

Change-Id: If6fa68e8afbc482a5300ffab2964694b02b34f41
Signed-off-by: Todd Poynor <toddpoynor@google.com>
(cherry picked from commit ca64b0cd3a12d7704f4e98f4f5d51f41eb5047a2)
PM: wakelock: Abort task freezing if a wake lock is held.

Avoids a problem where the device sometimes hangs for 20 seconds
before the screen is turned on.

Change-Id: Ib24dad1f0f56d280a80be820200ee9e9aea7a911
(cherry picked from commit 044fb1a352b4d367048b24c8c39abc2e572dc0e7)

Conflicts:

	kernel/power/process.c
consoleearlysuspend: Fix for 2.6.32

vt_waitactive now needs a 1 based console number

Change-Id: I07ab9a3773c93d67c09d928c8d5494ce823ffa2e
(cherry picked from commit b28a6a111c2c4779f92f310cfefe10606df4999f)
lib: memory alloc

Add a generic library (which uses genalloc) that manages
pools of contiguous memory.

APIs are provided to allocate (and if desired map) and free
memory, as well to initialize a memory pool.

Change-Id: I75deda08eb852a323b4d1a32c3b7980e7aa143a8
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
(cherry picked from commit 54bff5255ff4adf204d2b4a9805cdb998167fb9e)
lib: remove extraneous exports and function prototypes

Remove the function prototype for the function
alloc_from_memory_pool() (this function was never implemented).
The function mem_type_to_memory_pool() was not intended to be
exported, so remove the export and function prototypes.

Change-Id: Iac47d5c8a8aaf21554c2a7a56f42d6f7de689d3e
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
(cherry picked from commit fe7d2ee21af00476fe9e578fcfea1c34a70bd30f)
lib: Remove negative error values from allocate_contiguous_memory_nomap

allocate_contiguous_memory_nomap returns an unsigned long yet it
was returning errno codes for various failures.  Replace all negative
errno codes with 0, which is what all the callers expect on error anyway.

Change-Id: I3f847f70e0d7fa947a3442f43a980b3ffb1bfd96
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit f319151ecf9bdb51295ddbf6ac8385f63fd4ae70)