Linux Audio

Check our new training course

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