1*9afd92ecSPatrick Williams#!/bin/bash 2*9afd92ecSPatrick Williams 3*9afd92ecSPatrick Williams# Provide source directive to shellcheck. 4*9afd92ecSPatrick Williams# shellcheck source=meta-facebook/meta-greatlakes/recipes-phosphor/state/phosphor-state-manager/power-cmd 5*9afd92ecSPatrick Williamssource /usr/libexec/phosphor-state-manager/power-cmd 6*9afd92ecSPatrick Williams 7*9afd92ecSPatrick WilliamsCHASSIS_ID=$1 8*9afd92ecSPatrick WilliamsSLOT=$(( $1-1 )) 9*9afd92ecSPatrick WilliamsOFFSET=$(( 0x9 + SLOT )) 10*9afd92ecSPatrick Williams 11*9afd92ecSPatrick Williams# Server 12v power off 12*9afd92ecSPatrick Williamschassis-power-off() 13*9afd92ecSPatrick Williams{ 14*9afd92ecSPatrick Williams result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT") 15*9afd92ecSPatrick Williams echo "$result" 16*9afd92ecSPatrick Williams sleep 1 17*9afd92ecSPatrick Williams 18*9afd92ecSPatrick Williams # Check chassis status after doing 12V off 19*9afd92ecSPatrick Williams chassis_status=$(chassis-power-status $SLOT) 20*9afd92ecSPatrick Williams if [ "$chassis_status" == "$STATE_OFF" ] 21*9afd92ecSPatrick Williams then 22*9afd92ecSPatrick Williams busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF" 23*9afd92ecSPatrick Williams echo "Chassis is power off" 24*9afd92ecSPatrick Williams else 25*9afd92ecSPatrick Williams busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON" 26*9afd92ecSPatrick Williams echo "Chassis is power on" 27*9afd92ecSPatrick Williams exit 0; 28*9afd92ecSPatrick Williams fi 29*9afd92ecSPatrick Williams} 30*9afd92ecSPatrick Williams 31*9afd92ecSPatrick Williamschassis_status=$(chassis-power-status $SLOT) 32*9afd92ecSPatrick Williamsif [ "$chassis_status" == "$STATE_UNKNOWN" ] 33*9afd92ecSPatrick Williamsthen 34*9afd92ecSPatrick Williams echo "Invalid slot id" 35*9afd92ecSPatrick Williams exit 1; 36*9afd92ecSPatrick Williamselif [ "$chassis_status" == "$STATE_ON" ] 37*9afd92ecSPatrick Williamsthen 38*9afd92ecSPatrick Williams chassis-power-off 39*9afd92ecSPatrick Williams exit 0; 40*9afd92ecSPatrick Williamselse 41*9afd92ecSPatrick Williams echo "Chassis is already off" 42*9afd92ecSPatrick Williams exit 0; 43*9afd92ecSPatrick Williamsfi 44