2 * Zorro Driver Services
4 * Copyright (C) 2003 Geert Uytterhoeven
6 * Loosely based on drivers/pci/pci-driver.c
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/zorro.h>
19 * zorro_match_device - Tell if a Zorro device structure has a matching
20 * Zorro device id structure
21 * @ids: array of Zorro device id structures to search in
22 * @dev: the Zorro device structure to match against
24 * Used by a driver to check whether a Zorro device present in the
25 * system is in its list of supported devices. Returns the matching
26 * zorro_device_id structure or %NULL if there is no match.
29 const struct zorro_device_id *
30 zorro_match_device(const struct zorro_device_id *ids,
31 const struct zorro_dev *z)
34 if (ids->id == ZORRO_WILDCARD || ids->id == z->id)
40 EXPORT_SYMBOL(zorro_match_device);
43 static int zorro_device_probe(struct device *dev)
46 struct zorro_driver *drv = to_zorro_driver(dev->driver);
47 struct zorro_dev *z = to_zorro_dev(dev);
49 if (!z->driver && drv->probe) {
50 const struct zorro_device_id *id;
52 id = zorro_match_device(drv->id_table, z);
54 error = drv->probe(z, id);
64 static int zorro_device_remove(struct device *dev)
66 struct zorro_dev *z = to_zorro_dev(dev);
67 struct zorro_driver *drv = to_zorro_driver(dev->driver);
79 * zorro_register_driver - register a new Zorro driver
80 * @drv: the driver structure to register
82 * Adds the driver structure to the list of registered drivers
83 * Returns zero or a negative error value.
86 int zorro_register_driver(struct zorro_driver *drv)
88 /* initialize common driver fields */
89 drv->driver.name = drv->name;
90 drv->driver.bus = &zorro_bus_type;
92 /* register with core */
93 return driver_register(&drv->driver);
95 EXPORT_SYMBOL(zorro_register_driver);
99 * zorro_unregister_driver - unregister a zorro driver
100 * @drv: the driver structure to unregister
102 * Deletes the driver structure from the list of registered Zorro drivers,
103 * gives it a chance to clean up by calling its remove() function for
104 * each device it was responsible for, and marks those devices as
108 void zorro_unregister_driver(struct zorro_driver *drv)
110 driver_unregister(&drv->driver);
112 EXPORT_SYMBOL(zorro_unregister_driver);
116 * zorro_bus_match - Tell if a Zorro device structure has a matching Zorro
117 * device id structure
118 * @ids: array of Zorro device id structures to search in
119 * @dev: the Zorro device structure to match against
121 * Used by a driver to check whether a Zorro device present in the
122 * system is in its list of supported devices.Returns the matching
123 * zorro_device_id structure or %NULL if there is no match.
126 static int zorro_bus_match(struct device *dev, struct device_driver *drv)
128 struct zorro_dev *z = to_zorro_dev(dev);
129 struct zorro_driver *zorro_drv = to_zorro_driver(drv);
130 const struct zorro_device_id *ids = zorro_drv->id_table;
136 if (ids->id == ZORRO_WILDCARD || ids->id == z->id)
143 static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env)
150 z = to_zorro_dev(dev);
154 if (add_uevent_var(env, "ZORRO_ID=%08X", z->id) ||
155 add_uevent_var(env, "ZORRO_SLOT_NAME=%s", dev_name(dev)) ||
156 add_uevent_var(env, "ZORRO_SLOT_ADDR=%04X", z->slotaddr) ||
157 add_uevent_var(env, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT, z->id))
163 struct bus_type zorro_bus_type = {
166 .match = zorro_bus_match,
167 .uevent = zorro_uevent,
168 .probe = zorro_device_probe,
169 .remove = zorro_device_remove,
171 EXPORT_SYMBOL(zorro_bus_type);
174 static int __init zorro_driver_init(void)
176 return bus_register(&zorro_bus_type);
179 postcore_initcall(zorro_driver_init);