summaryrefslogtreecommitdiff
path: root/meta-facebook
diff options
context:
space:
mode:
authorPotin Lai <potin.lai@quantatw.com>2022-04-01 06:16:50 +0300
committerPatrick Williams <patrick@stwcx.xyz>2022-04-13 16:38:09 +0300
commitdc251664c3383c438c712daef53206d093fb0f4c (patch)
tree1c26b4c79cd6fd9c6c5e7379581fc805921342bb /meta-facebook
parent01e8355e63a322fc4bcb6df54bca7363059a5f93 (diff)
downloadopenbmc-dc251664c3383c438c712daef53206d093fb0f4c.tar.xz
meta-bletchley: motor-ctrl: add host status checking
Use mdio-util command to communicate with switch phy, and get port link status represent for host status. This feature is not support with EVT system due to MDIO0 is not connected. Tested on reworked EVT HW: root@bletchley:~# power-ctrl sled6 off Power off sled6 Motor go forward to press Power key Power key switch triggered Press power key for Sled6 5 seconds... Motor reverse to initial position successful root@bletchley:~# power-ctrl sled6 status Off root@bletchley:~# power-ctrl sled6 on Power on sled6 Motor go forward to press Power key Power key switch triggered Press power key for Sled6 0.5 seconds... Motor reverse to initial position successful root@bletchley:~# power-ctrl sled6 status On Signed-off-by: Potin Lai <potin.lai@quantatw.com> Change-Id: I523013447da9ed210499f5dca960f708292a4b33
Diffstat (limited to 'meta-facebook')
-rwxr-xr-xmeta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl106
-rw-r--r--meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/motor-ctrl_0.1.bb1
2 files changed, 101 insertions, 6 deletions
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
index 9395b9d304..523eb26d4d 100755
--- a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
@@ -159,6 +159,78 @@ function get_ac_status(){
fi
}
+function get_host_status()
+{
+ SLED_NUM=$1
+ MDIO_BUS=0
+ HOST_ST_UNKNOW="Unknow"
+ HOST_ST_ON="On"
+ HOST_ST_OFF="Off"
+ declare -a PORT_MAP=(0 3 2 1 7 6 5)
+
+ # check /dev/mem
+ if ! create_dev_mem; then
+ return 1
+ fi
+
+ CHECK_CNT=0
+ MDIO_ERR_CNT=0
+ CUR_HOST_ST=$HOST_ST_UNKNOW
+
+ while true
+ do
+ if POST_ST_VAL=$(mdio-util c22 r $MDIO_BUS "${PORT_MAP[SLED_NUM]}" 0); then
+ if [ $((POST_ST_VAL&16#0800)) -eq $((16#0800)) ]; then
+ TMP_HOST_ST="$HOST_ST_ON"
+ else
+ TMP_HOST_ST="$HOST_ST_OFF"
+ fi
+
+ if [ "$CUR_HOST_ST" == "$TMP_HOST_ST" ]; then
+ CHECK_CNT=$((CHECK_CNT+1))
+ else
+ CUR_HOST_ST=$TMP_HOST_ST
+ CHECK_CNT=0
+ fi
+
+ if [ "$CHECK_CNT" -ge 5 ]; then
+ echo "$CUR_HOST_ST"
+ break
+ fi
+ else
+ MDIO_ERR_CNT=$((MDIO_ERR_CNT+1))
+ if [ "$MDIO_ERR_CNT" -ge 5 ]; then
+ echo "$HOST_ST_UNKNOW"
+ return 1
+ fi
+ fi
+ done
+
+ return 0
+}
+
+function create_dev_mem()
+{
+ CHECK_CNT=0
+ while true
+ do
+ CHECK_CNT=$((CHECK_CNT+1))
+ if [ -c /dev/mem ]; then
+ # /dev/mem already exist
+ return 0
+ elif mknod /dev/mem c 1 1; then
+ # mknod success
+ return 0
+ elif [ "$CHECK_CNT" -ge 5 ]; then
+ break
+ fi
+ sleep 1
+ done
+
+ echo "create /dev/mem failed"
+ return 1
+}
+
function show_usage(){
echo "Usage: power-ctrl [sled1 | sled2 | sled3 | sled4 | sled5 | sled6] [on off ac-on ac-off status]"
echo " power-ctrl chassis-cycle"
@@ -201,23 +273,45 @@ fi
if [[ "$ACTION" == "on" ]]; then
if [ "$(get_ac_status "$SLED_NUM")" == "AC on" ];then
- echo "Power on ${SLED}"
- trigger_power_button "$SLED_NUM" "$DELAY_POWER_ON"
+ host_power_st=$(get_host_status "$SLED_NUM")
+ if [ "$host_power_st" == "On" ]; then
+ echo "${SLED} is already On"
+ elif [ "$host_power_st" == "Off" ]; then
+ echo "Power on ${SLED}"
+ trigger_power_button "$SLED_NUM" "$DELAY_POWER_ON"
+ else
+ echo "${SLED} power state is $host_power_st"
+ exit 1
+ fi
else
echo "${SLED} is ac-off, please turn on ac before power on"
exit 1
fi
elif [[ "$ACTION" == "off" ]];then
if [ "$(get_ac_status "$SLED_NUM")" == "AC on" ];then
- echo "Power off ${SLED}"
- trigger_power_button "$SLED_NUM" "$DELAY_POWER_OFF"
+ host_power_st=$(get_host_status "$SLED_NUM")
+ if [ "$host_power_st" == "On" ]; then
+ echo "Power off ${SLED}"
+ trigger_power_button "$SLED_NUM" "$DELAY_POWER_OFF"
+ elif [ "$host_power_st" == "Off" ]; then
+ echo "${SLED} is already Off"
+ else
+ echo "${SLED} power state is $host_power_st"
+ exit 1
+ fi
else
echo "${SLED} is already ac-off"
exit 1
fi
elif [[ "$ACTION" == "status" ]];then
- get_ac_status "$SLED_NUM"
- #TODO : check or record Host(DC) power status
+ AC_ST=$(get_ac_status "$SLED_NUM")
+ if [ "$AC_ST" == "AC on" ]; then
+ # check host power status if AC is on
+ get_host_status "$SLED_NUM" || exit 1
+ else
+ # AC off
+ echo "$AC_ST"
+ fi
elif [[ "$ACTION" == "ac-on" ]];then
set_gpio "power-host${SLED_NUM}" 1
elif [[ "$ACTION" == "ac-off" ]];then
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/motor-ctrl_0.1.bb b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/motor-ctrl_0.1.bb
index 41e0ce9f15..3cab5e2781 100644
--- a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/motor-ctrl_0.1.bb
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/motor-ctrl_0.1.bb
@@ -8,6 +8,7 @@ inherit obmc-phosphor-systemd
RDEPENDS:${PN} += "bash"
RDEPENDS:${PN} += "i2c-tools"
RDEPENDS:${PN} += "libgpiod-tools"
+RDEPENDS:${PN} += "mdio-util"
S = "${WORKDIR}"
SRC_URI += " \