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