kirkwood: add fan_ctrl script for PWM fan management
authorZoltan HERPAI <[email protected]>
Thu, 16 Jul 2020 15:47:11 +0000 (17:47 +0200)
committerZoltan HERPAI <[email protected]>
Wed, 29 Jul 2020 17:12:49 +0000 (19:12 +0200)
Signed-off-by: Zoltan HERPAI <[email protected]>
target/linux/kirkwood/base-files/etc/uci-defaults/04_storafan [new file with mode: 0644]
target/linux/kirkwood/base-files/sbin/fan_ctrl.sh [new file with mode: 0755]

diff --git a/target/linux/kirkwood/base-files/etc/uci-defaults/04_storafan b/target/linux/kirkwood/base-files/etc/uci-defaults/04_storafan
new file mode 100644 (file)
index 0000000..474d42d
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2020 OpenWrt
+#
+
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+netgear,stora)
+       # Set fan script execution in crontab
+       grep -s -q fan_ctrl.sh /etc/crontabs/root && exit 0
+
+       echo "# stora fan script runs every 5 minutes" >> /etc/crontabs/root
+       echo "*/5 * * * * /sbin/fan_ctrl.sh" >> /etc/crontabs/root
+
+       # Execute one time after initial flash (instead of waiting 5 min for cron)
+       /sbin/fan_ctrl.sh
+       ;;
+esac
+
+exit 0
diff --git a/target/linux/kirkwood/base-files/sbin/fan_ctrl.sh b/target/linux/kirkwood/base-files/sbin/fan_ctrl.sh
new file mode 100755 (executable)
index 0000000..bce8700
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+CPU_TEMP=$(cut -c1-2 /sys/devices/platform/ocp@f1000000/f1011000.i2c/i2c-0/0-0048/hwmon/hwmon?/temp1_input)
+
+CPU_LOW=45
+CPU_MID=50
+CPU_HIGH=55
+
+if [ ! -e /sys/devices/platform/ocp@f1000000/f1011000.i2c/i2c-0/0-001b/hwmon/hwmon?/pwm1 ]; then
+       exit 0
+else
+       FAN_CTRL=$(ls /sys/devices/platform/ocp@f1000000/f1011000.i2c/i2c-0/0-001b/hwmon/hwmon?/pwm1)
+fi
+
+if [ "$CPU_TEMP" -ge "$CPU_HIGH" ]; then
+       echo "255" > $FAN_CTRL
+elif [ "$CPU_TEMP" -ge "$CPU_MID" ]; then
+       echo "100" > $FAN_CTRL
+elif [ "$CPU_TEMP" -ge "$CPU_LOW" ]; then
+       echo "50" > $FAN_CTRL
+else
+       echo "0" > $FAN_CTRL
+fi