rt2x00usb: fix anchor initialization
[linux/fpc-iii.git] / net / bluetooth / hci_sysfs.c
blobca7a35ebaefb61095f278106adc8d5529a247d31
1 /* Bluetooth HCI driver model support. */
3 #include <linux/module.h>
5 #include <net/bluetooth/bluetooth.h>
6 #include <net/bluetooth/hci_core.h>
8 static struct class *bt_class;
10 static void bt_link_release(struct device *dev)
12 struct hci_conn *conn = to_hci_conn(dev);
13 kfree(conn);
16 static struct device_type bt_link = {
17 .name = "link",
18 .release = bt_link_release,
22 * The rfcomm tty device will possibly retain even when conn
23 * is down, and sysfs doesn't support move zombie device,
24 * so we should move the device before conn device is destroyed.
26 static int __match_tty(struct device *dev, void *data)
28 return !strncmp(dev_name(dev), "rfcomm", 6);
31 void hci_conn_init_sysfs(struct hci_conn *conn)
33 struct hci_dev *hdev = conn->hdev;
35 BT_DBG("conn %p", conn);
37 conn->dev.type = &bt_link;
38 conn->dev.class = bt_class;
39 conn->dev.parent = &hdev->dev;
41 device_initialize(&conn->dev);
44 void hci_conn_add_sysfs(struct hci_conn *conn)
46 struct hci_dev *hdev = conn->hdev;
48 BT_DBG("conn %p", conn);
50 dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
52 if (device_add(&conn->dev) < 0) {
53 BT_ERR("Failed to register connection device");
54 return;
57 hci_dev_hold(hdev);
60 void hci_conn_del_sysfs(struct hci_conn *conn)
62 struct hci_dev *hdev = conn->hdev;
64 if (!device_is_registered(&conn->dev))
65 return;
67 while (1) {
68 struct device *dev;
70 dev = device_find_child(&conn->dev, NULL, __match_tty);
71 if (!dev)
72 break;
73 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
74 put_device(dev);
77 device_del(&conn->dev);
79 hci_dev_put(hdev);
82 static void bt_host_release(struct device *dev)
84 struct hci_dev *hdev = to_hci_dev(dev);
85 kfree(hdev);
86 module_put(THIS_MODULE);
89 static struct device_type bt_host = {
90 .name = "host",
91 .release = bt_host_release,
94 void hci_init_sysfs(struct hci_dev *hdev)
96 struct device *dev = &hdev->dev;
98 dev->type = &bt_host;
99 dev->class = bt_class;
101 __module_get(THIS_MODULE);
102 device_initialize(dev);
105 int __init bt_sysfs_init(void)
107 bt_class = class_create(THIS_MODULE, "bluetooth");
109 return PTR_ERR_OR_ZERO(bt_class);
112 void bt_sysfs_cleanup(void)
114 class_destroy(bt_class);