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/dio.h>
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 static const struct dio_device_id *
0029 dio_match_device(const struct dio_device_id *ids,
0030 const struct dio_dev *d)
0031 {
0032 while (ids->id) {
0033 if (ids->id == DIO_WILDCARD)
0034 return ids;
0035 if (DIO_NEEDSSECID(ids->id & 0xff)) {
0036 if (ids->id == d->id)
0037 return ids;
0038 } else {
0039 if ((ids->id & 0xff) == (d->id & 0xff))
0040 return ids;
0041 }
0042 ids++;
0043 }
0044 return NULL;
0045 }
0046
0047 static int dio_device_probe(struct device *dev)
0048 {
0049 int error = 0;
0050 struct dio_driver *drv = to_dio_driver(dev->driver);
0051 struct dio_dev *d = to_dio_dev(dev);
0052
0053 if (!d->driver && drv->probe) {
0054 const struct dio_device_id *id;
0055
0056 id = dio_match_device(drv->id_table, d);
0057 if (id)
0058 error = drv->probe(d, id);
0059 if (error >= 0) {
0060 d->driver = drv;
0061 error = 0;
0062 }
0063 }
0064 return error;
0065 }
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 int dio_register_driver(struct dio_driver *drv)
0077 {
0078
0079 drv->driver.name = drv->name;
0080 drv->driver.bus = &dio_bus_type;
0081
0082
0083 return driver_register(&drv->driver);
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 void dio_unregister_driver(struct dio_driver *drv)
0098 {
0099 driver_unregister(&drv->driver);
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 static int dio_bus_match(struct device *dev, struct device_driver *drv)
0114 {
0115 struct dio_dev *d = to_dio_dev(dev);
0116 struct dio_driver *dio_drv = to_dio_driver(drv);
0117 const struct dio_device_id *ids = dio_drv->id_table;
0118
0119 if (!ids)
0120 return 0;
0121
0122 return dio_match_device(ids, d) ? 1 : 0;
0123 }
0124
0125
0126 struct bus_type dio_bus_type = {
0127 .name = "dio",
0128 .match = dio_bus_match,
0129 .probe = dio_device_probe,
0130 };
0131
0132
0133 static int __init dio_driver_init(void)
0134 {
0135 return bus_register(&dio_bus_type);
0136 }
0137
0138 postcore_initcall(dio_driver_init);
0139
0140 EXPORT_SYMBOL(dio_register_driver);
0141 EXPORT_SYMBOL(dio_unregister_driver);
0142 EXPORT_SYMBOL(dio_bus_type);