Incomplete: Enable HW PWM timers for the HDD fan

This commit is contained in:
coolneng 2022-05-16 23:30:06 +02:00
parent ec3588bcf8
commit 62a33ef405
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 24 additions and 10 deletions

View File

@ -2,14 +2,12 @@
BASE_PATH=/sys/class BASE_PATH=/sys/class
GPIO_PATH="$BASE_PATH"/gpio GPIO_PATH="$BASE_PATH"/gpio
PWM_PATH="$BASE_PATH"/pwm PWM_PATH="$BASE_PATH"/pwm/pwmchip0
# GPIO pins # GPIO pins
SATA0=26 SATA0=26
SATA1=25 SATA1=25
# PWM pins
CPU_FAN=12 CPU_FAN=12
HDD_FAN=13
# Values # Values
LOW=0 LOW=0
@ -27,7 +25,7 @@ unexport_pin() {
fi fi
} }
set_mode() { set_gpio() {
export_pin "$1" export_pin "$1"
echo "out" >$GPIO_PATH/gpio"$1"/direction echo "out" >$GPIO_PATH/gpio"$1"/direction
echo "$2" >$GPIO_PATH/gpio"$1"/value echo "$2" >$GPIO_PATH/gpio"$1"/value
@ -36,17 +34,33 @@ set_mode() {
fi fi
} }
enable_pwm_channel() {
echo "$1" >$PWM_PATH/export
echo 40000 >$PWM_PATH/pwm"$1"/period
echo 30000 >$PWM_PATH/pwm"$1"/duty_cycle
echo 1 >$PWM_PATH/pwm"$1"/enable
}
set_pwm() {
enable_pwm_channel 1
if [ "$1" = "clean" ]; then
echo 0 >$PWM_PATH/unexport
fi
}
turn_on() { turn_on() {
set_mode $SATA0 $HIGH set_gpio $SATA0 $HIGH
sleep 1 sleep 1
set_mode $SATA1 $HIGH set_gpio $SATA1 $HIGH
set_mode $CPU_FAN $HIGH set_gpio $CPU_FAN $HIGH
set_pwm
} }
turn_off() { turn_off() {
set_mode $SATA0 $LOW clean set_gpio $SATA0 $LOW clean
set_mode $SATA1 $LOW clean set_gpio $SATA1 $LOW clean
set_mode $CPU_FAN $LOW clean set_gpio $CPU_FAN $LOW clean
set_pwm clean
} }
trap turn_off INT trap turn_off INT