asus-laptop: fix module description
[deliverable/linux.git] / drivers / platform / x86 / asus-laptop.c
CommitLineData
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 67MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
50a90c4d 68MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
85091b71
CC
69MODULE_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 */
80static uint wapf = 1;
c26d85cb 81module_param(wapf, uint, 0444);
185e5af9
CC
82MODULE_PARM_DESC(wapf, "WAPF value");
83
668f4a03
DC
84static int wlan_status = 1;
85static int bluetooth_status = 1;
ba1ff5be
CC
86static int wimax_status = -1;
87static int wwan_status = -1;
abec04db 88static int als_status;
0e875f49 89
c26d85cb 90module_param(wlan_status, int, 0444);
d0930a2d 91MODULE_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 95module_param(bluetooth_status, int, 0444);
0e875f49
CC
96MODULE_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
100module_param(wimax_status, int, 0444);
101MODULE_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
105module_param(wwan_status, int, 0444);
106MODULE_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
110module_param(als_status, int, 0444);
111MODULE_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
207struct 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 219struct 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 256static 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
307static 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, &params, output);
f8d1c94b
CC
323 if (status == AE_OK)
324 return 0;
325 else
326 return -1;
85091b71
CC
327}
328
d8c67323
CC
329static 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
334static 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
360static 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
368static 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
374static 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
394static 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
425static 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
434static 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
476exit:
477 input_free_polled_device(ipd);
478 return err;
479}
480
17e78f62 481/* Generic LED function */
aee0afb8 482static 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
499static 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
509static 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
517static 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 525static 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 &params, &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 546static 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
560static 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 570static 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 578static 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
586static 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
607static 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
627static 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 677error:
aee0afb8 678 if (r)
be4ee82d 679 asus_led_exit(asus);
aee0afb8 680 return r;
be4ee82d
CC
681}
682
683/*
684 * Backlight device
685 */
4d441513 686static 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 700static 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
711static 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 718static 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
723static 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
733static 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
762static 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 */
778static 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
847static 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
858static 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 */
877static 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
885static 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 */
905static 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
925static 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
934static 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
942static 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
953static 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
962static 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
970static 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 */
982static 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
991static 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
999static 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 */
1011static 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
1020static 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
1028static 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 1040static 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 */
1055static 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 1070static 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
1087static 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
1095static 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 1108static 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
1115static 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
1123static 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
1139static 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
1154static 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
1171static 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
1185static 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
1194static 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
1202static 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 */
1222static 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
1229static const struct rfkill_ops asus_gps_rfkill_ops = {
1230 .set_block = asus_gps_rfkill_set,
1231};
1232
1233static 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
1242static 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
1269static 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
1275static 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 1304err_free_keymap:
66a71dd1 1305 sparse_keymap_free(input);
45036ae1 1306err_free_dev:
66a71dd1
CC
1307 input_free_device(input);
1308 return error;
be4ee82d
CC
1309}
1310
1311static 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 1323static 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 }
be4ee82d 1345 asus_input_notify(asus, event);
85091b71
CC
1346}
1347
2a1fd64c
CC
1348static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1349static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
ac9b1e5b
DT
1350static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1351 show_bluetooth, store_bluetooth);
ba1ff5be
CC
1352static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1353static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
3b81cf9d 1354static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
2a1fd64c 1355static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
33989ba6 1356static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
2a1fd64c
CC
1357static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1358static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1359static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1360
ac9b1e5b
DT
1361static struct attribute *asus_attributes[] = {
1362 &dev_attr_infos.attr,
1363 &dev_attr_wlan.attr,
1364 &dev_attr_bluetooth.attr,
ba1ff5be
CC
1365 &dev_attr_wimax.attr,
1366 &dev_attr_wwan.attr,
ac9b1e5b
DT
1367 &dev_attr_display.attr,
1368 &dev_attr_ledd.attr,
33989ba6 1369 &dev_attr_ls_value.attr,
ac9b1e5b
DT
1370 &dev_attr_ls_level.attr,
1371 &dev_attr_ls_switch.attr,
1372 &dev_attr_gps.attr,
1373 NULL
1374};
2a1fd64c 1375
ac9b1e5b
DT
1376static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1377 struct attribute *attr,
1378 int idx)
2a1fd64c 1379{
ac9b1e5b
DT
1380 struct device *dev = container_of(kobj, struct device, kobj);
1381 struct platform_device *pdev = to_platform_device(dev);
1382 struct asus_laptop *asus = platform_get_drvdata(pdev);
1383 acpi_handle handle = asus->handle;
1384 bool supported;
1385
33989ba6
AR
1386 if (asus->is_pega_lucid) {
1387 /* no ls_level interface on the Lucid */
1388 if (attr == &dev_attr_ls_switch.attr)
1389 supported = true;
1390 else if (attr == &dev_attr_ls_level.attr)
1391 supported = false;
1392 else
1393 goto normal;
1394
1395 return supported;
1396 }
1397
1398normal:
ac9b1e5b
DT
1399 if (attr == &dev_attr_wlan.attr) {
1400 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1401
1402 } else if (attr == &dev_attr_bluetooth.attr) {
1403 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1404
1405 } else if (attr == &dev_attr_display.attr) {
1406 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1407
ba1ff5be
CC
1408 } else if (attr == &dev_attr_wimax.attr) {
1409 supported =
1410 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1411
1412 } else if (attr == &dev_attr_wwan.attr) {
1413 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1414
ac9b1e5b
DT
1415 } else if (attr == &dev_attr_ledd.attr) {
1416 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1417
1418 } else if (attr == &dev_attr_ls_switch.attr ||
1419 attr == &dev_attr_ls_level.attr) {
1420 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
33989ba6
AR
1421 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1422 } else if (attr == &dev_attr_ls_value.attr) {
1423 supported = asus->is_pega_lucid;
ac9b1e5b
DT
1424 } else if (attr == &dev_attr_gps.attr) {
1425 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1426 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1427 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1428 } else {
1429 supported = true;
2a1fd64c
CC
1430 }
1431
ac9b1e5b
DT
1432 return supported ? attr->mode : 0;
1433}
2a1fd64c 1434
2a1fd64c 1435
ac9b1e5b
DT
1436static const struct attribute_group asus_attr_group = {
1437 .is_visible = asus_sysfs_is_visible,
1438 .attrs = asus_attributes,
1439};
85091b71 1440
9129d14d 1441static int asus_platform_init(struct asus_laptop *asus)
600ad520 1442{
71e687dc 1443 int result;
600ad520 1444
50a90c4d
CC
1445 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1446 if (!asus->platform_device)
600ad520 1447 return -ENOMEM;
9129d14d 1448 platform_set_drvdata(asus->platform_device, asus);
600ad520 1449
71e687dc
CC
1450 result = platform_device_add(asus->platform_device);
1451 if (result)
600ad520
CC
1452 goto fail_platform_device;
1453
ac9b1e5b
DT
1454 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1455 &asus_attr_group);
71e687dc 1456 if (result)
600ad520 1457 goto fail_sysfs;
ac9b1e5b 1458
600ad520
CC
1459 return 0;
1460
1461fail_sysfs:
50a90c4d 1462 platform_device_del(asus->platform_device);
600ad520 1463fail_platform_device:
50a90c4d 1464 platform_device_put(asus->platform_device);
71e687dc 1465 return result;
600ad520
CC
1466}
1467
9129d14d 1468static void asus_platform_exit(struct asus_laptop *asus)
600ad520 1469{
ac9b1e5b 1470 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
50a90c4d 1471 platform_device_unregister(asus->platform_device);
600ad520
CC
1472}
1473
1474static struct platform_driver platform_driver = {
8def05fa 1475 .driver = {
9129d14d
CC
1476 .name = ASUS_LAPTOP_FILE,
1477 .owner = THIS_MODULE,
b23910c2 1478 },
85091b71
CC
1479};
1480
85091b71 1481/*
50a90c4d
CC
1482 * This function is used to initialize the context with right values. In this
1483 * method, we can make all the detection we want, and modify the asus_laptop
1484 * struct
85091b71 1485 */
7c247645 1486static int asus_laptop_get_info(struct asus_laptop *asus)
85091b71
CC
1487{
1488 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
85091b71 1489 union acpi_object *model = NULL;
27663c58 1490 unsigned long long bsts_result, hwrs_result;
85091b71
CC
1491 char *string = NULL;
1492 acpi_status status;
1493
1494 /*
1495 * Get DSDT headers early enough to allow for differentiating between
1496 * models, but late enough to allow acpi_bus_register_driver() to fail
1497 * before doing anything ACPI-specific. Should we encounter a machine,
1498 * which needs special handling (i.e. its hotkey device has a different
7c247645 1499 * HID), this bit will be moved.
85091b71 1500 */
7c247645 1501 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
85091b71 1502 if (ACPI_FAILURE(status))
5ad77dcf 1503 pr_warn("Couldn't get the DSDT table header\n");
85091b71
CC
1504
1505 /* We have to write 0 on init this far for all ASUS models */
50a90c4d 1506 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
2fcc23da 1507 pr_err("Hotkey initialization failed\n");
85091b71
CC
1508 return -ENODEV;
1509 }
1510
1511 /* This needs to be called for some laptops to init properly */
9a816850 1512 status =
50a90c4d 1513 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
9a816850 1514 if (ACPI_FAILURE(status))
5ad77dcf 1515 pr_warn("Error calling BSTS\n");
85091b71 1516 else if (bsts_result)
2fcc23da 1517 pr_notice("BSTS called, 0x%02x returned\n",
9a816850 1518 (uint) bsts_result);
85091b71 1519
185e5af9 1520 /* This too ... */
e5593bf1
CC
1521 if (write_acpi_int(asus->handle, "CWAP", wapf))
1522 pr_err("Error calling CWAP(%d)\n", wapf);
85091b71
CC
1523 /*
1524 * Try to match the object returned by INIT to the specific model.
1525 * Handle every possible object (or the lack of thereof) the DSDT
1526 * writers might throw at us. When in trouble, we pass NULL to
1527 * asus_model_match() and try something completely different.
1528 */
1529 if (buffer.pointer) {
1530 model = buffer.pointer;
1531 switch (model->type) {
1532 case ACPI_TYPE_STRING:
1533 string = model->string.pointer;
1534 break;
1535 case ACPI_TYPE_BUFFER:
1536 string = model->buffer.pointer;
1537 break;
1538 default:
1539 string = "";
1540 break;
1541 }
1542 }
50a90c4d 1543 asus->name = kstrdup(string, GFP_KERNEL);
d8eca110
AL
1544 if (!asus->name) {
1545 kfree(buffer.pointer);
85091b71 1546 return -ENOMEM;
d8eca110 1547 }
85091b71 1548
8def05fa 1549 if (*string)
2fcc23da 1550 pr_notice(" %s model detected\n", string);
85091b71 1551
4564de17
CC
1552 /*
1553 * The HWRS method return informations about the hardware.
ba1ff5be
CC
1554 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1555 * 0x40 for WWAN, 0x10 for WIMAX.
4564de17 1556 * The significance of others is yet to be found.
4564de17 1557 */
9a816850 1558 status =
50a90c4d 1559 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
d99b577c
CC
1560 if (!ACPI_FAILURE(status))
1561 pr_notice(" HRWS returned %x", (int)hwrs_result);
4564de17 1562
d99b577c 1563 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
aa9df930 1564 asus->have_rsts = true;
4564de17 1565
85091b71
CC
1566 kfree(model);
1567
1568 return AE_OK;
1569}
1570
9129d14d 1571static int __devinit asus_acpi_init(struct asus_laptop *asus)
85091b71 1572{
600ad520 1573 int result = 0;
85091b71 1574
50a90c4d 1575 result = acpi_bus_get_status(asus->device);
600ad520 1576 if (result)
85091b71 1577 return result;
50a90c4d 1578 if (!asus->device->status.present) {
600ad520 1579 pr_err("Hotkey device not present, aborting\n");
85091b71
CC
1580 return -ENODEV;
1581 }
1582
7c247645 1583 result = asus_laptop_get_info(asus);
034ce90a 1584 if (result)
600ad520 1585 return result;
034ce90a 1586
600ad520 1587 /* WLED and BLED are on by default */
be4ee82d 1588 if (bluetooth_status >= 0)
e5593bf1
CC
1589 asus_bluetooth_set(asus, !!bluetooth_status);
1590
d0930a2d
CC
1591 if (wlan_status >= 0)
1592 asus_wlan_set(asus, !!wlan_status);
85091b71 1593
ba1ff5be
CC
1594 if (wimax_status >= 0)
1595 asus_wimax_set(asus, !!wimax_status);
1596
1597 if (wwan_status >= 0)
1598 asus_wwan_set(asus, !!wwan_status);
1599
600ad520 1600 /* Keyboard Backlight is on by default */
d99b577c 1601 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
4d441513 1602 asus_kled_set(asus, 1);
600ad520
CC
1603
1604 /* LED display is off by default */
50a90c4d 1605 asus->ledd_status = 0xFFF;
600ad520
CC
1606
1607 /* Set initial values of light sensor and level */
abec04db 1608 asus->light_switch = !!als_status;
be4ee82d 1609 asus->light_level = 5; /* level 5 for sensor sensitivity */
600ad520 1610
33989ba6
AR
1611 if (asus->is_pega_lucid) {
1612 asus_als_switch(asus, asus->light_switch);
1613 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1614 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
4d441513 1615 asus_als_switch(asus, asus->light_switch);
4d441513 1616 asus_als_level(asus, asus->light_level);
d99b577c 1617 }
600ad520 1618
600ad520
CC
1619 return result;
1620}
1621
af96f877
CC
1622static void __devinit asus_dmi_check(void)
1623{
1624 const char *model;
1625
1626 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1627 if (!model)
1628 return;
1629
1630 /* On L1400B WLED control the sound card, don't mess with it ... */
1631 if (strncmp(model, "L1400B", 6) == 0) {
1632 wlan_status = -1;
1633 }
1634}
1635
71e687dc
CC
1636static bool asus_device_present;
1637
600ad520
CC
1638static int __devinit asus_acpi_add(struct acpi_device *device)
1639{
9129d14d 1640 struct asus_laptop *asus;
600ad520
CC
1641 int result;
1642
1643 pr_notice("Asus Laptop Support version %s\n",
1644 ASUS_LAPTOP_VERSION);
50a90c4d
CC
1645 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1646 if (!asus)
600ad520 1647 return -ENOMEM;
50a90c4d
CC
1648 asus->handle = device->handle;
1649 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1650 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1651 device->driver_data = asus;
1652 asus->device = device;
600ad520 1653
af96f877
CC
1654 asus_dmi_check();
1655
9129d14d 1656 result = asus_acpi_init(asus);
8def05fa 1657 if (result)
600ad520 1658 goto fail_platform;
85091b71 1659
600ad520 1660 /*
8819de7f
AR
1661 * Need platform type detection first, then the platform
1662 * device. It is used as a parent for the sub-devices below.
600ad520 1663 */
8819de7f 1664 asus->is_pega_lucid = asus_check_pega_lucid(asus);
9129d14d 1665 result = asus_platform_init(asus);
116bf2e0 1666 if (result)
600ad520 1667 goto fail_platform;
116bf2e0
CC
1668
1669 if (!acpi_video_backlight_support()) {
9129d14d 1670 result = asus_backlight_init(asus);
116bf2e0
CC
1671 if (result)
1672 goto fail_backlight;
1673 } else
600ad520 1674 pr_info("Backlight controlled by ACPI video driver\n");
116bf2e0 1675
9129d14d 1676 result = asus_input_init(asus);
600ad520
CC
1677 if (result)
1678 goto fail_input;
1679
9129d14d 1680 result = asus_led_init(asus);
600ad520
CC
1681 if (result)
1682 goto fail_led;
1683
18e1311e
CC
1684 result = asus_rfkill_init(asus);
1685 if (result)
1686 goto fail_rfkill;
1687
b23910c2
AR
1688 result = pega_accel_init(asus);
1689 if (result && result != -ENODEV)
1690 goto fail_pega_accel;
1691
600ad520 1692 asus_device_present = true;
8def05fa 1693 return 0;
85091b71 1694
b23910c2
AR
1695fail_pega_accel:
1696 asus_rfkill_exit(asus);
18e1311e
CC
1697fail_rfkill:
1698 asus_led_exit(asus);
600ad520 1699fail_led:
9129d14d 1700 asus_input_exit(asus);
600ad520 1701fail_input:
9129d14d 1702 asus_backlight_exit(asus);
116bf2e0 1703fail_backlight:
9129d14d 1704 asus_platform_exit(asus);
600ad520 1705fail_platform:
50a90c4d
CC
1706 kfree(asus->name);
1707 kfree(asus);
116bf2e0 1708
600ad520
CC
1709 return result;
1710}
116bf2e0 1711
600ad520
CC
1712static int asus_acpi_remove(struct acpi_device *device, int type)
1713{
9129d14d
CC
1714 struct asus_laptop *asus = acpi_driver_data(device);
1715
1716 asus_backlight_exit(asus);
18e1311e 1717 asus_rfkill_exit(asus);
9129d14d
CC
1718 asus_led_exit(asus);
1719 asus_input_exit(asus);
b23910c2 1720 pega_accel_exit(asus);
9129d14d 1721 asus_platform_exit(asus);
600ad520 1722
50a90c4d
CC
1723 kfree(asus->name);
1724 kfree(asus);
600ad520
CC
1725 return 0;
1726}
1727
1728static const struct acpi_device_id asus_device_ids[] = {
1729 {"ATK0100", 0},
1730 {"ATK0101", 0},
1731 {"", 0},
1732};
1733MODULE_DEVICE_TABLE(acpi, asus_device_ids);
85091b71 1734
600ad520 1735static struct acpi_driver asus_acpi_driver = {
50a90c4d
CC
1736 .name = ASUS_LAPTOP_NAME,
1737 .class = ASUS_LAPTOP_CLASS,
600ad520
CC
1738 .owner = THIS_MODULE,
1739 .ids = asus_device_ids,
1740 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1741 .ops = {
1742 .add = asus_acpi_add,
1743 .remove = asus_acpi_remove,
1744 .notify = asus_acpi_notify,
1745 },
1746};
85091b71 1747
600ad520
CC
1748static int __init asus_laptop_init(void)
1749{
1750 int result;
85091b71 1751
600ad520
CC
1752 result = platform_driver_register(&platform_driver);
1753 if (result < 0)
1754 return result;
034ce90a 1755
600ad520
CC
1756 result = acpi_bus_register_driver(&asus_acpi_driver);
1757 if (result < 0)
1758 goto fail_acpi_driver;
1759 if (!asus_device_present) {
1760 result = -ENODEV;
1761 goto fail_no_device;
1762 }
1763 return 0;
85091b71 1764
600ad520
CC
1765fail_no_device:
1766 acpi_bus_unregister_driver(&asus_acpi_driver);
1767fail_acpi_driver:
1768 platform_driver_unregister(&platform_driver);
85091b71
CC
1769 return result;
1770}
1771
600ad520
CC
1772static void __exit asus_laptop_exit(void)
1773{
1774 acpi_bus_unregister_driver(&asus_acpi_driver);
1775 platform_driver_unregister(&platform_driver);
1776}
1777
85091b71
CC
1778module_init(asus_laptop_init);
1779module_exit(asus_laptop_exit);
This page took 0.553697 seconds and 5 git commands to generate.