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>
21 * zorro_match_device - Tell if a Zorro device structure has a matching
22 * Zorro device id structure
23 * @ids: array of Zorro device id structures to search in
24 * @dev: the Zorro device structure to match against
26 * Used by a driver to check whether a Zorro device present in the
27 * system is in its list of supported devices. Returns the matching
28 * zorro_device_id structure or %NULL if there is no match.
31 const struct zorro_device_id
*
32 zorro_match_device(const struct zorro_device_id
*ids
,
33 const struct zorro_dev
*z
)
36 if (ids
->id
== ZORRO_WILDCARD
|| ids
->id
== z
->id
)
42 EXPORT_SYMBOL(zorro_match_device
);
45 static int zorro_device_probe(struct device
*dev
)
48 struct zorro_driver
*drv
= to_zorro_driver(dev
->driver
);
49 struct zorro_dev
*z
= to_zorro_dev(dev
);
51 if (!z
->driver
&& drv
->probe
) {
52 const struct zorro_device_id
*id
;
54 id
= zorro_match_device(drv
->id_table
, z
);
56 error
= drv
->probe(z
, id
);
66 static int zorro_device_remove(struct device
*dev
)
68 struct zorro_dev
*z
= to_zorro_dev(dev
);
69 struct zorro_driver
*drv
= to_zorro_driver(dev
->driver
);
81 * zorro_register_driver - register a new Zorro driver
82 * @drv: the driver structure to register
84 * Adds the driver structure to the list of registered drivers
85 * Returns zero or a negative error value.
88 int zorro_register_driver(struct zorro_driver
*drv
)
90 /* initialize common driver fields */
91 drv
->driver
.name
= drv
->name
;
92 drv
->driver
.bus
= &zorro_bus_type
;
94 /* register with core */
95 return driver_register(&drv
->driver
);
97 EXPORT_SYMBOL(zorro_register_driver
);
101 * zorro_unregister_driver - unregister a zorro driver
102 * @drv: the driver structure to unregister
104 * Deletes the driver structure from the list of registered Zorro drivers,
105 * gives it a chance to clean up by calling its remove() function for
106 * each device it was responsible for, and marks those devices as
110 void zorro_unregister_driver(struct zorro_driver
*drv
)
112 driver_unregister(&drv
->driver
);
114 EXPORT_SYMBOL(zorro_unregister_driver
);
118 * zorro_bus_match - Tell if a Zorro device structure has a matching Zorro
119 * device id structure
120 * @ids: array of Zorro device id structures to search in
121 * @dev: the Zorro device structure to match against
123 * Used by a driver to check whether a Zorro device present in the
124 * system is in its list of supported devices.Returns the matching
125 * zorro_device_id structure or %NULL if there is no match.
128 static int zorro_bus_match(struct device
*dev
, struct device_driver
*drv
)
130 struct zorro_dev
*z
= to_zorro_dev(dev
);
131 struct zorro_driver
*zorro_drv
= to_zorro_driver(drv
);
132 const struct zorro_device_id
*ids
= zorro_drv
->id_table
;
138 if (ids
->id
== ZORRO_WILDCARD
|| ids
->id
== z
->id
)
145 static int zorro_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
152 z
= to_zorro_dev(dev
);
156 if (add_uevent_var(env
, "ZORRO_ID=%08X", z
->id
) ||
157 add_uevent_var(env
, "ZORRO_SLOT_NAME=%s", dev_name(dev
)) ||
158 add_uevent_var(env
, "ZORRO_SLOT_ADDR=%04X", z
->slotaddr
) ||
159 add_uevent_var(env
, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT
, z
->id
))
165 struct bus_type zorro_bus_type
= {
168 .dev_groups
= zorro_device_attribute_groups
,
169 .match
= zorro_bus_match
,
170 .uevent
= zorro_uevent
,
171 .probe
= zorro_device_probe
,
172 .remove
= zorro_device_remove
,
174 EXPORT_SYMBOL(zorro_bus_type
);
177 static int __init
zorro_driver_init(void)
179 return bus_register(&zorro_bus_type
);
182 postcore_initcall(zorro_driver_init
);