power: apply suspend to ram by echo mem 60/286260/5 accepted/tizen/unified/20230104.172227
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 3 Jan 2023 02:33:31 +0000 (11:33 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 3 Jan 2023 08:14:58 +0000 (08:14 +0000)
Change-Id: Ia68f749de8010ba7fbbb0ae8a29ec8f6d6de7ccf
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/power/power-suspend.c
src/power/power-suspend.h
src/power/power.c
src/shared/device-notifier.c
src/shared/device-notifier.h

index 92dc4e3..bf72a89 100644 (file)
@@ -41,6 +41,7 @@
 #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"
@@ -54,6 +55,7 @@
 #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"
@@ -717,11 +719,17 @@ void set_dim_state(bool on)
 
 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);
@@ -1441,9 +1449,8 @@ static int default_action(int timeout)
        }
 
        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);
@@ -1526,23 +1533,7 @@ go_suspend:
 #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:
@@ -2030,6 +2021,19 @@ static int input_init_handler(void)
        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;
@@ -2112,6 +2116,7 @@ static void display_init(void *data)
        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();
@@ -2178,9 +2183,8 @@ static void display_init(void *data)
 
                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.
@@ -2253,6 +2257,7 @@ static void display_exit(void *data)
                        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;
                }
index 25deced..bcc7488 100644 (file)
@@ -40,6 +40,7 @@
 #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"
@@ -53,6 +54,7 @@
 #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"
@@ -724,11 +726,17 @@ void set_dim_state(bool on)
 
 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);
@@ -1451,9 +1459,8 @@ static int default_action(int timeout)
        }
 
        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);
@@ -1536,23 +1543,7 @@ go_suspend:
 #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:
@@ -2036,6 +2027,19 @@ static int input_init_handler(void)
        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;
@@ -2118,6 +2122,7 @@ static void display_init(void *data)
        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();
@@ -2184,9 +2189,8 @@ static void display_init(void *data)
 
                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.
@@ -2259,6 +2263,7 @@ static void display_exit(void *data)
                        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;
                }
index 333d3b3..d51dcf7 100644 (file)
@@ -40,6 +40,7 @@
 #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"
@@ -53,6 +54,7 @@
 #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"
@@ -717,11 +719,17 @@ void set_dim_state(bool on)
 
 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);
@@ -1441,9 +1449,8 @@ static int default_action(int timeout)
        }
 
        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);
@@ -1526,23 +1533,7 @@ go_suspend:
 #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:
@@ -2027,6 +2018,19 @@ static int input_init_handler(void)
        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;
@@ -2109,6 +2113,7 @@ static void display_init(void *data)
        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();
@@ -2175,9 +2180,8 @@ static void display_init(void *data)
 
                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.
@@ -2250,6 +2254,7 @@ static void display_exit(void *data)
                        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;
                }
index baa1784..c3916b1 100644 (file)
@@ -40,6 +40,7 @@
 #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"
@@ -54,6 +55,7 @@
 #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"
@@ -935,19 +937,17 @@ void set_dim_state(bool on)
 
 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);
@@ -1717,9 +1717,8 @@ static int default_action(int timeout)
        }
 
        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);
@@ -1805,23 +1804,7 @@ go_suspend:
 #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:
@@ -2322,6 +2305,19 @@ static int input_init_handler(void)
        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;
@@ -2442,6 +2438,7 @@ static void display_init(void *data)
        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();
@@ -2508,9 +2505,8 @@ static void display_init(void *data)
 
                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.
@@ -2584,6 +2580,7 @@ static void display_exit(void *data)
                        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;
                }
index 0888af4..39866a6 100644 (file)
@@ -40,6 +40,7 @@
 #include "vconf.h"
 #include "display/display-dpms.h"
 #include "display/display.h"
+#include "power.h"
 #include "power-boot.h"
 #include "power-suspend.h"
 
@@ -70,6 +71,8 @@ static const char history_string[PM_LOG_MAX][15] = {
 
 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.
@@ -390,6 +393,44 @@ static int load_sleep_config(struct parse_result *result, void *user_data)
        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;
@@ -397,4 +438,12 @@ void power_suspend_init(void)
        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;
+       }
 }
index 16a02e3..0c629e6 100644 (file)
@@ -87,5 +87,7 @@ int check_wakeup_src(void);
 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__ */
index 42e0da3..4b60308 100644 (file)
@@ -255,7 +255,7 @@ static uint64_t alloc_unique_id(void)
 
 static void power_action_normal(void *udata)
 {
-       power_acquire_wakelock();
+       power_resume(transition_context.ti.reason);
 }
 
 static void power_action_sleep(void *udata)
@@ -266,7 +266,7 @@ static void power_action_sleep(void *udata)
                return;
        }
 
-       power_release_wakelock();
+       power_suspend(transition_context.ti.reason);
 }
 
 static void power_action_poweroff(void *data)
index e9190d6..dc4da09 100644 (file)
@@ -68,7 +68,7 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = {
        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),
index 2dabc45..3d3c5ec 100644 (file)
@@ -40,7 +40,7 @@ enum device_notifier_type {
        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,