Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * asus-laptop.c - Asus Laptop Support |
| 3 | * |
| 4 | * |
| 5 | * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor |
Corentin Chary | 8ec555c | 2007-03-11 10:28:03 +0100 | [diff] [blame] | 6 | * Copyright (C) 2006-2007 Corentin Chary |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 7 | * |
| 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 Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 33 | * Sam Lin - GPS support |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 34 | */ |
| 35 | |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 36 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 37 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 38 | #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 Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 44 | #include <linux/backlight.h> |
| 45 | #include <linux/fb.h> |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 46 | #include <linux/leds.h> |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 47 | #include <linux/platform_device.h> |
| 48 | #include <acpi/acpi_drivers.h> |
| 49 | #include <acpi/acpi_bus.h> |
| 50 | #include <asm/uaccess.h> |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 51 | #include <linux/input.h> |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 52 | |
Corentin Chary | 91687cc | 2009-11-28 10:32:34 +0100 | [diff] [blame^] | 53 | #define ASUS_LAPTOP_VERSION "0.42" |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 54 | |
Corentin Chary | 91687cc | 2009-11-28 10:32:34 +0100 | [diff] [blame^] | 55 | #define ASUS_HOTK_NAME "Asus Laptop Support" |
| 56 | #define ASUS_HOTK_CLASS "hotkey" |
| 57 | #define ASUS_HOTK_DEVICE_NAME "Hotkey" |
| 58 | #define ASUS_HOTK_FILE KBUILD_MODNAME |
| 59 | #define ASUS_HOTK_PREFIX "\\_SB.ATKD." |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 60 | |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 61 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 62 | /* |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 63 | * Some events we use, same for all Asus |
| 64 | */ |
Corentin Chary | 91687cc | 2009-11-28 10:32:34 +0100 | [diff] [blame^] | 65 | #define ATKD_BR_UP 0x10 |
| 66 | #define ATKD_BR_DOWN 0x20 |
| 67 | #define ATKD_LCD_ON 0x33 |
| 68 | #define ATKD_LCD_OFF 0x34 |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 69 | |
| 70 | /* |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 71 | * Known bits returned by \_SB.ATKD.HWRS |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 72 | */ |
Corentin Chary | 91687cc | 2009-11-28 10:32:34 +0100 | [diff] [blame^] | 73 | #define WL_HWRS 0x80 |
| 74 | #define BT_HWRS 0x100 |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Flags for hotk status |
| 78 | * WL_ON and BT_ON are also used for wireless_status() |
| 79 | */ |
Corentin Chary | 91687cc | 2009-11-28 10:32:34 +0100 | [diff] [blame^] | 80 | #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 Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 90 | |
| 91 | MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); |
| 92 | MODULE_DESCRIPTION(ASUS_HOTK_NAME); |
| 93 | MODULE_LICENSE("GPL"); |
| 94 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 95 | /* |
| 96 | * WAPF defines the behavior of the Fn+Fx wlan key |
Corentin Chary | 185e5af | 2007-03-11 10:27:33 +0100 | [diff] [blame] | 97 | * The significance of values is yet to be found, but |
| 98 | * most of the time: |
| 99 | * 0x0 will do nothing |
| 100 | * 0x1 will allow to control the device with Fn+Fx key. |
| 101 | * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key |
| 102 | * 0x5 like 0x1 or 0x4 |
| 103 | * So, if something doesn't work as you want, just try other values =) |
| 104 | */ |
| 105 | static uint wapf = 1; |
| 106 | module_param(wapf, uint, 0644); |
| 107 | MODULE_PARM_DESC(wapf, "WAPF value"); |
| 108 | |
Corentin Chary | 0e875f4 | 2010-01-10 20:49:26 +0100 | [diff] [blame] | 109 | static uint wireless_status = 1; |
| 110 | static uint bluetooth_status = 1; |
| 111 | |
| 112 | module_param(wireless_status, uint, 0644); |
| 113 | MODULE_PARM_DESC(wireless_status, "Set the wireless status on boot " |
| 114 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " |
| 115 | "default is 1"); |
| 116 | |
| 117 | module_param(bluetooth_status, uint, 0644); |
| 118 | MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot " |
| 119 | "(0 = disabled, 1 = enabled, -1 = don't do anything). " |
| 120 | "default is 1"); |
| 121 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 122 | #define ASUS_HANDLE(object, paths...) \ |
| 123 | static acpi_handle object##_handle = NULL; \ |
| 124 | static char *object##_paths[] = { paths } |
| 125 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 126 | /* LED */ |
| 127 | ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED"); |
| 128 | ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED"); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 129 | ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ |
| 130 | ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 131 | ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 132 | |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 133 | /* LEDD */ |
| 134 | ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM"); |
| 135 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 136 | /* |
| 137 | * Bluetooth and WLAN |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 138 | * WLED and BLED are not handled like other XLED, because in some dsdt |
| 139 | * they also control the WLAN/Bluetooth device. |
| 140 | */ |
| 141 | ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED"); |
| 142 | ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED"); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 143 | ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */ |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 144 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 145 | /* Brightness */ |
| 146 | ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV"); |
| 147 | ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV"); |
| 148 | |
| 149 | /* Backlight */ |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 150 | ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ |
| 151 | "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ |
| 152 | "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ |
| 153 | "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ |
| 154 | "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ |
Torsten Krah | 4d0b856e | 2008-10-17 09:47:57 +0200 | [diff] [blame] | 155 | "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */ |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 156 | "\\_SB.PCI0.PX40.Q10", /* S1x */ |
| 157 | "\\Q10"); /* A2x, L2D, L3D, M2E */ |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 158 | |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 159 | /* Display */ |
| 160 | ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP"); |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 161 | ASUS_HANDLE(display_get, |
| 162 | /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */ |
| 163 | "\\_SB.PCI0.P0P1.VGA.GETD", |
| 164 | /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */ |
| 165 | "\\_SB.PCI0.P0P2.VGA.GETD", |
| 166 | /* A6V A6Q */ |
| 167 | "\\_SB.PCI0.P0P3.VGA.GETD", |
| 168 | /* A6T, A6M */ |
| 169 | "\\_SB.PCI0.P0PA.VGA.GETD", |
| 170 | /* L3C */ |
| 171 | "\\_SB.PCI0.PCI1.VGAC.NMAP", |
| 172 | /* Z96F */ |
| 173 | "\\_SB.PCI0.VGA.GETD", |
| 174 | /* A2D */ |
| 175 | "\\ACTD", |
| 176 | /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ |
| 177 | "\\ADVG", |
| 178 | /* P30 */ |
| 179 | "\\DNXT", |
| 180 | /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ |
| 181 | "\\INFB", |
| 182 | /* A3F A6F A3N A3L M6N W3N W6A */ |
| 183 | "\\SSTE"); |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 184 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 185 | ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */ |
| 186 | ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */ |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 187 | |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 188 | /* GPS */ |
| 189 | /* R2H use different handle for GPS on/off */ |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 190 | ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */ |
| 191 | ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */ |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 192 | ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST"); |
| 193 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 194 | /* Keyboard light */ |
| 195 | ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB"); |
| 196 | ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB"); |
| 197 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 198 | /* |
| 199 | * This is the main structure, we can use it to store anything interesting |
| 200 | * about the hotk device |
| 201 | */ |
| 202 | struct asus_hotk { |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 203 | char *name; /* laptop name */ |
| 204 | struct acpi_device *device; /* the device we are in */ |
| 205 | acpi_handle handle; /* the handle of the hotk device */ |
| 206 | char status; /* status of the hotk, for LEDs, ... */ |
| 207 | u32 ledd_status; /* status of the LED display */ |
| 208 | u8 light_level; /* light sensor level */ |
| 209 | u8 light_switch; /* light sensor switch value */ |
| 210 | u16 event_count[128]; /* count for each event TODO make this better */ |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 211 | struct input_dev *inputdev; |
| 212 | u16 *keycode_map; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | /* |
| 216 | * This header is made available to allow proper configuration given model, |
| 217 | * revision number , ... this info cannot go in struct asus_hotk because it is |
| 218 | * available before the hotk |
| 219 | */ |
| 220 | static struct acpi_table_header *asus_info; |
| 221 | |
| 222 | /* The actual device the driver binds to */ |
| 223 | static struct asus_hotk *hotk; |
| 224 | |
| 225 | /* |
| 226 | * The hotkey driver declaration |
| 227 | */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 228 | static const struct acpi_device_id asus_device_ids[] = { |
| 229 | {"ATK0100", 0}, |
Ike Panhc | 14f8af3 | 2009-12-03 07:45:11 +0000 | [diff] [blame] | 230 | {"ATK0101", 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 231 | {"", 0}, |
| 232 | }; |
| 233 | MODULE_DEVICE_TABLE(acpi, asus_device_ids); |
| 234 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 235 | static int asus_hotk_add(struct acpi_device *device); |
| 236 | static int asus_hotk_remove(struct acpi_device *device, int type); |
Bjorn Helgaas | 586ed16 | 2009-04-30 09:35:53 -0600 | [diff] [blame] | 237 | static void asus_hotk_notify(struct acpi_device *device, u32 event); |
| 238 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 239 | static struct acpi_driver asus_hotk_driver = { |
| 240 | .name = ASUS_HOTK_NAME, |
| 241 | .class = ASUS_HOTK_CLASS, |
Alan Jenkins | edf6245 | 2009-12-03 07:44:51 +0000 | [diff] [blame] | 242 | .owner = THIS_MODULE, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 243 | .ids = asus_device_ids, |
Bjorn Helgaas | 586ed16 | 2009-04-30 09:35:53 -0600 | [diff] [blame] | 244 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 245 | .ops = { |
| 246 | .add = asus_hotk_add, |
| 247 | .remove = asus_hotk_remove, |
Bjorn Helgaas | 586ed16 | 2009-04-30 09:35:53 -0600 | [diff] [blame] | 248 | .notify = asus_hotk_notify, |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 249 | }, |
| 250 | }; |
| 251 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 252 | /* The backlight device /sys/class/backlight */ |
| 253 | static struct backlight_device *asus_backlight_device; |
| 254 | |
| 255 | /* |
| 256 | * The backlight class declaration |
| 257 | */ |
| 258 | static int read_brightness(struct backlight_device *bd); |
| 259 | static int update_bl_status(struct backlight_device *bd); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 260 | static struct backlight_ops asusbl_ops = { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 261 | .get_brightness = read_brightness, |
| 262 | .update_status = update_bl_status, |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 263 | }; |
| 264 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 265 | /* |
| 266 | * These functions actually update the LED's, and are called from a |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 267 | * workqueue. By doing this as separate work rather than when the LED |
| 268 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 269 | * potentially bad time, such as a timer interrupt. |
| 270 | */ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 271 | static struct workqueue_struct *led_workqueue; |
| 272 | |
Corentin Chary | 977c328 | 2009-08-28 12:56:49 +0000 | [diff] [blame] | 273 | #define ASUS_LED(object, ledname, max) \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 274 | static void object##_led_set(struct led_classdev *led_cdev, \ |
| 275 | enum led_brightness value); \ |
Corentin Chary | abfa57e | 2009-08-28 12:56:47 +0000 | [diff] [blame] | 276 | static enum led_brightness object##_led_get( \ |
| 277 | struct led_classdev *led_cdev); \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 278 | static void object##_led_update(struct work_struct *ignored); \ |
| 279 | static int object##_led_wk; \ |
Adrian Bunk | f110ef5 | 2007-02-20 01:07:25 +0100 | [diff] [blame] | 280 | static DECLARE_WORK(object##_led_work, object##_led_update); \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 281 | static struct led_classdev object##_led = { \ |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 282 | .name = "asus::" ledname, \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 283 | .brightness_set = object##_led_set, \ |
Corentin Chary | abfa57e | 2009-08-28 12:56:47 +0000 | [diff] [blame] | 284 | .brightness_get = object##_led_get, \ |
Corentin Chary | 977c328 | 2009-08-28 12:56:49 +0000 | [diff] [blame] | 285 | .max_brightness = max \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Corentin Chary | 977c328 | 2009-08-28 12:56:49 +0000 | [diff] [blame] | 288 | ASUS_LED(mled, "mail", 1); |
| 289 | ASUS_LED(tled, "touchpad", 1); |
| 290 | ASUS_LED(rled, "record", 1); |
| 291 | ASUS_LED(pled, "phone", 1); |
| 292 | ASUS_LED(gled, "gaming", 1); |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 293 | ASUS_LED(kled, "kbd_backlight", 3); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 294 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 295 | struct key_entry { |
| 296 | char type; |
| 297 | u8 code; |
| 298 | u16 keycode; |
| 299 | }; |
| 300 | |
| 301 | enum { KE_KEY, KE_END }; |
| 302 | |
| 303 | static struct key_entry asus_keymap[] = { |
Ike Panhc | 14f8af3 | 2009-12-03 07:45:11 +0000 | [diff] [blame] | 304 | {KE_KEY, 0x02, KEY_SCREENLOCK}, |
| 305 | {KE_KEY, 0x05, KEY_WLAN}, |
| 306 | {KE_KEY, 0x08, KEY_F13}, |
| 307 | {KE_KEY, 0x17, KEY_ZOOM}, |
| 308 | {KE_KEY, 0x1f, KEY_BATTERY}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 309 | {KE_KEY, 0x30, KEY_VOLUMEUP}, |
| 310 | {KE_KEY, 0x31, KEY_VOLUMEDOWN}, |
| 311 | {KE_KEY, 0x32, KEY_MUTE}, |
| 312 | {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE}, |
| 313 | {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE}, |
| 314 | {KE_KEY, 0x40, KEY_PREVIOUSSONG}, |
| 315 | {KE_KEY, 0x41, KEY_NEXTSONG}, |
Corentin Chary | 309f5fb | 2009-04-27 09:23:42 +0200 | [diff] [blame] | 316 | {KE_KEY, 0x43, KEY_STOPCD}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 317 | {KE_KEY, 0x45, KEY_PLAYPAUSE}, |
Corentin Chary | 4644d0e | 2009-08-28 12:56:52 +0000 | [diff] [blame] | 318 | {KE_KEY, 0x4c, KEY_MEDIA}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 319 | {KE_KEY, 0x50, KEY_EMAIL}, |
| 320 | {KE_KEY, 0x51, KEY_WWW}, |
Corentin Chary | 0aa20f7 | 2009-08-28 12:56:53 +0000 | [diff] [blame] | 321 | {KE_KEY, 0x55, KEY_CALC}, |
Corentin Chary | 309f5fb | 2009-04-27 09:23:42 +0200 | [diff] [blame] | 322 | {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */ |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 323 | {KE_KEY, 0x5D, KEY_WLAN}, |
Corentin Chary | f641375 | 2009-08-28 12:56:48 +0000 | [diff] [blame] | 324 | {KE_KEY, 0x5E, KEY_WLAN}, |
| 325 | {KE_KEY, 0x5F, KEY_WLAN}, |
| 326 | {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 327 | {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE}, |
Ike Panhc | 14f8af3 | 2009-12-03 07:45:11 +0000 | [diff] [blame] | 328 | {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE}, |
| 329 | {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE}, |
Corentin Chary | 16851f9 | 2009-12-03 07:45:10 +0000 | [diff] [blame] | 330 | {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */ |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 331 | {KE_KEY, 0x82, KEY_CAMERA}, |
Corentin Chary | 1f0233e | 2009-12-03 07:45:12 +0000 | [diff] [blame] | 332 | {KE_KEY, 0x88, KEY_WLAN }, |
Corentin Chary | 309f5fb | 2009-04-27 09:23:42 +0200 | [diff] [blame] | 333 | {KE_KEY, 0x8A, KEY_PROG1}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 334 | {KE_KEY, 0x95, KEY_MEDIA}, |
| 335 | {KE_KEY, 0x99, KEY_PHONE}, |
Corentin Chary | dc79526 | 2009-08-28 12:56:51 +0000 | [diff] [blame] | 336 | {KE_KEY, 0xc4, KEY_KBDILLUMUP}, |
| 337 | {KE_KEY, 0xc5, KEY_KBDILLUMDOWN}, |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 338 | {KE_END, 0}, |
| 339 | }; |
| 340 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 341 | /* |
| 342 | * This function evaluates an ACPI method, given an int as parameter, the |
| 343 | * method is searched within the scope of the handle, can be NULL. The output |
| 344 | * of the method is written is output, which can also be NULL |
| 345 | * |
Corentin CHARY | f8d1c94 | 2008-01-16 16:56:42 +0100 | [diff] [blame] | 346 | * returns 0 if write is successful, -1 else. |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 347 | */ |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 348 | static int write_acpi_int_ret(acpi_handle handle, const char *method, int val, |
| 349 | struct acpi_buffer *output) |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 350 | { |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 351 | struct acpi_object_list params; /* list of input parameters (an int) */ |
| 352 | union acpi_object in_obj; /* the only param we use */ |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 353 | acpi_status status; |
| 354 | |
Corentin CHARY | f8d1c94 | 2008-01-16 16:56:42 +0100 | [diff] [blame] | 355 | if (!handle) |
| 356 | return 0; |
| 357 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 358 | params.count = 1; |
| 359 | params.pointer = &in_obj; |
| 360 | in_obj.type = ACPI_TYPE_INTEGER; |
| 361 | in_obj.integer.value = val; |
| 362 | |
| 363 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); |
Corentin CHARY | f8d1c94 | 2008-01-16 16:56:42 +0100 | [diff] [blame] | 364 | if (status == AE_OK) |
| 365 | return 0; |
| 366 | else |
| 367 | return -1; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 368 | } |
| 369 | |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 370 | static int write_acpi_int(acpi_handle handle, const char *method, int val) |
| 371 | { |
| 372 | return write_acpi_int_ret(handle, method, val, NULL); |
| 373 | } |
| 374 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 375 | static int read_wireless_status(int mask) |
| 376 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 377 | unsigned long long status; |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 378 | acpi_status rv = AE_OK; |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 379 | |
| 380 | if (!wireless_status_handle) |
| 381 | return (hotk->status & mask) ? 1 : 0; |
| 382 | |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 383 | rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status); |
| 384 | if (ACPI_FAILURE(rv)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 385 | pr_warning("Error reading Wireless status\n"); |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 386 | else |
| 387 | return (status & mask) ? 1 : 0; |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 388 | |
| 389 | return (hotk->status & mask) ? 1 : 0; |
| 390 | } |
| 391 | |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 392 | static int read_gps_status(void) |
| 393 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 394 | unsigned long long status; |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 395 | acpi_status rv = AE_OK; |
| 396 | |
| 397 | rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status); |
| 398 | if (ACPI_FAILURE(rv)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 399 | pr_warning("Error reading GPS status\n"); |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 400 | else |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 401 | return status ? 1 : 0; |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 402 | |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 403 | return (hotk->status & GPS_ON) ? 1 : 0; |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 406 | /* Generic LED functions */ |
| 407 | static int read_status(int mask) |
| 408 | { |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 409 | /* There is a special method for both wireless devices */ |
| 410 | if (mask == BT_ON || mask == WL_ON) |
| 411 | return read_wireless_status(mask); |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 412 | else if (mask == GPS_ON) |
| 413 | return read_gps_status(); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 414 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 415 | return (hotk->status & mask) ? 1 : 0; |
| 416 | } |
| 417 | |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 418 | static void write_status(acpi_handle handle, int out, int mask) |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 419 | { |
| 420 | hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask); |
| 421 | |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 422 | switch (mask) { |
| 423 | case MLED_ON: |
Roel Kluin | e1af14e | 2008-02-02 21:07:38 +0100 | [diff] [blame] | 424 | out = !(out & 0x1); |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 425 | break; |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 426 | case GLED_ON: |
| 427 | out = (out & 0x1) + 1; |
| 428 | break; |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 429 | case GPS_ON: |
| 430 | handle = (out) ? gps_on_handle : gps_off_handle; |
| 431 | out = 0x02; |
| 432 | break; |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 433 | default: |
| 434 | out &= 0x1; |
| 435 | break; |
| 436 | } |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 437 | |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 438 | if (write_acpi_int(handle, NULL, out)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 439 | pr_warning(" write failed %x\n", mask); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* /sys/class/led handlers */ |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 443 | #define ASUS_LED_HANDLER(object, mask) \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 444 | static void object##_led_set(struct led_classdev *led_cdev, \ |
| 445 | enum led_brightness value) \ |
| 446 | { \ |
Corentin Chary | e3deda9 | 2008-09-24 10:35:55 +0200 | [diff] [blame] | 447 | object##_led_wk = (value > 0) ? 1 : 0; \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 448 | queue_work(led_workqueue, &object##_led_work); \ |
| 449 | } \ |
| 450 | static void object##_led_update(struct work_struct *ignored) \ |
| 451 | { \ |
| 452 | int value = object##_led_wk; \ |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 453 | write_status(object##_set_handle, value, (mask)); \ |
Corentin Chary | abfa57e | 2009-08-28 12:56:47 +0000 | [diff] [blame] | 454 | } \ |
| 455 | static enum led_brightness object##_led_get( \ |
| 456 | struct led_classdev *led_cdev) \ |
| 457 | { \ |
| 458 | return led_cdev->brightness; \ |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 461 | ASUS_LED_HANDLER(mled, MLED_ON); |
| 462 | ASUS_LED_HANDLER(pled, PLED_ON); |
| 463 | ASUS_LED_HANDLER(rled, RLED_ON); |
| 464 | ASUS_LED_HANDLER(tled, TLED_ON); |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 465 | ASUS_LED_HANDLER(gled, GLED_ON); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 466 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 467 | /* |
| 468 | * Keyboard backlight |
| 469 | */ |
| 470 | static int get_kled_lvl(void) |
| 471 | { |
| 472 | unsigned long long kblv; |
| 473 | struct acpi_object_list params; |
| 474 | union acpi_object in_obj; |
| 475 | acpi_status rv; |
| 476 | |
| 477 | params.count = 1; |
| 478 | params.pointer = &in_obj; |
| 479 | in_obj.type = ACPI_TYPE_INTEGER; |
| 480 | in_obj.integer.value = 2; |
| 481 | |
| 482 | rv = acpi_evaluate_integer(kled_get_handle, NULL, ¶ms, &kblv); |
| 483 | if (ACPI_FAILURE(rv)) { |
| 484 | pr_warning("Error reading kled level\n"); |
| 485 | return 0; |
| 486 | } |
| 487 | return kblv; |
| 488 | } |
| 489 | |
| 490 | static int set_kled_lvl(int kblv) |
| 491 | { |
| 492 | if (kblv > 0) |
| 493 | kblv = (1 << 7) | (kblv & 0x7F); |
| 494 | else |
| 495 | kblv = 0; |
| 496 | |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 497 | if (write_acpi_int(kled_set_handle, NULL, kblv)) { |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 498 | pr_warning("Keyboard LED display write failed\n"); |
| 499 | return -EINVAL; |
| 500 | } |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static void kled_led_set(struct led_classdev *led_cdev, |
| 505 | enum led_brightness value) |
| 506 | { |
| 507 | kled_led_wk = value; |
| 508 | queue_work(led_workqueue, &kled_led_work); |
| 509 | } |
| 510 | |
| 511 | static void kled_led_update(struct work_struct *ignored) |
| 512 | { |
| 513 | set_kled_lvl(kled_led_wk); |
| 514 | } |
| 515 | |
| 516 | static enum led_brightness kled_led_get(struct led_classdev *led_cdev) |
| 517 | { |
| 518 | return get_kled_lvl(); |
| 519 | } |
| 520 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 521 | static int get_lcd_state(void) |
| 522 | { |
| 523 | return read_status(LCD_ON); |
| 524 | } |
| 525 | |
| 526 | static int set_lcd_state(int value) |
| 527 | { |
| 528 | int lcd = 0; |
| 529 | acpi_status status = 0; |
| 530 | |
| 531 | lcd = value ? 1 : 0; |
| 532 | |
| 533 | if (lcd == get_lcd_state()) |
| 534 | return 0; |
| 535 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 536 | if (lcd_switch_handle) { |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 537 | status = acpi_evaluate_object(lcd_switch_handle, |
| 538 | NULL, NULL, NULL); |
| 539 | |
| 540 | if (ACPI_FAILURE(status)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 541 | pr_warning("Error switching LCD\n"); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 544 | write_status(NULL, lcd, LCD_ON); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void lcd_blank(int blank) |
| 549 | { |
| 550 | struct backlight_device *bd = asus_backlight_device; |
| 551 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 552 | if (bd) { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 553 | bd->props.power = blank; |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 554 | backlight_update_status(bd); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | static int read_brightness(struct backlight_device *bd) |
| 559 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 560 | unsigned long long value; |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 561 | acpi_status rv = AE_OK; |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 562 | |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 563 | rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value); |
| 564 | if (ACPI_FAILURE(rv)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 565 | pr_warning("Error reading brightness\n"); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 566 | |
| 567 | return value; |
| 568 | } |
| 569 | |
| 570 | static int set_brightness(struct backlight_device *bd, int value) |
| 571 | { |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 572 | if (write_acpi_int(brightness_set_handle, NULL, value)) { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 573 | pr_warning("Error changing brightness\n"); |
Corentin Chary | e5b50f6 | 2009-11-28 10:19:55 +0100 | [diff] [blame] | 574 | return -EIO; |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 575 | } |
Corentin Chary | e5b50f6 | 2009-11-28 10:19:55 +0100 | [diff] [blame] | 576 | return 0; |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static int update_bl_status(struct backlight_device *bd) |
| 580 | { |
| 581 | int rv; |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 582 | int value = bd->props.brightness; |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 583 | |
| 584 | rv = set_brightness(bd, value); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 585 | if (rv) |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 586 | return rv; |
| 587 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 588 | value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0; |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 589 | return set_lcd_state(value); |
| 590 | } |
| 591 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 592 | /* |
| 593 | * Platform device handlers |
| 594 | */ |
| 595 | |
| 596 | /* |
| 597 | * We write our info in page, we begin at offset off and cannot write more |
| 598 | * than count bytes. We set eof to 1 if we handle those 2 values. We return the |
| 599 | * number of bytes written in page |
| 600 | */ |
| 601 | static ssize_t show_infos(struct device *dev, |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 602 | struct device_attribute *attr, char *page) |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 603 | { |
| 604 | int len = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 605 | unsigned long long temp; |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 606 | char buf[16]; /* enough for all info */ |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 607 | acpi_status rv = AE_OK; |
| 608 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 609 | /* |
| 610 | * We use the easy way, we don't care of off and count, so we don't set eof |
| 611 | * to 1 |
| 612 | */ |
| 613 | |
| 614 | len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n"); |
| 615 | len += sprintf(page + len, "Model reference : %s\n", hotk->name); |
| 616 | /* |
| 617 | * The SFUN method probably allows the original driver to get the list |
| 618 | * of features supported by a given model. For now, 0x0100 or 0x0800 |
| 619 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. |
| 620 | * The significance of others is yet to be found. |
| 621 | */ |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 622 | rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp); |
| 623 | if (!ACPI_FAILURE(rv)) |
Corentin Chary | 1d4a380 | 2009-08-28 12:56:46 +0000 | [diff] [blame] | 624 | len += sprintf(page + len, "SFUN value : %#x\n", |
| 625 | (uint) temp); |
| 626 | /* |
| 627 | * The HWRS method return informations about the hardware. |
| 628 | * 0x80 bit is for WLAN, 0x100 for Bluetooth. |
| 629 | * The significance of others is yet to be found. |
| 630 | * If we don't find the method, we assume the device are present. |
| 631 | */ |
| 632 | rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp); |
| 633 | if (!ACPI_FAILURE(rv)) |
| 634 | len += sprintf(page + len, "HRWS value : %#x\n", |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 635 | (uint) temp); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 636 | /* |
| 637 | * Another value for userspace: the ASYM method returns 0x02 for |
| 638 | * battery low and 0x04 for battery critical, its readings tend to be |
| 639 | * more accurate than those provided by _BST. |
| 640 | * Note: since not all the laptops provide this method, errors are |
| 641 | * silently ignored. |
| 642 | */ |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 643 | rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp); |
| 644 | if (!ACPI_FAILURE(rv)) |
Corentin Chary | 1d4a380 | 2009-08-28 12:56:46 +0000 | [diff] [blame] | 645 | len += sprintf(page + len, "ASYM value : %#x\n", |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 646 | (uint) temp); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 647 | if (asus_info) { |
| 648 | snprintf(buf, 16, "%d", asus_info->length); |
| 649 | len += sprintf(page + len, "DSDT length : %s\n", buf); |
| 650 | snprintf(buf, 16, "%d", asus_info->checksum); |
| 651 | len += sprintf(page + len, "DSDT checksum : %s\n", buf); |
| 652 | snprintf(buf, 16, "%d", asus_info->revision); |
| 653 | len += sprintf(page + len, "DSDT revision : %s\n", buf); |
| 654 | snprintf(buf, 7, "%s", asus_info->oem_id); |
| 655 | len += sprintf(page + len, "OEM id : %s\n", buf); |
| 656 | snprintf(buf, 9, "%s", asus_info->oem_table_id); |
| 657 | len += sprintf(page + len, "OEM table id : %s\n", buf); |
| 658 | snprintf(buf, 16, "%x", asus_info->oem_revision); |
| 659 | len += sprintf(page + len, "OEM revision : 0x%s\n", buf); |
| 660 | snprintf(buf, 5, "%s", asus_info->asl_compiler_id); |
| 661 | len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); |
| 662 | snprintf(buf, 16, "%x", asus_info->asl_compiler_revision); |
| 663 | len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); |
| 664 | } |
| 665 | |
| 666 | return len; |
| 667 | } |
| 668 | |
| 669 | static int parse_arg(const char *buf, unsigned long count, int *val) |
| 670 | { |
| 671 | if (!count) |
| 672 | return 0; |
| 673 | if (count > 31) |
| 674 | return -EINVAL; |
| 675 | if (sscanf(buf, "%i", val) != 1) |
| 676 | return -EINVAL; |
| 677 | return count; |
| 678 | } |
| 679 | |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 680 | static ssize_t store_status(const char *buf, size_t count, |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 681 | acpi_handle handle, int mask) |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 682 | { |
| 683 | int rv, value; |
| 684 | int out = 0; |
| 685 | |
| 686 | rv = parse_arg(buf, count, &value); |
| 687 | if (rv > 0) |
| 688 | out = value ? 1 : 0; |
| 689 | |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 690 | write_status(handle, out, mask); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 691 | |
| 692 | return rv; |
| 693 | } |
| 694 | |
| 695 | /* |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 696 | * LEDD display |
| 697 | */ |
| 698 | static ssize_t show_ledd(struct device *dev, |
| 699 | struct device_attribute *attr, char *buf) |
| 700 | { |
| 701 | return sprintf(buf, "0x%08x\n", hotk->ledd_status); |
| 702 | } |
| 703 | |
| 704 | static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, |
| 705 | const char *buf, size_t count) |
| 706 | { |
| 707 | int rv, value; |
| 708 | |
| 709 | rv = parse_arg(buf, count, &value); |
| 710 | if (rv > 0) { |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 711 | if (write_acpi_int(ledd_set_handle, NULL, value)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 712 | pr_warning("LED display write failed\n"); |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 713 | else |
| 714 | hotk->ledd_status = (u32) value; |
| 715 | } |
| 716 | return rv; |
| 717 | } |
| 718 | |
| 719 | /* |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 720 | * WLAN |
| 721 | */ |
| 722 | static ssize_t show_wlan(struct device *dev, |
| 723 | struct device_attribute *attr, char *buf) |
| 724 | { |
| 725 | return sprintf(buf, "%d\n", read_status(WL_ON)); |
| 726 | } |
| 727 | |
| 728 | static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, |
| 729 | const char *buf, size_t count) |
| 730 | { |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 731 | return store_status(buf, count, wl_switch_handle, WL_ON); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /* |
| 735 | * Bluetooth |
| 736 | */ |
| 737 | static ssize_t show_bluetooth(struct device *dev, |
| 738 | struct device_attribute *attr, char *buf) |
| 739 | { |
| 740 | return sprintf(buf, "%d\n", read_status(BT_ON)); |
| 741 | } |
| 742 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 743 | static ssize_t store_bluetooth(struct device *dev, |
| 744 | struct device_attribute *attr, const char *buf, |
| 745 | size_t count) |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 746 | { |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 747 | return store_status(buf, count, bt_switch_handle, BT_ON); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 748 | } |
| 749 | |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 750 | /* |
| 751 | * Display |
| 752 | */ |
| 753 | static void set_display(int value) |
| 754 | { |
| 755 | /* no sanity check needed for now */ |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 756 | if (write_acpi_int(display_set_handle, NULL, value)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 757 | pr_warning("Error setting display\n"); |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | |
| 761 | static int read_display(void) |
| 762 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 763 | unsigned long long value = 0; |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 764 | acpi_status rv = AE_OK; |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 765 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 766 | /* |
| 767 | * In most of the case, we know how to set the display, but sometime |
| 768 | * we can't read it |
| 769 | */ |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 770 | if (display_get_handle) { |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 771 | rv = acpi_evaluate_integer(display_get_handle, NULL, |
| 772 | NULL, &value); |
| 773 | if (ACPI_FAILURE(rv)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 774 | pr_warning("Error reading display status\n"); |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | value &= 0x0F; /* needed for some models, shouldn't hurt others */ |
| 778 | |
| 779 | return value; |
| 780 | } |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 781 | |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 782 | /* |
| 783 | * Now, *this* one could be more user-friendly, but so far, no-one has |
| 784 | * complained. The significance of bits is the same as in store_disp() |
| 785 | */ |
| 786 | static ssize_t show_disp(struct device *dev, |
| 787 | struct device_attribute *attr, char *buf) |
| 788 | { |
| 789 | return sprintf(buf, "%d\n", read_display()); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * Experimental support for display switching. As of now: 1 should activate |
| 794 | * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. |
| 795 | * Any combination (bitwise) of these will suffice. I never actually tested 4 |
| 796 | * displays hooked up simultaneously, so be warned. See the acpi4asus README |
| 797 | * for more info. |
| 798 | */ |
| 799 | static ssize_t store_disp(struct device *dev, struct device_attribute *attr, |
| 800 | const char *buf, size_t count) |
| 801 | { |
| 802 | int rv, value; |
| 803 | |
| 804 | rv = parse_arg(buf, count, &value); |
| 805 | if (rv > 0) |
| 806 | set_display(value); |
| 807 | return rv; |
| 808 | } |
| 809 | |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 810 | /* |
| 811 | * Light Sens |
| 812 | */ |
| 813 | static void set_light_sens_switch(int value) |
| 814 | { |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 815 | if (write_acpi_int(ls_switch_handle, NULL, value)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 816 | pr_warning("Error setting light sensor switch\n"); |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 817 | hotk->light_switch = value; |
| 818 | } |
| 819 | |
| 820 | static ssize_t show_lssw(struct device *dev, |
| 821 | struct device_attribute *attr, char *buf) |
| 822 | { |
| 823 | return sprintf(buf, "%d\n", hotk->light_switch); |
| 824 | } |
| 825 | |
| 826 | static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, |
| 827 | const char *buf, size_t count) |
| 828 | { |
| 829 | int rv, value; |
| 830 | |
| 831 | rv = parse_arg(buf, count, &value); |
| 832 | if (rv > 0) |
| 833 | set_light_sens_switch(value ? 1 : 0); |
| 834 | |
| 835 | return rv; |
| 836 | } |
| 837 | |
| 838 | static void set_light_sens_level(int value) |
| 839 | { |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 840 | if (write_acpi_int(ls_level_handle, NULL, value)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 841 | pr_warning("Error setting light sensor level\n"); |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 842 | hotk->light_level = value; |
| 843 | } |
| 844 | |
| 845 | static ssize_t show_lslvl(struct device *dev, |
| 846 | struct device_attribute *attr, char *buf) |
| 847 | { |
| 848 | return sprintf(buf, "%d\n", hotk->light_level); |
| 849 | } |
| 850 | |
| 851 | static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, |
| 852 | const char *buf, size_t count) |
| 853 | { |
| 854 | int rv, value; |
| 855 | |
| 856 | rv = parse_arg(buf, count, &value); |
| 857 | if (rv > 0) { |
| 858 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; |
| 859 | /* 0 <= value <= 15 */ |
| 860 | set_light_sens_level(value); |
| 861 | } |
| 862 | |
| 863 | return rv; |
| 864 | } |
| 865 | |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 866 | /* |
| 867 | * GPS |
| 868 | */ |
| 869 | static ssize_t show_gps(struct device *dev, |
| 870 | struct device_attribute *attr, char *buf) |
| 871 | { |
| 872 | return sprintf(buf, "%d\n", read_status(GPS_ON)); |
| 873 | } |
| 874 | |
| 875 | static ssize_t store_gps(struct device *dev, struct device_attribute *attr, |
| 876 | const char *buf, size_t count) |
| 877 | { |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 878 | return store_status(buf, count, NULL, GPS_ON); |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 879 | } |
| 880 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 881 | /* |
| 882 | * Hotkey functions |
| 883 | */ |
| 884 | static struct key_entry *asus_get_entry_by_scancode(int code) |
| 885 | { |
| 886 | struct key_entry *key; |
| 887 | |
| 888 | for (key = asus_keymap; key->type != KE_END; key++) |
| 889 | if (code == key->code) |
| 890 | return key; |
| 891 | |
| 892 | return NULL; |
| 893 | } |
| 894 | |
| 895 | static struct key_entry *asus_get_entry_by_keycode(int code) |
| 896 | { |
| 897 | struct key_entry *key; |
| 898 | |
| 899 | for (key = asus_keymap; key->type != KE_END; key++) |
| 900 | if (code == key->keycode && key->type == KE_KEY) |
| 901 | return key; |
| 902 | |
| 903 | return NULL; |
| 904 | } |
| 905 | |
| 906 | static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode) |
| 907 | { |
| 908 | struct key_entry *key = asus_get_entry_by_scancode(scancode); |
| 909 | |
| 910 | if (key && key->type == KE_KEY) { |
| 911 | *keycode = key->keycode; |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | return -EINVAL; |
| 916 | } |
| 917 | |
| 918 | static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode) |
| 919 | { |
| 920 | struct key_entry *key; |
| 921 | int old_keycode; |
| 922 | |
| 923 | if (keycode < 0 || keycode > KEY_MAX) |
| 924 | return -EINVAL; |
| 925 | |
| 926 | key = asus_get_entry_by_scancode(scancode); |
| 927 | if (key && key->type == KE_KEY) { |
| 928 | old_keycode = key->keycode; |
| 929 | key->keycode = keycode; |
| 930 | set_bit(keycode, dev->keybit); |
| 931 | if (!asus_get_entry_by_keycode(old_keycode)) |
| 932 | clear_bit(old_keycode, dev->keybit); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
Bjorn Helgaas | 586ed16 | 2009-04-30 09:35:53 -0600 | [diff] [blame] | 939 | static void asus_hotk_notify(struct acpi_device *device, u32 event) |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 940 | { |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 941 | static struct key_entry *key; |
Corentin Chary | 6050c8d | 2009-02-15 19:30:19 +0100 | [diff] [blame] | 942 | u16 count; |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 943 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 944 | /* TODO Find a better way to handle events count. */ |
| 945 | if (!hotk) |
| 946 | return; |
| 947 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 948 | /* |
| 949 | * We need to tell the backlight device when the backlight power is |
| 950 | * switched |
| 951 | */ |
| 952 | if (event == ATKD_LCD_ON) { |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 953 | write_status(NULL, 1, LCD_ON); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 954 | lcd_blank(FB_BLANK_UNBLANK); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 955 | } else if (event == ATKD_LCD_OFF) { |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 956 | write_status(NULL, 0, LCD_ON); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 957 | lcd_blank(FB_BLANK_POWERDOWN); |
| 958 | } |
| 959 | |
Corentin Chary | 6050c8d | 2009-02-15 19:30:19 +0100 | [diff] [blame] | 960 | count = hotk->event_count[event % 128]++; |
| 961 | acpi_bus_generate_proc_event(hotk->device, event, count); |
Corentin Chary | 2a7dc0d | 2009-01-20 16:17:42 +0100 | [diff] [blame] | 962 | acpi_bus_generate_netlink_event(hotk->device->pnp.device_class, |
| 963 | dev_name(&hotk->device->dev), event, |
Corentin Chary | 6050c8d | 2009-02-15 19:30:19 +0100 | [diff] [blame] | 964 | count); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 965 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 966 | if (hotk->inputdev) { |
| 967 | key = asus_get_entry_by_scancode(event); |
| 968 | if (!key) |
| 969 | return ; |
| 970 | |
| 971 | switch (key->type) { |
| 972 | case KE_KEY: |
| 973 | input_report_key(hotk->inputdev, key->keycode, 1); |
| 974 | input_sync(hotk->inputdev); |
| 975 | input_report_key(hotk->inputdev, key->keycode, 0); |
| 976 | input_sync(hotk->inputdev); |
| 977 | break; |
| 978 | } |
| 979 | } |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | #define ASUS_CREATE_DEVICE_ATTR(_name) \ |
| 983 | struct device_attribute dev_attr_##_name = { \ |
| 984 | .attr = { \ |
| 985 | .name = __stringify(_name), \ |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 986 | .mode = 0 }, \ |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 987 | .show = NULL, \ |
| 988 | .store = NULL, \ |
| 989 | } |
| 990 | |
| 991 | #define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \ |
| 992 | do { \ |
| 993 | dev_attr_##_name.attr.mode = _mode; \ |
| 994 | dev_attr_##_name.show = _show; \ |
| 995 | dev_attr_##_name.store = _store; \ |
| 996 | } while(0) |
| 997 | |
| 998 | static ASUS_CREATE_DEVICE_ATTR(infos); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 999 | static ASUS_CREATE_DEVICE_ATTR(wlan); |
| 1000 | static ASUS_CREATE_DEVICE_ATTR(bluetooth); |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 1001 | static ASUS_CREATE_DEVICE_ATTR(display); |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 1002 | static ASUS_CREATE_DEVICE_ATTR(ledd); |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1003 | static ASUS_CREATE_DEVICE_ATTR(ls_switch); |
| 1004 | static ASUS_CREATE_DEVICE_ATTR(ls_level); |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1005 | static ASUS_CREATE_DEVICE_ATTR(gps); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1006 | |
| 1007 | static struct attribute *asuspf_attributes[] = { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1008 | &dev_attr_infos.attr, |
| 1009 | &dev_attr_wlan.attr, |
| 1010 | &dev_attr_bluetooth.attr, |
| 1011 | &dev_attr_display.attr, |
| 1012 | &dev_attr_ledd.attr, |
| 1013 | &dev_attr_ls_switch.attr, |
| 1014 | &dev_attr_ls_level.attr, |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1015 | &dev_attr_gps.attr, |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1016 | NULL |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1017 | }; |
| 1018 | |
| 1019 | static struct attribute_group asuspf_attribute_group = { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1020 | .attrs = asuspf_attributes |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | static struct platform_driver asuspf_driver = { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1024 | .driver = { |
| 1025 | .name = ASUS_HOTK_FILE, |
| 1026 | .owner = THIS_MODULE, |
| 1027 | } |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1028 | }; |
| 1029 | |
| 1030 | static struct platform_device *asuspf_device; |
| 1031 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1032 | static void asus_hotk_add_fs(void) |
| 1033 | { |
| 1034 | ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1035 | |
| 1036 | if (wl_switch_handle) |
| 1037 | ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan); |
| 1038 | |
| 1039 | if (bt_switch_handle) |
| 1040 | ASUS_SET_DEVICE_ATTR(bluetooth, 0644, |
| 1041 | show_bluetooth, store_bluetooth); |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 1042 | |
| 1043 | if (display_set_handle && display_get_handle) |
| 1044 | ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1045 | else if (display_set_handle) |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 1046 | ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp); |
| 1047 | |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 1048 | if (ledd_set_handle) |
| 1049 | ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd); |
| 1050 | |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1051 | if (ls_switch_handle && ls_level_handle) { |
| 1052 | ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); |
| 1053 | ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); |
| 1054 | } |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1055 | |
Corentin Chary | f398532 | 2007-05-06 14:48:22 +0200 | [diff] [blame] | 1056 | if (gps_status_handle && gps_on_handle && gps_off_handle) |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1057 | ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1060 | static int asus_handle_init(char *name, acpi_handle * handle, |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1061 | char **paths, int num_paths) |
| 1062 | { |
| 1063 | int i; |
| 1064 | acpi_status status; |
| 1065 | |
| 1066 | for (i = 0; i < num_paths; i++) { |
| 1067 | status = acpi_get_handle(NULL, paths[i], handle); |
| 1068 | if (ACPI_SUCCESS(status)) |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | *handle = NULL; |
| 1073 | return -ENODEV; |
| 1074 | } |
| 1075 | |
| 1076 | #define ASUS_HANDLE_INIT(object) \ |
| 1077 | asus_handle_init(#object, &object##_handle, object##_paths, \ |
| 1078 | ARRAY_SIZE(object##_paths)) |
| 1079 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1080 | /* |
| 1081 | * This function is used to initialize the hotk with right values. In this |
| 1082 | * method, we can make all the detection we want, and modify the hotk struct |
| 1083 | */ |
| 1084 | static int asus_hotk_get_info(void) |
| 1085 | { |
| 1086 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1087 | union acpi_object *model = NULL; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1088 | unsigned long long bsts_result, hwrs_result; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1089 | char *string = NULL; |
| 1090 | acpi_status status; |
| 1091 | |
| 1092 | /* |
| 1093 | * Get DSDT headers early enough to allow for differentiating between |
| 1094 | * models, but late enough to allow acpi_bus_register_driver() to fail |
| 1095 | * before doing anything ACPI-specific. Should we encounter a machine, |
| 1096 | * which needs special handling (i.e. its hotkey device has a different |
| 1097 | * HID), this bit will be moved. A global variable asus_info contains |
| 1098 | * the DSDT header. |
| 1099 | */ |
Len Brown | 894d79b | 2007-02-03 02:13:53 -0500 | [diff] [blame] | 1100 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1101 | if (ACPI_FAILURE(status)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1102 | pr_warning("Couldn't get the DSDT table header\n"); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1103 | |
| 1104 | /* We have to write 0 on init this far for all ASUS models */ |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 1105 | if (write_acpi_int_ret(hotk->handle, "INIT", 0, &buffer)) { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1106 | pr_err("Hotkey initialization failed\n"); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1107 | return -ENODEV; |
| 1108 | } |
| 1109 | |
| 1110 | /* This needs to be called for some laptops to init properly */ |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 1111 | status = |
| 1112 | acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result); |
| 1113 | if (ACPI_FAILURE(status)) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1114 | pr_warning("Error calling BSTS\n"); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1115 | else if (bsts_result) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1116 | pr_notice("BSTS called, 0x%02x returned\n", |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 1117 | (uint) bsts_result); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1118 | |
Corentin Chary | 185e5af | 2007-03-11 10:27:33 +0100 | [diff] [blame] | 1119 | /* This too ... */ |
Corentin Chary | d8c6732 | 2009-11-28 10:27:51 +0100 | [diff] [blame] | 1120 | write_acpi_int(hotk->handle, "CWAP", wapf); |
Corentin Chary | 185e5af | 2007-03-11 10:27:33 +0100 | [diff] [blame] | 1121 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1122 | /* |
| 1123 | * Try to match the object returned by INIT to the specific model. |
| 1124 | * Handle every possible object (or the lack of thereof) the DSDT |
| 1125 | * writers might throw at us. When in trouble, we pass NULL to |
| 1126 | * asus_model_match() and try something completely different. |
| 1127 | */ |
| 1128 | if (buffer.pointer) { |
| 1129 | model = buffer.pointer; |
| 1130 | switch (model->type) { |
| 1131 | case ACPI_TYPE_STRING: |
| 1132 | string = model->string.pointer; |
| 1133 | break; |
| 1134 | case ACPI_TYPE_BUFFER: |
| 1135 | string = model->buffer.pointer; |
| 1136 | break; |
| 1137 | default: |
| 1138 | string = ""; |
| 1139 | break; |
| 1140 | } |
| 1141 | } |
| 1142 | hotk->name = kstrdup(string, GFP_KERNEL); |
| 1143 | if (!hotk->name) |
| 1144 | return -ENOMEM; |
| 1145 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1146 | if (*string) |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1147 | pr_notice(" %s model detected\n", string); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1148 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1149 | ASUS_HANDLE_INIT(mled_set); |
| 1150 | ASUS_HANDLE_INIT(tled_set); |
| 1151 | ASUS_HANDLE_INIT(rled_set); |
| 1152 | ASUS_HANDLE_INIT(pled_set); |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 1153 | ASUS_HANDLE_INIT(gled_set); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1154 | |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 1155 | ASUS_HANDLE_INIT(ledd_set); |
| 1156 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1157 | ASUS_HANDLE_INIT(kled_set); |
| 1158 | ASUS_HANDLE_INIT(kled_get); |
| 1159 | |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1160 | /* |
| 1161 | * The HWRS method return informations about the hardware. |
| 1162 | * 0x80 bit is for WLAN, 0x100 for Bluetooth. |
| 1163 | * The significance of others is yet to be found. |
| 1164 | * If we don't find the method, we assume the device are present. |
| 1165 | */ |
Corentin Chary | 9a81685 | 2007-03-11 10:25:38 +0100 | [diff] [blame] | 1166 | status = |
| 1167 | acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result); |
| 1168 | if (ACPI_FAILURE(status)) |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1169 | hwrs_result = WL_HWRS | BT_HWRS; |
| 1170 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1171 | if (hwrs_result & WL_HWRS) |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1172 | ASUS_HANDLE_INIT(wl_switch); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1173 | if (hwrs_result & BT_HWRS) |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1174 | ASUS_HANDLE_INIT(bt_switch); |
| 1175 | |
| 1176 | ASUS_HANDLE_INIT(wireless_status); |
| 1177 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1178 | ASUS_HANDLE_INIT(brightness_set); |
| 1179 | ASUS_HANDLE_INIT(brightness_get); |
| 1180 | |
| 1181 | ASUS_HANDLE_INIT(lcd_switch); |
| 1182 | |
Corentin Chary | 78127b4 | 2007-01-26 14:04:49 +0100 | [diff] [blame] | 1183 | ASUS_HANDLE_INIT(display_set); |
| 1184 | ASUS_HANDLE_INIT(display_get); |
| 1185 | |
Corentin Chary | be96666 | 2009-08-29 10:28:29 +0200 | [diff] [blame] | 1186 | /* |
| 1187 | * There is a lot of models with "ALSL", but a few get |
| 1188 | * a real light sens, so we need to check it. |
| 1189 | */ |
Corentin Chary | 832d995 | 2007-05-06 14:47:29 +0200 | [diff] [blame] | 1190 | if (!ASUS_HANDLE_INIT(ls_switch)) |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1191 | ASUS_HANDLE_INIT(ls_level); |
| 1192 | |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1193 | ASUS_HANDLE_INIT(gps_on); |
| 1194 | ASUS_HANDLE_INIT(gps_off); |
| 1195 | ASUS_HANDLE_INIT(gps_status); |
| 1196 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1197 | kfree(model); |
| 1198 | |
| 1199 | return AE_OK; |
| 1200 | } |
| 1201 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1202 | static int asus_input_init(void) |
| 1203 | { |
| 1204 | const struct key_entry *key; |
| 1205 | int result; |
| 1206 | |
| 1207 | hotk->inputdev = input_allocate_device(); |
| 1208 | if (!hotk->inputdev) { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1209 | pr_info("Unable to allocate input device\n"); |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | hotk->inputdev->name = "Asus Laptop extra buttons"; |
| 1213 | hotk->inputdev->phys = ASUS_HOTK_FILE "/input0"; |
| 1214 | hotk->inputdev->id.bustype = BUS_HOST; |
| 1215 | hotk->inputdev->getkeycode = asus_getkeycode; |
| 1216 | hotk->inputdev->setkeycode = asus_setkeycode; |
| 1217 | |
| 1218 | for (key = asus_keymap; key->type != KE_END; key++) { |
| 1219 | switch (key->type) { |
| 1220 | case KE_KEY: |
| 1221 | set_bit(EV_KEY, hotk->inputdev->evbit); |
| 1222 | set_bit(key->keycode, hotk->inputdev->keybit); |
| 1223 | break; |
| 1224 | } |
| 1225 | } |
| 1226 | result = input_register_device(hotk->inputdev); |
| 1227 | if (result) { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1228 | pr_info("Unable to register input device\n"); |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1229 | input_free_device(hotk->inputdev); |
| 1230 | } |
| 1231 | return result; |
| 1232 | } |
| 1233 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1234 | static int asus_hotk_check(void) |
| 1235 | { |
| 1236 | int result = 0; |
| 1237 | |
| 1238 | result = acpi_bus_get_status(hotk->device); |
| 1239 | if (result) |
| 1240 | return result; |
| 1241 | |
| 1242 | if (hotk->device->status.present) { |
| 1243 | result = asus_hotk_get_info(); |
| 1244 | } else { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1245 | pr_err("Hotkey device not present, aborting\n"); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1246 | return -EINVAL; |
| 1247 | } |
| 1248 | |
| 1249 | return result; |
| 1250 | } |
| 1251 | |
| 1252 | static int asus_hotk_found; |
| 1253 | |
| 1254 | static int asus_hotk_add(struct acpi_device *device) |
| 1255 | { |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1256 | int result; |
| 1257 | |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1258 | pr_notice("Asus Laptop Support version %s\n", |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1259 | ASUS_LAPTOP_VERSION); |
| 1260 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1261 | hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1262 | if (!hotk) |
| 1263 | return -ENOMEM; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1264 | |
| 1265 | hotk->handle = device->handle; |
| 1266 | strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME); |
| 1267 | strcpy(acpi_device_class(device), ASUS_HOTK_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1268 | device->driver_data = hotk; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1269 | hotk->device = device; |
| 1270 | |
| 1271 | result = asus_hotk_check(); |
| 1272 | if (result) |
| 1273 | goto end; |
| 1274 | |
| 1275 | asus_hotk_add_fs(); |
| 1276 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1277 | asus_hotk_found = 1; |
| 1278 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1279 | /* WLED and BLED are on by default */ |
Corentin Chary | 0e875f4 | 2010-01-10 20:49:26 +0100 | [diff] [blame] | 1280 | if (bluetooth_status != -1) |
| 1281 | write_status(bt_switch_handle, !!bluetooth_status, BT_ON); |
| 1282 | if (wireless_status != -1) |
| 1283 | write_status(wl_switch_handle, !!wireless_status, WL_ON); |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 1284 | |
| 1285 | /* If the h/w switch is off, we need to check the real status */ |
| 1286 | write_status(NULL, read_status(BT_ON), BT_ON); |
| 1287 | write_status(NULL, read_status(WL_ON), WL_ON); |
Corentin Chary | 4564de1 | 2007-01-26 14:04:40 +0100 | [diff] [blame] | 1288 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1289 | /* LCD Backlight is on by default */ |
Corentin Chary | 935ffee | 2007-03-11 10:26:12 +0100 | [diff] [blame] | 1290 | write_status(NULL, 1, LCD_ON); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1291 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1292 | /* Keyboard Backlight is on by default */ |
| 1293 | if (kled_set_handle) |
| 1294 | set_kled_lvl(1); |
| 1295 | |
Corentin Chary | 722ad97 | 2007-01-26 14:04:55 +0100 | [diff] [blame] | 1296 | /* LED display is off by default */ |
| 1297 | hotk->ledd_status = 0xFFF; |
| 1298 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1299 | /* Set initial values of light sensor and level */ |
Corentin Chary | d951d4c | 2009-12-07 22:05:50 +0100 | [diff] [blame] | 1300 | hotk->light_switch = 0; /* Default to light sensor disabled */ |
| 1301 | hotk->light_level = 5; /* level 5 for sensor sensitivity */ |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1302 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1303 | if (ls_switch_handle) |
| 1304 | set_light_sens_switch(hotk->light_switch); |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1305 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1306 | if (ls_level_handle) |
| 1307 | set_light_sens_level(hotk->light_level); |
Corentin Chary | 8b85735 | 2007-01-26 14:04:58 +0100 | [diff] [blame] | 1308 | |
Corentin Chary | e539c2f | 2007-05-06 14:47:06 +0200 | [diff] [blame] | 1309 | /* GPS is on by default */ |
| 1310 | write_status(NULL, 1, GPS_ON); |
| 1311 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1312 | end: |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1313 | if (result) { |
| 1314 | kfree(hotk->name); |
| 1315 | kfree(hotk); |
| 1316 | } |
| 1317 | |
| 1318 | return result; |
| 1319 | } |
| 1320 | |
| 1321 | static int asus_hotk_remove(struct acpi_device *device, int type) |
| 1322 | { |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1323 | kfree(hotk->name); |
| 1324 | kfree(hotk); |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1329 | static void asus_backlight_exit(void) |
| 1330 | { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1331 | if (asus_backlight_device) |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1332 | backlight_device_unregister(asus_backlight_device); |
| 1333 | } |
| 1334 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1335 | #define ASUS_LED_UNREGISTER(object) \ |
Guillaume Chazarain | e1996a69 | 2007-08-16 18:18:53 +0200 | [diff] [blame] | 1336 | if (object##_led.dev) \ |
| 1337 | led_classdev_unregister(&object##_led) |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1338 | |
| 1339 | static void asus_led_exit(void) |
| 1340 | { |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1341 | destroy_workqueue(led_workqueue); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1342 | ASUS_LED_UNREGISTER(mled); |
| 1343 | ASUS_LED_UNREGISTER(tled); |
| 1344 | ASUS_LED_UNREGISTER(pled); |
| 1345 | ASUS_LED_UNREGISTER(rled); |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 1346 | ASUS_LED_UNREGISTER(gled); |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1347 | ASUS_LED_UNREGISTER(kled); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1350 | static void asus_input_exit(void) |
| 1351 | { |
| 1352 | if (hotk->inputdev) |
| 1353 | input_unregister_device(hotk->inputdev); |
| 1354 | } |
| 1355 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1356 | static void __exit asus_laptop_exit(void) |
| 1357 | { |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1358 | asus_backlight_exit(); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1359 | asus_led_exit(); |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1360 | asus_input_exit(); |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1361 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1362 | acpi_bus_unregister_driver(&asus_hotk_driver); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1363 | sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); |
| 1364 | platform_device_unregister(asuspf_device); |
| 1365 | platform_driver_unregister(&asuspf_driver); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1368 | static int asus_backlight_init(struct device *dev) |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1369 | { |
| 1370 | struct backlight_device *bd; |
| 1371 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1372 | if (brightness_set_handle && lcd_switch_handle) { |
| 1373 | bd = backlight_device_register(ASUS_HOTK_FILE, dev, |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1374 | NULL, &asusbl_ops); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1375 | if (IS_ERR(bd)) { |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1376 | pr_err("Could not register asus backlight device\n"); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1377 | asus_backlight_device = NULL; |
| 1378 | return PTR_ERR(bd); |
| 1379 | } |
| 1380 | |
| 1381 | asus_backlight_device = bd; |
| 1382 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1383 | bd->props.max_brightness = 15; |
| 1384 | bd->props.brightness = read_brightness(NULL); |
| 1385 | bd->props.power = FB_BLANK_UNBLANK; |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 1386 | backlight_update_status(bd); |
Corentin Chary | 6b7091e | 2007-01-26 14:04:45 +0100 | [diff] [blame] | 1387 | } |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1391 | static int asus_led_register(acpi_handle handle, |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1392 | struct led_classdev *ldev, struct device *dev) |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1393 | { |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1394 | if (!handle) |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1395 | return 0; |
| 1396 | |
| 1397 | return led_classdev_register(dev, ldev); |
| 1398 | } |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1399 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1400 | #define ASUS_LED_REGISTER(object, device) \ |
| 1401 | asus_led_register(object##_set_handle, &object##_led, device) |
| 1402 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1403 | static int asus_led_init(struct device *dev) |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1404 | { |
| 1405 | int rv; |
| 1406 | |
| 1407 | rv = ASUS_LED_REGISTER(mled, dev); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1408 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1409 | goto out; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1410 | |
| 1411 | rv = ASUS_LED_REGISTER(tled, dev); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1412 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1413 | goto out1; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1414 | |
| 1415 | rv = ASUS_LED_REGISTER(rled, dev); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1416 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1417 | goto out2; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1418 | |
| 1419 | rv = ASUS_LED_REGISTER(pled, dev); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1420 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1421 | goto out3; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1422 | |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 1423 | rv = ASUS_LED_REGISTER(gled, dev); |
| 1424 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1425 | goto out4; |
Corentin Chary | fdd8d08 | 2007-03-11 10:26:48 +0100 | [diff] [blame] | 1426 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1427 | if (kled_set_handle && kled_get_handle) |
| 1428 | rv = ASUS_LED_REGISTER(kled, dev); |
| 1429 | if (rv) |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1430 | goto out5; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1431 | |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1432 | led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 1433 | if (!led_workqueue) |
| 1434 | goto out6; |
| 1435 | |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1436 | return 0; |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1437 | out6: |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1438 | rv = -ENOMEM; |
Corentin Chary | b7d3fbc | 2009-08-28 12:56:50 +0000 | [diff] [blame] | 1439 | ASUS_LED_UNREGISTER(kled); |
| 1440 | out5: |
Al Viro | 3b0d711 | 2007-07-23 11:21:34 +0100 | [diff] [blame] | 1441 | ASUS_LED_UNREGISTER(gled); |
| 1442 | out4: |
| 1443 | ASUS_LED_UNREGISTER(pled); |
| 1444 | out3: |
| 1445 | ASUS_LED_UNREGISTER(rled); |
| 1446 | out2: |
| 1447 | ASUS_LED_UNREGISTER(tled); |
| 1448 | out1: |
| 1449 | ASUS_LED_UNREGISTER(mled); |
| 1450 | out: |
| 1451 | return rv; |
Corentin Chary | be18cda | 2007-01-26 14:04:35 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1454 | static int __init asus_laptop_init(void) |
| 1455 | { |
| 1456 | int result; |
| 1457 | |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1458 | result = acpi_bus_register_driver(&asus_hotk_driver); |
| 1459 | if (result < 0) |
| 1460 | return result; |
| 1461 | |
| 1462 | /* |
| 1463 | * This is a bit of a kludge. We only want this module loaded |
| 1464 | * for ASUS systems, but there's currently no way to probe the |
| 1465 | * ACPI namespace for ASUS HIDs. So we just return failure if |
| 1466 | * we didn't find one, which will cause the module to be |
| 1467 | * unloaded. |
| 1468 | */ |
| 1469 | if (!asus_hotk_found) { |
| 1470 | acpi_bus_unregister_driver(&asus_hotk_driver); |
| 1471 | return -ENODEV; |
| 1472 | } |
| 1473 | |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1474 | result = asus_input_init(); |
| 1475 | if (result) |
| 1476 | goto fail_input; |
| 1477 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1478 | /* Register platform stuff */ |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1479 | result = platform_driver_register(&asuspf_driver); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1480 | if (result) |
| 1481 | goto fail_platform_driver; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1482 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1483 | asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1); |
| 1484 | if (!asuspf_device) { |
| 1485 | result = -ENOMEM; |
| 1486 | goto fail_platform_device1; |
| 1487 | } |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1488 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1489 | result = platform_device_add(asuspf_device); |
| 1490 | if (result) |
| 1491 | goto fail_platform_device2; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1492 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1493 | result = sysfs_create_group(&asuspf_device->dev.kobj, |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1494 | &asuspf_attribute_group); |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1495 | if (result) |
| 1496 | goto fail_sysfs; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1497 | |
Corentin Chary | 116bf2e | 2009-06-16 19:28:46 +0000 | [diff] [blame] | 1498 | result = asus_led_init(&asuspf_device->dev); |
| 1499 | if (result) |
| 1500 | goto fail_led; |
| 1501 | |
| 1502 | if (!acpi_video_backlight_support()) { |
| 1503 | result = asus_backlight_init(&asuspf_device->dev); |
| 1504 | if (result) |
| 1505 | goto fail_backlight; |
| 1506 | } else |
Corentin Chary | 2fcc23d | 2009-06-19 14:52:03 +0200 | [diff] [blame] | 1507 | pr_info("Brightness ignored, must be controlled by " |
Corentin Chary | 116bf2e | 2009-06-16 19:28:46 +0000 | [diff] [blame] | 1508 | "ACPI video driver\n"); |
| 1509 | |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1510 | return 0; |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1511 | |
Corentin Chary | 116bf2e | 2009-06-16 19:28:46 +0000 | [diff] [blame] | 1512 | fail_backlight: |
| 1513 | asus_led_exit(); |
| 1514 | |
| 1515 | fail_led: |
| 1516 | sysfs_remove_group(&asuspf_device->dev.kobj, |
| 1517 | &asuspf_attribute_group); |
| 1518 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1519 | fail_sysfs: |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1520 | platform_device_del(asuspf_device); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1521 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1522 | fail_platform_device2: |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1523 | platform_device_put(asuspf_device); |
| 1524 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1525 | fail_platform_device1: |
Len Brown | 8def05f | 2007-01-30 01:46:43 -0500 | [diff] [blame] | 1526 | platform_driver_unregister(&asuspf_driver); |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1527 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1528 | fail_platform_driver: |
Corentin Chary | 034ce90 | 2009-01-20 16:17:43 +0100 | [diff] [blame] | 1529 | asus_input_exit(); |
| 1530 | |
Corentin Chary | ed6f442 | 2009-01-20 16:17:45 +0100 | [diff] [blame] | 1531 | fail_input: |
Corentin Chary | 85091b7 | 2007-01-26 14:04:30 +0100 | [diff] [blame] | 1532 | |
| 1533 | return result; |
| 1534 | } |
| 1535 | |
| 1536 | module_init(asus_laptop_init); |
| 1537 | module_exit(asus_laptop_exit); |