1*cf8f746cSAndrew Neyland#!/bin/sh
2*cf8f746cSAndrew Neyland# File which is managing GPIOS when detected. First parameter is which GPIOs that switched
3*cf8f746cSAndrew Neylandif [ "$1" = "up" ]
4*cf8f746cSAndrew Neylandthen
5*cf8f746cSAndrew Neyland	busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b true
6*cf8f746cSAndrew Neyland	devmem 0x80fc0230 8 0x1
7*cf8f746cSAndrew Neyland	sleep 2
8*cf8f746cSAndrew Neyland	devmem 0x80fc0230 8 0x1
9*cf8f746cSAndrew Neyland	# Activate local UBM (front NVME drive)
10*cf8f746cSAndrew Neyland
11*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 1
12*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
13*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 2
14*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
15*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 3
16*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
17*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 4
18*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
19*cf8f746cSAndrew Neyland	devmem 0xd1000088 8 5
20*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
21*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 6
22*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
23*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 7
24*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
25*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 8
26*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
27*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 9
28*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
29*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xa
30*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
31*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xb
32*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
33*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xc
34*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
35*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xd
36*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
37*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xe
38*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
39*cf8f746cSAndrew Neyland	devmem 0xd1000087 8 0xf
40*cf8f746cSAndrew Neyland	i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
41*cf8f746cSAndrew Neyland
42*cf8f746cSAndrew Neyland	devmem 0xd1000088 8 3
43*cf8f746cSAndrew Neyland	i2ctransfer -y 4 w4@0x40 0x34 0xbf 0x00 0xe8
44*cf8f746cSAndrew Neyland	devmem 0xd1000088 8 4
45*cf8f746cSAndrew Neyland	i2ctransfer -y 4 w4@0x40 0x34 0xbf 0x00 0xe8
46*cf8f746cSAndrew Neyland
47*cf8f746cSAndrew Neyland	devmem 0xd100008a 8 0x13
48*cf8f746cSAndrew Neyland	i2ctransfer -y 6 w4@0x40 0x34 0xbf 0x00 0xe8
49*cf8f746cSAndrew Neyland	devmem 0xd100008a 8 0x14
50*cf8f746cSAndrew Neyland	i2ctransfer -y 6 w4@0x40 0x34 0xbf 0x00 0xe8
51*cf8f746cSAndrew Neyland
52*cf8f746cSAndrew Neyland#	systemctl restart xyz.openbmc_project.EntityManager.service
53*cf8f746cSAndrew Neyland#	systemctl restart phosphor-pid-control.service
54*cf8f746cSAndrew Neylandelse
55*cf8f746cSAndrew Neyland	if [ "$1" = "down" ]
56*cf8f746cSAndrew Neyland	then
57*cf8f746cSAndrew Neyland		busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b false
58*cf8f746cSAndrew Neyland		# We can re-init the system
59*cf8f746cSAndrew Neyland		devmem 0xd1000009 8 0x24
60*cf8f746cSAndrew Neyland		# We need to check the reason why we have been shutdown
61*cf8f746cSAndrew Neyland		shutdownReason=$(devmem 0x80000074 16)
62*cf8f746cSAndrew Neyland		# If bit 10 is set Software initiated a shutdown we need to restart
63*cf8f746cSAndrew Neyland		isSet2=$(( shutdownReason | 0xFBFF ))
64*cf8f746cSAndrew Neyland		if [ "$isSet2" = "65535" ]
65*cf8f746cSAndrew Neyland		then
66*cf8f746cSAndrew Neyland			echo "Restarting" >> /tmp/gpios
67*cf8f746cSAndrew Neyland			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
68*cf8f746cSAndrew Neyland			obmcutil poweron
69*cf8f746cSAndrew Neyland		fi
70*cf8f746cSAndrew Neyland	fi
71*cf8f746cSAndrew Neylandfi
72*cf8f746cSAndrew Neylandecho "$1" >> /tmp/gpios.txt
73