mirror of
https://github.com/theupriser/steamify-cachyos.git
synced 2026-10-03 17:41:58 +02:00
feat: Power-off fix for the Steam Machine; the kernel pin is optional
Kernels >= 7.2 keep the firmware's S4/S5 wake bit on GPIO pin 18, so the Steam Machine starts again right after powering off. Steam Machine support now builds a DKMS module (patches/steamify-fremont-poweroff.c) that clears it before power-off, for every kernel. The kernel pin is no longer ticked by default. Module sources and patches move to patches/, embedded by the single-file build.
This commit is contained in:
1 parent
a5e644d71a
commit
7694c97d68
17 files changed
+297
-41
No files matched your search
+4
-9
@@ -60,8 +60,8 @@ cec_reload_driver() {
|
||||
cec_driver_enable() {
|
||||
detect_valve_fremont || return 0
|
||||
local tmp k
|
||||
if ! pacman -Q dkms >/dev/null 2>&1; then
|
||||
sudo pacman -S --needed --noconfirm dkms || { err "Installing dkms failed."; return 1; }
|
||||
if ! pacman -Q dkms patch >/dev/null 2>&1; then
|
||||
sudo pacman -S --needed --noconfirm dkms patch || { err "Installing dkms failed."; return 1; }
|
||||
fi
|
||||
install_kernel_headers || return 1
|
||||
tmp="$(mktemp -d)"
|
||||
@@ -72,13 +72,8 @@ cec_driver_enable() {
|
||||
err "Downloading Valve's CEC driver failed (or its checksum didn't match)."
|
||||
return 1
|
||||
fi
|
||||
# amdgpu registers its HDMI notifier without a port name, which only
|
||||
# matches the driver's named lookup ("Port C") if the driver loaded
|
||||
# first; amdgpu loads from the initramfs, so it never does. With a
|
||||
# single CEC port, look it up by device alone.
|
||||
sed -i 's/cec_notifier_cec_adap_register(hdmi_dev, conns\[port_num\],/cec_notifier_cec_adap_register(hdmi_dev, conns[1] ? conns[port_num] : NULL,/' \
|
||||
"$tmp/cros-ec-cec.c"
|
||||
grep -q 'conns\[1\] ? conns\[port_num\] : NULL' "$tmp/cros-ec-cec.c" ||
|
||||
# So it finds amdgpu's HDMI port (see the patch for why).
|
||||
patch_file cros-ec-cec-single-port.patch | patch -s -d "$tmp" -p1 ||
|
||||
{ rm -rf "$tmp"; err "Patching Valve's CEC driver failed."; return 1; }
|
||||
echo 'obj-m += cros-ec-cec.o' >"$tmp/Makefile"
|
||||
printf '%s\n' "# Written by Steamify: Valve's cros_ec_cec, which knows the Steam Machine." \
|
||||
|
||||
@@ -6,6 +6,9 @@ c_reset="\033[0m"; c_bold="\033[1m"; c_green="\033[32m"; c_yellow="\033[33m"; c_
|
||||
|
||||
info() { echo -e "${c_cyan}[INFO]${c_reset} $*"; }
|
||||
ok() { echo -e "${c_green}[OK]${c_reset} $*"; }
|
||||
# patch_file <name>: a file from patches/ (module sources, patches). The
|
||||
# single-file build replaces this with one that has them embedded.
|
||||
patch_file() { cat "$SCRIPT_DIR/patches/$1"; }
|
||||
warn() { echo -e "${c_yellow}[WARN]${c_reset} $*"; }
|
||||
err() { echo -e "${c_red}[ERROR] $*${c_reset}" >&2; }
|
||||
ask_yn() {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# Part of "Steam Machine support": the Steam Machine powers off instead of
|
||||
# booting up again, on every kernel. Since Linux 7.2 ("pinctrl-amd: Don't
|
||||
# clear S4 wake bits at probe") the S4/S5 wake bit the firmware leaves set
|
||||
# on GPIO pin 18 stays set, and the machine starts again right after
|
||||
# powering off (the reason for the kernel pin). Valve's kernel clears it at
|
||||
# probe on Fremont, in a patch not meant for upstream, so CachyOS won't get
|
||||
# it. A small module (patches/steamify-fremont-poweroff.c) clears it right
|
||||
# before power-off; DKMS builds it for every kernel. On kernels that clear it themselves it does nothing.
|
||||
# Sourced by steamify.sh; not meant to be run on its own.
|
||||
|
||||
POWEROFF_DKMS_NAME=steamify-fremont-poweroff
|
||||
POWEROFF_DKMS_VER=1
|
||||
POWEROFF_DKMS_SRC="/usr/src/$POWEROFF_DKMS_NAME-$POWEROFF_DKMS_VER"
|
||||
POWEROFF_MODULES_LOAD=/etc/modules-load.d/steamify-fremont-poweroff.conf
|
||||
|
||||
poweroff_fix_installed() { [[ -f "$POWEROFF_DKMS_SRC/dkms.conf" && -f "$POWEROFF_MODULES_LOAD" ]]; }
|
||||
|
||||
poweroff_fix_enable() {
|
||||
detect_valve_fremont || return 0
|
||||
local tmp k
|
||||
if ! pacman -Q dkms >/dev/null 2>&1; then
|
||||
sudo pacman -S --needed --noconfirm dkms || { err "Installing dkms failed."; return 1; }
|
||||
fi
|
||||
install_kernel_headers || return 1
|
||||
tmp="$(mktemp -d)"
|
||||
patch_file "$POWEROFF_DKMS_NAME.c" > "$tmp/$POWEROFF_DKMS_NAME.c"
|
||||
echo "obj-m += $POWEROFF_DKMS_NAME.o" >"$tmp/Makefile"
|
||||
printf '%s\n' "# Written by Steamify: the Steam Machine powers off instead of booting up again." \
|
||||
"PACKAGE_NAME=\"$POWEROFF_DKMS_NAME\"" "PACKAGE_VERSION=\"$POWEROFF_DKMS_VER\"" \
|
||||
"BUILT_MODULE_NAME[0]=\"$POWEROFF_DKMS_NAME\"" 'DEST_MODULE_LOCATION[0]="/updates/dkms"' \
|
||||
'AUTOINSTALL="yes"' >"$tmp/dkms.conf"
|
||||
sudo dkms remove "$POWEROFF_DKMS_NAME/$POWEROFF_DKMS_VER" --all >/dev/null 2>&1
|
||||
sudo rm -rf "$POWEROFF_DKMS_SRC"
|
||||
sudo install -d "$POWEROFF_DKMS_SRC" &&
|
||||
sudo install -m644 "$tmp"/{"$POWEROFF_DKMS_NAME.c",Makefile,dkms.conf} "$POWEROFF_DKMS_SRC/"
|
||||
rm -rf "$tmp"
|
||||
sudo dkms add "$POWEROFF_DKMS_NAME/$POWEROFF_DKMS_VER" >/dev/null ||
|
||||
{ err "Adding the power-off fix to DKMS failed."; return 1; }
|
||||
for k in /usr/lib/modules/*/build; do
|
||||
k="$(basename "$(dirname "$k")")"
|
||||
info "Building the power-off fix for $k..."
|
||||
sudo dkms install "$POWEROFF_DKMS_NAME/$POWEROFF_DKMS_VER" -k "$k" >/dev/null ||
|
||||
warn "Building the power-off fix for $k failed; with that kernel it may start again after shutting down."
|
||||
done
|
||||
echo "$POWEROFF_DKMS_NAME" | sudo tee "$POWEROFF_MODULES_LOAD" >/dev/null
|
||||
sudo modprobe "$POWEROFF_DKMS_NAME" 2>/dev/null
|
||||
return 0
|
||||
}
|
||||
|
||||
poweroff_fix_disable() {
|
||||
sudo rm -f "$POWEROFF_MODULES_LOAD"
|
||||
sudo modprobe -r "$POWEROFF_DKMS_NAME" 2>/dev/null
|
||||
[[ -d "$POWEROFF_DKMS_SRC" ]] || return 0
|
||||
sudo dkms remove "$POWEROFF_DKMS_NAME/$POWEROFF_DKMS_VER" --all >/dev/null 2>&1
|
||||
sudo rm -rf "$POWEROFF_DKMS_SRC"
|
||||
}
|
||||
+6
-4
@@ -16,7 +16,7 @@ declare -A PARENT=([boot]=gaming [kpin]=machine [hdmi]=machine [bios]=machine)
|
||||
# upset other devices on the TV, even on SteamOS), except on a Steam Machine,
|
||||
# which has CEC like on SteamOS. HDMI refresh boost needs someone at the
|
||||
# screen to confirm each step.
|
||||
NO_PRESELECT=(boot cec hdmi)
|
||||
NO_PRESELECT=(boot cec kpin hdmi)
|
||||
|
||||
declare -A LABEL=(
|
||||
[gaming]="SteamOS conversion: boot into gaming mode, Steam on the desktop"
|
||||
@@ -27,7 +27,7 @@ declare -A LABEL=(
|
||||
[launcher]="Steamify shortcut: the app on the desktop, Steamify Terminal in the launcher"
|
||||
[cec]="HDMI-CEC: use Steam with the TV remote, TV on/off with the PC (experimental)"
|
||||
[machine]="Steam Machine support: LED bar driver, hardware settings in Steam"
|
||||
[kpin]="Pin the kernel to $PINNED_KERNEL_VER (fixes rebooting after shutdown)"
|
||||
[kpin]="Pin the kernel to $PINNED_KERNEL_VER (optional, stays on an older kernel)"
|
||||
[hdmi]="HDMI refresh boost: highest refresh your HDMI display runs"
|
||||
[bios]="Update BIOS"
|
||||
)
|
||||
@@ -72,6 +72,8 @@ detect_components() {
|
||||
done
|
||||
# HDMI-CEC set up by an older version: tick it, so a normal run fixes it.
|
||||
component_available cec && cec_repair && WANTED[cec]=1
|
||||
# Steam Machine support from before 2.2.0 lacks the power-off fix.
|
||||
component_available machine && machine_repair && WANTED[machine]=1
|
||||
# The terminal-only Steamify shortcut from before 2.0.1: tick it, so a
|
||||
# normal run replaces it with the app.
|
||||
launcher_repair && WANTED[launcher]=1
|
||||
@@ -96,8 +98,8 @@ toggle_component() {
|
||||
if [[ "$c" == gaming && "${WANTED[gaming]}" == 0 ]]; then WANTED[single]=0; WANTED[boot]=0; fi
|
||||
# Where to boot to is part of the conversion, too.
|
||||
if [[ "$c" == boot && "${WANTED[boot]}" == 1 ]]; then WANTED[gaming]=1; fi
|
||||
# The kernel pin is opt-out: ticked along with Steam Machine support.
|
||||
if [[ "$c" == machine ]]; then WANTED[kpin]=${WANTED[machine]}; fi
|
||||
# The kernel pin is opt-in (the power-off fix made it optional).
|
||||
if [[ "$c" == machine && "${WANTED[machine]}" == 0 ]]; then WANTED[kpin]=0; fi
|
||||
if [[ "$c" == kpin && "${WANTED[kpin]}" == 1 ]]; then WANTED[machine]=1; fi
|
||||
# HDMI refresh boost and the BIOS update sit under Steam Machine support;
|
||||
# the boost also needs the pinned kernel (newer kernels don't need it).
|
||||
|
||||
+19
-8
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
# "Steam Machine support" menu item, only on Valve Fremont hardware: the
|
||||
# front LED bar driver, LED access for Steam, and steamos-manager.
|
||||
# front LED bar driver, LED access for Steam, steamos-manager, and the
|
||||
# power-off fix (lib/fremont-poweroff.sh).
|
||||
# Sourced by steamify.sh; not meant to be run on its own.
|
||||
|
||||
detect_valve_fremont() {
|
||||
@@ -14,8 +15,8 @@ detect_valve_fremont() {
|
||||
[[ "$vendor" == "OEM" && "$product" == "F7F" ]]
|
||||
}
|
||||
|
||||
# Kernel pinned on a Steam Machine: with newer linux-cachyos releases it
|
||||
# reboots instead of shutting down. The packages are kept in
|
||||
# Kernel pinned on a Steam Machine (optional): newer linux-cachyos releases
|
||||
# rebooted it instead of shutting down, which the power-off fix now handles. The packages are kept in
|
||||
# PINNED_KERNEL_DIR, so re-applying (or reinstalling after an update slipped
|
||||
# through) needs no download.
|
||||
PINNED_KERNEL_VER="7.1.6-1"
|
||||
@@ -334,13 +335,13 @@ reload_powerdevil() {
|
||||
kernel_overview() {
|
||||
# Per installed kernel: headers (needed to build DKMS modules), the
|
||||
# in-kernel Steam controller driver, and, on a Steam Machine, whether the
|
||||
# LED driver is built for it. Printed in the menu so it's easy to verify
|
||||
# LED driver and the power-off fix are built for it. Printed in the menu so it's easy to verify
|
||||
# a kernel update or a newly added kernel got everything.
|
||||
local mark="${c_green}yes${c_reset}" miss="${c_red}no ${c_reset}" leds=false
|
||||
detect_valve_fremont && command -v dkms >/dev/null 2>&1 && leds=true
|
||||
local kdir k pkg headers hid led running line
|
||||
local kdir k pkg headers hid led off running line
|
||||
local legend="> = running; controller = Steam controller driver"
|
||||
[[ "$leds" == true ]] && legend+=", LEDs = LED bar driver built"
|
||||
[[ "$leds" == true ]] && legend+=", LEDs = LED bar driver built, power-off = power-off fix built"
|
||||
echo -e " ${c_bold}Kernels${c_reset} ($legend)"
|
||||
for kdir in /usr/lib/modules/*/; do
|
||||
k="$(basename "$kdir")"
|
||||
@@ -352,7 +353,8 @@ kernel_overview() {
|
||||
line="$(printf '%-23s %-18s headers %b controller %b' "$k" "$pkg" "$headers" "$hid")"
|
||||
if [[ "$leds" == true ]]; then
|
||||
led="$miss"; dkms status -k "$k" leds-valve-dkms 2>/dev/null | grep -q installed && led="$mark"
|
||||
line+="$(printf ' LEDs %b' "$led")"
|
||||
off="$miss"; dkms status -k "$k" "$POWEROFF_DKMS_NAME" 2>/dev/null | grep -q installed && off="$mark"
|
||||
line+="$(printf ' LEDs %b power-off %b' "$led" "$off")"
|
||||
fi
|
||||
echo -e " ${running}${line}"
|
||||
done
|
||||
@@ -369,7 +371,13 @@ kernel_overview() {
|
||||
machine_available() { detect_valve_fremont; }
|
||||
|
||||
machine_status() {
|
||||
pacman -Qi leds-valve-dkms-git >/dev/null 2>&1 && pacman -Qi steamos-manager >/dev/null 2>&1
|
||||
pacman -Qi leds-valve-dkms-git >/dev/null 2>&1 && pacman -Qi steamos-manager >/dev/null 2>&1 &&
|
||||
poweroff_fix_installed
|
||||
}
|
||||
# Set up before 2.2.0: no power-off fix yet; the menu ticks it to add it.
|
||||
machine_repair() {
|
||||
pacman -Qi leds-valve-dkms-git >/dev/null 2>&1 && pacman -Qi steamos-manager >/dev/null 2>&1 &&
|
||||
! poweroff_fix_installed
|
||||
}
|
||||
|
||||
machine_enable() {
|
||||
@@ -381,6 +389,8 @@ machine_enable() {
|
||||
ensure_aur_helper || { warn "Couldn't set up an AUR helper automatically. Install yay or paru, then run the wizard again."; return 1; }
|
||||
install_valve_led_driver || { warn "LED driver setup ran into a problem - see errors above."; return 1; }
|
||||
install_headers_boot_check
|
||||
info "Installing the power-off fix (the machine stays off after shutting down)..."
|
||||
poweroff_fix_enable || { err "Installing the power-off fix failed."; return 1; }
|
||||
|
||||
# The LED files are root-only. Steam runs as the user; let it write them
|
||||
# in case it drives the bar directly (Valve's own privileged-write helper
|
||||
@@ -424,6 +434,7 @@ machine_disable() {
|
||||
sudo udevadm control --reload
|
||||
sudo modprobe -r leds-valve 2>/dev/null
|
||||
sudo pacman -Rns --noconfirm leds-valve-dkms-git 2>/dev/null
|
||||
poweroff_fix_disable
|
||||
krevert machine
|
||||
reload_powerdevil
|
||||
sudo systemctl disable ensure-kernel-headers.service 2>/dev/null
|
||||
|
||||
Reference in new issue
Block a user