forked from FrostbittenKing/fixasusbacklight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixbacklight.sh
executable file
·138 lines (123 loc) · 4.91 KB
/
fixbacklight.sh
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
#!/bin/bash
#
# Asus UX32VD acpi backlight fix
#
# Copyright(C) 2012 Eugen Dahm <[email protected]>.
#
# fix is based on a proposed bugfix posted on <https://bugs.freedesktop.org/show_bug.cgi?id=45452>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Asus UX31A/32VD acpi backlight fix
# (Disclaimer!!!! not recommended to use if laptop is not the Asus UX32VD
# probably works with other models too, but the didl and cadl offset needs to be extracted
# from the dsdt)
# Update: Apparently works 1:1 on the Asus UX31A bios 2.06 without changes, IGDM base-address differs on previous bios version(v 2.04)
# will most certainly change with the next bios update, so beware
# Tested with bios 2.06
# IGDM_BASE has to be determined for each notebook model (except UX31A and UX32VD bios 2.06, address is already known on these models)
# IGDM is the operation region (\_SB_.PCI0.GFX0.IGDM) containing the CADL/DIDL fields
# \aslb is a named field containing the base-address of the IGDM region
# this address is influenced by the bios version, and maybe somehow by the installed ram (I don't know yet)
# how to get the address:
# - git clone git://github.com/Bumblebee-Project/acpi_call.git
# - make
# - load module with insmod or copy to /lib/modules/.... and modprobe
# - echo '\aslb' > /proc/acpi/call
# - cat /proc/acpi/call
# - this is the IGDM base address - fill in below
IGDM_BASE=0xBE8B7018
DIDL_OFFSET=0x120
CADL_OFFSET=0x160
#bios version check, change according to installed bios version
BIOS_VERSION="UX32VD.206"
#irrelevant for now
#TOTAL_MEMORY="9937592"
DMIDECODE_BIOS_VERSION="bios-version"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit -1
fi
# check for dmidecode
which dmidecode > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error, dmidecode not found, please install it first" 2> /dev/stderr
exit -1
fi
function usage {
echo "usage: ./fixbacklight.sh <start | shutdown>"
}
function bios_version_check {
bios_version_found=$(dmidecode -s $DMIDECODE_BIOS_VERSION)
test $bios_version_found != $BIOS_VERSION
return $?
}
function memcheck {
mem_found=$(grep -i memtotal /proc/meminfo | cut -d ' ' -f 9)
test $mem_found != $TOTAL_MEMORY
return $?
}
if [ $# -ne 1 ]; then
usage
exit -1
fi
# Bios Version guard, base-address is influenced by bios version
bios_version_check
if [ $? -ne 1 ]; then
echo "Warning!!!, possible bug detected. Bios version does not match, please verify" > /dev/stderr
exit -1
fi
# this didn't work as intended, and apparently the base address is the same on the ux31a and the ux32vd with bios 2.06
# until I determine, how the base-address is influenced by the installed ram (if at all), this check is disabled
#memcheck guard
#memcheck
#if [ $? -ne 1 ]; then
# echo "Warning!!!, possible bug detected. Memory size doesn't match, found $mem_found kB, but expected $TOTAL_MEMORY kB" > /dev/stderr
# exit -1
#fi
# check if IGDM_BASE is initialized
if [ -z $IGDM_BASE ]; then
echo "IGDM_BASE not initialized. Please determine the IGDM base address, before you continue" > /dev/stderr
exit -1
fi
# this basically copies the values of the initialized fields DIDL-DDL8 in the IGDM opregion and initializes CADL-CAL8 with it
# CADL-CAL8 are fields, telling the bios that a screen or something is connected (this is a bit speculation - check
# <https://bugs.freedesktop.org/show_bug.cgi?id=45452> for more
# if interested, disasselbe the dsdt to understand, why no notifyevent gets thrown, when CADL isn't initialized
# (hint: _Q0E/_Q0F are the backlight methods on the UX32VD)
action="$1"
if [ "$action" = "start" ] ; then
dd if=/dev/mem skip=$(( $IGDM_BASE + $DIDL_OFFSET )) of=/dev/mem seek=$(( $IGDM_BASE + $CADL_OFFSET )) count=32 bs=1 > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo "CADL region successfully initialized"
exit 0
fi
elif [ "$action" = "shutdown" ]; then
perl -e 'print "\x00"x32' | dd of=/dev/mem bs=1 seek=$(( $IGDM_BASE + $CADL_OFFSET )) count=32 > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo "CADL region successfully prepared for shutdown"
exit 0
fi
else
echo "action $action unknown" > /dev/stderr
usage
exit -1
fi
if [ $status -ne 0 ]; then
echo "Error!!, couldn't initialize CADL"
exit -1
fi