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