]> code.delx.au - monosys/commitdiff
Lenovo M93p fan control - it87 driver configuration
authorJames Bunton <jamesbunton@delx.au>
Wed, 6 Mar 2024 05:01:03 +0000 (16:01 +1100)
committerJames Bunton <jamesbunton@delx.au>
Wed, 6 Mar 2024 12:05:57 +0000 (23:05 +1100)
hw/lenovo-m93p/etc/fancontrol [new file with mode: 0755]
hw/lenovo-m93p/etc/modprobe.d/it87.conf [new file with mode: 0644]
hw/lenovo-m93p/etc/systemd/system/fancontrol.service [new file with mode: 0644]

diff --git a/hw/lenovo-m93p/etc/fancontrol b/hw/lenovo-m93p/etc/fancontrol
new file mode 100755 (executable)
index 0000000..19b199d
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# https://www.kernel.org/doc/html/latest/hwmon/it87.html
+# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2cbb9c370fe32b5de5243f7338dc6ce8747d495b
+
+set -eux
+
+modprobe it87
+
+CT="$(grep -l coretemp /sys/class/hwmon/hwmon*/name | head -n1 | xargs dirname)/temp1_input"
+cd "$(grep -l it8792 /sys/class/hwmon/hwmon*/name | head -n1 | xargs dirname)"
+
+grep . pwm1* temp1*
+
+# automatic fan control - the chip seems to ignore these settings
+#echo 2          > pwm1_enable                  # automatic mode
+#echo 1          > pwm1_auto_channels_temp      # temperature channel
+#echo 127000     > pwm1_auto_point1_temp_hyst   # ??
+#echo 127000     > pwm1_auto_point1_temp        # fan off temp
+#echo 127000     > pwm1_auto_point2_temp        # fan start temp
+#echo 127000     > pwm1_auto_point3_temp        # fan max temperature
+#echo 100        > pwm1_auto_start              # start pwm value
+#echo 0          > pwm1_auto_slope              # pwm slope, 1/8th pwm
+
+# manual fan control - magic incantation
+echo 1          > pwm1_enable                   # manual mode
+echo 200000     > pwm1_freq                     # quieter fan
+echo 0          > temp3_type                    # disabled unused sensor
+echo 4          > temp1_type                    # switch sensor to thermistor
+sleep 1                                         # wait for driver to write to chip
+echo 0          > temp1_type                    # disable the sensor
+echo 42         > pwm1                          # set the fan speed
+
+grep . *pwm1* temp1*
+
+set +x
+OLDPWM="$(cat pwm1)"
+while sleep 1; do
+    TEMPC="$(cat "$CT")"
+    if [ "$TEMPC" -ge 85000 ]; then
+        NEWPWM=255
+    elif [ "$TEMPC" -ge 80000 ]; then
+        NEWPWM=180
+    elif [ "$TEMPC" -ge 60000 ]; then
+        NEWPWM=130
+    else
+        NEWPWM=100
+    fi
+    if [ "$OLDPWM" -ne "$NEWPWM" ]; then
+        echo "Fan speed change: OLDPWM=$OLDPWM TEMPC=$TEMPC NEWPWM=$NEWPWM"
+        echo "$NEWPWM" > pwm1
+        OLDPWM="$NEWPWM"
+        sleep 30
+    fi
+done
diff --git a/hw/lenovo-m93p/etc/modprobe.d/it87.conf b/hw/lenovo-m93p/etc/modprobe.d/it87.conf
new file mode 100644 (file)
index 0000000..ea7f363
--- /dev/null
@@ -0,0 +1 @@
+options it87 ignore_resource_conflict=1
diff --git a/hw/lenovo-m93p/etc/systemd/system/fancontrol.service b/hw/lenovo-m93p/etc/systemd/system/fancontrol.service
new file mode 100644 (file)
index 0000000..c5bdb5c
--- /dev/null
@@ -0,0 +1,5 @@
+[Service]
+ExecStart=/etc/fancontrol
+
+[Install]
+WantedBy=multi-user.target