summaryrefslogtreecommitdiff
path: root/pm/sleep.d/98smart-kernel-video
blob: 1c0952b4fecc5dafa24114b27b361147cc449760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
#
# Copyright 2008 Victor Lowther <victor.lowther@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.


. "${PM_FUNCTIONS}"

remove_all_video_quirks()
{
    remove_parameters --quirk-dpms-on \
    	--quirk-dpms-suspend \
	--quirk-s3-mode \
    	--quirk-s3-bios \
	--quirk-vbe-post \
	--quirk-vbe-post \
	--quirk-vga-mode-3 \
	--quirk-vbemode-restore \
	--quirk-vbestate-restore \
	--quirk-reset-brightness \
	--quirk-radeon-off \
	--quirk-no-fb \
	--quirk-save-pci
}

# Test to see if the kernel has a video driver that is smart enough to
# handle quirks without external assistance. If it is, remove the quirks.
have_kms()
{
    # if we are running with a KMS-enabled video driver, we should not
    # attempt to run any quirks
    grep -q -E '(noveau|drm)fb' /proc/fb || return 1
    remove_all_video_quirks
    add_parameters --quirk-no-chvt
}

have_nvidia()
{
    # despite the bad rep the nvidia driver has, it is miles better than
    # any other video driver when it comes to handling power managment and
    # suspend/resume in a quirk-free manner.
    [ -d /sys/module/nvidia ] || return 1
    remove_all_video_quirks
    add_parameters --quirk-no-chvt
}

have_fglrx()
{
    # the ATI driver is pretty good about it, too.
    [ -d /sys/module/fglrx ] || return 1
    remove_all_video_quirks
}

have_smart_intel()
{
    # currently, intel kernel modesetting is not quite smart enough
    # we still need acpi s3 kernel modesetting hooks, so don't remove those
    # options if they were passed.
    [ -d /sys/module/i915 ] || return 1
    local kernel_rev="$(uname -r |awk -F '[_-]' '{print $1}')"
    [ "$kernel_rev" \> "2.6.26" -o "$kernel_rev" = "2.6.26" ] || return 1
    remove_parameters --quirk-dpms-on \
	--quirk-dpms-suspend \
	--quirk-vbe-post \
	--quirk-vbe-post \
	--quirk-vga-mode3 \
	--quirk-vbemode-restore \
	--quirk-vbestate-restore \
	--quirk-reset-brightness \
	--quirk-radeon-off \
	--quirk-no-fb \
	--quirk-pci-save
}

smart_kernel_video() 
{
    have_kms || have_nvidia || have_fglrx || have_smart_intel || return $NA
}

case $1 in
     suspend|hibernate)
	smart_kernel_video ;;
     *) exit 0 ;;
esac