This source file includes following definitions.
- dio_match_device
- dio_device_probe
- dio_register_driver
- dio_unregister_driver
- dio_bus_match
- dio_driver_init
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/dio.h>
16
17
18
19
20
21
22
23
24
25
26
27
28 const struct dio_device_id *
29 dio_match_device(const struct dio_device_id *ids,
30 const struct dio_dev *d)
31 {
32 while (ids->id) {
33 if (ids->id == DIO_WILDCARD)
34 return ids;
35 if (DIO_NEEDSSECID(ids->id & 0xff)) {
36 if (ids->id == d->id)
37 return ids;
38 } else {
39 if ((ids->id & 0xff) == (d->id & 0xff))
40 return ids;
41 }
42 ids++;
43 }
44 return NULL;
45 }
46
47 static int dio_device_probe(struct device *dev)
48 {
49 int error = 0;
50 struct dio_driver *drv = to_dio_driver(dev->driver);
51 struct dio_dev *d = to_dio_dev(dev);
52
53 if (!d->driver && drv->probe) {
54 const struct dio_device_id *id;
55
56 id = dio_match_device(drv->id_table, d);
57 if (id)
58 error = drv->probe(d, id);
59 if (error >= 0) {
60 d->driver = drv;
61 error = 0;
62 }
63 }
64 return error;
65 }
66
67
68
69
70
71
72
73
74
75
76 int dio_register_driver(struct dio_driver *drv)
77 {
78
79 drv->driver.name = drv->name;
80 drv->driver.bus = &dio_bus_type;
81
82
83 return driver_register(&drv->driver);
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97 void dio_unregister_driver(struct dio_driver *drv)
98 {
99 driver_unregister(&drv->driver);
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113 static int dio_bus_match(struct device *dev, struct device_driver *drv)
114 {
115 struct dio_dev *d = to_dio_dev(dev);
116 struct dio_driver *dio_drv = to_dio_driver(drv);
117 const struct dio_device_id *ids = dio_drv->id_table;
118
119 if (!ids)
120 return 0;
121
122 return dio_match_device(ids, d) ? 1 : 0;
123 }
124
125
126 struct bus_type dio_bus_type = {
127 .name = "dio",
128 .match = dio_bus_match,
129 .probe = dio_device_probe,
130 };
131
132
133 static int __init dio_driver_init(void)
134 {
135 return bus_register(&dio_bus_type);
136 }
137
138 postcore_initcall(dio_driver_init);
139
140 EXPORT_SYMBOL(dio_match_device);
141 EXPORT_SYMBOL(dio_register_driver);
142 EXPORT_SYMBOL(dio_unregister_driver);
143 EXPORT_SYMBOL(dio_bus_type);