From 7ef286fc30235c93342626b9dd854e2178f55ad7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 8 Feb 2023 18:17:17 +0900 Subject: [PATCH 01/16] power: separate action_for_state() callback Separated the callback action_for_state() into two type - pre_action_state() - post_action_state() Literally, it only differs when the time it is invoked based on completing transition, one is before and the other is after finishing transition. It is necessary for echo mem. Previously, the action_for_state() always invoked 'right before' transition completion. As it is echo mem, system is forced to go suspend within the action_for_state() callback. After resuming from the suspend, the processing thread still be in the action_for_state(), which is still not having completed sleep transition. As a result, a system is waking up but the internal power state is about to be changed to sleep state. This is contradiction and causes various undesirable behavior. To address it, move echo mem to post_action_state(). Unlike the previous action_for_state(), the post_action_state() is invoked 'after' the completion of transition. That is, it is natural that waking up within the post_action_state() as it already has been finished sleep transition. Thus it won't change the internal state to sleep anymore. Change-Id: I49e12a19538bdb4241cba34fd536c942257ccaec Signed-off-by: Youngjae Cho --- src/power/power-suspend.c | 2 +- src/power/power.c | 97 +++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/power/power-suspend.c b/src/power/power-suspend.c index d475305..ff4b606 100644 --- a/src/power/power-suspend.c +++ b/src/power/power-suspend.c @@ -381,7 +381,6 @@ static void suspend_echo_mem(void) update_wakeup_reason(); device_notify(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, NULL); - power_request_change_state(DEVICED_POWER_STATE_NORMAL, (int) wakeup_reason); /* * FIXME: If the wakeup reason lingers after wakeup, a transition triggered from other * than the above line would take the lingering wakeup reason as a transition reason, @@ -391,6 +390,7 @@ static void suspend_echo_mem(void) * the transition is requested, not the time when it is executed. If then, the below resetting * line can be removed. */ + power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, (int) wakeup_reason, NULL); wakeup_reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN; } diff --git a/src/power/power.c b/src/power/power.c index 906ad61..8bd0b28 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -105,17 +105,25 @@ static void prepare_transition(const struct trans_info *ti); static void action_transition(void); static uint64_t get_next_state(void); -static void action_for_normal(void *data); -static void action_for_sleep(void *data); -static void action_for_poweroff(void *data); -static void (*const action_for_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = { - [DEVICED_POWER_STATE_NORMAL_INDEX] = action_for_normal, - [DEVICED_POWER_STATE_SLEEP_INDEX] = action_for_sleep, - [DEVICED_POWER_STATE_POWEROFF_INDEX] = action_for_poweroff, - [DEVICED_POWER_STATE_REBOOT_INDEX] = action_for_poweroff, - [DEVICED_POWER_STATE_EXIT_INDEX] = action_for_poweroff, +static void pre_action_normal(void *data); +static void pre_action_poweroff(void *data); +static void (*const pre_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = { + [DEVICED_POWER_STATE_NORMAL_INDEX] = pre_action_normal, + [DEVICED_POWER_STATE_POWEROFF_INDEX] = pre_action_poweroff, + [DEVICED_POWER_STATE_REBOOT_INDEX] = pre_action_poweroff, + [DEVICED_POWER_STATE_EXIT_INDEX] = pre_action_poweroff, }; +static void post_action_sleep(void *data); +static void post_action_poweroff(void *data); +static void (*const post_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = { + [DEVICED_POWER_STATE_SLEEP_INDEX] = post_action_sleep, + [DEVICED_POWER_STATE_POWEROFF_INDEX] = post_action_poweroff, + [DEVICED_POWER_STATE_REBOOT_INDEX] = post_action_poweroff, + [DEVICED_POWER_STATE_EXIT_INDEX] = post_action_poweroff, +}; + + uint64_t power_get_state(void) { return current; @@ -281,22 +289,25 @@ static uint64_t alloc_unique_id(void) return ++id; } -static void action_for_normal(void *udata) +static void pre_action_normal(void *udata) { power_resume(transition_context.ti.reason); } -static void action_for_sleep(void *udata) +static void post_action_sleep(void *udata) { power_suspend(transition_context.ti.reason); } -static void action_for_poweroff(void *data) +static void pre_action_poweroff(void *data) { // do not transition anymore after poweroff unregister_notifier(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, transition_request_callback); - poweroff_prepare(current); +} + +static void post_action_poweroff(void *data) +{ poweroff_main((void *)(intptr_t) current); } @@ -621,36 +632,48 @@ static void cancel_transition(void) static void action_transition(void) { uint64_t state = get_next_state(); + struct trans_info ti = { 0 , }; + int retval; + int index; transition_description(0); - if (state == transition_context.ti.next) { - // it has reached the destination state - struct trans_info ti = { 0 , }; - int retval; - int index; - - index = DEVICED_POWER_STATE_INDEX(transition_context.ti.next); - if (transition_context.cancel) - cancel_transition(); - else if (action_for_state[index]) - action_for_state[index](transition_context.ti.data); - - // transition end - transition_context.ongoing = 0; - current = transition_context.ti.next; - event_wake_unlock(EL_POWER_TRANSITION_STATE); - - // trigger next transition if exist - retval = dequeue_transition(&ti); - if (retval == 0) { - prepare_transition(&ti); - trigger_transition(); - } - } else { + if (state != transition_context.ti.next) { // step into the next transient state ++transition_context.transient_step; trigger_transition(); + return; + } + + /* it reached the destination state */ + index = DEVICED_POWER_STATE_INDEX(transition_context.ti.next); + if (transition_context.cancel) { + cancel_transition(); + goto trigger_next; + } + + if (pre_action_state[index]) + pre_action_state[index](transition_context.ti.data); + + current = transition_context.ti.next; + + if (post_action_state[index]) + post_action_state[index](transition_context.ti.data); + + /** + * transition_context.ongiong must be reset after the post_action_state(). + * This prevents the post_action_state() from triggering another transition + * that might have been requested during its execution. Transition will be + * enqueued, not executed, if transition_context.ongoing is 1. + */ + transition_context.ongoing = 0; + event_wake_unlock(EL_POWER_TRANSITION_STATE); + +trigger_next: + retval = dequeue_transition(&ti); + if (retval == 0) { + prepare_transition(&ti); + trigger_transition(); } } -- 2.7.4 From 971493207a7ba5f643afcd5d11eb7acc3f9d3759 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 8 Feb 2023 18:50:34 +0900 Subject: [PATCH 02/16] power: add transient scenario from START to SLEEP Transient scenario for suspending from START to SLEEP has been added. DEVICED_POWER_STATE_START | V DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_EARLY | V DEVICED_POWER_TRANSIENT_STATE_SUSPENDING | V DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_LATE | V DEVICED_POWER_STATE_SLEEP Change-Id: I814defb0245e94302746918fa5392ed3a08c64b3 Signed-off-by: Youngjae Cho --- src/power/power.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/power/power.c b/src/power/power.c index 8bd0b28..58a1e83 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -90,6 +90,10 @@ static const struct { int max_step; const uint64_t *scenario; } transient[DEVICED_POWER_STATE_MAX_INDEX][DEVICED_POWER_STATE_MAX_INDEX] = { + [DEVICED_POWER_STATE_START_INDEX][DEVICED_POWER_STATE_SLEEP_INDEX] = { + .max_step = ARRAY_SIZE(transient_scenario_suspending), + .scenario = transient_scenario_suspending, + }, [DEVICED_POWER_STATE_NORMAL_INDEX][DEVICED_POWER_STATE_SLEEP_INDEX] = { .max_step = ARRAY_SIZE(transient_scenario_suspending), .scenario = transient_scenario_suspending, -- 2.7.4 From eaf497a3ba352347fa41c1e30ebac125a4f213cd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 9 Feb 2023 11:33:52 +0900 Subject: [PATCH 03/16] power: skip echo mem if there is pending transition For echo mem, there could be some pending transitions when it comes to enter suspend. This is because transition is asynchronously processed. That is, if there were another transition request during a sleep transition, the sleep transition should be skipped and take the next transition immediately. Otherwise, the next transition will handled after wakeup, which is indefinite. Change-Id: Ia09a1d1162e21710538f6e9ce7bd1fb3e9c43d0f Signed-off-by: Youngjae Cho --- src/power/power-suspend.c | 12 ++++++++++++ src/power/power.c | 5 +++++ src/power/power.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/power/power-suspend.c b/src/power/power-suspend.c index ff4b606..efd6ccd 100644 --- a/src/power/power-suspend.c +++ b/src/power/power-suspend.c @@ -375,6 +375,18 @@ static int load_sleep_config(struct parse_result *result, void *user_data) static void suspend_echo_mem(void) { + if (is_there_pending_transition()) { + /** + * For echo mem, there could be some pending transitions at this point because + * transition is aynchronous. That is, if there were another transition request + * during a sleep transition, the sleep transition should be skipped and take + * the next transition immediately. Otherwise, the next transition will handled + * after wakeup, which is indefinite. + */ + _D("Skip echo mem, trigger next transition immediately."); + return; + } + sys_set_str("/sys/power/state", "mem"); // resume diff --git a/src/power/power.c b/src/power/power.c index 58a1e83..1ed50fc 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -362,6 +362,11 @@ static void broadcast_transition_info(void) transition_context.ti.reason)); } +int is_there_pending_transition(void) +{ + return (g_queue_peek_tail(transition_queue) != NULL); +} + static uint64_t available_starting_state(void) { struct trans_info *ti = NULL; diff --git a/src/power/power.h b/src/power/power.h index 8de8bb7..ea5190c 100644 --- a/src/power/power.h +++ b/src/power/power.h @@ -150,6 +150,7 @@ static inline void power_request_change_state(uint64_t next, int reason) uint64_t power_get_state(void); int add_change_state_wait(pid_t pid, guint64 state); +int is_there_pending_transition(void); void remove_change_state_wait(pid_t pid, guint64 state); int confirm_change_state_wait(pid_t pid, guint64 transition_id); int cancel_change_state_wait(pid_t pid, guint64 transition_id); -- 2.7.4 From 918acdfef05bde8242672031c7c10430a1e6c165 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 14 Feb 2023 10:11:34 +0900 Subject: [PATCH 04/16] display: change sleep reason to DISPLAY_OFF_TIMEOUT Technically, the sleep request of display plugin is triggered by timer, not by display off itself. 1. Display off, display state is changed to S_LCDOFF. 2. Start timer, 300ms. 3. On expiring the timer, display state is changed to S_SLEEP. 4. The display plugin requests power module to change its state to DEVICED_POWER_STATE_SLEEP. Therefore, it is proper to use enum DISPLAY_OFF_TIMEOUT instead of just DISPLAY_OFF. Change-Id: I93e6d092ebcc23e09db61f65d8f0b7e4dc5aac7e Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/wearable/display/core.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 2b7aa60..8e2fd12 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -1534,7 +1534,7 @@ 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); + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); return 0; go_lcd_off: diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 11fe205..9078ff4 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1544,7 +1544,7 @@ 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); + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); return 0; go_lcd_off: diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 444f02c..90f4e67 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1534,7 +1534,7 @@ 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); + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); return 0; go_lcd_off: diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 958b19a..3947491 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1805,7 +1805,7 @@ 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); + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); return 0; go_lcd_off: -- 2.7.4 From 212245d8c9b1bf1b9a22782ef8f97879eec7bac3 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 16 Feb 2023 14:32:53 +0900 Subject: [PATCH 05/16] display: Add display hal-backend check function Before plugin to core centralization, display hal backend check is needed. To move functions without plugin dependency, this temporary function is necessary. With this, plugin functions can be moved to core(deviced/src/display module). These functions will be modified during plugin to core centralization. void display_set_hal_backend_available(bool display_check_hal_backend) -> With this, while plugin probing, deviced core can know whether hal_backend is available or not. bool display_check_hal_backend_available(void) -> This function is for replacing the display_dev_available variable of plugins. Change-Id: I1e926da29ab097e08533f73136a2f928daca9167 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/device-interface.c | 2 ++ plugins/mobile/display/device-interface.c | 2 ++ plugins/tv/display/device-interface.c | 2 ++ plugins/wearable/display/device-interface.c | 2 ++ src/display/display.c | 13 +++++++++++++ src/display/display.h | 2 ++ 6 files changed, 23 insertions(+) diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index f07018d..c6bf212 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -875,10 +875,12 @@ int display_service_load(void) if (r < 0) { _E("There is no HAL for display."); display_dev_available = false; + display_set_hal_backend_available(display_dev_available); return 0; } display_dev_available = true; + display_set_hal_backend_available(display_dev_available); _D("Display device structure load success."); return 0; } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 1c3c8dd..14c5fd5 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -874,10 +874,12 @@ int display_service_load(void) if (r < 0) { _E("There is no HAL for display."); display_dev_available = false; + display_set_hal_backend_available(display_dev_available); return 0; } display_dev_available = true; + display_set_hal_backend_available(display_dev_available); _D("Display device structure load success."); return 0; } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index a5500ca..ad11487 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -875,10 +875,12 @@ int display_service_load(void) if (r < 0) { _E("There is no HAL for display."); display_dev_available = false; + display_set_hal_backend_available(display_dev_available); return 0; } display_dev_available = true; + display_set_hal_backend_available(display_dev_available); _D("Display device structure load success."); return 0; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index cb77833..d9fe84f 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -942,10 +942,12 @@ int display_service_load(void) if (r < 0) { _E("There is no HAL for display."); display_dev_available = false; + display_set_hal_backend_available(display_dev_available); return 0; } display_dev_available = true; + display_set_hal_backend_available(display_dev_available); _D("Display device structure load success."); return 0; } diff --git a/src/display/display.c b/src/display/display.c index ec81997..7885ea6 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -31,6 +31,7 @@ static int pm_cur_state; static int pm_old_state; static unsigned int pm_status_flag; static enum display_init_direction_e g_display_init_direction; +static bool g_display_hal_backend_available; inline int get_pm_cur_state(void) { @@ -172,3 +173,15 @@ int display_load_config(struct parse_result *result, void *user_data) return 0; } + +/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ +void display_set_hal_backend_available(bool display_hal_backend_available) +{ + g_display_hal_backend_available = display_hal_backend_available; +} + +/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ +bool display_is_hal_backend_available(void) +{ + return g_display_hal_backend_available; +} \ No newline at end of file diff --git a/src/display/display.h b/src/display/display.h index 0ecfac5..289b0d0 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -34,6 +34,8 @@ void clear_pm_status_flag(unsigned int status_flag); enum display_init_direction_e get_display_init_direction(void); void set_display_init_direction(enum display_init_direction_e display_init_direction); int display_load_config(struct parse_result *result, void *user_data); +void display_set_hal_backend_available(bool display_hal_backend_available); +bool display_is_hal_backend_available(void); enum brightness_request_e { BR_MIN = 0, -- 2.7.4 From 5163517997cc4566ceb390fd842b5f227ad3b4b3 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 16 Feb 2023 15:16:07 +0900 Subject: [PATCH 06/16] display: Move white_balance_ops functions from plugins to core display module Remove and redefine functions related to display white balance work. Because white balancing is common for display. Thus, these functions are added below display-panel. int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value) int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, int* out_val) -> With hal_display_white_balance enum type, it is possible to get and set white_balance values. Change-Id: I10213315d109e47f0e8c3a58382648ccef3ca2d1 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 5 -- plugins/iot-headed/display/device-interface.c | 87 ------------------------ plugins/mobile/display/core.c | 5 -- plugins/mobile/display/device-interface.c | 87 ------------------------ plugins/tv/display/core.c | 5 -- plugins/tv/display/device-interface.c | 87 ------------------------ plugins/wearable/display/core.c | 5 -- plugins/wearable/display/device-interface.c | 87 ------------------------ src/display/device-interface.h | 7 -- src/display/display-dbus.c | 10 +-- src/display/display-panel.c | 95 +++++++++++++++++++++++++++ src/display/display-panel.h | 27 ++++++++ 12 files changed, 125 insertions(+), 382 deletions(-) create mode 100644 src/display/display-panel.c create mode 100644 src/display/display-panel.h diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 8e2fd12..0a87e47 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -91,7 +91,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); static void (*power_saving_func) (int onoff); @@ -2352,10 +2351,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index c6bf212..ecb5eb2 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -55,11 +55,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -74,7 +69,6 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -89,11 +83,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -750,77 +739,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -859,11 +777,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 9078ff4..7948278 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -92,7 +92,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2363,10 +2362,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 14c5fd5..cef8002 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -56,11 +56,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -73,7 +68,6 @@ #define UNKNOWN_STR "unknown" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -88,11 +82,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -749,77 +738,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -858,11 +776,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 90f4e67..f9655cd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -90,7 +90,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2349,10 +2348,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index ad11487..8c1cd1c 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -55,11 +55,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -74,7 +69,6 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -89,11 +83,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -750,77 +739,6 @@ static void release_blink(void) release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static void restore_brightness_func(void) { backlight_ops.set_brightness = set_brightness; @@ -859,11 +777,6 @@ static struct _backlight_ops backlight_ops = { .release_blink = release_blink, }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3947491..293206d 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -101,7 +101,6 @@ extern void init_save_userlock(void); static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct battery_plugin *battery_plgn; static int (*fp_get_charging_status) (int *val); @@ -2680,10 +2679,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - battery_plgn = get_var_battery_plugin(); if (!battery_plgn) _E("Failed to get battery plugin variable."); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index d9fe84f..9689dd0 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -58,11 +58,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define MAX_WHITE_BALANCE_GAIN 2047 -#define MAX_WHITE_BALANCE_OFFSET 2047 -#define DEFAULT_WHITE_BALANCE_GAIN 1024 -#define DEFAULT_WHITE_BALANCE_OFFSET 0 - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -79,7 +74,6 @@ static struct _backlight_ops backlight_ops; -static struct _display_white_balance_ops display_white_balance_ops; static struct battery_plugin *battery_plgn; static bool custom_status; static int custom_brightness; @@ -101,11 +95,6 @@ inline struct _backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -inline struct _display_white_balance_ops *get_var_display_white_balance_ops(void) -{ - return &display_white_balance_ops; -} - bool display_dev_ready(void) { return display_dev_available; @@ -822,77 +811,6 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static int set_white_balance(enum hal_display_white_balance white_balance_type, int value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - if (value > MAX_WHITE_BALANCE_GAIN) - value = DEFAULT_WHITE_BALANCE_GAIN; - break; - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - if (value > MAX_WHITE_BALANCE_OFFSET) - value = DEFAULT_WHITE_BALANCE_OFFSET; - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_set_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Set white balance is not supported."); - else - _E("Failed to set white balance value."); - } - - return ret; -} - -static int get_white_balance(enum hal_display_white_balance white_balance_type, int* value) -{ - int ret = 0; - - if (!display_dev_available) { - _E("There is no display device."); - return -ENOENT; - } - - switch (white_balance_type) { - case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: - case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: - case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: - break; - default: - _E("Unknown white balance type"); - return -EINVAL; - } - - ret = hal_device_display_get_white_balance(white_balance_type, value); - if (ret < 0) { - if (ret == -ENODEV) - _E("Get white balance is not supported."); - else - _E("Failed to get white balance value."); - } - - return ret; -} - static struct _backlight_ops backlight_ops = { .off = backlight_off, .dim = backlight_dim, @@ -926,11 +844,6 @@ static struct _backlight_ops backlight_ops = { .get_brightness_raw = get_brightness, /* always fetch brightness from node even LBM mode */ }; -static struct _display_white_balance_ops display_white_balance_ops = { - .set_white_balance = set_white_balance, - .get_white_balance = get_white_balance, -}; - int display_service_load(void) { int r; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 56b41e4..759ff50 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -94,13 +94,6 @@ struct _backlight_ops { struct _backlight_ops *get_var_backlight_ops(void); -struct _display_white_balance_ops { - int (*set_white_balance)(enum hal_display_white_balance white_balance_type, int value); - int (*get_white_balance)(enum hal_display_white_balance white_balance_type, int* out_val); -}; - -struct _display_white_balance_ops *get_var_display_white_balance_ops(void); - enum dpms_state { DPMS_ON, /* In use */ DPMS_STANDBY, /* Blanked, low power */ diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index c181d0f..5c92a43 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -44,6 +44,7 @@ #include "display.h" #include "shared/plugin.h" #include "display-lock.h" +#include "display-panel.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -72,7 +73,6 @@ static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct _display_white_balance_ops *display_white_balance_ops; static struct display_config *display_conf; static GVariant *dbus_start(GDBusConnection *conn, @@ -1210,7 +1210,7 @@ static GVariant *dbus_setwhitebalance(GDBusConnection *conn, g_variant_get(param, "(ii)", &white_balance_type, &value); - ret_val = display_white_balance_ops->set_white_balance(white_balance_type, value); + ret_val = display_panel_set_white_balance(white_balance_type, value); if (ret_val < 0) { _E("Failed to set white balance"); ret = -EPERM; @@ -1232,7 +1232,7 @@ static GVariant *dbus_getwhitebalance(GDBusConnection *conn, g_variant_get(param, "(i)", &white_balance_type); - ret = display_white_balance_ops->get_white_balance(white_balance_type, &ret_val); + ret = display_panel_get_white_balance(white_balance_type, &ret_val); if (ret < 0) { _E("Failed to get white balance"); ret = -EPERM; @@ -1474,10 +1474,6 @@ static void __CONSTRUCTOR__ initialize(void) if (!backlight_ops) _E("Failed to get backlight operator variable."); - display_white_balance_ops = get_var_display_white_balance_ops(); - if (!display_white_balance_ops) - _E("Failed to get display white balance operator variable."); - display_conf = get_var_display_config(); if (!display_conf) _E("Failed to get display configuration variable."); diff --git a/src/display/display-panel.c b/src/display/display-panel.c new file mode 100644 index 0000000..9d65416 --- /dev/null +++ b/src/display/display-panel.c @@ -0,0 +1,95 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "shared/log.h" +#include "display-panel.h" +#include "display.h" + +#define MAX_WHITE_BALANCE_GAIN 2047 +#define MAX_WHITE_BALANCE_OFFSET 2047 +#define DEFAULT_WHITE_BALANCE_GAIN 1024 +#define DEFAULT_WHITE_BALANCE_OFFSET 0 + +int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, + int value) +{ + int ret = 0; + + if (!display_is_hal_backend_available()) { + _E("There is no display device."); + return -ENOENT; + } + + switch (white_balance_type) { + case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: + if (value > MAX_WHITE_BALANCE_GAIN) + value = DEFAULT_WHITE_BALANCE_GAIN; + break; + case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: + if (value > MAX_WHITE_BALANCE_OFFSET) + value = DEFAULT_WHITE_BALANCE_OFFSET; + break; + default: + _E("Unknown white balance type"); + return -EINVAL; + } + + ret = hal_device_display_set_white_balance(white_balance_type, value); + if (ret == -ENODEV) + _E("Set white balance is not supported."); + else if (ret < 0) + _E("Failed to set white balance value."); + + return ret; +} + +int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, + int* value) +{ + int ret = 0; + + if (!display_is_hal_backend_available()) { + _E("There is no display device."); + return -ENOENT; + } + + switch (white_balance_type) { + case HAL_DISPLAY_WHITE_BALANCE_R_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_G_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_B_GAIN: + case HAL_DISPLAY_WHITE_BALANCE_R_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_G_OFFSET: + case HAL_DISPLAY_WHITE_BALANCE_B_OFFSET: + break; + default: + _E("Unknown white balance type"); + return -EINVAL; + } + + ret = hal_device_display_get_white_balance(white_balance_type, value); + if (ret == -ENODEV) + _E("Get white balance is not supported."); + else if (ret < 0) + _E("Failed to get white balance value."); + + return ret; +} \ No newline at end of file diff --git a/src/display/display-panel.h b/src/display/display-panel.h new file mode 100644 index 0000000..efe6e45 --- /dev/null +++ b/src/display/display-panel.h @@ -0,0 +1,27 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DISPLAY_PANEL_H__ +#define __DISPLAY_PANEL_H__ + +#include + +int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value); +int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, int* out_val); + +#endif /* __DISPLAY_PANEL_H__ */ \ No newline at end of file -- 2.7.4 From e1ec4835d05d9a0cf6e8dd2cca00925c73484a1f Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Wed, 15 Feb 2023 17:22:26 +0900 Subject: [PATCH 07/16] display: Change get_var_display_config return type to const To prevent modify display config static struct in other file. If it wanted to be modified later, setter will have to be added. Change-Id: I477fc8476981f18d92509dfb6b2c0783cc7df734 Signed-off-by: TaeminYeom --- plugins/iot-headed/display/core.c | 2 +- plugins/iot-headed/display/device-interface.c | 2 +- plugins/iot-headed/display/key-filter.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/device-interface.c | 2 +- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/tv/display/device-interface.c | 2 +- plugins/tv/display/key-filter.c | 2 +- plugins/wearable/display/auto-brightness-sensorhub.c | 2 +- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/device-interface.c | 2 +- plugins/wearable/display/key-filter.c | 2 +- src/display/auto-brightness.c | 2 +- src/display/core.h | 2 +- src/display/display-dbus.c | 2 +- src/display/display-input.c | 2 +- src/display/display-lock.c | 2 +- src/display/setting.c | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 0a87e47..47e7e01 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -210,7 +210,7 @@ struct display_function_info display_info = { .face_detection = NULL, }; -inline struct display_config* get_var_display_config() +inline const struct display_config* get_var_display_config() { return &display_conf; } diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index ecb5eb2..188f583 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -76,7 +76,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; -static struct display_config *display_conf; +static const struct display_config *display_conf; inline struct _backlight_ops *get_var_backlight_ops(void) { diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index db9a338..7b75ac7 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -430,7 +430,7 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if (!display_conf) { _E("Failed to get display configuration variable."); return ignore; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 7948278..4927f70 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -212,7 +212,7 @@ struct display_function_info display_info = { .face_detection = NULL, }; -inline struct display_config* get_var_display_config() +inline const struct display_config* get_var_display_config() { return &display_conf; } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index cef8002..d7d79db 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -75,7 +75,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; -static struct display_config *display_conf; +static const struct display_config *display_conf; inline struct _backlight_ops *get_var_backlight_ops(void) { diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 1e56db1..b8fb9ca 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -449,7 +449,7 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if (!display_conf) { _E("Failed to get display configuration variable."); return ignore; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index f9655cd..a596b62 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -210,7 +210,7 @@ struct display_function_info display_info = { .face_detection = NULL, }; -inline struct display_config* get_var_display_config() +inline const struct display_config* get_var_display_config() { return &display_conf; } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 8c1cd1c..128b637 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -76,7 +76,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static bool display_dev_available = false; static guint release_timer; -static struct display_config *display_conf; +static const struct display_config *display_conf; inline struct _backlight_ops *get_var_backlight_ops(void) { diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 42851ce..e3b3cdf 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -430,7 +430,7 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if(!display_conf) { _E("Failed to get display configuration variable."); return ignore; diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 9eda1a1..51950bf 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -43,7 +43,7 @@ static bool lbm, hbm, hold_brt, lowdim; static void change_brightness_transit(int start, int end) { - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if(!display_conf) { _E("Failed to get display configuration variable."); return ; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 293206d..de4d504 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -235,7 +235,7 @@ struct display_function_info display_info = { .face_detection = NULL, }; -inline struct display_config *get_var_display_config() +inline const struct display_config *get_var_display_config() { return &display_conf; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 9689dd0..4683490 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -86,7 +86,7 @@ static int aod_max_level = -1; static int aod_normal_level = -1; static int aod_min_level = -1; static int aod_charging_level = -1; -static struct display_config *display_conf; +static const struct display_config *display_conf; static struct battery_status *battery = NULL; static struct battery_status* (*fp_get_var_battery_status)(void); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index ab4b47c..65ba5ab 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -426,7 +426,7 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if (!display_conf) { _E("Failed to get display configuration variable."); return ignore; diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 9b00ecf..d7a740d 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -73,7 +73,7 @@ static char *min_brightness_name = 0; /* light sensor */ static float lmax, lmin; -static struct display_config *display_conf; +static const struct display_config *display_conf; static bool update_working_position(void) { diff --git a/src/display/core.h b/src/display/core.h index fb52ede..34b6c94 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -127,7 +127,7 @@ struct display_config { * Global variables * display_conf : configuration of display */ -struct display_config* get_var_display_config(); +const struct display_config* get_var_display_config(); /* * @brief Display Extension features diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 5c92a43..19c30f2 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -73,7 +73,7 @@ static struct display_plugin *disp_plgn; static struct _backlight_ops *backlight_ops; -static struct display_config *display_conf; +static const struct display_config *display_conf; static GVariant *dbus_start(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, diff --git a/src/display/display-input.c b/src/display/display-input.c index 05fcde6..df63a54 100644 --- a/src/display/display-input.c +++ b/src/display/display-input.c @@ -38,7 +38,7 @@ static void process_input(struct libinput_event *ev) struct libinput_event_keyboard *k; unsigned int time; int fd = 0; - struct display_config *display_conf = get_var_display_config(); + const struct display_config *display_conf = get_var_display_config(); if(!display_conf) { _E("Failed to get display configuration variable."); return; diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 265fd09..bfdd7e9 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -42,7 +42,7 @@ static struct _backlight_ops *backlight_ops; static GList *cond_head[S_END]; static int trans_condition; -static struct display_config *display_conf; +static const struct display_config *display_conf; bool check_lock_state(int state) { diff --git a/src/display/setting.c b/src/display/setting.c index 0b0ebb2..cc695ff 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -48,7 +48,7 @@ static int force_lcdtimeout = 0; static int custom_on_timeout = 0; static int custom_normal_timeout = 0; static int custom_dim_timeout = 0; -static struct display_config *display_conf; +static const struct display_config *display_conf; int (*update_pm_setting) (int key_idx, int val); -- 2.7.4 From e40ed08ddd42dfca6f7bc3c9cbf9dbc3dcbb0a79 Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Wed, 15 Feb 2023 12:00:27 +0900 Subject: [PATCH 08/16] display: Change DPMS init and exit fucntion name For consistent naming rule with other DPMS function, change the names. init_dpms -> dpms_init exit_dpms -> dpms_exit add_timer_for_init_dpms -> add_timer_for_dpms_init delayed_init_done_dpms -> delayed_dpms_init_done Change-Id: I1de2c9741526238d33c03e815f2ff73fa2a13f9f Signed-off-by: TaeminYeom --- plugins/iot-headed/display/core.c | 14 +++++++------- plugins/iot-headed/display/device-interface.c | 2 +- plugins/mobile/display/core.c | 14 +++++++------- plugins/mobile/display/device-interface.c | 2 +- plugins/tv/display/core.c | 14 +++++++------- plugins/tv/display/device-interface.c | 2 +- plugins/wearable/display/core.c | 14 +++++++------- plugins/wearable/display/device-interface.c | 2 +- src/display/display-dpms.c | 10 +++++----- src/display/display-dpms.h | 4 ++-- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 47e7e01..6952ccc 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -1940,11 +1940,11 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_done_dpms(gpointer data) +static gboolean delayed_dpms_init_done(gpointer data) { int timeout; - if (!init_dpms()) + if (!dpms_init()) return G_SOURCE_CONTINUE; switch (get_pm_cur_state()) { @@ -1971,11 +1971,11 @@ static gboolean delayed_init_done_dpms(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_init_dpms(void) +static void add_timer_for_dpms_init(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_dpms_init_done, NULL); if (id == 0) - _E("Failed to add init_dpms timeout."); + _E("Failed to add dpms_init timeout."); } /** @@ -2167,13 +2167,13 @@ static void display_init(void *data) * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ // wm_ready = check_wm_ready(); - if (init_dpms()) { + if (dpms_init()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) lcd_off_procedure(LCD_OFF_BY_EVENT); else lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { - add_timer_for_init_dpms(); + add_timer_for_dpms_init(); } if (display_conf.lcd_always_on) { diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 188f583..1d716b7 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -823,7 +823,7 @@ int exit_sysfs(void) backlight_update(); - exit_dpms(); + dpms_exit(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 4927f70..61e5d41 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1950,11 +1950,11 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_done_dpms(gpointer data) +static gboolean delayed_dpms_init_done(gpointer data) { int timeout; - if (!init_dpms()) + if (!dpms_init()) return G_SOURCE_CONTINUE; switch (get_pm_cur_state()) { @@ -1981,11 +1981,11 @@ static gboolean delayed_init_done_dpms(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_init_dpms(void) +static void add_timer_for_dpms_init(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_dpms_init_done, NULL); if (id == 0) - _E("Failed to add init_dpms timeout."); + _E("Failed to add dpms_init timeout."); } /** @@ -2173,13 +2173,13 @@ static void display_init(void *data) * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ // wm_ready = check_wm_ready(); - if (init_dpms()) { + if (dpms_init()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) lcd_off_procedure(LCD_OFF_BY_EVENT); else lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { - add_timer_for_init_dpms(); + add_timer_for_dpms_init(); } if (display_conf.lcd_always_on) { diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index d7d79db..f35f24d 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -838,7 +838,7 @@ int exit_sysfs(void) backlight_update(); - exit_dpms(); + dpms_exit(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index a596b62..e6d22a3 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1940,11 +1940,11 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_done_dpms(gpointer data) +static gboolean delayed_dpms_init_done(gpointer data) { int timeout; - if (!init_dpms()) + if (!dpms_init()) return G_SOURCE_CONTINUE; switch (get_pm_cur_state()) { @@ -1971,11 +1971,11 @@ static gboolean delayed_init_done_dpms(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_init_dpms(void) +static void add_timer_for_dpms_init(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_dpms_init_done, NULL); if (id == 0) - _E("Failed to add init_dpms timeout."); + _E("Failed to add dpms_init timeout."); } /** @@ -2164,13 +2164,13 @@ static void display_init(void *data) * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ // wm_ready = check_wm_ready(); - if (init_dpms()) { + if (dpms_init()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) lcd_off_procedure(LCD_OFF_BY_EVENT); else lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { - add_timer_for_init_dpms(); + add_timer_for_dpms_init(); } if (display_conf.lcd_always_on) { diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 128b637..a136a0e 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -823,7 +823,7 @@ int exit_sysfs(void) backlight_update(); - exit_dpms(); + dpms_exit(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index de4d504..406c2dc 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2228,11 +2228,11 @@ static int powerlock_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean delayed_init_done_dpms(gpointer data) +static gboolean delayed_dpms_init_done(gpointer data) { int timeout; - if (!init_dpms()) + if (!dpms_init()) return G_SOURCE_CONTINUE; switch (get_pm_cur_state()) { @@ -2259,11 +2259,11 @@ static gboolean delayed_init_done_dpms(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_init_dpms(void) +static void add_timer_for_dpms_init(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_dpms_init_done, NULL); if (id == 0) - _E("Failed to add init_dpms timeout."); + _E("Failed to add dpms_init timeout."); } /** @@ -2489,13 +2489,13 @@ static void display_init(void *data) * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ // wm_ready = check_wm_ready(); - if (init_dpms()) { + if (dpms_init()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) lcd_off_procedure(LCD_OFF_BY_EVENT); else lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { - add_timer_for_init_dpms(); + add_timer_for_dpms_init(); } if (display_conf.lcd_always_on) { diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 4683490..e859f29 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -905,7 +905,7 @@ int exit_sysfs(void) backlight_update(); - exit_dpms(); + dpms_exit(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 2b1b156..e995905 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -126,7 +126,7 @@ static void handle_global(void *data, struct wl_registry *registry, info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2); if (!info->wl_output) { _E("Failed to bind registry."); - exit_dpms(); + dpms_exit(); return; } _D("Get wl_output."); @@ -134,7 +134,7 @@ static void handle_global(void *data, struct wl_registry *registry, info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); if (!info->tz_dpms_mng) { _E("Failed to bind registry."); - exit_dpms(); + dpms_exit(); return; } @@ -562,7 +562,7 @@ int dpms_get_cached_state(void) return dpms_cache; } -bool init_dpms(void) +bool dpms_init(void) { if (dpms_client) return true; @@ -579,7 +579,7 @@ bool init_dpms(void) if (!dpms_client) { _E("Failed to init dpms client."); - exit_dpms(); + dpms_exit(); return false; } _I("Successfully initialized dpms client."); @@ -590,7 +590,7 @@ bool init_dpms(void) return true; } -void exit_dpms(void) +void dpms_exit(void) { _I("Exit dpms."); if (dpms_loop) { diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index b9ac040..f1bbe2f 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -22,8 +22,8 @@ void dpms_set_state(int on); int dpms_get_state(void); int dpms_get_cached_state(void); -bool init_dpms(void); -void exit_dpms(void); +bool dpms_init(void); +void dpms_exit(void); void __register_dpms_checklist(int mode, void (*checker)(void), const char *caller); #define register_dpms_checklist(mode, checker) __register_dpms_checklist(mode, checker, __func__) #endif /* __DISPLAY_DPMS_H__ */ -- 2.7.4 From 7d71b2642fa719a7f45c5cc05fe877daa6291118 Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Tue, 14 Feb 2023 12:18:58 +0900 Subject: [PATCH 09/16] display: Add support to select the DPMS type DPMS (Display Power Management Signaling) is typically done by requesting window manager. But some devices don't support window manager and previous DPMS code was written assuming exiting window manager. So, to support none window manager devices, dpms_ops struct is added. According to DPMS type configuration, DPMS function can be bypassed. If a new DPMS function is created later, it can be supported by connecting to dpms_ops. [New added configuration] - DisplayDPMSType : Indicates the type of DPMS. (window_manager or none) Default value is window_manager Change-Id: I8a9f254102086b3e22c9498c1604e45c5053b60e Signed-off-by: TaeminYeom --- conf/display-profile-iot-headed.conf | 6 +++ conf/display-profile-mobile.conf | 6 +++ conf/display-profile-tv.conf | 6 +++ conf/display-profile-wearable.conf | 6 +++ plugins/iot-headed/display/core.c | 1 + plugins/mobile/display/core.c | 1 + plugins/tv/display/core.c | 1 + plugins/wearable/display/core.c | 1 + src/display/core.h | 2 + src/display/display-dpms.c | 91 +++++++++++++++++++++++++++++++++--- src/display/display-dpms.h | 6 +++ src/display/display.c | 4 ++ 12 files changed, 124 insertions(+), 7 deletions(-) diff --git a/conf/display-profile-iot-headed.conf b/conf/display-profile-iot-headed.conf index 9d90031..123ba50 100644 --- a/conf/display-profile-iot-headed.conf +++ b/conf/display-profile-iot-headed.conf @@ -42,6 +42,12 @@ # Default: horizontal # DisplayInitDirection=(horizontal or vertical) +# This is the type of DPMS. +# If DPMS type is window_manager, turning display on or off, it uses window manager DPMS. +# If DPMS type is none, when the DPMS function is called, it does nothing just returns true. +# Default value is window_manager. +# DisplayDPMSType=(window_manager or none) + LCDAlwaysOn=no TimeoutEnable=yes SleepSupport=no diff --git a/conf/display-profile-mobile.conf b/conf/display-profile-mobile.conf index b4141c5..a807a16 100644 --- a/conf/display-profile-mobile.conf +++ b/conf/display-profile-mobile.conf @@ -34,5 +34,11 @@ # If this value is no, LCD is turned off just by external requests. # TimeoutEnable=(yes or no) +# This is the type of DPMS. +# If DPMS type is window_manager, turning display on or off, it uses window manager DPMS. +# If DPMS type is none, when the DPMS function is called, it does nothing just returns true. +# Default value is window_manager. +# DisplayDPMSType=(window_manager or none) + LCDAlwaysOn=no TimeoutEnable=yes diff --git a/conf/display-profile-tv.conf b/conf/display-profile-tv.conf index 4e14b86..3859a02 100644 --- a/conf/display-profile-tv.conf +++ b/conf/display-profile-tv.conf @@ -34,6 +34,12 @@ # If this value is no, LCD is turned off just by external requests. # TimeoutEnable=(yes or no) +# This is the type of DPMS. +# If DPMS type is window_manager, turning display on or off, it uses window manager DPMS. +# If DPMS type is none, when the DPMS function is called, it does nothing just returns true. +# Default value is window_manager. +# DisplayDPMSType=(window_manager or none) + LCDAlwaysOn=yes TimeoutEnable=no SleepSupport=no diff --git a/conf/display-profile-wearable.conf b/conf/display-profile-wearable.conf index f4c1e22..c8daba4 100644 --- a/conf/display-profile-wearable.conf +++ b/conf/display-profile-wearable.conf @@ -34,6 +34,12 @@ # If this value is no, LCD is turned off just by external requests. # TimeoutEnable=(yes or no) +# This is the type of DPMS. +# If DPMS type is window_manager, turning display on or off, it uses window manager DPMS. +# If DPMS type is none, when the DPMS function is called, it does nothing just returns true. +# Default value is window_manager. +# DisplayDPMSType=(window_manager or none) + LCDAlwaysOn=no TimeoutEnable=yes ControlDisplay=no diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 6952ccc..660ea0e 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -201,6 +201,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .display_on_usb_conn_changed = true, + .display_dpms_type = DISPLAY_DPMS_TYPE_WINDOW_MANAGER, }; struct display_function_info display_info = { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 61e5d41..a511760 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -203,6 +203,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .display_on_usb_conn_changed = true, + .display_dpms_type = DISPLAY_DPMS_TYPE_WINDOW_MANAGER, }; struct display_function_info display_info = { diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index e6d22a3..e784dab 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -201,6 +201,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .display_on_usb_conn_changed = true, + .display_dpms_type = DISPLAY_DPMS_TYPE_WINDOW_MANAGER, }; struct display_function_info display_info = { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 406c2dc..abc7680 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -226,6 +226,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .display_on_usb_conn_changed = true, + .display_dpms_type = DISPLAY_DPMS_TYPE_WINDOW_MANAGER, }; struct display_function_info display_info = { diff --git a/src/display/core.h b/src/display/core.h index 34b6c94..c514619 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -27,6 +27,7 @@ #include "poll.h" #include "device-interface.h" #include "setting.h" +#include "display-dpms.h" #define WITHOUT_STARTNOTI 0x1 #define MASK_BIT 0x7 /* 111 */ @@ -121,6 +122,7 @@ struct display_config { bool input_support; bool touch_wakeup; bool display_on_usb_conn_changed; + enum display_dpms_type display_dpms_type; }; /* diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index e995905..37b0ff2 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -32,6 +32,7 @@ #include "display/util.h" #include "display/display-dpms.h" #include "display/device-interface.h" +#include "core.h" #define DPMS_RESPONSE_TIMEOUT 10 /* second */ @@ -49,10 +50,20 @@ typedef struct { bool connected; } wl_glib_info; +struct dpms_ops { + void (*set_state)(int on); + int (*get_state)(void); + int (*get_cached_state)(void); + bool (*init)(void); + void (*exit)(void); +}; + static wl_glib_info *dpms_client = NULL; static bool wm_is_ready; +static struct dpms_ops g_dpms_ops; + static GMainLoop *dpms_loop; static GMainContext *dpms_context; static bool dpms_get_state_done; @@ -491,7 +502,7 @@ static void wait_response(int timeout) g_source_unref(timeout_source); } -void dpms_set_state(int on) +static void wm_dpms_set_state(int on) { uint32_t mode; @@ -524,7 +535,7 @@ void dpms_set_state(int on) } } -int dpms_get_state(void) +static int wm_dpms_get_state(void) { if (!dpms_is_available()) { _E("Dpms is not available."); @@ -552,7 +563,7 @@ int dpms_get_state(void) } } -int dpms_get_cached_state(void) +static int wm_dpms_get_cached_state(void) { if (!dpms_is_available()) { _E("Dpms is not available."); @@ -562,7 +573,7 @@ int dpms_get_cached_state(void) return dpms_cache; } -bool dpms_init(void) +static bool wm_dpms_init(void) { if (dpms_client) return true; @@ -570,7 +581,7 @@ bool dpms_init(void) if (!check_wm_ready()) return false; - _I("Init dpms."); + _I("Init dpms window manager."); dpms_context = g_main_context_new(); /* Initialize client */ @@ -590,9 +601,9 @@ bool dpms_init(void) return true; } -void dpms_exit(void) +static void wm_dpms_exit(void) { - _I("Exit dpms."); + _I("Exit dpms window manager."); if (dpms_loop) { g_main_loop_unref(dpms_loop); dpms_loop = NULL; @@ -606,3 +617,69 @@ void dpms_exit(void) if (dpms_client && !g_source_is_destroyed((GSource *)dpms_client)) g_source_destroy((GSource *)dpms_client); } + +static void none_dpms_set_state(int on) { dpms_cache = on; } +static int none_dpms_get_state(void) { return dpms_cache; } +static int none_dpms_get_cached_state(void) { return dpms_cache; } +static bool none_dpms_init(void) { return true; } +static void none_dpms_exit(void) {} + +void dpms_set_state(int on) +{ + if (g_dpms_ops.set_state) + g_dpms_ops.set_state(on); +} + +int dpms_get_state(void) +{ + if (g_dpms_ops.get_state) + return g_dpms_ops.get_state(); + return -EINVAL; +} + +int dpms_get_cached_state(void) +{ + if (g_dpms_ops.get_cached_state) + return g_dpms_ops.get_cached_state(); + return -EINVAL; +} + +bool dpms_init(void) +{ + const struct display_config *display_conf = get_var_display_config(); + if (!display_conf) { + _E("Failed to get display configuration"); + return false; + } + + switch (display_conf->display_dpms_type) { + case DISPLAY_DPMS_TYPE_WINDOW_MANAGER: + g_dpms_ops.set_state = wm_dpms_set_state; + g_dpms_ops.get_state = wm_dpms_get_state; + g_dpms_ops.get_cached_state = wm_dpms_get_cached_state; + g_dpms_ops.init = wm_dpms_init; + g_dpms_ops.exit = wm_dpms_exit; + break; + case DISPLAY_DPMS_TYPE_NONE: + g_dpms_ops.set_state = none_dpms_set_state; + g_dpms_ops.get_state = none_dpms_get_state; + g_dpms_ops.get_cached_state = none_dpms_get_cached_state; + g_dpms_ops.init = none_dpms_init; + g_dpms_ops.exit = none_dpms_exit; + break; + default: + _E("Invalid dpms type"); + return false; + } + + if (g_dpms_ops.init) + return g_dpms_ops.init(); + + return false; +} + +void dpms_exit(void) +{ + if (g_dpms_ops.exit) + g_dpms_ops.exit(); +} diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index f1bbe2f..f1a970e 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -26,4 +26,10 @@ bool dpms_init(void); void dpms_exit(void); void __register_dpms_checklist(int mode, void (*checker)(void), const char *caller); #define register_dpms_checklist(mode, checker) __register_dpms_checklist(mode, checker, __func__) + +enum display_dpms_type { + DISPLAY_DPMS_TYPE_NONE, + DISPLAY_DPMS_TYPE_WINDOW_MANAGER, +}; + #endif /* __DISPLAY_DPMS_H__ */ diff --git a/src/display/display.c b/src/display/display.c index 7885ea6..36b1320 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -23,6 +23,7 @@ #include "util.h" #include "core.h" +#include "display-dpms.h" #include "display-ops.h" #include "dd-display.h" #include "shared/common.h" @@ -169,6 +170,9 @@ int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "DisplayInitDirection")) { c->display_init_direction = (MATCH(result->value, "vertical") ? \ DISPLAY_INIT_DIRECTION_VERTICAL : DISPLAY_INIT_DIRECTION_HORIZONTAL); + } else if (MATCH(result->name, "DisplayDPMSType")) { + c->display_dpms_type = (MATCH(result->value, "none") ? \ + DISPLAY_DPMS_TYPE_NONE : DISPLAY_DPMS_TYPE_WINDOW_MANAGER); } return 0; -- 2.7.4 From 6f5b33a6a9c1ab390565445e46089d802a469439 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Feb 2023 15:36:14 +0900 Subject: [PATCH 10/16] power: Wake unlock in case of cancelling transition Properly unlock the secondary wakelock when cancelling transition. Currently there is no scenario for cancelling wakeup transition though, it is important when it comes to undoing wakeup and trying to go sleep again. Change-Id: I5c4cc65d6bf8453919e0a2624603b8c04f574eb7 Signed-off-by: Youngjae Cho --- src/power/power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/power/power.c b/src/power/power.c index 1ed50fc..866386b 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -669,6 +669,7 @@ static void action_transition(void) if (post_action_state[index]) post_action_state[index](transition_context.ti.data); +trigger_next: /** * transition_context.ongiong must be reset after the post_action_state(). * This prevents the post_action_state() from triggering another transition @@ -678,7 +679,6 @@ static void action_transition(void) transition_context.ongoing = 0; event_wake_unlock(EL_POWER_TRANSITION_STATE); -trigger_next: retval = dequeue_transition(&ti); if (retval == 0) { prepare_transition(&ti); -- 2.7.4 From 065f075a23ebf1dc387df715dce9efe03b5cf5ba Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 10 Mar 2023 10:53:52 +0900 Subject: [PATCH 11/16] power: Relocate resuming device_notify() properly The resuming notify should be broadcasted after completely finishing wakeup transition. In other words, broadcasting should be held when a transition is waiting for being confirmed by user program. In this context, it is proper to relocate device_notify() to resume_echo_mem(), which is invoked on finishing wakeup transition. Change-Id: I0c924d5667b749f79e95f04b62c69e499ffb7058 Signed-off-by: Youngjae Cho --- src/power/power-suspend.c | 3 +-- src/power/power.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/power/power-suspend.c b/src/power/power-suspend.c index efd6ccd..aff5611 100644 --- a/src/power/power-suspend.c +++ b/src/power/power-suspend.c @@ -392,7 +392,6 @@ static void suspend_echo_mem(void) // resume update_wakeup_reason(); - device_notify(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, NULL); /* * FIXME: If the wakeup reason lingers after wakeup, a transition triggered from other * than the above line would take the lingering wakeup reason as a transition reason, @@ -408,7 +407,7 @@ static void suspend_echo_mem(void) static void resume_echo_mem(void) { - // nothing to do + device_notify(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, NULL); } static void suspend_autosleep(void) diff --git a/src/power/power.c b/src/power/power.c index 866386b..f6f05e9 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -295,7 +295,8 @@ static uint64_t alloc_unique_id(void) static void pre_action_normal(void *udata) { - power_resume(transition_context.ti.reason); + if (transition_context.ti.curr == DEVICED_POWER_STATE_SLEEP) + power_resume(transition_context.ti.reason); } static void post_action_sleep(void *udata) -- 2.7.4 From bbd0a3c2e25419e225028535ff03415b3f5807a7 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 14 Mar 2023 17:54:34 +0900 Subject: [PATCH 12/16] power: Use strncpy to avoid the potential problem sscanf function is detected as risky function in static analysis. Thus, change the sscanf function to strncpy function. Change-Id: I44b883eeaeea401dc251577f2bbced4f9ee8c72c Signed-off-by: Yunhee Seo --- src/power/power-boot.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/power/power-boot.c b/src/power/power-boot.c index 74ec729..0f39f4a 100644 --- a/src/power/power-boot.c +++ b/src/power/power-boot.c @@ -48,8 +48,8 @@ static struct trans_info init_ti = { }; static struct boot_condition { - char reason[64]; - char mode[64]; + char reason[128]; + char mode[128]; } bc = { "unknown", "normal" }; static guint sig_id[2] = {0, 0}; @@ -159,9 +159,9 @@ static int parse_matching_boot_condition(const struct parse_result *result, void SYS_G_LIST_FOREACH(result->props, elem, prop) { if (MATCH(prop->key, "BootReason")) - sscanf(prop->value, "%s", config_bc.reason); + strncpy(config_bc.reason, prop->value, sizeof(prop->value) - 1); else if (MATCH(prop->key, "BootMode")) - sscanf(prop->value, "%s", config_bc.mode); + strncpy(config_bc.mode, prop->value, sizeof(prop->value) - 1); } if (MATCH(bc.reason, config_bc.reason) && MATCH(bc.mode, config_bc.mode)) -- 2.7.4 From 447bee07b18b7ae3da3d2f2f1a3b876a58da1050 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 18:36:22 +0900 Subject: [PATCH 13/16] display: Remove unused code Change-Id: I4a4a48848d0b9e164f2c820c6086bf653b316b3f Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 36 ------------------------------------ plugins/mobile/display/core.c | 36 ------------------------------------ plugins/tv/display/core.c | 36 ------------------------------------ plugins/wearable/display/core.c | 36 ------------------------------------ src/display/core.h | 7 ------- 5 files changed, 151 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 660ea0e..e7ba15f 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -226,42 +226,6 @@ guint get_transition_timer(void) return timeout_src_id; } -void change_state_action(enum state_t state, int (*func)(int timeout)) -{ - _I("[%s] 'action' is changed.", states[state].name); - states[state].action = func; -} - -void change_state_trans(enum state_t state, int (*func)(int evt)) -{ - _I("[%s] 'trans' is changed.", states[state].name); - states[state].trans = func; -} - -void change_state_check(enum state_t state, int (*func)(int curr, int next)) -{ - _I("[%s] 'check' is changed.", states[state].name); - states[state].check = func; -} - -void change_state_name(enum state_t state, const char *name) -{ - _I("[%s] 'name' is changed.", states[state].name); - states[state].name = name; -} - -void change_trans_table(enum state_t state, enum state_t next) -{ - _I("[%s] 'timeout trans table' is changed.", states[state].name); - trans_table[state][EVENT_TIMEOUT] = next; -} - -void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) -{ - _I("'proc change state' is changed."); - proc_change_state = func; -} - static int display_brightness_changed(void *data) { int brt, ret; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index a511760..81f0750 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -228,42 +228,6 @@ guint get_transition_timer(void) return timeout_src_id; } -void change_state_action(enum state_t state, int (*func)(int timeout)) -{ - _I("[%s] 'action' is changed.", states[state].name); - states[state].action = func; -} - -void change_state_trans(enum state_t state, int (*func)(int evt)) -{ - _I("[%s] 'trans' is changed.", states[state].name); - states[state].trans = func; -} - -void change_state_check(enum state_t state, int (*func)(int curr, int next)) -{ - _I("[%s] 'check' is changed.", states[state].name); - states[state].check = func; -} - -void change_state_name(enum state_t state, const char *name) -{ - _I("[%s] 'name' is changed.", states[state].name); - states[state].name = name; -} - -void change_trans_table(enum state_t state, enum state_t next) -{ - _I("[%s] 'timeout trans table' is changed.", states[state].name); - trans_table[state][EVENT_TIMEOUT] = next; -} - -void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) -{ - _I("'proc change state' is changed."); - proc_change_state = func; -} - static int display_brightness_changed(void *data) { int brt, ret; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index e784dab..eecdd01 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -226,42 +226,6 @@ guint get_transition_timer(void) return timeout_src_id; } -void change_state_action(enum state_t state, int (*func)(int timeout)) -{ - _I("[%s] 'action' is changed.", states[state].name); - states[state].action = func; -} - -void change_state_trans(enum state_t state, int (*func)(int evt)) -{ - _I("[%s] 'trans' is changed.", states[state].name); - states[state].trans = func; -} - -void change_state_check(enum state_t state, int (*func)(int curr, int next)) -{ - _I("[%s] 'check' is changed.", states[state].name); - states[state].check = func; -} - -void change_state_name(enum state_t state, const char *name) -{ - _I("[%s] 'name' is changed.", states[state].name); - states[state].name = name; -} - -void change_trans_table(enum state_t state, enum state_t next) -{ - _I("[%s] 'timeout trans table' is changed.", states[state].name); - trans_table[state][EVENT_TIMEOUT] = next; -} - -void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) -{ - _I("'proc change state' is changed."); - proc_change_state = func; -} - static int display_brightness_changed(void *data) { int brt, ret; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index abc7680..b402d7e 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -251,42 +251,6 @@ guint get_transition_timer(void) return timeout_src_id; } -void change_state_action(enum state_t state, int (*func)(int timeout)) -{ - _I("[%s] 'action' is changed.", states[state].name); - states[state].action = func; -} - -void change_state_trans(enum state_t state, int (*func)(int evt)) -{ - _I("[%s] 'trans' is changed.", states[state].name); - states[state].trans = func; -} - -void change_state_check(enum state_t state, int (*func)(int curr, int next)) -{ - _I("[%s] 'check' is changed.", states[state].name); - states[state].check = func; -} - -void change_state_name(enum state_t state, const char *name) -{ - _I("[%s] 'name' is changed.", states[state].name); - states[state].name = name; -} - -void change_trans_table(enum state_t state, enum state_t next) -{ - _I("[%s] 'timeout trans table' is changed.", states[state].name); - trans_table[state][EVENT_TIMEOUT] = next; -} - -void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) -{ - _I("'proc change state' is changed."); - proc_change_state = func; -} - static int display_brightness_changed(void *data) { int brt, ret; diff --git a/src/display/core.h b/src/display/core.h index c514619..3e28126 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -180,13 +180,6 @@ void set_lock_screen_state(int state); void set_lock_screen_bg_state(bool state); /* core.c */ -void change_state_action(enum state_t state, int (*func)(int timeout)); -void change_state_trans(enum state_t state, int (*func)(int evt)); -void change_state_check(enum state_t state, int (*func)(int curr, int next)); -void change_state_name(enum state_t state, const char *name); -void change_trans_table(enum state_t state, enum state_t next); -void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)); - int delete_condition(enum state_t state); int custom_lcdoff(enum device_flags flag); int display_on_by_reason(const char *reason, int timeout); -- 2.7.4 From 9600e86c8e31cd8bd90fef5514857292d6325728 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 18:51:02 +0900 Subject: [PATCH 14/16] display: Remove unused s-cover(HALL IC) code Change-Id: If57090427d93e3465264ba9366374cd197ba6a23 Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 28 +++------------------------- plugins/mobile/display/core.c | 28 +++------------------------- plugins/tv/display/core.c | 28 +++------------------------- plugins/wearable/display/core.c | 28 +++------------------------- src/display/poll.h | 1 - src/display/setting.h | 1 - 6 files changed, 12 insertions(+), 102 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index e7ba15f..f8ecf49 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -102,7 +102,6 @@ static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; static char *custom_change_name; -static bool hallic_open = true; static guint lock_timeout_id; static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; @@ -468,11 +467,6 @@ int low_battery_state(int val) return false; } -int get_hallic_open(void) -{ - return hallic_open; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -622,15 +616,7 @@ static void update_display_time(void) { int run_timeout, val; - /* first priority : s cover */ - if (!hallic_open) { - states[S_NORMAL].timeout = S_COVER_TIMEOUT; - _I("S cover closed: Timeout(%d ms) is set by normal.", - S_COVER_TIMEOUT); - return; - } - - /* second priority : custom timeout */ + /* first priority : custom timeout */ if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; @@ -639,7 +625,7 @@ static void update_display_time(void) return; } - /* third priority : lock state */ + /* second priority : lock state */ if ((__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) && !get_lock_screen_bg_state()) { /* timeout is different according to key or event. */ @@ -1266,7 +1252,7 @@ int check_lcdoff_direct(void) return true; lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK && hallic_open) + if (lock != VCONFKEY_IDLE_LOCK) return false; hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); @@ -1600,14 +1586,6 @@ static int update_setting(int key_idx, int val) update_display_time(); states[get_pm_cur_state()].trans(EVENT_INPUT); break; - case SETTING_HALLIC_OPEN: - hallic_open = val; - update_display_time(); - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) - states[get_pm_cur_state()].trans(EVENT_INPUT); - else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) - proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); - break; case SETTING_LOW_BATT: if (low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 81f0750..6980389 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -104,7 +104,6 @@ static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; static char *custom_change_name; -static bool hallic_open = true; static guint lock_timeout_id; static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; @@ -475,11 +474,6 @@ int low_battery_state(int val) return false; } -int get_hallic_open(void) -{ - return hallic_open; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -629,15 +623,7 @@ static void update_display_time(void) { int run_timeout, val; - /* first priority : s cover */ - if (!hallic_open) { - states[S_NORMAL].timeout = S_COVER_TIMEOUT; - _I("S cover closed: Timeout(%d ms) is set by normal.", - S_COVER_TIMEOUT); - return; - } - - /* second priority : custom timeout */ + /* first priority : custom timeout */ if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; @@ -646,7 +632,7 @@ static void update_display_time(void) return; } - /* third priority : lock state */ + /* second priority : lock state */ if ((__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) && !get_lock_screen_bg_state()) { /* timeout is different according to key or event. */ @@ -1276,7 +1262,7 @@ int check_lcdoff_direct(void) return true; lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK && hallic_open) + if (lock != VCONFKEY_IDLE_LOCK) return false; hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); @@ -1610,14 +1596,6 @@ static int update_setting(int key_idx, int val) update_display_time(); states[get_pm_cur_state()].trans(EVENT_INPUT); break; - case SETTING_HALLIC_OPEN: - hallic_open = val; - update_display_time(); - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) - states[get_pm_cur_state()].trans(EVENT_INPUT); - else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) - proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); - break; case SETTING_LOW_BATT: if (low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index eecdd01..b1e1ab7 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -102,7 +102,6 @@ static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; static char *custom_change_name; -static bool hallic_open = true; static guint lock_timeout_id; static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; @@ -468,11 +467,6 @@ int low_battery_state(int val) return false; } -int get_hallic_open(void) -{ - return hallic_open; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -622,15 +616,7 @@ static void update_display_time(void) { int run_timeout, val; - /* first priority : s cover */ - if (!hallic_open) { - states[S_NORMAL].timeout = S_COVER_TIMEOUT; - _I("S cover closed: Timeout(%d ms) is set by normal.", - S_COVER_TIMEOUT); - return; - } - - /* second priority : custom timeout */ + /* first priority : custom timeout */ if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; @@ -639,7 +625,7 @@ static void update_display_time(void) return; } - /* third priority : lock state */ + /* second priority : lock state */ if ((__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) && !get_lock_screen_bg_state()) { /* timeout is different according to key or event. */ @@ -1266,7 +1252,7 @@ int check_lcdoff_direct(void) return true; lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK && hallic_open) + if (lock != VCONFKEY_IDLE_LOCK) return false; hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); @@ -1600,14 +1586,6 @@ static int update_setting(int key_idx, int val) update_display_time(); states[get_pm_cur_state()].trans(EVENT_INPUT); break; - case SETTING_HALLIC_OPEN: - hallic_open = val; - update_display_time(); - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) - states[get_pm_cur_state()].trans(EVENT_INPUT); - else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) - proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); - break; case SETTING_LOW_BATT: if (low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index b402d7e..da8f29e 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -113,7 +113,6 @@ static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; int custom_holdkey_block = false; static char *custom_change_name; -static bool hallic_open = true; static guint lock_timeout_id; static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; @@ -686,11 +685,6 @@ int low_battery_state(int val) return false; } -int get_hallic_open(void) -{ - return hallic_open; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -840,15 +834,7 @@ static void update_display_time(void) { int run_timeout, val; - /* first priority : s cover */ - if (!hallic_open) { - states[S_NORMAL].timeout = S_COVER_TIMEOUT; - _I("S cover closed: Timeout(%d ms) is set by normal.", - S_COVER_TIMEOUT); - return; - } - - /* second priority : custom timeout */ + /* first priority : custom timeout */ if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; @@ -857,7 +843,7 @@ static void update_display_time(void) return; } - /* third priority : lock state */ + /* second priority : lock state */ if ((__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) && !get_lock_screen_bg_state()) { /* timeout is different according to key or event. */ @@ -1517,7 +1503,7 @@ int check_lcdoff_direct(void) return true; lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK && hallic_open) + if (lock != VCONFKEY_IDLE_LOCK) return false; hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); @@ -1871,14 +1857,6 @@ static int update_setting(int key_idx, int val) update_display_time(); states[get_pm_cur_state()].trans(EVENT_INPUT); break; - case SETTING_HALLIC_OPEN: - hallic_open = val; - update_display_time(); - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDDIM)) - states[get_pm_cur_state()].trans(EVENT_INPUT); - else if ((get_pm_cur_state() == S_SLEEP) && hallic_open) - proc_change_state(S_LCDOFF, INTERNAL_LOCK_HALLIC); - break; case SETTING_LOW_BATT: if (low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) diff --git a/src/display/poll.h b/src/display/poll.h index aed0736..9328cac 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -62,7 +62,6 @@ enum { INTERNAL_LOCK_EARJACK, INTERNAL_LOCK_POWERKEY, INTERNAL_LOCK_PM, - INTERNAL_LOCK_HALLIC, INTERNAL_LOCK_SWIM, INTERNAL_LOCK_OVERHEAT, INTERNAL_LOCK_OVERCOOL, diff --git a/src/display/setting.h b/src/display/setting.h index 284fb62..077f505 100644 --- a/src/display/setting.h +++ b/src/display/setting.h @@ -42,7 +42,6 @@ enum { SETTING_LOW_BATT, SETTING_CHARGING, SETTING_POWEROFF, - SETTING_HALLIC_OPEN, SETTING_LOCK_SCREEN_BG, SETTING_END }; -- 2.7.4 From 0229a9c3bb3a213ffb5f9f00d7f2ccd2a8be9559 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 17 Feb 2023 17:26:45 +0900 Subject: [PATCH 15/16] display: Add functions related to brightness Move plugin static functions to core(display module). This is for moving backlight_ops functions related to brightess without dependency. int display_backlight_get_max_brightness(int *max_brightness) -> This function replaces the get_max_brightness function located in plugins. int display_backlight_get_normalized_brightness(int raw_brightness, int *normalized_brightness) -> This function replaces the get_brt_normalized function located in plugins. Change-Id: I7452f90075ef63acdc8f595fe99d47e0bfe4f4a1 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/device-interface.c | 81 +++++------------------- plugins/mobile/display/device-interface.c | 81 +++++------------------- plugins/tv/display/device-interface.c | 81 +++++------------------- plugins/wearable/display/device-interface.c | 81 +++++------------------- src/display/display-backlight.c | 90 +++++++++++++++++++++++++++ src/display/display-backlight.h | 26 ++++++++ 6 files changed, 184 insertions(+), 256 deletions(-) create mode 100644 src/display/display-backlight.c create mode 100644 src/display/display-backlight.h diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 1d716b7..4e7b22d 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -45,6 +45,7 @@ #include "display/display-dpms.h" #include "display/display.h" #include "display/display-lock.h" +#include "display/display-backlight.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -374,47 +375,19 @@ static int get_default_brt(void) return default_brightness; } -static int get_max_brightness(void) -{ - static int max = -1; - int ret; - - if (max > 0) - return max; - - if (!display_dev_available) { - _E("There is no HAL for display."); - return -ENOENT; - } - - ret = hal_device_display_get_max_brightness(&max); - if (ret < 0) { - if (ret == -ENODEV) { - _E("Get max brightness is not supported."); - max = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - return max; - } else { - _E("Failed to get max brightness: %d", ret); - return ret; - } - } - - return max; -} - static int set_brightness(int val) { - int max; + int max, ret; if (!display_dev_available) { _E("There is no display device."); return -ENOENT; } - max = get_max_brightness(); - if (max < 0) { + ret = display_backlight_get_max_brightness(&max); + if (ret < 0) { _E("Failed to get max brightness."); - return max; + return ret; } if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { @@ -436,36 +409,6 @@ static int set_brightness(int val) return hal_device_display_set_brightness(val); } -static int get_brt_normalized(int brt_raw) -{ - int quotient, remainder; - int max; - - max = get_max_brightness(); - if (max < 0) { - _E("Failed to get max brightness."); - return max; - } - - /* Maximum Brightness to users is 100. - * Thus the brightness value need to be calculated using real brightness. - * ex) Let's suppose that the maximum brightness of driver is 255. - * case 1) When the user sets the brightness to 41, - * real brightness is - * 41 * 255 / 100 = 104.55 = 104 (rounded off) - * case 2) When the user gets the brightness, - * the driver returns the brightness 104. - * Thus the brightness to users is - * 104 * 100 / 255 = 40.7843.... = 41 (rounded up) - */ - quotient = brt_raw * 100 / max; - remainder = brt_raw * 100 % max; - if (remainder > 0) - quotient++; - - return quotient; -} - static int get_brightness(int *val) { int brt, ret; @@ -485,7 +428,12 @@ static int get_brightness(int *val) return ret; } - *val = get_brt_normalized(brt); + ret = display_backlight_get_normalized_brightness(brt, val); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } @@ -507,7 +455,12 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return ret; } - *brt = get_brt_normalized(brt_raw); + ret = display_backlight_get_normalized_brightness(brt_raw, brt); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index f35f24d..9bfb003 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -44,6 +44,7 @@ #include "display/display-dpms.h" #include "display/display.h" #include "display/display-lock.h" +#include "display/display-backlight.h" #include "power/power-boot.h" #include "power/power-suspend.h" @@ -373,47 +374,19 @@ static int get_default_brt(void) return default_brightness; } -static int get_max_brightness(void) -{ - static int max = -1; - int ret; - - if (max > 0) - return max; - - if (!display_dev_available) { - _E("There is no HAL for display."); - return -ENOENT; - } - - ret = hal_device_display_get_max_brightness(&max); - if (ret < 0) { - if (ret == -ENODEV) { - _E("Get max brightness is not supported."); - max = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - return max; - } else { - _E("Failed to get max brightness: %d", ret); - return ret; - } - } - - return max; -} - static int set_brightness(int val) { - int max; + int max, ret; if (!display_dev_available) { _E("There is no display device."); return -ENOENT; } - max = get_max_brightness(); - if (max < 0) { + ret = display_backlight_get_max_brightness(&max); + if (ret < 0) { _E("Failed to get max brightness."); - return max; + return ret; } if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { @@ -435,36 +408,6 @@ static int set_brightness(int val) return hal_device_display_set_brightness(val); } -static int get_brt_normalized(int brt_raw) -{ - int quotient, remainder; - int max; - - max = get_max_brightness(); - if (max < 0) { - _E("Failed to get max brightness."); - return max; - } - - /* Maximum Brightness to users is 100. - * Thus the brightness value need to be calculated using real brightness. - * ex) Let's suppose that the maximum brightness of driver is 255. - * case 1) When the user sets the brightness to 41, - * real brightness is - * 41 * 255 / 100 = 104.55 = 104 (rounded off) - * case 2) When the user gets the brightness, - * the driver returns the brightness 104. - * Thus the brightness to users is - * 104 * 100 / 255 = 40.7843.... = 41 (rounded up) - */ - quotient = brt_raw * 100 / max; - remainder = brt_raw * 100 % max; - if (remainder > 0) - quotient++; - - return quotient; -} - static int get_brightness(int *val) { int brt, ret; @@ -484,7 +427,12 @@ static int get_brightness(int *val) return ret; } - *val = get_brt_normalized(brt); + ret = display_backlight_get_normalized_brightness(brt, val); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } @@ -506,7 +454,12 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return ret; } - *brt = get_brt_normalized(brt_raw); + ret = display_backlight_get_normalized_brightness(brt_raw, brt); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index a136a0e..89081e0 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -43,6 +43,7 @@ #include "core.h" #include "display/display-dpms.h" #include "display/display.h" +#include "display/display-backlight.h" #include "power/power-suspend.h" #include "display/display-lock.h" @@ -374,47 +375,19 @@ static int get_default_brt(void) return default_brightness; } -static int get_max_brightness(void) -{ - static int max = -1; - int ret; - - if (max > 0) - return max; - - if (!display_dev_available) { - _E("There is no HAL for display device."); - return -ENOENT; - } - - ret = hal_device_display_get_max_brightness(&max); - if (ret < 0) { - if (ret == -ENODEV) { - _E("Get max brightness is not supported."); - max = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - return max; - } else { - _E("Failed to get max brightness: %d", ret); - return ret; - } - } - - return max; -} - static int set_brightness(int val) { - int max; + int max, ret; if (!display_dev_available) { _E("There is no display device."); return -ENOENT; } - max = get_max_brightness(); - if (max < 0) { + ret = display_backlight_get_max_brightness(&max); + if (ret < 0) { _E("Failed to get max brightness."); - return max; + return ret; } if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { @@ -436,36 +409,6 @@ static int set_brightness(int val) return hal_device_display_set_brightness(val); } -static int get_brt_normalized(int brt_raw) -{ - int quotient, remainder; - int max; - - max = get_max_brightness(); - if (max < 0) { - _E("Failed to get max brightness."); - return max; - } - - /* Maximum Brightness to users is 100. - * Thus the brightness value need to be calculated using real brightness. - * ex) Let's suppose that the maximum brightness of driver is 255. - * case 1) When the user sets the brightness to 41, - * real brightness is - * 41 * 255 / 100 = 104.55 = 104 (rounded off) - * case 2) When the user gets the brightness, - * the driver returns the brightness 104. - * Thus the brightness to users is - * 104 * 100 / 255 = 40.7843.... = 41 (rounded up) - */ - quotient = brt_raw * 100 / max; - remainder = brt_raw * 100 % max; - if (remainder > 0) - quotient++; - - return quotient; -} - static int get_brightness(int *val) { int brt, ret; @@ -485,7 +428,12 @@ static int get_brightness(int *val) return ret; } - *val = get_brt_normalized(brt); + ret = display_backlight_get_normalized_brightness(brt, val); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } @@ -507,7 +455,12 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return ret; } - *brt = get_brt_normalized(brt_raw); + ret = display_backlight_get_normalized_brightness(brt_raw, brt); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index e859f29..e9d442a 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -44,6 +44,7 @@ #include "display/display-dpms.h" #include "display/display.h" #include "display/display-lock.h" +#include "display/display-backlight.h" #include "battery-monitor.h" #include "battery/power-supply.h" #include "power/power-suspend.h" @@ -385,47 +386,19 @@ static int get_default_brt(void) return default_brightness; } -static int get_max_brightness(void) -{ - static int max = -1; - int ret; - - if (max > 0) - return max; - - if (!display_dev_available) { - _E("There is no HAL for display."); - return -ENOENT; - } - - ret = hal_device_display_get_max_brightness(&max); - if (ret < 0) { - if (ret == -ENODEV) { - _E("Get max brightness is not supported."); - max = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - return max; - } else { - _E("Failed to get max brightness: %d", ret); - return ret; - } - } - - return max; -} - static int set_brightness(int val) { - int max; + int max, ret; if (!display_dev_available) { _E("There is no display device."); return -ENOENT; } - max = get_max_brightness(); - if (max < 0) { + ret = display_backlight_get_max_brightness(&max); + if (ret < 0) { _E("Failed to get max brightness."); - return max; + return ret; } if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { @@ -448,36 +421,6 @@ static int set_brightness(int val) return hal_device_display_set_brightness(val); } -static int get_brt_normalized(int brt_raw) -{ - int quotient, remainder; - int max; - - max = get_max_brightness(); - if (max < 0) { - _E("Failed to get max brightness."); - return max; - } - - /* Maximum Brightness to users is 100. - * Thus the brightness value need to be calculated using real brightness. - * ex) Let's suppose that the maximum brightness of driver is 255. - * case 1) When the user sets the brightness to 41, - * real brightness is - * 41 * 255 / 100 = 104.55 = 104 (rounded off) - * case 2) When the user gets the brightness, - * the driver returns the brightness 104. - * Thus the brightness to users is - * 104 * 100 / 255 = 40.7843.... = 41 (rounded up) - */ - quotient = brt_raw * 100 / max; - remainder = brt_raw * 100 % max; - if (remainder > 0) - quotient++; - - return quotient; -} - static int get_brightness(int *val) { int brt, ret; @@ -497,7 +440,12 @@ static int get_brightness(int *val) return ret; } - *val = get_brt_normalized(brt); + ret = display_backlight_get_normalized_brightness(brt, val); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } @@ -519,7 +467,12 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return ret; } - *brt = get_brt_normalized(brt_raw); + ret = display_backlight_get_normalized_brightness(brt_raw, brt); + if (ret < 0) { + _E("Failed to get normalized brightness."); + return ret; + } + return 0; } diff --git a/src/display/display-backlight.c b/src/display/display-backlight.c new file mode 100644 index 0000000..eea7666 --- /dev/null +++ b/src/display/display-backlight.c @@ -0,0 +1,90 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "shared/log.h" +#include "display.h" +#include "display-backlight.h" + +/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ +int display_backlight_get_max_brightness(int *max_brightness) +{ + static int max = -1; + int ret = 0; + + if (!max_brightness) + return -EINVAL; + + if (max > 0) { + *max_brightness = max; + return 0; + } + + if (!display_is_hal_backend_available()) { + _E("There is no HAL for display."); + return -ENOENT; + } + + ret = hal_device_display_get_max_brightness(&max); + if (ret == -ENODEV) { + _W("Get max brightness is not supported."); + *max_brightness = DEFAULT_DISPLAY_MAX_BRIGHTNESS; + return 0; + } else if (ret < 0) { + _E("Failed to get max brightness: %d", ret); + } + + return ret; +} + +/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ +int display_backlight_get_normalized_brightness(int raw_brightness, + int *normalized_brightness) +{ + int quotient, remainder; + int max, ret; + + if (!normalized_brightness) + return -EINVAL; + + ret = display_backlight_get_max_brightness(&max); + if (ret < 0) { + _E("Failed to get max brightness."); + return ret; + } + + /** + * Thus the brightness value need to be calculated using real brightness. + * ex) Let's suppose that the maximum brightness of driver is 255. + * case 1) When the user sets the brightness to 41, + * real brightness is + * 41 * 255 / 100 = 104.55 = 104 (rounded off) + * case 2) When the user gets the brightness, + * the driver returns the brightness 104. + * Thus the brightness to users is + * 104 * 100 / 255 = 40.7843.... = 41 (rounded up) + */ + quotient = raw_brightness * 100 / max; + remainder = raw_brightness * 100 % max; + if (remainder > 0) + quotient++; + + *normalized_brightness = quotient; + return 0; +} \ No newline at end of file diff --git a/src/display/display-backlight.h b/src/display/display-backlight.h new file mode 100644 index 0000000..cbf663c --- /dev/null +++ b/src/display/display-backlight.h @@ -0,0 +1,26 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DISPLAY_BACKLIGHT_H__ +#define __DISPLAY_BACKLIGHT_H__ + +int display_backlight_get_max_brightness(int *max_brightness); +int display_backlight_get_normalized_brightness(int raw_brightness, + int *normalized_brightness); + +#endif /* __DISPLAY_BACKLIGHT_H__ */ \ No newline at end of file -- 2.7.4 From a7997024e7e06e89c27761a3739632d21c9b8f7a Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 17 Feb 2023 16:33:47 +0900 Subject: [PATCH 16/16] display: Add display_panel_set_dpms_state function To move plugin functions without plugin dependency, this temporary function is needed. int display_panel_set_dpms_state(int dpms_on, enum device_flags flags) -> This function replaces the bl_onoff function of plugins. Change-Id: I0720781ba1cb2afeda5e461c1d979d4a9f2ceb4d Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/device-interface.c | 25 +++++-------------------- plugins/mobile/display/device-interface.c | 25 +++++-------------------- plugins/tv/display/device-interface.c | 25 +++++-------------------- plugins/wearable/display/device-interface.c | 25 +++++-------------------- src/display/display-panel.c | 21 ++++++++++++++++++++- src/display/display-panel.h | 3 +++ 6 files changed, 43 insertions(+), 81 deletions(-) diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 4e7b22d..8e9ad6b 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -46,6 +46,7 @@ #include "display/display.h" #include "display/display-lock.h" #include "display/display-backlight.h" +#include "display/display-panel.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -94,22 +95,6 @@ void dpms_set_running_state(int val) dpms_running_state = val; } -static int bl_onoff(int on, enum device_flags flags) -{ - dpms_set_state(on); - -#ifdef ENABLE_PM_LOG - if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); - else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); - else - pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); -#endif - - return 0; -} - static int bl_brt(int brightness, int delay) { int ret = -1; @@ -227,7 +212,7 @@ static int backlight_on(enum device_flags flags) _I("[DPMS XLIB Backlight] LCD on %#x cnt:%d", flags, cnt); cnt++; - ret = bl_onoff(DPMS_ON, flags); + ret = display_panel_set_dpms_state(DPMS_ON, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif @@ -255,9 +240,9 @@ static int backlight_off(enum device_flags flags) LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); if (flags & FORCE_OFF_MODE) - ret = bl_onoff(DPMS_FORCE_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_FORCE_OFF, flags); else - ret = bl_onoff(DPMS_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); @@ -354,7 +339,7 @@ static int backlight_standby(int force) if ((dpms_get_cached_state() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY, 0); + ret = display_panel_set_dpms_state(DPMS_STANDBY, 0); } return ret; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 9bfb003..8ee2752 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -45,6 +45,7 @@ #include "display/display.h" #include "display/display-lock.h" #include "display/display-backlight.h" +#include "display/display-panel.h" #include "power/power-boot.h" #include "power/power-suspend.h" @@ -93,22 +94,6 @@ void dpms_set_running_state(int val) dpms_running_state = val; } -static int bl_onoff(int on, enum device_flags flags) -{ - dpms_set_state(on); - -#ifdef ENABLE_PM_LOG - if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); - else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); - else - pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); -#endif - - return 0; -} - static int bl_brt(int brightness, int delay) { int ret = -1; @@ -226,7 +211,7 @@ static int backlight_on(enum device_flags flags) _I("[DPMS XLIB Backlight] LCD on %#x cnt:%d", flags, cnt); cnt++; - ret = bl_onoff(DPMS_ON, flags); + ret = display_panel_set_dpms_state(DPMS_ON, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif @@ -254,9 +239,9 @@ static int backlight_off(enum device_flags flags) LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); if (flags & FORCE_OFF_MODE) - ret = bl_onoff(DPMS_FORCE_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_FORCE_OFF, flags); else - ret = bl_onoff(DPMS_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); @@ -353,7 +338,7 @@ static int backlight_standby(int force) if ((dpms_get_cached_state() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY, 0); + ret = display_panel_set_dpms_state(DPMS_STANDBY, 0); } return ret; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 89081e0..41eea37 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -42,6 +42,7 @@ #include "vconf.h" #include "core.h" #include "display/display-dpms.h" +#include "display/display-panel.h" #include "display/display.h" #include "display/display-backlight.h" #include "power/power-suspend.h" @@ -94,22 +95,6 @@ void dpms_set_running_state(int val) dpms_running_state = val; } -static int bl_onoff(int on, enum device_flags flags) -{ - dpms_set_state(on); - -#ifdef ENABLE_PM_LOG - if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); - else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); - else - pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); -#endif - - return 0; -} - static int bl_brt(int brightness, int delay) { int ret = -1; @@ -227,7 +212,7 @@ static int backlight_on(enum device_flags flags) _I("[DPMS XLIB Backlight] LCD on %#x cnt:%d", flags, cnt); cnt++; - ret = bl_onoff(DPMS_ON, flags); + ret = display_panel_set_dpms_state(DPMS_ON, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif @@ -255,9 +240,9 @@ static int backlight_off(enum device_flags flags) LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); if (flags & FORCE_OFF_MODE) - ret = bl_onoff(DPMS_FORCE_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_FORCE_OFF, flags); else - ret = bl_onoff(DPMS_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); @@ -354,7 +339,7 @@ static int backlight_standby(int force) if ((dpms_get_cached_state() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY, 0); + ret = display_panel_set_dpms_state(DPMS_STANDBY, 0); } return ret; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index e9d442a..4cd6cb1 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -45,6 +45,7 @@ #include "display/display.h" #include "display/display-lock.h" #include "display/display-backlight.h" +#include "display/display-panel.h" #include "battery-monitor.h" #include "battery/power-supply.h" #include "power/power-suspend.h" @@ -106,22 +107,6 @@ void dpms_set_running_state(int val) dpms_running_state = val; } -static int bl_onoff(int on, enum device_flags flags) -{ - dpms_set_state(on); - -#ifdef ENABLE_PM_LOG - if (on == DPMS_ON) - pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); - else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) - pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); - else - pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); -#endif - - return 0; -} - static int bl_brt(int brightness, int delay) { int ret = -1; @@ -238,7 +223,7 @@ static int backlight_on(enum device_flags flags) _I("[DPMS XLIB Backlight] LCD on %#x cnt:%d", flags, cnt); cnt++; - ret = bl_onoff(DPMS_ON, flags); + ret = display_panel_set_dpms_state(DPMS_ON, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state()); #endif @@ -266,9 +251,9 @@ static int backlight_off(enum device_flags flags) LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); if (flags & FORCE_OFF_MODE) - ret = bl_onoff(DPMS_FORCE_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_FORCE_OFF, flags); else - ret = bl_onoff(DPMS_OFF, flags); + ret = display_panel_set_dpms_state(DPMS_OFF, flags); #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state()); @@ -365,7 +350,7 @@ static int backlight_standby(int force) if ((dpms_get_cached_state() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY, 0); + ret = display_panel_set_dpms_state(DPMS_STANDBY, 0); } return ret; diff --git a/src/display/display-panel.c b/src/display/display-panel.c index 9d65416..ec7d96d 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -17,14 +17,33 @@ */ #include "shared/log.h" -#include "display-panel.h" +#include "power/power-suspend.h" #include "display.h" +#include "display-dpms.h" +#include "display-panel.h" #define MAX_WHITE_BALANCE_GAIN 2047 #define MAX_WHITE_BALANCE_OFFSET 2047 #define DEFAULT_WHITE_BALANCE_GAIN 1024 #define DEFAULT_WHITE_BALANCE_OFFSET 0 +/* 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) +{ + dpms_set_state(dpms_on); + +#ifdef ENABLE_PM_LOG + if (dpms_on == DPMS_ON) + pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state()); + else if (dpms_on == DPMS_OFF || dpms_on == DPMS_FORCE_OFF) + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state()); + else + pm_history_save(PM_LOG_LCD_CONTROL_FAIL, dpms_on); +#endif + + return 0; +} + int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value) { diff --git a/src/display/display-panel.h b/src/display/display-panel.h index efe6e45..7ca5d63 100644 --- a/src/display/display-panel.h +++ b/src/display/display-panel.h @@ -21,6 +21,9 @@ #include +#include "shared/devices.h" + +int display_panel_set_dpms_state(int dpms_on, enum device_flags flags); int display_panel_set_white_balance(enum hal_display_white_balance white_balance_type, int value); int display_panel_get_white_balance(enum hal_display_white_balance white_balance_type, int* out_val); -- 2.7.4