toshiba_bluetooth.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/types.h>
  24. #include <acpi/acpi_bus.h>
  25. #include <acpi/acpi_drivers.h>
  26. MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@gmail.com>");
  27. MODULE_DESCRIPTION("Toshiba Laptop ACPI Bluetooth Enable Driver");
  28. MODULE_LICENSE("GPL");
  29. static int toshiba_bt_rfkill_add(struct acpi_device *device);
  30. static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type);
  31. static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
  32. static const struct acpi_device_id bt_device_ids[] = {
  33. { "TOS6205", 0},
  34. { "", 0},
  35. };
  36. MODULE_DEVICE_TABLE(acpi, bt_device_ids);
  37. static int toshiba_bt_resume(struct device *dev);
  38. static SIMPLE_DEV_PM_OPS(toshiba_bt_pm, NULL, toshiba_bt_resume);
  39. static struct acpi_driver toshiba_bt_rfkill_driver = {
  40. .name = "Toshiba BT",
  41. .class = "Toshiba",
  42. .ids = bt_device_ids,
  43. .ops = {
  44. .add = toshiba_bt_rfkill_add,
  45. .remove = toshiba_bt_rfkill_remove,
  46. .notify = toshiba_bt_rfkill_notify,
  47. },
  48. .owner = THIS_MODULE,
  49. .drv.pm = &toshiba_bt_pm,
  50. };
  51. static int toshiba_bluetooth_enable(acpi_handle handle)
  52. {
  53. acpi_status res1, res2;
  54. u64 result;
  55. /*
  56. * Query ACPI to verify RFKill switch is set to 'on'.
  57. * If not, we return silently, no need to report it as
  58. * an error.
  59. */
  60. res1 = acpi_evaluate_integer(handle, "BTST", NULL, &result);
  61. if (ACPI_FAILURE(res1))
  62. return res1;
  63. if (!(result & 0x01))
  64. return 0;
  65. pr_info("Re-enabling Toshiba Bluetooth\n");
  66. res1 = acpi_evaluate_object(handle, "AUSB", NULL, NULL);
  67. res2 = acpi_evaluate_object(handle, "BTPO", NULL, NULL);
  68. if (!ACPI_FAILURE(res1) || !ACPI_FAILURE(res2))
  69. return 0;
  70. pr_warn("Failed to re-enable Toshiba Bluetooth\n");
  71. return -ENODEV;
  72. }
  73. static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
  74. {
  75. toshiba_bluetooth_enable(device->handle);
  76. }
  77. static int toshiba_bt_resume(struct device *dev)
  78. {
  79. return toshiba_bluetooth_enable(to_acpi_device(dev)->handle);
  80. }
  81. static int toshiba_bt_rfkill_add(struct acpi_device *device)
  82. {
  83. acpi_status status;
  84. u64 bt_present;
  85. int result = -ENODEV;
  86. /*
  87. * Some Toshiba laptops may have a fake TOS6205 device in
  88. * their ACPI BIOS, so query the _STA method to see if there
  89. * is really anything there, before trying to enable it.
  90. */
  91. status = acpi_evaluate_integer(device->handle, "_STA", NULL,
  92. &bt_present);
  93. if (!ACPI_FAILURE(status) && bt_present) {
  94. pr_info("Detected Toshiba ACPI Bluetooth device - "
  95. "installing RFKill handler\n");
  96. result = toshiba_bluetooth_enable(device->handle);
  97. }
  98. return result;
  99. }
  100. static int __init toshiba_bt_rfkill_init(void)
  101. {
  102. int result;
  103. result = acpi_bus_register_driver(&toshiba_bt_rfkill_driver);
  104. if (result < 0) {
  105. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  106. "Error registering driver\n"));
  107. return result;
  108. }
  109. return 0;
  110. }
  111. static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type)
  112. {
  113. /* clean up */
  114. return 0;
  115. }
  116. static void __exit toshiba_bt_rfkill_exit(void)
  117. {
  118. acpi_bus_unregister_driver(&toshiba_bt_rfkill_driver);
  119. }
  120. module_init(toshiba_bt_rfkill_init);
  121. module_exit(toshiba_bt_rfkill_exit);