From 486ee2e582cc8d87003989adf62d68c4dac80d0c Mon Sep 17 00:00:00 2001 From: Aarron Lee Date: Sat, 7 Dec 2024 14:34:53 -0500 Subject: [PATCH] add mcu_powersave for other distros --- py_modules/advanced_options.py | 19 +++----------- py_modules/cpu_utils.py | 2 +- py_modules/device_utils.py | 9 ++++++- py_modules/devices/rog_ally.py | 46 +++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/py_modules/advanced_options.py b/py_modules/advanced_options.py index e09cd21..d6f2340 100644 --- a/py_modules/advanced_options.py +++ b/py_modules/advanced_options.py @@ -6,7 +6,6 @@ from enum import Enum from devices import rog_ally import device_utils -import json PLATFORM_PROFILE_PATH = '/sys/firmware/acpi/platform_profile' @@ -30,18 +29,6 @@ class RogAllySettings(Enum): class LegionGoSettings(Enum): CUSTOM_TDP_MODE = 'lenovoCustomTdpMode' -def is_bazzite_deck(): - IMAGE_INFO = "/usr/share/ublue-os/image-info.json" - if os.path.exists(IMAGE_INFO): - try: - with open(IMAGE_INFO, 'r') as f: - info = json.loads(f.read().strip()) - f.close() - return info.get("image-name") == "bazzite-deck" - except Exception as e: - decky_plugin.logger.error(f'{__name__} error checking bazzite image {e}') - return False - def modprobe_acpi_call(): # legion go currently requires acpi_call for using WMI to set TDP # using WMI to set TDP is safer on the Legion Go, ryzenadj is dangerous on the LGO @@ -206,7 +193,7 @@ def get_advanced_options(): 'ifFalsy': [DefaultSettings.ENABLE_TDP_CONTROL.value] } }) - if device_utils.is_rog_ally(): + if device_utils.is_rog_ally() or device_utils.is_rog_ally_x(): rog_ally_advanced_options(options) @@ -224,7 +211,7 @@ def rog_ally_advanced_options(options): 'ifFalsy': [DefaultSettings.ENABLE_TDP_CONTROL.value] } }) - if rog_ally.supports_mcu_powersave() and is_bazzite_deck(): + if rog_ally.supports_mcu_powersave(): options.append({ 'name': 'Enable Asus Extreme Powersave', 'description': 'Reduces power consumption during suspend', @@ -253,7 +240,7 @@ def gpu_control_enabled(): return get_setting(DefaultSettings.ENABLE_GPU_CONTROL.value) def handle_advanced_option_change(new_values): - if device_utils.is_rog_ally(): + if device_utils.is_rog_ally() or device_utils.is_rog_ally_x(): if rog_ally.supports_mcu_powersave(): powersave_enabled = new_values.get(RogAllySettings.USE_EXTREME_POWERSAVE.value, None) diff --git a/py_modules/cpu_utils.py b/py_modules/cpu_utils.py index 00c5f93..6df0bc7 100644 --- a/py_modules/cpu_utils.py +++ b/py_modules/cpu_utils.py @@ -84,7 +84,7 @@ def set_amd_tdp(tdp: int): LegionGoSettings.CUSTOM_TDP_MODE.value ): return legion_go.set_tdp(tdp) - elif device_utils.is_rog_ally(): + elif device_utils.is_rog_ally() or device_utils.is_rog_ally_x(): if advanced_options.get_setting(RogAllySettings.USE_PLATFORM_PROFILE.value): rog_ally.set_platform_profile(tdp) if advanced_options.get_setting(RogAllySettings.USE_WMI.value) and rog_ally.supports_wmi_tdp(): diff --git a/py_modules/device_utils.py b/py_modules/device_utils.py index 45cda24..ebbc49f 100644 --- a/py_modules/device_utils.py +++ b/py_modules/device_utils.py @@ -61,10 +61,17 @@ def get_device_name(): decky_plugin.logger.error(f'{__name__} error while trying to read device name') return DEVICE_NAME or '' +def is_rog_ally_x(): + device_name = get_device_name() + + if Devices.ROG_ALLY_X.value in device_name: + return True + return False + def is_rog_ally(): device_name = get_device_name() - if Devices.ROG_ALLY.value in device_name or Devices.ROG_ALLY_X.value in device_name: + if Devices.ROG_ALLY.value in device_name: return True return False diff --git a/py_modules/devices/rog_ally.py b/py_modules/devices/rog_ally.py index b1d0bc4..fd26536 100644 --- a/py_modules/devices/rog_ally.py +++ b/py_modules/devices/rog_ally.py @@ -4,6 +4,8 @@ import os import decky_plugin import bios_settings +import json +import device_utils PLATFORM_PROFILE_PATH = '/sys/firmware/acpi/platform_profile' @@ -121,6 +123,48 @@ def execute_bash_command(command, path): result = subprocess.run(cmd, timeout=1, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return result +def is_bazzite_deck(): + IMAGE_INFO = "/usr/share/ublue-os/image-info.json" + if os.path.exists(IMAGE_INFO): + try: + with open(IMAGE_INFO, 'r') as f: + info = json.loads(f.read().strip()) + f.close() + return info.get("image-name") == "bazzite-deck" + except Exception as e: + decky_plugin.logger.error(f'{__name__} error checking bazzite image {e}') + return False def supports_mcu_powersave(): - return os.path.exists(LEGACY_MCU_POWERSAVE_PATH) or os.path.exists(ASUS_ARMORY_MCU_POWERSAVE_PATH) \ No newline at end of file + mc_path_exists = os.path.exists(LEGACY_MCU_POWERSAVE_PATH) or os.path.exists(ASUS_ARMORY_MCU_POWERSAVE_PATH) + + if mc_path_exists: + # bazzite has it's own workaround for MCU + if is_bazzite_deck(): + return True + + # check MCU version + mc_version = get_mcu_version() + + if device_utils.is_rog_ally() and mc_version >= 319: + return True + if device_utils.is_rog_ally_x() and mc_version >= 314: + return True + + return False + +def get_mcu_version(): + command = "dmesg | grep -oP 'MCU version: \\K\\d+'" + try: + result = subprocess.run(command, shell=True, capture_output=True, text=True) + + version_str = str(result.stdout).strip() + + if (version_str == ''): + return 0 + + return int(version_str) + except Exception as e: + decky_plugin.logger.error(f'{__name__} error getting mcu version {e}') + + return 0