blob: 919624d225349f85434478b961a41cd5ef235ff9 [file] [log] [blame]
Charles Kearney92a3faa2023-05-30 14:24:18 -05001#!/bin/sh
2# File which is managing GPIOS when detected. First parameter is which GPIOs that switched
3if [ "$1" = "up" ]
4then
5 systemctl stop xyz.openbmc_project.ampere_host_error_monitor.service
6 rmmod smpro_hwmon smpro_errmon smpro_misc smpro_mfd
7 busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b true
8 smproStatus=$(lsmod | grep smpro-mfd)
9 if [ "$smproStatus" = "" ]
10 then
11 # sleep 15
12 # We need to wait for the SoC to be ready to communicate - We just received the PGOOD signal
13 # The status is reported through an interrupt that we can poll at 2e within the CPLD address space (0xd100_00e2)
14 max_retry=5
15 sleep_time=5
16 success=0
17 while [ "$max_retry" != "0" ]
18 do
19 waitForSoC=$(devmem 0xd10000e2 8)
20 isAvailable=$(( waitForSoC & 0x2 ))
21 if [ "r$isAvailable" = "r2" ]
22 then
23 max_retry=0
24 success=1
25 else
26 max_retry=$(( max_retry - 1))
27 sleep $sleep_time
28 fi
29 done
30 if [ "$success" = "1" ]
31 then
32 # Activate local UBM (front NVME drive)
33 devmem 0xd1000087 8 5
34 i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
35 i2ctransfer -y 3 w2@0x40 0x34 0xa7 r1
36
37 devmem 0xd1000087 8 7
38 i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
39 i2ctransfer -y 3 w2@0x40 0x34 0xa7 r1
40
41 devmem 0xd1000087 8 9
42 i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
43 i2ctransfer -y 3 w2@0x40 0x34 0xa7 r1
44
45 devmem 0xd1000087 8 0xb
46 i2ctransfer -y 3 w4@0x40 0x34 0xbf 0x00 0xe8
47 i2ctransfer -y 3 w2@0x40 0x34 0xa7 r1
48
49 devmem 0xd1000088 8 5
50 i2ctransfer -y 4 w4@0x40 0x34 0xbf 0x00 0xe8
51 i2ctransfer -y 4 w2@0x40 0x34 0xa7 r1
52
53 modprobe smpro-misc
54 modprobe smpro-errmon
55 modprobe smpro-hwmon
56 modprobe smpro-mfd
57 systemctl restart xyz.openbmc_project.ampere_host_error_monitor.service
58 systemctl restart xyz.openbmc_project.amperecpusensor.service
59 systemctl restart xyz.openbmc_project.EntityManager.service
60 systemctl restart phosphor-pid-control.service
61 fi
62 # We shall add a condition here to make an emergency stop
63 fi
64else
65 if [ "$1" = "down" ]
66 then
67 busctl set-property xyz.openbmc_project.Chassis.Gpios /xyz/openbmc_project/chassis/gpios xyz.openbmc_project.Chassis.Gpios PGood b false
68 # We can re-init the system
69 devmem 0xd1000009 8 0x24
70 # We need to check the reason why we have been shutdown
71 shutdownReason=$(devmem 0x80000074 16)
72 # If bit 10 is set Software initiated a shutdown we need to restart
73 isSet2=$( ${shutdownReason} | 0xFBFF )
74 if [ "$isSet2" = "65535" ]
75 then
76 echo "Restarting" >> /tmp/gpios
77 obmcutil poweron
78 fi
79 fi
80fi
81echo "$1" >> /tmp/gpios.txt