From 0a29a03060f8efc718b2f92d72f2f26161baf28f Mon Sep 17 00:00:00 2001 From: Zoltan HERPAI Date: Thu, 16 Jul 2020 17:47:11 +0200 Subject: [PATCH] kirkwood: add fan_ctrl script for PWM fan management Signed-off-by: Zoltan HERPAI --- .../base-files/etc/uci-defaults/04_storafan | 22 ++++++++++++++++++ .../kirkwood/base-files/sbin/fan_ctrl.sh | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 target/linux/kirkwood/base-files/etc/uci-defaults/04_storafan create mode 100755 target/linux/kirkwood/base-files/sbin/fan_ctrl.sh 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 index 0000000000..474d42d54e --- /dev/null +++ b/target/linux/kirkwood/base-files/etc/uci-defaults/04_storafan @@ -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 index 0000000000..bce8700736 --- /dev/null +++ b/target/linux/kirkwood/base-files/sbin/fan_ctrl.sh @@ -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 -- 2.30.2