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