The discovered bit in PGCCSR register indicates if the device has been
[linux-2.6/next.git] / drivers / platform / x86 / toshiba_bluetooth.c
blob5fb7186694df034f85d47fd6c3d5e8a03ac5a51b
1 /*
2 * Toshiba Bluetooth Enable Driver
4 * Copyright (C) 2009 Jes Sorensen <Jes.Sorensen@gmail.com>
6 * Thanks to Matthew Garrett for background info on ACPI innards which
7 * normal people aren't meant to understand :-)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Note the Toshiba Bluetooth RFKill switch seems to be a strange
14 * fish. It only provides a BT event when the switch is flipped to
15 * the 'on' position. When flipping it to 'off', the USB device is
16 * simply pulled away underneath us, without any BT event being
17 * delivered.
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/types.h>
26 #include <acpi/acpi_bus.h>
27 #include <acpi/acpi_drivers.h>
29 MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>");
30 MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
31 MODULE_LICENSE("GPL");
34 static int toshiba_bt_rfkill_add(struct acpi_device *device);
35 static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type);
36 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
37 static int toshiba_bt_resume(struct acpi_device *device);
39 static const struct acpi_device_id bt_device_ids[] = {
40 { "TOS6205", 0},
41 { "", 0},
43 MODULE_DEVICE_TABLE(acpi, bt_device_ids);
45 static struct acpi_driver toshiba_bt_rfkill_driver = {
46 .name = "Toshiba BT",
47 .class = "Toshiba",
48 .ids = bt_device_ids,
49 .ops = {
50 .add = toshiba_bt_rfkill_add,
51 .remove = toshiba_bt_rfkill_remove,
52 .notify = toshiba_bt_rfkill_notify,
53 .resume = toshiba_bt_resume,
55 .owner = THIS_MODULE,
59 static int toshiba_bluetooth_enable(acpi_handle handle)
61 acpi_status res1, res2;
62 u64 result;
65 * Query ACPI to verify RFKill switch is set to 'on'.
66 * If not, we return silently, no need to report it as
67 * an error.
69 res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result);
70 if (ACPI_FAILURE(res1))
71 return res1;
72 if (!(result & 0x01))
73 return 0;
75 pr_info("Re-enabling Toshiba Bluetooth\n");
76 res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
77 res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL);
78 if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2))
79 return 0;
81 pr_warn("Failed to re-enable Toshiba Bluetooth\n");
83 return -ENODEV;
86 static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
88 toshiba_bluetooth_enable(device->handle);
91 static int toshiba_bt_resume(struct acpi_device *device)
93 return toshiba_bluetooth_enable(device->handle);
96 static int toshiba_bt_rfkill_add(struct acpi_device *device)
98 acpi_status status;
99 u64 bt_present;
100 int result = -ENODEV;
103 * Some Toshiba laptops may have a fake TOS6205 device in
104 * their ACPI BIOS, so query the _STA method to see if there
105 * is really anything there, before trying to enable it.
107 status = acpi_evaluate_integer(device->handle, "_STA", NULL,
108 &bt_present);
110 if (!ACPI_FAILURE(status) && bt_present) {
111 pr_info("Detected Toshiba ACPI Bluetooth device - "
112 "installing RFKill handler\n");
113 result = toshiba_bluetooth_enable(device->handle);
116 return result;
119 static int __init toshiba_bt_rfkill_init(void)
121 int result;
123 result = acpi_bus_register_driver(&toshiba_bt_rfkill_driver);
124 if (result < 0) {
125 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
126 "Error registering driver\n"));
127 return result;
130 return 0;
133 static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type)
135 /* clean up */
136 return 0;
139 static void __exit toshiba_bt_rfkill_exit(void)
141 acpi_bus_unregister_driver(&toshiba_bt_rfkill_driver);
144 module_init(toshiba_bt_rfkill_init);
145 module_exit(toshiba_bt_rfkill_exit);