tc-driver.c 3.0 KB

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