#!/bin/sh BASE_PATH=/sys/class GPIO_PATH="$BASE_PATH"/gpio PWM_PATH="$BASE_PATH"/pwm/pwmchip0 # GPIO pins CPU_FAN=12 # Values LOW=0 HIGH=1 export_pin() { if [ ! -e $GPIO_PATH/gpio"$1" ]; then echo "$1" >$GPIO_PATH/export fi } unexport_pin() { if [ -e $GPIO_PATH/gpio"$1" ]; then echo "$1" >$GPIO_PATH/unexport fi } set_gpio() { export_pin "$1" echo "out" >$GPIO_PATH/gpio"$1"/direction echo "$2" >$GPIO_PATH/gpio"$1"/value if [ "$3" = "clean" ]; then unexport_pin "$1" 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() { if [ "$1" = "clean" ]; then echo 1 >$PWM_PATH/unexport else enable_pwm_channel 1 fi } turn_on() { set_gpio $CPU_FAN $HIGH set_pwm } turn_off() { set_gpio $CPU_FAN $LOW clean set_pwm clean } trap turn_off INT if [ "$1" = "on" ]; then turn_on else turn_off fi exit 0