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