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,46 @@
### NVME SSD Power Control Manager
#### Description
The package mantains for SSD power control and related noification handle Deamon
#### Design
The service power supply design follow PCI Express Card Electromechanical Specification Revision 3.0 in Section 2.2
nvme_gpio.service follow section 2.2.1 Initial power-Up to initinal and adjust related signal.
nvme_powermanager.service follow section 2.2.2 power management states monitor PRESENT signal and update related signal.
#### Process
* Plugging
1. U2_[SSD_index] PRSNT_N will be input low
2. Set PWR_U2_[SSD_index]_EN to high
3. Check PWRGD_U2_[SSD_index] is high
4-1. If PWRGD_U2_[SSD_index] is high (PWR Good)
- Wait 5ms
- Enable PCI Clock by SMBus 9FGL0851
- Wait 100ms
- Set RST_BMC_U2 to high
4-2. If PWRGD_U2_[SSD_index] is low (PWR Fail)
- Set RST_BMC_U2_[SSD_index]_R_N to low
- Wait 100ms
- Disable PCI Clock by SMBus
* Removing
1. U2_[SSD_index] PRSNT_N will be input high
2. Set RST_BMC_U2 to low
3. Wait 100ms
4. Disable PCI Clock by SMBus
5. Wait 5ms
6. PWR_U2_[SSD_index]_EN to low
#### Test
1. PRESENT detect SSD: The hardware design has been implemented.
2. Initial SSD slot Power output: nvme_gpio service has tested on Module. It could sucess initial gpios and set correct power output.
3. Detect PRESENT and change power setting: nvme_powermanager service has tested on Module. It could success detect SSD plugged or removal change power output.
4. Improve initial power-up sequence: For matched hardware default initial power-up setting, the nvme_gpio service only set unplugged slot related signal.
5. Improve service execute sequence: nvme_powermanager.service must wait for nvme_gpio.service ensure gpio export complete.
@@ -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
@@ -0,0 +1,37 @@
SUMMARY = "Phosphor OpenBMC Quanta NVME Power Control Service"
DESCRIPTION = "Phosphor OpenBMC Quanta NVME Power Control Daemon."
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
FILESEXTRAPATHS:append := "${THISDIR}/files:"
inherit systemd
DEPENDS += "systemd"
RDEPENDS:${PN} += "libsystemd"
RDEPENDS:${PN} += "bash"
RDEPENDS:${PN} += "iotools"
SRC_URI += "file://init_once.sh \
file://nvme_powermanager.sh \
file://nvme_powerctrl_library.sh \
file://nvme_gpio.service \
file://nvme_powermanager.service \
"
do_install () {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/init_once.sh ${D}${bindir}/
install -m 0755 ${WORKDIR}/nvme_powermanager.sh ${D}${bindir}/
install -d ${D}${libexecdir}
install -m 0755 ${WORKDIR}/nvme_powerctrl_library.sh ${D}${libexecdir}/
install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/nvme_gpio.service ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/nvme_powermanager.service ${D}${systemd_unitdir}/system
}
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = "nvme_gpio.service nvme_powermanager.service"