blob: 613762d825f9ffa71c5aee03ba05f3d80f6e6d5f [file] [log] [blame]
Corentin Chary85091b72007-01-26 14:04:30 +01001/*
2 * asus-laptop.c - Asus Laptop Support
3 *
4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Corentin Chary8ec555c2007-03-11 10:28:03 +01006 * Copyright (C) 2006-2007 Corentin Chary
Andy Ross8819de72011-10-14 11:13:35 +02007 * Copyright (C) 2011 Wind River Systems
Corentin Chary85091b72007-01-26 14:04:30 +01008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 *
24 * The development page for this driver is located at
25 * http://sourceforge.net/projects/acpi4asus/
26 *
27 * Credits:
28 * Pontus Fuchs - Helper functions, cleanup
29 * Johann Wiesner - Small compile fixes
30 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
31 * Eric Burghard - LED display support for W1N
32 * Josh Green - Light Sens support
Lucas De Marchic8440332011-03-17 17:18:22 -030033 * Thomas Tuttle - His first patch for led support was very helpful
Corentin Charye539c2f2007-05-06 14:47:06 +020034 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010035 */
36
Corentin Chary2fcc23d2009-06-19 14:52:03 +020037#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
Corentin Chary85091b72007-01-26 14:04:30 +010039#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/types.h>
43#include <linux/err.h>
44#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010045#include <linux/backlight.h>
46#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010047#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010048#include <linux/platform_device.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010049#include <linux/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010050#include <linux/input.h>
Corentin Chary66a71dd2010-01-25 22:50:11 +010051#include <linux/input/sparse-keymap.h>
Andy Ross8819de72011-10-14 11:13:35 +020052#include <linux/input-polldev.h>
Corentin Chary18e13112010-01-25 23:29:24 +010053#include <linux/rfkill.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090054#include <linux/slab.h>
Corentin Charyaf96f872011-02-06 13:27:30 +010055#include <linux/dmi.h>
Corentin Chary060cbce2010-01-28 10:52:40 +010056#include <acpi/acpi_drivers.h>
57#include <acpi/acpi_bus.h>
Corentin Chary85091b72007-01-26 14:04:30 +010058
Corentin Chary91687cc2009-11-28 10:32:34 +010059#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010060
Corentin Chary50a90c42009-11-30 21:55:12 +010061#define ASUS_LAPTOP_NAME "Asus Laptop Support"
62#define ASUS_LAPTOP_CLASS "hotkey"
63#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
64#define ASUS_LAPTOP_FILE KBUILD_MODNAME
65#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
Corentin Chary85091b72007-01-26 14:04:30 +010066
Corentin Chary85091b72007-01-26 14:04:30 +010067MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010068MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010069MODULE_LICENSE("GPL");
70
Corentin Charybe966662009-08-29 10:28:29 +020071/*
72 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010073 * The significance of values is yet to be found, but
74 * most of the time:
Corentin Charyfddbfed2011-07-01 11:34:39 +020075 * Bit | Bluetooth | WLAN
76 * 0 | Hardware | Hardware
77 * 1 | Hardware | Software
78 * 4 | Software | Software
Corentin Chary185e5af2007-03-11 10:27:33 +010079 */
80static uint wapf = 1;
Axel Linc26d85c2010-07-20 15:19:55 -070081module_param(wapf, uint, 0444);
Corentin Chary185e5af2007-03-11 10:27:33 +010082MODULE_PARM_DESC(wapf, "WAPF value");
83
Dan Carpenter668f4a02010-04-06 13:44:29 +030084static int wlan_status = 1;
85static int bluetooth_status = 1;
Corentin Charyba1ff5b2010-11-14 17:40:12 +010086static int wimax_status = -1;
87static int wwan_status = -1;
Andy Rossabec04d2011-10-14 11:13:37 +020088static int als_status;
Corentin Chary0e875f42010-01-10 20:49:26 +010089
Axel Linc26d85c2010-07-20 15:19:55 -070090module_param(wlan_status, int, 0444);
Corentin Charyd0930a22010-01-17 17:21:13 +010091MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
Corentin Chary0e875f42010-01-10 20:49:26 +010092 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
93 "default is 1");
94
Axel Linc26d85c2010-07-20 15:19:55 -070095module_param(bluetooth_status, int, 0444);
Corentin Chary0e875f42010-01-10 20:49:26 +010096MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
97 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
98 "default is 1");
99
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100100module_param(wimax_status, int, 0444);
101MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
102 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
103 "default is 1");
104
105module_param(wwan_status, int, 0444);
106MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
107 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
108 "default is 1");
109
Andy Rossabec04d2011-10-14 11:13:37 +0200110module_param(als_status, int, 0444);
111MODULE_PARM_DESC(als_status, "Set the ALS status on boot "
112 "(0 = disabled, 1 = enabled). "
113 "default is 0");
114
Corentin Charybe4ee822009-12-06 16:27:09 +0100115/*
116 * Some events we use, same for all Asus
117 */
Corentin Chary060cbce2010-01-28 10:52:40 +0100118#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
119#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
Corentin Charya539df52010-01-25 22:53:21 +0100120#define ATKD_BR_MIN ATKD_BR_UP
Corentin Chary060cbce2010-01-28 10:52:40 +0100121#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
Corentin Charybe4ee822009-12-06 16:27:09 +0100122#define ATKD_LCD_ON 0x33
123#define ATKD_LCD_OFF 0x34
124
125/*
126 * Known bits returned by \_SB.ATKD.HWRS
127 */
128#define WL_HWRS 0x80
129#define BT_HWRS 0x100
130
131/*
132 * Flags for hotk status
133 * WL_ON and BT_ON are also used for wireless_status()
134 */
Corentin Chary17e78f62010-01-13 22:21:33 +0100135#define WL_RSTS 0x01 /* internal Wifi */
136#define BT_RSTS 0x02 /* internal Bluetooth */
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100137#define WM_RSTS 0x08 /* internal wimax */
138#define WW_RSTS 0x20 /* internal wwan */
Corentin Charybe4ee822009-12-06 16:27:09 +0100139
Corentin Charybe18cda2007-01-26 14:04:35 +0100140/* LED */
Corentin Charyd99b5772010-01-22 21:20:57 +0100141#define METHOD_MLED "MLED"
142#define METHOD_TLED "TLED"
143#define METHOD_RLED "RLED" /* W1JC */
144#define METHOD_PLED "PLED" /* A7J */
145#define METHOD_GLED "GLED" /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100146
Corentin Chary722ad972007-01-26 14:04:55 +0100147/* LEDD */
Corentin Charyd99b5772010-01-22 21:20:57 +0100148#define METHOD_LEDD "SLCM"
Corentin Chary722ad972007-01-26 14:04:55 +0100149
Corentin Charybe966662009-08-29 10:28:29 +0200150/*
151 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100152 * WLED and BLED are not handled like other XLED, because in some dsdt
153 * they also control the WLAN/Bluetooth device.
154 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100155#define METHOD_WLAN "WLED"
156#define METHOD_BLUETOOTH "BLED"
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100157
158/* WWAN and WIMAX */
159#define METHOD_WWAN "GSMC"
160#define METHOD_WIMAX "WMXC"
161
Corentin Charyd99b5772010-01-22 21:20:57 +0100162#define METHOD_WL_STATUS "RSTS"
Corentin Chary4564de12007-01-26 14:04:40 +0100163
Corentin Chary6b7091e2007-01-26 14:04:45 +0100164/* Brightness */
Corentin Charyd99b5772010-01-22 21:20:57 +0100165#define METHOD_BRIGHTNESS_SET "SPLV"
166#define METHOD_BRIGHTNESS_GET "GPLV"
Corentin Chary6b7091e2007-01-26 14:04:45 +0100167
Corentin Chary78127b42007-01-26 14:04:49 +0100168/* Display */
Corentin Charyd99b5772010-01-22 21:20:57 +0100169#define METHOD_SWITCH_DISPLAY "SDSP"
Corentin Chary060cbce2010-01-28 10:52:40 +0100170
Corentin Charyd99b5772010-01-22 21:20:57 +0100171#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
172#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100173
Corentin Charye539c2f2007-05-06 14:47:06 +0200174/* GPS */
175/* R2H use different handle for GPS on/off */
Corentin Charyd99b5772010-01-22 21:20:57 +0100176#define METHOD_GPS_ON "SDON"
177#define METHOD_GPS_OFF "SDOF"
178#define METHOD_GPS_STATUS "GPST"
Corentin Charye539c2f2007-05-06 14:47:06 +0200179
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000180/* Keyboard light */
Corentin Charyd99b5772010-01-22 21:20:57 +0100181#define METHOD_KBD_LIGHT_SET "SLKB"
182#define METHOD_KBD_LIGHT_GET "GLKB"
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000183
Andy Ross8819de72011-10-14 11:13:35 +0200184/* For Pegatron Lucid tablet */
185#define DEVICE_NAME_PEGA "Lucid"
Andy Ross33989ba2011-10-14 11:13:36 +0200186
Andy Ross8819de72011-10-14 11:13:35 +0200187#define METHOD_PEGA_ENABLE "ENPR"
188#define METHOD_PEGA_DISABLE "DAPR"
Andy Ross33989ba2011-10-14 11:13:36 +0200189#define PEGA_ALS 0x04
190#define PEGA_ALS_POWER 0x05
191
Andy Ross8819de72011-10-14 11:13:35 +0200192#define METHOD_PEGA_READ "RDLN"
Andy Ross33989ba2011-10-14 11:13:36 +0200193#define PEGA_READ_ALS_H 0x02
194#define PEGA_READ_ALS_L 0x03
Andy Ross8819de72011-10-14 11:13:35 +0200195
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 /*
632 * Functions that actually update the LED's are called from a
633 * workqueue. By doing this as separate work rather than when the LED
634 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
635 * potentially bad time, such as a timer interrupt.
636 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100637 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
638 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100639 return -ENOMEM;
640
Corentin Charyaee0afb2010-01-26 21:01:34 +0100641 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
642 if (r)
643 goto error;
644 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
645 if (r)
646 goto error;
647 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
648 if (r)
649 goto error;
650 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
651 if (r)
652 goto error;
653 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
654 if (r)
655 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100656 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100657 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
658 struct asus_led *led = &asus->kled;
659 struct led_classdev *cdev = &led->led;
660
661 led->asus = asus;
662
663 INIT_WORK(&led->work, asus_kled_cdev_update);
664 cdev->name = "asus::kbd_backlight";
665 cdev->brightness_set = asus_kled_cdev_set;
666 cdev->brightness_get = asus_kled_cdev_get;
667 cdev->max_brightness = 3;
668 r = led_classdev_register(&asus->platform_device->dev, cdev);
669 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100670error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100671 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100672 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100673 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100674}
675
676/*
677 * Backlight device
678 */
Corentin Chary4d441512010-01-13 22:26:24 +0100679static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100680{
Corentin Charyd99b5772010-01-22 21:20:57 +0100681 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400682 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100683 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100684
Corentin Charyd99b5772010-01-22 21:20:57 +0100685 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
686 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100687 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700688 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100689
690 return value;
691}
692
Corentin Chary4d441512010-01-13 22:26:24 +0100693static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100694{
Corentin Charyd99b5772010-01-22 21:20:57 +0100695 struct asus_laptop *asus = bl_get_data(bd);
696
697 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700698 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100699 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100700 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100701 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100702}
703
704static int update_bl_status(struct backlight_device *bd)
705{
Richard Purdie599a52d2007-02-10 23:07:48 +0000706 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100707
Corentin Chary3b81cf92011-02-06 13:27:31 +0100708 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100709}
710
Lionel Debrouxacc24722010-11-16 14:14:02 +0100711static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100712 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100713 .update_status = update_bl_status,
714};
715
Corentin Charya539df52010-01-25 22:53:21 +0100716static int asus_backlight_notify(struct asus_laptop *asus)
717{
718 struct backlight_device *bd = asus->backlight_device;
719 int old = bd->props.brightness;
720
721 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
722
723 return old;
724}
725
Corentin Charybe4ee822009-12-06 16:27:09 +0100726static int asus_backlight_init(struct asus_laptop *asus)
727{
728 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500729 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100730
Corentin Chary71e687d2010-08-24 09:30:44 +0200731 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100732 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200733 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500734
Corentin Chary71e687d2010-08-24 09:30:44 +0200735 memset(&props, 0, sizeof(struct backlight_properties));
736 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700737 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100738
Corentin Chary71e687d2010-08-24 09:30:44 +0200739 bd = backlight_device_register(ASUS_LAPTOP_FILE,
740 &asus->platform_device->dev, asus,
741 &asusbl_ops, &props);
742 if (IS_ERR(bd)) {
743 pr_err("Could not register asus backlight device\n");
744 asus->backlight_device = NULL;
745 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100746 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200747
748 asus->backlight_device = bd;
749 bd->props.brightness = asus_read_brightness(bd);
750 bd->props.power = FB_BLANK_UNBLANK;
751 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100752 return 0;
753}
754
755static void asus_backlight_exit(struct asus_laptop *asus)
756{
757 if (asus->backlight_device)
758 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100759 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100760}
761
Corentin Chary85091b72007-01-26 14:04:30 +0100762/*
763 * Platform device handlers
764 */
765
766/*
767 * We write our info in page, we begin at offset off and cannot write more
768 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
769 * number of bytes written in page
770 */
771static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500772 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100773{
Corentin Chary9129d142009-12-01 22:39:41 +0100774 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100775 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400776 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200777 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100778 acpi_status rv = AE_OK;
779
Corentin Chary85091b72007-01-26 14:04:30 +0100780 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100781 * We use the easy way, we don't care of off and count,
782 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100783 */
784
Corentin Chary50a90c42009-11-30 21:55:12 +0100785 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
786 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100787 /*
788 * The SFUN method probably allows the original driver to get the list
789 * of features supported by a given model. For now, 0x0100 or 0x0800
790 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
791 * The significance of others is yet to be found.
792 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100793 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100794 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000795 len += sprintf(page + len, "SFUN value : %#x\n",
796 (uint) temp);
797 /*
798 * The HWRS method return informations about the hardware.
799 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
800 * The significance of others is yet to be found.
801 * If we don't find the method, we assume the device are present.
802 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100803 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000804 if (!ACPI_FAILURE(rv))
805 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100806 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100807 /*
808 * Another value for userspace: the ASYM method returns 0x02 for
809 * battery low and 0x04 for battery critical, its readings tend to be
810 * more accurate than those provided by _BST.
811 * Note: since not all the laptops provide this method, errors are
812 * silently ignored.
813 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100814 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100815 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000816 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100817 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100818 if (asus->dsdt_info) {
819 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100820 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100821 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100822 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100823 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100824 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100825 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100826 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100827 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100828 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100829 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100830 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100831 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100832 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100833 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100834 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
835 }
836
837 return len;
838}
839
840static int parse_arg(const char *buf, unsigned long count, int *val)
841{
842 if (!count)
843 return 0;
844 if (count > 31)
845 return -EINVAL;
846 if (sscanf(buf, "%i", val) != 1)
847 return -EINVAL;
848 return count;
849}
850
Corentin Chary17e78f62010-01-13 22:21:33 +0100851static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
852 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100853 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100854{
855 int rv, value;
856 int out = 0;
857
858 rv = parse_arg(buf, count, &value);
859 if (rv > 0)
860 out = value ? 1 : 0;
861
Corentin Charyd99b5772010-01-22 21:20:57 +0100862 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100863 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100864 return rv;
865}
866
867/*
Corentin Chary722ad972007-01-26 14:04:55 +0100868 * LEDD display
869 */
870static ssize_t show_ledd(struct device *dev,
871 struct device_attribute *attr, char *buf)
872{
Corentin Chary9129d142009-12-01 22:39:41 +0100873 struct asus_laptop *asus = dev_get_drvdata(dev);
874
Corentin Chary50a90c42009-11-30 21:55:12 +0100875 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100876}
877
878static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
879 const char *buf, size_t count)
880{
Corentin Chary9129d142009-12-01 22:39:41 +0100881 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100882 int rv, value;
883
884 rv = parse_arg(buf, count, &value);
885 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700886 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700887 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700888 return -ENODEV;
889 }
890 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100891 }
892 return rv;
893}
894
895/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100896 * Wireless
897 */
898static int asus_wireless_status(struct asus_laptop *asus, int mask)
899{
900 unsigned long long status;
901 acpi_status rv = AE_OK;
902
903 if (!asus->have_rsts)
904 return (asus->wireless_status & mask) ? 1 : 0;
905
Corentin Charyd99b5772010-01-22 21:20:57 +0100906 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
907 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100908 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700909 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100910 return -EINVAL;
911 }
912 return !!(status & mask);
913}
914
915/*
Corentin Chary4564de12007-01-26 14:04:40 +0100916 * WLAN
917 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100918static int asus_wlan_set(struct asus_laptop *asus, int status)
919{
920 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700921 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100922 return -EIO;
923 }
924 return 0;
925}
926
Corentin Chary4564de12007-01-26 14:04:40 +0100927static ssize_t show_wlan(struct device *dev,
928 struct device_attribute *attr, char *buf)
929{
Corentin Chary9129d142009-12-01 22:39:41 +0100930 struct asus_laptop *asus = dev_get_drvdata(dev);
931
Corentin Chary17e78f62010-01-13 22:21:33 +0100932 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100933}
934
935static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
936 const char *buf, size_t count)
937{
Corentin Chary9129d142009-12-01 22:39:41 +0100938 struct asus_laptop *asus = dev_get_drvdata(dev);
939
Corentin Charyd99b5772010-01-22 21:20:57 +0100940 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100941}
942
943/*
944 * Bluetooth
945 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100946static int asus_bluetooth_set(struct asus_laptop *asus, int status)
947{
948 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700949 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100950 return -EIO;
951 }
952 return 0;
953}
954
Corentin Chary4564de12007-01-26 14:04:40 +0100955static ssize_t show_bluetooth(struct device *dev,
956 struct device_attribute *attr, char *buf)
957{
Corentin Chary9129d142009-12-01 22:39:41 +0100958 struct asus_laptop *asus = dev_get_drvdata(dev);
959
Corentin Chary17e78f62010-01-13 22:21:33 +0100960 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100961}
962
Len Brown8def05f2007-01-30 01:46:43 -0500963static ssize_t store_bluetooth(struct device *dev,
964 struct device_attribute *attr, const char *buf,
965 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100966{
Corentin Chary9129d142009-12-01 22:39:41 +0100967 struct asus_laptop *asus = dev_get_drvdata(dev);
968
Corentin Charyd99b5772010-01-22 21:20:57 +0100969 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100970}
971
Corentin Chary78127b42007-01-26 14:04:49 +0100972/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100973 * Wimax
974 */
975static int asus_wimax_set(struct asus_laptop *asus, int status)
976{
977 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700978 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100979 return -EIO;
980 }
981 return 0;
982}
983
984static ssize_t show_wimax(struct device *dev,
985 struct device_attribute *attr, char *buf)
986{
987 struct asus_laptop *asus = dev_get_drvdata(dev);
988
989 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
990}
991
992static ssize_t store_wimax(struct device *dev,
993 struct device_attribute *attr, const char *buf,
994 size_t count)
995{
996 struct asus_laptop *asus = dev_get_drvdata(dev);
997
998 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
999}
1000
1001/*
1002 * Wwan
1003 */
1004static int asus_wwan_set(struct asus_laptop *asus, int status)
1005{
1006 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001007 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001008 return -EIO;
1009 }
1010 return 0;
1011}
1012
1013static ssize_t show_wwan(struct device *dev,
1014 struct device_attribute *attr, char *buf)
1015{
1016 struct asus_laptop *asus = dev_get_drvdata(dev);
1017
1018 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
1019}
1020
1021static ssize_t store_wwan(struct device *dev,
1022 struct device_attribute *attr, const char *buf,
1023 size_t count)
1024{
1025 struct asus_laptop *asus = dev_get_drvdata(dev);
1026
1027 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
1028}
1029
1030/*
Corentin Chary78127b42007-01-26 14:04:49 +01001031 * Display
1032 */
Corentin Chary4d441512010-01-13 22:26:24 +01001033static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +01001034{
1035 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +01001036 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001037 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +01001038 return;
1039}
1040
Corentin Chary78127b42007-01-26 14:04:49 +01001041/*
1042 * Experimental support for display switching. As of now: 1 should activate
1043 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1044 * Any combination (bitwise) of these will suffice. I never actually tested 4
1045 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1046 * for more info.
1047 */
1048static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1049 const char *buf, size_t count)
1050{
Corentin Chary9129d142009-12-01 22:39:41 +01001051 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001052 int rv, value;
1053
1054 rv = parse_arg(buf, count, &value);
1055 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001056 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001057 return rv;
1058}
1059
Corentin Chary8b857352007-01-26 14:04:58 +01001060/*
1061 * Light Sens
1062 */
Corentin Chary4d441512010-01-13 22:26:24 +01001063static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001064{
Andy Ross33989ba2011-10-14 11:13:36 +02001065 int ret;
1066
1067 if (asus->is_pega_lucid) {
1068 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
1069 if (!ret)
1070 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
1071 } else {
1072 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
1073 }
1074 if (ret)
1075 pr_warning("Error setting light sensor switch\n");
1076
Corentin Chary50a90c42009-11-30 21:55:12 +01001077 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001078}
1079
1080static ssize_t show_lssw(struct device *dev,
1081 struct device_attribute *attr, char *buf)
1082{
Corentin Chary9129d142009-12-01 22:39:41 +01001083 struct asus_laptop *asus = dev_get_drvdata(dev);
1084
Corentin Chary50a90c42009-11-30 21:55:12 +01001085 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001086}
1087
1088static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1089 const char *buf, size_t count)
1090{
Corentin Chary9129d142009-12-01 22:39:41 +01001091 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001092 int rv, value;
1093
1094 rv = parse_arg(buf, count, &value);
1095 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001096 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001097
1098 return rv;
1099}
1100
Corentin Chary4d441512010-01-13 22:26:24 +01001101static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001102{
Corentin Charyd99b5772010-01-22 21:20:57 +01001103 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001104 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001105 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001106}
1107
1108static ssize_t show_lslvl(struct device *dev,
1109 struct device_attribute *attr, char *buf)
1110{
Corentin Chary9129d142009-12-01 22:39:41 +01001111 struct asus_laptop *asus = dev_get_drvdata(dev);
1112
Corentin Chary50a90c42009-11-30 21:55:12 +01001113 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001114}
1115
1116static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1117 const char *buf, size_t count)
1118{
Corentin Chary9129d142009-12-01 22:39:41 +01001119 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001120 int rv, value;
1121
1122 rv = parse_arg(buf, count, &value);
1123 if (rv > 0) {
1124 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1125 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001126 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001127 }
1128
1129 return rv;
1130}
1131
Andy Ross33989ba2011-10-14 11:13:36 +02001132static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1133{
1134 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1135 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1136 &buffer);
1137 if (!err) {
1138 union acpi_object *obj = buffer.pointer;
1139 if (obj && obj->type == ACPI_TYPE_INTEGER)
1140 *result = obj->integer.value;
1141 else
1142 err = -EIO;
1143 }
1144 return err;
1145}
1146
1147static ssize_t show_lsvalue(struct device *dev,
1148 struct device_attribute *attr, char *buf)
1149{
1150 struct asus_laptop *asus = dev_get_drvdata(dev);
1151 int err, hi, lo;
1152
1153 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1154 if (!err)
1155 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1156 if (!err)
1157 return sprintf(buf, "%d\n", 10 * hi + lo);
1158 return err;
1159}
1160
Corentin Charye539c2f2007-05-06 14:47:06 +02001161/*
1162 * GPS
1163 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001164static int asus_gps_status(struct asus_laptop *asus)
1165{
1166 unsigned long long status;
1167 acpi_status rv = AE_OK;
1168
Corentin Charyd99b5772010-01-22 21:20:57 +01001169 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1170 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001171 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001172 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001173 return -ENODEV;
1174 }
1175 return !!status;
1176}
1177
1178static int asus_gps_switch(struct asus_laptop *asus, int status)
1179{
Corentin Charyd99b5772010-01-22 21:20:57 +01001180 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001181
Corentin Charyd99b5772010-01-22 21:20:57 +01001182 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001183 return -ENODEV;
1184 return 0;
1185}
1186
Corentin Charye539c2f2007-05-06 14:47:06 +02001187static ssize_t show_gps(struct device *dev,
1188 struct device_attribute *attr, char *buf)
1189{
Corentin Chary9129d142009-12-01 22:39:41 +01001190 struct asus_laptop *asus = dev_get_drvdata(dev);
1191
Corentin Chary6358bf22010-01-13 21:55:44 +01001192 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001193}
1194
1195static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1196 const char *buf, size_t count)
1197{
Corentin Chary060cbce2010-01-28 10:52:40 +01001198 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001199 int rv, value;
1200 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001201
Corentin Chary6358bf22010-01-13 21:55:44 +01001202 rv = parse_arg(buf, count, &value);
1203 if (rv <= 0)
1204 return -EINVAL;
1205 ret = asus_gps_switch(asus, !!value);
1206 if (ret)
1207 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001208 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001209 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001210}
1211
Corentin Chary034ce902009-01-20 16:17:43 +01001212/*
Corentin Chary18e13112010-01-25 23:29:24 +01001213 * rfkill
1214 */
1215static int asus_gps_rfkill_set(void *data, bool blocked)
1216{
Corentin Chary23f45c32010-08-24 09:30:46 +02001217 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001218
Corentin Chary23f45c32010-08-24 09:30:46 +02001219 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001220}
1221
1222static const struct rfkill_ops asus_gps_rfkill_ops = {
1223 .set_block = asus_gps_rfkill_set,
1224};
1225
1226static void asus_rfkill_exit(struct asus_laptop *asus)
1227{
1228 if (asus->gps_rfkill) {
1229 rfkill_unregister(asus->gps_rfkill);
1230 rfkill_destroy(asus->gps_rfkill);
1231 asus->gps_rfkill = NULL;
1232 }
1233}
1234
1235static int asus_rfkill_init(struct asus_laptop *asus)
1236{
1237 int result;
1238
1239 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1240 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1241 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1242 return 0;
1243
1244 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1245 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001246 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001247 if (!asus->gps_rfkill)
1248 return -EINVAL;
1249
1250 result = rfkill_register(asus->gps_rfkill);
1251 if (result) {
1252 rfkill_destroy(asus->gps_rfkill);
1253 asus->gps_rfkill = NULL;
1254 }
1255
1256 return result;
1257}
1258
1259/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001260 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001261 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001262static void asus_input_notify(struct asus_laptop *asus, int event)
1263{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001264 if (asus->inputdev)
1265 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001266}
1267
1268static int asus_input_init(struct asus_laptop *asus)
1269{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001270 struct input_dev *input;
1271 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001272
Corentin Chary66a71dd2010-01-25 22:50:11 +01001273 input = input_allocate_device();
1274 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001275 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001276 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001277 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001278 input->name = "Asus Laptop extra buttons";
1279 input->phys = ASUS_LAPTOP_FILE "/input0";
1280 input->id.bustype = BUS_HOST;
1281 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001282
Corentin Chary66a71dd2010-01-25 22:50:11 +01001283 error = sparse_keymap_setup(input, asus_keymap, NULL);
1284 if (error) {
1285 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001286 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001287 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001288 error = input_register_device(input);
1289 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001290 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001291 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001292 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001293
1294 asus->inputdev = input;
1295 return 0;
1296
Axel Lin45036ae2010-07-05 15:29:00 +08001297err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001298 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001299err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001300 input_free_device(input);
1301 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001302}
1303
1304static void asus_input_exit(struct asus_laptop *asus)
1305{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001306 if (asus->inputdev) {
1307 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001308 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001309 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001310 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001311}
1312
1313/*
1314 * ACPI driver
1315 */
Corentin Chary600ad522009-11-30 21:42:42 +01001316static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001317{
Corentin Chary9129d142009-12-01 22:39:41 +01001318 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001319 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001320
Corentin Chary619d8b12009-11-28 10:35:37 +01001321 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001322 count = asus->event_count[event % 128]++;
1323 acpi_bus_generate_proc_event(asus->device, event, count);
1324 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1325 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001326 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001327
Corentin Charya539df52010-01-25 22:53:21 +01001328 /* Brightness events are special */
1329 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1330
1331 /* Ignore them completely if the acpi video driver is used */
1332 if (asus->backlight_device != NULL) {
1333 /* Update the backlight device. */
1334 asus_backlight_notify(asus);
1335 }
1336 return ;
1337 }
Corentin Charybe4ee822009-12-06 16:27:09 +01001338 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001339}
1340
Corentin Chary2a1fd642010-01-26 21:02:23 +01001341static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1342static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001343static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1344 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001345static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1346static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001347static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001348static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001349static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001350static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1351static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1352static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1353
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001354static struct attribute *asus_attributes[] = {
1355 &dev_attr_infos.attr,
1356 &dev_attr_wlan.attr,
1357 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001358 &dev_attr_wimax.attr,
1359 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001360 &dev_attr_display.attr,
1361 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001362 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001363 &dev_attr_ls_level.attr,
1364 &dev_attr_ls_switch.attr,
1365 &dev_attr_gps.attr,
1366 NULL
1367};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001368
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001369static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1370 struct attribute *attr,
1371 int idx)
1372{
1373 struct device *dev = container_of(kobj, struct device, kobj);
1374 struct platform_device *pdev = to_platform_device(dev);
1375 struct asus_laptop *asus = platform_get_drvdata(pdev);
1376 acpi_handle handle = asus->handle;
1377 bool supported;
1378
Andy Ross33989ba2011-10-14 11:13:36 +02001379 if (asus->is_pega_lucid) {
1380 /* no ls_level interface on the Lucid */
1381 if (attr == &dev_attr_ls_switch.attr)
1382 supported = true;
1383 else if (attr == &dev_attr_ls_level.attr)
1384 supported = false;
1385 else
1386 goto normal;
1387
1388 return supported;
1389 }
1390
1391normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001392 if (attr == &dev_attr_wlan.attr) {
1393 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1394
1395 } else if (attr == &dev_attr_bluetooth.attr) {
1396 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1397
1398 } else if (attr == &dev_attr_display.attr) {
1399 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1400
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001401 } else if (attr == &dev_attr_wimax.attr) {
1402 supported =
1403 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1404
1405 } else if (attr == &dev_attr_wwan.attr) {
1406 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1407
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001408 } else if (attr == &dev_attr_ledd.attr) {
1409 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1410
1411 } else if (attr == &dev_attr_ls_switch.attr ||
1412 attr == &dev_attr_ls_level.attr) {
1413 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001414 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1415 } else if (attr == &dev_attr_ls_value.attr) {
1416 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001417 } else if (attr == &dev_attr_gps.attr) {
1418 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1419 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1420 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1421 } else {
1422 supported = true;
1423 }
1424
1425 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001426}
1427
Corentin Chary2a1fd642010-01-26 21:02:23 +01001428
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001429static const struct attribute_group asus_attr_group = {
1430 .is_visible = asus_sysfs_is_visible,
1431 .attrs = asus_attributes,
1432};
Corentin Chary85091b72007-01-26 14:04:30 +01001433
Corentin Chary9129d142009-12-01 22:39:41 +01001434static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001435{
Corentin Chary71e687d2010-08-24 09:30:44 +02001436 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001437
Corentin Chary50a90c42009-11-30 21:55:12 +01001438 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1439 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001440 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001441 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001442
Corentin Chary71e687d2010-08-24 09:30:44 +02001443 result = platform_device_add(asus->platform_device);
1444 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001445 goto fail_platform_device;
1446
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001447 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1448 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001449 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001450 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001451
Corentin Chary600ad522009-11-30 21:42:42 +01001452 return 0;
1453
1454fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001455 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001456fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001457 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001458 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001459}
1460
Corentin Chary9129d142009-12-01 22:39:41 +01001461static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001462{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001463 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001464 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001465}
1466
1467static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001468 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001469 .name = ASUS_LAPTOP_FILE,
1470 .owner = THIS_MODULE,
Andy Rossb23910c2011-10-14 11:13:38 +02001471 },
Corentin Chary85091b72007-01-26 14:04:30 +01001472};
1473
Corentin Chary85091b72007-01-26 14:04:30 +01001474/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001475 * This function is used to initialize the context with right values. In this
1476 * method, we can make all the detection we want, and modify the asus_laptop
1477 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001478 */
Corentin Chary7c247642009-11-30 22:13:54 +01001479static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001480{
1481 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001482 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001483 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001484 char *string = NULL;
1485 acpi_status status;
1486
1487 /*
1488 * Get DSDT headers early enough to allow for differentiating between
1489 * models, but late enough to allow acpi_bus_register_driver() to fail
1490 * before doing anything ACPI-specific. Should we encounter a machine,
1491 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001492 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001493 */
Corentin Chary7c247642009-11-30 22:13:54 +01001494 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001495 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001496 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001497
1498 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001499 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001500 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001501 return -ENODEV;
1502 }
1503
1504 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001505 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001506 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001507 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001508 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001509 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001510 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001511 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001512
Corentin Chary185e5af2007-03-11 10:27:33 +01001513 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001514 if (write_acpi_int(asus->handle, "CWAP", wapf))
1515 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001516 /*
1517 * Try to match the object returned by INIT to the specific model.
1518 * Handle every possible object (or the lack of thereof) the DSDT
1519 * writers might throw at us. When in trouble, we pass NULL to
1520 * asus_model_match() and try something completely different.
1521 */
1522 if (buffer.pointer) {
1523 model = buffer.pointer;
1524 switch (model->type) {
1525 case ACPI_TYPE_STRING:
1526 string = model->string.pointer;
1527 break;
1528 case ACPI_TYPE_BUFFER:
1529 string = model->buffer.pointer;
1530 break;
1531 default:
1532 string = "";
1533 break;
1534 }
1535 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001536 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001537 if (!asus->name) {
1538 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001539 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001540 }
Corentin Chary85091b72007-01-26 14:04:30 +01001541
Len Brown8def05f2007-01-30 01:46:43 -05001542 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001543 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001544
Corentin Chary4564de12007-01-26 14:04:40 +01001545 /*
1546 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001547 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1548 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001549 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001550 */
Corentin Chary9a816852007-03-11 10:25:38 +01001551 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001552 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001553 if (!ACPI_FAILURE(status))
1554 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001555
Corentin Charyd99b5772010-01-22 21:20:57 +01001556 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001557 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001558
Corentin Chary85091b72007-01-26 14:04:30 +01001559 kfree(model);
1560
1561 return AE_OK;
1562}
1563
Corentin Chary9129d142009-12-01 22:39:41 +01001564static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001565{
1566 int result = 0;
1567
Corentin Chary50a90c42009-11-30 21:55:12 +01001568 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001569 if (result)
1570 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001571 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001572 pr_err("Hotkey device not present, aborting\n");
1573 return -ENODEV;
1574 }
1575
Corentin Chary7c247642009-11-30 22:13:54 +01001576 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001577 if (result)
1578 return result;
1579
Corentin Chary600ad522009-11-30 21:42:42 +01001580 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001581 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001582 asus_bluetooth_set(asus, !!bluetooth_status);
1583
Corentin Charyd0930a22010-01-17 17:21:13 +01001584 if (wlan_status >= 0)
1585 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001586
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001587 if (wimax_status >= 0)
1588 asus_wimax_set(asus, !!wimax_status);
1589
1590 if (wwan_status >= 0)
1591 asus_wwan_set(asus, !!wwan_status);
1592
Corentin Chary600ad522009-11-30 21:42:42 +01001593 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001594 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001595 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001596
1597 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001598 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001599
1600 /* Set initial values of light sensor and level */
Andy Rossabec04d2011-10-14 11:13:37 +02001601 asus->light_switch = !!als_status;
Corentin Charybe4ee822009-12-06 16:27:09 +01001602 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001603
Andy Ross33989ba2011-10-14 11:13:36 +02001604 if (asus->is_pega_lucid) {
1605 asus_als_switch(asus, asus->light_switch);
1606 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1607 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001608 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001609 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001610 }
Corentin Chary600ad522009-11-30 21:42:42 +01001611
Corentin Chary600ad522009-11-30 21:42:42 +01001612 return result;
1613}
1614
Corentin Charyaf96f872011-02-06 13:27:30 +01001615static void __devinit asus_dmi_check(void)
1616{
1617 const char *model;
1618
1619 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1620 if (!model)
1621 return;
1622
1623 /* On L1400B WLED control the sound card, don't mess with it ... */
1624 if (strncmp(model, "L1400B", 6) == 0) {
1625 wlan_status = -1;
1626 }
1627}
1628
Corentin Chary71e687d2010-08-24 09:30:44 +02001629static bool asus_device_present;
1630
Corentin Chary600ad522009-11-30 21:42:42 +01001631static int __devinit asus_acpi_add(struct acpi_device *device)
1632{
Corentin Chary9129d142009-12-01 22:39:41 +01001633 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001634 int result;
1635
1636 pr_notice("Asus Laptop Support version %s\n",
1637 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001638 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1639 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001640 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001641 asus->handle = device->handle;
1642 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1643 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1644 device->driver_data = asus;
1645 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001646
Corentin Charyaf96f872011-02-06 13:27:30 +01001647 asus_dmi_check();
1648
Corentin Chary9129d142009-12-01 22:39:41 +01001649 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001650 if (result)
1651 goto fail_platform;
1652
1653 /*
Andy Ross8819de72011-10-14 11:13:35 +02001654 * Need platform type detection first, then the platform
1655 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001656 */
Andy Ross8819de72011-10-14 11:13:35 +02001657 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001658 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001659 if (result)
1660 goto fail_platform;
1661
1662 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001663 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001664 if (result)
1665 goto fail_backlight;
1666 } else
1667 pr_info("Backlight controlled by ACPI video driver\n");
1668
Corentin Chary9129d142009-12-01 22:39:41 +01001669 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001670 if (result)
1671 goto fail_input;
1672
Corentin Chary9129d142009-12-01 22:39:41 +01001673 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001674 if (result)
1675 goto fail_led;
1676
Corentin Chary18e13112010-01-25 23:29:24 +01001677 result = asus_rfkill_init(asus);
1678 if (result)
1679 goto fail_rfkill;
1680
Andy Rossb23910c2011-10-14 11:13:38 +02001681 result = pega_accel_init(asus);
1682 if (result && result != -ENODEV)
1683 goto fail_pega_accel;
1684
Corentin Chary600ad522009-11-30 21:42:42 +01001685 asus_device_present = true;
1686 return 0;
1687
Andy Rossb23910c2011-10-14 11:13:38 +02001688fail_pega_accel:
1689 asus_rfkill_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001690fail_rfkill:
1691 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001692fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001693 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001694fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001695 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001696fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001697 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001698fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001699 kfree(asus->name);
1700 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001701
1702 return result;
1703}
1704
1705static int asus_acpi_remove(struct acpi_device *device, int type)
1706{
Corentin Chary9129d142009-12-01 22:39:41 +01001707 struct asus_laptop *asus = acpi_driver_data(device);
1708
1709 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001710 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001711 asus_led_exit(asus);
1712 asus_input_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001713 pega_accel_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001714 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001715
Corentin Chary50a90c42009-11-30 21:55:12 +01001716 kfree(asus->name);
1717 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001718 return 0;
1719}
1720
1721static const struct acpi_device_id asus_device_ids[] = {
1722 {"ATK0100", 0},
1723 {"ATK0101", 0},
1724 {"", 0},
1725};
1726MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1727
1728static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001729 .name = ASUS_LAPTOP_NAME,
1730 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001731 .owner = THIS_MODULE,
1732 .ids = asus_device_ids,
1733 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1734 .ops = {
1735 .add = asus_acpi_add,
1736 .remove = asus_acpi_remove,
1737 .notify = asus_acpi_notify,
1738 },
1739};
1740
Corentin Chary85091b72007-01-26 14:04:30 +01001741static int __init asus_laptop_init(void)
1742{
1743 int result;
1744
Corentin Chary600ad522009-11-30 21:42:42 +01001745 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001746 if (result < 0)
1747 return result;
1748
Corentin Chary600ad522009-11-30 21:42:42 +01001749 result = acpi_bus_register_driver(&asus_acpi_driver);
1750 if (result < 0)
1751 goto fail_acpi_driver;
1752 if (!asus_device_present) {
1753 result = -ENODEV;
1754 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001755 }
Len Brown8def05f2007-01-30 01:46:43 -05001756 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001757
Corentin Chary600ad522009-11-30 21:42:42 +01001758fail_no_device:
1759 acpi_bus_unregister_driver(&asus_acpi_driver);
1760fail_acpi_driver:
1761 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001762 return result;
1763}
1764
Corentin Chary600ad522009-11-30 21:42:42 +01001765static void __exit asus_laptop_exit(void)
1766{
1767 acpi_bus_unregister_driver(&asus_acpi_driver);
1768 platform_driver_unregister(&platform_driver);
1769}
1770
Corentin Chary85091b72007-01-26 14:04:30 +01001771module_init(asus_laptop_init);
1772module_exit(asus_laptop_exit);