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