From 8764d7be2840fa9266c0ea9ba5c2ea06c9421069 Mon Sep 17 00:00:00 2001 From: M4xw Date: Thu, 29 Nov 2018 18:42:44 +0100 Subject: [PATCH] [LIBNX] Implement Over-/Downclocking and minor fixes --- configuration.c | 10 +++ configuration.h | 2 + frontend/drivers/platform_switch.c | 62 +++++++++++--- intl/msg_hash_chs.h | 2 + intl/msg_hash_de.h | 2 + intl/msg_hash_es.h | 2 + intl/msg_hash_lbl.h | 2 + intl/msg_hash_pt_br.h | 2 + intl/msg_hash_us.h | 2 + lakka.h | 63 +-------------- menu/cbs/menu_cbs_deferred_push.c | 7 +- menu/cbs/menu_cbs_ok.c | 21 ++++- menu/cbs/menu_cbs_sublabel.c | 9 ++- menu/cbs/menu_cbs_title.c | 21 +++-- menu/drivers/ozone/ozone.c | 4 +- menu/drivers/ozone/ozone_texture.c | 3 + menu/drivers/xmb.c | 7 +- menu/menu_displaylist.c | 30 ++++--- menu/menu_displaylist.h | 2 + menu/menu_driver.h | 2 + menu/menu_setting.c | 6 +- msg_hash.h | 3 +- switch_performance_profiles.h | 125 +++++++++++++++++++++++++++++ 23 files changed, 289 insertions(+), 100 deletions(-) create mode 100644 switch_performance_profiles.h diff --git a/configuration.c b/configuration.c index db570b0d95..981ba24638 100644 --- a/configuration.c +++ b/configuration.c @@ -1679,6 +1679,10 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, SETTING_UINT("video_record_threads", &settings->uints.video_record_threads, true, video_record_threads, false); +#ifdef HAVE_LIBNX + SETTING_UINT("libnx_overclock", &settings->uints.libnx_overclock, true, SWITCH_DEFAULT_CPU_PROFILE, false); +#endif + *size = count; return tmp; @@ -3133,6 +3137,12 @@ static bool config_load_file(const char *path, bool set_defaults, strlcpy(settings->arrays.menu_driver, "rgui", sizeof(settings->arrays.menu_driver)); #endif +#ifdef HAVE_LIBNX + // Apply initial clocks + extern void libnx_apply_overclock(); + libnx_apply_overclock(); +#endif + frontend_driver_set_sustained_performance_mode(settings->bools.sustained_performance_mode); recording_driver_update_streaming_url(); diff --git a/configuration.h b/configuration.h index f2c71cb15c..456fe8b953 100644 --- a/configuration.h +++ b/configuration.h @@ -446,6 +446,8 @@ typedef struct settings unsigned window_position_height; unsigned video_record_threads; + + unsigned libnx_overclock; } uints; struct diff --git a/frontend/drivers/platform_switch.c b/frontend/drivers/platform_switch.c index c90226cc79..59e38b6d44 100644 --- a/frontend/drivers/platform_switch.c +++ b/frontend/drivers/platform_switch.c @@ -13,6 +13,9 @@ #ifdef HAVE_LIBNX #include +#include "../../switch_performance_profiles.h" +#include "../../configuration.h" +#include #else #include #include @@ -70,18 +73,46 @@ static AppletHookCookie applet_hook_cookie; extern bool nxlink_connected; #endif -static void on_applet_hook(AppletHookType hook, void* param) { +void libnx_apply_overclock() { + const size_t profiles_count = sizeof(SWITCH_CPU_PROFILES) / sizeof(SWITCH_CPU_PROFILES[1]); + if (config_get_ptr()->uints.libnx_overclock >= 0 && config_get_ptr()->uints.libnx_overclock <= profiles_count) + pcvSetClockRate(PcvModule_Cpu, SWITCH_CPU_SPEEDS_VALUES[config_get_ptr()->uints.libnx_overclock]); +} + +static void on_applet_hook(AppletHookType hook, void *param) { + u32 performance_mode; + AppletFocusState focus_state; + /* Exit request */ - if(hook == AppletHookType_OnExitRequest) { + switch (hook) + { + case AppletHookType_OnExitRequest: RARCH_LOG("Got AppletHook OnExitRequest, exiting.\n"); retroarch_main_quit(); - } - /* Focus state*/ - else if (hook == AppletHookType_OnFocusState) { - AppletFocusState focus_state = appletGetFocusState(); - RARCH_LOG("Got AppletHook OnFocusState - new focus state is %d\n", focus_state); + break; + /* Focus state*/ + case AppletHookType_OnFocusState: + focus_state = appletGetFocusState(); + RARCH_LOG("Got AppletHook OnFocusState - new focus state is %d\n", focus_state); platform_switch_has_focus = focus_state == AppletFocusState_Focused; + if(!platform_switch_has_focus) { + pcvSetClockRate(PcvModule_Cpu, 1020000000); + } else { + libnx_apply_overclock(); + } + break; + + /* Performance mode */ + case AppletHookType_OnPerformanceMode: + // 0 == Handheld, 1 == Docked + // Since CPU doesn't change we just re-apply + performance_mode = appletGetPerformanceMode(); + libnx_apply_overclock(); + break; + + default: + break; } } @@ -211,6 +242,8 @@ static void frontend_switch_deinit(void *data) #ifdef HAVE_LIBNX nifmExit(); + pcvSetClockRate(PcvModule_Cpu, 1020000000); // Always 1020 MHz, unless SDEV + pcvExit(); #if defined(SWITCH) && defined(NXLINK) socketExit(); #endif @@ -235,7 +268,7 @@ static void frontend_switch_deinit(void *data) #ifdef HAVE_LIBNX static void frontend_switch_exec(const char *path, bool should_load_game) { - char game_path[PATH_MAX]; + char game_path[PATH_MAX-4]; const char *arg_data[3]; char error_string[200 + PATH_MAX]; int args = 0; @@ -623,16 +656,20 @@ static void frontend_switch_shutdown(bool unused) /* runloop_get_system_info isnt initialized that early.. */ extern void retro_get_system_info(struct retro_system_info *info); + static void frontend_switch_init(void *data) { + (void)data; #ifdef HAVE_LIBNX nifmInitialize(); + pcvInitialize(); + appletLockExit(); appletHook(&applet_hook_cookie, on_applet_hook, NULL); - appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend); + #ifndef HAVE_OPENGL /* Init Resolution before initDefault */ gfxInitResolution(1280, 720); @@ -643,7 +680,10 @@ static void frontend_switch_init(void *data) gfxConfigureTransform(0); #endif /* HAVE_OPENGL */ - appletInitializeGamePlayRecording(); + bool recording_supported = false; + appletIsGamePlayRecordingSupported(&recording_supported); + if(recording_supported) + appletInitializeGamePlayRecording(); #ifdef NXLINK socketInitializeDefault(); @@ -788,6 +828,8 @@ static enum frontend_powerstate frontend_switch_get_powerstate(int *seconds, int case ChargerType_Charger: case ChargerType_Usb: return FRONTEND_POWERSTATE_CHARGING; + default: + break; } return FRONTEND_POWERSTATE_NO_SOURCE; diff --git a/intl/msg_hash_chs.h b/intl/msg_hash_chs.h index 13f6fbb55a..328c18d273 100644 --- a/intl/msg_hash_chs.h +++ b/intl/msg_hash_chs.h @@ -15,6 +15,8 @@ MSG_HASH( MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, "调整 Switch 的屏幕亮度" ) +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH( MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, "CPU 超频" diff --git a/intl/msg_hash_de.h b/intl/msg_hash_de.h index 3a6c051535..48ab449e73 100644 --- a/intl/msg_hash_de.h +++ b/intl/msg_hash_de.h @@ -15,6 +15,8 @@ MSG_HASH( MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, "Anpassen der Switch Bildschirmhelligkeit" ) +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH( MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, "CPU Übertakten" diff --git a/intl/msg_hash_es.h b/intl/msg_hash_es.h index d60e909750..f3e9d8b2d3 100644 --- a/intl/msg_hash_es.h +++ b/intl/msg_hash_es.h @@ -15,6 +15,8 @@ MSG_HASH( MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, "Ajusta el brillo de la pantalla" ) +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH( MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, "CPU Overclock" diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index c9cb27d08f..d3d3be35a9 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -3,6 +3,8 @@ MSG_HASH(MENU_ENUM_LABEL_SWITCH_GPU_PROFILE, "switch_gpu_profile") MSG_HASH(MENU_ENUM_LABEL_SWITCH_BACKLIGHT_CONTROL, "switch_backlight_control") +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH(MENU_ENUM_LABEL_SWITCH_CPU_PROFILE, "switch_cpu_profile") #endif diff --git a/intl/msg_hash_pt_br.h b/intl/msg_hash_pt_br.h index c63c4404f9..0dd39c521a 100644 --- a/intl/msg_hash_pt_br.h +++ b/intl/msg_hash_pt_br.h @@ -15,6 +15,8 @@ MSG_HASH( MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, "Aumentar ou diminuir o brilho da tela do Switch" ) +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH( MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, "Overclock da CPU" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index fa0017737a..6fa546fe67 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -15,6 +15,8 @@ MSG_HASH( MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, "Increase or decrease the Switch screen brightness" ) +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MSG_HASH( MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, "CPU Overclock" diff --git a/lakka.h b/lakka.h index 0447aa6ed5..2b6073ead4 100644 --- a/lakka.h +++ b/lakka.h @@ -24,67 +24,6 @@ #define LAKKA_UPDATE_DIR "/storage/.update/" #define LAKKA_CONNMAN_DIR "/storage/.cache/connman/" -#ifdef HAVE_LAKKA_SWITCH -static char* SWITCH_GPU_PROFILES[] = { - "docked-overclock-3", - "docked-overclock-2", - "docked-overclock-1", - "docked", - "non-docked-overclock-5", - "non-docked-overclock-4", - "non-docked-overclock-3", - "non-docked-overclock-2", - "non-docked-overclock-1", - "non-docked", - "non-docked-underclock-1", - "non-docked-underclock-2", - "non-docked-underclock-3", -}; - -static char* SWITCH_GPU_SPEEDS[] = { - "998 Mhz", - "921 Mhz", - "844 Mhz", - "768 Mhz", - "691 Mhz", - "614 Mhz", - "537 Mhz", - "460 Mhz", - "384 Mhz", - "307 Mhz", - "230 Mhz", - "153 Mhz", - "76 Mhz" -}; - -static int SWITCH_BRIGHTNESS[] = { - 10, - 20, - 30, - 40, - 50, - 60, - 70, - 80, - 90, - 100 -}; - -static char* SWITCH_CPU_PROFILES[] = { - "overclock-4", - "overclock-3", - "overclock-2", - "overclock-1", - "default", -}; - -static char* SWITCH_CPU_SPEEDS[] = { - "1912 MHz", - "1734 MHz", - "1530 MHz", - "1224 MHz", - "1020 MHz" -}; -#endif +#include "switch_performance_profiles.h" #endif diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 7f8d37d4cc..79e1aee9b2 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -187,10 +187,13 @@ generic_deferred_push(deferred_push_core_content_dirs_subdir_list, DISPLAYLIST_ generic_deferred_push(deferred_push_lakka_list, DISPLAYLIST_LAKKA) #endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) +generic_deferred_push(deferred_push_switch_cpu_profile, DISPLAYLIST_SWITCH_CPU_PROFILE) +#endif + #ifdef HAVE_LAKKA_SWITCH generic_deferred_push(deferred_push_switch_gpu_profile, DISPLAYLIST_SWITCH_GPU_PROFILE) generic_deferred_push(deferred_push_switch_backlight_control, DISPLAYLIST_SWITCH_BACKLIGHT_CONTROL) -generic_deferred_push(deferred_push_switch_cpu_profile, DISPLAYLIST_SWITCH_CPU_PROFILE) #endif static int deferred_push_cursor_manager_list_deferred( @@ -906,6 +909,8 @@ static int menu_cbs_init_bind_deferred_push_compare_label( { BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_switch_backlight_control); } +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) else if (strstr(label, msg_hash_to_str(MENU_ENUM_LABEL_SWITCH_CPU_PROFILE))) { diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index a4d9230bce..0218028835 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2524,25 +2524,34 @@ static int action_ok_deferred_list_stub(const char *path, return 0; } -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) static int action_ok_set_switch_cpu_profile(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { char* profile_name = SWITCH_CPU_PROFILES[entry_idx]; - char command[PATH_MAX_LENGTH] = {0}; +#ifdef HAVE_LAKKA_SWITCH snprintf(command, sizeof(command), "cpu-profile set %s", profile_name); system(command); - snprintf(command, sizeof(command), "Current profile set to %s", profile_name); - +#else + config_get_ptr()->uints.libnx_overclock = entry_idx; + + unsigned profile_clock = SWITCH_CPU_SPEEDS_VALUES[entry_idx]; + pcvSetClockRate(PcvModule_Cpu, (u32)profile_clock); + snprintf(command, sizeof(command), "Current Clock set to %i", profile_clock); +#endif + runloop_msg_queue_push(command, 1, 90, true); return menu_cbs_exit(); } +#endif + +#ifdef HAVE_LAKKA_SWITCH static int action_ok_set_switch_gpu_profile(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) @@ -5187,6 +5196,8 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs, #ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: case MENU_ENUM_LABEL_SWITCH_BACKLIGHT_CONTROL: +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: #endif BIND_ACTION_OK(cbs, action_ok_push_default); @@ -5640,6 +5651,8 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs, case MENU_SET_SWITCH_BRIGHTNESS: BIND_ACTION_OK(cbs, action_ok_set_switch_backlight); break; +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case MENU_SET_SWITCH_CPU_PROFILE: BIND_ACTION_OK(cbs, action_ok_set_switch_cpu_profile); break; diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 81347b8267..2a95e163d8 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -485,9 +485,12 @@ default_sublabel_macro(action_bind_sublabel_show_wimp, #endif default_sublabel_macro(action_bind_sublabel_discord_allow, MENU_ENUM_SUBLABEL_DISCORD_ALLOW) +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) +default_sublabel_macro(action_bind_sublabel_switch_cpu_profile, MENU_ENUM_SUBLABEL_SWITCH_CPU_PROFILE) +#endif + #ifdef HAVE_LAKKA_SWITCH default_sublabel_macro(action_bind_sublabel_switch_gpu_profile, MENU_ENUM_SUBLABEL_SWITCH_GPU_PROFILE) -default_sublabel_macro(action_bind_sublabel_switch_cpu_profile, MENU_ENUM_SUBLABEL_SWITCH_CPU_PROFILE) default_sublabel_macro(action_bind_sublabel_switch_backlight_control, MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL) #endif @@ -2036,10 +2039,12 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_show_wimp); break; #endif -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_switch_cpu_profile); break; +#endif +#ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_switch_gpu_profile); break; diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index b3dc2440b8..9b3e3be0b7 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -210,9 +210,12 @@ default_title_copy_macro(action_get_title_cheevos_list, MENU_ENUM_LABE default_title_copy_macro(action_get_title_video_shader_parameters,MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PARAMETERS) default_title_copy_macro(action_get_title_video_shader_preset_parameters,MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_PARAMETERS) +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) +default_title_macro(action_get_title_switch_cpu_profile, MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE) +#endif + #ifdef HAVE_LAKKA_SWITCH default_title_macro(action_get_title_switch_gpu_profile, MENU_ENUM_LABEL_VALUE_SWITCH_GPU_PROFILE) -default_title_macro(action_get_title_switch_cpu_profile, MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE) default_title_macro(action_get_title_switch_backlight_control, MENU_ENUM_LABEL_VALUE_SWITCH_BACKLIGHT_CONTROL) #endif @@ -879,13 +882,15 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_LIBRETRO_INFO_PATH: BIND_ACTION_GET_TITLE(cbs, action_get_title_core_info_directory); break; +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) + case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: + BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_cpu_profile); + break; +#endif #ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_gpu_profile); break; - case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: - BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_cpu_profile); - break; case MENU_ENUM_LABEL_SWITCH_BACKLIGHT_CONTROL: BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_backlight_control); break; @@ -1176,13 +1181,15 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs, case MENU_LABEL_LIBRETRO_INFO_PATH: BIND_ACTION_GET_TITLE(cbs, action_get_title_core_info_directory); break; +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) + case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: + BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_cpu_profile); + break; +#endif #ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_gpu_profile); break; - case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: - BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_cpu_profile); - break; case MENU_ENUM_LABEL_SWITCH_BACKLIGHT_CONTROL: BIND_ACTION_GET_TITLE(cbs, action_get_title_switch_backlight_control); break; diff --git a/menu/drivers/ozone/ozone.c b/menu/drivers/ozone/ozone.c index 210799e229..bcd5773854 100644 --- a/menu/drivers/ozone/ozone.c +++ b/menu/drivers/ozone/ozone.c @@ -673,10 +673,12 @@ static int ozone_list_push(void *data, void *userdata, menu_displaylist_setting(&entry); } -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) entry.enum_idx = MENU_ENUM_LABEL_SWITCH_CPU_PROFILE; menu_displaylist_setting(&entry); +#endif +#ifdef HAVE_LAKKA_SWITCH entry.enum_idx = MENU_ENUM_LABEL_SWITCH_GPU_PROFILE; menu_displaylist_setting(&entry); diff --git a/menu/drivers/ozone/ozone_texture.c b/menu/drivers/ozone/ozone_texture.c index 7af3843ee1..846682d2ed 100644 --- a/menu/drivers/ozone/ozone_texture.c +++ b/menu/drivers/ozone/ozone_texture.c @@ -211,7 +211,10 @@ menu_texture_item ozone_entries_icon_get_texture(ozone_handle_t *ozone, return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_UI]; #ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: + return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_POWER]; #endif case MENU_ENUM_LABEL_POWER_MANAGEMENT_SETTINGS: return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_POWER]; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index d6d83e79f7..23561e1651 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2450,7 +2450,10 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb, return xmb->textures.list[XMB_TEXTURE_UI]; #ifdef HAVE_LAKKA_SWITCH case MENU_ENUM_LABEL_SWITCH_GPU_PROFILE: +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case MENU_ENUM_LABEL_SWITCH_CPU_PROFILE: + return xmb->textures.list[XMB_TEXTURE_POWER]; #endif case MENU_ENUM_LABEL_POWER_MANAGEMENT_SETTINGS: return xmb->textures.list[XMB_TEXTURE_POWER]; @@ -5714,10 +5717,12 @@ static int xmb_list_push(void *data, void *userdata, menu_displaylist_setting(&entry); } -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) entry.enum_idx = MENU_ENUM_LABEL_SWITCH_CPU_PROFILE; menu_displaylist_setting(&entry); +#endif +#ifdef HAVE_LAKKA_SWITCH entry.enum_idx = MENU_ENUM_LABEL_SWITCH_GPU_PROFILE; menu_displaylist_setting(&entry); diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index d28adcf9b3..e314c8ac54 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -51,6 +51,11 @@ #include "../../lakka.h" #endif +#ifdef HAVE_LIBNX +#include +#include "../../switch_performance_profiles.h" +#endif + #if defined(__linux__) || (defined(BSD) && !defined(__MACH__)) #include "../frontend/drivers/platform_unix.h" #endif @@ -4265,7 +4270,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist switch (type) { -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case DISPLAYLIST_SWITCH_CPU_PROFILE: { unsigned i; @@ -4274,17 +4279,22 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist FILE *profile = NULL; const size_t profiles_count = sizeof(SWITCH_CPU_PROFILES)/sizeof(SWITCH_CPU_PROFILES[1]); - runloop_msg_queue_push("Warning : extented overclocking can damage the Switch", 1, 90, true); + runloop_msg_queue_push("Warning : extended overclocking can damage the Switch", 1, 90, true); + menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); + +#ifdef HAVE_LAKKA_SWITCH profile = popen("cpu-profile get", "r"); fgets(current_profile, PATH_MAX_LENGTH, profile); pclose(profile); + - menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); - - snprintf(text, sizeof(text), - "Current profile : %s", current_profile); - + snprintf(text, sizeof(text), "Current profile : %s", current_profile); +#else + u32 currentClock = 0; + pcvGetClockRate(PcvModule_Cpu, ¤tClock); + snprintf(text, sizeof(text), "Current Clock : %i", currentClock); +#endif menu_entries_append_enum(info->list, text, "", @@ -4313,6 +4323,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist break; } +#if defined(HAVE_LAKKA_SWITCH) case DISPLAYLIST_SWITCH_GPU_PROFILE: { unsigned i; @@ -4330,7 +4341,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); snprintf(text, sizeof(text), "Current profile : %s", current_profile); - + menu_entries_append_enum(info->list, text, "", @@ -4383,7 +4394,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist break; } -#endif +#endif // HAVE_LAKKA_SWITCH +#endif // HAVE_LAKKA_SWITCH || HAVE_LIBNX case DISPLAYLIST_MUSIC_LIST: { char combined_path[PATH_MAX_LENGTH]; diff --git a/menu/menu_displaylist.h b/menu/menu_displaylist.h index a2a71f2af2..4d8f165351 100644 --- a/menu/menu_displaylist.h +++ b/menu/menu_displaylist.h @@ -183,6 +183,8 @@ enum menu_displaylist_ctl_state #ifdef HAVE_LAKKA_SWITCH DISPLAYLIST_SWITCH_GPU_PROFILE, DISPLAYLIST_SWITCH_BACKLIGHT_CONTROL, +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) DISPLAYLIST_SWITCH_CPU_PROFILE, #endif DISPLAYLIST_PENDING_CLEAR diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 0e97b73a3f..6487d37248 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -245,6 +245,8 @@ enum menu_settings_type #ifdef HAVE_LAKKA_SWITCH MENU_SET_SWITCH_GPU_PROFILE, MENU_SET_SWITCH_BRIGHTNESS, +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MENU_SET_SWITCH_CPU_PROFILE, #endif diff --git a/menu/menu_setting.c b/menu/menu_setting.c index c14112d8ee..daf67f6100 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -3750,8 +3750,7 @@ static bool setting_append_list( menu_settings_list_current_add_cmd(list, list_info, CMD_EVENT_QUIT); #endif -#if defined(HAVE_LAKKA) -#ifdef HAVE_LAKKA_SWITCH +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) CONFIG_ACTION( list, list_info, MENU_ENUM_LABEL_SWITCH_CPU_PROFILE, @@ -3759,7 +3758,10 @@ static bool setting_append_list( &group_info, &subgroup_info, parent_group); +#endif +#if defined(HAVE_LAKKA) +#ifdef HAVE_LAKKA_SWITCH CONFIG_ACTION( list, list_info, MENU_ENUM_LABEL_SWITCH_GPU_PROFILE, diff --git a/msg_hash.h b/msg_hash.h index b1565e79a0..326c32c92e 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -2172,7 +2172,8 @@ enum msg_hash_enums MENU_ENUM_LABEL_SWITCH_BACKLIGHT_CONTROL, MENU_ENUM_LABEL_VALUE_SWITCH_BACKLIGHT_CONTROL, MENU_ENUM_SUBLABEL_SWITCH_BACKLIGHT_CONTROL, - +#endif +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) MENU_ENUM_LABEL_SWITCH_CPU_PROFILE, MENU_ENUM_LABEL_VALUE_SWITCH_CPU_PROFILE, MENU_ENUM_SUBLABEL_SWITCH_CPU_PROFILE, diff --git a/switch_performance_profiles.h b/switch_performance_profiles.h new file mode 100644 index 0000000000..316e0bc122 --- /dev/null +++ b/switch_performance_profiles.h @@ -0,0 +1,125 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2018-2018 - Natinusala + * Copyright (C) 2018-2018 - M4xw + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __SWITCH_PERFORMANCE_PROFILES_H +#define __SWITCH_PERFORMANCE_PROFILES_H + +#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) +#ifdef HAVE_LAKKA_SWITCH +static char *SWITCH_GPU_PROFILES[] = { + "docked-overclock-3", + "docked-overclock-2", + "docked-overclock-1", + "docked", + "non-docked-overclock-5", + "non-docked-overclock-4", + "non-docked-overclock-3", + "non-docked-overclock-2", + "non-docked-overclock-1", + "non-docked", + "non-docked-underclock-1", + "non-docked-underclock-2", + "non-docked-underclock-3", +}; + +static char *SWITCH_GPU_SPEEDS[] = { + "998 Mhz", + "921 Mhz", + "844 Mhz", + "768 Mhz", + "691 Mhz", + "614 Mhz", + "537 Mhz", + "460 Mhz", + "384 Mhz", + "307 Mhz", + "230 Mhz", + "153 Mhz", + "76 Mhz"}; + +static int SWITCH_BRIGHTNESS[] = { + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100}; +#endif + +static char *SWITCH_CPU_PROFILES[] = { +#ifndef HAVE_LIBNX + "overclock-4", + "overclock-3", + "overclock-2", + "overclock-1", + "default", +#else + "Maximum Performance", + "High Performance", + "Boost Performance", + "Stock Performance", + "Powersaving Mode 1", + "Powersaving Mode 2", + "Powersaving Mode 3", +#endif +}; + +#define SWITCH_DEFAULT_CPU_PROFILE 3 /* Stock Performance */ +#define LIBNX_MAX_CPU_PROFILE 0 /* Max Performance */ + +static char *SWITCH_CPU_SPEEDS[] = { +#ifndef HAVE_LIBNX + "1912 MHz", + "1734 MHz", + "1530 MHz", + "1224 MHz", + "1020 MHz" +#else + "1785 MHz", + "1581 MHz", + "1224 MHz", + "1020 MHz", + "918 MHz", + "816 MHz", + "714 MHz" +#endif +}; + +static unsigned SWITCH_CPU_SPEEDS_VALUES[] = { +#ifndef HAVE_LIBNX + 1912000000, + 1734000000, + 1530000000, + 1224000000, + 1020000000 +#else + 1785000000, + 1581000000, + 1224000000, + 1020000000, + 918000000, + 816000000, + 714000000 +#endif +}; + +#endif + +#endif \ No newline at end of file