#!/bin/sh

# disable processing of 99video
before_hooks()
{
	disablehook 00clear "disabled by uswsusp"
	disablehook 99video "disabled by uswsusp"
}

get_quirks()
{
	OPTS=""
	ACPI_SLEEP=0
	for opt in $PM_CMDLINE; do
		case "${opt##--quirk-}" in # just quirks, please
			dpms-on) 	   ;; # no-op
			dpms-suspend) 	   ;; # no-op
			radeon-off) 	   OPTS="$OPTS --radeontool" ;;
			reset-brightness)  ;; # no-op
			s3-bios) 	   ACPI_SLEEP=$(($ACPI_SLEEP + 1)) ;;
			s3-mode) 	   ACPI_SLEEP=$(($ACPI_SLEEP + 2)) ;;
			vbe-post) 	   OPTS="$OPTS --vbe_post" ;;
			vbemode-restore)   OPTS="$OPTS --vbe_mode" ;;
			vbestate-restore)  OPTS="$OPTS --vbe_save" ;;
			vga-mode3) 	   ;; # no-op
			save-pci)          OPTS="$OPTS --pci_save" ;;
			none) 		   QUIRK_NONE="true" ;;
			*) continue ;;
		esac
	done
	[ $ACPI_SLEEP -ne 0 ] && OPTS="$OPTS --acpi_sleep $ACPI_SLEEP"
	# if we were told to ignore quirks, do so.
	[ "$QUIRK_NONE" = "true" ] && OPTS=""
}

check_suspend()
{
	command_exists s2ram || return 1
	grep -q mem /sys/power/state || [ -c /dev/pmu ]
}

do_suspend()
{
	get_quirks
	s2ram --force $OPTS
}

check_hibernate()
{
	[ -f /sys/power/disk ] && \
	grep -q disk /sys/power/state && \
	[ -c /dev/snapshot ] &&
	command_exists s2disk	
}

do_hibernate()
{
	s2disk
}

check_suspend_hybrid()
{
	grep -q mem /sys/power/state && \
	command_exists s2both && \
	check_hibernate
}

do_suspend_hybrid()
{
	get_quirks
	s2both --force $OPTS 
}

sleep_method_help()
{
	echo  # first echo makes it look nicer.
	echo "Video quirk handler options:"
	echo
	echo "  --quirk-dpms-on"
	echo "  --quirk-dpms-suspend"
	echo "  --quirk-radeon-off"
	echo "  --quirk-reset-brightness"
	echo "  --quirk-s3-bios"
	echo "  --quirk-s3-mode"
	echo "  --quirk-vbe-post"
	echo "  --quirk-vbemode-restore"
	echo "  --quirk-vbestate-restore"
	echo "  --quirk-vga-mode3"
	echo "  --quirk-save-pci"
	echo "  --quirk-none"
}
