#include <sys/time.h>
#include <libsyscommon/list.h>
#include <device/display-internal.h>
+#include <hal/device/hal-device-power.h>
#include "ambient-mode.h"
#include "util.h"
#include "shared/apps.h"
#include "extcon/extcon.h"
#include "battery/power-supply.h"
+#include "power/power.h"
#include "power/power-off.h"
#include "power/power-suspend.h"
#include "power/power-boot.h"
void lcd_on_direct(enum device_flags flags)
{
- if (pm_get_power_lock_support()
- && (get_pm_cur_state() == S_SLEEP)) {
- power_acquire_wakelock();
- set_pm_cur_state(S_NORMAL);
- }
+ enum hal_device_power_transition_reason reason;
+
+ if (flags & LCD_ON_BY_POWER_KEY)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY;
+ else if (flags & LCD_ON_BY_TOUCH)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN;
+ else
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
+
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, NULL);
+ set_pm_cur_state(S_NORMAL);
_D("lcd is on directly");
gettimeofday(&lcdon_tv, NULL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ power_get_wakeup_reason(), NULL);
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
#ifdef ENABLE_PM_LOG
pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
#endif
- if (pm_get_power_lock_support()) {
- power_enable_autosleep();
-
- if (power_release_wakelock() < 0)
- _E("Power unlock state error.");
- } else {
- pm_suspend();
- _I("system wakeup!!");
- system_wakeup_flag = true;
- /* Resume !! */
- if (check_wakeup_src() == EVENT_DEVICE)
- /* system waked up by devices */
- states[get_pm_cur_state()].trans(EVENT_DEVICE);
- else
- /* system waked up by user input */
- states[get_pm_cur_state()].trans(EVENT_INPUT);
- }
+ power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF);
return 0;
go_lcd_off:
return 0;
}
+static int power_resume_from_echomem_callback(void *data)
+{
+ system_wakeup_flag = true;
+ if (check_wakeup_src() == EVENT_DEVICE)
+ /* system waked up by devices */
+ states[get_pm_cur_state()].trans(EVENT_DEVICE);
+ else
+ /* system waked up by user input */
+ states[get_pm_cur_state()].trans(EVENT_INPUT);
+
+ return 0;
+}
+
static int poweroff_triggered_callback(void *udata)
{
int val = (int)(intptr_t) udata;
register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing);
+ register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
init_save_userlock();
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
_I("Start Power managing without noti");
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL);
/*
* Lock lcd off until booting is done.
* deviced guarantees all booting script is executing.
unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
+ unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
break;
}
#include <vconf-keys.h>
#include <sys/time.h>
#include <libsyscommon/list.h>
+#include <hal/device/hal-device-power.h>
#include "ambient-mode.h"
#include "util.h"
#include "shared/apps.h"
#include "extcon/extcon.h"
#include "battery/power-supply.h"
+#include "power/power.h"
#include "power/power-off.h"
#include "power/power-suspend.h"
#include "power/power-boot.h"
void lcd_on_direct(enum device_flags flags)
{
- if (pm_get_power_lock_support()
- && (get_pm_cur_state() == S_SLEEP)) {
- power_acquire_wakelock();
- set_pm_cur_state(S_NORMAL);
- }
+ enum hal_device_power_transition_reason reason;
+
+ if (flags & LCD_ON_BY_POWER_KEY)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY;
+ else if (flags & LCD_ON_BY_TOUCH)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN;
+ else
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
+
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, NULL);
+ set_pm_cur_state(S_NORMAL);
_D("lcd is on directly");
gettimeofday(&lcdon_tv, NULL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ power_get_wakeup_reason(), NULL);
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
#ifdef ENABLE_PM_LOG
pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
#endif
- if (pm_get_power_lock_support()) {
- power_enable_autosleep();
-
- if (power_release_wakelock() < 0)
- _E("Power unlock state error.");
- } else {
- pm_suspend();
- _I("system wakeup!!");
- system_wakeup_flag = true;
- /* Resume !! */
- if (check_wakeup_src() == EVENT_DEVICE)
- /* system waked up by devices */
- states[get_pm_cur_state()].trans(EVENT_DEVICE);
- else
- /* system waked up by user input */
- states[get_pm_cur_state()].trans(EVENT_INPUT);
- }
+ power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF);
return 0;
go_lcd_off:
return 0;
}
+static int power_resume_from_echomem_callback(void *data)
+{
+ system_wakeup_flag = true;
+ if (check_wakeup_src() == EVENT_DEVICE)
+ /* system waked up by devices */
+ states[get_pm_cur_state()].trans(EVENT_DEVICE);
+ else
+ /* system waked up by user input */
+ states[get_pm_cur_state()].trans(EVENT_INPUT);
+
+ return 0;
+}
+
static int poweroff_triggered_callback(void *udata)
{
int val = (int)(intptr_t) udata;
register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing);
+ register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
init_save_userlock();
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
_I("Start Power managing without noti");
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL);
/*
* Lock lcd off until booting is done.
* deviced guarantees all booting script is executing.
unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
+ unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
break;
}
#include <vconf-keys.h>
#include <sys/time.h>
#include <libsyscommon/list.h>
+#include <hal/device/hal-device-power.h>
#include "ambient-mode.h"
#include "util.h"
#include "shared/apps.h"
#include "extcon/extcon.h"
#include "battery/power-supply.h"
+#include "power/power.h"
#include "power/power-off.h"
#include "power/power-suspend.h"
#include "power/power-boot.h"
void lcd_on_direct(enum device_flags flags)
{
- if (pm_get_power_lock_support()
- && (get_pm_cur_state() == S_SLEEP)) {
- power_acquire_wakelock();
- set_pm_cur_state(S_NORMAL);
- }
+ enum hal_device_power_transition_reason reason;
+
+ if (flags & LCD_ON_BY_POWER_KEY)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY;
+ else if (flags & LCD_ON_BY_TOUCH)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN;
+ else
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
+
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, NULL);
+ set_pm_cur_state(S_NORMAL);
_D("lcd is on directly");
gettimeofday(&lcdon_tv, NULL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ power_get_wakeup_reason(), NULL);
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
#ifdef ENABLE_PM_LOG
pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
#endif
- if (pm_get_power_lock_support()) {
- power_enable_autosleep();
-
- if (power_release_wakelock() < 0)
- _E("Power unlock state error.");
- } else {
- pm_suspend();
- _I("system wakeup!!");
- system_wakeup_flag = true;
- /* Resume !! */
- if (check_wakeup_src() == EVENT_DEVICE)
- /* system waked up by devices */
- states[get_pm_cur_state()].trans(EVENT_DEVICE);
- else
- /* system waked up by user input */
- states[get_pm_cur_state()].trans(EVENT_INPUT);
- }
+ power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF);
return 0;
go_lcd_off:
return 0;
}
+static int power_resume_from_echomem_callback(void *data)
+{
+ system_wakeup_flag = true;
+ if (check_wakeup_src() == EVENT_DEVICE)
+ /* system waked up by devices */
+ states[get_pm_cur_state()].trans(EVENT_DEVICE);
+ else
+ /* system waked up by user input */
+ states[get_pm_cur_state()].trans(EVENT_INPUT);
+
+ return 0;
+}
+
static int poweroff_triggered_callback(void *udata)
{
int val = (int)(intptr_t) udata;
register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing);
+ register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
init_save_userlock();
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
_I("Start Power managing without noti");
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL);
/*
* Lock lcd off until booting is done.
* deviced guarantees all booting script is executing.
unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
+ unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
break;
}
#include <vconf-keys.h>
#include <sys/time.h>
#include <libsyscommon/list.h>
+#include <hal/device/hal-device-power.h>
#include "auto-brightness-sensorhub.h"
#include "ambient-mode.h"
#include "shared/apps.h"
#include "extcon/extcon.h"
#include "battery/power-supply.h"
+#include "power/power.h"
#include "power/power-off.h"
#include "power/power-suspend.h"
#include "power/power-boot.h"
void lcd_on_direct(enum device_flags flags)
{
- int ret;
+ enum hal_device_power_transition_reason reason;
- if (pm_get_power_lock_support()
- && (get_pm_cur_state() == S_SLEEP)) {
- power_acquire_wakelock();
- set_pm_cur_state(S_NORMAL);
- }
+ if (flags & LCD_ON_BY_POWER_KEY)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY;
+ else if (flags & LCD_ON_BY_TOUCH)
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN;
+ else
+ reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
- ret = is_lcdon_blocked();
- if (ret != LCDON_BLOCK_NONE) {
- _W("LCDON is blocked, %d", ret);
- return;
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, NULL);
+ set_pm_cur_state(S_NORMAL);
_D("lcd is on directly");
gettimeofday(&lcdon_tv, NULL);
}
if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ power_get_wakeup_reason(), NULL);
set_setting_pmstate(get_pm_cur_state());
pm_cur_state = get_pm_cur_state();
device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
#ifdef ENABLE_PM_LOG
pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
#endif
- if (pm_get_power_lock_support()) {
- power_enable_autosleep();
-
- if (power_release_wakelock() < 0)
- _E("Power unlock state error.");
- } else {
- pm_suspend();
- _I("system wakeup!!");
- system_wakeup_flag = true;
- /* Resume !! */
- if (check_wakeup_src() == EVENT_DEVICE)
- /* system waked up by devices */
- states[get_pm_cur_state()].trans(EVENT_DEVICE);
- else
- /* system waked up by user input */
- states[get_pm_cur_state()].trans(EVENT_INPUT);
- }
+ power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF);
return 0;
go_lcd_off:
return 0;
}
+static int power_resume_from_echomem_callback(void *data)
+{
+ system_wakeup_flag = true;
+ if (check_wakeup_src() == EVENT_DEVICE)
+ /* system waked up by devices */
+ states[get_pm_cur_state()].trans(EVENT_DEVICE);
+ else
+ /* system waked up by user input */
+ states[get_pm_cur_state()].trans(EVENT_INPUT);
+
+ return 0;
+}
+
static int poweroff_triggered_callback(void *udata)
{
int val = (int)(intptr_t) udata;
register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing);
+ register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
init_save_userlock();
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
_I("Start Power managing without noti");
- if (pm_get_power_lock_support()) {
- power_acquire_wakelock();
- }
+ power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL);
/*
* Lock lcd off until booting is done.
* deviced guarantees all booting script is executing.
unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed);
+ unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
break;
}
#include "vconf.h"
#include "display/display-dpms.h"
#include "display/display.h"
+#include "power.h"
#include "power-boot.h"
#include "power-suspend.h"
bool timeout_sleep_support = false;
+static void (*__power_suspend) (void);
+static void (*__power_resume) (void);
// Leave it for backward compatability. As the signal was implemented when distinction
// between power and display is unclear, path and interface is related with display.
return 0;
}
+static void suspend_echo_mem(void)
+{
+ sys_set_str("/sys/power/state", "mem");
+
+ device_notify(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, NULL);
+
+ // resume
+ update_wakeup_reason();
+ power_request_change_state(DEVICED_POWER_STATE_NORMAL, (int) wakeup_reason);
+}
+
+static void resume_echo_mem(void)
+{
+ // nothing to do
+}
+
+static void suspend_autosleep(void)
+{
+ sys_set_str("/sys/power/wake_unlock", "mainlock");
+}
+
+static void resume_autosleep(void)
+{
+ sys_set_str("/sys/power/wake_lock", "mainlock");
+}
+
+void power_suspend(int reason)
+{
+ if (__power_suspend)
+ __power_suspend();
+}
+
+void power_resume(int reason)
+{
+ if (__power_resume)
+ __power_resume();
+}
+
void power_suspend_init(void)
{
int retval;
retval = config_parse(POWER_CONF_FILE, load_sleep_config, NULL);
if (retval < 0)
_E("Failed to load sleep config: %d", retval);
+
+ if (pm_get_power_lock_support()) {
+ __power_suspend = suspend_autosleep;
+ __power_resume = resume_autosleep;
+ } else {
+ __power_suspend = suspend_echo_mem;
+ __power_resume = resume_echo_mem;
+ }
}
int get_wakeup_count(int *cnt);
int set_wakeup_count(int cnt);
int suspend_other_process(int type);
+void power_suspend(int reason);
+void power_resume(int reason);
void power_suspend_init(void);
#endif /* __DEVICED_POWER_SUSPEND_H__ */
static void power_action_normal(void *udata)
{
- power_acquire_wakelock();
+ power_resume(transition_context.ti.reason);
}
static void power_action_sleep(void *udata)
return;
}
- power_release_wakelock();
+ power_suspend(transition_context.ti.reason);
}
static void power_action_poweroff(void *data)
NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION),
NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE),
NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_LOCK),
- NOTIFY_STR(DEVICE_NOTIFIER_POWER_RESUME),
+ NOTIFY_STR(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM),
NOTIFY_STR(DEVICE_NOTIFIER_POWEROFF_TRIGGERED),
NOTIFY_STR(DEVICE_NOTIFIER_POWEROFF),
NOTIFY_STR(DEVICE_NOTIFIER_APPLICATION_BACKGROUND),
DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION,
DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE,
DEVICE_NOTIFIER_DISPLAY_LOCK,
- DEVICE_NOTIFIER_POWER_RESUME,
+ DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM,
DEVICE_NOTIFIER_POWEROFF_TRIGGERED,
DEVICE_NOTIFIER_POWEROFF,
DEVICE_NOTIFIER_APPLICATION_BACKGROUND,