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