/*1* DIO Driver Services2*3* Copyright (C) 2004 Jochen Friedrich4*5* Loosely based on drivers/pci/pci-driver.c and drivers/zorro/zorro-driver.c6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file COPYING in the main directory of this archive9* for more details.10*/1112#include <linux/init.h>13#include <linux/module.h>14#include <linux/dio.h>151617/**18* dio_match_device - Tell if a DIO device structure has a matching DIO device id structure19* @ids: array of DIO device id structures to search in20* @d: the DIO device structure to match against21*22* Used by a driver to check whether a DIO device present in the23* system is in its list of supported devices. Returns the matching24* dio_device_id structure or %NULL if there is no match.25*/2627static const struct dio_device_id *28dio_match_device(const struct dio_device_id *ids,29const struct dio_dev *d)30{31while (ids->id) {32if (ids->id == DIO_WILDCARD)33return ids;34if (DIO_NEEDSSECID(ids->id & 0xff)) {35if (ids->id == d->id)36return ids;37} else {38if ((ids->id & 0xff) == (d->id & 0xff))39return ids;40}41ids++;42}43return NULL;44}4546static int dio_device_probe(struct device *dev)47{48int error = 0;49struct dio_driver *drv = to_dio_driver(dev->driver);50struct dio_dev *d = to_dio_dev(dev);5152if (!d->driver && drv->probe) {53const struct dio_device_id *id;5455id = dio_match_device(drv->id_table, d);56if (id)57error = drv->probe(d, id);58if (error >= 0) {59d->driver = drv;60error = 0;61}62}63return error;64}656667/**68* dio_register_driver - register a new DIO driver69* @drv: the driver structure to register70*71* Adds the driver structure to the list of registered drivers72* Returns zero or a negative error value.73*/7475int dio_register_driver(struct dio_driver *drv)76{77/* initialize common driver fields */78drv->driver.name = drv->name;79drv->driver.bus = &dio_bus_type;8081/* register with core */82return driver_register(&drv->driver);83}848586/**87* dio_unregister_driver - unregister a DIO driver88* @drv: the driver structure to unregister89*90* Deletes the driver structure from the list of registered DIO drivers,91* gives it a chance to clean up by calling its remove() function for92* each device it was responsible for, and marks those devices as93* driverless.94*/9596void dio_unregister_driver(struct dio_driver *drv)97{98driver_unregister(&drv->driver);99}100101102/**103* dio_bus_match - Tell if a DIO device structure has a matching DIO device id structure104* @dev: the DIO device structure to match against105* @drv: the &device_driver that points to the array of DIO device id structures to search106*107* Used by the driver core to check whether a DIO device present in the108* system is in a driver's list of supported devices. Returns 1 if supported,109* and 0 if there is no match.110*/111112static int dio_bus_match(struct device *dev, const struct device_driver *drv)113{114struct dio_dev *d = to_dio_dev(dev);115const struct dio_driver *dio_drv = to_dio_driver(drv);116const struct dio_device_id *ids = dio_drv->id_table;117118if (!ids)119return 0;120121return dio_match_device(ids, d) ? 1 : 0;122}123124125const struct bus_type dio_bus_type = {126.name = "dio",127.match = dio_bus_match,128.probe = dio_device_probe,129};130131132static int __init dio_driver_init(void)133{134return bus_register(&dio_bus_type);135}136137postcore_initcall(dio_driver_init);138139EXPORT_SYMBOL(dio_register_driver);140EXPORT_SYMBOL(dio_unregister_driver);141EXPORT_SYMBOL(dio_bus_type);142143144