meta-gsj: quanta-nvme-powerctrl: Update package process

Update quanata-nvme-powerctrl process and
delete two duplication function and variable

init_once.sh:
1. Dump input pin information because of confirming HW signal.
2. HW POWER_U2 default is output high. If detect SSD is plugged, don't
   need to initialize POWER_U2 again.
3. Add RST_BMC_U2 steps, check PWRGD_U2 is fine, wait 100ms then st
   RST_BMC_U2 high.

nvme_powermanager.sh:
1. Add RST_BMC_U2 steps, check PWRGD_U2 is fine, wait 100ms then set
   RST_BMC_U2 high.
2. Independent package for power control delete nvme_main DBus property
   trigger and tranfer led trigger to nvem_main package.

Change-Id: I43dcb5848063c68845acf3753ef7ce31ce50e46a
Signed-off-by: Samuel Jiang <Samuel.Jiang@quantatw.com>
diff --git a/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh b/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh
index 91beec5..753c6c4 100644
--- a/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh
+++ b/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh
@@ -1,73 +1,47 @@
 #!/bin/bash
 
+source /usr/libexec/nvme_powerctrl_library.sh
 U2_PRESENT_STATUS=( 1 1 1 1 1 1 1 1 )
-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 )
 
-
-function set_gpio_direction(){
-    #$1 gpio pin, $2 'in','high','low'
-    echo $2 > /sys/class/gpio/gpio$1/direction
+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
 }
 
-function read_present_set_related_power(){
-    #$1 read present number, $2 output power gpio
-    var="${U2_PRESENT_STATUS[$1]}"
-    # present 0 is plugged,present 1 is removal
-    if [ "$var" == "0" ];then
-        set_gpio_direction $2 "high"
-    else 
-        set_gpio_direction $2 "low"
-    fi
-}
-
-function update_u2_status(){
-  #$1 read present gpio
-  var=$(cat /sys/class/gpio/gpio$2/value)
-  U2_PRESENT_STATUS[$1]="$var"
-}
-
-function check_present_and_powergood(){
-    #$2 present gpio, $3 powergood gpio
-    present=$(cat /sys/class/gpio/gpio$2/value)
-    pwrgd=$(cat /sys/class/gpio/gpio$3/value)
-    path=`expr $1`
-    if [ "$present" -eq 0 ] && [ "$pwrgd" -eq 1 ];then        
-        busctl set-property xyz.openbmc_project.nvme.manager /xyz/openbmc_project/nvme/$path xyz.openbmc_project.Inventory.Item Present b true
-    else        
-        busctl set-property xyz.openbmc_project.nvme.manager /xyz/openbmc_project/nvme/$path xyz.openbmc_project.Inventory.Item Present b false
-            if [ "$present" -eq "$pwrgd" ];then
-                #set fault led
-                busctl set-property xyz.openbmc_project.LED.GroupManager /xyz/openbmc_project/led/groups/led\_u2\_$1\_fault xyz.openbmc_project.Led.Group Asserted b true
-            else
-                busctl set-property xyz.openbmc_project.LED.GroupManager /xyz/openbmc_project/led/groups/led\_u2\_$1\_fault xyz.openbmc_project.Led.Group Asserted b false
-            fi
-        
-    fi
-    
-
-}
 
 ##Initial U2 present status
 for i in {0..7};
-do 
-    update_u2_status $i "${U2_PRESENT[$i]}"
+do
+    U2_PRESENT_STATUS[$i]=$(read_gpio_input ${U2_PRESENT[$i]})
 done
 
-
 ## Loop while
 while :
 do
   for i in {0..7};
   do
-    ## 1 scend scan all loop
+    ## 1 second scan all loop
     sleep 0.125
-    read=$(cat /sys/class/gpio/gpio${U2_PRESENT[$i]}/value)
-    if [ "${U2_PRESENT_STATUS[$1]}" != read ];then
-        update_u2_status $i "${U2_PRESENT[$i]}"
-        read_present_set_related_power $i "${POWER_U2[$i]}"
-        check_present_and_powergood $i "${U2_PRESENT[$i]}" "${POWER_U2[$i]}"
-    fi 
+    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