Linux Audio

Check our new training course

Loading...
v6.13.7
  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
 
 
 
 
 
 
 
 
 
 
 24void hci_conn_init_sysfs(struct hci_conn *conn)
 25{
 26	struct hci_dev *hdev = conn->hdev;
 27
 28	bt_dev_dbg(hdev, "conn %p", conn);
 29
 30	conn->dev.type = &bt_link;
 31	conn->dev.class = &bt_class;
 32	conn->dev.parent = &hdev->dev;
 33
 34	device_initialize(&conn->dev);
 35}
 36
 37void hci_conn_add_sysfs(struct hci_conn *conn)
 38{
 39	struct hci_dev *hdev = conn->hdev;
 40
 41	bt_dev_dbg(hdev, "conn %p", conn);
 42
 43	if (device_is_registered(&conn->dev))
 44		return;
 45
 46	dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
 47
 48	if (device_add(&conn->dev) < 0)
 49		bt_dev_err(hdev, "failed to register connection device");
 
 
 
 
 50}
 51
 52void hci_conn_del_sysfs(struct hci_conn *conn)
 53{
 54	struct hci_dev *hdev = conn->hdev;
 55
 56	bt_dev_dbg(hdev, "conn %p", conn);
 57
 58	if (!device_is_registered(&conn->dev)) {
 59		/* If device_add() has *not* succeeded, use *only* put_device()
 60		 * to drop the reference count.
 61		 */
 62		put_device(&conn->dev);
 63		return;
 64	}
 65
 66	/* If there are devices using the connection as parent reset it to NULL
 67	 * before unregistering the device.
 68	 */
 69	while (1) {
 70		struct device *dev;
 71
 72		dev = device_find_any_child(&conn->dev);
 73		if (!dev)
 74			break;
 75		device_move(dev, NULL, DPM_ORDER_DEV_LAST);
 76		put_device(dev);
 77	}
 78
 79	device_unregister(&conn->dev);
 
 
 80}
 81
 82static void bt_host_release(struct device *dev)
 83{
 84	struct hci_dev *hdev = to_hci_dev(dev);
 85
 86	if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
 87		hci_release_dev(hdev);
 88	else
 89		kfree(hdev);
 90	module_put(THIS_MODULE);
 91}
 92
 93static const struct device_type bt_host = {
 94	.name    = "host",
 95	.release = bt_host_release,
 96};
 97
 98void hci_init_sysfs(struct hci_dev *hdev)
 99{
100	struct device *dev = &hdev->dev;
101
102	dev->type = &bt_host;
103	dev->class = &bt_class;
104
105	__module_get(THIS_MODULE);
106	device_initialize(dev);
107}
108
109int __init bt_sysfs_init(void)
110{
111	return class_register(&bt_class);
 
 
112}
113
114void bt_sysfs_cleanup(void)
115{
116	class_unregister(&bt_class);
117}
v6.2
  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	if (device_is_registered(&conn->dev))
 52		return;
 53
 54	dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
 55
 56	if (device_add(&conn->dev) < 0) {
 57		bt_dev_err(hdev, "failed to register connection device");
 58		return;
 59	}
 60
 61	hci_dev_hold(hdev);
 62}
 63
 64void hci_conn_del_sysfs(struct hci_conn *conn)
 65{
 66	struct hci_dev *hdev = conn->hdev;
 67
 68	if (!device_is_registered(&conn->dev))
 
 
 
 
 
 
 69		return;
 
 70
 
 
 
 71	while (1) {
 72		struct device *dev;
 73
 74		dev = device_find_child(&conn->dev, NULL, __match_tty);
 75		if (!dev)
 76			break;
 77		device_move(dev, NULL, DPM_ORDER_DEV_LAST);
 78		put_device(dev);
 79	}
 80
 81	device_del(&conn->dev);
 82
 83	hci_dev_put(hdev);
 84}
 85
 86static void bt_host_release(struct device *dev)
 87{
 88	struct hci_dev *hdev = to_hci_dev(dev);
 89
 90	if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
 91		hci_release_dev(hdev);
 92	else
 93		kfree(hdev);
 94	module_put(THIS_MODULE);
 95}
 96
 97static const struct device_type bt_host = {
 98	.name    = "host",
 99	.release = bt_host_release,
100};
101
102void hci_init_sysfs(struct hci_dev *hdev)
103{
104	struct device *dev = &hdev->dev;
105
106	dev->type = &bt_host;
107	dev->class = bt_class;
108
109	__module_get(THIS_MODULE);
110	device_initialize(dev);
111}
112
113int __init bt_sysfs_init(void)
114{
115	bt_class = class_create(THIS_MODULE, "bluetooth");
116
117	return PTR_ERR_OR_ZERO(bt_class);
118}
119
120void bt_sysfs_cleanup(void)
121{
122	class_destroy(bt_class);
123}