Skip to content

Commit

Permalink
fix(Steam Deck): add option to start PowerStation service
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Nov 11, 2023
1 parent a5a5dbb commit 616ccba
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 62 deletions.
11 changes: 11 additions & 0 deletions core/platform/actions/start_powerstation.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends PlatformAction
class_name ActionStartPowerStation

const POWERTOOLS_PATH := "/usr/share/opengamepadui/scripts/powertools"


func execute() -> void:
logger.info("Starting PowerStation")
var cmd := CommandSync.new(POWERTOOLS_PATH, ["startPowerStation"])
if cmd.execute() != OK:
logger.warn("Failed to start PowerStation: " + cmd.stdout)
8 changes: 6 additions & 2 deletions core/platform/handheld/steamdeck/steamdeck.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="HandheldPlatform" load_steps=22 format=3 uid="uid://dxiglpg3bsp34"]
[gd_resource type="Resource" script_class="HandheldPlatform" load_steps=24 format=3 uid="uid://dxiglpg3bsp34"]

[ext_resource type="Texture2D" uid="uid://cvyo2q5qjpamv" path="res://assets/images/gamepad/steamdeck/diagram.png" id="1_6n0pc"]
[ext_resource type="Script" path="res://core/platform/handheld/handheld_platform.gd" id="1_ypdva"]
Expand All @@ -8,6 +8,7 @@
[ext_resource type="Script" path="res://core/platform/actions/start_opensd.gd" id="4_whgcr"]
[ext_resource type="Script" path="res://core/systems/input/events/native_event.gd" id="5_dthup"]
[ext_resource type="Script" path="res://core/platform/handheld_event_mapping.gd" id="6_1owfd"]
[ext_resource type="Script" path="res://core/platform/actions/start_powerstation.gd" id="9_0nhq7"]

[sub_resource type="Resource" id="Resource_ltx62"]
script = ExtResource("2_2w360")
Expand Down Expand Up @@ -67,6 +68,9 @@ name = "AT Translated Set 2 keyboard"
[sub_resource type="Resource" id="Resource_2gxl0"]
script = ExtResource("4_whgcr")

[sub_resource type="Resource" id="Resource_pyd8y"]
script = ExtResource("9_0nhq7")

[resource]
script = ExtResource("1_ypdva")
key_map = Array[ExtResource("6_1owfd")]([SubResource("Resource_or71w"), SubResource("Resource_0lnfg"), SubResource("Resource_x4pu0")])
Expand All @@ -78,5 +82,5 @@ diagram = ExtResource("1_6n0pc")
icon_mappings = Array[Resource("res://core/platform/handheld/handheld_icon_mapping.gd")]([])
thermal_policy_path = ""
name = "Steam Deck"
startup_actions = Array[Resource("res://core/platform/actions/platform_action.gd")]([SubResource("Resource_2gxl0")])
startup_actions = Array[Resource("res://core/platform/actions/platform_action.gd")]([SubResource("Resource_2gxl0"), SubResource("Resource_pyd8y")])
shutdown_actions = Array[Resource("res://core/platform/actions/platform_action.gd")]([])
124 changes: 64 additions & 60 deletions rootfs/usr/share/opengamepadui/scripts/powertools
Original file line number Diff line number Diff line change
Expand Up @@ -3,116 +3,120 @@
set -eu

if [[ $EUID -ne 0 ]]; then
exec pkexec --disable-internal-agent "$0" "$@"
exec pkexec --disable-internal-agent "$0" "$@"
fi

## CPU Generics
cpuBoost(){
state=$1
/usr/bin/echo $state > /sys/devices/system/cpu/cpufreq/boost
cpuBoost() {
state=$1
/usr/bin/echo $state >/sys/devices/system/cpu/cpufreq/boost
}

cpuToggle(){
num=$1
state=$2
/usr/bin/echo $state > /sys/bus/cpu/devices/cpu${num}/online
cpuToggle() {
num=$1
state=$2
/usr/bin/echo $state >/sys/bus/cpu/devices/cpu${num}/online
}

smtToggle(){
state=$1
/usr/bin/echo $state > /sys/devices/system/cpu/smt/control
smtToggle() {
state=$1
/usr/bin/echo $state >/sys/devices/system/cpu/smt/control
}

## AMD APU
amdGpuClock(){
min_clk=$1
max_clk=$2
card=$3
/usr/bin/echo "s 0 ${min_clk}" > /sys/class/drm/${card}/device/pp_od_clk_voltage
/usr/bin/echo "s 1 ${max_clk}" > /sys/class/drm/${card}/device/pp_od_clk_voltage
/usr/bin/echo "c" > /sys/class/drm/${card}/device/pp_od_clk_voltage
amdGpuClock() {
min_clk=$1
max_clk=$2
card=$3
/usr/bin/echo "s 0 ${min_clk}" >/sys/class/drm/${card}/device/pp_od_clk_voltage
/usr/bin/echo "s 1 ${max_clk}" >/sys/class/drm/${card}/device/pp_od_clk_voltage
/usr/bin/echo "c" >/sys/class/drm/${card}/device/pp_od_clk_voltage
}

ryzenadjLong(){
cmd=$1
val=$2
/usr/bin/ryzenadj $cmd $val
ryzenadjLong() {
cmd=$1
val=$2
/usr/bin/ryzenadj $cmd $val
}

ryzenadjShort(){
cmd=$1
/usr/bin/ryzenadj $cmd
ryzenadjShort() {
cmd=$1
/usr/bin/ryzenadj $cmd
}

setAmdPerfLevelValue() { # set power_dpm_force_performace_level mode
mode=$1
card=$2
/usr/bin/echo $mode > /sys/class/drm/${card}/device/power_dpm_force_performance_level
mode=$1
card=$2
/usr/bin/echo $mode >/sys/class/drm/${card}/device/power_dpm_force_performance_level
}

setAmdPerfLevelWrite() { # set power_dpm_force_performace_level write
card=$1
/usr/bin/chmod a+w /sys/class/drm/${card}/device/power_dpm_force_performance_level
card=$1
/usr/bin/chmod a+w /sys/class/drm/${card}/device/power_dpm_force_performance_level
}

setThermalPolicy(){
mode=$1
/usr/bin/echo $mode > /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy
setThermalPolicy() {
mode=$1
/usr/bin/echo $mode >/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy
}

## INTEL iGPU
# Package TDP Control
setRapl(){
power_type=$1
val=$2
/usr/bin/echo $val > /sys/class/powercap/intel-rapl/intel-rapl:0/${power_type}
setRapl() {
power_type=$1
val=$2
/usr/bin/echo $val >/sys/class/powercap/intel-rapl/intel-rapl:0/${power_type}
}

# GPU Frquency Control
intelGpuClock(){
min_clk=$1
max_clk=$2
card=$3
/usr/bin/echo $min_clk > /sys/class/drm/${card}/gt_min_freq_mhz
/usr/bin/echo $max_clk > /sys/class/drm/${card}gt_max_freq_mhz
intelGpuClock() {
min_clk=$1
max_clk=$2
card=$3
/usr/bin/echo $min_clk >/sys/class/drm/${card}/gt_min_freq_mhz
/usr/bin/echo $max_clk >/sys/class/drm/${card}gt_max_freq_mhz
}

## CPU Generics
if [[ $1 == "cpuBoost" ]]; then
cpuBoost $2
cpuBoost $2

elif [[ $1 == "cpuToggle" ]]; then
cpuToggle $2 $3
cpuToggle $2 $3

elif [[ $1 == "smtToggle" ]]; then
smtToggle $2
smtToggle $2

## AMD APU's
elif [[ $1 == "amdGpuClock" ]]; then
amdGpuClock $2 $3 $4
amdGpuClock $2 $3 $4

elif [[ $1 == "pdfpl" ]]; then
if [[ $2 == "write" ]]; then
setAmdPerfLevelWrite $3
else
setAmdPerfLevelValue $2 $3
fi
if [[ $2 == "write" ]]; then
setAmdPerfLevelWrite $3
else
setAmdPerfLevelValue $2 $3
fi

elif [[ $1 == "ryzenadj" ]]; then
if [[ $# > 2 ]]; then
ryzenadjLong $2 $3
else
ryzenadjShort $2
fi
if [[ $# > 2 ]]; then
ryzenadjLong $2 $3
else
ryzenadjShort $2
fi

## Intel iGPU's
elif [[ $1 == "setRapl" ]]; then
setRapl $2 $3
setRapl $2 $3

elif [[ $1 == "intelGpuClock" ]]; then
intelGpuClock $2 $3 $4
intelGpuClock $2 $3 $4

## ASUS Specific
elif [[ $1 == "setThermalPolicy" ]]; then
setThermalPolicy $2
setThermalPolicy $2

## PowerStation Service
elif [[ $1 == "startPowerStation" ]]; then
systemctl start powerstation
fi

0 comments on commit 616ccba

Please sign in to comment.