Commit d8eca1105fe2039e102c6a8a915d0af937b1b593

Authored by Axel Lin
Committed by Matthew Garrett
1 parent 1492616a43

asus-laptop: fix a memory leak in asus_laptop_get_info error path

The callers of write_acpi_int_ret() pass ACPI_ALLOCATE_BUFFER,
the caller must kfree the returned buffer if AE_OK is returned.

This patch adds a missing kfree(buffer.pointer) before return -ENOMEM
if kstrdup fail.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Corentin Chary <corentincj@iksaif.net>
Signed-off-by: Matthew Garrett <mjg@redhat.com>

Showing 1 changed file with 3 additions and 1 deletions Inline Diff

drivers/platform/x86/asus-laptop.c
1 /* 1 /*
2 * asus-laptop.c - Asus Laptop Support 2 * asus-laptop.c - Asus Laptop Support
3 * 3 *
4 * 4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * Copyright (C) 2006-2007 Corentin Chary 6 * Copyright (C) 2006-2007 Corentin Chary
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 21 *
22 * 22 *
23 * The development page for this driver is located at 23 * The development page for this driver is located at
24 * http://sourceforge.net/projects/acpi4asus/ 24 * http://sourceforge.net/projects/acpi4asus/
25 * 25 *
26 * Credits: 26 * Credits:
27 * Pontus Fuchs - Helper functions, cleanup 27 * Pontus Fuchs - Helper functions, cleanup
28 * Johann Wiesner - Small compile fixes 28 * Johann Wiesner - Small compile fixes
29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
30 * Eric Burghard - LED display support for W1N 30 * Eric Burghard - LED display support for W1N
31 * Josh Green - Light Sens support 31 * Josh Green - Light Sens support
32 * Thomas Tuttle - His first patch for led support was very helpfull 32 * Thomas Tuttle - His first patch for led support was very helpfull
33 * Sam Lin - GPS support 33 * Sam Lin - GPS support
34 */ 34 */
35 35
36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 37
38 #include <linux/kernel.h> 38 #include <linux/kernel.h>
39 #include <linux/module.h> 39 #include <linux/module.h>
40 #include <linux/init.h> 40 #include <linux/init.h>
41 #include <linux/types.h> 41 #include <linux/types.h>
42 #include <linux/err.h> 42 #include <linux/err.h>
43 #include <linux/proc_fs.h> 43 #include <linux/proc_fs.h>
44 #include <linux/backlight.h> 44 #include <linux/backlight.h>
45 #include <linux/fb.h> 45 #include <linux/fb.h>
46 #include <linux/leds.h> 46 #include <linux/leds.h>
47 #include <linux/platform_device.h> 47 #include <linux/platform_device.h>
48 #include <linux/uaccess.h> 48 #include <linux/uaccess.h>
49 #include <linux/input.h> 49 #include <linux/input.h>
50 #include <linux/input/sparse-keymap.h> 50 #include <linux/input/sparse-keymap.h>
51 #include <linux/rfkill.h> 51 #include <linux/rfkill.h>
52 #include <linux/slab.h> 52 #include <linux/slab.h>
53 #include <acpi/acpi_drivers.h> 53 #include <acpi/acpi_drivers.h>
54 #include <acpi/acpi_bus.h> 54 #include <acpi/acpi_bus.h>
55 55
56 #define ASUS_LAPTOP_VERSION "0.42" 56 #define ASUS_LAPTOP_VERSION "0.42"
57 57
58 #define ASUS_LAPTOP_NAME "Asus Laptop Support" 58 #define ASUS_LAPTOP_NAME "Asus Laptop Support"
59 #define ASUS_LAPTOP_CLASS "hotkey" 59 #define ASUS_LAPTOP_CLASS "hotkey"
60 #define ASUS_LAPTOP_DEVICE_NAME "Hotkey" 60 #define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
61 #define ASUS_LAPTOP_FILE KBUILD_MODNAME 61 #define ASUS_LAPTOP_FILE KBUILD_MODNAME
62 #define ASUS_LAPTOP_PREFIX "\\_SB.ATKD." 62 #define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
63 63
64 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); 64 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
65 MODULE_DESCRIPTION(ASUS_LAPTOP_NAME); 65 MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
66 MODULE_LICENSE("GPL"); 66 MODULE_LICENSE("GPL");
67 67
68 /* 68 /*
69 * WAPF defines the behavior of the Fn+Fx wlan key 69 * WAPF defines the behavior of the Fn+Fx wlan key
70 * The significance of values is yet to be found, but 70 * The significance of values is yet to be found, but
71 * most of the time: 71 * most of the time:
72 * 0x0 will do nothing 72 * 0x0 will do nothing
73 * 0x1 will allow to control the device with Fn+Fx key. 73 * 0x1 will allow to control the device with Fn+Fx key.
74 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key 74 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
75 * 0x5 like 0x1 or 0x4 75 * 0x5 like 0x1 or 0x4
76 * So, if something doesn't work as you want, just try other values =) 76 * So, if something doesn't work as you want, just try other values =)
77 */ 77 */
78 static uint wapf = 1; 78 static uint wapf = 1;
79 module_param(wapf, uint, 0644); 79 module_param(wapf, uint, 0644);
80 MODULE_PARM_DESC(wapf, "WAPF value"); 80 MODULE_PARM_DESC(wapf, "WAPF value");
81 81
82 static int wlan_status = 1; 82 static int wlan_status = 1;
83 static int bluetooth_status = 1; 83 static int bluetooth_status = 1;
84 84
85 module_param(wlan_status, int, 0644); 85 module_param(wlan_status, int, 0644);
86 MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot " 86 MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
87 "(0 = disabled, 1 = enabled, -1 = don't do anything). " 87 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
88 "default is 1"); 88 "default is 1");
89 89
90 module_param(bluetooth_status, int, 0644); 90 module_param(bluetooth_status, int, 0644);
91 MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot " 91 MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
92 "(0 = disabled, 1 = enabled, -1 = don't do anything). " 92 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
93 "default is 1"); 93 "default is 1");
94 94
95 /* 95 /*
96 * Some events we use, same for all Asus 96 * Some events we use, same for all Asus
97 */ 97 */
98 #define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */ 98 #define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
99 #define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */ 99 #define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
100 #define ATKD_BR_MIN ATKD_BR_UP 100 #define ATKD_BR_MIN ATKD_BR_UP
101 #define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */ 101 #define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
102 #define ATKD_LCD_ON 0x33 102 #define ATKD_LCD_ON 0x33
103 #define ATKD_LCD_OFF 0x34 103 #define ATKD_LCD_OFF 0x34
104 104
105 /* 105 /*
106 * Known bits returned by \_SB.ATKD.HWRS 106 * Known bits returned by \_SB.ATKD.HWRS
107 */ 107 */
108 #define WL_HWRS 0x80 108 #define WL_HWRS 0x80
109 #define BT_HWRS 0x100 109 #define BT_HWRS 0x100
110 110
111 /* 111 /*
112 * Flags for hotk status 112 * Flags for hotk status
113 * WL_ON and BT_ON are also used for wireless_status() 113 * WL_ON and BT_ON are also used for wireless_status()
114 */ 114 */
115 #define WL_RSTS 0x01 /* internal Wifi */ 115 #define WL_RSTS 0x01 /* internal Wifi */
116 #define BT_RSTS 0x02 /* internal Bluetooth */ 116 #define BT_RSTS 0x02 /* internal Bluetooth */
117 117
118 /* LED */ 118 /* LED */
119 #define METHOD_MLED "MLED" 119 #define METHOD_MLED "MLED"
120 #define METHOD_TLED "TLED" 120 #define METHOD_TLED "TLED"
121 #define METHOD_RLED "RLED" /* W1JC */ 121 #define METHOD_RLED "RLED" /* W1JC */
122 #define METHOD_PLED "PLED" /* A7J */ 122 #define METHOD_PLED "PLED" /* A7J */
123 #define METHOD_GLED "GLED" /* G1, G2 (probably) */ 123 #define METHOD_GLED "GLED" /* G1, G2 (probably) */
124 124
125 /* LEDD */ 125 /* LEDD */
126 #define METHOD_LEDD "SLCM" 126 #define METHOD_LEDD "SLCM"
127 127
128 /* 128 /*
129 * Bluetooth and WLAN 129 * Bluetooth and WLAN
130 * WLED and BLED are not handled like other XLED, because in some dsdt 130 * WLED and BLED are not handled like other XLED, because in some dsdt
131 * they also control the WLAN/Bluetooth device. 131 * they also control the WLAN/Bluetooth device.
132 */ 132 */
133 #define METHOD_WLAN "WLED" 133 #define METHOD_WLAN "WLED"
134 #define METHOD_BLUETOOTH "BLED" 134 #define METHOD_BLUETOOTH "BLED"
135 #define METHOD_WL_STATUS "RSTS" 135 #define METHOD_WL_STATUS "RSTS"
136 136
137 /* Brightness */ 137 /* Brightness */
138 #define METHOD_BRIGHTNESS_SET "SPLV" 138 #define METHOD_BRIGHTNESS_SET "SPLV"
139 #define METHOD_BRIGHTNESS_GET "GPLV" 139 #define METHOD_BRIGHTNESS_GET "GPLV"
140 140
141 /* Backlight */ 141 /* Backlight */
142 static acpi_handle lcd_switch_handle; 142 static acpi_handle lcd_switch_handle;
143 static char *lcd_switch_paths[] = { 143 static char *lcd_switch_paths[] = {
144 "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ 144 "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
145 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ 145 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
146 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ 146 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
147 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ 147 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
148 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ 148 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
149 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */ 149 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
150 "\\_SB.PCI0.PX40.Q10", /* S1x */ 150 "\\_SB.PCI0.PX40.Q10", /* S1x */
151 "\\Q10"}; /* A2x, L2D, L3D, M2E */ 151 "\\Q10"}; /* A2x, L2D, L3D, M2E */
152 152
153 /* Display */ 153 /* Display */
154 #define METHOD_SWITCH_DISPLAY "SDSP" 154 #define METHOD_SWITCH_DISPLAY "SDSP"
155 155
156 static acpi_handle display_get_handle; 156 static acpi_handle display_get_handle;
157 static char *display_get_paths[] = { 157 static char *display_get_paths[] = {
158 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */ 158 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
159 "\\_SB.PCI0.P0P1.VGA.GETD", 159 "\\_SB.PCI0.P0P1.VGA.GETD",
160 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */ 160 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
161 "\\_SB.PCI0.P0P2.VGA.GETD", 161 "\\_SB.PCI0.P0P2.VGA.GETD",
162 /* A6V A6Q */ 162 /* A6V A6Q */
163 "\\_SB.PCI0.P0P3.VGA.GETD", 163 "\\_SB.PCI0.P0P3.VGA.GETD",
164 /* A6T, A6M */ 164 /* A6T, A6M */
165 "\\_SB.PCI0.P0PA.VGA.GETD", 165 "\\_SB.PCI0.P0PA.VGA.GETD",
166 /* L3C */ 166 /* L3C */
167 "\\_SB.PCI0.PCI1.VGAC.NMAP", 167 "\\_SB.PCI0.PCI1.VGAC.NMAP",
168 /* Z96F */ 168 /* Z96F */
169 "\\_SB.PCI0.VGA.GETD", 169 "\\_SB.PCI0.VGA.GETD",
170 /* A2D */ 170 /* A2D */
171 "\\ACTD", 171 "\\ACTD",
172 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ 172 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
173 "\\ADVG", 173 "\\ADVG",
174 /* P30 */ 174 /* P30 */
175 "\\DNXT", 175 "\\DNXT",
176 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ 176 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
177 "\\INFB", 177 "\\INFB",
178 /* A3F A6F A3N A3L M6N W3N W6A */ 178 /* A3F A6F A3N A3L M6N W3N W6A */
179 "\\SSTE"}; 179 "\\SSTE"};
180 180
181 #define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */ 181 #define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
182 #define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */ 182 #define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
183 183
184 /* GPS */ 184 /* GPS */
185 /* R2H use different handle for GPS on/off */ 185 /* R2H use different handle for GPS on/off */
186 #define METHOD_GPS_ON "SDON" 186 #define METHOD_GPS_ON "SDON"
187 #define METHOD_GPS_OFF "SDOF" 187 #define METHOD_GPS_OFF "SDOF"
188 #define METHOD_GPS_STATUS "GPST" 188 #define METHOD_GPS_STATUS "GPST"
189 189
190 /* Keyboard light */ 190 /* Keyboard light */
191 #define METHOD_KBD_LIGHT_SET "SLKB" 191 #define METHOD_KBD_LIGHT_SET "SLKB"
192 #define METHOD_KBD_LIGHT_GET "GLKB" 192 #define METHOD_KBD_LIGHT_GET "GLKB"
193 193
194 /* 194 /*
195 * Define a specific led structure to keep the main structure clean 195 * Define a specific led structure to keep the main structure clean
196 */ 196 */
197 struct asus_led { 197 struct asus_led {
198 int wk; 198 int wk;
199 struct work_struct work; 199 struct work_struct work;
200 struct led_classdev led; 200 struct led_classdev led;
201 struct asus_laptop *asus; 201 struct asus_laptop *asus;
202 const char *method; 202 const char *method;
203 }; 203 };
204 204
205 /* 205 /*
206 * This is the main structure, we can use it to store anything interesting 206 * This is the main structure, we can use it to store anything interesting
207 * about the hotk device 207 * about the hotk device
208 */ 208 */
209 struct asus_laptop { 209 struct asus_laptop {
210 char *name; /* laptop name */ 210 char *name; /* laptop name */
211 211
212 struct acpi_table_header *dsdt_info; 212 struct acpi_table_header *dsdt_info;
213 struct platform_device *platform_device; 213 struct platform_device *platform_device;
214 struct acpi_device *device; /* the device we are in */ 214 struct acpi_device *device; /* the device we are in */
215 struct backlight_device *backlight_device; 215 struct backlight_device *backlight_device;
216 216
217 struct input_dev *inputdev; 217 struct input_dev *inputdev;
218 struct key_entry *keymap; 218 struct key_entry *keymap;
219 219
220 struct asus_led mled; 220 struct asus_led mled;
221 struct asus_led tled; 221 struct asus_led tled;
222 struct asus_led rled; 222 struct asus_led rled;
223 struct asus_led pled; 223 struct asus_led pled;
224 struct asus_led gled; 224 struct asus_led gled;
225 struct asus_led kled; 225 struct asus_led kled;
226 struct workqueue_struct *led_workqueue; 226 struct workqueue_struct *led_workqueue;
227 227
228 int wireless_status; 228 int wireless_status;
229 bool have_rsts; 229 bool have_rsts;
230 int lcd_state; 230 int lcd_state;
231 231
232 struct rfkill *gps_rfkill; 232 struct rfkill *gps_rfkill;
233 233
234 acpi_handle handle; /* the handle of the hotk device */ 234 acpi_handle handle; /* the handle of the hotk device */
235 u32 ledd_status; /* status of the LED display */ 235 u32 ledd_status; /* status of the LED display */
236 u8 light_level; /* light sensor level */ 236 u8 light_level; /* light sensor level */
237 u8 light_switch; /* light sensor switch value */ 237 u8 light_switch; /* light sensor switch value */
238 u16 event_count[128]; /* count for each event TODO make this better */ 238 u16 event_count[128]; /* count for each event TODO make this better */
239 u16 *keycode_map; 239 u16 *keycode_map;
240 }; 240 };
241 241
242 static const struct key_entry asus_keymap[] = { 242 static const struct key_entry asus_keymap[] = {
243 /* Lenovo SL Specific keycodes */ 243 /* Lenovo SL Specific keycodes */
244 {KE_KEY, 0x02, { KEY_SCREENLOCK } }, 244 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
245 {KE_KEY, 0x05, { KEY_WLAN } }, 245 {KE_KEY, 0x05, { KEY_WLAN } },
246 {KE_KEY, 0x08, { KEY_F13 } }, 246 {KE_KEY, 0x08, { KEY_F13 } },
247 {KE_KEY, 0x17, { KEY_ZOOM } }, 247 {KE_KEY, 0x17, { KEY_ZOOM } },
248 {KE_KEY, 0x1f, { KEY_BATTERY } }, 248 {KE_KEY, 0x1f, { KEY_BATTERY } },
249 /* End of Lenovo SL Specific keycodes */ 249 /* End of Lenovo SL Specific keycodes */
250 {KE_KEY, 0x30, { KEY_VOLUMEUP } }, 250 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
251 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, 251 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
252 {KE_KEY, 0x32, { KEY_MUTE } }, 252 {KE_KEY, 0x32, { KEY_MUTE } },
253 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } }, 253 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
254 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } }, 254 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
255 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } }, 255 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
256 {KE_KEY, 0x41, { KEY_NEXTSONG } }, 256 {KE_KEY, 0x41, { KEY_NEXTSONG } },
257 {KE_KEY, 0x43, { KEY_STOPCD } }, 257 {KE_KEY, 0x43, { KEY_STOPCD } },
258 {KE_KEY, 0x45, { KEY_PLAYPAUSE } }, 258 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
259 {KE_KEY, 0x4c, { KEY_MEDIA } }, 259 {KE_KEY, 0x4c, { KEY_MEDIA } },
260 {KE_KEY, 0x50, { KEY_EMAIL } }, 260 {KE_KEY, 0x50, { KEY_EMAIL } },
261 {KE_KEY, 0x51, { KEY_WWW } }, 261 {KE_KEY, 0x51, { KEY_WWW } },
262 {KE_KEY, 0x55, { KEY_CALC } }, 262 {KE_KEY, 0x55, { KEY_CALC } },
263 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */ 263 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
264 {KE_KEY, 0x5D, { KEY_WLAN } }, 264 {KE_KEY, 0x5D, { KEY_WLAN } },
265 {KE_KEY, 0x5E, { KEY_WLAN } }, 265 {KE_KEY, 0x5E, { KEY_WLAN } },
266 {KE_KEY, 0x5F, { KEY_WLAN } }, 266 {KE_KEY, 0x5F, { KEY_WLAN } },
267 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } }, 267 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
268 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } }, 268 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
269 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } }, 269 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
270 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } }, 270 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
271 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */ 271 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
272 {KE_KEY, 0x7E, { KEY_BLUETOOTH } }, 272 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
273 {KE_KEY, 0x7D, { KEY_BLUETOOTH } }, 273 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
274 {KE_KEY, 0x82, { KEY_CAMERA } }, 274 {KE_KEY, 0x82, { KEY_CAMERA } },
275 {KE_KEY, 0x88, { KEY_WLAN } }, 275 {KE_KEY, 0x88, { KEY_WLAN } },
276 {KE_KEY, 0x8A, { KEY_PROG1 } }, 276 {KE_KEY, 0x8A, { KEY_PROG1 } },
277 {KE_KEY, 0x95, { KEY_MEDIA } }, 277 {KE_KEY, 0x95, { KEY_MEDIA } },
278 {KE_KEY, 0x99, { KEY_PHONE } }, 278 {KE_KEY, 0x99, { KEY_PHONE } },
279 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } }, 279 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
280 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } }, 280 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
281 {KE_END, 0}, 281 {KE_END, 0},
282 }; 282 };
283 283
284 284
285 /* 285 /*
286 * This function evaluates an ACPI method, given an int as parameter, the 286 * This function evaluates an ACPI method, given an int as parameter, the
287 * method is searched within the scope of the handle, can be NULL. The output 287 * method is searched within the scope of the handle, can be NULL. The output
288 * of the method is written is output, which can also be NULL 288 * of the method is written is output, which can also be NULL
289 * 289 *
290 * returns 0 if write is successful, -1 else. 290 * returns 0 if write is successful, -1 else.
291 */ 291 */
292 static int write_acpi_int_ret(acpi_handle handle, const char *method, int val, 292 static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
293 struct acpi_buffer *output) 293 struct acpi_buffer *output)
294 { 294 {
295 struct acpi_object_list params; /* list of input parameters (an int) */ 295 struct acpi_object_list params; /* list of input parameters (an int) */
296 union acpi_object in_obj; /* the only param we use */ 296 union acpi_object in_obj; /* the only param we use */
297 acpi_status status; 297 acpi_status status;
298 298
299 if (!handle) 299 if (!handle)
300 return 0; 300 return 0;
301 301
302 params.count = 1; 302 params.count = 1;
303 params.pointer = &in_obj; 303 params.pointer = &in_obj;
304 in_obj.type = ACPI_TYPE_INTEGER; 304 in_obj.type = ACPI_TYPE_INTEGER;
305 in_obj.integer.value = val; 305 in_obj.integer.value = val;
306 306
307 status = acpi_evaluate_object(handle, (char *)method, &params, output); 307 status = acpi_evaluate_object(handle, (char *)method, &params, output);
308 if (status == AE_OK) 308 if (status == AE_OK)
309 return 0; 309 return 0;
310 else 310 else
311 return -1; 311 return -1;
312 } 312 }
313 313
314 static int write_acpi_int(acpi_handle handle, const char *method, int val) 314 static int write_acpi_int(acpi_handle handle, const char *method, int val)
315 { 315 {
316 return write_acpi_int_ret(handle, method, val, NULL); 316 return write_acpi_int_ret(handle, method, val, NULL);
317 } 317 }
318 318
319 static int acpi_check_handle(acpi_handle handle, const char *method, 319 static int acpi_check_handle(acpi_handle handle, const char *method,
320 acpi_handle *ret) 320 acpi_handle *ret)
321 { 321 {
322 acpi_status status; 322 acpi_status status;
323 323
324 if (method == NULL) 324 if (method == NULL)
325 return -ENODEV; 325 return -ENODEV;
326 326
327 if (ret) 327 if (ret)
328 status = acpi_get_handle(handle, (char *)method, 328 status = acpi_get_handle(handle, (char *)method,
329 ret); 329 ret);
330 else { 330 else {
331 acpi_handle dummy; 331 acpi_handle dummy;
332 332
333 status = acpi_get_handle(handle, (char *)method, 333 status = acpi_get_handle(handle, (char *)method,
334 &dummy); 334 &dummy);
335 } 335 }
336 336
337 if (status != AE_OK) { 337 if (status != AE_OK) {
338 if (ret) 338 if (ret)
339 pr_warning("Error finding %s\n", method); 339 pr_warning("Error finding %s\n", method);
340 return -ENODEV; 340 return -ENODEV;
341 } 341 }
342 return 0; 342 return 0;
343 } 343 }
344 344
345 /* Generic LED function */ 345 /* Generic LED function */
346 static int asus_led_set(struct asus_laptop *asus, const char *method, 346 static int asus_led_set(struct asus_laptop *asus, const char *method,
347 int value) 347 int value)
348 { 348 {
349 if (!strcmp(method, METHOD_MLED)) 349 if (!strcmp(method, METHOD_MLED))
350 value = !value; 350 value = !value;
351 else if (!strcmp(method, METHOD_GLED)) 351 else if (!strcmp(method, METHOD_GLED))
352 value = !value + 1; 352 value = !value + 1;
353 else 353 else
354 value = !!value; 354 value = !!value;
355 355
356 return write_acpi_int(asus->handle, method, value); 356 return write_acpi_int(asus->handle, method, value);
357 } 357 }
358 358
359 /* 359 /*
360 * LEDs 360 * LEDs
361 */ 361 */
362 /* /sys/class/led handlers */ 362 /* /sys/class/led handlers */
363 static void asus_led_cdev_set(struct led_classdev *led_cdev, 363 static void asus_led_cdev_set(struct led_classdev *led_cdev,
364 enum led_brightness value) 364 enum led_brightness value)
365 { 365 {
366 struct asus_led *led = container_of(led_cdev, struct asus_led, led); 366 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
367 struct asus_laptop *asus = led->asus; 367 struct asus_laptop *asus = led->asus;
368 368
369 led->wk = !!value; 369 led->wk = !!value;
370 queue_work(asus->led_workqueue, &led->work); 370 queue_work(asus->led_workqueue, &led->work);
371 } 371 }
372 372
373 static void asus_led_cdev_update(struct work_struct *work) 373 static void asus_led_cdev_update(struct work_struct *work)
374 { 374 {
375 struct asus_led *led = container_of(work, struct asus_led, work); 375 struct asus_led *led = container_of(work, struct asus_led, work);
376 struct asus_laptop *asus = led->asus; 376 struct asus_laptop *asus = led->asus;
377 377
378 asus_led_set(asus, led->method, led->wk); 378 asus_led_set(asus, led->method, led->wk);
379 } 379 }
380 380
381 static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev) 381 static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
382 { 382 {
383 return led_cdev->brightness; 383 return led_cdev->brightness;
384 } 384 }
385 385
386 /* 386 /*
387 * Keyboard backlight (also a LED) 387 * Keyboard backlight (also a LED)
388 */ 388 */
389 static int asus_kled_lvl(struct asus_laptop *asus) 389 static int asus_kled_lvl(struct asus_laptop *asus)
390 { 390 {
391 unsigned long long kblv; 391 unsigned long long kblv;
392 struct acpi_object_list params; 392 struct acpi_object_list params;
393 union acpi_object in_obj; 393 union acpi_object in_obj;
394 acpi_status rv; 394 acpi_status rv;
395 395
396 params.count = 1; 396 params.count = 1;
397 params.pointer = &in_obj; 397 params.pointer = &in_obj;
398 in_obj.type = ACPI_TYPE_INTEGER; 398 in_obj.type = ACPI_TYPE_INTEGER;
399 in_obj.integer.value = 2; 399 in_obj.integer.value = 2;
400 400
401 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET, 401 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
402 &params, &kblv); 402 &params, &kblv);
403 if (ACPI_FAILURE(rv)) { 403 if (ACPI_FAILURE(rv)) {
404 pr_warning("Error reading kled level\n"); 404 pr_warning("Error reading kled level\n");
405 return -ENODEV; 405 return -ENODEV;
406 } 406 }
407 return kblv; 407 return kblv;
408 } 408 }
409 409
410 static int asus_kled_set(struct asus_laptop *asus, int kblv) 410 static int asus_kled_set(struct asus_laptop *asus, int kblv)
411 { 411 {
412 if (kblv > 0) 412 if (kblv > 0)
413 kblv = (1 << 7) | (kblv & 0x7F); 413 kblv = (1 << 7) | (kblv & 0x7F);
414 else 414 else
415 kblv = 0; 415 kblv = 0;
416 416
417 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) { 417 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
418 pr_warning("Keyboard LED display write failed\n"); 418 pr_warning("Keyboard LED display write failed\n");
419 return -EINVAL; 419 return -EINVAL;
420 } 420 }
421 return 0; 421 return 0;
422 } 422 }
423 423
424 static void asus_kled_cdev_set(struct led_classdev *led_cdev, 424 static void asus_kled_cdev_set(struct led_classdev *led_cdev,
425 enum led_brightness value) 425 enum led_brightness value)
426 { 426 {
427 struct asus_led *led = container_of(led_cdev, struct asus_led, led); 427 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
428 struct asus_laptop *asus = led->asus; 428 struct asus_laptop *asus = led->asus;
429 429
430 led->wk = value; 430 led->wk = value;
431 queue_work(asus->led_workqueue, &led->work); 431 queue_work(asus->led_workqueue, &led->work);
432 } 432 }
433 433
434 static void asus_kled_cdev_update(struct work_struct *work) 434 static void asus_kled_cdev_update(struct work_struct *work)
435 { 435 {
436 struct asus_led *led = container_of(work, struct asus_led, work); 436 struct asus_led *led = container_of(work, struct asus_led, work);
437 struct asus_laptop *asus = led->asus; 437 struct asus_laptop *asus = led->asus;
438 438
439 asus_kled_set(asus, led->wk); 439 asus_kled_set(asus, led->wk);
440 } 440 }
441 441
442 static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev) 442 static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
443 { 443 {
444 struct asus_led *led = container_of(led_cdev, struct asus_led, led); 444 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
445 struct asus_laptop *asus = led->asus; 445 struct asus_laptop *asus = led->asus;
446 446
447 return asus_kled_lvl(asus); 447 return asus_kled_lvl(asus);
448 } 448 }
449 449
450 static void asus_led_exit(struct asus_laptop *asus) 450 static void asus_led_exit(struct asus_laptop *asus)
451 { 451 {
452 if (asus->mled.led.dev) 452 if (asus->mled.led.dev)
453 led_classdev_unregister(&asus->mled.led); 453 led_classdev_unregister(&asus->mled.led);
454 if (asus->tled.led.dev) 454 if (asus->tled.led.dev)
455 led_classdev_unregister(&asus->tled.led); 455 led_classdev_unregister(&asus->tled.led);
456 if (asus->pled.led.dev) 456 if (asus->pled.led.dev)
457 led_classdev_unregister(&asus->pled.led); 457 led_classdev_unregister(&asus->pled.led);
458 if (asus->rled.led.dev) 458 if (asus->rled.led.dev)
459 led_classdev_unregister(&asus->rled.led); 459 led_classdev_unregister(&asus->rled.led);
460 if (asus->gled.led.dev) 460 if (asus->gled.led.dev)
461 led_classdev_unregister(&asus->gled.led); 461 led_classdev_unregister(&asus->gled.led);
462 if (asus->kled.led.dev) 462 if (asus->kled.led.dev)
463 led_classdev_unregister(&asus->kled.led); 463 led_classdev_unregister(&asus->kled.led);
464 if (asus->led_workqueue) { 464 if (asus->led_workqueue) {
465 destroy_workqueue(asus->led_workqueue); 465 destroy_workqueue(asus->led_workqueue);
466 asus->led_workqueue = NULL; 466 asus->led_workqueue = NULL;
467 } 467 }
468 } 468 }
469 469
470 /* Ugly macro, need to fix that later */ 470 /* Ugly macro, need to fix that later */
471 static int asus_led_register(struct asus_laptop *asus, 471 static int asus_led_register(struct asus_laptop *asus,
472 struct asus_led *led, 472 struct asus_led *led,
473 const char *name, const char *method) 473 const char *name, const char *method)
474 { 474 {
475 struct led_classdev *led_cdev = &led->led; 475 struct led_classdev *led_cdev = &led->led;
476 476
477 if (!method || acpi_check_handle(asus->handle, method, NULL)) 477 if (!method || acpi_check_handle(asus->handle, method, NULL))
478 return 0; /* Led not present */ 478 return 0; /* Led not present */
479 479
480 led->asus = asus; 480 led->asus = asus;
481 led->method = method; 481 led->method = method;
482 482
483 INIT_WORK(&led->work, asus_led_cdev_update); 483 INIT_WORK(&led->work, asus_led_cdev_update);
484 led_cdev->name = name; 484 led_cdev->name = name;
485 led_cdev->brightness_set = asus_led_cdev_set; 485 led_cdev->brightness_set = asus_led_cdev_set;
486 led_cdev->brightness_get = asus_led_cdev_get; 486 led_cdev->brightness_get = asus_led_cdev_get;
487 led_cdev->max_brightness = 1; 487 led_cdev->max_brightness = 1;
488 return led_classdev_register(&asus->platform_device->dev, led_cdev); 488 return led_classdev_register(&asus->platform_device->dev, led_cdev);
489 } 489 }
490 490
491 static int asus_led_init(struct asus_laptop *asus) 491 static int asus_led_init(struct asus_laptop *asus)
492 { 492 {
493 int r; 493 int r;
494 494
495 /* 495 /*
496 * Functions that actually update the LED's are called from a 496 * Functions that actually update the LED's are called from a
497 * workqueue. By doing this as separate work rather than when the LED 497 * workqueue. By doing this as separate work rather than when the LED
498 * subsystem asks, we avoid messing with the Asus ACPI stuff during a 498 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
499 * potentially bad time, such as a timer interrupt. 499 * potentially bad time, such as a timer interrupt.
500 */ 500 */
501 asus->led_workqueue = create_singlethread_workqueue("led_workqueue"); 501 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
502 if (!asus->led_workqueue) 502 if (!asus->led_workqueue)
503 return -ENOMEM; 503 return -ENOMEM;
504 504
505 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED); 505 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
506 if (r) 506 if (r)
507 goto error; 507 goto error;
508 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED); 508 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
509 if (r) 509 if (r)
510 goto error; 510 goto error;
511 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED); 511 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
512 if (r) 512 if (r)
513 goto error; 513 goto error;
514 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED); 514 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
515 if (r) 515 if (r)
516 goto error; 516 goto error;
517 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED); 517 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
518 if (r) 518 if (r)
519 goto error; 519 goto error;
520 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) && 520 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
521 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) { 521 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
522 struct asus_led *led = &asus->kled; 522 struct asus_led *led = &asus->kled;
523 struct led_classdev *cdev = &led->led; 523 struct led_classdev *cdev = &led->led;
524 524
525 led->asus = asus; 525 led->asus = asus;
526 526
527 INIT_WORK(&led->work, asus_kled_cdev_update); 527 INIT_WORK(&led->work, asus_kled_cdev_update);
528 cdev->name = "asus::kbd_backlight"; 528 cdev->name = "asus::kbd_backlight";
529 cdev->brightness_set = asus_kled_cdev_set; 529 cdev->brightness_set = asus_kled_cdev_set;
530 cdev->brightness_get = asus_kled_cdev_get; 530 cdev->brightness_get = asus_kled_cdev_get;
531 cdev->max_brightness = 3; 531 cdev->max_brightness = 3;
532 r = led_classdev_register(&asus->platform_device->dev, cdev); 532 r = led_classdev_register(&asus->platform_device->dev, cdev);
533 } 533 }
534 error: 534 error:
535 if (r) 535 if (r)
536 asus_led_exit(asus); 536 asus_led_exit(asus);
537 return r; 537 return r;
538 } 538 }
539 539
540 /* 540 /*
541 * Backlight device 541 * Backlight device
542 */ 542 */
543 static int asus_lcd_status(struct asus_laptop *asus) 543 static int asus_lcd_status(struct asus_laptop *asus)
544 { 544 {
545 return asus->lcd_state; 545 return asus->lcd_state;
546 } 546 }
547 547
548 static int asus_lcd_set(struct asus_laptop *asus, int value) 548 static int asus_lcd_set(struct asus_laptop *asus, int value)
549 { 549 {
550 int lcd = 0; 550 int lcd = 0;
551 acpi_status status = 0; 551 acpi_status status = 0;
552 552
553 lcd = !!value; 553 lcd = !!value;
554 554
555 if (lcd == asus_lcd_status(asus)) 555 if (lcd == asus_lcd_status(asus))
556 return 0; 556 return 0;
557 557
558 if (!lcd_switch_handle) 558 if (!lcd_switch_handle)
559 return -ENODEV; 559 return -ENODEV;
560 560
561 status = acpi_evaluate_object(lcd_switch_handle, 561 status = acpi_evaluate_object(lcd_switch_handle,
562 NULL, NULL, NULL); 562 NULL, NULL, NULL);
563 563
564 if (ACPI_FAILURE(status)) { 564 if (ACPI_FAILURE(status)) {
565 pr_warning("Error switching LCD\n"); 565 pr_warning("Error switching LCD\n");
566 return -ENODEV; 566 return -ENODEV;
567 } 567 }
568 568
569 asus->lcd_state = lcd; 569 asus->lcd_state = lcd;
570 return 0; 570 return 0;
571 } 571 }
572 572
573 static void lcd_blank(struct asus_laptop *asus, int blank) 573 static void lcd_blank(struct asus_laptop *asus, int blank)
574 { 574 {
575 struct backlight_device *bd = asus->backlight_device; 575 struct backlight_device *bd = asus->backlight_device;
576 576
577 asus->lcd_state = (blank == FB_BLANK_UNBLANK); 577 asus->lcd_state = (blank == FB_BLANK_UNBLANK);
578 578
579 if (bd) { 579 if (bd) {
580 bd->props.power = blank; 580 bd->props.power = blank;
581 backlight_update_status(bd); 581 backlight_update_status(bd);
582 } 582 }
583 } 583 }
584 584
585 static int asus_read_brightness(struct backlight_device *bd) 585 static int asus_read_brightness(struct backlight_device *bd)
586 { 586 {
587 struct asus_laptop *asus = bl_get_data(bd); 587 struct asus_laptop *asus = bl_get_data(bd);
588 unsigned long long value; 588 unsigned long long value;
589 acpi_status rv = AE_OK; 589 acpi_status rv = AE_OK;
590 590
591 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET, 591 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
592 NULL, &value); 592 NULL, &value);
593 if (ACPI_FAILURE(rv)) 593 if (ACPI_FAILURE(rv))
594 pr_warning("Error reading brightness\n"); 594 pr_warning("Error reading brightness\n");
595 595
596 return value; 596 return value;
597 } 597 }
598 598
599 static int asus_set_brightness(struct backlight_device *bd, int value) 599 static int asus_set_brightness(struct backlight_device *bd, int value)
600 { 600 {
601 struct asus_laptop *asus = bl_get_data(bd); 601 struct asus_laptop *asus = bl_get_data(bd);
602 602
603 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) { 603 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
604 pr_warning("Error changing brightness\n"); 604 pr_warning("Error changing brightness\n");
605 return -EIO; 605 return -EIO;
606 } 606 }
607 return 0; 607 return 0;
608 } 608 }
609 609
610 static int update_bl_status(struct backlight_device *bd) 610 static int update_bl_status(struct backlight_device *bd)
611 { 611 {
612 struct asus_laptop *asus = bl_get_data(bd); 612 struct asus_laptop *asus = bl_get_data(bd);
613 int rv; 613 int rv;
614 int value = bd->props.brightness; 614 int value = bd->props.brightness;
615 615
616 rv = asus_set_brightness(bd, value); 616 rv = asus_set_brightness(bd, value);
617 if (rv) 617 if (rv)
618 return rv; 618 return rv;
619 619
620 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0; 620 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
621 return asus_lcd_set(asus, value); 621 return asus_lcd_set(asus, value);
622 } 622 }
623 623
624 static struct backlight_ops asusbl_ops = { 624 static struct backlight_ops asusbl_ops = {
625 .get_brightness = asus_read_brightness, 625 .get_brightness = asus_read_brightness,
626 .update_status = update_bl_status, 626 .update_status = update_bl_status,
627 }; 627 };
628 628
629 static int asus_backlight_notify(struct asus_laptop *asus) 629 static int asus_backlight_notify(struct asus_laptop *asus)
630 { 630 {
631 struct backlight_device *bd = asus->backlight_device; 631 struct backlight_device *bd = asus->backlight_device;
632 int old = bd->props.brightness; 632 int old = bd->props.brightness;
633 633
634 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); 634 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
635 635
636 return old; 636 return old;
637 } 637 }
638 638
639 static int asus_backlight_init(struct asus_laptop *asus) 639 static int asus_backlight_init(struct asus_laptop *asus)
640 { 640 {
641 struct backlight_device *bd; 641 struct backlight_device *bd;
642 struct device *dev = &asus->platform_device->dev; 642 struct device *dev = &asus->platform_device->dev;
643 struct backlight_properties props; 643 struct backlight_properties props;
644 644
645 if (!acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) && 645 if (!acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) &&
646 !acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL) && 646 !acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL) &&
647 lcd_switch_handle) { 647 lcd_switch_handle) {
648 memset(&props, 0, sizeof(struct backlight_properties)); 648 memset(&props, 0, sizeof(struct backlight_properties));
649 props.max_brightness = 15; 649 props.max_brightness = 15;
650 650
651 bd = backlight_device_register(ASUS_LAPTOP_FILE, dev, 651 bd = backlight_device_register(ASUS_LAPTOP_FILE, dev,
652 asus, &asusbl_ops, &props); 652 asus, &asusbl_ops, &props);
653 if (IS_ERR(bd)) { 653 if (IS_ERR(bd)) {
654 pr_err("Could not register asus backlight device\n"); 654 pr_err("Could not register asus backlight device\n");
655 asus->backlight_device = NULL; 655 asus->backlight_device = NULL;
656 return PTR_ERR(bd); 656 return PTR_ERR(bd);
657 } 657 }
658 658
659 asus->backlight_device = bd; 659 asus->backlight_device = bd;
660 660
661 bd->props.power = FB_BLANK_UNBLANK; 661 bd->props.power = FB_BLANK_UNBLANK;
662 bd->props.brightness = asus_read_brightness(bd); 662 bd->props.brightness = asus_read_brightness(bd);
663 backlight_update_status(bd); 663 backlight_update_status(bd);
664 } 664 }
665 return 0; 665 return 0;
666 } 666 }
667 667
668 static void asus_backlight_exit(struct asus_laptop *asus) 668 static void asus_backlight_exit(struct asus_laptop *asus)
669 { 669 {
670 if (asus->backlight_device) 670 if (asus->backlight_device)
671 backlight_device_unregister(asus->backlight_device); 671 backlight_device_unregister(asus->backlight_device);
672 asus->backlight_device = NULL; 672 asus->backlight_device = NULL;
673 } 673 }
674 674
675 /* 675 /*
676 * Platform device handlers 676 * Platform device handlers
677 */ 677 */
678 678
679 /* 679 /*
680 * We write our info in page, we begin at offset off and cannot write more 680 * We write our info in page, we begin at offset off and cannot write more
681 * than count bytes. We set eof to 1 if we handle those 2 values. We return the 681 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
682 * number of bytes written in page 682 * number of bytes written in page
683 */ 683 */
684 static ssize_t show_infos(struct device *dev, 684 static ssize_t show_infos(struct device *dev,
685 struct device_attribute *attr, char *page) 685 struct device_attribute *attr, char *page)
686 { 686 {
687 struct asus_laptop *asus = dev_get_drvdata(dev); 687 struct asus_laptop *asus = dev_get_drvdata(dev);
688 int len = 0; 688 int len = 0;
689 unsigned long long temp; 689 unsigned long long temp;
690 char buf[16]; /* enough for all info */ 690 char buf[16]; /* enough for all info */
691 acpi_status rv = AE_OK; 691 acpi_status rv = AE_OK;
692 692
693 /* 693 /*
694 * We use the easy way, we don't care of off and count, 694 * We use the easy way, we don't care of off and count,
695 * so we don't set eof to 1 695 * so we don't set eof to 1
696 */ 696 */
697 697
698 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n"); 698 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
699 len += sprintf(page + len, "Model reference : %s\n", asus->name); 699 len += sprintf(page + len, "Model reference : %s\n", asus->name);
700 /* 700 /*
701 * The SFUN method probably allows the original driver to get the list 701 * The SFUN method probably allows the original driver to get the list
702 * of features supported by a given model. For now, 0x0100 or 0x0800 702 * of features supported by a given model. For now, 0x0100 or 0x0800
703 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. 703 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
704 * The significance of others is yet to be found. 704 * The significance of others is yet to be found.
705 */ 705 */
706 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp); 706 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
707 if (!ACPI_FAILURE(rv)) 707 if (!ACPI_FAILURE(rv))
708 len += sprintf(page + len, "SFUN value : %#x\n", 708 len += sprintf(page + len, "SFUN value : %#x\n",
709 (uint) temp); 709 (uint) temp);
710 /* 710 /*
711 * The HWRS method return informations about the hardware. 711 * The HWRS method return informations about the hardware.
712 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 712 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
713 * The significance of others is yet to be found. 713 * The significance of others is yet to be found.
714 * If we don't find the method, we assume the device are present. 714 * If we don't find the method, we assume the device are present.
715 */ 715 */
716 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp); 716 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
717 if (!ACPI_FAILURE(rv)) 717 if (!ACPI_FAILURE(rv))
718 len += sprintf(page + len, "HRWS value : %#x\n", 718 len += sprintf(page + len, "HRWS value : %#x\n",
719 (uint) temp); 719 (uint) temp);
720 /* 720 /*
721 * Another value for userspace: the ASYM method returns 0x02 for 721 * Another value for userspace: the ASYM method returns 0x02 for
722 * battery low and 0x04 for battery critical, its readings tend to be 722 * battery low and 0x04 for battery critical, its readings tend to be
723 * more accurate than those provided by _BST. 723 * more accurate than those provided by _BST.
724 * Note: since not all the laptops provide this method, errors are 724 * Note: since not all the laptops provide this method, errors are
725 * silently ignored. 725 * silently ignored.
726 */ 726 */
727 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp); 727 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
728 if (!ACPI_FAILURE(rv)) 728 if (!ACPI_FAILURE(rv))
729 len += sprintf(page + len, "ASYM value : %#x\n", 729 len += sprintf(page + len, "ASYM value : %#x\n",
730 (uint) temp); 730 (uint) temp);
731 if (asus->dsdt_info) { 731 if (asus->dsdt_info) {
732 snprintf(buf, 16, "%d", asus->dsdt_info->length); 732 snprintf(buf, 16, "%d", asus->dsdt_info->length);
733 len += sprintf(page + len, "DSDT length : %s\n", buf); 733 len += sprintf(page + len, "DSDT length : %s\n", buf);
734 snprintf(buf, 16, "%d", asus->dsdt_info->checksum); 734 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
735 len += sprintf(page + len, "DSDT checksum : %s\n", buf); 735 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
736 snprintf(buf, 16, "%d", asus->dsdt_info->revision); 736 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
737 len += sprintf(page + len, "DSDT revision : %s\n", buf); 737 len += sprintf(page + len, "DSDT revision : %s\n", buf);
738 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id); 738 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
739 len += sprintf(page + len, "OEM id : %s\n", buf); 739 len += sprintf(page + len, "OEM id : %s\n", buf);
740 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id); 740 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
741 len += sprintf(page + len, "OEM table id : %s\n", buf); 741 len += sprintf(page + len, "OEM table id : %s\n", buf);
742 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision); 742 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
743 len += sprintf(page + len, "OEM revision : 0x%s\n", buf); 743 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
744 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id); 744 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
745 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); 745 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
746 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision); 746 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
747 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); 747 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
748 } 748 }
749 749
750 return len; 750 return len;
751 } 751 }
752 752
753 static int parse_arg(const char *buf, unsigned long count, int *val) 753 static int parse_arg(const char *buf, unsigned long count, int *val)
754 { 754 {
755 if (!count) 755 if (!count)
756 return 0; 756 return 0;
757 if (count > 31) 757 if (count > 31)
758 return -EINVAL; 758 return -EINVAL;
759 if (sscanf(buf, "%i", val) != 1) 759 if (sscanf(buf, "%i", val) != 1)
760 return -EINVAL; 760 return -EINVAL;
761 return count; 761 return count;
762 } 762 }
763 763
764 static ssize_t sysfs_acpi_set(struct asus_laptop *asus, 764 static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
765 const char *buf, size_t count, 765 const char *buf, size_t count,
766 const char *method) 766 const char *method)
767 { 767 {
768 int rv, value; 768 int rv, value;
769 int out = 0; 769 int out = 0;
770 770
771 rv = parse_arg(buf, count, &value); 771 rv = parse_arg(buf, count, &value);
772 if (rv > 0) 772 if (rv > 0)
773 out = value ? 1 : 0; 773 out = value ? 1 : 0;
774 774
775 if (write_acpi_int(asus->handle, method, value)) 775 if (write_acpi_int(asus->handle, method, value))
776 return -ENODEV; 776 return -ENODEV;
777 return rv; 777 return rv;
778 } 778 }
779 779
780 /* 780 /*
781 * LEDD display 781 * LEDD display
782 */ 782 */
783 static ssize_t show_ledd(struct device *dev, 783 static ssize_t show_ledd(struct device *dev,
784 struct device_attribute *attr, char *buf) 784 struct device_attribute *attr, char *buf)
785 { 785 {
786 struct asus_laptop *asus = dev_get_drvdata(dev); 786 struct asus_laptop *asus = dev_get_drvdata(dev);
787 787
788 return sprintf(buf, "0x%08x\n", asus->ledd_status); 788 return sprintf(buf, "0x%08x\n", asus->ledd_status);
789 } 789 }
790 790
791 static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, 791 static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
792 const char *buf, size_t count) 792 const char *buf, size_t count)
793 { 793 {
794 struct asus_laptop *asus = dev_get_drvdata(dev); 794 struct asus_laptop *asus = dev_get_drvdata(dev);
795 int rv, value; 795 int rv, value;
796 796
797 rv = parse_arg(buf, count, &value); 797 rv = parse_arg(buf, count, &value);
798 if (rv > 0) { 798 if (rv > 0) {
799 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) 799 if (write_acpi_int(asus->handle, METHOD_LEDD, value))
800 pr_warning("LED display write failed\n"); 800 pr_warning("LED display write failed\n");
801 else 801 else
802 asus->ledd_status = (u32) value; 802 asus->ledd_status = (u32) value;
803 } 803 }
804 return rv; 804 return rv;
805 } 805 }
806 806
807 /* 807 /*
808 * Wireless 808 * Wireless
809 */ 809 */
810 static int asus_wireless_status(struct asus_laptop *asus, int mask) 810 static int asus_wireless_status(struct asus_laptop *asus, int mask)
811 { 811 {
812 unsigned long long status; 812 unsigned long long status;
813 acpi_status rv = AE_OK; 813 acpi_status rv = AE_OK;
814 814
815 if (!asus->have_rsts) 815 if (!asus->have_rsts)
816 return (asus->wireless_status & mask) ? 1 : 0; 816 return (asus->wireless_status & mask) ? 1 : 0;
817 817
818 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS, 818 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
819 NULL, &status); 819 NULL, &status);
820 if (ACPI_FAILURE(rv)) { 820 if (ACPI_FAILURE(rv)) {
821 pr_warning("Error reading Wireless status\n"); 821 pr_warning("Error reading Wireless status\n");
822 return -EINVAL; 822 return -EINVAL;
823 } 823 }
824 return !!(status & mask); 824 return !!(status & mask);
825 } 825 }
826 826
827 /* 827 /*
828 * WLAN 828 * WLAN
829 */ 829 */
830 static int asus_wlan_set(struct asus_laptop *asus, int status) 830 static int asus_wlan_set(struct asus_laptop *asus, int status)
831 { 831 {
832 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) { 832 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
833 pr_warning("Error setting wlan status to %d", status); 833 pr_warning("Error setting wlan status to %d", status);
834 return -EIO; 834 return -EIO;
835 } 835 }
836 return 0; 836 return 0;
837 } 837 }
838 838
839 static ssize_t show_wlan(struct device *dev, 839 static ssize_t show_wlan(struct device *dev,
840 struct device_attribute *attr, char *buf) 840 struct device_attribute *attr, char *buf)
841 { 841 {
842 struct asus_laptop *asus = dev_get_drvdata(dev); 842 struct asus_laptop *asus = dev_get_drvdata(dev);
843 843
844 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS)); 844 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
845 } 845 }
846 846
847 static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, 847 static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
848 const char *buf, size_t count) 848 const char *buf, size_t count)
849 { 849 {
850 struct asus_laptop *asus = dev_get_drvdata(dev); 850 struct asus_laptop *asus = dev_get_drvdata(dev);
851 851
852 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN); 852 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
853 } 853 }
854 854
855 /* 855 /*
856 * Bluetooth 856 * Bluetooth
857 */ 857 */
858 static int asus_bluetooth_set(struct asus_laptop *asus, int status) 858 static int asus_bluetooth_set(struct asus_laptop *asus, int status)
859 { 859 {
860 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) { 860 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
861 pr_warning("Error setting bluetooth status to %d", status); 861 pr_warning("Error setting bluetooth status to %d", status);
862 return -EIO; 862 return -EIO;
863 } 863 }
864 return 0; 864 return 0;
865 } 865 }
866 866
867 static ssize_t show_bluetooth(struct device *dev, 867 static ssize_t show_bluetooth(struct device *dev,
868 struct device_attribute *attr, char *buf) 868 struct device_attribute *attr, char *buf)
869 { 869 {
870 struct asus_laptop *asus = dev_get_drvdata(dev); 870 struct asus_laptop *asus = dev_get_drvdata(dev);
871 871
872 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS)); 872 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
873 } 873 }
874 874
875 static ssize_t store_bluetooth(struct device *dev, 875 static ssize_t store_bluetooth(struct device *dev,
876 struct device_attribute *attr, const char *buf, 876 struct device_attribute *attr, const char *buf,
877 size_t count) 877 size_t count)
878 { 878 {
879 struct asus_laptop *asus = dev_get_drvdata(dev); 879 struct asus_laptop *asus = dev_get_drvdata(dev);
880 880
881 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH); 881 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
882 } 882 }
883 883
884 /* 884 /*
885 * Display 885 * Display
886 */ 886 */
887 static void asus_set_display(struct asus_laptop *asus, int value) 887 static void asus_set_display(struct asus_laptop *asus, int value)
888 { 888 {
889 /* no sanity check needed for now */ 889 /* no sanity check needed for now */
890 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value)) 890 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
891 pr_warning("Error setting display\n"); 891 pr_warning("Error setting display\n");
892 return; 892 return;
893 } 893 }
894 894
895 static int read_display(struct asus_laptop *asus) 895 static int read_display(struct asus_laptop *asus)
896 { 896 {
897 unsigned long long value = 0; 897 unsigned long long value = 0;
898 acpi_status rv = AE_OK; 898 acpi_status rv = AE_OK;
899 899
900 /* 900 /*
901 * In most of the case, we know how to set the display, but sometime 901 * In most of the case, we know how to set the display, but sometime
902 * we can't read it 902 * we can't read it
903 */ 903 */
904 if (display_get_handle) { 904 if (display_get_handle) {
905 rv = acpi_evaluate_integer(display_get_handle, NULL, 905 rv = acpi_evaluate_integer(display_get_handle, NULL,
906 NULL, &value); 906 NULL, &value);
907 if (ACPI_FAILURE(rv)) 907 if (ACPI_FAILURE(rv))
908 pr_warning("Error reading display status\n"); 908 pr_warning("Error reading display status\n");
909 } 909 }
910 910
911 value &= 0x0F; /* needed for some models, shouldn't hurt others */ 911 value &= 0x0F; /* needed for some models, shouldn't hurt others */
912 912
913 return value; 913 return value;
914 } 914 }
915 915
916 /* 916 /*
917 * Now, *this* one could be more user-friendly, but so far, no-one has 917 * Now, *this* one could be more user-friendly, but so far, no-one has
918 * complained. The significance of bits is the same as in store_disp() 918 * complained. The significance of bits is the same as in store_disp()
919 */ 919 */
920 static ssize_t show_disp(struct device *dev, 920 static ssize_t show_disp(struct device *dev,
921 struct device_attribute *attr, char *buf) 921 struct device_attribute *attr, char *buf)
922 { 922 {
923 struct asus_laptop *asus = dev_get_drvdata(dev); 923 struct asus_laptop *asus = dev_get_drvdata(dev);
924 924
925 if (!display_get_handle) 925 if (!display_get_handle)
926 return -ENODEV; 926 return -ENODEV;
927 return sprintf(buf, "%d\n", read_display(asus)); 927 return sprintf(buf, "%d\n", read_display(asus));
928 } 928 }
929 929
930 /* 930 /*
931 * Experimental support for display switching. As of now: 1 should activate 931 * Experimental support for display switching. As of now: 1 should activate
932 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. 932 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
933 * Any combination (bitwise) of these will suffice. I never actually tested 4 933 * Any combination (bitwise) of these will suffice. I never actually tested 4
934 * displays hooked up simultaneously, so be warned. See the acpi4asus README 934 * displays hooked up simultaneously, so be warned. See the acpi4asus README
935 * for more info. 935 * for more info.
936 */ 936 */
937 static ssize_t store_disp(struct device *dev, struct device_attribute *attr, 937 static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
938 const char *buf, size_t count) 938 const char *buf, size_t count)
939 { 939 {
940 struct asus_laptop *asus = dev_get_drvdata(dev); 940 struct asus_laptop *asus = dev_get_drvdata(dev);
941 int rv, value; 941 int rv, value;
942 942
943 rv = parse_arg(buf, count, &value); 943 rv = parse_arg(buf, count, &value);
944 if (rv > 0) 944 if (rv > 0)
945 asus_set_display(asus, value); 945 asus_set_display(asus, value);
946 return rv; 946 return rv;
947 } 947 }
948 948
949 /* 949 /*
950 * Light Sens 950 * Light Sens
951 */ 951 */
952 static void asus_als_switch(struct asus_laptop *asus, int value) 952 static void asus_als_switch(struct asus_laptop *asus, int value)
953 { 953 {
954 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value)) 954 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
955 pr_warning("Error setting light sensor switch\n"); 955 pr_warning("Error setting light sensor switch\n");
956 asus->light_switch = value; 956 asus->light_switch = value;
957 } 957 }
958 958
959 static ssize_t show_lssw(struct device *dev, 959 static ssize_t show_lssw(struct device *dev,
960 struct device_attribute *attr, char *buf) 960 struct device_attribute *attr, char *buf)
961 { 961 {
962 struct asus_laptop *asus = dev_get_drvdata(dev); 962 struct asus_laptop *asus = dev_get_drvdata(dev);
963 963
964 return sprintf(buf, "%d\n", asus->light_switch); 964 return sprintf(buf, "%d\n", asus->light_switch);
965 } 965 }
966 966
967 static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, 967 static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
968 const char *buf, size_t count) 968 const char *buf, size_t count)
969 { 969 {
970 struct asus_laptop *asus = dev_get_drvdata(dev); 970 struct asus_laptop *asus = dev_get_drvdata(dev);
971 int rv, value; 971 int rv, value;
972 972
973 rv = parse_arg(buf, count, &value); 973 rv = parse_arg(buf, count, &value);
974 if (rv > 0) 974 if (rv > 0)
975 asus_als_switch(asus, value ? 1 : 0); 975 asus_als_switch(asus, value ? 1 : 0);
976 976
977 return rv; 977 return rv;
978 } 978 }
979 979
980 static void asus_als_level(struct asus_laptop *asus, int value) 980 static void asus_als_level(struct asus_laptop *asus, int value)
981 { 981 {
982 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value)) 982 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
983 pr_warning("Error setting light sensor level\n"); 983 pr_warning("Error setting light sensor level\n");
984 asus->light_level = value; 984 asus->light_level = value;
985 } 985 }
986 986
987 static ssize_t show_lslvl(struct device *dev, 987 static ssize_t show_lslvl(struct device *dev,
988 struct device_attribute *attr, char *buf) 988 struct device_attribute *attr, char *buf)
989 { 989 {
990 struct asus_laptop *asus = dev_get_drvdata(dev); 990 struct asus_laptop *asus = dev_get_drvdata(dev);
991 991
992 return sprintf(buf, "%d\n", asus->light_level); 992 return sprintf(buf, "%d\n", asus->light_level);
993 } 993 }
994 994
995 static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, 995 static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
996 const char *buf, size_t count) 996 const char *buf, size_t count)
997 { 997 {
998 struct asus_laptop *asus = dev_get_drvdata(dev); 998 struct asus_laptop *asus = dev_get_drvdata(dev);
999 int rv, value; 999 int rv, value;
1000 1000
1001 rv = parse_arg(buf, count, &value); 1001 rv = parse_arg(buf, count, &value);
1002 if (rv > 0) { 1002 if (rv > 0) {
1003 value = (0 < value) ? ((15 < value) ? 15 : value) : 0; 1003 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1004 /* 0 <= value <= 15 */ 1004 /* 0 <= value <= 15 */
1005 asus_als_level(asus, value); 1005 asus_als_level(asus, value);
1006 } 1006 }
1007 1007
1008 return rv; 1008 return rv;
1009 } 1009 }
1010 1010
1011 /* 1011 /*
1012 * GPS 1012 * GPS
1013 */ 1013 */
1014 static int asus_gps_status(struct asus_laptop *asus) 1014 static int asus_gps_status(struct asus_laptop *asus)
1015 { 1015 {
1016 unsigned long long status; 1016 unsigned long long status;
1017 acpi_status rv = AE_OK; 1017 acpi_status rv = AE_OK;
1018 1018
1019 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS, 1019 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1020 NULL, &status); 1020 NULL, &status);
1021 if (ACPI_FAILURE(rv)) { 1021 if (ACPI_FAILURE(rv)) {
1022 pr_warning("Error reading GPS status\n"); 1022 pr_warning("Error reading GPS status\n");
1023 return -ENODEV; 1023 return -ENODEV;
1024 } 1024 }
1025 return !!status; 1025 return !!status;
1026 } 1026 }
1027 1027
1028 static int asus_gps_switch(struct asus_laptop *asus, int status) 1028 static int asus_gps_switch(struct asus_laptop *asus, int status)
1029 { 1029 {
1030 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF; 1030 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
1031 1031
1032 if (write_acpi_int(asus->handle, meth, 0x02)) 1032 if (write_acpi_int(asus->handle, meth, 0x02))
1033 return -ENODEV; 1033 return -ENODEV;
1034 return 0; 1034 return 0;
1035 } 1035 }
1036 1036
1037 static ssize_t show_gps(struct device *dev, 1037 static ssize_t show_gps(struct device *dev,
1038 struct device_attribute *attr, char *buf) 1038 struct device_attribute *attr, char *buf)
1039 { 1039 {
1040 struct asus_laptop *asus = dev_get_drvdata(dev); 1040 struct asus_laptop *asus = dev_get_drvdata(dev);
1041 1041
1042 return sprintf(buf, "%d\n", asus_gps_status(asus)); 1042 return sprintf(buf, "%d\n", asus_gps_status(asus));
1043 } 1043 }
1044 1044
1045 static ssize_t store_gps(struct device *dev, struct device_attribute *attr, 1045 static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1046 const char *buf, size_t count) 1046 const char *buf, size_t count)
1047 { 1047 {
1048 struct asus_laptop *asus = dev_get_drvdata(dev); 1048 struct asus_laptop *asus = dev_get_drvdata(dev);
1049 int rv, value; 1049 int rv, value;
1050 int ret; 1050 int ret;
1051 1051
1052 rv = parse_arg(buf, count, &value); 1052 rv = parse_arg(buf, count, &value);
1053 if (rv <= 0) 1053 if (rv <= 0)
1054 return -EINVAL; 1054 return -EINVAL;
1055 ret = asus_gps_switch(asus, !!value); 1055 ret = asus_gps_switch(asus, !!value);
1056 if (ret) 1056 if (ret)
1057 return ret; 1057 return ret;
1058 rfkill_set_sw_state(asus->gps_rfkill, !value); 1058 rfkill_set_sw_state(asus->gps_rfkill, !value);
1059 return rv; 1059 return rv;
1060 } 1060 }
1061 1061
1062 /* 1062 /*
1063 * rfkill 1063 * rfkill
1064 */ 1064 */
1065 static int asus_gps_rfkill_set(void *data, bool blocked) 1065 static int asus_gps_rfkill_set(void *data, bool blocked)
1066 { 1066 {
1067 acpi_handle handle = data; 1067 acpi_handle handle = data;
1068 1068
1069 return asus_gps_switch(handle, !blocked); 1069 return asus_gps_switch(handle, !blocked);
1070 } 1070 }
1071 1071
1072 static const struct rfkill_ops asus_gps_rfkill_ops = { 1072 static const struct rfkill_ops asus_gps_rfkill_ops = {
1073 .set_block = asus_gps_rfkill_set, 1073 .set_block = asus_gps_rfkill_set,
1074 }; 1074 };
1075 1075
1076 static void asus_rfkill_exit(struct asus_laptop *asus) 1076 static void asus_rfkill_exit(struct asus_laptop *asus)
1077 { 1077 {
1078 if (asus->gps_rfkill) { 1078 if (asus->gps_rfkill) {
1079 rfkill_unregister(asus->gps_rfkill); 1079 rfkill_unregister(asus->gps_rfkill);
1080 rfkill_destroy(asus->gps_rfkill); 1080 rfkill_destroy(asus->gps_rfkill);
1081 asus->gps_rfkill = NULL; 1081 asus->gps_rfkill = NULL;
1082 } 1082 }
1083 } 1083 }
1084 1084
1085 static int asus_rfkill_init(struct asus_laptop *asus) 1085 static int asus_rfkill_init(struct asus_laptop *asus)
1086 { 1086 {
1087 int result; 1087 int result;
1088 1088
1089 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) || 1089 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1090 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) || 1090 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1091 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) 1091 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1092 return 0; 1092 return 0;
1093 1093
1094 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev, 1094 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1095 RFKILL_TYPE_GPS, 1095 RFKILL_TYPE_GPS,
1096 &asus_gps_rfkill_ops, NULL); 1096 &asus_gps_rfkill_ops, NULL);
1097 if (!asus->gps_rfkill) 1097 if (!asus->gps_rfkill)
1098 return -EINVAL; 1098 return -EINVAL;
1099 1099
1100 result = rfkill_register(asus->gps_rfkill); 1100 result = rfkill_register(asus->gps_rfkill);
1101 if (result) { 1101 if (result) {
1102 rfkill_destroy(asus->gps_rfkill); 1102 rfkill_destroy(asus->gps_rfkill);
1103 asus->gps_rfkill = NULL; 1103 asus->gps_rfkill = NULL;
1104 } 1104 }
1105 1105
1106 return result; 1106 return result;
1107 } 1107 }
1108 1108
1109 /* 1109 /*
1110 * Input device (i.e. hotkeys) 1110 * Input device (i.e. hotkeys)
1111 */ 1111 */
1112 static void asus_input_notify(struct asus_laptop *asus, int event) 1112 static void asus_input_notify(struct asus_laptop *asus, int event)
1113 { 1113 {
1114 if (asus->inputdev) 1114 if (asus->inputdev)
1115 sparse_keymap_report_event(asus->inputdev, event, 1, true); 1115 sparse_keymap_report_event(asus->inputdev, event, 1, true);
1116 } 1116 }
1117 1117
1118 static int asus_input_init(struct asus_laptop *asus) 1118 static int asus_input_init(struct asus_laptop *asus)
1119 { 1119 {
1120 struct input_dev *input; 1120 struct input_dev *input;
1121 int error; 1121 int error;
1122 1122
1123 input = input_allocate_device(); 1123 input = input_allocate_device();
1124 if (!input) { 1124 if (!input) {
1125 pr_info("Unable to allocate input device\n"); 1125 pr_info("Unable to allocate input device\n");
1126 return 0; 1126 return 0;
1127 } 1127 }
1128 input->name = "Asus Laptop extra buttons"; 1128 input->name = "Asus Laptop extra buttons";
1129 input->phys = ASUS_LAPTOP_FILE "/input0"; 1129 input->phys = ASUS_LAPTOP_FILE "/input0";
1130 input->id.bustype = BUS_HOST; 1130 input->id.bustype = BUS_HOST;
1131 input->dev.parent = &asus->platform_device->dev; 1131 input->dev.parent = &asus->platform_device->dev;
1132 input_set_drvdata(input, asus); 1132 input_set_drvdata(input, asus);
1133 1133
1134 error = sparse_keymap_setup(input, asus_keymap, NULL); 1134 error = sparse_keymap_setup(input, asus_keymap, NULL);
1135 if (error) { 1135 if (error) {
1136 pr_err("Unable to setup input device keymap\n"); 1136 pr_err("Unable to setup input device keymap\n");
1137 goto err_keymap; 1137 goto err_keymap;
1138 } 1138 }
1139 error = input_register_device(input); 1139 error = input_register_device(input);
1140 if (error) { 1140 if (error) {
1141 pr_info("Unable to register input device\n"); 1141 pr_info("Unable to register input device\n");
1142 goto err_device; 1142 goto err_device;
1143 } 1143 }
1144 1144
1145 asus->inputdev = input; 1145 asus->inputdev = input;
1146 return 0; 1146 return 0;
1147 1147
1148 err_keymap: 1148 err_keymap:
1149 sparse_keymap_free(input); 1149 sparse_keymap_free(input);
1150 err_device: 1150 err_device:
1151 input_free_device(input); 1151 input_free_device(input);
1152 return error; 1152 return error;
1153 } 1153 }
1154 1154
1155 static void asus_input_exit(struct asus_laptop *asus) 1155 static void asus_input_exit(struct asus_laptop *asus)
1156 { 1156 {
1157 if (asus->inputdev) { 1157 if (asus->inputdev) {
1158 sparse_keymap_free(asus->inputdev); 1158 sparse_keymap_free(asus->inputdev);
1159 input_unregister_device(asus->inputdev); 1159 input_unregister_device(asus->inputdev);
1160 } 1160 }
1161 } 1161 }
1162 1162
1163 /* 1163 /*
1164 * ACPI driver 1164 * ACPI driver
1165 */ 1165 */
1166 static void asus_acpi_notify(struct acpi_device *device, u32 event) 1166 static void asus_acpi_notify(struct acpi_device *device, u32 event)
1167 { 1167 {
1168 struct asus_laptop *asus = acpi_driver_data(device); 1168 struct asus_laptop *asus = acpi_driver_data(device);
1169 u16 count; 1169 u16 count;
1170 1170
1171 /* 1171 /*
1172 * We need to tell the backlight device when the backlight power is 1172 * We need to tell the backlight device when the backlight power is
1173 * switched 1173 * switched
1174 */ 1174 */
1175 if (event == ATKD_LCD_ON) 1175 if (event == ATKD_LCD_ON)
1176 lcd_blank(asus, FB_BLANK_UNBLANK); 1176 lcd_blank(asus, FB_BLANK_UNBLANK);
1177 else if (event == ATKD_LCD_OFF) 1177 else if (event == ATKD_LCD_OFF)
1178 lcd_blank(asus, FB_BLANK_POWERDOWN); 1178 lcd_blank(asus, FB_BLANK_POWERDOWN);
1179 1179
1180 /* TODO Find a better way to handle events count. */ 1180 /* TODO Find a better way to handle events count. */
1181 count = asus->event_count[event % 128]++; 1181 count = asus->event_count[event % 128]++;
1182 acpi_bus_generate_proc_event(asus->device, event, count); 1182 acpi_bus_generate_proc_event(asus->device, event, count);
1183 acpi_bus_generate_netlink_event(asus->device->pnp.device_class, 1183 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1184 dev_name(&asus->device->dev), event, 1184 dev_name(&asus->device->dev), event,
1185 count); 1185 count);
1186 1186
1187 /* Brightness events are special */ 1187 /* Brightness events are special */
1188 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) { 1188 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1189 1189
1190 /* Ignore them completely if the acpi video driver is used */ 1190 /* Ignore them completely if the acpi video driver is used */
1191 if (asus->backlight_device != NULL) { 1191 if (asus->backlight_device != NULL) {
1192 /* Update the backlight device. */ 1192 /* Update the backlight device. */
1193 asus_backlight_notify(asus); 1193 asus_backlight_notify(asus);
1194 } 1194 }
1195 return ; 1195 return ;
1196 } 1196 }
1197 asus_input_notify(asus, event); 1197 asus_input_notify(asus, event);
1198 } 1198 }
1199 1199
1200 static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL); 1200 static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1201 static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan); 1201 static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
1202 static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, show_bluetooth, 1202 static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, show_bluetooth,
1203 store_bluetooth); 1203 store_bluetooth);
1204 static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp); 1204 static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
1205 static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd); 1205 static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1206 static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl); 1206 static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1207 static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw); 1207 static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1208 static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps); 1208 static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1209 1209
1210 static void asus_sysfs_exit(struct asus_laptop *asus) 1210 static void asus_sysfs_exit(struct asus_laptop *asus)
1211 { 1211 {
1212 struct platform_device *device = asus->platform_device; 1212 struct platform_device *device = asus->platform_device;
1213 1213
1214 device_remove_file(&device->dev, &dev_attr_infos); 1214 device_remove_file(&device->dev, &dev_attr_infos);
1215 device_remove_file(&device->dev, &dev_attr_wlan); 1215 device_remove_file(&device->dev, &dev_attr_wlan);
1216 device_remove_file(&device->dev, &dev_attr_bluetooth); 1216 device_remove_file(&device->dev, &dev_attr_bluetooth);
1217 device_remove_file(&device->dev, &dev_attr_display); 1217 device_remove_file(&device->dev, &dev_attr_display);
1218 device_remove_file(&device->dev, &dev_attr_ledd); 1218 device_remove_file(&device->dev, &dev_attr_ledd);
1219 device_remove_file(&device->dev, &dev_attr_ls_switch); 1219 device_remove_file(&device->dev, &dev_attr_ls_switch);
1220 device_remove_file(&device->dev, &dev_attr_ls_level); 1220 device_remove_file(&device->dev, &dev_attr_ls_level);
1221 device_remove_file(&device->dev, &dev_attr_gps); 1221 device_remove_file(&device->dev, &dev_attr_gps);
1222 } 1222 }
1223 1223
1224 static int asus_sysfs_init(struct asus_laptop *asus) 1224 static int asus_sysfs_init(struct asus_laptop *asus)
1225 { 1225 {
1226 struct platform_device *device = asus->platform_device; 1226 struct platform_device *device = asus->platform_device;
1227 int err; 1227 int err;
1228 1228
1229 err = device_create_file(&device->dev, &dev_attr_infos); 1229 err = device_create_file(&device->dev, &dev_attr_infos);
1230 if (err) 1230 if (err)
1231 return err; 1231 return err;
1232 1232
1233 if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL)) { 1233 if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL)) {
1234 err = device_create_file(&device->dev, &dev_attr_wlan); 1234 err = device_create_file(&device->dev, &dev_attr_wlan);
1235 if (err) 1235 if (err)
1236 return err; 1236 return err;
1237 } 1237 }
1238 1238
1239 if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL)) { 1239 if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL)) {
1240 err = device_create_file(&device->dev, &dev_attr_bluetooth); 1240 err = device_create_file(&device->dev, &dev_attr_bluetooth);
1241 if (err) 1241 if (err)
1242 return err; 1242 return err;
1243 } 1243 }
1244 1244
1245 if (!acpi_check_handle(asus->handle, METHOD_SWITCH_DISPLAY, NULL)) { 1245 if (!acpi_check_handle(asus->handle, METHOD_SWITCH_DISPLAY, NULL)) {
1246 err = device_create_file(&device->dev, &dev_attr_display); 1246 err = device_create_file(&device->dev, &dev_attr_display);
1247 if (err) 1247 if (err)
1248 return err; 1248 return err;
1249 } 1249 }
1250 1250
1251 if (!acpi_check_handle(asus->handle, METHOD_LEDD, NULL)) { 1251 if (!acpi_check_handle(asus->handle, METHOD_LEDD, NULL)) {
1252 err = device_create_file(&device->dev, &dev_attr_ledd); 1252 err = device_create_file(&device->dev, &dev_attr_ledd);
1253 if (err) 1253 if (err)
1254 return err; 1254 return err;
1255 } 1255 }
1256 1256
1257 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) && 1257 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1258 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) { 1258 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1259 err = device_create_file(&device->dev, &dev_attr_ls_switch); 1259 err = device_create_file(&device->dev, &dev_attr_ls_switch);
1260 if (err) 1260 if (err)
1261 return err; 1261 return err;
1262 err = device_create_file(&device->dev, &dev_attr_ls_level); 1262 err = device_create_file(&device->dev, &dev_attr_ls_level);
1263 if (err) 1263 if (err)
1264 return err; 1264 return err;
1265 } 1265 }
1266 1266
1267 if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) && 1267 if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
1268 !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) && 1268 !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
1269 !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) { 1269 !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) {
1270 err = device_create_file(&device->dev, &dev_attr_gps); 1270 err = device_create_file(&device->dev, &dev_attr_gps);
1271 if (err) 1271 if (err)
1272 return err; 1272 return err;
1273 } 1273 }
1274 1274
1275 return err; 1275 return err;
1276 } 1276 }
1277 1277
1278 static int asus_platform_init(struct asus_laptop *asus) 1278 static int asus_platform_init(struct asus_laptop *asus)
1279 { 1279 {
1280 int err; 1280 int err;
1281 1281
1282 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1); 1282 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1283 if (!asus->platform_device) 1283 if (!asus->platform_device)
1284 return -ENOMEM; 1284 return -ENOMEM;
1285 platform_set_drvdata(asus->platform_device, asus); 1285 platform_set_drvdata(asus->platform_device, asus);
1286 1286
1287 err = platform_device_add(asus->platform_device); 1287 err = platform_device_add(asus->platform_device);
1288 if (err) 1288 if (err)
1289 goto fail_platform_device; 1289 goto fail_platform_device;
1290 1290
1291 err = asus_sysfs_init(asus); 1291 err = asus_sysfs_init(asus);
1292 if (err) 1292 if (err)
1293 goto fail_sysfs; 1293 goto fail_sysfs;
1294 return 0; 1294 return 0;
1295 1295
1296 fail_sysfs: 1296 fail_sysfs:
1297 asus_sysfs_exit(asus); 1297 asus_sysfs_exit(asus);
1298 platform_device_del(asus->platform_device); 1298 platform_device_del(asus->platform_device);
1299 fail_platform_device: 1299 fail_platform_device:
1300 platform_device_put(asus->platform_device); 1300 platform_device_put(asus->platform_device);
1301 return err; 1301 return err;
1302 } 1302 }
1303 1303
1304 static void asus_platform_exit(struct asus_laptop *asus) 1304 static void asus_platform_exit(struct asus_laptop *asus)
1305 { 1305 {
1306 asus_sysfs_exit(asus); 1306 asus_sysfs_exit(asus);
1307 platform_device_unregister(asus->platform_device); 1307 platform_device_unregister(asus->platform_device);
1308 } 1308 }
1309 1309
1310 static struct platform_driver platform_driver = { 1310 static struct platform_driver platform_driver = {
1311 .driver = { 1311 .driver = {
1312 .name = ASUS_LAPTOP_FILE, 1312 .name = ASUS_LAPTOP_FILE,
1313 .owner = THIS_MODULE, 1313 .owner = THIS_MODULE,
1314 } 1314 }
1315 }; 1315 };
1316 1316
1317 static int asus_handle_init(char *name, acpi_handle * handle, 1317 static int asus_handle_init(char *name, acpi_handle * handle,
1318 char **paths, int num_paths) 1318 char **paths, int num_paths)
1319 { 1319 {
1320 int i; 1320 int i;
1321 acpi_status status; 1321 acpi_status status;
1322 1322
1323 for (i = 0; i < num_paths; i++) { 1323 for (i = 0; i < num_paths; i++) {
1324 status = acpi_get_handle(NULL, paths[i], handle); 1324 status = acpi_get_handle(NULL, paths[i], handle);
1325 if (ACPI_SUCCESS(status)) 1325 if (ACPI_SUCCESS(status))
1326 return 0; 1326 return 0;
1327 } 1327 }
1328 1328
1329 *handle = NULL; 1329 *handle = NULL;
1330 return -ENODEV; 1330 return -ENODEV;
1331 } 1331 }
1332 1332
1333 #define ASUS_HANDLE_INIT(object) \ 1333 #define ASUS_HANDLE_INIT(object) \
1334 asus_handle_init(#object, &object##_handle, object##_paths, \ 1334 asus_handle_init(#object, &object##_handle, object##_paths, \
1335 ARRAY_SIZE(object##_paths)) 1335 ARRAY_SIZE(object##_paths))
1336 1336
1337 /* 1337 /*
1338 * This function is used to initialize the context with right values. In this 1338 * This function is used to initialize the context with right values. In this
1339 * method, we can make all the detection we want, and modify the asus_laptop 1339 * method, we can make all the detection we want, and modify the asus_laptop
1340 * struct 1340 * struct
1341 */ 1341 */
1342 static int asus_laptop_get_info(struct asus_laptop *asus) 1342 static int asus_laptop_get_info(struct asus_laptop *asus)
1343 { 1343 {
1344 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1344 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1345 union acpi_object *model = NULL; 1345 union acpi_object *model = NULL;
1346 unsigned long long bsts_result, hwrs_result; 1346 unsigned long long bsts_result, hwrs_result;
1347 char *string = NULL; 1347 char *string = NULL;
1348 acpi_status status; 1348 acpi_status status;
1349 1349
1350 /* 1350 /*
1351 * Get DSDT headers early enough to allow for differentiating between 1351 * Get DSDT headers early enough to allow for differentiating between
1352 * models, but late enough to allow acpi_bus_register_driver() to fail 1352 * models, but late enough to allow acpi_bus_register_driver() to fail
1353 * before doing anything ACPI-specific. Should we encounter a machine, 1353 * before doing anything ACPI-specific. Should we encounter a machine,
1354 * which needs special handling (i.e. its hotkey device has a different 1354 * which needs special handling (i.e. its hotkey device has a different
1355 * HID), this bit will be moved. 1355 * HID), this bit will be moved.
1356 */ 1356 */
1357 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info); 1357 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
1358 if (ACPI_FAILURE(status)) 1358 if (ACPI_FAILURE(status))
1359 pr_warning("Couldn't get the DSDT table header\n"); 1359 pr_warning("Couldn't get the DSDT table header\n");
1360 1360
1361 /* We have to write 0 on init this far for all ASUS models */ 1361 /* We have to write 0 on init this far for all ASUS models */
1362 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) { 1362 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
1363 pr_err("Hotkey initialization failed\n"); 1363 pr_err("Hotkey initialization failed\n");
1364 return -ENODEV; 1364 return -ENODEV;
1365 } 1365 }
1366 1366
1367 /* This needs to be called for some laptops to init properly */ 1367 /* This needs to be called for some laptops to init properly */
1368 status = 1368 status =
1369 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result); 1369 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
1370 if (ACPI_FAILURE(status)) 1370 if (ACPI_FAILURE(status))
1371 pr_warning("Error calling BSTS\n"); 1371 pr_warning("Error calling BSTS\n");
1372 else if (bsts_result) 1372 else if (bsts_result)
1373 pr_notice("BSTS called, 0x%02x returned\n", 1373 pr_notice("BSTS called, 0x%02x returned\n",
1374 (uint) bsts_result); 1374 (uint) bsts_result);
1375 1375
1376 /* This too ... */ 1376 /* This too ... */
1377 if (write_acpi_int(asus->handle, "CWAP", wapf)) 1377 if (write_acpi_int(asus->handle, "CWAP", wapf))
1378 pr_err("Error calling CWAP(%d)\n", wapf); 1378 pr_err("Error calling CWAP(%d)\n", wapf);
1379 /* 1379 /*
1380 * Try to match the object returned by INIT to the specific model. 1380 * Try to match the object returned by INIT to the specific model.
1381 * Handle every possible object (or the lack of thereof) the DSDT 1381 * Handle every possible object (or the lack of thereof) the DSDT
1382 * writers might throw at us. When in trouble, we pass NULL to 1382 * writers might throw at us. When in trouble, we pass NULL to
1383 * asus_model_match() and try something completely different. 1383 * asus_model_match() and try something completely different.
1384 */ 1384 */
1385 if (buffer.pointer) { 1385 if (buffer.pointer) {
1386 model = buffer.pointer; 1386 model = buffer.pointer;
1387 switch (model->type) { 1387 switch (model->type) {
1388 case ACPI_TYPE_STRING: 1388 case ACPI_TYPE_STRING:
1389 string = model->string.pointer; 1389 string = model->string.pointer;
1390 break; 1390 break;
1391 case ACPI_TYPE_BUFFER: 1391 case ACPI_TYPE_BUFFER:
1392 string = model->buffer.pointer; 1392 string = model->buffer.pointer;
1393 break; 1393 break;
1394 default: 1394 default:
1395 string = ""; 1395 string = "";
1396 break; 1396 break;
1397 } 1397 }
1398 } 1398 }
1399 asus->name = kstrdup(string, GFP_KERNEL); 1399 asus->name = kstrdup(string, GFP_KERNEL);
1400 if (!asus->name) 1400 if (!asus->name) {
1401 kfree(buffer.pointer);
1401 return -ENOMEM; 1402 return -ENOMEM;
1403 }
1402 1404
1403 if (*string) 1405 if (*string)
1404 pr_notice(" %s model detected\n", string); 1406 pr_notice(" %s model detected\n", string);
1405 1407
1406 /* 1408 /*
1407 * The HWRS method return informations about the hardware. 1409 * The HWRS method return informations about the hardware.
1408 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 1410 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1409 * The significance of others is yet to be found. 1411 * The significance of others is yet to be found.
1410 */ 1412 */
1411 status = 1413 status =
1412 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result); 1414 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
1413 if (!ACPI_FAILURE(status)) 1415 if (!ACPI_FAILURE(status))
1414 pr_notice(" HRWS returned %x", (int)hwrs_result); 1416 pr_notice(" HRWS returned %x", (int)hwrs_result);
1415 1417
1416 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL)) 1418 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
1417 asus->have_rsts = true; 1419 asus->have_rsts = true;
1418 1420
1419 /* Scheduled for removal */ 1421 /* Scheduled for removal */
1420 ASUS_HANDLE_INIT(lcd_switch); 1422 ASUS_HANDLE_INIT(lcd_switch);
1421 ASUS_HANDLE_INIT(display_get); 1423 ASUS_HANDLE_INIT(display_get);
1422 1424
1423 kfree(model); 1425 kfree(model);
1424 1426
1425 return AE_OK; 1427 return AE_OK;
1426 } 1428 }
1427 1429
1428 static bool asus_device_present; 1430 static bool asus_device_present;
1429 1431
1430 static int __devinit asus_acpi_init(struct asus_laptop *asus) 1432 static int __devinit asus_acpi_init(struct asus_laptop *asus)
1431 { 1433 {
1432 int result = 0; 1434 int result = 0;
1433 1435
1434 result = acpi_bus_get_status(asus->device); 1436 result = acpi_bus_get_status(asus->device);
1435 if (result) 1437 if (result)
1436 return result; 1438 return result;
1437 if (!asus->device->status.present) { 1439 if (!asus->device->status.present) {
1438 pr_err("Hotkey device not present, aborting\n"); 1440 pr_err("Hotkey device not present, aborting\n");
1439 return -ENODEV; 1441 return -ENODEV;
1440 } 1442 }
1441 1443
1442 result = asus_laptop_get_info(asus); 1444 result = asus_laptop_get_info(asus);
1443 if (result) 1445 if (result)
1444 return result; 1446 return result;
1445 1447
1446 /* WLED and BLED are on by default */ 1448 /* WLED and BLED are on by default */
1447 if (bluetooth_status >= 0) 1449 if (bluetooth_status >= 0)
1448 asus_bluetooth_set(asus, !!bluetooth_status); 1450 asus_bluetooth_set(asus, !!bluetooth_status);
1449 1451
1450 if (wlan_status >= 0) 1452 if (wlan_status >= 0)
1451 asus_wlan_set(asus, !!wlan_status); 1453 asus_wlan_set(asus, !!wlan_status);
1452 1454
1453 /* Keyboard Backlight is on by default */ 1455 /* Keyboard Backlight is on by default */
1454 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL)) 1456 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
1455 asus_kled_set(asus, 1); 1457 asus_kled_set(asus, 1);
1456 1458
1457 /* LED display is off by default */ 1459 /* LED display is off by default */
1458 asus->ledd_status = 0xFFF; 1460 asus->ledd_status = 0xFFF;
1459 1461
1460 /* Set initial values of light sensor and level */ 1462 /* Set initial values of light sensor and level */
1461 asus->light_switch = 0; /* Default to light sensor disabled */ 1463 asus->light_switch = 0; /* Default to light sensor disabled */
1462 asus->light_level = 5; /* level 5 for sensor sensitivity */ 1464 asus->light_level = 5; /* level 5 for sensor sensitivity */
1463 1465
1464 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) && 1466 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1465 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) { 1467 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1466 asus_als_switch(asus, asus->light_switch); 1468 asus_als_switch(asus, asus->light_switch);
1467 asus_als_level(asus, asus->light_level); 1469 asus_als_level(asus, asus->light_level);
1468 } 1470 }
1469 1471
1470 asus->lcd_state = 1; /* LCD should be on when the module load */ 1472 asus->lcd_state = 1; /* LCD should be on when the module load */
1471 return result; 1473 return result;
1472 } 1474 }
1473 1475
1474 static int __devinit asus_acpi_add(struct acpi_device *device) 1476 static int __devinit asus_acpi_add(struct acpi_device *device)
1475 { 1477 {
1476 struct asus_laptop *asus; 1478 struct asus_laptop *asus;
1477 int result; 1479 int result;
1478 1480
1479 pr_notice("Asus Laptop Support version %s\n", 1481 pr_notice("Asus Laptop Support version %s\n",
1480 ASUS_LAPTOP_VERSION); 1482 ASUS_LAPTOP_VERSION);
1481 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL); 1483 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1482 if (!asus) 1484 if (!asus)
1483 return -ENOMEM; 1485 return -ENOMEM;
1484 asus->handle = device->handle; 1486 asus->handle = device->handle;
1485 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME); 1487 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1486 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS); 1488 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1487 device->driver_data = asus; 1489 device->driver_data = asus;
1488 asus->device = device; 1490 asus->device = device;
1489 1491
1490 result = asus_acpi_init(asus); 1492 result = asus_acpi_init(asus);
1491 if (result) 1493 if (result)
1492 goto fail_platform; 1494 goto fail_platform;
1493 1495
1494 /* 1496 /*
1495 * Register the platform device first. It is used as a parent for the 1497 * Register the platform device first. It is used as a parent for the
1496 * sub-devices below. 1498 * sub-devices below.
1497 */ 1499 */
1498 result = asus_platform_init(asus); 1500 result = asus_platform_init(asus);
1499 if (result) 1501 if (result)
1500 goto fail_platform; 1502 goto fail_platform;
1501 1503
1502 if (!acpi_video_backlight_support()) { 1504 if (!acpi_video_backlight_support()) {
1503 result = asus_backlight_init(asus); 1505 result = asus_backlight_init(asus);
1504 if (result) 1506 if (result)
1505 goto fail_backlight; 1507 goto fail_backlight;
1506 } else 1508 } else
1507 pr_info("Backlight controlled by ACPI video driver\n"); 1509 pr_info("Backlight controlled by ACPI video driver\n");
1508 1510
1509 result = asus_input_init(asus); 1511 result = asus_input_init(asus);
1510 if (result) 1512 if (result)
1511 goto fail_input; 1513 goto fail_input;
1512 1514
1513 result = asus_led_init(asus); 1515 result = asus_led_init(asus);
1514 if (result) 1516 if (result)
1515 goto fail_led; 1517 goto fail_led;
1516 1518
1517 result = asus_rfkill_init(asus); 1519 result = asus_rfkill_init(asus);
1518 if (result) 1520 if (result)
1519 goto fail_rfkill; 1521 goto fail_rfkill;
1520 1522
1521 asus_device_present = true; 1523 asus_device_present = true;
1522 return 0; 1524 return 0;
1523 1525
1524 fail_rfkill: 1526 fail_rfkill:
1525 asus_led_exit(asus); 1527 asus_led_exit(asus);
1526 fail_led: 1528 fail_led:
1527 asus_input_exit(asus); 1529 asus_input_exit(asus);
1528 fail_input: 1530 fail_input:
1529 asus_backlight_exit(asus); 1531 asus_backlight_exit(asus);
1530 fail_backlight: 1532 fail_backlight:
1531 asus_platform_exit(asus); 1533 asus_platform_exit(asus);
1532 fail_platform: 1534 fail_platform:
1533 kfree(asus->name); 1535 kfree(asus->name);
1534 kfree(asus); 1536 kfree(asus);
1535 1537
1536 return result; 1538 return result;
1537 } 1539 }
1538 1540
1539 static int asus_acpi_remove(struct acpi_device *device, int type) 1541 static int asus_acpi_remove(struct acpi_device *device, int type)
1540 { 1542 {
1541 struct asus_laptop *asus = acpi_driver_data(device); 1543 struct asus_laptop *asus = acpi_driver_data(device);
1542 1544
1543 asus_backlight_exit(asus); 1545 asus_backlight_exit(asus);
1544 asus_rfkill_exit(asus); 1546 asus_rfkill_exit(asus);
1545 asus_led_exit(asus); 1547 asus_led_exit(asus);
1546 asus_input_exit(asus); 1548 asus_input_exit(asus);
1547 asus_platform_exit(asus); 1549 asus_platform_exit(asus);
1548 1550
1549 kfree(asus->name); 1551 kfree(asus->name);
1550 kfree(asus); 1552 kfree(asus);
1551 return 0; 1553 return 0;
1552 } 1554 }
1553 1555
1554 static const struct acpi_device_id asus_device_ids[] = { 1556 static const struct acpi_device_id asus_device_ids[] = {
1555 {"ATK0100", 0}, 1557 {"ATK0100", 0},
1556 {"ATK0101", 0}, 1558 {"ATK0101", 0},
1557 {"", 0}, 1559 {"", 0},
1558 }; 1560 };
1559 MODULE_DEVICE_TABLE(acpi, asus_device_ids); 1561 MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1560 1562
1561 static struct acpi_driver asus_acpi_driver = { 1563 static struct acpi_driver asus_acpi_driver = {
1562 .name = ASUS_LAPTOP_NAME, 1564 .name = ASUS_LAPTOP_NAME,
1563 .class = ASUS_LAPTOP_CLASS, 1565 .class = ASUS_LAPTOP_CLASS,
1564 .owner = THIS_MODULE, 1566 .owner = THIS_MODULE,
1565 .ids = asus_device_ids, 1567 .ids = asus_device_ids,
1566 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 1568 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1567 .ops = { 1569 .ops = {
1568 .add = asus_acpi_add, 1570 .add = asus_acpi_add,
1569 .remove = asus_acpi_remove, 1571 .remove = asus_acpi_remove,
1570 .notify = asus_acpi_notify, 1572 .notify = asus_acpi_notify,
1571 }, 1573 },
1572 }; 1574 };
1573 1575
1574 static int __init asus_laptop_init(void) 1576 static int __init asus_laptop_init(void)
1575 { 1577 {
1576 int result; 1578 int result;
1577 1579
1578 result = platform_driver_register(&platform_driver); 1580 result = platform_driver_register(&platform_driver);
1579 if (result < 0) 1581 if (result < 0)
1580 return result; 1582 return result;
1581 1583
1582 result = acpi_bus_register_driver(&asus_acpi_driver); 1584 result = acpi_bus_register_driver(&asus_acpi_driver);
1583 if (result < 0) 1585 if (result < 0)
1584 goto fail_acpi_driver; 1586 goto fail_acpi_driver;
1585 if (!asus_device_present) { 1587 if (!asus_device_present) {
1586 result = -ENODEV; 1588 result = -ENODEV;
1587 goto fail_no_device; 1589 goto fail_no_device;
1588 } 1590 }
1589 return 0; 1591 return 0;
1590 1592
1591 fail_no_device: 1593 fail_no_device:
1592 acpi_bus_unregister_driver(&asus_acpi_driver); 1594 acpi_bus_unregister_driver(&asus_acpi_driver);
1593 fail_acpi_driver: 1595 fail_acpi_driver:
1594 platform_driver_unregister(&platform_driver); 1596 platform_driver_unregister(&platform_driver);
1595 return result; 1597 return result;
1596 } 1598 }
1597 1599
1598 static void __exit asus_laptop_exit(void) 1600 static void __exit asus_laptop_exit(void)
1599 { 1601 {
1600 acpi_bus_unregister_driver(&asus_acpi_driver); 1602 acpi_bus_unregister_driver(&asus_acpi_driver);
1601 platform_driver_unregister(&platform_driver); 1603 platform_driver_unregister(&platform_driver);
1602 } 1604 }
1603 1605
1604 module_init(asus_laptop_init); 1606 module_init(asus_laptop_init);
1605 module_exit(asus_laptop_exit); 1607 module_exit(asus_laptop_exit);
1606 1608