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