blob: 2b9d7b8636e368c6281f63ab71a6a4ea9866b7a5 [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 Charyaf96f872011-02-06 13:27:30 +010053#include <linux/dmi.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010054#include <acpi/acpi_drivers.h>
55#include <acpi/acpi_bus.h>
Corentin Chary85091b72007-01-26 14:04:30 +010056
Corentin Chary91687cc2009-11-28 10:32:34 +010057#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010058
Corentin Chary50a90c42009-11-30 21:55:12 +010059#define ASUS_LAPTOP_NAME "Asus Laptop Support"
60#define ASUS_LAPTOP_CLASS "hotkey"
61#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
62#define ASUS_LAPTOP_FILE KBUILD_MODNAME
63#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
Corentin Chary85091b72007-01-26 14:04:30 +010064
Corentin Chary85091b72007-01-26 14:04:30 +010065MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010066MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010067MODULE_LICENSE("GPL");
68
Corentin Charybe966662009-08-29 10:28:29 +020069/*
70 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010071 * The significance of values is yet to be found, but
72 * most of the time:
73 * 0x0 will do nothing
74 * 0x1 will allow to control the device with Fn+Fx key.
75 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
76 * 0x5 like 0x1 or 0x4
77 * So, if something doesn't work as you want, just try other values =)
78 */
79static uint wapf = 1;
Axel Linc26d85c2010-07-20 15:19:55 -070080module_param(wapf, uint, 0444);
Corentin Chary185e5af2007-03-11 10:27:33 +010081MODULE_PARM_DESC(wapf, "WAPF value");
82
Dan Carpenter668f4a02010-04-06 13:44:29 +030083static int wlan_status = 1;
84static int bluetooth_status = 1;
Corentin Charyba1ff5b2010-11-14 17:40:12 +010085static int wimax_status = -1;
86static int wwan_status = -1;
Corentin Chary0e875f42010-01-10 20:49:26 +010087
Axel Linc26d85c2010-07-20 15:19:55 -070088module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010089MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010090 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
91 "default is 1");
92
Axel Linc26d85c2010-07-20 15:19:55 -070093module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010094MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
95 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
96 "default is 1");
97
Corentin Charyba1ff5b2010-11-14 17:40:12 +010098module_param(wimax_status, int, 0444);
99MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
100 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
101 "default is 1");
102
103module_param(wwan_status, int, 0444);
104MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
105 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
106 "default is 1");
107
Corentin Charybe4ee822009-12-06 16:27:09 +0100108/*
109 * Some events we use, same for all Asus
110 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100111#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
112#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100113#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100114#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100115#define ATKD_LCD_ON 0x33
116#define ATKD_LCD_OFF 0x34
117
118/*
119 * Known bits returned by \_SB.ATKD.HWRS
120 */
121#define WL_HWRS 0x80
122#define BT_HWRS 0x100
123
124/*
125 * Flags for hotk status
126 * WL_ON and BT_ON are also used for wireless_status()
127 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100128#define WL_RSTS 0x01 /* internal Wifi */
129#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100130#define WM_RSTS 0x08 /* internal wimax */
131#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100132
Corentin Charybe18cda2007-01-26 14:04:35 +0100133/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100134#define METHOD_MLED "MLED"
135#define METHOD_TLED "TLED"
136#define METHOD_RLED "RLED" /* W1JC */
137#define METHOD_PLED "PLED" /* A7J */
138#define METHOD_GLED "GLED" /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100139
Corentin Chary722ad972007-01-26 14:04:55 +0100140/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100141#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100142
Corentin Charybe966662009-08-29 10:28:29 +0200143/*
144 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100145 * WLED and BLED are not handled like other XLED, because in some dsdt
146 * they also control the WLAN/Bluetooth device.
147 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100148#define METHOD_WLAN "WLED"
149#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100150
151/* WWAN and WIMAX */
152#define METHOD_WWAN "GSMC"
153#define METHOD_WIMAX "WMXC"
154
Corentin Charyd99b5772010-01-22 21:20:57 +0100155#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100156
Corentin Chary6b7091e2007-01-26 14:04:45 +0100157/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100158#define METHOD_BRIGHTNESS_SET "SPLV"
159#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100160
161/* Backlight */
Corentin Chary060cbce2010-01-28 10:52:40 +0100162static acpi_handle lcd_switch_handle;
Corentin Chary16721512010-03-02 22:24:12 +0100163static char *lcd_switch_paths[] = {
Corentin Chary060cbce2010-01-28 10:52:40 +0100164 "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
165 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
166 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
167 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
168 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
169 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
170 "\\_SB.PCI0.PX40.Q10", /* S1x */
171 "\\Q10"}; /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100172
Corentin Chary78127b42007-01-26 14:04:49 +0100173/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100174#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100175
176static acpi_handle display_get_handle;
Corentin Chary16721512010-03-02 22:24:12 +0100177static char *display_get_paths[] = {
Corentin Chary060cbce2010-01-28 10:52:40 +0100178 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
179 "\\_SB.PCI0.P0P1.VGA.GETD",
180 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
181 "\\_SB.PCI0.P0P2.VGA.GETD",
182 /* A6V A6Q */
183 "\\_SB.PCI0.P0P3.VGA.GETD",
184 /* A6T, A6M */
185 "\\_SB.PCI0.P0PA.VGA.GETD",
186 /* L3C */
187 "\\_SB.PCI0.PCI1.VGAC.NMAP",
188 /* Z96F */
189 "\\_SB.PCI0.VGA.GETD",
190 /* A2D */
191 "\\ACTD",
192 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
193 "\\ADVG",
194 /* P30 */
195 "\\DNXT",
196 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
197 "\\INFB",
198 /* A3F A6F A3N A3L M6N W3N W6A */
199 "\\SSTE"};
Corentin Chary78127b42007-01-26 14:04:49 +0100200
Corentin Charyd99b5772010-01-22 21:20:57 +0100201#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
202#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100203
Corentin Charye539c2f2007-05-06 14:47:06 +0200204/* GPS */
205/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100206#define METHOD_GPS_ON "SDON"
207#define METHOD_GPS_OFF "SDOF"
208#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200209
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000210/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100211#define METHOD_KBD_LIGHT_SET "SLKB"
212#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000213
Corentin Chary85091b72007-01-26 14:04:30 +0100214/*
Corentin Chary9129d142009-12-01 22:39:41 +0100215 * Define a specific led structure to keep the main structure clean
216 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100217struct asus_led {
218 int wk;
219 struct work_struct work;
220 struct led_classdev led;
221 struct asus_laptop *asus;
222 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100223};
224
225/*
Corentin Chary85091b72007-01-26 14:04:30 +0100226 * This is the main structure, we can use it to store anything interesting
227 * about the hotk device
228 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100229struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200230 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100231
Corentin Chary7c247642009-11-30 22:13:54 +0100232 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100233 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100234 struct acpi_device *device; /* the device we are in */
235 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100236
Corentin Chary7c247642009-11-30 22:13:54 +0100237 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100238 struct key_entry *keymap;
239
Corentin Charyaee0afb2010-01-26 21:01:34 +0100240 struct asus_led mled;
241 struct asus_led tled;
242 struct asus_led rled;
243 struct asus_led pled;
244 struct asus_led gled;
245 struct asus_led kled;
246 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100247
Corentin Charyaa9df932010-01-13 21:49:10 +0100248 int wireless_status;
249 bool have_rsts;
Corentin Chary3e68ae72010-01-13 22:10:39 +0100250 int lcd_state;
Corentin Charyaa9df932010-01-13 21:49:10 +0100251
Corentin Chary18e13112010-01-25 23:29:24 +0100252 struct rfkill *gps_rfkill;
253
Corentin Charybe966662009-08-29 10:28:29 +0200254 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200255 u32 ledd_status; /* status of the LED display */
256 u8 light_level; /* light sensor level */
257 u8 light_switch; /* light sensor switch value */
258 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100259};
260
Corentin Chary9129d142009-12-01 22:39:41 +0100261static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100262 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100263 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
264 {KE_KEY, 0x05, { KEY_WLAN } },
265 {KE_KEY, 0x08, { KEY_F13 } },
266 {KE_KEY, 0x17, { KEY_ZOOM } },
267 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100268 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100269 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
270 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
271 {KE_KEY, 0x32, { KEY_MUTE } },
272 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
273 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
274 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
275 {KE_KEY, 0x41, { KEY_NEXTSONG } },
276 {KE_KEY, 0x43, { KEY_STOPCD } },
277 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
278 {KE_KEY, 0x4c, { KEY_MEDIA } },
279 {KE_KEY, 0x50, { KEY_EMAIL } },
280 {KE_KEY, 0x51, { KEY_WWW } },
281 {KE_KEY, 0x55, { KEY_CALC } },
282 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
283 {KE_KEY, 0x5D, { KEY_WLAN } },
284 {KE_KEY, 0x5E, { KEY_WLAN } },
285 {KE_KEY, 0x5F, { KEY_WLAN } },
286 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
287 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
288 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
289 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
290 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d72010-01-17 17:37:19 +0100291 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
292 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100293 {KE_KEY, 0x82, { KEY_CAMERA } },
294 {KE_KEY, 0x88, { KEY_WLAN } },
295 {KE_KEY, 0x8A, { KEY_PROG1 } },
296 {KE_KEY, 0x95, { KEY_MEDIA } },
297 {KE_KEY, 0x99, { KEY_PHONE } },
298 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
299 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200300 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100301 {KE_END, 0},
302};
303
Corentin Chary66a71dd2010-01-25 22:50:11 +0100304
Corentin Chary85091b72007-01-26 14:04:30 +0100305/*
306 * This function evaluates an ACPI method, given an int as parameter, the
307 * method is searched within the scope of the handle, can be NULL. The output
308 * of the method is written is output, which can also be NULL
309 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100310 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100311 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100312static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
313 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100314{
Corentin Charybe966662009-08-29 10:28:29 +0200315 struct acpi_object_list params; /* list of input parameters (an int) */
316 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100317 acpi_status status;
318
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100319 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700320 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100321
Corentin Chary85091b72007-01-26 14:04:30 +0100322 params.count = 1;
323 params.pointer = &in_obj;
324 in_obj.type = ACPI_TYPE_INTEGER;
325 in_obj.integer.value = val;
326
327 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100328 if (status == AE_OK)
329 return 0;
330 else
331 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100332}
333
Corentin Charyd8c67322009-11-28 10:27:51 +0100334static int write_acpi_int(acpi_handle handle, const char *method, int val)
335{
336 return write_acpi_int_ret(handle, method, val, NULL);
337}
338
Corentin Charyd99b5772010-01-22 21:20:57 +0100339static int acpi_check_handle(acpi_handle handle, const char *method,
340 acpi_handle *ret)
341{
342 acpi_status status;
343
344 if (method == NULL)
345 return -ENODEV;
346
347 if (ret)
348 status = acpi_get_handle(handle, (char *)method,
349 ret);
350 else {
351 acpi_handle dummy;
352
353 status = acpi_get_handle(handle, (char *)method,
354 &dummy);
355 }
356
357 if (status != AE_OK) {
358 if (ret)
359 pr_warning("Error finding %s\n", method);
360 return -ENODEV;
361 }
362 return 0;
363}
364
Corentin Chary17e78f62010-01-13 22:21:33 +0100365/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100366static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100367 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100368{
Corentin Charyd99b5772010-01-22 21:20:57 +0100369 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100370 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100371 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100372 value = !value + 1;
373 else
374 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100375
Corentin Charye5593bf2010-01-17 17:20:11 +0100376 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100377}
378
Corentin Charybe4ee822009-12-06 16:27:09 +0100379/*
380 * LEDs
381 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100382/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100383static void asus_led_cdev_set(struct led_classdev *led_cdev,
384 enum led_brightness value)
385{
386 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
387 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100388
Corentin Charyaee0afb2010-01-26 21:01:34 +0100389 led->wk = !!value;
390 queue_work(asus->led_workqueue, &led->work);
391}
392
393static void asus_led_cdev_update(struct work_struct *work)
394{
395 struct asus_led *led = container_of(work, struct asus_led, work);
396 struct asus_laptop *asus = led->asus;
397
398 asus_led_set(asus, led->method, led->wk);
399}
400
401static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
402{
403 return led_cdev->brightness;
404}
Corentin Charybe18cda2007-01-26 14:04:35 +0100405
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000406/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100407 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000408 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100409static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000410{
411 unsigned long long kblv;
412 struct acpi_object_list params;
413 union acpi_object in_obj;
414 acpi_status rv;
415
416 params.count = 1;
417 params.pointer = &in_obj;
418 in_obj.type = ACPI_TYPE_INTEGER;
419 in_obj.integer.value = 2;
420
Corentin Charyd99b5772010-01-22 21:20:57 +0100421 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
422 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000423 if (ACPI_FAILURE(rv)) {
424 pr_warning("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100425 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000426 }
427 return kblv;
428}
429
Corentin Chary4d441512010-01-13 22:26:24 +0100430static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000431{
432 if (kblv > 0)
433 kblv = (1 << 7) | (kblv & 0x7F);
434 else
435 kblv = 0;
436
Corentin Charyd99b5772010-01-22 21:20:57 +0100437 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000438 pr_warning("Keyboard LED display write failed\n");
439 return -EINVAL;
440 }
441 return 0;
442}
443
Corentin Charyaee0afb2010-01-26 21:01:34 +0100444static void asus_kled_cdev_set(struct led_classdev *led_cdev,
445 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000446{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100447 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
448 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100449
Corentin Chary060cbce2010-01-28 10:52:40 +0100450 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100451 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000452}
453
Corentin Charyaee0afb2010-01-26 21:01:34 +0100454static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000455{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100456 struct asus_led *led = container_of(work, struct asus_led, work);
457 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100458
Corentin Charyaee0afb2010-01-26 21:01:34 +0100459 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000460}
461
Corentin Charyaee0afb2010-01-26 21:01:34 +0100462static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000463{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100464 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
465 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100466
467 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000468}
469
Corentin Charybe4ee822009-12-06 16:27:09 +0100470static void asus_led_exit(struct asus_laptop *asus)
471{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100472 if (asus->mled.led.dev)
473 led_classdev_unregister(&asus->mled.led);
474 if (asus->tled.led.dev)
475 led_classdev_unregister(&asus->tled.led);
476 if (asus->pled.led.dev)
477 led_classdev_unregister(&asus->pled.led);
478 if (asus->rled.led.dev)
479 led_classdev_unregister(&asus->rled.led);
480 if (asus->gled.led.dev)
481 led_classdev_unregister(&asus->gled.led);
482 if (asus->kled.led.dev)
483 led_classdev_unregister(&asus->kled.led);
484 if (asus->led_workqueue) {
485 destroy_workqueue(asus->led_workqueue);
486 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100487 }
488}
489
490/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100491static int asus_led_register(struct asus_laptop *asus,
492 struct asus_led *led,
493 const char *name, const char *method)
494{
495 struct led_classdev *led_cdev = &led->led;
496
497 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100498 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100499
500 led->asus = asus;
501 led->method = method;
502
503 INIT_WORK(&led->work, asus_led_cdev_update);
504 led_cdev->name = name;
505 led_cdev->brightness_set = asus_led_cdev_set;
506 led_cdev->brightness_get = asus_led_cdev_get;
507 led_cdev->max_brightness = 1;
508 return led_classdev_register(&asus->platform_device->dev, led_cdev);
509}
Corentin Charybe4ee822009-12-06 16:27:09 +0100510
511static int asus_led_init(struct asus_laptop *asus)
512{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100513 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100514
515 /*
516 * Functions that actually update the LED's are called from a
517 * workqueue. By doing this as separate work rather than when the LED
518 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
519 * potentially bad time, such as a timer interrupt.
520 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100521 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
522 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100523 return -ENOMEM;
524
Corentin Charyaee0afb2010-01-26 21:01:34 +0100525 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
526 if (r)
527 goto error;
528 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
529 if (r)
530 goto error;
531 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
532 if (r)
533 goto error;
534 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
535 if (r)
536 goto error;
537 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
538 if (r)
539 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100540 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100541 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
542 struct asus_led *led = &asus->kled;
543 struct led_classdev *cdev = &led->led;
544
545 led->asus = asus;
546
547 INIT_WORK(&led->work, asus_kled_cdev_update);
548 cdev->name = "asus::kbd_backlight";
549 cdev->brightness_set = asus_kled_cdev_set;
550 cdev->brightness_get = asus_kled_cdev_get;
551 cdev->max_brightness = 3;
552 r = led_classdev_register(&asus->platform_device->dev, cdev);
553 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100554error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100555 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100556 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100557 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100558}
559
560/*
561 * Backlight device
562 */
Corentin Chary3e68ae72010-01-13 22:10:39 +0100563static int asus_lcd_status(struct asus_laptop *asus)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100564{
Corentin Chary3e68ae72010-01-13 22:10:39 +0100565 return asus->lcd_state;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100566}
567
Corentin Chary3e68ae72010-01-13 22:10:39 +0100568static int asus_lcd_set(struct asus_laptop *asus, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100569{
570 int lcd = 0;
571 acpi_status status = 0;
572
Corentin Chary3e68ae72010-01-13 22:10:39 +0100573 lcd = !!value;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100574
Corentin Chary3e68ae72010-01-13 22:10:39 +0100575 if (lcd == asus_lcd_status(asus))
Corentin Chary6b7091e2007-01-26 14:04:45 +0100576 return 0;
577
Corentin Chary3e68ae72010-01-13 22:10:39 +0100578 if (!lcd_switch_handle)
579 return -ENODEV;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100580
Corentin Chary3e68ae72010-01-13 22:10:39 +0100581 status = acpi_evaluate_object(lcd_switch_handle,
582 NULL, NULL, NULL);
583
584 if (ACPI_FAILURE(status)) {
585 pr_warning("Error switching LCD\n");
586 return -ENODEV;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100587 }
588
Corentin Chary3e68ae72010-01-13 22:10:39 +0100589 asus->lcd_state = lcd;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100590 return 0;
591}
592
Corentin Chary9129d142009-12-01 22:39:41 +0100593static void lcd_blank(struct asus_laptop *asus, int blank)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100594{
Corentin Chary7c247642009-11-30 22:13:54 +0100595 struct backlight_device *bd = asus->backlight_device;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100596
Corentin Chary3e68ae72010-01-13 22:10:39 +0100597 asus->lcd_state = (blank == FB_BLANK_UNBLANK);
598
Len Brown8def05f2007-01-30 01:46:43 -0500599 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000600 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000601 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100602 }
603}
604
Corentin Chary4d441512010-01-13 22:26:24 +0100605static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100606{
Corentin Charyd99b5772010-01-22 21:20:57 +0100607 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400608 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100609 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100610
Corentin Charyd99b5772010-01-22 21:20:57 +0100611 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
612 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100613 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200614 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100615
616 return value;
617}
618
Corentin Chary4d441512010-01-13 22:26:24 +0100619static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100620{
Corentin Charyd99b5772010-01-22 21:20:57 +0100621 struct asus_laptop *asus = bl_get_data(bd);
622
623 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200624 pr_warning("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100625 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100626 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100627 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100628}
629
630static int update_bl_status(struct backlight_device *bd)
631{
Corentin Chary9129d142009-12-01 22:39:41 +0100632 struct asus_laptop *asus = bl_get_data(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100633 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000634 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100635
Corentin Chary4d441512010-01-13 22:26:24 +0100636 rv = asus_set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500637 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100638 return rv;
639
Richard Purdie599a52d2007-02-10 23:07:48 +0000640 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary3e68ae72010-01-13 22:10:39 +0100641 return asus_lcd_set(asus, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100642}
643
Lionel Debrouxacc24722010-11-16 14:14:02 +0100644static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100645 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100646 .update_status = update_bl_status,
647};
648
Corentin Charya539df52010-01-25 22:53:21 +0100649static int asus_backlight_notify(struct asus_laptop *asus)
650{
651 struct backlight_device *bd = asus->backlight_device;
652 int old = bd->props.brightness;
653
654 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
655
656 return old;
657}
658
Corentin Charybe4ee822009-12-06 16:27:09 +0100659static int asus_backlight_init(struct asus_laptop *asus)
660{
661 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500662 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100663
Corentin Chary71e687d2010-08-24 09:30:44 +0200664 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
665 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL) ||
666 !lcd_switch_handle)
667 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500668
Corentin Chary71e687d2010-08-24 09:30:44 +0200669 memset(&props, 0, sizeof(struct backlight_properties));
670 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700671 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100672
Corentin Chary71e687d2010-08-24 09:30:44 +0200673 bd = backlight_device_register(ASUS_LAPTOP_FILE,
674 &asus->platform_device->dev, asus,
675 &asusbl_ops, &props);
676 if (IS_ERR(bd)) {
677 pr_err("Could not register asus backlight device\n");
678 asus->backlight_device = NULL;
679 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100680 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200681
682 asus->backlight_device = bd;
683 bd->props.brightness = asus_read_brightness(bd);
684 bd->props.power = FB_BLANK_UNBLANK;
685 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100686 return 0;
687}
688
689static void asus_backlight_exit(struct asus_laptop *asus)
690{
691 if (asus->backlight_device)
692 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100693 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100694}
695
Corentin Chary85091b72007-01-26 14:04:30 +0100696/*
697 * Platform device handlers
698 */
699
700/*
701 * We write our info in page, we begin at offset off and cannot write more
702 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
703 * number of bytes written in page
704 */
705static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500706 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100707{
Corentin Chary9129d142009-12-01 22:39:41 +0100708 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100709 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400710 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200711 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100712 acpi_status rv = AE_OK;
713
Corentin Chary85091b72007-01-26 14:04:30 +0100714 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100715 * We use the easy way, we don't care of off and count,
716 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100717 */
718
Corentin Chary50a90c42009-11-30 21:55:12 +0100719 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
720 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100721 /*
722 * The SFUN method probably allows the original driver to get the list
723 * of features supported by a given model. For now, 0x0100 or 0x0800
724 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
725 * The significance of others is yet to be found.
726 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100727 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100728 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000729 len += sprintf(page + len, "SFUN value : %#x\n",
730 (uint) temp);
731 /*
732 * The HWRS method return informations about the hardware.
733 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
734 * The significance of others is yet to be found.
735 * If we don't find the method, we assume the device are present.
736 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100737 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000738 if (!ACPI_FAILURE(rv))
739 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100740 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100741 /*
742 * Another value for userspace: the ASYM method returns 0x02 for
743 * battery low and 0x04 for battery critical, its readings tend to be
744 * more accurate than those provided by _BST.
745 * Note: since not all the laptops provide this method, errors are
746 * silently ignored.
747 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100748 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100749 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000750 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100751 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100752 if (asus->dsdt_info) {
753 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100754 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100755 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100756 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100757 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100758 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100759 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100760 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100761 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100762 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100763 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100764 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100765 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100766 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100767 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100768 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
769 }
770
771 return len;
772}
773
774static int parse_arg(const char *buf, unsigned long count, int *val)
775{
776 if (!count)
777 return 0;
778 if (count > 31)
779 return -EINVAL;
780 if (sscanf(buf, "%i", val) != 1)
781 return -EINVAL;
782 return count;
783}
784
Corentin Chary17e78f62010-01-13 22:21:33 +0100785static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
786 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100787 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100788{
789 int rv, value;
790 int out = 0;
791
792 rv = parse_arg(buf, count, &value);
793 if (rv > 0)
794 out = value ? 1 : 0;
795
Corentin Charyd99b5772010-01-22 21:20:57 +0100796 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100797 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100798 return rv;
799}
800
801/*
Corentin Chary722ad972007-01-26 14:04:55 +0100802 * LEDD display
803 */
804static ssize_t show_ledd(struct device *dev,
805 struct device_attribute *attr, char *buf)
806{
Corentin Chary9129d142009-12-01 22:39:41 +0100807 struct asus_laptop *asus = dev_get_drvdata(dev);
808
Corentin Chary50a90c42009-11-30 21:55:12 +0100809 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100810}
811
812static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
813 const char *buf, size_t count)
814{
Corentin Chary9129d142009-12-01 22:39:41 +0100815 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100816 int rv, value;
817
818 rv = parse_arg(buf, count, &value);
819 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700820 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200821 pr_warning("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700822 return -ENODEV;
823 }
824 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100825 }
826 return rv;
827}
828
829/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100830 * Wireless
831 */
832static int asus_wireless_status(struct asus_laptop *asus, int mask)
833{
834 unsigned long long status;
835 acpi_status rv = AE_OK;
836
837 if (!asus->have_rsts)
838 return (asus->wireless_status & mask) ? 1 : 0;
839
Corentin Charyd99b5772010-01-22 21:20:57 +0100840 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
841 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100842 if (ACPI_FAILURE(rv)) {
843 pr_warning("Error reading Wireless status\n");
844 return -EINVAL;
845 }
846 return !!(status & mask);
847}
848
849/*
Corentin Chary4564de12007-01-26 14:04:40 +0100850 * WLAN
851 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100852static int asus_wlan_set(struct asus_laptop *asus, int status)
853{
854 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
855 pr_warning("Error setting wlan status to %d", status);
856 return -EIO;
857 }
858 return 0;
859}
860
Corentin Chary4564de12007-01-26 14:04:40 +0100861static ssize_t show_wlan(struct device *dev,
862 struct device_attribute *attr, char *buf)
863{
Corentin Chary9129d142009-12-01 22:39:41 +0100864 struct asus_laptop *asus = dev_get_drvdata(dev);
865
Corentin Chary17e78f62010-01-13 22:21:33 +0100866 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100867}
868
869static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
870 const char *buf, size_t count)
871{
Corentin Chary9129d142009-12-01 22:39:41 +0100872 struct asus_laptop *asus = dev_get_drvdata(dev);
873
Corentin Charyd99b5772010-01-22 21:20:57 +0100874 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100875}
876
877/*
878 * Bluetooth
879 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100880static int asus_bluetooth_set(struct asus_laptop *asus, int status)
881{
882 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
883 pr_warning("Error setting bluetooth status to %d", status);
884 return -EIO;
885 }
886 return 0;
887}
888
Corentin Chary4564de12007-01-26 14:04:40 +0100889static ssize_t show_bluetooth(struct device *dev,
890 struct device_attribute *attr, char *buf)
891{
Corentin Chary9129d142009-12-01 22:39:41 +0100892 struct asus_laptop *asus = dev_get_drvdata(dev);
893
Corentin Chary17e78f62010-01-13 22:21:33 +0100894 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100895}
896
Len Brown8def05f2007-01-30 01:46:43 -0500897static ssize_t store_bluetooth(struct device *dev,
898 struct device_attribute *attr, const char *buf,
899 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100900{
Corentin Chary9129d142009-12-01 22:39:41 +0100901 struct asus_laptop *asus = dev_get_drvdata(dev);
902
Corentin Charyd99b5772010-01-22 21:20:57 +0100903 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100904}
905
Corentin Chary78127b42007-01-26 14:04:49 +0100906/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100907 * Wimax
908 */
909static int asus_wimax_set(struct asus_laptop *asus, int status)
910{
911 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
912 pr_warning("Error setting wimax status to %d", status);
913 return -EIO;
914 }
915 return 0;
916}
917
918static ssize_t show_wimax(struct device *dev,
919 struct device_attribute *attr, char *buf)
920{
921 struct asus_laptop *asus = dev_get_drvdata(dev);
922
923 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
924}
925
926static ssize_t store_wimax(struct device *dev,
927 struct device_attribute *attr, const char *buf,
928 size_t count)
929{
930 struct asus_laptop *asus = dev_get_drvdata(dev);
931
932 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
933}
934
935/*
936 * Wwan
937 */
938static int asus_wwan_set(struct asus_laptop *asus, int status)
939{
940 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
941 pr_warning("Error setting wwan status to %d", status);
942 return -EIO;
943 }
944 return 0;
945}
946
947static ssize_t show_wwan(struct device *dev,
948 struct device_attribute *attr, char *buf)
949{
950 struct asus_laptop *asus = dev_get_drvdata(dev);
951
952 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
953}
954
955static ssize_t store_wwan(struct device *dev,
956 struct device_attribute *attr, const char *buf,
957 size_t count)
958{
959 struct asus_laptop *asus = dev_get_drvdata(dev);
960
961 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
962}
963
964/*
Corentin Chary78127b42007-01-26 14:04:49 +0100965 * Display
966 */
Corentin Chary4d441512010-01-13 22:26:24 +0100967static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +0100968{
969 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +0100970 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200971 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100972 return;
973}
974
Corentin Chary9129d142009-12-01 22:39:41 +0100975static int read_display(struct asus_laptop *asus)
Corentin Chary78127b42007-01-26 14:04:49 +0100976{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400977 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100978 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100979
Corentin Charybe966662009-08-29 10:28:29 +0200980 /*
981 * In most of the case, we know how to set the display, but sometime
982 * we can't read it
983 */
Len Brown8def05f2007-01-30 01:46:43 -0500984 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100985 rv = acpi_evaluate_integer(display_get_handle, NULL,
986 NULL, &value);
987 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200988 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100989 }
990
Corentin Chary060cbce2010-01-28 10:52:40 +0100991 value &= 0x0F; /* needed for some models, shouldn't hurt others */
Corentin Chary78127b42007-01-26 14:04:49 +0100992
993 return value;
994}
Len Brown8def05f2007-01-30 01:46:43 -0500995
Corentin Chary78127b42007-01-26 14:04:49 +0100996/*
997 * Now, *this* one could be more user-friendly, but so far, no-one has
998 * complained. The significance of bits is the same as in store_disp()
999 */
1000static ssize_t show_disp(struct device *dev,
1001 struct device_attribute *attr, char *buf)
1002{
Corentin Chary9129d142009-12-01 22:39:41 +01001003 struct asus_laptop *asus = dev_get_drvdata(dev);
1004
Corentin Chary2a1fd642010-01-26 21:02:23 +01001005 if (!display_get_handle)
1006 return -ENODEV;
Corentin Chary9129d142009-12-01 22:39:41 +01001007 return sprintf(buf, "%d\n", read_display(asus));
Corentin Chary78127b42007-01-26 14:04:49 +01001008}
1009
1010/*
1011 * Experimental support for display switching. As of now: 1 should activate
1012 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1013 * Any combination (bitwise) of these will suffice. I never actually tested 4
1014 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1015 * for more info.
1016 */
1017static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1018 const char *buf, size_t count)
1019{
Corentin Chary9129d142009-12-01 22:39:41 +01001020 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001021 int rv, value;
1022
1023 rv = parse_arg(buf, count, &value);
1024 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001025 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001026 return rv;
1027}
1028
Corentin Chary8b857352007-01-26 14:04:58 +01001029/*
1030 * Light Sens
1031 */
Corentin Chary4d441512010-01-13 22:26:24 +01001032static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001033{
Corentin Charyd99b5772010-01-22 21:20:57 +01001034 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001035 pr_warning("Error setting light sensor switch\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001036 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001037}
1038
1039static ssize_t show_lssw(struct device *dev,
1040 struct device_attribute *attr, char *buf)
1041{
Corentin Chary9129d142009-12-01 22:39:41 +01001042 struct asus_laptop *asus = dev_get_drvdata(dev);
1043
Corentin Chary50a90c42009-11-30 21:55:12 +01001044 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001045}
1046
1047static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1048 const char *buf, size_t count)
1049{
Corentin Chary9129d142009-12-01 22:39:41 +01001050 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001051 int rv, value;
1052
1053 rv = parse_arg(buf, count, &value);
1054 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001055 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001056
1057 return rv;
1058}
1059
Corentin Chary4d441512010-01-13 22:26:24 +01001060static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001061{
Corentin Charyd99b5772010-01-22 21:20:57 +01001062 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001063 pr_warning("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001064 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001065}
1066
1067static ssize_t show_lslvl(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 Chary50a90c42009-11-30 21:55:12 +01001072 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001073}
1074
1075static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1076 const char *buf, size_t count)
1077{
Corentin Chary9129d142009-12-01 22:39:41 +01001078 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001079 int rv, value;
1080
1081 rv = parse_arg(buf, count, &value);
1082 if (rv > 0) {
1083 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1084 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001085 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001086 }
1087
1088 return rv;
1089}
1090
Corentin Charye539c2f2007-05-06 14:47:06 +02001091/*
1092 * GPS
1093 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001094static int asus_gps_status(struct asus_laptop *asus)
1095{
1096 unsigned long long status;
1097 acpi_status rv = AE_OK;
1098
Corentin Charyd99b5772010-01-22 21:20:57 +01001099 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1100 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001101 if (ACPI_FAILURE(rv)) {
1102 pr_warning("Error reading GPS status\n");
1103 return -ENODEV;
1104 }
1105 return !!status;
1106}
1107
1108static int asus_gps_switch(struct asus_laptop *asus, int status)
1109{
Corentin Charyd99b5772010-01-22 21:20:57 +01001110 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001111
Corentin Charyd99b5772010-01-22 21:20:57 +01001112 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001113 return -ENODEV;
1114 return 0;
1115}
1116
Corentin Charye539c2f2007-05-06 14:47:06 +02001117static ssize_t show_gps(struct device *dev,
1118 struct device_attribute *attr, char *buf)
1119{
Corentin Chary9129d142009-12-01 22:39:41 +01001120 struct asus_laptop *asus = dev_get_drvdata(dev);
1121
Corentin Chary6358bf22010-01-13 21:55:44 +01001122 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001123}
1124
1125static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1126 const char *buf, size_t count)
1127{
Corentin Chary060cbce2010-01-28 10:52:40 +01001128 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001129 int rv, value;
1130 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001131
Corentin Chary6358bf22010-01-13 21:55:44 +01001132 rv = parse_arg(buf, count, &value);
1133 if (rv <= 0)
1134 return -EINVAL;
1135 ret = asus_gps_switch(asus, !!value);
1136 if (ret)
1137 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001138 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001139 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001140}
1141
Corentin Chary034ce902009-01-20 16:17:43 +01001142/*
Corentin Chary18e13112010-01-25 23:29:24 +01001143 * rfkill
1144 */
1145static int asus_gps_rfkill_set(void *data, bool blocked)
1146{
Corentin Chary23f45c32010-08-24 09:30:46 +02001147 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001148
Corentin Chary23f45c32010-08-24 09:30:46 +02001149 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001150}
1151
1152static const struct rfkill_ops asus_gps_rfkill_ops = {
1153 .set_block = asus_gps_rfkill_set,
1154};
1155
1156static void asus_rfkill_exit(struct asus_laptop *asus)
1157{
1158 if (asus->gps_rfkill) {
1159 rfkill_unregister(asus->gps_rfkill);
1160 rfkill_destroy(asus->gps_rfkill);
1161 asus->gps_rfkill = NULL;
1162 }
1163}
1164
1165static int asus_rfkill_init(struct asus_laptop *asus)
1166{
1167 int result;
1168
1169 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1170 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1171 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1172 return 0;
1173
1174 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1175 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001176 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001177 if (!asus->gps_rfkill)
1178 return -EINVAL;
1179
1180 result = rfkill_register(asus->gps_rfkill);
1181 if (result) {
1182 rfkill_destroy(asus->gps_rfkill);
1183 asus->gps_rfkill = NULL;
1184 }
1185
1186 return result;
1187}
1188
1189/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001190 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001191 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001192static void asus_input_notify(struct asus_laptop *asus, int event)
1193{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001194 if (asus->inputdev)
1195 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001196}
1197
1198static int asus_input_init(struct asus_laptop *asus)
1199{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001200 struct input_dev *input;
1201 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001202
Corentin Chary66a71dd2010-01-25 22:50:11 +01001203 input = input_allocate_device();
1204 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001205 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001206 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001207 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001208 input->name = "Asus Laptop extra buttons";
1209 input->phys = ASUS_LAPTOP_FILE "/input0";
1210 input->id.bustype = BUS_HOST;
1211 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001212
Corentin Chary66a71dd2010-01-25 22:50:11 +01001213 error = sparse_keymap_setup(input, asus_keymap, NULL);
1214 if (error) {
1215 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001216 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001217 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001218 error = input_register_device(input);
1219 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001220 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001221 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001222 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001223
1224 asus->inputdev = input;
1225 return 0;
1226
Axel Lin45036ae2010-07-05 15:29:00 +08001227err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001228 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001229err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001230 input_free_device(input);
1231 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001232}
1233
1234static void asus_input_exit(struct asus_laptop *asus)
1235{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001236 if (asus->inputdev) {
1237 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001238 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001239 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001240 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001241}
1242
1243/*
1244 * ACPI driver
1245 */
Corentin Chary600ad522009-11-30 21:42:42 +01001246static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001247{
Corentin Chary9129d142009-12-01 22:39:41 +01001248 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001249 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001250
Corentin Chary6b7091e2007-01-26 14:04:45 +01001251 /*
1252 * We need to tell the backlight device when the backlight power is
1253 * switched
1254 */
Corentin Chary3e68ae72010-01-13 22:10:39 +01001255 if (event == ATKD_LCD_ON)
Corentin Chary9129d142009-12-01 22:39:41 +01001256 lcd_blank(asus, FB_BLANK_UNBLANK);
Corentin Chary3e68ae72010-01-13 22:10:39 +01001257 else if (event == ATKD_LCD_OFF)
Corentin Chary9129d142009-12-01 22:39:41 +01001258 lcd_blank(asus, FB_BLANK_POWERDOWN);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001259
Corentin Chary619d8b12009-11-28 10:35:37 +01001260 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001261 count = asus->event_count[event % 128]++;
1262 acpi_bus_generate_proc_event(asus->device, event, count);
1263 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1264 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001265 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001266
Corentin Charya539df52010-01-25 22:53:21 +01001267 /* Brightness events are special */
1268 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1269
1270 /* Ignore them completely if the acpi video driver is used */
1271 if (asus->backlight_device != NULL) {
1272 /* Update the backlight device. */
1273 asus_backlight_notify(asus);
1274 }
1275 return ;
1276 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001277 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001278}
1279
Corentin Chary2a1fd642010-01-26 21:02:23 +01001280static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1281static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001282static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1283 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001284static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1285static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001286static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
1287static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1288static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1289static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1290static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1291
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001292static struct attribute *asus_attributes[] = {
1293 &dev_attr_infos.attr,
1294 &dev_attr_wlan.attr,
1295 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001296 &dev_attr_wimax.attr,
1297 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001298 &dev_attr_display.attr,
1299 &dev_attr_ledd.attr,
1300 &dev_attr_ls_level.attr,
1301 &dev_attr_ls_switch.attr,
1302 &dev_attr_gps.attr,
1303 NULL
1304};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001305
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001306static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1307 struct attribute *attr,
1308 int idx)
1309{
1310 struct device *dev = container_of(kobj, struct device, kobj);
1311 struct platform_device *pdev = to_platform_device(dev);
1312 struct asus_laptop *asus = platform_get_drvdata(pdev);
1313 acpi_handle handle = asus->handle;
1314 bool supported;
1315
1316 if (attr == &dev_attr_wlan.attr) {
1317 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1318
1319 } else if (attr == &dev_attr_bluetooth.attr) {
1320 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1321
1322 } else if (attr == &dev_attr_display.attr) {
1323 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1324
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001325 } else if (attr == &dev_attr_wimax.attr) {
1326 supported =
1327 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1328
1329 } else if (attr == &dev_attr_wwan.attr) {
1330 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1331
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001332 } else if (attr == &dev_attr_ledd.attr) {
1333 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1334
1335 } else if (attr == &dev_attr_ls_switch.attr ||
1336 attr == &dev_attr_ls_level.attr) {
1337 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
1338 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1339
1340 } else if (attr == &dev_attr_gps.attr) {
1341 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1342 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1343 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1344 } else {
1345 supported = true;
1346 }
1347
1348 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001349}
1350
Corentin Chary2a1fd642010-01-26 21:02:23 +01001351
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001352static const struct attribute_group asus_attr_group = {
1353 .is_visible = asus_sysfs_is_visible,
1354 .attrs = asus_attributes,
1355};
Corentin Chary85091b72007-01-26 14:04:30 +01001356
Corentin Chary9129d142009-12-01 22:39:41 +01001357static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001358{
Corentin Chary71e687d2010-08-24 09:30:44 +02001359 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001360
Corentin Chary50a90c42009-11-30 21:55:12 +01001361 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1362 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001363 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001364 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001365
Corentin Chary71e687d2010-08-24 09:30:44 +02001366 result = platform_device_add(asus->platform_device);
1367 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001368 goto fail_platform_device;
1369
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001370 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1371 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001372 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001373 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001374
Corentin Chary600ad522009-11-30 21:42:42 +01001375 return 0;
1376
1377fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001378 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001379fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001380 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001381 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001382}
1383
Corentin Chary9129d142009-12-01 22:39:41 +01001384static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001385{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001386 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001387 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001388}
1389
1390static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001391 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001392 .name = ASUS_LAPTOP_FILE,
1393 .owner = THIS_MODULE,
1394 }
Corentin Chary85091b72007-01-26 14:04:30 +01001395};
1396
Len Brown8def05f2007-01-30 01:46:43 -05001397static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001398 char **paths, int num_paths)
1399{
1400 int i;
1401 acpi_status status;
1402
1403 for (i = 0; i < num_paths; i++) {
1404 status = acpi_get_handle(NULL, paths[i], handle);
1405 if (ACPI_SUCCESS(status))
1406 return 0;
1407 }
1408
1409 *handle = NULL;
1410 return -ENODEV;
1411}
1412
1413#define ASUS_HANDLE_INIT(object) \
1414 asus_handle_init(#object, &object##_handle, object##_paths, \
1415 ARRAY_SIZE(object##_paths))
1416
Corentin Chary85091b72007-01-26 14:04:30 +01001417/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001418 * This function is used to initialize the context with right values. In this
1419 * method, we can make all the detection we want, and modify the asus_laptop
1420 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001421 */
Corentin Chary7c247642009-11-30 22:13:54 +01001422static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001423{
1424 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001425 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001426 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001427 char *string = NULL;
1428 acpi_status status;
1429
1430 /*
1431 * Get DSDT headers early enough to allow for differentiating between
1432 * models, but late enough to allow acpi_bus_register_driver() to fail
1433 * before doing anything ACPI-specific. Should we encounter a machine,
1434 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001435 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001436 */
Corentin Chary7c247642009-11-30 22:13:54 +01001437 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001438 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001439 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001440
1441 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001442 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001443 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001444 return -ENODEV;
1445 }
1446
1447 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001448 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001449 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001450 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001451 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001452 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001453 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001454 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001455
Corentin Chary185e5af2007-03-11 10:27:33 +01001456 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001457 if (write_acpi_int(asus->handle, "CWAP", wapf))
1458 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001459 /*
1460 * Try to match the object returned by INIT to the specific model.
1461 * Handle every possible object (or the lack of thereof) the DSDT
1462 * writers might throw at us. When in trouble, we pass NULL to
1463 * asus_model_match() and try something completely different.
1464 */
1465 if (buffer.pointer) {
1466 model = buffer.pointer;
1467 switch (model->type) {
1468 case ACPI_TYPE_STRING:
1469 string = model->string.pointer;
1470 break;
1471 case ACPI_TYPE_BUFFER:
1472 string = model->buffer.pointer;
1473 break;
1474 default:
1475 string = "";
1476 break;
1477 }
1478 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001479 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001480 if (!asus->name) {
1481 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001482 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001483 }
Corentin Chary85091b72007-01-26 14:04:30 +01001484
Len Brown8def05f2007-01-30 01:46:43 -05001485 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001486 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001487
Corentin Chary4564de12007-01-26 14:04:40 +01001488 /*
1489 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001490 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1491 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001492 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001493 */
Corentin Chary9a816852007-03-11 10:25:38 +01001494 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001495 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001496 if (!ACPI_FAILURE(status))
1497 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001498
Corentin Charyd99b5772010-01-22 21:20:57 +01001499 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001500 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001501
Corentin Charyd99b5772010-01-22 21:20:57 +01001502 /* Scheduled for removal */
Corentin Chary6b7091e2007-01-26 14:04:45 +01001503 ASUS_HANDLE_INIT(lcd_switch);
Corentin Chary78127b42007-01-26 14:04:49 +01001504 ASUS_HANDLE_INIT(display_get);
1505
Corentin Chary85091b72007-01-26 14:04:30 +01001506 kfree(model);
1507
1508 return AE_OK;
1509}
1510
Corentin Chary9129d142009-12-01 22:39:41 +01001511static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001512{
1513 int result = 0;
1514
Corentin Chary50a90c42009-11-30 21:55:12 +01001515 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001516 if (result)
1517 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001518 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001519 pr_err("Hotkey device not present, aborting\n");
1520 return -ENODEV;
1521 }
1522
Corentin Chary7c247642009-11-30 22:13:54 +01001523 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001524 if (result)
1525 return result;
1526
Corentin Chary600ad522009-11-30 21:42:42 +01001527 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001528 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001529 asus_bluetooth_set(asus, !!bluetooth_status);
1530
Corentin Charyd0930a22010-01-17 17:21:13 +01001531 if (wlan_status >= 0)
1532 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001533
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001534 if (wimax_status >= 0)
1535 asus_wimax_set(asus, !!wimax_status);
1536
1537 if (wwan_status >= 0)
1538 asus_wwan_set(asus, !!wwan_status);
1539
Corentin Chary600ad522009-11-30 21:42:42 +01001540 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001541 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001542 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001543
1544 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001545 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001546
1547 /* Set initial values of light sensor and level */
Corentin Charybe4ee822009-12-06 16:27:09 +01001548 asus->light_switch = 0; /* Default to light sensor disabled */
1549 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001550
Corentin Charyd99b5772010-01-22 21:20:57 +01001551 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1552 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001553 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001554 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001555 }
Corentin Chary600ad522009-11-30 21:42:42 +01001556
Corentin Chary47ee0e92010-01-24 11:17:15 +01001557 asus->lcd_state = 1; /* LCD should be on when the module load */
Corentin Chary600ad522009-11-30 21:42:42 +01001558 return result;
1559}
1560
Corentin Charyaf96f872011-02-06 13:27:30 +01001561static void __devinit asus_dmi_check(void)
1562{
1563 const char *model;
1564
1565 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1566 if (!model)
1567 return;
1568
1569 /* On L1400B WLED control the sound card, don't mess with it ... */
1570 if (strncmp(model, "L1400B", 6) == 0) {
1571 wlan_status = -1;
1572 }
1573}
1574
Corentin Chary71e687d2010-08-24 09:30:44 +02001575static bool asus_device_present;
1576
Corentin Chary600ad522009-11-30 21:42:42 +01001577static int __devinit asus_acpi_add(struct acpi_device *device)
1578{
Corentin Chary9129d142009-12-01 22:39:41 +01001579 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001580 int result;
1581
1582 pr_notice("Asus Laptop Support version %s\n",
1583 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001584 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1585 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001586 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001587 asus->handle = device->handle;
1588 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1589 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1590 device->driver_data = asus;
1591 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001592
Corentin Charyaf96f872011-02-06 13:27:30 +01001593 asus_dmi_check();
1594
Corentin Chary9129d142009-12-01 22:39:41 +01001595 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001596 if (result)
1597 goto fail_platform;
1598
1599 /*
1600 * Register the platform device first. It is used as a parent for the
1601 * sub-devices below.
1602 */
Corentin Chary9129d142009-12-01 22:39:41 +01001603 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001604 if (result)
1605 goto fail_platform;
1606
1607 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001608 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001609 if (result)
1610 goto fail_backlight;
1611 } else
1612 pr_info("Backlight controlled by ACPI video driver\n");
1613
Corentin Chary9129d142009-12-01 22:39:41 +01001614 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001615 if (result)
1616 goto fail_input;
1617
Corentin Chary9129d142009-12-01 22:39:41 +01001618 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001619 if (result)
1620 goto fail_led;
1621
Corentin Chary18e13112010-01-25 23:29:24 +01001622 result = asus_rfkill_init(asus);
1623 if (result)
1624 goto fail_rfkill;
1625
Corentin Chary600ad522009-11-30 21:42:42 +01001626 asus_device_present = true;
1627 return 0;
1628
Corentin Chary18e13112010-01-25 23:29:24 +01001629fail_rfkill:
1630 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001631fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001632 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001633fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001634 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001635fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001636 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001637fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001638 kfree(asus->name);
1639 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001640
1641 return result;
1642}
1643
1644static int asus_acpi_remove(struct acpi_device *device, int type)
1645{
Corentin Chary9129d142009-12-01 22:39:41 +01001646 struct asus_laptop *asus = acpi_driver_data(device);
1647
1648 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001649 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001650 asus_led_exit(asus);
1651 asus_input_exit(asus);
1652 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001653
Corentin Chary50a90c42009-11-30 21:55:12 +01001654 kfree(asus->name);
1655 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001656 return 0;
1657}
1658
1659static const struct acpi_device_id asus_device_ids[] = {
1660 {"ATK0100", 0},
1661 {"ATK0101", 0},
1662 {"", 0},
1663};
1664MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1665
1666static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001667 .name = ASUS_LAPTOP_NAME,
1668 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001669 .owner = THIS_MODULE,
1670 .ids = asus_device_ids,
1671 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1672 .ops = {
1673 .add = asus_acpi_add,
1674 .remove = asus_acpi_remove,
1675 .notify = asus_acpi_notify,
1676 },
1677};
1678
Corentin Chary85091b72007-01-26 14:04:30 +01001679static int __init asus_laptop_init(void)
1680{
1681 int result;
1682
Corentin Chary600ad522009-11-30 21:42:42 +01001683 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001684 if (result < 0)
1685 return result;
1686
Corentin Chary600ad522009-11-30 21:42:42 +01001687 result = acpi_bus_register_driver(&asus_acpi_driver);
1688 if (result < 0)
1689 goto fail_acpi_driver;
1690 if (!asus_device_present) {
1691 result = -ENODEV;
1692 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001693 }
Len Brown8def05f2007-01-30 01:46:43 -05001694 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001695
Corentin Chary600ad522009-11-30 21:42:42 +01001696fail_no_device:
1697 acpi_bus_unregister_driver(&asus_acpi_driver);
1698fail_acpi_driver:
1699 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001700 return result;
1701}
1702
Corentin Chary600ad522009-11-30 21:42:42 +01001703static void __exit asus_laptop_exit(void)
1704{
1705 acpi_bus_unregister_driver(&asus_acpi_driver);
1706 platform_driver_unregister(&platform_driver);
1707}
1708
Corentin Chary85091b72007-01-26 14:04:30 +01001709module_init(asus_laptop_init);
1710module_exit(asus_laptop_exit);