armbian-build/packages/bsp/odroid/fanctrl
Patrick Yavitz 40530ee344 Improve Meson64 Support: ODROID
Backport DTS/DTSI changes from linux-6.4.y to 6.1.y
Add meson64-reboot driver to all boards
Add board: ODROID N2L
Add uart_A uart_AO_B uart_B uart_C where appropriate
U-Boot v2023.07.02: ODROID N2/N2L/N2Plus/C4

Meson64-reboot driver: (source: tobetter)
While the current meson64-reboot driver is cleaner and doesn't
depend on modding other kernel sources, its functionality leaves
much to be desired. One example can be found in the ODROID C4.
Using the current driver, the board will not properly power off,
leaving the POWER LED still on. The new driver powers off the unit
completely.

Fan control: (ODROID N2L/N2PLus)
Added service and script for controlling the trip point.
fanctrl: arguments: 65 55 45 35 25 menu run

                              ┌──┤ Fan Control ├──┐
                              │                   │
                              │    6) 65°C        │
                              │    5) 55°C        │
                              │    4) 45°C        │
                              │    3) 35°C        │
                              │    2) 25°C        │
                              │    E) Exit ..     │
                              │                   │
                              │                   │
                              │      <Ok>         │
                              │                   │
                              └───────────────────┘

NOTES: (N2L/HC4): I do not own the units so I can't run tests.

Signed-off-by: Patrick Yavitz <pyavitz@xxxxx.com>
2023-08-20 19:20:06 +02:00

153 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# Description: Odroid N2L / N2Plus Fan Control
if [[ "$USER" == "root" ]]; then
:;
else
if [[ `command -v sudo` ]]; then
if [[ $EUID -ne 0 ]]; then
sudo $0 $@
exit
fi
else
echo "Please run this as root or with sudo privileges."
exit 0
fi
fi
POINT="55000"
FINDME=`command -v fanctrl`
# Functions
warning (){
WARNING_MSG="Argument is not supported."
echo -e "$WARNING_MSG"
exit 0
}
service (){
# A service runs that tests the fan, so lets double tap the trip point and check that it hasn't changed
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
CURRENT=`cat /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp`
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
sleep 5.5 # delay double tapping the trip point
if [[ "$CURRENT" == "$POINT" ]]; then
:;
else
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
fi
fi
}
trip_point (){
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
else
echo -e "You are missing trip_point_3_temp?"
exit 0
fi
}
65(){ # 65°C
sed -i "s/^POINT=.*/POINT="'"65000"'"/" $FINDME
sleep .25
fanctrl run
}
55(){ # 55°C
sed -i "s/^POINT=.*/POINT="'"55000"'"/" $FINDME
sleep .25
fanctrl run
}
45(){ # 45°C
sed -i "s/^POINT=.*/POINT="'"45000"'"/" $FINDME
sleep .25
fanctrl run
}
35(){ # 35°C
sed -i "s/^POINT=.*/POINT="'"35000"'"/" $FINDME
sleep .25
fanctrl run
}
25(){ # 25°C
sed -i "s/^POINT=.*/POINT="'"25000"'"/" $FINDME
sleep .25
fanctrl run
}
run (){ # run script
trip_point
}
menu (){
while [ 1 ]
do
CHOICE=$(
export NEWT_COLORS='root=,black roottext=lightgray,black title=black,lightgray'
whiptail --backtitle "Current Trip Point: $POINT" --title "Fan Control" --menu "" --nocancel 0 0 0 \
"6)" "65°C" \
"5)" "55°C" \
"4)" "45°C" \
"3)" "35°C" \
"2)" "25°C" \
"E)" "Exit .." 3>&2 2>&1 1>&3
)
case $CHOICE in
"6)")
clear -x
fanctrl 65
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 65°C" 0 0
;;
"5)")
clear -x
fanctrl 55
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 55°C" 0 0
;;
"4)")
clear -x
fanctrl 45
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 45°C" 0 0
;;
"3)")
clear -x
fanctrl 35
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 35°C" 0 0
;;
"2)")
clear -x
fanctrl 25
export NEWT_COLORS='root=,black'
whiptail --msgbox " Trip point set to 25°C" 0 0
;;
"E)")
clear -x
exit 0
;;
esac
done
}
if [ $# -eq 0 ]; then
>&2 echo -e "Arguments: 65 55 45 35 25 menu run"
exit 1
fi
case $1 in
65|55|45|35|25|menu|run|service)
;;
*)
echo -e "Arguments: 65 55 45 35 25 menu run" >&2
exit 1
esac
FANCTRL=`echo $1`
$FANCTRL
exit 0