Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,59 @@
#!/bin/bash
# shellcheck source=meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh
source /usr/libexec/nvme_powerctrl_library.sh
function set_gpio() {
#$1 gpio pin
echo "$1" > /sys/class/gpio/export
}
echo "Read Clock Gen Value is: $CLOCK_GEN_VALUE"
## Initial U2_PRESENT_N
for i in "${!U2_PRESENT[@]}";
do
set_gpio "${U2_PRESENT[$i]}";
set_gpio_direction "${U2_PRESENT[$i]}" 'in';
echo "Read $i SSD present: $(read_gpio_input "${U2_PRESENT[$i]}")"
done
## Initial POWER_U2_EN
for i in "${!POWER_U2[@]}";
do
set_gpio "${POWER_U2[$i]}";
done
## Initial PWRGD_U2
for i in "${!PWRGD_U2[@]}";
do
set_gpio "${PWRGD_U2[$i]}";
set_gpio_direction "${PWRGD_U2[$i]}" 'in';
echo "Read $i SSD Power Good: $(read_gpio_input "${PWRGD_U2[$i]}")"
done
## Initial RST_BMC_U2
for i in "${!RST_BMC_U2[@]}";
do
set_gpio "${RST_BMC_U2[$i]}";
done
### Initial related Power by Present
for i in {0..7};
do
update_value=$(printf '%x\n' "$((0x01 << i))")
if [ "$(read_gpio_input "${U2_PRESENT[$i]}")" == $PLUGGED ];then
CLOCK_GEN_VALUE=$(printf '0x%x\n' \
"$((CLOCK_GEN_VALUE | 0x$update_value))")
else
set_gpio_direction "${RST_BMC_U2[$i]}" "low"
set_gpio_direction "${POWER_U2[$i]}" "low"
CLOCK_GEN_VALUE=$(printf '0x%x\n' \
"$((CLOCK_GEN_VALUE & ~0x$update_value))")
fi
done
i2cset -y $I2C_BUS $CHIP_ADDR 0 "$CLOCK_GEN_VALUE" s
echo "Read Clock Gen Value again is: $CLOCK_GEN_VALUE"
exit 0;
@@ -0,0 +1,12 @@
[Unit]
Description = configure GPIO for SSD Power Control
Before=nvme_powermanager.service
[Service]
Restart=no
RemainAfterExit=true
Type=oneshot
ExecStart=/usr/bin/init_once.sh
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,65 @@
#!/bin/bash
export U2_PRESENT=( 148 149 150 151 152 153 154 155 )
export POWER_U2=( 195 196 202 199 198 197 127 126 )
export PWRGD_U2=( 161 162 163 164 165 166 167 168 )
export RST_BMC_U2=( 72 73 74 75 76 77 78 79 )
export PLUGGED=0
export I2C_BUS=8
export CHIP_ADDR=0x68
export CLOCK_GEN_VALUE=
CLOCK_GEN_VALUE=$(i2cget -y $I2C_BUS $CHIP_ADDR 0 i 2|cut -f3 -d' ')
function set_gpio_direction()
{
#$1 gpio pin, $2 'in','high','low'
echo "$2" > "/sys/class/gpio/gpio$1/direction"
}
function read_gpio_input()
{
#$1 read input gpio pin
cat "/sys/class/gpio/gpio$1/value"
}
function enable_nvme_power()
{
set_gpio_direction "${POWER_U2[$1]}" "high"
sleep 0.04
check_powergood "$1"
}
function check_powergood()
{
if [ "$(read_gpio_input "${PWRGD_U2[$1]}")" == 1 ];then
sleep 0.005
update_clock_gen_chip_register "$1" 1
sleep 0.1
set_gpio_direction "${RST_BMC_U2[$1]}" "high"
else
disable_nvme_power "$1"
fi
}
function disable_nvme_power()
{
set_gpio_direction "${RST_BMC_U2[$1]}" "low"
sleep 0.1
update_clock_gen_chip_register "$1" 0
sleep 0.005
set_gpio_direction "${POWER_U2[$1]}" "low"
}
function update_clock_gen_chip_register(){
#$1 nvme slot number, $2 enable/disable
update_value=$(printf '%x\n' "$((0x01 <<$1))")
if [ "$2" -eq 1 ];then
CLOCK_GEN_VALUE=$(printf '0x%x\n' \
"$((CLOCK_GEN_VALUE | 0x$update_value))")
else
CLOCK_GEN_VALUE=$(printf '0x%x\n' \
"$((CLOCK_GEN_VALUE & ~0x$update_value))")
fi
i2cset -y $I2C_BUS $CHIP_ADDR 0 "$CLOCK_GEN_VALUE" s
}
@@ -0,0 +1,11 @@
[Unit]
Description=SSD NVME Power Manager
Requires=nvme_gpio.service
After=nvme_gpio.service
[Service]
ExecStart=/usr/bin/nvme_powermanager.sh
Restart=always
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,48 @@
#!/bin/bash
# shellcheck source=meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh
source /usr/libexec/nvme_powerctrl_library.sh
U2_PRESENT_STATUS=( 1 1 1 1 1 1 1 1 )
function recovery_power()
{
set_gpio_direction "${POWER_U2[$1]}" "low"
sleep 0.2
set_gpio_direction "${POWER_U2[$1]}" "high"
sleep 0.2
check_powergood "$1"
}
##Initial U2 present status
for i in {0..7};
do
U2_PRESENT_STATUS[i]=$(read_gpio_input "${U2_PRESENT[$i]}")
done
## Loop while
while :
do
for i in {0..7};
do
## 1 second scan all loop
sleep 0.125
read_present=$(read_gpio_input "${U2_PRESENT[$i]}")
if [ "$read_present" != "${U2_PRESENT_STATUS[$i]}" ];then
U2_PRESENT_STATUS[i]="$read_present"
if [ "$read_present" == $PLUGGED ];then
echo "NVME $i Enable Power"
enable_nvme_power "$i"
else
echo "NVME $i Disable Power"
disable_nvme_power "$i"
fi
else
if [ "${U2_PRESENT_STATUS[$i]}" == $PLUGGED ] &&
[ "$(read_gpio_input "${PWRGD_U2[$i]}")" == 0 ];then
echo "NVME $i Recovery Power"
recovery_power "$i"
fi
fi
done
done