This source file includes following definitions.
- uwb_pal_init
- uwb_pal_register
- find_rc
- uwb_rc_class_device_exists
- uwb_pal_unregister
- uwb_rc_pal_init
1
2
3
4
5
6
7 #include <linux/kernel.h>
8 #include <linux/debugfs.h>
9 #include <linux/export.h>
10
11 #include "uwb.h"
12 #include "uwb-internal.h"
13
14
15
16
17
18 void uwb_pal_init(struct uwb_pal *pal)
19 {
20 INIT_LIST_HEAD(&pal->node);
21 }
22 EXPORT_SYMBOL_GPL(uwb_pal_init);
23
24
25
26
27
28
29
30 int uwb_pal_register(struct uwb_pal *pal)
31 {
32 struct uwb_rc *rc = pal->rc;
33 int ret;
34
35 if (pal->device) {
36
37 ret = sysfs_create_link(&pal->device->kobj,
38 &rc->uwb_dev.dev.kobj, "uwb_rc");
39 if (ret < 0)
40 return ret;
41
42 ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
43 &pal->device->kobj, pal->name);
44 if (ret < 0) {
45 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
46 return ret;
47 }
48 }
49
50 pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
51
52 mutex_lock(&rc->uwb_dev.mutex);
53 list_add(&pal->node, &rc->pals);
54 mutex_unlock(&rc->uwb_dev.mutex);
55
56 return 0;
57 }
58 EXPORT_SYMBOL_GPL(uwb_pal_register);
59
60 static int find_rc(struct device *dev, const void *data)
61 {
62 const struct uwb_rc *target_rc = data;
63 struct uwb_rc *rc = dev_get_drvdata(dev);
64
65 if (rc == NULL) {
66 WARN_ON(1);
67 return 0;
68 }
69 if (rc == target_rc) {
70 if (rc->ready == 0)
71 return 0;
72 else
73 return 1;
74 }
75 return 0;
76 }
77
78
79
80
81
82
83 static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc)
84 {
85 struct device *dev;
86
87 dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);
88
89 put_device(dev);
90
91 return (dev != NULL);
92 }
93
94
95
96
97
98 void uwb_pal_unregister(struct uwb_pal *pal)
99 {
100 struct uwb_rc *rc = pal->rc;
101
102 uwb_radio_stop(pal);
103
104 mutex_lock(&rc->uwb_dev.mutex);
105 list_del(&pal->node);
106 mutex_unlock(&rc->uwb_dev.mutex);
107
108 debugfs_remove(pal->debugfs_dir);
109
110 if (pal->device) {
111
112 if (uwb_rc_class_device_exists(rc))
113 sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
114
115
116 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
117 }
118 }
119 EXPORT_SYMBOL_GPL(uwb_pal_unregister);
120
121
122
123
124
125 void uwb_rc_pal_init(struct uwb_rc *rc)
126 {
127 INIT_LIST_HEAD(&rc->pals);
128 }