From cf175fc00d3b1bfc93386ff2112ce10c97dae5bc Mon Sep 17 00:00:00 2001 From: CTCaer Date: Wed, 2 Dec 2020 02:07:31 +0200 Subject: [PATCH] nyx: Add alternate power saving modes T210: By default max power savings is enabled. By changing `newpowersave=` to 0, it reverts to the old behavior of smaller power savings. This was added to mitigate some strange DRAM chips, hanging from constant frequency change of a 800 MHz - 1600 MHz back and forth. T210B01: Defaults to a simple loop with no power savings. That's because of untrained ram. --- nyx/nyx_gui/config.c | 4 ++++ nyx/nyx_gui/config.h | 1 + nyx/nyx_gui/frontend/gui.c | 40 +++++++++++++++++++++++++++++++------- nyx/nyx_gui/nyx.c | 2 ++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index 0a85090..944ac23 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -64,6 +64,7 @@ void set_nyx_default_configuration() n_cfg.verification = 1; n_cfg.ums_emmc_rw = 0; n_cfg.jc_disable = 0; + n_cfg.new_powersave = 1; } int create_config_entry() @@ -205,6 +206,9 @@ int create_nyx_config_entry() f_puts("\njcdisable=", &fp); itoa(n_cfg.jc_disable, lbuf, 10); f_puts(lbuf, &fp); + f_puts("\nnewpowersave=", &fp); + itoa(n_cfg.new_powersave, lbuf, 10); + f_puts(lbuf, &fp); f_puts("\n", &fp); f_close(&fp); diff --git a/nyx/nyx_gui/config.h b/nyx/nyx_gui/config.h index 1e2f60f..eb8cb66 100644 --- a/nyx/nyx_gui/config.h +++ b/nyx/nyx_gui/config.h @@ -51,6 +51,7 @@ typedef struct _nyx_config u32 verification; u32 ums_emmc_rw; u32 jc_disable; + u32 new_powersave; } nyx_config; void set_default_configuration(); diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 2e922ee..195486a 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -2235,6 +2235,30 @@ static void _nyx_main_menu(lv_theme_t * th) } } +static void _nyx_gui_loop_powersave_ram() +{ + // Saves 280 mW. + while (true) + { + minerva_change_freq(FREQ_1600); // Takes 295 us. + + lv_task_handler(); + + minerva_change_freq(FREQ_800); // Takes 80 us. + } +} + +static void _nyx_gui_loop_powersave_cpu() +{ + // Saves 75 mW. + while (true) + { + lv_task_handler(); + + bpmp_usleep(HALT_COP_MAX_CNT); // Takes 200 us. + } +} + void nyx_load_and_run() { memset(&system_tasks, 0, sizeof(system_maintenance_tasks_t)); @@ -2293,13 +2317,15 @@ void nyx_load_and_run() lv_task_once(task_run_sd_errors); } - while (true) + // Gui loop. + if (h_cfg.t210b01) { - minerva_change_freq(FREQ_1600); // Takes 295us. - - lv_task_handler(); - - minerva_change_freq(FREQ_800); // Takes 80us. Saves 280mW. - //bpmp_usleep(HALT_COP_MAX_CNT); // Taskes 200us. Saves 75mW. + // Minerva not supported on T210B01 yet. No power saving. + while (true) + lv_task_handler(); } + else if (n_cfg.new_powersave) + _nyx_gui_loop_powersave_ram(); // Alternate DRAM frequencies. Higher power savings. + else + _nyx_gui_loop_powersave_cpu(); // Suspend CPU. Lower power savings. } diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 25d7653..9227e96 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -280,6 +280,8 @@ void load_saved_configuration() n_cfg.ums_emmc_rw = atoi(kv->val) == 1; else if (!strcmp("jcdisable", kv->key)) n_cfg.jc_disable = atoi(kv->val) == 1; + else if (!strcmp("newpowersave", kv->key)) + n_cfg.new_powersave = atoi(kv->val) == 1; } break;