]>
Commit | Line | Data |
---|---|---|
85091b71 CC |
1 | /* |
2 | * asus-laptop.c - Asus Laptop Support | |
3 | * | |
4 | * | |
5 | * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor | |
8ec555c2 | 6 | * Copyright (C) 2006-2007 Corentin Chary |
8819de7f | 7 | * Copyright (C) 2011 Wind River Systems |
85091b71 CC |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | * | |
23 | * | |
24 | * The development page for this driver is located at | |
25 | * http://sourceforge.net/projects/acpi4asus/ | |
26 | * | |
27 | * Credits: | |
28 | * Pontus Fuchs - Helper functions, cleanup | |
29 | * Johann Wiesner - Small compile fixes | |
30 | * John Belmonte - ACPI code for Toshiba laptop was a good starting point. | |
31 | * Eric Burghard - LED display support for W1N | |
32 | * Josh Green - Light Sens support | |
c8440336 | 33 | * Thomas Tuttle - His first patch for led support was very helpful |
e539c2f6 | 34 | * Sam Lin - GPS support |
85091b71 CC |
35 | */ |
36 | ||
2fcc23da CC |
37 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
38 | ||
85091b71 CC |
39 | #include <linux/kernel.h> |
40 | #include <linux/module.h> | |
41 | #include <linux/init.h> | |
42 | #include <linux/types.h> | |
43 | #include <linux/err.h> | |
44 | #include <linux/proc_fs.h> | |
6b7091e7 CC |
45 | #include <linux/backlight.h> |
46 | #include <linux/fb.h> | |
be18cdab | 47 | #include <linux/leds.h> |
85091b71 | 48 | #include <linux/platform_device.h> |
060cbce6 | 49 | #include <linux/uaccess.h> |
034ce90a | 50 | #include <linux/input.h> |
66a71dd1 | 51 | #include <linux/input/sparse-keymap.h> |
8819de7f | 52 | #include <linux/input-polldev.h> |
18e1311e | 53 | #include <linux/rfkill.h> |
5a0e3ad6 | 54 | #include <linux/slab.h> |
af96f877 | 55 | #include <linux/dmi.h> |
060cbce6 CC |
56 | #include <acpi/acpi_drivers.h> |
57 | #include <acpi/acpi_bus.h> | |
85091b71 | 58 | |
91687cc8 | 59 | #define ASUS_LAPTOP_VERSION "0.42" |
85091b71 | 60 | |
50a90c4d CC |
61 | #define ASUS_LAPTOP_NAME "Asus Laptop Support" |
62 | #define ASUS_LAPTOP_CLASS "hotkey" | |
63 | #define ASUS_LAPTOP_DEVICE_NAME "Hotkey" | |
64 | #define ASUS_LAPTOP_FILE KBUILD_MODNAME | |
65 | #define ASUS_LAPTOP_PREFIX "\\_SB.ATKD." | |
85091b71 | 66 | |
85091b71 | 67 | MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); |
50a90c4d | 68 | MODULE_DESCRIPTION(ASUS_LAPTOP_NAME); |
85091b71 CC |
69 | MODULE_LICENSE("GPL"); |
70 | ||
be966660 CC |
71 | /* |
72 | * WAPF defines the behavior of the Fn+Fx wlan key | |
185e5af9 CC |
73 | * The significance of values is yet to be found, but |
74 | * most of the time: | |
fddbfed5 CC |
75 | * Bit | Bluetooth | WLAN |
76 | * 0 | Hardware | Hardware | |
77 | * 1 | Hardware | Software | |
78 | * 4 | Software | Software | |
185e5af9 CC |
79 | */ |
80 | static uint wapf = 1; | |
c26d85cb | 81 | module_param(wapf, uint, 0444); |
185e5af9 CC |
82 | MODULE_PARM_DESC(wapf, "WAPF value"); |
83 | ||
774b0678 CC |
84 | static char *wled_type = "unknown"; |
85 | static char *bled_type = "unknown"; | |
86 | ||
87 | module_param(wled_type, charp, 0444); | |
88 | MODULE_PARM_DESC(wlan_status, "Set the wled type on boot " | |
89 | "(unknown, led or rfkill). " | |
90 | "default is unknown"); | |
91 | ||
92 | module_param(bled_type, charp, 0444); | |
93 | MODULE_PARM_DESC(bled_type, "Set the bled type on boot " | |
94 | "(unknown, led or rfkill). " | |
95 | "default is unknown"); | |
96 | ||
668f4a03 DC |
97 | static int wlan_status = 1; |
98 | static int bluetooth_status = 1; | |
ba1ff5be CC |
99 | static int wimax_status = -1; |
100 | static int wwan_status = -1; | |
abec04db | 101 | static int als_status; |
0e875f49 | 102 | |
c26d85cb | 103 | module_param(wlan_status, int, 0444); |
d0930a2d | 104 | MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot " |
0e875f49 | 105 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " |
16cbf933 | 106 | "default is -1"); |
0e875f49 | 107 | |
c26d85cb | 108 | module_param(bluetooth_status, int, 0444); |
0e875f49 CC |
109 | MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot " |
110 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " | |
16cbf933 | 111 | "default is -1"); |
0e875f49 | 112 | |
ba1ff5be CC |
113 | module_param(wimax_status, int, 0444); |
114 | MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot " | |
115 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " | |
16cbf933 | 116 | "default is -1"); |
ba1ff5be CC |
117 | |
118 | module_param(wwan_status, int, 0444); | |
119 | MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot " | |
120 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " | |
16cbf933 | 121 | "default is -1"); |
ba1ff5be | 122 | |
abec04db AR |
123 | module_param(als_status, int, 0444); |
124 | MODULE_PARM_DESC(als_status, "Set the ALS status on boot " | |
125 | "(0 = disabled, 1 = enabled). " | |
126 | "default is 0"); | |
127 | ||
be4ee82d CC |
128 | /* |
129 | * Some events we use, same for all Asus | |
130 | */ | |
060cbce6 CC |
131 | #define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */ |
132 | #define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */ | |
a539df5e | 133 | #define ATKD_BR_MIN ATKD_BR_UP |
060cbce6 | 134 | #define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */ |
be4ee82d CC |
135 | #define ATKD_LCD_ON 0x33 |
136 | #define ATKD_LCD_OFF 0x34 | |
137 | ||
138 | /* | |
139 | * Known bits returned by \_SB.ATKD.HWRS | |
140 | */ | |
141 | #define WL_HWRS 0x80 | |
142 | #define BT_HWRS 0x100 | |
143 | ||
144 | /* | |
145 | * Flags for hotk status | |
146 | * WL_ON and BT_ON are also used for wireless_status() | |
147 | */ | |
17e78f62 CC |
148 | #define WL_RSTS 0x01 /* internal Wifi */ |
149 | #define BT_RSTS 0x02 /* internal Bluetooth */ | |
ba1ff5be CC |
150 | #define WM_RSTS 0x08 /* internal wimax */ |
151 | #define WW_RSTS 0x20 /* internal wwan */ | |
be4ee82d | 152 | |
774b0678 CC |
153 | /* WLED and BLED type */ |
154 | #define TYPE_UNKNOWN 0 | |
155 | #define TYPE_LED 1 | |
156 | #define TYPE_RFKILL 2 | |
157 | ||
be18cdab | 158 | /* LED */ |
d99b577c CC |
159 | #define METHOD_MLED "MLED" |
160 | #define METHOD_TLED "TLED" | |
161 | #define METHOD_RLED "RLED" /* W1JC */ | |
162 | #define METHOD_PLED "PLED" /* A7J */ | |
163 | #define METHOD_GLED "GLED" /* G1, G2 (probably) */ | |
be18cdab | 164 | |
722ad971 | 165 | /* LEDD */ |
d99b577c | 166 | #define METHOD_LEDD "SLCM" |
722ad971 | 167 | |
be966660 CC |
168 | /* |
169 | * Bluetooth and WLAN | |
4564de17 CC |
170 | * WLED and BLED are not handled like other XLED, because in some dsdt |
171 | * they also control the WLAN/Bluetooth device. | |
172 | */ | |
d99b577c CC |
173 | #define METHOD_WLAN "WLED" |
174 | #define METHOD_BLUETOOTH "BLED" | |
ba1ff5be CC |
175 | |
176 | /* WWAN and WIMAX */ | |
177 | #define METHOD_WWAN "GSMC" | |
178 | #define METHOD_WIMAX "WMXC" | |
179 | ||
d99b577c | 180 | #define METHOD_WL_STATUS "RSTS" |
4564de17 | 181 | |
6b7091e7 | 182 | /* Brightness */ |
d99b577c CC |
183 | #define METHOD_BRIGHTNESS_SET "SPLV" |
184 | #define METHOD_BRIGHTNESS_GET "GPLV" | |
6b7091e7 | 185 | |
78127b4a | 186 | /* Display */ |
d99b577c | 187 | #define METHOD_SWITCH_DISPLAY "SDSP" |
060cbce6 | 188 | |
d99b577c CC |
189 | #define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */ |
190 | #define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */ | |
8b857353 | 191 | |
e539c2f6 CC |
192 | /* GPS */ |
193 | /* R2H use different handle for GPS on/off */ | |
d99b577c CC |
194 | #define METHOD_GPS_ON "SDON" |
195 | #define METHOD_GPS_OFF "SDOF" | |
196 | #define METHOD_GPS_STATUS "GPST" | |
e539c2f6 | 197 | |
b7d3fbc2 | 198 | /* Keyboard light */ |
d99b577c CC |
199 | #define METHOD_KBD_LIGHT_SET "SLKB" |
200 | #define METHOD_KBD_LIGHT_GET "GLKB" | |
b7d3fbc2 | 201 | |
8819de7f AR |
202 | /* For Pegatron Lucid tablet */ |
203 | #define DEVICE_NAME_PEGA "Lucid" | |
33989ba6 | 204 | |
8819de7f AR |
205 | #define METHOD_PEGA_ENABLE "ENPR" |
206 | #define METHOD_PEGA_DISABLE "DAPR" | |
14908399 AA |
207 | #define PEGA_WLAN 0x00 |
208 | #define PEGA_BLUETOOTH 0x01 | |
209 | #define PEGA_WWAN 0x02 | |
33989ba6 AR |
210 | #define PEGA_ALS 0x04 |
211 | #define PEGA_ALS_POWER 0x05 | |
212 | ||
8819de7f | 213 | #define METHOD_PEGA_READ "RDLN" |
33989ba6 AR |
214 | #define PEGA_READ_ALS_H 0x02 |
215 | #define PEGA_READ_ALS_L 0x03 | |
8819de7f | 216 | |
b23910c2 AR |
217 | #define PEGA_ACCEL_NAME "pega_accel" |
218 | #define PEGA_ACCEL_DESC "Pegatron Lucid Tablet Accelerometer" | |
219 | #define METHOD_XLRX "XLRX" | |
220 | #define METHOD_XLRY "XLRY" | |
221 | #define METHOD_XLRZ "XLRZ" | |
222 | #define PEGA_ACC_CLAMP 512 /* 1G accel is reported as ~256, so clamp to 2G */ | |
223 | #define PEGA_ACC_RETRIES 3 | |
224 | ||
9129d14d CC |
225 | /* |
226 | * Define a specific led structure to keep the main structure clean | |
227 | */ | |
aee0afb8 CC |
228 | struct asus_led { |
229 | int wk; | |
230 | struct work_struct work; | |
231 | struct led_classdev led; | |
232 | struct asus_laptop *asus; | |
233 | const char *method; | |
9129d14d CC |
234 | }; |
235 | ||
14908399 AA |
236 | /* |
237 | * Same thing for rfkill | |
238 | */ | |
40969c7d | 239 | struct asus_rfkill { |
774b0678 CC |
240 | /* type of control. Maps to PEGA_* values or *_RSTS */ |
241 | int control_id; | |
14908399 AA |
242 | struct rfkill *rfkill; |
243 | struct asus_laptop *asus; | |
244 | }; | |
245 | ||
85091b71 CC |
246 | /* |
247 | * This is the main structure, we can use it to store anything interesting | |
248 | * about the hotk device | |
249 | */ | |
50a90c4d | 250 | struct asus_laptop { |
be966660 | 251 | char *name; /* laptop name */ |
600ad520 | 252 | |
7c247645 | 253 | struct acpi_table_header *dsdt_info; |
600ad520 | 254 | struct platform_device *platform_device; |
7c247645 CC |
255 | struct acpi_device *device; /* the device we are in */ |
256 | struct backlight_device *backlight_device; | |
9129d14d | 257 | |
7c247645 | 258 | struct input_dev *inputdev; |
9129d14d | 259 | struct key_entry *keymap; |
b23910c2 | 260 | struct input_polled_dev *pega_accel_poll; |
9129d14d | 261 | |
774b0678 CC |
262 | struct asus_led wled; |
263 | struct asus_led bled; | |
aee0afb8 CC |
264 | struct asus_led mled; |
265 | struct asus_led tled; | |
266 | struct asus_led rled; | |
267 | struct asus_led pled; | |
268 | struct asus_led gled; | |
269 | struct asus_led kled; | |
270 | struct workqueue_struct *led_workqueue; | |
7c247645 | 271 | |
774b0678 CC |
272 | int wled_type; |
273 | int bled_type; | |
aa9df930 CC |
274 | int wireless_status; |
275 | bool have_rsts; | |
8819de7f | 276 | bool is_pega_lucid; |
b23910c2 AR |
277 | bool pega_acc_live; |
278 | int pega_acc_x; | |
279 | int pega_acc_y; | |
280 | int pega_acc_z; | |
aa9df930 | 281 | |
40969c7d CC |
282 | struct asus_rfkill wlan; |
283 | struct asus_rfkill bluetooth; | |
284 | struct asus_rfkill wwan; | |
285 | struct asus_rfkill gps; | |
14908399 | 286 | |
be966660 | 287 | acpi_handle handle; /* the handle of the hotk device */ |
be966660 CC |
288 | u32 ledd_status; /* status of the LED display */ |
289 | u8 light_level; /* light sensor level */ | |
290 | u8 light_switch; /* light sensor switch value */ | |
291 | u16 event_count[128]; /* count for each event TODO make this better */ | |
85091b71 CC |
292 | }; |
293 | ||
9129d14d | 294 | static const struct key_entry asus_keymap[] = { |
a539df5e | 295 | /* Lenovo SL Specific keycodes */ |
66a71dd1 CC |
296 | {KE_KEY, 0x02, { KEY_SCREENLOCK } }, |
297 | {KE_KEY, 0x05, { KEY_WLAN } }, | |
298 | {KE_KEY, 0x08, { KEY_F13 } }, | |
299 | {KE_KEY, 0x17, { KEY_ZOOM } }, | |
300 | {KE_KEY, 0x1f, { KEY_BATTERY } }, | |
a539df5e | 301 | /* End of Lenovo SL Specific keycodes */ |
66a71dd1 CC |
302 | {KE_KEY, 0x30, { KEY_VOLUMEUP } }, |
303 | {KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, | |
304 | {KE_KEY, 0x32, { KEY_MUTE } }, | |
305 | {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } }, | |
306 | {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } }, | |
307 | {KE_KEY, 0x40, { KEY_PREVIOUSSONG } }, | |
308 | {KE_KEY, 0x41, { KEY_NEXTSONG } }, | |
309 | {KE_KEY, 0x43, { KEY_STOPCD } }, | |
310 | {KE_KEY, 0x45, { KEY_PLAYPAUSE } }, | |
311 | {KE_KEY, 0x4c, { KEY_MEDIA } }, | |
312 | {KE_KEY, 0x50, { KEY_EMAIL } }, | |
313 | {KE_KEY, 0x51, { KEY_WWW } }, | |
314 | {KE_KEY, 0x55, { KEY_CALC } }, | |
315 | {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */ | |
316 | {KE_KEY, 0x5D, { KEY_WLAN } }, | |
317 | {KE_KEY, 0x5E, { KEY_WLAN } }, | |
318 | {KE_KEY, 0x5F, { KEY_WLAN } }, | |
319 | {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } }, | |
320 | {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } }, | |
321 | {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } }, | |
322 | {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } }, | |
323 | {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */ | |
7f607d71 CC |
324 | {KE_KEY, 0x7E, { KEY_BLUETOOTH } }, |
325 | {KE_KEY, 0x7D, { KEY_BLUETOOTH } }, | |
66a71dd1 CC |
326 | {KE_KEY, 0x82, { KEY_CAMERA } }, |
327 | {KE_KEY, 0x88, { KEY_WLAN } }, | |
328 | {KE_KEY, 0x8A, { KEY_PROG1 } }, | |
329 | {KE_KEY, 0x95, { KEY_MEDIA } }, | |
330 | {KE_KEY, 0x99, { KEY_PHONE } }, | |
331 | {KE_KEY, 0xc4, { KEY_KBDILLUMUP } }, | |
332 | {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } }, | |
b58baecd | 333 | {KE_KEY, 0xb5, { KEY_CALC } }, |
034ce90a CC |
334 | {KE_END, 0}, |
335 | }; | |
336 | ||
66a71dd1 | 337 | |
85091b71 CC |
338 | /* |
339 | * This function evaluates an ACPI method, given an int as parameter, the | |
340 | * method is searched within the scope of the handle, can be NULL. The output | |
341 | * of the method is written is output, which can also be NULL | |
342 | * | |
f8d1c94b | 343 | * returns 0 if write is successful, -1 else. |
85091b71 | 344 | */ |
d8c67323 CC |
345 | static int write_acpi_int_ret(acpi_handle handle, const char *method, int val, |
346 | struct acpi_buffer *output) | |
85091b71 | 347 | { |
be966660 CC |
348 | struct acpi_object_list params; /* list of input parameters (an int) */ |
349 | union acpi_object in_obj; /* the only param we use */ | |
85091b71 CC |
350 | acpi_status status; |
351 | ||
f8d1c94b | 352 | if (!handle) |
9fb866f3 | 353 | return -1; |
f8d1c94b | 354 | |
85091b71 CC |
355 | params.count = 1; |
356 | params.pointer = &in_obj; | |
357 | in_obj.type = ACPI_TYPE_INTEGER; | |
358 | in_obj.integer.value = val; | |
359 | ||
360 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); | |
f8d1c94b CC |
361 | if (status == AE_OK) |
362 | return 0; | |
363 | else | |
364 | return -1; | |
85091b71 CC |
365 | } |
366 | ||
d8c67323 CC |
367 | static int write_acpi_int(acpi_handle handle, const char *method, int val) |
368 | { | |
369 | return write_acpi_int_ret(handle, method, val, NULL); | |
370 | } | |
371 | ||
d99b577c CC |
372 | static int acpi_check_handle(acpi_handle handle, const char *method, |
373 | acpi_handle *ret) | |
374 | { | |
375 | acpi_status status; | |
376 | ||
377 | if (method == NULL) | |
378 | return -ENODEV; | |
379 | ||
380 | if (ret) | |
381 | status = acpi_get_handle(handle, (char *)method, | |
382 | ret); | |
383 | else { | |
384 | acpi_handle dummy; | |
385 | ||
386 | status = acpi_get_handle(handle, (char *)method, | |
387 | &dummy); | |
388 | } | |
389 | ||
390 | if (status != AE_OK) { | |
391 | if (ret) | |
5ad77dcf | 392 | pr_warn("Error finding %s\n", method); |
d99b577c CC |
393 | return -ENODEV; |
394 | } | |
395 | return 0; | |
396 | } | |
397 | ||
8819de7f AR |
398 | static bool asus_check_pega_lucid(struct asus_laptop *asus) |
399 | { | |
400 | return !strcmp(asus->name, DEVICE_NAME_PEGA) && | |
401 | !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) && | |
402 | !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) && | |
403 | !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL); | |
404 | } | |
405 | ||
33989ba6 AR |
406 | static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable) |
407 | { | |
408 | char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE; | |
409 | return write_acpi_int(asus->handle, method, unit); | |
410 | } | |
411 | ||
b23910c2 AR |
412 | static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method) |
413 | { | |
414 | int i, delta; | |
415 | unsigned long long val; | |
416 | for (i = 0; i < PEGA_ACC_RETRIES; i++) { | |
417 | acpi_evaluate_integer(asus->handle, method, NULL, &val); | |
418 | ||
419 | /* The output is noisy. From reading the ASL | |
420 | * dissassembly, timeout errors are returned with 1's | |
421 | * in the high word, and the lack of locking around | |
422 | * thei hi/lo byte reads means that a transition | |
423 | * between (for example) -1 and 0 could be read as | |
424 | * 0xff00 or 0x00ff. */ | |
425 | delta = abs(curr - (short)val); | |
426 | if (delta < 128 && !(val & ~0xffff)) | |
427 | break; | |
428 | } | |
429 | return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP); | |
430 | } | |
431 | ||
432 | static void pega_accel_poll(struct input_polled_dev *ipd) | |
433 | { | |
434 | struct device *parent = ipd->input->dev.parent; | |
435 | struct asus_laptop *asus = dev_get_drvdata(parent); | |
436 | ||
437 | /* In some cases, the very first call to poll causes a | |
438 | * recursive fault under the polldev worker. This is | |
439 | * apparently related to very early userspace access to the | |
440 | * device, and perhaps a firmware bug. Fake the first report. */ | |
441 | if (!asus->pega_acc_live) { | |
442 | asus->pega_acc_live = true; | |
443 | input_report_abs(ipd->input, ABS_X, 0); | |
444 | input_report_abs(ipd->input, ABS_Y, 0); | |
445 | input_report_abs(ipd->input, ABS_Z, 0); | |
446 | input_sync(ipd->input); | |
447 | return; | |
448 | } | |
449 | ||
450 | asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX); | |
451 | asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY); | |
452 | asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ); | |
453 | ||
454 | /* Note transform, convert to "right/up/out" in the native | |
455 | * landscape orientation (i.e. the vector is the direction of | |
456 | * "real up" in the device's cartiesian coordinates). */ | |
457 | input_report_abs(ipd->input, ABS_X, -asus->pega_acc_x); | |
458 | input_report_abs(ipd->input, ABS_Y, -asus->pega_acc_y); | |
459 | input_report_abs(ipd->input, ABS_Z, asus->pega_acc_z); | |
460 | input_sync(ipd->input); | |
461 | } | |
462 | ||
463 | static void pega_accel_exit(struct asus_laptop *asus) | |
464 | { | |
465 | if (asus->pega_accel_poll) { | |
466 | input_unregister_polled_device(asus->pega_accel_poll); | |
467 | input_free_polled_device(asus->pega_accel_poll); | |
468 | } | |
469 | asus->pega_accel_poll = NULL; | |
470 | } | |
471 | ||
472 | static int pega_accel_init(struct asus_laptop *asus) | |
473 | { | |
474 | int err; | |
475 | struct input_polled_dev *ipd; | |
476 | ||
477 | if (!asus->is_pega_lucid) | |
478 | return -ENODEV; | |
479 | ||
480 | if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) || | |
481 | acpi_check_handle(asus->handle, METHOD_XLRY, NULL) || | |
482 | acpi_check_handle(asus->handle, METHOD_XLRZ, NULL)) | |
483 | return -ENODEV; | |
484 | ||
485 | ipd = input_allocate_polled_device(); | |
486 | if (!ipd) | |
487 | return -ENOMEM; | |
488 | ||
489 | ipd->poll = pega_accel_poll; | |
490 | ipd->poll_interval = 125; | |
491 | ipd->poll_interval_min = 50; | |
492 | ipd->poll_interval_max = 2000; | |
493 | ||
494 | ipd->input->name = PEGA_ACCEL_DESC; | |
495 | ipd->input->phys = PEGA_ACCEL_NAME "/input0"; | |
496 | ipd->input->dev.parent = &asus->platform_device->dev; | |
497 | ipd->input->id.bustype = BUS_HOST; | |
498 | ||
499 | set_bit(EV_ABS, ipd->input->evbit); | |
500 | input_set_abs_params(ipd->input, ABS_X, | |
501 | -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); | |
502 | input_set_abs_params(ipd->input, ABS_Y, | |
503 | -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); | |
504 | input_set_abs_params(ipd->input, ABS_Z, | |
505 | -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0); | |
506 | ||
507 | err = input_register_polled_device(ipd); | |
508 | if (err) | |
509 | goto exit; | |
510 | ||
511 | asus->pega_accel_poll = ipd; | |
512 | return 0; | |
513 | ||
514 | exit: | |
515 | input_free_polled_device(ipd); | |
516 | return err; | |
517 | } | |
518 | ||
17e78f62 | 519 | /* Generic LED function */ |
aee0afb8 | 520 | static int asus_led_set(struct asus_laptop *asus, const char *method, |
17e78f62 | 521 | int value) |
be18cdab | 522 | { |
d99b577c | 523 | if (!strcmp(method, METHOD_MLED)) |
17e78f62 | 524 | value = !value; |
d99b577c | 525 | else if (!strcmp(method, METHOD_GLED)) |
17e78f62 CC |
526 | value = !value + 1; |
527 | else | |
528 | value = !!value; | |
be18cdab | 529 | |
e5593bf1 | 530 | return write_acpi_int(asus->handle, method, value); |
be18cdab CC |
531 | } |
532 | ||
be4ee82d CC |
533 | /* |
534 | * LEDs | |
535 | */ | |
be18cdab | 536 | /* /sys/class/led handlers */ |
aee0afb8 CC |
537 | static void asus_led_cdev_set(struct led_classdev *led_cdev, |
538 | enum led_brightness value) | |
539 | { | |
540 | struct asus_led *led = container_of(led_cdev, struct asus_led, led); | |
541 | struct asus_laptop *asus = led->asus; | |
542 | ||
543 | led->wk = !!value; | |
544 | queue_work(asus->led_workqueue, &led->work); | |
545 | } | |
be18cdab | 546 | |
aee0afb8 CC |
547 | static void asus_led_cdev_update(struct work_struct *work) |
548 | { | |
549 | struct asus_led *led = container_of(work, struct asus_led, work); | |
550 | struct asus_laptop *asus = led->asus; | |
551 | ||
552 | asus_led_set(asus, led->method, led->wk); | |
553 | } | |
554 | ||
555 | static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev) | |
556 | { | |
557 | return led_cdev->brightness; | |
558 | } | |
be18cdab | 559 | |
b7d3fbc2 | 560 | /* |
be4ee82d | 561 | * Keyboard backlight (also a LED) |
b7d3fbc2 | 562 | */ |
d99b577c | 563 | static int asus_kled_lvl(struct asus_laptop *asus) |
b7d3fbc2 CC |
564 | { |
565 | unsigned long long kblv; | |
566 | struct acpi_object_list params; | |
567 | union acpi_object in_obj; | |
568 | acpi_status rv; | |
569 | ||
570 | params.count = 1; | |
571 | params.pointer = &in_obj; | |
572 | in_obj.type = ACPI_TYPE_INTEGER; | |
573 | in_obj.integer.value = 2; | |
574 | ||
d99b577c CC |
575 | rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET, |
576 | ¶ms, &kblv); | |
b7d3fbc2 | 577 | if (ACPI_FAILURE(rv)) { |
5ad77dcf | 578 | pr_warn("Error reading kled level\n"); |
4d441513 | 579 | return -ENODEV; |
b7d3fbc2 CC |
580 | } |
581 | return kblv; | |
582 | } | |
583 | ||
4d441513 | 584 | static int asus_kled_set(struct asus_laptop *asus, int kblv) |
b7d3fbc2 CC |
585 | { |
586 | if (kblv > 0) | |
587 | kblv = (1 << 7) | (kblv & 0x7F); | |
588 | else | |
589 | kblv = 0; | |
590 | ||
d99b577c | 591 | if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) { |
5ad77dcf | 592 | pr_warn("Keyboard LED display write failed\n"); |
b7d3fbc2 CC |
593 | return -EINVAL; |
594 | } | |
595 | return 0; | |
596 | } | |
597 | ||
aee0afb8 CC |
598 | static void asus_kled_cdev_set(struct led_classdev *led_cdev, |
599 | enum led_brightness value) | |
b7d3fbc2 | 600 | { |
aee0afb8 CC |
601 | struct asus_led *led = container_of(led_cdev, struct asus_led, led); |
602 | struct asus_laptop *asus = led->asus; | |
9129d14d | 603 | |
060cbce6 | 604 | led->wk = value; |
aee0afb8 | 605 | queue_work(asus->led_workqueue, &led->work); |
b7d3fbc2 CC |
606 | } |
607 | ||
aee0afb8 | 608 | static void asus_kled_cdev_update(struct work_struct *work) |
b7d3fbc2 | 609 | { |
aee0afb8 CC |
610 | struct asus_led *led = container_of(work, struct asus_led, work); |
611 | struct asus_laptop *asus = led->asus; | |
9129d14d | 612 | |
aee0afb8 | 613 | asus_kled_set(asus, led->wk); |
b7d3fbc2 CC |
614 | } |
615 | ||
aee0afb8 | 616 | static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev) |
b7d3fbc2 | 617 | { |
aee0afb8 CC |
618 | struct asus_led *led = container_of(led_cdev, struct asus_led, led); |
619 | struct asus_laptop *asus = led->asus; | |
d99b577c CC |
620 | |
621 | return asus_kled_lvl(asus); | |
b7d3fbc2 CC |
622 | } |
623 | ||
be4ee82d CC |
624 | static void asus_led_exit(struct asus_laptop *asus) |
625 | { | |
774b0678 CC |
626 | if (!IS_ERR_OR_NULL(asus->wled.led.dev)) |
627 | led_classdev_unregister(&asus->wled.led); | |
628 | if (!IS_ERR_OR_NULL(asus->bled.led.dev)) | |
629 | led_classdev_unregister(&asus->bled.led); | |
8fcf71aa | 630 | if (!IS_ERR_OR_NULL(asus->mled.led.dev)) |
aee0afb8 | 631 | led_classdev_unregister(&asus->mled.led); |
8fcf71aa | 632 | if (!IS_ERR_OR_NULL(asus->tled.led.dev)) |
aee0afb8 | 633 | led_classdev_unregister(&asus->tled.led); |
8fcf71aa | 634 | if (!IS_ERR_OR_NULL(asus->pled.led.dev)) |
aee0afb8 | 635 | led_classdev_unregister(&asus->pled.led); |
8fcf71aa | 636 | if (!IS_ERR_OR_NULL(asus->rled.led.dev)) |
aee0afb8 | 637 | led_classdev_unregister(&asus->rled.led); |
8fcf71aa | 638 | if (!IS_ERR_OR_NULL(asus->gled.led.dev)) |
aee0afb8 | 639 | led_classdev_unregister(&asus->gled.led); |
8fcf71aa | 640 | if (!IS_ERR_OR_NULL(asus->kled.led.dev)) |
aee0afb8 CC |
641 | led_classdev_unregister(&asus->kled.led); |
642 | if (asus->led_workqueue) { | |
643 | destroy_workqueue(asus->led_workqueue); | |
644 | asus->led_workqueue = NULL; | |
be4ee82d CC |
645 | } |
646 | } | |
647 | ||
648 | /* Ugly macro, need to fix that later */ | |
aee0afb8 CC |
649 | static int asus_led_register(struct asus_laptop *asus, |
650 | struct asus_led *led, | |
651 | const char *name, const char *method) | |
652 | { | |
653 | struct led_classdev *led_cdev = &led->led; | |
654 | ||
655 | if (!method || acpi_check_handle(asus->handle, method, NULL)) | |
060cbce6 | 656 | return 0; /* Led not present */ |
aee0afb8 CC |
657 | |
658 | led->asus = asus; | |
659 | led->method = method; | |
660 | ||
661 | INIT_WORK(&led->work, asus_led_cdev_update); | |
662 | led_cdev->name = name; | |
663 | led_cdev->brightness_set = asus_led_cdev_set; | |
664 | led_cdev->brightness_get = asus_led_cdev_get; | |
665 | led_cdev->max_brightness = 1; | |
666 | return led_classdev_register(&asus->platform_device->dev, led_cdev); | |
667 | } | |
be4ee82d CC |
668 | |
669 | static int asus_led_init(struct asus_laptop *asus) | |
670 | { | |
774b0678 | 671 | int r = 0; |
be4ee82d | 672 | |
8d38e42c CC |
673 | /* |
674 | * The Pegatron Lucid has no physical leds, but all methods are | |
675 | * available in the DSDT... | |
676 | */ | |
677 | if (asus->is_pega_lucid) | |
678 | return 0; | |
679 | ||
be4ee82d CC |
680 | /* |
681 | * Functions that actually update the LED's are called from a | |
682 | * workqueue. By doing this as separate work rather than when the LED | |
683 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a | |
684 | * potentially bad time, such as a timer interrupt. | |
685 | */ | |
aee0afb8 CC |
686 | asus->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
687 | if (!asus->led_workqueue) | |
be4ee82d CC |
688 | return -ENOMEM; |
689 | ||
774b0678 CC |
690 | if (asus->wled_type == TYPE_LED) |
691 | r = asus_led_register(asus, &asus->wled, "asus::wlan", | |
692 | METHOD_WLAN); | |
693 | if (r) | |
694 | goto error; | |
695 | if (asus->bled_type == TYPE_LED) | |
696 | r = asus_led_register(asus, &asus->bled, "asus::bluetooth", | |
697 | METHOD_BLUETOOTH); | |
698 | if (r) | |
699 | goto error; | |
aee0afb8 CC |
700 | r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED); |
701 | if (r) | |
702 | goto error; | |
703 | r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED); | |
704 | if (r) | |
705 | goto error; | |
706 | r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED); | |
707 | if (r) | |
708 | goto error; | |
709 | r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED); | |
710 | if (r) | |
711 | goto error; | |
712 | r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED); | |
713 | if (r) | |
714 | goto error; | |
d99b577c | 715 | if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) && |
aee0afb8 CC |
716 | !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) { |
717 | struct asus_led *led = &asus->kled; | |
718 | struct led_classdev *cdev = &led->led; | |
719 | ||
720 | led->asus = asus; | |
721 | ||
722 | INIT_WORK(&led->work, asus_kled_cdev_update); | |
723 | cdev->name = "asus::kbd_backlight"; | |
724 | cdev->brightness_set = asus_kled_cdev_set; | |
725 | cdev->brightness_get = asus_kled_cdev_get; | |
726 | cdev->max_brightness = 3; | |
727 | r = led_classdev_register(&asus->platform_device->dev, cdev); | |
728 | } | |
be4ee82d | 729 | error: |
aee0afb8 | 730 | if (r) |
be4ee82d | 731 | asus_led_exit(asus); |
aee0afb8 | 732 | return r; |
be4ee82d CC |
733 | } |
734 | ||
735 | /* | |
736 | * Backlight device | |
737 | */ | |
4d441513 | 738 | static int asus_read_brightness(struct backlight_device *bd) |
6b7091e7 | 739 | { |
d99b577c | 740 | struct asus_laptop *asus = bl_get_data(bd); |
27663c58 | 741 | unsigned long long value; |
9a816850 | 742 | acpi_status rv = AE_OK; |
6b7091e7 | 743 | |
d99b577c CC |
744 | rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET, |
745 | NULL, &value); | |
9a816850 | 746 | if (ACPI_FAILURE(rv)) |
5ad77dcf | 747 | pr_warn("Error reading brightness\n"); |
6b7091e7 CC |
748 | |
749 | return value; | |
750 | } | |
751 | ||
4d441513 | 752 | static int asus_set_brightness(struct backlight_device *bd, int value) |
6b7091e7 | 753 | { |
d99b577c CC |
754 | struct asus_laptop *asus = bl_get_data(bd); |
755 | ||
756 | if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) { | |
5ad77dcf | 757 | pr_warn("Error changing brightness\n"); |
e5b50f6a | 758 | return -EIO; |
6b7091e7 | 759 | } |
e5b50f6a | 760 | return 0; |
6b7091e7 CC |
761 | } |
762 | ||
763 | static int update_bl_status(struct backlight_device *bd) | |
764 | { | |
599a52d1 | 765 | int value = bd->props.brightness; |
6b7091e7 | 766 | |
3b81cf9d | 767 | return asus_set_brightness(bd, value); |
6b7091e7 CC |
768 | } |
769 | ||
acc2472e | 770 | static const struct backlight_ops asusbl_ops = { |
4d441513 | 771 | .get_brightness = asus_read_brightness, |
be4ee82d CC |
772 | .update_status = update_bl_status, |
773 | }; | |
774 | ||
a539df5e CC |
775 | static int asus_backlight_notify(struct asus_laptop *asus) |
776 | { | |
777 | struct backlight_device *bd = asus->backlight_device; | |
778 | int old = bd->props.brightness; | |
779 | ||
780 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); | |
781 | ||
782 | return old; | |
783 | } | |
784 | ||
be4ee82d CC |
785 | static int asus_backlight_init(struct asus_laptop *asus) |
786 | { | |
787 | struct backlight_device *bd; | |
a19a6ee6 | 788 | struct backlight_properties props; |
be4ee82d | 789 | |
71e687dc | 790 | if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) || |
3b81cf9d | 791 | acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL)) |
71e687dc | 792 | return 0; |
be4ee82d | 793 | |
71e687dc CC |
794 | memset(&props, 0, sizeof(struct backlight_properties)); |
795 | props.max_brightness = 15; | |
bb7ca747 | 796 | props.type = BACKLIGHT_PLATFORM; |
be4ee82d | 797 | |
71e687dc CC |
798 | bd = backlight_device_register(ASUS_LAPTOP_FILE, |
799 | &asus->platform_device->dev, asus, | |
800 | &asusbl_ops, &props); | |
801 | if (IS_ERR(bd)) { | |
802 | pr_err("Could not register asus backlight device\n"); | |
803 | asus->backlight_device = NULL; | |
804 | return PTR_ERR(bd); | |
be4ee82d | 805 | } |
71e687dc CC |
806 | |
807 | asus->backlight_device = bd; | |
808 | bd->props.brightness = asus_read_brightness(bd); | |
809 | bd->props.power = FB_BLANK_UNBLANK; | |
810 | backlight_update_status(bd); | |
be4ee82d CC |
811 | return 0; |
812 | } | |
813 | ||
814 | static void asus_backlight_exit(struct asus_laptop *asus) | |
815 | { | |
816 | if (asus->backlight_device) | |
817 | backlight_device_unregister(asus->backlight_device); | |
a539df5e | 818 | asus->backlight_device = NULL; |
be4ee82d CC |
819 | } |
820 | ||
85091b71 CC |
821 | /* |
822 | * Platform device handlers | |
823 | */ | |
824 | ||
825 | /* | |
826 | * We write our info in page, we begin at offset off and cannot write more | |
827 | * than count bytes. We set eof to 1 if we handle those 2 values. We return the | |
828 | * number of bytes written in page | |
829 | */ | |
830 | static ssize_t show_infos(struct device *dev, | |
8def05fa | 831 | struct device_attribute *attr, char *page) |
85091b71 | 832 | { |
9129d14d | 833 | struct asus_laptop *asus = dev_get_drvdata(dev); |
85091b71 | 834 | int len = 0; |
27663c58 | 835 | unsigned long long temp; |
be966660 | 836 | char buf[16]; /* enough for all info */ |
9a816850 CC |
837 | acpi_status rv = AE_OK; |
838 | ||
85091b71 | 839 | /* |
060cbce6 CC |
840 | * We use the easy way, we don't care of off and count, |
841 | * so we don't set eof to 1 | |
85091b71 CC |
842 | */ |
843 | ||
50a90c4d CC |
844 | len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n"); |
845 | len += sprintf(page + len, "Model reference : %s\n", asus->name); | |
85091b71 CC |
846 | /* |
847 | * The SFUN method probably allows the original driver to get the list | |
848 | * of features supported by a given model. For now, 0x0100 or 0x0800 | |
849 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. | |
850 | * The significance of others is yet to be found. | |
851 | */ | |
50a90c4d | 852 | rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp); |
9a816850 | 853 | if (!ACPI_FAILURE(rv)) |
1d4a3800 CC |
854 | len += sprintf(page + len, "SFUN value : %#x\n", |
855 | (uint) temp); | |
856 | /* | |
857 | * The HWRS method return informations about the hardware. | |
858 | * 0x80 bit is for WLAN, 0x100 for Bluetooth. | |
859 | * The significance of others is yet to be found. | |
860 | * If we don't find the method, we assume the device are present. | |
861 | */ | |
50a90c4d | 862 | rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp); |
1d4a3800 CC |
863 | if (!ACPI_FAILURE(rv)) |
864 | len += sprintf(page + len, "HRWS value : %#x\n", | |
9a816850 | 865 | (uint) temp); |
85091b71 CC |
866 | /* |
867 | * Another value for userspace: the ASYM method returns 0x02 for | |
868 | * battery low and 0x04 for battery critical, its readings tend to be | |
869 | * more accurate than those provided by _BST. | |
870 | * Note: since not all the laptops provide this method, errors are | |
871 | * silently ignored. | |
872 | */ | |
50a90c4d | 873 | rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp); |
9a816850 | 874 | if (!ACPI_FAILURE(rv)) |
1d4a3800 | 875 | len += sprintf(page + len, "ASYM value : %#x\n", |
9a816850 | 876 | (uint) temp); |
7c247645 CC |
877 | if (asus->dsdt_info) { |
878 | snprintf(buf, 16, "%d", asus->dsdt_info->length); | |
85091b71 | 879 | len += sprintf(page + len, "DSDT length : %s\n", buf); |
7c247645 | 880 | snprintf(buf, 16, "%d", asus->dsdt_info->checksum); |
85091b71 | 881 | len += sprintf(page + len, "DSDT checksum : %s\n", buf); |
7c247645 | 882 | snprintf(buf, 16, "%d", asus->dsdt_info->revision); |
85091b71 | 883 | len += sprintf(page + len, "DSDT revision : %s\n", buf); |
7c247645 | 884 | snprintf(buf, 7, "%s", asus->dsdt_info->oem_id); |
85091b71 | 885 | len += sprintf(page + len, "OEM id : %s\n", buf); |
7c247645 | 886 | snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id); |
85091b71 | 887 | len += sprintf(page + len, "OEM table id : %s\n", buf); |
7c247645 | 888 | snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision); |
85091b71 | 889 | len += sprintf(page + len, "OEM revision : 0x%s\n", buf); |
7c247645 | 890 | snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id); |
85091b71 | 891 | len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); |
7c247645 | 892 | snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision); |
85091b71 CC |
893 | len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); |
894 | } | |
895 | ||
896 | return len; | |
897 | } | |
898 | ||
899 | static int parse_arg(const char *buf, unsigned long count, int *val) | |
900 | { | |
901 | if (!count) | |
902 | return 0; | |
903 | if (count > 31) | |
904 | return -EINVAL; | |
905 | if (sscanf(buf, "%i", val) != 1) | |
906 | return -EINVAL; | |
907 | return count; | |
908 | } | |
909 | ||
17e78f62 CC |
910 | static ssize_t sysfs_acpi_set(struct asus_laptop *asus, |
911 | const char *buf, size_t count, | |
d99b577c | 912 | const char *method) |
4564de17 CC |
913 | { |
914 | int rv, value; | |
915 | int out = 0; | |
916 | ||
917 | rv = parse_arg(buf, count, &value); | |
918 | if (rv > 0) | |
919 | out = value ? 1 : 0; | |
920 | ||
d99b577c | 921 | if (write_acpi_int(asus->handle, method, value)) |
17e78f62 | 922 | return -ENODEV; |
4564de17 CC |
923 | return rv; |
924 | } | |
925 | ||
722ad971 CC |
926 | /* |
927 | * LEDD display | |
928 | */ | |
929 | static ssize_t show_ledd(struct device *dev, | |
930 | struct device_attribute *attr, char *buf) | |
931 | { | |
9129d14d CC |
932 | struct asus_laptop *asus = dev_get_drvdata(dev); |
933 | ||
50a90c4d | 934 | return sprintf(buf, "0x%08x\n", asus->ledd_status); |
722ad971 CC |
935 | } |
936 | ||
937 | static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, | |
938 | const char *buf, size_t count) | |
939 | { | |
9129d14d | 940 | struct asus_laptop *asus = dev_get_drvdata(dev); |
722ad971 CC |
941 | int rv, value; |
942 | ||
943 | rv = parse_arg(buf, count, &value); | |
944 | if (rv > 0) { | |
6a984a06 | 945 | if (write_acpi_int(asus->handle, METHOD_LEDD, value)) { |
5ad77dcf | 946 | pr_warn("LED display write failed\n"); |
6a984a06 AL |
947 | return -ENODEV; |
948 | } | |
949 | asus->ledd_status = (u32) value; | |
722ad971 CC |
950 | } |
951 | return rv; | |
952 | } | |
953 | ||
aa9df930 CC |
954 | /* |
955 | * Wireless | |
956 | */ | |
957 | static int asus_wireless_status(struct asus_laptop *asus, int mask) | |
958 | { | |
959 | unsigned long long status; | |
960 | acpi_status rv = AE_OK; | |
961 | ||
962 | if (!asus->have_rsts) | |
963 | return (asus->wireless_status & mask) ? 1 : 0; | |
964 | ||
d99b577c CC |
965 | rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS, |
966 | NULL, &status); | |
aa9df930 | 967 | if (ACPI_FAILURE(rv)) { |
5ad77dcf | 968 | pr_warn("Error reading Wireless status\n"); |
aa9df930 CC |
969 | return -EINVAL; |
970 | } | |
971 | return !!(status & mask); | |
972 | } | |
973 | ||
4564de17 CC |
974 | /* |
975 | * WLAN | |
976 | */ | |
e5593bf1 CC |
977 | static int asus_wlan_set(struct asus_laptop *asus, int status) |
978 | { | |
979 | if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) { | |
5ad77dcf | 980 | pr_warn("Error setting wlan status to %d\n", status); |
e5593bf1 CC |
981 | return -EIO; |
982 | } | |
983 | return 0; | |
984 | } | |
985 | ||
4564de17 CC |
986 | static ssize_t show_wlan(struct device *dev, |
987 | struct device_attribute *attr, char *buf) | |
988 | { | |
9129d14d CC |
989 | struct asus_laptop *asus = dev_get_drvdata(dev); |
990 | ||
17e78f62 | 991 | return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS)); |
4564de17 CC |
992 | } |
993 | ||
994 | static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, | |
995 | const char *buf, size_t count) | |
996 | { | |
9129d14d CC |
997 | struct asus_laptop *asus = dev_get_drvdata(dev); |
998 | ||
d99b577c | 999 | return sysfs_acpi_set(asus, buf, count, METHOD_WLAN); |
4564de17 CC |
1000 | } |
1001 | ||
774b0678 | 1002 | /*e |
4564de17 CC |
1003 | * Bluetooth |
1004 | */ | |
e5593bf1 CC |
1005 | static int asus_bluetooth_set(struct asus_laptop *asus, int status) |
1006 | { | |
1007 | if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) { | |
5ad77dcf | 1008 | pr_warn("Error setting bluetooth status to %d\n", status); |
e5593bf1 CC |
1009 | return -EIO; |
1010 | } | |
1011 | return 0; | |
1012 | } | |
1013 | ||
4564de17 CC |
1014 | static ssize_t show_bluetooth(struct device *dev, |
1015 | struct device_attribute *attr, char *buf) | |
1016 | { | |
9129d14d CC |
1017 | struct asus_laptop *asus = dev_get_drvdata(dev); |
1018 | ||
17e78f62 | 1019 | return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS)); |
4564de17 CC |
1020 | } |
1021 | ||
8def05fa LB |
1022 | static ssize_t store_bluetooth(struct device *dev, |
1023 | struct device_attribute *attr, const char *buf, | |
1024 | size_t count) | |
4564de17 | 1025 | { |
9129d14d CC |
1026 | struct asus_laptop *asus = dev_get_drvdata(dev); |
1027 | ||
d99b577c | 1028 | return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH); |
4564de17 CC |
1029 | } |
1030 | ||
ba1ff5be CC |
1031 | /* |
1032 | * Wimax | |
1033 | */ | |
1034 | static int asus_wimax_set(struct asus_laptop *asus, int status) | |
1035 | { | |
1036 | if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) { | |
5ad77dcf | 1037 | pr_warn("Error setting wimax status to %d\n", status); |
ba1ff5be CC |
1038 | return -EIO; |
1039 | } | |
1040 | return 0; | |
1041 | } | |
1042 | ||
1043 | static ssize_t show_wimax(struct device *dev, | |
1044 | struct device_attribute *attr, char *buf) | |
1045 | { | |
1046 | struct asus_laptop *asus = dev_get_drvdata(dev); | |
1047 | ||
1048 | return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS)); | |
1049 | } | |
1050 | ||
1051 | static ssize_t store_wimax(struct device *dev, | |
1052 | struct device_attribute *attr, const char *buf, | |
1053 | size_t count) | |
1054 | { | |
1055 | struct asus_laptop *asus = dev_get_drvdata(dev); | |
1056 | ||
1057 | return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX); | |
1058 | } | |
1059 | ||
1060 | /* | |
1061 | * Wwan | |
1062 | */ | |
1063 | static int asus_wwan_set(struct asus_laptop *asus, int status) | |
1064 | { | |
1065 | if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) { | |
5ad77dcf | 1066 | pr_warn("Error setting wwan status to %d\n", status); |
ba1ff5be CC |
1067 | return -EIO; |
1068 | } | |
1069 | return 0; | |
1070 | } | |
1071 | ||
1072 | static ssize_t show_wwan(struct device *dev, | |
1073 | struct device_attribute *attr, char *buf) | |
1074 | { | |
1075 | struct asus_laptop *asus = dev_get_drvdata(dev); | |
1076 | ||
1077 | return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS)); | |
1078 | } | |
1079 | ||
1080 | static ssize_t store_wwan(struct device *dev, | |
1081 | struct device_attribute *attr, const char *buf, | |
1082 | size_t count) | |
1083 | { | |
1084 | struct asus_laptop *asus = dev_get_drvdata(dev); | |
1085 | ||
1086 | return sysfs_acpi_set(asus, buf, count, METHOD_WWAN); | |
1087 | } | |
1088 | ||
78127b4a CC |
1089 | /* |
1090 | * Display | |
1091 | */ | |
4d441513 | 1092 | static void asus_set_display(struct asus_laptop *asus, int value) |
78127b4a CC |
1093 | { |
1094 | /* no sanity check needed for now */ | |
d99b577c | 1095 | if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value)) |
5ad77dcf | 1096 | pr_warn("Error setting display\n"); |
78127b4a CC |
1097 | return; |
1098 | } | |
1099 | ||
78127b4a CC |
1100 | /* |
1101 | * Experimental support for display switching. As of now: 1 should activate | |
1102 | * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. | |
1103 | * Any combination (bitwise) of these will suffice. I never actually tested 4 | |
1104 | * displays hooked up simultaneously, so be warned. See the acpi4asus README | |
1105 | * for more info. | |
1106 | */ | |
1107 | static ssize_t store_disp(struct device *dev, struct device_attribute *attr, | |
1108 | const char *buf, size_t count) | |
1109 | { | |
9129d14d | 1110 | struct asus_laptop *asus = dev_get_drvdata(dev); |
78127b4a CC |
1111 | int rv, value; |
1112 | ||
1113 | rv = parse_arg(buf, count, &value); | |
1114 | if (rv > 0) | |
4d441513 | 1115 | asus_set_display(asus, value); |
78127b4a CC |
1116 | return rv; |
1117 | } | |
1118 | ||
8b857353 CC |
1119 | /* |
1120 | * Light Sens | |
1121 | */ | |
4d441513 | 1122 | static void asus_als_switch(struct asus_laptop *asus, int value) |
8b857353 | 1123 | { |
33989ba6 AR |
1124 | int ret; |
1125 | ||
1126 | if (asus->is_pega_lucid) { | |
1127 | ret = asus_pega_lucid_set(asus, PEGA_ALS, value); | |
1128 | if (!ret) | |
1129 | ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value); | |
1130 | } else { | |
1131 | ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value); | |
1132 | } | |
1133 | if (ret) | |
1134 | pr_warning("Error setting light sensor switch\n"); | |
1135 | ||
50a90c4d | 1136 | asus->light_switch = value; |
8b857353 CC |
1137 | } |
1138 | ||
1139 | static ssize_t show_lssw(struct device *dev, | |
1140 | struct device_attribute *attr, char *buf) | |
1141 | { | |
9129d14d CC |
1142 | struct asus_laptop *asus = dev_get_drvdata(dev); |
1143 | ||
50a90c4d | 1144 | return sprintf(buf, "%d\n", asus->light_switch); |
8b857353 CC |
1145 | } |
1146 | ||
1147 | static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, | |
1148 | const char *buf, size_t count) | |
1149 | { | |
9129d14d | 1150 | struct asus_laptop *asus = dev_get_drvdata(dev); |
8b857353 CC |
1151 | int rv, value; |
1152 | ||
1153 | rv = parse_arg(buf, count, &value); | |
1154 | if (rv > 0) | |
4d441513 | 1155 | asus_als_switch(asus, value ? 1 : 0); |
8b857353 CC |
1156 | |
1157 | return rv; | |
1158 | } | |
1159 | ||
4d441513 | 1160 | static void asus_als_level(struct asus_laptop *asus, int value) |
8b857353 | 1161 | { |
d99b577c | 1162 | if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value)) |
5ad77dcf | 1163 | pr_warn("Error setting light sensor level\n"); |
50a90c4d | 1164 | asus->light_level = value; |
8b857353 CC |
1165 | } |
1166 | ||
1167 | static ssize_t show_lslvl(struct device *dev, | |
1168 | struct device_attribute *attr, char *buf) | |
1169 | { | |
9129d14d CC |
1170 | struct asus_laptop *asus = dev_get_drvdata(dev); |
1171 | ||
50a90c4d | 1172 | return sprintf(buf, "%d\n", asus->light_level); |
8b857353 CC |
1173 | } |
1174 | ||
1175 | static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, | |
1176 | const char *buf, size_t count) | |
1177 | { | |
9129d14d | 1178 | struct asus_laptop *asus = dev_get_drvdata(dev); |
8b857353 CC |
1179 | int rv, value; |
1180 | ||
1181 | rv = parse_arg(buf, count, &value); | |
1182 | if (rv > 0) { | |
1183 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; | |
1184 | /* 0 <= value <= 15 */ | |
4d441513 | 1185 | asus_als_level(asus, value); |
8b857353 CC |
1186 | } |
1187 | ||
1188 | return rv; | |
1189 | } | |
1190 | ||
33989ba6 AR |
1191 | static int pega_int_read(struct asus_laptop *asus, int arg, int *result) |
1192 | { | |
1193 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
1194 | int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg, | |
1195 | &buffer); | |
1196 | if (!err) { | |
1197 | union acpi_object *obj = buffer.pointer; | |
1198 | if (obj && obj->type == ACPI_TYPE_INTEGER) | |
1199 | *result = obj->integer.value; | |
1200 | else | |
1201 | err = -EIO; | |
1202 | } | |
1203 | return err; | |
1204 | } | |
1205 | ||
1206 | static ssize_t show_lsvalue(struct device *dev, | |
1207 | struct device_attribute *attr, char *buf) | |
1208 | { | |
1209 | struct asus_laptop *asus = dev_get_drvdata(dev); | |
1210 | int err, hi, lo; | |
1211 | ||
1212 | err = pega_int_read(asus, PEGA_READ_ALS_H, &hi); | |
1213 | if (!err) | |
1214 | err = pega_int_read(asus, PEGA_READ_ALS_L, &lo); | |
1215 | if (!err) | |
1216 | return sprintf(buf, "%d\n", 10 * hi + lo); | |
1217 | return err; | |
1218 | } | |
1219 | ||
e539c2f6 CC |
1220 | /* |
1221 | * GPS | |
1222 | */ | |
6358bf2c CC |
1223 | static int asus_gps_status(struct asus_laptop *asus) |
1224 | { | |
1225 | unsigned long long status; | |
1226 | acpi_status rv = AE_OK; | |
1227 | ||
d99b577c CC |
1228 | rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS, |
1229 | NULL, &status); | |
6358bf2c | 1230 | if (ACPI_FAILURE(rv)) { |
5ad77dcf | 1231 | pr_warn("Error reading GPS status\n"); |
6358bf2c CC |
1232 | return -ENODEV; |
1233 | } | |
1234 | return !!status; | |
1235 | } | |
1236 | ||
1237 | static int asus_gps_switch(struct asus_laptop *asus, int status) | |
1238 | { | |
d99b577c | 1239 | const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF; |
6358bf2c | 1240 | |
d99b577c | 1241 | if (write_acpi_int(asus->handle, meth, 0x02)) |
6358bf2c CC |
1242 | return -ENODEV; |
1243 | return 0; | |
1244 | } | |
1245 | ||
e539c2f6 CC |
1246 | static ssize_t show_gps(struct device *dev, |
1247 | struct device_attribute *attr, char *buf) | |
1248 | { | |
9129d14d CC |
1249 | struct asus_laptop *asus = dev_get_drvdata(dev); |
1250 | ||
6358bf2c | 1251 | return sprintf(buf, "%d\n", asus_gps_status(asus)); |
e539c2f6 CC |
1252 | } |
1253 | ||
1254 | static ssize_t store_gps(struct device *dev, struct device_attribute *attr, | |
1255 | const char *buf, size_t count) | |
1256 | { | |
060cbce6 | 1257 | struct asus_laptop *asus = dev_get_drvdata(dev); |
6358bf2c CC |
1258 | int rv, value; |
1259 | int ret; | |
9129d14d | 1260 | |
6358bf2c CC |
1261 | rv = parse_arg(buf, count, &value); |
1262 | if (rv <= 0) | |
1263 | return -EINVAL; | |
1264 | ret = asus_gps_switch(asus, !!value); | |
1265 | if (ret) | |
1266 | return ret; | |
40969c7d | 1267 | rfkill_set_sw_state(asus->gps.rfkill, !value); |
6358bf2c | 1268 | return rv; |
e539c2f6 CC |
1269 | } |
1270 | ||
18e1311e CC |
1271 | /* |
1272 | * rfkill | |
1273 | */ | |
1274 | static int asus_gps_rfkill_set(void *data, bool blocked) | |
1275 | { | |
23f45c3a | 1276 | struct asus_laptop *asus = data; |
18e1311e | 1277 | |
23f45c3a | 1278 | return asus_gps_switch(asus, !blocked); |
18e1311e CC |
1279 | } |
1280 | ||
1281 | static const struct rfkill_ops asus_gps_rfkill_ops = { | |
1282 | .set_block = asus_gps_rfkill_set, | |
1283 | }; | |
1284 | ||
774b0678 CC |
1285 | static int asus_rfkill_set(void *data, bool blocked) |
1286 | { | |
1287 | struct asus_rfkill *rfk = data; | |
1288 | struct asus_laptop *asus = rfk->asus; | |
1289 | ||
1290 | if (rfk->control_id == WL_RSTS) | |
1291 | return asus_wlan_set(asus, !blocked); | |
1292 | else if (rfk->control_id == BT_RSTS) | |
1293 | return asus_bluetooth_set(asus, !blocked); | |
1294 | ||
1295 | return -EINVAL; | |
1296 | } | |
1297 | ||
1298 | static const struct rfkill_ops asus_rfkill_ops = { | |
1299 | .set_block = asus_rfkill_set, | |
1300 | }; | |
1301 | ||
40969c7d CC |
1302 | static void asus_rfkill_terminate(struct asus_rfkill *rfk) |
1303 | { | |
1304 | if (!rfk->rfkill) | |
1305 | return ; | |
1306 | ||
1307 | rfkill_unregister(rfk->rfkill); | |
1308 | rfkill_destroy(rfk->rfkill); | |
1309 | rfk->rfkill = NULL; | |
1310 | } | |
1311 | ||
18e1311e CC |
1312 | static void asus_rfkill_exit(struct asus_laptop *asus) |
1313 | { | |
40969c7d CC |
1314 | asus_rfkill_terminate(&asus->wwan); |
1315 | asus_rfkill_terminate(&asus->bluetooth); | |
1316 | asus_rfkill_terminate(&asus->wlan); | |
1317 | asus_rfkill_terminate(&asus->gps); | |
18e1311e CC |
1318 | } |
1319 | ||
774b0678 CC |
1320 | static int asus_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk, |
1321 | const char *name, int control_id, int type, | |
1322 | const struct rfkill_ops *ops) | |
18e1311e CC |
1323 | { |
1324 | int result; | |
1325 | ||
774b0678 CC |
1326 | rfk->control_id = control_id; |
1327 | rfk->asus = asus; | |
1328 | rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev, | |
1329 | type, ops, rfk); | |
1330 | if (!rfk->rfkill) | |
18e1311e CC |
1331 | return -EINVAL; |
1332 | ||
774b0678 | 1333 | result = rfkill_register(rfk->rfkill); |
18e1311e | 1334 | if (result) { |
774b0678 CC |
1335 | rfkill_destroy(rfk->rfkill); |
1336 | rfk->rfkill = NULL; | |
18e1311e CC |
1337 | } |
1338 | ||
1339 | return result; | |
1340 | } | |
1341 | ||
774b0678 CC |
1342 | static int asus_rfkill_init(struct asus_laptop *asus) |
1343 | { | |
1344 | int result = 0; | |
1345 | ||
1346 | if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) && | |
1347 | !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) && | |
1348 | !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) | |
1349 | result = asus_rfkill_setup(asus, &asus->gps, "asus-gps", | |
1350 | -1, RFKILL_TYPE_GPS, | |
1351 | &asus_gps_rfkill_ops); | |
1352 | if (result) | |
1353 | goto exit; | |
1354 | ||
1355 | ||
1356 | if (asus->wled_type == TYPE_RFKILL) | |
1357 | result = asus_rfkill_setup(asus, &asus->wlan, "asus-wlan", | |
1358 | WL_RSTS, RFKILL_TYPE_WLAN, | |
1359 | &asus_rfkill_ops); | |
1360 | if (result) | |
1361 | goto exit; | |
1362 | ||
1363 | if (asus->bled_type == TYPE_RFKILL) | |
1364 | result = asus_rfkill_setup(asus, &asus->bluetooth, | |
1365 | "asus-bluetooth", BT_RSTS, | |
1366 | RFKILL_TYPE_BLUETOOTH, | |
1367 | &asus_rfkill_ops); | |
1368 | if (result) | |
1369 | goto exit; | |
1370 | ||
1371 | exit: | |
1372 | if (result) | |
1373 | asus_rfkill_exit(asus); | |
1374 | ||
1375 | return result; | |
1376 | } | |
1377 | ||
14908399 AA |
1378 | static int pega_rfkill_set(void *data, bool blocked) |
1379 | { | |
40969c7d | 1380 | struct asus_rfkill *rfk = data; |
14908399 | 1381 | |
40969c7d | 1382 | int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked); |
14908399 AA |
1383 | return ret; |
1384 | } | |
1385 | ||
1386 | static const struct rfkill_ops pega_rfkill_ops = { | |
1387 | .set_block = pega_rfkill_set, | |
1388 | }; | |
1389 | ||
40969c7d CC |
1390 | static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk, |
1391 | const char *name, int controlid, int rfkill_type) | |
14908399 | 1392 | { |
774b0678 CC |
1393 | return asus_rfkill_setup(asus, rfk, name, controlid, rfkill_type, |
1394 | &pega_rfkill_ops); | |
14908399 AA |
1395 | } |
1396 | ||
1397 | static int pega_rfkill_init(struct asus_laptop *asus) | |
1398 | { | |
1399 | int ret = 0; | |
1400 | ||
1401 | if(!asus->is_pega_lucid) | |
1402 | return -ENODEV; | |
1403 | ||
40969c7d CC |
1404 | ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan", |
1405 | PEGA_WLAN, RFKILL_TYPE_WLAN); | |
14908399 | 1406 | if(ret) |
40969c7d CC |
1407 | goto exit; |
1408 | ||
1409 | ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt", | |
1410 | PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH); | |
14908399 | 1411 | if(ret) |
40969c7d | 1412 | goto exit; |
14908399 | 1413 | |
40969c7d CC |
1414 | ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan", |
1415 | PEGA_WWAN, RFKILL_TYPE_WWAN); | |
1416 | ||
1417 | exit: | |
1418 | if (ret) | |
1419 | asus_rfkill_exit(asus); | |
14908399 AA |
1420 | |
1421 | return ret; | |
1422 | } | |
1423 | ||
034ce90a | 1424 | /* |
be4ee82d | 1425 | * Input device (i.e. hotkeys) |
034ce90a | 1426 | */ |
be4ee82d CC |
1427 | static void asus_input_notify(struct asus_laptop *asus, int event) |
1428 | { | |
e0ac9133 CC |
1429 | if (!asus->inputdev) |
1430 | return ; | |
1431 | if (!sparse_keymap_report_event(asus->inputdev, event, 1, true)) | |
1432 | pr_info("Unknown key %x pressed\n", event); | |
be4ee82d CC |
1433 | } |
1434 | ||
1435 | static int asus_input_init(struct asus_laptop *asus) | |
1436 | { | |
66a71dd1 CC |
1437 | struct input_dev *input; |
1438 | int error; | |
be4ee82d | 1439 | |
66a71dd1 CC |
1440 | input = input_allocate_device(); |
1441 | if (!input) { | |
40969c7d | 1442 | pr_warn("Unable to allocate input device\n"); |
45036ae1 | 1443 | return -ENOMEM; |
be4ee82d | 1444 | } |
66a71dd1 CC |
1445 | input->name = "Asus Laptop extra buttons"; |
1446 | input->phys = ASUS_LAPTOP_FILE "/input0"; | |
1447 | input->id.bustype = BUS_HOST; | |
1448 | input->dev.parent = &asus->platform_device->dev; | |
66a71dd1 CC |
1449 | |
1450 | error = sparse_keymap_setup(input, asus_keymap, NULL); | |
1451 | if (error) { | |
1452 | pr_err("Unable to setup input device keymap\n"); | |
45036ae1 | 1453 | goto err_free_dev; |
be4ee82d | 1454 | } |
66a71dd1 CC |
1455 | error = input_register_device(input); |
1456 | if (error) { | |
40969c7d | 1457 | pr_warn("Unable to register input device\n"); |
45036ae1 | 1458 | goto err_free_keymap; |
be4ee82d | 1459 | } |
66a71dd1 CC |
1460 | |
1461 | asus->inputdev = input; | |
1462 | return 0; | |
1463 | ||
45036ae1 | 1464 | err_free_keymap: |
66a71dd1 | 1465 | sparse_keymap_free(input); |
45036ae1 | 1466 | err_free_dev: |
66a71dd1 CC |
1467 | input_free_device(input); |
1468 | return error; | |
be4ee82d CC |
1469 | } |
1470 | ||
1471 | static void asus_input_exit(struct asus_laptop *asus) | |
1472 | { | |
66a71dd1 CC |
1473 | if (asus->inputdev) { |
1474 | sparse_keymap_free(asus->inputdev); | |
be4ee82d | 1475 | input_unregister_device(asus->inputdev); |
66a71dd1 | 1476 | } |
71e687dc | 1477 | asus->inputdev = NULL; |
be4ee82d CC |
1478 | } |
1479 | ||
1480 | /* | |
1481 | * ACPI driver | |
1482 | */ | |
600ad520 | 1483 | static void asus_acpi_notify(struct acpi_device *device, u32 event) |
85091b71 | 1484 | { |
9129d14d | 1485 | struct asus_laptop *asus = acpi_driver_data(device); |
6050c8dd | 1486 | u16 count; |
034ce90a | 1487 | |
619d8b11 | 1488 | /* TODO Find a better way to handle events count. */ |
50a90c4d CC |
1489 | count = asus->event_count[event % 128]++; |
1490 | acpi_bus_generate_proc_event(asus->device, event, count); | |
1491 | acpi_bus_generate_netlink_event(asus->device->pnp.device_class, | |
1492 | dev_name(&asus->device->dev), event, | |
6050c8dd | 1493 | count); |
85091b71 | 1494 | |
a539df5e CC |
1495 | /* Brightness events are special */ |
1496 | if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) { | |
1497 | ||
1498 | /* Ignore them completely if the acpi video driver is used */ | |
1499 | if (asus->backlight_device != NULL) { | |
1500 | /* Update the backlight device. */ | |
1501 | asus_backlight_notify(asus); | |
1502 | } | |
1503 | return ; | |
1504 | } | |
b93f8281 AA |
1505 | |
1506 | /* Accelerometer "coarse orientation change" event */ | |
1507 | if (asus->pega_accel_poll && event == 0xEA) { | |
1508 | kobject_uevent(&asus->pega_accel_poll->input->dev.kobj, | |
1509 | KOBJ_CHANGE); | |
1510 | return ; | |
1511 | } | |
1512 | ||
be4ee82d | 1513 | asus_input_notify(asus, event); |
85091b71 CC |
1514 | } |
1515 | ||
2a1fd64c CC |
1516 | static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL); |
1517 | static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan); | |
ac9b1e5b DT |
1518 | static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, |
1519 | show_bluetooth, store_bluetooth); | |
ba1ff5be CC |
1520 | static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax); |
1521 | static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan); | |
3b81cf9d | 1522 | static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp); |
2a1fd64c | 1523 | static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd); |
33989ba6 | 1524 | static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL); |
2a1fd64c CC |
1525 | static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl); |
1526 | static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw); | |
1527 | static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps); | |
1528 | ||
ac9b1e5b DT |
1529 | static struct attribute *asus_attributes[] = { |
1530 | &dev_attr_infos.attr, | |
1531 | &dev_attr_wlan.attr, | |
1532 | &dev_attr_bluetooth.attr, | |
ba1ff5be CC |
1533 | &dev_attr_wimax.attr, |
1534 | &dev_attr_wwan.attr, | |
ac9b1e5b DT |
1535 | &dev_attr_display.attr, |
1536 | &dev_attr_ledd.attr, | |
33989ba6 | 1537 | &dev_attr_ls_value.attr, |
ac9b1e5b DT |
1538 | &dev_attr_ls_level.attr, |
1539 | &dev_attr_ls_switch.attr, | |
1540 | &dev_attr_gps.attr, | |
1541 | NULL | |
1542 | }; | |
2a1fd64c | 1543 | |
587a1f16 | 1544 | static umode_t asus_sysfs_is_visible(struct kobject *kobj, |
ac9b1e5b DT |
1545 | struct attribute *attr, |
1546 | int idx) | |
2a1fd64c | 1547 | { |
ac9b1e5b DT |
1548 | struct device *dev = container_of(kobj, struct device, kobj); |
1549 | struct platform_device *pdev = to_platform_device(dev); | |
1550 | struct asus_laptop *asus = platform_get_drvdata(pdev); | |
1551 | acpi_handle handle = asus->handle; | |
1552 | bool supported; | |
1553 | ||
33989ba6 AR |
1554 | if (asus->is_pega_lucid) { |
1555 | /* no ls_level interface on the Lucid */ | |
1556 | if (attr == &dev_attr_ls_switch.attr) | |
1557 | supported = true; | |
1558 | else if (attr == &dev_attr_ls_level.attr) | |
1559 | supported = false; | |
1560 | else | |
1561 | goto normal; | |
1562 | ||
1563 | return supported; | |
1564 | } | |
1565 | ||
1566 | normal: | |
ac9b1e5b DT |
1567 | if (attr == &dev_attr_wlan.attr) { |
1568 | supported = !acpi_check_handle(handle, METHOD_WLAN, NULL); | |
1569 | ||
1570 | } else if (attr == &dev_attr_bluetooth.attr) { | |
1571 | supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL); | |
1572 | ||
1573 | } else if (attr == &dev_attr_display.attr) { | |
1574 | supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL); | |
1575 | ||
ba1ff5be CC |
1576 | } else if (attr == &dev_attr_wimax.attr) { |
1577 | supported = | |
1578 | !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL); | |
1579 | ||
1580 | } else if (attr == &dev_attr_wwan.attr) { | |
1581 | supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL); | |
1582 | ||
ac9b1e5b DT |
1583 | } else if (attr == &dev_attr_ledd.attr) { |
1584 | supported = !acpi_check_handle(handle, METHOD_LEDD, NULL); | |
1585 | ||
1586 | } else if (attr == &dev_attr_ls_switch.attr || | |
1587 | attr == &dev_attr_ls_level.attr) { | |
1588 | supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) && | |
33989ba6 AR |
1589 | !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL); |
1590 | } else if (attr == &dev_attr_ls_value.attr) { | |
1591 | supported = asus->is_pega_lucid; | |
ac9b1e5b DT |
1592 | } else if (attr == &dev_attr_gps.attr) { |
1593 | supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) && | |
1594 | !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) && | |
1595 | !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL); | |
1596 | } else { | |
1597 | supported = true; | |
2a1fd64c CC |
1598 | } |
1599 | ||
ac9b1e5b DT |
1600 | return supported ? attr->mode : 0; |
1601 | } | |
2a1fd64c | 1602 | |
2a1fd64c | 1603 | |
ac9b1e5b DT |
1604 | static const struct attribute_group asus_attr_group = { |
1605 | .is_visible = asus_sysfs_is_visible, | |
1606 | .attrs = asus_attributes, | |
1607 | }; | |
85091b71 | 1608 | |
9129d14d | 1609 | static int asus_platform_init(struct asus_laptop *asus) |
600ad520 | 1610 | { |
71e687dc | 1611 | int result; |
600ad520 | 1612 | |
50a90c4d CC |
1613 | asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1); |
1614 | if (!asus->platform_device) | |
600ad520 | 1615 | return -ENOMEM; |
9129d14d | 1616 | platform_set_drvdata(asus->platform_device, asus); |
600ad520 | 1617 | |
71e687dc CC |
1618 | result = platform_device_add(asus->platform_device); |
1619 | if (result) | |
600ad520 CC |
1620 | goto fail_platform_device; |
1621 | ||
ac9b1e5b DT |
1622 | result = sysfs_create_group(&asus->platform_device->dev.kobj, |
1623 | &asus_attr_group); | |
71e687dc | 1624 | if (result) |
600ad520 | 1625 | goto fail_sysfs; |
ac9b1e5b | 1626 | |
600ad520 CC |
1627 | return 0; |
1628 | ||
1629 | fail_sysfs: | |
50a90c4d | 1630 | platform_device_del(asus->platform_device); |
600ad520 | 1631 | fail_platform_device: |
50a90c4d | 1632 | platform_device_put(asus->platform_device); |
71e687dc | 1633 | return result; |
600ad520 CC |
1634 | } |
1635 | ||
9129d14d | 1636 | static void asus_platform_exit(struct asus_laptop *asus) |
600ad520 | 1637 | { |
ac9b1e5b | 1638 | sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group); |
50a90c4d | 1639 | platform_device_unregister(asus->platform_device); |
600ad520 CC |
1640 | } |
1641 | ||
1642 | static struct platform_driver platform_driver = { | |
8def05fa | 1643 | .driver = { |
9129d14d CC |
1644 | .name = ASUS_LAPTOP_FILE, |
1645 | .owner = THIS_MODULE, | |
b23910c2 | 1646 | }, |
85091b71 CC |
1647 | }; |
1648 | ||
85091b71 | 1649 | /* |
50a90c4d CC |
1650 | * This function is used to initialize the context with right values. In this |
1651 | * method, we can make all the detection we want, and modify the asus_laptop | |
1652 | * struct | |
85091b71 | 1653 | */ |
7c247645 | 1654 | static int asus_laptop_get_info(struct asus_laptop *asus) |
85091b71 CC |
1655 | { |
1656 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
85091b71 | 1657 | union acpi_object *model = NULL; |
27663c58 | 1658 | unsigned long long bsts_result, hwrs_result; |
85091b71 CC |
1659 | char *string = NULL; |
1660 | acpi_status status; | |
1661 | ||
1662 | /* | |
1663 | * Get DSDT headers early enough to allow for differentiating between | |
1664 | * models, but late enough to allow acpi_bus_register_driver() to fail | |
1665 | * before doing anything ACPI-specific. Should we encounter a machine, | |
1666 | * which needs special handling (i.e. its hotkey device has a different | |
7c247645 | 1667 | * HID), this bit will be moved. |
85091b71 | 1668 | */ |
7c247645 | 1669 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info); |
85091b71 | 1670 | if (ACPI_FAILURE(status)) |
5ad77dcf | 1671 | pr_warn("Couldn't get the DSDT table header\n"); |
85091b71 CC |
1672 | |
1673 | /* We have to write 0 on init this far for all ASUS models */ | |
50a90c4d | 1674 | if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) { |
2fcc23da | 1675 | pr_err("Hotkey initialization failed\n"); |
85091b71 CC |
1676 | return -ENODEV; |
1677 | } | |
1678 | ||
1679 | /* This needs to be called for some laptops to init properly */ | |
9a816850 | 1680 | status = |
50a90c4d | 1681 | acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result); |
9a816850 | 1682 | if (ACPI_FAILURE(status)) |
5ad77dcf | 1683 | pr_warn("Error calling BSTS\n"); |
85091b71 | 1684 | else if (bsts_result) |
2fcc23da | 1685 | pr_notice("BSTS called, 0x%02x returned\n", |
9a816850 | 1686 | (uint) bsts_result); |
85091b71 | 1687 | |
185e5af9 | 1688 | /* This too ... */ |
e5593bf1 CC |
1689 | if (write_acpi_int(asus->handle, "CWAP", wapf)) |
1690 | pr_err("Error calling CWAP(%d)\n", wapf); | |
85091b71 CC |
1691 | /* |
1692 | * Try to match the object returned by INIT to the specific model. | |
1693 | * Handle every possible object (or the lack of thereof) the DSDT | |
1694 | * writers might throw at us. When in trouble, we pass NULL to | |
1695 | * asus_model_match() and try something completely different. | |
1696 | */ | |
1697 | if (buffer.pointer) { | |
1698 | model = buffer.pointer; | |
1699 | switch (model->type) { | |
1700 | case ACPI_TYPE_STRING: | |
1701 | string = model->string.pointer; | |
1702 | break; | |
1703 | case ACPI_TYPE_BUFFER: | |
1704 | string = model->buffer.pointer; | |
1705 | break; | |
1706 | default: | |
1707 | string = ""; | |
1708 | break; | |
1709 | } | |
1710 | } | |
50a90c4d | 1711 | asus->name = kstrdup(string, GFP_KERNEL); |
d8eca110 AL |
1712 | if (!asus->name) { |
1713 | kfree(buffer.pointer); | |
85091b71 | 1714 | return -ENOMEM; |
d8eca110 | 1715 | } |
85091b71 | 1716 | |
8def05fa | 1717 | if (*string) |
2fcc23da | 1718 | pr_notice(" %s model detected\n", string); |
85091b71 | 1719 | |
4564de17 CC |
1720 | /* |
1721 | * The HWRS method return informations about the hardware. | |
ba1ff5be CC |
1722 | * 0x80 bit is for WLAN, 0x100 for Bluetooth, |
1723 | * 0x40 for WWAN, 0x10 for WIMAX. | |
4564de17 | 1724 | * The significance of others is yet to be found. |
4564de17 | 1725 | */ |
9a816850 | 1726 | status = |
50a90c4d | 1727 | acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result); |
d99b577c CC |
1728 | if (!ACPI_FAILURE(status)) |
1729 | pr_notice(" HRWS returned %x", (int)hwrs_result); | |
4564de17 | 1730 | |
d99b577c | 1731 | if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL)) |
aa9df930 | 1732 | asus->have_rsts = true; |
4564de17 | 1733 | |
85091b71 CC |
1734 | kfree(model); |
1735 | ||
1736 | return AE_OK; | |
1737 | } | |
1738 | ||
9129d14d | 1739 | static int __devinit asus_acpi_init(struct asus_laptop *asus) |
85091b71 | 1740 | { |
600ad520 | 1741 | int result = 0; |
85091b71 | 1742 | |
50a90c4d | 1743 | result = acpi_bus_get_status(asus->device); |
600ad520 | 1744 | if (result) |
85091b71 | 1745 | return result; |
50a90c4d | 1746 | if (!asus->device->status.present) { |
600ad520 | 1747 | pr_err("Hotkey device not present, aborting\n"); |
85091b71 CC |
1748 | return -ENODEV; |
1749 | } | |
1750 | ||
7c247645 | 1751 | result = asus_laptop_get_info(asus); |
034ce90a | 1752 | if (result) |
600ad520 | 1753 | return result; |
034ce90a | 1754 | |
774b0678 CC |
1755 | if (!strcmp(bled_type, "led")) |
1756 | asus->bled_type = TYPE_LED; | |
1757 | else if (!strcmp(bled_type, "rfkill")) | |
1758 | asus->bled_type = TYPE_RFKILL; | |
1759 | ||
1760 | if (!strcmp(wled_type, "led")) | |
1761 | asus->wled_type = TYPE_LED; | |
1762 | else if (!strcmp(wled_type, "rfkill")) | |
1763 | asus->wled_type = TYPE_RFKILL; | |
1764 | ||
be4ee82d | 1765 | if (bluetooth_status >= 0) |
e5593bf1 CC |
1766 | asus_bluetooth_set(asus, !!bluetooth_status); |
1767 | ||
d0930a2d CC |
1768 | if (wlan_status >= 0) |
1769 | asus_wlan_set(asus, !!wlan_status); | |
85091b71 | 1770 | |
ba1ff5be CC |
1771 | if (wimax_status >= 0) |
1772 | asus_wimax_set(asus, !!wimax_status); | |
1773 | ||
1774 | if (wwan_status >= 0) | |
1775 | asus_wwan_set(asus, !!wwan_status); | |
1776 | ||
600ad520 | 1777 | /* Keyboard Backlight is on by default */ |
d99b577c | 1778 | if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL)) |
4d441513 | 1779 | asus_kled_set(asus, 1); |
600ad520 CC |
1780 | |
1781 | /* LED display is off by default */ | |
50a90c4d | 1782 | asus->ledd_status = 0xFFF; |
600ad520 CC |
1783 | |
1784 | /* Set initial values of light sensor and level */ | |
abec04db | 1785 | asus->light_switch = !!als_status; |
be4ee82d | 1786 | asus->light_level = 5; /* level 5 for sensor sensitivity */ |
600ad520 | 1787 | |
33989ba6 AR |
1788 | if (asus->is_pega_lucid) { |
1789 | asus_als_switch(asus, asus->light_switch); | |
1790 | } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) && | |
1791 | !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) { | |
4d441513 | 1792 | asus_als_switch(asus, asus->light_switch); |
4d441513 | 1793 | asus_als_level(asus, asus->light_level); |
d99b577c | 1794 | } |
600ad520 | 1795 | |
600ad520 CC |
1796 | return result; |
1797 | } | |
1798 | ||
af96f877 CC |
1799 | static void __devinit asus_dmi_check(void) |
1800 | { | |
1801 | const char *model; | |
1802 | ||
1803 | model = dmi_get_system_info(DMI_PRODUCT_NAME); | |
1804 | if (!model) | |
1805 | return; | |
1806 | ||
1807 | /* On L1400B WLED control the sound card, don't mess with it ... */ | |
1808 | if (strncmp(model, "L1400B", 6) == 0) { | |
1809 | wlan_status = -1; | |
1810 | } | |
1811 | } | |
1812 | ||
71e687dc CC |
1813 | static bool asus_device_present; |
1814 | ||
600ad520 CC |
1815 | static int __devinit asus_acpi_add(struct acpi_device *device) |
1816 | { | |
9129d14d | 1817 | struct asus_laptop *asus; |
600ad520 CC |
1818 | int result; |
1819 | ||
1820 | pr_notice("Asus Laptop Support version %s\n", | |
1821 | ASUS_LAPTOP_VERSION); | |
50a90c4d CC |
1822 | asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL); |
1823 | if (!asus) | |
600ad520 | 1824 | return -ENOMEM; |
50a90c4d CC |
1825 | asus->handle = device->handle; |
1826 | strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME); | |
1827 | strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS); | |
1828 | device->driver_data = asus; | |
1829 | asus->device = device; | |
600ad520 | 1830 | |
af96f877 CC |
1831 | asus_dmi_check(); |
1832 | ||
9129d14d | 1833 | result = asus_acpi_init(asus); |
8def05fa | 1834 | if (result) |
600ad520 | 1835 | goto fail_platform; |
85091b71 | 1836 | |
600ad520 | 1837 | /* |
8819de7f AR |
1838 | * Need platform type detection first, then the platform |
1839 | * device. It is used as a parent for the sub-devices below. | |
600ad520 | 1840 | */ |
8819de7f | 1841 | asus->is_pega_lucid = asus_check_pega_lucid(asus); |
9129d14d | 1842 | result = asus_platform_init(asus); |
116bf2e0 | 1843 | if (result) |
600ad520 | 1844 | goto fail_platform; |
116bf2e0 CC |
1845 | |
1846 | if (!acpi_video_backlight_support()) { | |
9129d14d | 1847 | result = asus_backlight_init(asus); |
116bf2e0 CC |
1848 | if (result) |
1849 | goto fail_backlight; | |
1850 | } else | |
600ad520 | 1851 | pr_info("Backlight controlled by ACPI video driver\n"); |
116bf2e0 | 1852 | |
9129d14d | 1853 | result = asus_input_init(asus); |
600ad520 CC |
1854 | if (result) |
1855 | goto fail_input; | |
1856 | ||
9129d14d | 1857 | result = asus_led_init(asus); |
600ad520 CC |
1858 | if (result) |
1859 | goto fail_led; | |
1860 | ||
18e1311e CC |
1861 | result = asus_rfkill_init(asus); |
1862 | if (result) | |
1863 | goto fail_rfkill; | |
1864 | ||
b23910c2 AR |
1865 | result = pega_accel_init(asus); |
1866 | if (result && result != -ENODEV) | |
1867 | goto fail_pega_accel; | |
1868 | ||
14908399 AA |
1869 | result = pega_rfkill_init(asus); |
1870 | if (result && result != -ENODEV) | |
1871 | goto fail_pega_rfkill; | |
1872 | ||
600ad520 | 1873 | asus_device_present = true; |
8def05fa | 1874 | return 0; |
85091b71 | 1875 | |
14908399 AA |
1876 | fail_pega_rfkill: |
1877 | pega_accel_exit(asus); | |
b23910c2 AR |
1878 | fail_pega_accel: |
1879 | asus_rfkill_exit(asus); | |
18e1311e CC |
1880 | fail_rfkill: |
1881 | asus_led_exit(asus); | |
600ad520 | 1882 | fail_led: |
9129d14d | 1883 | asus_input_exit(asus); |
600ad520 | 1884 | fail_input: |
9129d14d | 1885 | asus_backlight_exit(asus); |
116bf2e0 | 1886 | fail_backlight: |
9129d14d | 1887 | asus_platform_exit(asus); |
600ad520 | 1888 | fail_platform: |
50a90c4d CC |
1889 | kfree(asus->name); |
1890 | kfree(asus); | |
116bf2e0 | 1891 | |
600ad520 CC |
1892 | return result; |
1893 | } | |
116bf2e0 | 1894 | |
600ad520 CC |
1895 | static int asus_acpi_remove(struct acpi_device *device, int type) |
1896 | { | |
9129d14d CC |
1897 | struct asus_laptop *asus = acpi_driver_data(device); |
1898 | ||
1899 | asus_backlight_exit(asus); | |
18e1311e | 1900 | asus_rfkill_exit(asus); |
9129d14d CC |
1901 | asus_led_exit(asus); |
1902 | asus_input_exit(asus); | |
b23910c2 | 1903 | pega_accel_exit(asus); |
9129d14d | 1904 | asus_platform_exit(asus); |
600ad520 | 1905 | |
50a90c4d CC |
1906 | kfree(asus->name); |
1907 | kfree(asus); | |
600ad520 CC |
1908 | return 0; |
1909 | } | |
1910 | ||
1911 | static const struct acpi_device_id asus_device_ids[] = { | |
1912 | {"ATK0100", 0}, | |
1913 | {"ATK0101", 0}, | |
1914 | {"", 0}, | |
1915 | }; | |
1916 | MODULE_DEVICE_TABLE(acpi, asus_device_ids); | |
85091b71 | 1917 | |
600ad520 | 1918 | static struct acpi_driver asus_acpi_driver = { |
50a90c4d CC |
1919 | .name = ASUS_LAPTOP_NAME, |
1920 | .class = ASUS_LAPTOP_CLASS, | |
600ad520 CC |
1921 | .owner = THIS_MODULE, |
1922 | .ids = asus_device_ids, | |
1923 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, | |
1924 | .ops = { | |
1925 | .add = asus_acpi_add, | |
1926 | .remove = asus_acpi_remove, | |
1927 | .notify = asus_acpi_notify, | |
1928 | }, | |
1929 | }; | |
85091b71 | 1930 | |
600ad520 CC |
1931 | static int __init asus_laptop_init(void) |
1932 | { | |
1933 | int result; | |
85091b71 | 1934 | |
600ad520 CC |
1935 | result = platform_driver_register(&platform_driver); |
1936 | if (result < 0) | |
1937 | return result; | |
034ce90a | 1938 | |
600ad520 CC |
1939 | result = acpi_bus_register_driver(&asus_acpi_driver); |
1940 | if (result < 0) | |
1941 | goto fail_acpi_driver; | |
1942 | if (!asus_device_present) { | |
1943 | result = -ENODEV; | |
1944 | goto fail_no_device; | |
1945 | } | |
1946 | return 0; | |
85091b71 | 1947 | |
600ad520 CC |
1948 | fail_no_device: |
1949 | acpi_bus_unregister_driver(&asus_acpi_driver); | |
1950 | fail_acpi_driver: | |
1951 | platform_driver_unregister(&platform_driver); | |
85091b71 CC |
1952 | return result; |
1953 | } | |
1954 | ||
600ad520 CC |
1955 | static void __exit asus_laptop_exit(void) |
1956 | { | |
1957 | acpi_bus_unregister_driver(&asus_acpi_driver); | |
1958 | platform_driver_unregister(&platform_driver); | |
1959 | } | |
1960 | ||
85091b71 CC |
1961 | module_init(asus_laptop_init); |
1962 | module_exit(asus_laptop_exit); |