blob: 012c44d38d4893f538470801d4fdf548e45093b5 [file] [log] [blame]
Corentin Chary85091b72007-01-26 14:04:30 +01001/*
2 * asus-laptop.c - Asus Laptop Support
3 *
4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Corentin Chary8ec555c2007-03-11 10:28:03 +01006 * Copyright (C) 2006-2007 Corentin Chary
Andy Ross8819de72011-10-14 11:13:35 +02007 * Copyright (C) 2011 Wind River Systems
Corentin Chary85091b72007-01-26 14:04:30 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 *
24 * The development page for this driver is located at
25 * http://sourceforge.net/projects/acpi4asus/
26 *
27 * Credits:
28 * Pontus Fuchs - Helper functions, cleanup
29 * Johann Wiesner - Small compile fixes
30 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
31 * Eric Burghard - LED display support for W1N
32 * Josh Green - Light Sens support
Lucas De Marchic8440332011-03-17 17:18:22 -030033 * Thomas Tuttle - His first patch for led support was very helpful
Corentin Charye539c2f2007-05-06 14:47:06 +020034 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010035 */
36
Corentin Chary2fcc23d2009-06-19 14:52:03 +020037#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
Corentin Chary85091b72007-01-26 14:04:30 +010039#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/types.h>
43#include <linux/err.h>
44#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010045#include <linux/backlight.h>
46#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010047#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010048#include <linux/platform_device.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010049#include <linux/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010050#include <linux/input.h>
Corentin Chary66a71dd2010-01-25 22:50:11 +010051#include <linux/input/sparse-keymap.h>
Andy Ross8819de72011-10-14 11:13:35 +020052#include <linux/input-polldev.h>
Corentin Chary18e13112010-01-25 23:29:24 +010053#include <linux/rfkill.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090054#include <linux/slab.h>
Corentin Charyaf96f872011-02-06 13:27:30 +010055#include <linux/dmi.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010056#include <acpi/acpi_drivers.h>
57#include <acpi/acpi_bus.h>
Corentin Chary85091b72007-01-26 14:04:30 +010058
Corentin Chary91687cc2009-11-28 10:32:34 +010059#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010060
Corentin Chary50a90c42009-11-30 21:55:12 +010061#define ASUS_LAPTOP_NAME "Asus Laptop Support"
62#define ASUS_LAPTOP_CLASS "hotkey"
63#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
64#define ASUS_LAPTOP_FILE KBUILD_MODNAME
65#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
Corentin Chary85091b72007-01-26 14:04:30 +010066
Corentin Chary85091b72007-01-26 14:04:30 +010067MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010068MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010069MODULE_LICENSE("GPL");
70
Corentin Charybe966662009-08-29 10:28:29 +020071/*
72 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010073 * The significance of values is yet to be found, but
74 * most of the time:
Corentin Charyfddbfed2011-07-01 11:34:39 +020075 * Bit | Bluetooth | WLAN
76 * 0 | Hardware | Hardware
77 * 1 | Hardware | Software
78 * 4 | Software | Software
Corentin Chary185e5af2007-03-11 10:27:33 +010079 */
80static uint wapf = 1;
Axel Linc26d85c2010-07-20 15:19:55 -070081module_param(wapf, uint, 0444);
Corentin Chary185e5af2007-03-11 10:27:33 +010082MODULE_PARM_DESC(wapf, "WAPF value");
83
Dan Carpenter668f4a02010-04-06 13:44:29 +030084static int wlan_status = 1;
85static int bluetooth_status = 1;
Corentin Charyba1ff5b2010-11-14 17:40:12 +010086static int wimax_status = -1;
87static int wwan_status = -1;
Andy Rossabec04d2011-10-14 11:13:37 +020088static int als_status;
Corentin Chary0e875f42010-01-10 20:49:26 +010089
Axel Linc26d85c2010-07-20 15:19:55 -070090module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010091MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010092 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
Corentin Chary16cbf932011-10-14 11:13:40 +020093 "default is -1");
Corentin Chary0e875f42010-01-10 20:49:26 +010094
Axel Linc26d85c2010-07-20 15:19:55 -070095module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010096MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
97 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
Corentin Chary16cbf932011-10-14 11:13:40 +020098 "default is -1");
Corentin Chary0e875f42010-01-10 20:49:26 +010099
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100100module_param(wimax_status, int, 0444);
101MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
102 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
Corentin Chary16cbf932011-10-14 11:13:40 +0200103 "default is -1");
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100104
105module_param(wwan_status, int, 0444);
106MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
107 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
Corentin Chary16cbf932011-10-14 11:13:40 +0200108 "default is -1");
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100109
Andy Rossabec04d2011-10-14 11:13:37 +0200110module_param(als_status, int, 0444);
111MODULE_PARM_DESC(als_status, "Set the ALS status on boot "
112 "(0 = disabled, 1 = enabled). "
113 "default is 0");
114
Corentin Charybe4ee822009-12-06 16:27:09 +0100115/*
116 * Some events we use, same for all Asus
117 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100118#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
119#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100120#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100121#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100122#define ATKD_LCD_ON 0x33
123#define ATKD_LCD_OFF 0x34
124
125/*
126 * Known bits returned by \_SB.ATKD.HWRS
127 */
128#define WL_HWRS 0x80
129#define BT_HWRS 0x100
130
131/*
132 * Flags for hotk status
133 * WL_ON and BT_ON are also used for wireless_status()
134 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100135#define WL_RSTS 0x01 /* internal Wifi */
136#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100137#define WM_RSTS 0x08 /* internal wimax */
138#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100139
Corentin Charybe18cda2007-01-26 14:04:35 +0100140/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100141#define METHOD_MLED "MLED"
142#define METHOD_TLED "TLED"
143#define METHOD_RLED "RLED" /* W1JC */
144#define METHOD_PLED "PLED" /* A7J */
145#define METHOD_GLED "GLED" /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100146
Corentin Chary722ad972007-01-26 14:04:55 +0100147/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100148#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100149
Corentin Charybe966662009-08-29 10:28:29 +0200150/*
151 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100152 * WLED and BLED are not handled like other XLED, because in some dsdt
153 * they also control the WLAN/Bluetooth device.
154 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100155#define METHOD_WLAN "WLED"
156#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100157
158/* WWAN and WIMAX */
159#define METHOD_WWAN "GSMC"
160#define METHOD_WIMAX "WMXC"
161
Corentin Charyd99b5772010-01-22 21:20:57 +0100162#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100163
Corentin Chary6b7091e2007-01-26 14:04:45 +0100164/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100165#define METHOD_BRIGHTNESS_SET "SPLV"
166#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100167
Corentin Chary78127b42007-01-26 14:04:49 +0100168/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100169#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100170
Corentin Charyd99b5772010-01-22 21:20:57 +0100171#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
172#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100173
Corentin Charye539c2f2007-05-06 14:47:06 +0200174/* GPS */
175/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100176#define METHOD_GPS_ON "SDON"
177#define METHOD_GPS_OFF "SDOF"
178#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200179
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000180/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100181#define METHOD_KBD_LIGHT_SET "SLKB"
182#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000183
Andy Ross8819de72011-10-14 11:13:35 +0200184/* For Pegatron Lucid tablet */
185#define DEVICE_NAME_PEGA "Lucid"
Andy Ross33989ba2011-10-14 11:13:36 +0200186
Andy Ross8819de72011-10-14 11:13:35 +0200187#define METHOD_PEGA_ENABLE "ENPR"
188#define METHOD_PEGA_DISABLE "DAPR"
Andy Ross33989ba2011-10-14 11:13:36 +0200189#define PEGA_ALS 0x04
190#define PEGA_ALS_POWER 0x05
191
Andy Ross8819de72011-10-14 11:13:35 +0200192#define METHOD_PEGA_READ "RDLN"
Andy Ross33989ba2011-10-14 11:13:36 +0200193#define PEGA_READ_ALS_H 0x02
194#define PEGA_READ_ALS_L 0x03
Andy Ross8819de72011-10-14 11:13:35 +0200195
Andy Rossb23910c2011-10-14 11:13:38 +0200196#define PEGA_ACCEL_NAME "pega_accel"
197#define PEGA_ACCEL_DESC "Pegatron Lucid Tablet Accelerometer"
198#define METHOD_XLRX "XLRX"
199#define METHOD_XLRY "XLRY"
200#define METHOD_XLRZ "XLRZ"
201#define PEGA_ACC_CLAMP 512 /* 1G accel is reported as ~256, so clamp to 2G */
202#define PEGA_ACC_RETRIES 3
203
Corentin Chary85091b72007-01-26 14:04:30 +0100204/*
Corentin Chary9129d142009-12-01 22:39:41 +0100205 * Define a specific led structure to keep the main structure clean
206 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100207struct asus_led {
208 int wk;
209 struct work_struct work;
210 struct led_classdev led;
211 struct asus_laptop *asus;
212 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100213};
214
215/*
Corentin Chary85091b72007-01-26 14:04:30 +0100216 * This is the main structure, we can use it to store anything interesting
217 * about the hotk device
218 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100219struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200220 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100221
Corentin Chary7c247642009-11-30 22:13:54 +0100222 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100223 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100224 struct acpi_device *device; /* the device we are in */
225 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100226
Corentin Chary7c247642009-11-30 22:13:54 +0100227 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100228 struct key_entry *keymap;
Andy Rossb23910c2011-10-14 11:13:38 +0200229 struct input_polled_dev *pega_accel_poll;
Corentin Chary9129d142009-12-01 22:39:41 +0100230
Corentin Charyaee0afb2010-01-26 21:01:34 +0100231 struct asus_led mled;
232 struct asus_led tled;
233 struct asus_led rled;
234 struct asus_led pled;
235 struct asus_led gled;
236 struct asus_led kled;
237 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100238
Corentin Charyaa9df932010-01-13 21:49:10 +0100239 int wireless_status;
240 bool have_rsts;
Andy Ross8819de72011-10-14 11:13:35 +0200241 bool is_pega_lucid;
Andy Rossb23910c2011-10-14 11:13:38 +0200242 bool pega_acc_live;
243 int pega_acc_x;
244 int pega_acc_y;
245 int pega_acc_z;
Corentin Charyaa9df932010-01-13 21:49:10 +0100246
Corentin Chary18e13112010-01-25 23:29:24 +0100247 struct rfkill *gps_rfkill;
248
Corentin Charybe966662009-08-29 10:28:29 +0200249 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200250 u32 ledd_status; /* status of the LED display */
251 u8 light_level; /* light sensor level */
252 u8 light_switch; /* light sensor switch value */
253 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100254};
255
Corentin Chary9129d142009-12-01 22:39:41 +0100256static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100257 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100258 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
259 {KE_KEY, 0x05, { KEY_WLAN } },
260 {KE_KEY, 0x08, { KEY_F13 } },
261 {KE_KEY, 0x17, { KEY_ZOOM } },
262 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100263 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100264 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
265 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
266 {KE_KEY, 0x32, { KEY_MUTE } },
267 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
268 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
269 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
270 {KE_KEY, 0x41, { KEY_NEXTSONG } },
271 {KE_KEY, 0x43, { KEY_STOPCD } },
272 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
273 {KE_KEY, 0x4c, { KEY_MEDIA } },
274 {KE_KEY, 0x50, { KEY_EMAIL } },
275 {KE_KEY, 0x51, { KEY_WWW } },
276 {KE_KEY, 0x55, { KEY_CALC } },
277 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
278 {KE_KEY, 0x5D, { KEY_WLAN } },
279 {KE_KEY, 0x5E, { KEY_WLAN } },
280 {KE_KEY, 0x5F, { KEY_WLAN } },
281 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
282 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
283 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
284 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
285 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d72010-01-17 17:37:19 +0100286 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
287 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100288 {KE_KEY, 0x82, { KEY_CAMERA } },
289 {KE_KEY, 0x88, { KEY_WLAN } },
290 {KE_KEY, 0x8A, { KEY_PROG1 } },
291 {KE_KEY, 0x95, { KEY_MEDIA } },
292 {KE_KEY, 0x99, { KEY_PHONE } },
293 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
294 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200295 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100296 {KE_END, 0},
297};
298
Corentin Chary66a71dd2010-01-25 22:50:11 +0100299
Corentin Chary85091b72007-01-26 14:04:30 +0100300/*
301 * This function evaluates an ACPI method, given an int as parameter, the
302 * method is searched within the scope of the handle, can be NULL. The output
303 * of the method is written is output, which can also be NULL
304 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100305 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100306 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100307static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
308 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100309{
Corentin Charybe966662009-08-29 10:28:29 +0200310 struct acpi_object_list params; /* list of input parameters (an int) */
311 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100312 acpi_status status;
313
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100314 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700315 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100316
Corentin Chary85091b72007-01-26 14:04:30 +0100317 params.count = 1;
318 params.pointer = &in_obj;
319 in_obj.type = ACPI_TYPE_INTEGER;
320 in_obj.integer.value = val;
321
322 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100323 if (status == AE_OK)
324 return 0;
325 else
326 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100327}
328
Corentin Charyd8c67322009-11-28 10:27:51 +0100329static int write_acpi_int(acpi_handle handle, const char *method, int val)
330{
331 return write_acpi_int_ret(handle, method, val, NULL);
332}
333
Corentin Charyd99b5772010-01-22 21:20:57 +0100334static int acpi_check_handle(acpi_handle handle, const char *method,
335 acpi_handle *ret)
336{
337 acpi_status status;
338
339 if (method == NULL)
340 return -ENODEV;
341
342 if (ret)
343 status = acpi_get_handle(handle, (char *)method,
344 ret);
345 else {
346 acpi_handle dummy;
347
348 status = acpi_get_handle(handle, (char *)method,
349 &dummy);
350 }
351
352 if (status != AE_OK) {
353 if (ret)
Joe Perches5ad77dc2011-03-29 15:21:35 -0700354 pr_warn("Error finding %s\n", method);
Corentin Charyd99b5772010-01-22 21:20:57 +0100355 return -ENODEV;
356 }
357 return 0;
358}
359
Andy Ross8819de72011-10-14 11:13:35 +0200360static bool asus_check_pega_lucid(struct asus_laptop *asus)
361{
362 return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
363 !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
364 !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
365 !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
366}
367
Andy Ross33989ba2011-10-14 11:13:36 +0200368static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
369{
370 char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
371 return write_acpi_int(asus->handle, method, unit);
372}
373
Andy Rossb23910c2011-10-14 11:13:38 +0200374static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
375{
376 int i, delta;
377 unsigned long long val;
378 for (i = 0; i < PEGA_ACC_RETRIES; i++) {
379 acpi_evaluate_integer(asus->handle, method, NULL, &val);
380
381 /* The output is noisy. From reading the ASL
382 * dissassembly, timeout errors are returned with 1's
383 * in the high word, and the lack of locking around
384 * thei hi/lo byte reads means that a transition
385 * between (for example) -1 and 0 could be read as
386 * 0xff00 or 0x00ff. */
387 delta = abs(curr - (short)val);
388 if (delta < 128 && !(val & ~0xffff))
389 break;
390 }
391 return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP);
392}
393
394static void pega_accel_poll(struct input_polled_dev *ipd)
395{
396 struct device *parent = ipd->input->dev.parent;
397 struct asus_laptop *asus = dev_get_drvdata(parent);
398
399 /* In some cases, the very first call to poll causes a
400 * recursive fault under the polldev worker. This is
401 * apparently related to very early userspace access to the
402 * device, and perhaps a firmware bug. Fake the first report. */
403 if (!asus->pega_acc_live) {
404 asus->pega_acc_live = true;
405 input_report_abs(ipd->input, ABS_X, 0);
406 input_report_abs(ipd->input, ABS_Y, 0);
407 input_report_abs(ipd->input, ABS_Z, 0);
408 input_sync(ipd->input);
409 return;
410 }
411
412 asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX);
413 asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY);
414 asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ);
415
416 /* Note transform, convert to "right/up/out" in the native
417 * landscape orientation (i.e. the vector is the direction of
418 * "real up" in the device's cartiesian coordinates). */
419 input_report_abs(ipd->input, ABS_X, -asus->pega_acc_x);
420 input_report_abs(ipd->input, ABS_Y, -asus->pega_acc_y);
421 input_report_abs(ipd->input, ABS_Z, asus->pega_acc_z);
422 input_sync(ipd->input);
423}
424
425static void pega_accel_exit(struct asus_laptop *asus)
426{
427 if (asus->pega_accel_poll) {
428 input_unregister_polled_device(asus->pega_accel_poll);
429 input_free_polled_device(asus->pega_accel_poll);
430 }
431 asus->pega_accel_poll = NULL;
432}
433
434static int pega_accel_init(struct asus_laptop *asus)
435{
436 int err;
437 struct input_polled_dev *ipd;
438
439 if (!asus->is_pega_lucid)
440 return -ENODEV;
441
442 if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) ||
443 acpi_check_handle(asus->handle, METHOD_XLRY, NULL) ||
444 acpi_check_handle(asus->handle, METHOD_XLRZ, NULL))
445 return -ENODEV;
446
447 ipd = input_allocate_polled_device();
448 if (!ipd)
449 return -ENOMEM;
450
451 ipd->poll = pega_accel_poll;
452 ipd->poll_interval = 125;
453 ipd->poll_interval_min = 50;
454 ipd->poll_interval_max = 2000;
455
456 ipd->input->name = PEGA_ACCEL_DESC;
457 ipd->input->phys = PEGA_ACCEL_NAME "/input0";
458 ipd->input->dev.parent = &asus->platform_device->dev;
459 ipd->input->id.bustype = BUS_HOST;
460
461 set_bit(EV_ABS, ipd->input->evbit);
462 input_set_abs_params(ipd->input, ABS_X,
463 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
464 input_set_abs_params(ipd->input, ABS_Y,
465 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
466 input_set_abs_params(ipd->input, ABS_Z,
467 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
468
469 err = input_register_polled_device(ipd);
470 if (err)
471 goto exit;
472
473 asus->pega_accel_poll = ipd;
474 return 0;
475
476exit:
477 input_free_polled_device(ipd);
478 return err;
479}
480
Corentin Chary17e78f62010-01-13 22:21:33 +0100481/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100482static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100483 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100484{
Corentin Charyd99b5772010-01-22 21:20:57 +0100485 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100486 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100487 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100488 value = !value + 1;
489 else
490 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100491
Corentin Charye5593bf2010-01-17 17:20:11 +0100492 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100493}
494
Corentin Charybe4ee822009-12-06 16:27:09 +0100495/*
496 * LEDs
497 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100498/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100499static void asus_led_cdev_set(struct led_classdev *led_cdev,
500 enum led_brightness value)
501{
502 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
503 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100504
Corentin Charyaee0afb2010-01-26 21:01:34 +0100505 led->wk = !!value;
506 queue_work(asus->led_workqueue, &led->work);
507}
508
509static void asus_led_cdev_update(struct work_struct *work)
510{
511 struct asus_led *led = container_of(work, struct asus_led, work);
512 struct asus_laptop *asus = led->asus;
513
514 asus_led_set(asus, led->method, led->wk);
515}
516
517static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
518{
519 return led_cdev->brightness;
520}
Corentin Charybe18cda2007-01-26 14:04:35 +0100521
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000522/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100523 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000524 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100525static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000526{
527 unsigned long long kblv;
528 struct acpi_object_list params;
529 union acpi_object in_obj;
530 acpi_status rv;
531
532 params.count = 1;
533 params.pointer = &in_obj;
534 in_obj.type = ACPI_TYPE_INTEGER;
535 in_obj.integer.value = 2;
536
Corentin Charyd99b5772010-01-22 21:20:57 +0100537 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
538 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000539 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700540 pr_warn("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100541 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000542 }
543 return kblv;
544}
545
Corentin Chary4d441512010-01-13 22:26:24 +0100546static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000547{
548 if (kblv > 0)
549 kblv = (1 << 7) | (kblv & 0x7F);
550 else
551 kblv = 0;
552
Corentin Charyd99b5772010-01-22 21:20:57 +0100553 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700554 pr_warn("Keyboard LED display write failed\n");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000555 return -EINVAL;
556 }
557 return 0;
558}
559
Corentin Charyaee0afb2010-01-26 21:01:34 +0100560static void asus_kled_cdev_set(struct led_classdev *led_cdev,
561 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000562{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100563 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
564 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100565
Corentin Chary060cbce2010-01-28 10:52:40 +0100566 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100567 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000568}
569
Corentin Charyaee0afb2010-01-26 21:01:34 +0100570static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000571{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100572 struct asus_led *led = container_of(work, struct asus_led, work);
573 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100574
Corentin Charyaee0afb2010-01-26 21:01:34 +0100575 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000576}
577
Corentin Charyaee0afb2010-01-26 21:01:34 +0100578static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000579{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100580 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
581 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100582
583 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000584}
585
Corentin Charybe4ee822009-12-06 16:27:09 +0100586static void asus_led_exit(struct asus_laptop *asus)
587{
Axel Lin8fcf71a2011-08-08 17:17:18 +0800588 if (!IS_ERR_OR_NULL(asus->mled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100589 led_classdev_unregister(&asus->mled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800590 if (!IS_ERR_OR_NULL(asus->tled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100591 led_classdev_unregister(&asus->tled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800592 if (!IS_ERR_OR_NULL(asus->pled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100593 led_classdev_unregister(&asus->pled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800594 if (!IS_ERR_OR_NULL(asus->rled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100595 led_classdev_unregister(&asus->rled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800596 if (!IS_ERR_OR_NULL(asus->gled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100597 led_classdev_unregister(&asus->gled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800598 if (!IS_ERR_OR_NULL(asus->kled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100599 led_classdev_unregister(&asus->kled.led);
600 if (asus->led_workqueue) {
601 destroy_workqueue(asus->led_workqueue);
602 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100603 }
604}
605
606/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100607static int asus_led_register(struct asus_laptop *asus,
608 struct asus_led *led,
609 const char *name, const char *method)
610{
611 struct led_classdev *led_cdev = &led->led;
612
613 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100614 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100615
616 led->asus = asus;
617 led->method = method;
618
619 INIT_WORK(&led->work, asus_led_cdev_update);
620 led_cdev->name = name;
621 led_cdev->brightness_set = asus_led_cdev_set;
622 led_cdev->brightness_get = asus_led_cdev_get;
623 led_cdev->max_brightness = 1;
624 return led_classdev_register(&asus->platform_device->dev, led_cdev);
625}
Corentin Charybe4ee822009-12-06 16:27:09 +0100626
627static int asus_led_init(struct asus_laptop *asus)
628{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100629 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100630
631 /*
Corentin Chary8d38e422011-10-14 11:13:39 +0200632 * The Pegatron Lucid has no physical leds, but all methods are
633 * available in the DSDT...
634 */
635 if (asus->is_pega_lucid)
636 return 0;
637
638 /*
Corentin Charybe4ee822009-12-06 16:27:09 +0100639 * Functions that actually update the LED's are called from a
640 * workqueue. By doing this as separate work rather than when the LED
641 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
642 * potentially bad time, such as a timer interrupt.
643 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100644 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
645 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100646 return -ENOMEM;
647
Corentin Charyaee0afb2010-01-26 21:01:34 +0100648 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
649 if (r)
650 goto error;
651 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
652 if (r)
653 goto error;
654 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
655 if (r)
656 goto error;
657 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
658 if (r)
659 goto error;
660 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
661 if (r)
662 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100663 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100664 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
665 struct asus_led *led = &asus->kled;
666 struct led_classdev *cdev = &led->led;
667
668 led->asus = asus;
669
670 INIT_WORK(&led->work, asus_kled_cdev_update);
671 cdev->name = "asus::kbd_backlight";
672 cdev->brightness_set = asus_kled_cdev_set;
673 cdev->brightness_get = asus_kled_cdev_get;
674 cdev->max_brightness = 3;
675 r = led_classdev_register(&asus->platform_device->dev, cdev);
676 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100677error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100678 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100679 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100680 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100681}
682
683/*
684 * Backlight device
685 */
Corentin Chary4d441512010-01-13 22:26:24 +0100686static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100687{
Corentin Charyd99b5772010-01-22 21:20:57 +0100688 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400689 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100690 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100691
Corentin Charyd99b5772010-01-22 21:20:57 +0100692 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
693 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100694 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700695 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100696
697 return value;
698}
699
Corentin Chary4d441512010-01-13 22:26:24 +0100700static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100701{
Corentin Charyd99b5772010-01-22 21:20:57 +0100702 struct asus_laptop *asus = bl_get_data(bd);
703
704 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700705 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100706 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100707 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100708 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100709}
710
711static int update_bl_status(struct backlight_device *bd)
712{
Richard Purdie599a52d2007-02-10 23:07:48 +0000713 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100714
Corentin Chary3b81cf92011-02-06 13:27:31 +0100715 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100716}
717
Lionel Debrouxacc24722010-11-16 14:14:02 +0100718static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100719 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100720 .update_status = update_bl_status,
721};
722
Corentin Charya539df52010-01-25 22:53:21 +0100723static int asus_backlight_notify(struct asus_laptop *asus)
724{
725 struct backlight_device *bd = asus->backlight_device;
726 int old = bd->props.brightness;
727
728 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
729
730 return old;
731}
732
Corentin Charybe4ee822009-12-06 16:27:09 +0100733static int asus_backlight_init(struct asus_laptop *asus)
734{
735 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500736 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100737
Corentin Chary71e687d2010-08-24 09:30:44 +0200738 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100739 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200740 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500741
Corentin Chary71e687d2010-08-24 09:30:44 +0200742 memset(&props, 0, sizeof(struct backlight_properties));
743 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700744 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100745
Corentin Chary71e687d2010-08-24 09:30:44 +0200746 bd = backlight_device_register(ASUS_LAPTOP_FILE,
747 &asus->platform_device->dev, asus,
748 &asusbl_ops, &props);
749 if (IS_ERR(bd)) {
750 pr_err("Could not register asus backlight device\n");
751 asus->backlight_device = NULL;
752 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100753 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200754
755 asus->backlight_device = bd;
756 bd->props.brightness = asus_read_brightness(bd);
757 bd->props.power = FB_BLANK_UNBLANK;
758 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100759 return 0;
760}
761
762static void asus_backlight_exit(struct asus_laptop *asus)
763{
764 if (asus->backlight_device)
765 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100766 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100767}
768
Corentin Chary85091b72007-01-26 14:04:30 +0100769/*
770 * Platform device handlers
771 */
772
773/*
774 * We write our info in page, we begin at offset off and cannot write more
775 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
776 * number of bytes written in page
777 */
778static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500779 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100780{
Corentin Chary9129d142009-12-01 22:39:41 +0100781 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100782 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400783 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200784 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100785 acpi_status rv = AE_OK;
786
Corentin Chary85091b72007-01-26 14:04:30 +0100787 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100788 * We use the easy way, we don't care of off and count,
789 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100790 */
791
Corentin Chary50a90c42009-11-30 21:55:12 +0100792 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
793 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100794 /*
795 * The SFUN method probably allows the original driver to get the list
796 * of features supported by a given model. For now, 0x0100 or 0x0800
797 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
798 * The significance of others is yet to be found.
799 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100800 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100801 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000802 len += sprintf(page + len, "SFUN value : %#x\n",
803 (uint) temp);
804 /*
805 * The HWRS method return informations about the hardware.
806 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
807 * The significance of others is yet to be found.
808 * If we don't find the method, we assume the device are present.
809 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100810 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000811 if (!ACPI_FAILURE(rv))
812 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100813 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100814 /*
815 * Another value for userspace: the ASYM method returns 0x02 for
816 * battery low and 0x04 for battery critical, its readings tend to be
817 * more accurate than those provided by _BST.
818 * Note: since not all the laptops provide this method, errors are
819 * silently ignored.
820 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100821 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100822 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000823 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100824 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100825 if (asus->dsdt_info) {
826 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100827 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100828 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100829 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100830 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100831 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100832 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100833 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100834 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100835 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100836 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100837 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100838 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100839 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100840 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100841 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
842 }
843
844 return len;
845}
846
847static int parse_arg(const char *buf, unsigned long count, int *val)
848{
849 if (!count)
850 return 0;
851 if (count > 31)
852 return -EINVAL;
853 if (sscanf(buf, "%i", val) != 1)
854 return -EINVAL;
855 return count;
856}
857
Corentin Chary17e78f62010-01-13 22:21:33 +0100858static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
859 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100860 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100861{
862 int rv, value;
863 int out = 0;
864
865 rv = parse_arg(buf, count, &value);
866 if (rv > 0)
867 out = value ? 1 : 0;
868
Corentin Charyd99b5772010-01-22 21:20:57 +0100869 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100870 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100871 return rv;
872}
873
874/*
Corentin Chary722ad972007-01-26 14:04:55 +0100875 * LEDD display
876 */
877static ssize_t show_ledd(struct device *dev,
878 struct device_attribute *attr, char *buf)
879{
Corentin Chary9129d142009-12-01 22:39:41 +0100880 struct asus_laptop *asus = dev_get_drvdata(dev);
881
Corentin Chary50a90c42009-11-30 21:55:12 +0100882 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100883}
884
885static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
886 const char *buf, size_t count)
887{
Corentin Chary9129d142009-12-01 22:39:41 +0100888 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100889 int rv, value;
890
891 rv = parse_arg(buf, count, &value);
892 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700893 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700894 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700895 return -ENODEV;
896 }
897 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100898 }
899 return rv;
900}
901
902/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100903 * Wireless
904 */
905static int asus_wireless_status(struct asus_laptop *asus, int mask)
906{
907 unsigned long long status;
908 acpi_status rv = AE_OK;
909
910 if (!asus->have_rsts)
911 return (asus->wireless_status & mask) ? 1 : 0;
912
Corentin Charyd99b5772010-01-22 21:20:57 +0100913 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
914 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100915 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700916 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100917 return -EINVAL;
918 }
919 return !!(status & mask);
920}
921
922/*
Corentin Chary4564de12007-01-26 14:04:40 +0100923 * WLAN
924 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100925static int asus_wlan_set(struct asus_laptop *asus, int status)
926{
927 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700928 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100929 return -EIO;
930 }
931 return 0;
932}
933
Corentin Chary4564de12007-01-26 14:04:40 +0100934static ssize_t show_wlan(struct device *dev,
935 struct device_attribute *attr, char *buf)
936{
Corentin Chary9129d142009-12-01 22:39:41 +0100937 struct asus_laptop *asus = dev_get_drvdata(dev);
938
Corentin Chary17e78f62010-01-13 22:21:33 +0100939 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100940}
941
942static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
943 const char *buf, size_t count)
944{
Corentin Chary9129d142009-12-01 22:39:41 +0100945 struct asus_laptop *asus = dev_get_drvdata(dev);
946
Corentin Charyd99b5772010-01-22 21:20:57 +0100947 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100948}
949
950/*
951 * Bluetooth
952 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100953static int asus_bluetooth_set(struct asus_laptop *asus, int status)
954{
955 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700956 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100957 return -EIO;
958 }
959 return 0;
960}
961
Corentin Chary4564de12007-01-26 14:04:40 +0100962static ssize_t show_bluetooth(struct device *dev,
963 struct device_attribute *attr, char *buf)
964{
Corentin Chary9129d142009-12-01 22:39:41 +0100965 struct asus_laptop *asus = dev_get_drvdata(dev);
966
Corentin Chary17e78f62010-01-13 22:21:33 +0100967 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100968}
969
Len Brown8def05f2007-01-30 01:46:43 -0500970static ssize_t store_bluetooth(struct device *dev,
971 struct device_attribute *attr, const char *buf,
972 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100973{
Corentin Chary9129d142009-12-01 22:39:41 +0100974 struct asus_laptop *asus = dev_get_drvdata(dev);
975
Corentin Charyd99b5772010-01-22 21:20:57 +0100976 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100977}
978
Corentin Chary78127b42007-01-26 14:04:49 +0100979/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100980 * Wimax
981 */
982static int asus_wimax_set(struct asus_laptop *asus, int status)
983{
984 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700985 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100986 return -EIO;
987 }
988 return 0;
989}
990
991static ssize_t show_wimax(struct device *dev,
992 struct device_attribute *attr, char *buf)
993{
994 struct asus_laptop *asus = dev_get_drvdata(dev);
995
996 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
997}
998
999static ssize_t store_wimax(struct device *dev,
1000 struct device_attribute *attr, const char *buf,
1001 size_t count)
1002{
1003 struct asus_laptop *asus = dev_get_drvdata(dev);
1004
1005 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
1006}
1007
1008/*
1009 * Wwan
1010 */
1011static int asus_wwan_set(struct asus_laptop *asus, int status)
1012{
1013 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001014 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001015 return -EIO;
1016 }
1017 return 0;
1018}
1019
1020static ssize_t show_wwan(struct device *dev,
1021 struct device_attribute *attr, char *buf)
1022{
1023 struct asus_laptop *asus = dev_get_drvdata(dev);
1024
1025 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
1026}
1027
1028static ssize_t store_wwan(struct device *dev,
1029 struct device_attribute *attr, const char *buf,
1030 size_t count)
1031{
1032 struct asus_laptop *asus = dev_get_drvdata(dev);
1033
1034 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
1035}
1036
1037/*
Corentin Chary78127b42007-01-26 14:04:49 +01001038 * Display
1039 */
Corentin Chary4d441512010-01-13 22:26:24 +01001040static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +01001041{
1042 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +01001043 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001044 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +01001045 return;
1046}
1047
Corentin Chary78127b42007-01-26 14:04:49 +01001048/*
1049 * Experimental support for display switching. As of now: 1 should activate
1050 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1051 * Any combination (bitwise) of these will suffice. I never actually tested 4
1052 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1053 * for more info.
1054 */
1055static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1056 const char *buf, size_t count)
1057{
Corentin Chary9129d142009-12-01 22:39:41 +01001058 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001059 int rv, value;
1060
1061 rv = parse_arg(buf, count, &value);
1062 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001063 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001064 return rv;
1065}
1066
Corentin Chary8b857352007-01-26 14:04:58 +01001067/*
1068 * Light Sens
1069 */
Corentin Chary4d441512010-01-13 22:26:24 +01001070static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001071{
Andy Ross33989ba2011-10-14 11:13:36 +02001072 int ret;
1073
1074 if (asus->is_pega_lucid) {
1075 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
1076 if (!ret)
1077 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
1078 } else {
1079 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
1080 }
1081 if (ret)
1082 pr_warning("Error setting light sensor switch\n");
1083
Corentin Chary50a90c42009-11-30 21:55:12 +01001084 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001085}
1086
1087static ssize_t show_lssw(struct device *dev,
1088 struct device_attribute *attr, char *buf)
1089{
Corentin Chary9129d142009-12-01 22:39:41 +01001090 struct asus_laptop *asus = dev_get_drvdata(dev);
1091
Corentin Chary50a90c42009-11-30 21:55:12 +01001092 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001093}
1094
1095static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1096 const char *buf, size_t count)
1097{
Corentin Chary9129d142009-12-01 22:39:41 +01001098 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001099 int rv, value;
1100
1101 rv = parse_arg(buf, count, &value);
1102 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001103 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001104
1105 return rv;
1106}
1107
Corentin Chary4d441512010-01-13 22:26:24 +01001108static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001109{
Corentin Charyd99b5772010-01-22 21:20:57 +01001110 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001111 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001112 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001113}
1114
1115static ssize_t show_lslvl(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 Chary50a90c42009-11-30 21:55:12 +01001120 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001121}
1122
1123static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1124 const char *buf, size_t count)
1125{
Corentin Chary9129d142009-12-01 22:39:41 +01001126 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001127 int rv, value;
1128
1129 rv = parse_arg(buf, count, &value);
1130 if (rv > 0) {
1131 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1132 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001133 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001134 }
1135
1136 return rv;
1137}
1138
Andy Ross33989ba2011-10-14 11:13:36 +02001139static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1140{
1141 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1142 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1143 &buffer);
1144 if (!err) {
1145 union acpi_object *obj = buffer.pointer;
1146 if (obj && obj->type == ACPI_TYPE_INTEGER)
1147 *result = obj->integer.value;
1148 else
1149 err = -EIO;
1150 }
1151 return err;
1152}
1153
1154static ssize_t show_lsvalue(struct device *dev,
1155 struct device_attribute *attr, char *buf)
1156{
1157 struct asus_laptop *asus = dev_get_drvdata(dev);
1158 int err, hi, lo;
1159
1160 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1161 if (!err)
1162 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1163 if (!err)
1164 return sprintf(buf, "%d\n", 10 * hi + lo);
1165 return err;
1166}
1167
Corentin Charye539c2f2007-05-06 14:47:06 +02001168/*
1169 * GPS
1170 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001171static int asus_gps_status(struct asus_laptop *asus)
1172{
1173 unsigned long long status;
1174 acpi_status rv = AE_OK;
1175
Corentin Charyd99b5772010-01-22 21:20:57 +01001176 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1177 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001178 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001179 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001180 return -ENODEV;
1181 }
1182 return !!status;
1183}
1184
1185static int asus_gps_switch(struct asus_laptop *asus, int status)
1186{
Corentin Charyd99b5772010-01-22 21:20:57 +01001187 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001188
Corentin Charyd99b5772010-01-22 21:20:57 +01001189 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001190 return -ENODEV;
1191 return 0;
1192}
1193
Corentin Charye539c2f2007-05-06 14:47:06 +02001194static ssize_t show_gps(struct device *dev,
1195 struct device_attribute *attr, char *buf)
1196{
Corentin Chary9129d142009-12-01 22:39:41 +01001197 struct asus_laptop *asus = dev_get_drvdata(dev);
1198
Corentin Chary6358bf22010-01-13 21:55:44 +01001199 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001200}
1201
1202static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1203 const char *buf, size_t count)
1204{
Corentin Chary060cbce2010-01-28 10:52:40 +01001205 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001206 int rv, value;
1207 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001208
Corentin Chary6358bf22010-01-13 21:55:44 +01001209 rv = parse_arg(buf, count, &value);
1210 if (rv <= 0)
1211 return -EINVAL;
1212 ret = asus_gps_switch(asus, !!value);
1213 if (ret)
1214 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001215 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001216 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001217}
1218
Corentin Chary034ce902009-01-20 16:17:43 +01001219/*
Corentin Chary18e13112010-01-25 23:29:24 +01001220 * rfkill
1221 */
1222static int asus_gps_rfkill_set(void *data, bool blocked)
1223{
Corentin Chary23f45c32010-08-24 09:30:46 +02001224 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001225
Corentin Chary23f45c32010-08-24 09:30:46 +02001226 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001227}
1228
1229static const struct rfkill_ops asus_gps_rfkill_ops = {
1230 .set_block = asus_gps_rfkill_set,
1231};
1232
1233static void asus_rfkill_exit(struct asus_laptop *asus)
1234{
1235 if (asus->gps_rfkill) {
1236 rfkill_unregister(asus->gps_rfkill);
1237 rfkill_destroy(asus->gps_rfkill);
1238 asus->gps_rfkill = NULL;
1239 }
1240}
1241
1242static int asus_rfkill_init(struct asus_laptop *asus)
1243{
1244 int result;
1245
1246 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1247 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1248 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1249 return 0;
1250
1251 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1252 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001253 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001254 if (!asus->gps_rfkill)
1255 return -EINVAL;
1256
1257 result = rfkill_register(asus->gps_rfkill);
1258 if (result) {
1259 rfkill_destroy(asus->gps_rfkill);
1260 asus->gps_rfkill = NULL;
1261 }
1262
1263 return result;
1264}
1265
1266/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001267 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001268 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001269static void asus_input_notify(struct asus_laptop *asus, int event)
1270{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001271 if (asus->inputdev)
1272 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001273}
1274
1275static int asus_input_init(struct asus_laptop *asus)
1276{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001277 struct input_dev *input;
1278 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001279
Corentin Chary66a71dd2010-01-25 22:50:11 +01001280 input = input_allocate_device();
1281 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001282 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001283 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001284 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001285 input->name = "Asus Laptop extra buttons";
1286 input->phys = ASUS_LAPTOP_FILE "/input0";
1287 input->id.bustype = BUS_HOST;
1288 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001289
Corentin Chary66a71dd2010-01-25 22:50:11 +01001290 error = sparse_keymap_setup(input, asus_keymap, NULL);
1291 if (error) {
1292 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001293 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001294 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001295 error = input_register_device(input);
1296 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001297 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001298 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001299 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001300
1301 asus->inputdev = input;
1302 return 0;
1303
Axel Lin45036ae2010-07-05 15:29:00 +08001304err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001305 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001306err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001307 input_free_device(input);
1308 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001309}
1310
1311static void asus_input_exit(struct asus_laptop *asus)
1312{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001313 if (asus->inputdev) {
1314 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001315 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001316 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001317 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001318}
1319
1320/*
1321 * ACPI driver
1322 */
Corentin Chary600ad522009-11-30 21:42:42 +01001323static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001324{
Corentin Chary9129d142009-12-01 22:39:41 +01001325 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001326 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001327
Corentin Chary619d8b12009-11-28 10:35:37 +01001328 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001329 count = asus->event_count[event % 128]++;
1330 acpi_bus_generate_proc_event(asus->device, event, count);
1331 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1332 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001333 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001334
Corentin Charya539df52010-01-25 22:53:21 +01001335 /* Brightness events are special */
1336 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1337
1338 /* Ignore them completely if the acpi video driver is used */
1339 if (asus->backlight_device != NULL) {
1340 /* Update the backlight device. */
1341 asus_backlight_notify(asus);
1342 }
1343 return ;
1344 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001345 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001346}
1347
Corentin Chary2a1fd642010-01-26 21:02:23 +01001348static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1349static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001350static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1351 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001352static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1353static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001354static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001355static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001356static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001357static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1358static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1359static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1360
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001361static struct attribute *asus_attributes[] = {
1362 &dev_attr_infos.attr,
1363 &dev_attr_wlan.attr,
1364 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001365 &dev_attr_wimax.attr,
1366 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001367 &dev_attr_display.attr,
1368 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001369 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001370 &dev_attr_ls_level.attr,
1371 &dev_attr_ls_switch.attr,
1372 &dev_attr_gps.attr,
1373 NULL
1374};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001375
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001376static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1377 struct attribute *attr,
1378 int idx)
1379{
1380 struct device *dev = container_of(kobj, struct device, kobj);
1381 struct platform_device *pdev = to_platform_device(dev);
1382 struct asus_laptop *asus = platform_get_drvdata(pdev);
1383 acpi_handle handle = asus->handle;
1384 bool supported;
1385
Andy Ross33989ba2011-10-14 11:13:36 +02001386 if (asus->is_pega_lucid) {
1387 /* no ls_level interface on the Lucid */
1388 if (attr == &dev_attr_ls_switch.attr)
1389 supported = true;
1390 else if (attr == &dev_attr_ls_level.attr)
1391 supported = false;
1392 else
1393 goto normal;
1394
1395 return supported;
1396 }
1397
1398normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001399 if (attr == &dev_attr_wlan.attr) {
1400 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1401
1402 } else if (attr == &dev_attr_bluetooth.attr) {
1403 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1404
1405 } else if (attr == &dev_attr_display.attr) {
1406 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1407
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001408 } else if (attr == &dev_attr_wimax.attr) {
1409 supported =
1410 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1411
1412 } else if (attr == &dev_attr_wwan.attr) {
1413 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1414
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001415 } else if (attr == &dev_attr_ledd.attr) {
1416 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1417
1418 } else if (attr == &dev_attr_ls_switch.attr ||
1419 attr == &dev_attr_ls_level.attr) {
1420 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001421 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1422 } else if (attr == &dev_attr_ls_value.attr) {
1423 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001424 } else if (attr == &dev_attr_gps.attr) {
1425 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1426 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1427 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1428 } else {
1429 supported = true;
1430 }
1431
1432 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001433}
1434
Corentin Chary2a1fd642010-01-26 21:02:23 +01001435
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001436static const struct attribute_group asus_attr_group = {
1437 .is_visible = asus_sysfs_is_visible,
1438 .attrs = asus_attributes,
1439};
Corentin Chary85091b72007-01-26 14:04:30 +01001440
Corentin Chary9129d142009-12-01 22:39:41 +01001441static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001442{
Corentin Chary71e687d2010-08-24 09:30:44 +02001443 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001444
Corentin Chary50a90c42009-11-30 21:55:12 +01001445 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1446 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001447 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001448 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001449
Corentin Chary71e687d2010-08-24 09:30:44 +02001450 result = platform_device_add(asus->platform_device);
1451 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001452 goto fail_platform_device;
1453
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001454 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1455 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001456 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001457 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001458
Corentin Chary600ad522009-11-30 21:42:42 +01001459 return 0;
1460
1461fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001462 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001463fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001464 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001465 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001466}
1467
Corentin Chary9129d142009-12-01 22:39:41 +01001468static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001469{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001470 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001471 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001472}
1473
1474static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001475 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001476 .name = ASUS_LAPTOP_FILE,
1477 .owner = THIS_MODULE,
Andy Rossb23910c2011-10-14 11:13:38 +02001478 },
Corentin Chary85091b72007-01-26 14:04:30 +01001479};
1480
Corentin Chary85091b72007-01-26 14:04:30 +01001481/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001482 * This function is used to initialize the context with right values. In this
1483 * method, we can make all the detection we want, and modify the asus_laptop
1484 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001485 */
Corentin Chary7c247642009-11-30 22:13:54 +01001486static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001487{
1488 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001489 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001490 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001491 char *string = NULL;
1492 acpi_status status;
1493
1494 /*
1495 * Get DSDT headers early enough to allow for differentiating between
1496 * models, but late enough to allow acpi_bus_register_driver() to fail
1497 * before doing anything ACPI-specific. Should we encounter a machine,
1498 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001499 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001500 */
Corentin Chary7c247642009-11-30 22:13:54 +01001501 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001502 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001503 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001504
1505 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001506 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001507 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001508 return -ENODEV;
1509 }
1510
1511 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001512 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001513 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001514 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001515 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001516 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001517 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001518 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001519
Corentin Chary185e5af2007-03-11 10:27:33 +01001520 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001521 if (write_acpi_int(asus->handle, "CWAP", wapf))
1522 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001523 /*
1524 * Try to match the object returned by INIT to the specific model.
1525 * Handle every possible object (or the lack of thereof) the DSDT
1526 * writers might throw at us. When in trouble, we pass NULL to
1527 * asus_model_match() and try something completely different.
1528 */
1529 if (buffer.pointer) {
1530 model = buffer.pointer;
1531 switch (model->type) {
1532 case ACPI_TYPE_STRING:
1533 string = model->string.pointer;
1534 break;
1535 case ACPI_TYPE_BUFFER:
1536 string = model->buffer.pointer;
1537 break;
1538 default:
1539 string = "";
1540 break;
1541 }
1542 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001543 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001544 if (!asus->name) {
1545 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001546 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001547 }
Corentin Chary85091b72007-01-26 14:04:30 +01001548
Len Brown8def05f2007-01-30 01:46:43 -05001549 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001550 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001551
Corentin Chary4564de12007-01-26 14:04:40 +01001552 /*
1553 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001554 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1555 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001556 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001557 */
Corentin Chary9a816852007-03-11 10:25:38 +01001558 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001559 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001560 if (!ACPI_FAILURE(status))
1561 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001562
Corentin Charyd99b5772010-01-22 21:20:57 +01001563 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001564 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001565
Corentin Chary85091b72007-01-26 14:04:30 +01001566 kfree(model);
1567
1568 return AE_OK;
1569}
1570
Corentin Chary9129d142009-12-01 22:39:41 +01001571static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001572{
1573 int result = 0;
1574
Corentin Chary50a90c42009-11-30 21:55:12 +01001575 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001576 if (result)
1577 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001578 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001579 pr_err("Hotkey device not present, aborting\n");
1580 return -ENODEV;
1581 }
1582
Corentin Chary7c247642009-11-30 22:13:54 +01001583 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001584 if (result)
1585 return result;
1586
Corentin Chary600ad522009-11-30 21:42:42 +01001587 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001588 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001589 asus_bluetooth_set(asus, !!bluetooth_status);
1590
Corentin Charyd0930a22010-01-17 17:21:13 +01001591 if (wlan_status >= 0)
1592 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001593
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001594 if (wimax_status >= 0)
1595 asus_wimax_set(asus, !!wimax_status);
1596
1597 if (wwan_status >= 0)
1598 asus_wwan_set(asus, !!wwan_status);
1599
Corentin Chary600ad522009-11-30 21:42:42 +01001600 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001601 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001602 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001603
1604 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001605 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001606
1607 /* Set initial values of light sensor and level */
Andy Rossabec04d2011-10-14 11:13:37 +02001608 asus->light_switch = !!als_status;
Corentin Charybe4ee822009-12-06 16:27:09 +01001609 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001610
Andy Ross33989ba2011-10-14 11:13:36 +02001611 if (asus->is_pega_lucid) {
1612 asus_als_switch(asus, asus->light_switch);
1613 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1614 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001615 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001616 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001617 }
Corentin Chary600ad522009-11-30 21:42:42 +01001618
Corentin Chary600ad522009-11-30 21:42:42 +01001619 return result;
1620}
1621
Corentin Charyaf96f872011-02-06 13:27:30 +01001622static void __devinit asus_dmi_check(void)
1623{
1624 const char *model;
1625
1626 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1627 if (!model)
1628 return;
1629
1630 /* On L1400B WLED control the sound card, don't mess with it ... */
1631 if (strncmp(model, "L1400B", 6) == 0) {
1632 wlan_status = -1;
1633 }
1634}
1635
Corentin Chary71e687d2010-08-24 09:30:44 +02001636static bool asus_device_present;
1637
Corentin Chary600ad522009-11-30 21:42:42 +01001638static int __devinit asus_acpi_add(struct acpi_device *device)
1639{
Corentin Chary9129d142009-12-01 22:39:41 +01001640 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001641 int result;
1642
1643 pr_notice("Asus Laptop Support version %s\n",
1644 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001645 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1646 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001647 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001648 asus->handle = device->handle;
1649 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1650 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1651 device->driver_data = asus;
1652 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001653
Corentin Charyaf96f872011-02-06 13:27:30 +01001654 asus_dmi_check();
1655
Corentin Chary9129d142009-12-01 22:39:41 +01001656 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001657 if (result)
1658 goto fail_platform;
1659
1660 /*
Andy Ross8819de72011-10-14 11:13:35 +02001661 * Need platform type detection first, then the platform
1662 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001663 */
Andy Ross8819de72011-10-14 11:13:35 +02001664 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001665 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001666 if (result)
1667 goto fail_platform;
1668
1669 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001670 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001671 if (result)
1672 goto fail_backlight;
1673 } else
1674 pr_info("Backlight controlled by ACPI video driver\n");
1675
Corentin Chary9129d142009-12-01 22:39:41 +01001676 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001677 if (result)
1678 goto fail_input;
1679
Corentin Chary9129d142009-12-01 22:39:41 +01001680 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001681 if (result)
1682 goto fail_led;
1683
Corentin Chary18e13112010-01-25 23:29:24 +01001684 result = asus_rfkill_init(asus);
1685 if (result)
1686 goto fail_rfkill;
1687
Andy Rossb23910c2011-10-14 11:13:38 +02001688 result = pega_accel_init(asus);
1689 if (result && result != -ENODEV)
1690 goto fail_pega_accel;
1691
Corentin Chary600ad522009-11-30 21:42:42 +01001692 asus_device_present = true;
1693 return 0;
1694
Andy Rossb23910c2011-10-14 11:13:38 +02001695fail_pega_accel:
1696 asus_rfkill_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001697fail_rfkill:
1698 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001699fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001700 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001701fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001702 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001703fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001704 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001705fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001706 kfree(asus->name);
1707 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001708
1709 return result;
1710}
1711
1712static int asus_acpi_remove(struct acpi_device *device, int type)
1713{
Corentin Chary9129d142009-12-01 22:39:41 +01001714 struct asus_laptop *asus = acpi_driver_data(device);
1715
1716 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001717 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001718 asus_led_exit(asus);
1719 asus_input_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001720 pega_accel_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001721 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001722
Corentin Chary50a90c42009-11-30 21:55:12 +01001723 kfree(asus->name);
1724 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001725 return 0;
1726}
1727
1728static const struct acpi_device_id asus_device_ids[] = {
1729 {"ATK0100", 0},
1730 {"ATK0101", 0},
1731 {"", 0},
1732};
1733MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1734
1735static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001736 .name = ASUS_LAPTOP_NAME,
1737 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001738 .owner = THIS_MODULE,
1739 .ids = asus_device_ids,
1740 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1741 .ops = {
1742 .add = asus_acpi_add,
1743 .remove = asus_acpi_remove,
1744 .notify = asus_acpi_notify,
1745 },
1746};
1747
Corentin Chary85091b72007-01-26 14:04:30 +01001748static int __init asus_laptop_init(void)
1749{
1750 int result;
1751
Corentin Chary600ad522009-11-30 21:42:42 +01001752 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001753 if (result < 0)
1754 return result;
1755
Corentin Chary600ad522009-11-30 21:42:42 +01001756 result = acpi_bus_register_driver(&asus_acpi_driver);
1757 if (result < 0)
1758 goto fail_acpi_driver;
1759 if (!asus_device_present) {
1760 result = -ENODEV;
1761 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001762 }
Len Brown8def05f2007-01-30 01:46:43 -05001763 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001764
Corentin Chary600ad522009-11-30 21:42:42 +01001765fail_no_device:
1766 acpi_bus_unregister_driver(&asus_acpi_driver);
1767fail_acpi_driver:
1768 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001769 return result;
1770}
1771
Corentin Chary600ad522009-11-30 21:42:42 +01001772static void __exit asus_laptop_exit(void)
1773{
1774 acpi_bus_unregister_driver(&asus_acpi_driver);
1775 platform_driver_unregister(&platform_driver);
1776}
1777
Corentin Chary85091b72007-01-26 14:04:30 +01001778module_init(asus_laptop_init);
1779module_exit(asus_laptop_exit);