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