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