meta-facebook: yosemite4: Adjust sled cycle method

Use FRU information to distinguish different sled cycle methods.

PVT or after : notify CPLD by GPIOO7
Before PVT : notify CPLD by CPLD IO expender

Tested:
Did sled cycle on EVT, DVT an PVT system.

Change-Id: Iad82056ff9a57ef6bf39ec1978c5d099b55706a9
Signed-off-by: Marshall Zhan <marshall.zhan.wiwynn@gmail.com>
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
index fe7233e..22c5256 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
@@ -16,9 +16,15 @@
 IO_EXP_SLED_CYCLE=12
 #IO_EXP_BIC_PWR_CTRL=32
 IO_EXP_SLOT_12V_STATUS=$((CHASSIS_ID + 23))
+MANAGEMENT_BOARD_VERSION=$(get_product_version Management_Board)
 
 GPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$SPIDER_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
-GPIOCHIP_IO_EXP_SLED_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MANAGEMENT_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLED_PWR_CTRL_ADDR/"*gpiochip*)
+if [ -z "$MANAGEMENT_BOARD_VERSION" ]; then
+    echo "Failed to check management board fru info, sled cycle keep default setting"
+elif [ "$MANAGEMENT_BOARD_VERSION" = "DVT" ] || [ "$MANAGEMENT_BOARD_VERSION" = "EVT" ]; then
+    GPIOCHIP_IO_EXP_SLED_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MANAGEMENT_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLED_PWR_CTRL_ADDR/"*gpiochip*)
+fi
+
 #GPIOCHIP_IO_EXP_BIC_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$IO_EXP_SLOT_PWR_STATUS-00$IO_EXP_BIC_PWR_CTRL_ADDR/"*gpiochip*)
 
 is_nuvoton_board="$(check_nuvoton_board)"
@@ -88,10 +94,21 @@
     exit 1;
 }
 
+sled-cycle()
+{
+    if [ -z "$MANAGEMENT_BOARD_VERSION" ]; then
+        set_gpio FM_BMC_SLED_CYCLE_R 1
+    elif [ "$MANAGEMENT_BOARD_VERSION" = "DVT" ] || [ "$MANAGEMENT_BOARD_VERSION" = "EVT" ]; then
+        gpio_set "$GPIOCHIP_IO_EXP_SLED_PWR_CTRL" "$IO_EXP_SLED_CYCLE"=1
+    else
+        set_gpio FM_BMC_SLED_CYCLE_R 1
+    fi
+}
+
 if [ "$1" == 0 ]
 then
     echo "Starting sled cycle..."
-    if ! gpio_set "$GPIOCHIP_IO_EXP_SLED_PWR_CTRL" "$IO_EXP_SLED_CYCLE"=1
+    if ! sled-cycle
     then
         echo "Failed to do sled cycle"
     fi
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
index 9d10248..437fd44 100644
--- a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
@@ -23,23 +23,6 @@
     done
 }
 
-# probe devices behind mux for management board cpld
-
-rev_id_gpiochip=$(basename "/sys/bus/i2c/devices/13-0020/"*gpiochip*)
-rev_id_bit0=$(gpioget "$rev_id_gpiochip" 0)
-rev_id_bit1=$(gpioget "$rev_id_gpiochip" 1)
-rev_id_bit2=$(gpioget "$rev_id_gpiochip" 2)
-rev_id_bit3=$(gpioget "$rev_id_gpiochip" 3)
-
-# Default devicetree was set for EVT and later, only POC will do following manual devices' probing
-if [ "$rev_id_bit0" -eq 0 ] && [ "$rev_id_bit1" -eq 0 ] && [ "$rev_id_bit2" -eq 0 ] && [ "$rev_id_bit3" -eq 0 ]
-then
-    echo 24c128 "0x50" > /sys/bus/i2c/devices/i2c-12/new_device
-    echo 24c64 "0x54" > /sys/bus/i2c/devices/i2c-12/new_device
-    echo tmp75 "0x48" > /sys/bus/i2c/devices/i2c-12/new_device
-    echo nct3018y "0x6f" > /sys/bus/i2c/devices/i2c-12/new_device
-fi
-
 # set initial value for GPIO output pins
 set_gpio EN_P5V_USB_CPLD_R    1
 set_gpio EN_NIC0_POWER_BMC_R  1
@@ -51,6 +34,7 @@
 set_gpio FM_BMC_READY_R2      1
 set_gpio SPI_LOCK_REQ_BMC_N   1
 set_gpio EN_P3V_BAT_SCALED_R  0
+set_gpio FM_BMC_SLED_CYCLE_R  0
 
 set_gpio NIC0_MAIN_PWR_EN 1
 set_gpio NIC1_MAIN_PWR_EN 1
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-schematic-init b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-schematic-init
index a68839e..e254977 100644
--- a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-schematic-init
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-schematic-init
@@ -3,13 +3,23 @@
 source /usr/libexec/yosemite4-common-functions
 
 # probe devices behind mux for management board cpld
+mgm_stage=$(get_product_version Management_Board)
 
-stage=$(busctl introspect xyz.openbmc_project.FruDevice /xyz/openbmc_project/FruDevice/Medusa_Board | grep '.PRODUCT_VERSION' | awk -F\" '{print $2}')
+if [ -z "$mgm_stage" ]; then
+    echo "Failed to check management board fru info, all CPLD I/O expender are keeping default setting"
+elif [ "$mgm_stage" = "DVT" ] || [ "$mgm_stage" = "EVT" ]; then
+    echo pca9506 "0x20" > /sys/bus/i2c/devices/i2c-13/new_device
+    echo pca9506 "0x21" > /sys/bus/i2c/devices/i2c-13/new_device
+    echo pca9506 "0x22" > /sys/bus/i2c/devices/i2c-13/new_device
+    echo pca9506 "0x23" > /sys/bus/i2c/devices/i2c-13/new_device
+fi
 
 # set initial value for pca9555 i/o pins on medusa board
-if [ -z "$stage" ]; then
+medusa_stage=$(get_product_version Medusa_Board)
+
+if [ -z "$medusa_stage" ]; then
     echo "Failed to check medusa board fru info, all I/O pins are keeping default input"
-elif [ "$stage" = "POC" ]; then
+elif [ "$medusa_stage" = "POC" ]; then
     set_gpio P48V_OCP_GPIO1       0
     set_gpio P48V_OCP_GPIO2       0
     set_gpio P48V_OCP_GPIO3       0
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
index 5c69011..d8a54c4 100644
--- a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
@@ -26,3 +26,11 @@
     grep nuvoton /sys/firmware/devicetree/base/compatible
     return 0
 }
+
+get_product_version()
+{
+    local FRU_NAME=$1
+    local PRODUCT_VERSION
+    PRODUCT_VERSION=$(busctl get-property xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Yosemite_4_"$FRU_NAME" xyz.openbmc_project.Inventory.Decorator.Revision Version| awk -F\" '{print $2}')
+    echo "$PRODUCT_VERSION"
+}