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