#!/bin/sh
set -e

path=$(find /sys/class/hwmon/*/ -name pwm2_temp_sel -print -quit | sed 's%/[^/]*$%%')
if [ "$SYSTEMD_SLEEP_ACTION" ]; then
	[ $1 = post ] || exit
else
	[ $# -eq 0 ] || path=/sys/class/hwmon/$1
fi

[ "$path" ] || exit 1
cd "$path"

t () {
        i=$1
        temp=$2
        pwm=$3

        echo $(( $temp * 1000 )) > pwm${index}_auto_point${i}_temp
        echo $pwm  > pwm${index}_auto_point${i}_pwm
}

echo 2000 > pwm2_step_up_time
echo 4000 > pwm2_step_down_time

# CPU radiator fan
index=2
echo 7 > pwm${index}_temp_sel # 7=smbus master
echo 5 > pwm${index}_enable  # 5=smartfan vi mode
echo 1 > pwm${index}_mode # 1=pwm fan
t 1   10 0
t 2   70 130
t 3   85 255
t 4   95 255
t 5  100 255

# rear fan
index=5
# 7 = SMBUSMASTER = CPU Tctrl
echo 7 > pwm${index}_temp_sel
echo 5 > pwm${index}_enable
echo 1 > pwm${index}_mode
t 1   70 50
t 2  100 50
t 3  100 255
t 4  100 255
t 5  100 255
