Files
NANOKVM-LicheeRV-Nano-Build…/buildroot/board/cvitek/SG200X/overlay/etc/init.d/S00pmu
2025-08-04 20:36:48 +08:00

63 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
PMU_BUS=4
PMU_ADDR=0x34
PMU_REG_VER=0x03
pmu_detected() {
pmu_version=$(i2cget -y "$PMU_BUS" "$PMU_ADDR" "$PMU_REG_VER" 2>/dev/null)
if [ $? -ne 0 ]; then
return 1
fi
pmu_version=$((pmu_version & 0xCF))
chip_id_1=$((0x47))
chip_id_2=$((0x4a))
if [ "$pmu_version" -eq "$chip_id_1" ] || [ "$pmu_version" -eq "$chip_id_2" ]; then
return 0
else
return 1
fi
}
start() {
# if ! command -v i2cget &> /dev/null; then
# echo "i2cget not found, please install i2c-tools"
# exit 1
# fi
if pmu_detected; then
exec /usr/bin/axp2101
else
echo "No PMU, skip"
fi
}
stop() {
if pmu_detected; then
runlevel=$(cat /run/runlevel | awk '{ print $1 }')
if [ "$runlevel" = "0" ]; then
echo "Stopping PMU"
value=$(i2cget -y "$PMU_BUS" "$PMU_ADDR" 0x10)
value=$((value | 0x01))
i2cset -y "$PMU_BUS" "$PMU_ADDR" 0x10 $value
fi
else
echo "No PMU, skip"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac