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
+ }
+]