]> code.delx.au - monosys/blob - hw/lenovo-m93p/etc/fancontrol
Lenovo M93p fan control - it87 driver configuration
[monosys] / hw / lenovo-m93p / etc / fancontrol
1 #!/bin/bash
2
3 # https://www.kernel.org/doc/html/latest/hwmon/it87.html
4 # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2cbb9c370fe32b5de5243f7338dc6ce8747d495b
5
6 set -eux
7
8 modprobe it87
9
10 CT="$(grep -l coretemp /sys/class/hwmon/hwmon*/name | head -n1 | xargs dirname)/temp1_input"
11 cd "$(grep -l it8792 /sys/class/hwmon/hwmon*/name | head -n1 | xargs dirname)"
12
13 grep . pwm1* temp1*
14
15 # automatic fan control - the chip seems to ignore these settings
16 #echo 2 > pwm1_enable # automatic mode
17 #echo 1 > pwm1_auto_channels_temp # temperature channel
18 #echo 127000 > pwm1_auto_point1_temp_hyst # ??
19 #echo 127000 > pwm1_auto_point1_temp # fan off temp
20 #echo 127000 > pwm1_auto_point2_temp # fan start temp
21 #echo 127000 > pwm1_auto_point3_temp # fan max temperature
22 #echo 100 > pwm1_auto_start # start pwm value
23 #echo 0 > pwm1_auto_slope # pwm slope, 1/8th pwm
24
25 # manual fan control - magic incantation
26 echo 1 > pwm1_enable # manual mode
27 echo 200000 > pwm1_freq # quieter fan
28 echo 0 > temp3_type # disabled unused sensor
29 echo 4 > temp1_type # switch sensor to thermistor
30 sleep 1 # wait for driver to write to chip
31 echo 0 > temp1_type # disable the sensor
32 echo 42 > pwm1 # set the fan speed
33
34 grep . *pwm1* temp1*
35
36 set +x
37 OLDPWM="$(cat pwm1)"
38 while sleep 1; do
39 TEMPC="$(cat "$CT")"
40 if [ "$TEMPC" -ge 85000 ]; then
41 NEWPWM=255
42 elif [ "$TEMPC" -ge 80000 ]; then
43 NEWPWM=180
44 elif [ "$TEMPC" -ge 60000 ]; then
45 NEWPWM=130
46 else
47 NEWPWM=100
48 fi
49 if [ "$OLDPWM" -ne "$NEWPWM" ]; then
50 echo "Fan speed change: OLDPWM=$OLDPWM TEMPC=$TEMPC NEWPWM=$NEWPWM"
51 echo "$NEWPWM" > pwm1
52 OLDPWM="$NEWPWM"
53 sleep 30
54 fi
55 done