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