Merge remote-tracking branch 'pm/linux-next'
[linux-2.6/next.git] / drivers / tc / tc-driver.c
blob16b5bae63c7490198ac07a0993603002cba8fb90
1 /*
2 * TURBOchannel driver services.
4 * Copyright (c) 2005 James Simmons
5 * Copyright (c) 2006 Maciej W. Rozycki
7 * Loosely based on drivers/dio/dio-driver.c and
8 * drivers/pci/pci-driver.c.
10 * This file is subject to the terms and conditions of the GNU
11 * General Public License. See the file "COPYING" in the main
12 * directory of this archive for more details.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/tc.h>
19 /**
20 * tc_register_driver - register a new TC driver
21 * @drv: the driver structure to register
23 * Adds the driver structure to the list of registered drivers
24 * Returns a negative value on error, otherwise 0.
25 * If no error occurred, the driver remains registered even if
26 * no device was claimed during registration.
28 int tc_register_driver(struct tc_driver *tdrv)
30 return driver_register(&tdrv->driver);
32 EXPORT_SYMBOL(tc_register_driver);
34 /**
35 * tc_unregister_driver - unregister a TC driver
36 * @drv: the driver structure to unregister
38 * Deletes the driver structure from the list of registered TC drivers,
39 * gives it a chance to clean up by calling its remove() function for
40 * each device it was responsible for, and marks those devices as
41 * driverless.
43 void tc_unregister_driver(struct tc_driver *tdrv)
45 driver_unregister(&tdrv->driver);
47 EXPORT_SYMBOL(tc_unregister_driver);
49 /**
50 * tc_match_device - tell if a TC device structure has a matching
51 * TC device ID structure
52 * @tdrv: the TC driver to earch for matching TC device ID strings
53 * @tdev: the TC device structure to match against
55 * Used by a driver to check whether a TC device present in the
56 * system is in its list of supported devices. Returns the matching
57 * tc_device_id structure or %NULL if there is no match.
59 const struct tc_device_id *tc_match_device(struct tc_driver *tdrv,
60 struct tc_dev *tdev)
62 const struct tc_device_id *id = tdrv->id_table;
64 if (id) {
65 while (id->name[0] || id->vendor[0]) {
66 if (strcmp(tdev->name, id->name) == 0 &&
67 strcmp(tdev->vendor, id->vendor) == 0)
68 return id;
69 id++;
72 return NULL;
74 EXPORT_SYMBOL(tc_match_device);
76 /**
77 * tc_bus_match - Tell if a device structure has a matching
78 * TC device ID structure
79 * @dev: the device structure to match against
80 * @drv: the device driver to search for matching TC device ID strings
82 * Used by a driver to check whether a TC device present in the
83 * system is in its list of supported devices. Returns 1 if there
84 * is a match or 0 otherwise.
86 static int tc_bus_match(struct device *dev, struct device_driver *drv)
88 struct tc_dev *tdev = to_tc_dev(dev);
89 struct tc_driver *tdrv = to_tc_driver(drv);
90 const struct tc_device_id *id;
92 id = tc_match_device(tdrv, tdev);
93 if (id)
94 return 1;
96 return 0;
99 struct bus_type tc_bus_type = {
100 .name = "tc",
101 .match = tc_bus_match,
103 EXPORT_SYMBOL(tc_bus_type);
105 static int __init tc_driver_init(void)
107 return bus_register(&tc_bus_type);
110 postcore_initcall(tc_driver_init);