Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
umc.h
Go to the documentation of this file.
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 
39 #ifndef _LINUX_UWB_UMC_H_
40 #define _LINUX_UWB_UMC_H_
41 
42 #include <linux/device.h>
43 #include <linux/pci.h>
44 
45 /*
46  * UMC capability IDs.
47  *
48  * 0x00 is reserved so use it for the radio controller device.
49  *
50  * [WHCI] table 2-8
51  */
52 #define UMC_CAP_ID_WHCI_RC 0x00 /* radio controller */
53 #define UMC_CAP_ID_WHCI_WUSB_HC 0x01 /* WUSB host controller */
54 
64 struct umc_dev {
69  unsigned irq;
70  struct device dev;
71 };
72 
73 #define to_umc_dev(d) container_of(d, struct umc_dev, dev)
74 
82 struct umc_driver {
83  char *name;
85  int (*match)(struct umc_driver *, struct umc_dev *);
86  const void *match_data;
87 
88  int (*probe)(struct umc_dev *);
89  void (*remove)(struct umc_dev *);
91  int (*resume)(struct umc_dev *);
92  int (*pre_reset)(struct umc_dev *);
93  int (*post_reset)(struct umc_dev *);
94 
96 };
97 
98 #define to_umc_driver(d) container_of(d, struct umc_driver, driver)
99 
100 extern struct bus_type umc_bus_type;
101 
102 struct umc_dev *umc_device_create(struct device *parent, int n);
103 int __must_check umc_device_register(struct umc_dev *umc);
104 void umc_device_unregister(struct umc_dev *umc);
105 
106 int __must_check __umc_driver_register(struct umc_driver *umc_drv,
107  struct module *mod,
108  const char *mod_name);
109 
114 #define umc_driver_register(umc_drv) \
115  __umc_driver_register(umc_drv, THIS_MODULE, KBUILD_MODNAME)
116 
117 void umc_driver_unregister(struct umc_driver *umc_drv);
118 
119 /*
120  * Utility function you can use to match (umc_driver->match) against a
121  * null-terminated array of 'struct pci_device_id' in
122  * umc_driver->match_data.
123  */
124 int umc_match_pci_id(struct umc_driver *umc_drv, struct umc_dev *umc);
125 
143 static inline struct pci_dev *umc_parent_pci_dev(struct umc_dev *umc_dev)
144 {
145  struct pci_dev *pci_dev = NULL;
146  if (umc_dev->dev.parent->bus == &pci_bus_type)
147  pci_dev = to_pci_dev(umc_dev->dev.parent);
148  return pci_dev;
149 }
150 
159 static inline struct umc_dev *umc_dev_get(struct umc_dev *umc_dev)
160 {
161  get_device(&umc_dev->dev);
162  return umc_dev;
163 }
164 
169 static inline void umc_dev_put(struct umc_dev *umc_dev)
170 {
171  put_device(&umc_dev->dev);
172 }
173 
179 static inline void umc_set_drvdata(struct umc_dev *umc_dev, void *data)
180 {
181  dev_set_drvdata(&umc_dev->dev, data);
182 }
183 
188 static inline void *umc_get_drvdata(struct umc_dev *umc_dev)
189 {
190  return dev_get_drvdata(&umc_dev->dev);
191 }
192 
193 int umc_controller_reset(struct umc_dev *umc);
194 
195 #endif /* #ifndef _LINUX_UWB_UMC_H_ */