brintos

brintos / linux-shallow public Read only

0
0
Text · 3.0 KiB · 2f6d147 Raw
110 lines · c
1/*2 *	TURBOchannel driver services.3 *4 *	Copyright (c) 2005  James Simmons5 *	Copyright (c) 2006  Maciej W. Rozycki6 *7 *	Loosely based on drivers/dio/dio-driver.c and8 *	drivers/pci/pci-driver.c.9 *10 *	This file is subject to the terms and conditions of the GNU11 *	General Public License.  See the file "COPYING" in the main12 *	directory of this archive for more details.13 */14 15#include <linux/init.h>16#include <linux/module.h>17#include <linux/tc.h>18 19/**20 * tc_register_driver - register a new TC driver21 * @drv: the driver structure to register22 *23 * Adds the driver structure to the list of registered drivers24 * Returns a negative value on error, otherwise 0.25 * If no error occurred, the driver remains registered even if26 * no device was claimed during registration.27 */28int tc_register_driver(struct tc_driver *tdrv)29{30	return driver_register(&tdrv->driver);31}32EXPORT_SYMBOL(tc_register_driver);33 34/**35 * tc_unregister_driver - unregister a TC driver36 * @drv: the driver structure to unregister37 *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 for40 * each device it was responsible for, and marks those devices as41 * driverless.42 */43void tc_unregister_driver(struct tc_driver *tdrv)44{45	driver_unregister(&tdrv->driver);46}47EXPORT_SYMBOL(tc_unregister_driver);48 49/**50 * tc_match_device - tell if a TC device structure has a matching51 *                   TC device ID structure52 * @tdrv: the TC driver to earch for matching TC device ID strings53 * @tdev: the TC device structure to match against54 *55 * Used by a driver to check whether a TC device present in the56 * system is in its list of supported devices.  Returns the matching57 * tc_device_id structure or %NULL if there is no match.58 */59static const struct tc_device_id *tc_match_device(const struct tc_driver *tdrv,60						  struct tc_dev *tdev)61{62	const struct tc_device_id *id = tdrv->id_table;63 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++;70		}71	}72	return NULL;73}74 75/**76 * tc_bus_match - Tell if a device structure has a matching77 *                TC device ID structure78 * @dev: the device structure to match against79 * @drv: the device driver to search for matching TC device ID strings80 *81 * Used by a driver to check whether a TC device present in the82 * system is in its list of supported devices.  Returns 1 if there83 * is a match or 0 otherwise.84 */85static int tc_bus_match(struct device *dev, const struct device_driver *drv)86{87	struct tc_dev *tdev = to_tc_dev(dev);88	const struct tc_driver *tdrv = to_tc_driver(drv);89	const struct tc_device_id *id;90 91	id = tc_match_device(tdrv, tdev);92	if (id)93		return 1;94 95	return 0;96}97 98const struct bus_type tc_bus_type = {99	.name	= "tc",100	.match	= tc_bus_match,101};102EXPORT_SYMBOL(tc_bus_type);103 104static int __init tc_driver_init(void)105{106	return bus_register(&tc_bus_type);107}108 109postcore_initcall(tc_driver_init);110