Commit ef588965 authored by AlaskaLinuxUser's avatar AlaskaLinuxUser

Fix early suspend so everything else will work right.

parent 963008d5
......@@ -876,7 +876,7 @@ static int __init cpufreq_asswax_init(void)
INIT_WORK(&freq_scale_work, cpufreq_asswax_freq_change_time_work);
// WJH register_early_suspend(&asswax_power_suspend);
register_early_suspend(&asswax_power_suspend);
return cpufreq_register_governor(&cpufreq_gov_asswax);
}
......
......@@ -724,7 +724,7 @@ static int cpufreq_governor_brazilianwax(struct cpufreq_policy *new_policy,
this_brazilianwax->enable = 1;
// imoseyon - should only register for suspend when governor active
// WJH register_early_suspend(&brazilianwax_power_suspend);
register_early_suspend(&brazilianwax_power_suspend);
pr_info("[imoseyon] brazilianwax active\n");
// notice no break here!
......@@ -749,7 +749,7 @@ static int cpufreq_governor_brazilianwax(struct cpufreq_policy *new_policy,
pm_idle = pm_idle_old;
// unregister when governor exits
// WJH unregister_early_suspend(&brazilianwax_power_suspend);
unregister_early_suspend(&brazilianwax_power_suspend);
pr_info("[imoseyon] brazilianwax inactive\n");
break;
}
......
......@@ -638,7 +638,7 @@ return rc;
enabled = 1;
registration = 1;
// WJH register_early_suspend(&interactivex_power_suspend);
register_early_suspend(&interactivex_power_suspend);
registration = 0;
pr_info("[imoseyon] interactivex start\n");
break;
......@@ -667,7 +667,7 @@ sysfs_remove_group(cpufreq_global_kobject,
&interactivex_attr_group);
enabled = 0;
// WJH unregister_early_suspend(&interactivex_power_suspend);
unregister_early_suspend(&interactivex_power_suspend);
pr_info("[imoseyon] interactivex inactive\n");
break;
......
......@@ -736,7 +736,7 @@ static int __init cpufreq_smartass_init(void)
INIT_WORK(&freq_scale_work, cpufreq_smartass_freq_change_time_work);
// WJH register_early_suspend(&smartass_power_suspend);
register_early_suspend(&smartass_power_suspend);
return cpufreq_register_governor(&cpufreq_gov_smartass);
}
......
......@@ -843,7 +843,7 @@ static int __init cpufreq_smartass_init(void)
INIT_WORK(&freq_scale_work, cpufreq_smartass_freq_change_time_work);
// WJH register_early_suspend(&smartass_power_suspend);
register_early_suspend(&smartass_power_suspend);
return cpufreq_register_governor(&cpufreq_gov_smartass2);
}
......
......@@ -29,11 +29,11 @@
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/input.h>
// WJH #ifndef CONFIG_HAS_EARLYSUSPEND
#ifndef CONFIG_HAS_EARLYSUSPEND
#include <linux/lcd_notify.h>
// WJH #else
#else
#include <linux/earlysuspend.h>
// WJH #endif
#endif
#include <linux/hrtimer.h>
#include <asm-generic/cputime.h>
......@@ -403,7 +403,7 @@ static int __init doubletap2wake_init(void)
pr_err("%s: Failed to register lcd callback\n", __func__);
}
#else
// WJH register_early_suspend(&dt2w_early_suspend_handler);
register_early_suspend(&dt2w_early_suspend_handler);
#endif
#ifndef ANDROID_TOUCH_DECLARED
......
......@@ -19,6 +19,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
......@@ -29,11 +30,11 @@
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/input.h>
// WJH #ifndef CONFIG_HAS_EARLYSUSPEND
#ifndef CONFIG_HAS_EARLYSUSPEND
#include <linux/lcd_notify.h>
// WJH #else
#else
#include <linux/earlysuspend.h>
// WJH #endif
#endif
#include <linux/hrtimer.h>
/* uncomment since no touchscreen defines android touch, do that here */
......@@ -428,7 +429,7 @@ static int __init sweep2wake_init(void)
pr_err("%s: Failed to register lcd callback\n", __func__);
}
#else
// WJH register_early_suspend(&s2w_early_suspend_handler);
register_early_suspend(&s2w_early_suspend_handler);
#endif
#ifndef ANDROID_TOUCH_DECLARED
......
......@@ -16,10 +16,7 @@
#ifndef _LINUX_EARLYSUSPEND_H
#define _LINUX_EARLYSUSPEND_H
// WJH #ifdef CONFIG_HAS_EARLYSUSPEND
#ifndef CONFIG_HAS_EARLYSUSPEND
#define CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/list.h>
#endif
......@@ -39,12 +36,12 @@ enum {
EARLY_SUSPEND_LEVEL_DISABLE_FB = 150,
};
struct early_suspend {
// WJH #ifdef CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_HAS_EARLYSUSPEND
struct list_head link;
int level;
void (*suspend)(struct early_suspend *h);
void (*resume)(struct early_suspend *h);
// WJH #endif
#endif
};
#ifdef CONFIG_HAS_EARLYSUSPEND
......@@ -56,3 +53,5 @@ void unregister_early_suspend(struct early_suspend *handler);
#endif
#endif
......@@ -31,6 +31,7 @@ config SUSPEND_SKIP_SYNC
config HAS_EARLYSUSPEND
bool
default y
config WAKELOCK
bool "Android's method of preventing suspend"
......
......@@ -8,6 +8,8 @@ obj-$(CONFIG_FREEZER) += process.o
obj-$(CONFIG_SUSPEND) += suspend.o
obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o
obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o
obj-$(CONFIG_EARLYSUSPEND) += earlysuspend.o
obj-$(CONFIG_HAS_EARLYSUSPEND) += earlysuspend.o
obj-$(CONFIG_PM_AUTOSLEEP) += autosleep.o
obj-$(CONFIG_PM_WAKELOCKS) += wakelock.o
......
/* kernel/power/earlysuspend.c
*
* Copyright (C) 2005-2008 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/earlysuspend.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/rtc.h>
#include <linux/syscalls.h> /* sys_sync */
#include <linux/wakelock.h>
#include <linux/workqueue.h>
#include "power.h"
enum {
DEBUG_USER_STATE = 1U << 0,
DEBUG_SUSPEND = 1U << 2,
DEBUG_VERBOSE = 1U << 3,
};
static int debug_mask = DEBUG_USER_STATE | DEBUG_SUSPEND | DEBUG_VERBOSE;
/* static int debug_mask = DEBUG_USER_STATE; */
module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
int earlysuspend_debug_mask = 0;
/* int earlysuspend_debug_mask = DEBUG_USER_STATE; */
int early_suspend_count = 0;
int forbid_id = 0x0;
#define _TAG_PM_M "Ker_PM"
#define pm_warn(fmt, ...) \
do { \
if (earlysuspend_debug_mask) \
pr_warn("[%s][%s]" fmt, _TAG_PM_M, __func__, ##__VA_ARGS__); \
} while (0)
static DEFINE_MUTEX(early_suspend_lock);
static LIST_HEAD(early_suspend_handlers);
static void early_sys_sync(struct work_struct *work);
static void early_suspend(struct work_struct *work);
static void late_resume(struct work_struct *work);
static DECLARE_WORK(early_sys_sync_work, early_sys_sync);
static DECLARE_WORK(early_suspend_work, early_suspend);
static DECLARE_WORK(late_resume_work, late_resume);
static DEFINE_SPINLOCK(state_lock);
/* */
struct wake_lock sys_sync_wake_lock;
struct workqueue_struct *suspend_work_queue;
struct workqueue_struct *sys_sync_work_queue;
suspend_state_t requested_suspend_state = PM_SUSPEND_MEM;
enum {
SUSPEND_REQUESTED = 0x1,
SUSPENDED = 0x2,
SUSPEND_REQUESTED_AND_SUSPENDED = SUSPEND_REQUESTED | SUSPENDED,
};
static int state;
static DECLARE_COMPLETION(fb_drv_ready);
void register_early_suspend(struct early_suspend *handler)
{
struct list_head *pos;
mutex_lock(&early_suspend_lock);
list_for_each(pos, &early_suspend_handlers) {
struct early_suspend *e;
e = list_entry(pos, struct early_suspend, link);
if (e->level > handler->level)
break;
}
list_add_tail(&handler->link, pos);
early_suspend_count++;
if ((state & SUSPENDED) && handler->suspend)
handler->suspend(handler);
mutex_unlock(&early_suspend_lock);
}
EXPORT_SYMBOL(register_early_suspend);
void unregister_early_suspend(struct early_suspend *handler)
{
mutex_lock(&early_suspend_lock);
list_del(&handler->link);
early_suspend_count--;
mutex_unlock(&early_suspend_lock);
}
EXPORT_SYMBOL(unregister_early_suspend);
static void early_sys_sync(struct work_struct *work)
{
wake_lock(&sys_sync_wake_lock);
sys_sync();
wake_unlock(&sys_sync_wake_lock);
}
static void early_suspend(struct work_struct *work)
{
struct early_suspend *pos;
unsigned long irqflags;
int abort = 0, count = 0;
pr_info("Beginning %s", __func__);
mutex_lock(&early_suspend_lock);
spin_lock_irqsave(&state_lock, irqflags);
if (state == SUSPEND_REQUESTED)
state |= SUSPENDED;
else
abort = 1;
spin_unlock_irqrestore(&state_lock, irqflags);
if (abort) {
pm_warn("abort, state %d\n", state);
mutex_unlock(&early_suspend_lock);
goto abort;
}
pr_warn("early_suspend_count = %d, forbid_id = 0x%x\n", early_suspend_count, forbid_id);
if (earlysuspend_debug_mask & DEBUG_SUSPEND)
pm_warn("call handlers\n");
list_for_each_entry(pos, &early_suspend_handlers, link) {
if (pos->suspend != NULL) {
if (!(forbid_id & (0x1 << count))) {
/* if (earlysuspend_debug_mask & DEBUG_VERBOSE) */
pr_warn("ES handlers %d: [%pf], level: %d\n", count, pos->suspend,
pos->level);
pos->suspend(pos);
}
count++;
}
}
mutex_unlock(&early_suspend_lock);
/* Remove sys_sync from early_suspend, and use work queue to complete sys_sync */
abort:
if (state == SUSPEND_REQUESTED_AND_SUSPENDED) {
/* wake_unlock(&main_wake_lock); */
#ifdef CONFIG_MTK_HIBERNATION
suspend_state_t susp_state = get_suspend_state();
pr_info("%s: calling pm_autosleep_set_state() with parameter: %d", __func__, susp_state);
pm_autosleep_set_state(susp_state);
#else
pm_autosleep_set_state(PM_SUSPEND_MEM);
#endif
}
}
static void late_resume(struct work_struct *work)
{
struct early_suspend *pos;
unsigned long irqflags;
int abort = 0;
int completed = 0, count = 0;
pr_info("Beginning %s", __func__);
pm_autosleep_set_state(PM_SUSPEND_ON);
mutex_lock(&early_suspend_lock);
spin_lock_irqsave(&state_lock, irqflags);
if (state == SUSPENDED)
state &= ~SUSPENDED;
else
abort = 1;
spin_unlock_irqrestore(&state_lock, irqflags);
if (abort) {
if (earlysuspend_debug_mask & DEBUG_SUSPEND)
pm_warn("abort, state %d\n", state);
goto abort;
}
pr_warn("late_resume_count = %d, forbid_id = 0x%x\n", early_suspend_count, forbid_id);
if (earlysuspend_debug_mask & DEBUG_SUSPEND)
pm_warn("call handlers\n");
list_for_each_entry_reverse(pos, &early_suspend_handlers, link) {
if (!completed && pos->level < EARLY_SUSPEND_LEVEL_STOP_DRAWING) {
complete(&fb_drv_ready);
completed = 1;
}
if (pos->resume != NULL) {
if (!(forbid_id & (0x1 << (early_suspend_count - count - 1)))) {
/* if (earlysuspend_debug_mask & DEBUG_VERBOSE) */
pr_warn("LR handlers %d: [%pf], level: %d\n", count, pos->resume,
pos->level);
pos->resume(pos);
}
count++;
}
}
if (earlysuspend_debug_mask & DEBUG_SUSPEND)
pr_info("%s done\n", __func__);
abort:
if (!completed)
complete(&fb_drv_ready);
mutex_unlock(&early_suspend_lock);
}
void request_suspend_state(suspend_state_t new_state)
{
unsigned long irqflags;
int old_sleep;
int wait_flag = 0;
spin_lock_irqsave(&state_lock, irqflags);
old_sleep = state & SUSPEND_REQUESTED;
if (earlysuspend_debug_mask & DEBUG_USER_STATE) {
struct timespec ts;
struct rtc_time tm;
getnstimeofday(&ts);
rtc_time_to_tm(ts.tv_sec, &tm);
pr_info("%s (%d->%d) at %lld (%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n",
new_state != PM_SUSPEND_ON ? "sleep" : "wakeup",
requested_suspend_state, new_state,
ktime_to_ns(ktime_get()),
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec);
}
if (!old_sleep && new_state != PM_SUSPEND_ON) {
state |= SUSPEND_REQUESTED;
pr_debug("sys_sync_work_queue early_sys_sync_work");
queue_work(sys_sync_work_queue, &early_sys_sync_work);
pr_debug("suspend_work_queue early_suspend_work");
queue_work(suspend_work_queue, &early_suspend_work);
} else if (old_sleep && new_state == PM_SUSPEND_ON) {
state &= ~SUSPEND_REQUESTED;
/* wake_lock(&main_wake_lock); */
/* /cun */
if (queue_work(suspend_work_queue, &late_resume_work)) {
/*
* In order to synchronize the backlight turn on timing,
* block the thread and wait for fb driver late_resume()
* callback function is completed
*/
wait_flag = 1;
}
}
requested_suspend_state = new_state;
spin_unlock_irqrestore(&state_lock, irqflags);
if (wait_flag == 1) {
wait_for_completion(&fb_drv_ready);
pr_info("%s wait for completion done", __func__);
}
}
suspend_state_t get_suspend_state(void)
{
return requested_suspend_state;
}
/* cun */
static int __init org_wakelocks_init(void)
{
int ret;
wake_lock_init(&sys_sync_wake_lock, WAKE_LOCK_SUSPEND, "sys_sync");
sys_sync_work_queue = create_singlethread_workqueue("fs_sync");
if (sys_sync_work_queue == NULL)
pr_err("[wakelocks_init] fs_sync workqueue create failed\n");
suspend_work_queue = create_singlethread_workqueue("suspend");
if (suspend_work_queue == NULL) {
ret = -ENOMEM;
goto err_suspend_work_queue;
}
return 0;
err_suspend_work_queue:
return ret;
}
static void __exit org_wakelocks_exit(void)
{
destroy_workqueue(suspend_work_queue);
}
core_initcall(org_wakelocks_init);
module_exit(org_wakelocks_exit);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment