From 9a393799b9428d85e67331b2a32a5dd26c97d77e Mon Sep 17 00:00:00 2001 From: Samuel Jiang Date: Thu, 23 May 2019 14:59:35 +0800 Subject: meta-gsj: quanta-nvme-powerctrl: add shared script Add shared nvme_powerctrl_library script for mantain function It could be easy review steps with specification. (From meta-quanta rev: a9607d7703020f46598b28a4d1cea7be6997b47a) Change-Id: I7d7471005d253a3a0cca6bbcc083d0bfcf7efbc6 Signed-off-by: Samuel Jiang Signed-off-by: Brad Bishop --- .../files/nvme_powerctrl_library.sh | 63 ++++++++++++++++++++++ .../quanta-nvme-powerctrl/quanta-nvme-powerctrl.bb | 6 ++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh (limited to 'meta-quanta/meta-gsj') diff --git a/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh b/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh new file mode 100644 index 000000000..3737aacc1 --- /dev/null +++ b/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_library.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +U2_PRESENT=( 148 149 150 151 152 153 154 155 ) +POWER_U2=( 195 196 202 199 198 197 127 126 ) +PWRGD_U2=( 161 162 163 164 165 166 167 168 ) +RST_BMC_U2=( 72 73 74 75 76 77 78 79 ) +PLUGGED=0 +I2C_BUS=8 +CHIP_ADDR=0x68 +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 + echo $(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 +} diff --git a/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/quanta-nvme-powerctrl.bb b/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/quanta-nvme-powerctrl.bb index 8d0aa8c72..ada2a6a36 100644 --- a/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/quanta-nvme-powerctrl.bb +++ b/meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/quanta-nvme-powerctrl.bb @@ -14,6 +14,7 @@ RDEPENDS_${PN} += "bash" SRC_URI += "file://init_once.sh \ file://nvme_powermanager.sh \ + file://nvme_powerctrl_library.sh \ file://nvme_gpio.service \ file://nvme_powermanager.service \ " @@ -23,9 +24,12 @@ do_install () { 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 + install -m 0644 ${WORKDIR}/nvme_powermanager.service ${D}${systemd_unitdir}/system } SYSTEMD_PACKAGES = "${PN}" -- cgit v1.2.3