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
)
42 static int zorro_device_probe(struct device
*dev
)
45 struct zorro_driver
*drv
= to_zorro_driver(dev
->driver
);
46 struct zorro_dev
*z
= to_zorro_dev(dev
);
48 if (!z
->driver
&& drv
->probe
) {
49 const struct zorro_device_id
*id
;
51 id
= zorro_match_device(drv
->id_table
, z
);
53 error
= drv
->probe(z
, id
);
63 static int zorro_device_remove(struct device
*dev
)
65 struct zorro_dev
*z
= to_zorro_dev(dev
);
66 struct zorro_driver
*drv
= to_zorro_driver(dev
->driver
);
78 * zorro_register_driver - register a new Zorro driver
79 * @drv: the driver structure to register
81 * Adds the driver structure to the list of registered drivers
82 * Returns zero or a negative error value.
85 int zorro_register_driver(struct zorro_driver
*drv
)
87 /* initialize common driver fields */
88 drv
->driver
.name
= drv
->name
;
89 drv
->driver
.bus
= &zorro_bus_type
;
91 /* register with core */
92 return driver_register(&drv
->driver
);
97 * zorro_unregister_driver - unregister a zorro driver
98 * @drv: the driver structure to unregister
100 * Deletes the driver structure from the list of registered Zorro drivers,
101 * gives it a chance to clean up by calling its remove() function for
102 * each device it was responsible for, and marks those devices as
106 void zorro_unregister_driver(struct zorro_driver
*drv
)
108 driver_unregister(&drv
->driver
);
113 * zorro_bus_match - Tell if a Zorro device structure has a matching Zorro
114 * device id structure
115 * @ids: array of Zorro device id structures to search in
116 * @dev: the Zorro device structure to match against
118 * Used by a driver to check whether a Zorro device present in the
119 * system is in its list of supported devices.Returns the matching
120 * zorro_device_id structure or %NULL if there is no match.
123 static int zorro_bus_match(struct device
*dev
, struct device_driver
*drv
)
125 struct zorro_dev
*z
= to_zorro_dev(dev
);
126 struct zorro_driver
*zorro_drv
= to_zorro_driver(drv
);
127 const struct zorro_device_id
*ids
= zorro_drv
->id_table
;
133 if (ids
->id
== ZORRO_WILDCARD
|| ids
->id
== z
->id
)
141 struct bus_type zorro_bus_type
= {
143 .match
= zorro_bus_match
,
144 .probe
= zorro_device_probe
,
145 .remove
= zorro_device_remove
,
149 static int __init
zorro_driver_init(void)
151 return bus_register(&zorro_bus_type
);
154 postcore_initcall(zorro_driver_init
);
156 EXPORT_SYMBOL(zorro_match_device
);
157 EXPORT_SYMBOL(zorro_register_driver
);
158 EXPORT_SYMBOL(zorro_unregister_driver
);
159 EXPORT_SYMBOL(zorro_dev_driver
);
160 EXPORT_SYMBOL(zorro_bus_type
);