meta-hpe: dl360-g11 power sequencing
Signed-off-by: Andrew Neyland <andrew.neyland@hpe.com>
Change-Id: I991a2519850214a547b8129281d043a5f8af9d9e
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/dl360Start.sh b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/dl360Start.sh
new file mode 100644
index 0000000..df560e0
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/dl360Start.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# A power up request has been made we must setup the system properly
+# the machine needs to get out of Hold too
+
+# We need to enable UART PortA
+devmem 0x80fc0230 8 0x1
+# clear previous reset reason
+devmem 0x80000074 16 0x0
+# Release the Soc
+currentVal=$(devmem 0xD100011A 8)
+currentVal=$(( currentVal | 1 << 3 ))
+devmem 0xD100011A 8 "0x""${currentVal}"
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.service
new file mode 100644
index 0000000..21711bc
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=HPE virtualnic configuration
+Before=network-pre.target
+Wants=network-pre.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/etc/virtualnic/virtualnic start
+ExecStop=/etc/virtualnic/virtualnic stop
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.sh b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.sh
new file mode 100644
index 0000000..a8dca6f
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpios-manager.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+# File which is managing GPIOS when detected. First parameter is which GPIOs that switched
+if [ "$1" = "up" ]
+then
+ busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b true
+ devmem 0x80fc0230 8 0x1
+ sleep 2
+ devmem 0x80fc0230 8 0x1
+ # Activate local UBM (front NVME drive)
+
+ devmem 0xd1000087 8 1
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 2
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 3
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 4
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000088 8 5
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 6
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 7
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 8
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 9
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xa
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xb
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xc
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xd
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xe
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000087 8 0xf
+ i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
+
+ devmem 0xd1000088 8 3
+ i2ctransfer -y 4 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd1000088 8 4
+ i2ctransfer -y 4 w4@0x40 0x34 0xbf 0x00 0xe8
+
+ devmem 0xd100008a 8 0x13
+ i2ctransfer -y 6 w4@0x40 0x34 0xbf 0x00 0xe8
+ devmem 0xd100008a 8 0x14
+ i2ctransfer -y 6 w4@0x40 0x34 0xbf 0x00 0xe8
+
+# systemctl restart xyz.openbmc_project.EntityManager.service
+# systemctl restart phosphor-pid-control.service
+else
+ if [ "$1" = "down" ]
+ then
+ busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b false
+ # We can re-init the system
+ devmem 0xd1000009 8 0x24
+ # We need to check the reason why we have been shutdown
+ shutdownReason=$(devmem 0x80000074 16)
+ # If bit 10 is set Software initiated a shutdown we need to restart
+ isSet2=$(( shutdownReason | 0xFBFF ))
+ if [ "$isSet2" = "65535" ]
+ then
+ echo "Restarting" >> /tmp/gpios
+ dbus-send --system --dest=xyz.openbmc_project.State.Host --print-reply --type=method_call /xyz/openbmc_project/state/host0 org.freedesktop.DBus.Properties.Set string:RequestedHostTransition variant:string:xyz.openbmc_project.State.Host.Transition.On
+ obmcutil poweron
+ fi
+ fi
+fi
+echo "$1" >> /tmp/gpios.txt
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosdown.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosdown.service
new file mode 100644
index 0000000..2807856
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosdown.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PowerOK
+
+[Service]
+ExecStart=/usr/bin/gpios-manager.sh down
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosup.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosup.service
new file mode 100644
index 0000000..f929a44
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/gpiosup.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PowerOK
+
+[Service]
+ExecStart=/usr/bin/gpios-manager.sh up
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/ipmi-power-button-monitoring.sh b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/ipmi-power-button-monitoring.sh
new file mode 100644
index 0000000..3c1bb0f
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/ipmi-power-button-monitoring.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+dbus-monitor --system --profile "type='method_call',path='/xyz/openbmc_project/state/host0',interface='org.freedesktop.DBus.Properties',member='Set'" | awk '/xyz.openbmc_project.State.Host/ { print "DONE" }' | while read -r; do
+/usr/bin/dl360Start.sh
+done
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/monitor-ipmi-power-transition.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/monitor-ipmi-power-transition.service
new file mode 100644
index 0000000..7b4ecdd
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/monitor-ipmi-power-transition.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=DL360 IPMI power sequencing request
+After=dbus.service
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/bin/ipmi-power-button-monitoring.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-button.sh b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-button.sh
new file mode 100644
index 0000000..e25ae66
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-button.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# File which is managing GPIOS when detected. First parameter is which GPIOs that switched
+if [ "$1" = "pressed" ]
+then
+ busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PButton b true
+else
+ if [ "$1" = "released" ]
+ then
+ busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PButton b false
+ fi
+fi
+echo "$1" >> /tmp/buttons.txt
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-sequencing.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-sequencing.service
new file mode 100644
index 0000000..af28bc9
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/power-sequencing.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=DL360 power sequencing manager
+#After=dbus.service
+After=xyz.openbmc_project.Chassis.Control.Power@0.service
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/bin/startMonitoring.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service
new file mode 100644
index 0000000..dca0f42
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 Power Button
+
+[Service]
+ExecStart=/usr/bin/power-button.sh pressed
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service
new file mode 100644
index 0000000..5433728
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 Power Button Release
+
+[Service]
+ExecStart=/usr/bin/power-button.sh released
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/startMonitoring.sh b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/startMonitoring.sh
new file mode 100644
index 0000000..486591b
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/startMonitoring.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# We just started we have to update the Gpios status
+/usr/bin/phosphor-multi-gpio-monitor --config /usr/share/gpios/test.json
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/test.json b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/test.json
new file mode 100644
index 0000000..0aed0f8
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/files/test.json
@@ -0,0 +1,10 @@
+[
+ {
+ "Name": "PowerGoodUp",
+ "LineName": "PS_PWROK",
+ "EventMon": "BOTH",
+ "TargetRising" : "gpiosup.service",
+ "TargetFalling" : "gpiosdown.service",
+ "Continue": true
+ }
+]
diff --git a/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/power-sequencing.bb b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/power-sequencing.bb
new file mode 100644
index 0000000..d609e3b
--- /dev/null
+++ b/meta-hpe/meta-dl360-g11/recipes-hpe/power-sequencing/power-sequencing.bb
@@ -0,0 +1,31 @@
+inherit obmc-phosphor-systemd
+SUMMARY = "Power Sequencing for HPE DL360 Gen11"
+SYSTEMD_AUTO_ENABLE = "enable"
+SYSTEMD_SERVICE:${PN} = "monitor-ipmi-power-transition.service power-sequencing.service gpiosdown.service gpiosup.service powerbuttonpressed.service powerbuttonreleased.service"
+SRC_URI:append = " file://monitor-ipmi-power-transition.service file://ipmi-power-button-monitoring.sh file://dl360Start.sh file://power-sequencing.service file://gpiosdown.service file://gpiosup.service file://gpios-manager.sh file://test.json file://powerbuttonreleased.service file://powerbuttonpressed.service file://power-button.sh file://startMonitoring.sh"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+IMAGE_INSTALL += "power-sequencing "
+
+FILES:${PN} = "/usr/share/gpios/* /usr/bin/* /etc/system/*"
+
+do_install:append() {
+ install -d ${D}${sysconfdir}/system/
+ install -d ${D}/usr/share/gpios
+ install -d ${D}/usr/bin
+ install -m 0644 ${WORKDIR}/test.json ${D}/usr/share/gpios/test.json
+ install -m 0644 ${WORKDIR}/power-sequencing.service ${D}${sysconfdir}/system/power-sequencing.service
+ install -m 0644 ${WORKDIR}/gpiosup.service ${D}${sysconfdir}/system/gpiosup.service
+ install -m 0644 ${WORKDIR}/gpiosdown.service ${D}${sysconfdir}/system/gpiosdown.service
+ install -m 0644 ${WORKDIR}/powerbuttonpressed.service ${D}${sysconfdir}/system/powerbuttonpressed.service
+ install -m 0644 ${WORKDIR}/powerbuttonreleased.service ${D}${sysconfdir}/system/powerbuttonreleased.service
+ install -m 0644 ${WORKDIR}/monitor-ipmi-power-transition.service ${D}${sysconfdir}/system/monitor-ipmi-power-transition.service
+ install -m 0755 ${WORKDIR}/gpios-manager.sh ${D}/usr/bin/gpios-manager.sh
+ install -m 0755 ${WORKDIR}/startMonitoring.sh ${D}/usr/bin/startMonitoring.sh
+ install -m 0755 ${WORKDIR}/dl360Start.sh ${D}/usr/bin/dl360Start.sh
+ install -m 0755 ${WORKDIR}/ipmi-power-button-monitoring.sh ${D}/usr/bin/ipmi-power-button-monitoring.sh
+ install -m 0755 ${WORKDIR}/power-button.sh ${D}/usr/bin/power-button.sh
+}
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosdown.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosdown.service
deleted file mode 100644
index a2416b6..0000000
--- a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosdown.service
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=HPE RL300 PowerOK
-
-[Service]
-ExecStart=/usr/bin/gpios-manager down
-
-[Install]
-# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosup.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosup.service
deleted file mode 100644
index 7aed15b..0000000
--- a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/gpiosup.service
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=HPE RL300 PowerOK
-
-[Service]
-ExecStart=/usr/bin/gpios-manager up
-
-[Install]
-# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service
deleted file mode 100644
index f3d28ea..0000000
--- a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonpressed.service
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=HPE RL300 Power Button
-
-[Service]
-ExecStart=/usr/bin/power-button pressed
-
-[Install]
-# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service
deleted file mode 100644
index 65e1b40..0000000
--- a/meta-hpe/meta-rl300-g11/recipes-hpe/power-sequencing/files/powerbuttonreleased.service
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=HPE RL300 Power Button Release
-
-[Service]
-ExecStart=/usr/bin/power-button released
-
-[Install]
-# WantedBy=multi-user.target