#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2022-present Fewtarius (https://github.com/fewtarius) get_gpu_power_profile() { cat /sys/class/drm/card0/device/power_dpm_state 2>/dev/null } gpu_power_profile() { for card in /sys/class/drm/card*/device/power_dpm_state do if [ -e "${card}" ] then echo ${1} >${card} 2>/dev/null fi done } get_gpu_performance_level() { cat /sys/class/drm/card0/device/power_dpm_force_performance_level 2>/dev/null } gpu_performance_level() { for card in /sys/class/drm/card*/device/power_dpm_force_performance_level do if [ -e "${card}" ] then echo ${1} >${card} 2>/dev/null fi done } pcie_aspm_policy() { PCIEPOWERSAVE=$(get_setting system.pcie.powersave) if [ ! "${PCIEPOWERSAVE}" = "1" ] then return 0 fi if [ -e "/sys/module/pcie_aspm/parameters/policy" ] then echo ${1} >/sys/module/pcie_aspm/parameters/policy 2>/dev/null fi } cpu_perftune() { CPUPOWERSAVE=$(get_setting system.cpu.powersave) if [ ! "${CPUPOWERSAVE}" = "1" ] then return 0 fi CPU="$(awk '/vendor_id/ {print $3;exit}' /proc/cpuinfo)" if [ "${CPU}" = "AuthenticAMD" ] then if [ "${1}" = "battery" ] then ryzenadj --power-saving >/dev/null 2>&1 else ryzenadj --max-performance >/dev/null 2>&1 fi elif [ "${CPU}" = "GenuineIntel" ] then for policy in $(find /sys/devices/system/cpu/cpufreq/policy*/ -name energy_performance_preference) do if [ "${1}" = "battery" ] then echo power >${policy} >/dev/null 2>&1 else echo performance >${policy} >/dev/null 2>&1 fi done fi } audio_powersave() { AUDIOPOWERSAVE=$(get_setting system.audio.powersave) if [ ! "${AUDIOPOWERSAVE}" = "1" ] then return 0 fi for MODULE in snd_hda_intel snd_ac97_codec do if [ -e "/sys/module/${MODULE}/parameters/power_save" ] then echo ${1} >/sys/module/${MODULE}/parameters/power_save 2>/dev/null fi done } usb_powersave() { USBPOWERSAVE=$(get_setting system.usb.powersave) if [ ! "${USBPOWERSAVE}" = "1" ] then return 0 fi find /sys/devices -name control -print0 | \ while read -r -d '' DEVICE do echo ${1} >"${DEVICE}" 2>/dev/null done } usb_powerlevel() { USBPOWERSAVE=$(get_setting system.usb.powersave) if [ ! "${USBPOWERSAVE}" = "1" ] then return 0 fi for device in $(find /sys/devices/pci* -name level) do echo ${1} >${device} 2>/dev/null done } pci_powersave() { PCIPOWERSAVE=$(get_setting system.pci.powersave) if [ ! "${PCIPOWERSAVE}" = "1" ] then return 0 fi for device in $(find /sys/devices/pci* -name wakeup) do echo ${1} >${device} 2>/dev/null done }