142b4e9eeSJes Sorensen /* 242b4e9eeSJes Sorensen * Toshiba Bluetooth Enable Driver 342b4e9eeSJes Sorensen * 442b4e9eeSJes Sorensen * Copyright (C) 2009 Jes Sorensen <Jes.Sorensen@gmail.com> 542b4e9eeSJes Sorensen * 642b4e9eeSJes Sorensen * Thanks to Matthew Garrett for background info on ACPI innards which 742b4e9eeSJes Sorensen * normal people aren't meant to understand :-) 842b4e9eeSJes Sorensen * 942b4e9eeSJes Sorensen * This program is free software; you can redistribute it and/or modify 1042b4e9eeSJes Sorensen * it under the terms of the GNU General Public License version 2 as 1142b4e9eeSJes Sorensen * published by the Free Software Foundation. 1242b4e9eeSJes Sorensen * 1342b4e9eeSJes Sorensen * Note the Toshiba Bluetooth RFKill switch seems to be a strange 1442b4e9eeSJes Sorensen * fish. It only provides a BT event when the switch is flipped to 1542b4e9eeSJes Sorensen * the 'on' position. When flipping it to 'off', the USB device is 1642b4e9eeSJes Sorensen * simply pulled away underneath us, without any BT event being 1742b4e9eeSJes Sorensen * delivered. 1842b4e9eeSJes Sorensen */ 1942b4e9eeSJes Sorensen 2042b4e9eeSJes Sorensen #include <linux/kernel.h> 2142b4e9eeSJes Sorensen #include <linux/module.h> 2242b4e9eeSJes Sorensen #include <linux/init.h> 2342b4e9eeSJes Sorensen #include <linux/types.h> 2442b4e9eeSJes Sorensen #include <acpi/acpi_bus.h> 2542b4e9eeSJes Sorensen #include <acpi/acpi_drivers.h> 2642b4e9eeSJes Sorensen 2742b4e9eeSJes Sorensen MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>"); 2842b4e9eeSJes Sorensen MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver"); 2942b4e9eeSJes Sorensen MODULE_LICENSE("GPL"); 3042b4e9eeSJes Sorensen 3142b4e9eeSJes Sorensen 3242b4e9eeSJes Sorensen static int toshiba_bt_rfkill_add(struct acpi_device *device); 3342b4e9eeSJes Sorensen static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type); 3442b4e9eeSJes Sorensen static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event); 3542b4e9eeSJes Sorensen static int toshiba_bt_resume(struct acpi_device *device); 3642b4e9eeSJes Sorensen 3742b4e9eeSJes Sorensen static const struct acpi_device_id bt_device_ids[] = { 3842b4e9eeSJes Sorensen { "TOS6205", 0}, 3942b4e9eeSJes Sorensen { "", 0}, 4042b4e9eeSJes Sorensen }; 4142b4e9eeSJes Sorensen MODULE_DEVICE_TABLE(acpi, bt_device_ids); 4242b4e9eeSJes Sorensen 4342b4e9eeSJes Sorensen static struct acpi_driver toshiba_bt_rfkill_driver = { 4442b4e9eeSJes Sorensen .name = "Toshiba BT", 4542b4e9eeSJes Sorensen .class = "Toshiba", 4642b4e9eeSJes Sorensen .ids = bt_device_ids, 4742b4e9eeSJes Sorensen .ops = { 4842b4e9eeSJes Sorensen .add = toshiba_bt_rfkill_add, 4942b4e9eeSJes Sorensen .remove = toshiba_bt_rfkill_remove, 5042b4e9eeSJes Sorensen .notify = toshiba_bt_rfkill_notify, 5142b4e9eeSJes Sorensen .resume = toshiba_bt_resume, 5242b4e9eeSJes Sorensen }, 5342b4e9eeSJes Sorensen .owner = THIS_MODULE, 5442b4e9eeSJes Sorensen }; 5542b4e9eeSJes Sorensen 5642b4e9eeSJes Sorensen 5742b4e9eeSJes Sorensen static int toshiba_bluetooth_enable(acpi_handle handle) 5842b4e9eeSJes Sorensen { 5942b4e9eeSJes Sorensen acpi_status res1, res2; 6042b4e9eeSJes Sorensen acpi_integer result; 6142b4e9eeSJes Sorensen 6242b4e9eeSJes Sorensen /* 6342b4e9eeSJes Sorensen * Query ACPI to verify RFKill switch is set to 'on'. 6442b4e9eeSJes Sorensen * If not, we return silently, no need to report it as 6542b4e9eeSJes Sorensen * an error. 6642b4e9eeSJes Sorensen */ 6742b4e9eeSJes Sorensen res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result); 6842b4e9eeSJes Sorensen if (ACPI_FAILURE(res1)) 6942b4e9eeSJes Sorensen return res1; 7042b4e9eeSJes Sorensen if (!(result & 0x01)) 7142b4e9eeSJes Sorensen return 0; 7242b4e9eeSJes Sorensen 7342b4e9eeSJes Sorensen printk(KERN_INFO "toshiba_bluetooth: Re-enabling Toshiba Bluetooth\n"); 7442b4e9eeSJes Sorensen res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL); 7542b4e9eeSJes Sorensen res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL); 7642b4e9eeSJes Sorensen if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2)) 7742b4e9eeSJes Sorensen return 0; 7842b4e9eeSJes Sorensen 7942b4e9eeSJes Sorensen printk(KERN_WARNING "toshiba_bluetooth: Failed to re-enable " 8042b4e9eeSJes Sorensen "Toshiba Bluetooth\n"); 8142b4e9eeSJes Sorensen 8242b4e9eeSJes Sorensen return -ENODEV; 8342b4e9eeSJes Sorensen } 8442b4e9eeSJes Sorensen 8542b4e9eeSJes Sorensen static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event) 8642b4e9eeSJes Sorensen { 8742b4e9eeSJes Sorensen toshiba_bluetooth_enable(device->handle); 8842b4e9eeSJes Sorensen } 8942b4e9eeSJes Sorensen 9042b4e9eeSJes Sorensen static int toshiba_bt_resume(struct acpi_device *device) 9142b4e9eeSJes Sorensen { 9242b4e9eeSJes Sorensen return toshiba_bluetooth_enable(device->handle); 9342b4e9eeSJes Sorensen } 9442b4e9eeSJes Sorensen 9542b4e9eeSJes Sorensen static int toshiba_bt_rfkill_add(struct acpi_device *device) 9642b4e9eeSJes Sorensen { 9742b4e9eeSJes Sorensen acpi_status status; 9842b4e9eeSJes Sorensen acpi_integer bt_present; 9942b4e9eeSJes Sorensen int result = -ENODEV; 10042b4e9eeSJes Sorensen 10142b4e9eeSJes Sorensen /* 10242b4e9eeSJes Sorensen * Some Toshiba laptops may have a fake TOS6205 device in 10342b4e9eeSJes Sorensen * their ACPI BIOS, so query the _STA method to see if there 10442b4e9eeSJes Sorensen * is really anything there, before trying to enable it. 10542b4e9eeSJes Sorensen */ 10642b4e9eeSJes Sorensen status = acpi_evaluate_integer(device->handle, "_STA", NULL, 10742b4e9eeSJes Sorensen &bt_present); 10842b4e9eeSJes Sorensen 10942b4e9eeSJes Sorensen if (!ACPI_FAILURE(status) && bt_present) { 11042b4e9eeSJes Sorensen printk(KERN_INFO "Detected Toshiba ACPI Bluetooth device - " 11142b4e9eeSJes Sorensen "installing RFKill handler\n"); 11242b4e9eeSJes Sorensen result = toshiba_bluetooth_enable(device->handle); 11342b4e9eeSJes Sorensen } 11442b4e9eeSJes Sorensen 11542b4e9eeSJes Sorensen return result; 11642b4e9eeSJes Sorensen } 11742b4e9eeSJes Sorensen 11842b4e9eeSJes Sorensen static int __init toshiba_bt_rfkill_init(void) 11942b4e9eeSJes Sorensen { 12042b4e9eeSJes Sorensen int result; 12142b4e9eeSJes Sorensen 12242b4e9eeSJes Sorensen result = acpi_bus_register_driver(&toshiba_bt_rfkill_driver); 12342b4e9eeSJes Sorensen if (result < 0) { 12442b4e9eeSJes Sorensen ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 12542b4e9eeSJes Sorensen "Error registering driver\n")); 12642b4e9eeSJes Sorensen return result; 12742b4e9eeSJes Sorensen } 12842b4e9eeSJes Sorensen 12942b4e9eeSJes Sorensen return 0; 13042b4e9eeSJes Sorensen } 13142b4e9eeSJes Sorensen 13242b4e9eeSJes Sorensen static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type) 13342b4e9eeSJes Sorensen { 13442b4e9eeSJes Sorensen /* clean up */ 13542b4e9eeSJes Sorensen return 0; 13642b4e9eeSJes Sorensen } 13742b4e9eeSJes Sorensen 13842b4e9eeSJes Sorensen static void __exit toshiba_bt_rfkill_exit(void) 13942b4e9eeSJes Sorensen { 14042b4e9eeSJes Sorensen acpi_bus_unregister_driver(&toshiba_bt_rfkill_driver); 14142b4e9eeSJes Sorensen } 14242b4e9eeSJes Sorensen 14342b4e9eeSJes Sorensen module_init(toshiba_bt_rfkill_init); 14442b4e9eeSJes Sorensen module_exit(toshiba_bt_rfkill_exit); 145