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/zorro.h>
16
17#include "zorro.h"
18
19
20
21
22
23
24
25
26
27
28
29
30
31static const struct zorro_device_id *
32zorro_match_device(const struct zorro_device_id *ids,
33 const struct zorro_dev *z)
34{
35 while (ids->id) {
36 if (ids->id == ZORRO_WILDCARD || ids->id == z->id)
37 return ids;
38 ids++;
39 }
40 return NULL;
41}
42
43
44static int zorro_device_probe(struct device *dev)
45{
46 int error = 0;
47 struct zorro_driver *drv = to_zorro_driver(dev->driver);
48 struct zorro_dev *z = to_zorro_dev(dev);
49
50 if (drv->probe) {
51 const struct zorro_device_id *id;
52
53 id = zorro_match_device(drv->id_table, z);
54 if (id)
55 error = drv->probe(z, id);
56 if (error >= 0)
57 error = 0;
58 }
59 return error;
60}
61
62
63static void zorro_device_remove(struct device *dev)
64{
65 struct zorro_dev *z = to_zorro_dev(dev);
66 struct zorro_driver *drv = to_zorro_driver(dev->driver);
67
68 if (drv->remove)
69 drv->remove(z);
70}
71
72
73
74
75
76
77
78
79
80
81int zorro_register_driver(struct zorro_driver *drv)
82{
83
84 drv->driver.name = drv->name;
85 drv->driver.bus = &zorro_bus_type;
86
87
88 return driver_register(&drv->driver);
89}
90EXPORT_SYMBOL(zorro_register_driver);
91
92
93
94
95
96
97
98
99
100
101
102
103void zorro_unregister_driver(struct zorro_driver *drv)
104{
105 driver_unregister(&drv->driver);
106}
107EXPORT_SYMBOL(zorro_unregister_driver);
108
109
110
111
112
113
114
115
116
117
118
119
120
121static int zorro_bus_match(struct device *dev, struct device_driver *drv)
122{
123 struct zorro_dev *z = to_zorro_dev(dev);
124 struct zorro_driver *zorro_drv = to_zorro_driver(drv);
125 const struct zorro_device_id *ids = zorro_drv->id_table;
126
127 if (!ids)
128 return 0;
129
130 return !!zorro_match_device(ids, z);
131}
132
133static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env)
134{
135 struct zorro_dev *z;
136
137 if (!dev)
138 return -ENODEV;
139
140 z = to_zorro_dev(dev);
141 if (!z)
142 return -ENODEV;
143
144 if (add_uevent_var(env, "ZORRO_ID=%08X", z->id) ||
145 add_uevent_var(env, "ZORRO_SLOT_NAME=%s", dev_name(dev)) ||
146 add_uevent_var(env, "ZORRO_SLOT_ADDR=%04X", z->slotaddr) ||
147 add_uevent_var(env, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT, z->id))
148 return -ENOMEM;
149
150 return 0;
151}
152
153struct bus_type zorro_bus_type = {
154 .name = "zorro",
155 .dev_name = "zorro",
156 .dev_groups = zorro_device_attribute_groups,
157 .match = zorro_bus_match,
158 .uevent = zorro_uevent,
159 .probe = zorro_device_probe,
160 .remove = zorro_device_remove,
161};
162EXPORT_SYMBOL(zorro_bus_type);
163
164
165static int __init zorro_driver_init(void)
166{
167 return bus_register(&zorro_bus_type);
168}
169
170postcore_initcall(zorro_driver_init);
171
172