File: hardware_tweaks

package info (click to toggle)
hibernate 1.99-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 780 kB
  • ctags: 61
  • sloc: sh: 2,194; makefile: 58
file content (238 lines) | stat: -rw-r--r-- 5,740 bytes parent folder | download | duplicates (2)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler HardwareTweaksOptions

###
## IBM ACPI
###

AddConfigHelp "IbmAcpi <boolean>" "Use the ibm_acpi kernel module to signal suspend progress."

# ibm_acpi proc directory
IBM_ACPI_PROC=/proc/acpi/ibm

# ibm_acpi LED control file
IBM_ACPI_LED=$IBM_ACPI_PROC/led

# ibm_acpi beep control
IBM_ACPI_BEEP=$IBM_ACPI_PROC/beep

IbmAcpiLed() {
    if [ -f "$IBM_ACPI_LED" ] ; then
	echo $1 $2 > $IBM_ACPI_LED
    else
	vecho 1 "File '$IBM_ACPI_LED' not found. Unable to signal LED."
    fi
}

IbmAcpiBeep() {
    if [ -f "$IBM_ACPI_BEEP" ] ; then
	echo $1 > $IBM_ACPI_BEEP
    else
	vecho 1 "File '$IBM_ACPI_BEEP' not found. Unable to emit beep."
    fi
}

IbmAcpiStartSuspend() {
    # blink suspend LED
    IbmAcpiLed 7 blink
    return 0 # this shouldn't stop suspending
}

IbmAcpiEndResume() {
    # turn off suspend LED
    IbmAcpiLed 7 off

    # audible failure if another scriplet failed
    [ $EXIT_CODE -gt 1 ] && IbmAcpiBeep 4

    return 0
}

###
## radeontool
###

AddConfigHelp "RadeonTool <boolean>" "Use radeontool to turn off LCD backlight."

RadeonToolBacklightOff() {
    if ! command -v radeontool > /dev/null 2>&1 ; then
	USE_RADEONTOOL=0
	vecho 1 "'radeontool' utility not found. Radeontool disabled."
	return 0
    fi

    radeontool light off || return 1

    return 0
}

RadeonToolBacklightOn() {
    [ x"$USE_RADEONTOOL" = "x1" ] || return 0

    radeontool light on || return 1

    return 0
}

###
## i915resolution
###

AddConfigHelp "Runi915resolution <boolean>" "Set to run 915resolution before switching back to X."

i915resolutionResume() {
    local action
    action=start
    [ "$DISTRIBUTION" = "gentoo" ] && action=restart
    /etc/init.d/915resolution $action || return 1
    return 0
}

###
## cpufreq maximiser
###

AddConfigHelp "FullSpeedCPU <boolean>" "Sets the CPU to full speed whilst suspending."

FullSpeedCPUSuspend() {
    local cpu
    HW_FULLSPEEDCPU_RESTORER=`mktemp /tmp/tmp.hibernate.XXXXXX`
    for cpu in /sys/devices/system/cpu/*/cpufreq ; do
	local cpunum min_freq setspeed governor i
	[ -d $cpu ] || continue

	# Find out if this CPU has been affected already.
	cpunum=${cpu#/sys/devices/system/cpu/cpu}
	cpunum=${cpunum%/cpufreq}
	if IsANumber $cpunum ; then
	    eval "done_this=\$hw_cpu_${cpunum}_done"
	    [ "x$done_this" = "xcpudone" ] && continue
	fi
	# Mark all affected CPUs as done
	for i in `cat $cpu/affected_cpus 2>/dev/null` ; do
	    IsANumber $i && eval "hw_cpu_${i}_done=cpudone"
	done

	# Backup what we have.
	max_freq=`cat $cpu/scaling_max_freq`
	min_freq=`cat $cpu/scaling_min_freq`
	[ -f "$cpu/scaling_setspeed" ] && setspeed=`cat $cpu/scaling_setspeed`
	governor=`cat $cpu/scaling_governor`
	cat <<EOT >> $HW_FULLSPEEDCPU_RESTORER
# Temporary file for hibernate script.
# If you're reading this then it's probably safe to delete.

echo $min_freq > $cpu/scaling_min_freq
echo $governor > $cpu/scaling_governor
[ -f "$cpu/scaling_setspeed" ] && echo "$setspeed" > $cpu/scaling_setspeed
EOT

	# Set governor to performance if we've got it
	grep -q performance $cpu/scaling_available_governors 2>/dev/null && \
	    echo performance > $cpu/scaling_governor
	# Set scaling_min_freq to scaling_max_freq
	echo $max_freq > $cpu/scaling_min_freq

	vecho 2 "Switched to performance, with min freq at $max_freq"
    done
    return 0
}

FullSpeedCPUResume() {
    [ -f "$HW_FULLSPEEDCPU_RESTORER" ] || return 0
    . "$HW_FULLSPEEDCPU_RESTORER"
    rm -f "$HW_FULLSPEEDCPU_RESTORER"
    return 0
}

###
## ACPI Video flags
###

AddConfigHelp "AcpiVideoS3Bios <boolean>" "Sets s3_bios mode, replaces acpi_sleep=s3_bios kernel parameter."
AddConfigHelp "AcpiVideoS3Mode <boolean>" "Sets s3_mode mode, replaces acpi_sleep=s3_mode kernel parameter."

ACPIVIDEO_FLAGS=0

AcpiVideoFlagsSuspend() {
    echo "${ACPIVIDEO_FLAGS}" > /proc/sys/kernel/acpi_video_flags
}

###
## Option handler for all of the above:
###

HardwareTweaksOptions() {
    case $1 in
	radeontool)
	    BoolIsOn "$1" "$2" || return 0
	    USE_RADEONTOOL=1
	    if [ -z "$RADEONTOOL_HOOKED" ] ; then
		AddSuspendHook 98 RadeonToolBacklightOff
		AddResumeHook 98 RadeonToolBacklightOn
		RADEONTOOL_HOOKED=1

		# Enable SwitchToTextMode too.
		XHacksOptions switchtotextmode 1
	    fi
	    ;;
	ibmacpi)
	    BoolIsOn "$1" "$2" || return 0
	    if [ -d $IBM_ACPI_PROC ] ; then
		USE_IBM_ACPI=1
	    else
		vecho 1 "Directory '$IBM_ACPI_PROC' not found. IbmAcpi disabled."
		return 0
	    fi
	    if [ -z "$IBM_ACPI_HOOKED" ] ; then
		# in call order
		AddSuspendHook 12 IbmAcpiStartSuspend
		AddResumeHook 12 IbmAcpiEndResume
		IBM_ACPI_HOOKED=1
	    fi
	    ;;
	runi915resolution)
	    BoolIsOn "$1" "$2" || return 0
	    if [ -z "$I915RESOLUTION_HOOKED" ] ; then
		# Needs to come before xhacks switches back to X.
		AddResumeHook 98 i915resolutionResume
		I915RESOLUTION_HOOKED=1

		# Enable SwitchToTextMode too.
		XHacksOptions switchtotextmode 1
	    fi
	    ;;
	fullspeedcpu)
	    BoolIsOn "$1" "$2" || return 0
	    if [ -z "$FULLSPEEDCPU_HOOKED" ] ; then
		AddSuspendHook 98 FullSpeedCPUSuspend
		AddResumeHook 98 FullSpeedCPUResume
		FULLSPEEDCPU_HOOKED=1
	    fi
	    ;;
	acpivideos3bios)
	    BoolIsOn "$1" "$2" || return 0
	    ACPIVIDEO_FLAGS=$((${ACPIVIDEO_FLAGS}+1))
	    if [ -z "$ACPIVIDEOFLAGS_HOOKED" ]; then
		    AddSuspendHook 12 AcpiVideoFlagsSuspend
		    ACPIVIDEOFLAGS_HOOKED=1
	    fi
	    ;;
	acpivideos3mode)
	    BoolIsOn "$1" "$2" || return 0
	    ACPIVIDEO_FLAGS=$((${ACPIVIDEO_FLAGS}+2))
	    if [ -z "$ACPIVIDEOFLAGS_HOOKED" ]; then
		    AddSuspendHook 12 AcpiVideoFlagsSuspend
		    ACPIVIDEOFLAGS_HOOKED=1
	    fi
	    ;;
	*)
	    return 1
    esac

    return 0
}

# $Id: hardware_tweaks 1196 2008-05-01 11:58:52Z nigel $