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