blob: 391c32bd703e1c77171800d6e17aefe53acbeff7 [file] [log] [blame]
Yong Wangee027e42010-03-21 10:26:34 +08001/*
2 * Eee PC WMI hotkey driver
3 *
4 * Copyright(C) 2010 Intel Corporation.
Corentin Chary4c4edfa2010-11-29 08:14:11 +01005 * Copyright(C) 2010 Corentin Chary <corentin.chary@gmail.com>
Yong Wangee027e42010-03-21 10:26:34 +08006 *
7 * Portions based on wistron_btns.c:
8 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
9 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
10 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Yong Wang81248882010-04-11 09:26:33 +080027#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
Yong Wangee027e42010-03-21 10:26:34 +080029#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/types.h>
Tejun Heoa32f3922010-04-05 11:37:59 +090033#include <linux/slab.h>
Yong Wangee027e42010-03-21 10:26:34 +080034#include <linux/input.h>
35#include <linux/input/sparse-keymap.h>
Yong Wang3d7b1652010-04-11 09:27:54 +080036#include <linux/fb.h>
37#include <linux/backlight.h>
Corentin Chary084fca62010-11-29 08:14:06 +010038#include <linux/leds.h>
Corentin Charyba48fdb2010-11-29 08:14:07 +010039#include <linux/rfkill.h>
Corentin Charyafa7c882011-02-06 13:28:28 +010040#include <linux/pci.h>
41#include <linux/pci_hotplug.h>
Corentin Chary8c1b2d82010-11-29 08:14:09 +010042#include <linux/debugfs.h>
43#include <linux/seq_file.h>
Yong Wang45f2c692010-04-11 09:27:19 +080044#include <linux/platform_device.h>
Corentin Charyafa7c882011-02-06 13:28:28 +010045#include <linux/dmi.h>
Yong Wangee027e42010-03-21 10:26:34 +080046#include <acpi/acpi_bus.h>
47#include <acpi/acpi_drivers.h>
48
Yong Wang45f2c692010-04-11 09:27:19 +080049#define EEEPC_WMI_FILE "eeepc-wmi"
50
Yong Wangee027e42010-03-21 10:26:34 +080051MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
52MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
53MODULE_LICENSE("GPL");
54
Corentin Charyd358cb52010-11-29 08:14:14 +010055#define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */
56
Yong Wangee027e42010-03-21 10:26:34 +080057#define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
Yong Wang3d7b1652010-04-11 09:27:54 +080058#define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
Yong Wangee027e42010-03-21 10:26:34 +080059
60MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
Yong Wang3d7b1652010-04-11 09:27:54 +080061MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
Yong Wangee027e42010-03-21 10:26:34 +080062
Corentin Chary33e0e6f2011-02-06 13:28:34 +010063#define NOTIFY_BRNUP_MIN 0x11
64#define NOTIFY_BRNUP_MAX 0x1f
65#define NOTIFY_BRNDOWN_MIN 0x20
66#define NOTIFY_BRNDOWN_MAX 0x2e
Yong Wangee027e42010-03-21 10:26:34 +080067
Corentin Chary33e0e6f2011-02-06 13:28:34 +010068#define EEEPC_WMI_METHODID_DSTS 0x53544344
69#define EEEPC_WMI_METHODID_DEVS 0x53564544
70#define EEEPC_WMI_METHODID_CFVS 0x53564643
Yong Wang3d7b1652010-04-11 09:27:54 +080071
Corentin Charyba48fdb2010-11-29 08:14:07 +010072#define EEEPC_WMI_DEVID_WLAN 0x00010011
73#define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013
74#define EEEPC_WMI_DEVID_WWAN3G 0x00010019
Corentin Chary33e0e6f2011-02-06 13:28:34 +010075#define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012
76#define EEEPC_WMI_DEVID_TPDLED 0x00100011
Yong Wang3d7b1652010-04-11 09:27:54 +080077
Corentin Charyaafa7192011-02-06 13:28:35 +010078#define EEEPC_WMI_DSTS_STATUS_BIT 0x00000001
79#define EEEPC_WMI_DSTS_PRESENCE_BIT 0x00010000
80
Corentin Charyafa7c882011-02-06 13:28:28 +010081static bool hotplug_wireless;
82
83module_param(hotplug_wireless, bool, 0444);
84MODULE_PARM_DESC(hotplug_wireless,
85 "Enable hotplug for wireless device. "
86 "If your laptop needs that, please report to "
87 "acpi4asus-user@lists.sourceforge.net.");
88
Yong Wangee027e42010-03-21 10:26:34 +080089static const struct key_entry eeepc_wmi_keymap[] = {
90 /* Sleep already handled via generic ACPI code */
Yong Wangee027e42010-03-21 10:26:34 +080091 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
92 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
Corentin Chary5628e5a2011-02-06 13:28:26 +010093 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
94 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
95 { KE_KEY, 0x32, { KEY_MUTE } },
96 { KE_KEY, 0x5c, { KEY_F15 } },
97 { KE_KEY, 0x5d, { KEY_WLAN } },
Chris Bagwelleda17482010-10-11 18:47:17 -050098 { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
Corentin Charybc40cce2011-02-06 13:28:27 +010099 { KE_KEY, 0x88, { KEY_WLAN } },
Corentin Chary5628e5a2011-02-06 13:28:26 +0100100 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
101 { KE_KEY, 0xe0, { KEY_PROG1 } },
Chris Bagwelleda17482010-10-11 18:47:17 -0500102 { KE_KEY, 0xe1, { KEY_F14 } },
103 { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } },
Yong Wangee027e42010-03-21 10:26:34 +0800104 { KE_END, 0},
105};
106
Yong Wang3d7b1652010-04-11 09:27:54 +0800107struct bios_args {
108 u32 dev_id;
109 u32 ctrl_param;
110};
111
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100112/*
113 * eeepc-wmi/ - debugfs root directory
114 * dev_id - current dev_id
115 * ctrl_param - current ctrl_param
116 * devs - call DEVS(dev_id, ctrl_param) and print result
117 * dsts - call DSTS(dev_id) and print result
118 */
119struct eeepc_wmi_debug {
120 struct dentry *root;
121 u32 dev_id;
122 u32 ctrl_param;
123};
124
Yong Wang81248882010-04-11 09:26:33 +0800125struct eeepc_wmi {
Corentin Charyafa7c882011-02-06 13:28:28 +0100126 bool hotplug_wireless;
127
Yong Wang81248882010-04-11 09:26:33 +0800128 struct input_dev *inputdev;
Yong Wang3d7b1652010-04-11 09:27:54 +0800129 struct backlight_device *backlight_device;
Corentin Chary27c136c2010-11-29 08:14:05 +0100130 struct platform_device *platform_device;
Corentin Chary084fca62010-11-29 08:14:06 +0100131
132 struct led_classdev tpd_led;
133 int tpd_led_wk;
134 struct workqueue_struct *led_workqueue;
135 struct work_struct tpd_led_work;
Corentin Charyba48fdb2010-11-29 08:14:07 +0100136
137 struct rfkill *wlan_rfkill;
138 struct rfkill *bluetooth_rfkill;
139 struct rfkill *wwan3g_rfkill;
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100140
Corentin Charyafa7c882011-02-06 13:28:28 +0100141 struct hotplug_slot *hotplug_slot;
142 struct mutex hotplug_lock;
Corentin Chary279f8f92011-02-06 13:28:29 +0100143 struct mutex wmi_lock;
144 struct workqueue_struct *hotplug_workqueue;
145 struct work_struct hotplug_work;
Corentin Charyafa7c882011-02-06 13:28:28 +0100146
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100147 struct eeepc_wmi_debug debug;
Yong Wang81248882010-04-11 09:26:33 +0800148};
149
Yong Wang81248882010-04-11 09:26:33 +0800150static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
Yong Wangee027e42010-03-21 10:26:34 +0800151{
152 int err;
153
Yong Wang81248882010-04-11 09:26:33 +0800154 eeepc->inputdev = input_allocate_device();
155 if (!eeepc->inputdev)
Yong Wangee027e42010-03-21 10:26:34 +0800156 return -ENOMEM;
157
Yong Wang81248882010-04-11 09:26:33 +0800158 eeepc->inputdev->name = "Eee PC WMI hotkeys";
Yong Wang45f2c692010-04-11 09:27:19 +0800159 eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
Yong Wang81248882010-04-11 09:26:33 +0800160 eeepc->inputdev->id.bustype = BUS_HOST;
Corentin Chary27c136c2010-11-29 08:14:05 +0100161 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
Yong Wangee027e42010-03-21 10:26:34 +0800162
Yong Wang81248882010-04-11 09:26:33 +0800163 err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
Yong Wangee027e42010-03-21 10:26:34 +0800164 if (err)
165 goto err_free_dev;
166
Yong Wang81248882010-04-11 09:26:33 +0800167 err = input_register_device(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800168 if (err)
169 goto err_free_keymap;
170
171 return 0;
172
173err_free_keymap:
Yong Wang81248882010-04-11 09:26:33 +0800174 sparse_keymap_free(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800175err_free_dev:
Yong Wang81248882010-04-11 09:26:33 +0800176 input_free_device(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800177 return err;
178}
179
Yong Wang81248882010-04-11 09:26:33 +0800180static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc)
181{
182 if (eeepc->inputdev) {
183 sparse_keymap_free(eeepc->inputdev);
184 input_unregister_device(eeepc->inputdev);
185 }
186
187 eeepc->inputdev = NULL;
188}
189
Corentin Chary2a3f0062010-11-29 08:14:10 +0100190static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *retval)
Yong Wang3d7b1652010-04-11 09:27:54 +0800191{
192 struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id };
193 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
194 union acpi_object *obj;
195 acpi_status status;
196 u32 tmp;
197
198 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
Corentin Charyafa7c882011-02-06 13:28:28 +0100199 1, EEEPC_WMI_METHODID_DSTS,
200 &input, &output);
Yong Wang3d7b1652010-04-11 09:27:54 +0800201
202 if (ACPI_FAILURE(status))
203 return status;
204
205 obj = (union acpi_object *)output.pointer;
206 if (obj && obj->type == ACPI_TYPE_INTEGER)
207 tmp = (u32)obj->integer.value;
208 else
209 tmp = 0;
210
Corentin Chary2a3f0062010-11-29 08:14:10 +0100211 if (retval)
212 *retval = tmp;
Yong Wang3d7b1652010-04-11 09:27:54 +0800213
214 kfree(obj);
215
216 return status;
217
218}
219
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100220static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
221 u32 *retval)
Yong Wang3d7b1652010-04-11 09:27:54 +0800222{
223 struct bios_args args = {
224 .dev_id = dev_id,
225 .ctrl_param = ctrl_param,
226 };
227 struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
228 acpi_status status;
229
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100230 if (!retval) {
231 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
232 EEEPC_WMI_METHODID_DEVS,
233 &input, NULL);
234 } else {
235 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
236 union acpi_object *obj;
237 u32 tmp;
238
239 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
240 EEEPC_WMI_METHODID_DEVS,
241 &input, &output);
242
243 if (ACPI_FAILURE(status))
244 return status;
245
246 obj = (union acpi_object *)output.pointer;
247 if (obj && obj->type == ACPI_TYPE_INTEGER)
248 tmp = (u32)obj->integer.value;
249 else
250 tmp = 0;
251
252 *retval = tmp;
253
254 kfree(obj);
255 }
Yong Wang3d7b1652010-04-11 09:27:54 +0800256
257 return status;
258}
259
Corentin Chary5c956382011-02-06 13:28:31 +0100260/* Helper for special devices with magic return codes */
261static int eeepc_wmi_get_devstate_simple(u32 dev_id)
262{
263 u32 retval = 0;
264 acpi_status status;
265
266 status = eeepc_wmi_get_devstate(dev_id, &retval);
267
268 if (ACPI_FAILURE(status))
269 return -EINVAL;
270
Corentin Charyaafa7192011-02-06 13:28:35 +0100271 if (!(retval & EEEPC_WMI_DSTS_PRESENCE_BIT))
Corentin Chary5c956382011-02-06 13:28:31 +0100272 return -ENODEV;
273
Corentin Charyaafa7192011-02-06 13:28:35 +0100274 return retval & EEEPC_WMI_DSTS_STATUS_BIT;
Corentin Chary5c956382011-02-06 13:28:31 +0100275}
276
Corentin Chary084fca62010-11-29 08:14:06 +0100277/*
278 * LEDs
279 */
280/*
281 * These functions actually update the LED's, and are called from a
282 * workqueue. By doing this as separate work rather than when the LED
283 * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a
284 * potentially bad time, such as a timer interrupt.
285 */
286static void tpd_led_update(struct work_struct *work)
287{
288 int ctrl_param;
289 struct eeepc_wmi *eeepc;
290
291 eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
292
293 ctrl_param = eeepc->tpd_led_wk;
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100294 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param, NULL);
Corentin Chary084fca62010-11-29 08:14:06 +0100295}
296
297static void tpd_led_set(struct led_classdev *led_cdev,
298 enum led_brightness value)
299{
300 struct eeepc_wmi *eeepc;
301
302 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
303
304 eeepc->tpd_led_wk = !!value;
305 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
306}
307
308static int read_tpd_state(struct eeepc_wmi *eeepc)
309{
Corentin Chary5c956382011-02-06 13:28:31 +0100310 return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TPDLED);
Corentin Chary084fca62010-11-29 08:14:06 +0100311}
312
313static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
314{
315 struct eeepc_wmi *eeepc;
316
317 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
318
319 return read_tpd_state(eeepc);
320}
321
322static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
323{
324 int rv;
325
326 if (read_tpd_state(eeepc) < 0)
327 return 0;
328
329 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
330 if (!eeepc->led_workqueue)
331 return -ENOMEM;
332 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
333
334 eeepc->tpd_led.name = "eeepc::touchpad";
335 eeepc->tpd_led.brightness_set = tpd_led_set;
336 eeepc->tpd_led.brightness_get = tpd_led_get;
337 eeepc->tpd_led.max_brightness = 1;
338
339 rv = led_classdev_register(&eeepc->platform_device->dev,
340 &eeepc->tpd_led);
341 if (rv) {
342 destroy_workqueue(eeepc->led_workqueue);
343 return rv;
344 }
345
346 return 0;
347}
348
349static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
350{
351 if (eeepc->tpd_led.dev)
352 led_classdev_unregister(&eeepc->tpd_led);
353 if (eeepc->led_workqueue)
354 destroy_workqueue(eeepc->led_workqueue);
355}
356
357/*
Corentin Charyafa7c882011-02-06 13:28:28 +0100358 * PCI hotplug (for wlan rfkill)
359 */
360static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc)
361{
Corentin Chary5c956382011-02-06 13:28:31 +0100362 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
Corentin Charyafa7c882011-02-06 13:28:28 +0100363
Corentin Chary5c956382011-02-06 13:28:31 +0100364 if (result < 0)
Corentin Charyafa7c882011-02-06 13:28:28 +0100365 return false;
Corentin Chary5c956382011-02-06 13:28:31 +0100366 return !result;
Corentin Charyafa7c882011-02-06 13:28:28 +0100367}
368
369static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc)
370{
371 struct pci_dev *dev;
372 struct pci_bus *bus;
Corentin Chary279f8f92011-02-06 13:28:29 +0100373 bool blocked;
Corentin Charyafa7c882011-02-06 13:28:28 +0100374 bool absent;
375 u32 l;
376
Corentin Chary279f8f92011-02-06 13:28:29 +0100377 mutex_lock(&eeepc->wmi_lock);
378 blocked = eeepc_wlan_rfkill_blocked(eeepc);
379 mutex_unlock(&eeepc->wmi_lock);
Corentin Charyafa7c882011-02-06 13:28:28 +0100380
381 mutex_lock(&eeepc->hotplug_lock);
382
Corentin Chary279f8f92011-02-06 13:28:29 +0100383 if (eeepc->wlan_rfkill)
384 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
385
Corentin Charyafa7c882011-02-06 13:28:28 +0100386 if (eeepc->hotplug_slot) {
387 bus = pci_find_bus(0, 1);
388 if (!bus) {
389 pr_warning("Unable to find PCI bus 1?\n");
390 goto out_unlock;
391 }
392
393 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
394 pr_err("Unable to read PCI config space?\n");
395 goto out_unlock;
396 }
397 absent = (l == 0xffffffff);
398
399 if (blocked != absent) {
400 pr_warning("BIOS says wireless lan is %s, "
401 "but the pci device is %s\n",
402 blocked ? "blocked" : "unblocked",
403 absent ? "absent" : "present");
404 pr_warning("skipped wireless hotplug as probably "
405 "inappropriate for this model\n");
406 goto out_unlock;
407 }
408
409 if (!blocked) {
410 dev = pci_get_slot(bus, 0);
411 if (dev) {
412 /* Device already present */
413 pci_dev_put(dev);
414 goto out_unlock;
415 }
416 dev = pci_scan_single_device(bus, 0);
417 if (dev) {
418 pci_bus_assign_resources(bus);
419 if (pci_bus_add_device(dev))
420 pr_err("Unable to hotplug wifi\n");
421 }
422 } else {
423 dev = pci_get_slot(bus, 0);
424 if (dev) {
425 pci_remove_bus_device(dev);
426 pci_dev_put(dev);
427 }
428 }
429 }
430
431out_unlock:
432 mutex_unlock(&eeepc->hotplug_lock);
433}
434
435static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
436{
437 struct eeepc_wmi *eeepc = data;
438
439 if (event != ACPI_NOTIFY_BUS_CHECK)
440 return;
441
Corentin Chary279f8f92011-02-06 13:28:29 +0100442 /*
443 * We can't call directly eeepc_rfkill_hotplug because most
444 * of the time WMBC is still being executed and not reetrant.
445 * There is currently no way to tell ACPICA that we want this
446 * method to be serialized, we schedule a eeepc_rfkill_hotplug
447 * call later, in a safer context.
448 */
449 queue_work(eeepc->hotplug_workqueue, &eeepc->hotplug_work);
Corentin Charyafa7c882011-02-06 13:28:28 +0100450}
451
452static int eeepc_register_rfkill_notifier(struct eeepc_wmi *eeepc,
453 char *node)
454{
455 acpi_status status;
456 acpi_handle handle;
457
458 status = acpi_get_handle(NULL, node, &handle);
459
460 if (ACPI_SUCCESS(status)) {
461 status = acpi_install_notify_handler(handle,
462 ACPI_SYSTEM_NOTIFY,
463 eeepc_rfkill_notify,
464 eeepc);
465 if (ACPI_FAILURE(status))
466 pr_warning("Failed to register notify on %s\n", node);
467 } else
468 return -ENODEV;
469
470 return 0;
471}
472
473static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc,
474 char *node)
475{
476 acpi_status status = AE_OK;
477 acpi_handle handle;
478
479 status = acpi_get_handle(NULL, node, &handle);
480
481 if (ACPI_SUCCESS(status)) {
482 status = acpi_remove_notify_handler(handle,
483 ACPI_SYSTEM_NOTIFY,
484 eeepc_rfkill_notify);
485 if (ACPI_FAILURE(status))
486 pr_err("Error removing rfkill notify handler %s\n",
487 node);
488 }
489}
490
491static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
492 u8 *value)
493{
Corentin Chary5c956382011-02-06 13:28:31 +0100494 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
Corentin Charyafa7c882011-02-06 13:28:28 +0100495
Corentin Chary5c956382011-02-06 13:28:31 +0100496 if (result < 0)
497 return result;
Corentin Charyafa7c882011-02-06 13:28:28 +0100498
Corentin Chary5c956382011-02-06 13:28:31 +0100499 *value = !!result;
Corentin Charyafa7c882011-02-06 13:28:28 +0100500 return 0;
501}
502
503static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
504{
505 kfree(hotplug_slot->info);
506 kfree(hotplug_slot);
507}
508
509static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
510 .owner = THIS_MODULE,
511 .get_adapter_status = eeepc_get_adapter_status,
512 .get_power_status = eeepc_get_adapter_status,
513};
514
Corentin Chary279f8f92011-02-06 13:28:29 +0100515static void eeepc_hotplug_work(struct work_struct *work)
516{
517 struct eeepc_wmi *eeepc;
518
519 eeepc = container_of(work, struct eeepc_wmi, hotplug_work);
520 eeepc_rfkill_hotplug(eeepc);
521}
522
Corentin Charyafa7c882011-02-06 13:28:28 +0100523static int eeepc_setup_pci_hotplug(struct eeepc_wmi *eeepc)
524{
525 int ret = -ENOMEM;
526 struct pci_bus *bus = pci_find_bus(0, 1);
527
528 if (!bus) {
529 pr_err("Unable to find wifi PCI bus\n");
530 return -ENODEV;
531 }
532
Corentin Chary279f8f92011-02-06 13:28:29 +0100533 eeepc->hotplug_workqueue =
534 create_singlethread_workqueue("hotplug_workqueue");
535 if (!eeepc->hotplug_workqueue)
536 goto error_workqueue;
537
538 INIT_WORK(&eeepc->hotplug_work, eeepc_hotplug_work);
539
Corentin Charyafa7c882011-02-06 13:28:28 +0100540 eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
541 if (!eeepc->hotplug_slot)
542 goto error_slot;
543
544 eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
545 GFP_KERNEL);
546 if (!eeepc->hotplug_slot->info)
547 goto error_info;
548
549 eeepc->hotplug_slot->private = eeepc;
550 eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
551 eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
552 eeepc_get_adapter_status(eeepc->hotplug_slot,
553 &eeepc->hotplug_slot->info->adapter_status);
554
555 ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
556 if (ret) {
557 pr_err("Unable to register hotplug slot - %d\n", ret);
558 goto error_register;
559 }
560
561 return 0;
562
563error_register:
564 kfree(eeepc->hotplug_slot->info);
565error_info:
566 kfree(eeepc->hotplug_slot);
567 eeepc->hotplug_slot = NULL;
568error_slot:
Corentin Chary279f8f92011-02-06 13:28:29 +0100569 destroy_workqueue(eeepc->hotplug_workqueue);
570error_workqueue:
Corentin Charyafa7c882011-02-06 13:28:28 +0100571 return ret;
572}
573
574/*
Corentin Charyba48fdb2010-11-29 08:14:07 +0100575 * Rfkill devices
576 */
577static int eeepc_rfkill_set(void *data, bool blocked)
578{
579 int dev_id = (unsigned long)data;
580 u32 ctrl_param = !blocked;
Corentin Chary7898cf12011-02-06 13:28:30 +0100581 acpi_status status;
Corentin Charyba48fdb2010-11-29 08:14:07 +0100582
Corentin Chary7898cf12011-02-06 13:28:30 +0100583 status = eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL);
584
585 if (ACPI_FAILURE(status))
586 return -EIO;
587
588 return 0;
Corentin Charyba48fdb2010-11-29 08:14:07 +0100589}
590
591static void eeepc_rfkill_query(struct rfkill *rfkill, void *data)
592{
593 int dev_id = (unsigned long)data;
Corentin Chary5c956382011-02-06 13:28:31 +0100594 int result;
Corentin Charyba48fdb2010-11-29 08:14:07 +0100595
Corentin Chary5c956382011-02-06 13:28:31 +0100596 result = eeepc_wmi_get_devstate_simple(dev_id);
Corentin Charyba48fdb2010-11-29 08:14:07 +0100597
Corentin Chary5c956382011-02-06 13:28:31 +0100598 if (result < 0)
Corentin Charyba48fdb2010-11-29 08:14:07 +0100599 return ;
600
Corentin Chary5c956382011-02-06 13:28:31 +0100601 rfkill_set_sw_state(rfkill, !result);
Corentin Charyba48fdb2010-11-29 08:14:07 +0100602}
603
Corentin Chary279f8f92011-02-06 13:28:29 +0100604static int eeepc_rfkill_wlan_set(void *data, bool blocked)
605{
606 struct eeepc_wmi *eeepc = data;
607 int ret;
608
609 /*
610 * This handler is enabled only if hotplug is enabled.
611 * In this case, the eeepc_wmi_set_devstate() will
612 * trigger a wmi notification and we need to wait
613 * this call to finish before being able to call
614 * any wmi method
615 */
616 mutex_lock(&eeepc->wmi_lock);
617 ret = eeepc_rfkill_set((void *)(long)EEEPC_WMI_DEVID_WLAN, blocked);
618 mutex_unlock(&eeepc->wmi_lock);
619 return ret;
620}
621
622static void eeepc_rfkill_wlan_query(struct rfkill *rfkill, void *data)
623{
624 eeepc_rfkill_query(rfkill, (void *)(long)EEEPC_WMI_DEVID_WLAN);
625}
626
627static const struct rfkill_ops eeepc_rfkill_wlan_ops = {
628 .set_block = eeepc_rfkill_wlan_set,
629 .query = eeepc_rfkill_wlan_query,
630};
631
Corentin Charyba48fdb2010-11-29 08:14:07 +0100632static const struct rfkill_ops eeepc_rfkill_ops = {
633 .set_block = eeepc_rfkill_set,
634 .query = eeepc_rfkill_query,
635};
636
637static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
638 struct rfkill **rfkill,
639 const char *name,
640 enum rfkill_type type, int dev_id)
641{
Corentin Chary5c956382011-02-06 13:28:31 +0100642 int result = eeepc_wmi_get_devstate_simple(dev_id);
Corentin Charyba48fdb2010-11-29 08:14:07 +0100643
Corentin Chary5c956382011-02-06 13:28:31 +0100644 if (result < 0)
645 return result;
Corentin Charyba48fdb2010-11-29 08:14:07 +0100646
Corentin Chary279f8f92011-02-06 13:28:29 +0100647 if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless)
648 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
649 &eeepc_rfkill_wlan_ops, eeepc);
650 else
651 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
652 &eeepc_rfkill_ops, (void *)(long)dev_id);
Corentin Charyba48fdb2010-11-29 08:14:07 +0100653
654 if (!*rfkill)
655 return -EINVAL;
656
Corentin Chary5c956382011-02-06 13:28:31 +0100657 rfkill_init_sw_state(*rfkill, !result);
Corentin Charyba48fdb2010-11-29 08:14:07 +0100658 result = rfkill_register(*rfkill);
659 if (result) {
660 rfkill_destroy(*rfkill);
661 *rfkill = NULL;
662 return result;
663 }
664 return 0;
665}
666
667static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc)
668{
Corentin Charyafa7c882011-02-06 13:28:28 +0100669 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
670 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
671 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
Corentin Charyba48fdb2010-11-29 08:14:07 +0100672 if (eeepc->wlan_rfkill) {
673 rfkill_unregister(eeepc->wlan_rfkill);
674 rfkill_destroy(eeepc->wlan_rfkill);
675 eeepc->wlan_rfkill = NULL;
676 }
Corentin Charyafa7c882011-02-06 13:28:28 +0100677 /*
678 * Refresh pci hotplug in case the rfkill state was changed after
679 * eeepc_unregister_rfkill_notifier()
680 */
681 eeepc_rfkill_hotplug(eeepc);
682 if (eeepc->hotplug_slot)
683 pci_hp_deregister(eeepc->hotplug_slot);
Corentin Chary279f8f92011-02-06 13:28:29 +0100684 if (eeepc->hotplug_workqueue)
685 destroy_workqueue(eeepc->hotplug_workqueue);
Corentin Charyafa7c882011-02-06 13:28:28 +0100686
Corentin Charyba48fdb2010-11-29 08:14:07 +0100687 if (eeepc->bluetooth_rfkill) {
688 rfkill_unregister(eeepc->bluetooth_rfkill);
689 rfkill_destroy(eeepc->bluetooth_rfkill);
690 eeepc->bluetooth_rfkill = NULL;
691 }
692 if (eeepc->wwan3g_rfkill) {
693 rfkill_unregister(eeepc->wwan3g_rfkill);
694 rfkill_destroy(eeepc->wwan3g_rfkill);
695 eeepc->wwan3g_rfkill = NULL;
696 }
697}
698
699static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc)
700{
701 int result = 0;
702
Corentin Charyafa7c882011-02-06 13:28:28 +0100703 mutex_init(&eeepc->hotplug_lock);
Corentin Chary279f8f92011-02-06 13:28:29 +0100704 mutex_init(&eeepc->wmi_lock);
Corentin Charyafa7c882011-02-06 13:28:28 +0100705
Corentin Charyba48fdb2010-11-29 08:14:07 +0100706 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
707 "eeepc-wlan", RFKILL_TYPE_WLAN,
708 EEEPC_WMI_DEVID_WLAN);
709
710 if (result && result != -ENODEV)
711 goto exit;
712
713 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
714 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
715 EEEPC_WMI_DEVID_BLUETOOTH);
716
717 if (result && result != -ENODEV)
718 goto exit;
719
720 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
721 "eeepc-wwan3g", RFKILL_TYPE_WWAN,
722 EEEPC_WMI_DEVID_WWAN3G);
723
724 if (result && result != -ENODEV)
725 goto exit;
726
Corentin Charyafa7c882011-02-06 13:28:28 +0100727 result = eeepc_setup_pci_hotplug(eeepc);
728 /*
729 * If we get -EBUSY then something else is handling the PCI hotplug -
730 * don't fail in this case
731 */
732 if (result == -EBUSY)
733 result = 0;
734
735 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
736 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
737 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
738 /*
739 * Refresh pci hotplug in case the rfkill state was changed during
740 * setup.
741 */
742 eeepc_rfkill_hotplug(eeepc);
743
Corentin Charyba48fdb2010-11-29 08:14:07 +0100744exit:
745 if (result && result != -ENODEV)
746 eeepc_wmi_rfkill_exit(eeepc);
747
748 if (result == -ENODEV)
749 result = 0;
750
751 return result;
752}
753
754/*
Corentin Chary084fca62010-11-29 08:14:06 +0100755 * Backlight
756 */
Yong Wang3d7b1652010-04-11 09:27:54 +0800757static int read_brightness(struct backlight_device *bd)
758{
Corentin Charydfed65d2010-11-29 08:14:12 +0100759 u32 retval;
Yong Wang3d7b1652010-04-11 09:27:54 +0800760 acpi_status status;
761
Corentin Chary2a3f0062010-11-29 08:14:10 +0100762 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &retval);
Yong Wang3d7b1652010-04-11 09:27:54 +0800763
764 if (ACPI_FAILURE(status))
765 return -1;
766 else
Corentin Chary2a3f0062010-11-29 08:14:10 +0100767 return retval & 0xFF;
Yong Wang3d7b1652010-04-11 09:27:54 +0800768}
769
770static int update_bl_status(struct backlight_device *bd)
771{
772
Corentin Charydfed65d2010-11-29 08:14:12 +0100773 u32 ctrl_param;
Yong Wang3d7b1652010-04-11 09:27:54 +0800774 acpi_status status;
775
776 ctrl_param = bd->props.brightness;
777
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100778 status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
779 ctrl_param, NULL);
Yong Wang3d7b1652010-04-11 09:27:54 +0800780
781 if (ACPI_FAILURE(status))
782 return -1;
783 else
784 return 0;
785}
786
787static const struct backlight_ops eeepc_wmi_bl_ops = {
788 .get_brightness = read_brightness,
789 .update_status = update_bl_status,
790};
791
792static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code)
793{
794 struct backlight_device *bd = eeepc->backlight_device;
795 int old = bd->props.brightness;
Daniel Mackb7670ed2010-05-19 12:37:01 +0200796 int new = old;
Yong Wang3d7b1652010-04-11 09:27:54 +0800797
798 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
799 new = code - NOTIFY_BRNUP_MIN + 1;
800 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
801 new = code - NOTIFY_BRNDOWN_MIN;
802
803 bd->props.brightness = new;
804 backlight_update_status(bd);
805 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
806
807 return old;
808}
809
810static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
811{
812 struct backlight_device *bd;
813 struct backlight_properties props;
814
815 memset(&props, 0, sizeof(struct backlight_properties));
816 props.max_brightness = 15;
817 bd = backlight_device_register(EEEPC_WMI_FILE,
Corentin Chary27c136c2010-11-29 08:14:05 +0100818 &eeepc->platform_device->dev, eeepc,
Yong Wang3d7b1652010-04-11 09:27:54 +0800819 &eeepc_wmi_bl_ops, &props);
820 if (IS_ERR(bd)) {
821 pr_err("Could not register backlight device\n");
822 return PTR_ERR(bd);
823 }
824
825 eeepc->backlight_device = bd;
826
827 bd->props.brightness = read_brightness(bd);
828 bd->props.power = FB_BLANK_UNBLANK;
829 backlight_update_status(bd);
830
831 return 0;
832}
833
834static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
835{
836 if (eeepc->backlight_device)
837 backlight_device_unregister(eeepc->backlight_device);
838
839 eeepc->backlight_device = NULL;
840}
841
842static void eeepc_wmi_notify(u32 value, void *context)
843{
844 struct eeepc_wmi *eeepc = context;
845 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
846 union acpi_object *obj;
847 acpi_status status;
848 int code;
849 int orig_code;
850
851 status = wmi_get_event_data(value, &response);
852 if (status != AE_OK) {
853 pr_err("bad event status 0x%x\n", status);
854 return;
855 }
856
857 obj = (union acpi_object *)response.pointer;
858
859 if (obj && obj->type == ACPI_TYPE_INTEGER) {
860 code = obj->integer.value;
861 orig_code = code;
862
863 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
864 code = NOTIFY_BRNUP_MIN;
865 else if (code >= NOTIFY_BRNDOWN_MIN &&
866 code <= NOTIFY_BRNDOWN_MAX)
867 code = NOTIFY_BRNDOWN_MIN;
868
869 if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
870 if (!acpi_video_backlight_support())
871 eeepc_wmi_backlight_notify(eeepc, orig_code);
872 }
873
874 if (!sparse_keymap_report_event(eeepc->inputdev,
875 code, 1, true))
876 pr_info("Unknown key %x pressed\n", code);
877 }
878
879 kfree(obj);
880}
881
Dmitry Torokhov67fa38e2010-11-03 11:14:01 -0700882static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
883 const char *buf, size_t count)
Chris Bagwell7f80d732010-10-11 18:47:18 -0500884{
885 int value;
886 struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
887 acpi_status status;
888
889 if (!count || sscanf(buf, "%i", &value) != 1)
890 return -EINVAL;
891 if (value < 0 || value > 2)
892 return -EINVAL;
893
894 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
895 1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
896
897 if (ACPI_FAILURE(status))
898 return -EIO;
899 else
900 return count;
901}
902
903static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
904
Corentin Chary4e37b422010-11-29 08:14:08 +0100905static struct attribute *platform_attributes[] = {
906 &dev_attr_cpufv.attr,
907 NULL
908};
909
910static struct attribute_group platform_attribute_group = {
911 .attrs = platform_attributes
912};
913
Chris Bagwell7f80d732010-10-11 18:47:18 -0500914static void eeepc_wmi_sysfs_exit(struct platform_device *device)
915{
Corentin Chary4e37b422010-11-29 08:14:08 +0100916 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Chris Bagwell7f80d732010-10-11 18:47:18 -0500917}
918
919static int eeepc_wmi_sysfs_init(struct platform_device *device)
920{
Corentin Chary4e37b422010-11-29 08:14:08 +0100921 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
Chris Bagwell7f80d732010-10-11 18:47:18 -0500922}
923
Corentin Chary27c136c2010-11-29 08:14:05 +0100924/*
925 * Platform device
926 */
927static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc)
928{
Corentin Charya04ce292011-02-06 13:28:33 +0100929 return eeepc_wmi_sysfs_init(eeepc->platform_device);
Corentin Chary27c136c2010-11-29 08:14:05 +0100930}
931
932static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc)
933{
934 eeepc_wmi_sysfs_exit(eeepc->platform_device);
Corentin Chary27c136c2010-11-29 08:14:05 +0100935}
936
937/*
Corentin Chary8c1b2d82010-11-29 08:14:09 +0100938 * debugfs
939 */
940struct eeepc_wmi_debugfs_node {
941 struct eeepc_wmi *eeepc;
942 char *name;
943 int (*show)(struct seq_file *m, void *data);
944};
945
946static int show_dsts(struct seq_file *m, void *data)
947{
948 struct eeepc_wmi *eeepc = m->private;
949 acpi_status status;
950 u32 retval = -1;
951
952 status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval);
953
954 if (ACPI_FAILURE(status))
955 return -EIO;
956
957 seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval);
958
959 return 0;
960}
961
962static int show_devs(struct seq_file *m, void *data)
963{
964 struct eeepc_wmi *eeepc = m->private;
965 acpi_status status;
966 u32 retval = -1;
967
968 status = eeepc_wmi_set_devstate(eeepc->debug.dev_id,
969 eeepc->debug.ctrl_param, &retval);
970 if (ACPI_FAILURE(status))
971 return -EIO;
972
973 seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id,
974 eeepc->debug.ctrl_param, retval);
975
976 return 0;
977}
978
979static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = {
980 { NULL, "devs", show_devs },
981 { NULL, "dsts", show_dsts },
982};
983
984static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file)
985{
986 struct eeepc_wmi_debugfs_node *node = inode->i_private;
987
988 return single_open(file, node->show, node->eeepc);
989}
990
991static const struct file_operations eeepc_wmi_debugfs_io_ops = {
992 .owner = THIS_MODULE,
993 .open = eeepc_wmi_debugfs_open,
994 .read = seq_read,
995 .llseek = seq_lseek,
996 .release = single_release,
997};
998
999static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc)
1000{
1001 debugfs_remove_recursive(eeepc->debug.root);
1002}
1003
1004static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc)
1005{
1006 struct dentry *dent;
1007 int i;
1008
1009 eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL);
1010 if (!eeepc->debug.root) {
1011 pr_err("failed to create debugfs directory");
1012 goto error_debugfs;
1013 }
1014
1015 dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR,
1016 eeepc->debug.root, &eeepc->debug.dev_id);
1017 if (!dent)
1018 goto error_debugfs;
1019
1020 dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR,
1021 eeepc->debug.root, &eeepc->debug.ctrl_param);
1022 if (!dent)
1023 goto error_debugfs;
1024
1025 for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) {
1026 struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i];
1027
1028 node->eeepc = eeepc;
1029 dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
1030 eeepc->debug.root, node,
1031 &eeepc_wmi_debugfs_io_ops);
1032 if (!dent) {
1033 pr_err("failed to create debug file: %s\n", node->name);
1034 goto error_debugfs;
1035 }
1036 }
1037
1038 return 0;
1039
1040error_debugfs:
1041 eeepc_wmi_debugfs_exit(eeepc);
1042 return -ENOMEM;
1043}
1044
1045/*
Corentin Chary27c136c2010-11-29 08:14:05 +01001046 * WMI Driver
1047 */
Corentin Charyafa7c882011-02-06 13:28:28 +01001048static void eeepc_dmi_check(struct eeepc_wmi *eeepc)
1049{
1050 const char *model;
1051
1052 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1053 if (!model)
1054 return;
1055
1056 /*
1057 * Whitelist for wlan hotplug
1058 *
1059 * Eeepc 1000H needs the current hotplug code to handle
1060 * Fn+F2 correctly. We may add other Eeepc here later, but
1061 * it seems that most of the laptops supported by eeepc-wmi
1062 * don't need to be on this list
1063 */
1064 if (strcmp(model, "1000H") == 0) {
1065 eeepc->hotplug_wireless = true;
1066 pr_info("wlan hotplug enabled\n");
1067 }
1068}
1069
Corentin Charya04ce292011-02-06 13:28:33 +01001070static int __init eeepc_wmi_add(struct platform_device *pdev)
Yong Wangee027e42010-03-21 10:26:34 +08001071{
Yong Wang45f2c692010-04-11 09:27:19 +08001072 struct eeepc_wmi *eeepc;
Yong Wangee027e42010-03-21 10:26:34 +08001073 acpi_status status;
Corentin Chary27c136c2010-11-29 08:14:05 +01001074 int err;
Yong Wangee027e42010-03-21 10:26:34 +08001075
Corentin Chary27c136c2010-11-29 08:14:05 +01001076 eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL);
1077 if (!eeepc)
Corentin Charya04ce292011-02-06 13:28:33 +01001078 return -ENOMEM;
1079
1080 eeepc->platform_device = pdev;
1081 platform_set_drvdata(eeepc->platform_device, eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +01001082
Corentin Charyafa7c882011-02-06 13:28:28 +01001083 eeepc->hotplug_wireless = hotplug_wireless;
1084 eeepc_dmi_check(eeepc);
1085
Corentin Chary27c136c2010-11-29 08:14:05 +01001086 err = eeepc_wmi_platform_init(eeepc);
1087 if (err)
1088 goto fail_platform;
Yong Wang45f2c692010-04-11 09:27:19 +08001089
1090 err = eeepc_wmi_input_init(eeepc);
1091 if (err)
Corentin Chary27c136c2010-11-29 08:14:05 +01001092 goto fail_input;
Yong Wang3d7b1652010-04-11 09:27:54 +08001093
Corentin Chary084fca62010-11-29 08:14:06 +01001094 err = eeepc_wmi_led_init(eeepc);
1095 if (err)
1096 goto fail_leds;
1097
Corentin Charyba48fdb2010-11-29 08:14:07 +01001098 err = eeepc_wmi_rfkill_init(eeepc);
1099 if (err)
1100 goto fail_rfkill;
1101
Yong Wang3d7b1652010-04-11 09:27:54 +08001102 if (!acpi_video_backlight_support()) {
1103 err = eeepc_wmi_backlight_init(eeepc);
1104 if (err)
Corentin Chary27c136c2010-11-29 08:14:05 +01001105 goto fail_backlight;
Yong Wang3d7b1652010-04-11 09:27:54 +08001106 } else
1107 pr_info("Backlight controlled by ACPI video driver\n");
Yong Wang45f2c692010-04-11 09:27:19 +08001108
1109 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
Corentin Chary27c136c2010-11-29 08:14:05 +01001110 eeepc_wmi_notify, eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +08001111 if (ACPI_FAILURE(status)) {
1112 pr_err("Unable to register notify handler - %d\n",
1113 status);
1114 err = -ENODEV;
Corentin Chary27c136c2010-11-29 08:14:05 +01001115 goto fail_wmi_handler;
Yong Wang45f2c692010-04-11 09:27:19 +08001116 }
1117
Corentin Chary8c1b2d82010-11-29 08:14:09 +01001118 err = eeepc_wmi_debugfs_init(eeepc);
1119 if (err)
1120 goto fail_debugfs;
1121
Corentin Charya04ce292011-02-06 13:28:33 +01001122 return 0;
Yong Wang45f2c692010-04-11 09:27:19 +08001123
Corentin Chary8c1b2d82010-11-29 08:14:09 +01001124fail_debugfs:
1125 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
Corentin Chary27c136c2010-11-29 08:14:05 +01001126fail_wmi_handler:
Yong Wang3d7b1652010-04-11 09:27:54 +08001127 eeepc_wmi_backlight_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +01001128fail_backlight:
Corentin Charyba48fdb2010-11-29 08:14:07 +01001129 eeepc_wmi_rfkill_exit(eeepc);
1130fail_rfkill:
Corentin Chary084fca62010-11-29 08:14:06 +01001131 eeepc_wmi_led_exit(eeepc);
1132fail_leds:
Yong Wang45f2c692010-04-11 09:27:19 +08001133 eeepc_wmi_input_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +01001134fail_input:
1135 eeepc_wmi_platform_exit(eeepc);
1136fail_platform:
1137 kfree(eeepc);
Corentin Charya04ce292011-02-06 13:28:33 +01001138 return err;
Yong Wang45f2c692010-04-11 09:27:19 +08001139}
1140
Corentin Charya04ce292011-02-06 13:28:33 +01001141static int __exit eeepc_wmi_remove(struct platform_device *device)
Yong Wang45f2c692010-04-11 09:27:19 +08001142{
1143 struct eeepc_wmi *eeepc;
1144
1145 eeepc = platform_get_drvdata(device);
1146 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
Yong Wang3d7b1652010-04-11 09:27:54 +08001147 eeepc_wmi_backlight_exit(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +08001148 eeepc_wmi_input_exit(eeepc);
Corentin Chary084fca62010-11-29 08:14:06 +01001149 eeepc_wmi_led_exit(eeepc);
Corentin Charyba48fdb2010-11-29 08:14:07 +01001150 eeepc_wmi_rfkill_exit(eeepc);
Corentin Chary8c1b2d82010-11-29 08:14:09 +01001151 eeepc_wmi_debugfs_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +01001152 eeepc_wmi_platform_exit(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +08001153
Corentin Chary27c136c2010-11-29 08:14:05 +01001154 kfree(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +08001155 return 0;
1156}
1157
Corentin Chary0773d7f2011-02-06 13:28:32 +01001158/*
1159 * Platform driver - hibernate/resume callbacks
1160 */
1161static int eeepc_hotk_thaw(struct device *device)
1162{
1163 struct eeepc_wmi *eeepc = dev_get_drvdata(device);
1164
1165 if (eeepc->wlan_rfkill) {
1166 bool wlan;
1167
1168 /*
1169 * Work around bios bug - acpi _PTS turns off the wireless led
1170 * during suspend. Normally it restores it on resume, but
1171 * we should kick it ourselves in case hibernation is aborted.
1172 */
1173 wlan = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
1174 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_WLAN, wlan, NULL);
1175 }
1176
1177 return 0;
1178}
1179
1180static int eeepc_hotk_restore(struct device *device)
1181{
1182 struct eeepc_wmi *eeepc = dev_get_drvdata(device);
1183 int bl;
1184
1185 /* Refresh both wlan rfkill state and pci hotplug */
1186 if (eeepc->wlan_rfkill)
1187 eeepc_rfkill_hotplug(eeepc);
1188
1189 if (eeepc->bluetooth_rfkill) {
1190 bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BLUETOOTH);
1191 rfkill_set_sw_state(eeepc->bluetooth_rfkill, bl);
1192}
1193 if (eeepc->wwan3g_rfkill) {
1194 bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WWAN3G);
1195 rfkill_set_sw_state(eeepc->wwan3g_rfkill, bl);
1196 }
1197
1198 return 0;
1199}
1200
1201static const struct dev_pm_ops eeepc_pm_ops = {
1202 .thaw = eeepc_hotk_thaw,
1203 .restore = eeepc_hotk_restore,
1204};
1205
Yong Wang45f2c692010-04-11 09:27:19 +08001206static struct platform_driver platform_driver = {
Corentin Charya04ce292011-02-06 13:28:33 +01001207 .remove = __exit_p(eeepc_wmi_remove),
Yong Wang45f2c692010-04-11 09:27:19 +08001208 .driver = {
1209 .name = EEEPC_WMI_FILE,
1210 .owner = THIS_MODULE,
Corentin Chary0773d7f2011-02-06 13:28:32 +01001211 .pm = &eeepc_pm_ops,
Yong Wang45f2c692010-04-11 09:27:19 +08001212 },
Yong Wang45f2c692010-04-11 09:27:19 +08001213};
1214
Corentin Charyd358cb52010-11-29 08:14:14 +01001215static acpi_status __init eeepc_wmi_parse_device(acpi_handle handle, u32 level,
1216 void *context, void **retval)
1217{
1218 pr_warning("Found legacy ATKD device (%s)", EEEPC_ACPI_HID);
1219 *(bool *)context = true;
1220 return AE_CTRL_TERMINATE;
1221}
1222
1223static int __init eeepc_wmi_check_atkd(void)
1224{
1225 acpi_status status;
1226 bool found = false;
1227
1228 status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
1229 &found, NULL);
1230
1231 if (ACPI_FAILURE(status) || !found)
1232 return 0;
1233 return -1;
1234}
1235
Corentin Charya04ce292011-02-06 13:28:33 +01001236static int __init eeepc_wmi_probe(struct platform_device *pdev)
Yong Wang45f2c692010-04-11 09:27:19 +08001237{
Yong Wang3d7b1652010-04-11 09:27:54 +08001238 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) ||
1239 !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) {
Yong Wang81248882010-04-11 09:26:33 +08001240 pr_warning("No known WMI GUID found\n");
Yong Wangee027e42010-03-21 10:26:34 +08001241 return -ENODEV;
1242 }
1243
Corentin Charyd358cb52010-11-29 08:14:14 +01001244 if (eeepc_wmi_check_atkd()) {
1245 pr_warning("WMI device present, but legacy ATKD device is also "
1246 "present and enabled.");
1247 pr_warning("You probably booted with acpi_osi=\"Linux\" or "
1248 "acpi_osi=\"!Windows 2009\"");
1249 pr_warning("Can't load eeepc-wmi, use default acpi_osi "
1250 "(preferred) or eeepc-laptop");
1251 return -ENODEV;
1252 }
1253
Corentin Charya04ce292011-02-06 13:28:33 +01001254 return eeepc_wmi_add(pdev);
1255}
Yong Wangee027e42010-03-21 10:26:34 +08001256
Corentin Charya04ce292011-02-06 13:28:33 +01001257static struct platform_device *platform_device;
Yong Wangee027e42010-03-21 10:26:34 +08001258
Corentin Charya04ce292011-02-06 13:28:33 +01001259static int __init eeepc_wmi_init(void)
1260{
1261 platform_device = platform_create_bundle(&platform_driver,
1262 eeepc_wmi_probe,
1263 NULL, 0, NULL, 0);
1264 if (IS_ERR(platform_device))
1265 return PTR_ERR(platform_device);
Yong Wangee027e42010-03-21 10:26:34 +08001266 return 0;
1267}
1268
1269static void __exit eeepc_wmi_exit(void)
1270{
Corentin Charya04ce292011-02-06 13:28:33 +01001271 platform_device_unregister(platform_device);
Yong Wang45f2c692010-04-11 09:27:19 +08001272 platform_driver_unregister(&platform_driver);
Yong Wangee027e42010-03-21 10:26:34 +08001273}
1274
1275module_init(eeepc_wmi_init);
1276module_exit(eeepc_wmi_exit);