Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 1 | /* |
| 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 Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 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 | |
| 29 | MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>"); |
| 30 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
| 33 | |
| 34 | static int toshiba_bt_rfkill_add(struct acpi_device *device); |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 35 | static int toshiba_bt_rfkill_remove(struct acpi_device *device); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 36 | static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 37 | |
| 38 | static const struct acpi_device_id bt_device_ids[] = { |
| 39 | { "TOS6205", 0}, |
| 40 | { "", 0}, |
| 41 | }; |
| 42 | MODULE_DEVICE_TABLE(acpi, bt_device_ids); |
| 43 | |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 44 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | d69239a | 2012-06-27 23:27:48 +0200 | [diff] [blame] | 45 | static int toshiba_bt_resume(struct device *dev); |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 46 | #endif |
Rafael J. Wysocki | d69239a | 2012-06-27 23:27:48 +0200 | [diff] [blame] | 47 | static SIMPLE_DEV_PM_OPS(toshiba_bt_pm, NULL, toshiba_bt_resume); |
| 48 | |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 49 | static 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, |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 57 | }, |
| 58 | .owner = THIS_MODULE, |
Rafael J. Wysocki | d69239a | 2012-06-27 23:27:48 +0200 | [diff] [blame] | 59 | .drv.pm = &toshiba_bt_pm, |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | |
| 63 | static int toshiba_bluetooth_enable(acpi_handle handle) |
| 64 | { |
| 65 | acpi_status res1, res2; |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 66 | u64 result; |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Query ACPI to verify RFKill switch is set to 'on'. |
| 70 | * If not, we return silently, no need to report it as |
| 71 | * an error. |
| 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 | |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 79 | pr_info("Re-enabling Toshiba Bluetooth\n"); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 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 | |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 85 | pr_warn("Failed to re-enable Toshiba Bluetooth\n"); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 86 | |
| 87 | return -ENODEV; |
| 88 | } |
| 89 | |
| 90 | static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event) |
| 91 | { |
| 92 | toshiba_bluetooth_enable(device->handle); |
| 93 | } |
| 94 | |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | d69239a | 2012-06-27 23:27:48 +0200 | [diff] [blame] | 96 | static int toshiba_bt_resume(struct device *dev) |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 97 | { |
Rafael J. Wysocki | d69239a | 2012-06-27 23:27:48 +0200 | [diff] [blame] | 98 | return toshiba_bluetooth_enable(to_acpi_device(dev)->handle); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 99 | } |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 100 | #endif |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 101 | |
| 102 | static int toshiba_bt_rfkill_add(struct acpi_device *device) |
| 103 | { |
| 104 | acpi_status status; |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 105 | u64 bt_present; |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 106 | int result = -ENODEV; |
| 107 | |
| 108 | /* |
| 109 | * Some Toshiba laptops may have a fake TOS6205 device in |
| 110 | * their ACPI BIOS, so query the _STA method to see if there |
| 111 | * is really anything there, before trying to enable it. |
| 112 | */ |
| 113 | status = acpi_evaluate_integer(device->handle, "_STA", NULL, |
| 114 | &bt_present); |
| 115 | |
| 116 | if (!ACPI_FAILURE(status) && bt_present) { |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 117 | pr_info("Detected Toshiba ACPI Bluetooth device - " |
| 118 | "installing RFKill handler\n"); |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 119 | result = toshiba_bluetooth_enable(device->handle); |
| 120 | } |
| 121 | |
| 122 | return result; |
| 123 | } |
| 124 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 125 | static int toshiba_bt_rfkill_remove(struct acpi_device *device) |
Jes Sorensen | 42b4e9e | 2009-12-16 12:08:15 -0500 | [diff] [blame] | 126 | { |
| 127 | /* clean up */ |
| 128 | return 0; |
| 129 | } |
| 130 | |
Mika Westerberg | 01d1775 | 2012-09-07 10:31:48 +0300 | [diff] [blame] | 131 | module_acpi_driver(toshiba_bt_rfkill_driver); |