-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvega-fan-control
executable file
·120 lines (108 loc) · 3.47 KB
/
vega-fan-control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Script to control AMD Vega card fans.
#
# authored-by: Aaron Echols
# email: atechols at gmail dot com
#
# NOTES:
#
# This script has been released under the GNU GENERAL PUBLIC LICENSE.
# Please contribute to the upstream author at:
# https://github.com/dasunsrule32/radeon-scripts
#
# Install Instructions:
#
# https://github.com/dasunsrule32/radeon-scripts/blob/master/systemd/INSTALL-vega-fan-control.md
#
# Variables:
# ----------
DEBUG=0 # Enable (1) or Disable (0) DEBUG.
AMDSYSFILE="power_dpm_force_performance_level" # AMD SYSFS file to search for.
SYSPATH=$(awk '{print}' <<< `find /sys/devices -name $AMDSYSFILE -type f -exec dirname {} \;`) # Autodetect SYSFS path.
HWMONPATH="hwmon/hwmon0"
KERNELVER=$(awk -F. '{printf("%d%02d\n", $1, $2)}' <<< `uname -r`) # Get kernel version.
KERNELREQ="415" # Minimum required kernel version for script.
# Functions:
# ----------
# Echo a string value that is passed
echo_text() {
echo -e >&2 "$@";
}
# Restore default PWM settings on exit:
pwm_default() {
echo_text "\nRestoring PWM defaults"
echo "2" > "$SYSPATH/$HWMONPATH/pwm1_enable"
if [ $DEBUG = 1 ]; then
cat $SYSPATH/$HWMONPATH/pwm1_enable
fi
}
# Main body:
# ----------
# Check if root:
if [[ $EUID -ne 0 ]]; then
echo_text "You need to be root to run this script..."
exit 1
fi
# Check if kernel version is new enough:
if [ $KERNELVER -lt $KERNELREQ ]; then
echo_text "Kernel is too old, exiting..."
exit 2
else
echo_text "Kernel requirements met, continuing..."
fi
# Set PWM to manual control:
echo "1" > "$SYSPATH/$HWMONPATH/pwm1_enable"
# On exit set default fan controls:
trap "pwm_default" EXIT
if [ $DEBUG -eq 1 ]; then
echo_text "Hit ctrl-c to exit..."
fi
while :
do
# Get GPU temperatures:
GPUTEMP=`awk '{print $1/(1000)}' $SYSPATH/$HWMONPATH/temp1_input`
# Set RPM based on temperature range:
if [ "$GPUTEMP" -ge "20" ] && [ "$GPUTEMP" -le "24" ]; then
FANRPM=400
elif [ "$GPUTEMP" -ge "25" ] && [ "$GPUTEMP" -le "29" ]; then
FANRPM=600
elif [ "$GPUTEMP" -ge "30" ] && [ "$GPUTEMP" -le "34" ]; then
FANRPM=800
elif [ "$GPUTEMP" -ge "35" ] && [ "$GPUTEMP" -le "39" ]; then
FANRPM=1200
elif [ "$GPUTEMP" -ge "40" ] && [ "$GPUTEMP" -le "44" ]; then
FANRPM=1600
elif [ "$GPUTEMP" -ge "44" ] && [ "$GPUTEMP" -le "49" ]; then
FANRPM=1800
elif [ "$GPUTEMP" -ge "50" ] && [ "$GPUTEMP" -le "54" ]; then
FANRPM=2000
elif [ "$GPUTEMP" -ge "55" ] && [ "$GPUTEMP" -le "59" ]; then
FANRPM=2200
elif [ "$GPUTEMP" -ge "60" ] && [ "$GPUTEMP" -le "64" ]; then
FANRPM=2400
elif [ "$GPUTEMP" -ge "65" ] && [ "$GPUTEMP" -le "69" ]; then
FANRPM=2600
elif [ "$GPUTEMP" -ge "70" ] && [ "$GPUTEMP" -le "74" ]; then
FANRPM=2800
elif [ "$GPUTEMP" -ge "75" ] && [ "$GPUTEMP" -le "79" ]; then
FANRPM=3000
elif [ "$GPUTEMP" -ge "80" ] && [ "$GPUTEMP" -le "86" ]; then
FANRPM=3200
fi
# Set the RPM in the sys device for AMD fancontrol:
echo "$FANRPM" > "$SYSPATH/$HWMONPATH/fan1_target"
# Wait 2 seconds to re-evaluate temperatures:
sleep 2s
# Debug output:
if [ $DEBUG -eq 1 ]; then
echo_text "GPU Temp: $GPUTEMP"
echo_text " Fan RPM: $FANRPM"
fi
# Workaround for issue: https://github.com/dasunsrule32/radeon-scripts/issues/3
GET_PWM1=`cat $SYSPATH/$HWMONPATH/pwm1_enable`
if [ "$GET_PWM1" -eq 2 ]; then
echo "1" > "$SYSPATH/$HWMONPATH/pwm1_enable"
echo_text "\nRe-enabling fan control"
fi
done