blob: dd926b913ec9d297dbc73aec81c8bd100a528cd8 [file] [log] [blame]
Corentin Chary85091b72007-01-26 14:04:30 +01001/*
2 * asus-laptop.c - Asus Laptop Support
3 *
4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Corentin Chary8ec555c2007-03-11 10:28:03 +01006 * Copyright (C) 2006-2007 Corentin Chary
Corentin Chary85091b72007-01-26 14:04:30 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 *
23 * The development page for this driver is located at
24 * http://sourceforge.net/projects/acpi4asus/
25 *
26 * Credits:
27 * Pontus Fuchs - Helper functions, cleanup
28 * Johann Wiesner - Small compile fixes
29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
30 * Eric Burghard - LED display support for W1N
31 * Josh Green - Light Sens support
32 * Thomas Tuttle - His first patch for led support was very helpfull
Corentin Charye539c2f2007-05-06 14:47:06 +020033 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010034 */
35
Corentin Chary2fcc23d2009-06-19 14:52:03 +020036#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
Corentin Chary85091b72007-01-26 14:04:30 +010038#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/types.h>
42#include <linux/err.h>
43#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010044#include <linux/backlight.h>
45#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010046#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010047#include <linux/platform_device.h>
48#include <acpi/acpi_drivers.h>
49#include <acpi/acpi_bus.h>
50#include <asm/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010051#include <linux/input.h>
Corentin Chary85091b72007-01-26 14:04:30 +010052
Corentin Charyf3985322007-05-06 14:48:22 +020053#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010054
55#define ASUS_HOTK_NAME "Asus Laptop Support"
56#define ASUS_HOTK_CLASS "hotkey"
57#define ASUS_HOTK_DEVICE_NAME "Hotkey"
Corentin Chary2fcc23d2009-06-19 14:52:03 +020058#define ASUS_HOTK_FILE KBUILD_MODNAME
Corentin Chary85091b72007-01-26 14:04:30 +010059#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
60
Corentin Chary2fcc23d2009-06-19 14:52:03 +020061
Corentin Charybe18cda2007-01-26 14:04:35 +010062/*
Corentin Chary6b7091e2007-01-26 14:04:45 +010063 * Some events we use, same for all Asus
64 */
65#define ATKD_BR_UP 0x10
66#define ATKD_BR_DOWN 0x20
67#define ATKD_LCD_ON 0x33
68#define ATKD_LCD_OFF 0x34
69
70/*
Corentin Chary4564de12007-01-26 14:04:40 +010071 * Known bits returned by \_SB.ATKD.HWRS
Corentin Charybe18cda2007-01-26 14:04:35 +010072 */
Corentin Chary4564de12007-01-26 14:04:40 +010073#define WL_HWRS 0x80
74#define BT_HWRS 0x100
75
76/*
77 * Flags for hotk status
78 * WL_ON and BT_ON are also used for wireless_status()
79 */
80#define WL_ON 0x01 //internal Wifi
81#define BT_ON 0x02 //internal Bluetooth
Corentin Charybe18cda2007-01-26 14:04:35 +010082#define MLED_ON 0x04 //mail LED
83#define TLED_ON 0x08 //touchpad LED
Len Brown8def05f2007-01-30 01:46:43 -050084#define RLED_ON 0x10 //Record LED
85#define PLED_ON 0x20 //Phone LED
Corentin Charyfdd8d082007-03-11 10:26:48 +010086#define GLED_ON 0x40 //Gaming LED
87#define LCD_ON 0x80 //LCD backlight
Corentin Charyf3985322007-05-06 14:48:22 +020088#define GPS_ON 0x100 //GPS
Corentin Charyb7d3fbc2009-08-28 12:56:50 +000089#define KEY_ON 0x200 //Keyboard backlight
Corentin Charybe18cda2007-01-26 14:04:35 +010090
Corentin Chary85091b72007-01-26 14:04:30 +010091#define ASUS_LOG ASUS_HOTK_FILE ": "
92#define ASUS_ERR KERN_ERR ASUS_LOG
93#define ASUS_WARNING KERN_WARNING ASUS_LOG
94#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
95#define ASUS_INFO KERN_INFO ASUS_LOG
96#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
97
98MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
99MODULE_DESCRIPTION(ASUS_HOTK_NAME);
100MODULE_LICENSE("GPL");
101
Corentin Chary185e5af2007-03-11 10:27:33 +0100102/* WAPF defines the behavior of the Fn+Fx wlan key
103 * The significance of values is yet to be found, but
104 * most of the time:
105 * 0x0 will do nothing
106 * 0x1 will allow to control the device with Fn+Fx key.
107 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
108 * 0x5 like 0x1 or 0x4
109 * So, if something doesn't work as you want, just try other values =)
110 */
111static uint wapf = 1;
112module_param(wapf, uint, 0644);
113MODULE_PARM_DESC(wapf, "WAPF value");
114
Corentin Chary85091b72007-01-26 14:04:30 +0100115#define ASUS_HANDLE(object, paths...) \
116 static acpi_handle object##_handle = NULL; \
117 static char *object##_paths[] = { paths }
118
Corentin Charybe18cda2007-01-26 14:04:35 +0100119/* LED */
120ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
121ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500122ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
123ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charyfdd8d082007-03-11 10:26:48 +0100124ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100125
Corentin Chary722ad972007-01-26 14:04:55 +0100126/* LEDD */
127ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
128
Corentin Chary4564de12007-01-26 14:04:40 +0100129/* Bluetooth and WLAN
130 * WLED and BLED are not handled like other XLED, because in some dsdt
131 * they also control the WLAN/Bluetooth device.
132 */
133ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
134ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500135ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100136
Corentin Chary6b7091e2007-01-26 14:04:45 +0100137/* Brightness */
138ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
139ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
140
141/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500142ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
143 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
144 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
145 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
146 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
Torsten Krah4d0b856e2008-10-17 09:47:57 +0200147 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
Len Brown8def05f2007-01-30 01:46:43 -0500148 "\\_SB.PCI0.PX40.Q10", /* S1x */
149 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100150
Corentin Chary78127b42007-01-26 14:04:49 +0100151/* Display */
152ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Len Brown8def05f2007-01-30 01:46:43 -0500153ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G
154 M6A M6V VX-1 V6J V6V W3Z */
155 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
Corentin Charyf3985322007-05-06 14:48:22 +0200156 S5A M5A z33A W1Jc W2V G1 */
Len Brown8def05f2007-01-30 01:46:43 -0500157 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
158 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
159 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */
160 "\\_SB.PCI0.VGA.GETD", /* Z96F */
161 "\\ACTD", /* A2D */
162 "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
163 "\\DNXT", /* P30 */
164 "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
165 "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
Corentin Chary78127b42007-01-26 14:04:49 +0100166
Len Brown8def05f2007-01-30 01:46:43 -0500167ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
168ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100169
Corentin Charye539c2f2007-05-06 14:47:06 +0200170/* GPS */
171/* R2H use different handle for GPS on/off */
Corentin Charyf3985322007-05-06 14:48:22 +0200172ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
173ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
Corentin Charye539c2f2007-05-06 14:47:06 +0200174ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
175
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000176/* Keyboard light */
177ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
178ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
179
Corentin Chary85091b72007-01-26 14:04:30 +0100180/*
181 * This is the main structure, we can use it to store anything interesting
182 * about the hotk device
183 */
184struct asus_hotk {
Len Brown8def05f2007-01-30 01:46:43 -0500185 char *name; //laptop name
Corentin Chary85091b72007-01-26 14:04:30 +0100186 struct acpi_device *device; //the device we are in
187 acpi_handle handle; //the handle of the hotk device
188 char status; //status of the hotk, for LEDs, ...
Corentin Chary722ad972007-01-26 14:04:55 +0100189 u32 ledd_status; //status of the LED display
Len Brown8def05f2007-01-30 01:46:43 -0500190 u8 light_level; //light sensor level
191 u8 light_switch; //light sensor switch value
Corentin Chary85091b72007-01-26 14:04:30 +0100192 u16 event_count[128]; //count for each event TODO make this better
Corentin Chary034ce902009-01-20 16:17:43 +0100193 struct input_dev *inputdev;
194 u16 *keycode_map;
Corentin Chary85091b72007-01-26 14:04:30 +0100195};
196
197/*
198 * This header is made available to allow proper configuration given model,
199 * revision number , ... this info cannot go in struct asus_hotk because it is
200 * available before the hotk
201 */
202static struct acpi_table_header *asus_info;
203
204/* The actual device the driver binds to */
205static struct asus_hotk *hotk;
206
207/*
208 * The hotkey driver declaration
209 */
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200210static const struct acpi_device_id asus_device_ids[] = {
211 {"ATK0100", 0},
212 {"", 0},
213};
214MODULE_DEVICE_TABLE(acpi, asus_device_ids);
215
Corentin Chary85091b72007-01-26 14:04:30 +0100216static int asus_hotk_add(struct acpi_device *device);
217static int asus_hotk_remove(struct acpi_device *device, int type);
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600218static void asus_hotk_notify(struct acpi_device *device, u32 event);
219
Corentin Chary85091b72007-01-26 14:04:30 +0100220static struct acpi_driver asus_hotk_driver = {
221 .name = ASUS_HOTK_NAME,
222 .class = ASUS_HOTK_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200223 .ids = asus_device_ids,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600224 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Corentin Chary85091b72007-01-26 14:04:30 +0100225 .ops = {
226 .add = asus_hotk_add,
227 .remove = asus_hotk_remove,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600228 .notify = asus_hotk_notify,
Corentin Chary85091b72007-01-26 14:04:30 +0100229 },
230};
231
Corentin Chary6b7091e2007-01-26 14:04:45 +0100232/* The backlight device /sys/class/backlight */
233static struct backlight_device *asus_backlight_device;
234
235/*
236 * The backlight class declaration
237 */
238static int read_brightness(struct backlight_device *bd);
239static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000240static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500241 .get_brightness = read_brightness,
242 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100243};
244
Corentin Charybe18cda2007-01-26 14:04:35 +0100245/* These functions actually update the LED's, and are called from a
246 * workqueue. By doing this as separate work rather than when the LED
247 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
248 * potentially bad time, such as a timer interrupt. */
249static struct workqueue_struct *led_workqueue;
250
Corentin Chary977c3282009-08-28 12:56:49 +0000251#define ASUS_LED(object, ledname, max) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100252 static void object##_led_set(struct led_classdev *led_cdev, \
253 enum led_brightness value); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000254 static enum led_brightness object##_led_get( \
255 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100256 static void object##_led_update(struct work_struct *ignored); \
257 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100258 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100259 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100260 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100261 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000262 .brightness_get = object##_led_get, \
Corentin Chary977c3282009-08-28 12:56:49 +0000263 .max_brightness = max \
Corentin Charybe18cda2007-01-26 14:04:35 +0100264 }
265
Corentin Chary977c3282009-08-28 12:56:49 +0000266ASUS_LED(mled, "mail", 1);
267ASUS_LED(tled, "touchpad", 1);
268ASUS_LED(rled, "record", 1);
269ASUS_LED(pled, "phone", 1);
270ASUS_LED(gled, "gaming", 1);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000271ASUS_LED(kled, "kbd_backlight", 3);
Corentin Charybe18cda2007-01-26 14:04:35 +0100272
Corentin Chary034ce902009-01-20 16:17:43 +0100273struct key_entry {
274 char type;
275 u8 code;
276 u16 keycode;
277};
278
279enum { KE_KEY, KE_END };
280
281static struct key_entry asus_keymap[] = {
282 {KE_KEY, 0x30, KEY_VOLUMEUP},
283 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
284 {KE_KEY, 0x32, KEY_MUTE},
285 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
286 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
287 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
288 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200289 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100290 {KE_KEY, 0x45, KEY_PLAYPAUSE},
291 {KE_KEY, 0x50, KEY_EMAIL},
292 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200293 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100294 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000295 {KE_KEY, 0x5E, KEY_WLAN},
296 {KE_KEY, 0x5F, KEY_WLAN},
297 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100298 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
299 {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
300 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200301 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100302 {KE_KEY, 0x95, KEY_MEDIA},
303 {KE_KEY, 0x99, KEY_PHONE},
Corentin Charydc795262009-08-28 12:56:51 +0000304 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
305 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
Corentin Chary034ce902009-01-20 16:17:43 +0100306 {KE_END, 0},
307};
308
Corentin Chary85091b72007-01-26 14:04:30 +0100309/*
310 * This function evaluates an ACPI method, given an int as parameter, the
311 * method is searched within the scope of the handle, can be NULL. The output
312 * of the method is written is output, which can also be NULL
313 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100314 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100315 */
316static int write_acpi_int(acpi_handle handle, const char *method, int val,
317 struct acpi_buffer *output)
318{
319 struct acpi_object_list params; //list of input parameters (an int here)
320 union acpi_object in_obj; //the only param we use
321 acpi_status status;
322
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100323 if (!handle)
324 return 0;
325
Corentin Chary85091b72007-01-26 14:04:30 +0100326 params.count = 1;
327 params.pointer = &in_obj;
328 in_obj.type = ACPI_TYPE_INTEGER;
329 in_obj.integer.value = val;
330
331 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100332 if (status == AE_OK)
333 return 0;
334 else
335 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100336}
337
Len Brown8def05f2007-01-30 01:46:43 -0500338static int read_wireless_status(int mask)
339{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400340 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100341 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100342
343 if (!wireless_status_handle)
344 return (hotk->status & mask) ? 1 : 0;
345
Corentin Chary9a816852007-03-11 10:25:38 +0100346 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
347 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200348 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100349 else
350 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100351
352 return (hotk->status & mask) ? 1 : 0;
353}
354
Corentin Charyf3985322007-05-06 14:48:22 +0200355static int read_gps_status(void)
356{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400357 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200358 acpi_status rv = AE_OK;
359
360 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
361 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200362 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200363 else
Corentin Charyf3985322007-05-06 14:48:22 +0200364 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200365
Corentin Charyf3985322007-05-06 14:48:22 +0200366 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200367}
368
Corentin Charybe18cda2007-01-26 14:04:35 +0100369/* Generic LED functions */
370static int read_status(int mask)
371{
Corentin Chary4564de12007-01-26 14:04:40 +0100372 /* There is a special method for both wireless devices */
373 if (mask == BT_ON || mask == WL_ON)
374 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200375 else if (mask == GPS_ON)
376 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100377
Corentin Charybe18cda2007-01-26 14:04:35 +0100378 return (hotk->status & mask) ? 1 : 0;
379}
380
Corentin Chary935ffee2007-03-11 10:26:12 +0100381static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100382{
383 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
384
Corentin Chary935ffee2007-03-11 10:26:12 +0100385 switch (mask) {
386 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100387 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100388 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100389 case GLED_ON:
390 out = (out & 0x1) + 1;
391 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200392 case GPS_ON:
393 handle = (out) ? gps_on_handle : gps_off_handle;
394 out = 0x02;
395 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100396 default:
397 out &= 0x1;
398 break;
399 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100400
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100401 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200402 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100403}
404
405/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100406#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100407 static void object##_led_set(struct led_classdev *led_cdev, \
408 enum led_brightness value) \
409 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200410 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100411 queue_work(led_workqueue, &object##_led_work); \
412 } \
413 static void object##_led_update(struct work_struct *ignored) \
414 { \
415 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100416 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000417 } \
418 static enum led_brightness object##_led_get( \
419 struct led_classdev *led_cdev) \
420 { \
421 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100422 }
423
Corentin Chary935ffee2007-03-11 10:26:12 +0100424ASUS_LED_HANDLER(mled, MLED_ON);
425ASUS_LED_HANDLER(pled, PLED_ON);
426ASUS_LED_HANDLER(rled, RLED_ON);
427ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100428ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100429
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000430/*
431 * Keyboard backlight
432 */
433static int get_kled_lvl(void)
434{
435 unsigned long long kblv;
436 struct acpi_object_list params;
437 union acpi_object in_obj;
438 acpi_status rv;
439
440 params.count = 1;
441 params.pointer = &in_obj;
442 in_obj.type = ACPI_TYPE_INTEGER;
443 in_obj.integer.value = 2;
444
445 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
446 if (ACPI_FAILURE(rv)) {
447 pr_warning("Error reading kled level\n");
448 return 0;
449 }
450 return kblv;
451}
452
453static int set_kled_lvl(int kblv)
454{
455 if (kblv > 0)
456 kblv = (1 << 7) | (kblv & 0x7F);
457 else
458 kblv = 0;
459
460 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
461 pr_warning("Keyboard LED display write failed\n");
462 return -EINVAL;
463 }
464 return 0;
465}
466
467static void kled_led_set(struct led_classdev *led_cdev,
468 enum led_brightness value)
469{
470 kled_led_wk = value;
471 queue_work(led_workqueue, &kled_led_work);
472}
473
474static void kled_led_update(struct work_struct *ignored)
475{
476 set_kled_lvl(kled_led_wk);
477}
478
479static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
480{
481 return get_kled_lvl();
482}
483
Corentin Chary6b7091e2007-01-26 14:04:45 +0100484static int get_lcd_state(void)
485{
486 return read_status(LCD_ON);
487}
488
489static int set_lcd_state(int value)
490{
491 int lcd = 0;
492 acpi_status status = 0;
493
494 lcd = value ? 1 : 0;
495
496 if (lcd == get_lcd_state())
497 return 0;
498
Len Brown8def05f2007-01-30 01:46:43 -0500499 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100500 status = acpi_evaluate_object(lcd_switch_handle,
501 NULL, NULL, NULL);
502
503 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200504 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100505 }
506
Corentin Chary935ffee2007-03-11 10:26:12 +0100507 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100508 return 0;
509}
510
511static void lcd_blank(int blank)
512{
513 struct backlight_device *bd = asus_backlight_device;
514
Len Brown8def05f2007-01-30 01:46:43 -0500515 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000516 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000517 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100518 }
519}
520
521static int read_brightness(struct backlight_device *bd)
522{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400523 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100524 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100525
Corentin Chary9a816852007-03-11 10:25:38 +0100526 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
527 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200528 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100529
530 return value;
531}
532
533static int set_brightness(struct backlight_device *bd, int value)
534{
535 int ret = 0;
536
537 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
538 /* 0 <= value <= 15 */
539
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100540 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200541 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100542 ret = -EIO;
543 }
544
545 return ret;
546}
547
548static int update_bl_status(struct backlight_device *bd)
549{
550 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000551 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100552
553 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500554 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100555 return rv;
556
Richard Purdie599a52d2007-02-10 23:07:48 +0000557 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100558 return set_lcd_state(value);
559}
560
Corentin Chary85091b72007-01-26 14:04:30 +0100561/*
562 * Platform device handlers
563 */
564
565/*
566 * We write our info in page, we begin at offset off and cannot write more
567 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
568 * number of bytes written in page
569 */
570static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500571 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100572{
573 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400574 unsigned long long temp;
Corentin Chary85091b72007-01-26 14:04:30 +0100575 char buf[16]; //enough for all info
Corentin Chary9a816852007-03-11 10:25:38 +0100576 acpi_status rv = AE_OK;
577
Corentin Chary85091b72007-01-26 14:04:30 +0100578 /*
579 * We use the easy way, we don't care of off and count, so we don't set eof
580 * to 1
581 */
582
583 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
584 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
585 /*
586 * The SFUN method probably allows the original driver to get the list
587 * of features supported by a given model. For now, 0x0100 or 0x0800
588 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
589 * The significance of others is yet to be found.
590 */
Corentin Chary9a816852007-03-11 10:25:38 +0100591 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
592 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000593 len += sprintf(page + len, "SFUN value : %#x\n",
594 (uint) temp);
595 /*
596 * The HWRS method return informations about the hardware.
597 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
598 * The significance of others is yet to be found.
599 * If we don't find the method, we assume the device are present.
600 */
601 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
602 if (!ACPI_FAILURE(rv))
603 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100604 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100605 /*
606 * Another value for userspace: the ASYM method returns 0x02 for
607 * battery low and 0x04 for battery critical, its readings tend to be
608 * more accurate than those provided by _BST.
609 * Note: since not all the laptops provide this method, errors are
610 * silently ignored.
611 */
Corentin Chary9a816852007-03-11 10:25:38 +0100612 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
613 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000614 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100615 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100616 if (asus_info) {
617 snprintf(buf, 16, "%d", asus_info->length);
618 len += sprintf(page + len, "DSDT length : %s\n", buf);
619 snprintf(buf, 16, "%d", asus_info->checksum);
620 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
621 snprintf(buf, 16, "%d", asus_info->revision);
622 len += sprintf(page + len, "DSDT revision : %s\n", buf);
623 snprintf(buf, 7, "%s", asus_info->oem_id);
624 len += sprintf(page + len, "OEM id : %s\n", buf);
625 snprintf(buf, 9, "%s", asus_info->oem_table_id);
626 len += sprintf(page + len, "OEM table id : %s\n", buf);
627 snprintf(buf, 16, "%x", asus_info->oem_revision);
628 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
629 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
630 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
631 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
632 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
633 }
634
635 return len;
636}
637
638static int parse_arg(const char *buf, unsigned long count, int *val)
639{
640 if (!count)
641 return 0;
642 if (count > 31)
643 return -EINVAL;
644 if (sscanf(buf, "%i", val) != 1)
645 return -EINVAL;
646 return count;
647}
648
Corentin Chary4564de12007-01-26 14:04:40 +0100649static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100650 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100651{
652 int rv, value;
653 int out = 0;
654
655 rv = parse_arg(buf, count, &value);
656 if (rv > 0)
657 out = value ? 1 : 0;
658
Corentin Chary935ffee2007-03-11 10:26:12 +0100659 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100660
661 return rv;
662}
663
664/*
Corentin Chary722ad972007-01-26 14:04:55 +0100665 * LEDD display
666 */
667static ssize_t show_ledd(struct device *dev,
668 struct device_attribute *attr, char *buf)
669{
670 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
671}
672
673static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
674 const char *buf, size_t count)
675{
676 int rv, value;
677
678 rv = parse_arg(buf, count, &value);
679 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100680 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200681 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100682 else
683 hotk->ledd_status = (u32) value;
684 }
685 return rv;
686}
687
688/*
Corentin Chary4564de12007-01-26 14:04:40 +0100689 * WLAN
690 */
691static ssize_t show_wlan(struct device *dev,
692 struct device_attribute *attr, char *buf)
693{
694 return sprintf(buf, "%d\n", read_status(WL_ON));
695}
696
697static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
698 const char *buf, size_t count)
699{
Corentin Chary935ffee2007-03-11 10:26:12 +0100700 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100701}
702
703/*
704 * Bluetooth
705 */
706static ssize_t show_bluetooth(struct device *dev,
707 struct device_attribute *attr, char *buf)
708{
709 return sprintf(buf, "%d\n", read_status(BT_ON));
710}
711
Len Brown8def05f2007-01-30 01:46:43 -0500712static ssize_t store_bluetooth(struct device *dev,
713 struct device_attribute *attr, const char *buf,
714 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100715{
Corentin Chary935ffee2007-03-11 10:26:12 +0100716 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100717}
718
Corentin Chary78127b42007-01-26 14:04:49 +0100719/*
720 * Display
721 */
722static void set_display(int value)
723{
724 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100725 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200726 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100727 return;
728}
729
730static int read_display(void)
731{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400732 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100733 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100734
735 /* In most of the case, we know how to set the display, but sometime
736 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500737 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100738 rv = acpi_evaluate_integer(display_get_handle, NULL,
739 NULL, &value);
740 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200741 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100742 }
743
744 value &= 0x0F; /* needed for some models, shouldn't hurt others */
745
746 return value;
747}
Len Brown8def05f2007-01-30 01:46:43 -0500748
Corentin Chary78127b42007-01-26 14:04:49 +0100749/*
750 * Now, *this* one could be more user-friendly, but so far, no-one has
751 * complained. The significance of bits is the same as in store_disp()
752 */
753static ssize_t show_disp(struct device *dev,
754 struct device_attribute *attr, char *buf)
755{
756 return sprintf(buf, "%d\n", read_display());
757}
758
759/*
760 * Experimental support for display switching. As of now: 1 should activate
761 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
762 * Any combination (bitwise) of these will suffice. I never actually tested 4
763 * displays hooked up simultaneously, so be warned. See the acpi4asus README
764 * for more info.
765 */
766static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
767 const char *buf, size_t count)
768{
769 int rv, value;
770
771 rv = parse_arg(buf, count, &value);
772 if (rv > 0)
773 set_display(value);
774 return rv;
775}
776
Corentin Chary8b857352007-01-26 14:04:58 +0100777/*
778 * Light Sens
779 */
780static void set_light_sens_switch(int value)
781{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100782 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200783 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100784 hotk->light_switch = value;
785}
786
787static ssize_t show_lssw(struct device *dev,
788 struct device_attribute *attr, char *buf)
789{
790 return sprintf(buf, "%d\n", hotk->light_switch);
791}
792
793static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
794 const char *buf, size_t count)
795{
796 int rv, value;
797
798 rv = parse_arg(buf, count, &value);
799 if (rv > 0)
800 set_light_sens_switch(value ? 1 : 0);
801
802 return rv;
803}
804
805static void set_light_sens_level(int value)
806{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100807 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200808 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100809 hotk->light_level = value;
810}
811
812static ssize_t show_lslvl(struct device *dev,
813 struct device_attribute *attr, char *buf)
814{
815 return sprintf(buf, "%d\n", hotk->light_level);
816}
817
818static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
819 const char *buf, size_t count)
820{
821 int rv, value;
822
823 rv = parse_arg(buf, count, &value);
824 if (rv > 0) {
825 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
826 /* 0 <= value <= 15 */
827 set_light_sens_level(value);
828 }
829
830 return rv;
831}
832
Corentin Charye539c2f2007-05-06 14:47:06 +0200833/*
834 * GPS
835 */
836static ssize_t show_gps(struct device *dev,
837 struct device_attribute *attr, char *buf)
838{
839 return sprintf(buf, "%d\n", read_status(GPS_ON));
840}
841
842static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
843 const char *buf, size_t count)
844{
Corentin Charyf3985322007-05-06 14:48:22 +0200845 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200846}
847
Corentin Chary034ce902009-01-20 16:17:43 +0100848/*
849 * Hotkey functions
850 */
851static struct key_entry *asus_get_entry_by_scancode(int code)
852{
853 struct key_entry *key;
854
855 for (key = asus_keymap; key->type != KE_END; key++)
856 if (code == key->code)
857 return key;
858
859 return NULL;
860}
861
862static struct key_entry *asus_get_entry_by_keycode(int code)
863{
864 struct key_entry *key;
865
866 for (key = asus_keymap; key->type != KE_END; key++)
867 if (code == key->keycode && key->type == KE_KEY)
868 return key;
869
870 return NULL;
871}
872
873static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
874{
875 struct key_entry *key = asus_get_entry_by_scancode(scancode);
876
877 if (key && key->type == KE_KEY) {
878 *keycode = key->keycode;
879 return 0;
880 }
881
882 return -EINVAL;
883}
884
885static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
886{
887 struct key_entry *key;
888 int old_keycode;
889
890 if (keycode < 0 || keycode > KEY_MAX)
891 return -EINVAL;
892
893 key = asus_get_entry_by_scancode(scancode);
894 if (key && key->type == KE_KEY) {
895 old_keycode = key->keycode;
896 key->keycode = keycode;
897 set_bit(keycode, dev->keybit);
898 if (!asus_get_entry_by_keycode(old_keycode))
899 clear_bit(old_keycode, dev->keybit);
900 return 0;
901 }
902
903 return -EINVAL;
904}
905
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600906static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100907{
Corentin Chary034ce902009-01-20 16:17:43 +0100908 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100909 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100910
Corentin Chary85091b72007-01-26 14:04:30 +0100911 /* TODO Find a better way to handle events count. */
912 if (!hotk)
913 return;
914
Corentin Chary6b7091e2007-01-26 14:04:45 +0100915 /*
916 * We need to tell the backlight device when the backlight power is
917 * switched
918 */
919 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100920 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100921 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500922 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100923 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100924 lcd_blank(FB_BLANK_POWERDOWN);
925 }
926
Corentin Chary6050c8d2009-02-15 19:30:19 +0100927 count = hotk->event_count[event % 128]++;
928 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100929 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
930 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100931 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100932
Corentin Chary034ce902009-01-20 16:17:43 +0100933 if (hotk->inputdev) {
934 key = asus_get_entry_by_scancode(event);
935 if (!key)
936 return ;
937
938 switch (key->type) {
939 case KE_KEY:
940 input_report_key(hotk->inputdev, key->keycode, 1);
941 input_sync(hotk->inputdev);
942 input_report_key(hotk->inputdev, key->keycode, 0);
943 input_sync(hotk->inputdev);
944 break;
945 }
946 }
Corentin Chary85091b72007-01-26 14:04:30 +0100947}
948
949#define ASUS_CREATE_DEVICE_ATTR(_name) \
950 struct device_attribute dev_attr_##_name = { \
951 .attr = { \
952 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900953 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100954 .show = NULL, \
955 .store = NULL, \
956 }
957
958#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
959 do { \
960 dev_attr_##_name.attr.mode = _mode; \
961 dev_attr_##_name.show = _show; \
962 dev_attr_##_name.store = _store; \
963 } while(0)
964
965static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100966static ASUS_CREATE_DEVICE_ATTR(wlan);
967static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100968static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100969static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100970static ASUS_CREATE_DEVICE_ATTR(ls_switch);
971static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200972static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100973
974static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500975 &dev_attr_infos.attr,
976 &dev_attr_wlan.attr,
977 &dev_attr_bluetooth.attr,
978 &dev_attr_display.attr,
979 &dev_attr_ledd.attr,
980 &dev_attr_ls_switch.attr,
981 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +0200982 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -0500983 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100984};
985
986static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500987 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100988};
989
990static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500991 .driver = {
992 .name = ASUS_HOTK_FILE,
993 .owner = THIS_MODULE,
994 }
Corentin Chary85091b72007-01-26 14:04:30 +0100995};
996
997static struct platform_device *asuspf_device;
998
Corentin Chary85091b72007-01-26 14:04:30 +0100999static void asus_hotk_add_fs(void)
1000{
1001 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +01001002
1003 if (wl_switch_handle)
1004 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1005
1006 if (bt_switch_handle)
1007 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1008 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001009
1010 if (display_set_handle && display_get_handle)
1011 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -05001012 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +01001013 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1014
Corentin Chary722ad972007-01-26 14:04:55 +01001015 if (ledd_set_handle)
1016 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1017
Corentin Chary8b857352007-01-26 14:04:58 +01001018 if (ls_switch_handle && ls_level_handle) {
1019 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1020 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1021 }
Corentin Charye539c2f2007-05-06 14:47:06 +02001022
Corentin Charyf3985322007-05-06 14:48:22 +02001023 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +02001024 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001025}
1026
Len Brown8def05f2007-01-30 01:46:43 -05001027static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001028 char **paths, int num_paths)
1029{
1030 int i;
1031 acpi_status status;
1032
1033 for (i = 0; i < num_paths; i++) {
1034 status = acpi_get_handle(NULL, paths[i], handle);
1035 if (ACPI_SUCCESS(status))
1036 return 0;
1037 }
1038
1039 *handle = NULL;
1040 return -ENODEV;
1041}
1042
1043#define ASUS_HANDLE_INIT(object) \
1044 asus_handle_init(#object, &object##_handle, object##_paths, \
1045 ARRAY_SIZE(object##_paths))
1046
Corentin Chary85091b72007-01-26 14:04:30 +01001047/*
1048 * This function is used to initialize the hotk with right values. In this
1049 * method, we can make all the detection we want, and modify the hotk struct
1050 */
1051static int asus_hotk_get_info(void)
1052{
1053 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001054 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001055 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001056 char *string = NULL;
1057 acpi_status status;
1058
1059 /*
1060 * Get DSDT headers early enough to allow for differentiating between
1061 * models, but late enough to allow acpi_bus_register_driver() to fail
1062 * before doing anything ACPI-specific. Should we encounter a machine,
1063 * which needs special handling (i.e. its hotkey device has a different
1064 * HID), this bit will be moved. A global variable asus_info contains
1065 * the DSDT header.
1066 */
Len Brown894d79b2007-02-03 02:13:53 -05001067 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001068 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001069 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001070
1071 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +01001072 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001073 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001074 return -ENODEV;
1075 }
1076
1077 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001078 status =
1079 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1080 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001081 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001082 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001083 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001084 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001085
Corentin Chary185e5af2007-03-11 10:27:33 +01001086 /* This too ... */
1087 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1088
Corentin Chary85091b72007-01-26 14:04:30 +01001089 /*
1090 * Try to match the object returned by INIT to the specific model.
1091 * Handle every possible object (or the lack of thereof) the DSDT
1092 * writers might throw at us. When in trouble, we pass NULL to
1093 * asus_model_match() and try something completely different.
1094 */
1095 if (buffer.pointer) {
1096 model = buffer.pointer;
1097 switch (model->type) {
1098 case ACPI_TYPE_STRING:
1099 string = model->string.pointer;
1100 break;
1101 case ACPI_TYPE_BUFFER:
1102 string = model->buffer.pointer;
1103 break;
1104 default:
1105 string = "";
1106 break;
1107 }
1108 }
1109 hotk->name = kstrdup(string, GFP_KERNEL);
1110 if (!hotk->name)
1111 return -ENOMEM;
1112
Len Brown8def05f2007-01-30 01:46:43 -05001113 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001114 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001115
Corentin Charybe18cda2007-01-26 14:04:35 +01001116 ASUS_HANDLE_INIT(mled_set);
1117 ASUS_HANDLE_INIT(tled_set);
1118 ASUS_HANDLE_INIT(rled_set);
1119 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001120 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001121
Corentin Chary722ad972007-01-26 14:04:55 +01001122 ASUS_HANDLE_INIT(ledd_set);
1123
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001124 ASUS_HANDLE_INIT(kled_set);
1125 ASUS_HANDLE_INIT(kled_get);
1126
Corentin Chary4564de12007-01-26 14:04:40 +01001127 /*
1128 * The HWRS method return informations about the hardware.
1129 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1130 * The significance of others is yet to be found.
1131 * If we don't find the method, we assume the device are present.
1132 */
Corentin Chary9a816852007-03-11 10:25:38 +01001133 status =
1134 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1135 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001136 hwrs_result = WL_HWRS | BT_HWRS;
1137
Len Brown8def05f2007-01-30 01:46:43 -05001138 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001139 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001140 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001141 ASUS_HANDLE_INIT(bt_switch);
1142
1143 ASUS_HANDLE_INIT(wireless_status);
1144
Corentin Chary6b7091e2007-01-26 14:04:45 +01001145 ASUS_HANDLE_INIT(brightness_set);
1146 ASUS_HANDLE_INIT(brightness_get);
1147
1148 ASUS_HANDLE_INIT(lcd_switch);
1149
Corentin Chary78127b42007-01-26 14:04:49 +01001150 ASUS_HANDLE_INIT(display_set);
1151 ASUS_HANDLE_INIT(display_get);
1152
Corentin Chary8b857352007-01-26 14:04:58 +01001153 /* There is a lot of models with "ALSL", but a few get
1154 a real light sens, so we need to check it. */
Corentin Chary832d9952007-05-06 14:47:29 +02001155 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001156 ASUS_HANDLE_INIT(ls_level);
1157
Corentin Charye539c2f2007-05-06 14:47:06 +02001158 ASUS_HANDLE_INIT(gps_on);
1159 ASUS_HANDLE_INIT(gps_off);
1160 ASUS_HANDLE_INIT(gps_status);
1161
Corentin Chary85091b72007-01-26 14:04:30 +01001162 kfree(model);
1163
1164 return AE_OK;
1165}
1166
Corentin Chary034ce902009-01-20 16:17:43 +01001167static int asus_input_init(void)
1168{
1169 const struct key_entry *key;
1170 int result;
1171
1172 hotk->inputdev = input_allocate_device();
1173 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001174 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001175 return 0;
1176 }
1177 hotk->inputdev->name = "Asus Laptop extra buttons";
1178 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1179 hotk->inputdev->id.bustype = BUS_HOST;
1180 hotk->inputdev->getkeycode = asus_getkeycode;
1181 hotk->inputdev->setkeycode = asus_setkeycode;
1182
1183 for (key = asus_keymap; key->type != KE_END; key++) {
1184 switch (key->type) {
1185 case KE_KEY:
1186 set_bit(EV_KEY, hotk->inputdev->evbit);
1187 set_bit(key->keycode, hotk->inputdev->keybit);
1188 break;
1189 }
1190 }
1191 result = input_register_device(hotk->inputdev);
1192 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001193 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001194 input_free_device(hotk->inputdev);
1195 }
1196 return result;
1197}
1198
Corentin Chary85091b72007-01-26 14:04:30 +01001199static int asus_hotk_check(void)
1200{
1201 int result = 0;
1202
1203 result = acpi_bus_get_status(hotk->device);
1204 if (result)
1205 return result;
1206
1207 if (hotk->device->status.present) {
1208 result = asus_hotk_get_info();
1209 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001210 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001211 return -EINVAL;
1212 }
1213
1214 return result;
1215}
1216
1217static int asus_hotk_found;
1218
1219static int asus_hotk_add(struct acpi_device *device)
1220{
Corentin Chary85091b72007-01-26 14:04:30 +01001221 int result;
1222
1223 if (!device)
1224 return -EINVAL;
1225
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001226 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001227 ASUS_LAPTOP_VERSION);
1228
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001229 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001230 if (!hotk)
1231 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001232
1233 hotk->handle = device->handle;
1234 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1235 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001236 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001237 hotk->device = device;
1238
1239 result = asus_hotk_check();
1240 if (result)
1241 goto end;
1242
1243 asus_hotk_add_fs();
1244
Corentin Chary85091b72007-01-26 14:04:30 +01001245 asus_hotk_found = 1;
1246
Corentin Chary6b7091e2007-01-26 14:04:45 +01001247 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001248 write_status(bt_switch_handle, 1, BT_ON);
1249 write_status(wl_switch_handle, 1, WL_ON);
1250
1251 /* If the h/w switch is off, we need to check the real status */
1252 write_status(NULL, read_status(BT_ON), BT_ON);
1253 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001254
Corentin Chary6b7091e2007-01-26 14:04:45 +01001255 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001256 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001257
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001258 /* Keyboard Backlight is on by default */
1259 if (kled_set_handle)
1260 set_kled_lvl(1);
1261
Corentin Chary722ad972007-01-26 14:04:55 +01001262 /* LED display is off by default */
1263 hotk->ledd_status = 0xFFF;
1264
Len Brown8def05f2007-01-30 01:46:43 -05001265 /* Set initial values of light sensor and level */
1266 hotk->light_switch = 1; /* Default to light sensor disabled */
1267 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001268
Len Brown8def05f2007-01-30 01:46:43 -05001269 if (ls_switch_handle)
1270 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001271
Len Brown8def05f2007-01-30 01:46:43 -05001272 if (ls_level_handle)
1273 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001274
Corentin Charye539c2f2007-05-06 14:47:06 +02001275 /* GPS is on by default */
1276 write_status(NULL, 1, GPS_ON);
1277
Corentin Charyed6f4422009-01-20 16:17:45 +01001278end:
Corentin Chary85091b72007-01-26 14:04:30 +01001279 if (result) {
1280 kfree(hotk->name);
1281 kfree(hotk);
1282 }
1283
1284 return result;
1285}
1286
1287static int asus_hotk_remove(struct acpi_device *device, int type)
1288{
Corentin Chary85091b72007-01-26 14:04:30 +01001289 if (!device || !acpi_driver_data(device))
1290 return -EINVAL;
1291
Corentin Chary85091b72007-01-26 14:04:30 +01001292 kfree(hotk->name);
1293 kfree(hotk);
1294
1295 return 0;
1296}
1297
Corentin Chary6b7091e2007-01-26 14:04:45 +01001298static void asus_backlight_exit(void)
1299{
Len Brown8def05f2007-01-30 01:46:43 -05001300 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001301 backlight_device_unregister(asus_backlight_device);
1302}
1303
Corentin Charybe18cda2007-01-26 14:04:35 +01001304#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a62007-08-16 18:18:53 +02001305 if (object##_led.dev) \
1306 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001307
1308static void asus_led_exit(void)
1309{
Al Viro3b0d7112007-07-23 11:21:34 +01001310 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001311 ASUS_LED_UNREGISTER(mled);
1312 ASUS_LED_UNREGISTER(tled);
1313 ASUS_LED_UNREGISTER(pled);
1314 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001315 ASUS_LED_UNREGISTER(gled);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001316 ASUS_LED_UNREGISTER(kled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001317}
1318
Corentin Chary034ce902009-01-20 16:17:43 +01001319static void asus_input_exit(void)
1320{
1321 if (hotk->inputdev)
1322 input_unregister_device(hotk->inputdev);
1323}
1324
Corentin Chary85091b72007-01-26 14:04:30 +01001325static void __exit asus_laptop_exit(void)
1326{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001327 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001328 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001329 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001330
Corentin Chary85091b72007-01-26 14:04:30 +01001331 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001332 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1333 platform_device_unregister(asuspf_device);
1334 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001335}
1336
Len Brown8def05f2007-01-30 01:46:43 -05001337static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001338{
1339 struct backlight_device *bd;
1340
Len Brown8def05f2007-01-30 01:46:43 -05001341 if (brightness_set_handle && lcd_switch_handle) {
1342 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001343 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001344 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001345 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001346 asus_backlight_device = NULL;
1347 return PTR_ERR(bd);
1348 }
1349
1350 asus_backlight_device = bd;
1351
Richard Purdie599a52d2007-02-10 23:07:48 +00001352 bd->props.max_brightness = 15;
1353 bd->props.brightness = read_brightness(NULL);
1354 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001355 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001356 }
1357 return 0;
1358}
1359
Corentin Charybe18cda2007-01-26 14:04:35 +01001360static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001361 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001362{
Len Brown8def05f2007-01-30 01:46:43 -05001363 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001364 return 0;
1365
1366 return led_classdev_register(dev, ldev);
1367}
Len Brown8def05f2007-01-30 01:46:43 -05001368
Corentin Charybe18cda2007-01-26 14:04:35 +01001369#define ASUS_LED_REGISTER(object, device) \
1370 asus_led_register(object##_set_handle, &object##_led, device)
1371
Len Brown8def05f2007-01-30 01:46:43 -05001372static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001373{
1374 int rv;
1375
1376 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001377 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001378 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001379
1380 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001381 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001382 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001383
1384 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001385 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001386 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001387
1388 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001389 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001390 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001391
Corentin Charyfdd8d082007-03-11 10:26:48 +01001392 rv = ASUS_LED_REGISTER(gled, dev);
1393 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001394 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001395
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001396 if (kled_set_handle && kled_get_handle)
1397 rv = ASUS_LED_REGISTER(kled, dev);
1398 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001399 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001400
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001401 led_workqueue = create_singlethread_workqueue("led_workqueue");
1402 if (!led_workqueue)
1403 goto out6;
1404
Corentin Charybe18cda2007-01-26 14:04:35 +01001405 return 0;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001406out6:
Al Viro3b0d7112007-07-23 11:21:34 +01001407 rv = -ENOMEM;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001408 ASUS_LED_UNREGISTER(kled);
1409out5:
Al Viro3b0d7112007-07-23 11:21:34 +01001410 ASUS_LED_UNREGISTER(gled);
1411out4:
1412 ASUS_LED_UNREGISTER(pled);
1413out3:
1414 ASUS_LED_UNREGISTER(rled);
1415out2:
1416 ASUS_LED_UNREGISTER(tled);
1417out1:
1418 ASUS_LED_UNREGISTER(mled);
1419out:
1420 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001421}
1422
Corentin Chary85091b72007-01-26 14:04:30 +01001423static int __init asus_laptop_init(void)
1424{
1425 int result;
1426
1427 if (acpi_disabled)
1428 return -ENODEV;
1429
Corentin Chary85091b72007-01-26 14:04:30 +01001430 result = acpi_bus_register_driver(&asus_hotk_driver);
1431 if (result < 0)
1432 return result;
1433
1434 /*
1435 * This is a bit of a kludge. We only want this module loaded
1436 * for ASUS systems, but there's currently no way to probe the
1437 * ACPI namespace for ASUS HIDs. So we just return failure if
1438 * we didn't find one, which will cause the module to be
1439 * unloaded.
1440 */
1441 if (!asus_hotk_found) {
1442 acpi_bus_unregister_driver(&asus_hotk_driver);
1443 return -ENODEV;
1444 }
1445
Corentin Chary034ce902009-01-20 16:17:43 +01001446 result = asus_input_init();
1447 if (result)
1448 goto fail_input;
1449
Len Brown8def05f2007-01-30 01:46:43 -05001450 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001451 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001452 if (result)
1453 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001454
Len Brown8def05f2007-01-30 01:46:43 -05001455 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1456 if (!asuspf_device) {
1457 result = -ENOMEM;
1458 goto fail_platform_device1;
1459 }
Corentin Chary85091b72007-01-26 14:04:30 +01001460
Len Brown8def05f2007-01-30 01:46:43 -05001461 result = platform_device_add(asuspf_device);
1462 if (result)
1463 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001464
Len Brown8def05f2007-01-30 01:46:43 -05001465 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001466 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001467 if (result)
1468 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001469
Corentin Chary116bf2e2009-06-16 19:28:46 +00001470 result = asus_led_init(&asuspf_device->dev);
1471 if (result)
1472 goto fail_led;
1473
1474 if (!acpi_video_backlight_support()) {
1475 result = asus_backlight_init(&asuspf_device->dev);
1476 if (result)
1477 goto fail_backlight;
1478 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001479 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001480 "ACPI video driver\n");
1481
Len Brown8def05f2007-01-30 01:46:43 -05001482 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001483
Corentin Chary116bf2e2009-06-16 19:28:46 +00001484fail_backlight:
1485 asus_led_exit();
1486
1487fail_led:
1488 sysfs_remove_group(&asuspf_device->dev.kobj,
1489 &asuspf_attribute_group);
1490
Corentin Charyed6f4422009-01-20 16:17:45 +01001491fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001492 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001493
Corentin Charyed6f4422009-01-20 16:17:45 +01001494fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001495 platform_device_put(asuspf_device);
1496
Corentin Charyed6f4422009-01-20 16:17:45 +01001497fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001498 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001499
Corentin Charyed6f4422009-01-20 16:17:45 +01001500fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001501 asus_input_exit();
1502
Corentin Charyed6f4422009-01-20 16:17:45 +01001503fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001504
1505 return result;
1506}
1507
1508module_init(asus_laptop_init);
1509module_exit(asus_laptop_exit);