blob: 2cb1ea62b4a7f9ac7b268adadb251105be279923 [file] [log] [blame]
Jes Sorensen42b4e9e2009-12-16 12:08:15 -05001/*
2 * Toshiba Bluetooth Enable Driver
3 *
4 * Copyright (C) 2009 Jes Sorensen <Jes.Sorensen@gmail.com>
5 *
6 * Thanks to Matthew Garrett for background info on ACPI innards which
7 * normal people aren't meant to understand :-)
8 *
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.
12 *
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.
18 */
19
Joe Perches7e334602011-03-29 15:21:52 -070020#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050022#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/types.h>
Lv Zheng8b484632013-12-03 08:49:16 +080026#include <linux/acpi.h>
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050027
28MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>");
29MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
30MODULE_LICENSE("GPL");
31
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050032static int toshiba_bt_rfkill_add(struct acpi_device *device);
Rafael J. Wysocki51fac832013-01-24 00:24:48 +010033static int toshiba_bt_rfkill_remove(struct acpi_device *device);
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050034static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050035
36static const struct acpi_device_id bt_device_ids[] = {
37 { "TOS6205", 0},
38 { "", 0},
39};
40MODULE_DEVICE_TABLE(acpi, bt_device_ids);
41
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +020042#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockid69239a2012-06-27 23:27:48 +020043static int toshiba_bt_resume(struct device *dev);
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +020044#endif
Rafael J. Wysockid69239a2012-06-27 23:27:48 +020045static SIMPLE_DEV_PM_OPS(toshiba_bt_pm, NULL, toshiba_bt_resume);
46
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050047static struct acpi_driver toshiba_bt_rfkill_driver = {
48 .name = "Toshiba BT",
49 .class = "Toshiba",
50 .ids = bt_device_ids,
51 .ops = {
52 .add = toshiba_bt_rfkill_add,
53 .remove = toshiba_bt_rfkill_remove,
54 .notify = toshiba_bt_rfkill_notify,
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050055 },
56 .owner = THIS_MODULE,
Rafael J. Wysockid69239a2012-06-27 23:27:48 +020057 .drv.pm = &toshiba_bt_pm,
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050058};
59
60
61static int toshiba_bluetooth_enable(acpi_handle handle)
62{
63 acpi_status res1, res2;
Lin Ming439913f2010-01-28 10:53:19 +080064 u64 result;
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050065
66 /*
67 * Query ACPI to verify RFKill switch is set to 'on'.
68 * If not, we return silently, no need to report it as
69 * an error.
70 */
71 res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result);
72 if (ACPI_FAILURE(res1))
73 return res1;
74 if (!(result & 0x01))
75 return 0;
76
Joe Perches7e334602011-03-29 15:21:52 -070077 pr_info("Re-enabling Toshiba Bluetooth\n");
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050078 res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
79 res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL);
80 if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2))
81 return 0;
82
Joe Perches7e334602011-03-29 15:21:52 -070083 pr_warn("Failed to re-enable Toshiba Bluetooth\n");
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050084
85 return -ENODEV;
86}
87
88static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
89{
90 toshiba_bluetooth_enable(device->handle);
91}
92
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +020093#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockid69239a2012-06-27 23:27:48 +020094static int toshiba_bt_resume(struct device *dev)
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050095{
Rafael J. Wysockid69239a2012-06-27 23:27:48 +020096 return toshiba_bluetooth_enable(to_acpi_device(dev)->handle);
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050097}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +020098#endif
Jes Sorensen42b4e9e2009-12-16 12:08:15 -050099
100static int toshiba_bt_rfkill_add(struct acpi_device *device)
101{
102 acpi_status status;
Lin Ming439913f2010-01-28 10:53:19 +0800103 u64 bt_present;
Jes Sorensen42b4e9e2009-12-16 12:08:15 -0500104 int result = -ENODEV;
105
106 /*
107 * Some Toshiba laptops may have a fake TOS6205 device in
108 * their ACPI BIOS, so query the _STA method to see if there
109 * is really anything there, before trying to enable it.
110 */
111 status = acpi_evaluate_integer(device->handle, "_STA", NULL,
112 &bt_present);
113
114 if (!ACPI_FAILURE(status) && bt_present) {
Joe Perches7e334602011-03-29 15:21:52 -0700115 pr_info("Detected Toshiba ACPI Bluetooth device - "
116 "installing RFKill handler\n");
Jes Sorensen42b4e9e2009-12-16 12:08:15 -0500117 result = toshiba_bluetooth_enable(device->handle);
118 }
119
120 return result;
121}
122
Rafael J. Wysocki51fac832013-01-24 00:24:48 +0100123static int toshiba_bt_rfkill_remove(struct acpi_device *device)
Jes Sorensen42b4e9e2009-12-16 12:08:15 -0500124{
125 /* clean up */
126 return 0;
127}
128
Mika Westerberg01d17752012-09-07 10:31:48 +0300129module_acpi_driver(toshiba_bt_rfkill_driver);