2005-04-16 18:20:36 -04:00
|
|
|
/* Bluetooth HCI driver model support. */
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
2006-07-03 04:02:37 -04:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
#include <net/bluetooth/hci_core.h>
|
|
|
|
|
|
|
|
#ifndef CONFIG_BT_HCI_CORE_DEBUG
|
|
|
|
#undef BT_DBG
|
|
|
|
#define BT_DBG(D...)
|
|
|
|
#endif
|
2008-01-30 00:14:08 -05:00
|
|
|
static struct workqueue_struct *btaddconn;
|
|
|
|
static struct workqueue_struct *btdelconn;
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2006-07-06 06:34:41 -04:00
|
|
|
static inline char *typetostr(int type)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-07-06 06:34:41 -04:00
|
|
|
switch (type) {
|
2006-07-08 07:57:15 -04:00
|
|
|
case HCI_VIRTUAL:
|
2006-07-06 06:34:41 -04:00
|
|
|
return "VIRTUAL";
|
|
|
|
case HCI_USB:
|
|
|
|
return "USB";
|
|
|
|
case HCI_PCCARD:
|
|
|
|
return "PCCARD";
|
|
|
|
case HCI_UART:
|
|
|
|
return "UART";
|
|
|
|
case HCI_RS232:
|
|
|
|
return "RS232";
|
|
|
|
case HCI_PCI:
|
|
|
|
return "PCI";
|
2006-07-08 07:57:15 -04:00
|
|
|
case HCI_SDIO:
|
|
|
|
return "SDIO";
|
2006-07-06 06:34:41 -04:00
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-06 06:34:41 -04:00
|
|
|
return sprintf(buf, "%s\n", typetostr(hdev->type));
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2007-10-20 07:33:56 -04:00
|
|
|
static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
char name[249];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 248; i++)
|
|
|
|
name[i] = hdev->dev_name[i];
|
|
|
|
|
|
|
|
name[248] = '\0';
|
|
|
|
return sprintf(buf, "%s\n", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "0x%.2x%.2x%.2x\n",
|
|
|
|
hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2005-04-16 18:20:36 -04:00
|
|
|
bdaddr_t bdaddr;
|
|
|
|
baswap(&bdaddr, &hdev->bdaddr);
|
|
|
|
return sprintf(buf, "%s\n", batostr(&bdaddr));
|
|
|
|
}
|
|
|
|
|
2007-10-20 07:33:56 -04:00
|
|
|
static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
|
|
|
|
hdev->features[0], hdev->features[1],
|
|
|
|
hdev->features[2], hdev->features[3],
|
|
|
|
hdev->features[4], hdev->features[5],
|
|
|
|
hdev->features[6], hdev->features[7]);
|
|
|
|
}
|
|
|
|
|
2006-09-23 03:57:20 -04:00
|
|
|
static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "%d\n", hdev->manufacturer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "%d\n", hdev->hci_ver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "%d\n", hdev->hci_rev);
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2005-04-16 18:20:36 -04:00
|
|
|
struct inquiry_cache *cache = &hdev->inq_cache;
|
|
|
|
struct inquiry_entry *e;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
hci_dev_lock_bh(hdev);
|
|
|
|
|
|
|
|
for (e = cache->list; e; e = e->next) {
|
|
|
|
struct inquiry_data *data = &e->data;
|
|
|
|
bdaddr_t bdaddr;
|
|
|
|
baswap(&bdaddr, &data->bdaddr);
|
|
|
|
n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
|
|
|
|
batostr(&bdaddr),
|
|
|
|
data->pscan_rep_mode, data->pscan_period_mode, data->pscan_mode,
|
|
|
|
data->dev_class[2], data->dev_class[1], data->dev_class[0],
|
|
|
|
__le16_to_cpu(data->clock_offset), data->rssi, e->timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
hci_dev_unlock_bh(hdev);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
return sprintf(buf, "%d\n", hdev->idle_timeout);
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
char *ptr;
|
|
|
|
__u32 val;
|
|
|
|
|
|
|
|
val = simple_strtoul(buf, &ptr, 10);
|
|
|
|
if (ptr == buf)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (val != 0 && (val < 500 || val > 3600000))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
hdev->idle_timeout = val;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
return sprintf(buf, "%d\n", hdev->sniff_max_interval);
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
char *ptr;
|
|
|
|
__u16 val;
|
|
|
|
|
|
|
|
val = simple_strtoul(buf, &ptr, 10);
|
|
|
|
if (ptr == buf)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (val < 0x0002 || val > 0xFFFE || val % 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (val < hdev->sniff_min_interval)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
hdev->sniff_max_interval = val;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
return sprintf(buf, "%d\n", hdev->sniff_min_interval);
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
2006-07-03 04:02:33 -04:00
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct hci_dev *hdev = dev_get_drvdata(dev);
|
2006-07-03 04:02:33 -04:00
|
|
|
char *ptr;
|
|
|
|
__u16 val;
|
|
|
|
|
|
|
|
val = simple_strtoul(buf, &ptr, 10);
|
|
|
|
if (ptr == buf)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (val < 0x0002 || val > 0xFFFE || val % 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (val > hdev->sniff_max_interval)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
hdev->sniff_min_interval = val;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
|
2007-10-20 07:33:56 -04:00
|
|
|
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
|
|
|
|
static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
|
2007-10-20 07:33:56 -04:00
|
|
|
static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
|
2006-09-23 03:57:20 -04:00
|
|
|
static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
|
|
|
|
static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
|
|
|
|
static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
|
2006-07-03 04:02:33 -04:00
|
|
|
show_idle_timeout, store_idle_timeout);
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR,
|
2006-07-03 04:02:33 -04:00
|
|
|
show_sniff_max_interval, store_sniff_max_interval);
|
2006-07-03 04:02:41 -04:00
|
|
|
static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
|
2006-07-03 04:02:33 -04:00
|
|
|
show_sniff_min_interval, store_sniff_min_interval);
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static struct device_attribute *bt_attrs[] = {
|
|
|
|
&dev_attr_type,
|
2007-10-20 07:33:56 -04:00
|
|
|
&dev_attr_name,
|
|
|
|
&dev_attr_class,
|
2006-07-03 04:02:41 -04:00
|
|
|
&dev_attr_address,
|
2007-10-20 07:33:56 -04:00
|
|
|
&dev_attr_features,
|
2006-09-23 03:57:20 -04:00
|
|
|
&dev_attr_manufacturer,
|
|
|
|
&dev_attr_hci_version,
|
|
|
|
&dev_attr_hci_revision,
|
2006-07-03 04:02:41 -04:00
|
|
|
&dev_attr_inquiry_cache,
|
|
|
|
&dev_attr_idle_timeout,
|
|
|
|
&dev_attr_sniff_max_interval,
|
|
|
|
&dev_attr_sniff_min_interval,
|
2005-04-16 18:20:36 -04:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2006-07-06 06:38:46 -04:00
|
|
|
static ssize_t show_conn_type(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn = dev_get_drvdata(dev);
|
|
|
|
return sprintf(buf, "%s\n", conn->type == ACL_LINK ? "ACL" : "SCO");
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_conn_address(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn = dev_get_drvdata(dev);
|
|
|
|
bdaddr_t bdaddr;
|
|
|
|
baswap(&bdaddr, &conn->dst);
|
|
|
|
return sprintf(buf, "%s\n", batostr(&bdaddr));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONN_ATTR(_name,_mode,_show,_store) \
|
|
|
|
struct device_attribute conn_attr_##_name = __ATTR(_name,_mode,_show,_store)
|
|
|
|
|
|
|
|
static CONN_ATTR(type, S_IRUGO, show_conn_type, NULL);
|
|
|
|
static CONN_ATTR(address, S_IRUGO, show_conn_address, NULL);
|
|
|
|
|
|
|
|
static struct device_attribute *conn_attrs[] = {
|
|
|
|
&conn_attr_type,
|
|
|
|
&conn_attr_address,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
struct class *bt_class = NULL;
|
2005-11-08 12:57:38 -05:00
|
|
|
EXPORT_SYMBOL_GPL(bt_class);
|
|
|
|
|
2006-07-03 04:02:37 -04:00
|
|
|
static struct bus_type bt_bus = {
|
|
|
|
.name = "bluetooth",
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *bt_platform;
|
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
static void bt_release(struct device *dev)
|
|
|
|
{
|
2006-07-06 06:38:46 -04:00
|
|
|
void *data = dev_get_drvdata(dev);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
2006-11-22 09:57:56 -05:00
|
|
|
static void add_conn(struct work_struct *work)
|
2006-07-06 06:38:46 -04:00
|
|
|
{
|
2006-11-22 09:57:56 -05:00
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn, work);
|
2006-07-06 06:38:46 -04:00
|
|
|
int i;
|
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
flush_workqueue(btdelconn);
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2007-01-07 20:16:38 -05:00
|
|
|
if (device_add(&conn->dev) < 0) {
|
2006-10-15 11:30:45 -04:00
|
|
|
BT_ERR("Failed to register connection device");
|
|
|
|
return;
|
|
|
|
}
|
2006-07-06 06:38:46 -04:00
|
|
|
|
|
|
|
for (i = 0; conn_attrs[i]; i++)
|
2006-10-15 11:30:45 -04:00
|
|
|
if (device_create_file(&conn->dev, conn_attrs[i]) < 0)
|
|
|
|
BT_ERR("Failed to create connection attribute");
|
2006-07-06 06:38:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void hci_conn_add_sysfs(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
bdaddr_t *ba = &conn->dst;
|
|
|
|
|
|
|
|
BT_DBG("conn %p", conn);
|
|
|
|
|
2006-11-18 16:14:05 -05:00
|
|
|
conn->dev.bus = &bt_bus;
|
|
|
|
conn->dev.parent = &hdev->dev;
|
|
|
|
|
2006-07-06 06:38:46 -04:00
|
|
|
conn->dev.release = bt_release;
|
|
|
|
|
|
|
|
snprintf(conn->dev.bus_id, BUS_ID_SIZE,
|
|
|
|
"%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
|
|
|
|
conn->type == ACL_LINK ? "acl" : "sco",
|
|
|
|
ba->b[5], ba->b[4], ba->b[3],
|
|
|
|
ba->b[2], ba->b[1], ba->b[0]);
|
|
|
|
|
|
|
|
dev_set_drvdata(&conn->dev, conn);
|
|
|
|
|
2007-01-07 20:16:38 -05:00
|
|
|
device_initialize(&conn->dev);
|
|
|
|
|
2006-11-22 09:57:56 -05:00
|
|
|
INIT_WORK(&conn->work, add_conn);
|
2006-07-06 06:38:46 -04:00
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
queue_work(btaddconn, &conn->work);
|
2006-07-06 06:38:46 -04:00
|
|
|
}
|
|
|
|
|
2008-01-22 01:35:21 -05:00
|
|
|
static int __match_tty(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
/* The rfcomm tty device will possibly retain even when conn
|
|
|
|
* is down, and sysfs doesn't support move zombie device,
|
|
|
|
* so we should move the device before conn device is destroyed.
|
|
|
|
* Due to the only child device of hci_conn dev is rfcomm
|
|
|
|
* tty_dev, here just return 1
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-11-22 09:57:56 -05:00
|
|
|
static void del_conn(struct work_struct *work)
|
2006-07-06 06:38:46 -04:00
|
|
|
{
|
2008-01-22 01:35:21 -05:00
|
|
|
struct device *dev;
|
2006-11-22 09:57:56 -05:00
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn, work);
|
2008-01-22 01:35:21 -05:00
|
|
|
|
|
|
|
while (dev = device_find_child(&conn->dev, NULL, __match_tty)) {
|
|
|
|
device_move(dev, NULL);
|
|
|
|
put_device(dev);
|
|
|
|
}
|
2006-07-06 06:38:46 -04:00
|
|
|
device_del(&conn->dev);
|
2007-12-29 22:17:47 -05:00
|
|
|
put_device(&conn->dev);
|
2006-07-06 06:38:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void hci_conn_del_sysfs(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
BT_DBG("conn %p", conn);
|
|
|
|
|
2007-01-07 20:16:38 -05:00
|
|
|
if (!device_is_registered(&conn->dev))
|
|
|
|
return;
|
|
|
|
|
2006-11-22 09:57:56 -05:00
|
|
|
INIT_WORK(&conn->work, del_conn);
|
2006-07-06 06:38:46 -04:00
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
queue_work(btdelconn, &conn->work);
|
2006-07-03 04:02:41 -04:00
|
|
|
}
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
int hci_register_sysfs(struct hci_dev *hdev)
|
|
|
|
{
|
2006-07-03 04:02:41 -04:00
|
|
|
struct device *dev = &hdev->dev;
|
2005-04-16 18:20:36 -04:00
|
|
|
unsigned int i;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
|
|
|
|
|
2007-05-04 18:36:03 -04:00
|
|
|
dev->bus = &bt_bus;
|
2006-10-15 11:30:50 -04:00
|
|
|
dev->parent = hdev->parent;
|
2006-07-03 04:02:41 -04:00
|
|
|
|
|
|
|
strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
dev->release = bt_release;
|
2006-07-03 04:02:37 -04:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
dev_set_drvdata(dev, hdev);
|
2006-07-03 04:02:37 -04:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
err = device_register(dev);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
for (i = 0; bt_attrs[i]; i++)
|
2006-10-15 11:30:45 -04:00
|
|
|
if (device_create_file(dev, bt_attrs[i]) < 0)
|
|
|
|
BT_ERR("Failed to create device attribute");
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2007-05-07 20:32:08 -04:00
|
|
|
if (sysfs_create_link(&bt_class->subsys.kobj,
|
2007-05-04 18:36:03 -04:00
|
|
|
&dev->kobj, kobject_name(&dev->kobj)) < 0)
|
|
|
|
BT_ERR("Failed to create class symlink");
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hci_unregister_sysfs(struct hci_dev *hdev)
|
|
|
|
{
|
|
|
|
BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
|
|
|
|
|
2007-05-07 20:32:08 -04:00
|
|
|
sysfs_remove_link(&bt_class->subsys.kobj,
|
2007-05-04 18:36:03 -04:00
|
|
|
kobject_name(&hdev->dev.kobj));
|
|
|
|
|
2006-07-06 06:34:41 -04:00
|
|
|
device_del(&hdev->dev);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int __init bt_sysfs_init(void)
|
|
|
|
{
|
2006-07-03 04:02:37 -04:00
|
|
|
int err;
|
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
btaddconn = create_singlethread_workqueue("btaddconn");
|
|
|
|
if (!btaddconn) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
btdelconn = create_singlethread_workqueue("btdelconn");
|
|
|
|
if (!btdelconn) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_del;
|
|
|
|
}
|
|
|
|
|
2006-07-03 04:02:37 -04:00
|
|
|
bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0);
|
2008-01-30 00:14:08 -05:00
|
|
|
if (IS_ERR(bt_platform)) {
|
|
|
|
err = PTR_ERR(bt_platform);
|
|
|
|
goto out_platform;
|
|
|
|
}
|
2006-07-03 04:02:37 -04:00
|
|
|
|
|
|
|
err = bus_register(&bt_bus);
|
2008-01-30 00:14:08 -05:00
|
|
|
if (err < 0)
|
|
|
|
goto out_bus;
|
2006-07-03 04:02:37 -04:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
bt_class = class_create(THIS_MODULE, "bluetooth");
|
|
|
|
if (IS_ERR(bt_class)) {
|
2008-01-30 00:14:08 -05:00
|
|
|
err = PTR_ERR(bt_class);
|
|
|
|
goto out_class;
|
2006-07-03 04:02:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-01-30 00:14:08 -05:00
|
|
|
|
|
|
|
out_class:
|
|
|
|
bus_unregister(&bt_bus);
|
|
|
|
out_bus:
|
|
|
|
platform_device_unregister(bt_platform);
|
|
|
|
out_platform:
|
|
|
|
destroy_workqueue(btdelconn);
|
|
|
|
out_del:
|
|
|
|
destroy_workqueue(btaddconn);
|
|
|
|
out:
|
|
|
|
return err;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:29:37 -04:00
|
|
|
void bt_sysfs_cleanup(void)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2008-01-30 00:14:08 -05:00
|
|
|
destroy_workqueue(btaddconn);
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2008-01-30 00:14:08 -05:00
|
|
|
destroy_workqueue(btdelconn);
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2006-07-03 04:02:41 -04:00
|
|
|
class_destroy(bt_class);
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2006-07-03 04:02:37 -04:00
|
|
|
bus_unregister(&bt_bus);
|
2008-01-31 21:33:10 -05:00
|
|
|
|
2006-07-03 04:02:37 -04:00
|
|
|
platform_device_unregister(bt_platform);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|