aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/Kconfig15
-rw-r--r--drivers/platform/x86/asus-laptop.c1741
-rw-r--r--drivers/platform/x86/asus_acpi.c3
-rw-r--r--drivers/platform/x86/classmate-laptop.c35
-rw-r--r--drivers/platform/x86/compal-laptop.c247
-rw-r--r--drivers/platform/x86/dell-laptop.c257
-rw-r--r--drivers/platform/x86/dell-wmi.c16
-rw-r--r--drivers/platform/x86/eeepc-laptop.c21
-rw-r--r--drivers/platform/x86/hp-wmi.c20
-rw-r--r--drivers/platform/x86/msi-laptop.c360
-rw-r--r--drivers/platform/x86/panasonic-laptop.c15
-rw-r--r--drivers/platform/x86/sony-laptop.c91
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c120
-rw-r--r--drivers/platform/x86/topstar-laptop.c13
-rw-r--r--drivers/platform/x86/toshiba_acpi.c205
-rw-r--r--drivers/platform/x86/toshiba_bluetooth.c4
-rw-r--r--drivers/platform/x86/wmi.c4
17 files changed, 2009 insertions, 1158 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index f526e735c5ab..e631dbeafd79 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -59,6 +59,8 @@ config ASUS_LAPTOP
59 select NEW_LEDS 59 select NEW_LEDS
60 select BACKLIGHT_CLASS_DEVICE 60 select BACKLIGHT_CLASS_DEVICE
61 depends on INPUT 61 depends on INPUT
62 depends on RFKILL || RFKILL = n
63 select INPUT_SPARSEKMAP
62 ---help--- 64 ---help---
63 This is the new Linux driver for Asus laptops. It may also support some 65 This is the new Linux driver for Asus laptops. It may also support some
64 MEDION, JVC or VICTOR laptops. It makes all the extra buttons generate 66 MEDION, JVC or VICTOR laptops. It makes all the extra buttons generate
@@ -79,6 +81,7 @@ config DELL_LAPTOP
79 depends on BACKLIGHT_CLASS_DEVICE 81 depends on BACKLIGHT_CLASS_DEVICE
80 depends on RFKILL || RFKILL = n 82 depends on RFKILL || RFKILL = n
81 depends on POWER_SUPPLY 83 depends on POWER_SUPPLY
84 depends on SERIO_I8042
82 default n 85 default n
83 ---help--- 86 ---help---
84 This driver adds support for rfkill and backlight control to Dell 87 This driver adds support for rfkill and backlight control to Dell
@@ -147,6 +150,7 @@ config MSI_LAPTOP
147 tristate "MSI Laptop Extras" 150 tristate "MSI Laptop Extras"
148 depends on ACPI 151 depends on ACPI
149 depends on BACKLIGHT_CLASS_DEVICE 152 depends on BACKLIGHT_CLASS_DEVICE
153 depends on RFKILL
150 ---help--- 154 ---help---
151 This is a driver for laptops built by MSI (MICRO-STAR 155 This is a driver for laptops built by MSI (MICRO-STAR
152 INTERNATIONAL): 156 INTERNATIONAL):
@@ -176,6 +180,7 @@ config COMPAL_LAPTOP
176 tristate "Compal Laptop Extras" 180 tristate "Compal Laptop Extras"
177 depends on ACPI 181 depends on ACPI
178 depends on BACKLIGHT_CLASS_DEVICE 182 depends on BACKLIGHT_CLASS_DEVICE
183 depends on RFKILL
179 ---help--- 184 ---help---
180 This is a driver for laptops built by Compal: 185 This is a driver for laptops built by Compal:
181 186
@@ -319,9 +324,15 @@ config THINKPAD_ACPI_VIDEO
319 server running, phase of the moon, and the current mood of 324 server running, phase of the moon, and the current mood of
320 Schroedinger's cat. If you can use X.org's RandR to control 325 Schroedinger's cat. If you can use X.org's RandR to control
321 your ThinkPad's video output ports instead of this feature, 326 your ThinkPad's video output ports instead of this feature,
322 don't think twice: do it and say N here to save some memory. 327 don't think twice: do it and say N here to save memory and avoid
328 bad interactions with X.org.
329
330 NOTE: access to this feature is limited to processes with the
331 CAP_SYS_ADMIN capability, to avoid local DoS issues in platforms
332 where it interacts badly with X.org.
323 333
324 If you are not sure, say Y here. 334 If you are not sure, say Y here but do try to check if you could
335 be using X.org RandR instead.
325 336
326config THINKPAD_ACPI_HOTKEY_POLL 337config THINKPAD_ACPI_HOTKEY_POLL
327 bool "Support NVRAM polling for hot keys" 338 bool "Support NVRAM polling for hot keys"
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index 61a1c7503658..791fcf321506 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -45,58 +45,23 @@
45#include <linux/fb.h> 45#include <linux/fb.h>
46#include <linux/leds.h> 46#include <linux/leds.h>
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/uaccess.h>
49#include <linux/input.h>
50#include <linux/input/sparse-keymap.h>
51#include <linux/rfkill.h>
48#include <acpi/acpi_drivers.h> 52#include <acpi/acpi_drivers.h>
49#include <acpi/acpi_bus.h> 53#include <acpi/acpi_bus.h>
50#include <asm/uaccess.h>
51#include <linux/input.h>
52
53#define ASUS_LAPTOP_VERSION "0.42"
54
55#define ASUS_HOTK_NAME "Asus Laptop Support"
56#define ASUS_HOTK_CLASS "hotkey"
57#define ASUS_HOTK_DEVICE_NAME "Hotkey"
58#define ASUS_HOTK_FILE KBUILD_MODNAME
59#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
60 54
55#define ASUS_LAPTOP_VERSION "0.42"
61 56
62/* 57#define ASUS_LAPTOP_NAME "Asus Laptop Support"
63 * Some events we use, same for all Asus 58#define ASUS_LAPTOP_CLASS "hotkey"
64 */ 59#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
65#define ATKD_BR_UP 0x10 60#define ASUS_LAPTOP_FILE KBUILD_MODNAME
66#define ATKD_BR_DOWN 0x20 61#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
67#define ATKD_LCD_ON 0x33
68#define ATKD_LCD_OFF 0x34
69
70/*
71 * Known bits returned by \_SB.ATKD.HWRS
72 */
73#define WL_HWRS 0x80
74#define BT_HWRS 0x100
75
76/*
77 * Flags for hotk status
78 * WL_ON and BT_ON are also used for wireless_status()
79 */
80#define WL_ON 0x01 /* internal Wifi */
81#define BT_ON 0x02 /* internal Bluetooth */
82#define MLED_ON 0x04 /* mail LED */
83#define TLED_ON 0x08 /* touchpad LED */
84#define RLED_ON 0x10 /* Record LED */
85#define PLED_ON 0x20 /* Phone LED */
86#define GLED_ON 0x40 /* Gaming LED */
87#define LCD_ON 0x80 /* LCD backlight */
88#define GPS_ON 0x100 /* GPS */
89#define KEY_ON 0x200 /* Keyboard backlight */
90
91#define ASUS_LOG ASUS_HOTK_FILE ": "
92#define ASUS_ERR KERN_ERR ASUS_LOG
93#define ASUS_WARNING KERN_WARNING ASUS_LOG
94#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
95#define ASUS_INFO KERN_INFO ASUS_LOG
96#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
97 62
98MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); 63MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
99MODULE_DESCRIPTION(ASUS_HOTK_NAME); 64MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
100MODULE_LICENSE("GPL"); 65MODULE_LICENSE("GPL");
101 66
102/* 67/*
@@ -113,225 +78,209 @@ static uint wapf = 1;
113module_param(wapf, uint, 0644); 78module_param(wapf, uint, 0644);
114MODULE_PARM_DESC(wapf, "WAPF value"); 79MODULE_PARM_DESC(wapf, "WAPF value");
115 80
116#define ASUS_HANDLE(object, paths...) \ 81static uint wlan_status = 1;
117 static acpi_handle object##_handle = NULL; \ 82static uint bluetooth_status = 1;
118 static char *object##_paths[] = { paths } 83
84module_param(wlan_status, uint, 0644);
85MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
86 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
87 "default is 1");
88
89module_param(bluetooth_status, uint, 0644);
90MODULE_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
94/*
95 * Some events we use, same for all Asus
96 */
97#define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
98#define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
99#define ATKD_BR_MIN ATKD_BR_UP
100#define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
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 */
114#define WL_RSTS 0x01 /* internal Wifi */
115#define BT_RSTS 0x02 /* internal Bluetooth */
119 116
120/* LED */ 117/* LED */
121ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED"); 118#define METHOD_MLED "MLED"
122ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED"); 119#define METHOD_TLED "TLED"
123ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ 120#define METHOD_RLED "RLED" /* W1JC */
124ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ 121#define METHOD_PLED "PLED" /* A7J */
125ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */ 122#define METHOD_GLED "GLED" /* G1, G2 (probably) */
126 123
127/* LEDD */ 124/* LEDD */
128ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM"); 125#define METHOD_LEDD "SLCM"
129 126
130/* 127/*
131 * Bluetooth and WLAN 128 * Bluetooth and WLAN
132 * WLED and BLED are not handled like other XLED, because in some dsdt 129 * WLED and BLED are not handled like other XLED, because in some dsdt
133 * they also control the WLAN/Bluetooth device. 130 * they also control the WLAN/Bluetooth device.
134 */ 131 */
135ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED"); 132#define METHOD_WLAN "WLED"
136ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED"); 133#define METHOD_BLUETOOTH "BLED"
137ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */ 134#define METHOD_WL_STATUS "RSTS"
138 135
139/* Brightness */ 136/* Brightness */
140ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV"); 137#define METHOD_BRIGHTNESS_SET "SPLV"
141ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV"); 138#define METHOD_BRIGHTNESS_GET "GPLV"
142 139
143/* Backlight */ 140/* Backlight */
144ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ 141static acpi_handle lcd_switch_handle;
145 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ 142static const char *lcd_switch_paths[] = {
146 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ 143 "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
147 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ 144 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
148 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ 145 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
149 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */ 146 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
150 "\\_SB.PCI0.PX40.Q10", /* S1x */ 147 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
151 "\\Q10"); /* A2x, L2D, L3D, M2E */ 148 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
149 "\\_SB.PCI0.PX40.Q10", /* S1x */
150 "\\Q10"}; /* A2x, L2D, L3D, M2E */
152 151
153/* Display */ 152/* Display */
154ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP"); 153#define METHOD_SWITCH_DISPLAY "SDSP"
155ASUS_HANDLE(display_get, 154
156 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */ 155static acpi_handle display_get_handle;
157 "\\_SB.PCI0.P0P1.VGA.GETD", 156static const char *display_get_paths[] = {
158 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */ 157 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
159 "\\_SB.PCI0.P0P2.VGA.GETD", 158 "\\_SB.PCI0.P0P1.VGA.GETD",
160 /* A6V A6Q */ 159 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
161 "\\_SB.PCI0.P0P3.VGA.GETD", 160 "\\_SB.PCI0.P0P2.VGA.GETD",
162 /* A6T, A6M */ 161 /* A6V A6Q */
163 "\\_SB.PCI0.P0PA.VGA.GETD", 162 "\\_SB.PCI0.P0P3.VGA.GETD",
164 /* L3C */ 163 /* A6T, A6M */
165 "\\_SB.PCI0.PCI1.VGAC.NMAP", 164 "\\_SB.PCI0.P0PA.VGA.GETD",
166 /* Z96F */ 165 /* L3C */
167 "\\_SB.PCI0.VGA.GETD", 166 "\\_SB.PCI0.PCI1.VGAC.NMAP",
168 /* A2D */ 167 /* Z96F */
169 "\\ACTD", 168 "\\_SB.PCI0.VGA.GETD",
170 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ 169 /* A2D */
171 "\\ADVG", 170 "\\ACTD",
172 /* P30 */ 171 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
173 "\\DNXT", 172 "\\ADVG",
174 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ 173 /* P30 */
175 "\\INFB", 174 "\\DNXT",
176 /* A3F A6F A3N A3L M6N W3N W6A */ 175 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
177 "\\SSTE"); 176 "\\INFB",
178 177 /* A3F A6F A3N A3L M6N W3N W6A */
179ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */ 178 "\\SSTE"};
180ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */ 179
180#define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
181#define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
181 182
182/* GPS */ 183/* GPS */
183/* R2H use different handle for GPS on/off */ 184/* R2H use different handle for GPS on/off */
184ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */ 185#define METHOD_GPS_ON "SDON"
185ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */ 186#define METHOD_GPS_OFF "SDOF"
186ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST"); 187#define METHOD_GPS_STATUS "GPST"
187 188
188/* Keyboard light */ 189/* Keyboard light */
189ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB"); 190#define METHOD_KBD_LIGHT_SET "SLKB"
190ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB"); 191#define METHOD_KBD_LIGHT_GET "GLKB"
191 192
192/* 193/*
193 * This is the main structure, we can use it to store anything interesting 194 * Define a specific led structure to keep the main structure clean
194 * about the hotk device
195 */ 195 */
196struct asus_hotk { 196struct asus_led {
197 char *name; /* laptop name */ 197 int wk;
198 struct acpi_device *device; /* the device we are in */ 198 struct work_struct work;
199 acpi_handle handle; /* the handle of the hotk device */ 199 struct led_classdev led;
200 char status; /* status of the hotk, for LEDs, ... */ 200 struct asus_laptop *asus;
201 u32 ledd_status; /* status of the LED display */ 201 const char *method;
202 u8 light_level; /* light sensor level */
203 u8 light_switch; /* light sensor switch value */
204 u16 event_count[128]; /* count for each event TODO make this better */
205 struct input_dev *inputdev;
206 u16 *keycode_map;
207}; 202};
208 203
209/* 204/*
210 * This header is made available to allow proper configuration given model, 205 * This is the main structure, we can use it to store anything interesting
211 * revision number , ... this info cannot go in struct asus_hotk because it is 206 * about the hotk device
212 * available before the hotk
213 */
214static struct acpi_table_header *asus_info;
215
216/* The actual device the driver binds to */
217static struct asus_hotk *hotk;
218
219/*
220 * The hotkey driver declaration
221 */ 207 */
222static const struct acpi_device_id asus_device_ids[] = { 208struct asus_laptop {
223 {"ATK0100", 0}, 209 char *name; /* laptop name */
224 {"ATK0101", 0},
225 {"", 0},
226};
227MODULE_DEVICE_TABLE(acpi, asus_device_ids);
228 210
229static int asus_hotk_add(struct acpi_device *device); 211 struct acpi_table_header *dsdt_info;
230static int asus_hotk_remove(struct acpi_device *device, int type); 212 struct platform_device *platform_device;
231static void asus_hotk_notify(struct acpi_device *device, u32 event); 213 struct acpi_device *device; /* the device we are in */
214 struct backlight_device *backlight_device;
232 215
233static struct acpi_driver asus_hotk_driver = { 216 struct input_dev *inputdev;
234 .name = ASUS_HOTK_NAME, 217 struct key_entry *keymap;
235 .class = ASUS_HOTK_CLASS,
236 .owner = THIS_MODULE,
237 .ids = asus_device_ids,
238 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
239 .ops = {
240 .add = asus_hotk_add,
241 .remove = asus_hotk_remove,
242 .notify = asus_hotk_notify,
243 },
244};
245 218
246/* The backlight device /sys/class/backlight */ 219 struct asus_led mled;
247static struct backlight_device *asus_backlight_device; 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;
248 226
249/* 227 int wireless_status;
250 * The backlight class declaration 228 bool have_rsts;
251 */ 229 int lcd_state;
252static int read_brightness(struct backlight_device *bd);
253static int update_bl_status(struct backlight_device *bd);
254static struct backlight_ops asusbl_ops = {
255 .get_brightness = read_brightness,
256 .update_status = update_bl_status,
257};
258 230
259/* 231 struct rfkill *gps_rfkill;
260 * These functions actually update the LED's, and are called from a
261 * workqueue. By doing this as separate work rather than when the LED
262 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
263 * potentially bad time, such as a timer interrupt.
264 */
265static struct workqueue_struct *led_workqueue;
266
267#define ASUS_LED(object, ledname, max) \
268 static void object##_led_set(struct led_classdev *led_cdev, \
269 enum led_brightness value); \
270 static enum led_brightness object##_led_get( \
271 struct led_classdev *led_cdev); \
272 static void object##_led_update(struct work_struct *ignored); \
273 static int object##_led_wk; \
274 static DECLARE_WORK(object##_led_work, object##_led_update); \
275 static struct led_classdev object##_led = { \
276 .name = "asus::" ledname, \
277 .brightness_set = object##_led_set, \
278 .brightness_get = object##_led_get, \
279 .max_brightness = max \
280 }
281 232
282ASUS_LED(mled, "mail", 1); 233 acpi_handle handle; /* the handle of the hotk device */
283ASUS_LED(tled, "touchpad", 1); 234 u32 ledd_status; /* status of the LED display */
284ASUS_LED(rled, "record", 1); 235 u8 light_level; /* light sensor level */
285ASUS_LED(pled, "phone", 1); 236 u8 light_switch; /* light sensor switch value */
286ASUS_LED(gled, "gaming", 1); 237 u16 event_count[128]; /* count for each event TODO make this better */
287ASUS_LED(kled, "kbd_backlight", 3); 238 u16 *keycode_map;
288
289struct key_entry {
290 char type;
291 u8 code;
292 u16 keycode;
293}; 239};
294 240
295enum { KE_KEY, KE_END }; 241static const struct key_entry asus_keymap[] = {
296 242 /* Lenovo SL Specific keycodes */
297static struct key_entry asus_keymap[] = { 243 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
298 {KE_KEY, 0x02, KEY_SCREENLOCK}, 244 {KE_KEY, 0x05, { KEY_WLAN } },
299 {KE_KEY, 0x05, KEY_WLAN}, 245 {KE_KEY, 0x08, { KEY_F13 } },
300 {KE_KEY, 0x08, KEY_F13}, 246 {KE_KEY, 0x17, { KEY_ZOOM } },
301 {KE_KEY, 0x17, KEY_ZOOM}, 247 {KE_KEY, 0x1f, { KEY_BATTERY } },
302 {KE_KEY, 0x1f, KEY_BATTERY}, 248 /* End of Lenovo SL Specific keycodes */
303 {KE_KEY, 0x30, KEY_VOLUMEUP}, 249 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
304 {KE_KEY, 0x31, KEY_VOLUMEDOWN}, 250 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
305 {KE_KEY, 0x32, KEY_MUTE}, 251 {KE_KEY, 0x32, { KEY_MUTE } },
306 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE}, 252 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
307 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE}, 253 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
308 {KE_KEY, 0x40, KEY_PREVIOUSSONG}, 254 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
309 {KE_KEY, 0x41, KEY_NEXTSONG}, 255 {KE_KEY, 0x41, { KEY_NEXTSONG } },
310 {KE_KEY, 0x43, KEY_STOPCD}, 256 {KE_KEY, 0x43, { KEY_STOPCD } },
311 {KE_KEY, 0x45, KEY_PLAYPAUSE}, 257 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
312 {KE_KEY, 0x4c, KEY_MEDIA}, 258 {KE_KEY, 0x4c, { KEY_MEDIA } },
313 {KE_KEY, 0x50, KEY_EMAIL}, 259 {KE_KEY, 0x50, { KEY_EMAIL } },
314 {KE_KEY, 0x51, KEY_WWW}, 260 {KE_KEY, 0x51, { KEY_WWW } },
315 {KE_KEY, 0x55, KEY_CALC}, 261 {KE_KEY, 0x55, { KEY_CALC } },
316 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */ 262 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
317 {KE_KEY, 0x5D, KEY_WLAN}, 263 {KE_KEY, 0x5D, { KEY_WLAN } },
318 {KE_KEY, 0x5E, KEY_WLAN}, 264 {KE_KEY, 0x5E, { KEY_WLAN } },
319 {KE_KEY, 0x5F, KEY_WLAN}, 265 {KE_KEY, 0x5F, { KEY_WLAN } },
320 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE}, 266 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
321 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE}, 267 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
322 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE}, 268 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
323 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE}, 269 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
324 {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */ 270 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
325 {KE_KEY, 0x82, KEY_CAMERA}, 271 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
326 {KE_KEY, 0x88, KEY_WLAN }, 272 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
327 {KE_KEY, 0x8A, KEY_PROG1}, 273 {KE_KEY, 0x82, { KEY_CAMERA } },
328 {KE_KEY, 0x95, KEY_MEDIA}, 274 {KE_KEY, 0x88, { KEY_WLAN } },
329 {KE_KEY, 0x99, KEY_PHONE}, 275 {KE_KEY, 0x8A, { KEY_PROG1 } },
330 {KE_KEY, 0xc4, KEY_KBDILLUMUP}, 276 {KE_KEY, 0x95, { KEY_MEDIA } },
331 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN}, 277 {KE_KEY, 0x99, { KEY_PHONE } },
278 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
279 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
332 {KE_END, 0}, 280 {KE_END, 0},
333}; 281};
334 282
283
335/* 284/*
336 * This function evaluates an ACPI method, given an int as parameter, the 285 * This function evaluates an ACPI method, given an int as parameter, the
337 * method is searched within the scope of the handle, can be NULL. The output 286 * method is searched within the scope of the handle, can be NULL. The output
@@ -339,8 +288,8 @@ static struct key_entry asus_keymap[] = {
339 * 288 *
340 * returns 0 if write is successful, -1 else. 289 * returns 0 if write is successful, -1 else.
341 */ 290 */
342static int write_acpi_int(acpi_handle handle, const char *method, int val, 291static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
343 struct acpi_buffer *output) 292 struct acpi_buffer *output)
344{ 293{
345 struct acpi_object_list params; /* list of input parameters (an int) */ 294 struct acpi_object_list params; /* list of input parameters (an int) */
346 union acpi_object in_obj; /* the only param we use */ 295 union acpi_object in_obj; /* the only param we use */
@@ -361,102 +310,82 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
361 return -1; 310 return -1;
362} 311}
363 312
364static int read_wireless_status(int mask) 313static int write_acpi_int(acpi_handle handle, const char *method, int val)
365{ 314{
366 unsigned long long status; 315 return write_acpi_int_ret(handle, method, val, NULL);
367 acpi_status rv = AE_OK; 316}
317
318static int acpi_check_handle(acpi_handle handle, const char *method,
319 acpi_handle *ret)
320{
321 acpi_status status;
368 322
369 if (!wireless_status_handle) 323 if (method == NULL)
370 return (hotk->status & mask) ? 1 : 0; 324 return -ENODEV;
371 325
372 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status); 326 if (ret)
373 if (ACPI_FAILURE(rv)) 327 status = acpi_get_handle(handle, (char *)method,
374 pr_warning("Error reading Wireless status\n"); 328 ret);
375 else 329 else {
376 return (status & mask) ? 1 : 0; 330 acpi_handle dummy;
377 331
378 return (hotk->status & mask) ? 1 : 0; 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;
379} 342}
380 343
381static int read_gps_status(void) 344/* Generic LED function */
345static int asus_led_set(struct asus_laptop *asus, const char *method,
346 int value)
382{ 347{
383 unsigned long long status; 348 if (!strcmp(method, METHOD_MLED))
384 acpi_status rv = AE_OK; 349 value = !value;
385 350 else if (!strcmp(method, METHOD_GLED))
386 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status); 351 value = !value + 1;
387 if (ACPI_FAILURE(rv))
388 pr_warning("Error reading GPS status\n");
389 else 352 else
390 return status ? 1 : 0; 353 value = !!value;
391 354
392 return (hotk->status & GPS_ON) ? 1 : 0; 355 return write_acpi_int(asus->handle, method, value);
393} 356}
394 357
395/* Generic LED functions */ 358/*
396static int read_status(int mask) 359 * LEDs
360 */
361/* /sys/class/led handlers */
362static void asus_led_cdev_set(struct led_classdev *led_cdev,
363 enum led_brightness value)
397{ 364{
398 /* There is a special method for both wireless devices */ 365 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
399 if (mask == BT_ON || mask == WL_ON) 366 struct asus_laptop *asus = led->asus;
400 return read_wireless_status(mask);
401 else if (mask == GPS_ON)
402 return read_gps_status();
403 367
404 return (hotk->status & mask) ? 1 : 0; 368 led->wk = !!value;
369 queue_work(asus->led_workqueue, &led->work);
405} 370}
406 371
407static void write_status(acpi_handle handle, int out, int mask) 372static void asus_led_cdev_update(struct work_struct *work)
408{ 373{
409 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask); 374 struct asus_led *led = container_of(work, struct asus_led, work);
410 375 struct asus_laptop *asus = led->asus;
411 switch (mask) {
412 case MLED_ON:
413 out = !(out & 0x1);
414 break;
415 case GLED_ON:
416 out = (out & 0x1) + 1;
417 break;
418 case GPS_ON:
419 handle = (out) ? gps_on_handle : gps_off_handle;
420 out = 0x02;
421 break;
422 default:
423 out &= 0x1;
424 break;
425 }
426 376
427 if (write_acpi_int(handle, NULL, out, NULL)) 377 asus_led_set(asus, led->method, led->wk);
428 pr_warning(" write failed %x\n", mask);
429} 378}
430 379
431/* /sys/class/led handlers */ 380static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
432#define ASUS_LED_HANDLER(object, mask) \ 381{
433 static void object##_led_set(struct led_classdev *led_cdev, \ 382 return led_cdev->brightness;
434 enum led_brightness value) \ 383}
435 { \
436 object##_led_wk = (value > 0) ? 1 : 0; \
437 queue_work(led_workqueue, &object##_led_work); \
438 } \
439 static void object##_led_update(struct work_struct *ignored) \
440 { \
441 int value = object##_led_wk; \
442 write_status(object##_set_handle, value, (mask)); \
443 } \
444 static enum led_brightness object##_led_get( \
445 struct led_classdev *led_cdev) \
446 { \
447 return led_cdev->brightness; \
448 }
449
450ASUS_LED_HANDLER(mled, MLED_ON);
451ASUS_LED_HANDLER(pled, PLED_ON);
452ASUS_LED_HANDLER(rled, RLED_ON);
453ASUS_LED_HANDLER(tled, TLED_ON);
454ASUS_LED_HANDLER(gled, GLED_ON);
455 384
456/* 385/*
457 * Keyboard backlight 386 * Keyboard backlight (also a LED)
458 */ 387 */
459static int get_kled_lvl(void) 388static int asus_kled_lvl(struct asus_laptop *asus)
460{ 389{
461 unsigned long long kblv; 390 unsigned long long kblv;
462 struct acpi_object_list params; 391 struct acpi_object_list params;
@@ -468,75 +397,183 @@ static int get_kled_lvl(void)
468 in_obj.type = ACPI_TYPE_INTEGER; 397 in_obj.type = ACPI_TYPE_INTEGER;
469 in_obj.integer.value = 2; 398 in_obj.integer.value = 2;
470 399
471 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv); 400 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
401 &params, &kblv);
472 if (ACPI_FAILURE(rv)) { 402 if (ACPI_FAILURE(rv)) {
473 pr_warning("Error reading kled level\n"); 403 pr_warning("Error reading kled level\n");
474 return 0; 404 return -ENODEV;
475 } 405 }
476 return kblv; 406 return kblv;
477} 407}
478 408
479static int set_kled_lvl(int kblv) 409static int asus_kled_set(struct asus_laptop *asus, int kblv)
480{ 410{
481 if (kblv > 0) 411 if (kblv > 0)
482 kblv = (1 << 7) | (kblv & 0x7F); 412 kblv = (1 << 7) | (kblv & 0x7F);
483 else 413 else
484 kblv = 0; 414 kblv = 0;
485 415
486 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) { 416 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
487 pr_warning("Keyboard LED display write failed\n"); 417 pr_warning("Keyboard LED display write failed\n");
488 return -EINVAL; 418 return -EINVAL;
489 } 419 }
490 return 0; 420 return 0;
491} 421}
492 422
493static void kled_led_set(struct led_classdev *led_cdev, 423static void asus_kled_cdev_set(struct led_classdev *led_cdev,
494 enum led_brightness value) 424 enum led_brightness value)
495{ 425{
496 kled_led_wk = value; 426 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
497 queue_work(led_workqueue, &kled_led_work); 427 struct asus_laptop *asus = led->asus;
428
429 led->wk = value;
430 queue_work(asus->led_workqueue, &led->work);
498} 431}
499 432
500static void kled_led_update(struct work_struct *ignored) 433static void asus_kled_cdev_update(struct work_struct *work)
501{ 434{
502 set_kled_lvl(kled_led_wk); 435 struct asus_led *led = container_of(work, struct asus_led, work);
436 struct asus_laptop *asus = led->asus;
437
438 asus_kled_set(asus, led->wk);
503} 439}
504 440
505static enum led_brightness kled_led_get(struct led_classdev *led_cdev) 441static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
506{ 442{
507 return get_kled_lvl(); 443 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
444 struct asus_laptop *asus = led->asus;
445
446 return asus_kled_lvl(asus);
508} 447}
509 448
510static int get_lcd_state(void) 449static void asus_led_exit(struct asus_laptop *asus)
511{ 450{
512 return read_status(LCD_ON); 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;
466 }
513} 467}
514 468
515static int set_lcd_state(int value) 469/* Ugly macro, need to fix that later */
470static 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))
477 return 0; /* Led not present */
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}
489
490static int asus_led_init(struct asus_laptop *asus)
491{
492 int r;
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 */
500 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
501 if (!asus->led_workqueue)
502 return -ENOMEM;
503
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;
519 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
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 }
533error:
534 if (r)
535 asus_led_exit(asus);
536 return r;
537}
538
539/*
540 * Backlight device
541 */
542static int asus_lcd_status(struct asus_laptop *asus)
543{
544 return asus->lcd_state;
545}
546
547static int asus_lcd_set(struct asus_laptop *asus, int value)
516{ 548{
517 int lcd = 0; 549 int lcd = 0;
518 acpi_status status = 0; 550 acpi_status status = 0;
519 551
520 lcd = value ? 1 : 0; 552 lcd = !!value;
521 553
522 if (lcd == get_lcd_state()) 554 if (lcd == asus_lcd_status(asus))
523 return 0; 555 return 0;
524 556
525 if (lcd_switch_handle) { 557 if (!lcd_switch_handle)
526 status = acpi_evaluate_object(lcd_switch_handle, 558 return -ENODEV;
527 NULL, NULL, NULL); 559
560 status = acpi_evaluate_object(lcd_switch_handle,
561 NULL, NULL, NULL);
528 562
529 if (ACPI_FAILURE(status)) 563 if (ACPI_FAILURE(status)) {
530 pr_warning("Error switching LCD\n"); 564 pr_warning("Error switching LCD\n");
565 return -ENODEV;
531 } 566 }
532 567
533 write_status(NULL, lcd, LCD_ON); 568 asus->lcd_state = lcd;
534 return 0; 569 return 0;
535} 570}
536 571
537static void lcd_blank(int blank) 572static void lcd_blank(struct asus_laptop *asus, int blank)
538{ 573{
539 struct backlight_device *bd = asus_backlight_device; 574 struct backlight_device *bd = asus->backlight_device;
575
576 asus->lcd_state = (blank == FB_BLANK_UNBLANK);
540 577
541 if (bd) { 578 if (bd) {
542 bd->props.power = blank; 579 bd->props.power = blank;
@@ -544,44 +581,91 @@ static void lcd_blank(int blank)
544 } 581 }
545} 582}
546 583
547static int read_brightness(struct backlight_device *bd) 584static int asus_read_brightness(struct backlight_device *bd)
548{ 585{
586 struct asus_laptop *asus = bl_get_data(bd);
549 unsigned long long value; 587 unsigned long long value;
550 acpi_status rv = AE_OK; 588 acpi_status rv = AE_OK;
551 589
552 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value); 590 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
591 NULL, &value);
553 if (ACPI_FAILURE(rv)) 592 if (ACPI_FAILURE(rv))
554 pr_warning("Error reading brightness\n"); 593 pr_warning("Error reading brightness\n");
555 594
556 return value; 595 return value;
557} 596}
558 597
559static int set_brightness(struct backlight_device *bd, int value) 598static int asus_set_brightness(struct backlight_device *bd, int value)
560{ 599{
561 int ret = 0; 600 struct asus_laptop *asus = bl_get_data(bd);
562
563 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
564 /* 0 <= value <= 15 */
565 601
566 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) { 602 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
567 pr_warning("Error changing brightness\n"); 603 pr_warning("Error changing brightness\n");
568 ret = -EIO; 604 return -EIO;
569 } 605 }
570 606 return 0;
571 return ret;
572} 607}
573 608
574static int update_bl_status(struct backlight_device *bd) 609static int update_bl_status(struct backlight_device *bd)
575{ 610{
611 struct asus_laptop *asus = bl_get_data(bd);
576 int rv; 612 int rv;
577 int value = bd->props.brightness; 613 int value = bd->props.brightness;
578 614
579 rv = set_brightness(bd, value); 615 rv = asus_set_brightness(bd, value);
580 if (rv) 616 if (rv)
581 return rv; 617 return rv;
582 618
583 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0; 619 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
584 return set_lcd_state(value); 620 return asus_lcd_set(asus, value);
621}
622
623static struct backlight_ops asusbl_ops = {
624 .get_brightness = asus_read_brightness,
625 .update_status = update_bl_status,
626};
627
628static 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
638static int asus_backlight_init(struct asus_laptop *asus)
639{
640 struct backlight_device *bd;
641 struct device *dev = &asus->platform_device->dev;
642
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) {
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;
657 bd->props.power = FB_BLANK_UNBLANK;
658 bd->props.brightness = asus_read_brightness(bd);
659 backlight_update_status(bd);
660 }
661 return 0;
662}
663
664static void asus_backlight_exit(struct asus_laptop *asus)
665{
666 if (asus->backlight_device)
667 backlight_device_unregister(asus->backlight_device);
668 asus->backlight_device = NULL;
585} 669}
586 670
587/* 671/*
@@ -596,25 +680,26 @@ static int update_bl_status(struct backlight_device *bd)
596static ssize_t show_infos(struct device *dev, 680static ssize_t show_infos(struct device *dev,
597 struct device_attribute *attr, char *page) 681 struct device_attribute *attr, char *page)
598{ 682{
683 struct asus_laptop *asus = dev_get_drvdata(dev);
599 int len = 0; 684 int len = 0;
600 unsigned long long temp; 685 unsigned long long temp;
601 char buf[16]; /* enough for all info */ 686 char buf[16]; /* enough for all info */
602 acpi_status rv = AE_OK; 687 acpi_status rv = AE_OK;
603 688
604 /* 689 /*
605 * We use the easy way, we don't care of off and count, so we don't set eof 690 * We use the easy way, we don't care of off and count,
606 * to 1 691 * so we don't set eof to 1
607 */ 692 */
608 693
609 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n"); 694 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
610 len += sprintf(page + len, "Model reference : %s\n", hotk->name); 695 len += sprintf(page + len, "Model reference : %s\n", asus->name);
611 /* 696 /*
612 * The SFUN method probably allows the original driver to get the list 697 * The SFUN method probably allows the original driver to get the list
613 * of features supported by a given model. For now, 0x0100 or 0x0800 698 * of features supported by a given model. For now, 0x0100 or 0x0800
614 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. 699 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
615 * The significance of others is yet to be found. 700 * The significance of others is yet to be found.
616 */ 701 */
617 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp); 702 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
618 if (!ACPI_FAILURE(rv)) 703 if (!ACPI_FAILURE(rv))
619 len += sprintf(page + len, "SFUN value : %#x\n", 704 len += sprintf(page + len, "SFUN value : %#x\n",
620 (uint) temp); 705 (uint) temp);
@@ -624,7 +709,7 @@ static ssize_t show_infos(struct device *dev,
624 * The significance of others is yet to be found. 709 * The significance of others is yet to be found.
625 * If we don't find the method, we assume the device are present. 710 * If we don't find the method, we assume the device are present.
626 */ 711 */
627 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp); 712 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
628 if (!ACPI_FAILURE(rv)) 713 if (!ACPI_FAILURE(rv))
629 len += sprintf(page + len, "HRWS value : %#x\n", 714 len += sprintf(page + len, "HRWS value : %#x\n",
630 (uint) temp); 715 (uint) temp);
@@ -635,26 +720,26 @@ static ssize_t show_infos(struct device *dev,
635 * Note: since not all the laptops provide this method, errors are 720 * Note: since not all the laptops provide this method, errors are
636 * silently ignored. 721 * silently ignored.
637 */ 722 */
638 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp); 723 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
639 if (!ACPI_FAILURE(rv)) 724 if (!ACPI_FAILURE(rv))
640 len += sprintf(page + len, "ASYM value : %#x\n", 725 len += sprintf(page + len, "ASYM value : %#x\n",
641 (uint) temp); 726 (uint) temp);
642 if (asus_info) { 727 if (asus->dsdt_info) {
643 snprintf(buf, 16, "%d", asus_info->length); 728 snprintf(buf, 16, "%d", asus->dsdt_info->length);
644 len += sprintf(page + len, "DSDT length : %s\n", buf); 729 len += sprintf(page + len, "DSDT length : %s\n", buf);
645 snprintf(buf, 16, "%d", asus_info->checksum); 730 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
646 len += sprintf(page + len, "DSDT checksum : %s\n", buf); 731 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
647 snprintf(buf, 16, "%d", asus_info->revision); 732 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
648 len += sprintf(page + len, "DSDT revision : %s\n", buf); 733 len += sprintf(page + len, "DSDT revision : %s\n", buf);
649 snprintf(buf, 7, "%s", asus_info->oem_id); 734 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
650 len += sprintf(page + len, "OEM id : %s\n", buf); 735 len += sprintf(page + len, "OEM id : %s\n", buf);
651 snprintf(buf, 9, "%s", asus_info->oem_table_id); 736 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
652 len += sprintf(page + len, "OEM table id : %s\n", buf); 737 len += sprintf(page + len, "OEM table id : %s\n", buf);
653 snprintf(buf, 16, "%x", asus_info->oem_revision); 738 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
654 len += sprintf(page + len, "OEM revision : 0x%s\n", buf); 739 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
655 snprintf(buf, 5, "%s", asus_info->asl_compiler_id); 740 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
656 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); 741 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
657 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision); 742 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
658 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); 743 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
659 } 744 }
660 745
@@ -672,8 +757,9 @@ static int parse_arg(const char *buf, unsigned long count, int *val)
672 return count; 757 return count;
673} 758}
674 759
675static ssize_t store_status(const char *buf, size_t count, 760static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
676 acpi_handle handle, int mask) 761 const char *buf, size_t count,
762 const char *method)
677{ 763{
678 int rv, value; 764 int rv, value;
679 int out = 0; 765 int out = 0;
@@ -682,8 +768,8 @@ static ssize_t store_status(const char *buf, size_t count,
682 if (rv > 0) 768 if (rv > 0)
683 out = value ? 1 : 0; 769 out = value ? 1 : 0;
684 770
685 write_status(handle, out, mask); 771 if (write_acpi_int(asus->handle, method, value))
686 772 return -ENODEV;
687 return rv; 773 return rv;
688} 774}
689 775
@@ -693,67 +779,116 @@ static ssize_t store_status(const char *buf, size_t count,
693static ssize_t show_ledd(struct device *dev, 779static ssize_t show_ledd(struct device *dev,
694 struct device_attribute *attr, char *buf) 780 struct device_attribute *attr, char *buf)
695{ 781{
696 return sprintf(buf, "0x%08x\n", hotk->ledd_status); 782 struct asus_laptop *asus = dev_get_drvdata(dev);
783
784 return sprintf(buf, "0x%08x\n", asus->ledd_status);
697} 785}
698 786
699static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, 787static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
700 const char *buf, size_t count) 788 const char *buf, size_t count)
701{ 789{
790 struct asus_laptop *asus = dev_get_drvdata(dev);
702 int rv, value; 791 int rv, value;
703 792
704 rv = parse_arg(buf, count, &value); 793 rv = parse_arg(buf, count, &value);
705 if (rv > 0) { 794 if (rv > 0) {
706 if (write_acpi_int(ledd_set_handle, NULL, value, NULL)) 795 if (write_acpi_int(asus->handle, METHOD_LEDD, value))
707 pr_warning("LED display write failed\n"); 796 pr_warning("LED display write failed\n");
708 else 797 else
709 hotk->ledd_status = (u32) value; 798 asus->ledd_status = (u32) value;
710 } 799 }
711 return rv; 800 return rv;
712} 801}
713 802
714/* 803/*
804 * Wireless
805 */
806static 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
814 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
815 NULL, &status);
816 if (ACPI_FAILURE(rv)) {
817 pr_warning("Error reading Wireless status\n");
818 return -EINVAL;
819 }
820 return !!(status & mask);
821}
822
823/*
715 * WLAN 824 * WLAN
716 */ 825 */
826static 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
717static ssize_t show_wlan(struct device *dev, 835static ssize_t show_wlan(struct device *dev,
718 struct device_attribute *attr, char *buf) 836 struct device_attribute *attr, char *buf)
719{ 837{
720 return sprintf(buf, "%d\n", read_status(WL_ON)); 838 struct asus_laptop *asus = dev_get_drvdata(dev);
839
840 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
721} 841}
722 842
723static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, 843static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
724 const char *buf, size_t count) 844 const char *buf, size_t count)
725{ 845{
726 return store_status(buf, count, wl_switch_handle, WL_ON); 846 struct asus_laptop *asus = dev_get_drvdata(dev);
847
848 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
727} 849}
728 850
729/* 851/*
730 * Bluetooth 852 * Bluetooth
731 */ 853 */
854static 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
732static ssize_t show_bluetooth(struct device *dev, 863static ssize_t show_bluetooth(struct device *dev,
733 struct device_attribute *attr, char *buf) 864 struct device_attribute *attr, char *buf)
734{ 865{
735 return sprintf(buf, "%d\n", read_status(BT_ON)); 866 struct asus_laptop *asus = dev_get_drvdata(dev);
867
868 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
736} 869}
737 870
738static ssize_t store_bluetooth(struct device *dev, 871static ssize_t store_bluetooth(struct device *dev,
739 struct device_attribute *attr, const char *buf, 872 struct device_attribute *attr, const char *buf,
740 size_t count) 873 size_t count)
741{ 874{
742 return store_status(buf, count, bt_switch_handle, BT_ON); 875 struct asus_laptop *asus = dev_get_drvdata(dev);
876
877 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
743} 878}
744 879
745/* 880/*
746 * Display 881 * Display
747 */ 882 */
748static void set_display(int value) 883static void asus_set_display(struct asus_laptop *asus, int value)
749{ 884{
750 /* no sanity check needed for now */ 885 /* no sanity check needed for now */
751 if (write_acpi_int(display_set_handle, NULL, value, NULL)) 886 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
752 pr_warning("Error setting display\n"); 887 pr_warning("Error setting display\n");
753 return; 888 return;
754} 889}
755 890
756static int read_display(void) 891static int read_display(struct asus_laptop *asus)
757{ 892{
758 unsigned long long value = 0; 893 unsigned long long value = 0;
759 acpi_status rv = AE_OK; 894 acpi_status rv = AE_OK;
@@ -769,7 +904,7 @@ static int read_display(void)
769 pr_warning("Error reading display status\n"); 904 pr_warning("Error reading display status\n");
770 } 905 }
771 906
772 value &= 0x0F; /* needed for some models, shouldn't hurt others */ 907 value &= 0x0F; /* needed for some models, shouldn't hurt others */
773 908
774 return value; 909 return value;
775} 910}
@@ -781,7 +916,11 @@ static int read_display(void)
781static ssize_t show_disp(struct device *dev, 916static ssize_t show_disp(struct device *dev,
782 struct device_attribute *attr, char *buf) 917 struct device_attribute *attr, char *buf)
783{ 918{
784 return sprintf(buf, "%d\n", read_display()); 919 struct asus_laptop *asus = dev_get_drvdata(dev);
920
921 if (!display_get_handle)
922 return -ENODEV;
923 return sprintf(buf, "%d\n", read_display(asus));
785} 924}
786 925
787/* 926/*
@@ -794,65 +933,72 @@ static ssize_t show_disp(struct device *dev,
794static ssize_t store_disp(struct device *dev, struct device_attribute *attr, 933static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
795 const char *buf, size_t count) 934 const char *buf, size_t count)
796{ 935{
936 struct asus_laptop *asus = dev_get_drvdata(dev);
797 int rv, value; 937 int rv, value;
798 938
799 rv = parse_arg(buf, count, &value); 939 rv = parse_arg(buf, count, &value);
800 if (rv > 0) 940 if (rv > 0)
801 set_display(value); 941 asus_set_display(asus, value);
802 return rv; 942 return rv;
803} 943}
804 944
805/* 945/*
806 * Light Sens 946 * Light Sens
807 */ 947 */
808static void set_light_sens_switch(int value) 948static void asus_als_switch(struct asus_laptop *asus, int value)
809{ 949{
810 if (write_acpi_int(ls_switch_handle, NULL, value, NULL)) 950 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
811 pr_warning("Error setting light sensor switch\n"); 951 pr_warning("Error setting light sensor switch\n");
812 hotk->light_switch = value; 952 asus->light_switch = value;
813} 953}
814 954
815static ssize_t show_lssw(struct device *dev, 955static ssize_t show_lssw(struct device *dev,
816 struct device_attribute *attr, char *buf) 956 struct device_attribute *attr, char *buf)
817{ 957{
818 return sprintf(buf, "%d\n", hotk->light_switch); 958 struct asus_laptop *asus = dev_get_drvdata(dev);
959
960 return sprintf(buf, "%d\n", asus->light_switch);
819} 961}
820 962
821static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, 963static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
822 const char *buf, size_t count) 964 const char *buf, size_t count)
823{ 965{
966 struct asus_laptop *asus = dev_get_drvdata(dev);
824 int rv, value; 967 int rv, value;
825 968
826 rv = parse_arg(buf, count, &value); 969 rv = parse_arg(buf, count, &value);
827 if (rv > 0) 970 if (rv > 0)
828 set_light_sens_switch(value ? 1 : 0); 971 asus_als_switch(asus, value ? 1 : 0);
829 972
830 return rv; 973 return rv;
831} 974}
832 975
833static void set_light_sens_level(int value) 976static void asus_als_level(struct asus_laptop *asus, int value)
834{ 977{
835 if (write_acpi_int(ls_level_handle, NULL, value, NULL)) 978 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
836 pr_warning("Error setting light sensor level\n"); 979 pr_warning("Error setting light sensor level\n");
837 hotk->light_level = value; 980 asus->light_level = value;
838} 981}
839 982
840static ssize_t show_lslvl(struct device *dev, 983static ssize_t show_lslvl(struct device *dev,
841 struct device_attribute *attr, char *buf) 984 struct device_attribute *attr, char *buf)
842{ 985{
843 return sprintf(buf, "%d\n", hotk->light_level); 986 struct asus_laptop *asus = dev_get_drvdata(dev);
987
988 return sprintf(buf, "%d\n", asus->light_level);
844} 989}
845 990
846static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, 991static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
847 const char *buf, size_t count) 992 const char *buf, size_t count)
848{ 993{
994 struct asus_laptop *asus = dev_get_drvdata(dev);
849 int rv, value; 995 int rv, value;
850 996
851 rv = parse_arg(buf, count, &value); 997 rv = parse_arg(buf, count, &value);
852 if (rv > 0) { 998 if (rv > 0) {
853 value = (0 < value) ? ((15 < value) ? 15 : value) : 0; 999 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
854 /* 0 <= value <= 15 */ 1000 /* 0 <= value <= 15 */
855 set_light_sens_level(value); 1001 asus_als_level(asus, value);
856 } 1002 }
857 1003
858 return rv; 1004 return rv;
@@ -861,197 +1007,309 @@ static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
861/* 1007/*
862 * GPS 1008 * GPS
863 */ 1009 */
1010static int asus_gps_status(struct asus_laptop *asus)
1011{
1012 unsigned long long status;
1013 acpi_status rv = AE_OK;
1014
1015 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
1016 NULL, &status);
1017 if (ACPI_FAILURE(rv)) {
1018 pr_warning("Error reading GPS status\n");
1019 return -ENODEV;
1020 }
1021 return !!status;
1022}
1023
1024static int asus_gps_switch(struct asus_laptop *asus, int status)
1025{
1026 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
1027
1028 if (write_acpi_int(asus->handle, meth, 0x02))
1029 return -ENODEV;
1030 return 0;
1031}
1032
864static ssize_t show_gps(struct device *dev, 1033static ssize_t show_gps(struct device *dev,
865 struct device_attribute *attr, char *buf) 1034 struct device_attribute *attr, char *buf)
866{ 1035{
867 return sprintf(buf, "%d\n", read_status(GPS_ON)); 1036 struct asus_laptop *asus = dev_get_drvdata(dev);
1037
1038 return sprintf(buf, "%d\n", asus_gps_status(asus));
868} 1039}
869 1040
870static ssize_t store_gps(struct device *dev, struct device_attribute *attr, 1041static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
871 const char *buf, size_t count) 1042 const char *buf, size_t count)
872{ 1043{
873 return store_status(buf, count, NULL, GPS_ON); 1044 struct asus_laptop *asus = dev_get_drvdata(dev);
1045 int rv, value;
1046 int ret;
1047
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;
1054 rfkill_set_sw_state(asus->gps_rfkill, !value);
1055 return rv;
874} 1056}
875 1057
876/* 1058/*
877 * Hotkey functions 1059 * rfkill
878 */ 1060 */
879static struct key_entry *asus_get_entry_by_scancode(int code) 1061static int asus_gps_rfkill_set(void *data, bool blocked)
880{ 1062{
881 struct key_entry *key; 1063 acpi_handle handle = data;
882
883 for (key = asus_keymap; key->type != KE_END; key++)
884 if (code == key->code)
885 return key;
886 1064
887 return NULL; 1065 return asus_gps_switch(handle, !blocked);
888} 1066}
889 1067
890static struct key_entry *asus_get_entry_by_keycode(int code) 1068static const struct rfkill_ops asus_gps_rfkill_ops = {
891{ 1069 .set_block = asus_gps_rfkill_set,
892 struct key_entry *key; 1070};
893
894 for (key = asus_keymap; key->type != KE_END; key++)
895 if (code == key->keycode && key->type == KE_KEY)
896 return key;
897 1071
898 return NULL; 1072static 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 }
899} 1079}
900 1080
901static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode) 1081static int asus_rfkill_init(struct asus_laptop *asus)
902{ 1082{
903 struct key_entry *key = asus_get_entry_by_scancode(scancode); 1083 int result;
904 1084
905 if (key && key->type == KE_KEY) { 1085 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
906 *keycode = key->keycode; 1086 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1087 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
907 return 0; 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;
908 } 1100 }
909 1101
910 return -EINVAL; 1102 return result;
911} 1103}
912 1104
913static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode) 1105/*
1106 * Input device (i.e. hotkeys)
1107 */
1108static void asus_input_notify(struct asus_laptop *asus, int event)
914{ 1109{
915 struct key_entry *key; 1110 if (asus->inputdev)
916 int old_keycode; 1111 sparse_keymap_report_event(asus->inputdev, event, 1, true);
1112}
917 1113
918 if (keycode < 0 || keycode > KEY_MAX) 1114static int asus_input_init(struct asus_laptop *asus)
919 return -EINVAL; 1115{
1116 struct input_dev *input;
1117 int error;
920 1118
921 key = asus_get_entry_by_scancode(scancode); 1119 input = input_allocate_device();
922 if (key && key->type == KE_KEY) { 1120 if (!input) {
923 old_keycode = key->keycode; 1121 pr_info("Unable to allocate input device\n");
924 key->keycode = keycode;
925 set_bit(keycode, dev->keybit);
926 if (!asus_get_entry_by_keycode(old_keycode))
927 clear_bit(old_keycode, dev->keybit);
928 return 0; 1122 return 0;
929 } 1123 }
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);
1129
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;
1134 }
1135 error = input_register_device(input);
1136 if (error) {
1137 pr_info("Unable to register input device\n");
1138 goto err_device;
1139 }
1140
1141 asus->inputdev = input;
1142 return 0;
930 1143
931 return -EINVAL; 1144err_keymap:
1145 sparse_keymap_free(input);
1146err_device:
1147 input_free_device(input);
1148 return error;
932} 1149}
933 1150
934static void asus_hotk_notify(struct acpi_device *device, u32 event) 1151static void asus_input_exit(struct asus_laptop *asus)
935{ 1152{
936 static struct key_entry *key; 1153 if (asus->inputdev) {
937 u16 count; 1154 sparse_keymap_free(asus->inputdev);
1155 input_unregister_device(asus->inputdev);
1156 }
1157}
938 1158
939 /* TODO Find a better way to handle events count. */ 1159/*
940 if (!hotk) 1160 * ACPI driver
941 return; 1161 */
1162static void asus_acpi_notify(struct acpi_device *device, u32 event)
1163{
1164 struct asus_laptop *asus = acpi_driver_data(device);
1165 u16 count;
942 1166
943 /* 1167 /*
944 * We need to tell the backlight device when the backlight power is 1168 * We need to tell the backlight device when the backlight power is
945 * switched 1169 * switched
946 */ 1170 */
947 if (event == ATKD_LCD_ON) { 1171 if (event == ATKD_LCD_ON)
948 write_status(NULL, 1, LCD_ON); 1172 lcd_blank(asus, FB_BLANK_UNBLANK);
949 lcd_blank(FB_BLANK_UNBLANK); 1173 else if (event == ATKD_LCD_OFF)
950 } else if (event == ATKD_LCD_OFF) { 1174 lcd_blank(asus, FB_BLANK_POWERDOWN);
951 write_status(NULL, 0, LCD_ON);
952 lcd_blank(FB_BLANK_POWERDOWN);
953 }
954 1175
955 count = hotk->event_count[event % 128]++; 1176 /* TODO Find a better way to handle events count. */
956 acpi_bus_generate_proc_event(hotk->device, event, count); 1177 count = asus->event_count[event % 128]++;
957 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class, 1178 acpi_bus_generate_proc_event(asus->device, event, count);
958 dev_name(&hotk->device->dev), event, 1179 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1180 dev_name(&asus->device->dev), event,
959 count); 1181 count);
960 1182
961 if (hotk->inputdev) { 1183 /* Brightness events are special */
962 key = asus_get_entry_by_scancode(event); 1184 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
963 if (!key) 1185
964 return ; 1186 /* Ignore them completely if the acpi video driver is used */
965 1187 if (asus->backlight_device != NULL) {
966 switch (key->type) { 1188 /* Update the backlight device. */
967 case KE_KEY: 1189 asus_backlight_notify(asus);
968 input_report_key(hotk->inputdev, key->keycode, 1);
969 input_sync(hotk->inputdev);
970 input_report_key(hotk->inputdev, key->keycode, 0);
971 input_sync(hotk->inputdev);
972 break;
973 } 1190 }
1191 return ;
974 } 1192 }
1193 asus_input_notify(asus, event);
975} 1194}
976 1195
977#define ASUS_CREATE_DEVICE_ATTR(_name) \ 1196static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
978 struct device_attribute dev_attr_##_name = { \ 1197static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
979 .attr = { \ 1198static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, show_bluetooth,
980 .name = __stringify(_name), \ 1199 store_bluetooth);
981 .mode = 0 }, \ 1200static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
982 .show = NULL, \ 1201static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
983 .store = NULL, \ 1202static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1203static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1204static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1205
1206static 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
1220static 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;
984 } 1233 }
985 1234
986#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \ 1235 if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL)) {
987 do { \ 1236 err = device_create_file(&device->dev, &dev_attr_bluetooth);
988 dev_attr_##_name.attr.mode = _mode; \ 1237 if (err)
989 dev_attr_##_name.show = _show; \ 1238 return err;
990 dev_attr_##_name.store = _store; \ 1239 }
991 } while(0)
992
993static ASUS_CREATE_DEVICE_ATTR(infos);
994static ASUS_CREATE_DEVICE_ATTR(wlan);
995static ASUS_CREATE_DEVICE_ATTR(bluetooth);
996static ASUS_CREATE_DEVICE_ATTR(display);
997static ASUS_CREATE_DEVICE_ATTR(ledd);
998static ASUS_CREATE_DEVICE_ATTR(ls_switch);
999static ASUS_CREATE_DEVICE_ATTR(ls_level);
1000static ASUS_CREATE_DEVICE_ATTR(gps);
1001
1002static struct attribute *asuspf_attributes[] = {
1003 &dev_attr_infos.attr,
1004 &dev_attr_wlan.attr,
1005 &dev_attr_bluetooth.attr,
1006 &dev_attr_display.attr,
1007 &dev_attr_ledd.attr,
1008 &dev_attr_ls_switch.attr,
1009 &dev_attr_ls_level.attr,
1010 &dev_attr_gps.attr,
1011 NULL
1012};
1013 1240
1014static struct attribute_group asuspf_attribute_group = { 1241 if (!acpi_check_handle(asus->handle, METHOD_SWITCH_DISPLAY, NULL)) {
1015 .attrs = asuspf_attributes 1242 err = device_create_file(&device->dev, &dev_attr_display);
1016}; 1243 if (err)
1244 return err;
1245 }
1017 1246
1018static struct platform_driver asuspf_driver = { 1247 if (!acpi_check_handle(asus->handle, METHOD_LEDD, NULL)) {
1019 .driver = { 1248 err = device_create_file(&device->dev, &dev_attr_ledd);
1020 .name = ASUS_HOTK_FILE, 1249 if (err)
1021 .owner = THIS_MODULE, 1250 return err;
1022 } 1251 }
1023};
1024 1252
1025static struct platform_device *asuspf_device; 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 }
1026 1262
1027static void asus_hotk_add_fs(void) 1263 if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
1028{ 1264 !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
1029 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, 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 }
1030 1270
1031 if (wl_switch_handle) 1271 return err;
1032 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan); 1272}
1273
1274static int asus_platform_init(struct asus_laptop *asus)
1275{
1276 int err;
1033 1277
1034 if (bt_switch_handle) 1278 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1035 ASUS_SET_DEVICE_ATTR(bluetooth, 0644, 1279 if (!asus->platform_device)
1036 show_bluetooth, store_bluetooth); 1280 return -ENOMEM;
1281 platform_set_drvdata(asus->platform_device, asus);
1037 1282
1038 if (display_set_handle && display_get_handle) 1283 err = platform_device_add(asus->platform_device);
1039 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp); 1284 if (err)
1040 else if (display_set_handle) 1285 goto fail_platform_device;
1041 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1042 1286
1043 if (ledd_set_handle) 1287 err = asus_sysfs_init(asus);
1044 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd); 1288 if (err)
1289 goto fail_sysfs;
1290 return 0;
1045 1291
1046 if (ls_switch_handle && ls_level_handle) { 1292fail_sysfs:
1047 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); 1293 asus_sysfs_exit(asus);
1048 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); 1294 platform_device_del(asus->platform_device);
1049 } 1295fail_platform_device:
1296 platform_device_put(asus->platform_device);
1297 return err;
1298}
1050 1299
1051 if (gps_status_handle && gps_on_handle && gps_off_handle) 1300static void asus_platform_exit(struct asus_laptop *asus)
1052 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps); 1301{
1302 asus_sysfs_exit(asus);
1303 platform_device_unregister(asus->platform_device);
1053} 1304}
1054 1305
1306static struct platform_driver platform_driver = {
1307 .driver = {
1308 .name = ASUS_LAPTOP_FILE,
1309 .owner = THIS_MODULE,
1310 }
1311};
1312
1055static int asus_handle_init(char *name, acpi_handle * handle, 1313static int asus_handle_init(char *name, acpi_handle * handle,
1056 char **paths, int num_paths) 1314 char **paths, int num_paths)
1057{ 1315{
@@ -1073,10 +1331,11 @@ static int asus_handle_init(char *name, acpi_handle * handle,
1073 ARRAY_SIZE(object##_paths)) 1331 ARRAY_SIZE(object##_paths))
1074 1332
1075/* 1333/*
1076 * This function is used to initialize the hotk with right values. In this 1334 * This function is used to initialize the context with right values. In this
1077 * method, we can make all the detection we want, and modify the hotk struct 1335 * method, we can make all the detection we want, and modify the asus_laptop
1336 * struct
1078 */ 1337 */
1079static int asus_hotk_get_info(void) 1338static int asus_laptop_get_info(struct asus_laptop *asus)
1080{ 1339{
1081 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1340 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1082 union acpi_object *model = NULL; 1341 union acpi_object *model = NULL;
@@ -1089,22 +1348,21 @@ static int asus_hotk_get_info(void)
1089 * models, but late enough to allow acpi_bus_register_driver() to fail 1348 * models, but late enough to allow acpi_bus_register_driver() to fail
1090 * before doing anything ACPI-specific. Should we encounter a machine, 1349 * before doing anything ACPI-specific. Should we encounter a machine,
1091 * which needs special handling (i.e. its hotkey device has a different 1350 * which needs special handling (i.e. its hotkey device has a different
1092 * HID), this bit will be moved. A global variable asus_info contains 1351 * HID), this bit will be moved.
1093 * the DSDT header.
1094 */ 1352 */
1095 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); 1353 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
1096 if (ACPI_FAILURE(status)) 1354 if (ACPI_FAILURE(status))
1097 pr_warning("Couldn't get the DSDT table header\n"); 1355 pr_warning("Couldn't get the DSDT table header\n");
1098 1356
1099 /* We have to write 0 on init this far for all ASUS models */ 1357 /* We have to write 0 on init this far for all ASUS models */
1100 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { 1358 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
1101 pr_err("Hotkey initialization failed\n"); 1359 pr_err("Hotkey initialization failed\n");
1102 return -ENODEV; 1360 return -ENODEV;
1103 } 1361 }
1104 1362
1105 /* This needs to be called for some laptops to init properly */ 1363 /* This needs to be called for some laptops to init properly */
1106 status = 1364 status =
1107 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result); 1365 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
1108 if (ACPI_FAILURE(status)) 1366 if (ACPI_FAILURE(status))
1109 pr_warning("Error calling BSTS\n"); 1367 pr_warning("Error calling BSTS\n");
1110 else if (bsts_result) 1368 else if (bsts_result)
@@ -1112,8 +1370,8 @@ static int asus_hotk_get_info(void)
1112 (uint) bsts_result); 1370 (uint) bsts_result);
1113 1371
1114 /* This too ... */ 1372 /* This too ... */
1115 write_acpi_int(hotk->handle, "CWAP", wapf, NULL); 1373 if (write_acpi_int(asus->handle, "CWAP", wapf))
1116 1374 pr_err("Error calling CWAP(%d)\n", wapf);
1117 /* 1375 /*
1118 * Try to match the object returned by INIT to the specific model. 1376 * Try to match the object returned by INIT to the specific model.
1119 * Handle every possible object (or the lack of thereof) the DSDT 1377 * Handle every possible object (or the lack of thereof) the DSDT
@@ -1134,397 +1392,210 @@ static int asus_hotk_get_info(void)
1134 break; 1392 break;
1135 } 1393 }
1136 } 1394 }
1137 hotk->name = kstrdup(string, GFP_KERNEL); 1395 asus->name = kstrdup(string, GFP_KERNEL);
1138 if (!hotk->name) 1396 if (!asus->name)
1139 return -ENOMEM; 1397 return -ENOMEM;
1140 1398
1141 if (*string) 1399 if (*string)
1142 pr_notice(" %s model detected\n", string); 1400 pr_notice(" %s model detected\n", string);
1143 1401
1144 ASUS_HANDLE_INIT(mled_set);
1145 ASUS_HANDLE_INIT(tled_set);
1146 ASUS_HANDLE_INIT(rled_set);
1147 ASUS_HANDLE_INIT(pled_set);
1148 ASUS_HANDLE_INIT(gled_set);
1149
1150 ASUS_HANDLE_INIT(ledd_set);
1151
1152 ASUS_HANDLE_INIT(kled_set);
1153 ASUS_HANDLE_INIT(kled_get);
1154
1155 /* 1402 /*
1156 * The HWRS method return informations about the hardware. 1403 * The HWRS method return informations about the hardware.
1157 * 0x80 bit is for WLAN, 0x100 for Bluetooth. 1404 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1158 * The significance of others is yet to be found. 1405 * The significance of others is yet to be found.
1159 * If we don't find the method, we assume the device are present.
1160 */ 1406 */
1161 status = 1407 status =
1162 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result); 1408 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
1163 if (ACPI_FAILURE(status)) 1409 if (!ACPI_FAILURE(status))
1164 hwrs_result = WL_HWRS | BT_HWRS; 1410 pr_notice(" HRWS returned %x", (int)hwrs_result);
1165
1166 if (hwrs_result & WL_HWRS)
1167 ASUS_HANDLE_INIT(wl_switch);
1168 if (hwrs_result & BT_HWRS)
1169 ASUS_HANDLE_INIT(bt_switch);
1170
1171 ASUS_HANDLE_INIT(wireless_status);
1172 1411
1173 ASUS_HANDLE_INIT(brightness_set); 1412 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
1174 ASUS_HANDLE_INIT(brightness_get); 1413 asus->have_rsts = true;
1175 1414
1415 /* Scheduled for removal */
1176 ASUS_HANDLE_INIT(lcd_switch); 1416 ASUS_HANDLE_INIT(lcd_switch);
1177
1178 ASUS_HANDLE_INIT(display_set);
1179 ASUS_HANDLE_INIT(display_get); 1417 ASUS_HANDLE_INIT(display_get);
1180 1418
1181 /*
1182 * There is a lot of models with "ALSL", but a few get
1183 * a real light sens, so we need to check it.
1184 */
1185 if (!ASUS_HANDLE_INIT(ls_switch))
1186 ASUS_HANDLE_INIT(ls_level);
1187
1188 ASUS_HANDLE_INIT(gps_on);
1189 ASUS_HANDLE_INIT(gps_off);
1190 ASUS_HANDLE_INIT(gps_status);
1191
1192 kfree(model); 1419 kfree(model);
1193 1420
1194 return AE_OK; 1421 return AE_OK;
1195} 1422}
1196 1423
1197static int asus_input_init(void) 1424static bool asus_device_present;
1198{
1199 const struct key_entry *key;
1200 int result;
1201 1425
1202 hotk->inputdev = input_allocate_device(); 1426static int __devinit asus_acpi_init(struct asus_laptop *asus)
1203 if (!hotk->inputdev) {
1204 pr_info("Unable to allocate input device\n");
1205 return 0;
1206 }
1207 hotk->inputdev->name = "Asus Laptop extra buttons";
1208 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1209 hotk->inputdev->id.bustype = BUS_HOST;
1210 hotk->inputdev->getkeycode = asus_getkeycode;
1211 hotk->inputdev->setkeycode = asus_setkeycode;
1212
1213 for (key = asus_keymap; key->type != KE_END; key++) {
1214 switch (key->type) {
1215 case KE_KEY:
1216 set_bit(EV_KEY, hotk->inputdev->evbit);
1217 set_bit(key->keycode, hotk->inputdev->keybit);
1218 break;
1219 }
1220 }
1221 result = input_register_device(hotk->inputdev);
1222 if (result) {
1223 pr_info("Unable to register input device\n");
1224 input_free_device(hotk->inputdev);
1225 }
1226 return result;
1227}
1228
1229static int asus_hotk_check(void)
1230{ 1427{
1231 int result = 0; 1428 int result = 0;
1232 1429
1233 result = acpi_bus_get_status(hotk->device); 1430 result = acpi_bus_get_status(asus->device);
1234 if (result) 1431 if (result)
1235 return result; 1432 return result;
1236 1433 if (!asus->device->status.present) {
1237 if (hotk->device->status.present) {
1238 result = asus_hotk_get_info();
1239 } else {
1240 pr_err("Hotkey device not present, aborting\n"); 1434 pr_err("Hotkey device not present, aborting\n");
1241 return -EINVAL; 1435 return -ENODEV;
1242 } 1436 }
1243 1437
1244 return result; 1438 result = asus_laptop_get_info(asus);
1245}
1246
1247static int asus_hotk_found;
1248
1249static int asus_hotk_add(struct acpi_device *device)
1250{
1251 int result;
1252
1253 pr_notice("Asus Laptop Support version %s\n",
1254 ASUS_LAPTOP_VERSION);
1255
1256 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1257 if (!hotk)
1258 return -ENOMEM;
1259
1260 hotk->handle = device->handle;
1261 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1262 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
1263 device->driver_data = hotk;
1264 hotk->device = device;
1265
1266 result = asus_hotk_check();
1267 if (result) 1439 if (result)
1268 goto end; 1440 return result;
1269
1270 asus_hotk_add_fs();
1271
1272 asus_hotk_found = 1;
1273 1441
1274 /* WLED and BLED are on by default */ 1442 /* WLED and BLED are on by default */
1275 write_status(bt_switch_handle, 1, BT_ON); 1443 if (bluetooth_status >= 0)
1276 write_status(wl_switch_handle, 1, WL_ON); 1444 asus_bluetooth_set(asus, !!bluetooth_status);
1277
1278 /* If the h/w switch is off, we need to check the real status */
1279 write_status(NULL, read_status(BT_ON), BT_ON);
1280 write_status(NULL, read_status(WL_ON), WL_ON);
1281 1445
1282 /* LCD Backlight is on by default */ 1446 if (wlan_status >= 0)
1283 write_status(NULL, 1, LCD_ON); 1447 asus_wlan_set(asus, !!wlan_status);
1284 1448
1285 /* Keyboard Backlight is on by default */ 1449 /* Keyboard Backlight is on by default */
1286 if (kled_set_handle) 1450 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
1287 set_kled_lvl(1); 1451 asus_kled_set(asus, 1);
1288 1452
1289 /* LED display is off by default */ 1453 /* LED display is off by default */
1290 hotk->ledd_status = 0xFFF; 1454 asus->ledd_status = 0xFFF;
1291 1455
1292 /* Set initial values of light sensor and level */ 1456 /* Set initial values of light sensor and level */
1293 hotk->light_switch = 0; /* Default to light sensor disabled */ 1457 asus->light_switch = 0; /* Default to light sensor disabled */
1294 hotk->light_level = 5; /* level 5 for sensor sensitivity */ 1458 asus->light_level = 5; /* level 5 for sensor sensitivity */
1295 1459
1296 if (ls_switch_handle) 1460 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1297 set_light_sens_switch(hotk->light_switch); 1461 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1298 1462 asus_als_switch(asus, asus->light_switch);
1299 if (ls_level_handle) 1463 asus_als_level(asus, asus->light_level);
1300 set_light_sens_level(hotk->light_level);
1301
1302 /* GPS is on by default */
1303 write_status(NULL, 1, GPS_ON);
1304
1305end:
1306 if (result) {
1307 kfree(hotk->name);
1308 kfree(hotk);
1309 } 1464 }
1310 1465
1466 asus->lcd_state = 1; /* LCD should be on when the module load */
1311 return result; 1467 return result;
1312} 1468}
1313 1469
1314static int asus_hotk_remove(struct acpi_device *device, int type) 1470static int __devinit asus_acpi_add(struct acpi_device *device)
1315{
1316 kfree(hotk->name);
1317 kfree(hotk);
1318
1319 return 0;
1320}
1321
1322static void asus_backlight_exit(void)
1323{ 1471{
1324 if (asus_backlight_device) 1472 struct asus_laptop *asus;
1325 backlight_device_unregister(asus_backlight_device); 1473 int result;
1326}
1327
1328#define ASUS_LED_UNREGISTER(object) \
1329 if (object##_led.dev) \
1330 led_classdev_unregister(&object##_led)
1331 1474
1332static void asus_led_exit(void) 1475 pr_notice("Asus Laptop Support version %s\n",
1333{ 1476 ASUS_LAPTOP_VERSION);
1334 destroy_workqueue(led_workqueue); 1477 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1335 ASUS_LED_UNREGISTER(mled); 1478 if (!asus)
1336 ASUS_LED_UNREGISTER(tled); 1479 return -ENOMEM;
1337 ASUS_LED_UNREGISTER(pled); 1480 asus->handle = device->handle;
1338 ASUS_LED_UNREGISTER(rled); 1481 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1339 ASUS_LED_UNREGISTER(gled); 1482 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1340 ASUS_LED_UNREGISTER(kled); 1483 device->driver_data = asus;
1341} 1484 asus->device = device;
1342 1485
1343static void asus_input_exit(void) 1486 result = asus_acpi_init(asus);
1344{ 1487 if (result)
1345 if (hotk->inputdev) 1488 goto fail_platform;
1346 input_unregister_device(hotk->inputdev);
1347}
1348 1489
1349static void __exit asus_laptop_exit(void) 1490 /*
1350{ 1491 * Register the platform device first. It is used as a parent for the
1351 asus_backlight_exit(); 1492 * sub-devices below.
1352 asus_led_exit(); 1493 */
1353 asus_input_exit(); 1494 result = asus_platform_init(asus);
1495 if (result)
1496 goto fail_platform;
1354 1497
1355 acpi_bus_unregister_driver(&asus_hotk_driver); 1498 if (!acpi_video_backlight_support()) {
1356 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); 1499 result = asus_backlight_init(asus);
1357 platform_device_unregister(asuspf_device); 1500 if (result)
1358 platform_driver_unregister(&asuspf_driver); 1501 goto fail_backlight;
1359} 1502 } else
1503 pr_info("Backlight controlled by ACPI video driver\n");
1360 1504
1361static int asus_backlight_init(struct device *dev) 1505 result = asus_input_init(asus);
1362{ 1506 if (result)
1363 struct backlight_device *bd; 1507 goto fail_input;
1364 1508
1365 if (brightness_set_handle && lcd_switch_handle) { 1509 result = asus_led_init(asus);
1366 bd = backlight_device_register(ASUS_HOTK_FILE, dev, 1510 if (result)
1367 NULL, &asusbl_ops); 1511 goto fail_led;
1368 if (IS_ERR(bd)) {
1369 pr_err("Could not register asus backlight device\n");
1370 asus_backlight_device = NULL;
1371 return PTR_ERR(bd);
1372 }
1373 1512
1374 asus_backlight_device = bd; 1513 result = asus_rfkill_init(asus);
1514 if (result)
1515 goto fail_rfkill;
1375 1516
1376 bd->props.max_brightness = 15; 1517 asus_device_present = true;
1377 bd->props.brightness = read_brightness(NULL);
1378 bd->props.power = FB_BLANK_UNBLANK;
1379 backlight_update_status(bd);
1380 }
1381 return 0; 1518 return 0;
1382}
1383 1519
1384static int asus_led_register(acpi_handle handle, 1520fail_rfkill:
1385 struct led_classdev *ldev, struct device *dev) 1521 asus_led_exit(asus);
1386{ 1522fail_led:
1387 if (!handle) 1523 asus_input_exit(asus);
1388 return 0; 1524fail_input:
1525 asus_backlight_exit(asus);
1526fail_backlight:
1527 asus_platform_exit(asus);
1528fail_platform:
1529 kfree(asus->name);
1530 kfree(asus);
1389 1531
1390 return led_classdev_register(dev, ldev); 1532 return result;
1391} 1533}
1392 1534
1393#define ASUS_LED_REGISTER(object, device) \ 1535static int asus_acpi_remove(struct acpi_device *device, int type)
1394 asus_led_register(object##_set_handle, &object##_led, device)
1395
1396static int asus_led_init(struct device *dev)
1397{ 1536{
1398 int rv; 1537 struct asus_laptop *asus = acpi_driver_data(device);
1399
1400 rv = ASUS_LED_REGISTER(mled, dev);
1401 if (rv)
1402 goto out;
1403
1404 rv = ASUS_LED_REGISTER(tled, dev);
1405 if (rv)
1406 goto out1;
1407
1408 rv = ASUS_LED_REGISTER(rled, dev);
1409 if (rv)
1410 goto out2;
1411
1412 rv = ASUS_LED_REGISTER(pled, dev);
1413 if (rv)
1414 goto out3;
1415
1416 rv = ASUS_LED_REGISTER(gled, dev);
1417 if (rv)
1418 goto out4;
1419 1538
1420 if (kled_set_handle && kled_get_handle) 1539 asus_backlight_exit(asus);
1421 rv = ASUS_LED_REGISTER(kled, dev); 1540 asus_rfkill_exit(asus);
1422 if (rv) 1541 asus_led_exit(asus);
1423 goto out5; 1542 asus_input_exit(asus);
1424 1543 asus_platform_exit(asus);
1425 led_workqueue = create_singlethread_workqueue("led_workqueue");
1426 if (!led_workqueue)
1427 goto out6;
1428 1544
1545 kfree(asus->name);
1546 kfree(asus);
1429 return 0; 1547 return 0;
1430out6:
1431 rv = -ENOMEM;
1432 ASUS_LED_UNREGISTER(kled);
1433out5:
1434 ASUS_LED_UNREGISTER(gled);
1435out4:
1436 ASUS_LED_UNREGISTER(pled);
1437out3:
1438 ASUS_LED_UNREGISTER(rled);
1439out2:
1440 ASUS_LED_UNREGISTER(tled);
1441out1:
1442 ASUS_LED_UNREGISTER(mled);
1443out:
1444 return rv;
1445} 1548}
1446 1549
1550static const struct acpi_device_id asus_device_ids[] = {
1551 {"ATK0100", 0},
1552 {"ATK0101", 0},
1553 {"", 0},
1554};
1555MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1556
1557static struct acpi_driver asus_acpi_driver = {
1558 .name = ASUS_LAPTOP_NAME,
1559 .class = ASUS_LAPTOP_CLASS,
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
1447static int __init asus_laptop_init(void) 1570static int __init asus_laptop_init(void)
1448{ 1571{
1449 int result; 1572 int result;
1450 1573
1451 result = acpi_bus_register_driver(&asus_hotk_driver); 1574 result = platform_driver_register(&platform_driver);
1452 if (result < 0) 1575 if (result < 0)
1453 return result; 1576 return result;
1454 1577
1455 /* 1578 result = acpi_bus_register_driver(&asus_acpi_driver);
1456 * This is a bit of a kludge. We only want this module loaded 1579 if (result < 0)
1457 * for ASUS systems, but there's currently no way to probe the 1580 goto fail_acpi_driver;
1458 * ACPI namespace for ASUS HIDs. So we just return failure if 1581 if (!asus_device_present) {
1459 * we didn't find one, which will cause the module to be 1582 result = -ENODEV;
1460 * unloaded. 1583 goto fail_no_device;
1461 */
1462 if (!asus_hotk_found) {
1463 acpi_bus_unregister_driver(&asus_hotk_driver);
1464 return -ENODEV;
1465 }
1466
1467 result = asus_input_init();
1468 if (result)
1469 goto fail_input;
1470
1471 /* Register platform stuff */
1472 result = platform_driver_register(&asuspf_driver);
1473 if (result)
1474 goto fail_platform_driver;
1475
1476 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1477 if (!asuspf_device) {
1478 result = -ENOMEM;
1479 goto fail_platform_device1;
1480 } 1584 }
1481
1482 result = platform_device_add(asuspf_device);
1483 if (result)
1484 goto fail_platform_device2;
1485
1486 result = sysfs_create_group(&asuspf_device->dev.kobj,
1487 &asuspf_attribute_group);
1488 if (result)
1489 goto fail_sysfs;
1490
1491 result = asus_led_init(&asuspf_device->dev);
1492 if (result)
1493 goto fail_led;
1494
1495 if (!acpi_video_backlight_support()) {
1496 result = asus_backlight_init(&asuspf_device->dev);
1497 if (result)
1498 goto fail_backlight;
1499 } else
1500 pr_info("Brightness ignored, must be controlled by "
1501 "ACPI video driver\n");
1502
1503 return 0; 1585 return 0;
1504 1586
1505fail_backlight: 1587fail_no_device:
1506 asus_led_exit(); 1588 acpi_bus_unregister_driver(&asus_acpi_driver);
1507 1589fail_acpi_driver:
1508fail_led: 1590 platform_driver_unregister(&platform_driver);
1509 sysfs_remove_group(&asuspf_device->dev.kobj,
1510 &asuspf_attribute_group);
1511
1512fail_sysfs:
1513 platform_device_del(asuspf_device);
1514
1515fail_platform_device2:
1516 platform_device_put(asuspf_device);
1517
1518fail_platform_device1:
1519 platform_driver_unregister(&asuspf_driver);
1520
1521fail_platform_driver:
1522 asus_input_exit();
1523
1524fail_input:
1525
1526 return result; 1591 return result;
1527} 1592}
1528 1593
1594static void __exit asus_laptop_exit(void)
1595{
1596 acpi_bus_unregister_driver(&asus_acpi_driver);
1597 platform_driver_unregister(&platform_driver);
1598}
1599
1529module_init(asus_laptop_init); 1600module_init(asus_laptop_init);
1530module_exit(asus_laptop_exit); 1601module_exit(asus_laptop_exit);
diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
index c1d2aeeea948..1381430e1105 100644
--- a/drivers/platform/x86/asus_acpi.c
+++ b/drivers/platform/x86/asus_acpi.c
@@ -1225,9 +1225,8 @@ static int asus_model_match(char *model)
1225 else if (strncmp(model, "M2N", 3) == 0 || 1225 else if (strncmp(model, "M2N", 3) == 0 ||
1226 strncmp(model, "M3N", 3) == 0 || 1226 strncmp(model, "M3N", 3) == 0 ||
1227 strncmp(model, "M5N", 3) == 0 || 1227 strncmp(model, "M5N", 3) == 0 ||
1228 strncmp(model, "M6N", 3) == 0 ||
1229 strncmp(model, "S1N", 3) == 0 || 1228 strncmp(model, "S1N", 3) == 0 ||
1230 strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0) 1229 strncmp(model, "S5N", 3) == 0)
1231 return xxN; 1230 return xxN;
1232 else if (strncmp(model, "M1", 2) == 0) 1231 else if (strncmp(model, "M1", 2) == 0)
1233 return M1A; 1232 return M1A;
diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index ed90082cdf1d..035a7dd65a3f 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -34,6 +34,11 @@ struct cmpc_accel {
34#define CMPC_ACCEL_SENSITIVITY_DEFAULT 5 34#define CMPC_ACCEL_SENSITIVITY_DEFAULT 5
35 35
36 36
37#define CMPC_ACCEL_HID "ACCE0000"
38#define CMPC_TABLET_HID "TBLT0000"
39#define CMPC_BL_HID "IPML200"
40#define CMPC_KEYS_HID "FnBT0000"
41
37/* 42/*
38 * Generic input device code. 43 * Generic input device code.
39 */ 44 */
@@ -282,10 +287,9 @@ static int cmpc_accel_remove(struct acpi_device *acpi, int type)
282} 287}
283 288
284static const struct acpi_device_id cmpc_accel_device_ids[] = { 289static const struct acpi_device_id cmpc_accel_device_ids[] = {
285 {"ACCE0000", 0}, 290 {CMPC_ACCEL_HID, 0},
286 {"", 0} 291 {"", 0}
287}; 292};
288MODULE_DEVICE_TABLE(acpi, cmpc_accel_device_ids);
289 293
290static struct acpi_driver cmpc_accel_acpi_driver = { 294static struct acpi_driver cmpc_accel_acpi_driver = {
291 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
@@ -366,10 +370,9 @@ static int cmpc_tablet_resume(struct acpi_device *acpi)
366} 370}
367 371
368static const struct acpi_device_id cmpc_tablet_device_ids[] = { 372static const struct acpi_device_id cmpc_tablet_device_ids[] = {
369 {"TBLT0000", 0}, 373 {CMPC_TABLET_HID, 0},
370 {"", 0} 374 {"", 0}
371}; 375};
372MODULE_DEVICE_TABLE(acpi, cmpc_tablet_device_ids);
373 376
374static struct acpi_driver cmpc_tablet_acpi_driver = { 377static struct acpi_driver cmpc_tablet_acpi_driver = {
375 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
@@ -477,17 +480,16 @@ static int cmpc_bl_remove(struct acpi_device *acpi, int type)
477 return 0; 480 return 0;
478} 481}
479 482
480static const struct acpi_device_id cmpc_device_ids[] = { 483static const struct acpi_device_id cmpc_bl_device_ids[] = {
481 {"IPML200", 0}, 484 {CMPC_BL_HID, 0},
482 {"", 0} 485 {"", 0}
483}; 486};
484MODULE_DEVICE_TABLE(acpi, cmpc_device_ids);
485 487
486static struct acpi_driver cmpc_bl_acpi_driver = { 488static struct acpi_driver cmpc_bl_acpi_driver = {
487 .owner = THIS_MODULE, 489 .owner = THIS_MODULE,
488 .name = "cmpc", 490 .name = "cmpc",
489 .class = "cmpc", 491 .class = "cmpc",
490 .ids = cmpc_device_ids, 492 .ids = cmpc_bl_device_ids,
491 .ops = { 493 .ops = {
492 .add = cmpc_bl_add, 494 .add = cmpc_bl_add,
493 .remove = cmpc_bl_remove 495 .remove = cmpc_bl_remove
@@ -505,6 +507,10 @@ static int cmpc_keys_codes[] = {
505 KEY_BRIGHTNESSDOWN, 507 KEY_BRIGHTNESSDOWN,
506 KEY_BRIGHTNESSUP, 508 KEY_BRIGHTNESSUP,
507 KEY_VENDOR, 509 KEY_VENDOR,
510 KEY_UNKNOWN,
511 KEY_CAMERA,
512 KEY_BACK,
513 KEY_FORWARD,
508 KEY_MAX 514 KEY_MAX
509}; 515};
510 516
@@ -540,10 +546,9 @@ static int cmpc_keys_remove(struct acpi_device *acpi, int type)
540} 546}
541 547
542static const struct acpi_device_id cmpc_keys_device_ids[] = { 548static const struct acpi_device_id cmpc_keys_device_ids[] = {
543 {"FnBT0000", 0}, 549 {CMPC_KEYS_HID, 0},
544 {"", 0} 550 {"", 0}
545}; 551};
546MODULE_DEVICE_TABLE(acpi, cmpc_keys_device_ids);
547 552
548static struct acpi_driver cmpc_keys_acpi_driver = { 553static struct acpi_driver cmpc_keys_acpi_driver = {
549 .owner = THIS_MODULE, 554 .owner = THIS_MODULE,
@@ -607,3 +612,13 @@ static void cmpc_exit(void)
607 612
608module_init(cmpc_init); 613module_init(cmpc_init);
609module_exit(cmpc_exit); 614module_exit(cmpc_exit);
615
616static const struct acpi_device_id cmpc_device_ids[] = {
617 {CMPC_ACCEL_HID, 0},
618 {CMPC_TABLET_HID, 0},
619 {CMPC_BL_HID, 0},
620 {CMPC_KEYS_HID, 0},
621 {"", 0}
622};
623
624MODULE_DEVICE_TABLE(acpi, cmpc_device_ids);
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 1a387e79f719..2740b40aad9b 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -26,17 +26,8 @@
26/* 26/*
27 * comapl-laptop.c - Compal laptop support. 27 * comapl-laptop.c - Compal laptop support.
28 * 28 *
29 * This driver exports a few files in /sys/devices/platform/compal-laptop/: 29 * The driver registers itself with the rfkill subsystem and
30 * 30 * the Linux backlight control subsystem.
31 * wlan - wlan subsystem state: contains 0 or 1 (rw)
32 *
33 * bluetooth - Bluetooth subsystem state: contains 0 or 1 (rw)
34 *
35 * raw - raw value taken from embedded controller register (ro)
36 *
37 * In addition to these platform device attributes the driver
38 * registers itself in the Linux backlight control subsystem and is
39 * available to userspace under /sys/class/backlight/compal-laptop/.
40 * 31 *
41 * This driver might work on other laptops produced by Compal. If you 32 * This driver might work on other laptops produced by Compal. If you
42 * want to try it you can pass force=1 as argument to the module which 33 * want to try it you can pass force=1 as argument to the module which
@@ -51,6 +42,7 @@
51#include <linux/dmi.h> 42#include <linux/dmi.h>
52#include <linux/backlight.h> 43#include <linux/backlight.h>
53#include <linux/platform_device.h> 44#include <linux/platform_device.h>
45#include <linux/rfkill.h>
54 46
55#define COMPAL_DRIVER_VERSION "0.2.6" 47#define COMPAL_DRIVER_VERSION "0.2.6"
56 48
@@ -63,6 +55,10 @@
63#define WLAN_MASK 0x01 55#define WLAN_MASK 0x01
64#define BT_MASK 0x02 56#define BT_MASK 0x02
65 57
58static struct rfkill *wifi_rfkill;
59static struct rfkill *bt_rfkill;
60static struct platform_device *compal_device;
61
66static int force; 62static int force;
67module_param(force, bool, 0); 63module_param(force, bool, 0);
68MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); 64MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
@@ -88,65 +84,75 @@ static int get_lcd_level(void)
88 return (int) result; 84 return (int) result;
89} 85}
90 86
91static int set_wlan_state(int state) 87static int compal_rfkill_set(void *data, bool blocked)
92{ 88{
89 unsigned long radio = (unsigned long) data;
93 u8 result, value; 90 u8 result, value;
94 91
95 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 92 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
96 93
97 if ((result & KILLSWITCH_MASK) == 0) 94 if (!blocked)
98 return -EINVAL; 95 value = (u8) (result | radio);
99 else { 96 else
100 if (state) 97 value = (u8) (result & ~radio);
101 value = (u8) (result | WLAN_MASK); 98 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
102 else
103 value = (u8) (result & ~WLAN_MASK);
104 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
105 }
106 99
107 return 0; 100 return 0;
108} 101}
109 102
110static int set_bluetooth_state(int state) 103static void compal_rfkill_poll(struct rfkill *rfkill, void *data)
111{ 104{
112 u8 result, value; 105 u8 result;
106 bool hw_blocked;
113 107
114 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 108 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
115 109
116 if ((result & KILLSWITCH_MASK) == 0) 110 hw_blocked = !(result & KILLSWITCH_MASK);
117 return -EINVAL; 111 rfkill_set_hw_state(rfkill, hw_blocked);
118 else {
119 if (state)
120 value = (u8) (result | BT_MASK);
121 else
122 value = (u8) (result & ~BT_MASK);
123 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
124 }
125
126 return 0;
127} 112}
128 113
129static int get_wireless_state(int *wlan, int *bluetooth) 114static const struct rfkill_ops compal_rfkill_ops = {
115 .poll = compal_rfkill_poll,
116 .set_block = compal_rfkill_set,
117};
118
119static int setup_rfkill(void)
130{ 120{
131 u8 result; 121 int ret;
132 122
133 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 123 wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev,
124 RFKILL_TYPE_WLAN, &compal_rfkill_ops,
125 (void *) WLAN_MASK);
126 if (!wifi_rfkill)
127 return -ENOMEM;
134 128
135 if (wlan) { 129 ret = rfkill_register(wifi_rfkill);
136 if ((result & KILLSWITCH_MASK) == 0) 130 if (ret)
137 *wlan = 0; 131 goto err_wifi;
138 else
139 *wlan = result & WLAN_MASK;
140 }
141 132
142 if (bluetooth) { 133 bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev,
143 if ((result & KILLSWITCH_MASK) == 0) 134 RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops,
144 *bluetooth = 0; 135 (void *) BT_MASK);
145 else 136 if (!bt_rfkill) {
146 *bluetooth = (result & BT_MASK) >> 1; 137 ret = -ENOMEM;
138 goto err_allocate_bt;
147 } 139 }
140 ret = rfkill_register(bt_rfkill);
141 if (ret)
142 goto err_register_bt;
148 143
149 return 0; 144 return 0;
145
146err_register_bt:
147 rfkill_destroy(bt_rfkill);
148
149err_allocate_bt:
150 rfkill_unregister(wifi_rfkill);
151
152err_wifi:
153 rfkill_destroy(wifi_rfkill);
154
155 return ret;
150} 156}
151 157
152/* Backlight device stuff */ 158/* Backlight device stuff */
@@ -169,86 +175,6 @@ static struct backlight_ops compalbl_ops = {
169 175
170static struct backlight_device *compalbl_device; 176static struct backlight_device *compalbl_device;
171 177
172/* Platform device */
173
174static ssize_t show_wlan(struct device *dev,
175 struct device_attribute *attr, char *buf)
176{
177 int ret, enabled;
178
179 ret = get_wireless_state(&enabled, NULL);
180 if (ret < 0)
181 return ret;
182
183 return sprintf(buf, "%i\n", enabled);
184}
185
186static ssize_t show_raw(struct device *dev,
187 struct device_attribute *attr, char *buf)
188{
189 u8 result;
190
191 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
192
193 return sprintf(buf, "%i\n", result);
194}
195
196static ssize_t show_bluetooth(struct device *dev,
197 struct device_attribute *attr, char *buf)
198{
199 int ret, enabled;
200
201 ret = get_wireless_state(NULL, &enabled);
202 if (ret < 0)
203 return ret;
204
205 return sprintf(buf, "%i\n", enabled);
206}
207
208static ssize_t store_wlan_state(struct device *dev,
209 struct device_attribute *attr, const char *buf, size_t count)
210{
211 int state, ret;
212
213 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
214 return -EINVAL;
215
216 ret = set_wlan_state(state);
217 if (ret < 0)
218 return ret;
219
220 return count;
221}
222
223static ssize_t store_bluetooth_state(struct device *dev,
224 struct device_attribute *attr, const char *buf, size_t count)
225{
226 int state, ret;
227
228 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
229 return -EINVAL;
230
231 ret = set_bluetooth_state(state);
232 if (ret < 0)
233 return ret;
234
235 return count;
236}
237
238static DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth_state);
239static DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan_state);
240static DEVICE_ATTR(raw, 0444, show_raw, NULL);
241
242static struct attribute *compal_attributes[] = {
243 &dev_attr_bluetooth.attr,
244 &dev_attr_wlan.attr,
245 &dev_attr_raw.attr,
246 NULL
247};
248
249static struct attribute_group compal_attribute_group = {
250 .attrs = compal_attributes
251};
252 178
253static struct platform_driver compal_driver = { 179static struct platform_driver compal_driver = {
254 .driver = { 180 .driver = {
@@ -257,8 +183,6 @@ static struct platform_driver compal_driver = {
257 } 183 }
258}; 184};
259 185
260static struct platform_device *compal_device;
261
262/* Initialization */ 186/* Initialization */
263 187
264static int dmi_check_cb(const struct dmi_system_id *id) 188static int dmi_check_cb(const struct dmi_system_id *id)
@@ -310,6 +234,47 @@ static struct dmi_system_id __initdata compal_dmi_table[] = {
310 }, 234 },
311 .callback = dmi_check_cb 235 .callback = dmi_check_cb
312 }, 236 },
237 {
238 .ident = "Dell Mini 9",
239 .matches = {
240 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
241 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
242 },
243 .callback = dmi_check_cb
244 },
245 {
246 .ident = "Dell Mini 10",
247 .matches = {
248 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
249 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
250 },
251 .callback = dmi_check_cb
252 },
253 {
254 .ident = "Dell Mini 10v",
255 .matches = {
256 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
257 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
258 },
259 .callback = dmi_check_cb
260 },
261 {
262 .ident = "Dell Inspiron 11z",
263 .matches = {
264 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
265 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
266 },
267 .callback = dmi_check_cb
268 },
269 {
270 .ident = "Dell Mini 12",
271 .matches = {
272 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
273 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
274 },
275 .callback = dmi_check_cb
276 },
277
313 { } 278 { }
314}; 279};
315 280
@@ -348,23 +313,21 @@ static int __init compal_init(void)
348 313
349 ret = platform_device_add(compal_device); 314 ret = platform_device_add(compal_device);
350 if (ret) 315 if (ret)
351 goto fail_platform_device1; 316 goto fail_platform_device;
352 317
353 ret = sysfs_create_group(&compal_device->dev.kobj, 318 ret = setup_rfkill();
354 &compal_attribute_group);
355 if (ret) 319 if (ret)
356 goto fail_platform_device2; 320 goto fail_rfkill;
357 321
358 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION 322 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION
359 " successfully loaded.\n"); 323 " successfully loaded.\n");
360 324
361 return 0; 325 return 0;
362 326
363fail_platform_device2: 327fail_rfkill:
364
365 platform_device_del(compal_device); 328 platform_device_del(compal_device);
366 329
367fail_platform_device1: 330fail_platform_device:
368 331
369 platform_device_put(compal_device); 332 platform_device_put(compal_device);
370 333
@@ -382,10 +345,13 @@ fail_backlight:
382static void __exit compal_cleanup(void) 345static void __exit compal_cleanup(void)
383{ 346{
384 347
385 sysfs_remove_group(&compal_device->dev.kobj, &compal_attribute_group);
386 platform_device_unregister(compal_device); 348 platform_device_unregister(compal_device);
387 platform_driver_unregister(&compal_driver); 349 platform_driver_unregister(&compal_driver);
388 backlight_device_unregister(compalbl_device); 350 backlight_device_unregister(compalbl_device);
351 rfkill_unregister(wifi_rfkill);
352 rfkill_destroy(wifi_rfkill);
353 rfkill_unregister(bt_rfkill);
354 rfkill_destroy(bt_rfkill);
389 355
390 printk(KERN_INFO "compal-laptop: driver unloaded.\n"); 356 printk(KERN_INFO "compal-laptop: driver unloaded.\n");
391} 357}
@@ -403,3 +369,8 @@ MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*");
403MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*"); 369MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*");
404MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*"); 370MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*");
405MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*"); 371MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*");
372MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron910:*");
373MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1010:*");
374MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1011:*");
375MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1110:*");
376MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1210:*");
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index 3780994dc8f2..ef614979afe9 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -22,6 +22,8 @@
22#include <linux/rfkill.h> 22#include <linux/rfkill.h>
23#include <linux/power_supply.h> 23#include <linux/power_supply.h>
24#include <linux/acpi.h> 24#include <linux/acpi.h>
25#include <linux/mm.h>
26#include <linux/i8042.h>
25#include "../../firmware/dcdbas.h" 27#include "../../firmware/dcdbas.h"
26 28
27#define BRIGHTNESS_TOKEN 0x7d 29#define BRIGHTNESS_TOKEN 0x7d
@@ -79,9 +81,73 @@ static const struct dmi_system_id __initdata dell_device_table[] = {
79 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), 81 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
80 }, 82 },
81 }, 83 },
84 {
85 .ident = "Dell Computer Corporation",
86 .matches = {
87 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
88 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
89 },
90 },
82 { } 91 { }
83}; 92};
84 93
94static struct dmi_system_id __devinitdata dell_blacklist[] = {
95 /* Supported by compal-laptop */
96 {
97 .ident = "Dell Mini 9",
98 .matches = {
99 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
100 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
101 },
102 },
103 {
104 .ident = "Dell Mini 10",
105 .matches = {
106 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
107 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
108 },
109 },
110 {
111 .ident = "Dell Mini 10v",
112 .matches = {
113 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
114 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
115 },
116 },
117 {
118 .ident = "Dell Inspiron 11z",
119 .matches = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
121 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
122 },
123 },
124 {
125 .ident = "Dell Mini 12",
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
129 },
130 },
131 {}
132};
133
134static struct calling_interface_buffer *buffer;
135static struct page *bufferpage;
136static DEFINE_MUTEX(buffer_mutex);
137
138static int hwswitch_state;
139
140static void get_buffer(void)
141{
142 mutex_lock(&buffer_mutex);
143 memset(buffer, 0, sizeof(struct calling_interface_buffer));
144}
145
146static void release_buffer(void)
147{
148 mutex_unlock(&buffer_mutex);
149}
150
85static void __init parse_da_table(const struct dmi_header *dm) 151static void __init parse_da_table(const struct dmi_header *dm)
86{ 152{
87 /* Final token is a terminator, so we don't want to copy it */ 153 /* Final token is a terminator, so we don't want to copy it */
@@ -160,6 +226,8 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
160/* Derived from information in DellWirelessCtl.cpp: 226/* Derived from information in DellWirelessCtl.cpp:
161 Class 17, select 11 is radio control. It returns an array of 32-bit values. 227 Class 17, select 11 is radio control. It returns an array of 32-bit values.
162 228
229 Input byte 0 = 0: Wireless information
230
163 result[0]: return code 231 result[0]: return code
164 result[1]: 232 result[1]:
165 Bit 0: Hardware switch supported 233 Bit 0: Hardware switch supported
@@ -180,33 +248,62 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
180 Bits 20-31: Reserved 248 Bits 20-31: Reserved
181 result[2]: NVRAM size in bytes 249 result[2]: NVRAM size in bytes
182 result[3]: NVRAM format version number 250 result[3]: NVRAM format version number
251
252 Input byte 0 = 2: Wireless switch configuration
253 result[0]: return code
254 result[1]:
255 Bit 0: Wifi controlled by switch
256 Bit 1: Bluetooth controlled by switch
257 Bit 2: WWAN controlled by switch
258 Bits 3-6: Reserved
259 Bit 7: Wireless switch config locked
260 Bit 8: Wifi locator enabled
261 Bits 9-14: Reserved
262 Bit 15: Wifi locator setting locked
263 Bits 16-31: Reserved
183*/ 264*/
184 265
185static int dell_rfkill_set(void *data, bool blocked) 266static int dell_rfkill_set(void *data, bool blocked)
186{ 267{
187 struct calling_interface_buffer buffer;
188 int disable = blocked ? 1 : 0; 268 int disable = blocked ? 1 : 0;
189 unsigned long radio = (unsigned long)data; 269 unsigned long radio = (unsigned long)data;
270 int hwswitch_bit = (unsigned long)data - 1;
271 int ret = 0;
272
273 get_buffer();
274 dell_send_request(buffer, 17, 11);
275
276 /* If the hardware switch controls this radio, and the hardware
277 switch is disabled, don't allow changing the software state */
278 if ((hwswitch_state & BIT(hwswitch_bit)) &&
279 !(buffer->output[1] & BIT(16))) {
280 ret = -EINVAL;
281 goto out;
282 }
190 283
191 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 284 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
192 buffer.input[0] = (1 | (radio<<8) | (disable << 16)); 285 dell_send_request(buffer, 17, 11);
193 dell_send_request(&buffer, 17, 11);
194 286
195 return 0; 287out:
288 release_buffer();
289 return ret;
196} 290}
197 291
198static void dell_rfkill_query(struct rfkill *rfkill, void *data) 292static void dell_rfkill_query(struct rfkill *rfkill, void *data)
199{ 293{
200 struct calling_interface_buffer buffer;
201 int status; 294 int status;
202 int bit = (unsigned long)data + 16; 295 int bit = (unsigned long)data + 16;
296 int hwswitch_bit = (unsigned long)data - 1;
203 297
204 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 298 get_buffer();
205 dell_send_request(&buffer, 17, 11); 299 dell_send_request(buffer, 17, 11);
206 status = buffer.output[1]; 300 status = buffer->output[1];
301 release_buffer();
207 302
208 rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); 303 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
209 rfkill_set_hw_state(rfkill, !(status & BIT(16))); 304
305 if (hwswitch_state & (BIT(hwswitch_bit)))
306 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
210} 307}
211 308
212static const struct rfkill_ops dell_rfkill_ops = { 309static const struct rfkill_ops dell_rfkill_ops = {
@@ -214,15 +311,36 @@ static const struct rfkill_ops dell_rfkill_ops = {
214 .query = dell_rfkill_query, 311 .query = dell_rfkill_query,
215}; 312};
216 313
314static void dell_update_rfkill(struct work_struct *ignored)
315{
316 if (wifi_rfkill)
317 dell_rfkill_query(wifi_rfkill, (void *)1);
318 if (bluetooth_rfkill)
319 dell_rfkill_query(bluetooth_rfkill, (void *)2);
320 if (wwan_rfkill)
321 dell_rfkill_query(wwan_rfkill, (void *)3);
322}
323static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
324
325
217static int __init dell_setup_rfkill(void) 326static int __init dell_setup_rfkill(void)
218{ 327{
219 struct calling_interface_buffer buffer;
220 int status; 328 int status;
221 int ret; 329 int ret;
222 330
223 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 331 if (dmi_check_system(dell_blacklist)) {
224 dell_send_request(&buffer, 17, 11); 332 printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
225 status = buffer.output[1]; 333 "not enabling rfkill\n");
334 return 0;
335 }
336
337 get_buffer();
338 dell_send_request(buffer, 17, 11);
339 status = buffer->output[1];
340 buffer->input[0] = 0x2;
341 dell_send_request(buffer, 17, 11);
342 hwswitch_state = buffer->output[1];
343 release_buffer();
226 344
227 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { 345 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
228 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, 346 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
@@ -298,39 +416,49 @@ static void dell_cleanup_rfkill(void)
298 416
299static int dell_send_intensity(struct backlight_device *bd) 417static int dell_send_intensity(struct backlight_device *bd)
300{ 418{
301 struct calling_interface_buffer buffer; 419 int ret = 0;
302 420
303 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 421 get_buffer();
304 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 422 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
305 buffer.input[1] = bd->props.brightness; 423 buffer->input[1] = bd->props.brightness;
306 424
307 if (buffer.input[0] == -1) 425 if (buffer->input[0] == -1) {
308 return -ENODEV; 426 ret = -ENODEV;
427 goto out;
428 }
309 429
310 if (power_supply_is_system_supplied() > 0) 430 if (power_supply_is_system_supplied() > 0)
311 dell_send_request(&buffer, 1, 2); 431 dell_send_request(buffer, 1, 2);
312 else 432 else
313 dell_send_request(&buffer, 1, 1); 433 dell_send_request(buffer, 1, 1);
314 434
435out:
436 release_buffer();
315 return 0; 437 return 0;
316} 438}
317 439
318static int dell_get_intensity(struct backlight_device *bd) 440static int dell_get_intensity(struct backlight_device *bd)
319{ 441{
320 struct calling_interface_buffer buffer; 442 int ret = 0;
321 443
322 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 444 get_buffer();
323 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 445 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
324 446
325 if (buffer.input[0] == -1) 447 if (buffer->input[0] == -1) {
326 return -ENODEV; 448 ret = -ENODEV;
449 goto out;
450 }
327 451
328 if (power_supply_is_system_supplied() > 0) 452 if (power_supply_is_system_supplied() > 0)
329 dell_send_request(&buffer, 0, 2); 453 dell_send_request(buffer, 0, 2);
330 else 454 else
331 dell_send_request(&buffer, 0, 1); 455 dell_send_request(buffer, 0, 1);
332 456
333 return buffer.output[1]; 457out:
458 release_buffer();
459 if (ret)
460 return ret;
461 return buffer->output[1];
334} 462}
335 463
336static struct backlight_ops dell_ops = { 464static struct backlight_ops dell_ops = {
@@ -338,9 +466,32 @@ static struct backlight_ops dell_ops = {
338 .update_status = dell_send_intensity, 466 .update_status = dell_send_intensity,
339}; 467};
340 468
469bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
470 struct serio *port)
471{
472 static bool extended;
473
474 if (str & 0x20)
475 return false;
476
477 if (unlikely(data == 0xe0)) {
478 extended = true;
479 return false;
480 } else if (unlikely(extended)) {
481 switch (data) {
482 case 0x8:
483 schedule_delayed_work(&dell_rfkill_work,
484 round_jiffies_relative(HZ));
485 break;
486 }
487 extended = false;
488 }
489
490 return false;
491}
492
341static int __init dell_init(void) 493static int __init dell_init(void)
342{ 494{
343 struct calling_interface_buffer buffer;
344 int max_intensity = 0; 495 int max_intensity = 0;
345 int ret; 496 int ret;
346 497
@@ -366,6 +517,17 @@ static int __init dell_init(void)
366 if (ret) 517 if (ret)
367 goto fail_platform_device2; 518 goto fail_platform_device2;
368 519
520 /*
521 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
522 * is passed to SMI handler.
523 */
524 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
525
526 if (!bufferpage)
527 goto fail_buffer;
528 buffer = page_address(bufferpage);
529 mutex_init(&buffer_mutex);
530
369 ret = dell_setup_rfkill(); 531 ret = dell_setup_rfkill();
370 532
371 if (ret) { 533 if (ret) {
@@ -373,6 +535,13 @@ static int __init dell_init(void)
373 goto fail_rfkill; 535 goto fail_rfkill;
374 } 536 }
375 537
538 ret = i8042_install_filter(dell_laptop_i8042_filter);
539 if (ret) {
540 printk(KERN_WARNING
541 "dell-laptop: Unable to install key filter\n");
542 goto fail_filter;
543 }
544
376#ifdef CONFIG_ACPI 545#ifdef CONFIG_ACPI
377 /* In the event of an ACPI backlight being available, don't 546 /* In the event of an ACPI backlight being available, don't
378 * register the platform controller. 547 * register the platform controller.
@@ -381,13 +550,13 @@ static int __init dell_init(void)
381 return 0; 550 return 0;
382#endif 551#endif
383 552
384 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 553 get_buffer();
385 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 554 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
386 555 if (buffer->input[0] != -1) {
387 if (buffer.input[0] != -1) { 556 dell_send_request(buffer, 0, 2);
388 dell_send_request(&buffer, 0, 2); 557 max_intensity = buffer->output[3];
389 max_intensity = buffer.output[3];
390 } 558 }
559 release_buffer();
391 560
392 if (max_intensity) { 561 if (max_intensity) {
393 dell_backlight_device = backlight_device_register( 562 dell_backlight_device = backlight_device_register(
@@ -410,8 +579,13 @@ static int __init dell_init(void)
410 return 0; 579 return 0;
411 580
412fail_backlight: 581fail_backlight:
582 i8042_remove_filter(dell_laptop_i8042_filter);
583 cancel_delayed_work_sync(&dell_rfkill_work);
584fail_filter:
413 dell_cleanup_rfkill(); 585 dell_cleanup_rfkill();
414fail_rfkill: 586fail_rfkill:
587 free_page((unsigned long)bufferpage);
588fail_buffer:
415 platform_device_del(platform_device); 589 platform_device_del(platform_device);
416fail_platform_device2: 590fail_platform_device2:
417 platform_device_put(platform_device); 591 platform_device_put(platform_device);
@@ -424,8 +598,16 @@ fail_platform_driver:
424 598
425static void __exit dell_exit(void) 599static void __exit dell_exit(void)
426{ 600{
601 i8042_remove_filter(dell_laptop_i8042_filter);
602 cancel_delayed_work_sync(&dell_rfkill_work);
427 backlight_device_unregister(dell_backlight_device); 603 backlight_device_unregister(dell_backlight_device);
428 dell_cleanup_rfkill(); 604 dell_cleanup_rfkill();
605 if (platform_device) {
606 platform_device_unregister(platform_device);
607 platform_driver_unregister(&platform_driver);
608 }
609 kfree(da_tokens);
610 free_page((unsigned long)buffer);
429} 611}
430 612
431module_init(dell_init); 613module_init(dell_init);
@@ -435,3 +617,4 @@ MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
435MODULE_DESCRIPTION("Dell laptop driver"); 617MODULE_DESCRIPTION("Dell laptop driver");
436MODULE_LICENSE("GPL"); 618MODULE_LICENSE("GPL");
437MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); 619MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
620MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");
diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c
index 1b1dddbd5744..bed764e3ea2a 100644
--- a/drivers/platform/x86/dell-wmi.c
+++ b/drivers/platform/x86/dell-wmi.c
@@ -142,7 +142,7 @@ static struct key_entry *dell_wmi_keymap = dell_legacy_wmi_keymap;
142 142
143static struct input_dev *dell_wmi_input_dev; 143static struct input_dev *dell_wmi_input_dev;
144 144
145static struct key_entry *dell_wmi_get_entry_by_scancode(int code) 145static struct key_entry *dell_wmi_get_entry_by_scancode(unsigned int code)
146{ 146{
147 struct key_entry *key; 147 struct key_entry *key;
148 148
@@ -153,7 +153,7 @@ static struct key_entry *dell_wmi_get_entry_by_scancode(int code)
153 return NULL; 153 return NULL;
154} 154}
155 155
156static struct key_entry *dell_wmi_get_entry_by_keycode(int keycode) 156static struct key_entry *dell_wmi_get_entry_by_keycode(unsigned int keycode)
157{ 157{
158 struct key_entry *key; 158 struct key_entry *key;
159 159
@@ -164,8 +164,8 @@ static struct key_entry *dell_wmi_get_entry_by_keycode(int keycode)
164 return NULL; 164 return NULL;
165} 165}
166 166
167static int dell_wmi_getkeycode(struct input_dev *dev, int scancode, 167static int dell_wmi_getkeycode(struct input_dev *dev,
168 int *keycode) 168 unsigned int scancode, unsigned int *keycode)
169{ 169{
170 struct key_entry *key = dell_wmi_get_entry_by_scancode(scancode); 170 struct key_entry *key = dell_wmi_get_entry_by_scancode(scancode);
171 171
@@ -177,13 +177,11 @@ static int dell_wmi_getkeycode(struct input_dev *dev, int scancode,
177 return -EINVAL; 177 return -EINVAL;
178} 178}
179 179
180static int dell_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode) 180static int dell_wmi_setkeycode(struct input_dev *dev,
181 unsigned int scancode, unsigned int keycode)
181{ 182{
182 struct key_entry *key; 183 struct key_entry *key;
183 int old_keycode; 184 unsigned int old_keycode;
184
185 if (keycode < 0 || keycode > KEY_MAX)
186 return -EINVAL;
187 185
188 key = dell_wmi_get_entry_by_scancode(scancode); 186 key = dell_wmi_get_entry_by_scancode(scancode);
189 if (key && key->type == KE_KEY) { 187 if (key && key->type == KE_KEY) {
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index e2be6bb33d92..9a844caa3756 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -578,6 +578,8 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc)
578 struct pci_dev *dev; 578 struct pci_dev *dev;
579 struct pci_bus *bus; 579 struct pci_bus *bus;
580 bool blocked = eeepc_wlan_rfkill_blocked(eeepc); 580 bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
581 bool absent;
582 u32 l;
581 583
582 if (eeepc->wlan_rfkill) 584 if (eeepc->wlan_rfkill)
583 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked); 585 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
@@ -591,6 +593,22 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc)
591 goto out_unlock; 593 goto out_unlock;
592 } 594 }
593 595
596 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
597 pr_err("Unable to read PCI config space?\n");
598 goto out_unlock;
599 }
600 absent = (l == 0xffffffff);
601
602 if (blocked != absent) {
603 pr_warning("BIOS says wireless lan is %s, "
604 "but the pci device is %s\n",
605 blocked ? "blocked" : "unblocked",
606 absent ? "absent" : "present");
607 pr_warning("skipped wireless hotplug as probably "
608 "inappropriate for this model\n");
609 goto out_unlock;
610 }
611
594 if (!blocked) { 612 if (!blocked) {
595 dev = pci_get_slot(bus, 0); 613 dev = pci_get_slot(bus, 0);
596 if (dev) { 614 if (dev) {
@@ -1277,7 +1295,8 @@ static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
1277 * hotplug code. In fact, current hotplug code seems to unplug another 1295 * hotplug code. In fact, current hotplug code seems to unplug another
1278 * device... 1296 * device...
1279 */ 1297 */
1280 if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0) { 1298 if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0 ||
1299 strcmp(model, "1005PE") == 0) {
1281 eeepc->hotplug_disabled = true; 1300 eeepc->hotplug_disabled = true;
1282 pr_info("wlan hotplug disabled\n"); 1301 pr_info("wlan hotplug disabled\n");
1283 } 1302 }
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index ad4c414dbfbc..56086363becc 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -57,7 +57,7 @@ enum hp_wmi_radio {
57 HPWMI_WWAN = 2, 57 HPWMI_WWAN = 2,
58}; 58};
59 59
60static int __init hp_wmi_bios_setup(struct platform_device *device); 60static int __devinit hp_wmi_bios_setup(struct platform_device *device);
61static int __exit hp_wmi_bios_remove(struct platform_device *device); 61static int __exit hp_wmi_bios_remove(struct platform_device *device);
62static int hp_wmi_resume_handler(struct device *device); 62static int hp_wmi_resume_handler(struct device *device);
63 63
@@ -89,6 +89,7 @@ static struct key_entry hp_wmi_keymap[] = {
89 {KE_KEY, 0x20e6, KEY_PROG1}, 89 {KE_KEY, 0x20e6, KEY_PROG1},
90 {KE_KEY, 0x2142, KEY_MEDIA}, 90 {KE_KEY, 0x2142, KEY_MEDIA},
91 {KE_KEY, 0x213b, KEY_INFO}, 91 {KE_KEY, 0x213b, KEY_INFO},
92 {KE_KEY, 0x2169, KEY_DIRECTION},
92 {KE_KEY, 0x231b, KEY_HELP}, 93 {KE_KEY, 0x231b, KEY_HELP},
93 {KE_END, 0} 94 {KE_END, 0}
94}; 95};
@@ -277,7 +278,7 @@ static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
277static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); 278static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
278static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); 279static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
279 280
280static struct key_entry *hp_wmi_get_entry_by_scancode(int code) 281static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
281{ 282{
282 struct key_entry *key; 283 struct key_entry *key;
283 284
@@ -288,7 +289,7 @@ static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
288 return NULL; 289 return NULL;
289} 290}
290 291
291static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode) 292static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
292{ 293{
293 struct key_entry *key; 294 struct key_entry *key;
294 295
@@ -299,7 +300,8 @@ static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
299 return NULL; 300 return NULL;
300} 301}
301 302
302static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode) 303static int hp_wmi_getkeycode(struct input_dev *dev,
304 unsigned int scancode, unsigned int *keycode)
303{ 305{
304 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); 306 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
305 307
@@ -311,13 +313,11 @@ static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
311 return -EINVAL; 313 return -EINVAL;
312} 314}
313 315
314static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode) 316static int hp_wmi_setkeycode(struct input_dev *dev,
317 unsigned int scancode, unsigned int keycode)
315{ 318{
316 struct key_entry *key; 319 struct key_entry *key;
317 int old_keycode; 320 unsigned int old_keycode;
318
319 if (keycode < 0 || keycode > KEY_MAX)
320 return -EINVAL;
321 321
322 key = hp_wmi_get_entry_by_scancode(scancode); 322 key = hp_wmi_get_entry_by_scancode(scancode);
323 if (key && key->type == KE_KEY) { 323 if (key && key->type == KE_KEY) {
@@ -446,7 +446,7 @@ static void cleanup_sysfs(struct platform_device *device)
446 device_remove_file(&device->dev, &dev_attr_tablet); 446 device_remove_file(&device->dev, &dev_attr_tablet);
447} 447}
448 448
449static int __init hp_wmi_bios_setup(struct platform_device *device) 449static int __devinit hp_wmi_bios_setup(struct platform_device *device)
450{ 450{
451 int err; 451 int err;
452 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); 452 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
index 759763d18e4c..c2b05da4289a 100644
--- a/drivers/platform/x86/msi-laptop.c
+++ b/drivers/platform/x86/msi-laptop.c
@@ -58,6 +58,7 @@
58#include <linux/dmi.h> 58#include <linux/dmi.h>
59#include <linux/backlight.h> 59#include <linux/backlight.h>
60#include <linux/platform_device.h> 60#include <linux/platform_device.h>
61#include <linux/rfkill.h>
61 62
62#define MSI_DRIVER_VERSION "0.5" 63#define MSI_DRIVER_VERSION "0.5"
63 64
@@ -66,6 +67,20 @@
66#define MSI_EC_COMMAND_WIRELESS 0x10 67#define MSI_EC_COMMAND_WIRELESS 0x10
67#define MSI_EC_COMMAND_LCD_LEVEL 0x11 68#define MSI_EC_COMMAND_LCD_LEVEL 0x11
68 69
70#define MSI_STANDARD_EC_COMMAND_ADDRESS 0x2e
71#define MSI_STANDARD_EC_BLUETOOTH_MASK (1 << 0)
72#define MSI_STANDARD_EC_WEBCAM_MASK (1 << 1)
73#define MSI_STANDARD_EC_WLAN_MASK (1 << 3)
74#define MSI_STANDARD_EC_3G_MASK (1 << 4)
75
76/* For set SCM load flag to disable BIOS fn key */
77#define MSI_STANDARD_EC_SCM_LOAD_ADDRESS 0x2d
78#define MSI_STANDARD_EC_SCM_LOAD_MASK (1 << 0)
79
80static int msi_laptop_resume(struct platform_device *device);
81
82#define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
83
69static int force; 84static int force;
70module_param(force, bool, 0); 85module_param(force, bool, 0);
71MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); 86MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
@@ -74,6 +89,23 @@ static int auto_brightness;
74module_param(auto_brightness, int, 0); 89module_param(auto_brightness, int, 0);
75MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)"); 90MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
76 91
92static bool old_ec_model;
93static int wlan_s, bluetooth_s, threeg_s;
94static int threeg_exists;
95
96/* Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
97 * those netbook will load the SCM (windows app) to disable the original
98 * Wlan/Bluetooth control by BIOS when user press fn key, then control
99 * Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
100 * cann't on/off 3G module on those 3G netbook.
101 * On Linux, msi-laptop driver will do the same thing to disable the
102 * original BIOS control, then might need use HAL or other userland
103 * application to do the software control that simulate with SCM.
104 * e.g. MSI N034 netbook
105 */
106static bool load_scm_model;
107static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
108
77/* Hardware access */ 109/* Hardware access */
78 110
79static int set_lcd_level(int level) 111static int set_lcd_level(int level)
@@ -130,6 +162,35 @@ static int set_auto_brightness(int enable)
130 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1); 162 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
131} 163}
132 164
165static ssize_t set_device_state(const char *buf, size_t count, u8 mask)
166{
167 int status;
168 u8 wdata = 0, rdata;
169 int result;
170
171 if (sscanf(buf, "%i", &status) != 1 || (status < 0 || status > 1))
172 return -EINVAL;
173
174 /* read current device state */
175 result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
176 if (result < 0)
177 return -EINVAL;
178
179 if (!!(rdata & mask) != status) {
180 /* reverse device bit */
181 if (rdata & mask)
182 wdata = rdata & ~mask;
183 else
184 wdata = rdata | mask;
185
186 result = ec_write(MSI_STANDARD_EC_COMMAND_ADDRESS, wdata);
187 if (result < 0)
188 return -EINVAL;
189 }
190
191 return count;
192}
193
133static int get_wireless_state(int *wlan, int *bluetooth) 194static int get_wireless_state(int *wlan, int *bluetooth)
134{ 195{
135 u8 wdata = 0, rdata; 196 u8 wdata = 0, rdata;
@@ -148,6 +209,38 @@ static int get_wireless_state(int *wlan, int *bluetooth)
148 return 0; 209 return 0;
149} 210}
150 211
212static int get_wireless_state_ec_standard(void)
213{
214 u8 rdata;
215 int result;
216
217 result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
218 if (result < 0)
219 return -1;
220
221 wlan_s = !!(rdata & MSI_STANDARD_EC_WLAN_MASK);
222
223 bluetooth_s = !!(rdata & MSI_STANDARD_EC_BLUETOOTH_MASK);
224
225 threeg_s = !!(rdata & MSI_STANDARD_EC_3G_MASK);
226
227 return 0;
228}
229
230static int get_threeg_exists(void)
231{
232 u8 rdata;
233 int result;
234
235 result = ec_read(MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS, &rdata);
236 if (result < 0)
237 return -1;
238
239 threeg_exists = !!(rdata & MSI_STANDARD_EC_3G_MASK);
240
241 return 0;
242}
243
151/* Backlight device stuff */ 244/* Backlight device stuff */
152 245
153static int bl_get_brightness(struct backlight_device *b) 246static int bl_get_brightness(struct backlight_device *b)
@@ -176,26 +269,71 @@ static ssize_t show_wlan(struct device *dev,
176 269
177 int ret, enabled; 270 int ret, enabled;
178 271
179 ret = get_wireless_state(&enabled, NULL); 272 if (old_ec_model) {
273 ret = get_wireless_state(&enabled, NULL);
274 } else {
275 ret = get_wireless_state_ec_standard();
276 enabled = wlan_s;
277 }
180 if (ret < 0) 278 if (ret < 0)
181 return ret; 279 return ret;
182 280
183 return sprintf(buf, "%i\n", enabled); 281 return sprintf(buf, "%i\n", enabled);
184} 282}
185 283
284static ssize_t store_wlan(struct device *dev,
285 struct device_attribute *attr, const char *buf, size_t count)
286{
287 return set_device_state(buf, count, MSI_STANDARD_EC_WLAN_MASK);
288}
289
186static ssize_t show_bluetooth(struct device *dev, 290static ssize_t show_bluetooth(struct device *dev,
187 struct device_attribute *attr, char *buf) 291 struct device_attribute *attr, char *buf)
188{ 292{
189 293
190 int ret, enabled; 294 int ret, enabled;
191 295
192 ret = get_wireless_state(NULL, &enabled); 296 if (old_ec_model) {
297 ret = get_wireless_state(NULL, &enabled);
298 } else {
299 ret = get_wireless_state_ec_standard();
300 enabled = bluetooth_s;
301 }
193 if (ret < 0) 302 if (ret < 0)
194 return ret; 303 return ret;
195 304
196 return sprintf(buf, "%i\n", enabled); 305 return sprintf(buf, "%i\n", enabled);
197} 306}
198 307
308static ssize_t store_bluetooth(struct device *dev,
309 struct device_attribute *attr, const char *buf, size_t count)
310{
311 return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
312}
313
314static ssize_t show_threeg(struct device *dev,
315 struct device_attribute *attr, char *buf)
316{
317
318 int ret;
319
320 /* old msi ec not support 3G */
321 if (old_ec_model)
322 return -1;
323
324 ret = get_wireless_state_ec_standard();
325 if (ret < 0)
326 return ret;
327
328 return sprintf(buf, "%i\n", threeg_s);
329}
330
331static ssize_t store_threeg(struct device *dev,
332 struct device_attribute *attr, const char *buf, size_t count)
333{
334 return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
335}
336
199static ssize_t show_lcd_level(struct device *dev, 337static ssize_t show_lcd_level(struct device *dev,
200 struct device_attribute *attr, char *buf) 338 struct device_attribute *attr, char *buf)
201{ 339{
@@ -258,6 +396,7 @@ static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
258static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness); 396static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
259static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL); 397static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
260static DEVICE_ATTR(wlan, 0444, show_wlan, NULL); 398static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
399static DEVICE_ATTR(threeg, 0444, show_threeg, NULL);
261 400
262static struct attribute *msipf_attributes[] = { 401static struct attribute *msipf_attributes[] = {
263 &dev_attr_lcd_level.attr, 402 &dev_attr_lcd_level.attr,
@@ -275,7 +414,8 @@ static struct platform_driver msipf_driver = {
275 .driver = { 414 .driver = {
276 .name = "msi-laptop-pf", 415 .name = "msi-laptop-pf",
277 .owner = THIS_MODULE, 416 .owner = THIS_MODULE,
278 } 417 },
418 .resume = msi_laptop_resume,
279}; 419};
280 420
281static struct platform_device *msipf_device; 421static struct platform_device *msipf_device;
@@ -332,6 +472,192 @@ static struct dmi_system_id __initdata msi_dmi_table[] = {
332 { } 472 { }
333}; 473};
334 474
475static struct dmi_system_id __initdata msi_load_scm_models_dmi_table[] = {
476 {
477 .ident = "MSI N034",
478 .matches = {
479 DMI_MATCH(DMI_SYS_VENDOR,
480 "MICRO-STAR INTERNATIONAL CO., LTD"),
481 DMI_MATCH(DMI_PRODUCT_NAME, "MS-N034"),
482 DMI_MATCH(DMI_CHASSIS_VENDOR,
483 "MICRO-STAR INTERNATIONAL CO., LTD")
484 },
485 .callback = dmi_check_cb
486 },
487 { }
488};
489
490static int rfkill_bluetooth_set(void *data, bool blocked)
491{
492 /* Do something with blocked...*/
493 /*
494 * blocked == false is on
495 * blocked == true is off
496 */
497 if (blocked)
498 set_device_state("0", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
499 else
500 set_device_state("1", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
501
502 return 0;
503}
504
505static int rfkill_wlan_set(void *data, bool blocked)
506{
507 if (blocked)
508 set_device_state("0", 0, MSI_STANDARD_EC_WLAN_MASK);
509 else
510 set_device_state("1", 0, MSI_STANDARD_EC_WLAN_MASK);
511
512 return 0;
513}
514
515static int rfkill_threeg_set(void *data, bool blocked)
516{
517 if (blocked)
518 set_device_state("0", 0, MSI_STANDARD_EC_3G_MASK);
519 else
520 set_device_state("1", 0, MSI_STANDARD_EC_3G_MASK);
521
522 return 0;
523}
524
525static struct rfkill_ops rfkill_bluetooth_ops = {
526 .set_block = rfkill_bluetooth_set
527};
528
529static struct rfkill_ops rfkill_wlan_ops = {
530 .set_block = rfkill_wlan_set
531};
532
533static struct rfkill_ops rfkill_threeg_ops = {
534 .set_block = rfkill_threeg_set
535};
536
537static void rfkill_cleanup(void)
538{
539 if (rfk_bluetooth) {
540 rfkill_unregister(rfk_bluetooth);
541 rfkill_destroy(rfk_bluetooth);
542 }
543
544 if (rfk_threeg) {
545 rfkill_unregister(rfk_threeg);
546 rfkill_destroy(rfk_threeg);
547 }
548
549 if (rfk_wlan) {
550 rfkill_unregister(rfk_wlan);
551 rfkill_destroy(rfk_wlan);
552 }
553}
554
555static int rfkill_init(struct platform_device *sdev)
556{
557 /* add rfkill */
558 int retval;
559
560 rfk_bluetooth = rfkill_alloc("msi-bluetooth", &sdev->dev,
561 RFKILL_TYPE_BLUETOOTH,
562 &rfkill_bluetooth_ops, NULL);
563 if (!rfk_bluetooth) {
564 retval = -ENOMEM;
565 goto err_bluetooth;
566 }
567 retval = rfkill_register(rfk_bluetooth);
568 if (retval)
569 goto err_bluetooth;
570
571 rfk_wlan = rfkill_alloc("msi-wlan", &sdev->dev, RFKILL_TYPE_WLAN,
572 &rfkill_wlan_ops, NULL);
573 if (!rfk_wlan) {
574 retval = -ENOMEM;
575 goto err_wlan;
576 }
577 retval = rfkill_register(rfk_wlan);
578 if (retval)
579 goto err_wlan;
580
581 if (threeg_exists) {
582 rfk_threeg = rfkill_alloc("msi-threeg", &sdev->dev,
583 RFKILL_TYPE_WWAN, &rfkill_threeg_ops, NULL);
584 if (!rfk_threeg) {
585 retval = -ENOMEM;
586 goto err_threeg;
587 }
588 retval = rfkill_register(rfk_threeg);
589 if (retval)
590 goto err_threeg;
591 }
592
593 return 0;
594
595err_threeg:
596 rfkill_destroy(rfk_threeg);
597 if (rfk_wlan)
598 rfkill_unregister(rfk_wlan);
599err_wlan:
600 rfkill_destroy(rfk_wlan);
601 if (rfk_bluetooth)
602 rfkill_unregister(rfk_bluetooth);
603err_bluetooth:
604 rfkill_destroy(rfk_bluetooth);
605
606 return retval;
607}
608
609static int msi_laptop_resume(struct platform_device *device)
610{
611 u8 data;
612 int result;
613
614 if (!load_scm_model)
615 return 0;
616
617 /* set load SCM to disable hardware control by fn key */
618 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
619 if (result < 0)
620 return result;
621
622 result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
623 data | MSI_STANDARD_EC_SCM_LOAD_MASK);
624 if (result < 0)
625 return result;
626
627 return 0;
628}
629
630static int load_scm_model_init(struct platform_device *sdev)
631{
632 u8 data;
633 int result;
634
635 /* allow userland write sysfs file */
636 dev_attr_bluetooth.store = store_bluetooth;
637 dev_attr_wlan.store = store_wlan;
638 dev_attr_threeg.store = store_threeg;
639 dev_attr_bluetooth.attr.mode |= S_IWUSR;
640 dev_attr_wlan.attr.mode |= S_IWUSR;
641 dev_attr_threeg.attr.mode |= S_IWUSR;
642
643 /* disable hardware control by fn key */
644 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
645 if (result < 0)
646 return result;
647
648 result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
649 data | MSI_STANDARD_EC_SCM_LOAD_MASK);
650 if (result < 0)
651 return result;
652
653 /* initial rfkill */
654 result = rfkill_init(sdev);
655 if (result < 0)
656 return result;
657
658 return 0;
659}
660
335static int __init msi_init(void) 661static int __init msi_init(void)
336{ 662{
337 int ret; 663 int ret;
@@ -339,8 +665,14 @@ static int __init msi_init(void)
339 if (acpi_disabled) 665 if (acpi_disabled)
340 return -ENODEV; 666 return -ENODEV;
341 667
342 if (!force && !dmi_check_system(msi_dmi_table)) 668 if (force || dmi_check_system(msi_dmi_table))
343 return -ENODEV; 669 old_ec_model = 1;
670
671 if (!old_ec_model)
672 get_threeg_exists();
673
674 if (!old_ec_model && dmi_check_system(msi_load_scm_models_dmi_table))
675 load_scm_model = 1;
344 676
345 if (auto_brightness < 0 || auto_brightness > 2) 677 if (auto_brightness < 0 || auto_brightness > 2)
346 return -EINVAL; 678 return -EINVAL;
@@ -374,10 +706,23 @@ static int __init msi_init(void)
374 if (ret) 706 if (ret)
375 goto fail_platform_device1; 707 goto fail_platform_device1;
376 708
709 if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
710 ret = -EINVAL;
711 goto fail_platform_device1;
712 }
713
377 ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group); 714 ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
378 if (ret) 715 if (ret)
379 goto fail_platform_device2; 716 goto fail_platform_device2;
380 717
718 if (!old_ec_model) {
719 if (threeg_exists)
720 ret = device_create_file(&msipf_device->dev,
721 &dev_attr_threeg);
722 if (ret)
723 goto fail_platform_device2;
724 }
725
381 /* Disable automatic brightness control by default because 726 /* Disable automatic brightness control by default because
382 * this module was probably loaded to do brightness control in 727 * this module was probably loaded to do brightness control in
383 * software. */ 728 * software. */
@@ -412,10 +757,14 @@ static void __exit msi_cleanup(void)
412{ 757{
413 758
414 sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group); 759 sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
760 if (!old_ec_model && threeg_exists)
761 device_remove_file(&msipf_device->dev, &dev_attr_threeg);
415 platform_device_unregister(msipf_device); 762 platform_device_unregister(msipf_device);
416 platform_driver_unregister(&msipf_driver); 763 platform_driver_unregister(&msipf_driver);
417 backlight_device_unregister(msibl_device); 764 backlight_device_unregister(msibl_device);
418 765
766 rfkill_cleanup();
767
419 /* Enable automatic brightness control again */ 768 /* Enable automatic brightness control again */
420 if (auto_brightness != 2) 769 if (auto_brightness != 2)
421 set_auto_brightness(1); 770 set_auto_brightness(1);
@@ -435,3 +784,4 @@ MODULE_ALIAS("dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARIN
435MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*"); 784MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
436MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*"); 785MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
437MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*"); 786MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
787MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N034:*");
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index fe7cf0188acc..c9fc479fc290 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -200,7 +200,7 @@ static struct acpi_driver acpi_pcc_driver = {
200}; 200};
201 201
202#define KEYMAP_SIZE 11 202#define KEYMAP_SIZE 11
203static const int initial_keymap[KEYMAP_SIZE] = { 203static const unsigned int initial_keymap[KEYMAP_SIZE] = {
204 /* 0 */ KEY_RESERVED, 204 /* 0 */ KEY_RESERVED,
205 /* 1 */ KEY_BRIGHTNESSDOWN, 205 /* 1 */ KEY_BRIGHTNESSDOWN,
206 /* 2 */ KEY_BRIGHTNESSUP, 206 /* 2 */ KEY_BRIGHTNESSUP,
@@ -222,7 +222,7 @@ struct pcc_acpi {
222 struct acpi_device *device; 222 struct acpi_device *device;
223 struct input_dev *input_dev; 223 struct input_dev *input_dev;
224 struct backlight_device *backlight; 224 struct backlight_device *backlight;
225 int keymap[KEYMAP_SIZE]; 225 unsigned int keymap[KEYMAP_SIZE];
226}; 226};
227 227
228struct pcc_keyinput { 228struct pcc_keyinput {
@@ -445,7 +445,8 @@ static struct attribute_group pcc_attr_group = {
445 445
446/* hotkey input device driver */ 446/* hotkey input device driver */
447 447
448static int pcc_getkeycode(struct input_dev *dev, int scancode, int *keycode) 448static int pcc_getkeycode(struct input_dev *dev,
449 unsigned int scancode, unsigned int *keycode)
449{ 450{
450 struct pcc_acpi *pcc = input_get_drvdata(dev); 451 struct pcc_acpi *pcc = input_get_drvdata(dev);
451 452
@@ -457,7 +458,7 @@ static int pcc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
457 return 0; 458 return 0;
458} 459}
459 460
460static int keymap_get_by_keycode(struct pcc_acpi *pcc, int keycode) 461static int keymap_get_by_keycode(struct pcc_acpi *pcc, unsigned int keycode)
461{ 462{
462 int i; 463 int i;
463 464
@@ -469,7 +470,8 @@ static int keymap_get_by_keycode(struct pcc_acpi *pcc, int keycode)
469 return 0; 470 return 0;
470} 471}
471 472
472static int pcc_setkeycode(struct input_dev *dev, int scancode, int keycode) 473static int pcc_setkeycode(struct input_dev *dev,
474 unsigned int scancode, unsigned int keycode)
473{ 475{
474 struct pcc_acpi *pcc = input_get_drvdata(dev); 476 struct pcc_acpi *pcc = input_get_drvdata(dev);
475 int oldkeycode; 477 int oldkeycode;
@@ -477,9 +479,6 @@ static int pcc_setkeycode(struct input_dev *dev, int scancode, int keycode)
477 if (scancode >= ARRAY_SIZE(pcc->keymap)) 479 if (scancode >= ARRAY_SIZE(pcc->keymap))
478 return -EINVAL; 480 return -EINVAL;
479 481
480 if (keycode < 0 || keycode > KEY_MAX)
481 return -EINVAL;
482
483 oldkeycode = pcc->keymap[scancode]; 482 oldkeycode = pcc->keymap[scancode];
484 pcc->keymap[scancode] = keycode; 483 pcc->keymap[scancode] = keycode;
485 484
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 3f71a605a492..5a3d8514c66d 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -145,7 +145,7 @@ struct sony_laptop_input_s {
145 struct input_dev *key_dev; 145 struct input_dev *key_dev;
146 struct kfifo fifo; 146 struct kfifo fifo;
147 spinlock_t fifo_lock; 147 spinlock_t fifo_lock;
148 struct workqueue_struct *wq; 148 struct timer_list release_key_timer;
149}; 149};
150 150
151static struct sony_laptop_input_s sony_laptop_input = { 151static struct sony_laptop_input_s sony_laptop_input = {
@@ -299,20 +299,26 @@ static int sony_laptop_input_keycode_map[] = {
299}; 299};
300 300
301/* release buttons after a short delay if pressed */ 301/* release buttons after a short delay if pressed */
302static void do_sony_laptop_release_key(struct work_struct *work) 302static void do_sony_laptop_release_key(unsigned long unused)
303{ 303{
304 struct sony_laptop_keypress kp; 304 struct sony_laptop_keypress kp;
305 unsigned long flags;
306
307 spin_lock_irqsave(&sony_laptop_input.fifo_lock, flags);
305 308
306 while (kfifo_out_locked(&sony_laptop_input.fifo, (unsigned char *)&kp, 309 if (kfifo_out(&sony_laptop_input.fifo,
307 sizeof(kp), &sony_laptop_input.fifo_lock) 310 (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
308 == sizeof(kp)) {
309 msleep(10);
310 input_report_key(kp.dev, kp.key, 0); 311 input_report_key(kp.dev, kp.key, 0);
311 input_sync(kp.dev); 312 input_sync(kp.dev);
312 } 313 }
314
315 /* If there is something in the fifo schedule next release. */
316 if (kfifo_len(&sony_laptop_input.fifo) != 0)
317 mod_timer(&sony_laptop_input.release_key_timer,
318 jiffies + msecs_to_jiffies(10));
319
320 spin_unlock_irqrestore(&sony_laptop_input.fifo_lock, flags);
313} 321}
314static DECLARE_WORK(sony_laptop_release_key_work,
315 do_sony_laptop_release_key);
316 322
317/* forward event to the input subsystem */ 323/* forward event to the input subsystem */
318static void sony_laptop_report_input_event(u8 event) 324static void sony_laptop_report_input_event(u8 event)
@@ -366,13 +372,13 @@ static void sony_laptop_report_input_event(u8 event)
366 /* we emit the scancode so we can always remap the key */ 372 /* we emit the scancode so we can always remap the key */
367 input_event(kp.dev, EV_MSC, MSC_SCAN, event); 373 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
368 input_sync(kp.dev); 374 input_sync(kp.dev);
369 kfifo_in_locked(&sony_laptop_input.fifo,
370 (unsigned char *)&kp, sizeof(kp),
371 &sony_laptop_input.fifo_lock);
372 375
373 if (!work_pending(&sony_laptop_release_key_work)) 376 /* schedule key release */
374 queue_work(sony_laptop_input.wq, 377 kfifo_in_locked(&sony_laptop_input.fifo,
375 &sony_laptop_release_key_work); 378 (unsigned char *)&kp, sizeof(kp),
379 &sony_laptop_input.fifo_lock);
380 mod_timer(&sony_laptop_input.release_key_timer,
381 jiffies + msecs_to_jiffies(10));
376 } else 382 } else
377 dprintk("unknown input event %.2x\n", event); 383 dprintk("unknown input event %.2x\n", event);
378} 384}
@@ -390,27 +396,21 @@ static int sony_laptop_setup_input(struct acpi_device *acpi_device)
390 396
391 /* kfifo */ 397 /* kfifo */
392 spin_lock_init(&sony_laptop_input.fifo_lock); 398 spin_lock_init(&sony_laptop_input.fifo_lock);
393 error = 399 error = kfifo_alloc(&sony_laptop_input.fifo,
394 kfifo_alloc(&sony_laptop_input.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); 400 SONY_LAPTOP_BUF_SIZE, GFP_KERNEL);
395 if (error) { 401 if (error) {
396 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); 402 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
397 goto err_dec_users; 403 goto err_dec_users;
398 } 404 }
399 405
400 /* init workqueue */ 406 setup_timer(&sony_laptop_input.release_key_timer,
401 sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop"); 407 do_sony_laptop_release_key, 0);
402 if (!sony_laptop_input.wq) {
403 printk(KERN_ERR DRV_PFX
404 "Unable to create workqueue.\n");
405 error = -ENXIO;
406 goto err_free_kfifo;
407 }
408 408
409 /* input keys */ 409 /* input keys */
410 key_dev = input_allocate_device(); 410 key_dev = input_allocate_device();
411 if (!key_dev) { 411 if (!key_dev) {
412 error = -ENOMEM; 412 error = -ENOMEM;
413 goto err_destroy_wq; 413 goto err_free_kfifo;
414 } 414 }
415 415
416 key_dev->name = "Sony Vaio Keys"; 416 key_dev->name = "Sony Vaio Keys";
@@ -419,18 +419,15 @@ static int sony_laptop_setup_input(struct acpi_device *acpi_device)
419 key_dev->dev.parent = &acpi_device->dev; 419 key_dev->dev.parent = &acpi_device->dev;
420 420
421 /* Initialize the Input Drivers: special keys */ 421 /* Initialize the Input Drivers: special keys */
422 set_bit(EV_KEY, key_dev->evbit); 422 input_set_capability(key_dev, EV_MSC, MSC_SCAN);
423 set_bit(EV_MSC, key_dev->evbit); 423
424 set_bit(MSC_SCAN, key_dev->mscbit); 424 __set_bit(EV_KEY, key_dev->evbit);
425 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]); 425 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
426 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map); 426 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
427 key_dev->keycode = &sony_laptop_input_keycode_map; 427 key_dev->keycode = &sony_laptop_input_keycode_map;
428 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) { 428 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++)
429 if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) { 429 __set_bit(sony_laptop_input_keycode_map[i], key_dev->keybit);
430 set_bit(sony_laptop_input_keycode_map[i], 430 __clear_bit(KEY_RESERVED, key_dev->keybit);
431 key_dev->keybit);
432 }
433 }
434 431
435 error = input_register_device(key_dev); 432 error = input_register_device(key_dev);
436 if (error) 433 if (error)
@@ -450,9 +447,8 @@ static int sony_laptop_setup_input(struct acpi_device *acpi_device)
450 jog_dev->id.vendor = PCI_VENDOR_ID_SONY; 447 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
451 key_dev->dev.parent = &acpi_device->dev; 448 key_dev->dev.parent = &acpi_device->dev;
452 449
453 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 450 input_set_capability(jog_dev, EV_KEY, BTN_MIDDLE);
454 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE); 451 input_set_capability(jog_dev, EV_REL, REL_WHEEL);
455 jog_dev->relbit[0] = BIT_MASK(REL_WHEEL);
456 452
457 error = input_register_device(jog_dev); 453 error = input_register_device(jog_dev);
458 if (error) 454 if (error)
@@ -473,9 +469,6 @@ err_unregister_keydev:
473err_free_keydev: 469err_free_keydev:
474 input_free_device(key_dev); 470 input_free_device(key_dev);
475 471
476err_destroy_wq:
477 destroy_workqueue(sony_laptop_input.wq);
478
479err_free_kfifo: 472err_free_kfifo:
480 kfifo_free(&sony_laptop_input.fifo); 473 kfifo_free(&sony_laptop_input.fifo);
481 474
@@ -486,12 +479,23 @@ err_dec_users:
486 479
487static void sony_laptop_remove_input(void) 480static void sony_laptop_remove_input(void)
488{ 481{
489 /* cleanup only after the last user has gone */ 482 struct sony_laptop_keypress kp = { NULL };
483
484 /* Cleanup only after the last user has gone */
490 if (!atomic_dec_and_test(&sony_laptop_input.users)) 485 if (!atomic_dec_and_test(&sony_laptop_input.users))
491 return; 486 return;
492 487
493 /* flush workqueue first */ 488 del_timer_sync(&sony_laptop_input.release_key_timer);
494 flush_workqueue(sony_laptop_input.wq); 489
490 /*
491 * Generate key-up events for remaining keys. Note that we don't
492 * need locking since nobody is adding new events to the kfifo.
493 */
494 while (kfifo_out(&sony_laptop_input.fifo,
495 (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
496 input_report_key(kp.dev, kp.key, 0);
497 input_sync(kp.dev);
498 }
495 499
496 /* destroy input devs */ 500 /* destroy input devs */
497 input_unregister_device(sony_laptop_input.key_dev); 501 input_unregister_device(sony_laptop_input.key_dev);
@@ -502,7 +506,6 @@ static void sony_laptop_remove_input(void)
502 sony_laptop_input.jog_dev = NULL; 506 sony_laptop_input.jog_dev = NULL;
503 } 507 }
504 508
505 destroy_workqueue(sony_laptop_input.wq);
506 kfifo_free(&sony_laptop_input.fifo); 509 kfifo_free(&sony_laptop_input.fifo);
507} 510}
508 511
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index eb603f1d55ca..c64e3528889b 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -286,6 +286,7 @@ struct ibm_init_struct {
286 char param[32]; 286 char param[32];
287 287
288 int (*init) (struct ibm_init_struct *); 288 int (*init) (struct ibm_init_struct *);
289 mode_t base_procfs_mode;
289 struct ibm_struct *data; 290 struct ibm_struct *data;
290}; 291};
291 292
@@ -1667,7 +1668,7 @@ static void tpacpi_remove_driver_attributes(struct device_driver *drv)
1667 * Table of recommended minimum BIOS versions 1668 * Table of recommended minimum BIOS versions
1668 * 1669 *
1669 * Reasons for listing: 1670 * Reasons for listing:
1670 * 1. Stable BIOS, listed because the unknown ammount of 1671 * 1. Stable BIOS, listed because the unknown amount of
1671 * bugs and bad ACPI behaviour on older versions 1672 * bugs and bad ACPI behaviour on older versions
1672 * 1673 *
1673 * 2. BIOS or EC fw with known bugs that trigger on Linux 1674 * 2. BIOS or EC fw with known bugs that trigger on Linux
@@ -2082,6 +2083,7 @@ static struct attribute_set *hotkey_dev_attributes;
2082 2083
2083static void tpacpi_driver_event(const unsigned int hkey_event); 2084static void tpacpi_driver_event(const unsigned int hkey_event);
2084static void hotkey_driver_event(const unsigned int scancode); 2085static void hotkey_driver_event(const unsigned int scancode);
2086static void hotkey_poll_setup(const bool may_warn);
2085 2087
2086/* HKEY.MHKG() return bits */ 2088/* HKEY.MHKG() return bits */
2087#define TP_HOTKEY_TABLET_MASK (1 << 3) 2089#define TP_HOTKEY_TABLET_MASK (1 << 3)
@@ -2264,6 +2266,8 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
2264 2266
2265 rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & 2267 rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) &
2266 ~hotkey_source_mask); 2268 ~hotkey_source_mask);
2269 hotkey_poll_setup(true);
2270
2267 mutex_unlock(&hotkey_mutex); 2271 mutex_unlock(&hotkey_mutex);
2268 2272
2269 return rc; 2273 return rc;
@@ -2548,7 +2552,7 @@ static void hotkey_poll_stop_sync(void)
2548} 2552}
2549 2553
2550/* call with hotkey_mutex held */ 2554/* call with hotkey_mutex held */
2551static void hotkey_poll_setup(bool may_warn) 2555static void hotkey_poll_setup(const bool may_warn)
2552{ 2556{
2553 const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; 2557 const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask;
2554 const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; 2558 const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask;
@@ -2579,7 +2583,7 @@ static void hotkey_poll_setup(bool may_warn)
2579 } 2583 }
2580} 2584}
2581 2585
2582static void hotkey_poll_setup_safe(bool may_warn) 2586static void hotkey_poll_setup_safe(const bool may_warn)
2583{ 2587{
2584 mutex_lock(&hotkey_mutex); 2588 mutex_lock(&hotkey_mutex);
2585 hotkey_poll_setup(may_warn); 2589 hotkey_poll_setup(may_warn);
@@ -2597,7 +2601,11 @@ static void hotkey_poll_set_freq(unsigned int freq)
2597 2601
2598#else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ 2602#else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2599 2603
2600static void hotkey_poll_setup_safe(bool __unused) 2604static void hotkey_poll_setup(const bool __unused)
2605{
2606}
2607
2608static void hotkey_poll_setup_safe(const bool __unused)
2601{ 2609{
2602} 2610}
2603 2611
@@ -2607,16 +2615,11 @@ static int hotkey_inputdev_open(struct input_dev *dev)
2607{ 2615{
2608 switch (tpacpi_lifecycle) { 2616 switch (tpacpi_lifecycle) {
2609 case TPACPI_LIFE_INIT: 2617 case TPACPI_LIFE_INIT:
2610 /*
2611 * hotkey_init will call hotkey_poll_setup_safe
2612 * at the appropriate moment
2613 */
2614 return 0;
2615 case TPACPI_LIFE_EXITING:
2616 return -EBUSY;
2617 case TPACPI_LIFE_RUNNING: 2618 case TPACPI_LIFE_RUNNING:
2618 hotkey_poll_setup_safe(false); 2619 hotkey_poll_setup_safe(false);
2619 return 0; 2620 return 0;
2621 case TPACPI_LIFE_EXITING:
2622 return -EBUSY;
2620 } 2623 }
2621 2624
2622 /* Should only happen if tpacpi_lifecycle is corrupt */ 2625 /* Should only happen if tpacpi_lifecycle is corrupt */
@@ -2627,7 +2630,7 @@ static int hotkey_inputdev_open(struct input_dev *dev)
2627static void hotkey_inputdev_close(struct input_dev *dev) 2630static void hotkey_inputdev_close(struct input_dev *dev)
2628{ 2631{
2629 /* disable hotkey polling when possible */ 2632 /* disable hotkey polling when possible */
2630 if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING && 2633 if (tpacpi_lifecycle != TPACPI_LIFE_EXITING &&
2631 !(hotkey_source_mask & hotkey_driver_mask)) 2634 !(hotkey_source_mask & hotkey_driver_mask))
2632 hotkey_poll_setup_safe(false); 2635 hotkey_poll_setup_safe(false);
2633} 2636}
@@ -3655,13 +3658,19 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
3655 break; 3658 break;
3656 case 3: 3659 case 3:
3657 /* 0x3000-0x3FFF: bay-related wakeups */ 3660 /* 0x3000-0x3FFF: bay-related wakeups */
3658 if (hkey == TP_HKEY_EV_BAYEJ_ACK) { 3661 switch (hkey) {
3662 case TP_HKEY_EV_BAYEJ_ACK:
3659 hotkey_autosleep_ack = 1; 3663 hotkey_autosleep_ack = 1;
3660 printk(TPACPI_INFO 3664 printk(TPACPI_INFO
3661 "bay ejected\n"); 3665 "bay ejected\n");
3662 hotkey_wakeup_hotunplug_complete_notify_change(); 3666 hotkey_wakeup_hotunplug_complete_notify_change();
3663 known_ev = true; 3667 known_ev = true;
3664 } else { 3668 break;
3669 case TP_HKEY_EV_OPTDRV_EJ:
3670 /* FIXME: kick libata if SATA link offline */
3671 known_ev = true;
3672 break;
3673 default:
3665 known_ev = false; 3674 known_ev = false;
3666 } 3675 }
3667 break; 3676 break;
@@ -3870,7 +3879,7 @@ enum {
3870 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ 3879 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
3871 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ 3880 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
3872 TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: 3881 TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume:
3873 off / last state */ 3882 0 = disable, 1 = enable */
3874}; 3883};
3875 3884
3876enum { 3885enum {
@@ -3916,10 +3925,11 @@ static int bluetooth_set_status(enum tpacpi_rfkill_state state)
3916 } 3925 }
3917#endif 3926#endif
3918 3927
3919 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3920 status = TP_ACPI_BLUETOOTH_RESUMECTRL;
3921 if (state == TPACPI_RFK_RADIO_ON) 3928 if (state == TPACPI_RFK_RADIO_ON)
3922 status |= TP_ACPI_BLUETOOTH_RADIOSSW; 3929 status = TP_ACPI_BLUETOOTH_RADIOSSW
3930 | TP_ACPI_BLUETOOTH_RESUMECTRL;
3931 else
3932 status = 0;
3923 3933
3924 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) 3934 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
3925 return -EIO; 3935 return -EIO;
@@ -4070,7 +4080,7 @@ enum {
4070 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ 4080 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
4071 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ 4081 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
4072 TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: 4082 TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume:
4073 off / last state */ 4083 0 = disable, 1 = enable */
4074}; 4084};
4075 4085
4076#define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" 4086#define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
@@ -4107,10 +4117,11 @@ static int wan_set_status(enum tpacpi_rfkill_state state)
4107 } 4117 }
4108#endif 4118#endif
4109 4119
4110 /* We make sure to set TP_ACPI_WANCARD_RESUMECTRL */
4111 status = TP_ACPI_WANCARD_RESUMECTRL;
4112 if (state == TPACPI_RFK_RADIO_ON) 4120 if (state == TPACPI_RFK_RADIO_ON)
4113 status |= TP_ACPI_WANCARD_RADIOSSW; 4121 status = TP_ACPI_WANCARD_RADIOSSW
4122 | TP_ACPI_WANCARD_RESUMECTRL;
4123 else
4124 status = 0;
4114 4125
4115 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) 4126 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
4116 return -EIO; 4127 return -EIO;
@@ -4619,6 +4630,10 @@ static int video_read(struct seq_file *m)
4619 return 0; 4630 return 0;
4620 } 4631 }
4621 4632
4633 /* Even reads can crash X.org, so... */
4634 if (!capable(CAP_SYS_ADMIN))
4635 return -EPERM;
4636
4622 status = video_outputsw_get(); 4637 status = video_outputsw_get();
4623 if (status < 0) 4638 if (status < 0)
4624 return status; 4639 return status;
@@ -4652,6 +4667,10 @@ static int video_write(char *buf)
4652 if (video_supported == TPACPI_VIDEO_NONE) 4667 if (video_supported == TPACPI_VIDEO_NONE)
4653 return -ENODEV; 4668 return -ENODEV;
4654 4669
4670 /* Even reads can crash X.org, let alone writes... */
4671 if (!capable(CAP_SYS_ADMIN))
4672 return -EPERM;
4673
4655 enable = 0; 4674 enable = 0;
4656 disable = 0; 4675 disable = 0;
4657 4676
@@ -6133,13 +6152,13 @@ static const struct tpacpi_quirk brightness_quirk_table[] __initconst = {
6133 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ 6152 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */
6134 6153
6135 /* Models with ATI GPUs that can use ECNVRAM */ 6154 /* Models with ATI GPUs that can use ECNVRAM */
6136 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), 6155 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */
6137 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), 6156 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
6138 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), 6157 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */
6139 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), 6158 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
6140 6159
6141 /* Models with Intel Extreme Graphics 2 */ 6160 /* Models with Intel Extreme Graphics 2 */
6142 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), 6161 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */
6143 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), 6162 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
6144 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), 6163 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC),
6145 6164
@@ -6522,7 +6541,8 @@ static int volume_set_status(const u8 status)
6522 return volume_set_status_ec(status); 6541 return volume_set_status_ec(status);
6523} 6542}
6524 6543
6525static int volume_set_mute_ec(const bool mute) 6544/* returns < 0 on error, 0 on no change, 1 on change */
6545static int __volume_set_mute_ec(const bool mute)
6526{ 6546{
6527 int rc; 6547 int rc;
6528 u8 s, n; 6548 u8 s, n;
@@ -6537,22 +6557,37 @@ static int volume_set_mute_ec(const bool mute)
6537 n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : 6557 n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK :
6538 s & ~TP_EC_AUDIO_MUTESW_MSK; 6558 s & ~TP_EC_AUDIO_MUTESW_MSK;
6539 6559
6540 if (n != s) 6560 if (n != s) {
6541 rc = volume_set_status_ec(n); 6561 rc = volume_set_status_ec(n);
6562 if (!rc)
6563 rc = 1;
6564 }
6542 6565
6543unlock: 6566unlock:
6544 mutex_unlock(&volume_mutex); 6567 mutex_unlock(&volume_mutex);
6545 return rc; 6568 return rc;
6546} 6569}
6547 6570
6571static int volume_alsa_set_mute(const bool mute)
6572{
6573 dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n",
6574 (mute) ? "" : "un");
6575 return __volume_set_mute_ec(mute);
6576}
6577
6548static int volume_set_mute(const bool mute) 6578static int volume_set_mute(const bool mute)
6549{ 6579{
6580 int rc;
6581
6550 dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", 6582 dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n",
6551 (mute) ? "" : "un"); 6583 (mute) ? "" : "un");
6552 return volume_set_mute_ec(mute); 6584
6585 rc = __volume_set_mute_ec(mute);
6586 return (rc < 0) ? rc : 0;
6553} 6587}
6554 6588
6555static int volume_set_volume_ec(const u8 vol) 6589/* returns < 0 on error, 0 on no change, 1 on change */
6590static int __volume_set_volume_ec(const u8 vol)
6556{ 6591{
6557 int rc; 6592 int rc;
6558 u8 s, n; 6593 u8 s, n;
@@ -6569,19 +6604,22 @@ static int volume_set_volume_ec(const u8 vol)
6569 6604
6570 n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; 6605 n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol;
6571 6606
6572 if (n != s) 6607 if (n != s) {
6573 rc = volume_set_status_ec(n); 6608 rc = volume_set_status_ec(n);
6609 if (!rc)
6610 rc = 1;
6611 }
6574 6612
6575unlock: 6613unlock:
6576 mutex_unlock(&volume_mutex); 6614 mutex_unlock(&volume_mutex);
6577 return rc; 6615 return rc;
6578} 6616}
6579 6617
6580static int volume_set_volume(const u8 vol) 6618static int volume_alsa_set_volume(const u8 vol)
6581{ 6619{
6582 dbg_printk(TPACPI_DBG_MIXER, 6620 dbg_printk(TPACPI_DBG_MIXER,
6583 "trying to set volume level to %hu\n", vol); 6621 "ALSA: trying to set volume level to %hu\n", vol);
6584 return volume_set_volume_ec(vol); 6622 return __volume_set_volume_ec(vol);
6585} 6623}
6586 6624
6587static void volume_alsa_notify_change(void) 6625static void volume_alsa_notify_change(void)
@@ -6628,7 +6666,7 @@ static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol,
6628static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, 6666static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol,
6629 struct snd_ctl_elem_value *ucontrol) 6667 struct snd_ctl_elem_value *ucontrol)
6630{ 6668{
6631 return volume_set_volume(ucontrol->value.integer.value[0]); 6669 return volume_alsa_set_volume(ucontrol->value.integer.value[0]);
6632} 6670}
6633 6671
6634#define volume_alsa_mute_info snd_ctl_boolean_mono_info 6672#define volume_alsa_mute_info snd_ctl_boolean_mono_info
@@ -6651,7 +6689,7 @@ static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol,
6651static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, 6689static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol,
6652 struct snd_ctl_elem_value *ucontrol) 6690 struct snd_ctl_elem_value *ucontrol)
6653{ 6691{
6654 return volume_set_mute(!ucontrol->value.integer.value[0]); 6692 return volume_alsa_set_mute(!ucontrol->value.integer.value[0]);
6655} 6693}
6656 6694
6657static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata = { 6695static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata = {
@@ -7070,7 +7108,7 @@ static struct ibm_struct volume_driver_data = {
7070 * 7108 *
7071 * Fan speed changes of any sort (including those caused by the 7109 * Fan speed changes of any sort (including those caused by the
7072 * disengaged mode) are usually done slowly by the firmware as the 7110 * disengaged mode) are usually done slowly by the firmware as the
7073 * maximum ammount of fan duty cycle change per second seems to be 7111 * maximum amount of fan duty cycle change per second seems to be
7074 * limited. 7112 * limited.
7075 * 7113 *
7076 * Reading is not available if GFAN exists. 7114 * Reading is not available if GFAN exists.
@@ -8477,9 +8515,10 @@ static int __init ibm_init(struct ibm_init_struct *iibm)
8477 "%s installed\n", ibm->name); 8515 "%s installed\n", ibm->name);
8478 8516
8479 if (ibm->read) { 8517 if (ibm->read) {
8480 mode_t mode; 8518 mode_t mode = iibm->base_procfs_mode;
8481 8519
8482 mode = S_IRUGO; 8520 if (!mode)
8521 mode = S_IRUGO;
8483 if (ibm->write) 8522 if (ibm->write)
8484 mode |= S_IWUSR; 8523 mode |= S_IWUSR;
8485 entry = proc_create_data(ibm->name, mode, proc_dir, 8524 entry = proc_create_data(ibm->name, mode, proc_dir,
@@ -8670,6 +8709,7 @@ static struct ibm_init_struct ibms_init[] __initdata = {
8670#ifdef CONFIG_THINKPAD_ACPI_VIDEO 8709#ifdef CONFIG_THINKPAD_ACPI_VIDEO
8671 { 8710 {
8672 .init = video_init, 8711 .init = video_init,
8712 .base_procfs_mode = S_IRUSR,
8673 .data = &video_driver_data, 8713 .data = &video_driver_data,
8674 }, 8714 },
8675#endif 8715#endif
@@ -9032,6 +9072,9 @@ static int __init thinkpad_acpi_module_init(void)
9032 return ret; 9072 return ret;
9033 } 9073 }
9034 } 9074 }
9075
9076 tpacpi_lifecycle = TPACPI_LIFE_RUNNING;
9077
9035 ret = input_register_device(tpacpi_inputdev); 9078 ret = input_register_device(tpacpi_inputdev);
9036 if (ret < 0) { 9079 if (ret < 0) {
9037 printk(TPACPI_ERR "unable to register input device\n"); 9080 printk(TPACPI_ERR "unable to register input device\n");
@@ -9041,7 +9084,6 @@ static int __init thinkpad_acpi_module_init(void)
9041 tp_features.input_device_registered = 1; 9084 tp_features.input_device_registered = 1;
9042 } 9085 }
9043 9086
9044 tpacpi_lifecycle = TPACPI_LIFE_RUNNING;
9045 return 0; 9087 return 0;
9046} 9088}
9047 9089
diff --git a/drivers/platform/x86/topstar-laptop.c b/drivers/platform/x86/topstar-laptop.c
index 02f3d4e9e666..4d6516fded7e 100644
--- a/drivers/platform/x86/topstar-laptop.c
+++ b/drivers/platform/x86/topstar-laptop.c
@@ -46,7 +46,7 @@ static struct tps_key_entry topstar_keymap[] = {
46 { } 46 { }
47}; 47};
48 48
49static struct tps_key_entry *tps_get_key_by_scancode(int code) 49static struct tps_key_entry *tps_get_key_by_scancode(unsigned int code)
50{ 50{
51 struct tps_key_entry *key; 51 struct tps_key_entry *key;
52 52
@@ -57,7 +57,7 @@ static struct tps_key_entry *tps_get_key_by_scancode(int code)
57 return NULL; 57 return NULL;
58} 58}
59 59
60static struct tps_key_entry *tps_get_key_by_keycode(int code) 60static struct tps_key_entry *tps_get_key_by_keycode(unsigned int code)
61{ 61{
62 struct tps_key_entry *key; 62 struct tps_key_entry *key;
63 63
@@ -126,7 +126,8 @@ static int acpi_topstar_fncx_switch(struct acpi_device *device, bool state)
126 return 0; 126 return 0;
127} 127}
128 128
129static int topstar_getkeycode(struct input_dev *dev, int scancode, int *keycode) 129static int topstar_getkeycode(struct input_dev *dev,
130 unsigned int scancode, unsigned int *keycode)
130{ 131{
131 struct tps_key_entry *key = tps_get_key_by_scancode(scancode); 132 struct tps_key_entry *key = tps_get_key_by_scancode(scancode);
132 133
@@ -137,14 +138,12 @@ static int topstar_getkeycode(struct input_dev *dev, int scancode, int *keycode)
137 return 0; 138 return 0;
138} 139}
139 140
140static int topstar_setkeycode(struct input_dev *dev, int scancode, int keycode) 141static int topstar_setkeycode(struct input_dev *dev,
142 unsigned int scancode, unsigned int keycode)
141{ 143{
142 struct tps_key_entry *key; 144 struct tps_key_entry *key;
143 int old_keycode; 145 int old_keycode;
144 146
145 if (keycode < 0 || keycode > KEY_MAX)
146 return -EINVAL;
147
148 key = tps_get_key_by_scancode(scancode); 147 key = tps_get_key_by_scancode(scancode);
149 148
150 if (!key) 149 if (!key)
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 77bf5d8f893a..789240d1b577 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -46,6 +46,7 @@
46#include <linux/backlight.h> 46#include <linux/backlight.h>
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/rfkill.h> 48#include <linux/rfkill.h>
49#include <linux/input.h>
49 50
50#include <asm/uaccess.h> 51#include <asm/uaccess.h>
51 52
@@ -62,9 +63,10 @@ MODULE_LICENSE("GPL");
62 63
63/* Toshiba ACPI method paths */ 64/* Toshiba ACPI method paths */
64#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM" 65#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
65#define METHOD_HCI_1 "\\_SB_.VALD.GHCI" 66#define TOSH_INTERFACE_1 "\\_SB_.VALD"
66#define METHOD_HCI_2 "\\_SB_.VALZ.GHCI" 67#define TOSH_INTERFACE_2 "\\_SB_.VALZ"
67#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" 68#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
69#define GHCI_METHOD ".GHCI"
68 70
69/* Toshiba HCI interface definitions 71/* Toshiba HCI interface definitions
70 * 72 *
@@ -116,6 +118,36 @@ static const struct acpi_device_id toshiba_device_ids[] = {
116}; 118};
117MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); 119MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
118 120
121struct key_entry {
122 char type;
123 u16 code;
124 u16 keycode;
125};
126
127enum {KE_KEY, KE_END};
128
129static struct key_entry toshiba_acpi_keymap[] = {
130 {KE_KEY, 0x101, KEY_MUTE},
131 {KE_KEY, 0x13b, KEY_COFFEE},
132 {KE_KEY, 0x13c, KEY_BATTERY},
133 {KE_KEY, 0x13d, KEY_SLEEP},
134 {KE_KEY, 0x13e, KEY_SUSPEND},
135 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
136 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
137 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
138 {KE_KEY, 0x142, KEY_WLAN},
139 {KE_KEY, 0x143, KEY_PROG1},
140 {KE_KEY, 0xb05, KEY_PROG2},
141 {KE_KEY, 0xb06, KEY_WWW},
142 {KE_KEY, 0xb07, KEY_MAIL},
143 {KE_KEY, 0xb30, KEY_STOP},
144 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
145 {KE_KEY, 0xb32, KEY_NEXTSONG},
146 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
147 {KE_KEY, 0xb5a, KEY_MEDIA},
148 {KE_END, 0, 0},
149};
150
119/* utility 151/* utility
120 */ 152 */
121 153
@@ -251,6 +283,8 @@ static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
251struct toshiba_acpi_dev { 283struct toshiba_acpi_dev {
252 struct platform_device *p_dev; 284 struct platform_device *p_dev;
253 struct rfkill *bt_rfk; 285 struct rfkill *bt_rfk;
286 struct input_dev *hotkey_dev;
287 acpi_handle handle;
254 288
255 const char *bt_name; 289 const char *bt_name;
256 290
@@ -711,8 +745,158 @@ static struct backlight_ops toshiba_backlight_data = {
711 .update_status = set_lcd_status, 745 .update_status = set_lcd_status,
712}; 746};
713 747
748static struct key_entry *toshiba_acpi_get_entry_by_scancode(unsigned int code)
749{
750 struct key_entry *key;
751
752 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
753 if (code == key->code)
754 return key;
755
756 return NULL;
757}
758
759static struct key_entry *toshiba_acpi_get_entry_by_keycode(unsigned int code)
760{
761 struct key_entry *key;
762
763 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
764 if (code == key->keycode && key->type == KE_KEY)
765 return key;
766
767 return NULL;
768}
769
770static int toshiba_acpi_getkeycode(struct input_dev *dev,
771 unsigned int scancode, unsigned int *keycode)
772{
773 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
774
775 if (key && key->type == KE_KEY) {
776 *keycode = key->keycode;
777 return 0;
778 }
779
780 return -EINVAL;
781}
782
783static int toshiba_acpi_setkeycode(struct input_dev *dev,
784 unsigned int scancode, unsigned int keycode)
785{
786 struct key_entry *key;
787 unsigned int old_keycode;
788
789 key = toshiba_acpi_get_entry_by_scancode(scancode);
790 if (key && key->type == KE_KEY) {
791 old_keycode = key->keycode;
792 key->keycode = keycode;
793 set_bit(keycode, dev->keybit);
794 if (!toshiba_acpi_get_entry_by_keycode(old_keycode))
795 clear_bit(old_keycode, dev->keybit);
796 return 0;
797 }
798
799 return -EINVAL;
800}
801
802static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
803{
804 u32 hci_result, value;
805 struct key_entry *key;
806
807 if (event != 0x80)
808 return;
809 do {
810 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
811 if (hci_result == HCI_SUCCESS) {
812 if (value == 0x100)
813 continue;
814 /* act on key press; ignore key release */
815 if (value & 0x80)
816 continue;
817
818 key = toshiba_acpi_get_entry_by_scancode
819 (value);
820 if (!key) {
821 printk(MY_INFO "Unknown key %x\n",
822 value);
823 continue;
824 }
825 input_report_key(toshiba_acpi.hotkey_dev,
826 key->keycode, 1);
827 input_sync(toshiba_acpi.hotkey_dev);
828 input_report_key(toshiba_acpi.hotkey_dev,
829 key->keycode, 0);
830 input_sync(toshiba_acpi.hotkey_dev);
831 } else if (hci_result == HCI_NOT_SUPPORTED) {
832 /* This is a workaround for an unresolved issue on
833 * some machines where system events sporadically
834 * become disabled. */
835 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
836 printk(MY_NOTICE "Re-enabled hotkeys\n");
837 }
838 } while (hci_result != HCI_EMPTY);
839}
840
841static int toshiba_acpi_setup_keyboard(char *device)
842{
843 acpi_status status;
844 acpi_handle handle;
845 int result;
846 const struct key_entry *key;
847
848 status = acpi_get_handle(NULL, device, &handle);
849 if (ACPI_FAILURE(status)) {
850 printk(MY_INFO "Unable to get notification device\n");
851 return -ENODEV;
852 }
853
854 toshiba_acpi.handle = handle;
855
856 status = acpi_evaluate_object(handle, "ENAB", NULL, NULL);
857 if (ACPI_FAILURE(status)) {
858 printk(MY_INFO "Unable to enable hotkeys\n");
859 return -ENODEV;
860 }
861
862 status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
863 toshiba_acpi_notify, NULL);
864 if (ACPI_FAILURE(status)) {
865 printk(MY_INFO "Unable to install hotkey notification\n");
866 return -ENODEV;
867 }
868
869 toshiba_acpi.hotkey_dev = input_allocate_device();
870 if (!toshiba_acpi.hotkey_dev) {
871 printk(MY_INFO "Unable to register input device\n");
872 return -ENOMEM;
873 }
874
875 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
876 toshiba_acpi.hotkey_dev->phys = device;
877 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
878 toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode;
879 toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode;
880
881 for (key = toshiba_acpi_keymap; key->type != KE_END; key++) {
882 set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit);
883 set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit);
884 }
885
886 result = input_register_device(toshiba_acpi.hotkey_dev);
887 if (result) {
888 printk(MY_INFO "Unable to register input device\n");
889 return result;
890 }
891
892 return 0;
893}
894
714static void toshiba_acpi_exit(void) 895static void toshiba_acpi_exit(void)
715{ 896{
897 if (toshiba_acpi.hotkey_dev)
898 input_unregister_device(toshiba_acpi.hotkey_dev);
899
716 if (toshiba_acpi.bt_rfk) { 900 if (toshiba_acpi.bt_rfk) {
717 rfkill_unregister(toshiba_acpi.bt_rfk); 901 rfkill_unregister(toshiba_acpi.bt_rfk);
718 rfkill_destroy(toshiba_acpi.bt_rfk); 902 rfkill_destroy(toshiba_acpi.bt_rfk);
@@ -726,6 +910,9 @@ static void toshiba_acpi_exit(void)
726 if (toshiba_proc_dir) 910 if (toshiba_proc_dir)
727 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 911 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
728 912
913 acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY,
914 toshiba_acpi_notify);
915
729 platform_device_unregister(toshiba_acpi.p_dev); 916 platform_device_unregister(toshiba_acpi.p_dev);
730 917
731 return; 918 return;
@@ -742,11 +929,15 @@ static int __init toshiba_acpi_init(void)
742 return -ENODEV; 929 return -ENODEV;
743 930
744 /* simple device detection: look for HCI method */ 931 /* simple device detection: look for HCI method */
745 if (is_valid_acpi_path(METHOD_HCI_1)) 932 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
746 method_hci = METHOD_HCI_1; 933 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
747 else if (is_valid_acpi_path(METHOD_HCI_2)) 934 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
748 method_hci = METHOD_HCI_2; 935 printk(MY_INFO "Unable to activate hotkeys\n");
749 else 936 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
937 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
938 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
939 printk(MY_INFO "Unable to activate hotkeys\n");
940 } else
750 return -ENODEV; 941 return -ENODEV;
751 942
752 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n", 943 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
diff --git a/drivers/platform/x86/toshiba_bluetooth.c b/drivers/platform/x86/toshiba_bluetooth.c
index a350418e87ea..944068611919 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -57,7 +57,7 @@ static struct acpi_driver toshiba_bt_rfkill_driver = {
57static int toshiba_bluetooth_enable(acpi_handle handle) 57static int toshiba_bluetooth_enable(acpi_handle handle)
58{ 58{
59 acpi_status res1, res2; 59 acpi_status res1, res2;
60 acpi_integer result; 60 u64 result;
61 61
62 /* 62 /*
63 * Query ACPI to verify RFKill switch is set to 'on'. 63 * Query ACPI to verify RFKill switch is set to 'on'.
@@ -95,7 +95,7 @@ static int toshiba_bt_resume(struct acpi_device *device)
95static int toshiba_bt_rfkill_add(struct acpi_device *device) 95static int toshiba_bt_rfkill_add(struct acpi_device *device)
96{ 96{
97 acpi_status status; 97 acpi_status status;
98 acpi_integer bt_present; 98 u64 bt_present;
99 int result = -ENODEV; 99 int result = -ENODEV;
100 100
101 /* 101 /*
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index b104302fea0a..09e9918c69c1 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -796,7 +796,7 @@ static __init acpi_status parse_wdg(acpi_handle handle)
796 */ 796 */
797static acpi_status 797static acpi_status
798acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address, 798acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
799 u32 bits, acpi_integer * value, 799 u32 bits, u64 *value,
800 void *handler_context, void *region_context) 800 void *handler_context, void *region_context)
801{ 801{
802 int result = 0, i = 0; 802 int result = 0, i = 0;
@@ -813,7 +813,7 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
813 813
814 if (function == ACPI_READ) { 814 if (function == ACPI_READ) {
815 result = ec_read(address, &temp); 815 result = ec_read(address, &temp);
816 (*value) |= ((acpi_integer)temp) << i; 816 (*value) |= ((u64)temp) << i;
817 } else { 817 } else {
818 temp = 0xff & ((*value) >> i); 818 temp = 0xff & ((*value) >> i);
819 result = ec_write(address, temp); 819 result = ec_write(address, temp);