blob: 410e545e427ba145319c599ebb13f93a2fc03a9a [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); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000249 static enum led_brightness object##_led_get( \
250 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100251 static void object##_led_update(struct work_struct *ignored); \
252 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100253 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100254 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100255 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100256 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000257 .brightness_get = object##_led_get, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100258 }
259
260ASUS_LED(mled, "mail");
261ASUS_LED(tled, "touchpad");
262ASUS_LED(rled, "record");
263ASUS_LED(pled, "phone");
Corentin Charyfdd8d082007-03-11 10:26:48 +0100264ASUS_LED(gled, "gaming");
Corentin Charybe18cda2007-01-26 14:04:35 +0100265
Corentin Chary034ce902009-01-20 16:17:43 +0100266struct key_entry {
267 char type;
268 u8 code;
269 u16 keycode;
270};
271
272enum { KE_KEY, KE_END };
273
274static struct key_entry asus_keymap[] = {
275 {KE_KEY, 0x30, KEY_VOLUMEUP},
276 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
277 {KE_KEY, 0x32, KEY_MUTE},
278 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
279 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
280 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
281 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200282 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100283 {KE_KEY, 0x45, KEY_PLAYPAUSE},
284 {KE_KEY, 0x50, KEY_EMAIL},
285 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200286 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100287 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000288 {KE_KEY, 0x5E, KEY_WLAN},
289 {KE_KEY, 0x5F, KEY_WLAN},
290 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100291 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
292 {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
293 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200294 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100295 {KE_KEY, 0x95, KEY_MEDIA},
296 {KE_KEY, 0x99, KEY_PHONE},
297 {KE_END, 0},
298};
299
Corentin Chary85091b72007-01-26 14:04:30 +0100300/*
301 * This function evaluates an ACPI method, given an int as parameter, the
302 * method is searched within the scope of the handle, can be NULL. The output
303 * of the method is written is output, which can also be NULL
304 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100305 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100306 */
307static int write_acpi_int(acpi_handle handle, const char *method, int val,
308 struct acpi_buffer *output)
309{
310 struct acpi_object_list params; //list of input parameters (an int here)
311 union acpi_object in_obj; //the only param we use
312 acpi_status status;
313
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100314 if (!handle)
315 return 0;
316
Corentin Chary85091b72007-01-26 14:04:30 +0100317 params.count = 1;
318 params.pointer = &in_obj;
319 in_obj.type = ACPI_TYPE_INTEGER;
320 in_obj.integer.value = val;
321
322 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100323 if (status == AE_OK)
324 return 0;
325 else
326 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100327}
328
Len Brown8def05f2007-01-30 01:46:43 -0500329static int read_wireless_status(int mask)
330{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400331 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100332 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100333
334 if (!wireless_status_handle)
335 return (hotk->status & mask) ? 1 : 0;
336
Corentin Chary9a816852007-03-11 10:25:38 +0100337 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
338 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200339 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100340 else
341 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100342
343 return (hotk->status & mask) ? 1 : 0;
344}
345
Corentin Charyf3985322007-05-06 14:48:22 +0200346static int read_gps_status(void)
347{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400348 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200349 acpi_status rv = AE_OK;
350
351 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
352 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200353 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200354 else
Corentin Charyf3985322007-05-06 14:48:22 +0200355 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200356
Corentin Charyf3985322007-05-06 14:48:22 +0200357 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200358}
359
Corentin Charybe18cda2007-01-26 14:04:35 +0100360/* Generic LED functions */
361static int read_status(int mask)
362{
Corentin Chary4564de12007-01-26 14:04:40 +0100363 /* There is a special method for both wireless devices */
364 if (mask == BT_ON || mask == WL_ON)
365 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200366 else if (mask == GPS_ON)
367 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100368
Corentin Charybe18cda2007-01-26 14:04:35 +0100369 return (hotk->status & mask) ? 1 : 0;
370}
371
Corentin Chary935ffee2007-03-11 10:26:12 +0100372static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100373{
374 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
375
Corentin Chary935ffee2007-03-11 10:26:12 +0100376 switch (mask) {
377 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100378 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100379 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100380 case GLED_ON:
381 out = (out & 0x1) + 1;
382 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200383 case GPS_ON:
384 handle = (out) ? gps_on_handle : gps_off_handle;
385 out = 0x02;
386 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100387 default:
388 out &= 0x1;
389 break;
390 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100391
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100392 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200393 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100394}
395
396/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100397#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100398 static void object##_led_set(struct led_classdev *led_cdev, \
399 enum led_brightness value) \
400 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200401 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100402 queue_work(led_workqueue, &object##_led_work); \
403 } \
404 static void object##_led_update(struct work_struct *ignored) \
405 { \
406 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100407 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000408 } \
409 static enum led_brightness object##_led_get( \
410 struct led_classdev *led_cdev) \
411 { \
412 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100413 }
414
Corentin Chary935ffee2007-03-11 10:26:12 +0100415ASUS_LED_HANDLER(mled, MLED_ON);
416ASUS_LED_HANDLER(pled, PLED_ON);
417ASUS_LED_HANDLER(rled, RLED_ON);
418ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100419ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100420
Corentin Chary6b7091e2007-01-26 14:04:45 +0100421static int get_lcd_state(void)
422{
423 return read_status(LCD_ON);
424}
425
426static int set_lcd_state(int value)
427{
428 int lcd = 0;
429 acpi_status status = 0;
430
431 lcd = value ? 1 : 0;
432
433 if (lcd == get_lcd_state())
434 return 0;
435
Len Brown8def05f2007-01-30 01:46:43 -0500436 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100437 status = acpi_evaluate_object(lcd_switch_handle,
438 NULL, NULL, NULL);
439
440 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200441 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100442 }
443
Corentin Chary935ffee2007-03-11 10:26:12 +0100444 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100445 return 0;
446}
447
448static void lcd_blank(int blank)
449{
450 struct backlight_device *bd = asus_backlight_device;
451
Len Brown8def05f2007-01-30 01:46:43 -0500452 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000453 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000454 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100455 }
456}
457
458static int read_brightness(struct backlight_device *bd)
459{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400460 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100461 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100462
Corentin Chary9a816852007-03-11 10:25:38 +0100463 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
464 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200465 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100466
467 return value;
468}
469
470static int set_brightness(struct backlight_device *bd, int value)
471{
472 int ret = 0;
473
474 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
475 /* 0 <= value <= 15 */
476
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100477 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200478 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100479 ret = -EIO;
480 }
481
482 return ret;
483}
484
485static int update_bl_status(struct backlight_device *bd)
486{
487 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000488 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100489
490 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500491 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100492 return rv;
493
Richard Purdie599a52d2007-02-10 23:07:48 +0000494 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100495 return set_lcd_state(value);
496}
497
Corentin Chary85091b72007-01-26 14:04:30 +0100498/*
499 * Platform device handlers
500 */
501
502/*
503 * We write our info in page, we begin at offset off and cannot write more
504 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
505 * number of bytes written in page
506 */
507static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500508 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100509{
510 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400511 unsigned long long temp;
Corentin Chary85091b72007-01-26 14:04:30 +0100512 char buf[16]; //enough for all info
Corentin Chary9a816852007-03-11 10:25:38 +0100513 acpi_status rv = AE_OK;
514
Corentin Chary85091b72007-01-26 14:04:30 +0100515 /*
516 * We use the easy way, we don't care of off and count, so we don't set eof
517 * to 1
518 */
519
520 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
521 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
522 /*
523 * The SFUN method probably allows the original driver to get the list
524 * of features supported by a given model. For now, 0x0100 or 0x0800
525 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
526 * The significance of others is yet to be found.
527 */
Corentin Chary9a816852007-03-11 10:25:38 +0100528 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
529 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000530 len += sprintf(page + len, "SFUN value : %#x\n",
531 (uint) temp);
532 /*
533 * The HWRS method return informations about the hardware.
534 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
535 * The significance of others is yet to be found.
536 * If we don't find the method, we assume the device are present.
537 */
538 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
539 if (!ACPI_FAILURE(rv))
540 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100541 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100542 /*
543 * Another value for userspace: the ASYM method returns 0x02 for
544 * battery low and 0x04 for battery critical, its readings tend to be
545 * more accurate than those provided by _BST.
546 * Note: since not all the laptops provide this method, errors are
547 * silently ignored.
548 */
Corentin Chary9a816852007-03-11 10:25:38 +0100549 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
550 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000551 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100552 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100553 if (asus_info) {
554 snprintf(buf, 16, "%d", asus_info->length);
555 len += sprintf(page + len, "DSDT length : %s\n", buf);
556 snprintf(buf, 16, "%d", asus_info->checksum);
557 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
558 snprintf(buf, 16, "%d", asus_info->revision);
559 len += sprintf(page + len, "DSDT revision : %s\n", buf);
560 snprintf(buf, 7, "%s", asus_info->oem_id);
561 len += sprintf(page + len, "OEM id : %s\n", buf);
562 snprintf(buf, 9, "%s", asus_info->oem_table_id);
563 len += sprintf(page + len, "OEM table id : %s\n", buf);
564 snprintf(buf, 16, "%x", asus_info->oem_revision);
565 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
566 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
567 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
568 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
569 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
570 }
571
572 return len;
573}
574
575static int parse_arg(const char *buf, unsigned long count, int *val)
576{
577 if (!count)
578 return 0;
579 if (count > 31)
580 return -EINVAL;
581 if (sscanf(buf, "%i", val) != 1)
582 return -EINVAL;
583 return count;
584}
585
Corentin Chary4564de12007-01-26 14:04:40 +0100586static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100587 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100588{
589 int rv, value;
590 int out = 0;
591
592 rv = parse_arg(buf, count, &value);
593 if (rv > 0)
594 out = value ? 1 : 0;
595
Corentin Chary935ffee2007-03-11 10:26:12 +0100596 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100597
598 return rv;
599}
600
601/*
Corentin Chary722ad972007-01-26 14:04:55 +0100602 * LEDD display
603 */
604static ssize_t show_ledd(struct device *dev,
605 struct device_attribute *attr, char *buf)
606{
607 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
608}
609
610static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
611 const char *buf, size_t count)
612{
613 int rv, value;
614
615 rv = parse_arg(buf, count, &value);
616 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100617 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200618 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100619 else
620 hotk->ledd_status = (u32) value;
621 }
622 return rv;
623}
624
625/*
Corentin Chary4564de12007-01-26 14:04:40 +0100626 * WLAN
627 */
628static ssize_t show_wlan(struct device *dev,
629 struct device_attribute *attr, char *buf)
630{
631 return sprintf(buf, "%d\n", read_status(WL_ON));
632}
633
634static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
635 const char *buf, size_t count)
636{
Corentin Chary935ffee2007-03-11 10:26:12 +0100637 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100638}
639
640/*
641 * Bluetooth
642 */
643static ssize_t show_bluetooth(struct device *dev,
644 struct device_attribute *attr, char *buf)
645{
646 return sprintf(buf, "%d\n", read_status(BT_ON));
647}
648
Len Brown8def05f2007-01-30 01:46:43 -0500649static ssize_t store_bluetooth(struct device *dev,
650 struct device_attribute *attr, const char *buf,
651 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100652{
Corentin Chary935ffee2007-03-11 10:26:12 +0100653 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100654}
655
Corentin Chary78127b42007-01-26 14:04:49 +0100656/*
657 * Display
658 */
659static void set_display(int value)
660{
661 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100662 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200663 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100664 return;
665}
666
667static int read_display(void)
668{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400669 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100670 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100671
672 /* In most of the case, we know how to set the display, but sometime
673 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500674 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100675 rv = acpi_evaluate_integer(display_get_handle, NULL,
676 NULL, &value);
677 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200678 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100679 }
680
681 value &= 0x0F; /* needed for some models, shouldn't hurt others */
682
683 return value;
684}
Len Brown8def05f2007-01-30 01:46:43 -0500685
Corentin Chary78127b42007-01-26 14:04:49 +0100686/*
687 * Now, *this* one could be more user-friendly, but so far, no-one has
688 * complained. The significance of bits is the same as in store_disp()
689 */
690static ssize_t show_disp(struct device *dev,
691 struct device_attribute *attr, char *buf)
692{
693 return sprintf(buf, "%d\n", read_display());
694}
695
696/*
697 * Experimental support for display switching. As of now: 1 should activate
698 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
699 * Any combination (bitwise) of these will suffice. I never actually tested 4
700 * displays hooked up simultaneously, so be warned. See the acpi4asus README
701 * for more info.
702 */
703static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
704 const char *buf, size_t count)
705{
706 int rv, value;
707
708 rv = parse_arg(buf, count, &value);
709 if (rv > 0)
710 set_display(value);
711 return rv;
712}
713
Corentin Chary8b857352007-01-26 14:04:58 +0100714/*
715 * Light Sens
716 */
717static void set_light_sens_switch(int value)
718{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100719 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200720 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100721 hotk->light_switch = value;
722}
723
724static ssize_t show_lssw(struct device *dev,
725 struct device_attribute *attr, char *buf)
726{
727 return sprintf(buf, "%d\n", hotk->light_switch);
728}
729
730static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
731 const char *buf, size_t count)
732{
733 int rv, value;
734
735 rv = parse_arg(buf, count, &value);
736 if (rv > 0)
737 set_light_sens_switch(value ? 1 : 0);
738
739 return rv;
740}
741
742static void set_light_sens_level(int value)
743{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100744 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200745 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100746 hotk->light_level = value;
747}
748
749static ssize_t show_lslvl(struct device *dev,
750 struct device_attribute *attr, char *buf)
751{
752 return sprintf(buf, "%d\n", hotk->light_level);
753}
754
755static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
756 const char *buf, size_t count)
757{
758 int rv, value;
759
760 rv = parse_arg(buf, count, &value);
761 if (rv > 0) {
762 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
763 /* 0 <= value <= 15 */
764 set_light_sens_level(value);
765 }
766
767 return rv;
768}
769
Corentin Charye539c2f2007-05-06 14:47:06 +0200770/*
771 * GPS
772 */
773static ssize_t show_gps(struct device *dev,
774 struct device_attribute *attr, char *buf)
775{
776 return sprintf(buf, "%d\n", read_status(GPS_ON));
777}
778
779static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
780 const char *buf, size_t count)
781{
Corentin Charyf3985322007-05-06 14:48:22 +0200782 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200783}
784
Corentin Chary034ce902009-01-20 16:17:43 +0100785/*
786 * Hotkey functions
787 */
788static struct key_entry *asus_get_entry_by_scancode(int code)
789{
790 struct key_entry *key;
791
792 for (key = asus_keymap; key->type != KE_END; key++)
793 if (code == key->code)
794 return key;
795
796 return NULL;
797}
798
799static struct key_entry *asus_get_entry_by_keycode(int code)
800{
801 struct key_entry *key;
802
803 for (key = asus_keymap; key->type != KE_END; key++)
804 if (code == key->keycode && key->type == KE_KEY)
805 return key;
806
807 return NULL;
808}
809
810static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
811{
812 struct key_entry *key = asus_get_entry_by_scancode(scancode);
813
814 if (key && key->type == KE_KEY) {
815 *keycode = key->keycode;
816 return 0;
817 }
818
819 return -EINVAL;
820}
821
822static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
823{
824 struct key_entry *key;
825 int old_keycode;
826
827 if (keycode < 0 || keycode > KEY_MAX)
828 return -EINVAL;
829
830 key = asus_get_entry_by_scancode(scancode);
831 if (key && key->type == KE_KEY) {
832 old_keycode = key->keycode;
833 key->keycode = keycode;
834 set_bit(keycode, dev->keybit);
835 if (!asus_get_entry_by_keycode(old_keycode))
836 clear_bit(old_keycode, dev->keybit);
837 return 0;
838 }
839
840 return -EINVAL;
841}
842
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600843static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100844{
Corentin Chary034ce902009-01-20 16:17:43 +0100845 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100846 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100847
Corentin Chary85091b72007-01-26 14:04:30 +0100848 /* TODO Find a better way to handle events count. */
849 if (!hotk)
850 return;
851
Corentin Chary6b7091e2007-01-26 14:04:45 +0100852 /*
853 * We need to tell the backlight device when the backlight power is
854 * switched
855 */
856 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100857 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100858 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500859 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100860 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100861 lcd_blank(FB_BLANK_POWERDOWN);
862 }
863
Corentin Chary6050c8d2009-02-15 19:30:19 +0100864 count = hotk->event_count[event % 128]++;
865 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100866 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
867 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100868 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100869
Corentin Chary034ce902009-01-20 16:17:43 +0100870 if (hotk->inputdev) {
871 key = asus_get_entry_by_scancode(event);
872 if (!key)
873 return ;
874
875 switch (key->type) {
876 case KE_KEY:
877 input_report_key(hotk->inputdev, key->keycode, 1);
878 input_sync(hotk->inputdev);
879 input_report_key(hotk->inputdev, key->keycode, 0);
880 input_sync(hotk->inputdev);
881 break;
882 }
883 }
Corentin Chary85091b72007-01-26 14:04:30 +0100884}
885
886#define ASUS_CREATE_DEVICE_ATTR(_name) \
887 struct device_attribute dev_attr_##_name = { \
888 .attr = { \
889 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900890 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100891 .show = NULL, \
892 .store = NULL, \
893 }
894
895#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
896 do { \
897 dev_attr_##_name.attr.mode = _mode; \
898 dev_attr_##_name.show = _show; \
899 dev_attr_##_name.store = _store; \
900 } while(0)
901
902static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100903static ASUS_CREATE_DEVICE_ATTR(wlan);
904static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100905static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100906static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100907static ASUS_CREATE_DEVICE_ATTR(ls_switch);
908static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200909static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100910
911static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500912 &dev_attr_infos.attr,
913 &dev_attr_wlan.attr,
914 &dev_attr_bluetooth.attr,
915 &dev_attr_display.attr,
916 &dev_attr_ledd.attr,
917 &dev_attr_ls_switch.attr,
918 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +0200919 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -0500920 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100921};
922
923static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500924 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100925};
926
927static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500928 .driver = {
929 .name = ASUS_HOTK_FILE,
930 .owner = THIS_MODULE,
931 }
Corentin Chary85091b72007-01-26 14:04:30 +0100932};
933
934static struct platform_device *asuspf_device;
935
Corentin Chary85091b72007-01-26 14:04:30 +0100936static void asus_hotk_add_fs(void)
937{
938 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +0100939
940 if (wl_switch_handle)
941 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
942
943 if (bt_switch_handle)
944 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
945 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100946
947 if (display_set_handle && display_get_handle)
948 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -0500949 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +0100950 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
951
Corentin Chary722ad972007-01-26 14:04:55 +0100952 if (ledd_set_handle)
953 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
954
Corentin Chary8b857352007-01-26 14:04:58 +0100955 if (ls_switch_handle && ls_level_handle) {
956 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
957 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
958 }
Corentin Charye539c2f2007-05-06 14:47:06 +0200959
Corentin Charyf3985322007-05-06 14:48:22 +0200960 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +0200961 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100962}
963
Len Brown8def05f2007-01-30 01:46:43 -0500964static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +0100965 char **paths, int num_paths)
966{
967 int i;
968 acpi_status status;
969
970 for (i = 0; i < num_paths; i++) {
971 status = acpi_get_handle(NULL, paths[i], handle);
972 if (ACPI_SUCCESS(status))
973 return 0;
974 }
975
976 *handle = NULL;
977 return -ENODEV;
978}
979
980#define ASUS_HANDLE_INIT(object) \
981 asus_handle_init(#object, &object##_handle, object##_paths, \
982 ARRAY_SIZE(object##_paths))
983
Corentin Chary85091b72007-01-26 14:04:30 +0100984/*
985 * This function is used to initialize the hotk with right values. In this
986 * method, we can make all the detection we want, and modify the hotk struct
987 */
988static int asus_hotk_get_info(void)
989{
990 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +0100991 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400992 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +0100993 char *string = NULL;
994 acpi_status status;
995
996 /*
997 * Get DSDT headers early enough to allow for differentiating between
998 * models, but late enough to allow acpi_bus_register_driver() to fail
999 * before doing anything ACPI-specific. Should we encounter a machine,
1000 * which needs special handling (i.e. its hotkey device has a different
1001 * HID), this bit will be moved. A global variable asus_info contains
1002 * the DSDT header.
1003 */
Len Brown894d79b2007-02-03 02:13:53 -05001004 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001005 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001006 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001007
1008 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +01001009 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001010 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001011 return -ENODEV;
1012 }
1013
1014 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001015 status =
1016 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1017 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001018 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001019 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001020 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001021 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001022
Corentin Chary185e5af2007-03-11 10:27:33 +01001023 /* This too ... */
1024 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1025
Corentin Chary85091b72007-01-26 14:04:30 +01001026 /*
1027 * Try to match the object returned by INIT to the specific model.
1028 * Handle every possible object (or the lack of thereof) the DSDT
1029 * writers might throw at us. When in trouble, we pass NULL to
1030 * asus_model_match() and try something completely different.
1031 */
1032 if (buffer.pointer) {
1033 model = buffer.pointer;
1034 switch (model->type) {
1035 case ACPI_TYPE_STRING:
1036 string = model->string.pointer;
1037 break;
1038 case ACPI_TYPE_BUFFER:
1039 string = model->buffer.pointer;
1040 break;
1041 default:
1042 string = "";
1043 break;
1044 }
1045 }
1046 hotk->name = kstrdup(string, GFP_KERNEL);
1047 if (!hotk->name)
1048 return -ENOMEM;
1049
Len Brown8def05f2007-01-30 01:46:43 -05001050 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001051 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001052
Corentin Charybe18cda2007-01-26 14:04:35 +01001053 ASUS_HANDLE_INIT(mled_set);
1054 ASUS_HANDLE_INIT(tled_set);
1055 ASUS_HANDLE_INIT(rled_set);
1056 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001057 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001058
Corentin Chary722ad972007-01-26 14:04:55 +01001059 ASUS_HANDLE_INIT(ledd_set);
1060
Corentin Chary4564de12007-01-26 14:04:40 +01001061 /*
1062 * The HWRS method return informations about the hardware.
1063 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1064 * The significance of others is yet to be found.
1065 * If we don't find the method, we assume the device are present.
1066 */
Corentin Chary9a816852007-03-11 10:25:38 +01001067 status =
1068 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1069 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001070 hwrs_result = WL_HWRS | BT_HWRS;
1071
Len Brown8def05f2007-01-30 01:46:43 -05001072 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001073 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001074 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001075 ASUS_HANDLE_INIT(bt_switch);
1076
1077 ASUS_HANDLE_INIT(wireless_status);
1078
Corentin Chary6b7091e2007-01-26 14:04:45 +01001079 ASUS_HANDLE_INIT(brightness_set);
1080 ASUS_HANDLE_INIT(brightness_get);
1081
1082 ASUS_HANDLE_INIT(lcd_switch);
1083
Corentin Chary78127b42007-01-26 14:04:49 +01001084 ASUS_HANDLE_INIT(display_set);
1085 ASUS_HANDLE_INIT(display_get);
1086
Corentin Chary8b857352007-01-26 14:04:58 +01001087 /* There is a lot of models with "ALSL", but a few get
1088 a real light sens, so we need to check it. */
Corentin Chary832d9952007-05-06 14:47:29 +02001089 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001090 ASUS_HANDLE_INIT(ls_level);
1091
Corentin Charye539c2f2007-05-06 14:47:06 +02001092 ASUS_HANDLE_INIT(gps_on);
1093 ASUS_HANDLE_INIT(gps_off);
1094 ASUS_HANDLE_INIT(gps_status);
1095
Corentin Chary85091b72007-01-26 14:04:30 +01001096 kfree(model);
1097
1098 return AE_OK;
1099}
1100
Corentin Chary034ce902009-01-20 16:17:43 +01001101static int asus_input_init(void)
1102{
1103 const struct key_entry *key;
1104 int result;
1105
1106 hotk->inputdev = input_allocate_device();
1107 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001108 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001109 return 0;
1110 }
1111 hotk->inputdev->name = "Asus Laptop extra buttons";
1112 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1113 hotk->inputdev->id.bustype = BUS_HOST;
1114 hotk->inputdev->getkeycode = asus_getkeycode;
1115 hotk->inputdev->setkeycode = asus_setkeycode;
1116
1117 for (key = asus_keymap; key->type != KE_END; key++) {
1118 switch (key->type) {
1119 case KE_KEY:
1120 set_bit(EV_KEY, hotk->inputdev->evbit);
1121 set_bit(key->keycode, hotk->inputdev->keybit);
1122 break;
1123 }
1124 }
1125 result = input_register_device(hotk->inputdev);
1126 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001127 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001128 input_free_device(hotk->inputdev);
1129 }
1130 return result;
1131}
1132
Corentin Chary85091b72007-01-26 14:04:30 +01001133static int asus_hotk_check(void)
1134{
1135 int result = 0;
1136
1137 result = acpi_bus_get_status(hotk->device);
1138 if (result)
1139 return result;
1140
1141 if (hotk->device->status.present) {
1142 result = asus_hotk_get_info();
1143 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001144 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001145 return -EINVAL;
1146 }
1147
1148 return result;
1149}
1150
1151static int asus_hotk_found;
1152
1153static int asus_hotk_add(struct acpi_device *device)
1154{
Corentin Chary85091b72007-01-26 14:04:30 +01001155 int result;
1156
1157 if (!device)
1158 return -EINVAL;
1159
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001160 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001161 ASUS_LAPTOP_VERSION);
1162
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001163 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001164 if (!hotk)
1165 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001166
1167 hotk->handle = device->handle;
1168 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1169 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001170 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001171 hotk->device = device;
1172
1173 result = asus_hotk_check();
1174 if (result)
1175 goto end;
1176
1177 asus_hotk_add_fs();
1178
Corentin Chary85091b72007-01-26 14:04:30 +01001179 asus_hotk_found = 1;
1180
Corentin Chary6b7091e2007-01-26 14:04:45 +01001181 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001182 write_status(bt_switch_handle, 1, BT_ON);
1183 write_status(wl_switch_handle, 1, WL_ON);
1184
1185 /* If the h/w switch is off, we need to check the real status */
1186 write_status(NULL, read_status(BT_ON), BT_ON);
1187 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001188
Corentin Chary6b7091e2007-01-26 14:04:45 +01001189 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001190 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001191
Corentin Chary722ad972007-01-26 14:04:55 +01001192 /* LED display is off by default */
1193 hotk->ledd_status = 0xFFF;
1194
Len Brown8def05f2007-01-30 01:46:43 -05001195 /* Set initial values of light sensor and level */
1196 hotk->light_switch = 1; /* Default to light sensor disabled */
1197 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001198
Len Brown8def05f2007-01-30 01:46:43 -05001199 if (ls_switch_handle)
1200 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001201
Len Brown8def05f2007-01-30 01:46:43 -05001202 if (ls_level_handle)
1203 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001204
Corentin Charye539c2f2007-05-06 14:47:06 +02001205 /* GPS is on by default */
1206 write_status(NULL, 1, GPS_ON);
1207
Corentin Charyed6f4422009-01-20 16:17:45 +01001208end:
Corentin Chary85091b72007-01-26 14:04:30 +01001209 if (result) {
1210 kfree(hotk->name);
1211 kfree(hotk);
1212 }
1213
1214 return result;
1215}
1216
1217static int asus_hotk_remove(struct acpi_device *device, int type)
1218{
Corentin Chary85091b72007-01-26 14:04:30 +01001219 if (!device || !acpi_driver_data(device))
1220 return -EINVAL;
1221
Corentin Chary85091b72007-01-26 14:04:30 +01001222 kfree(hotk->name);
1223 kfree(hotk);
1224
1225 return 0;
1226}
1227
Corentin Chary6b7091e2007-01-26 14:04:45 +01001228static void asus_backlight_exit(void)
1229{
Len Brown8def05f2007-01-30 01:46:43 -05001230 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001231 backlight_device_unregister(asus_backlight_device);
1232}
1233
Corentin Charybe18cda2007-01-26 14:04:35 +01001234#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a692007-08-16 18:18:53 +02001235 if (object##_led.dev) \
1236 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001237
1238static void asus_led_exit(void)
1239{
Al Viro3b0d7112007-07-23 11:21:34 +01001240 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001241 ASUS_LED_UNREGISTER(mled);
1242 ASUS_LED_UNREGISTER(tled);
1243 ASUS_LED_UNREGISTER(pled);
1244 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001245 ASUS_LED_UNREGISTER(gled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001246}
1247
Corentin Chary034ce902009-01-20 16:17:43 +01001248static void asus_input_exit(void)
1249{
1250 if (hotk->inputdev)
1251 input_unregister_device(hotk->inputdev);
1252}
1253
Corentin Chary85091b72007-01-26 14:04:30 +01001254static void __exit asus_laptop_exit(void)
1255{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001256 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001257 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001258 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001259
Corentin Chary85091b72007-01-26 14:04:30 +01001260 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001261 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1262 platform_device_unregister(asuspf_device);
1263 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001264}
1265
Len Brown8def05f2007-01-30 01:46:43 -05001266static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001267{
1268 struct backlight_device *bd;
1269
Len Brown8def05f2007-01-30 01:46:43 -05001270 if (brightness_set_handle && lcd_switch_handle) {
1271 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001272 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001273 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001274 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001275 asus_backlight_device = NULL;
1276 return PTR_ERR(bd);
1277 }
1278
1279 asus_backlight_device = bd;
1280
Richard Purdie599a52d2007-02-10 23:07:48 +00001281 bd->props.max_brightness = 15;
1282 bd->props.brightness = read_brightness(NULL);
1283 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001284 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001285 }
1286 return 0;
1287}
1288
Corentin Charybe18cda2007-01-26 14:04:35 +01001289static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001290 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001291{
Len Brown8def05f2007-01-30 01:46:43 -05001292 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001293 return 0;
1294
1295 return led_classdev_register(dev, ldev);
1296}
Len Brown8def05f2007-01-30 01:46:43 -05001297
Corentin Charybe18cda2007-01-26 14:04:35 +01001298#define ASUS_LED_REGISTER(object, device) \
1299 asus_led_register(object##_set_handle, &object##_led, device)
1300
Len Brown8def05f2007-01-30 01:46:43 -05001301static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001302{
1303 int rv;
1304
1305 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001306 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001307 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001308
1309 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001310 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001311 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001312
1313 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001314 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001315 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001316
1317 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001318 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001319 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001320
Corentin Charyfdd8d082007-03-11 10:26:48 +01001321 rv = ASUS_LED_REGISTER(gled, dev);
1322 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001323 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001324
Corentin Charybe18cda2007-01-26 14:04:35 +01001325 led_workqueue = create_singlethread_workqueue("led_workqueue");
Len Brown8def05f2007-01-30 01:46:43 -05001326 if (!led_workqueue)
Al Viro3b0d7112007-07-23 11:21:34 +01001327 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001328
1329 return 0;
Al Viro3b0d7112007-07-23 11:21:34 +01001330out5:
1331 rv = -ENOMEM;
1332 ASUS_LED_UNREGISTER(gled);
1333out4:
1334 ASUS_LED_UNREGISTER(pled);
1335out3:
1336 ASUS_LED_UNREGISTER(rled);
1337out2:
1338 ASUS_LED_UNREGISTER(tled);
1339out1:
1340 ASUS_LED_UNREGISTER(mled);
1341out:
1342 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001343}
1344
Corentin Chary85091b72007-01-26 14:04:30 +01001345static int __init asus_laptop_init(void)
1346{
1347 int result;
1348
1349 if (acpi_disabled)
1350 return -ENODEV;
1351
Corentin Chary85091b72007-01-26 14:04:30 +01001352 result = acpi_bus_register_driver(&asus_hotk_driver);
1353 if (result < 0)
1354 return result;
1355
1356 /*
1357 * This is a bit of a kludge. We only want this module loaded
1358 * for ASUS systems, but there's currently no way to probe the
1359 * ACPI namespace for ASUS HIDs. So we just return failure if
1360 * we didn't find one, which will cause the module to be
1361 * unloaded.
1362 */
1363 if (!asus_hotk_found) {
1364 acpi_bus_unregister_driver(&asus_hotk_driver);
1365 return -ENODEV;
1366 }
1367
Corentin Chary034ce902009-01-20 16:17:43 +01001368 result = asus_input_init();
1369 if (result)
1370 goto fail_input;
1371
Len Brown8def05f2007-01-30 01:46:43 -05001372 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001373 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001374 if (result)
1375 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001376
Len Brown8def05f2007-01-30 01:46:43 -05001377 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1378 if (!asuspf_device) {
1379 result = -ENOMEM;
1380 goto fail_platform_device1;
1381 }
Corentin Chary85091b72007-01-26 14:04:30 +01001382
Len Brown8def05f2007-01-30 01:46:43 -05001383 result = platform_device_add(asuspf_device);
1384 if (result)
1385 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001386
Len Brown8def05f2007-01-30 01:46:43 -05001387 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001388 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001389 if (result)
1390 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001391
Corentin Chary116bf2e2009-06-16 19:28:46 +00001392 result = asus_led_init(&asuspf_device->dev);
1393 if (result)
1394 goto fail_led;
1395
1396 if (!acpi_video_backlight_support()) {
1397 result = asus_backlight_init(&asuspf_device->dev);
1398 if (result)
1399 goto fail_backlight;
1400 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001401 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001402 "ACPI video driver\n");
1403
Len Brown8def05f2007-01-30 01:46:43 -05001404 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001405
Corentin Chary116bf2e2009-06-16 19:28:46 +00001406fail_backlight:
1407 asus_led_exit();
1408
1409fail_led:
1410 sysfs_remove_group(&asuspf_device->dev.kobj,
1411 &asuspf_attribute_group);
1412
Corentin Charyed6f4422009-01-20 16:17:45 +01001413fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001414 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001415
Corentin Charyed6f4422009-01-20 16:17:45 +01001416fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001417 platform_device_put(asuspf_device);
1418
Corentin Charyed6f4422009-01-20 16:17:45 +01001419fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001420 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001421
Corentin Charyed6f4422009-01-20 16:17:45 +01001422fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001423 asus_input_exit();
1424
Corentin Charyed6f4422009-01-20 16:17:45 +01001425fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001426
1427 return result;
1428}
1429
1430module_init(asus_laptop_init);
1431module_exit(asus_laptop_exit);