blob: f3aa6a7fdab60c71448b85bb6eeb68a3f8c1cc7f [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
Corentin Chary85091b72007-01-26 14:04:30 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 *
23 * The development page for this driver is located at
24 * http://sourceforge.net/projects/acpi4asus/
25 *
26 * Credits:
27 * Pontus Fuchs - Helper functions, cleanup
28 * Johann Wiesner - Small compile fixes
29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
30 * Eric Burghard - LED display support for W1N
31 * Josh Green - Light Sens support
32 * Thomas Tuttle - His first patch for led support was very helpfull
Corentin Charye539c2f2007-05-06 14:47:06 +020033 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010034 */
35
Corentin Chary2fcc23d2009-06-19 14:52:03 +020036#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
Corentin Chary85091b72007-01-26 14:04:30 +010038#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/types.h>
42#include <linux/err.h>
43#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010044#include <linux/backlight.h>
45#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010046#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010047#include <linux/platform_device.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010048#include <linux/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010049#include <linux/input.h>
Corentin Chary66a71dd2010-01-25 22:50:11 +010050#include <linux/input/sparse-keymap.h>
Corentin Chary18e13112010-01-25 23:29:24 +010051#include <linux/rfkill.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090052#include <linux/slab.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010053#include <acpi/acpi_drivers.h>
54#include <acpi/acpi_bus.h>
Corentin Chary85091b72007-01-26 14:04:30 +010055
Corentin Chary91687cc2009-11-28 10:32:34 +010056#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010057
Corentin Chary50a90c42009-11-30 21:55:12 +010058#define ASUS_LAPTOP_NAME "Asus Laptop Support"
59#define ASUS_LAPTOP_CLASS "hotkey"
60#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
61#define ASUS_LAPTOP_FILE KBUILD_MODNAME
62#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
Corentin Chary85091b72007-01-26 14:04:30 +010063
Corentin Chary85091b72007-01-26 14:04:30 +010064MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010065MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010066MODULE_LICENSE("GPL");
67
Corentin Charybe966662009-08-29 10:28:29 +020068/*
69 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010070 * The significance of values is yet to be found, but
71 * most of the time:
72 * 0x0 will do nothing
73 * 0x1 will allow to control the device with Fn+Fx key.
74 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
75 * 0x5 like 0x1 or 0x4
76 * So, if something doesn't work as you want, just try other values =)
77 */
78static uint wapf = 1;
Axel Linc26d85c2010-07-20 15:19:55 -070079module_param(wapf, uint, 0444);
Corentin Chary185e5af2007-03-11 10:27:33 +010080MODULE_PARM_DESC(wapf, "WAPF value");
81
Dan Carpenter668f4a02010-04-06 13:44:29 +030082static int wlan_status = 1;
83static int bluetooth_status = 1;
Corentin Charyba1ff5b2010-11-14 17:40:12 +010084static int wimax_status = -1;
85static int wwan_status = -1;
Corentin Chary0e875f42010-01-10 20:49:26 +010086
Axel Linc26d85c2010-07-20 15:19:55 -070087module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010088MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010089 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
90 "default is 1");
91
Axel Linc26d85c2010-07-20 15:19:55 -070092module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010093MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
94 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
95 "default is 1");
96
Corentin Charyba1ff5b2010-11-14 17:40:12 +010097module_param(wimax_status, int, 0444);
98MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
99 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
100 "default is 1");
101
102module_param(wwan_status, int, 0444);
103MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
104 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
105 "default is 1");
106
Corentin Charybe4ee822009-12-06 16:27:09 +0100107/*
108 * Some events we use, same for all Asus
109 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100110#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
111#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100112#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100113#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100114#define ATKD_LCD_ON 0x33
115#define ATKD_LCD_OFF 0x34
116
117/*
118 * Known bits returned by \_SB.ATKD.HWRS
119 */
120#define WL_HWRS 0x80
121#define BT_HWRS 0x100
122
123/*
124 * Flags for hotk status
125 * WL_ON and BT_ON are also used for wireless_status()
126 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100127#define WL_RSTS 0x01 /* internal Wifi */
128#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100129#define WM_RSTS 0x08 /* internal wimax */
130#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100131
Corentin Charybe18cda2007-01-26 14:04:35 +0100132/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100133#define METHOD_MLED "MLED"
134#define METHOD_TLED "TLED"
135#define METHOD_RLED "RLED" /* W1JC */
136#define METHOD_PLED "PLED" /* A7J */
137#define METHOD_GLED "GLED" /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100138
Corentin Chary722ad972007-01-26 14:04:55 +0100139/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100140#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100141
Corentin Charybe966662009-08-29 10:28:29 +0200142/*
143 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100144 * WLED and BLED are not handled like other XLED, because in some dsdt
145 * they also control the WLAN/Bluetooth device.
146 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100147#define METHOD_WLAN "WLED"
148#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100149
150/* WWAN and WIMAX */
151#define METHOD_WWAN "GSMC"
152#define METHOD_WIMAX "WMXC"
153
Corentin Charyd99b5772010-01-22 21:20:57 +0100154#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100155
Corentin Chary6b7091e2007-01-26 14:04:45 +0100156/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100157#define METHOD_BRIGHTNESS_SET "SPLV"
158#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100159
160/* Backlight */
Corentin Chary060cbce2010-01-28 10:52:40 +0100161static acpi_handle lcd_switch_handle;
Corentin Chary16721512010-03-02 22:24:12 +0100162static char *lcd_switch_paths[] = {
Corentin Chary060cbce2010-01-28 10:52:40 +0100163 "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
164 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
165 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
166 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
167 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
168 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
169 "\\_SB.PCI0.PX40.Q10", /* S1x */
170 "\\Q10"}; /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100171
Corentin Chary78127b42007-01-26 14:04:49 +0100172/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100173#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100174
175static acpi_handle display_get_handle;
Corentin Chary16721512010-03-02 22:24:12 +0100176static char *display_get_paths[] = {
Corentin Chary060cbce2010-01-28 10:52:40 +0100177 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
178 "\\_SB.PCI0.P0P1.VGA.GETD",
179 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
180 "\\_SB.PCI0.P0P2.VGA.GETD",
181 /* A6V A6Q */
182 "\\_SB.PCI0.P0P3.VGA.GETD",
183 /* A6T, A6M */
184 "\\_SB.PCI0.P0PA.VGA.GETD",
185 /* L3C */
186 "\\_SB.PCI0.PCI1.VGAC.NMAP",
187 /* Z96F */
188 "\\_SB.PCI0.VGA.GETD",
189 /* A2D */
190 "\\ACTD",
191 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
192 "\\ADVG",
193 /* P30 */
194 "\\DNXT",
195 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
196 "\\INFB",
197 /* A3F A6F A3N A3L M6N W3N W6A */
198 "\\SSTE"};
Corentin Chary78127b42007-01-26 14:04:49 +0100199
Corentin Charyd99b5772010-01-22 21:20:57 +0100200#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
201#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100202
Corentin Charye539c2f2007-05-06 14:47:06 +0200203/* GPS */
204/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100205#define METHOD_GPS_ON "SDON"
206#define METHOD_GPS_OFF "SDOF"
207#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200208
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000209/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100210#define METHOD_KBD_LIGHT_SET "SLKB"
211#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000212
Corentin Chary85091b72007-01-26 14:04:30 +0100213/*
Corentin Chary9129d142009-12-01 22:39:41 +0100214 * Define a specific led structure to keep the main structure clean
215 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100216struct asus_led {
217 int wk;
218 struct work_struct work;
219 struct led_classdev led;
220 struct asus_laptop *asus;
221 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100222};
223
224/*
Corentin Chary85091b72007-01-26 14:04:30 +0100225 * This is the main structure, we can use it to store anything interesting
226 * about the hotk device
227 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100228struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200229 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100230
Corentin Chary7c247642009-11-30 22:13:54 +0100231 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100232 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100233 struct acpi_device *device; /* the device we are in */
234 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100235
Corentin Chary7c247642009-11-30 22:13:54 +0100236 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100237 struct key_entry *keymap;
238
Corentin Charyaee0afb2010-01-26 21:01:34 +0100239 struct asus_led mled;
240 struct asus_led tled;
241 struct asus_led rled;
242 struct asus_led pled;
243 struct asus_led gled;
244 struct asus_led kled;
245 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100246
Corentin Charyaa9df932010-01-13 21:49:10 +0100247 int wireless_status;
248 bool have_rsts;
Corentin Chary3e68ae72010-01-13 22:10:39 +0100249 int lcd_state;
Corentin Charyaa9df932010-01-13 21:49:10 +0100250
Corentin Chary18e13112010-01-25 23:29:24 +0100251 struct rfkill *gps_rfkill;
252
Corentin Charybe966662009-08-29 10:28:29 +0200253 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200254 u32 ledd_status; /* status of the LED display */
255 u8 light_level; /* light sensor level */
256 u8 light_switch; /* light sensor switch value */
257 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100258};
259
Corentin Chary9129d142009-12-01 22:39:41 +0100260static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100261 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100262 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
263 {KE_KEY, 0x05, { KEY_WLAN } },
264 {KE_KEY, 0x08, { KEY_F13 } },
265 {KE_KEY, 0x17, { KEY_ZOOM } },
266 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100267 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100268 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
269 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
270 {KE_KEY, 0x32, { KEY_MUTE } },
271 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
272 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
273 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
274 {KE_KEY, 0x41, { KEY_NEXTSONG } },
275 {KE_KEY, 0x43, { KEY_STOPCD } },
276 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
277 {KE_KEY, 0x4c, { KEY_MEDIA } },
278 {KE_KEY, 0x50, { KEY_EMAIL } },
279 {KE_KEY, 0x51, { KEY_WWW } },
280 {KE_KEY, 0x55, { KEY_CALC } },
281 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
282 {KE_KEY, 0x5D, { KEY_WLAN } },
283 {KE_KEY, 0x5E, { KEY_WLAN } },
284 {KE_KEY, 0x5F, { KEY_WLAN } },
285 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
286 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
287 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
288 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
289 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d72010-01-17 17:37:19 +0100290 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
291 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100292 {KE_KEY, 0x82, { KEY_CAMERA } },
293 {KE_KEY, 0x88, { KEY_WLAN } },
294 {KE_KEY, 0x8A, { KEY_PROG1 } },
295 {KE_KEY, 0x95, { KEY_MEDIA } },
296 {KE_KEY, 0x99, { KEY_PHONE } },
297 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
298 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200299 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100300 {KE_END, 0},
301};
302
Corentin Chary66a71dd2010-01-25 22:50:11 +0100303
Corentin Chary85091b72007-01-26 14:04:30 +0100304/*
305 * This function evaluates an ACPI method, given an int as parameter, the
306 * method is searched within the scope of the handle, can be NULL. The output
307 * of the method is written is output, which can also be NULL
308 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100309 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100310 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100311static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
312 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100313{
Corentin Charybe966662009-08-29 10:28:29 +0200314 struct acpi_object_list params; /* list of input parameters (an int) */
315 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100316 acpi_status status;
317
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100318 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700319 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100320
Corentin Chary85091b72007-01-26 14:04:30 +0100321 params.count = 1;
322 params.pointer = &in_obj;
323 in_obj.type = ACPI_TYPE_INTEGER;
324 in_obj.integer.value = val;
325
326 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100327 if (status == AE_OK)
328 return 0;
329 else
330 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100331}
332
Corentin Charyd8c67322009-11-28 10:27:51 +0100333static int write_acpi_int(acpi_handle handle, const char *method, int val)
334{
335 return write_acpi_int_ret(handle, method, val, NULL);
336}
337
Corentin Charyd99b5772010-01-22 21:20:57 +0100338static int acpi_check_handle(acpi_handle handle, const char *method,
339 acpi_handle *ret)
340{
341 acpi_status status;
342
343 if (method == NULL)
344 return -ENODEV;
345
346 if (ret)
347 status = acpi_get_handle(handle, (char *)method,
348 ret);
349 else {
350 acpi_handle dummy;
351
352 status = acpi_get_handle(handle, (char *)method,
353 &dummy);
354 }
355
356 if (status != AE_OK) {
357 if (ret)
358 pr_warning("Error finding %s\n", method);
359 return -ENODEV;
360 }
361 return 0;
362}
363
Corentin Chary17e78f62010-01-13 22:21:33 +0100364/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100365static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100366 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100367{
Corentin Charyd99b5772010-01-22 21:20:57 +0100368 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100369 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100370 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100371 value = !value + 1;
372 else
373 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100374
Corentin Charye5593bf2010-01-17 17:20:11 +0100375 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100376}
377
Corentin Charybe4ee822009-12-06 16:27:09 +0100378/*
379 * LEDs
380 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100381/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100382static void asus_led_cdev_set(struct led_classdev *led_cdev,
383 enum led_brightness value)
384{
385 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
386 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100387
Corentin Charyaee0afb2010-01-26 21:01:34 +0100388 led->wk = !!value;
389 queue_work(asus->led_workqueue, &led->work);
390}
391
392static void asus_led_cdev_update(struct work_struct *work)
393{
394 struct asus_led *led = container_of(work, struct asus_led, work);
395 struct asus_laptop *asus = led->asus;
396
397 asus_led_set(asus, led->method, led->wk);
398}
399
400static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
401{
402 return led_cdev->brightness;
403}
Corentin Charybe18cda2007-01-26 14:04:35 +0100404
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000405/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100406 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000407 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100408static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000409{
410 unsigned long long kblv;
411 struct acpi_object_list params;
412 union acpi_object in_obj;
413 acpi_status rv;
414
415 params.count = 1;
416 params.pointer = &in_obj;
417 in_obj.type = ACPI_TYPE_INTEGER;
418 in_obj.integer.value = 2;
419
Corentin Charyd99b5772010-01-22 21:20:57 +0100420 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
421 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000422 if (ACPI_FAILURE(rv)) {
423 pr_warning("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100424 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000425 }
426 return kblv;
427}
428
Corentin Chary4d441512010-01-13 22:26:24 +0100429static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000430{
431 if (kblv > 0)
432 kblv = (1 << 7) | (kblv & 0x7F);
433 else
434 kblv = 0;
435
Corentin Charyd99b5772010-01-22 21:20:57 +0100436 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000437 pr_warning("Keyboard LED display write failed\n");
438 return -EINVAL;
439 }
440 return 0;
441}
442
Corentin Charyaee0afb2010-01-26 21:01:34 +0100443static void asus_kled_cdev_set(struct led_classdev *led_cdev,
444 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000445{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100446 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
447 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100448
Corentin Chary060cbce2010-01-28 10:52:40 +0100449 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100450 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000451}
452
Corentin Charyaee0afb2010-01-26 21:01:34 +0100453static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000454{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100455 struct asus_led *led = container_of(work, struct asus_led, work);
456 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100457
Corentin Charyaee0afb2010-01-26 21:01:34 +0100458 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000459}
460
Corentin Charyaee0afb2010-01-26 21:01:34 +0100461static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000462{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100463 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
464 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100465
466 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000467}
468
Corentin Charybe4ee822009-12-06 16:27:09 +0100469static void asus_led_exit(struct asus_laptop *asus)
470{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100471 if (asus->mled.led.dev)
472 led_classdev_unregister(&asus->mled.led);
473 if (asus->tled.led.dev)
474 led_classdev_unregister(&asus->tled.led);
475 if (asus->pled.led.dev)
476 led_classdev_unregister(&asus->pled.led);
477 if (asus->rled.led.dev)
478 led_classdev_unregister(&asus->rled.led);
479 if (asus->gled.led.dev)
480 led_classdev_unregister(&asus->gled.led);
481 if (asus->kled.led.dev)
482 led_classdev_unregister(&asus->kled.led);
483 if (asus->led_workqueue) {
484 destroy_workqueue(asus->led_workqueue);
485 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100486 }
487}
488
489/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100490static int asus_led_register(struct asus_laptop *asus,
491 struct asus_led *led,
492 const char *name, const char *method)
493{
494 struct led_classdev *led_cdev = &led->led;
495
496 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100497 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100498
499 led->asus = asus;
500 led->method = method;
501
502 INIT_WORK(&led->work, asus_led_cdev_update);
503 led_cdev->name = name;
504 led_cdev->brightness_set = asus_led_cdev_set;
505 led_cdev->brightness_get = asus_led_cdev_get;
506 led_cdev->max_brightness = 1;
507 return led_classdev_register(&asus->platform_device->dev, led_cdev);
508}
Corentin Charybe4ee822009-12-06 16:27:09 +0100509
510static int asus_led_init(struct asus_laptop *asus)
511{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100512 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100513
514 /*
515 * Functions that actually update the LED's are called from a
516 * workqueue. By doing this as separate work rather than when the LED
517 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
518 * potentially bad time, such as a timer interrupt.
519 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100520 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
521 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100522 return -ENOMEM;
523
Corentin Charyaee0afb2010-01-26 21:01:34 +0100524 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
525 if (r)
526 goto error;
527 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
528 if (r)
529 goto error;
530 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
531 if (r)
532 goto error;
533 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
534 if (r)
535 goto error;
536 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
537 if (r)
538 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100539 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100540 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
541 struct asus_led *led = &asus->kled;
542 struct led_classdev *cdev = &led->led;
543
544 led->asus = asus;
545
546 INIT_WORK(&led->work, asus_kled_cdev_update);
547 cdev->name = "asus::kbd_backlight";
548 cdev->brightness_set = asus_kled_cdev_set;
549 cdev->brightness_get = asus_kled_cdev_get;
550 cdev->max_brightness = 3;
551 r = led_classdev_register(&asus->platform_device->dev, cdev);
552 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100553error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100554 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100555 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100556 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100557}
558
559/*
560 * Backlight device
561 */
Corentin Chary3e68ae72010-01-13 22:10:39 +0100562static int asus_lcd_status(struct asus_laptop *asus)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100563{
Corentin Chary3e68ae72010-01-13 22:10:39 +0100564 return asus->lcd_state;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100565}
566
Corentin Chary3e68ae72010-01-13 22:10:39 +0100567static int asus_lcd_set(struct asus_laptop *asus, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100568{
569 int lcd = 0;
570 acpi_status status = 0;
571
Corentin Chary3e68ae72010-01-13 22:10:39 +0100572 lcd = !!value;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100573
Corentin Chary3e68ae72010-01-13 22:10:39 +0100574 if (lcd == asus_lcd_status(asus))
Corentin Chary6b7091e2007-01-26 14:04:45 +0100575 return 0;
576
Corentin Chary3e68ae72010-01-13 22:10:39 +0100577 if (!lcd_switch_handle)
578 return -ENODEV;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100579
Corentin Chary3e68ae72010-01-13 22:10:39 +0100580 status = acpi_evaluate_object(lcd_switch_handle,
581 NULL, NULL, NULL);
582
583 if (ACPI_FAILURE(status)) {
584 pr_warning("Error switching LCD\n");
585 return -ENODEV;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100586 }
587
Corentin Chary3e68ae72010-01-13 22:10:39 +0100588 asus->lcd_state = lcd;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100589 return 0;
590}
591
Corentin Chary9129d142009-12-01 22:39:41 +0100592static void lcd_blank(struct asus_laptop *asus, int blank)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100593{
Corentin Chary7c247642009-11-30 22:13:54 +0100594 struct backlight_device *bd = asus->backlight_device;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100595
Corentin Chary3e68ae72010-01-13 22:10:39 +0100596 asus->lcd_state = (blank == FB_BLANK_UNBLANK);
597
Len Brown8def05f2007-01-30 01:46:43 -0500598 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000599 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000600 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100601 }
602}
603
Corentin Chary4d441512010-01-13 22:26:24 +0100604static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100605{
Corentin Charyd99b5772010-01-22 21:20:57 +0100606 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400607 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100608 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100609
Corentin Charyd99b5772010-01-22 21:20:57 +0100610 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
611 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100612 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200613 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100614
615 return value;
616}
617
Corentin Chary4d441512010-01-13 22:26:24 +0100618static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100619{
Corentin Charyd99b5772010-01-22 21:20:57 +0100620 struct asus_laptop *asus = bl_get_data(bd);
621
622 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200623 pr_warning("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100624 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100625 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100626 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100627}
628
629static int update_bl_status(struct backlight_device *bd)
630{
Corentin Chary9129d142009-12-01 22:39:41 +0100631 struct asus_laptop *asus = bl_get_data(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100632 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000633 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100634
Corentin Chary4d441512010-01-13 22:26:24 +0100635 rv = asus_set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500636 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100637 return rv;
638
Richard Purdie599a52d2007-02-10 23:07:48 +0000639 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary3e68ae72010-01-13 22:10:39 +0100640 return asus_lcd_set(asus, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100641}
642
Lionel Debrouxacc24722010-11-16 14:14:02 +0100643static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100644 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100645 .update_status = update_bl_status,
646};
647
Corentin Charya539df52010-01-25 22:53:21 +0100648static int asus_backlight_notify(struct asus_laptop *asus)
649{
650 struct backlight_device *bd = asus->backlight_device;
651 int old = bd->props.brightness;
652
653 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
654
655 return old;
656}
657
Corentin Charybe4ee822009-12-06 16:27:09 +0100658static int asus_backlight_init(struct asus_laptop *asus)
659{
660 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500661 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100662
Corentin Chary71e687d2010-08-24 09:30:44 +0200663 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
664 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL) ||
665 !lcd_switch_handle)
666 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500667
Corentin Chary71e687d2010-08-24 09:30:44 +0200668 memset(&props, 0, sizeof(struct backlight_properties));
669 props.max_brightness = 15;
Corentin Charybe4ee822009-12-06 16:27:09 +0100670
Corentin Chary71e687d2010-08-24 09:30:44 +0200671 bd = backlight_device_register(ASUS_LAPTOP_FILE,
672 &asus->platform_device->dev, asus,
673 &asusbl_ops, &props);
674 if (IS_ERR(bd)) {
675 pr_err("Could not register asus backlight device\n");
676 asus->backlight_device = NULL;
677 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100678 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200679
680 asus->backlight_device = bd;
681 bd->props.brightness = asus_read_brightness(bd);
682 bd->props.power = FB_BLANK_UNBLANK;
683 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100684 return 0;
685}
686
687static void asus_backlight_exit(struct asus_laptop *asus)
688{
689 if (asus->backlight_device)
690 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100691 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100692}
693
Corentin Chary85091b72007-01-26 14:04:30 +0100694/*
695 * Platform device handlers
696 */
697
698/*
699 * We write our info in page, we begin at offset off and cannot write more
700 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
701 * number of bytes written in page
702 */
703static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500704 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100705{
Corentin Chary9129d142009-12-01 22:39:41 +0100706 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100707 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400708 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200709 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100710 acpi_status rv = AE_OK;
711
Corentin Chary85091b72007-01-26 14:04:30 +0100712 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100713 * We use the easy way, we don't care of off and count,
714 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100715 */
716
Corentin Chary50a90c42009-11-30 21:55:12 +0100717 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
718 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100719 /*
720 * The SFUN method probably allows the original driver to get the list
721 * of features supported by a given model. For now, 0x0100 or 0x0800
722 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
723 * The significance of others is yet to be found.
724 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100725 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100726 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000727 len += sprintf(page + len, "SFUN value : %#x\n",
728 (uint) temp);
729 /*
730 * The HWRS method return informations about the hardware.
731 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
732 * The significance of others is yet to be found.
733 * If we don't find the method, we assume the device are present.
734 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100735 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000736 if (!ACPI_FAILURE(rv))
737 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100738 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100739 /*
740 * Another value for userspace: the ASYM method returns 0x02 for
741 * battery low and 0x04 for battery critical, its readings tend to be
742 * more accurate than those provided by _BST.
743 * Note: since not all the laptops provide this method, errors are
744 * silently ignored.
745 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100746 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100747 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000748 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100749 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100750 if (asus->dsdt_info) {
751 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100752 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100753 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100754 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100755 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100756 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100757 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100758 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100759 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100760 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100761 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100762 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100763 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100764 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100765 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100766 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
767 }
768
769 return len;
770}
771
772static int parse_arg(const char *buf, unsigned long count, int *val)
773{
774 if (!count)
775 return 0;
776 if (count > 31)
777 return -EINVAL;
778 if (sscanf(buf, "%i", val) != 1)
779 return -EINVAL;
780 return count;
781}
782
Corentin Chary17e78f62010-01-13 22:21:33 +0100783static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
784 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100785 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100786{
787 int rv, value;
788 int out = 0;
789
790 rv = parse_arg(buf, count, &value);
791 if (rv > 0)
792 out = value ? 1 : 0;
793
Corentin Charyd99b5772010-01-22 21:20:57 +0100794 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100795 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100796 return rv;
797}
798
799/*
Corentin Chary722ad972007-01-26 14:04:55 +0100800 * LEDD display
801 */
802static ssize_t show_ledd(struct device *dev,
803 struct device_attribute *attr, char *buf)
804{
Corentin Chary9129d142009-12-01 22:39:41 +0100805 struct asus_laptop *asus = dev_get_drvdata(dev);
806
Corentin Chary50a90c42009-11-30 21:55:12 +0100807 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100808}
809
810static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
811 const char *buf, size_t count)
812{
Corentin Chary9129d142009-12-01 22:39:41 +0100813 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100814 int rv, value;
815
816 rv = parse_arg(buf, count, &value);
817 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700818 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200819 pr_warning("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700820 return -ENODEV;
821 }
822 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100823 }
824 return rv;
825}
826
827/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100828 * Wireless
829 */
830static int asus_wireless_status(struct asus_laptop *asus, int mask)
831{
832 unsigned long long status;
833 acpi_status rv = AE_OK;
834
835 if (!asus->have_rsts)
836 return (asus->wireless_status & mask) ? 1 : 0;
837
Corentin Charyd99b5772010-01-22 21:20:57 +0100838 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
839 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100840 if (ACPI_FAILURE(rv)) {
841 pr_warning("Error reading Wireless status\n");
842 return -EINVAL;
843 }
844 return !!(status & mask);
845}
846
847/*
Corentin Chary4564de12007-01-26 14:04:40 +0100848 * WLAN
849 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100850static int asus_wlan_set(struct asus_laptop *asus, int status)
851{
852 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
853 pr_warning("Error setting wlan status to %d", status);
854 return -EIO;
855 }
856 return 0;
857}
858
Corentin Chary4564de12007-01-26 14:04:40 +0100859static ssize_t show_wlan(struct device *dev,
860 struct device_attribute *attr, char *buf)
861{
Corentin Chary9129d142009-12-01 22:39:41 +0100862 struct asus_laptop *asus = dev_get_drvdata(dev);
863
Corentin Chary17e78f62010-01-13 22:21:33 +0100864 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100865}
866
867static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
868 const char *buf, size_t count)
869{
Corentin Chary9129d142009-12-01 22:39:41 +0100870 struct asus_laptop *asus = dev_get_drvdata(dev);
871
Corentin Charyd99b5772010-01-22 21:20:57 +0100872 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100873}
874
875/*
876 * Bluetooth
877 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100878static int asus_bluetooth_set(struct asus_laptop *asus, int status)
879{
880 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
881 pr_warning("Error setting bluetooth status to %d", status);
882 return -EIO;
883 }
884 return 0;
885}
886
Corentin Chary4564de12007-01-26 14:04:40 +0100887static ssize_t show_bluetooth(struct device *dev,
888 struct device_attribute *attr, char *buf)
889{
Corentin Chary9129d142009-12-01 22:39:41 +0100890 struct asus_laptop *asus = dev_get_drvdata(dev);
891
Corentin Chary17e78f62010-01-13 22:21:33 +0100892 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100893}
894
Len Brown8def05f2007-01-30 01:46:43 -0500895static ssize_t store_bluetooth(struct device *dev,
896 struct device_attribute *attr, const char *buf,
897 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100898{
Corentin Chary9129d142009-12-01 22:39:41 +0100899 struct asus_laptop *asus = dev_get_drvdata(dev);
900
Corentin Charyd99b5772010-01-22 21:20:57 +0100901 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100902}
903
Corentin Chary78127b42007-01-26 14:04:49 +0100904/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100905 * Wimax
906 */
907static int asus_wimax_set(struct asus_laptop *asus, int status)
908{
909 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
910 pr_warning("Error setting wimax status to %d", status);
911 return -EIO;
912 }
913 return 0;
914}
915
916static ssize_t show_wimax(struct device *dev,
917 struct device_attribute *attr, char *buf)
918{
919 struct asus_laptop *asus = dev_get_drvdata(dev);
920
921 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
922}
923
924static ssize_t store_wimax(struct device *dev,
925 struct device_attribute *attr, const char *buf,
926 size_t count)
927{
928 struct asus_laptop *asus = dev_get_drvdata(dev);
929
930 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
931}
932
933/*
934 * Wwan
935 */
936static int asus_wwan_set(struct asus_laptop *asus, int status)
937{
938 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
939 pr_warning("Error setting wwan status to %d", status);
940 return -EIO;
941 }
942 return 0;
943}
944
945static ssize_t show_wwan(struct device *dev,
946 struct device_attribute *attr, char *buf)
947{
948 struct asus_laptop *asus = dev_get_drvdata(dev);
949
950 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
951}
952
953static ssize_t store_wwan(struct device *dev,
954 struct device_attribute *attr, const char *buf,
955 size_t count)
956{
957 struct asus_laptop *asus = dev_get_drvdata(dev);
958
959 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
960}
961
962/*
Corentin Chary78127b42007-01-26 14:04:49 +0100963 * Display
964 */
Corentin Chary4d441512010-01-13 22:26:24 +0100965static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +0100966{
967 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +0100968 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200969 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100970 return;
971}
972
Corentin Chary9129d142009-12-01 22:39:41 +0100973static int read_display(struct asus_laptop *asus)
Corentin Chary78127b42007-01-26 14:04:49 +0100974{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400975 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100976 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100977
Corentin Charybe966662009-08-29 10:28:29 +0200978 /*
979 * In most of the case, we know how to set the display, but sometime
980 * we can't read it
981 */
Len Brown8def05f2007-01-30 01:46:43 -0500982 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100983 rv = acpi_evaluate_integer(display_get_handle, NULL,
984 NULL, &value);
985 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200986 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100987 }
988
Corentin Chary060cbce2010-01-28 10:52:40 +0100989 value &= 0x0F; /* needed for some models, shouldn't hurt others */
Corentin Chary78127b42007-01-26 14:04:49 +0100990
991 return value;
992}
Len Brown8def05f2007-01-30 01:46:43 -0500993
Corentin Chary78127b42007-01-26 14:04:49 +0100994/*
995 * Now, *this* one could be more user-friendly, but so far, no-one has
996 * complained. The significance of bits is the same as in store_disp()
997 */
998static ssize_t show_disp(struct device *dev,
999 struct device_attribute *attr, char *buf)
1000{
Corentin Chary9129d142009-12-01 22:39:41 +01001001 struct asus_laptop *asus = dev_get_drvdata(dev);
1002
Corentin Chary2a1fd642010-01-26 21:02:23 +01001003 if (!display_get_handle)
1004 return -ENODEV;
Corentin Chary9129d142009-12-01 22:39:41 +01001005 return sprintf(buf, "%d\n", read_display(asus));
Corentin Chary78127b42007-01-26 14:04:49 +01001006}
1007
1008/*
1009 * Experimental support for display switching. As of now: 1 should activate
1010 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1011 * Any combination (bitwise) of these will suffice. I never actually tested 4
1012 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1013 * for more info.
1014 */
1015static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1016 const char *buf, size_t count)
1017{
Corentin Chary9129d142009-12-01 22:39:41 +01001018 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001019 int rv, value;
1020
1021 rv = parse_arg(buf, count, &value);
1022 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001023 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001024 return rv;
1025}
1026
Corentin Chary8b857352007-01-26 14:04:58 +01001027/*
1028 * Light Sens
1029 */
Corentin Chary4d441512010-01-13 22:26:24 +01001030static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001031{
Corentin Charyd99b5772010-01-22 21:20:57 +01001032 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001033 pr_warning("Error setting light sensor switch\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001034 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001035}
1036
1037static ssize_t show_lssw(struct device *dev,
1038 struct device_attribute *attr, char *buf)
1039{
Corentin Chary9129d142009-12-01 22:39:41 +01001040 struct asus_laptop *asus = dev_get_drvdata(dev);
1041
Corentin Chary50a90c42009-11-30 21:55:12 +01001042 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001043}
1044
1045static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1046 const char *buf, size_t count)
1047{
Corentin Chary9129d142009-12-01 22:39:41 +01001048 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001049 int rv, value;
1050
1051 rv = parse_arg(buf, count, &value);
1052 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001053 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001054
1055 return rv;
1056}
1057
Corentin Chary4d441512010-01-13 22:26:24 +01001058static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001059{
Corentin Charyd99b5772010-01-22 21:20:57 +01001060 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001061 pr_warning("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001062 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001063}
1064
1065static ssize_t show_lslvl(struct device *dev,
1066 struct device_attribute *attr, char *buf)
1067{
Corentin Chary9129d142009-12-01 22:39:41 +01001068 struct asus_laptop *asus = dev_get_drvdata(dev);
1069
Corentin Chary50a90c42009-11-30 21:55:12 +01001070 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001071}
1072
1073static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1074 const char *buf, size_t count)
1075{
Corentin Chary9129d142009-12-01 22:39:41 +01001076 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001077 int rv, value;
1078
1079 rv = parse_arg(buf, count, &value);
1080 if (rv > 0) {
1081 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1082 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001083 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001084 }
1085
1086 return rv;
1087}
1088
Corentin Charye539c2f2007-05-06 14:47:06 +02001089/*
1090 * GPS
1091 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001092static int asus_gps_status(struct asus_laptop *asus)
1093{
1094 unsigned long long status;
1095 acpi_status rv = AE_OK;
1096
Corentin Charyd99b5772010-01-22 21:20:57 +01001097 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1098 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001099 if (ACPI_FAILURE(rv)) {
1100 pr_warning("Error reading GPS status\n");
1101 return -ENODEV;
1102 }
1103 return !!status;
1104}
1105
1106static int asus_gps_switch(struct asus_laptop *asus, int status)
1107{
Corentin Charyd99b5772010-01-22 21:20:57 +01001108 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001109
Corentin Charyd99b5772010-01-22 21:20:57 +01001110 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001111 return -ENODEV;
1112 return 0;
1113}
1114
Corentin Charye539c2f2007-05-06 14:47:06 +02001115static ssize_t show_gps(struct device *dev,
1116 struct device_attribute *attr, char *buf)
1117{
Corentin Chary9129d142009-12-01 22:39:41 +01001118 struct asus_laptop *asus = dev_get_drvdata(dev);
1119
Corentin Chary6358bf22010-01-13 21:55:44 +01001120 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001121}
1122
1123static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1124 const char *buf, size_t count)
1125{
Corentin Chary060cbce2010-01-28 10:52:40 +01001126 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001127 int rv, value;
1128 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001129
Corentin Chary6358bf22010-01-13 21:55:44 +01001130 rv = parse_arg(buf, count, &value);
1131 if (rv <= 0)
1132 return -EINVAL;
1133 ret = asus_gps_switch(asus, !!value);
1134 if (ret)
1135 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001136 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001137 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001138}
1139
Corentin Chary034ce902009-01-20 16:17:43 +01001140/*
Corentin Chary18e13112010-01-25 23:29:24 +01001141 * rfkill
1142 */
1143static int asus_gps_rfkill_set(void *data, bool blocked)
1144{
Corentin Chary23f45c32010-08-24 09:30:46 +02001145 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001146
Corentin Chary23f45c32010-08-24 09:30:46 +02001147 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001148}
1149
1150static const struct rfkill_ops asus_gps_rfkill_ops = {
1151 .set_block = asus_gps_rfkill_set,
1152};
1153
1154static void asus_rfkill_exit(struct asus_laptop *asus)
1155{
1156 if (asus->gps_rfkill) {
1157 rfkill_unregister(asus->gps_rfkill);
1158 rfkill_destroy(asus->gps_rfkill);
1159 asus->gps_rfkill = NULL;
1160 }
1161}
1162
1163static int asus_rfkill_init(struct asus_laptop *asus)
1164{
1165 int result;
1166
1167 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1168 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1169 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1170 return 0;
1171
1172 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1173 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001174 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001175 if (!asus->gps_rfkill)
1176 return -EINVAL;
1177
1178 result = rfkill_register(asus->gps_rfkill);
1179 if (result) {
1180 rfkill_destroy(asus->gps_rfkill);
1181 asus->gps_rfkill = NULL;
1182 }
1183
1184 return result;
1185}
1186
1187/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001188 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001189 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001190static void asus_input_notify(struct asus_laptop *asus, int event)
1191{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001192 if (asus->inputdev)
1193 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001194}
1195
1196static int asus_input_init(struct asus_laptop *asus)
1197{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001198 struct input_dev *input;
1199 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001200
Corentin Chary66a71dd2010-01-25 22:50:11 +01001201 input = input_allocate_device();
1202 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001203 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001204 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001205 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001206 input->name = "Asus Laptop extra buttons";
1207 input->phys = ASUS_LAPTOP_FILE "/input0";
1208 input->id.bustype = BUS_HOST;
1209 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001210
Corentin Chary66a71dd2010-01-25 22:50:11 +01001211 error = sparse_keymap_setup(input, asus_keymap, NULL);
1212 if (error) {
1213 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001214 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001215 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001216 error = input_register_device(input);
1217 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001218 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001219 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001220 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001221
1222 asus->inputdev = input;
1223 return 0;
1224
Axel Lin45036ae2010-07-05 15:29:00 +08001225err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001226 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001227err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001228 input_free_device(input);
1229 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001230}
1231
1232static void asus_input_exit(struct asus_laptop *asus)
1233{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001234 if (asus->inputdev) {
1235 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001236 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001237 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001238 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001239}
1240
1241/*
1242 * ACPI driver
1243 */
Corentin Chary600ad522009-11-30 21:42:42 +01001244static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001245{
Corentin Chary9129d142009-12-01 22:39:41 +01001246 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001247 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001248
Corentin Chary6b7091e2007-01-26 14:04:45 +01001249 /*
1250 * We need to tell the backlight device when the backlight power is
1251 * switched
1252 */
Corentin Chary3e68ae72010-01-13 22:10:39 +01001253 if (event == ATKD_LCD_ON)
Corentin Chary9129d142009-12-01 22:39:41 +01001254 lcd_blank(asus, FB_BLANK_UNBLANK);
Corentin Chary3e68ae72010-01-13 22:10:39 +01001255 else if (event == ATKD_LCD_OFF)
Corentin Chary9129d142009-12-01 22:39:41 +01001256 lcd_blank(asus, FB_BLANK_POWERDOWN);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001257
Corentin Chary619d8b12009-11-28 10:35:37 +01001258 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001259 count = asus->event_count[event % 128]++;
1260 acpi_bus_generate_proc_event(asus->device, event, count);
1261 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1262 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001263 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001264
Corentin Charya539df52010-01-25 22:53:21 +01001265 /* Brightness events are special */
1266 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1267
1268 /* Ignore them completely if the acpi video driver is used */
1269 if (asus->backlight_device != NULL) {
1270 /* Update the backlight device. */
1271 asus_backlight_notify(asus);
1272 }
1273 return ;
1274 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001275 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001276}
1277
Corentin Chary2a1fd642010-01-26 21:02:23 +01001278static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1279static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001280static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1281 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001282static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1283static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001284static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
1285static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1286static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1287static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1288static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1289
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001290static struct attribute *asus_attributes[] = {
1291 &dev_attr_infos.attr,
1292 &dev_attr_wlan.attr,
1293 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001294 &dev_attr_wimax.attr,
1295 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001296 &dev_attr_display.attr,
1297 &dev_attr_ledd.attr,
1298 &dev_attr_ls_level.attr,
1299 &dev_attr_ls_switch.attr,
1300 &dev_attr_gps.attr,
1301 NULL
1302};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001303
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001304static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1305 struct attribute *attr,
1306 int idx)
1307{
1308 struct device *dev = container_of(kobj, struct device, kobj);
1309 struct platform_device *pdev = to_platform_device(dev);
1310 struct asus_laptop *asus = platform_get_drvdata(pdev);
1311 acpi_handle handle = asus->handle;
1312 bool supported;
1313
1314 if (attr == &dev_attr_wlan.attr) {
1315 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1316
1317 } else if (attr == &dev_attr_bluetooth.attr) {
1318 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1319
1320 } else if (attr == &dev_attr_display.attr) {
1321 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1322
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001323 } else if (attr == &dev_attr_wimax.attr) {
1324 supported =
1325 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1326
1327 } else if (attr == &dev_attr_wwan.attr) {
1328 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1329
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001330 } else if (attr == &dev_attr_ledd.attr) {
1331 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1332
1333 } else if (attr == &dev_attr_ls_switch.attr ||
1334 attr == &dev_attr_ls_level.attr) {
1335 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
1336 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1337
1338 } else if (attr == &dev_attr_gps.attr) {
1339 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1340 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1341 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1342 } else {
1343 supported = true;
1344 }
1345
1346 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001347}
1348
Corentin Chary2a1fd642010-01-26 21:02:23 +01001349
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001350static const struct attribute_group asus_attr_group = {
1351 .is_visible = asus_sysfs_is_visible,
1352 .attrs = asus_attributes,
1353};
Corentin Chary85091b72007-01-26 14:04:30 +01001354
Corentin Chary9129d142009-12-01 22:39:41 +01001355static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001356{
Corentin Chary71e687d2010-08-24 09:30:44 +02001357 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001358
Corentin Chary50a90c42009-11-30 21:55:12 +01001359 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1360 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001361 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001362 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001363
Corentin Chary71e687d2010-08-24 09:30:44 +02001364 result = platform_device_add(asus->platform_device);
1365 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001366 goto fail_platform_device;
1367
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001368 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1369 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001370 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001371 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001372
Corentin Chary600ad522009-11-30 21:42:42 +01001373 return 0;
1374
1375fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001376 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001377fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001378 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001379 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001380}
1381
Corentin Chary9129d142009-12-01 22:39:41 +01001382static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001383{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001384 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001385 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001386}
1387
1388static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001389 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001390 .name = ASUS_LAPTOP_FILE,
1391 .owner = THIS_MODULE,
1392 }
Corentin Chary85091b72007-01-26 14:04:30 +01001393};
1394
Len Brown8def05f2007-01-30 01:46:43 -05001395static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001396 char **paths, int num_paths)
1397{
1398 int i;
1399 acpi_status status;
1400
1401 for (i = 0; i < num_paths; i++) {
1402 status = acpi_get_handle(NULL, paths[i], handle);
1403 if (ACPI_SUCCESS(status))
1404 return 0;
1405 }
1406
1407 *handle = NULL;
1408 return -ENODEV;
1409}
1410
1411#define ASUS_HANDLE_INIT(object) \
1412 asus_handle_init(#object, &object##_handle, object##_paths, \
1413 ARRAY_SIZE(object##_paths))
1414
Corentin Chary85091b72007-01-26 14:04:30 +01001415/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001416 * This function is used to initialize the context with right values. In this
1417 * method, we can make all the detection we want, and modify the asus_laptop
1418 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001419 */
Corentin Chary7c247642009-11-30 22:13:54 +01001420static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001421{
1422 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001423 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001424 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001425 char *string = NULL;
1426 acpi_status status;
1427
1428 /*
1429 * Get DSDT headers early enough to allow for differentiating between
1430 * models, but late enough to allow acpi_bus_register_driver() to fail
1431 * before doing anything ACPI-specific. Should we encounter a machine,
1432 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001433 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001434 */
Corentin Chary7c247642009-11-30 22:13:54 +01001435 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001436 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001437 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001438
1439 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001440 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001441 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001442 return -ENODEV;
1443 }
1444
1445 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001446 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001447 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001448 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001449 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001450 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001451 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001452 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001453
Corentin Chary185e5af2007-03-11 10:27:33 +01001454 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001455 if (write_acpi_int(asus->handle, "CWAP", wapf))
1456 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001457 /*
1458 * Try to match the object returned by INIT to the specific model.
1459 * Handle every possible object (or the lack of thereof) the DSDT
1460 * writers might throw at us. When in trouble, we pass NULL to
1461 * asus_model_match() and try something completely different.
1462 */
1463 if (buffer.pointer) {
1464 model = buffer.pointer;
1465 switch (model->type) {
1466 case ACPI_TYPE_STRING:
1467 string = model->string.pointer;
1468 break;
1469 case ACPI_TYPE_BUFFER:
1470 string = model->buffer.pointer;
1471 break;
1472 default:
1473 string = "";
1474 break;
1475 }
1476 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001477 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001478 if (!asus->name) {
1479 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001480 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001481 }
Corentin Chary85091b72007-01-26 14:04:30 +01001482
Len Brown8def05f2007-01-30 01:46:43 -05001483 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001484 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001485
Corentin Chary4564de12007-01-26 14:04:40 +01001486 /*
1487 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001488 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1489 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001490 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001491 */
Corentin Chary9a816852007-03-11 10:25:38 +01001492 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001493 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001494 if (!ACPI_FAILURE(status))
1495 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001496
Corentin Charyd99b5772010-01-22 21:20:57 +01001497 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001498 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001499
Corentin Charyd99b5772010-01-22 21:20:57 +01001500 /* Scheduled for removal */
Corentin Chary6b7091e2007-01-26 14:04:45 +01001501 ASUS_HANDLE_INIT(lcd_switch);
Corentin Chary78127b42007-01-26 14:04:49 +01001502 ASUS_HANDLE_INIT(display_get);
1503
Corentin Chary85091b72007-01-26 14:04:30 +01001504 kfree(model);
1505
1506 return AE_OK;
1507}
1508
Corentin Chary9129d142009-12-01 22:39:41 +01001509static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001510{
1511 int result = 0;
1512
Corentin Chary50a90c42009-11-30 21:55:12 +01001513 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001514 if (result)
1515 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001516 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001517 pr_err("Hotkey device not present, aborting\n");
1518 return -ENODEV;
1519 }
1520
Corentin Chary7c247642009-11-30 22:13:54 +01001521 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001522 if (result)
1523 return result;
1524
Corentin Chary600ad522009-11-30 21:42:42 +01001525 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001526 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001527 asus_bluetooth_set(asus, !!bluetooth_status);
1528
Corentin Charyd0930a22010-01-17 17:21:13 +01001529 if (wlan_status >= 0)
1530 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001531
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001532 if (wimax_status >= 0)
1533 asus_wimax_set(asus, !!wimax_status);
1534
1535 if (wwan_status >= 0)
1536 asus_wwan_set(asus, !!wwan_status);
1537
Corentin Chary600ad522009-11-30 21:42:42 +01001538 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001539 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001540 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001541
1542 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001543 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001544
1545 /* Set initial values of light sensor and level */
Corentin Charybe4ee822009-12-06 16:27:09 +01001546 asus->light_switch = 0; /* Default to light sensor disabled */
1547 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001548
Corentin Charyd99b5772010-01-22 21:20:57 +01001549 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1550 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001551 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001552 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001553 }
Corentin Chary600ad522009-11-30 21:42:42 +01001554
Corentin Chary47ee0e92010-01-24 11:17:15 +01001555 asus->lcd_state = 1; /* LCD should be on when the module load */
Corentin Chary600ad522009-11-30 21:42:42 +01001556 return result;
1557}
1558
Corentin Chary71e687d2010-08-24 09:30:44 +02001559static bool asus_device_present;
1560
Corentin Chary600ad522009-11-30 21:42:42 +01001561static int __devinit asus_acpi_add(struct acpi_device *device)
1562{
Corentin Chary9129d142009-12-01 22:39:41 +01001563 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001564 int result;
1565
1566 pr_notice("Asus Laptop Support version %s\n",
1567 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001568 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1569 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001570 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001571 asus->handle = device->handle;
1572 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1573 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1574 device->driver_data = asus;
1575 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001576
Corentin Chary9129d142009-12-01 22:39:41 +01001577 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001578 if (result)
1579 goto fail_platform;
1580
1581 /*
1582 * Register the platform device first. It is used as a parent for the
1583 * sub-devices below.
1584 */
Corentin Chary9129d142009-12-01 22:39:41 +01001585 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001586 if (result)
1587 goto fail_platform;
1588
1589 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001590 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001591 if (result)
1592 goto fail_backlight;
1593 } else
1594 pr_info("Backlight controlled by ACPI video driver\n");
1595
Corentin Chary9129d142009-12-01 22:39:41 +01001596 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001597 if (result)
1598 goto fail_input;
1599
Corentin Chary9129d142009-12-01 22:39:41 +01001600 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001601 if (result)
1602 goto fail_led;
1603
Corentin Chary18e13112010-01-25 23:29:24 +01001604 result = asus_rfkill_init(asus);
1605 if (result)
1606 goto fail_rfkill;
1607
Corentin Chary600ad522009-11-30 21:42:42 +01001608 asus_device_present = true;
1609 return 0;
1610
Corentin Chary18e13112010-01-25 23:29:24 +01001611fail_rfkill:
1612 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001613fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001614 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001615fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001616 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001617fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001618 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001619fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001620 kfree(asus->name);
1621 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001622
1623 return result;
1624}
1625
1626static int asus_acpi_remove(struct acpi_device *device, int type)
1627{
Corentin Chary9129d142009-12-01 22:39:41 +01001628 struct asus_laptop *asus = acpi_driver_data(device);
1629
1630 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001631 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001632 asus_led_exit(asus);
1633 asus_input_exit(asus);
1634 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001635
Corentin Chary50a90c42009-11-30 21:55:12 +01001636 kfree(asus->name);
1637 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001638 return 0;
1639}
1640
1641static const struct acpi_device_id asus_device_ids[] = {
1642 {"ATK0100", 0},
1643 {"ATK0101", 0},
1644 {"", 0},
1645};
1646MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1647
1648static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001649 .name = ASUS_LAPTOP_NAME,
1650 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001651 .owner = THIS_MODULE,
1652 .ids = asus_device_ids,
1653 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1654 .ops = {
1655 .add = asus_acpi_add,
1656 .remove = asus_acpi_remove,
1657 .notify = asus_acpi_notify,
1658 },
1659};
1660
Corentin Chary85091b72007-01-26 14:04:30 +01001661static int __init asus_laptop_init(void)
1662{
1663 int result;
1664
Corentin Chary600ad522009-11-30 21:42:42 +01001665 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001666 if (result < 0)
1667 return result;
1668
Corentin Chary600ad522009-11-30 21:42:42 +01001669 result = acpi_bus_register_driver(&asus_acpi_driver);
1670 if (result < 0)
1671 goto fail_acpi_driver;
1672 if (!asus_device_present) {
1673 result = -ENODEV;
1674 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001675 }
Len Brown8def05f2007-01-30 01:46:43 -05001676 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001677
Corentin Chary600ad522009-11-30 21:42:42 +01001678fail_no_device:
1679 acpi_bus_unregister_driver(&asus_acpi_driver);
1680fail_acpi_driver:
1681 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001682 return result;
1683}
1684
Corentin Chary600ad522009-11-30 21:42:42 +01001685static void __exit asus_laptop_exit(void)
1686{
1687 acpi_bus_unregister_driver(&asus_acpi_driver);
1688 platform_driver_unregister(&platform_driver);
1689}
1690
Corentin Chary85091b72007-01-26 14:04:30 +01001691module_init(asus_laptop_init);
1692module_exit(asus_laptop_exit);