diff --git a/target/linux/rockchip/armv8/base-files/etc/init.d/rockchip-fan b/target/linux/rockchip/armv8/base-files/etc/init.d/rockchip-fan new file mode 100755 index 000000000..ebdea2f11 --- /dev/null +++ b/target/linux/rockchip/armv8/base-files/etc/init.d/rockchip-fan @@ -0,0 +1,8 @@ +#!/bin/sh /etc/rc.common + +START=96 + +start() { + echo "fa-pwmfan started" + /usr/bin/rockchip-pwm-fan.sh > /dev/null& +} \ No newline at end of file diff --git a/target/linux/rockchip/armv8/base-files/usr/bin/rockchip-pwm-fan.sh b/target/linux/rockchip/armv8/base-files/usr/bin/rockchip-pwm-fan.sh new file mode 100755 index 000000000..a287fb108 --- /dev/null +++ b/target/linux/rockchip/armv8/base-files/usr/bin/rockchip-pwm-fan.sh @@ -0,0 +1,46 @@ +#!/bin/bash +echo -n 4 > /sys/class/thermal/cooling_device0/cur_state +sleep 5 +echo -n 0 > /sys/class/thermal/cooling_device0/cur_state +declare -a CpuTemps=(70000 60000 50000 40000 35000) +declare -a PwmDutyCycles=(4 3 2 1 0) +declare -a Percents=(100 70 50 20 0) +DefaultDuty=0 +DefaultPercents=0 + +while true +do + temp=$(cat /sys/class/thermal/thermal_zone0/temp) + INDEX=0 + FOUNDTEMP=0 + DUTY=$DefaultDuty + PERCENT=$DefaultPercents + + for i in 0 1 2 3 4; do + if [ $temp -gt ${CpuTemps[$i]} ]; then + INDEX=$i + FOUNDTEMP=1 + break + fi + done + if [ ${FOUNDTEMP} == 1 ]; then + DUTY=${PwmDutyCycles[$i]} + PERCENT=${Percents[$i]} + fi + + if [[ $last_dutu -eq '0' ]]; then + if [[ $DUTY -ne '0' ]]; then + echo -n 4 > /sys/class/thermal/cooling_device0/cur_state; + sleep 1s; + echo -n $DUTY > /sys/class/thermal/cooling_device0/cur_state; + else + echo -n 0 > /sys/class/thermal/cooling_device0/cur_state; + fi + else + echo -n $DUTY > /sys/class/thermal/cooling_device0/cur_state; + fi + + last_dutu=$DUTY + echo "temp: $temp, duty: $DUTY, ${PERCENT}%" + sleep 10s; +done \ No newline at end of file