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