umc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * UWB Multi-interface Controller support.
  3. *
  4. * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5. *
  6. * This file is released under the GPLv2
  7. *
  8. * UMC (UWB Multi-interface Controller) capabilities (e.g., radio
  9. * controller, host controller) are presented as devices on the "umc"
  10. * bus.
  11. *
  12. * The radio controller is not strictly a UMC capability but it's
  13. * useful to present it as such.
  14. *
  15. * References:
  16. *
  17. * [WHCI] Wireless Host Controller Interface Specification for
  18. * Certified Wireless Universal Serial Bus, revision 0.95.
  19. *
  20. * How this works is kind of convoluted but simple. The whci.ko driver
  21. * loads when WHCI devices are detected. These WHCI devices expose
  22. * many devices in the same PCI function (they couldn't have reused
  23. * functions, no), so for each PCI function that exposes these many
  24. * devices, whci ceates a umc_dev [whci_probe() -> whci_add_cap()]
  25. * with umc_device_create() and adds it to the bus with
  26. * umc_device_register().
  27. *
  28. * umc_device_register() calls device_register() which will push the
  29. * bus management code to load your UMC driver's somehting_probe()
  30. * that you have registered for that capability code.
  31. *
  32. * Now when the WHCI device is removed, whci_remove() will go over
  33. * each umc_dev assigned to each of the PCI function's capabilities
  34. * and through whci_del_cap() call umc_device_unregister() each
  35. * created umc_dev. Of course, if you are bound to the device, your
  36. * driver's something_remove() will be called.
  37. */
  38. #ifndef _LINUX_UWB_UMC_H_
  39. #define _LINUX_UWB_UMC_H_
  40. #include <linux/device.h>
  41. #include <linux/pci.h>
  42. /*
  43. * UMC capability IDs.
  44. *
  45. * 0x00 is reserved so use it for the radio controller device.
  46. *
  47. * [WHCI] table 2-8
  48. */
  49. #define UMC_CAP_ID_WHCI_RC 0x00 /* radio controller */
  50. #define UMC_CAP_ID_WHCI_WUSB_HC 0x01 /* WUSB host controller */
  51. /**
  52. * struct umc_dev - UMC capability device
  53. *
  54. * @version: version of the specification this capability conforms to.
  55. * @cap_id: capability ID.
  56. * @bar: PCI Bar (64 bit) where the resource lies
  57. * @resource: register space resource.
  58. * @irq: interrupt line.
  59. */
  60. struct umc_dev {
  61. u16 version;
  62. u8 cap_id;
  63. u8 bar;
  64. struct resource resource;
  65. unsigned irq;
  66. struct device dev;
  67. };
  68. #define to_umc_dev(d) container_of(d, struct umc_dev, dev)
  69. /**
  70. * struct umc_driver - UMC capability driver
  71. * @cap_id: supported capability ID.
  72. * @match: driver specific capability matching function.
  73. * @match_data: driver specific data for match() (e.g., a
  74. * table of pci_device_id's if umc_match_pci_id() is used).
  75. */
  76. struct umc_driver {
  77. char *name;
  78. u8 cap_id;
  79. int (*match)(struct umc_driver *, struct umc_dev *);
  80. const void *match_data;
  81. int (*probe)(struct umc_dev *);
  82. void (*remove)(struct umc_dev *);
  83. int (*pre_reset)(struct umc_dev *);
  84. int (*post_reset)(struct umc_dev *);
  85. struct device_driver driver;
  86. };
  87. #define to_umc_driver(d) container_of(d, struct umc_driver, driver)
  88. extern struct bus_type umc_bus_type;
  89. struct umc_dev *umc_device_create(struct device *parent, int n);
  90. int __must_check umc_device_register(struct umc_dev *umc);
  91. void umc_device_unregister(struct umc_dev *umc);
  92. int __must_check __umc_driver_register(struct umc_driver *umc_drv,
  93. struct module *mod,
  94. const char *mod_name);
  95. /**
  96. * umc_driver_register - register a UMC capabiltity driver.
  97. * @umc_drv: pointer to the driver.
  98. */
  99. #define umc_driver_register(umc_drv) \
  100. __umc_driver_register(umc_drv, THIS_MODULE, KBUILD_MODNAME)
  101. void umc_driver_unregister(struct umc_driver *umc_drv);
  102. /*
  103. * Utility function you can use to match (umc_driver->match) against a
  104. * null-terminated array of 'struct pci_device_id' in
  105. * umc_driver->match_data.
  106. */
  107. int umc_match_pci_id(struct umc_driver *umc_drv, struct umc_dev *umc);
  108. /**
  109. * umc_parent_pci_dev - return the UMC's parent PCI device or NULL if none
  110. * @umc_dev: UMC device whose parent PCI device we are looking for
  111. *
  112. * DIRTY!!! DON'T RELY ON THIS
  113. *
  114. * FIXME: This is as dirty as it gets, but we need some way to check
  115. * the correct type of umc_dev->parent (so that for example, we can
  116. * cast to pci_dev). Casting to pci_dev is necessary because at some
  117. * point we need to request resources from the device. Mapping is
  118. * easily over come (ioremap and stuff are bus agnostic), but hooking
  119. * up to some error handlers (such as pci error handlers) might need
  120. * this.
  121. *
  122. * THIS might (probably will) be removed in the future, so don't count
  123. * on it.
  124. */
  125. static inline struct pci_dev *umc_parent_pci_dev(struct umc_dev *umc_dev)
  126. {
  127. struct pci_dev *pci_dev = NULL;
  128. if (dev_is_pci(umc_dev->dev.parent))
  129. pci_dev = to_pci_dev(umc_dev->dev.parent);
  130. return pci_dev;
  131. }
  132. /**
  133. * umc_dev_get() - reference a UMC device.
  134. * @umc_dev: Pointer to UMC device.
  135. *
  136. * NOTE: we are assuming in this whole scheme that the parent device
  137. * is referenced at _probe() time and unreferenced at _remove()
  138. * time by the parent's subsystem.
  139. */
  140. static inline struct umc_dev *umc_dev_get(struct umc_dev *umc_dev)
  141. {
  142. get_device(&umc_dev->dev);
  143. return umc_dev;
  144. }
  145. /**
  146. * umc_dev_put() - unreference a UMC device.
  147. * @umc_dev: Pointer to UMC device.
  148. */
  149. static inline void umc_dev_put(struct umc_dev *umc_dev)
  150. {
  151. put_device(&umc_dev->dev);
  152. }
  153. /**
  154. * umc_set_drvdata - set UMC device's driver data.
  155. * @umc_dev: Pointer to UMC device.
  156. * @data: Data to set.
  157. */
  158. static inline void umc_set_drvdata(struct umc_dev *umc_dev, void *data)
  159. {
  160. dev_set_drvdata(&umc_dev->dev, data);
  161. }
  162. /**
  163. * umc_get_drvdata - recover UMC device's driver data.
  164. * @umc_dev: Pointer to UMC device.
  165. */
  166. static inline void *umc_get_drvdata(struct umc_dev *umc_dev)
  167. {
  168. return dev_get_drvdata(&umc_dev->dev);
  169. }
  170. int umc_controller_reset(struct umc_dev *umc);
  171. #endif /* #ifndef _LINUX_UWB_UMC_H_ */