blob: db32d0337a7ce509d3ad88301779390b96056da2 [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 */
Corentin Chary40969c72011-12-15 08:27:33 +0100221struct asus_rfkill {
Anisse Astier14908392011-10-14 11:13:42 +0200222 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 Chary40969c72011-12-15 08:27:33 +0100259 struct asus_rfkill wlan;
260 struct asus_rfkill bluetooth;
261 struct asus_rfkill wwan;
262 struct asus_rfkill gps;
Anisse Astier14908392011-10-14 11:13:42 +0200263
Corentin Charybe966662009-08-29 10:28:29 +0200264 acpi_handle handle; /* the handle of the hotk device */
Corentin Charybe966662009-08-29 10:28:29 +0200265 u32 ledd_status; /* status of the LED display */
266 u8 light_level; /* light sensor level */
267 u8 light_switch; /* light sensor switch value */
268 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary85091b72007-01-26 14:04:30 +0100269};
270
Corentin Chary9129d142009-12-01 22:39:41 +0100271static const struct key_entry asus_keymap[] = {
Corentin Charya539df52010-01-25 22:53:21 +0100272 /* Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100273 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
274 {KE_KEY, 0x05, { KEY_WLAN } },
275 {KE_KEY, 0x08, { KEY_F13 } },
276 {KE_KEY, 0x17, { KEY_ZOOM } },
277 {KE_KEY, 0x1f, { KEY_BATTERY } },
Corentin Charya539df52010-01-25 22:53:21 +0100278 /* End of Lenovo SL Specific keycodes */
Corentin Chary66a71dd2010-01-25 22:50:11 +0100279 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
280 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
281 {KE_KEY, 0x32, { KEY_MUTE } },
282 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
283 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
284 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
285 {KE_KEY, 0x41, { KEY_NEXTSONG } },
286 {KE_KEY, 0x43, { KEY_STOPCD } },
287 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
288 {KE_KEY, 0x4c, { KEY_MEDIA } },
289 {KE_KEY, 0x50, { KEY_EMAIL } },
290 {KE_KEY, 0x51, { KEY_WWW } },
291 {KE_KEY, 0x55, { KEY_CALC } },
292 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
293 {KE_KEY, 0x5D, { KEY_WLAN } },
294 {KE_KEY, 0x5E, { KEY_WLAN } },
295 {KE_KEY, 0x5F, { KEY_WLAN } },
296 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
297 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
298 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
299 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
300 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
Corentin Chary7f607d712010-01-17 17:37:19 +0100301 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
302 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
Corentin Chary66a71dd2010-01-25 22:50:11 +0100303 {KE_KEY, 0x82, { KEY_CAMERA } },
304 {KE_KEY, 0x88, { KEY_WLAN } },
305 {KE_KEY, 0x8A, { KEY_PROG1 } },
306 {KE_KEY, 0x95, { KEY_MEDIA } },
307 {KE_KEY, 0x99, { KEY_PHONE } },
308 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
309 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
Corentin Charyb58baecd2010-08-24 09:30:45 +0200310 {KE_KEY, 0xb5, { KEY_CALC } },
Corentin Chary034ce902009-01-20 16:17:43 +0100311 {KE_END, 0},
312};
313
Corentin Chary66a71dd2010-01-25 22:50:11 +0100314
Corentin Chary85091b72007-01-26 14:04:30 +0100315/*
316 * This function evaluates an ACPI method, given an int as parameter, the
317 * method is searched within the scope of the handle, can be NULL. The output
318 * of the method is written is output, which can also be NULL
319 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100320 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100321 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100322static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
323 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100324{
Corentin Charybe966662009-08-29 10:28:29 +0200325 struct acpi_object_list params; /* list of input parameters (an int) */
326 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100327 acpi_status status;
328
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100329 if (!handle)
Axel Lin9fb866f2010-07-20 15:19:47 -0700330 return -1;
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100331
Corentin Chary85091b72007-01-26 14:04:30 +0100332 params.count = 1;
333 params.pointer = &in_obj;
334 in_obj.type = ACPI_TYPE_INTEGER;
335 in_obj.integer.value = val;
336
337 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100338 if (status == AE_OK)
339 return 0;
340 else
341 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100342}
343
Corentin Charyd8c67322009-11-28 10:27:51 +0100344static int write_acpi_int(acpi_handle handle, const char *method, int val)
345{
346 return write_acpi_int_ret(handle, method, val, NULL);
347}
348
Corentin Charyd99b5772010-01-22 21:20:57 +0100349static int acpi_check_handle(acpi_handle handle, const char *method,
350 acpi_handle *ret)
351{
352 acpi_status status;
353
354 if (method == NULL)
355 return -ENODEV;
356
357 if (ret)
358 status = acpi_get_handle(handle, (char *)method,
359 ret);
360 else {
361 acpi_handle dummy;
362
363 status = acpi_get_handle(handle, (char *)method,
364 &dummy);
365 }
366
367 if (status != AE_OK) {
368 if (ret)
Joe Perches5ad77dc2011-03-29 15:21:35 -0700369 pr_warn("Error finding %s\n", method);
Corentin Charyd99b5772010-01-22 21:20:57 +0100370 return -ENODEV;
371 }
372 return 0;
373}
374
Andy Ross8819de72011-10-14 11:13:35 +0200375static bool asus_check_pega_lucid(struct asus_laptop *asus)
376{
377 return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
378 !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
379 !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
380 !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
381}
382
Andy Ross33989ba2011-10-14 11:13:36 +0200383static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
384{
385 char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
386 return write_acpi_int(asus->handle, method, unit);
387}
388
Andy Rossb23910c2011-10-14 11:13:38 +0200389static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
390{
391 int i, delta;
392 unsigned long long val;
393 for (i = 0; i < PEGA_ACC_RETRIES; i++) {
394 acpi_evaluate_integer(asus->handle, method, NULL, &val);
395
396 /* The output is noisy. From reading the ASL
397 * dissassembly, timeout errors are returned with 1's
398 * in the high word, and the lack of locking around
399 * thei hi/lo byte reads means that a transition
400 * between (for example) -1 and 0 could be read as
401 * 0xff00 or 0x00ff. */
402 delta = abs(curr - (short)val);
403 if (delta < 128 && !(val & ~0xffff))
404 break;
405 }
406 return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP);
407}
408
409static void pega_accel_poll(struct input_polled_dev *ipd)
410{
411 struct device *parent = ipd->input->dev.parent;
412 struct asus_laptop *asus = dev_get_drvdata(parent);
413
414 /* In some cases, the very first call to poll causes a
415 * recursive fault under the polldev worker. This is
416 * apparently related to very early userspace access to the
417 * device, and perhaps a firmware bug. Fake the first report. */
418 if (!asus->pega_acc_live) {
419 asus->pega_acc_live = true;
420 input_report_abs(ipd->input, ABS_X, 0);
421 input_report_abs(ipd->input, ABS_Y, 0);
422 input_report_abs(ipd->input, ABS_Z, 0);
423 input_sync(ipd->input);
424 return;
425 }
426
427 asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX);
428 asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY);
429 asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ);
430
431 /* Note transform, convert to "right/up/out" in the native
432 * landscape orientation (i.e. the vector is the direction of
433 * "real up" in the device's cartiesian coordinates). */
434 input_report_abs(ipd->input, ABS_X, -asus->pega_acc_x);
435 input_report_abs(ipd->input, ABS_Y, -asus->pega_acc_y);
436 input_report_abs(ipd->input, ABS_Z, asus->pega_acc_z);
437 input_sync(ipd->input);
438}
439
440static void pega_accel_exit(struct asus_laptop *asus)
441{
442 if (asus->pega_accel_poll) {
443 input_unregister_polled_device(asus->pega_accel_poll);
444 input_free_polled_device(asus->pega_accel_poll);
445 }
446 asus->pega_accel_poll = NULL;
447}
448
449static int pega_accel_init(struct asus_laptop *asus)
450{
451 int err;
452 struct input_polled_dev *ipd;
453
454 if (!asus->is_pega_lucid)
455 return -ENODEV;
456
457 if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) ||
458 acpi_check_handle(asus->handle, METHOD_XLRY, NULL) ||
459 acpi_check_handle(asus->handle, METHOD_XLRZ, NULL))
460 return -ENODEV;
461
462 ipd = input_allocate_polled_device();
463 if (!ipd)
464 return -ENOMEM;
465
466 ipd->poll = pega_accel_poll;
467 ipd->poll_interval = 125;
468 ipd->poll_interval_min = 50;
469 ipd->poll_interval_max = 2000;
470
471 ipd->input->name = PEGA_ACCEL_DESC;
472 ipd->input->phys = PEGA_ACCEL_NAME "/input0";
473 ipd->input->dev.parent = &asus->platform_device->dev;
474 ipd->input->id.bustype = BUS_HOST;
475
476 set_bit(EV_ABS, ipd->input->evbit);
477 input_set_abs_params(ipd->input, ABS_X,
478 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
479 input_set_abs_params(ipd->input, ABS_Y,
480 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
481 input_set_abs_params(ipd->input, ABS_Z,
482 -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
483
484 err = input_register_polled_device(ipd);
485 if (err)
486 goto exit;
487
488 asus->pega_accel_poll = ipd;
489 return 0;
490
491exit:
492 input_free_polled_device(ipd);
493 return err;
494}
495
Corentin Chary17e78f62010-01-13 22:21:33 +0100496/* Generic LED function */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100497static int asus_led_set(struct asus_laptop *asus, const char *method,
Corentin Chary17e78f62010-01-13 22:21:33 +0100498 int value)
Corentin Charybe18cda2007-01-26 14:04:35 +0100499{
Corentin Charyd99b5772010-01-22 21:20:57 +0100500 if (!strcmp(method, METHOD_MLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100501 value = !value;
Corentin Charyd99b5772010-01-22 21:20:57 +0100502 else if (!strcmp(method, METHOD_GLED))
Corentin Chary17e78f62010-01-13 22:21:33 +0100503 value = !value + 1;
504 else
505 value = !!value;
Corentin Charybe18cda2007-01-26 14:04:35 +0100506
Corentin Charye5593bf2010-01-17 17:20:11 +0100507 return write_acpi_int(asus->handle, method, value);
Corentin Charybe18cda2007-01-26 14:04:35 +0100508}
509
Corentin Charybe4ee822009-12-06 16:27:09 +0100510/*
511 * LEDs
512 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100513/* /sys/class/led handlers */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100514static void asus_led_cdev_set(struct led_classdev *led_cdev,
515 enum led_brightness value)
516{
517 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
518 struct asus_laptop *asus = led->asus;
Corentin Charybe18cda2007-01-26 14:04:35 +0100519
Corentin Charyaee0afb2010-01-26 21:01:34 +0100520 led->wk = !!value;
521 queue_work(asus->led_workqueue, &led->work);
522}
523
524static void asus_led_cdev_update(struct work_struct *work)
525{
526 struct asus_led *led = container_of(work, struct asus_led, work);
527 struct asus_laptop *asus = led->asus;
528
529 asus_led_set(asus, led->method, led->wk);
530}
531
532static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
533{
534 return led_cdev->brightness;
535}
Corentin Charybe18cda2007-01-26 14:04:35 +0100536
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000537/*
Corentin Charybe4ee822009-12-06 16:27:09 +0100538 * Keyboard backlight (also a LED)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000539 */
Corentin Charyd99b5772010-01-22 21:20:57 +0100540static int asus_kled_lvl(struct asus_laptop *asus)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000541{
542 unsigned long long kblv;
543 struct acpi_object_list params;
544 union acpi_object in_obj;
545 acpi_status rv;
546
547 params.count = 1;
548 params.pointer = &in_obj;
549 in_obj.type = ACPI_TYPE_INTEGER;
550 in_obj.integer.value = 2;
551
Corentin Charyd99b5772010-01-22 21:20:57 +0100552 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
553 &params, &kblv);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000554 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700555 pr_warn("Error reading kled level\n");
Corentin Chary4d441512010-01-13 22:26:24 +0100556 return -ENODEV;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000557 }
558 return kblv;
559}
560
Corentin Chary4d441512010-01-13 22:26:24 +0100561static int asus_kled_set(struct asus_laptop *asus, int kblv)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000562{
563 if (kblv > 0)
564 kblv = (1 << 7) | (kblv & 0x7F);
565 else
566 kblv = 0;
567
Corentin Charyd99b5772010-01-22 21:20:57 +0100568 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700569 pr_warn("Keyboard LED display write failed\n");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000570 return -EINVAL;
571 }
572 return 0;
573}
574
Corentin Charyaee0afb2010-01-26 21:01:34 +0100575static void asus_kled_cdev_set(struct led_classdev *led_cdev,
576 enum led_brightness value)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000577{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100578 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
579 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100580
Corentin Chary060cbce2010-01-28 10:52:40 +0100581 led->wk = value;
Corentin Charyaee0afb2010-01-26 21:01:34 +0100582 queue_work(asus->led_workqueue, &led->work);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000583}
584
Corentin Charyaee0afb2010-01-26 21:01:34 +0100585static void asus_kled_cdev_update(struct work_struct *work)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000586{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100587 struct asus_led *led = container_of(work, struct asus_led, work);
588 struct asus_laptop *asus = led->asus;
Corentin Chary9129d142009-12-01 22:39:41 +0100589
Corentin Charyaee0afb2010-01-26 21:01:34 +0100590 asus_kled_set(asus, led->wk);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000591}
592
Corentin Charyaee0afb2010-01-26 21:01:34 +0100593static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000594{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100595 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
596 struct asus_laptop *asus = led->asus;
Corentin Charyd99b5772010-01-22 21:20:57 +0100597
598 return asus_kled_lvl(asus);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000599}
600
Corentin Charybe4ee822009-12-06 16:27:09 +0100601static void asus_led_exit(struct asus_laptop *asus)
602{
Axel Lin8fcf71a2011-08-08 17:17:18 +0800603 if (!IS_ERR_OR_NULL(asus->mled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100604 led_classdev_unregister(&asus->mled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800605 if (!IS_ERR_OR_NULL(asus->tled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100606 led_classdev_unregister(&asus->tled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800607 if (!IS_ERR_OR_NULL(asus->pled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100608 led_classdev_unregister(&asus->pled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800609 if (!IS_ERR_OR_NULL(asus->rled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100610 led_classdev_unregister(&asus->rled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800611 if (!IS_ERR_OR_NULL(asus->gled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100612 led_classdev_unregister(&asus->gled.led);
Axel Lin8fcf71a2011-08-08 17:17:18 +0800613 if (!IS_ERR_OR_NULL(asus->kled.led.dev))
Corentin Charyaee0afb2010-01-26 21:01:34 +0100614 led_classdev_unregister(&asus->kled.led);
615 if (asus->led_workqueue) {
616 destroy_workqueue(asus->led_workqueue);
617 asus->led_workqueue = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100618 }
619}
620
621/* Ugly macro, need to fix that later */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100622static int asus_led_register(struct asus_laptop *asus,
623 struct asus_led *led,
624 const char *name, const char *method)
625{
626 struct led_classdev *led_cdev = &led->led;
627
628 if (!method || acpi_check_handle(asus->handle, method, NULL))
Corentin Chary060cbce2010-01-28 10:52:40 +0100629 return 0; /* Led not present */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100630
631 led->asus = asus;
632 led->method = method;
633
634 INIT_WORK(&led->work, asus_led_cdev_update);
635 led_cdev->name = name;
636 led_cdev->brightness_set = asus_led_cdev_set;
637 led_cdev->brightness_get = asus_led_cdev_get;
638 led_cdev->max_brightness = 1;
639 return led_classdev_register(&asus->platform_device->dev, led_cdev);
640}
Corentin Charybe4ee822009-12-06 16:27:09 +0100641
642static int asus_led_init(struct asus_laptop *asus)
643{
Corentin Charyaee0afb2010-01-26 21:01:34 +0100644 int r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100645
646 /*
Corentin Chary8d38e422011-10-14 11:13:39 +0200647 * The Pegatron Lucid has no physical leds, but all methods are
648 * available in the DSDT...
649 */
650 if (asus->is_pega_lucid)
651 return 0;
652
653 /*
Corentin Charybe4ee822009-12-06 16:27:09 +0100654 * Functions that actually update the LED's are called from a
655 * workqueue. By doing this as separate work rather than when the LED
656 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
657 * potentially bad time, such as a timer interrupt.
658 */
Corentin Charyaee0afb2010-01-26 21:01:34 +0100659 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
660 if (!asus->led_workqueue)
Corentin Charybe4ee822009-12-06 16:27:09 +0100661 return -ENOMEM;
662
Corentin Charyaee0afb2010-01-26 21:01:34 +0100663 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
664 if (r)
665 goto error;
666 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
667 if (r)
668 goto error;
669 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
670 if (r)
671 goto error;
672 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
673 if (r)
674 goto error;
675 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
676 if (r)
677 goto error;
Corentin Charyd99b5772010-01-22 21:20:57 +0100678 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
Corentin Charyaee0afb2010-01-26 21:01:34 +0100679 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
680 struct asus_led *led = &asus->kled;
681 struct led_classdev *cdev = &led->led;
682
683 led->asus = asus;
684
685 INIT_WORK(&led->work, asus_kled_cdev_update);
686 cdev->name = "asus::kbd_backlight";
687 cdev->brightness_set = asus_kled_cdev_set;
688 cdev->brightness_get = asus_kled_cdev_get;
689 cdev->max_brightness = 3;
690 r = led_classdev_register(&asus->platform_device->dev, cdev);
691 }
Corentin Charybe4ee822009-12-06 16:27:09 +0100692error:
Corentin Charyaee0afb2010-01-26 21:01:34 +0100693 if (r)
Corentin Charybe4ee822009-12-06 16:27:09 +0100694 asus_led_exit(asus);
Corentin Charyaee0afb2010-01-26 21:01:34 +0100695 return r;
Corentin Charybe4ee822009-12-06 16:27:09 +0100696}
697
698/*
699 * Backlight device
700 */
Corentin Chary4d441512010-01-13 22:26:24 +0100701static int asus_read_brightness(struct backlight_device *bd)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100702{
Corentin Charyd99b5772010-01-22 21:20:57 +0100703 struct asus_laptop *asus = bl_get_data(bd);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400704 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100705 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100706
Corentin Charyd99b5772010-01-22 21:20:57 +0100707 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
708 NULL, &value);
Corentin Chary9a816852007-03-11 10:25:38 +0100709 if (ACPI_FAILURE(rv))
Joe Perches5ad77dc2011-03-29 15:21:35 -0700710 pr_warn("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100711
712 return value;
713}
714
Corentin Chary4d441512010-01-13 22:26:24 +0100715static int asus_set_brightness(struct backlight_device *bd, int value)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100716{
Corentin Charyd99b5772010-01-22 21:20:57 +0100717 struct asus_laptop *asus = bl_get_data(bd);
718
719 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700720 pr_warn("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100721 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100722 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100723 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100724}
725
726static int update_bl_status(struct backlight_device *bd)
727{
Richard Purdie599a52d2007-02-10 23:07:48 +0000728 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100729
Corentin Chary3b81cf92011-02-06 13:27:31 +0100730 return asus_set_brightness(bd, value);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100731}
732
Lionel Debrouxacc24722010-11-16 14:14:02 +0100733static const struct backlight_ops asusbl_ops = {
Corentin Chary4d441512010-01-13 22:26:24 +0100734 .get_brightness = asus_read_brightness,
Corentin Charybe4ee822009-12-06 16:27:09 +0100735 .update_status = update_bl_status,
736};
737
Corentin Charya539df52010-01-25 22:53:21 +0100738static int asus_backlight_notify(struct asus_laptop *asus)
739{
740 struct backlight_device *bd = asus->backlight_device;
741 int old = bd->props.brightness;
742
743 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
744
745 return old;
746}
747
Corentin Charybe4ee822009-12-06 16:27:09 +0100748static int asus_backlight_init(struct asus_laptop *asus)
749{
750 struct backlight_device *bd;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500751 struct backlight_properties props;
Corentin Charybe4ee822009-12-06 16:27:09 +0100752
Corentin Chary71e687d2010-08-24 09:30:44 +0200753 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
Corentin Chary3b81cf92011-02-06 13:27:31 +0100754 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
Corentin Chary71e687d2010-08-24 09:30:44 +0200755 return 0;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500756
Corentin Chary71e687d2010-08-24 09:30:44 +0200757 memset(&props, 0, sizeof(struct backlight_properties));
758 props.max_brightness = 15;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700759 props.type = BACKLIGHT_PLATFORM;
Corentin Charybe4ee822009-12-06 16:27:09 +0100760
Corentin Chary71e687d2010-08-24 09:30:44 +0200761 bd = backlight_device_register(ASUS_LAPTOP_FILE,
762 &asus->platform_device->dev, asus,
763 &asusbl_ops, &props);
764 if (IS_ERR(bd)) {
765 pr_err("Could not register asus backlight device\n");
766 asus->backlight_device = NULL;
767 return PTR_ERR(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100768 }
Corentin Chary71e687d2010-08-24 09:30:44 +0200769
770 asus->backlight_device = bd;
771 bd->props.brightness = asus_read_brightness(bd);
772 bd->props.power = FB_BLANK_UNBLANK;
773 backlight_update_status(bd);
Corentin Charybe4ee822009-12-06 16:27:09 +0100774 return 0;
775}
776
777static void asus_backlight_exit(struct asus_laptop *asus)
778{
779 if (asus->backlight_device)
780 backlight_device_unregister(asus->backlight_device);
Corentin Charya539df52010-01-25 22:53:21 +0100781 asus->backlight_device = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +0100782}
783
Corentin Chary85091b72007-01-26 14:04:30 +0100784/*
785 * Platform device handlers
786 */
787
788/*
789 * We write our info in page, we begin at offset off and cannot write more
790 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
791 * number of bytes written in page
792 */
793static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500794 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100795{
Corentin Chary9129d142009-12-01 22:39:41 +0100796 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary85091b72007-01-26 14:04:30 +0100797 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400798 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200799 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100800 acpi_status rv = AE_OK;
801
Corentin Chary85091b72007-01-26 14:04:30 +0100802 /*
Corentin Chary060cbce2010-01-28 10:52:40 +0100803 * We use the easy way, we don't care of off and count,
804 * so we don't set eof to 1
Corentin Chary85091b72007-01-26 14:04:30 +0100805 */
806
Corentin Chary50a90c42009-11-30 21:55:12 +0100807 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
808 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100809 /*
810 * The SFUN method probably allows the original driver to get the list
811 * of features supported by a given model. For now, 0x0100 or 0x0800
812 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
813 * The significance of others is yet to be found.
814 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100815 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100816 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000817 len += sprintf(page + len, "SFUN value : %#x\n",
818 (uint) temp);
819 /*
820 * The HWRS method return informations about the hardware.
821 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
822 * The significance of others is yet to be found.
823 * If we don't find the method, we assume the device are present.
824 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100825 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000826 if (!ACPI_FAILURE(rv))
827 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100828 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100829 /*
830 * Another value for userspace: the ASYM method returns 0x02 for
831 * battery low and 0x04 for battery critical, its readings tend to be
832 * more accurate than those provided by _BST.
833 * Note: since not all the laptops provide this method, errors are
834 * silently ignored.
835 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100836 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100837 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000838 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100839 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100840 if (asus->dsdt_info) {
841 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100842 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100843 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100844 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100845 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100846 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100847 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100848 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100849 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100850 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100851 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100852 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100853 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100854 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100855 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100856 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
857 }
858
859 return len;
860}
861
862static int parse_arg(const char *buf, unsigned long count, int *val)
863{
864 if (!count)
865 return 0;
866 if (count > 31)
867 return -EINVAL;
868 if (sscanf(buf, "%i", val) != 1)
869 return -EINVAL;
870 return count;
871}
872
Corentin Chary17e78f62010-01-13 22:21:33 +0100873static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
874 const char *buf, size_t count,
Corentin Charyd99b5772010-01-22 21:20:57 +0100875 const char *method)
Corentin Chary4564de12007-01-26 14:04:40 +0100876{
877 int rv, value;
878 int out = 0;
879
880 rv = parse_arg(buf, count, &value);
881 if (rv > 0)
882 out = value ? 1 : 0;
883
Corentin Charyd99b5772010-01-22 21:20:57 +0100884 if (write_acpi_int(asus->handle, method, value))
Corentin Chary17e78f62010-01-13 22:21:33 +0100885 return -ENODEV;
Corentin Chary4564de12007-01-26 14:04:40 +0100886 return rv;
887}
888
889/*
Corentin Chary722ad972007-01-26 14:04:55 +0100890 * LEDD display
891 */
892static ssize_t show_ledd(struct device *dev,
893 struct device_attribute *attr, char *buf)
894{
Corentin Chary9129d142009-12-01 22:39:41 +0100895 struct asus_laptop *asus = dev_get_drvdata(dev);
896
Corentin Chary50a90c42009-11-30 21:55:12 +0100897 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100898}
899
900static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
901 const char *buf, size_t count)
902{
Corentin Chary9129d142009-12-01 22:39:41 +0100903 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary722ad972007-01-26 14:04:55 +0100904 int rv, value;
905
906 rv = parse_arg(buf, count, &value);
907 if (rv > 0) {
Axel Lin6a984a02010-07-20 15:19:48 -0700908 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700909 pr_warn("LED display write failed\n");
Axel Lin6a984a02010-07-20 15:19:48 -0700910 return -ENODEV;
911 }
912 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100913 }
914 return rv;
915}
916
917/*
Corentin Charyaa9df932010-01-13 21:49:10 +0100918 * Wireless
919 */
920static int asus_wireless_status(struct asus_laptop *asus, int mask)
921{
922 unsigned long long status;
923 acpi_status rv = AE_OK;
924
925 if (!asus->have_rsts)
926 return (asus->wireless_status & mask) ? 1 : 0;
927
Corentin Charyd99b5772010-01-22 21:20:57 +0100928 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
929 NULL, &status);
Corentin Charyaa9df932010-01-13 21:49:10 +0100930 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700931 pr_warn("Error reading Wireless status\n");
Corentin Charyaa9df932010-01-13 21:49:10 +0100932 return -EINVAL;
933 }
934 return !!(status & mask);
935}
936
937/*
Corentin Chary4564de12007-01-26 14:04:40 +0100938 * WLAN
939 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100940static int asus_wlan_set(struct asus_laptop *asus, int status)
941{
942 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700943 pr_warn("Error setting wlan status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100944 return -EIO;
945 }
946 return 0;
947}
948
Corentin Chary4564de12007-01-26 14:04:40 +0100949static ssize_t show_wlan(struct device *dev,
950 struct device_attribute *attr, char *buf)
951{
Corentin Chary9129d142009-12-01 22:39:41 +0100952 struct asus_laptop *asus = dev_get_drvdata(dev);
953
Corentin Chary17e78f62010-01-13 22:21:33 +0100954 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100955}
956
957static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
958 const char *buf, size_t count)
959{
Corentin Chary9129d142009-12-01 22:39:41 +0100960 struct asus_laptop *asus = dev_get_drvdata(dev);
961
Corentin Charyd99b5772010-01-22 21:20:57 +0100962 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
Corentin Chary4564de12007-01-26 14:04:40 +0100963}
964
965/*
966 * Bluetooth
967 */
Corentin Charye5593bf2010-01-17 17:20:11 +0100968static int asus_bluetooth_set(struct asus_laptop *asus, int status)
969{
970 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -0700971 pr_warn("Error setting bluetooth status to %d\n", status);
Corentin Charye5593bf2010-01-17 17:20:11 +0100972 return -EIO;
973 }
974 return 0;
975}
976
Corentin Chary4564de12007-01-26 14:04:40 +0100977static ssize_t show_bluetooth(struct device *dev,
978 struct device_attribute *attr, char *buf)
979{
Corentin Chary9129d142009-12-01 22:39:41 +0100980 struct asus_laptop *asus = dev_get_drvdata(dev);
981
Corentin Chary17e78f62010-01-13 22:21:33 +0100982 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
Corentin Chary4564de12007-01-26 14:04:40 +0100983}
984
Len Brown8def05f2007-01-30 01:46:43 -0500985static ssize_t store_bluetooth(struct device *dev,
986 struct device_attribute *attr, const char *buf,
987 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100988{
Corentin Chary9129d142009-12-01 22:39:41 +0100989 struct asus_laptop *asus = dev_get_drvdata(dev);
990
Corentin Charyd99b5772010-01-22 21:20:57 +0100991 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
Corentin Chary4564de12007-01-26 14:04:40 +0100992}
993
Corentin Chary78127b42007-01-26 14:04:49 +0100994/*
Corentin Charyba1ff5b2010-11-14 17:40:12 +0100995 * Wimax
996 */
997static int asus_wimax_set(struct asus_laptop *asus, int status)
998{
999 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001000 pr_warn("Error setting wimax status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001001 return -EIO;
1002 }
1003 return 0;
1004}
1005
1006static ssize_t show_wimax(struct device *dev,
1007 struct device_attribute *attr, char *buf)
1008{
1009 struct asus_laptop *asus = dev_get_drvdata(dev);
1010
1011 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
1012}
1013
1014static ssize_t store_wimax(struct device *dev,
1015 struct device_attribute *attr, const char *buf,
1016 size_t count)
1017{
1018 struct asus_laptop *asus = dev_get_drvdata(dev);
1019
1020 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
1021}
1022
1023/*
1024 * Wwan
1025 */
1026static int asus_wwan_set(struct asus_laptop *asus, int status)
1027{
1028 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001029 pr_warn("Error setting wwan status to %d\n", status);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001030 return -EIO;
1031 }
1032 return 0;
1033}
1034
1035static ssize_t show_wwan(struct device *dev,
1036 struct device_attribute *attr, char *buf)
1037{
1038 struct asus_laptop *asus = dev_get_drvdata(dev);
1039
1040 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
1041}
1042
1043static ssize_t store_wwan(struct device *dev,
1044 struct device_attribute *attr, const char *buf,
1045 size_t count)
1046{
1047 struct asus_laptop *asus = dev_get_drvdata(dev);
1048
1049 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
1050}
1051
1052/*
Corentin Chary78127b42007-01-26 14:04:49 +01001053 * Display
1054 */
Corentin Chary4d441512010-01-13 22:26:24 +01001055static void asus_set_display(struct asus_laptop *asus, int value)
Corentin Chary78127b42007-01-26 14:04:49 +01001056{
1057 /* no sanity check needed for now */
Corentin Charyd99b5772010-01-22 21:20:57 +01001058 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001059 pr_warn("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +01001060 return;
1061}
1062
Corentin Chary78127b42007-01-26 14:04:49 +01001063/*
1064 * Experimental support for display switching. As of now: 1 should activate
1065 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
1066 * Any combination (bitwise) of these will suffice. I never actually tested 4
1067 * displays hooked up simultaneously, so be warned. See the acpi4asus README
1068 * for more info.
1069 */
1070static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
1071 const char *buf, size_t count)
1072{
Corentin Chary9129d142009-12-01 22:39:41 +01001073 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary78127b42007-01-26 14:04:49 +01001074 int rv, value;
1075
1076 rv = parse_arg(buf, count, &value);
1077 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001078 asus_set_display(asus, value);
Corentin Chary78127b42007-01-26 14:04:49 +01001079 return rv;
1080}
1081
Corentin Chary8b857352007-01-26 14:04:58 +01001082/*
1083 * Light Sens
1084 */
Corentin Chary4d441512010-01-13 22:26:24 +01001085static void asus_als_switch(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001086{
Andy Ross33989ba2011-10-14 11:13:36 +02001087 int ret;
1088
1089 if (asus->is_pega_lucid) {
1090 ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
1091 if (!ret)
1092 ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
1093 } else {
1094 ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
1095 }
1096 if (ret)
1097 pr_warning("Error setting light sensor switch\n");
1098
Corentin Chary50a90c42009-11-30 21:55:12 +01001099 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001100}
1101
1102static ssize_t show_lssw(struct device *dev,
1103 struct device_attribute *attr, char *buf)
1104{
Corentin Chary9129d142009-12-01 22:39:41 +01001105 struct asus_laptop *asus = dev_get_drvdata(dev);
1106
Corentin Chary50a90c42009-11-30 21:55:12 +01001107 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001108}
1109
1110static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
1111 const char *buf, size_t count)
1112{
Corentin Chary9129d142009-12-01 22:39:41 +01001113 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001114 int rv, value;
1115
1116 rv = parse_arg(buf, count, &value);
1117 if (rv > 0)
Corentin Chary4d441512010-01-13 22:26:24 +01001118 asus_als_switch(asus, value ? 1 : 0);
Corentin Chary8b857352007-01-26 14:04:58 +01001119
1120 return rv;
1121}
1122
Corentin Chary4d441512010-01-13 22:26:24 +01001123static void asus_als_level(struct asus_laptop *asus, int value)
Corentin Chary8b857352007-01-26 14:04:58 +01001124{
Corentin Charyd99b5772010-01-22 21:20:57 +01001125 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001126 pr_warn("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001127 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +01001128}
1129
1130static ssize_t show_lslvl(struct device *dev,
1131 struct device_attribute *attr, char *buf)
1132{
Corentin Chary9129d142009-12-01 22:39:41 +01001133 struct asus_laptop *asus = dev_get_drvdata(dev);
1134
Corentin Chary50a90c42009-11-30 21:55:12 +01001135 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001136}
1137
1138static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
1139 const char *buf, size_t count)
1140{
Corentin Chary9129d142009-12-01 22:39:41 +01001141 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary8b857352007-01-26 14:04:58 +01001142 int rv, value;
1143
1144 rv = parse_arg(buf, count, &value);
1145 if (rv > 0) {
1146 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
1147 /* 0 <= value <= 15 */
Corentin Chary4d441512010-01-13 22:26:24 +01001148 asus_als_level(asus, value);
Corentin Chary8b857352007-01-26 14:04:58 +01001149 }
1150
1151 return rv;
1152}
1153
Andy Ross33989ba2011-10-14 11:13:36 +02001154static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
1155{
1156 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1157 int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
1158 &buffer);
1159 if (!err) {
1160 union acpi_object *obj = buffer.pointer;
1161 if (obj && obj->type == ACPI_TYPE_INTEGER)
1162 *result = obj->integer.value;
1163 else
1164 err = -EIO;
1165 }
1166 return err;
1167}
1168
1169static ssize_t show_lsvalue(struct device *dev,
1170 struct device_attribute *attr, char *buf)
1171{
1172 struct asus_laptop *asus = dev_get_drvdata(dev);
1173 int err, hi, lo;
1174
1175 err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
1176 if (!err)
1177 err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
1178 if (!err)
1179 return sprintf(buf, "%d\n", 10 * hi + lo);
1180 return err;
1181}
1182
Corentin Charye539c2f2007-05-06 14:47:06 +02001183/*
1184 * GPS
1185 */
Corentin Chary6358bf22010-01-13 21:55:44 +01001186static int asus_gps_status(struct asus_laptop *asus)
1187{
1188 unsigned long long status;
1189 acpi_status rv = AE_OK;
1190
Corentin Charyd99b5772010-01-22 21:20:57 +01001191 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1192 NULL, &status);
Corentin Chary6358bf22010-01-13 21:55:44 +01001193 if (ACPI_FAILURE(rv)) {
Joe Perches5ad77dc2011-03-29 15:21:35 -07001194 pr_warn("Error reading GPS status\n");
Corentin Chary6358bf22010-01-13 21:55:44 +01001195 return -ENODEV;
1196 }
1197 return !!status;
1198}
1199
1200static int asus_gps_switch(struct asus_laptop *asus, int status)
1201{
Corentin Charyd99b5772010-01-22 21:20:57 +01001202 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
Corentin Chary6358bf22010-01-13 21:55:44 +01001203
Corentin Charyd99b5772010-01-22 21:20:57 +01001204 if (write_acpi_int(asus->handle, meth, 0x02))
Corentin Chary6358bf22010-01-13 21:55:44 +01001205 return -ENODEV;
1206 return 0;
1207}
1208
Corentin Charye539c2f2007-05-06 14:47:06 +02001209static ssize_t show_gps(struct device *dev,
1210 struct device_attribute *attr, char *buf)
1211{
Corentin Chary9129d142009-12-01 22:39:41 +01001212 struct asus_laptop *asus = dev_get_drvdata(dev);
1213
Corentin Chary6358bf22010-01-13 21:55:44 +01001214 return sprintf(buf, "%d\n", asus_gps_status(asus));
Corentin Charye539c2f2007-05-06 14:47:06 +02001215}
1216
1217static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1218 const char *buf, size_t count)
1219{
Corentin Chary060cbce2010-01-28 10:52:40 +01001220 struct asus_laptop *asus = dev_get_drvdata(dev);
Corentin Chary6358bf22010-01-13 21:55:44 +01001221 int rv, value;
1222 int ret;
Corentin Chary9129d142009-12-01 22:39:41 +01001223
Corentin Chary6358bf22010-01-13 21:55:44 +01001224 rv = parse_arg(buf, count, &value);
1225 if (rv <= 0)
1226 return -EINVAL;
1227 ret = asus_gps_switch(asus, !!value);
1228 if (ret)
1229 return ret;
Corentin Chary40969c72011-12-15 08:27:33 +01001230 rfkill_set_sw_state(asus->gps.rfkill, !value);
Corentin Chary6358bf22010-01-13 21:55:44 +01001231 return rv;
Corentin Charye539c2f2007-05-06 14:47:06 +02001232}
1233
Corentin Chary034ce902009-01-20 16:17:43 +01001234/*
Corentin Chary18e13112010-01-25 23:29:24 +01001235 * rfkill
1236 */
1237static int asus_gps_rfkill_set(void *data, bool blocked)
1238{
Corentin Chary23f45c32010-08-24 09:30:46 +02001239 struct asus_laptop *asus = data;
Corentin Chary18e13112010-01-25 23:29:24 +01001240
Corentin Chary23f45c32010-08-24 09:30:46 +02001241 return asus_gps_switch(asus, !blocked);
Corentin Chary18e13112010-01-25 23:29:24 +01001242}
1243
1244static const struct rfkill_ops asus_gps_rfkill_ops = {
1245 .set_block = asus_gps_rfkill_set,
1246};
1247
Corentin Chary40969c72011-12-15 08:27:33 +01001248static void asus_rfkill_terminate(struct asus_rfkill *rfk)
1249{
1250 if (!rfk->rfkill)
1251 return ;
1252
1253 rfkill_unregister(rfk->rfkill);
1254 rfkill_destroy(rfk->rfkill);
1255 rfk->rfkill = NULL;
1256}
1257
Corentin Chary18e13112010-01-25 23:29:24 +01001258static void asus_rfkill_exit(struct asus_laptop *asus)
1259{
Corentin Chary40969c72011-12-15 08:27:33 +01001260 asus_rfkill_terminate(&asus->wwan);
1261 asus_rfkill_terminate(&asus->bluetooth);
1262 asus_rfkill_terminate(&asus->wlan);
1263 asus_rfkill_terminate(&asus->gps);
Corentin Chary18e13112010-01-25 23:29:24 +01001264}
1265
1266static int asus_rfkill_init(struct asus_laptop *asus)
1267{
1268 int result;
1269
1270 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1271 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1272 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1273 return 0;
1274
Corentin Chary40969c72011-12-15 08:27:33 +01001275 asus->gps.rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
Corentin Chary18e13112010-01-25 23:29:24 +01001276 RFKILL_TYPE_GPS,
Corentin Chary23f45c32010-08-24 09:30:46 +02001277 &asus_gps_rfkill_ops, asus);
Corentin Chary40969c72011-12-15 08:27:33 +01001278 if (!asus->gps.rfkill)
Corentin Chary18e13112010-01-25 23:29:24 +01001279 return -EINVAL;
1280
Corentin Chary40969c72011-12-15 08:27:33 +01001281 result = rfkill_register(asus->gps.rfkill);
Corentin Chary18e13112010-01-25 23:29:24 +01001282 if (result) {
Corentin Chary40969c72011-12-15 08:27:33 +01001283 rfkill_destroy(asus->gps.rfkill);
1284 asus->gps.rfkill = NULL;
Corentin Chary18e13112010-01-25 23:29:24 +01001285 }
1286
1287 return result;
1288}
1289
Anisse Astier14908392011-10-14 11:13:42 +02001290static int pega_rfkill_set(void *data, bool blocked)
1291{
Corentin Chary40969c72011-12-15 08:27:33 +01001292 struct asus_rfkill *rfk = data;
Anisse Astier14908392011-10-14 11:13:42 +02001293
Corentin Chary40969c72011-12-15 08:27:33 +01001294 int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
Anisse Astier14908392011-10-14 11:13:42 +02001295 return ret;
1296}
1297
1298static const struct rfkill_ops pega_rfkill_ops = {
1299 .set_block = pega_rfkill_set,
1300};
1301
Corentin Chary40969c72011-12-15 08:27:33 +01001302static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
1303 const char *name, int controlid, int rfkill_type)
Anisse Astier14908392011-10-14 11:13:42 +02001304{
1305 int result;
1306
Corentin Chary40969c72011-12-15 08:27:33 +01001307 rfk->control_id = controlid;
1308 rfk->asus = asus;
1309 rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
1310 rfkill_type, &pega_rfkill_ops, rfk);
1311 if (!rfk->rfkill)
Anisse Astier14908392011-10-14 11:13:42 +02001312 return -EINVAL;
1313
Corentin Chary40969c72011-12-15 08:27:33 +01001314 result = rfkill_register(rfk->rfkill);
Anisse Astier14908392011-10-14 11:13:42 +02001315 if (result) {
Corentin Chary40969c72011-12-15 08:27:33 +01001316 rfkill_destroy(rfk->rfkill);
1317 rfk->rfkill = NULL;
Anisse Astier14908392011-10-14 11:13:42 +02001318 }
1319
1320 return result;
1321}
1322
1323static int pega_rfkill_init(struct asus_laptop *asus)
1324{
1325 int ret = 0;
1326
1327 if(!asus->is_pega_lucid)
1328 return -ENODEV;
1329
Corentin Chary40969c72011-12-15 08:27:33 +01001330 ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
1331 PEGA_WLAN, RFKILL_TYPE_WLAN);
Anisse Astier14908392011-10-14 11:13:42 +02001332 if(ret)
Corentin Chary40969c72011-12-15 08:27:33 +01001333 goto exit;
Anisse Astier14908392011-10-14 11:13:42 +02001334
Corentin Chary40969c72011-12-15 08:27:33 +01001335 ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
1336 PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
1337 if(ret)
1338 goto exit;
1339
1340 ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
1341 PEGA_WWAN, RFKILL_TYPE_WWAN);
1342
1343exit:
1344 if (ret)
1345 asus_rfkill_exit(asus);
Anisse Astier14908392011-10-14 11:13:42 +02001346
1347 return ret;
1348}
1349
Corentin Chary18e13112010-01-25 23:29:24 +01001350/*
Corentin Charybe4ee822009-12-06 16:27:09 +01001351 * Input device (i.e. hotkeys)
Corentin Chary034ce902009-01-20 16:17:43 +01001352 */
Corentin Charybe4ee822009-12-06 16:27:09 +01001353static void asus_input_notify(struct asus_laptop *asus, int event)
1354{
Corentin Charye0ac9132011-12-15 08:27:31 +01001355 if (!asus->inputdev)
1356 return ;
1357 if (!sparse_keymap_report_event(asus->inputdev, event, 1, true))
1358 pr_info("Unknown key %x pressed\n", event);
Corentin Charybe4ee822009-12-06 16:27:09 +01001359}
1360
1361static int asus_input_init(struct asus_laptop *asus)
1362{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001363 struct input_dev *input;
1364 int error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001365
Corentin Chary66a71dd2010-01-25 22:50:11 +01001366 input = input_allocate_device();
1367 if (!input) {
Corentin Chary40969c72011-12-15 08:27:33 +01001368 pr_warn("Unable to allocate input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001369 return -ENOMEM;
Corentin Charybe4ee822009-12-06 16:27:09 +01001370 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001371 input->name = "Asus Laptop extra buttons";
1372 input->phys = ASUS_LAPTOP_FILE "/input0";
1373 input->id.bustype = BUS_HOST;
1374 input->dev.parent = &asus->platform_device->dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001375
Corentin Chary66a71dd2010-01-25 22:50:11 +01001376 error = sparse_keymap_setup(input, asus_keymap, NULL);
1377 if (error) {
1378 pr_err("Unable to setup input device keymap\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001379 goto err_free_dev;
Corentin Charybe4ee822009-12-06 16:27:09 +01001380 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001381 error = input_register_device(input);
1382 if (error) {
Corentin Chary40969c72011-12-15 08:27:33 +01001383 pr_warn("Unable to register input device\n");
Axel Lin45036ae2010-07-05 15:29:00 +08001384 goto err_free_keymap;
Corentin Charybe4ee822009-12-06 16:27:09 +01001385 }
Corentin Chary66a71dd2010-01-25 22:50:11 +01001386
1387 asus->inputdev = input;
1388 return 0;
1389
Axel Lin45036ae2010-07-05 15:29:00 +08001390err_free_keymap:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001391 sparse_keymap_free(input);
Axel Lin45036ae2010-07-05 15:29:00 +08001392err_free_dev:
Corentin Chary66a71dd2010-01-25 22:50:11 +01001393 input_free_device(input);
1394 return error;
Corentin Charybe4ee822009-12-06 16:27:09 +01001395}
1396
1397static void asus_input_exit(struct asus_laptop *asus)
1398{
Corentin Chary66a71dd2010-01-25 22:50:11 +01001399 if (asus->inputdev) {
1400 sparse_keymap_free(asus->inputdev);
Corentin Charybe4ee822009-12-06 16:27:09 +01001401 input_unregister_device(asus->inputdev);
Corentin Chary66a71dd2010-01-25 22:50:11 +01001402 }
Corentin Chary71e687d2010-08-24 09:30:44 +02001403 asus->inputdev = NULL;
Corentin Charybe4ee822009-12-06 16:27:09 +01001404}
1405
1406/*
1407 * ACPI driver
1408 */
Corentin Chary600ad522009-11-30 21:42:42 +01001409static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +01001410{
Corentin Chary9129d142009-12-01 22:39:41 +01001411 struct asus_laptop *asus = acpi_driver_data(device);
Corentin Chary6050c8d2009-02-15 19:30:19 +01001412 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +01001413
Corentin Chary619d8b12009-11-28 10:35:37 +01001414 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +01001415 count = asus->event_count[event % 128]++;
1416 acpi_bus_generate_proc_event(asus->device, event, count);
1417 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1418 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +01001419 count);
Corentin Chary85091b72007-01-26 14:04:30 +01001420
Corentin Charya539df52010-01-25 22:53:21 +01001421 /* Brightness events are special */
1422 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1423
1424 /* Ignore them completely if the acpi video driver is used */
1425 if (asus->backlight_device != NULL) {
1426 /* Update the backlight device. */
1427 asus_backlight_notify(asus);
1428 }
1429 return ;
1430 }
Anisse Astierb93f8282011-10-14 11:13:41 +02001431
1432 /* Accelerometer "coarse orientation change" event */
1433 if (asus->pega_accel_poll && event == 0xEA) {
1434 kobject_uevent(&asus->pega_accel_poll->input->dev.kobj,
1435 KOBJ_CHANGE);
1436 return ;
1437 }
1438
Corentin Charybe4ee822009-12-06 16:27:09 +01001439 asus_input_notify(asus, event);
Corentin Chary85091b72007-01-26 14:04:30 +01001440}
1441
Corentin Chary2a1fd642010-01-26 21:02:23 +01001442static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1443static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001444static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1445 show_bluetooth, store_bluetooth);
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001446static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1447static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
Corentin Chary3b81cf92011-02-06 13:27:31 +01001448static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001449static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
Andy Ross33989ba2011-10-14 11:13:36 +02001450static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
Corentin Chary2a1fd642010-01-26 21:02:23 +01001451static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1452static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1453static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1454
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001455static struct attribute *asus_attributes[] = {
1456 &dev_attr_infos.attr,
1457 &dev_attr_wlan.attr,
1458 &dev_attr_bluetooth.attr,
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001459 &dev_attr_wimax.attr,
1460 &dev_attr_wwan.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001461 &dev_attr_display.attr,
1462 &dev_attr_ledd.attr,
Andy Ross33989ba2011-10-14 11:13:36 +02001463 &dev_attr_ls_value.attr,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001464 &dev_attr_ls_level.attr,
1465 &dev_attr_ls_switch.attr,
1466 &dev_attr_gps.attr,
1467 NULL
1468};
Corentin Chary2a1fd642010-01-26 21:02:23 +01001469
Al Viro587a1f12011-07-23 23:11:19 -04001470static umode_t asus_sysfs_is_visible(struct kobject *kobj,
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001471 struct attribute *attr,
1472 int idx)
1473{
1474 struct device *dev = container_of(kobj, struct device, kobj);
1475 struct platform_device *pdev = to_platform_device(dev);
1476 struct asus_laptop *asus = platform_get_drvdata(pdev);
1477 acpi_handle handle = asus->handle;
1478 bool supported;
1479
Andy Ross33989ba2011-10-14 11:13:36 +02001480 if (asus->is_pega_lucid) {
1481 /* no ls_level interface on the Lucid */
1482 if (attr == &dev_attr_ls_switch.attr)
1483 supported = true;
1484 else if (attr == &dev_attr_ls_level.attr)
1485 supported = false;
1486 else
1487 goto normal;
1488
1489 return supported;
1490 }
1491
1492normal:
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001493 if (attr == &dev_attr_wlan.attr) {
1494 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1495
1496 } else if (attr == &dev_attr_bluetooth.attr) {
1497 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1498
1499 } else if (attr == &dev_attr_display.attr) {
1500 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1501
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001502 } else if (attr == &dev_attr_wimax.attr) {
1503 supported =
1504 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1505
1506 } else if (attr == &dev_attr_wwan.attr) {
1507 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1508
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001509 } else if (attr == &dev_attr_ledd.attr) {
1510 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1511
1512 } else if (attr == &dev_attr_ls_switch.attr ||
1513 attr == &dev_attr_ls_level.attr) {
1514 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
Andy Ross33989ba2011-10-14 11:13:36 +02001515 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1516 } else if (attr == &dev_attr_ls_value.attr) {
1517 supported = asus->is_pega_lucid;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001518 } else if (attr == &dev_attr_gps.attr) {
1519 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1520 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1521 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1522 } else {
1523 supported = true;
1524 }
1525
1526 return supported ? attr->mode : 0;
Corentin Chary2a1fd642010-01-26 21:02:23 +01001527}
1528
Corentin Chary2a1fd642010-01-26 21:02:23 +01001529
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001530static const struct attribute_group asus_attr_group = {
1531 .is_visible = asus_sysfs_is_visible,
1532 .attrs = asus_attributes,
1533};
Corentin Chary85091b72007-01-26 14:04:30 +01001534
Corentin Chary9129d142009-12-01 22:39:41 +01001535static int asus_platform_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001536{
Corentin Chary71e687d2010-08-24 09:30:44 +02001537 int result;
Corentin Chary600ad522009-11-30 21:42:42 +01001538
Corentin Chary50a90c42009-11-30 21:55:12 +01001539 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1540 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +01001541 return -ENOMEM;
Corentin Chary9129d142009-12-01 22:39:41 +01001542 platform_set_drvdata(asus->platform_device, asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001543
Corentin Chary71e687d2010-08-24 09:30:44 +02001544 result = platform_device_add(asus->platform_device);
1545 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001546 goto fail_platform_device;
1547
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001548 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1549 &asus_attr_group);
Corentin Chary71e687d2010-08-24 09:30:44 +02001550 if (result)
Corentin Chary600ad522009-11-30 21:42:42 +01001551 goto fail_sysfs;
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001552
Corentin Chary600ad522009-11-30 21:42:42 +01001553 return 0;
1554
1555fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001556 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001557fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001558 platform_device_put(asus->platform_device);
Corentin Chary71e687d2010-08-24 09:30:44 +02001559 return result;
Corentin Chary600ad522009-11-30 21:42:42 +01001560}
1561
Corentin Chary9129d142009-12-01 22:39:41 +01001562static void asus_platform_exit(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001563{
Dmitry Torokhovac9b1e52010-08-26 00:12:19 -07001564 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001565 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001566}
1567
1568static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001569 .driver = {
Corentin Chary9129d142009-12-01 22:39:41 +01001570 .name = ASUS_LAPTOP_FILE,
1571 .owner = THIS_MODULE,
Andy Rossb23910c2011-10-14 11:13:38 +02001572 },
Corentin Chary85091b72007-01-26 14:04:30 +01001573};
1574
Corentin Chary85091b72007-01-26 14:04:30 +01001575/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001576 * This function is used to initialize the context with right values. In this
1577 * method, we can make all the detection we want, and modify the asus_laptop
1578 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001579 */
Corentin Chary7c247642009-11-30 22:13:54 +01001580static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001581{
1582 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001583 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001584 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001585 char *string = NULL;
1586 acpi_status status;
1587
1588 /*
1589 * Get DSDT headers early enough to allow for differentiating between
1590 * models, but late enough to allow acpi_bus_register_driver() to fail
1591 * before doing anything ACPI-specific. Should we encounter a machine,
1592 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001593 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001594 */
Corentin Chary7c247642009-11-30 22:13:54 +01001595 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001596 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001597 pr_warn("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001598
1599 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001600 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001601 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001602 return -ENODEV;
1603 }
1604
1605 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001606 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001607 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001608 if (ACPI_FAILURE(status))
Joe Perches5ad77dc2011-03-29 15:21:35 -07001609 pr_warn("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001610 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001611 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001612 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001613
Corentin Chary185e5af2007-03-11 10:27:33 +01001614 /* This too ... */
Corentin Charye5593bf2010-01-17 17:20:11 +01001615 if (write_acpi_int(asus->handle, "CWAP", wapf))
1616 pr_err("Error calling CWAP(%d)\n", wapf);
Corentin Chary85091b72007-01-26 14:04:30 +01001617 /*
1618 * Try to match the object returned by INIT to the specific model.
1619 * Handle every possible object (or the lack of thereof) the DSDT
1620 * writers might throw at us. When in trouble, we pass NULL to
1621 * asus_model_match() and try something completely different.
1622 */
1623 if (buffer.pointer) {
1624 model = buffer.pointer;
1625 switch (model->type) {
1626 case ACPI_TYPE_STRING:
1627 string = model->string.pointer;
1628 break;
1629 case ACPI_TYPE_BUFFER:
1630 string = model->buffer.pointer;
1631 break;
1632 default:
1633 string = "";
1634 break;
1635 }
1636 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001637 asus->name = kstrdup(string, GFP_KERNEL);
Axel Lind8eca112010-06-29 11:09:47 +08001638 if (!asus->name) {
1639 kfree(buffer.pointer);
Corentin Chary85091b72007-01-26 14:04:30 +01001640 return -ENOMEM;
Axel Lind8eca112010-06-29 11:09:47 +08001641 }
Corentin Chary85091b72007-01-26 14:04:30 +01001642
Len Brown8def05f2007-01-30 01:46:43 -05001643 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001644 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001645
Corentin Chary4564de12007-01-26 14:04:40 +01001646 /*
1647 * The HWRS method return informations about the hardware.
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001648 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1649 * 0x40 for WWAN, 0x10 for WIMAX.
Corentin Chary4564de12007-01-26 14:04:40 +01001650 * The significance of others is yet to be found.
Corentin Chary4564de12007-01-26 14:04:40 +01001651 */
Corentin Chary9a816852007-03-11 10:25:38 +01001652 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001653 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Charyd99b5772010-01-22 21:20:57 +01001654 if (!ACPI_FAILURE(status))
1655 pr_notice(" HRWS returned %x", (int)hwrs_result);
Corentin Chary4564de12007-01-26 14:04:40 +01001656
Corentin Charyd99b5772010-01-22 21:20:57 +01001657 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
Corentin Charyaa9df932010-01-13 21:49:10 +01001658 asus->have_rsts = true;
Corentin Chary4564de12007-01-26 14:04:40 +01001659
Corentin Chary85091b72007-01-26 14:04:30 +01001660 kfree(model);
1661
1662 return AE_OK;
1663}
1664
Corentin Chary9129d142009-12-01 22:39:41 +01001665static int __devinit asus_acpi_init(struct asus_laptop *asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001666{
1667 int result = 0;
1668
Corentin Chary50a90c42009-11-30 21:55:12 +01001669 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001670 if (result)
1671 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001672 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001673 pr_err("Hotkey device not present, aborting\n");
1674 return -ENODEV;
1675 }
1676
Corentin Chary7c247642009-11-30 22:13:54 +01001677 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001678 if (result)
1679 return result;
1680
Corentin Chary600ad522009-11-30 21:42:42 +01001681 /* WLED and BLED are on by default */
Corentin Charybe4ee822009-12-06 16:27:09 +01001682 if (bluetooth_status >= 0)
Corentin Charye5593bf2010-01-17 17:20:11 +01001683 asus_bluetooth_set(asus, !!bluetooth_status);
1684
Corentin Charyd0930a22010-01-17 17:21:13 +01001685 if (wlan_status >= 0)
1686 asus_wlan_set(asus, !!wlan_status);
Corentin Chary600ad522009-11-30 21:42:42 +01001687
Corentin Charyba1ff5b2010-11-14 17:40:12 +01001688 if (wimax_status >= 0)
1689 asus_wimax_set(asus, !!wimax_status);
1690
1691 if (wwan_status >= 0)
1692 asus_wwan_set(asus, !!wwan_status);
1693
Corentin Chary600ad522009-11-30 21:42:42 +01001694 /* Keyboard Backlight is on by default */
Corentin Charyd99b5772010-01-22 21:20:57 +01001695 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
Corentin Chary4d441512010-01-13 22:26:24 +01001696 asus_kled_set(asus, 1);
Corentin Chary600ad522009-11-30 21:42:42 +01001697
1698 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001699 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001700
1701 /* Set initial values of light sensor and level */
Andy Rossabec04d2011-10-14 11:13:37 +02001702 asus->light_switch = !!als_status;
Corentin Charybe4ee822009-12-06 16:27:09 +01001703 asus->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary600ad522009-11-30 21:42:42 +01001704
Andy Ross33989ba2011-10-14 11:13:36 +02001705 if (asus->is_pega_lucid) {
1706 asus_als_switch(asus, asus->light_switch);
1707 } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1708 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
Corentin Chary4d441512010-01-13 22:26:24 +01001709 asus_als_switch(asus, asus->light_switch);
Corentin Chary4d441512010-01-13 22:26:24 +01001710 asus_als_level(asus, asus->light_level);
Corentin Charyd99b5772010-01-22 21:20:57 +01001711 }
Corentin Chary600ad522009-11-30 21:42:42 +01001712
Corentin Chary600ad522009-11-30 21:42:42 +01001713 return result;
1714}
1715
Corentin Charyaf96f872011-02-06 13:27:30 +01001716static void __devinit asus_dmi_check(void)
1717{
1718 const char *model;
1719
1720 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1721 if (!model)
1722 return;
1723
1724 /* On L1400B WLED control the sound card, don't mess with it ... */
1725 if (strncmp(model, "L1400B", 6) == 0) {
1726 wlan_status = -1;
1727 }
1728}
1729
Corentin Chary71e687d2010-08-24 09:30:44 +02001730static bool asus_device_present;
1731
Corentin Chary600ad522009-11-30 21:42:42 +01001732static int __devinit asus_acpi_add(struct acpi_device *device)
1733{
Corentin Chary9129d142009-12-01 22:39:41 +01001734 struct asus_laptop *asus;
Corentin Chary600ad522009-11-30 21:42:42 +01001735 int result;
1736
1737 pr_notice("Asus Laptop Support version %s\n",
1738 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001739 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1740 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001741 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001742 asus->handle = device->handle;
1743 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1744 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1745 device->driver_data = asus;
1746 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001747
Corentin Charyaf96f872011-02-06 13:27:30 +01001748 asus_dmi_check();
1749
Corentin Chary9129d142009-12-01 22:39:41 +01001750 result = asus_acpi_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001751 if (result)
1752 goto fail_platform;
1753
1754 /*
Andy Ross8819de72011-10-14 11:13:35 +02001755 * Need platform type detection first, then the platform
1756 * device. It is used as a parent for the sub-devices below.
Corentin Chary600ad522009-11-30 21:42:42 +01001757 */
Andy Ross8819de72011-10-14 11:13:35 +02001758 asus->is_pega_lucid = asus_check_pega_lucid(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001759 result = asus_platform_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001760 if (result)
1761 goto fail_platform;
1762
1763 if (!acpi_video_backlight_support()) {
Corentin Chary9129d142009-12-01 22:39:41 +01001764 result = asus_backlight_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001765 if (result)
1766 goto fail_backlight;
1767 } else
1768 pr_info("Backlight controlled by ACPI video driver\n");
1769
Corentin Chary9129d142009-12-01 22:39:41 +01001770 result = asus_input_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001771 if (result)
1772 goto fail_input;
1773
Corentin Chary9129d142009-12-01 22:39:41 +01001774 result = asus_led_init(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001775 if (result)
1776 goto fail_led;
1777
Corentin Chary18e13112010-01-25 23:29:24 +01001778 result = asus_rfkill_init(asus);
1779 if (result)
1780 goto fail_rfkill;
1781
Andy Rossb23910c2011-10-14 11:13:38 +02001782 result = pega_accel_init(asus);
1783 if (result && result != -ENODEV)
1784 goto fail_pega_accel;
1785
Anisse Astier14908392011-10-14 11:13:42 +02001786 result = pega_rfkill_init(asus);
1787 if (result && result != -ENODEV)
1788 goto fail_pega_rfkill;
1789
Corentin Chary600ad522009-11-30 21:42:42 +01001790 asus_device_present = true;
1791 return 0;
1792
Anisse Astier14908392011-10-14 11:13:42 +02001793fail_pega_rfkill:
1794 pega_accel_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001795fail_pega_accel:
1796 asus_rfkill_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001797fail_rfkill:
1798 asus_led_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001799fail_led:
Corentin Chary9129d142009-12-01 22:39:41 +01001800 asus_input_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001801fail_input:
Corentin Chary9129d142009-12-01 22:39:41 +01001802 asus_backlight_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001803fail_backlight:
Corentin Chary9129d142009-12-01 22:39:41 +01001804 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001805fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001806 kfree(asus->name);
1807 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001808
1809 return result;
1810}
1811
1812static int asus_acpi_remove(struct acpi_device *device, int type)
1813{
Corentin Chary9129d142009-12-01 22:39:41 +01001814 struct asus_laptop *asus = acpi_driver_data(device);
1815
1816 asus_backlight_exit(asus);
Corentin Chary18e13112010-01-25 23:29:24 +01001817 asus_rfkill_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001818 asus_led_exit(asus);
1819 asus_input_exit(asus);
Andy Rossb23910c2011-10-14 11:13:38 +02001820 pega_accel_exit(asus);
Corentin Chary9129d142009-12-01 22:39:41 +01001821 asus_platform_exit(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001822
Corentin Chary50a90c42009-11-30 21:55:12 +01001823 kfree(asus->name);
1824 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001825 return 0;
1826}
1827
1828static const struct acpi_device_id asus_device_ids[] = {
1829 {"ATK0100", 0},
1830 {"ATK0101", 0},
1831 {"", 0},
1832};
1833MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1834
1835static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001836 .name = ASUS_LAPTOP_NAME,
1837 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001838 .owner = THIS_MODULE,
1839 .ids = asus_device_ids,
1840 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1841 .ops = {
1842 .add = asus_acpi_add,
1843 .remove = asus_acpi_remove,
1844 .notify = asus_acpi_notify,
1845 },
1846};
1847
Corentin Chary85091b72007-01-26 14:04:30 +01001848static int __init asus_laptop_init(void)
1849{
1850 int result;
1851
Corentin Chary600ad522009-11-30 21:42:42 +01001852 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001853 if (result < 0)
1854 return result;
1855
Corentin Chary600ad522009-11-30 21:42:42 +01001856 result = acpi_bus_register_driver(&asus_acpi_driver);
1857 if (result < 0)
1858 goto fail_acpi_driver;
1859 if (!asus_device_present) {
1860 result = -ENODEV;
1861 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001862 }
Len Brown8def05f2007-01-30 01:46:43 -05001863 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001864
Corentin Chary600ad522009-11-30 21:42:42 +01001865fail_no_device:
1866 acpi_bus_unregister_driver(&asus_acpi_driver);
1867fail_acpi_driver:
1868 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001869 return result;
1870}
1871
Corentin Chary600ad522009-11-30 21:42:42 +01001872static void __exit asus_laptop_exit(void)
1873{
1874 acpi_bus_unregister_driver(&asus_acpi_driver);
1875 platform_driver_unregister(&platform_driver);
1876}
1877
Corentin Chary85091b72007-01-26 14:04:30 +01001878module_init(asus_laptop_init);
1879module_exit(asus_laptop_exit);