blob: 83948dff24192546e868fc0fea54b6f0df77299b [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},
Ike Panhc14f8af32009-12-03 07:45:11 +0000224 {"ATK0101", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200225 {"", 0},
226};
227MODULE_DEVICE_TABLE(acpi, asus_device_ids);
228
Corentin Chary85091b72007-01-26 14:04:30 +0100229static int asus_hotk_add(struct acpi_device *device);
230static int asus_hotk_remove(struct acpi_device *device, int type);
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600231static void asus_hotk_notify(struct acpi_device *device, u32 event);
232
Corentin Chary85091b72007-01-26 14:04:30 +0100233static struct acpi_driver asus_hotk_driver = {
234 .name = ASUS_HOTK_NAME,
235 .class = ASUS_HOTK_CLASS,
Alan Jenkinsedf62452009-12-03 07:44:51 +0000236 .owner = THIS_MODULE,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200237 .ids = asus_device_ids,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600238 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Corentin Chary85091b72007-01-26 14:04:30 +0100239 .ops = {
240 .add = asus_hotk_add,
241 .remove = asus_hotk_remove,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600242 .notify = asus_hotk_notify,
Corentin Chary85091b72007-01-26 14:04:30 +0100243 },
244};
245
Corentin Chary6b7091e2007-01-26 14:04:45 +0100246/* The backlight device /sys/class/backlight */
247static struct backlight_device *asus_backlight_device;
248
249/*
250 * The backlight class declaration
251 */
252static int read_brightness(struct backlight_device *bd);
253static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000254static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500255 .get_brightness = read_brightness,
256 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100257};
258
Corentin Charybe966662009-08-29 10:28:29 +0200259/*
260 * These functions actually update the LED's, and are called from a
Corentin Charybe18cda2007-01-26 14:04:35 +0100261 * workqueue. By doing this as separate work rather than when the LED
262 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
Corentin Charybe966662009-08-29 10:28:29 +0200263 * potentially bad time, such as a timer interrupt.
264 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100265static struct workqueue_struct *led_workqueue;
266
Corentin Chary977c3282009-08-28 12:56:49 +0000267#define ASUS_LED(object, ledname, max) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100268 static void object##_led_set(struct led_classdev *led_cdev, \
269 enum led_brightness value); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000270 static enum led_brightness object##_led_get( \
271 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100272 static void object##_led_update(struct work_struct *ignored); \
273 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100274 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100275 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100276 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100277 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000278 .brightness_get = object##_led_get, \
Corentin Chary977c3282009-08-28 12:56:49 +0000279 .max_brightness = max \
Corentin Charybe18cda2007-01-26 14:04:35 +0100280 }
281
Corentin Chary977c3282009-08-28 12:56:49 +0000282ASUS_LED(mled, "mail", 1);
283ASUS_LED(tled, "touchpad", 1);
284ASUS_LED(rled, "record", 1);
285ASUS_LED(pled, "phone", 1);
286ASUS_LED(gled, "gaming", 1);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000287ASUS_LED(kled, "kbd_backlight", 3);
Corentin Charybe18cda2007-01-26 14:04:35 +0100288
Corentin Chary034ce902009-01-20 16:17:43 +0100289struct key_entry {
290 char type;
291 u8 code;
292 u16 keycode;
293};
294
295enum { KE_KEY, KE_END };
296
297static struct key_entry asus_keymap[] = {
Ike Panhc14f8af32009-12-03 07:45:11 +0000298 {KE_KEY, 0x02, KEY_SCREENLOCK},
299 {KE_KEY, 0x05, KEY_WLAN},
300 {KE_KEY, 0x08, KEY_F13},
301 {KE_KEY, 0x17, KEY_ZOOM},
302 {KE_KEY, 0x1f, KEY_BATTERY},
Corentin Chary034ce902009-01-20 16:17:43 +0100303 {KE_KEY, 0x30, KEY_VOLUMEUP},
304 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
305 {KE_KEY, 0x32, KEY_MUTE},
306 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
307 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
308 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
309 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200310 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100311 {KE_KEY, 0x45, KEY_PLAYPAUSE},
Corentin Chary4644d0e2009-08-28 12:56:52 +0000312 {KE_KEY, 0x4c, KEY_MEDIA},
Corentin Chary034ce902009-01-20 16:17:43 +0100313 {KE_KEY, 0x50, KEY_EMAIL},
314 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary0aa20f72009-08-28 12:56:53 +0000315 {KE_KEY, 0x55, KEY_CALC},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200316 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100317 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000318 {KE_KEY, 0x5E, KEY_WLAN},
319 {KE_KEY, 0x5F, KEY_WLAN},
320 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100321 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
Ike Panhc14f8af32009-12-03 07:45:11 +0000322 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE},
323 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE},
Corentin Chary16851f92009-12-03 07:45:10 +0000324 {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */
Corentin Chary034ce902009-01-20 16:17:43 +0100325 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200326 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100327 {KE_KEY, 0x95, KEY_MEDIA},
328 {KE_KEY, 0x99, KEY_PHONE},
Corentin Charydc795262009-08-28 12:56:51 +0000329 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
330 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
Corentin Chary034ce902009-01-20 16:17:43 +0100331 {KE_END, 0},
332};
333
Corentin Chary85091b72007-01-26 14:04:30 +0100334/*
335 * This function evaluates an ACPI method, given an int as parameter, the
336 * method is searched within the scope of the handle, can be NULL. The output
337 * of the method is written is output, which can also be NULL
338 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100339 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100340 */
341static int write_acpi_int(acpi_handle handle, const char *method, int val,
342 struct acpi_buffer *output)
343{
Corentin Charybe966662009-08-29 10:28:29 +0200344 struct acpi_object_list params; /* list of input parameters (an int) */
345 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100346 acpi_status status;
347
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100348 if (!handle)
349 return 0;
350
Corentin Chary85091b72007-01-26 14:04:30 +0100351 params.count = 1;
352 params.pointer = &in_obj;
353 in_obj.type = ACPI_TYPE_INTEGER;
354 in_obj.integer.value = val;
355
356 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100357 if (status == AE_OK)
358 return 0;
359 else
360 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100361}
362
Len Brown8def05f2007-01-30 01:46:43 -0500363static int read_wireless_status(int mask)
364{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400365 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100366 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100367
368 if (!wireless_status_handle)
369 return (hotk->status & mask) ? 1 : 0;
370
Corentin Chary9a816852007-03-11 10:25:38 +0100371 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
372 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200373 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100374 else
375 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100376
377 return (hotk->status & mask) ? 1 : 0;
378}
379
Corentin Charyf3985322007-05-06 14:48:22 +0200380static int read_gps_status(void)
381{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400382 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200383 acpi_status rv = AE_OK;
384
385 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
386 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200387 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200388 else
Corentin Charyf3985322007-05-06 14:48:22 +0200389 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200390
Corentin Charyf3985322007-05-06 14:48:22 +0200391 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200392}
393
Corentin Charybe18cda2007-01-26 14:04:35 +0100394/* Generic LED functions */
395static int read_status(int mask)
396{
Corentin Chary4564de12007-01-26 14:04:40 +0100397 /* There is a special method for both wireless devices */
398 if (mask == BT_ON || mask == WL_ON)
399 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200400 else if (mask == GPS_ON)
401 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100402
Corentin Charybe18cda2007-01-26 14:04:35 +0100403 return (hotk->status & mask) ? 1 : 0;
404}
405
Corentin Chary935ffee2007-03-11 10:26:12 +0100406static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100407{
408 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
409
Corentin Chary935ffee2007-03-11 10:26:12 +0100410 switch (mask) {
411 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100412 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100413 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100414 case GLED_ON:
415 out = (out & 0x1) + 1;
416 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200417 case GPS_ON:
418 handle = (out) ? gps_on_handle : gps_off_handle;
419 out = 0x02;
420 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100421 default:
422 out &= 0x1;
423 break;
424 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100425
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100426 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200427 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100428}
429
430/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100431#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100432 static void object##_led_set(struct led_classdev *led_cdev, \
433 enum led_brightness value) \
434 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200435 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100436 queue_work(led_workqueue, &object##_led_work); \
437 } \
438 static void object##_led_update(struct work_struct *ignored) \
439 { \
440 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100441 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000442 } \
443 static enum led_brightness object##_led_get( \
444 struct led_classdev *led_cdev) \
445 { \
446 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100447 }
448
Corentin Chary935ffee2007-03-11 10:26:12 +0100449ASUS_LED_HANDLER(mled, MLED_ON);
450ASUS_LED_HANDLER(pled, PLED_ON);
451ASUS_LED_HANDLER(rled, RLED_ON);
452ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100453ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100454
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000455/*
456 * Keyboard backlight
457 */
458static int get_kled_lvl(void)
459{
460 unsigned long long kblv;
461 struct acpi_object_list params;
462 union acpi_object in_obj;
463 acpi_status rv;
464
465 params.count = 1;
466 params.pointer = &in_obj;
467 in_obj.type = ACPI_TYPE_INTEGER;
468 in_obj.integer.value = 2;
469
470 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
471 if (ACPI_FAILURE(rv)) {
472 pr_warning("Error reading kled level\n");
473 return 0;
474 }
475 return kblv;
476}
477
478static int set_kled_lvl(int kblv)
479{
480 if (kblv > 0)
481 kblv = (1 << 7) | (kblv & 0x7F);
482 else
483 kblv = 0;
484
485 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
486 pr_warning("Keyboard LED display write failed\n");
487 return -EINVAL;
488 }
489 return 0;
490}
491
492static void kled_led_set(struct led_classdev *led_cdev,
493 enum led_brightness value)
494{
495 kled_led_wk = value;
496 queue_work(led_workqueue, &kled_led_work);
497}
498
499static void kled_led_update(struct work_struct *ignored)
500{
501 set_kled_lvl(kled_led_wk);
502}
503
504static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
505{
506 return get_kled_lvl();
507}
508
Corentin Chary6b7091e2007-01-26 14:04:45 +0100509static int get_lcd_state(void)
510{
511 return read_status(LCD_ON);
512}
513
514static int set_lcd_state(int value)
515{
516 int lcd = 0;
517 acpi_status status = 0;
518
519 lcd = value ? 1 : 0;
520
521 if (lcd == get_lcd_state())
522 return 0;
523
Len Brown8def05f2007-01-30 01:46:43 -0500524 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100525 status = acpi_evaluate_object(lcd_switch_handle,
526 NULL, NULL, NULL);
527
528 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200529 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100530 }
531
Corentin Chary935ffee2007-03-11 10:26:12 +0100532 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100533 return 0;
534}
535
536static void lcd_blank(int blank)
537{
538 struct backlight_device *bd = asus_backlight_device;
539
Len Brown8def05f2007-01-30 01:46:43 -0500540 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000541 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000542 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100543 }
544}
545
546static int read_brightness(struct backlight_device *bd)
547{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400548 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100549 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100550
Corentin Chary9a816852007-03-11 10:25:38 +0100551 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
552 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200553 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100554
555 return value;
556}
557
558static int set_brightness(struct backlight_device *bd, int value)
559{
560 int ret = 0;
561
562 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
563 /* 0 <= value <= 15 */
564
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100565 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200566 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100567 ret = -EIO;
568 }
569
570 return ret;
571}
572
573static int update_bl_status(struct backlight_device *bd)
574{
575 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000576 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100577
578 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500579 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100580 return rv;
581
Richard Purdie599a52d2007-02-10 23:07:48 +0000582 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100583 return set_lcd_state(value);
584}
585
Corentin Chary85091b72007-01-26 14:04:30 +0100586/*
587 * Platform device handlers
588 */
589
590/*
591 * We write our info in page, we begin at offset off and cannot write more
592 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
593 * number of bytes written in page
594 */
595static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500596 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100597{
598 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400599 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200600 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100601 acpi_status rv = AE_OK;
602
Corentin Chary85091b72007-01-26 14:04:30 +0100603 /*
604 * We use the easy way, we don't care of off and count, so we don't set eof
605 * to 1
606 */
607
608 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
609 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
610 /*
611 * The SFUN method probably allows the original driver to get the list
612 * of features supported by a given model. For now, 0x0100 or 0x0800
613 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
614 * The significance of others is yet to be found.
615 */
Corentin Chary9a816852007-03-11 10:25:38 +0100616 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
617 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000618 len += sprintf(page + len, "SFUN value : %#x\n",
619 (uint) temp);
620 /*
621 * The HWRS method return informations about the hardware.
622 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
623 * The significance of others is yet to be found.
624 * If we don't find the method, we assume the device are present.
625 */
626 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
627 if (!ACPI_FAILURE(rv))
628 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100629 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100630 /*
631 * Another value for userspace: the ASYM method returns 0x02 for
632 * battery low and 0x04 for battery critical, its readings tend to be
633 * more accurate than those provided by _BST.
634 * Note: since not all the laptops provide this method, errors are
635 * silently ignored.
636 */
Corentin Chary9a816852007-03-11 10:25:38 +0100637 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
638 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000639 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100640 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100641 if (asus_info) {
642 snprintf(buf, 16, "%d", asus_info->length);
643 len += sprintf(page + len, "DSDT length : %s\n", buf);
644 snprintf(buf, 16, "%d", asus_info->checksum);
645 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
646 snprintf(buf, 16, "%d", asus_info->revision);
647 len += sprintf(page + len, "DSDT revision : %s\n", buf);
648 snprintf(buf, 7, "%s", asus_info->oem_id);
649 len += sprintf(page + len, "OEM id : %s\n", buf);
650 snprintf(buf, 9, "%s", asus_info->oem_table_id);
651 len += sprintf(page + len, "OEM table id : %s\n", buf);
652 snprintf(buf, 16, "%x", asus_info->oem_revision);
653 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
654 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
655 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
656 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
657 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
658 }
659
660 return len;
661}
662
663static int parse_arg(const char *buf, unsigned long count, int *val)
664{
665 if (!count)
666 return 0;
667 if (count > 31)
668 return -EINVAL;
669 if (sscanf(buf, "%i", val) != 1)
670 return -EINVAL;
671 return count;
672}
673
Corentin Chary4564de12007-01-26 14:04:40 +0100674static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100675 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100676{
677 int rv, value;
678 int out = 0;
679
680 rv = parse_arg(buf, count, &value);
681 if (rv > 0)
682 out = value ? 1 : 0;
683
Corentin Chary935ffee2007-03-11 10:26:12 +0100684 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100685
686 return rv;
687}
688
689/*
Corentin Chary722ad972007-01-26 14:04:55 +0100690 * LEDD display
691 */
692static ssize_t show_ledd(struct device *dev,
693 struct device_attribute *attr, char *buf)
694{
695 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
696}
697
698static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
699 const char *buf, size_t count)
700{
701 int rv, value;
702
703 rv = parse_arg(buf, count, &value);
704 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100705 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200706 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100707 else
708 hotk->ledd_status = (u32) value;
709 }
710 return rv;
711}
712
713/*
Corentin Chary4564de12007-01-26 14:04:40 +0100714 * WLAN
715 */
716static ssize_t show_wlan(struct device *dev,
717 struct device_attribute *attr, char *buf)
718{
719 return sprintf(buf, "%d\n", read_status(WL_ON));
720}
721
722static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
723 const char *buf, size_t count)
724{
Corentin Chary935ffee2007-03-11 10:26:12 +0100725 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100726}
727
728/*
729 * Bluetooth
730 */
731static ssize_t show_bluetooth(struct device *dev,
732 struct device_attribute *attr, char *buf)
733{
734 return sprintf(buf, "%d\n", read_status(BT_ON));
735}
736
Len Brown8def05f2007-01-30 01:46:43 -0500737static ssize_t store_bluetooth(struct device *dev,
738 struct device_attribute *attr, const char *buf,
739 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100740{
Corentin Chary935ffee2007-03-11 10:26:12 +0100741 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100742}
743
Corentin Chary78127b42007-01-26 14:04:49 +0100744/*
745 * Display
746 */
747static void set_display(int value)
748{
749 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100750 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200751 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100752 return;
753}
754
755static int read_display(void)
756{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400757 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100758 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100759
Corentin Charybe966662009-08-29 10:28:29 +0200760 /*
761 * In most of the case, we know how to set the display, but sometime
762 * we can't read it
763 */
Len Brown8def05f2007-01-30 01:46:43 -0500764 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100765 rv = acpi_evaluate_integer(display_get_handle, NULL,
766 NULL, &value);
767 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200768 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100769 }
770
771 value &= 0x0F; /* needed for some models, shouldn't hurt others */
772
773 return value;
774}
Len Brown8def05f2007-01-30 01:46:43 -0500775
Corentin Chary78127b42007-01-26 14:04:49 +0100776/*
777 * Now, *this* one could be more user-friendly, but so far, no-one has
778 * complained. The significance of bits is the same as in store_disp()
779 */
780static ssize_t show_disp(struct device *dev,
781 struct device_attribute *attr, char *buf)
782{
783 return sprintf(buf, "%d\n", read_display());
784}
785
786/*
787 * Experimental support for display switching. As of now: 1 should activate
788 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
789 * Any combination (bitwise) of these will suffice. I never actually tested 4
790 * displays hooked up simultaneously, so be warned. See the acpi4asus README
791 * for more info.
792 */
793static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
794 const char *buf, size_t count)
795{
796 int rv, value;
797
798 rv = parse_arg(buf, count, &value);
799 if (rv > 0)
800 set_display(value);
801 return rv;
802}
803
Corentin Chary8b857352007-01-26 14:04:58 +0100804/*
805 * Light Sens
806 */
807static void set_light_sens_switch(int value)
808{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100809 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200810 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100811 hotk->light_switch = value;
812}
813
814static ssize_t show_lssw(struct device *dev,
815 struct device_attribute *attr, char *buf)
816{
817 return sprintf(buf, "%d\n", hotk->light_switch);
818}
819
820static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
821 const char *buf, size_t count)
822{
823 int rv, value;
824
825 rv = parse_arg(buf, count, &value);
826 if (rv > 0)
827 set_light_sens_switch(value ? 1 : 0);
828
829 return rv;
830}
831
832static void set_light_sens_level(int value)
833{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100834 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200835 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100836 hotk->light_level = value;
837}
838
839static ssize_t show_lslvl(struct device *dev,
840 struct device_attribute *attr, char *buf)
841{
842 return sprintf(buf, "%d\n", hotk->light_level);
843}
844
845static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
846 const char *buf, size_t count)
847{
848 int rv, value;
849
850 rv = parse_arg(buf, count, &value);
851 if (rv > 0) {
852 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
853 /* 0 <= value <= 15 */
854 set_light_sens_level(value);
855 }
856
857 return rv;
858}
859
Corentin Charye539c2f2007-05-06 14:47:06 +0200860/*
861 * GPS
862 */
863static ssize_t show_gps(struct device *dev,
864 struct device_attribute *attr, char *buf)
865{
866 return sprintf(buf, "%d\n", read_status(GPS_ON));
867}
868
869static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
870 const char *buf, size_t count)
871{
Corentin Charyf3985322007-05-06 14:48:22 +0200872 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200873}
874
Corentin Chary034ce902009-01-20 16:17:43 +0100875/*
876 * Hotkey functions
877 */
878static struct key_entry *asus_get_entry_by_scancode(int code)
879{
880 struct key_entry *key;
881
882 for (key = asus_keymap; key->type != KE_END; key++)
883 if (code == key->code)
884 return key;
885
886 return NULL;
887}
888
889static struct key_entry *asus_get_entry_by_keycode(int code)
890{
891 struct key_entry *key;
892
893 for (key = asus_keymap; key->type != KE_END; key++)
894 if (code == key->keycode && key->type == KE_KEY)
895 return key;
896
897 return NULL;
898}
899
900static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
901{
902 struct key_entry *key = asus_get_entry_by_scancode(scancode);
903
904 if (key && key->type == KE_KEY) {
905 *keycode = key->keycode;
906 return 0;
907 }
908
909 return -EINVAL;
910}
911
912static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
913{
914 struct key_entry *key;
915 int old_keycode;
916
917 if (keycode < 0 || keycode > KEY_MAX)
918 return -EINVAL;
919
920 key = asus_get_entry_by_scancode(scancode);
921 if (key && key->type == KE_KEY) {
922 old_keycode = key->keycode;
923 key->keycode = keycode;
924 set_bit(keycode, dev->keybit);
925 if (!asus_get_entry_by_keycode(old_keycode))
926 clear_bit(old_keycode, dev->keybit);
927 return 0;
928 }
929
930 return -EINVAL;
931}
932
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600933static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100934{
Corentin Chary034ce902009-01-20 16:17:43 +0100935 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100936 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100937
Corentin Chary85091b72007-01-26 14:04:30 +0100938 /* TODO Find a better way to handle events count. */
939 if (!hotk)
940 return;
941
Corentin Chary6b7091e2007-01-26 14:04:45 +0100942 /*
943 * We need to tell the backlight device when the backlight power is
944 * switched
945 */
946 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100947 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100948 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500949 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100950 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100951 lcd_blank(FB_BLANK_POWERDOWN);
952 }
953
Corentin Chary6050c8d2009-02-15 19:30:19 +0100954 count = hotk->event_count[event % 128]++;
955 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100956 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
957 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100958 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100959
Corentin Chary034ce902009-01-20 16:17:43 +0100960 if (hotk->inputdev) {
961 key = asus_get_entry_by_scancode(event);
962 if (!key)
963 return ;
964
965 switch (key->type) {
966 case KE_KEY:
967 input_report_key(hotk->inputdev, key->keycode, 1);
968 input_sync(hotk->inputdev);
969 input_report_key(hotk->inputdev, key->keycode, 0);
970 input_sync(hotk->inputdev);
971 break;
972 }
973 }
Corentin Chary85091b72007-01-26 14:04:30 +0100974}
975
976#define ASUS_CREATE_DEVICE_ATTR(_name) \
977 struct device_attribute dev_attr_##_name = { \
978 .attr = { \
979 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900980 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100981 .show = NULL, \
982 .store = NULL, \
983 }
984
985#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
986 do { \
987 dev_attr_##_name.attr.mode = _mode; \
988 dev_attr_##_name.show = _show; \
989 dev_attr_##_name.store = _store; \
990 } while(0)
991
992static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100993static ASUS_CREATE_DEVICE_ATTR(wlan);
994static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100995static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100996static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100997static ASUS_CREATE_DEVICE_ATTR(ls_switch);
998static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200999static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001000
1001static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -05001002 &dev_attr_infos.attr,
1003 &dev_attr_wlan.attr,
1004 &dev_attr_bluetooth.attr,
1005 &dev_attr_display.attr,
1006 &dev_attr_ledd.attr,
1007 &dev_attr_ls_switch.attr,
1008 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +02001009 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -05001010 NULL
Corentin Chary85091b72007-01-26 14:04:30 +01001011};
1012
1013static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -05001014 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +01001015};
1016
1017static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001018 .driver = {
1019 .name = ASUS_HOTK_FILE,
1020 .owner = THIS_MODULE,
1021 }
Corentin Chary85091b72007-01-26 14:04:30 +01001022};
1023
1024static struct platform_device *asuspf_device;
1025
Corentin Chary85091b72007-01-26 14:04:30 +01001026static void asus_hotk_add_fs(void)
1027{
1028 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +01001029
1030 if (wl_switch_handle)
1031 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1032
1033 if (bt_switch_handle)
1034 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1035 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001036
1037 if (display_set_handle && display_get_handle)
1038 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -05001039 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +01001040 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1041
Corentin Chary722ad972007-01-26 14:04:55 +01001042 if (ledd_set_handle)
1043 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1044
Corentin Chary8b857352007-01-26 14:04:58 +01001045 if (ls_switch_handle && ls_level_handle) {
1046 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1047 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1048 }
Corentin Charye539c2f2007-05-06 14:47:06 +02001049
Corentin Charyf3985322007-05-06 14:48:22 +02001050 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +02001051 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001052}
1053
Len Brown8def05f2007-01-30 01:46:43 -05001054static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001055 char **paths, int num_paths)
1056{
1057 int i;
1058 acpi_status status;
1059
1060 for (i = 0; i < num_paths; i++) {
1061 status = acpi_get_handle(NULL, paths[i], handle);
1062 if (ACPI_SUCCESS(status))
1063 return 0;
1064 }
1065
1066 *handle = NULL;
1067 return -ENODEV;
1068}
1069
1070#define ASUS_HANDLE_INIT(object) \
1071 asus_handle_init(#object, &object##_handle, object##_paths, \
1072 ARRAY_SIZE(object##_paths))
1073
Corentin Chary85091b72007-01-26 14:04:30 +01001074/*
1075 * This function is used to initialize the hotk with right values. In this
1076 * method, we can make all the detection we want, and modify the hotk struct
1077 */
1078static int asus_hotk_get_info(void)
1079{
1080 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001081 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001082 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001083 char *string = NULL;
1084 acpi_status status;
1085
1086 /*
1087 * Get DSDT headers early enough to allow for differentiating between
1088 * models, but late enough to allow acpi_bus_register_driver() to fail
1089 * before doing anything ACPI-specific. Should we encounter a machine,
1090 * which needs special handling (i.e. its hotkey device has a different
1091 * HID), this bit will be moved. A global variable asus_info contains
1092 * the DSDT header.
1093 */
Len Brown894d79b2007-02-03 02:13:53 -05001094 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001095 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001096 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001097
1098 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +01001099 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001100 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001101 return -ENODEV;
1102 }
1103
1104 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001105 status =
1106 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1107 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001108 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001109 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001110 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001111 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001112
Corentin Chary185e5af2007-03-11 10:27:33 +01001113 /* This too ... */
1114 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1115
Corentin Chary85091b72007-01-26 14:04:30 +01001116 /*
1117 * Try to match the object returned by INIT to the specific model.
1118 * Handle every possible object (or the lack of thereof) the DSDT
1119 * writers might throw at us. When in trouble, we pass NULL to
1120 * asus_model_match() and try something completely different.
1121 */
1122 if (buffer.pointer) {
1123 model = buffer.pointer;
1124 switch (model->type) {
1125 case ACPI_TYPE_STRING:
1126 string = model->string.pointer;
1127 break;
1128 case ACPI_TYPE_BUFFER:
1129 string = model->buffer.pointer;
1130 break;
1131 default:
1132 string = "";
1133 break;
1134 }
1135 }
1136 hotk->name = kstrdup(string, GFP_KERNEL);
1137 if (!hotk->name)
1138 return -ENOMEM;
1139
Len Brown8def05f2007-01-30 01:46:43 -05001140 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001141 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001142
Corentin Charybe18cda2007-01-26 14:04:35 +01001143 ASUS_HANDLE_INIT(mled_set);
1144 ASUS_HANDLE_INIT(tled_set);
1145 ASUS_HANDLE_INIT(rled_set);
1146 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001147 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001148
Corentin Chary722ad972007-01-26 14:04:55 +01001149 ASUS_HANDLE_INIT(ledd_set);
1150
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001151 ASUS_HANDLE_INIT(kled_set);
1152 ASUS_HANDLE_INIT(kled_get);
1153
Corentin Chary4564de12007-01-26 14:04:40 +01001154 /*
1155 * The HWRS method return informations about the hardware.
1156 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1157 * The significance of others is yet to be found.
1158 * If we don't find the method, we assume the device are present.
1159 */
Corentin Chary9a816852007-03-11 10:25:38 +01001160 status =
1161 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1162 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001163 hwrs_result = WL_HWRS | BT_HWRS;
1164
Len Brown8def05f2007-01-30 01:46:43 -05001165 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001166 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001167 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001168 ASUS_HANDLE_INIT(bt_switch);
1169
1170 ASUS_HANDLE_INIT(wireless_status);
1171
Corentin Chary6b7091e2007-01-26 14:04:45 +01001172 ASUS_HANDLE_INIT(brightness_set);
1173 ASUS_HANDLE_INIT(brightness_get);
1174
1175 ASUS_HANDLE_INIT(lcd_switch);
1176
Corentin Chary78127b42007-01-26 14:04:49 +01001177 ASUS_HANDLE_INIT(display_set);
1178 ASUS_HANDLE_INIT(display_get);
1179
Corentin Charybe966662009-08-29 10:28:29 +02001180 /*
1181 * There is a lot of models with "ALSL", but a few get
1182 * a real light sens, so we need to check it.
1183 */
Corentin Chary832d9952007-05-06 14:47:29 +02001184 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001185 ASUS_HANDLE_INIT(ls_level);
1186
Corentin Charye539c2f2007-05-06 14:47:06 +02001187 ASUS_HANDLE_INIT(gps_on);
1188 ASUS_HANDLE_INIT(gps_off);
1189 ASUS_HANDLE_INIT(gps_status);
1190
Corentin Chary85091b72007-01-26 14:04:30 +01001191 kfree(model);
1192
1193 return AE_OK;
1194}
1195
Corentin Chary034ce902009-01-20 16:17:43 +01001196static int asus_input_init(void)
1197{
1198 const struct key_entry *key;
1199 int result;
1200
1201 hotk->inputdev = input_allocate_device();
1202 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001203 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001204 return 0;
1205 }
1206 hotk->inputdev->name = "Asus Laptop extra buttons";
1207 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1208 hotk->inputdev->id.bustype = BUS_HOST;
1209 hotk->inputdev->getkeycode = asus_getkeycode;
1210 hotk->inputdev->setkeycode = asus_setkeycode;
1211
1212 for (key = asus_keymap; key->type != KE_END; key++) {
1213 switch (key->type) {
1214 case KE_KEY:
1215 set_bit(EV_KEY, hotk->inputdev->evbit);
1216 set_bit(key->keycode, hotk->inputdev->keybit);
1217 break;
1218 }
1219 }
1220 result = input_register_device(hotk->inputdev);
1221 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001222 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001223 input_free_device(hotk->inputdev);
1224 }
1225 return result;
1226}
1227
Corentin Chary85091b72007-01-26 14:04:30 +01001228static int asus_hotk_check(void)
1229{
1230 int result = 0;
1231
1232 result = acpi_bus_get_status(hotk->device);
1233 if (result)
1234 return result;
1235
1236 if (hotk->device->status.present) {
1237 result = asus_hotk_get_info();
1238 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001239 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001240 return -EINVAL;
1241 }
1242
1243 return result;
1244}
1245
1246static int asus_hotk_found;
1247
1248static int asus_hotk_add(struct acpi_device *device)
1249{
Corentin Chary85091b72007-01-26 14:04:30 +01001250 int result;
1251
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001252 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001253 ASUS_LAPTOP_VERSION);
1254
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001255 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001256 if (!hotk)
1257 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001258
1259 hotk->handle = device->handle;
1260 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1261 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001262 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001263 hotk->device = device;
1264
1265 result = asus_hotk_check();
1266 if (result)
1267 goto end;
1268
1269 asus_hotk_add_fs();
1270
Corentin Chary85091b72007-01-26 14:04:30 +01001271 asus_hotk_found = 1;
1272
Corentin Chary6b7091e2007-01-26 14:04:45 +01001273 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001274 write_status(bt_switch_handle, 1, BT_ON);
1275 write_status(wl_switch_handle, 1, WL_ON);
1276
1277 /* If the h/w switch is off, we need to check the real status */
1278 write_status(NULL, read_status(BT_ON), BT_ON);
1279 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001280
Corentin Chary6b7091e2007-01-26 14:04:45 +01001281 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001282 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001283
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001284 /* Keyboard Backlight is on by default */
1285 if (kled_set_handle)
1286 set_kled_lvl(1);
1287
Corentin Chary722ad972007-01-26 14:04:55 +01001288 /* LED display is off by default */
1289 hotk->ledd_status = 0xFFF;
1290
Len Brown8def05f2007-01-30 01:46:43 -05001291 /* Set initial values of light sensor and level */
1292 hotk->light_switch = 1; /* Default to light sensor disabled */
1293 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001294
Len Brown8def05f2007-01-30 01:46:43 -05001295 if (ls_switch_handle)
1296 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001297
Len Brown8def05f2007-01-30 01:46:43 -05001298 if (ls_level_handle)
1299 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001300
Corentin Charye539c2f2007-05-06 14:47:06 +02001301 /* GPS is on by default */
1302 write_status(NULL, 1, GPS_ON);
1303
Corentin Charyed6f4422009-01-20 16:17:45 +01001304end:
Corentin Chary85091b72007-01-26 14:04:30 +01001305 if (result) {
1306 kfree(hotk->name);
1307 kfree(hotk);
1308 }
1309
1310 return result;
1311}
1312
1313static int asus_hotk_remove(struct acpi_device *device, int type)
1314{
Corentin Chary85091b72007-01-26 14:04:30 +01001315 kfree(hotk->name);
1316 kfree(hotk);
1317
1318 return 0;
1319}
1320
Corentin Chary6b7091e2007-01-26 14:04:45 +01001321static void asus_backlight_exit(void)
1322{
Len Brown8def05f2007-01-30 01:46:43 -05001323 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001324 backlight_device_unregister(asus_backlight_device);
1325}
1326
Corentin Charybe18cda2007-01-26 14:04:35 +01001327#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a692007-08-16 18:18:53 +02001328 if (object##_led.dev) \
1329 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001330
1331static void asus_led_exit(void)
1332{
Al Viro3b0d7112007-07-23 11:21:34 +01001333 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001334 ASUS_LED_UNREGISTER(mled);
1335 ASUS_LED_UNREGISTER(tled);
1336 ASUS_LED_UNREGISTER(pled);
1337 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001338 ASUS_LED_UNREGISTER(gled);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001339 ASUS_LED_UNREGISTER(kled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001340}
1341
Corentin Chary034ce902009-01-20 16:17:43 +01001342static void asus_input_exit(void)
1343{
1344 if (hotk->inputdev)
1345 input_unregister_device(hotk->inputdev);
1346}
1347
Corentin Chary85091b72007-01-26 14:04:30 +01001348static void __exit asus_laptop_exit(void)
1349{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001350 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001351 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001352 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001353
Corentin Chary85091b72007-01-26 14:04:30 +01001354 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001355 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1356 platform_device_unregister(asuspf_device);
1357 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001358}
1359
Len Brown8def05f2007-01-30 01:46:43 -05001360static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001361{
1362 struct backlight_device *bd;
1363
Len Brown8def05f2007-01-30 01:46:43 -05001364 if (brightness_set_handle && lcd_switch_handle) {
1365 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001366 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001367 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001368 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001369 asus_backlight_device = NULL;
1370 return PTR_ERR(bd);
1371 }
1372
1373 asus_backlight_device = bd;
1374
Richard Purdie599a52d2007-02-10 23:07:48 +00001375 bd->props.max_brightness = 15;
1376 bd->props.brightness = read_brightness(NULL);
1377 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001378 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001379 }
1380 return 0;
1381}
1382
Corentin Charybe18cda2007-01-26 14:04:35 +01001383static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001384 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001385{
Len Brown8def05f2007-01-30 01:46:43 -05001386 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001387 return 0;
1388
1389 return led_classdev_register(dev, ldev);
1390}
Len Brown8def05f2007-01-30 01:46:43 -05001391
Corentin Charybe18cda2007-01-26 14:04:35 +01001392#define ASUS_LED_REGISTER(object, device) \
1393 asus_led_register(object##_set_handle, &object##_led, device)
1394
Len Brown8def05f2007-01-30 01:46:43 -05001395static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001396{
1397 int rv;
1398
1399 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001400 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001401 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001402
1403 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001404 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001405 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001406
1407 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001408 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001409 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001410
1411 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001412 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001413 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001414
Corentin Charyfdd8d082007-03-11 10:26:48 +01001415 rv = ASUS_LED_REGISTER(gled, dev);
1416 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001417 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001418
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001419 if (kled_set_handle && kled_get_handle)
1420 rv = ASUS_LED_REGISTER(kled, dev);
1421 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001422 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001423
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001424 led_workqueue = create_singlethread_workqueue("led_workqueue");
1425 if (!led_workqueue)
1426 goto out6;
1427
Corentin Charybe18cda2007-01-26 14:04:35 +01001428 return 0;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001429out6:
Al Viro3b0d7112007-07-23 11:21:34 +01001430 rv = -ENOMEM;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001431 ASUS_LED_UNREGISTER(kled);
1432out5:
Al Viro3b0d7112007-07-23 11:21:34 +01001433 ASUS_LED_UNREGISTER(gled);
1434out4:
1435 ASUS_LED_UNREGISTER(pled);
1436out3:
1437 ASUS_LED_UNREGISTER(rled);
1438out2:
1439 ASUS_LED_UNREGISTER(tled);
1440out1:
1441 ASUS_LED_UNREGISTER(mled);
1442out:
1443 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001444}
1445
Corentin Chary85091b72007-01-26 14:04:30 +01001446static int __init asus_laptop_init(void)
1447{
1448 int result;
1449
Corentin Chary85091b72007-01-26 14:04:30 +01001450 result = acpi_bus_register_driver(&asus_hotk_driver);
1451 if (result < 0)
1452 return result;
1453
1454 /*
1455 * This is a bit of a kludge. We only want this module loaded
1456 * for ASUS systems, but there's currently no way to probe the
1457 * ACPI namespace for ASUS HIDs. So we just return failure if
1458 * we didn't find one, which will cause the module to be
1459 * unloaded.
1460 */
1461 if (!asus_hotk_found) {
1462 acpi_bus_unregister_driver(&asus_hotk_driver);
1463 return -ENODEV;
1464 }
1465
Corentin Chary034ce902009-01-20 16:17:43 +01001466 result = asus_input_init();
1467 if (result)
1468 goto fail_input;
1469
Len Brown8def05f2007-01-30 01:46:43 -05001470 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001471 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001472 if (result)
1473 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001474
Len Brown8def05f2007-01-30 01:46:43 -05001475 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1476 if (!asuspf_device) {
1477 result = -ENOMEM;
1478 goto fail_platform_device1;
1479 }
Corentin Chary85091b72007-01-26 14:04:30 +01001480
Len Brown8def05f2007-01-30 01:46:43 -05001481 result = platform_device_add(asuspf_device);
1482 if (result)
1483 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001484
Len Brown8def05f2007-01-30 01:46:43 -05001485 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001486 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001487 if (result)
1488 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001489
Corentin Chary116bf2e2009-06-16 19:28:46 +00001490 result = asus_led_init(&asuspf_device->dev);
1491 if (result)
1492 goto fail_led;
1493
1494 if (!acpi_video_backlight_support()) {
1495 result = asus_backlight_init(&asuspf_device->dev);
1496 if (result)
1497 goto fail_backlight;
1498 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001499 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001500 "ACPI video driver\n");
1501
Len Brown8def05f2007-01-30 01:46:43 -05001502 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001503
Corentin Chary116bf2e2009-06-16 19:28:46 +00001504fail_backlight:
1505 asus_led_exit();
1506
1507fail_led:
1508 sysfs_remove_group(&asuspf_device->dev.kobj,
1509 &asuspf_attribute_group);
1510
Corentin Charyed6f4422009-01-20 16:17:45 +01001511fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001512 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001513
Corentin Charyed6f4422009-01-20 16:17:45 +01001514fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001515 platform_device_put(asuspf_device);
1516
Corentin Charyed6f4422009-01-20 16:17:45 +01001517fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001518 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001519
Corentin Charyed6f4422009-01-20 16:17:45 +01001520fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001521 asus_input_exit();
1522
Corentin Charyed6f4422009-01-20 16:17:45 +01001523fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001524
1525 return result;
1526}
1527
1528module_init(asus_laptop_init);
1529module_exit(asus_laptop_exit);