display: Apply resource-manager for controlling power 98/296598/4
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 1 Aug 2023 09:50:19 +0000 (18:50 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 3 Aug 2023 01:19:54 +0000 (10:19 +0900)
 Previously, controlling power has operated via power functions such as
power_request_change_state(), power_request_change_state_strict(). It
has changed to work via the libsyscommon resource-manager.

Change-Id: I39253c193ccf73e66a6075c4e46e4a1432c501dd
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/display/display-panel.c
src/display/display-state-transition.c
src/display/display.c

index 583b86e..6d7e5b4 100644 (file)
@@ -16,6 +16,9 @@
  * limitations under the License.
  */
 #include <sys/time.h>
+#include <libsyscommon/resource-manager.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
 
 #include "shared/log.h"
 #include "power/power.h"
        (b.tv_sec * 1000000 + b.tv_usec)) \
        / 1000)
 
+#define POWER_RESOURCE_ID              get_power_resource_id()
+
 static bool lcd_paneloff_mode = false;
 static bool lcd_on_broadcasted = true;
 static struct timeval lcd_on_timeval;
 
+static int get_power_resource_id(void)
+{
+       static int resource_id = -1;
+
+       if (resource_id >= 0)
+               return resource_id;
+
+       int ret = syscommon_resman_get_resource_id(DEVICED_RESOURCE_TYPE_POWER, &resource_id);
+       if (ret < 0)
+               return -1;
+       else
+               return resource_id;
+}
+
 /* FIXME: This function is for temporary use, should be fixed after plugin refactoring */
 int display_panel_set_dpms_state(int dpms_on, enum device_flags flags)
 {
@@ -323,7 +342,10 @@ void display_panel_lcd_on_direct(enum device_flags flags)
        else
                reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
 
-       power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, NULL);
+       syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+               DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
+               DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, 0);
+
        set_pm_cur_state(S_NORMAL);
 
        _D("lcd is on directly");
index 260e0ee..4c413d3 100644 (file)
@@ -22,6 +22,9 @@
  */
 
 #include <libsyscommon/common.h>
+#include <libsyscommon/resource-manager.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
 #include "shared/log.h"
 #include "core/udev.h"
 #include "device-interface.h"
@@ -35,6 +38,7 @@
 #include "power/power-suspend.h"
 
 #define ALWAYS_ON_TIMEOUT              360000000
+#define POWER_RESOURCE_ID              get_power_resource_id()
 
 static guint state_transition_timer_id;
 static unsigned int custom_normal_timeout = 0;
@@ -52,6 +56,20 @@ static int trans_table[S_END][EVENT_END] = {
        { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
 };
 
+static int get_power_resource_id(void)
+{
+       static int resource_id = -1;
+
+       if (resource_id >= 0)
+               return resource_id;
+
+       int ret = syscommon_resman_get_resource_id(DEVICED_RESOURCE_TYPE_POWER, &resource_id);
+       if (ret < 0)
+               return -1;
+       else
+               return resource_id;
+}
+
 static bool is_display_state_valid(enum state_t display_state)
 {
        return (display_state >= S_START && display_state < S_END);
@@ -473,8 +491,14 @@ int display_state_transition_do_state_action(int timeout)
        }
 
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
-               power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
-                       power_get_wakeup_reason(), NULL);
+               int wakeup_reason = 0;
+
+               syscommon_resman_get_resource_attr_int(POWER_RESOURCE_ID,
+                       DEVICED_POWER_ATTR_INT_WAKEUP_REASON, &wakeup_reason);
+               syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+                       DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
+                       DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, wakeup_reason, 0);
+
                set_setting_pmstate(get_pm_cur_state());
                pm_cur_state = get_pm_cur_state();
                syscommon_notifier_emit_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
@@ -555,7 +579,11 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT);
+       syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+               DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
+               DEVICED_POWER_STATE_ALL, DEVICED_POWER_STATE_SLEEP,
+               HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT, 0);
+
        return 0;
 
 go_lcd_off:
index 223cb8c..e4620e2 100644 (file)
@@ -19,6 +19,9 @@
 #include <signal.h>
 
 #include <libsyscommon/list.h>
+#include <libsyscommon/resource-manager.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
 #include <shared/devices.h>
 
 #include "core/udev.h"
@@ -38,6 +41,7 @@
 #include "lock-detector.h"
 
 #define DELAYED_INIT_WATING_TIME       60000   /* 1 minute */
+#define POWER_RESOURCE_ID              get_power_resource_id()
 
 static const struct device_ops *display_plugin_device_ops;
 static int pm_cur_state;
@@ -50,6 +54,20 @@ static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT;
 
 extern void init_save_userlock(void);
 
+static int get_power_resource_id(void)
+{
+       static int resource_id = -1;
+
+       if (resource_id >= 0)
+               return resource_id;
+
+       int ret = syscommon_resman_get_resource_id(DEVICED_RESOURCE_TYPE_POWER, &resource_id);
+       if (ret < 0)
+               return -1;
+       else
+               return resource_id;
+}
+
 inline int get_pm_cur_state(void)
 {
        return pm_cur_state;
@@ -593,8 +611,11 @@ static void display_init(void *data)
 
        if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                _I("Start Power managing without noti");
-               power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
-                       HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL);
+               syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+                       DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
+                       DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
+                       HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, 0);
+
                /*
                        * Lock lcd off until booting is done.
                        * deviced guarantees all booting script is executing.