Skip to content

Commit

Permalink
add mcu_powersave for other distros
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed Dec 7, 2024
1 parent c1a5f54 commit 486ee2e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
19 changes: 3 additions & 16 deletions py_modules/advanced_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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',
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion py_modules/cpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
9 changes: 8 additions & 1 deletion py_modules/device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 45 additions & 1 deletion py_modules/devices/rog_ally.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
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

0 comments on commit 486ee2e

Please sign in to comment.