1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/rio.h>
16#include <linux/rio_ids.h>
17
18#include "rio.h"
19
20
21
22
23
24
25
26
27
28
29static const struct rio_device_id *rio_match_device(const struct rio_device_id
30 *id,
31 const struct rio_dev *rdev)
32{
33 while (id->vid || id->asm_vid) {
34 if (((id->vid == RIO_ANY_ID) || (id->vid == rdev->vid)) &&
35 ((id->did == RIO_ANY_ID) || (id->did == rdev->did)) &&
36 ((id->asm_vid == RIO_ANY_ID)
37 || (id->asm_vid == rdev->asm_vid))
38 && ((id->asm_did == RIO_ANY_ID)
39 || (id->asm_did == rdev->asm_did)))
40 return id;
41 id++;
42 }
43 return NULL;
44}
45
46
47
48
49
50
51
52
53
54
55
56
57struct rio_dev *rio_dev_get(struct rio_dev *rdev)
58{
59 if (rdev)
60 get_device(&rdev->dev);
61
62 return rdev;
63}
64
65
66
67
68
69
70
71
72
73
74void rio_dev_put(struct rio_dev *rdev)
75{
76 if (rdev)
77 put_device(&rdev->dev);
78}
79
80
81
82
83
84
85
86
87
88static int rio_device_probe(struct device *dev)
89{
90 struct rio_driver *rdrv = to_rio_driver(dev->driver);
91 struct rio_dev *rdev = to_rio_dev(dev);
92 int error = -ENODEV;
93 const struct rio_device_id *id;
94
95 if (!rdev->driver && rdrv->probe) {
96 if (!rdrv->id_table)
97 return error;
98 id = rio_match_device(rdrv->id_table, rdev);
99 rio_dev_get(rdev);
100 if (id)
101 error = rdrv->probe(rdev, id);
102 if (error >= 0) {
103 rdev->driver = rdrv;
104 error = 0;
105 rio_dev_put(rdev);
106 }
107 }
108 return error;
109}
110
111
112
113
114
115
116
117
118
119
120static int rio_device_remove(struct device *dev)
121{
122 struct rio_dev *rdev = to_rio_dev(dev);
123 struct rio_driver *rdrv = rdev->driver;
124
125 if (rdrv) {
126 if (rdrv->remove)
127 rdrv->remove(rdev);
128 rdev->driver = NULL;
129 }
130
131 rio_dev_put(rdev);
132
133 return 0;
134}
135
136
137
138
139
140
141
142
143
144
145int rio_register_driver(struct rio_driver *rdrv)
146{
147
148 rdrv->driver.name = rdrv->name;
149 rdrv->driver.bus = &rio_bus_type;
150
151
152 return driver_register(&rdrv->driver);
153}
154
155
156
157
158
159
160
161
162
163
164void rio_unregister_driver(struct rio_driver *rdrv)
165{
166 driver_unregister(&rdrv->driver);
167}
168
169
170
171
172
173
174
175
176
177
178
179
180static int rio_match_bus(struct device *dev, struct device_driver *drv)
181{
182 struct rio_dev *rdev = to_rio_dev(dev);
183 struct rio_driver *rdrv = to_rio_driver(drv);
184 const struct rio_device_id *id = rdrv->id_table;
185 const struct rio_device_id *found_id;
186
187 if (!id)
188 goto out;
189
190 found_id = rio_match_device(id, rdev);
191
192 if (found_id)
193 return 1;
194
195 out:return 0;
196}
197
198static struct device rio_bus = {
199 .bus_id = "rapidio",
200};
201
202struct bus_type rio_bus_type = {
203 .name = "rapidio",
204 .match = rio_match_bus,
205 .dev_attrs = rio_dev_attrs,
206 .probe = rio_device_probe,
207 .remove = rio_device_remove,
208};
209
210
211
212
213
214
215
216static int __init rio_bus_init(void)
217{
218 if (device_register(&rio_bus) < 0)
219 printk("RIO: failed to register RIO bus device\n");
220 return bus_register(&rio_bus_type);
221}
222
223postcore_initcall(rio_bus_init);
224
225EXPORT_SYMBOL_GPL(rio_register_driver);
226EXPORT_SYMBOL_GPL(rio_unregister_driver);
227EXPORT_SYMBOL_GPL(rio_bus_type);
228EXPORT_SYMBOL_GPL(rio_dev_get);
229EXPORT_SYMBOL_GPL(rio_dev_put);
230