1e81cec1eSBright Cheng#!/bin/bash
2e81cec1eSBright Cheng
3*173fe438SLora Lin# Provide source directive to shellcheck.
4*173fe438SLora Lin# shellcheck source=meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
5*173fe438SLora Linsource /usr/libexec/phosphor-state-manager/power-cmd
6*173fe438SLora Lin# shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
7*173fe438SLora Linsource /usr/libexec/yosemite4-common-functions
8*173fe438SLora Lin
9e81cec1eSBright Cheng# Handle chassis and host power state for chassis poweron failure.
10e81cec1eSBright Cheng
11e81cec1eSBright ChengCHASSIS_ID=$1
12*173fe438SLora LinIO_EXP_SLOT_PWR_STATUS=$((CHASSIS_ID - 1))
13e81cec1eSBright Cheng
14*173fe438SLora LinGPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$SPIDER_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
15*173fe438SLora Lin
16*173fe438SLora Linchassis_status=$(get_ac_on_status "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
17*173fe438SLora Linif [ "$chassis_status" == "$STATE_OFF" ]
18*173fe438SLora Linthen
19e81cec1eSBright Cheng    # Stop obmc-chassis-poweron.target to avoid chassis-state-manager to set power state to On.
20e81cec1eSBright Cheng    /bin/systemctl stop obmc-chassis-poweron@"${CHASSIS_ID}".target
21e81cec1eSBright Cheng
22e81cec1eSBright Cheng    # Set chassis power state to Off.
23e81cec1eSBright Cheng    /bin/sh -c "busctl set-property $(mapper get-service /xyz/openbmc_project/state/chassis"${CHASSIS_ID}") \
24e81cec1eSBright Cheng        /xyz/openbmc_project/state/chassis${CHASSIS_ID} \
25e81cec1eSBright Cheng        xyz.openbmc_project.State.Chassis CurrentPowerState \
26e81cec1eSBright Cheng        s xyz.openbmc_project.State.Chassis.PowerState.Off"
27*173fe438SLora Linfi
28