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
);
16 static struct device_type bt_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");
60 void hci_conn_del_sysfs(struct hci_conn
*conn
)
62 struct hci_dev
*hdev
= conn
->hdev
;
64 if (!device_is_registered(&conn
->dev
))
70 dev
= device_find_child(&conn
->dev
, NULL
, __match_tty
);
73 device_move(dev
, NULL
, DPM_ORDER_DEV_LAST
);
77 device_del(&conn
->dev
);
82 static void bt_host_release(struct device
*dev
)
84 struct hci_dev
*hdev
= to_hci_dev(dev
);
86 module_put(THIS_MODULE
);
89 static struct device_type bt_host
= {
91 .release
= bt_host_release
,
94 void hci_init_sysfs(struct hci_dev
*hdev
)
96 struct device
*dev
= &hdev
->dev
;
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
);