#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2005-2019 System76, Inc.

# This script removes the thunderbolt PCI bridge on suspend and rescans it
# on resume in order to prevent hangs on resume.

set -e

case "$(cat /sys/class/dmi/id/product_version)" in
    darp6 | galp4)
        case "$2" in
            suspend | hybrid-sleep)
                case "$1" in
                    pre)
                        echo 1 > '/sys/devices/pci0000:00/0000:00:1c.0/remove'
                        ;;
                    post)
                        echo 1 > '/sys/devices/pci0000:00/0000:00:00.0/rescan'
                        ;;
                esac
                ;;
        esac
        ;;
esac
