blob: 23449508d86b888eb5f0e12abdd931830edab858 [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 Charybe18cda2007-01-26 14:04:35 +010089
Corentin Chary85091b72007-01-26 14:04:30 +010090#define ASUS_LOG ASUS_HOTK_FILE ": "
91#define ASUS_ERR KERN_ERR ASUS_LOG
92#define ASUS_WARNING KERN_WARNING ASUS_LOG
93#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
94#define ASUS_INFO KERN_INFO ASUS_LOG
95#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
96
97MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
98MODULE_DESCRIPTION(ASUS_HOTK_NAME);
99MODULE_LICENSE("GPL");
100
Corentin Chary185e5af2007-03-11 10:27:33 +0100101/* WAPF defines the behavior of the Fn+Fx wlan key
102 * The significance of values is yet to be found, but
103 * most of the time:
104 * 0x0 will do nothing
105 * 0x1 will allow to control the device with Fn+Fx key.
106 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
107 * 0x5 like 0x1 or 0x4
108 * So, if something doesn't work as you want, just try other values =)
109 */
110static uint wapf = 1;
111module_param(wapf, uint, 0644);
112MODULE_PARM_DESC(wapf, "WAPF value");
113
Corentin Chary85091b72007-01-26 14:04:30 +0100114#define ASUS_HANDLE(object, paths...) \
115 static acpi_handle object##_handle = NULL; \
116 static char *object##_paths[] = { paths }
117
Corentin Charybe18cda2007-01-26 14:04:35 +0100118/* LED */
119ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
120ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500121ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
122ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charyfdd8d082007-03-11 10:26:48 +0100123ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100124
Corentin Chary722ad972007-01-26 14:04:55 +0100125/* LEDD */
126ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
127
Corentin Chary4564de12007-01-26 14:04:40 +0100128/* Bluetooth and WLAN
129 * WLED and BLED are not handled like other XLED, because in some dsdt
130 * they also control the WLAN/Bluetooth device.
131 */
132ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
133ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500134ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100135
Corentin Chary6b7091e2007-01-26 14:04:45 +0100136/* Brightness */
137ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
138ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
139
140/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500141ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
142 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
143 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
144 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
145 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
Torsten Krah4d0b856e2008-10-17 09:47:57 +0200146 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
Len Brown8def05f2007-01-30 01:46:43 -0500147 "\\_SB.PCI0.PX40.Q10", /* S1x */
148 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100149
Corentin Chary78127b42007-01-26 14:04:49 +0100150/* Display */
151ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Len Brown8def05f2007-01-30 01:46:43 -0500152ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G
153 M6A M6V VX-1 V6J V6V W3Z */
154 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
Corentin Charyf3985322007-05-06 14:48:22 +0200155 S5A M5A z33A W1Jc W2V G1 */
Len Brown8def05f2007-01-30 01:46:43 -0500156 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
157 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
158 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */
159 "\\_SB.PCI0.VGA.GETD", /* Z96F */
160 "\\ACTD", /* A2D */
161 "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
162 "\\DNXT", /* P30 */
163 "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
164 "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
Corentin Chary78127b42007-01-26 14:04:49 +0100165
Len Brown8def05f2007-01-30 01:46:43 -0500166ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
167ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100168
Corentin Charye539c2f2007-05-06 14:47:06 +0200169/* GPS */
170/* R2H use different handle for GPS on/off */
Corentin Charyf3985322007-05-06 14:48:22 +0200171ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
172ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
Corentin Charye539c2f2007-05-06 14:47:06 +0200173ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
174
Corentin Chary85091b72007-01-26 14:04:30 +0100175/*
176 * This is the main structure, we can use it to store anything interesting
177 * about the hotk device
178 */
179struct asus_hotk {
Len Brown8def05f2007-01-30 01:46:43 -0500180 char *name; //laptop name
Corentin Chary85091b72007-01-26 14:04:30 +0100181 struct acpi_device *device; //the device we are in
182 acpi_handle handle; //the handle of the hotk device
183 char status; //status of the hotk, for LEDs, ...
Corentin Chary722ad972007-01-26 14:04:55 +0100184 u32 ledd_status; //status of the LED display
Len Brown8def05f2007-01-30 01:46:43 -0500185 u8 light_level; //light sensor level
186 u8 light_switch; //light sensor switch value
Corentin Chary85091b72007-01-26 14:04:30 +0100187 u16 event_count[128]; //count for each event TODO make this better
Corentin Chary034ce902009-01-20 16:17:43 +0100188 struct input_dev *inputdev;
189 u16 *keycode_map;
Corentin Chary85091b72007-01-26 14:04:30 +0100190};
191
192/*
193 * This header is made available to allow proper configuration given model,
194 * revision number , ... this info cannot go in struct asus_hotk because it is
195 * available before the hotk
196 */
197static struct acpi_table_header *asus_info;
198
199/* The actual device the driver binds to */
200static struct asus_hotk *hotk;
201
202/*
203 * The hotkey driver declaration
204 */
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200205static const struct acpi_device_id asus_device_ids[] = {
206 {"ATK0100", 0},
207 {"", 0},
208};
209MODULE_DEVICE_TABLE(acpi, asus_device_ids);
210
Corentin Chary85091b72007-01-26 14:04:30 +0100211static int asus_hotk_add(struct acpi_device *device);
212static int asus_hotk_remove(struct acpi_device *device, int type);
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600213static void asus_hotk_notify(struct acpi_device *device, u32 event);
214
Corentin Chary85091b72007-01-26 14:04:30 +0100215static struct acpi_driver asus_hotk_driver = {
216 .name = ASUS_HOTK_NAME,
217 .class = ASUS_HOTK_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200218 .ids = asus_device_ids,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600219 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Corentin Chary85091b72007-01-26 14:04:30 +0100220 .ops = {
221 .add = asus_hotk_add,
222 .remove = asus_hotk_remove,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600223 .notify = asus_hotk_notify,
Corentin Chary85091b72007-01-26 14:04:30 +0100224 },
225};
226
Corentin Chary6b7091e2007-01-26 14:04:45 +0100227/* The backlight device /sys/class/backlight */
228static struct backlight_device *asus_backlight_device;
229
230/*
231 * The backlight class declaration
232 */
233static int read_brightness(struct backlight_device *bd);
234static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000235static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500236 .get_brightness = read_brightness,
237 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100238};
239
Corentin Charybe18cda2007-01-26 14:04:35 +0100240/* These functions actually update the LED's, and are called from a
241 * workqueue. By doing this as separate work rather than when the LED
242 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
243 * potentially bad time, such as a timer interrupt. */
244static struct workqueue_struct *led_workqueue;
245
246#define ASUS_LED(object, ledname) \
247 static void object##_led_set(struct led_classdev *led_cdev, \
248 enum led_brightness value); \
249 static void object##_led_update(struct work_struct *ignored); \
250 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100251 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100252 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100253 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100254 .brightness_set = object##_led_set, \
255 }
256
257ASUS_LED(mled, "mail");
258ASUS_LED(tled, "touchpad");
259ASUS_LED(rled, "record");
260ASUS_LED(pled, "phone");
Corentin Charyfdd8d082007-03-11 10:26:48 +0100261ASUS_LED(gled, "gaming");
Corentin Charybe18cda2007-01-26 14:04:35 +0100262
Corentin Chary034ce902009-01-20 16:17:43 +0100263struct key_entry {
264 char type;
265 u8 code;
266 u16 keycode;
267};
268
269enum { KE_KEY, KE_END };
270
271static struct key_entry asus_keymap[] = {
272 {KE_KEY, 0x30, KEY_VOLUMEUP},
273 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
274 {KE_KEY, 0x32, KEY_MUTE},
275 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
276 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
277 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
278 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200279 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100280 {KE_KEY, 0x45, KEY_PLAYPAUSE},
281 {KE_KEY, 0x50, KEY_EMAIL},
282 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200283 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100284 {KE_KEY, 0x5D, KEY_WLAN},
285 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
286 {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
287 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200288 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100289 {KE_KEY, 0x95, KEY_MEDIA},
290 {KE_KEY, 0x99, KEY_PHONE},
291 {KE_END, 0},
292};
293
Corentin Chary85091b72007-01-26 14:04:30 +0100294/*
295 * This function evaluates an ACPI method, given an int as parameter, the
296 * method is searched within the scope of the handle, can be NULL. The output
297 * of the method is written is output, which can also be NULL
298 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100299 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100300 */
301static int write_acpi_int(acpi_handle handle, const char *method, int val,
302 struct acpi_buffer *output)
303{
304 struct acpi_object_list params; //list of input parameters (an int here)
305 union acpi_object in_obj; //the only param we use
306 acpi_status status;
307
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100308 if (!handle)
309 return 0;
310
Corentin Chary85091b72007-01-26 14:04:30 +0100311 params.count = 1;
312 params.pointer = &in_obj;
313 in_obj.type = ACPI_TYPE_INTEGER;
314 in_obj.integer.value = val;
315
316 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100317 if (status == AE_OK)
318 return 0;
319 else
320 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100321}
322
Len Brown8def05f2007-01-30 01:46:43 -0500323static int read_wireless_status(int mask)
324{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400325 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100326 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100327
328 if (!wireless_status_handle)
329 return (hotk->status & mask) ? 1 : 0;
330
Corentin Chary9a816852007-03-11 10:25:38 +0100331 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
332 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200333 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100334 else
335 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100336
337 return (hotk->status & mask) ? 1 : 0;
338}
339
Corentin Charyf3985322007-05-06 14:48:22 +0200340static int read_gps_status(void)
341{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400342 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200343 acpi_status rv = AE_OK;
344
345 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
346 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200347 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200348 else
Corentin Charyf3985322007-05-06 14:48:22 +0200349 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200350
Corentin Charyf3985322007-05-06 14:48:22 +0200351 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200352}
353
Corentin Charybe18cda2007-01-26 14:04:35 +0100354/* Generic LED functions */
355static int read_status(int mask)
356{
Corentin Chary4564de12007-01-26 14:04:40 +0100357 /* There is a special method for both wireless devices */
358 if (mask == BT_ON || mask == WL_ON)
359 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200360 else if (mask == GPS_ON)
361 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100362
Corentin Charybe18cda2007-01-26 14:04:35 +0100363 return (hotk->status & mask) ? 1 : 0;
364}
365
Corentin Chary935ffee2007-03-11 10:26:12 +0100366static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100367{
368 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
369
Corentin Chary935ffee2007-03-11 10:26:12 +0100370 switch (mask) {
371 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100372 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100373 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100374 case GLED_ON:
375 out = (out & 0x1) + 1;
376 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200377 case GPS_ON:
378 handle = (out) ? gps_on_handle : gps_off_handle;
379 out = 0x02;
380 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100381 default:
382 out &= 0x1;
383 break;
384 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100385
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100386 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200387 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100388}
389
390/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100391#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100392 static void object##_led_set(struct led_classdev *led_cdev, \
393 enum led_brightness value) \
394 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200395 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100396 queue_work(led_workqueue, &object##_led_work); \
397 } \
398 static void object##_led_update(struct work_struct *ignored) \
399 { \
400 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100401 write_status(object##_set_handle, value, (mask)); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100402 }
403
Corentin Chary935ffee2007-03-11 10:26:12 +0100404ASUS_LED_HANDLER(mled, MLED_ON);
405ASUS_LED_HANDLER(pled, PLED_ON);
406ASUS_LED_HANDLER(rled, RLED_ON);
407ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100408ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100409
Corentin Chary6b7091e2007-01-26 14:04:45 +0100410static int get_lcd_state(void)
411{
412 return read_status(LCD_ON);
413}
414
415static int set_lcd_state(int value)
416{
417 int lcd = 0;
418 acpi_status status = 0;
419
420 lcd = value ? 1 : 0;
421
422 if (lcd == get_lcd_state())
423 return 0;
424
Len Brown8def05f2007-01-30 01:46:43 -0500425 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100426 status = acpi_evaluate_object(lcd_switch_handle,
427 NULL, NULL, NULL);
428
429 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200430 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100431 }
432
Corentin Chary935ffee2007-03-11 10:26:12 +0100433 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100434 return 0;
435}
436
437static void lcd_blank(int blank)
438{
439 struct backlight_device *bd = asus_backlight_device;
440
Len Brown8def05f2007-01-30 01:46:43 -0500441 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000442 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000443 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100444 }
445}
446
447static int read_brightness(struct backlight_device *bd)
448{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400449 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100450 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100451
Corentin Chary9a816852007-03-11 10:25:38 +0100452 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
453 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200454 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100455
456 return value;
457}
458
459static int set_brightness(struct backlight_device *bd, int value)
460{
461 int ret = 0;
462
463 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
464 /* 0 <= value <= 15 */
465
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100466 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200467 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100468 ret = -EIO;
469 }
470
471 return ret;
472}
473
474static int update_bl_status(struct backlight_device *bd)
475{
476 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000477 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100478
479 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500480 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100481 return rv;
482
Richard Purdie599a52d2007-02-10 23:07:48 +0000483 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100484 return set_lcd_state(value);
485}
486
Corentin Chary85091b72007-01-26 14:04:30 +0100487/*
488 * Platform device handlers
489 */
490
491/*
492 * We write our info in page, we begin at offset off and cannot write more
493 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
494 * number of bytes written in page
495 */
496static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500497 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100498{
499 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400500 unsigned long long temp;
Corentin Chary85091b72007-01-26 14:04:30 +0100501 char buf[16]; //enough for all info
Corentin Chary9a816852007-03-11 10:25:38 +0100502 acpi_status rv = AE_OK;
503
Corentin Chary85091b72007-01-26 14:04:30 +0100504 /*
505 * We use the easy way, we don't care of off and count, so we don't set eof
506 * to 1
507 */
508
509 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
510 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
511 /*
512 * The SFUN method probably allows the original driver to get the list
513 * of features supported by a given model. For now, 0x0100 or 0x0800
514 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
515 * The significance of others is yet to be found.
516 */
Corentin Chary9a816852007-03-11 10:25:38 +0100517 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
518 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000519 len += sprintf(page + len, "SFUN value : %#x\n",
520 (uint) temp);
521 /*
522 * The HWRS method return informations about the hardware.
523 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
524 * The significance of others is yet to be found.
525 * If we don't find the method, we assume the device are present.
526 */
527 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
528 if (!ACPI_FAILURE(rv))
529 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100530 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100531 /*
532 * Another value for userspace: the ASYM method returns 0x02 for
533 * battery low and 0x04 for battery critical, its readings tend to be
534 * more accurate than those provided by _BST.
535 * Note: since not all the laptops provide this method, errors are
536 * silently ignored.
537 */
Corentin Chary9a816852007-03-11 10:25:38 +0100538 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
539 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000540 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100541 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100542 if (asus_info) {
543 snprintf(buf, 16, "%d", asus_info->length);
544 len += sprintf(page + len, "DSDT length : %s\n", buf);
545 snprintf(buf, 16, "%d", asus_info->checksum);
546 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
547 snprintf(buf, 16, "%d", asus_info->revision);
548 len += sprintf(page + len, "DSDT revision : %s\n", buf);
549 snprintf(buf, 7, "%s", asus_info->oem_id);
550 len += sprintf(page + len, "OEM id : %s\n", buf);
551 snprintf(buf, 9, "%s", asus_info->oem_table_id);
552 len += sprintf(page + len, "OEM table id : %s\n", buf);
553 snprintf(buf, 16, "%x", asus_info->oem_revision);
554 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
555 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
556 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
557 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
558 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
559 }
560
561 return len;
562}
563
564static int parse_arg(const char *buf, unsigned long count, int *val)
565{
566 if (!count)
567 return 0;
568 if (count > 31)
569 return -EINVAL;
570 if (sscanf(buf, "%i", val) != 1)
571 return -EINVAL;
572 return count;
573}
574
Corentin Chary4564de12007-01-26 14:04:40 +0100575static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100576 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100577{
578 int rv, value;
579 int out = 0;
580
581 rv = parse_arg(buf, count, &value);
582 if (rv > 0)
583 out = value ? 1 : 0;
584
Corentin Chary935ffee2007-03-11 10:26:12 +0100585 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100586
587 return rv;
588}
589
590/*
Corentin Chary722ad972007-01-26 14:04:55 +0100591 * LEDD display
592 */
593static ssize_t show_ledd(struct device *dev,
594 struct device_attribute *attr, char *buf)
595{
596 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
597}
598
599static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
600 const char *buf, size_t count)
601{
602 int rv, value;
603
604 rv = parse_arg(buf, count, &value);
605 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100606 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200607 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100608 else
609 hotk->ledd_status = (u32) value;
610 }
611 return rv;
612}
613
614/*
Corentin Chary4564de12007-01-26 14:04:40 +0100615 * WLAN
616 */
617static ssize_t show_wlan(struct device *dev,
618 struct device_attribute *attr, char *buf)
619{
620 return sprintf(buf, "%d\n", read_status(WL_ON));
621}
622
623static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
624 const char *buf, size_t count)
625{
Corentin Chary935ffee2007-03-11 10:26:12 +0100626 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100627}
628
629/*
630 * Bluetooth
631 */
632static ssize_t show_bluetooth(struct device *dev,
633 struct device_attribute *attr, char *buf)
634{
635 return sprintf(buf, "%d\n", read_status(BT_ON));
636}
637
Len Brown8def05f2007-01-30 01:46:43 -0500638static ssize_t store_bluetooth(struct device *dev,
639 struct device_attribute *attr, const char *buf,
640 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100641{
Corentin Chary935ffee2007-03-11 10:26:12 +0100642 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100643}
644
Corentin Chary78127b42007-01-26 14:04:49 +0100645/*
646 * Display
647 */
648static void set_display(int value)
649{
650 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100651 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200652 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100653 return;
654}
655
656static int read_display(void)
657{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400658 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100659 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100660
661 /* In most of the case, we know how to set the display, but sometime
662 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500663 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100664 rv = acpi_evaluate_integer(display_get_handle, NULL,
665 NULL, &value);
666 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200667 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100668 }
669
670 value &= 0x0F; /* needed for some models, shouldn't hurt others */
671
672 return value;
673}
Len Brown8def05f2007-01-30 01:46:43 -0500674
Corentin Chary78127b42007-01-26 14:04:49 +0100675/*
676 * Now, *this* one could be more user-friendly, but so far, no-one has
677 * complained. The significance of bits is the same as in store_disp()
678 */
679static ssize_t show_disp(struct device *dev,
680 struct device_attribute *attr, char *buf)
681{
682 return sprintf(buf, "%d\n", read_display());
683}
684
685/*
686 * Experimental support for display switching. As of now: 1 should activate
687 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
688 * Any combination (bitwise) of these will suffice. I never actually tested 4
689 * displays hooked up simultaneously, so be warned. See the acpi4asus README
690 * for more info.
691 */
692static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
693 const char *buf, size_t count)
694{
695 int rv, value;
696
697 rv = parse_arg(buf, count, &value);
698 if (rv > 0)
699 set_display(value);
700 return rv;
701}
702
Corentin Chary8b857352007-01-26 14:04:58 +0100703/*
704 * Light Sens
705 */
706static void set_light_sens_switch(int value)
707{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100708 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200709 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100710 hotk->light_switch = value;
711}
712
713static ssize_t show_lssw(struct device *dev,
714 struct device_attribute *attr, char *buf)
715{
716 return sprintf(buf, "%d\n", hotk->light_switch);
717}
718
719static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
720 const char *buf, size_t count)
721{
722 int rv, value;
723
724 rv = parse_arg(buf, count, &value);
725 if (rv > 0)
726 set_light_sens_switch(value ? 1 : 0);
727
728 return rv;
729}
730
731static void set_light_sens_level(int value)
732{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100733 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200734 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100735 hotk->light_level = value;
736}
737
738static ssize_t show_lslvl(struct device *dev,
739 struct device_attribute *attr, char *buf)
740{
741 return sprintf(buf, "%d\n", hotk->light_level);
742}
743
744static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
745 const char *buf, size_t count)
746{
747 int rv, value;
748
749 rv = parse_arg(buf, count, &value);
750 if (rv > 0) {
751 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
752 /* 0 <= value <= 15 */
753 set_light_sens_level(value);
754 }
755
756 return rv;
757}
758
Corentin Charye539c2f2007-05-06 14:47:06 +0200759/*
760 * GPS
761 */
762static ssize_t show_gps(struct device *dev,
763 struct device_attribute *attr, char *buf)
764{
765 return sprintf(buf, "%d\n", read_status(GPS_ON));
766}
767
768static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
769 const char *buf, size_t count)
770{
Corentin Charyf3985322007-05-06 14:48:22 +0200771 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200772}
773
Corentin Chary034ce902009-01-20 16:17:43 +0100774/*
775 * Hotkey functions
776 */
777static struct key_entry *asus_get_entry_by_scancode(int code)
778{
779 struct key_entry *key;
780
781 for (key = asus_keymap; key->type != KE_END; key++)
782 if (code == key->code)
783 return key;
784
785 return NULL;
786}
787
788static struct key_entry *asus_get_entry_by_keycode(int code)
789{
790 struct key_entry *key;
791
792 for (key = asus_keymap; key->type != KE_END; key++)
793 if (code == key->keycode && key->type == KE_KEY)
794 return key;
795
796 return NULL;
797}
798
799static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
800{
801 struct key_entry *key = asus_get_entry_by_scancode(scancode);
802
803 if (key && key->type == KE_KEY) {
804 *keycode = key->keycode;
805 return 0;
806 }
807
808 return -EINVAL;
809}
810
811static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
812{
813 struct key_entry *key;
814 int old_keycode;
815
816 if (keycode < 0 || keycode > KEY_MAX)
817 return -EINVAL;
818
819 key = asus_get_entry_by_scancode(scancode);
820 if (key && key->type == KE_KEY) {
821 old_keycode = key->keycode;
822 key->keycode = keycode;
823 set_bit(keycode, dev->keybit);
824 if (!asus_get_entry_by_keycode(old_keycode))
825 clear_bit(old_keycode, dev->keybit);
826 return 0;
827 }
828
829 return -EINVAL;
830}
831
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600832static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100833{
Corentin Chary034ce902009-01-20 16:17:43 +0100834 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100835 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100836
Corentin Chary85091b72007-01-26 14:04:30 +0100837 /* TODO Find a better way to handle events count. */
838 if (!hotk)
839 return;
840
Corentin Chary6b7091e2007-01-26 14:04:45 +0100841 /*
842 * We need to tell the backlight device when the backlight power is
843 * switched
844 */
845 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100846 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100847 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500848 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100849 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100850 lcd_blank(FB_BLANK_POWERDOWN);
851 }
852
Corentin Chary6050c8d2009-02-15 19:30:19 +0100853 count = hotk->event_count[event % 128]++;
854 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100855 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
856 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100857 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100858
Corentin Chary034ce902009-01-20 16:17:43 +0100859 if (hotk->inputdev) {
860 key = asus_get_entry_by_scancode(event);
861 if (!key)
862 return ;
863
864 switch (key->type) {
865 case KE_KEY:
866 input_report_key(hotk->inputdev, key->keycode, 1);
867 input_sync(hotk->inputdev);
868 input_report_key(hotk->inputdev, key->keycode, 0);
869 input_sync(hotk->inputdev);
870 break;
871 }
872 }
Corentin Chary85091b72007-01-26 14:04:30 +0100873}
874
875#define ASUS_CREATE_DEVICE_ATTR(_name) \
876 struct device_attribute dev_attr_##_name = { \
877 .attr = { \
878 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900879 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100880 .show = NULL, \
881 .store = NULL, \
882 }
883
884#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
885 do { \
886 dev_attr_##_name.attr.mode = _mode; \
887 dev_attr_##_name.show = _show; \
888 dev_attr_##_name.store = _store; \
889 } while(0)
890
891static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100892static ASUS_CREATE_DEVICE_ATTR(wlan);
893static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100894static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100895static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100896static ASUS_CREATE_DEVICE_ATTR(ls_switch);
897static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200898static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100899
900static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500901 &dev_attr_infos.attr,
902 &dev_attr_wlan.attr,
903 &dev_attr_bluetooth.attr,
904 &dev_attr_display.attr,
905 &dev_attr_ledd.attr,
906 &dev_attr_ls_switch.attr,
907 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +0200908 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -0500909 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100910};
911
912static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500913 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100914};
915
916static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500917 .driver = {
918 .name = ASUS_HOTK_FILE,
919 .owner = THIS_MODULE,
920 }
Corentin Chary85091b72007-01-26 14:04:30 +0100921};
922
923static struct platform_device *asuspf_device;
924
Corentin Chary85091b72007-01-26 14:04:30 +0100925static void asus_hotk_add_fs(void)
926{
927 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +0100928
929 if (wl_switch_handle)
930 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
931
932 if (bt_switch_handle)
933 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
934 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100935
936 if (display_set_handle && display_get_handle)
937 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -0500938 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +0100939 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
940
Corentin Chary722ad972007-01-26 14:04:55 +0100941 if (ledd_set_handle)
942 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
943
Corentin Chary8b857352007-01-26 14:04:58 +0100944 if (ls_switch_handle && ls_level_handle) {
945 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
946 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
947 }
Corentin Charye539c2f2007-05-06 14:47:06 +0200948
Corentin Charyf3985322007-05-06 14:48:22 +0200949 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +0200950 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100951}
952
Len Brown8def05f2007-01-30 01:46:43 -0500953static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +0100954 char **paths, int num_paths)
955{
956 int i;
957 acpi_status status;
958
959 for (i = 0; i < num_paths; i++) {
960 status = acpi_get_handle(NULL, paths[i], handle);
961 if (ACPI_SUCCESS(status))
962 return 0;
963 }
964
965 *handle = NULL;
966 return -ENODEV;
967}
968
969#define ASUS_HANDLE_INIT(object) \
970 asus_handle_init(#object, &object##_handle, object##_paths, \
971 ARRAY_SIZE(object##_paths))
972
Corentin Chary85091b72007-01-26 14:04:30 +0100973/*
974 * This function is used to initialize the hotk with right values. In this
975 * method, we can make all the detection we want, and modify the hotk struct
976 */
977static int asus_hotk_get_info(void)
978{
979 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +0100980 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400981 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +0100982 char *string = NULL;
983 acpi_status status;
984
985 /*
986 * Get DSDT headers early enough to allow for differentiating between
987 * models, but late enough to allow acpi_bus_register_driver() to fail
988 * before doing anything ACPI-specific. Should we encounter a machine,
989 * which needs special handling (i.e. its hotkey device has a different
990 * HID), this bit will be moved. A global variable asus_info contains
991 * the DSDT header.
992 */
Len Brown894d79b2007-02-03 02:13:53 -0500993 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +0100994 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200995 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +0100996
997 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100998 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200999 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001000 return -ENODEV;
1001 }
1002
1003 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001004 status =
1005 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1006 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001007 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001008 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001009 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001010 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001011
Corentin Chary185e5af2007-03-11 10:27:33 +01001012 /* This too ... */
1013 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1014
Corentin Chary85091b72007-01-26 14:04:30 +01001015 /*
1016 * Try to match the object returned by INIT to the specific model.
1017 * Handle every possible object (or the lack of thereof) the DSDT
1018 * writers might throw at us. When in trouble, we pass NULL to
1019 * asus_model_match() and try something completely different.
1020 */
1021 if (buffer.pointer) {
1022 model = buffer.pointer;
1023 switch (model->type) {
1024 case ACPI_TYPE_STRING:
1025 string = model->string.pointer;
1026 break;
1027 case ACPI_TYPE_BUFFER:
1028 string = model->buffer.pointer;
1029 break;
1030 default:
1031 string = "";
1032 break;
1033 }
1034 }
1035 hotk->name = kstrdup(string, GFP_KERNEL);
1036 if (!hotk->name)
1037 return -ENOMEM;
1038
Len Brown8def05f2007-01-30 01:46:43 -05001039 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001040 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001041
Corentin Charybe18cda2007-01-26 14:04:35 +01001042 ASUS_HANDLE_INIT(mled_set);
1043 ASUS_HANDLE_INIT(tled_set);
1044 ASUS_HANDLE_INIT(rled_set);
1045 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001046 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001047
Corentin Chary722ad972007-01-26 14:04:55 +01001048 ASUS_HANDLE_INIT(ledd_set);
1049
Corentin Chary4564de12007-01-26 14:04:40 +01001050 /*
1051 * The HWRS method return informations about the hardware.
1052 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1053 * The significance of others is yet to be found.
1054 * If we don't find the method, we assume the device are present.
1055 */
Corentin Chary9a816852007-03-11 10:25:38 +01001056 status =
1057 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1058 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001059 hwrs_result = WL_HWRS | BT_HWRS;
1060
Len Brown8def05f2007-01-30 01:46:43 -05001061 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001062 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001063 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001064 ASUS_HANDLE_INIT(bt_switch);
1065
1066 ASUS_HANDLE_INIT(wireless_status);
1067
Corentin Chary6b7091e2007-01-26 14:04:45 +01001068 ASUS_HANDLE_INIT(brightness_set);
1069 ASUS_HANDLE_INIT(brightness_get);
1070
1071 ASUS_HANDLE_INIT(lcd_switch);
1072
Corentin Chary78127b42007-01-26 14:04:49 +01001073 ASUS_HANDLE_INIT(display_set);
1074 ASUS_HANDLE_INIT(display_get);
1075
Corentin Chary8b857352007-01-26 14:04:58 +01001076 /* There is a lot of models with "ALSL", but a few get
1077 a real light sens, so we need to check it. */
Corentin Chary832d9952007-05-06 14:47:29 +02001078 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001079 ASUS_HANDLE_INIT(ls_level);
1080
Corentin Charye539c2f2007-05-06 14:47:06 +02001081 ASUS_HANDLE_INIT(gps_on);
1082 ASUS_HANDLE_INIT(gps_off);
1083 ASUS_HANDLE_INIT(gps_status);
1084
Corentin Chary85091b72007-01-26 14:04:30 +01001085 kfree(model);
1086
1087 return AE_OK;
1088}
1089
Corentin Chary034ce902009-01-20 16:17:43 +01001090static int asus_input_init(void)
1091{
1092 const struct key_entry *key;
1093 int result;
1094
1095 hotk->inputdev = input_allocate_device();
1096 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001097 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001098 return 0;
1099 }
1100 hotk->inputdev->name = "Asus Laptop extra buttons";
1101 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1102 hotk->inputdev->id.bustype = BUS_HOST;
1103 hotk->inputdev->getkeycode = asus_getkeycode;
1104 hotk->inputdev->setkeycode = asus_setkeycode;
1105
1106 for (key = asus_keymap; key->type != KE_END; key++) {
1107 switch (key->type) {
1108 case KE_KEY:
1109 set_bit(EV_KEY, hotk->inputdev->evbit);
1110 set_bit(key->keycode, hotk->inputdev->keybit);
1111 break;
1112 }
1113 }
1114 result = input_register_device(hotk->inputdev);
1115 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001116 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001117 input_free_device(hotk->inputdev);
1118 }
1119 return result;
1120}
1121
Corentin Chary85091b72007-01-26 14:04:30 +01001122static int asus_hotk_check(void)
1123{
1124 int result = 0;
1125
1126 result = acpi_bus_get_status(hotk->device);
1127 if (result)
1128 return result;
1129
1130 if (hotk->device->status.present) {
1131 result = asus_hotk_get_info();
1132 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001133 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001134 return -EINVAL;
1135 }
1136
1137 return result;
1138}
1139
1140static int asus_hotk_found;
1141
1142static int asus_hotk_add(struct acpi_device *device)
1143{
Corentin Chary85091b72007-01-26 14:04:30 +01001144 int result;
1145
1146 if (!device)
1147 return -EINVAL;
1148
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001149 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001150 ASUS_LAPTOP_VERSION);
1151
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001152 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001153 if (!hotk)
1154 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001155
1156 hotk->handle = device->handle;
1157 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1158 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001159 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001160 hotk->device = device;
1161
1162 result = asus_hotk_check();
1163 if (result)
1164 goto end;
1165
1166 asus_hotk_add_fs();
1167
Corentin Chary85091b72007-01-26 14:04:30 +01001168 asus_hotk_found = 1;
1169
Corentin Chary6b7091e2007-01-26 14:04:45 +01001170 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001171 write_status(bt_switch_handle, 1, BT_ON);
1172 write_status(wl_switch_handle, 1, WL_ON);
1173
1174 /* If the h/w switch is off, we need to check the real status */
1175 write_status(NULL, read_status(BT_ON), BT_ON);
1176 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001177
Corentin Chary6b7091e2007-01-26 14:04:45 +01001178 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001179 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001180
Corentin Chary722ad972007-01-26 14:04:55 +01001181 /* LED display is off by default */
1182 hotk->ledd_status = 0xFFF;
1183
Len Brown8def05f2007-01-30 01:46:43 -05001184 /* Set initial values of light sensor and level */
1185 hotk->light_switch = 1; /* Default to light sensor disabled */
1186 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001187
Len Brown8def05f2007-01-30 01:46:43 -05001188 if (ls_switch_handle)
1189 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001190
Len Brown8def05f2007-01-30 01:46:43 -05001191 if (ls_level_handle)
1192 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001193
Corentin Charye539c2f2007-05-06 14:47:06 +02001194 /* GPS is on by default */
1195 write_status(NULL, 1, GPS_ON);
1196
Corentin Charyed6f4422009-01-20 16:17:45 +01001197end:
Corentin Chary85091b72007-01-26 14:04:30 +01001198 if (result) {
1199 kfree(hotk->name);
1200 kfree(hotk);
1201 }
1202
1203 return result;
1204}
1205
1206static int asus_hotk_remove(struct acpi_device *device, int type)
1207{
Corentin Chary85091b72007-01-26 14:04:30 +01001208 if (!device || !acpi_driver_data(device))
1209 return -EINVAL;
1210
Corentin Chary85091b72007-01-26 14:04:30 +01001211 kfree(hotk->name);
1212 kfree(hotk);
1213
1214 return 0;
1215}
1216
Corentin Chary6b7091e2007-01-26 14:04:45 +01001217static void asus_backlight_exit(void)
1218{
Len Brown8def05f2007-01-30 01:46:43 -05001219 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001220 backlight_device_unregister(asus_backlight_device);
1221}
1222
Corentin Charybe18cda2007-01-26 14:04:35 +01001223#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a692007-08-16 18:18:53 +02001224 if (object##_led.dev) \
1225 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001226
1227static void asus_led_exit(void)
1228{
Al Viro3b0d7112007-07-23 11:21:34 +01001229 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001230 ASUS_LED_UNREGISTER(mled);
1231 ASUS_LED_UNREGISTER(tled);
1232 ASUS_LED_UNREGISTER(pled);
1233 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001234 ASUS_LED_UNREGISTER(gled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001235}
1236
Corentin Chary034ce902009-01-20 16:17:43 +01001237static void asus_input_exit(void)
1238{
1239 if (hotk->inputdev)
1240 input_unregister_device(hotk->inputdev);
1241}
1242
Corentin Chary85091b72007-01-26 14:04:30 +01001243static void __exit asus_laptop_exit(void)
1244{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001245 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001246 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001247 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001248
Corentin Chary85091b72007-01-26 14:04:30 +01001249 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001250 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1251 platform_device_unregister(asuspf_device);
1252 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001253}
1254
Len Brown8def05f2007-01-30 01:46:43 -05001255static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001256{
1257 struct backlight_device *bd;
1258
Len Brown8def05f2007-01-30 01:46:43 -05001259 if (brightness_set_handle && lcd_switch_handle) {
1260 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001261 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001262 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001263 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001264 asus_backlight_device = NULL;
1265 return PTR_ERR(bd);
1266 }
1267
1268 asus_backlight_device = bd;
1269
Richard Purdie599a52d2007-02-10 23:07:48 +00001270 bd->props.max_brightness = 15;
1271 bd->props.brightness = read_brightness(NULL);
1272 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001273 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001274 }
1275 return 0;
1276}
1277
Corentin Charybe18cda2007-01-26 14:04:35 +01001278static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001279 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001280{
Len Brown8def05f2007-01-30 01:46:43 -05001281 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001282 return 0;
1283
1284 return led_classdev_register(dev, ldev);
1285}
Len Brown8def05f2007-01-30 01:46:43 -05001286
Corentin Charybe18cda2007-01-26 14:04:35 +01001287#define ASUS_LED_REGISTER(object, device) \
1288 asus_led_register(object##_set_handle, &object##_led, device)
1289
Len Brown8def05f2007-01-30 01:46:43 -05001290static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001291{
1292 int rv;
1293
1294 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001295 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001296 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001297
1298 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001299 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001300 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001301
1302 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001303 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001304 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001305
1306 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001307 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001308 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001309
Corentin Charyfdd8d082007-03-11 10:26:48 +01001310 rv = ASUS_LED_REGISTER(gled, dev);
1311 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001312 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001313
Corentin Charybe18cda2007-01-26 14:04:35 +01001314 led_workqueue = create_singlethread_workqueue("led_workqueue");
Len Brown8def05f2007-01-30 01:46:43 -05001315 if (!led_workqueue)
Al Viro3b0d7112007-07-23 11:21:34 +01001316 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001317
1318 return 0;
Al Viro3b0d7112007-07-23 11:21:34 +01001319out5:
1320 rv = -ENOMEM;
1321 ASUS_LED_UNREGISTER(gled);
1322out4:
1323 ASUS_LED_UNREGISTER(pled);
1324out3:
1325 ASUS_LED_UNREGISTER(rled);
1326out2:
1327 ASUS_LED_UNREGISTER(tled);
1328out1:
1329 ASUS_LED_UNREGISTER(mled);
1330out:
1331 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001332}
1333
Corentin Chary85091b72007-01-26 14:04:30 +01001334static int __init asus_laptop_init(void)
1335{
1336 int result;
1337
1338 if (acpi_disabled)
1339 return -ENODEV;
1340
Corentin Chary85091b72007-01-26 14:04:30 +01001341 result = acpi_bus_register_driver(&asus_hotk_driver);
1342 if (result < 0)
1343 return result;
1344
1345 /*
1346 * This is a bit of a kludge. We only want this module loaded
1347 * for ASUS systems, but there's currently no way to probe the
1348 * ACPI namespace for ASUS HIDs. So we just return failure if
1349 * we didn't find one, which will cause the module to be
1350 * unloaded.
1351 */
1352 if (!asus_hotk_found) {
1353 acpi_bus_unregister_driver(&asus_hotk_driver);
1354 return -ENODEV;
1355 }
1356
Corentin Chary034ce902009-01-20 16:17:43 +01001357 result = asus_input_init();
1358 if (result)
1359 goto fail_input;
1360
Len Brown8def05f2007-01-30 01:46:43 -05001361 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001362 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001363 if (result)
1364 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001365
Len Brown8def05f2007-01-30 01:46:43 -05001366 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1367 if (!asuspf_device) {
1368 result = -ENOMEM;
1369 goto fail_platform_device1;
1370 }
Corentin Chary85091b72007-01-26 14:04:30 +01001371
Len Brown8def05f2007-01-30 01:46:43 -05001372 result = platform_device_add(asuspf_device);
1373 if (result)
1374 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001375
Len Brown8def05f2007-01-30 01:46:43 -05001376 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001377 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001378 if (result)
1379 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001380
Corentin Chary116bf2e2009-06-16 19:28:46 +00001381 result = asus_led_init(&asuspf_device->dev);
1382 if (result)
1383 goto fail_led;
1384
1385 if (!acpi_video_backlight_support()) {
1386 result = asus_backlight_init(&asuspf_device->dev);
1387 if (result)
1388 goto fail_backlight;
1389 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001390 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001391 "ACPI video driver\n");
1392
Len Brown8def05f2007-01-30 01:46:43 -05001393 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001394
Corentin Chary116bf2e2009-06-16 19:28:46 +00001395fail_backlight:
1396 asus_led_exit();
1397
1398fail_led:
1399 sysfs_remove_group(&asuspf_device->dev.kobj,
1400 &asuspf_attribute_group);
1401
Corentin Charyed6f4422009-01-20 16:17:45 +01001402fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001403 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001404
Corentin Charyed6f4422009-01-20 16:17:45 +01001405fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001406 platform_device_put(asuspf_device);
1407
Corentin Charyed6f4422009-01-20 16:17:45 +01001408fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001409 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001410
Corentin Charyed6f4422009-01-20 16:17:45 +01001411fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001412 asus_input_exit();
1413
Corentin Charyed6f4422009-01-20 16:17:45 +01001414fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001415
1416 return result;
1417}
1418
1419module_init(asus_laptop_init);
1420module_exit(asus_laptop_exit);