Created
August 5, 2023 12:00
-
-
Save polter-rnd/ed35eb0f85708c0a608b6f2e84ead5ba to your computer and use it in GitHub Desktop.
Fixup NVIDIA audio device power state when HDMI screen is attached or removed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NVHDA_FILE="/proc/acpi/nvhda" | |
# Check all HDMI connections | |
while IFS= read -r; do | |
DRIVER=$(realpath "$(dirname "$REPLY")"/../device/driver) | |
if [ "$(basename "$DRIVER")" = "nvidia" ]; then | |
HDMI_CONNECTED=1 | |
break | |
fi | |
done < <(grep -l ^connected /sys/class/drm/*HDMI*/status) | |
NVHDA_STATUS="$(cat $NVHDA_FILE)" | |
NVHDA_STATUS="${NVHDA_STATUS##* }" | |
if [ -n "$HDMI_CONNECTED" ] && [ "$NVHDA_STATUS" == "OFF" ]; then | |
echo "ON" > "$NVHDA_FILE" | |
echo "HDA NVidia: turned on" | |
elif [ -z "$HDMI_CONNECTED" ] && [ "$NVHDA_STATUS" == "ON" ]; then | |
echo "OFF" > "$NVHDA_FILE" | |
echo "HDA NVidia: turned off" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment