blob: b7944f9038866f2e50ba3c84604e2e7dea7f55b0 [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"
Anisse Astier14908392011-10-14 11:13:42 +0200189#define PEGA_WLAN 0x00
190#define PEGA_BLUETOOTH 0x01
191#define PEGA_WWAN 0x02
Andy Ross33989ba2011-10-14 11:13:36 +0200192#define PEGA_ALS 0x04
193#define PEGA_ALS_POWER 0x05
194
Andy Ross8819de72011-10-14 11:13:35 +0200195#define METHOD_PEGA_READ "RDLN"
Andy Ross33989ba2011-10-14 11:13:36 +0200196#define PEGA_READ_ALS_H 0x02
197#define PEGA_READ_ALS_L 0x03
Andy Ross8819de72011-10-14 11:13:35 +0200198
Andy Rossb23910c2011-10-14 11:13:38 +0200199#define PEGA_ACCEL_NAME "pega_accel"
200#define PEGA_ACCEL_DESC "Pegatron Lucid Tablet Accelerometer"
201#define METHOD_XLRX "XLRX"
202#define METHOD_XLRY "XLRY"
203#define METHOD_XLRZ "XLRZ"
204#define PEGA_ACC_CLAMP 512 /* 1G accel is reported as ~256, so clamp to 2G */
205#define PEGA_ACC_RETRIES 3
206
Corentin Chary85091b72007-01-26 14:04:30 +0100207/*
Corentin Chary9129d142009-12-01 22:39:41 +0100208 * Define a specific led structure to keep the main structure clean
209 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100210struct asus_led {
211 int wk;
212 struct work_struct work;
213 struct led_classdev led;
214 struct asus_laptop *asus;
215 const char *method;
Corentin Chary9129d142009-12-01 22:39:41 +0100216};
217
218/*
Anisse Astier14908392011-10-14 11:13:42 +0200219 * Same thing for rfkill
220 */
221struct asus_pega_rfkill {
222 int control_id; /* type of control. Maps to PEGA_* values */
223 struct rfkill *rfkill;
224 struct asus_laptop *asus;
225};
226
227/*
Corentin Chary85091b72007-01-26 14:04:30 +0100228 * This is the main structure, we can use it to store anything interesting
229 * about the hotk device
230 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100231struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200232 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100233
Corentin Chary7c247642009-11-30 22:13:54 +0100234 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100235 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100236 struct acpi_device *device; /* the device we are in */
237 struct backlight_device *backlight_device;
Corentin Chary9129d142009-12-01 22:39:41 +0100238
Corentin Chary7c247642009-11-30 22:13:54 +0100239 struct input_dev *inputdev;
Corentin Chary9129d142009-12-01 22:39:41 +0100240 struct key_entry *keymap;
Andy Rossb23910c2011-10-14 11:13:38 +0200241 struct input_polled_dev *pega_accel_poll;
Corentin Chary9129d142009-12-01 22:39:41 +0100242
Corentin Charyaee0afb2010-01-26 21:01:34 +0100243 struct asus_led mled;
244 struct asus_led tled;
245 struct asus_led rled;
246 struct asus_led pled;
247 struct asus_led gled;
248 struct asus_led kled;
249 struct workqueue_struct *led_workqueue;
Corentin Chary7c247642009-11-30 22:13:54 +0100250
Corentin Charyaa9df932010-01-13 21:49:10 +0100251 int wireless_status;
252 bool have_rsts;
Andy Ross8819de72011-10-14 11:13:35 +0200253 bool is_pega_lucid;
Andy Rossb23910c2011-10-14 11:13:38 +0200254 bool pega_acc_live;
255 int pega_acc_x;
256 int pega_acc_y;
257 int pega_acc_z;
Corentin Charyaa9df932010-01-13 21:49:10 +0100258
Corentin Chary18e13112010-01-25 23:29:24 +0100259 struct rfkill *gps_rfkill;
260
Anisse Astier14908392011-10-14 11:13:42 +0200261 struct asus_pega_rfkill wlanrfk;
262 struct asus_pega_rfkill btrfk;
263 struct asus_pega_rfkill wwanrfk;
264
Corentin Charybe966662009-08-29 10:28:29 +0200265 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200266 u32 ledd_status; /* status of the LED display */
267 u8 light_level; /* light sensor level */
268 u8 light_switch; /* light sensor switch value */
269 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100270};
271
Corentin Chary9129d142009-12-01 22:39:41 +0100272static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100273 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100274 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
275 {KE_KEY, 0x05, { KEY_WLAN } },
276 {KE_KEY, 0x08, { KEY_F13 } },
277 {KE_KEY, 0x17, { KEY_ZOOM } },
278 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100279 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100280 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
281 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
282 {KE_KEY, 0x32, { KEY_MUTE } },
283 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
284 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
285 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
286 {KE_KEY, 0x41, { KEY_NEXTSONG } },
287 {KE_KEY, 0x43, { KEY_STOPCD } },
288 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
289 {KE_KEY, 0x4c, { KEY_MEDIA } },
290 {KE_KEY, 0x50, { KEY_EMAIL } },
291 {KE_KEY, 0x51, { KEY_WWW } },
292 {KE_KEY, 0x55, { KEY_CALC } },
293 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
294 {KE_KEY, 0x5D, { KEY_WLAN } },
295 {KE_KEY, 0x5E, { KEY_WLAN } },
296 {KE_KEY, 0x5F, { KEY_WLAN } },
297 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
298 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
299 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
300 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
301 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d72010-01-17 17:37:19 +0100302 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
303 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100304 {KE_KEY, 0x82, { KEY_CAMERA } },
305 {KE_KEY, 0x88, { KEY_WLAN } },
306 {KE_KEY, 0x8A, { KEY_PROG1 } },
307 {KE_KEY, 0x95, { KEY_MEDIA } },
308 {KE_KEY, 0x99, { KEY_PHONE } },
309 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
310 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200311 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100312 {KE_END, 0},
313};
314
Corentin Chary66a71dd2010-01-25 22:50:11 +0100315
Corentin Chary85091b72007-01-26 14:04:30 +0100316/*
317 * This function evaluates an ACPI method, given an int as parameter, the
318 * method is searched within the scope of the handle, can be NULL. The output
319 * of the method is written is output, which can also be NULL
320 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100321 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100322 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100323static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
324 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100325{
Corentin Charybe966662009-08-29 10:28:29 +0200326 struct acpi_object_list params; /* list of input parameters (an int) */
327 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100328 acpi_status status;
329
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100330 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700331 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100332
Corentin Chary85091b72007-01-26 14:04:30 +0100333 params.count = 1;
334 params.pointer = &in_obj;
335 in_obj.type = ACPI_TYPE_INTEGER;
336 in_obj.integer.value = val;
337
338 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100339 if (status == AE_OK)
340 return 0;
341 else
342 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100343}
344
Corentin Charyd8c67322009-11-28 10:27:51 +0100345static int write_acpi_int(acpi_handle handle, const char *method, int val)
346{
347 return write_acpi_int_ret(handle, method, val, NULL);
348}
349
Corentin Charyd99b5772010-01-22 21:20:57 +0100350static int acpi_check_handle(acpi_handle handle, const char *method,
351 acpi_handle *ret)
352{
353 acpi_status status;
354
355 if (method == NULL)
356 return -ENODEV;
357
358 if (ret)
359 status = acpi_get_handle(handle, (char *)method,
360 ret);
361 else {
362 acpi_handle dummy;
363
364 status = acpi_get_handle(handle, (char *)method,
365 &dummy);
366 }
367
368 if (status != AE_OK) {
369 if (ret)
Joe Perches5ad77dc2011-03-29 15:21:35 -0700370 pr_warn("Error finding %s\n", method);
Corentin Charyd99b5772010-01-22 21:20:57 +0100371 return -ENODEV;
372 }
373 return 0;
374}
375
Andy Ross8819de72011-10-14 11:13:35 +0200376static bool asus_check_pega_lucid(struct asus_laptop *asus)
377{
378 return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
379 !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
380 !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
381 !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
382}
383
Andy Ross33989ba2011-10-14 11:13:36 +0200384static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
385{
386 char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
387 return write_acpi_int(asus->handle, method, unit);
388}
389
Andy Rossb23910c2011-10-14 11:13:38 +0200390static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
391{
392 int i, delta;
393 unsigned long long val;
394 for (i = 0; i < PEGA_ACC_RETRIES; i++) {
395 acpi_evaluate_integer(asus->handle, method, NULL, &val);
396
397 /* The output is noisy. From reading the ASL
398 * dissassembly, timeout errors are returned with 1's
399 * in the high word, and the lack of locking around
400 * thei hi/lo byte reads means that a transition
401 * between (for example) -1 and 0 could be read as
402 * 0xff00 or 0x00ff. */
403 delta = abs(curr - (short)val);
404 if (delta < 128 && !(val & ~0xffff))
405 break;
406 }
407 return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP);
408}
409
410static void pega_accel_poll(struct input_polled_dev *ipd)
411{
412 struct device *parent = ipd->input->dev.parent;
413 struct asus_laptop *asus = dev_get_drvdata(parent);
414
415 /* In some cases, the very first call to poll causes a
416 * recursive fault under the polldev worker. This is
417 * apparently related to very early userspace access to the
418 * device, and perhaps a firmware bug. Fake the first report. */
419 if (!asus->pega_acc_live) {
420 asus->pega_acc_live = true;
421 input_report_abs(ipd->input, ABS_X, 0);
422 input_report_abs(ipd->input, ABS_Y, 0);
423 input_report_abs(ipd->input, ABS_Z, 0);
424 input_sync(ipd->input);
425 return;
426 }
427
428 asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX);
429 asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY);
430 asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ);
431
432 /* Note transform, convert to "right/up/out" in the native
433 * landscape orientation (i.e. the vector is the direction of
434 * "real up" in the device's cartiesian coordinates). */
435 input_report_abs(ipd->input, ABS_X, -asus->pega_acc_x);
436 input_report_abs(ipd->input, ABS_Y, -asus->pega_acc_y);
437 input_report_abs(ipd->input, ABS_Z, asus->pega_acc_z);
438 input_sync(ipd->input);
439}
440
441static void pega_accel_exit(struct asus_laptop *asus)
442{
443 if (asus->pega_accel_poll) {
444 input_unregister_polled_device(asus->pega_accel_poll);
445 input_free_polled_device(asus->pega_accel_poll);
446 }
447 asus->pega_accel_poll = NULL;
448}
449
450static int pega_accel_init(struct asus_laptop *asus)
451{
452 int err;
453 struct input_polled_dev *ipd;
454
455 if (!asus->is_pega_lucid)
456 return -ENODEV;
457
458 if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) ||
459 acpi_check_handle(asus->handle, METHOD_XLRY, NULL) ||
460 acpi_check_handle(asus->handle, METHOD_XLRZ, NULL))
461 return -ENODEV;
462
463 ipd = input_allocate_polled_device();
464 if (!ipd)
465 return -ENOMEM;
466
467 ipd->poll = pega_accel_poll;
468 ipd->poll_interval = 125;
469 ipd->poll_interval_min = 50;
470 ipd->poll_interval_max = 2000;
471
472 ipd->input->name = PEGA_ACCEL_DESC;
473 ipd->input->phys = PEGA_ACCEL_NAME "/input0";
474 ipd->input->dev.parent = &asus->platform_device->dev;
475 ipd->input->id.bustype = BUS_HOST;
476
477 set_bit(EV_ABS, ipd->input->evbit);
478 input_set_abs_params(ipd->input, ABS_X,
479 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
480 input_set_abs_params(ipd->input, ABS_Y,
481 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
482 input_set_abs_params(ipd->input, ABS_Z,
483 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
484
485 err = input_register_polled_device(ipd);
486 if (err)
487 goto exit;
488
489 asus->pega_accel_poll = ipd;
490 return 0;
491
492exit:
493 input_free_polled_device(ipd);
494 return err;
495}
496
Corentin Chary17e78f62010-01-13 22:21:33 +0100497/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100498static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100499 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100500{
Corentin Charyd99b5772010-01-22 21:20:57 +0100501 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100502 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100503 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100504 value = !value + 1;
505 else
506 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100507
Corentin Charye5593bf2010-01-17 17:20:11 +0100508 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100509}
510
Corentin Charybe4ee822009-12-06 16:27:09 +0100511/*
512 * LEDs
513 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100514/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100515static void asus_led_cdev_set(struct led_classdev *led_cdev,
516 enum led_brightness value)
517{
518 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
519 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100520
Corentin Charyaee0afb2010-01-26 21:01:34 +0100521 led->wk = !!value;
522 queue_work(asus->led_workqueue, &led->work);
523}
524
525static void asus_led_cdev_update(struct work_struct *work)
526{
527 struct asus_led *led = container_of(work, struct asus_led, work);
528 struct asus_laptop *asus = led->asus;
529
530 asus_led_set(asus, led->method, led->wk);
531}
532
533static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
534{
535 return led_cdev->brightness;
536}
Corentin Charybe18cda2007-01-26 14:04:35 +0100537
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000538/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100539 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000540 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100541static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000542{
543 unsigned long long kblv;
544 struct acpi_object_list params;
545 union acpi_object in_obj;
546 acpi_status rv;
547
548 params.count = 1;
549 params.pointer = &in_obj;
550 in_obj.type = ACPI_TYPE_INTEGER;
551 in_obj.integer.value = 2;
552
Corentin Charyd99b5772010-01-22 21:20:57 +0100553 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
554 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000555 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700556 pr_warn("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100557 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000558 }
559 return kblv;
560}
561
Corentin Chary4d441512010-01-13 22:26:24 +0100562static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000563{
564 if (kblv > 0)
565 kblv = (1 << 7) | (kblv & 0x7F);
566 else
567 kblv = 0;
568
Corentin Charyd99b5772010-01-22 21:20:57 +0100569 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700570 pr_warn("Keyboard LED display write failed\n");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000571 return -EINVAL;
572 }
573 return 0;
574}
575
Corentin Charyaee0afb2010-01-26 21:01:34 +0100576static void asus_kled_cdev_set(struct led_classdev *led_cdev,
577 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000578{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100579 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
580 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100581
Corentin Chary060cbce2010-01-28 10:52:40 +0100582 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100583 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000584}
585
Corentin Charyaee0afb2010-01-26 21:01:34 +0100586static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000587{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100588 struct asus_led *led = container_of(work, struct asus_led, work);
589 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100590
Corentin Charyaee0afb2010-01-26 21:01:34 +0100591 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000592}
593
Corentin Charyaee0afb2010-01-26 21:01:34 +0100594static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000595{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100596 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
597 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100598
599 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000600}
601
Corentin Charybe4ee822009-12-06 16:27:09 +0100602static void asus_led_exit(struct asus_laptop *asus)
603{
Axel Lin8fcf71a2011-08-08 17:17:18 +0800604 if (!IS_ERR_OR_NULL(asus->mled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100605 led_classdev_unregister(&asus->mled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800606 if (!IS_ERR_OR_NULL(asus->tled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100607 led_classdev_unregister(&asus->tled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800608 if (!IS_ERR_OR_NULL(asus->pled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100609 led_classdev_unregister(&asus->pled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800610 if (!IS_ERR_OR_NULL(asus->rled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100611 led_classdev_unregister(&asus->rled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800612 if (!IS_ERR_OR_NULL(asus->gled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100613 led_classdev_unregister(&asus->gled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800614 if (!IS_ERR_OR_NULL(asus->kled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100615 led_classdev_unregister(&asus->kled.led);
616 if (asus->led_workqueue) {
617 destroy_workqueue(asus->led_workqueue);
618 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100619 }
620}
621
622/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100623static int asus_led_register(struct asus_laptop *asus,
624 struct asus_led *led,
625 const char *name, const char *method)
626{
627 struct led_classdev *led_cdev = &led->led;
628
629 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100630 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100631
632 led->asus = asus;
633 led->method = method;
634
635 INIT_WORK(&led->work, asus_led_cdev_update);
636 led_cdev->name = name;
637 led_cdev->brightness_set = asus_led_cdev_set;
638 led_cdev->brightness_get = asus_led_cdev_get;
639 led_cdev->max_brightness = 1;
640 return led_classdev_register(&asus->platform_device->dev, led_cdev);
641}
Corentin Charybe4ee822009-12-06 16:27:09 +0100642
643static int asus_led_init(struct asus_laptop *asus)
644{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100645 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100646
647 /*
Corentin Chary8d38e422011-10-14 11:13:39 +0200648 * The Pegatron Lucid has no physical leds, but all methods are
649 * available in the DSDT...
650 */
651 if (asus->is_pega_lucid)
652 return 0;
653
654 /*
Corentin Charybe4ee822009-12-06 16:27:09 +0100655 * Functions that actually update the LED's are called from a
656 * workqueue. By doing this as separate work rather than when the LED
657 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
658 * potentially bad time, such as a timer interrupt.
659 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100660 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
661 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100662 return -ENOMEM;
663
Corentin Charyaee0afb2010-01-26 21:01:34 +0100664 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
665 if (r)
666 goto error;
667 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
668 if (r)
669 goto error;
670 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
671 if (r)
672 goto error;
673 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
674 if (r)
675 goto error;
676 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
677 if (r)
678 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100679 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100680 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
681 struct asus_led *led = &asus->kled;
682 struct led_classdev *cdev = &led->led;
683
684 led->asus = asus;
685
686 INIT_WORK(&led->work, asus_kled_cdev_update);
687 cdev->name = "asus::kbd_backlight";
688 cdev->brightness_set = asus_kled_cdev_set;
689 cdev->brightness_get = asus_kled_cdev_get;
690 cdev->max_brightness = 3;
691 r = led_classdev_register(&asus->platform_device->dev, cdev);
692 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100693error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100694 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100695 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100696 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100697}
698
699/*
700 * Backlight device
701 */
Corentin Chary4d441512010-01-13 22:26:24 +0100702static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100703{
Corentin Charyd99b5772010-01-22 21:20:57 +0100704 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400705 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100706 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100707
Corentin Charyd99b5772010-01-22 21:20:57 +0100708 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
709 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100710 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700711 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100712
713 return value;
714}
715
Corentin Chary4d441512010-01-13 22:26:24 +0100716static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100717{
Corentin Charyd99b5772010-01-22 21:20:57 +0100718 struct asus_laptop *asus = bl_get_data(bd);
719
720 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700721 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100722 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100723 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100724 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100725}
726
727static int update_bl_status(struct backlight_device *bd)
728{
Richard Purdie599a52d2007-02-10 23:07:48 +0000729 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100730
Corentin Chary3b81cf92011-02-06 13:27:31 +0100731 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100732}
733
Lionel Debrouxacc24722010-11-16 14:14:02 +0100734static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100735 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100736 .update_status = update_bl_status,
737};
738
Corentin Charya539df52010-01-25 22:53:21 +0100739static int asus_backlight_notify(struct asus_laptop *asus)
740{
741 struct backlight_device *bd = asus->backlight_device;
742 int old = bd->props.brightness;
743
744 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
745
746 return old;
747}
748
Corentin Charybe4ee822009-12-06 16:27:09 +0100749static int asus_backlight_init(struct asus_laptop *asus)
750{
751 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500752 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100753
Corentin Chary71e687d2010-08-24 09:30:44 +0200754 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100755 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200756 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500757
Corentin Chary71e687d2010-08-24 09:30:44 +0200758 memset(&props, 0, sizeof(struct backlight_properties));
759 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700760 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100761
Corentin Chary71e687d2010-08-24 09:30:44 +0200762 bd = backlight_device_register(ASUS_LAPTOP_FILE,
763 &asus->platform_device->dev, asus,
764 &asusbl_ops, &props);
765 if (IS_ERR(bd)) {
766 pr_err("Could not register asus backlight device\n");
767 asus->backlight_device = NULL;
768 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100769 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200770
771 asus->backlight_device = bd;
772 bd->props.brightness = asus_read_brightness(bd);
773 bd->props.power = FB_BLANK_UNBLANK;
774 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100775 return 0;
776}
777
778static void asus_backlight_exit(struct asus_laptop *asus)
779{
780 if (asus->backlight_device)
781 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100782 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100783}
784
Corentin Chary85091b72007-01-26 14:04:30 +0100785/*
786 * Platform device handlers
787 */
788
789/*
790 * We write our info in page, we begin at offset off and cannot write more
791 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
792 * number of bytes written in page
793 */
794static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500795 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100796{
Corentin Chary9129d142009-12-01 22:39:41 +0100797 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100798 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400799 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200800 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100801 acpi_status rv = AE_OK;
802
Corentin Chary85091b72007-01-26 14:04:30 +0100803 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100804 * We use the easy way, we don't care of off and count,
805 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100806 */
807
Corentin Chary50a90c42009-11-30 21:55:12 +0100808 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
809 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100810 /*
811 * The SFUN method probably allows the original driver to get the list
812 * of features supported by a given model. For now, 0x0100 or 0x0800
813 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
814 * The significance of others is yet to be found.
815 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100816 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100817 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000818 len += sprintf(page + len, "SFUN value : %#x\n",
819 (uint) temp);
820 /*
821 * The HWRS method return informations about the hardware.
822 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
823 * The significance of others is yet to be found.
824 * If we don't find the method, we assume the device are present.
825 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100826 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000827 if (!ACPI_FAILURE(rv))
828 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100829 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100830 /*
831 * Another value for userspace: the ASYM method returns 0x02 for
832 * battery low and 0x04 for battery critical, its readings tend to be
833 * more accurate than those provided by _BST.
834 * Note: since not all the laptops provide this method, errors are
835 * silently ignored.
836 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100837 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100838 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000839 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100840 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100841 if (asus->dsdt_info) {
842 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100843 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100844 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100845 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100846 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100847 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100848 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100849 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100850 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100851 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100852 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100853 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100854 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100855 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100856 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100857 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
858 }
859
860 return len;
861}
862
863static int parse_arg(const char *buf, unsigned long count, int *val)
864{
865 if (!count)
866 return 0;
867 if (count > 31)
868 return -EINVAL;
869 if (sscanf(buf, "%i", val) != 1)
870 return -EINVAL;
871 return count;
872}
873
Corentin Chary17e78f62010-01-13 22:21:33 +0100874static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
875 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100876 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100877{
878 int rv, value;
879 int out = 0;
880
881 rv = parse_arg(buf, count, &value);
882 if (rv > 0)
883 out = value ? 1 : 0;
884
Corentin Charyd99b5772010-01-22 21:20:57 +0100885 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100886 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100887 return rv;
888}
889
890/*
Corentin Chary722ad972007-01-26 14:04:55 +0100891 * LEDD display
892 */
893static ssize_t show_ledd(struct device *dev,
894 struct device_attribute *attr, char *buf)
895{
Corentin Chary9129d142009-12-01 22:39:41 +0100896 struct asus_laptop *asus = dev_get_drvdata(dev);
897
Corentin Chary50a90c42009-11-30 21:55:12 +0100898 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100899}
900
901static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
902 const char *buf, size_t count)
903{
Corentin Chary9129d142009-12-01 22:39:41 +0100904 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100905 int rv, value;
906
907 rv = parse_arg(buf, count, &value);
908 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700909 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700910 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700911 return -ENODEV;
912 }
913 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100914 }
915 return rv;
916}
917
918/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100919 * Wireless
920 */
921static int asus_wireless_status(struct asus_laptop *asus, int mask)
922{
923 unsigned long long status;
924 acpi_status rv = AE_OK;
925
926 if (!asus->have_rsts)
927 return (asus->wireless_status & mask) ? 1 : 0;
928
Corentin Charyd99b5772010-01-22 21:20:57 +0100929 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
930 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100931 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700932 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100933 return -EINVAL;
934 }
935 return !!(status & mask);
936}
937
938/*
Corentin Chary4564de12007-01-26 14:04:40 +0100939 * WLAN
940 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100941static int asus_wlan_set(struct asus_laptop *asus, int status)
942{
943 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700944 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100945 return -EIO;
946 }
947 return 0;
948}
949
Corentin Chary4564de12007-01-26 14:04:40 +0100950static ssize_t show_wlan(struct device *dev,
951 struct device_attribute *attr, char *buf)
952{
Corentin Chary9129d142009-12-01 22:39:41 +0100953 struct asus_laptop *asus = dev_get_drvdata(dev);
954
Corentin Chary17e78f62010-01-13 22:21:33 +0100955 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100956}
957
958static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
959 const char *buf, size_t count)
960{
Corentin Chary9129d142009-12-01 22:39:41 +0100961 struct asus_laptop *asus = dev_get_drvdata(dev);
962
Corentin Charyd99b5772010-01-22 21:20:57 +0100963 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100964}
965
966/*
967 * Bluetooth
968 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100969static int asus_bluetooth_set(struct asus_laptop *asus, int status)
970{
971 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700972 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100973 return -EIO;
974 }
975 return 0;
976}
977
Corentin Chary4564de12007-01-26 14:04:40 +0100978static ssize_t show_bluetooth(struct device *dev,
979 struct device_attribute *attr, char *buf)
980{
Corentin Chary9129d142009-12-01 22:39:41 +0100981 struct asus_laptop *asus = dev_get_drvdata(dev);
982
Corentin Chary17e78f62010-01-13 22:21:33 +0100983 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100984}
985
Len Brown8def05f2007-01-30 01:46:43 -0500986static ssize_t store_bluetooth(struct device *dev,
987 struct device_attribute *attr, const char *buf,
988 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100989{
Corentin Chary9129d142009-12-01 22:39:41 +0100990 struct asus_laptop *asus = dev_get_drvdata(dev);
991
Corentin Charyd99b5772010-01-22 21:20:57 +0100992 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100993}
994
Corentin Chary78127b42007-01-26 14:04:49 +0100995/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100996 * Wimax
997 */
998static int asus_wimax_set(struct asus_laptop *asus, int status)
999{
1000 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001001 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001002 return -EIO;
1003 }
1004 return 0;
1005}
1006
1007static ssize_t show_wimax(struct device *dev,
1008 struct device_attribute *attr, char *buf)
1009{
1010 struct asus_laptop *asus = dev_get_drvdata(dev);
1011
1012 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
1013}
1014
1015static ssize_t store_wimax(struct device *dev,
1016 struct device_attribute *attr, const char *buf,
1017 size_t count)
1018{
1019 struct asus_laptop *asus = dev_get_drvdata(dev);
1020
1021 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
1022}
1023
1024/*
1025 * Wwan
1026 */
1027static int asus_wwan_set(struct asus_laptop *asus, int status)
1028{
1029 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001030 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001031 return -EIO;
1032 }
1033 return 0;
1034}
1035
1036static ssize_t show_wwan(struct device *dev,
1037 struct device_attribute *attr, char *buf)
1038{
1039 struct asus_laptop *asus = dev_get_drvdata(dev);
1040
1041 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
1042}
1043
1044static ssize_t store_wwan(struct device *dev,
1045 struct device_attribute *attr, const char *buf,
1046 size_t count)
1047{
1048 struct asus_laptop *asus = dev_get_drvdata(dev);
1049
1050 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
1051}
1052
1053/*
Corentin Chary78127b42007-01-26 14:04:49 +01001054 * Display
1055 */
Corentin Chary4d441512010-01-13 22:26:24 +01001056static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +01001057{
1058 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +01001059 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001060 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +01001061 return;
1062}
1063
Corentin Chary78127b42007-01-26 14:04:49 +01001064/*
1065 * Experimental support for display switching. As of now: 1 should activate
1066 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1067 * Any combination (bitwise) of these will suffice. I never actually tested 4
1068 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1069 * for more info.
1070 */
1071static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1072 const char *buf, size_t count)
1073{
Corentin Chary9129d142009-12-01 22:39:41 +01001074 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001075 int rv, value;
1076
1077 rv = parse_arg(buf, count, &value);
1078 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001079 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001080 return rv;
1081}
1082
Corentin Chary8b857352007-01-26 14:04:58 +01001083/*
1084 * Light Sens
1085 */
Corentin Chary4d441512010-01-13 22:26:24 +01001086static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001087{
Andy Ross33989ba2011-10-14 11:13:36 +02001088 int ret;
1089
1090 if (asus->is_pega_lucid) {
1091 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
1092 if (!ret)
1093 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
1094 } else {
1095 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
1096 }
1097 if (ret)
1098 pr_warning("Error setting light sensor switch\n");
1099
Corentin Chary50a90c42009-11-30 21:55:12 +01001100 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001101}
1102
1103static ssize_t show_lssw(struct device *dev,
1104 struct device_attribute *attr, char *buf)
1105{
Corentin Chary9129d142009-12-01 22:39:41 +01001106 struct asus_laptop *asus = dev_get_drvdata(dev);
1107
Corentin Chary50a90c42009-11-30 21:55:12 +01001108 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001109}
1110
1111static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1112 const char *buf, size_t count)
1113{
Corentin Chary9129d142009-12-01 22:39:41 +01001114 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001115 int rv, value;
1116
1117 rv = parse_arg(buf, count, &value);
1118 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001119 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001120
1121 return rv;
1122}
1123
Corentin Chary4d441512010-01-13 22:26:24 +01001124static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001125{
Corentin Charyd99b5772010-01-22 21:20:57 +01001126 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001127 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001128 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001129}
1130
1131static ssize_t show_lslvl(struct device *dev,
1132 struct device_attribute *attr, char *buf)
1133{
Corentin Chary9129d142009-12-01 22:39:41 +01001134 struct asus_laptop *asus = dev_get_drvdata(dev);
1135
Corentin Chary50a90c42009-11-30 21:55:12 +01001136 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001137}
1138
1139static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1140 const char *buf, size_t count)
1141{
Corentin Chary9129d142009-12-01 22:39:41 +01001142 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001143 int rv, value;
1144
1145 rv = parse_arg(buf, count, &value);
1146 if (rv > 0) {
1147 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1148 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001149 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001150 }
1151
1152 return rv;
1153}
1154
Andy Ross33989ba2011-10-14 11:13:36 +02001155static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1156{
1157 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1158 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1159 &buffer);
1160 if (!err) {
1161 union acpi_object *obj = buffer.pointer;
1162 if (obj && obj->type == ACPI_TYPE_INTEGER)
1163 *result = obj->integer.value;
1164 else
1165 err = -EIO;
1166 }
1167 return err;
1168}
1169
1170static ssize_t show_lsvalue(struct device *dev,
1171 struct device_attribute *attr, char *buf)
1172{
1173 struct asus_laptop *asus = dev_get_drvdata(dev);
1174 int err, hi, lo;
1175
1176 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1177 if (!err)
1178 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1179 if (!err)
1180 return sprintf(buf, "%d\n", 10 * hi + lo);
1181 return err;
1182}
1183
Corentin Charye539c2f2007-05-06 14:47:06 +02001184/*
1185 * GPS
1186 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001187static int asus_gps_status(struct asus_laptop *asus)
1188{
1189 unsigned long long status;
1190 acpi_status rv = AE_OK;
1191
Corentin Charyd99b5772010-01-22 21:20:57 +01001192 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1193 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001194 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001195 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001196 return -ENODEV;
1197 }
1198 return !!status;
1199}
1200
1201static int asus_gps_switch(struct asus_laptop *asus, int status)
1202{
Corentin Charyd99b5772010-01-22 21:20:57 +01001203 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001204
Corentin Charyd99b5772010-01-22 21:20:57 +01001205 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001206 return -ENODEV;
1207 return 0;
1208}
1209
Corentin Charye539c2f2007-05-06 14:47:06 +02001210static ssize_t show_gps(struct device *dev,
1211 struct device_attribute *attr, char *buf)
1212{
Corentin Chary9129d142009-12-01 22:39:41 +01001213 struct asus_laptop *asus = dev_get_drvdata(dev);
1214
Corentin Chary6358bf22010-01-13 21:55:44 +01001215 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001216}
1217
1218static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1219 const char *buf, size_t count)
1220{
Corentin Chary060cbce2010-01-28 10:52:40 +01001221 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001222 int rv, value;
1223 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001224
Corentin Chary6358bf22010-01-13 21:55:44 +01001225 rv = parse_arg(buf, count, &value);
1226 if (rv <= 0)
1227 return -EINVAL;
1228 ret = asus_gps_switch(asus, !!value);
1229 if (ret)
1230 return ret;
Corentin Chary18e13112010-01-25 23:29:24 +01001231 rfkill_set_sw_state(asus->gps_rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001232 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001233}
1234
Corentin Chary034ce902009-01-20 16:17:43 +01001235/*
Corentin Chary18e13112010-01-25 23:29:24 +01001236 * rfkill
1237 */
1238static int asus_gps_rfkill_set(void *data, bool blocked)
1239{
Corentin Chary23f45c32010-08-24 09:30:46 +02001240 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001241
Corentin Chary23f45c32010-08-24 09:30:46 +02001242 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001243}
1244
1245static const struct rfkill_ops asus_gps_rfkill_ops = {
1246 .set_block = asus_gps_rfkill_set,
1247};
1248
1249static void asus_rfkill_exit(struct asus_laptop *asus)
1250{
1251 if (asus->gps_rfkill) {
1252 rfkill_unregister(asus->gps_rfkill);
1253 rfkill_destroy(asus->gps_rfkill);
1254 asus->gps_rfkill = NULL;
1255 }
1256}
1257
1258static int asus_rfkill_init(struct asus_laptop *asus)
1259{
1260 int result;
1261
1262 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1263 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1264 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1265 return 0;
1266
1267 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1268 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001269 &asus_gps_rfkill_ops, asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001270 if (!asus->gps_rfkill)
1271 return -EINVAL;
1272
1273 result = rfkill_register(asus->gps_rfkill);
1274 if (result) {
1275 rfkill_destroy(asus->gps_rfkill);
1276 asus->gps_rfkill = NULL;
1277 }
1278
1279 return result;
1280}
1281
Anisse Astier14908392011-10-14 11:13:42 +02001282static int pega_rfkill_set(void *data, bool blocked)
1283{
1284 struct asus_pega_rfkill *pega_rfk = data;
1285
1286 int ret = asus_pega_lucid_set(pega_rfk->asus, pega_rfk->control_id, !blocked);
1287 pr_warn("Setting rfkill %d, to %d; returned %d\n", pega_rfk->control_id, !blocked, ret);
1288
1289 return ret;
1290}
1291
1292static const struct rfkill_ops pega_rfkill_ops = {
1293 .set_block = pega_rfkill_set,
1294};
1295
1296static void pega_rfkill_terminate(struct asus_pega_rfkill *pega_rfk)
1297{
1298 pr_warn("Terminating %d\n", pega_rfk->control_id);
1299 if (pega_rfk->rfkill) {
1300 rfkill_unregister(pega_rfk->rfkill);
1301 rfkill_destroy(pega_rfk->rfkill);
1302 pega_rfk->rfkill = NULL;
1303 }
1304}
1305
1306static void pega_rfkill_exit(struct asus_laptop *asus)
1307{
1308 pega_rfkill_terminate(&asus->wwanrfk);
1309 pega_rfkill_terminate(&asus->btrfk);
1310 pega_rfkill_terminate(&asus->wlanrfk);
1311}
1312
1313static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_pega_rfkill *pega_rfk,
1314 const char *name, int controlid, int rfkill_type)
1315{
1316 int result;
1317
1318 pr_warn("Setting up rfk %s, control %d, type %d\n", name, controlid, rfkill_type);
1319 pega_rfk->control_id = controlid;
1320 pega_rfk->asus = asus;
1321 pega_rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
1322 rfkill_type, &pega_rfkill_ops, pega_rfk);
1323 if (!pega_rfk->rfkill)
1324 return -EINVAL;
1325
1326 result = rfkill_register(pega_rfk->rfkill);
1327 if (result) {
1328 rfkill_destroy(pega_rfk->rfkill);
1329 pega_rfk->rfkill = NULL;
1330 }
1331
1332 return result;
1333}
1334
1335static int pega_rfkill_init(struct asus_laptop *asus)
1336{
1337 int ret = 0;
1338
1339 if(!asus->is_pega_lucid)
1340 return -ENODEV;
1341
1342 ret = pega_rfkill_setup(asus, &asus->wlanrfk, "pega-wlan", PEGA_WLAN, RFKILL_TYPE_WLAN);
1343 if(ret)
1344 return ret;
1345 ret = pega_rfkill_setup(asus, &asus->btrfk, "pega-bt", PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
1346 if(ret)
1347 goto err_btrfk;
1348 ret = pega_rfkill_setup(asus, &asus->wwanrfk, "pega-wwan", PEGA_WWAN, RFKILL_TYPE_WWAN);
1349 if(ret)
1350 goto err_wwanrfk;
1351
1352 pr_warn("Pega rfkill init succeeded\n");
1353 return 0;
1354err_wwanrfk:
1355 pega_rfkill_terminate(&asus->btrfk);
1356err_btrfk:
1357 pega_rfkill_terminate(&asus->wlanrfk);
1358
1359 return ret;
1360}
1361
Corentin Chary18e13112010-01-25 23:29:24 +01001362/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001363 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001364 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001365static void asus_input_notify(struct asus_laptop *asus, int event)
1366{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001367 if (asus->inputdev)
1368 sparse_keymap_report_event(asus->inputdev, event, 1, true);
Corentin Charybe4ee822009-12-06 16:27:09 +01001369}
1370
1371static int asus_input_init(struct asus_laptop *asus)
1372{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001373 struct input_dev *input;
1374 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001375
Corentin Chary66a71dd2010-01-25 22:50:11 +01001376 input = input_allocate_device();
1377 if (!input) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001378 pr_info("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001379 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001380 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001381 input->name = "Asus Laptop extra buttons";
1382 input->phys = ASUS_LAPTOP_FILE "/input0";
1383 input->id.bustype = BUS_HOST;
1384 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001385
Corentin Chary66a71dd2010-01-25 22:50:11 +01001386 error = sparse_keymap_setup(input, asus_keymap, NULL);
1387 if (error) {
1388 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001389 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001390 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001391 error = input_register_device(input);
1392 if (error) {
Corentin Charybe4ee822009-12-06 16:27:09 +01001393 pr_info("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001394 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001395 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001396
1397 asus->inputdev = input;
1398 return 0;
1399
Axel Lin45036ae2010-07-05 15:29:00 +08001400err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001401 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001402err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001403 input_free_device(input);
1404 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001405}
1406
1407static void asus_input_exit(struct asus_laptop *asus)
1408{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001409 if (asus->inputdev) {
1410 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001411 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001412 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001413 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001414}
1415
1416/*
1417 * ACPI driver
1418 */
Corentin Chary600ad522009-11-30 21:42:42 +01001419static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001420{
Corentin Chary9129d142009-12-01 22:39:41 +01001421 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001422 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001423
Corentin Chary619d8b12009-11-28 10:35:37 +01001424 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001425 count = asus->event_count[event % 128]++;
1426 acpi_bus_generate_proc_event(asus->device, event, count);
1427 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1428 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001429 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001430
Corentin Charya539df52010-01-25 22:53:21 +01001431 /* Brightness events are special */
1432 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1433
1434 /* Ignore them completely if the acpi video driver is used */
1435 if (asus->backlight_device != NULL) {
1436 /* Update the backlight device. */
1437 asus_backlight_notify(asus);
1438 }
1439 return ;
1440 }
Anisse Astierb93f8282011-10-14 11:13:41 +02001441
1442 /* Accelerometer "coarse orientation change" event */
1443 if (asus->pega_accel_poll && event == 0xEA) {
1444 kobject_uevent(&asus->pega_accel_poll->input->dev.kobj,
1445 KOBJ_CHANGE);
1446 return ;
1447 }
1448
Corentin Charybe4ee822009-12-06 16:27:09 +01001449 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001450}
1451
Corentin Chary2a1fd642010-01-26 21:02:23 +01001452static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1453static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001454static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1455 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001456static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1457static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001458static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001459static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001460static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001461static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1462static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1463static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1464
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001465static struct attribute *asus_attributes[] = {
1466 &dev_attr_infos.attr,
1467 &dev_attr_wlan.attr,
1468 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001469 &dev_attr_wimax.attr,
1470 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001471 &dev_attr_display.attr,
1472 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001473 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001474 &dev_attr_ls_level.attr,
1475 &dev_attr_ls_switch.attr,
1476 &dev_attr_gps.attr,
1477 NULL
1478};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001479
Al Viro587a1f12011-07-23 23:11:19 -04001480static umode_t asus_sysfs_is_visible(struct kobject *kobj,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001481 struct attribute *attr,
1482 int idx)
1483{
1484 struct device *dev = container_of(kobj, struct device, kobj);
1485 struct platform_device *pdev = to_platform_device(dev);
1486 struct asus_laptop *asus = platform_get_drvdata(pdev);
1487 acpi_handle handle = asus->handle;
1488 bool supported;
1489
Andy Ross33989ba2011-10-14 11:13:36 +02001490 if (asus->is_pega_lucid) {
1491 /* no ls_level interface on the Lucid */
1492 if (attr == &dev_attr_ls_switch.attr)
1493 supported = true;
1494 else if (attr == &dev_attr_ls_level.attr)
1495 supported = false;
1496 else
1497 goto normal;
1498
1499 return supported;
1500 }
1501
1502normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001503 if (attr == &dev_attr_wlan.attr) {
1504 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1505
1506 } else if (attr == &dev_attr_bluetooth.attr) {
1507 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1508
1509 } else if (attr == &dev_attr_display.attr) {
1510 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1511
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001512 } else if (attr == &dev_attr_wimax.attr) {
1513 supported =
1514 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1515
1516 } else if (attr == &dev_attr_wwan.attr) {
1517 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1518
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001519 } else if (attr == &dev_attr_ledd.attr) {
1520 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1521
1522 } else if (attr == &dev_attr_ls_switch.attr ||
1523 attr == &dev_attr_ls_level.attr) {
1524 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001525 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1526 } else if (attr == &dev_attr_ls_value.attr) {
1527 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001528 } else if (attr == &dev_attr_gps.attr) {
1529 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1530 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1531 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1532 } else {
1533 supported = true;
1534 }
1535
1536 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001537}
1538
Corentin Chary2a1fd642010-01-26 21:02:23 +01001539
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001540static const struct attribute_group asus_attr_group = {
1541 .is_visible = asus_sysfs_is_visible,
1542 .attrs = asus_attributes,
1543};
Corentin Chary85091b72007-01-26 14:04:30 +01001544
Corentin Chary9129d142009-12-01 22:39:41 +01001545static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001546{
Corentin Chary71e687d2010-08-24 09:30:44 +02001547 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001548
Corentin Chary50a90c42009-11-30 21:55:12 +01001549 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1550 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001551 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001552 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001553
Corentin Chary71e687d2010-08-24 09:30:44 +02001554 result = platform_device_add(asus->platform_device);
1555 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001556 goto fail_platform_device;
1557
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001558 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1559 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001560 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001561 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001562
Corentin Chary600ad522009-11-30 21:42:42 +01001563 return 0;
1564
1565fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001566 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001567fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001568 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001569 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001570}
1571
Corentin Chary9129d142009-12-01 22:39:41 +01001572static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001573{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001574 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001575 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001576}
1577
1578static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001579 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001580 .name = ASUS_LAPTOP_FILE,
1581 .owner = THIS_MODULE,
Andy Rossb23910c2011-10-14 11:13:38 +02001582 },
Corentin Chary85091b72007-01-26 14:04:30 +01001583};
1584
Corentin Chary85091b72007-01-26 14:04:30 +01001585/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001586 * This function is used to initialize the context with right values. In this
1587 * method, we can make all the detection we want, and modify the asus_laptop
1588 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001589 */
Corentin Chary7c247642009-11-30 22:13:54 +01001590static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001591{
1592 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001593 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001594 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001595 char *string = NULL;
1596 acpi_status status;
1597
1598 /*
1599 * Get DSDT headers early enough to allow for differentiating between
1600 * models, but late enough to allow acpi_bus_register_driver() to fail
1601 * before doing anything ACPI-specific. Should we encounter a machine,
1602 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001603 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001604 */
Corentin Chary7c247642009-11-30 22:13:54 +01001605 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001606 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001607 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001608
1609 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001610 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001611 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001612 return -ENODEV;
1613 }
1614
1615 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001616 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001617 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001618 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001619 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001620 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001621 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001622 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001623
Corentin Chary185e5af2007-03-11 10:27:33 +01001624 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001625 if (write_acpi_int(asus->handle, "CWAP", wapf))
1626 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001627 /*
1628 * Try to match the object returned by INIT to the specific model.
1629 * Handle every possible object (or the lack of thereof) the DSDT
1630 * writers might throw at us. When in trouble, we pass NULL to
1631 * asus_model_match() and try something completely different.
1632 */
1633 if (buffer.pointer) {
1634 model = buffer.pointer;
1635 switch (model->type) {
1636 case ACPI_TYPE_STRING:
1637 string = model->string.pointer;
1638 break;
1639 case ACPI_TYPE_BUFFER:
1640 string = model->buffer.pointer;
1641 break;
1642 default:
1643 string = "";
1644 break;
1645 }
1646 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001647 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001648 if (!asus->name) {
1649 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001650 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001651 }
Corentin Chary85091b72007-01-26 14:04:30 +01001652
Len Brown8def05f2007-01-30 01:46:43 -05001653 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001654 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001655
Corentin Chary4564de12007-01-26 14:04:40 +01001656 /*
1657 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001658 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1659 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001660 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001661 */
Corentin Chary9a816852007-03-11 10:25:38 +01001662 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001663 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001664 if (!ACPI_FAILURE(status))
1665 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001666
Corentin Charyd99b5772010-01-22 21:20:57 +01001667 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001668 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001669
Corentin Chary85091b72007-01-26 14:04:30 +01001670 kfree(model);
1671
1672 return AE_OK;
1673}
1674
Corentin Chary9129d142009-12-01 22:39:41 +01001675static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001676{
1677 int result = 0;
1678
Corentin Chary50a90c42009-11-30 21:55:12 +01001679 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001680 if (result)
1681 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001682 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001683 pr_err("Hotkey device not present, aborting\n");
1684 return -ENODEV;
1685 }
1686
Corentin Chary7c247642009-11-30 22:13:54 +01001687 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001688 if (result)
1689 return result;
1690
Corentin Chary600ad522009-11-30 21:42:42 +01001691 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001692 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001693 asus_bluetooth_set(asus, !!bluetooth_status);
1694
Corentin Charyd0930a22010-01-17 17:21:13 +01001695 if (wlan_status >= 0)
1696 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001697
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001698 if (wimax_status >= 0)
1699 asus_wimax_set(asus, !!wimax_status);
1700
1701 if (wwan_status >= 0)
1702 asus_wwan_set(asus, !!wwan_status);
1703
Corentin Chary600ad522009-11-30 21:42:42 +01001704 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001705 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001706 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001707
1708 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001709 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001710
1711 /* Set initial values of light sensor and level */
Andy Rossabec04d2011-10-14 11:13:37 +02001712 asus->light_switch = !!als_status;
Corentin Charybe4ee822009-12-06 16:27:09 +01001713 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001714
Andy Ross33989ba2011-10-14 11:13:36 +02001715 if (asus->is_pega_lucid) {
1716 asus_als_switch(asus, asus->light_switch);
1717 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1718 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001719 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001720 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001721 }
Corentin Chary600ad522009-11-30 21:42:42 +01001722
Corentin Chary600ad522009-11-30 21:42:42 +01001723 return result;
1724}
1725
Corentin Charyaf96f872011-02-06 13:27:30 +01001726static void __devinit asus_dmi_check(void)
1727{
1728 const char *model;
1729
1730 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1731 if (!model)
1732 return;
1733
1734 /* On L1400B WLED control the sound card, don't mess with it ... */
1735 if (strncmp(model, "L1400B", 6) == 0) {
1736 wlan_status = -1;
1737 }
1738}
1739
Corentin Chary71e687d2010-08-24 09:30:44 +02001740static bool asus_device_present;
1741
Corentin Chary600ad522009-11-30 21:42:42 +01001742static int __devinit asus_acpi_add(struct acpi_device *device)
1743{
Corentin Chary9129d142009-12-01 22:39:41 +01001744 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001745 int result;
1746
1747 pr_notice("Asus Laptop Support version %s\n",
1748 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001749 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1750 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001751 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001752 asus->handle = device->handle;
1753 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1754 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1755 device->driver_data = asus;
1756 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001757
Corentin Charyaf96f872011-02-06 13:27:30 +01001758 asus_dmi_check();
1759
Corentin Chary9129d142009-12-01 22:39:41 +01001760 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001761 if (result)
1762 goto fail_platform;
1763
1764 /*
Andy Ross8819de72011-10-14 11:13:35 +02001765 * Need platform type detection first, then the platform
1766 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001767 */
Andy Ross8819de72011-10-14 11:13:35 +02001768 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001769 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001770 if (result)
1771 goto fail_platform;
1772
1773 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001774 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001775 if (result)
1776 goto fail_backlight;
1777 } else
1778 pr_info("Backlight controlled by ACPI video driver\n");
1779
Corentin Chary9129d142009-12-01 22:39:41 +01001780 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001781 if (result)
1782 goto fail_input;
1783
Corentin Chary9129d142009-12-01 22:39:41 +01001784 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001785 if (result)
1786 goto fail_led;
1787
Corentin Chary18e13112010-01-25 23:29:24 +01001788 result = asus_rfkill_init(asus);
1789 if (result)
1790 goto fail_rfkill;
1791
Andy Rossb23910c2011-10-14 11:13:38 +02001792 result = pega_accel_init(asus);
1793 if (result && result != -ENODEV)
1794 goto fail_pega_accel;
1795
Anisse Astier14908392011-10-14 11:13:42 +02001796 result = pega_rfkill_init(asus);
1797 if (result && result != -ENODEV)
1798 goto fail_pega_rfkill;
1799
Corentin Chary600ad522009-11-30 21:42:42 +01001800 asus_device_present = true;
1801 return 0;
1802
Anisse Astier14908392011-10-14 11:13:42 +02001803fail_pega_rfkill:
1804 pega_accel_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001805fail_pega_accel:
1806 asus_rfkill_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001807fail_rfkill:
1808 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001809fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001810 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001811fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001812 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001813fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001814 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001815fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001816 kfree(asus->name);
1817 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001818
1819 return result;
1820}
1821
1822static int asus_acpi_remove(struct acpi_device *device, int type)
1823{
Corentin Chary9129d142009-12-01 22:39:41 +01001824 struct asus_laptop *asus = acpi_driver_data(device);
1825
1826 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001827 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001828 asus_led_exit(asus);
1829 asus_input_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001830 pega_accel_exit(asus);
Anisse Astier14908392011-10-14 11:13:42 +02001831 pega_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001832 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001833
Corentin Chary50a90c42009-11-30 21:55:12 +01001834 kfree(asus->name);
1835 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001836 return 0;
1837}
1838
1839static const struct acpi_device_id asus_device_ids[] = {
1840 {"ATK0100", 0},
1841 {"ATK0101", 0},
1842 {"", 0},
1843};
1844MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1845
1846static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001847 .name = ASUS_LAPTOP_NAME,
1848 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001849 .owner = THIS_MODULE,
1850 .ids = asus_device_ids,
1851 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1852 .ops = {
1853 .add = asus_acpi_add,
1854 .remove = asus_acpi_remove,
1855 .notify = asus_acpi_notify,
1856 },
1857};
1858
Corentin Chary85091b72007-01-26 14:04:30 +01001859static int __init asus_laptop_init(void)
1860{
1861 int result;
1862
Corentin Chary600ad522009-11-30 21:42:42 +01001863 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001864 if (result < 0)
1865 return result;
1866
Corentin Chary600ad522009-11-30 21:42:42 +01001867 result = acpi_bus_register_driver(&asus_acpi_driver);
1868 if (result < 0)
1869 goto fail_acpi_driver;
1870 if (!asus_device_present) {
1871 result = -ENODEV;
1872 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001873 }
Len Brown8def05f2007-01-30 01:46:43 -05001874 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001875
Corentin Chary600ad522009-11-30 21:42:42 +01001876fail_no_device:
1877 acpi_bus_unregister_driver(&asus_acpi_driver);
1878fail_acpi_driver:
1879 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001880 return result;
1881}
1882
Corentin Chary600ad522009-11-30 21:42:42 +01001883static void __exit asus_laptop_exit(void)
1884{
1885 acpi_bus_unregister_driver(&asus_acpi_driver);
1886 platform_driver_unregister(&platform_driver);
1887}
1888
Corentin Chary85091b72007-01-26 14:04:30 +01001889module_init(asus_laptop_init);
1890module_exit(asus_laptop_exit);