display: power: Replace common code with the libsyscommon 86/296886/3
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 4 Aug 2023 05:32:05 +0000 (14:32 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 9 Aug 2023 08:59:20 +0000 (17:59 +0900)
Change-Id: I7baf001d4d03ef675465b821d564cae3958055ca
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/display/display-panel.c
src/display/display-state-transition.c
src/display/display.c
src/power/resource-power.c

index 6d7e5b4..32a8b01 100644 (file)
        (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)
 {
@@ -342,7 +326,7 @@ void display_panel_lcd_on_direct(enum device_flags flags)
        else
                reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
 
-       syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+       syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
                DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, reason, 0);
 
index 4c413d3..79c0b98 100644 (file)
@@ -38,7 +38,6 @@
 #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;
@@ -56,20 +55,6 @@ 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);
@@ -493,9 +478,9 @@ int display_state_transition_do_state_action(int timeout)
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
                int wakeup_reason = 0;
 
-               syscommon_resman_get_resource_attr_int(POWER_RESOURCE_ID,
+               syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                        DEVICED_POWER_ATTR_INT_WAKEUP_REASON, &wakeup_reason);
-               syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+               syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                        DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
                        DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, wakeup_reason, 0);
 
@@ -579,7 +564,7 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+       syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                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);
index e4620e2..dd2a599 100644 (file)
@@ -41,7 +41,6 @@
 #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;
@@ -54,20 +53,6 @@ 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;
@@ -611,7 +596,7 @@ static void display_init(void *data)
 
        if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                _I("Start Power managing without noti");
-               syscommon_resman_set_resource_attr_uint64_4(POWER_RESOURCE_ID,
+               syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                        DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
                        DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL,
                        HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, 0);
index 3951008..ffa13d3 100644 (file)
 #include "power.h"
 #include "power-suspend.h"
 
-static bool attr_always_supported(int resource_id, const struct syscommon_resman_resource_attribute *attr)
-{
-       return true;
-}
-
 static int set_current_state(int resource_id, const struct syscommon_resman_resource_attribute *attr,
        const void *data1, const void *data2, const void *data3, const void *data4,
        int count1, int count2, int count3, int count4)
@@ -86,7 +81,7 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
                .ops = {
                        .set_4_tuple = set_current_state,
-                       .is_supported = attr_always_supported,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
                },
        }, {
                .name = "DEVICED_POWER_ATTR_UINT64_CURRENT_STATE",
@@ -95,7 +90,7 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
                .ops = {
                        .get = get_current_state,
-                       .is_supported = attr_always_supported,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
                },
        }, {
                .name = "DEVICED_POWER_ATTR_INT_WAKEUP_REASON",
@@ -104,7 +99,7 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
                .ops = {
                        .get = get_wakeup_reason,
-                       .is_supported = attr_always_supported,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
                },
        }
 };