Brandon Kim | f271434 | 2020-08-12 19:15:12 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # PSU hard reset (power cycle) script. |
| 4 | # |
| 5 | # Power cycle the entire tray by setting the PSU hotswap reset (GPIO218) to high |
| 6 | # |
| 7 | # Global variable: PSU_HARDRESET_DELAY specifies the number of seconds to wait |
| 8 | # before pulling the trigger. If not specified or zero, the script power cycles |
| 9 | # immediately. |
George Hung | 2143eac | 2020-12-29 14:09:09 +0800 | [diff] [blame] | 10 | |
| 11 | ################################################## |
| 12 | # Stop the phosphor-hwmon daemon |
| 13 | # Return: |
| 14 | # 0 if success, non-zero if error |
| 15 | ################################################## |
| 16 | stop_phosphor_hwmon() { |
| 17 | if (( $# != 0 )); then |
| 18 | echo 'Usage: stop_phosphor_hwmon' >&2 |
| 19 | return 1 |
| 20 | fi |
| 21 | |
| 22 | echo "Stopping phosphor-hwmon" >&2 |
| 23 | local srv='system-xyz.openbmc_project.Hwmon.slice' |
| 24 | systemctl stop "${srv}" |
| 25 | } |
| 26 | |
Brandon Kim | f271434 | 2020-08-12 19:15:12 -0700 | [diff] [blame] | 27 | main() { |
| 28 | # Sleep PSU_HARDRESET_DELAY seconds |
| 29 | local psu_delay=$((PSU_HARDRESET_DELAY)) |
| 30 | if ((psu_delay > 0)); then |
| 31 | echo "Sleeping ${psu_delay} seconds before PSU hard reset!" |
| 32 | sleep "${psu_delay}" |
| 33 | fi |
| 34 | |
George Hung | 2143eac | 2020-12-29 14:09:09 +0800 | [diff] [blame] | 35 | # Stop phosphor-hwmon so that ADM1272 powercycle doesn't happen |
| 36 | # in the middle of an i2c transaction and stuck the bus low |
| 37 | stop_phosphor_hwmon |
| 38 | |
Brandon Kim | f271434 | 2020-08-12 19:15:12 -0700 | [diff] [blame] | 39 | gpioset gpiochip6 26=1 |
| 40 | } |
| 41 | |
| 42 | # Exit without running main() if sourced |
| 43 | return 0 2>/dev/null |
| 44 | |
| 45 | main "$@" |