aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAzael Avalos <coproscefalo@gmail.com>2015-03-26 16:56:07 -0400
committerDarren Hart <dvhart@linux.intel.com>2015-03-26 17:15:07 -0400
commit5d3fc1d54e5a020c087002dd8590ee21c17e3182 (patch)
tree29e1ef432d822450feb13cdc5a28761f5d2cb6c4
parent18b8696b66d79024649c895d4a5b7da4f268300e (diff)
toshiba_bluetooth: Fix enabling/disabling loop on recent devices
Bug 93911 reported a broken handling of the BT device, causing the driver to get stuck in a loop enabling/disabling the device whenever the device is deactivated by the kill switch as follows: 1. The user activated the kill switch, causing the system to generate a 0x90 (status change) event and disabling the BT device. 2. The driver catches the event and re-enables the BT device. 3. The system detects the device being activated, but since the kill switch is activated, disables the BT device (again) and generates a 0x90 event (again). 4. Repeat from 2. This patch adds an extra check to verify the status of the BT device, returning silently if it is already activated. Also, checks and returns appropriate error values while evaluating the AUSB and BTPO methods. Signed-off-by: Azael Avalos <coproscefalo@gmail.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
-rw-r--r--drivers/platform/x86/toshiba_bluetooth.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/drivers/platform/x86/toshiba_bluetooth.c b/drivers/platform/x86/toshiba_bluetooth.c
index b8404c7a74cf..249800763362 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -2,6 +2,7 @@
2 * Toshiba Bluetooth Enable Driver 2 * Toshiba Bluetooth Enable Driver
3 * 3 *
4 * Copyright (C) 2009 Jes Sorensen <Jes.Sorensen@gmail.com> 4 * Copyright (C) 2009 Jes Sorensen <Jes.Sorensen@gmail.com>
5 * Copyright (C) 2015 Azael Avalos <coproscefalo@gmail.com>
5 * 6 *
6 * Thanks to Matthew Garrett for background info on ACPI innards which 7 * Thanks to Matthew Garrett for background info on ACPI innards which
7 * normal people aren't meant to understand :-) 8 * normal people aren't meant to understand :-)
@@ -25,6 +26,10 @@
25#include <linux/types.h> 26#include <linux/types.h>
26#include <linux/acpi.h> 27#include <linux/acpi.h>
27 28
29#define BT_KILLSWITCH_MASK 0x01
30#define BT_PLUGGED_MASK 0x40
31#define BT_POWER_MASK 0x80
32
28MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>"); 33MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>");
29MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver"); 34MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
30MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
@@ -97,29 +102,48 @@ static int toshiba_bluetooth_status(acpi_handle handle)
97 102
98static int toshiba_bluetooth_enable(acpi_handle handle) 103static int toshiba_bluetooth_enable(acpi_handle handle)
99{ 104{
100 acpi_status res1, res2; 105 acpi_status result;
101 u64 result; 106 bool killswitch;
107 bool powered;
108 bool plugged;
109 int status;
102 110
103 /* 111 /*
104 * Query ACPI to verify RFKill switch is set to 'on'. 112 * Query ACPI to verify RFKill switch is set to 'on'.
105 * If not, we return silently, no need to report it as 113 * If not, we return silently, no need to report it as
106 * an error. 114 * an error.
107 */ 115 */
108 res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result); 116 status = toshiba_bluetooth_status(handle);
109 if (ACPI_FAILURE(res1)) 117 if (status < 0)
110 return res1; 118 return status;
111 if (!(result & 0x01)) 119
112 return 0; 120 killswitch = (status & BT_KILLSWITCH_MASK) ? true : false;
121 powered = (status & BT_POWER_MASK) ? true : false;
122 plugged = (status & BT_PLUGGED_MASK) ? true : false;
113 123
114 pr_info("Re-enabling Toshiba Bluetooth\n"); 124 if (!killswitch)
115 res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL); 125 return 0;
116 res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL); 126 /*
117 if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2)) 127 * This check ensures to only enable the device if it is powered
128 * off or detached, as some recent devices somehow pass the killswitch
129 * test, causing a loop enabling/disabling the device, see bug 93911.
130 */
131 if (powered || plugged)
118 return 0; 132 return 0;
119 133
120 pr_warn("Failed to re-enable Toshiba Bluetooth\n"); 134 result = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
135 if (ACPI_FAILURE(result)) {
136 pr_err("Could not attach USB Bluetooth device\n");
137 return -ENXIO;
138 }
121 139
122 return -ENODEV; 140 result = acpi_evaluate_object(handle, "BTPO", NULL, NULL);
141 if (ACPI_FAILURE(result)) {
142 pr_err("Could not power ON Bluetooth device\n");
143 return -ENXIO;
144 }
145
146 return 0;
123} 147}
124 148
125static int toshiba_bluetooth_disable(acpi_handle handle) 149static int toshiba_bluetooth_disable(acpi_handle handle)