blob: 10b0a8663bb741b6b6bdb26eac9c40de0f3ad3e1 [file] [log] [blame]
Corentin Chary85091b72007-01-26 14:04:30 +01001/*
2 * asus-laptop.c - Asus Laptop Support
3 *
4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Corentin Chary8ec555c2007-03-11 10:28:03 +01006 * Copyright (C) 2006-2007 Corentin Chary
Andy Ross8819de72011-10-14 11:13:35 +02007 * Copyright (C) 2011 Wind River Systems
Corentin Chary85091b72007-01-26 14:04:30 +01008 *
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
Lucas De Marchic8440332011-03-17 17:18:22 -030033 * Thomas Tuttle - His first patch for led support was very helpful
Corentin Charye539c2f2007-05-06 14:47:06 +020034 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010035 */
36
Corentin Chary2fcc23d2009-06-19 14:52:03 +020037#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
Corentin Chary85091b72007-01-26 14:04:30 +010039#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>
Corentin Chary6b7091e2007-01-26 14:04:45 +010045#include <linux/backlight.h>
46#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010047#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010048#include <linux/platform_device.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010049#include <linux/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010050#include <linux/input.h>
Corentin Chary66a71dd2010-01-25 22:50:11 +010051#include <linux/input/sparse-keymap.h>
Andy Ross8819de72011-10-14 11:13:35 +020052#include <linux/input-polldev.h>
Corentin Chary18e13112010-01-25 23:29:24 +010053#include <linux/rfkill.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090054#include <linux/slab.h>
Corentin Charyaf96f872011-02-06 13:27:30 +010055#include <linux/dmi.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010056#include <acpi/acpi_drivers.h>
57#include <acpi/acpi_bus.h>
Corentin Chary85091b72007-01-26 14:04:30 +010058
Corentin Chary91687cc2009-11-28 10:32:34 +010059#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010060
Corentin Chary50a90c42009-11-30 21:55:12 +010061#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."
Corentin Chary85091b72007-01-26 14:04:30 +010066
Corentin Chary85091b72007-01-26 14:04:30 +010067MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010068MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010069MODULE_LICENSE("GPL");
70
Corentin Charybe966662009-08-29 10:28:29 +020071/*
72 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010073 * The significance of values is yet to be found, but
74 * most of the time:
Corentin Charyfddbfed2011-07-01 11:34:39 +020075 * Bit | Bluetooth | WLAN
76 * 0 | Hardware | Hardware
77 * 1 | Hardware | Software
78 * 4 | Software | Software
Corentin Chary185e5af2007-03-11 10:27:33 +010079 */
80static uint wapf = 1;
Axel Linc26d85c2010-07-20 15:19:55 -070081module_param(wapf, uint, 0444);
Corentin Chary185e5af2007-03-11 10:27:33 +010082MODULE_PARM_DESC(wapf, "WAPF value");
83
Dan Carpenter668f4a02010-04-06 13:44:29 +030084static int wlan_status = 1;
85static int bluetooth_status = 1;
Corentin Charyba1ff5b2010-11-14 17:40:12 +010086static int wimax_status = -1;
87static int wwan_status = -1;
Corentin Chary0e875f42010-01-10 20:49:26 +010088
Axel Linc26d85c2010-07-20 15:19:55 -070089module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010090MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010091 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
92 "default is 1");
93
Axel Linc26d85c2010-07-20 15:19:55 -070094module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010095MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
96 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
97 "default is 1");
98
Corentin Charyba1ff5b2010-11-14 17:40:12 +010099module_param(wimax_status, int, 0444);
100MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
101 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
102 "default is 1");
103
104module_param(wwan_status, int, 0444);
105MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
106 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
107 "default is 1");
108
Corentin Charybe4ee822009-12-06 16:27:09 +0100109/*
110 * Some events we use, same for all Asus
111 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100112#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
113#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100114#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100115#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100116#define ATKD_LCD_ON 0x33
117#define ATKD_LCD_OFF 0x34
118
119/*
120 * Known bits returned by \_SB.ATKD.HWRS
121 */
122#define WL_HWRS 0x80
123#define BT_HWRS 0x100
124
125/*
126 * Flags for hotk status
127 * WL_ON and BT_ON are also used for wireless_status()
128 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100129#define WL_RSTS 0x01 /* internal Wifi */
130#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100131#define WM_RSTS 0x08 /* internal wimax */
132#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100133
Corentin Charybe18cda2007-01-26 14:04:35 +0100134/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100135#define METHOD_MLED "MLED"
136#define METHOD_TLED "TLED"
137#define METHOD_RLED "RLED" /* W1JC */
138#define METHOD_PLED "PLED" /* A7J */
139#define METHOD_GLED "GLED" /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100140
Corentin Chary722ad972007-01-26 14:04:55 +0100141/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100142#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100143
Corentin Charybe966662009-08-29 10:28:29 +0200144/*
145 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100146 * WLED and BLED are not handled like other XLED, because in some dsdt
147 * they also control the WLAN/Bluetooth device.
148 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100149#define METHOD_WLAN "WLED"
150#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100151
152/* WWAN and WIMAX */
153#define METHOD_WWAN "GSMC"
154#define METHOD_WIMAX "WMXC"
155
Corentin Charyd99b5772010-01-22 21:20:57 +0100156#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100157
Corentin Chary6b7091e2007-01-26 14:04:45 +0100158/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100159#define METHOD_BRIGHTNESS_SET "SPLV"
160#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100161
Corentin Chary78127b42007-01-26 14:04:49 +0100162/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100163#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100164
Corentin Charyd99b5772010-01-22 21:20:57 +0100165#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
166#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100167
Corentin Charye539c2f2007-05-06 14:47:06 +0200168/* GPS */
169/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100170#define METHOD_GPS_ON "SDON"
171#define METHOD_GPS_OFF "SDOF"
172#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200173
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000174/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100175#define METHOD_KBD_LIGHT_SET "SLKB"
176#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000177
Andy Ross8819de72011-10-14 11:13:35 +0200178/* For Pegatron Lucid tablet */
179#define DEVICE_NAME_PEGA "Lucid"
Andy Ross33989ba2011-10-14 11:13:36 +0200180
Andy Ross8819de72011-10-14 11:13:35 +0200181#define METHOD_PEGA_ENABLE "ENPR"
182#define METHOD_PEGA_DISABLE "DAPR"
Andy Ross33989ba2011-10-14 11:13:36 +0200183#define PEGA_ALS 0x04
184#define PEGA_ALS_POWER 0x05
185
Andy Ross8819de72011-10-14 11:13:35 +0200186#define METHOD_PEGA_READ "RDLN"
Andy Ross33989ba2011-10-14 11:13:36 +0200187#define PEGA_READ_ALS_H 0x02
188#define PEGA_READ_ALS_L 0x03
Andy Ross8819de72011-10-14 11:13:35 +0200189
Corentin Chary85091b72007-01-26 14:04:30 +0100190/*
Corentin Chary9129d142009-12-01 22:39:41 +0100191 * Define a specific led structure to keep the main structure clean
192 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100193struct asus_led {
194 int wk;
195 struct work_struct work;
196 struct led_classdev led;
197 struct asus_laptop *asus;
198 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100199};
200
201/*
Corentin Chary85091b72007-01-26 14:04:30 +0100202 * This is the main structure, we can use it to store anything interesting
203 * about the hotk device
204 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100205struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200206 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100207
Corentin Chary7c247642009-11-30 22:13:54 +0100208 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100209 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100210 struct acpi_device *device; /* the device we are in */
211 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100212
Corentin Chary7c247642009-11-30 22:13:54 +0100213 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100214 struct key_entry *keymap;
215
Corentin Charyaee0afb2010-01-26 21:01:34 +0100216 struct asus_led mled;
217 struct asus_led tled;
218 struct asus_led rled;
219 struct asus_led pled;
220 struct asus_led gled;
221 struct asus_led kled;
222 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100223
Corentin Charyaa9df932010-01-13 21:49:10 +0100224 int wireless_status;
225 bool have_rsts;
Andy Ross8819de72011-10-14 11:13:35 +0200226 bool is_pega_lucid;
Corentin Charyaa9df932010-01-13 21:49:10 +0100227
Corentin Chary18e13112010-01-25 23:29:24 +0100228 struct rfkill *gps_rfkill;
229
Corentin Charybe966662009-08-29 10:28:29 +0200230 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200231 u32 ledd_status; /* status of the LED display */
232 u8 light_level; /* light sensor level */
233 u8 light_switch; /* light sensor switch value */
234 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100235};
236
Corentin Chary9129d142009-12-01 22:39:41 +0100237static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100238 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100239 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
240 {KE_KEY, 0x05, { KEY_WLAN } },
241 {KE_KEY, 0x08, { KEY_F13 } },
242 {KE_KEY, 0x17, { KEY_ZOOM } },
243 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100244 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100245 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
246 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
247 {KE_KEY, 0x32, { KEY_MUTE } },
248 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
249 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
250 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
251 {KE_KEY, 0x41, { KEY_NEXTSONG } },
252 {KE_KEY, 0x43, { KEY_STOPCD } },
253 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
254 {KE_KEY, 0x4c, { KEY_MEDIA } },
255 {KE_KEY, 0x50, { KEY_EMAIL } },
256 {KE_KEY, 0x51, { KEY_WWW } },
257 {KE_KEY, 0x55, { KEY_CALC } },
258 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
259 {KE_KEY, 0x5D, { KEY_WLAN } },
260 {KE_KEY, 0x5E, { KEY_WLAN } },
261 {KE_KEY, 0x5F, { KEY_WLAN } },
262 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
263 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
264 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
265 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
266 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d72010-01-17 17:37:19 +0100267 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
268 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100269 {KE_KEY, 0x82, { KEY_CAMERA } },
270 {KE_KEY, 0x88, { KEY_WLAN } },
271 {KE_KEY, 0x8A, { KEY_PROG1 } },
272 {KE_KEY, 0x95, { KEY_MEDIA } },
273 {KE_KEY, 0x99, { KEY_PHONE } },
274 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
275 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200276 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100277 {KE_END, 0},
278};
279
Corentin Chary66a71dd2010-01-25 22:50:11 +0100280
Corentin Chary85091b72007-01-26 14:04:30 +0100281/*
282 * This function evaluates an ACPI method, given an int as parameter, the
283 * method is searched within the scope of the handle, can be NULL. The output
284 * of the method is written is output, which can also be NULL
285 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100286 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100287 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100288static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
289 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100290{
Corentin Charybe966662009-08-29 10:28:29 +0200291 struct acpi_object_list params; /* list of input parameters (an int) */
292 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100293 acpi_status status;
294
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100295 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700296 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100297
Corentin Chary85091b72007-01-26 14:04:30 +0100298 params.count = 1;
299 params.pointer = &in_obj;
300 in_obj.type = ACPI_TYPE_INTEGER;
301 in_obj.integer.value = val;
302
303 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100304 if (status == AE_OK)
305 return 0;
306 else
307 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100308}
309
Corentin Charyd8c67322009-11-28 10:27:51 +0100310static int write_acpi_int(acpi_handle handle, const char *method, int val)
311{
312 return write_acpi_int_ret(handle, method, val, NULL);
313}
314
Corentin Charyd99b5772010-01-22 21:20:57 +0100315static int acpi_check_handle(acpi_handle handle, const char *method,
316 acpi_handle *ret)
317{
318 acpi_status status;
319
320 if (method == NULL)
321 return -ENODEV;
322
323 if (ret)
324 status = acpi_get_handle(handle, (char *)method,
325 ret);
326 else {
327 acpi_handle dummy;
328
329 status = acpi_get_handle(handle, (char *)method,
330 &dummy);
331 }
332
333 if (status != AE_OK) {
334 if (ret)
Joe Perches5ad77dc2011-03-29 15:21:35 -0700335 pr_warn("Error finding %s\n", method);
Corentin Charyd99b5772010-01-22 21:20:57 +0100336 return -ENODEV;
337 }
338 return 0;
339}
340
Andy Ross8819de72011-10-14 11:13:35 +0200341static bool asus_check_pega_lucid(struct asus_laptop *asus)
342{
343 return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
344 !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
345 !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
346 !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
347}
348
Andy Ross33989ba2011-10-14 11:13:36 +0200349static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
350{
351 char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
352 return write_acpi_int(asus->handle, method, unit);
353}
354
Corentin Chary17e78f62010-01-13 22:21:33 +0100355/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100356static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100357 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100358{
Corentin Charyd99b5772010-01-22 21:20:57 +0100359 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100360 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100361 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100362 value = !value + 1;
363 else
364 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100365
Corentin Charye5593bf2010-01-17 17:20:11 +0100366 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100367}
368
Corentin Charybe4ee822009-12-06 16:27:09 +0100369/*
370 * LEDs
371 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100372/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100373static void asus_led_cdev_set(struct led_classdev *led_cdev,
374 enum led_brightness value)
375{
376 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
377 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100378
Corentin Charyaee0afb2010-01-26 21:01:34 +0100379 led->wk = !!value;
380 queue_work(asus->led_workqueue, &led->work);
381}
382
383static void asus_led_cdev_update(struct work_struct *work)
384{
385 struct asus_led *led = container_of(work, struct asus_led, work);
386 struct asus_laptop *asus = led->asus;
387
388 asus_led_set(asus, led->method, led->wk);
389}
390
391static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
392{
393 return led_cdev->brightness;
394}
Corentin Charybe18cda2007-01-26 14:04:35 +0100395
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000396/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100397 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000398 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100399static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000400{
401 unsigned long long kblv;
402 struct acpi_object_list params;
403 union acpi_object in_obj;
404 acpi_status rv;
405
406 params.count = 1;
407 params.pointer = &in_obj;
408 in_obj.type = ACPI_TYPE_INTEGER;
409 in_obj.integer.value = 2;
410
Corentin Charyd99b5772010-01-22 21:20:57 +0100411 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
412 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000413 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700414 pr_warn("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100415 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000416 }
417 return kblv;
418}
419
Corentin Chary4d441512010-01-13 22:26:24 +0100420static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000421{
422 if (kblv > 0)
423 kblv = (1 << 7) | (kblv & 0x7F);
424 else
425 kblv = 0;
426
Corentin Charyd99b5772010-01-22 21:20:57 +0100427 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700428 pr_warn("Keyboard LED display write failed\n");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000429 return -EINVAL;
430 }
431 return 0;
432}
433
Corentin Charyaee0afb2010-01-26 21:01:34 +0100434static void asus_kled_cdev_set(struct led_classdev *led_cdev,
435 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000436{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100437 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
438 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100439
Corentin Chary060cbce2010-01-28 10:52:40 +0100440 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100441 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000442}
443
Corentin Charyaee0afb2010-01-26 21:01:34 +0100444static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000445{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100446 struct asus_led *led = container_of(work, struct asus_led, work);
447 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100448
Corentin Charyaee0afb2010-01-26 21:01:34 +0100449 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000450}
451
Corentin Charyaee0afb2010-01-26 21:01:34 +0100452static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000453{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100454 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
455 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100456
457 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000458}
459
Corentin Charybe4ee822009-12-06 16:27:09 +0100460static void asus_led_exit(struct asus_laptop *asus)
461{
Axel Lin8fcf71a2011-08-08 17:17:18 +0800462 if (!IS_ERR_OR_NULL(asus->mled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100463 led_classdev_unregister(&asus->mled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800464 if (!IS_ERR_OR_NULL(asus->tled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100465 led_classdev_unregister(&asus->tled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800466 if (!IS_ERR_OR_NULL(asus->pled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100467 led_classdev_unregister(&asus->pled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800468 if (!IS_ERR_OR_NULL(asus->rled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100469 led_classdev_unregister(&asus->rled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800470 if (!IS_ERR_OR_NULL(asus->gled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100471 led_classdev_unregister(&asus->gled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800472 if (!IS_ERR_OR_NULL(asus->kled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100473 led_classdev_unregister(&asus->kled.led);
474 if (asus->led_workqueue) {
475 destroy_workqueue(asus->led_workqueue);
476 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100477 }
478}
479
480/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100481static int asus_led_register(struct asus_laptop *asus,
482 struct asus_led *led,
483 const char *name, const char *method)
484{
485 struct led_classdev *led_cdev = &led->led;
486
487 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100488 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100489
490 led->asus = asus;
491 led->method = method;
492
493 INIT_WORK(&led->work, asus_led_cdev_update);
494 led_cdev->name = name;
495 led_cdev->brightness_set = asus_led_cdev_set;
496 led_cdev->brightness_get = asus_led_cdev_get;
497 led_cdev->max_brightness = 1;
498 return led_classdev_register(&asus->platform_device->dev, led_cdev);
499}
Corentin Charybe4ee822009-12-06 16:27:09 +0100500
501static int asus_led_init(struct asus_laptop *asus)
502{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100503 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100504
505 /*
506 * Functions that actually update the LED's are called from a
507 * workqueue. By doing this as separate work rather than when the LED
508 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
509 * potentially bad time, such as a timer interrupt.
510 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100511 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
512 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100513 return -ENOMEM;
514
Corentin Charyaee0afb2010-01-26 21:01:34 +0100515 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
516 if (r)
517 goto error;
518 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
519 if (r)
520 goto error;
521 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
522 if (r)
523 goto error;
524 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
525 if (r)
526 goto error;
527 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
528 if (r)
529 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100530 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100531 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
532 struct asus_led *led = &asus->kled;
533 struct led_classdev *cdev = &led->led;
534
535 led->asus = asus;
536
537 INIT_WORK(&led->work, asus_kled_cdev_update);
538 cdev->name = "asus::kbd_backlight";
539 cdev->brightness_set = asus_kled_cdev_set;
540 cdev->brightness_get = asus_kled_cdev_get;
541 cdev->max_brightness = 3;
542 r = led_classdev_register(&asus->platform_device->dev, cdev);
543 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100544error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100545 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100546 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100547 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100548}
549
550/*
551 * Backlight device
552 */
Corentin Chary4d441512010-01-13 22:26:24 +0100553static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100554{
Corentin Charyd99b5772010-01-22 21:20:57 +0100555 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400556 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100557 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100558
Corentin Charyd99b5772010-01-22 21:20:57 +0100559 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
560 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100561 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700562 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100563
564 return value;
565}
566
Corentin Chary4d441512010-01-13 22:26:24 +0100567static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100568{
Corentin Charyd99b5772010-01-22 21:20:57 +0100569 struct asus_laptop *asus = bl_get_data(bd);
570
571 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700572 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100573 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100574 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100575 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100576}
577
578static int update_bl_status(struct backlight_device *bd)
579{
Richard Purdie599a52d2007-02-10 23:07:48 +0000580 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100581
Corentin Chary3b81cf92011-02-06 13:27:31 +0100582 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100583}
584
Lionel Debrouxacc24722010-11-16 14:14:02 +0100585static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100586 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100587 .update_status = update_bl_status,
588};
589
Corentin Charya539df52010-01-25 22:53:21 +0100590static int asus_backlight_notify(struct asus_laptop *asus)
591{
592 struct backlight_device *bd = asus->backlight_device;
593 int old = bd->props.brightness;
594
595 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
596
597 return old;
598}
599
Corentin Charybe4ee822009-12-06 16:27:09 +0100600static int asus_backlight_init(struct asus_laptop *asus)
601{
602 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500603 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100604
Corentin Chary71e687d2010-08-24 09:30:44 +0200605 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100606 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200607 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500608
Corentin Chary71e687d2010-08-24 09:30:44 +0200609 memset(&props, 0, sizeof(struct backlight_properties));
610 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700611 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100612
Corentin Chary71e687d2010-08-24 09:30:44 +0200613 bd = backlight_device_register(ASUS_LAPTOP_FILE,
614 &asus->platform_device->dev, asus,
615 &asusbl_ops, &props);
616 if (IS_ERR(bd)) {
617 pr_err("Could not register asus backlight device\n");
618 asus->backlight_device = NULL;
619 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100620 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200621
622 asus->backlight_device = bd;
623 bd->props.brightness = asus_read_brightness(bd);
624 bd->props.power = FB_BLANK_UNBLANK;
625 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100626 return 0;
627}
628
629static void asus_backlight_exit(struct asus_laptop *asus)
630{
631 if (asus->backlight_device)
632 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100633 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100634}
635
Corentin Chary85091b72007-01-26 14:04:30 +0100636/*
637 * Platform device handlers
638 */
639
640/*
641 * We write our info in page, we begin at offset off and cannot write more
642 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
643 * number of bytes written in page
644 */
645static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500646 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100647{
Corentin Chary9129d142009-12-01 22:39:41 +0100648 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100649 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400650 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200651 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100652 acpi_status rv = AE_OK;
653
Corentin Chary85091b72007-01-26 14:04:30 +0100654 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100655 * We use the easy way, we don't care of off and count,
656 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100657 */
658
Corentin Chary50a90c42009-11-30 21:55:12 +0100659 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
660 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100661 /*
662 * The SFUN method probably allows the original driver to get the list
663 * of features supported by a given model. For now, 0x0100 or 0x0800
664 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
665 * The significance of others is yet to be found.
666 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100667 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100668 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000669 len += sprintf(page + len, "SFUN value : %#x\n",
670 (uint) temp);
671 /*
672 * The HWRS method return informations about the hardware.
673 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
674 * The significance of others is yet to be found.
675 * If we don't find the method, we assume the device are present.
676 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100677 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000678 if (!ACPI_FAILURE(rv))
679 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100680 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100681 /*
682 * Another value for userspace: the ASYM method returns 0x02 for
683 * battery low and 0x04 for battery critical, its readings tend to be
684 * more accurate than those provided by _BST.
685 * Note: since not all the laptops provide this method, errors are
686 * silently ignored.
687 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100688 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100689 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000690 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100691 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100692 if (asus->dsdt_info) {
693 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100694 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100695 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100696 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100697 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100698 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100699 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100700 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100701 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100702 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100703 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100704 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100705 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100706 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100707 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100708 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
709 }
710
711 return len;
712}
713
714static int parse_arg(const char *buf, unsigned long count, int *val)
715{
716 if (!count)
717 return 0;
718 if (count > 31)
719 return -EINVAL;
720 if (sscanf(buf, "%i", val) != 1)
721 return -EINVAL;
722 return count;
723}
724
Corentin Chary17e78f62010-01-13 22:21:33 +0100725static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
726 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100727 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100728{
729 int rv, value;
730 int out = 0;
731
732 rv = parse_arg(buf, count, &value);
733 if (rv > 0)
734 out = value ? 1 : 0;
735
Corentin Charyd99b5772010-01-22 21:20:57 +0100736 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100737 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100738 return rv;
739}
740
741/*
Corentin Chary722ad972007-01-26 14:04:55 +0100742 * LEDD display
743 */
744static ssize_t show_ledd(struct device *dev,
745 struct device_attribute *attr, char *buf)
746{
Corentin Chary9129d142009-12-01 22:39:41 +0100747 struct asus_laptop *asus = dev_get_drvdata(dev);
748
Corentin Chary50a90c42009-11-30 21:55:12 +0100749 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100750}
751
752static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
753 const char *buf, size_t count)
754{
Corentin Chary9129d142009-12-01 22:39:41 +0100755 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100756 int rv, value;
757
758 rv = parse_arg(buf, count, &value);
759 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700760 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700761 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700762 return -ENODEV;
763 }
764 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100765 }
766 return rv;
767}
768
769/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100770 * Wireless
771 */
772static int asus_wireless_status(struct asus_laptop *asus, int mask)
773{
774 unsigned long long status;
775 acpi_status rv = AE_OK;
776
777 if (!asus->have_rsts)
778 return (asus->wireless_status & mask) ? 1 : 0;
779
Corentin Charyd99b5772010-01-22 21:20:57 +0100780 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
781 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100782 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700783 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100784 return -EINVAL;
785 }
786 return !!(status & mask);
787}
788
789/*
Corentin Chary4564de12007-01-26 14:04:40 +0100790 * WLAN
791 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100792static int asus_wlan_set(struct asus_laptop *asus, int status)
793{
794 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700795 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100796 return -EIO;
797 }
798 return 0;
799}
800
Corentin Chary4564de12007-01-26 14:04:40 +0100801static ssize_t show_wlan(struct device *dev,
802 struct device_attribute *attr, char *buf)
803{
Corentin Chary9129d142009-12-01 22:39:41 +0100804 struct asus_laptop *asus = dev_get_drvdata(dev);
805
Corentin Chary17e78f62010-01-13 22:21:33 +0100806 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100807}
808
809static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
810 const char *buf, size_t count)
811{
Corentin Chary9129d142009-12-01 22:39:41 +0100812 struct asus_laptop *asus = dev_get_drvdata(dev);
813
Corentin Charyd99b5772010-01-22 21:20:57 +0100814 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100815}
816
817/*
818 * Bluetooth
819 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100820static int asus_bluetooth_set(struct asus_laptop *asus, int status)
821{
822 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700823 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100824 return -EIO;
825 }
826 return 0;
827}
828
Corentin Chary4564de12007-01-26 14:04:40 +0100829static ssize_t show_bluetooth(struct device *dev,
830 struct device_attribute *attr, char *buf)
831{
Corentin Chary9129d142009-12-01 22:39:41 +0100832 struct asus_laptop *asus = dev_get_drvdata(dev);
833
Corentin Chary17e78f62010-01-13 22:21:33 +0100834 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100835}
836
Len Brown8def05f2007-01-30 01:46:43 -0500837static ssize_t store_bluetooth(struct device *dev,
838 struct device_attribute *attr, const char *buf,
839 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100840{
Corentin Chary9129d142009-12-01 22:39:41 +0100841 struct asus_laptop *asus = dev_get_drvdata(dev);
842
Corentin Charyd99b5772010-01-22 21:20:57 +0100843 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100844}
845
Corentin Chary78127b42007-01-26 14:04:49 +0100846/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100847 * Wimax
848 */
849static int asus_wimax_set(struct asus_laptop *asus, int status)
850{
851 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700852 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100853 return -EIO;
854 }
855 return 0;
856}
857
858static ssize_t show_wimax(struct device *dev,
859 struct device_attribute *attr, char *buf)
860{
861 struct asus_laptop *asus = dev_get_drvdata(dev);
862
863 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
864}
865
866static ssize_t store_wimax(struct device *dev,
867 struct device_attribute *attr, const char *buf,
868 size_t count)
869{
870 struct asus_laptop *asus = dev_get_drvdata(dev);
871
872 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
873}
874
875/*
876 * Wwan
877 */
878static int asus_wwan_set(struct asus_laptop *asus, int status)
879{
880 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700881 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100882 return -EIO;
883 }
884 return 0;
885}
886
887static ssize_t show_wwan(struct device *dev,
888 struct device_attribute *attr, char *buf)
889{
890 struct asus_laptop *asus = dev_get_drvdata(dev);
891
892 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
893}
894
895static ssize_t store_wwan(struct device *dev,
896 struct device_attribute *attr, const char *buf,
897 size_t count)
898{
899 struct asus_laptop *asus = dev_get_drvdata(dev);
900
901 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
902}
903
904/*
Corentin Chary78127b42007-01-26 14:04:49 +0100905 * Display
906 */
Corentin Chary4d441512010-01-13 22:26:24 +0100907static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +0100908{
909 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +0100910 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700911 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100912 return;
913}
914
Corentin Chary78127b42007-01-26 14:04:49 +0100915/*
916 * Experimental support for display switching. As of now: 1 should activate
917 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
918 * Any combination (bitwise) of these will suffice. I never actually tested 4
919 * displays hooked up simultaneously, so be warned. See the acpi4asus README
920 * for more info.
921 */
922static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
923 const char *buf, size_t count)
924{
Corentin Chary9129d142009-12-01 22:39:41 +0100925 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +0100926 int rv, value;
927
928 rv = parse_arg(buf, count, &value);
929 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +0100930 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +0100931 return rv;
932}
933
Corentin Chary8b857352007-01-26 14:04:58 +0100934/*
935 * Light Sens
936 */
Corentin Chary4d441512010-01-13 22:26:24 +0100937static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +0100938{
Andy Ross33989ba2011-10-14 11:13:36 +0200939 int ret;
940
941 if (asus->is_pega_lucid) {
942 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
943 if (!ret)
944 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
945 } else {
946 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
947 }
948 if (ret)
949 pr_warning("Error setting light sensor switch\n");
950
Corentin Chary50a90c42009-11-30 21:55:12 +0100951 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100952}
953
954static ssize_t show_lssw(struct device *dev,
955 struct device_attribute *attr, char *buf)
956{
Corentin Chary9129d142009-12-01 22:39:41 +0100957 struct asus_laptop *asus = dev_get_drvdata(dev);
958
Corentin Chary50a90c42009-11-30 21:55:12 +0100959 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +0100960}
961
962static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
963 const char *buf, size_t count)
964{
Corentin Chary9129d142009-12-01 22:39:41 +0100965 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +0100966 int rv, value;
967
968 rv = parse_arg(buf, count, &value);
969 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +0100970 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +0100971
972 return rv;
973}
974
Corentin Chary4d441512010-01-13 22:26:24 +0100975static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +0100976{
Corentin Charyd99b5772010-01-22 21:20:57 +0100977 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700978 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +0100979 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100980}
981
982static ssize_t show_lslvl(struct device *dev,
983 struct device_attribute *attr, char *buf)
984{
Corentin Chary9129d142009-12-01 22:39:41 +0100985 struct asus_laptop *asus = dev_get_drvdata(dev);
986
Corentin Chary50a90c42009-11-30 21:55:12 +0100987 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +0100988}
989
990static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
991 const char *buf, size_t count)
992{
Corentin Chary9129d142009-12-01 22:39:41 +0100993 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +0100994 int rv, value;
995
996 rv = parse_arg(buf, count, &value);
997 if (rv > 0) {
998 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
999 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001000 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001001 }
1002
1003 return rv;
1004}
1005
Andy Ross33989ba2011-10-14 11:13:36 +02001006static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1007{
1008 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1009 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1010 &buffer);
1011 if (!err) {
1012 union acpi_object *obj = buffer.pointer;
1013 if (obj && obj->type == ACPI_TYPE_INTEGER)
1014 *result = obj->integer.value;
1015 else
1016 err = -EIO;
1017 }
1018 return err;
1019}
1020
1021static ssize_t show_lsvalue(struct device *dev,
1022 struct device_attribute *attr, char *buf)
1023{
1024 struct asus_laptop *asus = dev_get_drvdata(dev);
1025 int err, hi, lo;
1026
1027 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1028 if (!err)
1029 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1030 if (!err)
1031 return sprintf(buf, "%d\n", 10 * hi + lo);
1032 return err;
1033}
1034
Corentin Charye539c2f2007-05-06 14:47:06 +02001035/*
1036 * GPS
1037 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001038static int asus_gps_status(struct asus_laptop *asus)
1039{
1040 unsigned long long status;
1041 acpi_status rv = AE_OK;
1042
Corentin Charyd99b5772010-01-22 21:20:57 +01001043 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1044 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001045 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001046 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001047 return -ENODEV;
1048 }
1049 return !!status;
1050}
1051
1052static int asus_gps_switch(struct asus_laptop *asus, int status)
1053{
Corentin Charyd99b5772010-01-22 21:20:57 +01001054 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001055
Corentin Charyd99b5772010-01-22 21:20:57 +01001056 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001057 return -ENODEV;
1058 return 0;
1059}
1060
Corentin Charye539c2f2007-05-06 14:47:06 +02001061static ssize_t show_gps(struct device *dev,
1062 struct device_attribute *attr, char *buf)
1063{
Corentin Chary9129d142009-12-01 22:39:41 +01001064 struct asus_laptop *asus = dev_get_drvdata(dev);
1065
Corentin Chary6358bf22010-01-13 21:55:44 +01001066 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001067}
1068
1069static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1070 const char *buf, size_t count)
1071{
Corentin Chary060cbce2010-01-28 10:52:40 +01001072 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001073 int rv, value;
1074 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001075
Corentin Chary6358bf22010-01-13 21:55:44 +01001076 rv = parse_arg(buf, count, &value);
1077 if (rv <= 0)
1078 return -EINVAL;
1079 ret = asus_gps_switch(asus, !!value);
1080 if (ret)
1081 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001082 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001083 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001084}
1085
Corentin Chary034ce902009-01-20 16:17:43 +01001086/*
Corentin Chary18e13112010-01-25 23:29:24 +01001087 * rfkill
1088 */
1089static int asus_gps_rfkill_set(void *data, bool blocked)
1090{
Corentin Chary23f45c32010-08-24 09:30:46 +02001091 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001092
Corentin Chary23f45c32010-08-24 09:30:46 +02001093 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001094}
1095
1096static const struct rfkill_ops asus_gps_rfkill_ops = {
1097 .set_block = asus_gps_rfkill_set,
1098};
1099
1100static void asus_rfkill_exit(struct asus_laptop *asus)
1101{
1102 if (asus->gps_rfkill) {
1103 rfkill_unregister(asus->gps_rfkill);
1104 rfkill_destroy(asus->gps_rfkill);
1105 asus->gps_rfkill = NULL;
1106 }
1107}
1108
1109static int asus_rfkill_init(struct asus_laptop *asus)
1110{
1111 int result;
1112
1113 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1114 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1115 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1116 return 0;
1117
1118 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1119 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001120 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001121 if (!asus->gps_rfkill)
1122 return -EINVAL;
1123
1124 result = rfkill_register(asus->gps_rfkill);
1125 if (result) {
1126 rfkill_destroy(asus->gps_rfkill);
1127 asus->gps_rfkill = NULL;
1128 }
1129
1130 return result;
1131}
1132
1133/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001134 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001135 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001136static void asus_input_notify(struct asus_laptop *asus, int event)
1137{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001138 if (asus->inputdev)
1139 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001140}
1141
1142static int asus_input_init(struct asus_laptop *asus)
1143{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001144 struct input_dev *input;
1145 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001146
Corentin Chary66a71dd2010-01-25 22:50:11 +01001147 input = input_allocate_device();
1148 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001149 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001150 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001151 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001152 input->name = "Asus Laptop extra buttons";
1153 input->phys = ASUS_LAPTOP_FILE "/input0";
1154 input->id.bustype = BUS_HOST;
1155 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001156
Corentin Chary66a71dd2010-01-25 22:50:11 +01001157 error = sparse_keymap_setup(input, asus_keymap, NULL);
1158 if (error) {
1159 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001160 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001161 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001162 error = input_register_device(input);
1163 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001164 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001165 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001166 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001167
1168 asus->inputdev = input;
1169 return 0;
1170
Axel Lin45036ae2010-07-05 15:29:00 +08001171err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001172 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001173err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001174 input_free_device(input);
1175 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001176}
1177
1178static void asus_input_exit(struct asus_laptop *asus)
1179{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001180 if (asus->inputdev) {
1181 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001182 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001183 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001184 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001185}
1186
1187/*
1188 * ACPI driver
1189 */
Corentin Chary600ad522009-11-30 21:42:42 +01001190static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001191{
Corentin Chary9129d142009-12-01 22:39:41 +01001192 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001193 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001194
Corentin Chary619d8b12009-11-28 10:35:37 +01001195 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001196 count = asus->event_count[event % 128]++;
1197 acpi_bus_generate_proc_event(asus->device, event, count);
1198 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1199 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001200 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001201
Corentin Charya539df52010-01-25 22:53:21 +01001202 /* Brightness events are special */
1203 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1204
1205 /* Ignore them completely if the acpi video driver is used */
1206 if (asus->backlight_device != NULL) {
1207 /* Update the backlight device. */
1208 asus_backlight_notify(asus);
1209 }
1210 return ;
1211 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001212 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001213}
1214
Corentin Chary2a1fd642010-01-26 21:02:23 +01001215static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1216static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001217static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1218 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001219static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1220static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001221static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001222static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001223static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001224static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1225static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1226static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1227
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001228static struct attribute *asus_attributes[] = {
1229 &dev_attr_infos.attr,
1230 &dev_attr_wlan.attr,
1231 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001232 &dev_attr_wimax.attr,
1233 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001234 &dev_attr_display.attr,
1235 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001236 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001237 &dev_attr_ls_level.attr,
1238 &dev_attr_ls_switch.attr,
1239 &dev_attr_gps.attr,
1240 NULL
1241};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001242
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001243static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1244 struct attribute *attr,
1245 int idx)
1246{
1247 struct device *dev = container_of(kobj, struct device, kobj);
1248 struct platform_device *pdev = to_platform_device(dev);
1249 struct asus_laptop *asus = platform_get_drvdata(pdev);
1250 acpi_handle handle = asus->handle;
1251 bool supported;
1252
Andy Ross33989ba2011-10-14 11:13:36 +02001253 if (asus->is_pega_lucid) {
1254 /* no ls_level interface on the Lucid */
1255 if (attr == &dev_attr_ls_switch.attr)
1256 supported = true;
1257 else if (attr == &dev_attr_ls_level.attr)
1258 supported = false;
1259 else
1260 goto normal;
1261
1262 return supported;
1263 }
1264
1265normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001266 if (attr == &dev_attr_wlan.attr) {
1267 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1268
1269 } else if (attr == &dev_attr_bluetooth.attr) {
1270 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1271
1272 } else if (attr == &dev_attr_display.attr) {
1273 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1274
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001275 } else if (attr == &dev_attr_wimax.attr) {
1276 supported =
1277 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1278
1279 } else if (attr == &dev_attr_wwan.attr) {
1280 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1281
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001282 } else if (attr == &dev_attr_ledd.attr) {
1283 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1284
1285 } else if (attr == &dev_attr_ls_switch.attr ||
1286 attr == &dev_attr_ls_level.attr) {
1287 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001288 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1289 } else if (attr == &dev_attr_ls_value.attr) {
1290 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001291 } else if (attr == &dev_attr_gps.attr) {
1292 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1293 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1294 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1295 } else {
1296 supported = true;
1297 }
1298
1299 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001300}
1301
Corentin Chary2a1fd642010-01-26 21:02:23 +01001302
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001303static const struct attribute_group asus_attr_group = {
1304 .is_visible = asus_sysfs_is_visible,
1305 .attrs = asus_attributes,
1306};
Corentin Chary85091b72007-01-26 14:04:30 +01001307
Corentin Chary9129d142009-12-01 22:39:41 +01001308static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001309{
Corentin Chary71e687d2010-08-24 09:30:44 +02001310 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001311
Corentin Chary50a90c42009-11-30 21:55:12 +01001312 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1313 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001314 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001315 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001316
Corentin Chary71e687d2010-08-24 09:30:44 +02001317 result = platform_device_add(asus->platform_device);
1318 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001319 goto fail_platform_device;
1320
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001321 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1322 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001323 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001324 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001325
Corentin Chary600ad522009-11-30 21:42:42 +01001326 return 0;
1327
1328fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001329 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001330fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001331 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001332 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001333}
1334
Corentin Chary9129d142009-12-01 22:39:41 +01001335static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001336{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001337 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001338 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001339}
1340
1341static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001342 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001343 .name = ASUS_LAPTOP_FILE,
1344 .owner = THIS_MODULE,
1345 }
Corentin Chary85091b72007-01-26 14:04:30 +01001346};
1347
Corentin Chary85091b72007-01-26 14:04:30 +01001348/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001349 * This function is used to initialize the context with right values. In this
1350 * method, we can make all the detection we want, and modify the asus_laptop
1351 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001352 */
Corentin Chary7c247642009-11-30 22:13:54 +01001353static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001354{
1355 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001356 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001357 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001358 char *string = NULL;
1359 acpi_status status;
1360
1361 /*
1362 * Get DSDT headers early enough to allow for differentiating between
1363 * models, but late enough to allow acpi_bus_register_driver() to fail
1364 * before doing anything ACPI-specific. Should we encounter a machine,
1365 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001366 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001367 */
Corentin Chary7c247642009-11-30 22:13:54 +01001368 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001369 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001370 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001371
1372 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001373 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001374 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001375 return -ENODEV;
1376 }
1377
1378 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001379 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001380 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001381 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001382 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001383 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001384 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001385 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001386
Corentin Chary185e5af2007-03-11 10:27:33 +01001387 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001388 if (write_acpi_int(asus->handle, "CWAP", wapf))
1389 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001390 /*
1391 * Try to match the object returned by INIT to the specific model.
1392 * Handle every possible object (or the lack of thereof) the DSDT
1393 * writers might throw at us. When in trouble, we pass NULL to
1394 * asus_model_match() and try something completely different.
1395 */
1396 if (buffer.pointer) {
1397 model = buffer.pointer;
1398 switch (model->type) {
1399 case ACPI_TYPE_STRING:
1400 string = model->string.pointer;
1401 break;
1402 case ACPI_TYPE_BUFFER:
1403 string = model->buffer.pointer;
1404 break;
1405 default:
1406 string = "";
1407 break;
1408 }
1409 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001410 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001411 if (!asus->name) {
1412 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001413 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001414 }
Corentin Chary85091b72007-01-26 14:04:30 +01001415
Len Brown8def05f2007-01-30 01:46:43 -05001416 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001417 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001418
Corentin Chary4564de12007-01-26 14:04:40 +01001419 /*
1420 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001421 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1422 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001423 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001424 */
Corentin Chary9a816852007-03-11 10:25:38 +01001425 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001426 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001427 if (!ACPI_FAILURE(status))
1428 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001429
Corentin Charyd99b5772010-01-22 21:20:57 +01001430 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001431 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001432
Corentin Chary85091b72007-01-26 14:04:30 +01001433 kfree(model);
1434
1435 return AE_OK;
1436}
1437
Corentin Chary9129d142009-12-01 22:39:41 +01001438static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001439{
1440 int result = 0;
1441
Corentin Chary50a90c42009-11-30 21:55:12 +01001442 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001443 if (result)
1444 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001445 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001446 pr_err("Hotkey device not present, aborting\n");
1447 return -ENODEV;
1448 }
1449
Corentin Chary7c247642009-11-30 22:13:54 +01001450 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001451 if (result)
1452 return result;
1453
Corentin Chary600ad522009-11-30 21:42:42 +01001454 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001455 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001456 asus_bluetooth_set(asus, !!bluetooth_status);
1457
Corentin Charyd0930a22010-01-17 17:21:13 +01001458 if (wlan_status >= 0)
1459 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001460
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001461 if (wimax_status >= 0)
1462 asus_wimax_set(asus, !!wimax_status);
1463
1464 if (wwan_status >= 0)
1465 asus_wwan_set(asus, !!wwan_status);
1466
Corentin Chary600ad522009-11-30 21:42:42 +01001467 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001468 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001469 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001470
1471 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001472 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001473
1474 /* Set initial values of light sensor and level */
Corentin Charybe4ee822009-12-06 16:27:09 +01001475 asus->light_switch = 0; /* Default to light sensor disabled */
1476 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001477
Andy Ross33989ba2011-10-14 11:13:36 +02001478 if (asus->is_pega_lucid) {
1479 asus_als_switch(asus, asus->light_switch);
1480 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1481 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001482 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001483 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001484 }
Corentin Chary600ad522009-11-30 21:42:42 +01001485
Corentin Chary600ad522009-11-30 21:42:42 +01001486 return result;
1487}
1488
Corentin Charyaf96f872011-02-06 13:27:30 +01001489static void __devinit asus_dmi_check(void)
1490{
1491 const char *model;
1492
1493 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1494 if (!model)
1495 return;
1496
1497 /* On L1400B WLED control the sound card, don't mess with it ... */
1498 if (strncmp(model, "L1400B", 6) == 0) {
1499 wlan_status = -1;
1500 }
1501}
1502
Corentin Chary71e687d2010-08-24 09:30:44 +02001503static bool asus_device_present;
1504
Corentin Chary600ad522009-11-30 21:42:42 +01001505static int __devinit asus_acpi_add(struct acpi_device *device)
1506{
Corentin Chary9129d142009-12-01 22:39:41 +01001507 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001508 int result;
1509
1510 pr_notice("Asus Laptop Support version %s\n",
1511 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001512 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1513 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001514 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001515 asus->handle = device->handle;
1516 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1517 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1518 device->driver_data = asus;
1519 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001520
Corentin Charyaf96f872011-02-06 13:27:30 +01001521 asus_dmi_check();
1522
Corentin Chary9129d142009-12-01 22:39:41 +01001523 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001524 if (result)
1525 goto fail_platform;
1526
1527 /*
Andy Ross8819de72011-10-14 11:13:35 +02001528 * Need platform type detection first, then the platform
1529 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001530 */
Andy Ross8819de72011-10-14 11:13:35 +02001531 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001532 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001533 if (result)
1534 goto fail_platform;
1535
1536 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001537 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001538 if (result)
1539 goto fail_backlight;
1540 } else
1541 pr_info("Backlight controlled by ACPI video driver\n");
1542
Corentin Chary9129d142009-12-01 22:39:41 +01001543 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001544 if (result)
1545 goto fail_input;
1546
Corentin Chary9129d142009-12-01 22:39:41 +01001547 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001548 if (result)
1549 goto fail_led;
1550
Corentin Chary18e13112010-01-25 23:29:24 +01001551 result = asus_rfkill_init(asus);
1552 if (result)
1553 goto fail_rfkill;
1554
Corentin Chary600ad522009-11-30 21:42:42 +01001555 asus_device_present = true;
1556 return 0;
1557
Corentin Chary18e13112010-01-25 23:29:24 +01001558fail_rfkill:
1559 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001560fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001561 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001562fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001563 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001564fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001565 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001566fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001567 kfree(asus->name);
1568 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001569
1570 return result;
1571}
1572
1573static int asus_acpi_remove(struct acpi_device *device, int type)
1574{
Corentin Chary9129d142009-12-01 22:39:41 +01001575 struct asus_laptop *asus = acpi_driver_data(device);
1576
1577 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001578 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001579 asus_led_exit(asus);
1580 asus_input_exit(asus);
1581 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001582
Corentin Chary50a90c42009-11-30 21:55:12 +01001583 kfree(asus->name);
1584 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001585 return 0;
1586}
1587
1588static const struct acpi_device_id asus_device_ids[] = {
1589 {"ATK0100", 0},
1590 {"ATK0101", 0},
1591 {"", 0},
1592};
1593MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1594
1595static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001596 .name = ASUS_LAPTOP_NAME,
1597 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001598 .owner = THIS_MODULE,
1599 .ids = asus_device_ids,
1600 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1601 .ops = {
1602 .add = asus_acpi_add,
1603 .remove = asus_acpi_remove,
1604 .notify = asus_acpi_notify,
1605 },
1606};
1607
Corentin Chary85091b72007-01-26 14:04:30 +01001608static int __init asus_laptop_init(void)
1609{
1610 int result;
1611
Corentin Chary600ad522009-11-30 21:42:42 +01001612 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001613 if (result < 0)
1614 return result;
1615
Corentin Chary600ad522009-11-30 21:42:42 +01001616 result = acpi_bus_register_driver(&asus_acpi_driver);
1617 if (result < 0)
1618 goto fail_acpi_driver;
1619 if (!asus_device_present) {
1620 result = -ENODEV;
1621 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001622 }
Len Brown8def05f2007-01-30 01:46:43 -05001623 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001624
Corentin Chary600ad522009-11-30 21:42:42 +01001625fail_no_device:
1626 acpi_bus_unregister_driver(&asus_acpi_driver);
1627fail_acpi_driver:
1628 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001629 return result;
1630}
1631
Corentin Chary600ad522009-11-30 21:42:42 +01001632static void __exit asus_laptop_exit(void)
1633{
1634 acpi_bus_unregister_driver(&asus_acpi_driver);
1635 platform_driver_unregister(&platform_driver);
1636}
1637
Corentin Chary85091b72007-01-26 14:04:30 +01001638module_init(asus_laptop_init);
1639module_exit(asus_laptop_exit);