blob: 6c05172bf3d3358b579b412d337c93098b2a21ea [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 */
Corentin Charybe966662009-08-29 10:28:29 +020080#define WL_ON 0x01 /* internal Wifi */
81#define BT_ON 0x02 /* internal Bluetooth */
82#define MLED_ON 0x04 /* mail LED */
83#define TLED_ON 0x08 /* touchpad LED */
84#define RLED_ON 0x10 /* Record LED */
85#define PLED_ON 0x20 /* Phone LED */
86#define GLED_ON 0x40 /* Gaming LED */
87#define LCD_ON 0x80 /* LCD backlight */
88#define GPS_ON 0x100 /* GPS */
89#define KEY_ON 0x200 /* Keyboard backlight */
Corentin Charybe18cda2007-01-26 14:04:35 +010090
Corentin Chary85091b72007-01-26 14:04:30 +010091#define ASUS_LOG ASUS_HOTK_FILE ": "
92#define ASUS_ERR KERN_ERR ASUS_LOG
93#define ASUS_WARNING KERN_WARNING ASUS_LOG
94#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
95#define ASUS_INFO KERN_INFO ASUS_LOG
96#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
97
98MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
99MODULE_DESCRIPTION(ASUS_HOTK_NAME);
100MODULE_LICENSE("GPL");
101
Corentin Charybe966662009-08-29 10:28:29 +0200102/*
103 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +0100104 * The significance of values is yet to be found, but
105 * most of the time:
106 * 0x0 will do nothing
107 * 0x1 will allow to control the device with Fn+Fx key.
108 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
109 * 0x5 like 0x1 or 0x4
110 * So, if something doesn't work as you want, just try other values =)
111 */
112static uint wapf = 1;
113module_param(wapf, uint, 0644);
114MODULE_PARM_DESC(wapf, "WAPF value");
115
Corentin Chary85091b72007-01-26 14:04:30 +0100116#define ASUS_HANDLE(object, paths...) \
117 static acpi_handle object##_handle = NULL; \
118 static char *object##_paths[] = { paths }
119
Corentin Charybe18cda2007-01-26 14:04:35 +0100120/* LED */
121ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
122ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500123ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
124ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charyfdd8d082007-03-11 10:26:48 +0100125ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100126
Corentin Chary722ad972007-01-26 14:04:55 +0100127/* LEDD */
128ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
129
Corentin Charybe966662009-08-29 10:28:29 +0200130/*
131 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100132 * WLED and BLED are not handled like other XLED, because in some dsdt
133 * they also control the WLAN/Bluetooth device.
134 */
135ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
136ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500137ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100138
Corentin Chary6b7091e2007-01-26 14:04:45 +0100139/* Brightness */
140ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
141ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
142
143/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500144ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
145 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
146 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
147 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
148 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
Torsten Krah4d0b856e2008-10-17 09:47:57 +0200149 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
Len Brown8def05f2007-01-30 01:46:43 -0500150 "\\_SB.PCI0.PX40.Q10", /* S1x */
151 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100152
Corentin Chary78127b42007-01-26 14:04:49 +0100153/* Display */
154ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Corentin Charybe966662009-08-29 10:28:29 +0200155ASUS_HANDLE(display_get,
156 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
157 "\\_SB.PCI0.P0P1.VGA.GETD",
158 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
159 "\\_SB.PCI0.P0P2.VGA.GETD",
160 /* A6V A6Q */
161 "\\_SB.PCI0.P0P3.VGA.GETD",
162 /* A6T, A6M */
163 "\\_SB.PCI0.P0PA.VGA.GETD",
164 /* L3C */
165 "\\_SB.PCI0.PCI1.VGAC.NMAP",
166 /* Z96F */
167 "\\_SB.PCI0.VGA.GETD",
168 /* A2D */
169 "\\ACTD",
170 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
171 "\\ADVG",
172 /* P30 */
173 "\\DNXT",
174 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
175 "\\INFB",
176 /* A3F A6F A3N A3L M6N W3N W6A */
177 "\\SSTE");
Corentin Chary78127b42007-01-26 14:04:49 +0100178
Corentin Charybe966662009-08-29 10:28:29 +0200179ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
180ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100181
Corentin Charye539c2f2007-05-06 14:47:06 +0200182/* GPS */
183/* R2H use different handle for GPS on/off */
Corentin Charyf3985322007-05-06 14:48:22 +0200184ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
185ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
Corentin Charye539c2f2007-05-06 14:47:06 +0200186ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
187
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000188/* Keyboard light */
189ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
190ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
191
Corentin Chary85091b72007-01-26 14:04:30 +0100192/*
193 * This is the main structure, we can use it to store anything interesting
194 * about the hotk device
195 */
196struct asus_hotk {
Corentin Charybe966662009-08-29 10:28:29 +0200197 char *name; /* laptop name */
198 struct acpi_device *device; /* the device we are in */
199 acpi_handle handle; /* the handle of the hotk device */
200 char status; /* status of the hotk, for LEDs, ... */
201 u32 ledd_status; /* status of the LED display */
202 u8 light_level; /* light sensor level */
203 u8 light_switch; /* light sensor switch value */
204 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary034ce902009-01-20 16:17:43 +0100205 struct input_dev *inputdev;
206 u16 *keycode_map;
Corentin Chary85091b72007-01-26 14:04:30 +0100207};
208
209/*
210 * This header is made available to allow proper configuration given model,
211 * revision number , ... this info cannot go in struct asus_hotk because it is
212 * available before the hotk
213 */
214static struct acpi_table_header *asus_info;
215
216/* The actual device the driver binds to */
217static struct asus_hotk *hotk;
218
219/*
220 * The hotkey driver declaration
221 */
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200222static const struct acpi_device_id asus_device_ids[] = {
223 {"ATK0100", 0},
224 {"", 0},
225};
226MODULE_DEVICE_TABLE(acpi, asus_device_ids);
227
Corentin Chary85091b72007-01-26 14:04:30 +0100228static int asus_hotk_add(struct acpi_device *device);
229static int asus_hotk_remove(struct acpi_device *device, int type);
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600230static void asus_hotk_notify(struct acpi_device *device, u32 event);
231
Corentin Chary85091b72007-01-26 14:04:30 +0100232static struct acpi_driver asus_hotk_driver = {
233 .name = ASUS_HOTK_NAME,
234 .class = ASUS_HOTK_CLASS,
Alan Jenkinsedf62452009-12-03 07:44:51 +0000235 .owner = THIS_MODULE,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200236 .ids = asus_device_ids,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600237 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Corentin Chary85091b72007-01-26 14:04:30 +0100238 .ops = {
239 .add = asus_hotk_add,
240 .remove = asus_hotk_remove,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600241 .notify = asus_hotk_notify,
Corentin Chary85091b72007-01-26 14:04:30 +0100242 },
243};
244
Corentin Chary6b7091e2007-01-26 14:04:45 +0100245/* The backlight device /sys/class/backlight */
246static struct backlight_device *asus_backlight_device;
247
248/*
249 * The backlight class declaration
250 */
251static int read_brightness(struct backlight_device *bd);
252static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000253static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500254 .get_brightness = read_brightness,
255 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100256};
257
Corentin Charybe966662009-08-29 10:28:29 +0200258/*
259 * These functions actually update the LED's, and are called from a
Corentin Charybe18cda2007-01-26 14:04:35 +0100260 * workqueue. By doing this as separate work rather than when the LED
261 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
Corentin Charybe966662009-08-29 10:28:29 +0200262 * potentially bad time, such as a timer interrupt.
263 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100264static struct workqueue_struct *led_workqueue;
265
Corentin Chary977c3282009-08-28 12:56:49 +0000266#define ASUS_LED(object, ledname, max) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100267 static void object##_led_set(struct led_classdev *led_cdev, \
268 enum led_brightness value); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000269 static enum led_brightness object##_led_get( \
270 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100271 static void object##_led_update(struct work_struct *ignored); \
272 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100273 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100274 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100275 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100276 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000277 .brightness_get = object##_led_get, \
Corentin Chary977c3282009-08-28 12:56:49 +0000278 .max_brightness = max \
Corentin Charybe18cda2007-01-26 14:04:35 +0100279 }
280
Corentin Chary977c3282009-08-28 12:56:49 +0000281ASUS_LED(mled, "mail", 1);
282ASUS_LED(tled, "touchpad", 1);
283ASUS_LED(rled, "record", 1);
284ASUS_LED(pled, "phone", 1);
285ASUS_LED(gled, "gaming", 1);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000286ASUS_LED(kled, "kbd_backlight", 3);
Corentin Charybe18cda2007-01-26 14:04:35 +0100287
Corentin Chary034ce902009-01-20 16:17:43 +0100288struct key_entry {
289 char type;
290 u8 code;
291 u16 keycode;
292};
293
294enum { KE_KEY, KE_END };
295
296static struct key_entry asus_keymap[] = {
297 {KE_KEY, 0x30, KEY_VOLUMEUP},
298 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
299 {KE_KEY, 0x32, KEY_MUTE},
300 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
301 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
302 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
303 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200304 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100305 {KE_KEY, 0x45, KEY_PLAYPAUSE},
Corentin Chary4644d0e2009-08-28 12:56:52 +0000306 {KE_KEY, 0x4c, KEY_MEDIA},
Corentin Chary034ce902009-01-20 16:17:43 +0100307 {KE_KEY, 0x50, KEY_EMAIL},
308 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary0aa20f72009-08-28 12:56:53 +0000309 {KE_KEY, 0x55, KEY_CALC},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200310 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100311 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000312 {KE_KEY, 0x5E, KEY_WLAN},
313 {KE_KEY, 0x5F, KEY_WLAN},
314 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100315 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
316 {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
317 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200318 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100319 {KE_KEY, 0x95, KEY_MEDIA},
320 {KE_KEY, 0x99, KEY_PHONE},
Corentin Charydc795262009-08-28 12:56:51 +0000321 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
322 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
Corentin Chary034ce902009-01-20 16:17:43 +0100323 {KE_END, 0},
324};
325
Corentin Chary85091b72007-01-26 14:04:30 +0100326/*
327 * This function evaluates an ACPI method, given an int as parameter, the
328 * method is searched within the scope of the handle, can be NULL. The output
329 * of the method is written is output, which can also be NULL
330 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100331 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100332 */
333static int write_acpi_int(acpi_handle handle, const char *method, int val,
334 struct acpi_buffer *output)
335{
Corentin Charybe966662009-08-29 10:28:29 +0200336 struct acpi_object_list params; /* list of input parameters (an int) */
337 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100338 acpi_status status;
339
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100340 if (!handle)
341 return 0;
342
Corentin Chary85091b72007-01-26 14:04:30 +0100343 params.count = 1;
344 params.pointer = &in_obj;
345 in_obj.type = ACPI_TYPE_INTEGER;
346 in_obj.integer.value = val;
347
348 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100349 if (status == AE_OK)
350 return 0;
351 else
352 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100353}
354
Len Brown8def05f2007-01-30 01:46:43 -0500355static int read_wireless_status(int mask)
356{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400357 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100358 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100359
360 if (!wireless_status_handle)
361 return (hotk->status & mask) ? 1 : 0;
362
Corentin Chary9a816852007-03-11 10:25:38 +0100363 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
364 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200365 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100366 else
367 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100368
369 return (hotk->status & mask) ? 1 : 0;
370}
371
Corentin Charyf3985322007-05-06 14:48:22 +0200372static int read_gps_status(void)
373{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400374 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200375 acpi_status rv = AE_OK;
376
377 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
378 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200379 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200380 else
Corentin Charyf3985322007-05-06 14:48:22 +0200381 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200382
Corentin Charyf3985322007-05-06 14:48:22 +0200383 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200384}
385
Corentin Charybe18cda2007-01-26 14:04:35 +0100386/* Generic LED functions */
387static int read_status(int mask)
388{
Corentin Chary4564de12007-01-26 14:04:40 +0100389 /* There is a special method for both wireless devices */
390 if (mask == BT_ON || mask == WL_ON)
391 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200392 else if (mask == GPS_ON)
393 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100394
Corentin Charybe18cda2007-01-26 14:04:35 +0100395 return (hotk->status & mask) ? 1 : 0;
396}
397
Corentin Chary935ffee2007-03-11 10:26:12 +0100398static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100399{
400 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
401
Corentin Chary935ffee2007-03-11 10:26:12 +0100402 switch (mask) {
403 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100404 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100405 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100406 case GLED_ON:
407 out = (out & 0x1) + 1;
408 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200409 case GPS_ON:
410 handle = (out) ? gps_on_handle : gps_off_handle;
411 out = 0x02;
412 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100413 default:
414 out &= 0x1;
415 break;
416 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100417
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100418 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200419 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100420}
421
422/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100423#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100424 static void object##_led_set(struct led_classdev *led_cdev, \
425 enum led_brightness value) \
426 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200427 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100428 queue_work(led_workqueue, &object##_led_work); \
429 } \
430 static void object##_led_update(struct work_struct *ignored) \
431 { \
432 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100433 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000434 } \
435 static enum led_brightness object##_led_get( \
436 struct led_classdev *led_cdev) \
437 { \
438 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100439 }
440
Corentin Chary935ffee2007-03-11 10:26:12 +0100441ASUS_LED_HANDLER(mled, MLED_ON);
442ASUS_LED_HANDLER(pled, PLED_ON);
443ASUS_LED_HANDLER(rled, RLED_ON);
444ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100445ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100446
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000447/*
448 * Keyboard backlight
449 */
450static int get_kled_lvl(void)
451{
452 unsigned long long kblv;
453 struct acpi_object_list params;
454 union acpi_object in_obj;
455 acpi_status rv;
456
457 params.count = 1;
458 params.pointer = &in_obj;
459 in_obj.type = ACPI_TYPE_INTEGER;
460 in_obj.integer.value = 2;
461
462 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
463 if (ACPI_FAILURE(rv)) {
464 pr_warning("Error reading kled level\n");
465 return 0;
466 }
467 return kblv;
468}
469
470static int set_kled_lvl(int kblv)
471{
472 if (kblv > 0)
473 kblv = (1 << 7) | (kblv & 0x7F);
474 else
475 kblv = 0;
476
477 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
478 pr_warning("Keyboard LED display write failed\n");
479 return -EINVAL;
480 }
481 return 0;
482}
483
484static void kled_led_set(struct led_classdev *led_cdev,
485 enum led_brightness value)
486{
487 kled_led_wk = value;
488 queue_work(led_workqueue, &kled_led_work);
489}
490
491static void kled_led_update(struct work_struct *ignored)
492{
493 set_kled_lvl(kled_led_wk);
494}
495
496static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
497{
498 return get_kled_lvl();
499}
500
Corentin Chary6b7091e2007-01-26 14:04:45 +0100501static int get_lcd_state(void)
502{
503 return read_status(LCD_ON);
504}
505
506static int set_lcd_state(int value)
507{
508 int lcd = 0;
509 acpi_status status = 0;
510
511 lcd = value ? 1 : 0;
512
513 if (lcd == get_lcd_state())
514 return 0;
515
Len Brown8def05f2007-01-30 01:46:43 -0500516 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100517 status = acpi_evaluate_object(lcd_switch_handle,
518 NULL, NULL, NULL);
519
520 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200521 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100522 }
523
Corentin Chary935ffee2007-03-11 10:26:12 +0100524 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100525 return 0;
526}
527
528static void lcd_blank(int blank)
529{
530 struct backlight_device *bd = asus_backlight_device;
531
Len Brown8def05f2007-01-30 01:46:43 -0500532 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000533 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000534 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100535 }
536}
537
538static int read_brightness(struct backlight_device *bd)
539{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400540 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100541 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100542
Corentin Chary9a816852007-03-11 10:25:38 +0100543 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
544 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200545 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100546
547 return value;
548}
549
550static int set_brightness(struct backlight_device *bd, int value)
551{
552 int ret = 0;
553
554 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
555 /* 0 <= value <= 15 */
556
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100557 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200558 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100559 ret = -EIO;
560 }
561
562 return ret;
563}
564
565static int update_bl_status(struct backlight_device *bd)
566{
567 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000568 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100569
570 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500571 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100572 return rv;
573
Richard Purdie599a52d2007-02-10 23:07:48 +0000574 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100575 return set_lcd_state(value);
576}
577
Corentin Chary85091b72007-01-26 14:04:30 +0100578/*
579 * Platform device handlers
580 */
581
582/*
583 * We write our info in page, we begin at offset off and cannot write more
584 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
585 * number of bytes written in page
586 */
587static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500588 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100589{
590 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400591 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200592 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100593 acpi_status rv = AE_OK;
594
Corentin Chary85091b72007-01-26 14:04:30 +0100595 /*
596 * We use the easy way, we don't care of off and count, so we don't set eof
597 * to 1
598 */
599
600 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
601 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
602 /*
603 * The SFUN method probably allows the original driver to get the list
604 * of features supported by a given model. For now, 0x0100 or 0x0800
605 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
606 * The significance of others is yet to be found.
607 */
Corentin Chary9a816852007-03-11 10:25:38 +0100608 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
609 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000610 len += sprintf(page + len, "SFUN value : %#x\n",
611 (uint) temp);
612 /*
613 * The HWRS method return informations about the hardware.
614 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
615 * The significance of others is yet to be found.
616 * If we don't find the method, we assume the device are present.
617 */
618 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
619 if (!ACPI_FAILURE(rv))
620 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100621 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100622 /*
623 * Another value for userspace: the ASYM method returns 0x02 for
624 * battery low and 0x04 for battery critical, its readings tend to be
625 * more accurate than those provided by _BST.
626 * Note: since not all the laptops provide this method, errors are
627 * silently ignored.
628 */
Corentin Chary9a816852007-03-11 10:25:38 +0100629 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
630 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000631 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100632 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100633 if (asus_info) {
634 snprintf(buf, 16, "%d", asus_info->length);
635 len += sprintf(page + len, "DSDT length : %s\n", buf);
636 snprintf(buf, 16, "%d", asus_info->checksum);
637 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
638 snprintf(buf, 16, "%d", asus_info->revision);
639 len += sprintf(page + len, "DSDT revision : %s\n", buf);
640 snprintf(buf, 7, "%s", asus_info->oem_id);
641 len += sprintf(page + len, "OEM id : %s\n", buf);
642 snprintf(buf, 9, "%s", asus_info->oem_table_id);
643 len += sprintf(page + len, "OEM table id : %s\n", buf);
644 snprintf(buf, 16, "%x", asus_info->oem_revision);
645 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
646 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
647 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
648 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
649 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
650 }
651
652 return len;
653}
654
655static int parse_arg(const char *buf, unsigned long count, int *val)
656{
657 if (!count)
658 return 0;
659 if (count > 31)
660 return -EINVAL;
661 if (sscanf(buf, "%i", val) != 1)
662 return -EINVAL;
663 return count;
664}
665
Corentin Chary4564de12007-01-26 14:04:40 +0100666static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100667 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100668{
669 int rv, value;
670 int out = 0;
671
672 rv = parse_arg(buf, count, &value);
673 if (rv > 0)
674 out = value ? 1 : 0;
675
Corentin Chary935ffee2007-03-11 10:26:12 +0100676 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100677
678 return rv;
679}
680
681/*
Corentin Chary722ad972007-01-26 14:04:55 +0100682 * LEDD display
683 */
684static ssize_t show_ledd(struct device *dev,
685 struct device_attribute *attr, char *buf)
686{
687 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
688}
689
690static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
691 const char *buf, size_t count)
692{
693 int rv, value;
694
695 rv = parse_arg(buf, count, &value);
696 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100697 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200698 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100699 else
700 hotk->ledd_status = (u32) value;
701 }
702 return rv;
703}
704
705/*
Corentin Chary4564de12007-01-26 14:04:40 +0100706 * WLAN
707 */
708static ssize_t show_wlan(struct device *dev,
709 struct device_attribute *attr, char *buf)
710{
711 return sprintf(buf, "%d\n", read_status(WL_ON));
712}
713
714static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
715 const char *buf, size_t count)
716{
Corentin Chary935ffee2007-03-11 10:26:12 +0100717 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100718}
719
720/*
721 * Bluetooth
722 */
723static ssize_t show_bluetooth(struct device *dev,
724 struct device_attribute *attr, char *buf)
725{
726 return sprintf(buf, "%d\n", read_status(BT_ON));
727}
728
Len Brown8def05f2007-01-30 01:46:43 -0500729static ssize_t store_bluetooth(struct device *dev,
730 struct device_attribute *attr, const char *buf,
731 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100732{
Corentin Chary935ffee2007-03-11 10:26:12 +0100733 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100734}
735
Corentin Chary78127b42007-01-26 14:04:49 +0100736/*
737 * Display
738 */
739static void set_display(int value)
740{
741 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100742 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200743 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100744 return;
745}
746
747static int read_display(void)
748{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400749 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100750 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100751
Corentin Charybe966662009-08-29 10:28:29 +0200752 /*
753 * In most of the case, we know how to set the display, but sometime
754 * we can't read it
755 */
Len Brown8def05f2007-01-30 01:46:43 -0500756 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100757 rv = acpi_evaluate_integer(display_get_handle, NULL,
758 NULL, &value);
759 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200760 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100761 }
762
763 value &= 0x0F; /* needed for some models, shouldn't hurt others */
764
765 return value;
766}
Len Brown8def05f2007-01-30 01:46:43 -0500767
Corentin Chary78127b42007-01-26 14:04:49 +0100768/*
769 * Now, *this* one could be more user-friendly, but so far, no-one has
770 * complained. The significance of bits is the same as in store_disp()
771 */
772static ssize_t show_disp(struct device *dev,
773 struct device_attribute *attr, char *buf)
774{
775 return sprintf(buf, "%d\n", read_display());
776}
777
778/*
779 * Experimental support for display switching. As of now: 1 should activate
780 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
781 * Any combination (bitwise) of these will suffice. I never actually tested 4
782 * displays hooked up simultaneously, so be warned. See the acpi4asus README
783 * for more info.
784 */
785static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
786 const char *buf, size_t count)
787{
788 int rv, value;
789
790 rv = parse_arg(buf, count, &value);
791 if (rv > 0)
792 set_display(value);
793 return rv;
794}
795
Corentin Chary8b857352007-01-26 14:04:58 +0100796/*
797 * Light Sens
798 */
799static void set_light_sens_switch(int value)
800{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100801 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200802 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100803 hotk->light_switch = value;
804}
805
806static ssize_t show_lssw(struct device *dev,
807 struct device_attribute *attr, char *buf)
808{
809 return sprintf(buf, "%d\n", hotk->light_switch);
810}
811
812static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
813 const char *buf, size_t count)
814{
815 int rv, value;
816
817 rv = parse_arg(buf, count, &value);
818 if (rv > 0)
819 set_light_sens_switch(value ? 1 : 0);
820
821 return rv;
822}
823
824static void set_light_sens_level(int value)
825{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100826 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200827 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100828 hotk->light_level = value;
829}
830
831static ssize_t show_lslvl(struct device *dev,
832 struct device_attribute *attr, char *buf)
833{
834 return sprintf(buf, "%d\n", hotk->light_level);
835}
836
837static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
838 const char *buf, size_t count)
839{
840 int rv, value;
841
842 rv = parse_arg(buf, count, &value);
843 if (rv > 0) {
844 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
845 /* 0 <= value <= 15 */
846 set_light_sens_level(value);
847 }
848
849 return rv;
850}
851
Corentin Charye539c2f2007-05-06 14:47:06 +0200852/*
853 * GPS
854 */
855static ssize_t show_gps(struct device *dev,
856 struct device_attribute *attr, char *buf)
857{
858 return sprintf(buf, "%d\n", read_status(GPS_ON));
859}
860
861static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
862 const char *buf, size_t count)
863{
Corentin Charyf3985322007-05-06 14:48:22 +0200864 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200865}
866
Corentin Chary034ce902009-01-20 16:17:43 +0100867/*
868 * Hotkey functions
869 */
870static struct key_entry *asus_get_entry_by_scancode(int code)
871{
872 struct key_entry *key;
873
874 for (key = asus_keymap; key->type != KE_END; key++)
875 if (code == key->code)
876 return key;
877
878 return NULL;
879}
880
881static struct key_entry *asus_get_entry_by_keycode(int code)
882{
883 struct key_entry *key;
884
885 for (key = asus_keymap; key->type != KE_END; key++)
886 if (code == key->keycode && key->type == KE_KEY)
887 return key;
888
889 return NULL;
890}
891
892static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
893{
894 struct key_entry *key = asus_get_entry_by_scancode(scancode);
895
896 if (key && key->type == KE_KEY) {
897 *keycode = key->keycode;
898 return 0;
899 }
900
901 return -EINVAL;
902}
903
904static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
905{
906 struct key_entry *key;
907 int old_keycode;
908
909 if (keycode < 0 || keycode > KEY_MAX)
910 return -EINVAL;
911
912 key = asus_get_entry_by_scancode(scancode);
913 if (key && key->type == KE_KEY) {
914 old_keycode = key->keycode;
915 key->keycode = keycode;
916 set_bit(keycode, dev->keybit);
917 if (!asus_get_entry_by_keycode(old_keycode))
918 clear_bit(old_keycode, dev->keybit);
919 return 0;
920 }
921
922 return -EINVAL;
923}
924
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600925static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100926{
Corentin Chary034ce902009-01-20 16:17:43 +0100927 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100928 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100929
Corentin Chary85091b72007-01-26 14:04:30 +0100930 /* TODO Find a better way to handle events count. */
931 if (!hotk)
932 return;
933
Corentin Chary6b7091e2007-01-26 14:04:45 +0100934 /*
935 * We need to tell the backlight device when the backlight power is
936 * switched
937 */
938 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100939 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100940 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500941 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100942 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100943 lcd_blank(FB_BLANK_POWERDOWN);
944 }
945
Corentin Chary6050c8d2009-02-15 19:30:19 +0100946 count = hotk->event_count[event % 128]++;
947 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100948 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
949 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100950 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100951
Corentin Chary034ce902009-01-20 16:17:43 +0100952 if (hotk->inputdev) {
953 key = asus_get_entry_by_scancode(event);
954 if (!key)
955 return ;
956
957 switch (key->type) {
958 case KE_KEY:
959 input_report_key(hotk->inputdev, key->keycode, 1);
960 input_sync(hotk->inputdev);
961 input_report_key(hotk->inputdev, key->keycode, 0);
962 input_sync(hotk->inputdev);
963 break;
964 }
965 }
Corentin Chary85091b72007-01-26 14:04:30 +0100966}
967
968#define ASUS_CREATE_DEVICE_ATTR(_name) \
969 struct device_attribute dev_attr_##_name = { \
970 .attr = { \
971 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900972 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100973 .show = NULL, \
974 .store = NULL, \
975 }
976
977#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
978 do { \
979 dev_attr_##_name.attr.mode = _mode; \
980 dev_attr_##_name.show = _show; \
981 dev_attr_##_name.store = _store; \
982 } while(0)
983
984static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100985static ASUS_CREATE_DEVICE_ATTR(wlan);
986static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100987static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100988static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100989static ASUS_CREATE_DEVICE_ATTR(ls_switch);
990static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200991static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100992
993static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500994 &dev_attr_infos.attr,
995 &dev_attr_wlan.attr,
996 &dev_attr_bluetooth.attr,
997 &dev_attr_display.attr,
998 &dev_attr_ledd.attr,
999 &dev_attr_ls_switch.attr,
1000 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +02001001 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -05001002 NULL
Corentin Chary85091b72007-01-26 14:04:30 +01001003};
1004
1005static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -05001006 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +01001007};
1008
1009static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001010 .driver = {
1011 .name = ASUS_HOTK_FILE,
1012 .owner = THIS_MODULE,
1013 }
Corentin Chary85091b72007-01-26 14:04:30 +01001014};
1015
1016static struct platform_device *asuspf_device;
1017
Corentin Chary85091b72007-01-26 14:04:30 +01001018static void asus_hotk_add_fs(void)
1019{
1020 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +01001021
1022 if (wl_switch_handle)
1023 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1024
1025 if (bt_switch_handle)
1026 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1027 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001028
1029 if (display_set_handle && display_get_handle)
1030 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -05001031 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +01001032 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1033
Corentin Chary722ad972007-01-26 14:04:55 +01001034 if (ledd_set_handle)
1035 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1036
Corentin Chary8b857352007-01-26 14:04:58 +01001037 if (ls_switch_handle && ls_level_handle) {
1038 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1039 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1040 }
Corentin Charye539c2f2007-05-06 14:47:06 +02001041
Corentin Charyf3985322007-05-06 14:48:22 +02001042 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +02001043 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001044}
1045
Len Brown8def05f2007-01-30 01:46:43 -05001046static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001047 char **paths, int num_paths)
1048{
1049 int i;
1050 acpi_status status;
1051
1052 for (i = 0; i < num_paths; i++) {
1053 status = acpi_get_handle(NULL, paths[i], handle);
1054 if (ACPI_SUCCESS(status))
1055 return 0;
1056 }
1057
1058 *handle = NULL;
1059 return -ENODEV;
1060}
1061
1062#define ASUS_HANDLE_INIT(object) \
1063 asus_handle_init(#object, &object##_handle, object##_paths, \
1064 ARRAY_SIZE(object##_paths))
1065
Corentin Chary85091b72007-01-26 14:04:30 +01001066/*
1067 * This function is used to initialize the hotk with right values. In this
1068 * method, we can make all the detection we want, and modify the hotk struct
1069 */
1070static int asus_hotk_get_info(void)
1071{
1072 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001073 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001074 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001075 char *string = NULL;
1076 acpi_status status;
1077
1078 /*
1079 * Get DSDT headers early enough to allow for differentiating between
1080 * models, but late enough to allow acpi_bus_register_driver() to fail
1081 * before doing anything ACPI-specific. Should we encounter a machine,
1082 * which needs special handling (i.e. its hotkey device has a different
1083 * HID), this bit will be moved. A global variable asus_info contains
1084 * the DSDT header.
1085 */
Len Brown894d79b2007-02-03 02:13:53 -05001086 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001087 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001088 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001089
1090 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +01001091 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001092 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001093 return -ENODEV;
1094 }
1095
1096 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001097 status =
1098 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1099 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001100 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001101 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001102 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001103 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001104
Corentin Chary185e5af2007-03-11 10:27:33 +01001105 /* This too ... */
1106 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1107
Corentin Chary85091b72007-01-26 14:04:30 +01001108 /*
1109 * Try to match the object returned by INIT to the specific model.
1110 * Handle every possible object (or the lack of thereof) the DSDT
1111 * writers might throw at us. When in trouble, we pass NULL to
1112 * asus_model_match() and try something completely different.
1113 */
1114 if (buffer.pointer) {
1115 model = buffer.pointer;
1116 switch (model->type) {
1117 case ACPI_TYPE_STRING:
1118 string = model->string.pointer;
1119 break;
1120 case ACPI_TYPE_BUFFER:
1121 string = model->buffer.pointer;
1122 break;
1123 default:
1124 string = "";
1125 break;
1126 }
1127 }
1128 hotk->name = kstrdup(string, GFP_KERNEL);
1129 if (!hotk->name)
1130 return -ENOMEM;
1131
Len Brown8def05f2007-01-30 01:46:43 -05001132 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001133 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001134
Corentin Charybe18cda2007-01-26 14:04:35 +01001135 ASUS_HANDLE_INIT(mled_set);
1136 ASUS_HANDLE_INIT(tled_set);
1137 ASUS_HANDLE_INIT(rled_set);
1138 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001139 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001140
Corentin Chary722ad972007-01-26 14:04:55 +01001141 ASUS_HANDLE_INIT(ledd_set);
1142
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001143 ASUS_HANDLE_INIT(kled_set);
1144 ASUS_HANDLE_INIT(kled_get);
1145
Corentin Chary4564de12007-01-26 14:04:40 +01001146 /*
1147 * The HWRS method return informations about the hardware.
1148 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1149 * The significance of others is yet to be found.
1150 * If we don't find the method, we assume the device are present.
1151 */
Corentin Chary9a816852007-03-11 10:25:38 +01001152 status =
1153 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1154 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001155 hwrs_result = WL_HWRS | BT_HWRS;
1156
Len Brown8def05f2007-01-30 01:46:43 -05001157 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001158 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001159 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001160 ASUS_HANDLE_INIT(bt_switch);
1161
1162 ASUS_HANDLE_INIT(wireless_status);
1163
Corentin Chary6b7091e2007-01-26 14:04:45 +01001164 ASUS_HANDLE_INIT(brightness_set);
1165 ASUS_HANDLE_INIT(brightness_get);
1166
1167 ASUS_HANDLE_INIT(lcd_switch);
1168
Corentin Chary78127b42007-01-26 14:04:49 +01001169 ASUS_HANDLE_INIT(display_set);
1170 ASUS_HANDLE_INIT(display_get);
1171
Corentin Charybe966662009-08-29 10:28:29 +02001172 /*
1173 * There is a lot of models with "ALSL", but a few get
1174 * a real light sens, so we need to check it.
1175 */
Corentin Chary832d9952007-05-06 14:47:29 +02001176 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001177 ASUS_HANDLE_INIT(ls_level);
1178
Corentin Charye539c2f2007-05-06 14:47:06 +02001179 ASUS_HANDLE_INIT(gps_on);
1180 ASUS_HANDLE_INIT(gps_off);
1181 ASUS_HANDLE_INIT(gps_status);
1182
Corentin Chary85091b72007-01-26 14:04:30 +01001183 kfree(model);
1184
1185 return AE_OK;
1186}
1187
Corentin Chary034ce902009-01-20 16:17:43 +01001188static int asus_input_init(void)
1189{
1190 const struct key_entry *key;
1191 int result;
1192
1193 hotk->inputdev = input_allocate_device();
1194 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001195 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001196 return 0;
1197 }
1198 hotk->inputdev->name = "Asus Laptop extra buttons";
1199 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1200 hotk->inputdev->id.bustype = BUS_HOST;
1201 hotk->inputdev->getkeycode = asus_getkeycode;
1202 hotk->inputdev->setkeycode = asus_setkeycode;
1203
1204 for (key = asus_keymap; key->type != KE_END; key++) {
1205 switch (key->type) {
1206 case KE_KEY:
1207 set_bit(EV_KEY, hotk->inputdev->evbit);
1208 set_bit(key->keycode, hotk->inputdev->keybit);
1209 break;
1210 }
1211 }
1212 result = input_register_device(hotk->inputdev);
1213 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001214 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001215 input_free_device(hotk->inputdev);
1216 }
1217 return result;
1218}
1219
Corentin Chary85091b72007-01-26 14:04:30 +01001220static int asus_hotk_check(void)
1221{
1222 int result = 0;
1223
1224 result = acpi_bus_get_status(hotk->device);
1225 if (result)
1226 return result;
1227
1228 if (hotk->device->status.present) {
1229 result = asus_hotk_get_info();
1230 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001231 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001232 return -EINVAL;
1233 }
1234
1235 return result;
1236}
1237
1238static int asus_hotk_found;
1239
1240static int asus_hotk_add(struct acpi_device *device)
1241{
Corentin Chary85091b72007-01-26 14:04:30 +01001242 int result;
1243
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001244 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001245 ASUS_LAPTOP_VERSION);
1246
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001247 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001248 if (!hotk)
1249 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001250
1251 hotk->handle = device->handle;
1252 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1253 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001254 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001255 hotk->device = device;
1256
1257 result = asus_hotk_check();
1258 if (result)
1259 goto end;
1260
1261 asus_hotk_add_fs();
1262
Corentin Chary85091b72007-01-26 14:04:30 +01001263 asus_hotk_found = 1;
1264
Corentin Chary6b7091e2007-01-26 14:04:45 +01001265 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001266 write_status(bt_switch_handle, 1, BT_ON);
1267 write_status(wl_switch_handle, 1, WL_ON);
1268
1269 /* If the h/w switch is off, we need to check the real status */
1270 write_status(NULL, read_status(BT_ON), BT_ON);
1271 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001272
Corentin Chary6b7091e2007-01-26 14:04:45 +01001273 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001274 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001275
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001276 /* Keyboard Backlight is on by default */
1277 if (kled_set_handle)
1278 set_kled_lvl(1);
1279
Corentin Chary722ad972007-01-26 14:04:55 +01001280 /* LED display is off by default */
1281 hotk->ledd_status = 0xFFF;
1282
Len Brown8def05f2007-01-30 01:46:43 -05001283 /* Set initial values of light sensor and level */
1284 hotk->light_switch = 1; /* Default to light sensor disabled */
1285 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001286
Len Brown8def05f2007-01-30 01:46:43 -05001287 if (ls_switch_handle)
1288 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001289
Len Brown8def05f2007-01-30 01:46:43 -05001290 if (ls_level_handle)
1291 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001292
Corentin Charye539c2f2007-05-06 14:47:06 +02001293 /* GPS is on by default */
1294 write_status(NULL, 1, GPS_ON);
1295
Corentin Charyed6f4422009-01-20 16:17:45 +01001296end:
Corentin Chary85091b72007-01-26 14:04:30 +01001297 if (result) {
1298 kfree(hotk->name);
1299 kfree(hotk);
1300 }
1301
1302 return result;
1303}
1304
1305static int asus_hotk_remove(struct acpi_device *device, int type)
1306{
Corentin Chary85091b72007-01-26 14:04:30 +01001307 kfree(hotk->name);
1308 kfree(hotk);
1309
1310 return 0;
1311}
1312
Corentin Chary6b7091e2007-01-26 14:04:45 +01001313static void asus_backlight_exit(void)
1314{
Len Brown8def05f2007-01-30 01:46:43 -05001315 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001316 backlight_device_unregister(asus_backlight_device);
1317}
1318
Corentin Charybe18cda2007-01-26 14:04:35 +01001319#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a692007-08-16 18:18:53 +02001320 if (object##_led.dev) \
1321 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001322
1323static void asus_led_exit(void)
1324{
Al Viro3b0d7112007-07-23 11:21:34 +01001325 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001326 ASUS_LED_UNREGISTER(mled);
1327 ASUS_LED_UNREGISTER(tled);
1328 ASUS_LED_UNREGISTER(pled);
1329 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001330 ASUS_LED_UNREGISTER(gled);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001331 ASUS_LED_UNREGISTER(kled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001332}
1333
Corentin Chary034ce902009-01-20 16:17:43 +01001334static void asus_input_exit(void)
1335{
1336 if (hotk->inputdev)
1337 input_unregister_device(hotk->inputdev);
1338}
1339
Corentin Chary85091b72007-01-26 14:04:30 +01001340static void __exit asus_laptop_exit(void)
1341{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001342 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001343 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001344 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001345
Corentin Chary85091b72007-01-26 14:04:30 +01001346 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001347 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1348 platform_device_unregister(asuspf_device);
1349 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001350}
1351
Len Brown8def05f2007-01-30 01:46:43 -05001352static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001353{
1354 struct backlight_device *bd;
1355
Len Brown8def05f2007-01-30 01:46:43 -05001356 if (brightness_set_handle && lcd_switch_handle) {
1357 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001358 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001359 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001360 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001361 asus_backlight_device = NULL;
1362 return PTR_ERR(bd);
1363 }
1364
1365 asus_backlight_device = bd;
1366
Richard Purdie599a52d2007-02-10 23:07:48 +00001367 bd->props.max_brightness = 15;
1368 bd->props.brightness = read_brightness(NULL);
1369 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001370 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001371 }
1372 return 0;
1373}
1374
Corentin Charybe18cda2007-01-26 14:04:35 +01001375static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001376 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001377{
Len Brown8def05f2007-01-30 01:46:43 -05001378 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001379 return 0;
1380
1381 return led_classdev_register(dev, ldev);
1382}
Len Brown8def05f2007-01-30 01:46:43 -05001383
Corentin Charybe18cda2007-01-26 14:04:35 +01001384#define ASUS_LED_REGISTER(object, device) \
1385 asus_led_register(object##_set_handle, &object##_led, device)
1386
Len Brown8def05f2007-01-30 01:46:43 -05001387static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001388{
1389 int rv;
1390
1391 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001392 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001393 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001394
1395 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001396 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001397 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001398
1399 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001400 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001401 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001402
1403 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001404 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001405 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001406
Corentin Charyfdd8d082007-03-11 10:26:48 +01001407 rv = ASUS_LED_REGISTER(gled, dev);
1408 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001409 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001410
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001411 if (kled_set_handle && kled_get_handle)
1412 rv = ASUS_LED_REGISTER(kled, dev);
1413 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001414 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001415
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001416 led_workqueue = create_singlethread_workqueue("led_workqueue");
1417 if (!led_workqueue)
1418 goto out6;
1419
Corentin Charybe18cda2007-01-26 14:04:35 +01001420 return 0;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001421out6:
Al Viro3b0d7112007-07-23 11:21:34 +01001422 rv = -ENOMEM;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001423 ASUS_LED_UNREGISTER(kled);
1424out5:
Al Viro3b0d7112007-07-23 11:21:34 +01001425 ASUS_LED_UNREGISTER(gled);
1426out4:
1427 ASUS_LED_UNREGISTER(pled);
1428out3:
1429 ASUS_LED_UNREGISTER(rled);
1430out2:
1431 ASUS_LED_UNREGISTER(tled);
1432out1:
1433 ASUS_LED_UNREGISTER(mled);
1434out:
1435 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001436}
1437
Corentin Chary85091b72007-01-26 14:04:30 +01001438static int __init asus_laptop_init(void)
1439{
1440 int result;
1441
Corentin Chary85091b72007-01-26 14:04:30 +01001442 result = acpi_bus_register_driver(&asus_hotk_driver);
1443 if (result < 0)
1444 return result;
1445
1446 /*
1447 * This is a bit of a kludge. We only want this module loaded
1448 * for ASUS systems, but there's currently no way to probe the
1449 * ACPI namespace for ASUS HIDs. So we just return failure if
1450 * we didn't find one, which will cause the module to be
1451 * unloaded.
1452 */
1453 if (!asus_hotk_found) {
1454 acpi_bus_unregister_driver(&asus_hotk_driver);
1455 return -ENODEV;
1456 }
1457
Corentin Chary034ce902009-01-20 16:17:43 +01001458 result = asus_input_init();
1459 if (result)
1460 goto fail_input;
1461
Len Brown8def05f2007-01-30 01:46:43 -05001462 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001463 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001464 if (result)
1465 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001466
Len Brown8def05f2007-01-30 01:46:43 -05001467 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1468 if (!asuspf_device) {
1469 result = -ENOMEM;
1470 goto fail_platform_device1;
1471 }
Corentin Chary85091b72007-01-26 14:04:30 +01001472
Len Brown8def05f2007-01-30 01:46:43 -05001473 result = platform_device_add(asuspf_device);
1474 if (result)
1475 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001476
Len Brown8def05f2007-01-30 01:46:43 -05001477 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001478 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001479 if (result)
1480 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001481
Corentin Chary116bf2e2009-06-16 19:28:46 +00001482 result = asus_led_init(&asuspf_device->dev);
1483 if (result)
1484 goto fail_led;
1485
1486 if (!acpi_video_backlight_support()) {
1487 result = asus_backlight_init(&asuspf_device->dev);
1488 if (result)
1489 goto fail_backlight;
1490 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001491 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001492 "ACPI video driver\n");
1493
Len Brown8def05f2007-01-30 01:46:43 -05001494 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001495
Corentin Chary116bf2e2009-06-16 19:28:46 +00001496fail_backlight:
1497 asus_led_exit();
1498
1499fail_led:
1500 sysfs_remove_group(&asuspf_device->dev.kobj,
1501 &asuspf_attribute_group);
1502
Corentin Charyed6f4422009-01-20 16:17:45 +01001503fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001504 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001505
Corentin Charyed6f4422009-01-20 16:17:45 +01001506fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001507 platform_device_put(asuspf_device);
1508
Corentin Charyed6f4422009-01-20 16:17:45 +01001509fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001510 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001511
Corentin Charyed6f4422009-01-20 16:17:45 +01001512fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001513 asus_input_exit();
1514
Corentin Charyed6f4422009-01-20 16:17:45 +01001515fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001516
1517 return result;
1518}
1519
1520module_init(asus_laptop_init);
1521module_exit(asus_laptop_exit);