if (pm_get_power_lock_support()
&& (get_pm_cur_state() == S_SLEEP)) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
set_pm_cur_state(S_NORMAL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
#endif
broadcast_pm_suspend();
if (pm_get_power_lock_support()) {
- pm_enable_autosleep();
+ power_enable_autosleep();
- if (pm_power_unlock() < 0)
+ if (power_release_wakelock() < 0)
_E("Power unlock state error.");
} else {
pm_suspend();
_I("Start Power managing without noti");
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
/*
* Lock lcd off until booting is done.
#include "shared/log.h"
#include "shared/device-notifier.h"
+#include "power/power-control.h"
#include "power-state-manager.h"
#include "power-state-wait.h"
node->pid, node->comm, node->locktime, node->timeout);
}
-/* check the lock_list is empty.
- * if it is, then request wake unlock */
-static void try_wake_unlock(void)
-{
- if (SYS_G_LIST_LENGTH(lock_list) == 0)
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, NULL);
- else
- print_lock_node();
-}
-
-static void try_wake_lock(void)
-{
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL);
-}
-
-/* remove given node from lock list.
- * after removing the node, request wake unlock if possible */
static void remove_lock_node(struct lock_node *node)
{
if (!node)
SYS_G_LIST_REMOVE(lock_list, node);
free(node);
- try_wake_unlock();
+ /* Check the lock_list is empty after removing the node.
+ * If it is, then request wake unlock */
+ if (SYS_G_LIST_LENGTH(lock_list) == 0)
+ power_release_wakelock();
+ else
+ print_lock_node();
}
static gboolean lock_expired_cb(void *data)
}
_D("pid=%d(%s) request CPU lock for %dms", pid, node->comm, timeout);
- try_wake_lock();
+ power_acquire_wakelock();
if (timeout > 0)
node->timer_id = g_timeout_add(timeout, lock_expired_cb, node);
#include "shared/devices.h"
#include "shared/device-notifier.h"
#include "shared/log.h"
+#include "power/power-control.h"
#include "power-state-manager.h"
#include "power-dbus.h"
#include "power-state-wait.h"
return;
}
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, NULL);
+ power_release_wakelock();
}
static void psm_trigger_poweroff(void)
return;
if (power_device->execute) {
- device_notify(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, NULL);
+ power_disable_autosleep();
power_device->execute("poweroff");
}
}
{
current = PSM_NORMAL;
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL);
+ power_acquire_wakelock();
broadcast_transition_info(ti);
}
current = PSM_SLEEP;
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL);
+ power_acquire_wakelock();
broadcast_transition_info(ti);
waiting = update_change_state_wait(state_transition_counter, ti, psm_wake_unlock);
if (waiting > 0) {
{
current = PSM_NORMAL;
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL);
+ power_acquire_wakelock();
broadcast_transition_info(ti);
update_change_state_wait(state_transition_counter, ti, NULL);
}
{
int waiting;
- device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL);
+ power_acquire_wakelock();
broadcast_transition_info(ti);
waiting = update_change_state_wait(state_transition_counter, ti, psm_wake_unlock);
if (waiting > 0) {
/* Deferred autosleep enable,
* This prevents system go suspend during booting */
- device_notify(DEVICE_NOTIFIER_REQUEST_ENABLE_AUTOSLEEP, NULL);
+ power_enable_autosleep();
return 0;
}
if (pm_get_power_lock_support()
&& (get_pm_cur_state() == S_SLEEP)) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
set_pm_cur_state(S_NORMAL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
#endif
broadcast_pm_suspend();
if (pm_get_power_lock_support()) {
- pm_enable_autosleep();
+ power_enable_autosleep();
- if (pm_power_unlock() < 0)
+ if (power_release_wakelock() < 0)
_E("Power unlock state error.");
} else {
pm_suspend();
_I("Start Power managing without noti");
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
/*
* Lock lcd off until booting is done.
if (pm_get_power_lock_support()
&& (get_pm_cur_state() == S_SLEEP)) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
set_pm_cur_state(S_NORMAL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
#endif
broadcast_pm_suspend();
if (pm_get_power_lock_support()) {
- pm_enable_autosleep();
+ power_enable_autosleep();
- if (pm_power_unlock() < 0)
+ if (power_release_wakelock() < 0)
_E("Power unlock state error.");
} else {
pm_suspend();
_I("Start Power managing without noti");
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
/*
* Lock lcd off until booting is done.
if (pm_get_power_lock_support()
&& (get_pm_cur_state() == S_SLEEP)) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
set_pm_cur_state(S_NORMAL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
#endif
broadcast_pm_suspend();
if (pm_get_power_lock_support()) {
- pm_enable_autosleep();
+ power_enable_autosleep();
- if (pm_power_unlock() < 0)
+ if (power_release_wakelock() < 0)
_E("Power unlock state error.");
} else {
pm_suspend();
_I("Start Power managing without noti");
if (pm_get_power_lock_support()) {
broadcast_pm_wakeup();
- pm_power_lock();
+ power_acquire_wakelock();
}
/*
* Lock lcd off until booting is done.
#define CHECK_OPS(d, op) (d != NULL && d->op != NULL)
#ifdef ENABLE_PM_LOG
+#include "power/power-control.h"
#define MAX_LOG_COUNT 250
-
-enum pm_log_type {
- PM_LOG_MIN = 0,
- PM_LOG_KEY_PRESS = PM_LOG_MIN, /* key log */
- PM_LOG_KEY_LONG_PRESS,
- PM_LOG_KEY_RELEASE,
- PM_LOG_LCD_ON, /* lcd log */
- PM_LOG_LCD_ON_COMPLETE,
- PM_LOG_LCD_ON_FAIL,
- PM_LOG_LCD_DIM,
- PM_LOG_LCD_DIM_FAIL,
- PM_LOG_LCD_OFF,
- PM_LOG_LCD_OFF_COMPLETE,
- PM_LOG_LCD_OFF_FAIL,
- PM_LOG_LCD_CONTROL_FAIL,
- PM_LOG_SLEEP,
- PM_LOG_MAX
-};
-
-void pm_history_save(enum pm_log_type, int);
#endif
/*
return 0;
}
-int pm_enable_autosleep(void)
+int power_enable_autosleep(void)
{
_I("System autosleep enabled.");
return sys_set_str(POWER_AUTOSLEEP_PATH, "mem");
}
-int pm_disable_autosleep(void)
+int power_disable_autosleep(void)
{
_I("System autosleep disabled.");
return sys_set_str(POWER_AUTOSLEEP_PATH, "off");
}
-int pm_power_lock(void)
+int power_acquire_wakelock(void)
{
+ if (mainlock_status == POWER_LOCK)
+ return 0;
+
_I("system power lock");
suspend_other_process(VITAL_WAKEUP);
mainlock_status = POWER_LOCK;
return power_lock_support;
}
-int pm_power_unlock(void)
+int power_release_wakelock(void)
{
+ if (mainlock_status == POWER_UNLOCK)
+ return 0;
+
_I("system power unlock");
suspend_other_process(VITAL_SLEEP);
mainlock_status = POWER_UNLOCK;
return 0;
}
-static int __pm_enable_autosleep(void *data)
-{
- return pm_enable_autosleep();
-}
-
-static int __pm_disable_autosleep(void *data)
-{
-
- return pm_disable_autosleep();
-}
-
-static int __pm_power_lock(void *data)
-{
- if (mainlock_status == POWER_UNLOCK)
- pm_power_lock();
-
- return 0;
-}
-
-static int __pm_power_unlock(void *data)
-{
- if (mainlock_status == POWER_LOCK)
- pm_power_unlock();
-
- return 0;
-}
-
static int load_sleep_config(struct parse_result *result, void *user_data)
{
if (!MATCH(result->section, "PowerState"))
if (check_default(plugin_device_ops))
return;
- /* if there is plugin of power-control,
- * register notifier for the plugin module */
- register_notifier(DEVICE_NOTIFIER_REQUEST_ENABLE_AUTOSLEEP, __pm_enable_autosleep);
- register_notifier(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, __pm_disable_autosleep);
- register_notifier(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, __pm_power_lock);
- register_notifier(DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, __pm_power_unlock);
-
_D("[%s] Initialization.", plugin_device_ops->name);
if (plugin_device_ops->init)
plugin_device_ops->init(NULL);
#include "display/core.h"
-
#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep"
#define POWER_LOCK_PATH "/sys/power/wake_lock"
#define POWER_UNLOCK_PATH "/sys/power/wake_unlock"
VITAL_EXIT,
};
+enum pm_log_type {
+ PM_LOG_MIN = 0,
+ PM_LOG_KEY_PRESS = PM_LOG_MIN, /* key log */
+ PM_LOG_KEY_LONG_PRESS,
+ PM_LOG_KEY_RELEASE,
+ PM_LOG_LCD_ON, /* lcd log */
+ PM_LOG_LCD_ON_COMPLETE,
+ PM_LOG_LCD_ON_FAIL,
+ PM_LOG_LCD_DIM,
+ PM_LOG_LCD_DIM_FAIL,
+ PM_LOG_LCD_OFF,
+ PM_LOG_LCD_OFF_COMPLETE,
+ PM_LOG_LCD_OFF_FAIL,
+ PM_LOG_LCD_CONTROL_FAIL,
+ PM_LOG_SLEEP,
+ PM_LOG_MAX
+};
+
+
extern bool timeout_sleep_support;
#ifdef ENABLE_PM_LOG
bool vital_mode(void);
int vital_state_changed(void *data);
int pm_suspend(void);
-int pm_enable_autosleep(void);
-int pm_power_lock(void);
-int pm_power_unlock(void);
+int power_enable_autosleep(void);
+int power_disable_autosleep(void);
+int power_acquire_wakelock(void);
+int power_release_wakelock(void);
int pm_get_power_lock(void);
int pm_get_power_lock_support(void);
int check_wakeup_src(void);
free(handle);
}
+static int poweroff_add_handle(pid_t pid)
+{
+ struct poweroff_handle *handle;
+ GList *l;
+
+ SYS_G_LIST_FOREACH(poweroff_handles, l, handle) {
+ if (handle->pid == pid)
+ break;
+ }
+
+ if (handle)
+ poweroff_remove_handle(pid);
+
+ _D("Make a new handle.");
+ handle = (struct poweroff_handle *)malloc(sizeof(struct poweroff_handle));
+ if (handle == NULL) {
+ _E("Not enough memory.");
+ return -ENOMEM;
+ }
+
+ handle->pid = pid;
+ handle->timeout_id = 0;
+ handle->timeout = POWEROFF_WAIT_MAX;
+
+ SYS_G_LIST_APPEND(poweroff_handles, handle);
+ _D("Add a new poweroff timer. pid=%d timeout=%d timeout_id=%d)", handle->pid, handle->timeout, handle->timeout_id);
+
+ return 0;
+}
+
static gboolean poweroff_wait_timeout_cb(void *data)
{
char timeout[50] = {0,};
const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
- struct poweroff_handle *handle;
int ret;
pid_t pid;
- GList *l;
if (poweroff_stage >= POWEROFF_WAIT_OTHERS) {
_E("It's too late. Poweroff is already in waiting stage.");
CRITICAL_LOG("PID %d requested to a poweroff timer.", pid);
- SYS_G_LIST_FOREACH(poweroff_handles, l, handle) {
- if (handle->pid == pid)
- break;
- }
-
- if (handle)
- poweroff_remove_handle(pid);
-
- _D("Make a new handle.");
- handle = (struct poweroff_handle *)malloc(sizeof(struct poweroff_handle));
- if (handle == NULL) {
- _E("Not enough memory.");
- ret = -1;
- goto out;
- }
-
- handle->pid = pid;
- handle->timeout_id = 0;
- handle->timeout = POWEROFF_WAIT_MAX;
-
- SYS_G_LIST_APPEND(poweroff_handles, handle);
- _D("Add a new poweroff timer. pid=%d timeout=%d timeout_id=%d)", handle->pid, handle->timeout, handle->timeout_id);
-
- ret = 0;
+ ret = poweroff_add_handle(pid);
out:
return g_variant_new("(i)", ret);
return 0;
}
+int poweroff_add_wait(pid_t pid)
+{
+ return poweroff_add_handle(pid);
+}
+
+void poweroff_remove_wait(pid_t pid)
+{
+ g_idle_add(poweroff_wait_timeout_cb, (void *)(intptr_t) pid);
+}
+
static int load_config(struct parse_result *result, void *user_data)
{
enum poweroff_type type;
#ifndef __POWER_HANDLE_H__
#define __POWER_HANDLE_H__
+#include <sys/types.h>
+
#define POWER_OPS_NAME "power"
#define POWER_POWEROFF "poweroff"
};
int check_power_flag(void);
-void poweroff(void);
void poweroff_request_shutdown(void);
+int poweroff_add_wait(pid_t pid);
+void poweroff_remove_wait(pid_t pid);
+
#endif /* __POWER_HANDLE_H__ */
/* Purpose of calling methods of different modules
* Use prefix DEVICE_NOTIFIER_REQUEST */
- DEVICE_NOTIFIER_REQUEST_ENABLE_AUTOSLEEP,
- DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP,
- DEVICE_NOTIFIER_REQUEST_WAKE_LOCK,
- DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK,
DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE,
DEVICE_NOTIFIER_MAX,
};