1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
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>
28
29MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>");
30MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
31MODULE_LICENSE("GPL");
32
33
34static int toshiba_bt_rfkill_add(struct acpi_device *device);
35static int toshiba_bt_rfkill_remove(struct acpi_device *device);
36static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
37
38static const struct acpi_device_id bt_device_ids[] = {
39 { "TOS6205", 0},
40 { "", 0},
41};
42MODULE_DEVICE_TABLE(acpi, bt_device_ids);
43
44#ifdef CONFIG_PM_SLEEP
45static int toshiba_bt_resume(struct device *dev);
46#endif
47static SIMPLE_DEV_PM_OPS(toshiba_bt_pm, NULL, toshiba_bt_resume);
48
49static struct acpi_driver toshiba_bt_rfkill_driver = {
50 .name = "Toshiba BT",
51 .class = "Toshiba",
52 .ids = bt_device_ids,
53 .ops = {
54 .add = toshiba_bt_rfkill_add,
55 .remove = toshiba_bt_rfkill_remove,
56 .notify = toshiba_bt_rfkill_notify,
57 },
58 .owner = THIS_MODULE,
59 .drv.pm = &toshiba_bt_pm,
60};
61
62
63static int toshiba_bluetooth_enable(acpi_handle handle)
64{
65 acpi_status res1, res2;
66 u64 result;
67
68
69
70
71
72
73 res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result);
74 if (ACPI_FAILURE(res1))
75 return res1;
76 if (!(result & 0x01))
77 return 0;
78
79 pr_info("Re-enabling Toshiba Bluetooth\n");
80 res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
81 res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL);
82 if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2))
83 return 0;
84
85 pr_warn("Failed to re-enable Toshiba Bluetooth\n");
86
87 return -ENODEV;
88}
89
90static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
91{
92 toshiba_bluetooth_enable(device->handle);
93}
94
95#ifdef CONFIG_PM_SLEEP
96static int toshiba_bt_resume(struct device *dev)
97{
98 return toshiba_bluetooth_enable(to_acpi_device(dev)->handle);
99}
100#endif
101
102static int toshiba_bt_rfkill_add(struct acpi_device *device)
103{
104 acpi_status status;
105 u64 bt_present;
106 int result = -ENODEV;
107
108
109
110
111
112
113 status = acpi_evaluate_integer(device->handle, "_STA", NULL,
114 &bt_present);
115
116 if (!ACPI_FAILURE(status) && bt_present) {
117 pr_info("Detected Toshiba ACPI Bluetooth device - "
118 "installing RFKill handler\n");
119 result = toshiba_bluetooth_enable(device->handle);
120 }
121
122 return result;
123}
124
125static int toshiba_bt_rfkill_remove(struct acpi_device *device)
126{
127
128 return 0;
129}
130
131module_acpi_driver(toshiba_bt_rfkill_driver);
132