0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/init.h>
0014 #include <linux/module.h>
0015 #include <linux/zorro.h>
0016
0017 #include "zorro.h"
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 static const struct zorro_device_id *
0032 zorro_match_device(const struct zorro_device_id *ids,
0033 const struct zorro_dev *z)
0034 {
0035 while (ids->id) {
0036 if (ids->id == ZORRO_WILDCARD || ids->id == z->id)
0037 return ids;
0038 ids++;
0039 }
0040 return NULL;
0041 }
0042
0043
0044 static int zorro_device_probe(struct device *dev)
0045 {
0046 int error = 0;
0047 struct zorro_driver *drv = to_zorro_driver(dev->driver);
0048 struct zorro_dev *z = to_zorro_dev(dev);
0049
0050 if (drv->probe) {
0051 const struct zorro_device_id *id;
0052
0053 id = zorro_match_device(drv->id_table, z);
0054 if (id)
0055 error = drv->probe(z, id);
0056 if (error >= 0)
0057 error = 0;
0058 }
0059 return error;
0060 }
0061
0062
0063 static void zorro_device_remove(struct device *dev)
0064 {
0065 struct zorro_dev *z = to_zorro_dev(dev);
0066 struct zorro_driver *drv = to_zorro_driver(dev->driver);
0067
0068 if (drv->remove)
0069 drv->remove(z);
0070 }
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 int zorro_register_driver(struct zorro_driver *drv)
0082 {
0083
0084 drv->driver.name = drv->name;
0085 drv->driver.bus = &zorro_bus_type;
0086
0087
0088 return driver_register(&drv->driver);
0089 }
0090 EXPORT_SYMBOL(zorro_register_driver);
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 void zorro_unregister_driver(struct zorro_driver *drv)
0104 {
0105 driver_unregister(&drv->driver);
0106 }
0107 EXPORT_SYMBOL(zorro_unregister_driver);
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 static int zorro_bus_match(struct device *dev, struct device_driver *drv)
0122 {
0123 struct zorro_dev *z = to_zorro_dev(dev);
0124 struct zorro_driver *zorro_drv = to_zorro_driver(drv);
0125 const struct zorro_device_id *ids = zorro_drv->id_table;
0126
0127 if (!ids)
0128 return 0;
0129
0130 return !!zorro_match_device(ids, z);
0131 }
0132
0133 static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env)
0134 {
0135 struct zorro_dev *z;
0136
0137 if (!dev)
0138 return -ENODEV;
0139
0140 z = to_zorro_dev(dev);
0141 if (!z)
0142 return -ENODEV;
0143
0144 if (add_uevent_var(env, "ZORRO_ID=%08X", z->id) ||
0145 add_uevent_var(env, "ZORRO_SLOT_NAME=%s", dev_name(dev)) ||
0146 add_uevent_var(env, "ZORRO_SLOT_ADDR=%04X", z->slotaddr) ||
0147 add_uevent_var(env, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT, z->id))
0148 return -ENOMEM;
0149
0150 return 0;
0151 }
0152
0153 struct bus_type zorro_bus_type = {
0154 .name = "zorro",
0155 .dev_name = "zorro",
0156 .dev_groups = zorro_device_attribute_groups,
0157 .match = zorro_bus_match,
0158 .uevent = zorro_uevent,
0159 .probe = zorro_device_probe,
0160 .remove = zorro_device_remove,
0161 };
0162 EXPORT_SYMBOL(zorro_bus_type);
0163
0164
0165 static int __init zorro_driver_init(void)
0166 {
0167 return bus_register(&zorro_bus_type);
0168 }
0169
0170 postcore_initcall(zorro_driver_init);
0171