blob: 8327d06b6e8adfe0d50ef7e379379bc9b68d9ff0 [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;
Andy Rossabec04d2011-10-14 11:13:37 +020088static int als_status;
Corentin Chary0e875f42010-01-10 20:49:26 +010089
Axel Linc26d85c2010-07-20 15:19:55 -070090module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010091MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010092 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
93 "default is 1");
94
Axel Linc26d85c2010-07-20 15:19:55 -070095module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010096MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
97 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
98 "default is 1");
99
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100100module_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). "
103 "default is 1");
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). "
108 "default is 1");
109
Andy Rossabec04d2011-10-14 11:13:37 +0200110module_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
Corentin Charybe4ee822009-12-06 16:27:09 +0100115/*
116 * Some events we use, same for all Asus
117 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100118#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
119#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100120#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100121#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100122#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 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100135#define WL_RSTS 0x01 /* internal Wifi */
136#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100137#define WM_RSTS 0x08 /* internal wimax */
138#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100139
Corentin Charybe18cda2007-01-26 14:04:35 +0100140/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100141#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) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100146
Corentin Chary722ad972007-01-26 14:04:55 +0100147/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100148#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100149
Corentin Charybe966662009-08-29 10:28:29 +0200150/*
151 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100152 * WLED and BLED are not handled like other XLED, because in some dsdt
153 * they also control the WLAN/Bluetooth device.
154 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100155#define METHOD_WLAN "WLED"
156#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100157
158/* WWAN and WIMAX */
159#define METHOD_WWAN "GSMC"
160#define METHOD_WIMAX "WMXC"
161
Corentin Charyd99b5772010-01-22 21:20:57 +0100162#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100163
Corentin Chary6b7091e2007-01-26 14:04:45 +0100164/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100165#define METHOD_BRIGHTNESS_SET "SPLV"
166#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100167
Corentin Chary78127b42007-01-26 14:04:49 +0100168/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100169#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100170
Corentin Charyd99b5772010-01-22 21:20:57 +0100171#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
172#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100173
Corentin Charye539c2f2007-05-06 14:47:06 +0200174/* GPS */
175/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100176#define METHOD_GPS_ON "SDON"
177#define METHOD_GPS_OFF "SDOF"
178#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200179
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000180/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100181#define METHOD_KBD_LIGHT_SET "SLKB"
182#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000183
Andy Ross8819de72011-10-14 11:13:35 +0200184/* For Pegatron Lucid tablet */
185#define DEVICE_NAME_PEGA "Lucid"
Andy Ross33989ba2011-10-14 11:13:36 +0200186
Andy Ross8819de72011-10-14 11:13:35 +0200187#define METHOD_PEGA_ENABLE "ENPR"
188#define METHOD_PEGA_DISABLE "DAPR"
Andy Ross33989ba2011-10-14 11:13:36 +0200189#define PEGA_ALS 0x04
190#define PEGA_ALS_POWER 0x05
191
Andy Ross8819de72011-10-14 11:13:35 +0200192#define METHOD_PEGA_READ "RDLN"
Andy Ross33989ba2011-10-14 11:13:36 +0200193#define PEGA_READ_ALS_H 0x02
194#define PEGA_READ_ALS_L 0x03
Andy Ross8819de72011-10-14 11:13:35 +0200195
Corentin Chary85091b72007-01-26 14:04:30 +0100196/*
Corentin Chary9129d142009-12-01 22:39:41 +0100197 * Define a specific led structure to keep the main structure clean
198 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100199struct asus_led {
200 int wk;
201 struct work_struct work;
202 struct led_classdev led;
203 struct asus_laptop *asus;
204 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100205};
206
207/*
Corentin Chary85091b72007-01-26 14:04:30 +0100208 * This is the main structure, we can use it to store anything interesting
209 * about the hotk device
210 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100211struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200212 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100213
Corentin Chary7c247642009-11-30 22:13:54 +0100214 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100215 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100216 struct acpi_device *device; /* the device we are in */
217 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100218
Corentin Chary7c247642009-11-30 22:13:54 +0100219 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100220 struct key_entry *keymap;
221
Corentin Charyaee0afb2010-01-26 21:01:34 +0100222 struct asus_led mled;
223 struct asus_led tled;
224 struct asus_led rled;
225 struct asus_led pled;
226 struct asus_led gled;
227 struct asus_led kled;
228 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100229
Corentin Charyaa9df932010-01-13 21:49:10 +0100230 int wireless_status;
231 bool have_rsts;
Andy Ross8819de72011-10-14 11:13:35 +0200232 bool is_pega_lucid;
Corentin Charyaa9df932010-01-13 21:49:10 +0100233
Corentin Chary18e13112010-01-25 23:29:24 +0100234 struct rfkill *gps_rfkill;
235
Corentin Charybe966662009-08-29 10:28:29 +0200236 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200237 u32 ledd_status; /* status of the LED display */
238 u8 light_level; /* light sensor level */
239 u8 light_switch; /* light sensor switch value */
240 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100241};
242
Corentin Chary9129d142009-12-01 22:39:41 +0100243static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100244 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100245 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
246 {KE_KEY, 0x05, { KEY_WLAN } },
247 {KE_KEY, 0x08, { KEY_F13 } },
248 {KE_KEY, 0x17, { KEY_ZOOM } },
249 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100250 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100251 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
252 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
253 {KE_KEY, 0x32, { KEY_MUTE } },
254 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
255 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
256 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
257 {KE_KEY, 0x41, { KEY_NEXTSONG } },
258 {KE_KEY, 0x43, { KEY_STOPCD } },
259 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
260 {KE_KEY, 0x4c, { KEY_MEDIA } },
261 {KE_KEY, 0x50, { KEY_EMAIL } },
262 {KE_KEY, 0x51, { KEY_WWW } },
263 {KE_KEY, 0x55, { KEY_CALC } },
264 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
265 {KE_KEY, 0x5D, { KEY_WLAN } },
266 {KE_KEY, 0x5E, { KEY_WLAN } },
267 {KE_KEY, 0x5F, { KEY_WLAN } },
268 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
269 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
270 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
271 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
272 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d712010-01-17 17:37:19 +0100273 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
274 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100275 {KE_KEY, 0x82, { KEY_CAMERA } },
276 {KE_KEY, 0x88, { KEY_WLAN } },
277 {KE_KEY, 0x8A, { KEY_PROG1 } },
278 {KE_KEY, 0x95, { KEY_MEDIA } },
279 {KE_KEY, 0x99, { KEY_PHONE } },
280 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
281 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200282 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100283 {KE_END, 0},
284};
285
Corentin Chary66a71dd2010-01-25 22:50:11 +0100286
Corentin Chary85091b72007-01-26 14:04:30 +0100287/*
288 * This function evaluates an ACPI method, given an int as parameter, the
289 * method is searched within the scope of the handle, can be NULL. The output
290 * of the method is written is output, which can also be NULL
291 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100292 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100293 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100294static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
295 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100296{
Corentin Charybe966662009-08-29 10:28:29 +0200297 struct acpi_object_list params; /* list of input parameters (an int) */
298 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100299 acpi_status status;
300
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100301 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700302 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100303
Corentin Chary85091b72007-01-26 14:04:30 +0100304 params.count = 1;
305 params.pointer = &in_obj;
306 in_obj.type = ACPI_TYPE_INTEGER;
307 in_obj.integer.value = val;
308
309 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100310 if (status == AE_OK)
311 return 0;
312 else
313 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100314}
315
Corentin Charyd8c67322009-11-28 10:27:51 +0100316static int write_acpi_int(acpi_handle handle, const char *method, int val)
317{
318 return write_acpi_int_ret(handle, method, val, NULL);
319}
320
Corentin Charyd99b5772010-01-22 21:20:57 +0100321static int acpi_check_handle(acpi_handle handle, const char *method,
322 acpi_handle *ret)
323{
324 acpi_status status;
325
326 if (method == NULL)
327 return -ENODEV;
328
329 if (ret)
330 status = acpi_get_handle(handle, (char *)method,
331 ret);
332 else {
333 acpi_handle dummy;
334
335 status = acpi_get_handle(handle, (char *)method,
336 &dummy);
337 }
338
339 if (status != AE_OK) {
340 if (ret)
Joe Perches5ad77dc2011-03-29 15:21:35 -0700341 pr_warn("Error finding %s\n", method);
Corentin Charyd99b5772010-01-22 21:20:57 +0100342 return -ENODEV;
343 }
344 return 0;
345}
346
Andy Ross8819de72011-10-14 11:13:35 +0200347static bool asus_check_pega_lucid(struct asus_laptop *asus)
348{
349 return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
350 !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
351 !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
352 !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
353}
354
Andy Ross33989ba2011-10-14 11:13:36 +0200355static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
356{
357 char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
358 return write_acpi_int(asus->handle, method, unit);
359}
360
Corentin Chary17e78f62010-01-13 22:21:33 +0100361/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100362static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100363 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100364{
Corentin Charyd99b5772010-01-22 21:20:57 +0100365 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100366 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100367 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100368 value = !value + 1;
369 else
370 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100371
Corentin Charye5593bf2010-01-17 17:20:11 +0100372 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100373}
374
Corentin Charybe4ee822009-12-06 16:27:09 +0100375/*
376 * LEDs
377 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100378/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100379static void asus_led_cdev_set(struct led_classdev *led_cdev,
380 enum led_brightness value)
381{
382 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
383 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100384
Corentin Charyaee0afb2010-01-26 21:01:34 +0100385 led->wk = !!value;
386 queue_work(asus->led_workqueue, &led->work);
387}
388
389static void asus_led_cdev_update(struct work_struct *work)
390{
391 struct asus_led *led = container_of(work, struct asus_led, work);
392 struct asus_laptop *asus = led->asus;
393
394 asus_led_set(asus, led->method, led->wk);
395}
396
397static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
398{
399 return led_cdev->brightness;
400}
Corentin Charybe18cda2007-01-26 14:04:35 +0100401
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000402/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100403 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000404 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100405static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000406{
407 unsigned long long kblv;
408 struct acpi_object_list params;
409 union acpi_object in_obj;
410 acpi_status rv;
411
412 params.count = 1;
413 params.pointer = &in_obj;
414 in_obj.type = ACPI_TYPE_INTEGER;
415 in_obj.integer.value = 2;
416
Corentin Charyd99b5772010-01-22 21:20:57 +0100417 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
418 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000419 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700420 pr_warn("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100421 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000422 }
423 return kblv;
424}
425
Corentin Chary4d441512010-01-13 22:26:24 +0100426static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000427{
428 if (kblv > 0)
429 kblv = (1 << 7) | (kblv & 0x7F);
430 else
431 kblv = 0;
432
Corentin Charyd99b5772010-01-22 21:20:57 +0100433 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700434 pr_warn("Keyboard LED display write failed\n");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000435 return -EINVAL;
436 }
437 return 0;
438}
439
Corentin Charyaee0afb2010-01-26 21:01:34 +0100440static void asus_kled_cdev_set(struct led_classdev *led_cdev,
441 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000442{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100443 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
444 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100445
Corentin Chary060cbce2010-01-28 10:52:40 +0100446 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100447 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000448}
449
Corentin Charyaee0afb2010-01-26 21:01:34 +0100450static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000451{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100452 struct asus_led *led = container_of(work, struct asus_led, work);
453 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100454
Corentin Charyaee0afb2010-01-26 21:01:34 +0100455 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000456}
457
Corentin Charyaee0afb2010-01-26 21:01:34 +0100458static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000459{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100460 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
461 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100462
463 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000464}
465
Corentin Charybe4ee822009-12-06 16:27:09 +0100466static void asus_led_exit(struct asus_laptop *asus)
467{
Axel Lin8fcf71a2011-08-08 17:17:18 +0800468 if (!IS_ERR_OR_NULL(asus->mled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100469 led_classdev_unregister(&asus->mled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800470 if (!IS_ERR_OR_NULL(asus->tled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100471 led_classdev_unregister(&asus->tled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800472 if (!IS_ERR_OR_NULL(asus->pled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100473 led_classdev_unregister(&asus->pled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800474 if (!IS_ERR_OR_NULL(asus->rled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100475 led_classdev_unregister(&asus->rled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800476 if (!IS_ERR_OR_NULL(asus->gled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100477 led_classdev_unregister(&asus->gled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800478 if (!IS_ERR_OR_NULL(asus->kled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100479 led_classdev_unregister(&asus->kled.led);
480 if (asus->led_workqueue) {
481 destroy_workqueue(asus->led_workqueue);
482 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100483 }
484}
485
486/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100487static int asus_led_register(struct asus_laptop *asus,
488 struct asus_led *led,
489 const char *name, const char *method)
490{
491 struct led_classdev *led_cdev = &led->led;
492
493 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100494 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100495
496 led->asus = asus;
497 led->method = method;
498
499 INIT_WORK(&led->work, asus_led_cdev_update);
500 led_cdev->name = name;
501 led_cdev->brightness_set = asus_led_cdev_set;
502 led_cdev->brightness_get = asus_led_cdev_get;
503 led_cdev->max_brightness = 1;
504 return led_classdev_register(&asus->platform_device->dev, led_cdev);
505}
Corentin Charybe4ee822009-12-06 16:27:09 +0100506
507static int asus_led_init(struct asus_laptop *asus)
508{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100509 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100510
511 /*
512 * Functions that actually update the LED's are called from a
513 * workqueue. By doing this as separate work rather than when the LED
514 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
515 * potentially bad time, such as a timer interrupt.
516 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100517 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
518 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100519 return -ENOMEM;
520
Corentin Charyaee0afb2010-01-26 21:01:34 +0100521 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
522 if (r)
523 goto error;
524 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
525 if (r)
526 goto error;
527 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
528 if (r)
529 goto error;
530 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
531 if (r)
532 goto error;
533 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
534 if (r)
535 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100536 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100537 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
538 struct asus_led *led = &asus->kled;
539 struct led_classdev *cdev = &led->led;
540
541 led->asus = asus;
542
543 INIT_WORK(&led->work, asus_kled_cdev_update);
544 cdev->name = "asus::kbd_backlight";
545 cdev->brightness_set = asus_kled_cdev_set;
546 cdev->brightness_get = asus_kled_cdev_get;
547 cdev->max_brightness = 3;
548 r = led_classdev_register(&asus->platform_device->dev, cdev);
549 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100550error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100551 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100552 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100553 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100554}
555
556/*
557 * Backlight device
558 */
Corentin Chary4d441512010-01-13 22:26:24 +0100559static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100560{
Corentin Charyd99b5772010-01-22 21:20:57 +0100561 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400562 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100563 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100564
Corentin Charyd99b5772010-01-22 21:20:57 +0100565 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
566 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100567 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700568 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100569
570 return value;
571}
572
Corentin Chary4d441512010-01-13 22:26:24 +0100573static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100574{
Corentin Charyd99b5772010-01-22 21:20:57 +0100575 struct asus_laptop *asus = bl_get_data(bd);
576
577 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700578 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100579 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100580 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100581 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100582}
583
584static int update_bl_status(struct backlight_device *bd)
585{
Richard Purdie599a52d2007-02-10 23:07:48 +0000586 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100587
Corentin Chary3b81cf92011-02-06 13:27:31 +0100588 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100589}
590
Lionel Debrouxacc24722010-11-16 14:14:02 +0100591static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100592 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100593 .update_status = update_bl_status,
594};
595
Corentin Charya539df52010-01-25 22:53:21 +0100596static int asus_backlight_notify(struct asus_laptop *asus)
597{
598 struct backlight_device *bd = asus->backlight_device;
599 int old = bd->props.brightness;
600
601 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
602
603 return old;
604}
605
Corentin Charybe4ee822009-12-06 16:27:09 +0100606static int asus_backlight_init(struct asus_laptop *asus)
607{
608 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500609 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100610
Corentin Chary71e687d2010-08-24 09:30:44 +0200611 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100612 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200613 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500614
Corentin Chary71e687d2010-08-24 09:30:44 +0200615 memset(&props, 0, sizeof(struct backlight_properties));
616 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700617 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100618
Corentin Chary71e687d2010-08-24 09:30:44 +0200619 bd = backlight_device_register(ASUS_LAPTOP_FILE,
620 &asus->platform_device->dev, asus,
621 &asusbl_ops, &props);
622 if (IS_ERR(bd)) {
623 pr_err("Could not register asus backlight device\n");
624 asus->backlight_device = NULL;
625 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100626 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200627
628 asus->backlight_device = bd;
629 bd->props.brightness = asus_read_brightness(bd);
630 bd->props.power = FB_BLANK_UNBLANK;
631 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100632 return 0;
633}
634
635static void asus_backlight_exit(struct asus_laptop *asus)
636{
637 if (asus->backlight_device)
638 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100639 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100640}
641
Corentin Chary85091b72007-01-26 14:04:30 +0100642/*
643 * Platform device handlers
644 */
645
646/*
647 * We write our info in page, we begin at offset off and cannot write more
648 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
649 * number of bytes written in page
650 */
651static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500652 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100653{
Corentin Chary9129d142009-12-01 22:39:41 +0100654 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100655 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400656 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200657 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100658 acpi_status rv = AE_OK;
659
Corentin Chary85091b72007-01-26 14:04:30 +0100660 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100661 * We use the easy way, we don't care of off and count,
662 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100663 */
664
Corentin Chary50a90c42009-11-30 21:55:12 +0100665 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
666 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100667 /*
668 * The SFUN method probably allows the original driver to get the list
669 * of features supported by a given model. For now, 0x0100 or 0x0800
670 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
671 * The significance of others is yet to be found.
672 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100673 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100674 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000675 len += sprintf(page + len, "SFUN value : %#x\n",
676 (uint) temp);
677 /*
678 * The HWRS method return informations about the hardware.
679 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
680 * The significance of others is yet to be found.
681 * If we don't find the method, we assume the device are present.
682 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100683 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000684 if (!ACPI_FAILURE(rv))
685 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100686 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100687 /*
688 * Another value for userspace: the ASYM method returns 0x02 for
689 * battery low and 0x04 for battery critical, its readings tend to be
690 * more accurate than those provided by _BST.
691 * Note: since not all the laptops provide this method, errors are
692 * silently ignored.
693 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100694 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100695 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000696 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100697 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100698 if (asus->dsdt_info) {
699 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100700 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100701 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100702 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100703 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100704 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100705 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100706 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100707 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100708 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100709 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100710 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100711 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100712 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100713 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100714 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
715 }
716
717 return len;
718}
719
720static int parse_arg(const char *buf, unsigned long count, int *val)
721{
722 if (!count)
723 return 0;
724 if (count > 31)
725 return -EINVAL;
726 if (sscanf(buf, "%i", val) != 1)
727 return -EINVAL;
728 return count;
729}
730
Corentin Chary17e78f62010-01-13 22:21:33 +0100731static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
732 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100733 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100734{
735 int rv, value;
736 int out = 0;
737
738 rv = parse_arg(buf, count, &value);
739 if (rv > 0)
740 out = value ? 1 : 0;
741
Corentin Charyd99b5772010-01-22 21:20:57 +0100742 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100743 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100744 return rv;
745}
746
747/*
Corentin Chary722ad972007-01-26 14:04:55 +0100748 * LEDD display
749 */
750static ssize_t show_ledd(struct device *dev,
751 struct device_attribute *attr, char *buf)
752{
Corentin Chary9129d142009-12-01 22:39:41 +0100753 struct asus_laptop *asus = dev_get_drvdata(dev);
754
Corentin Chary50a90c42009-11-30 21:55:12 +0100755 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100756}
757
758static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
759 const char *buf, size_t count)
760{
Corentin Chary9129d142009-12-01 22:39:41 +0100761 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100762 int rv, value;
763
764 rv = parse_arg(buf, count, &value);
765 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700766 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700767 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700768 return -ENODEV;
769 }
770 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100771 }
772 return rv;
773}
774
775/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100776 * Wireless
777 */
778static int asus_wireless_status(struct asus_laptop *asus, int mask)
779{
780 unsigned long long status;
781 acpi_status rv = AE_OK;
782
783 if (!asus->have_rsts)
784 return (asus->wireless_status & mask) ? 1 : 0;
785
Corentin Charyd99b5772010-01-22 21:20:57 +0100786 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
787 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100788 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700789 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100790 return -EINVAL;
791 }
792 return !!(status & mask);
793}
794
795/*
Corentin Chary4564de12007-01-26 14:04:40 +0100796 * WLAN
797 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100798static int asus_wlan_set(struct asus_laptop *asus, int status)
799{
800 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700801 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100802 return -EIO;
803 }
804 return 0;
805}
806
Corentin Chary4564de12007-01-26 14:04:40 +0100807static ssize_t show_wlan(struct device *dev,
808 struct device_attribute *attr, char *buf)
809{
Corentin Chary9129d142009-12-01 22:39:41 +0100810 struct asus_laptop *asus = dev_get_drvdata(dev);
811
Corentin Chary17e78f62010-01-13 22:21:33 +0100812 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100813}
814
815static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
816 const char *buf, size_t count)
817{
Corentin Chary9129d142009-12-01 22:39:41 +0100818 struct asus_laptop *asus = dev_get_drvdata(dev);
819
Corentin Charyd99b5772010-01-22 21:20:57 +0100820 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100821}
822
823/*
824 * Bluetooth
825 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100826static int asus_bluetooth_set(struct asus_laptop *asus, int status)
827{
828 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700829 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100830 return -EIO;
831 }
832 return 0;
833}
834
Corentin Chary4564de12007-01-26 14:04:40 +0100835static ssize_t show_bluetooth(struct device *dev,
836 struct device_attribute *attr, char *buf)
837{
Corentin Chary9129d142009-12-01 22:39:41 +0100838 struct asus_laptop *asus = dev_get_drvdata(dev);
839
Corentin Chary17e78f62010-01-13 22:21:33 +0100840 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100841}
842
Len Brown8def05f2007-01-30 01:46:43 -0500843static ssize_t store_bluetooth(struct device *dev,
844 struct device_attribute *attr, const char *buf,
845 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100846{
Corentin Chary9129d142009-12-01 22:39:41 +0100847 struct asus_laptop *asus = dev_get_drvdata(dev);
848
Corentin Charyd99b5772010-01-22 21:20:57 +0100849 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100850}
851
Corentin Chary78127b42007-01-26 14:04:49 +0100852/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100853 * Wimax
854 */
855static int asus_wimax_set(struct asus_laptop *asus, int status)
856{
857 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700858 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100859 return -EIO;
860 }
861 return 0;
862}
863
864static ssize_t show_wimax(struct device *dev,
865 struct device_attribute *attr, char *buf)
866{
867 struct asus_laptop *asus = dev_get_drvdata(dev);
868
869 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
870}
871
872static ssize_t store_wimax(struct device *dev,
873 struct device_attribute *attr, const char *buf,
874 size_t count)
875{
876 struct asus_laptop *asus = dev_get_drvdata(dev);
877
878 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
879}
880
881/*
882 * Wwan
883 */
884static int asus_wwan_set(struct asus_laptop *asus, int status)
885{
886 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700887 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100888 return -EIO;
889 }
890 return 0;
891}
892
893static ssize_t show_wwan(struct device *dev,
894 struct device_attribute *attr, char *buf)
895{
896 struct asus_laptop *asus = dev_get_drvdata(dev);
897
898 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
899}
900
901static ssize_t store_wwan(struct device *dev,
902 struct device_attribute *attr, const char *buf,
903 size_t count)
904{
905 struct asus_laptop *asus = dev_get_drvdata(dev);
906
907 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
908}
909
910/*
Corentin Chary78127b42007-01-26 14:04:49 +0100911 * Display
912 */
Corentin Chary4d441512010-01-13 22:26:24 +0100913static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +0100914{
915 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +0100916 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700917 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100918 return;
919}
920
Corentin Chary78127b42007-01-26 14:04:49 +0100921/*
922 * Experimental support for display switching. As of now: 1 should activate
923 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
924 * Any combination (bitwise) of these will suffice. I never actually tested 4
925 * displays hooked up simultaneously, so be warned. See the acpi4asus README
926 * for more info.
927 */
928static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
929 const char *buf, size_t count)
930{
Corentin Chary9129d142009-12-01 22:39:41 +0100931 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +0100932 int rv, value;
933
934 rv = parse_arg(buf, count, &value);
935 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +0100936 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +0100937 return rv;
938}
939
Corentin Chary8b857352007-01-26 14:04:58 +0100940/*
941 * Light Sens
942 */
Corentin Chary4d441512010-01-13 22:26:24 +0100943static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +0100944{
Andy Ross33989ba2011-10-14 11:13:36 +0200945 int ret;
946
947 if (asus->is_pega_lucid) {
948 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
949 if (!ret)
950 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
951 } else {
952 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
953 }
954 if (ret)
955 pr_warning("Error setting light sensor switch\n");
956
Corentin Chary50a90c42009-11-30 21:55:12 +0100957 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100958}
959
960static ssize_t show_lssw(struct device *dev,
961 struct device_attribute *attr, char *buf)
962{
Corentin Chary9129d142009-12-01 22:39:41 +0100963 struct asus_laptop *asus = dev_get_drvdata(dev);
964
Corentin Chary50a90c42009-11-30 21:55:12 +0100965 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +0100966}
967
968static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
969 const char *buf, size_t count)
970{
Corentin Chary9129d142009-12-01 22:39:41 +0100971 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +0100972 int rv, value;
973
974 rv = parse_arg(buf, count, &value);
975 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +0100976 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +0100977
978 return rv;
979}
980
Corentin Chary4d441512010-01-13 22:26:24 +0100981static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +0100982{
Corentin Charyd99b5772010-01-22 21:20:57 +0100983 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700984 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +0100985 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100986}
987
988static ssize_t show_lslvl(struct device *dev,
989 struct device_attribute *attr, char *buf)
990{
Corentin Chary9129d142009-12-01 22:39:41 +0100991 struct asus_laptop *asus = dev_get_drvdata(dev);
992
Corentin Chary50a90c42009-11-30 21:55:12 +0100993 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +0100994}
995
996static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
997 const char *buf, size_t count)
998{
Corentin Chary9129d142009-12-01 22:39:41 +0100999 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001000 int rv, value;
1001
1002 rv = parse_arg(buf, count, &value);
1003 if (rv > 0) {
1004 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1005 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001006 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001007 }
1008
1009 return rv;
1010}
1011
Andy Ross33989ba2011-10-14 11:13:36 +02001012static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1013{
1014 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1015 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1016 &buffer);
1017 if (!err) {
1018 union acpi_object *obj = buffer.pointer;
1019 if (obj && obj->type == ACPI_TYPE_INTEGER)
1020 *result = obj->integer.value;
1021 else
1022 err = -EIO;
1023 }
1024 return err;
1025}
1026
1027static ssize_t show_lsvalue(struct device *dev,
1028 struct device_attribute *attr, char *buf)
1029{
1030 struct asus_laptop *asus = dev_get_drvdata(dev);
1031 int err, hi, lo;
1032
1033 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1034 if (!err)
1035 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1036 if (!err)
1037 return sprintf(buf, "%d\n", 10 * hi + lo);
1038 return err;
1039}
1040
Corentin Charye539c2f2007-05-06 14:47:06 +02001041/*
1042 * GPS
1043 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001044static int asus_gps_status(struct asus_laptop *asus)
1045{
1046 unsigned long long status;
1047 acpi_status rv = AE_OK;
1048
Corentin Charyd99b5772010-01-22 21:20:57 +01001049 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1050 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001051 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001052 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001053 return -ENODEV;
1054 }
1055 return !!status;
1056}
1057
1058static int asus_gps_switch(struct asus_laptop *asus, int status)
1059{
Corentin Charyd99b5772010-01-22 21:20:57 +01001060 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001061
Corentin Charyd99b5772010-01-22 21:20:57 +01001062 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001063 return -ENODEV;
1064 return 0;
1065}
1066
Corentin Charye539c2f2007-05-06 14:47:06 +02001067static ssize_t show_gps(struct device *dev,
1068 struct device_attribute *attr, char *buf)
1069{
Corentin Chary9129d142009-12-01 22:39:41 +01001070 struct asus_laptop *asus = dev_get_drvdata(dev);
1071
Corentin Chary6358bf22010-01-13 21:55:44 +01001072 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001073}
1074
1075static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1076 const char *buf, size_t count)
1077{
Corentin Chary060cbce2010-01-28 10:52:40 +01001078 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001079 int rv, value;
1080 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001081
Corentin Chary6358bf22010-01-13 21:55:44 +01001082 rv = parse_arg(buf, count, &value);
1083 if (rv <= 0)
1084 return -EINVAL;
1085 ret = asus_gps_switch(asus, !!value);
1086 if (ret)
1087 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001088 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001089 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001090}
1091
Corentin Chary034ce902009-01-20 16:17:43 +01001092/*
Corentin Chary18e13112010-01-25 23:29:24 +01001093 * rfkill
1094 */
1095static int asus_gps_rfkill_set(void *data, bool blocked)
1096{
Corentin Chary23f45c32010-08-24 09:30:46 +02001097 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001098
Corentin Chary23f45c32010-08-24 09:30:46 +02001099 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001100}
1101
1102static const struct rfkill_ops asus_gps_rfkill_ops = {
1103 .set_block = asus_gps_rfkill_set,
1104};
1105
1106static void asus_rfkill_exit(struct asus_laptop *asus)
1107{
1108 if (asus->gps_rfkill) {
1109 rfkill_unregister(asus->gps_rfkill);
1110 rfkill_destroy(asus->gps_rfkill);
1111 asus->gps_rfkill = NULL;
1112 }
1113}
1114
1115static int asus_rfkill_init(struct asus_laptop *asus)
1116{
1117 int result;
1118
1119 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1120 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1121 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1122 return 0;
1123
1124 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1125 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001126 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001127 if (!asus->gps_rfkill)
1128 return -EINVAL;
1129
1130 result = rfkill_register(asus->gps_rfkill);
1131 if (result) {
1132 rfkill_destroy(asus->gps_rfkill);
1133 asus->gps_rfkill = NULL;
1134 }
1135
1136 return result;
1137}
1138
1139/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001140 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001141 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001142static void asus_input_notify(struct asus_laptop *asus, int event)
1143{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001144 if (asus->inputdev)
1145 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001146}
1147
1148static int asus_input_init(struct asus_laptop *asus)
1149{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001150 struct input_dev *input;
1151 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001152
Corentin Chary66a71dd2010-01-25 22:50:11 +01001153 input = input_allocate_device();
1154 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001155 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001156 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001157 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001158 input->name = "Asus Laptop extra buttons";
1159 input->phys = ASUS_LAPTOP_FILE "/input0";
1160 input->id.bustype = BUS_HOST;
1161 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001162
Corentin Chary66a71dd2010-01-25 22:50:11 +01001163 error = sparse_keymap_setup(input, asus_keymap, NULL);
1164 if (error) {
1165 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001166 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001167 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001168 error = input_register_device(input);
1169 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001170 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001171 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001172 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001173
1174 asus->inputdev = input;
1175 return 0;
1176
Axel Lin45036ae2010-07-05 15:29:00 +08001177err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001178 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001179err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001180 input_free_device(input);
1181 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001182}
1183
1184static void asus_input_exit(struct asus_laptop *asus)
1185{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001186 if (asus->inputdev) {
1187 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001188 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001189 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001190 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001191}
1192
1193/*
1194 * ACPI driver
1195 */
Corentin Chary600ad522009-11-30 21:42:42 +01001196static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001197{
Corentin Chary9129d142009-12-01 22:39:41 +01001198 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001199 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001200
Corentin Chary619d8b12009-11-28 10:35:37 +01001201 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001202 count = asus->event_count[event % 128]++;
1203 acpi_bus_generate_proc_event(asus->device, event, count);
1204 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1205 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001206 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001207
Corentin Charya539df52010-01-25 22:53:21 +01001208 /* Brightness events are special */
1209 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1210
1211 /* Ignore them completely if the acpi video driver is used */
1212 if (asus->backlight_device != NULL) {
1213 /* Update the backlight device. */
1214 asus_backlight_notify(asus);
1215 }
1216 return ;
1217 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001218 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001219}
1220
Corentin Chary2a1fd642010-01-26 21:02:23 +01001221static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1222static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001223static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1224 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001225static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1226static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001227static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001228static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001229static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001230static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1231static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1232static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1233
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001234static struct attribute *asus_attributes[] = {
1235 &dev_attr_infos.attr,
1236 &dev_attr_wlan.attr,
1237 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001238 &dev_attr_wimax.attr,
1239 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001240 &dev_attr_display.attr,
1241 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001242 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001243 &dev_attr_ls_level.attr,
1244 &dev_attr_ls_switch.attr,
1245 &dev_attr_gps.attr,
1246 NULL
1247};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001248
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001249static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1250 struct attribute *attr,
1251 int idx)
1252{
1253 struct device *dev = container_of(kobj, struct device, kobj);
1254 struct platform_device *pdev = to_platform_device(dev);
1255 struct asus_laptop *asus = platform_get_drvdata(pdev);
1256 acpi_handle handle = asus->handle;
1257 bool supported;
1258
Andy Ross33989ba2011-10-14 11:13:36 +02001259 if (asus->is_pega_lucid) {
1260 /* no ls_level interface on the Lucid */
1261 if (attr == &dev_attr_ls_switch.attr)
1262 supported = true;
1263 else if (attr == &dev_attr_ls_level.attr)
1264 supported = false;
1265 else
1266 goto normal;
1267
1268 return supported;
1269 }
1270
1271normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001272 if (attr == &dev_attr_wlan.attr) {
1273 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1274
1275 } else if (attr == &dev_attr_bluetooth.attr) {
1276 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1277
1278 } else if (attr == &dev_attr_display.attr) {
1279 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1280
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001281 } else if (attr == &dev_attr_wimax.attr) {
1282 supported =
1283 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1284
1285 } else if (attr == &dev_attr_wwan.attr) {
1286 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1287
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001288 } else if (attr == &dev_attr_ledd.attr) {
1289 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1290
1291 } else if (attr == &dev_attr_ls_switch.attr ||
1292 attr == &dev_attr_ls_level.attr) {
1293 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001294 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1295 } else if (attr == &dev_attr_ls_value.attr) {
1296 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001297 } else if (attr == &dev_attr_gps.attr) {
1298 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1299 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1300 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1301 } else {
1302 supported = true;
1303 }
1304
1305 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001306}
1307
Corentin Chary2a1fd642010-01-26 21:02:23 +01001308
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001309static const struct attribute_group asus_attr_group = {
1310 .is_visible = asus_sysfs_is_visible,
1311 .attrs = asus_attributes,
1312};
Corentin Chary85091b72007-01-26 14:04:30 +01001313
Corentin Chary9129d142009-12-01 22:39:41 +01001314static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001315{
Corentin Chary71e687d2010-08-24 09:30:44 +02001316 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001317
Corentin Chary50a90c42009-11-30 21:55:12 +01001318 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1319 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001320 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001321 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001322
Corentin Chary71e687d2010-08-24 09:30:44 +02001323 result = platform_device_add(asus->platform_device);
1324 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001325 goto fail_platform_device;
1326
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001327 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1328 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001329 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001330 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001331
Corentin Chary600ad522009-11-30 21:42:42 +01001332 return 0;
1333
1334fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001335 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001336fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001337 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001338 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001339}
1340
Corentin Chary9129d142009-12-01 22:39:41 +01001341static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001342{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001343 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001344 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001345}
1346
1347static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001348 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001349 .name = ASUS_LAPTOP_FILE,
1350 .owner = THIS_MODULE,
1351 }
Corentin Chary85091b72007-01-26 14:04:30 +01001352};
1353
Corentin Chary85091b72007-01-26 14:04:30 +01001354/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001355 * This function is used to initialize the context with right values. In this
1356 * method, we can make all the detection we want, and modify the asus_laptop
1357 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001358 */
Corentin Chary7c247642009-11-30 22:13:54 +01001359static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001360{
1361 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001362 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001363 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001364 char *string = NULL;
1365 acpi_status status;
1366
1367 /*
1368 * Get DSDT headers early enough to allow for differentiating between
1369 * models, but late enough to allow acpi_bus_register_driver() to fail
1370 * before doing anything ACPI-specific. Should we encounter a machine,
1371 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001372 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001373 */
Corentin Chary7c247642009-11-30 22:13:54 +01001374 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001375 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001376 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001377
1378 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001379 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001380 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001381 return -ENODEV;
1382 }
1383
1384 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001385 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001386 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001387 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001388 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001389 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001390 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001391 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001392
Corentin Chary185e5af2007-03-11 10:27:33 +01001393 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001394 if (write_acpi_int(asus->handle, "CWAP", wapf))
1395 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001396 /*
1397 * Try to match the object returned by INIT to the specific model.
1398 * Handle every possible object (or the lack of thereof) the DSDT
1399 * writers might throw at us. When in trouble, we pass NULL to
1400 * asus_model_match() and try something completely different.
1401 */
1402 if (buffer.pointer) {
1403 model = buffer.pointer;
1404 switch (model->type) {
1405 case ACPI_TYPE_STRING:
1406 string = model->string.pointer;
1407 break;
1408 case ACPI_TYPE_BUFFER:
1409 string = model->buffer.pointer;
1410 break;
1411 default:
1412 string = "";
1413 break;
1414 }
1415 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001416 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001417 if (!asus->name) {
1418 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001419 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001420 }
Corentin Chary85091b72007-01-26 14:04:30 +01001421
Len Brown8def05f2007-01-30 01:46:43 -05001422 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001423 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001424
Corentin Chary4564de12007-01-26 14:04:40 +01001425 /*
1426 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001427 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1428 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001429 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001430 */
Corentin Chary9a816852007-03-11 10:25:38 +01001431 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001432 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001433 if (!ACPI_FAILURE(status))
1434 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001435
Corentin Charyd99b5772010-01-22 21:20:57 +01001436 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001437 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001438
Corentin Chary85091b72007-01-26 14:04:30 +01001439 kfree(model);
1440
1441 return AE_OK;
1442}
1443
Corentin Chary9129d142009-12-01 22:39:41 +01001444static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001445{
1446 int result = 0;
1447
Corentin Chary50a90c42009-11-30 21:55:12 +01001448 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001449 if (result)
1450 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001451 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001452 pr_err("Hotkey device not present, aborting\n");
1453 return -ENODEV;
1454 }
1455
Corentin Chary7c247642009-11-30 22:13:54 +01001456 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001457 if (result)
1458 return result;
1459
Corentin Chary600ad522009-11-30 21:42:42 +01001460 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001461 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001462 asus_bluetooth_set(asus, !!bluetooth_status);
1463
Corentin Charyd0930a22010-01-17 17:21:13 +01001464 if (wlan_status >= 0)
1465 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001466
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001467 if (wimax_status >= 0)
1468 asus_wimax_set(asus, !!wimax_status);
1469
1470 if (wwan_status >= 0)
1471 asus_wwan_set(asus, !!wwan_status);
1472
Corentin Chary600ad522009-11-30 21:42:42 +01001473 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001474 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001475 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001476
1477 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001478 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001479
1480 /* Set initial values of light sensor and level */
Andy Rossabec04d2011-10-14 11:13:37 +02001481 asus->light_switch = !!als_status;
Corentin Charybe4ee822009-12-06 16:27:09 +01001482 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001483
Andy Ross33989ba2011-10-14 11:13:36 +02001484 if (asus->is_pega_lucid) {
1485 asus_als_switch(asus, asus->light_switch);
1486 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1487 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001488 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001489 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001490 }
Corentin Chary600ad522009-11-30 21:42:42 +01001491
Corentin Chary600ad522009-11-30 21:42:42 +01001492 return result;
1493}
1494
Corentin Charyaf96f872011-02-06 13:27:30 +01001495static void __devinit asus_dmi_check(void)
1496{
1497 const char *model;
1498
1499 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1500 if (!model)
1501 return;
1502
1503 /* On L1400B WLED control the sound card, don't mess with it ... */
1504 if (strncmp(model, "L1400B", 6) == 0) {
1505 wlan_status = -1;
1506 }
1507}
1508
Corentin Chary71e687d2010-08-24 09:30:44 +02001509static bool asus_device_present;
1510
Corentin Chary600ad522009-11-30 21:42:42 +01001511static int __devinit asus_acpi_add(struct acpi_device *device)
1512{
Corentin Chary9129d142009-12-01 22:39:41 +01001513 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001514 int result;
1515
1516 pr_notice("Asus Laptop Support version %s\n",
1517 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001518 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1519 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001520 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001521 asus->handle = device->handle;
1522 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1523 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1524 device->driver_data = asus;
1525 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001526
Corentin Charyaf96f872011-02-06 13:27:30 +01001527 asus_dmi_check();
1528
Corentin Chary9129d142009-12-01 22:39:41 +01001529 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001530 if (result)
1531 goto fail_platform;
1532
1533 /*
Andy Ross8819de72011-10-14 11:13:35 +02001534 * Need platform type detection first, then the platform
1535 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001536 */
Andy Ross8819de72011-10-14 11:13:35 +02001537 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001538 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001539 if (result)
1540 goto fail_platform;
1541
1542 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001543 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001544 if (result)
1545 goto fail_backlight;
1546 } else
1547 pr_info("Backlight controlled by ACPI video driver\n");
1548
Corentin Chary9129d142009-12-01 22:39:41 +01001549 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001550 if (result)
1551 goto fail_input;
1552
Corentin Chary9129d142009-12-01 22:39:41 +01001553 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001554 if (result)
1555 goto fail_led;
1556
Corentin Chary18e13112010-01-25 23:29:24 +01001557 result = asus_rfkill_init(asus);
1558 if (result)
1559 goto fail_rfkill;
1560
Corentin Chary600ad522009-11-30 21:42:42 +01001561 asus_device_present = true;
1562 return 0;
1563
Corentin Chary18e13112010-01-25 23:29:24 +01001564fail_rfkill:
1565 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001566fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001567 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001568fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001569 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001570fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001571 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001572fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001573 kfree(asus->name);
1574 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001575
1576 return result;
1577}
1578
1579static int asus_acpi_remove(struct acpi_device *device, int type)
1580{
Corentin Chary9129d142009-12-01 22:39:41 +01001581 struct asus_laptop *asus = acpi_driver_data(device);
1582
1583 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001584 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001585 asus_led_exit(asus);
1586 asus_input_exit(asus);
1587 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001588
Corentin Chary50a90c42009-11-30 21:55:12 +01001589 kfree(asus->name);
1590 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001591 return 0;
1592}
1593
1594static const struct acpi_device_id asus_device_ids[] = {
1595 {"ATK0100", 0},
1596 {"ATK0101", 0},
1597 {"", 0},
1598};
1599MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1600
1601static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001602 .name = ASUS_LAPTOP_NAME,
1603 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001604 .owner = THIS_MODULE,
1605 .ids = asus_device_ids,
1606 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1607 .ops = {
1608 .add = asus_acpi_add,
1609 .remove = asus_acpi_remove,
1610 .notify = asus_acpi_notify,
1611 },
1612};
1613
Corentin Chary85091b72007-01-26 14:04:30 +01001614static int __init asus_laptop_init(void)
1615{
1616 int result;
1617
Corentin Chary600ad522009-11-30 21:42:42 +01001618 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001619 if (result < 0)
1620 return result;
1621
Corentin Chary600ad522009-11-30 21:42:42 +01001622 result = acpi_bus_register_driver(&asus_acpi_driver);
1623 if (result < 0)
1624 goto fail_acpi_driver;
1625 if (!asus_device_present) {
1626 result = -ENODEV;
1627 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001628 }
Len Brown8def05f2007-01-30 01:46:43 -05001629 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001630
Corentin Chary600ad522009-11-30 21:42:42 +01001631fail_no_device:
1632 acpi_bus_unregister_driver(&asus_acpi_driver);
1633fail_acpi_driver:
1634 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001635 return result;
1636}
1637
Corentin Chary600ad522009-11-30 21:42:42 +01001638static void __exit asus_laptop_exit(void)
1639{
1640 acpi_bus_unregister_driver(&asus_acpi_driver);
1641 platform_driver_unregister(&platform_driver);
1642}
1643
Corentin Chary85091b72007-01-26 14:04:30 +01001644module_init(asus_laptop_init);
1645module_exit(asus_laptop_exit);