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