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