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