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