Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/* Bluetooth HCI driver model support. */
  3
  4#include <linux/module.h>
  5
  6#include <net/bluetooth/bluetooth.h>
  7#include <net/bluetooth/hci_core.h>
  8
  9static const struct class bt_class = {
 10	.name = "bluetooth",
 11};
 12
 13static void bt_link_release(struct device *dev)
 14{
 15	struct hci_conn *conn = to_hci_conn(dev);
 16	kfree(conn);
 17}
 18
 19static const struct device_type bt_link = {
 20	.name    = "link",
 21	.release = bt_link_release,
 22};
 23
 24/*
 25 * The rfcomm tty device will possibly retain even when conn
 26 * is down, and sysfs doesn't support move zombie device,
 27 * so we should move the device before conn device is destroyed.
 28 */
 29static int __match_tty(struct device *dev, void *data)
 30{
 31	return !strncmp(dev_name(dev), "rfcomm", 6);
 32}
 33
 34void hci_conn_init_sysfs(struct hci_conn *conn)
 35{
 36	struct hci_dev *hdev = conn->hdev;
 37
 38	bt_dev_dbg(hdev, "conn %p", conn);
 39
 40	conn->dev.type = &bt_link;
 41	conn->dev.class = &bt_class;
 42	conn->dev.parent = &hdev->dev;
 43
 44	device_initialize(&conn->dev);
 45}
 46
 47void hci_conn_add_sysfs(struct hci_conn *conn)
 48{
 49	struct hci_dev *hdev = conn->hdev;
 50
 51	bt_dev_dbg(hdev, "conn %p", conn);
 52
 53	if (device_is_registered(&conn->dev))
 54		return;
 55
 56	dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
 57
 58	if (device_add(&conn->dev) < 0)
 59		bt_dev_err(hdev, "failed to register connection device");
 
 
 
 
 60}
 61
 62void hci_conn_del_sysfs(struct hci_conn *conn)
 63{
 64	struct hci_dev *hdev = conn->hdev;
 65
 66	bt_dev_dbg(hdev, "conn %p", conn);
 67
 68	if (!device_is_registered(&conn->dev)) {
 69		/* If device_add() has *not* succeeded, use *only* put_device()
 70		 * to drop the reference count.
 71		 */
 72		put_device(&conn->dev);
 73		return;
 74	}
 75
 76	while (1) {
 77		struct device *dev;
 78
 79		dev = device_find_child(&conn->dev, NULL, __match_tty);
 80		if (!dev)
 81			break;
 82		device_move(dev, NULL, DPM_ORDER_DEV_LAST);
 83		put_device(dev);
 84	}
 85
 86	device_unregister(&conn->dev);
 
 
 87}
 88
 89static void bt_host_release(struct device *dev)
 90{
 91	struct hci_dev *hdev = to_hci_dev(dev);
 92
 93	if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
 94		hci_release_dev(hdev);
 95	else
 96		kfree(hdev);
 97	module_put(THIS_MODULE);
 98}
 99
100static const struct device_type bt_host = {
101	.name    = "host",
102	.release = bt_host_release,
103};
104
105void hci_init_sysfs(struct hci_dev *hdev)
106{
107	struct device *dev = &hdev->dev;
108
109	dev->type = &bt_host;
110	dev->class = &bt_class;
111
112	__module_get(THIS_MODULE);
113	device_initialize(dev);
114}
115
116int __init bt_sysfs_init(void)
117{
118	return class_register(&bt_class);
 
 
119}
120
121void bt_sysfs_cleanup(void)
122{
123	class_unregister(&bt_class);
124}
v5.4
  1// SPDX-License-Identifier: GPL-2.0
  2/* Bluetooth HCI driver model support. */
  3
  4#include <linux/module.h>
  5
  6#include <net/bluetooth/bluetooth.h>
  7#include <net/bluetooth/hci_core.h>
  8
  9static struct class *bt_class;
 
 
 10
 11static void bt_link_release(struct device *dev)
 12{
 13	struct hci_conn *conn = to_hci_conn(dev);
 14	kfree(conn);
 15}
 16
 17static const struct device_type bt_link = {
 18	.name    = "link",
 19	.release = bt_link_release,
 20};
 21
 22/*
 23 * The rfcomm tty device will possibly retain even when conn
 24 * is down, and sysfs doesn't support move zombie device,
 25 * so we should move the device before conn device is destroyed.
 26 */
 27static int __match_tty(struct device *dev, void *data)
 28{
 29	return !strncmp(dev_name(dev), "rfcomm", 6);
 30}
 31
 32void hci_conn_init_sysfs(struct hci_conn *conn)
 33{
 34	struct hci_dev *hdev = conn->hdev;
 35
 36	BT_DBG("conn %p", conn);
 37
 38	conn->dev.type = &bt_link;
 39	conn->dev.class = bt_class;
 40	conn->dev.parent = &hdev->dev;
 41
 42	device_initialize(&conn->dev);
 43}
 44
 45void hci_conn_add_sysfs(struct hci_conn *conn)
 46{
 47	struct hci_dev *hdev = conn->hdev;
 48
 49	BT_DBG("conn %p", conn);
 
 
 
 50
 51	dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
 52
 53	if (device_add(&conn->dev) < 0) {
 54		bt_dev_err(hdev, "failed to register connection device");
 55		return;
 56	}
 57
 58	hci_dev_hold(hdev);
 59}
 60
 61void hci_conn_del_sysfs(struct hci_conn *conn)
 62{
 63	struct hci_dev *hdev = conn->hdev;
 64
 65	if (!device_is_registered(&conn->dev))
 
 
 
 
 
 
 66		return;
 
 67
 68	while (1) {
 69		struct device *dev;
 70
 71		dev = device_find_child(&conn->dev, NULL, __match_tty);
 72		if (!dev)
 73			break;
 74		device_move(dev, NULL, DPM_ORDER_DEV_LAST);
 75		put_device(dev);
 76	}
 77
 78	device_del(&conn->dev);
 79
 80	hci_dev_put(hdev);
 81}
 82
 83static void bt_host_release(struct device *dev)
 84{
 85	struct hci_dev *hdev = to_hci_dev(dev);
 86	kfree(hdev);
 
 
 
 
 87	module_put(THIS_MODULE);
 88}
 89
 90static const struct device_type bt_host = {
 91	.name    = "host",
 92	.release = bt_host_release,
 93};
 94
 95void hci_init_sysfs(struct hci_dev *hdev)
 96{
 97	struct device *dev = &hdev->dev;
 98
 99	dev->type = &bt_host;
100	dev->class = bt_class;
101
102	__module_get(THIS_MODULE);
103	device_initialize(dev);
104}
105
106int __init bt_sysfs_init(void)
107{
108	bt_class = class_create(THIS_MODULE, "bluetooth");
109
110	return PTR_ERR_OR_ZERO(bt_class);
111}
112
113void bt_sysfs_cleanup(void)
114{
115	class_destroy(bt_class);
116}