diff --git a/target/linux/realtek/base-files/etc/init.d/hwmon_fancontrol b/target/linux/realtek/base-files/etc/init.d/hwmon_fancontrol index 85e57522fcd..cec1e8723b6 100755 --- a/target/linux/realtek/base-files/etc/init.d/hwmon_fancontrol +++ b/target/linux/realtek/base-files/etc/init.d/hwmon_fancontrol @@ -35,6 +35,41 @@ plasmacloud_common() { echo 2 > "$path_to_hwmon/pwm2_enable" } +dlink_dgs_1210() { + local path_to_hwmon="$(find -L /sys/bus/i2c/devices/4-004c -type d -maxdepth 2 -mindepth 2 -name 'hwmon*' || true)" + + if [ -z "$path_to_hwmon" ]; then + logger -t hwmon_fancontrol "LM63 hwmon interface not found on i2c 4-004c (kmod lm63 loaded?)" + return 1 + fi + + # Set to manual mode temporarily to allow LUT and frequency setup + echo 1 > "$path_to_hwmon/pwm1_enable" + + # Configure PWM frequency (~7826 Hz / PFR divisor 23) matching OEM defaults + echo 7826 > "$path_to_hwmon/pwm1_freq" + + # Point 1: If temp > 0 C, set fan speed to PWM 155/255 (OEM default 0x1c) + echo 0 > "$path_to_hwmon/pwm1_auto_point1_temp" + echo $((0x1c * 255 / 46)) > "$path_to_hwmon/pwm1_auto_point1_pwm" + + # Point 2: If temp > 51 C, set fan speed to PWM 255/255 (OEM default 0x2e) + echo 51000 > "$path_to_hwmon/pwm1_auto_point2_temp" + echo $((0x2e * 255 / 46)) > "$path_to_hwmon/pwm1_auto_point2_pwm" + + # Point 3-8: Set the chip default values for unused points as reboot does not clean them + for p in 3 4 5 6 7 8; do + echo 127000 > "$path_to_hwmon/pwm1_auto_point${p}_temp" + echo 255 > "$path_to_hwmon/pwm1_auto_point${p}_pwm" + done + + # Hysteresis: Set 3 C (3000 mC) hysteresis for LUT (OEM default 0x03) + echo 3000 > "$path_to_hwmon/pwm1_auto_point_temp_hyst" + + # Switch to hardware auto mode + echo 2 > "$path_to_hwmon/pwm1_enable" +} + dlink_dgs_1250() { local path_temp_hwmon="$(find /sys/devices/platform/i2c-gpio-4/i2c-4/4-0048/hwmon/ -type d -maxdepth 1 -mindepth 1 -name 'hwmon*')" local path_fan_hwmon="$(find /sys/devices/platform/gpio-fan/hwmon/ -type d -maxdepth 1 -mindepth 1 -name 'hwmon*')" @@ -92,6 +127,10 @@ boot() { plasmacloud,psx28) plasmacloud_common ;; + d-link,dgs-1210-28p-f|\ + d-link,dgs-1210-28mp-f) + dlink_dgs_1210 + ;; d-link,dgs-1250-28x) dlink_dgs_1250 ;; diff --git a/target/linux/realtek/base-files/etc/uci-defaults/04_dlinkfan b/target/linux/realtek/base-files/etc/uci-defaults/04_dlinkfan deleted file mode 100644 index a06768efa43..00000000000 --- a/target/linux/realtek/base-files/etc/uci-defaults/04_dlinkfan +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright (C) 2024 openwrt.org -# - -. /lib/functions.sh - -board=$(board_name) - -case "$board" in -d-link,dgs-1210-28p-f|d-link,dgs-1210-28mp-f) - # Enable fan control - FAN_CTRL='/sys/class/hwmon/hwmon0' - echo 1 > "$FAN_CTRL/pwm1_enable" - - # Set fan script execution in crontab - grep -s -q fan_ctrl.sh /etc/crontabs/root && exit 0 - - echo "# dlink 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/realtek/base-files/etc/uci-defaults/04_dlinkfan_migration b/target/linux/realtek/base-files/etc/uci-defaults/04_dlinkfan_migration new file mode 100644 index 00000000000..d372a72d393 --- /dev/null +++ b/target/linux/realtek/base-files/etc/uci-defaults/04_dlinkfan_migration @@ -0,0 +1,29 @@ +#!/bin/sh + +. /lib/functions.sh + +CRON_FILE="/etc/crontabs/root" +LINE1="# dlink fan script runs every 5 minutes" +LINE2="*/5 * * * * /sbin/fan_ctrl.sh" + +case "$(board_name)" in +d-link,dgs-1210-28p-f|d-link,dgs-1210-28mp-f) + [ -f "$CRON_FILE" ] || exit 0 + + # Remove legacy user-space fan_ctrl script from crontab + if grep -x -F -q "$LINE1" "$CRON_FILE" && grep -x -F -q "$LINE2" "$CRON_FILE"; then + grep -v -x -F "$LINE1" "$CRON_FILE" | grep -v -x -F "$LINE2" > "${CRON_FILE}.tmp" + mv "${CRON_FILE}.tmp" "$CRON_FILE" + [ -s "$CRON_FILE" ] || rm -f "$CRON_FILE" + + /etc/init.d/cron restart 2>/dev/null + + # if the user changed it, just warn (fan_ctrl.sh is gone anyway). + elif grep -E -q '^[[:space:]]*[^#].*fan_ctrl\.sh' "$CRON_FILE"; then + logger -t dlinkfan_migration -p user.err "Custom fan_ctrl.sh entry found in $CRON_FILE. Leaving file untouched!" + exit 1 + fi + ;; +esac + +exit 0 diff --git a/target/linux/realtek/base-files/sbin/fan_ctrl.sh b/target/linux/realtek/base-files/sbin/fan_ctrl.sh deleted file mode 100755 index e7b661d7bb6..00000000000 --- a/target/linux/realtek/base-files/sbin/fan_ctrl.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -PSU_TEMP=$(cut -c1-2 /sys/class/hwmon/hwmon0/temp1_input) - -FAN_CTRL='/sys/class/hwmon/hwmon0/pwm1' - -PSU_THRESH=51000 - -if [ "$PSU_TEMP" -ge "$PSU_THRESH" ];then - echo "250" > $FAN_CTRL -else - echo "156" > $FAN_CTRL -fi