diff options
-rw-r--r-- | Documentation/DocBook/usb.tmpl | 1 | ||||
-rw-r--r-- | drivers/usb/core/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 338 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 311 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 3 |
5 files changed, 343 insertions, 312 deletions
diff --git a/Documentation/DocBook/usb.tmpl b/Documentation/DocBook/usb.tmpl index 15ce0f21e5e0..320af25de3a2 100644 --- a/Documentation/DocBook/usb.tmpl +++ b/Documentation/DocBook/usb.tmpl | |||
@@ -253,6 +253,7 @@ | |||
253 | !Edrivers/usb/core/urb.c | 253 | !Edrivers/usb/core/urb.c |
254 | !Edrivers/usb/core/message.c | 254 | !Edrivers/usb/core/message.c |
255 | !Edrivers/usb/core/file.c | 255 | !Edrivers/usb/core/file.c |
256 | !Edrivers/usb/core/driver.c | ||
256 | !Edrivers/usb/core/usb.c | 257 | !Edrivers/usb/core/usb.c |
257 | !Edrivers/usb/core/hub.c | 258 | !Edrivers/usb/core/hub.c |
258 | </chapter> | 259 | </chapter> |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 86d5c380892d..28329ddf187c 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for USB Core files and filesystem | 2 | # Makefile for USB Core files and filesystem |
3 | # | 3 | # |
4 | 4 | ||
5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o \ | 5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ |
6 | config.o file.o buffer.o sysfs.o devio.o notify.o | 6 | config.o file.o buffer.o sysfs.o devio.o notify.o |
7 | 7 | ||
8 | ifeq ($(CONFIG_PCI),y) | 8 | ifeq ($(CONFIG_PCI),y) |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c new file mode 100644 index 000000000000..921a21be651d --- /dev/null +++ b/drivers/usb/core/driver.c | |||
@@ -0,0 +1,338 @@ | |||
1 | /* | ||
2 | * drivers/usb/driver.c - most of the driver model stuff for usb | ||
3 | * | ||
4 | * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de> | ||
5 | * | ||
6 | * based on drivers/usb/usb.c which had the following copyrights: | ||
7 | * (C) Copyright Linus Torvalds 1999 | ||
8 | * (C) Copyright Johannes Erdfelt 1999-2001 | ||
9 | * (C) Copyright Andreas Gal 1999 | ||
10 | * (C) Copyright Gregory P. Smith 1999 | ||
11 | * (C) Copyright Deti Fliegl 1999 (new USB architecture) | ||
12 | * (C) Copyright Randy Dunlap 2000 | ||
13 | * (C) Copyright David Brownell 2000-2004 | ||
14 | * (C) Copyright Yggdrasil Computing, Inc. 2000 | ||
15 | * (usb_device_id matching changes by Adam J. Richter) | ||
16 | * (C) Copyright Greg Kroah-Hartman 2002-2003 | ||
17 | * | ||
18 | * NOTE! This is not actually a driver at all, rather this is | ||
19 | * just a collection of helper routines that implement the | ||
20 | * generic USB things that the real drivers can use.. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/config.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/usb.h> | ||
27 | #include "hcd.h" | ||
28 | #include "usb.h" | ||
29 | |||
30 | static int generic_probe(struct device *dev) | ||
31 | { | ||
32 | return 0; | ||
33 | } | ||
34 | static int generic_remove(struct device *dev) | ||
35 | { | ||
36 | struct usb_device *udev = to_usb_device(dev); | ||
37 | |||
38 | /* if this is only an unbind, not a physical disconnect, then | ||
39 | * unconfigure the device */ | ||
40 | if (udev->state == USB_STATE_CONFIGURED) | ||
41 | usb_set_configuration(udev, 0); | ||
42 | |||
43 | /* in case the call failed or the device was suspended */ | ||
44 | if (udev->state >= USB_STATE_CONFIGURED) | ||
45 | usb_disable_device(udev, 0); | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | struct device_driver usb_generic_driver = { | ||
50 | .owner = THIS_MODULE, | ||
51 | .name = "usb", | ||
52 | .bus = &usb_bus_type, | ||
53 | .probe = generic_probe, | ||
54 | .remove = generic_remove, | ||
55 | }; | ||
56 | |||
57 | /* Fun hack to determine if the struct device is a | ||
58 | * usb device or a usb interface. */ | ||
59 | int usb_generic_driver_data; | ||
60 | |||
61 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
62 | static int usb_probe_interface(struct device *dev) | ||
63 | { | ||
64 | struct usb_interface * intf = to_usb_interface(dev); | ||
65 | struct usb_driver * driver = to_usb_driver(dev->driver); | ||
66 | const struct usb_device_id *id; | ||
67 | int error = -ENODEV; | ||
68 | |||
69 | dev_dbg(dev, "%s\n", __FUNCTION__); | ||
70 | |||
71 | if (!driver->probe) | ||
72 | return error; | ||
73 | /* FIXME we'd much prefer to just resume it ... */ | ||
74 | if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED) | ||
75 | return -EHOSTUNREACH; | ||
76 | |||
77 | id = usb_match_id(intf, driver->id_table); | ||
78 | if (id) { | ||
79 | dev_dbg(dev, "%s - got id\n", __FUNCTION__); | ||
80 | |||
81 | /* Interface "power state" doesn't correspond to any hardware | ||
82 | * state whatsoever. We use it to record when it's bound to | ||
83 | * a driver that may start I/0: it's not frozen/quiesced. | ||
84 | */ | ||
85 | mark_active(intf); | ||
86 | intf->condition = USB_INTERFACE_BINDING; | ||
87 | error = driver->probe(intf, id); | ||
88 | if (error) { | ||
89 | mark_quiesced(intf); | ||
90 | intf->condition = USB_INTERFACE_UNBOUND; | ||
91 | } else | ||
92 | intf->condition = USB_INTERFACE_BOUND; | ||
93 | } | ||
94 | |||
95 | return error; | ||
96 | } | ||
97 | |||
98 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
99 | static int usb_unbind_interface(struct device *dev) | ||
100 | { | ||
101 | struct usb_interface *intf = to_usb_interface(dev); | ||
102 | struct usb_driver *driver = to_usb_driver(intf->dev.driver); | ||
103 | |||
104 | intf->condition = USB_INTERFACE_UNBINDING; | ||
105 | |||
106 | /* release all urbs for this interface */ | ||
107 | usb_disable_interface(interface_to_usbdev(intf), intf); | ||
108 | |||
109 | if (driver && driver->disconnect) | ||
110 | driver->disconnect(intf); | ||
111 | |||
112 | /* reset other interface state */ | ||
113 | usb_set_interface(interface_to_usbdev(intf), | ||
114 | intf->altsetting[0].desc.bInterfaceNumber, | ||
115 | 0); | ||
116 | usb_set_intfdata(intf, NULL); | ||
117 | intf->condition = USB_INTERFACE_UNBOUND; | ||
118 | mark_quiesced(intf); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * usb_match_id - find first usb_device_id matching device or interface | ||
125 | * @interface: the interface of interest | ||
126 | * @id: array of usb_device_id structures, terminated by zero entry | ||
127 | * | ||
128 | * usb_match_id searches an array of usb_device_id's and returns | ||
129 | * the first one matching the device or interface, or null. | ||
130 | * This is used when binding (or rebinding) a driver to an interface. | ||
131 | * Most USB device drivers will use this indirectly, through the usb core, | ||
132 | * but some layered driver frameworks use it directly. | ||
133 | * These device tables are exported with MODULE_DEVICE_TABLE, through | ||
134 | * modutils, to support the driver loading functionality of USB hotplugging. | ||
135 | * | ||
136 | * What Matches: | ||
137 | * | ||
138 | * The "match_flags" element in a usb_device_id controls which | ||
139 | * members are used. If the corresponding bit is set, the | ||
140 | * value in the device_id must match its corresponding member | ||
141 | * in the device or interface descriptor, or else the device_id | ||
142 | * does not match. | ||
143 | * | ||
144 | * "driver_info" is normally used only by device drivers, | ||
145 | * but you can create a wildcard "matches anything" usb_device_id | ||
146 | * as a driver's "modules.usbmap" entry if you provide an id with | ||
147 | * only a nonzero "driver_info" field. If you do this, the USB device | ||
148 | * driver's probe() routine should use additional intelligence to | ||
149 | * decide whether to bind to the specified interface. | ||
150 | * | ||
151 | * What Makes Good usb_device_id Tables: | ||
152 | * | ||
153 | * The match algorithm is very simple, so that intelligence in | ||
154 | * driver selection must come from smart driver id records. | ||
155 | * Unless you have good reasons to use another selection policy, | ||
156 | * provide match elements only in related groups, and order match | ||
157 | * specifiers from specific to general. Use the macros provided | ||
158 | * for that purpose if you can. | ||
159 | * | ||
160 | * The most specific match specifiers use device descriptor | ||
161 | * data. These are commonly used with product-specific matches; | ||
162 | * the USB_DEVICE macro lets you provide vendor and product IDs, | ||
163 | * and you can also match against ranges of product revisions. | ||
164 | * These are widely used for devices with application or vendor | ||
165 | * specific bDeviceClass values. | ||
166 | * | ||
167 | * Matches based on device class/subclass/protocol specifications | ||
168 | * are slightly more general; use the USB_DEVICE_INFO macro, or | ||
169 | * its siblings. These are used with single-function devices | ||
170 | * where bDeviceClass doesn't specify that each interface has | ||
171 | * its own class. | ||
172 | * | ||
173 | * Matches based on interface class/subclass/protocol are the | ||
174 | * most general; they let drivers bind to any interface on a | ||
175 | * multiple-function device. Use the USB_INTERFACE_INFO | ||
176 | * macro, or its siblings, to match class-per-interface style | ||
177 | * devices (as recorded in bDeviceClass). | ||
178 | * | ||
179 | * Within those groups, remember that not all combinations are | ||
180 | * meaningful. For example, don't give a product version range | ||
181 | * without vendor and product IDs; or specify a protocol without | ||
182 | * its associated class and subclass. | ||
183 | */ | ||
184 | const struct usb_device_id *usb_match_id(struct usb_interface *interface, | ||
185 | const struct usb_device_id *id) | ||
186 | { | ||
187 | struct usb_host_interface *intf; | ||
188 | struct usb_device *dev; | ||
189 | |||
190 | /* proc_connectinfo in devio.c may call us with id == NULL. */ | ||
191 | if (id == NULL) | ||
192 | return NULL; | ||
193 | |||
194 | intf = interface->cur_altsetting; | ||
195 | dev = interface_to_usbdev(interface); | ||
196 | |||
197 | /* It is important to check that id->driver_info is nonzero, | ||
198 | since an entry that is all zeroes except for a nonzero | ||
199 | id->driver_info is the way to create an entry that | ||
200 | indicates that the driver want to examine every | ||
201 | device and interface. */ | ||
202 | for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || | ||
203 | id->driver_info; id++) { | ||
204 | |||
205 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && | ||
206 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) | ||
207 | continue; | ||
208 | |||
209 | if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && | ||
210 | id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) | ||
211 | continue; | ||
212 | |||
213 | /* No need to test id->bcdDevice_lo != 0, since 0 is never | ||
214 | greater than any unsigned number. */ | ||
215 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && | ||
216 | (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) | ||
217 | continue; | ||
218 | |||
219 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && | ||
220 | (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) | ||
221 | continue; | ||
222 | |||
223 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && | ||
224 | (id->bDeviceClass != dev->descriptor.bDeviceClass)) | ||
225 | continue; | ||
226 | |||
227 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && | ||
228 | (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) | ||
229 | continue; | ||
230 | |||
231 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && | ||
232 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) | ||
233 | continue; | ||
234 | |||
235 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && | ||
236 | (id->bInterfaceClass != intf->desc.bInterfaceClass)) | ||
237 | continue; | ||
238 | |||
239 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && | ||
240 | (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) | ||
241 | continue; | ||
242 | |||
243 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && | ||
244 | (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) | ||
245 | continue; | ||
246 | |||
247 | return id; | ||
248 | } | ||
249 | |||
250 | return NULL; | ||
251 | } | ||
252 | EXPORT_SYMBOL_GPL(usb_match_id); | ||
253 | |||
254 | int usb_device_match(struct device *dev, struct device_driver *drv) | ||
255 | { | ||
256 | struct usb_interface *intf; | ||
257 | struct usb_driver *usb_drv; | ||
258 | const struct usb_device_id *id; | ||
259 | |||
260 | /* check for generic driver, which we don't match any device with */ | ||
261 | if (drv == &usb_generic_driver) | ||
262 | return 0; | ||
263 | |||
264 | intf = to_usb_interface(dev); | ||
265 | usb_drv = to_usb_driver(drv); | ||
266 | |||
267 | id = usb_match_id(intf, usb_drv->id_table); | ||
268 | if (id) | ||
269 | return 1; | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * usb_register - register a USB driver | ||
276 | * @new_driver: USB operations for the driver | ||
277 | * | ||
278 | * Registers a USB driver with the USB core. The list of unattached | ||
279 | * interfaces will be rescanned whenever a new driver is added, allowing | ||
280 | * the new driver to attach to any recognized devices. | ||
281 | * Returns a negative error code on failure and 0 on success. | ||
282 | * | ||
283 | * NOTE: if you want your driver to use the USB major number, you must call | ||
284 | * usb_register_dev() to enable that functionality. This function no longer | ||
285 | * takes care of that. | ||
286 | */ | ||
287 | int usb_register(struct usb_driver *new_driver) | ||
288 | { | ||
289 | int retval = 0; | ||
290 | |||
291 | if (usb_disabled()) | ||
292 | return -ENODEV; | ||
293 | |||
294 | new_driver->driver.name = (char *)new_driver->name; | ||
295 | new_driver->driver.bus = &usb_bus_type; | ||
296 | new_driver->driver.probe = usb_probe_interface; | ||
297 | new_driver->driver.remove = usb_unbind_interface; | ||
298 | new_driver->driver.owner = new_driver->owner; | ||
299 | |||
300 | usb_lock_all_devices(); | ||
301 | retval = driver_register(&new_driver->driver); | ||
302 | usb_unlock_all_devices(); | ||
303 | |||
304 | if (!retval) { | ||
305 | pr_info("%s: registered new driver %s\n", | ||
306 | usbcore_name, new_driver->name); | ||
307 | usbfs_update_special(); | ||
308 | } else { | ||
309 | printk(KERN_ERR "%s: error %d registering driver %s\n", | ||
310 | usbcore_name, retval, new_driver->name); | ||
311 | } | ||
312 | |||
313 | return retval; | ||
314 | } | ||
315 | EXPORT_SYMBOL_GPL(usb_register); | ||
316 | |||
317 | /** | ||
318 | * usb_deregister - unregister a USB driver | ||
319 | * @driver: USB operations of the driver to unregister | ||
320 | * Context: must be able to sleep | ||
321 | * | ||
322 | * Unlinks the specified driver from the internal USB driver list. | ||
323 | * | ||
324 | * NOTE: If you called usb_register_dev(), you still need to call | ||
325 | * usb_deregister_dev() to clean up your driver's allocated minor numbers, | ||
326 | * this * call will no longer do it for you. | ||
327 | */ | ||
328 | void usb_deregister(struct usb_driver *driver) | ||
329 | { | ||
330 | pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); | ||
331 | |||
332 | usb_lock_all_devices(); | ||
333 | driver_unregister(&driver->driver); | ||
334 | usb_unlock_all_devices(); | ||
335 | |||
336 | usbfs_update_special(); | ||
337 | } | ||
338 | EXPORT_SYMBOL_GPL(usb_deregister); | ||
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index e80ef9467825..294e9f127477 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -52,161 +52,6 @@ static int nousb; /* Disable USB when built into kernel image */ | |||
52 | static DECLARE_RWSEM(usb_all_devices_rwsem); | 52 | static DECLARE_RWSEM(usb_all_devices_rwsem); |
53 | 53 | ||
54 | 54 | ||
55 | static int generic_probe (struct device *dev) | ||
56 | { | ||
57 | return 0; | ||
58 | } | ||
59 | static int generic_remove (struct device *dev) | ||
60 | { | ||
61 | struct usb_device *udev = to_usb_device(dev); | ||
62 | |||
63 | /* if this is only an unbind, not a physical disconnect, then | ||
64 | * unconfigure the device */ | ||
65 | if (udev->state == USB_STATE_CONFIGURED) | ||
66 | usb_set_configuration(udev, 0); | ||
67 | |||
68 | /* in case the call failed or the device was suspended */ | ||
69 | if (udev->state >= USB_STATE_CONFIGURED) | ||
70 | usb_disable_device(udev, 0); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static struct device_driver usb_generic_driver = { | ||
75 | .owner = THIS_MODULE, | ||
76 | .name = "usb", | ||
77 | .bus = &usb_bus_type, | ||
78 | .probe = generic_probe, | ||
79 | .remove = generic_remove, | ||
80 | }; | ||
81 | |||
82 | static int usb_generic_driver_data; | ||
83 | |||
84 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
85 | static int usb_probe_interface(struct device *dev) | ||
86 | { | ||
87 | struct usb_interface * intf = to_usb_interface(dev); | ||
88 | struct usb_driver * driver = to_usb_driver(dev->driver); | ||
89 | const struct usb_device_id *id; | ||
90 | int error = -ENODEV; | ||
91 | |||
92 | dev_dbg(dev, "%s\n", __FUNCTION__); | ||
93 | |||
94 | if (!driver->probe) | ||
95 | return error; | ||
96 | /* FIXME we'd much prefer to just resume it ... */ | ||
97 | if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED) | ||
98 | return -EHOSTUNREACH; | ||
99 | |||
100 | id = usb_match_id (intf, driver->id_table); | ||
101 | if (id) { | ||
102 | dev_dbg (dev, "%s - got id\n", __FUNCTION__); | ||
103 | |||
104 | /* Interface "power state" doesn't correspond to any hardware | ||
105 | * state whatsoever. We use it to record when it's bound to | ||
106 | * a driver that may start I/0: it's not frozen/quiesced. | ||
107 | */ | ||
108 | mark_active(intf); | ||
109 | intf->condition = USB_INTERFACE_BINDING; | ||
110 | error = driver->probe (intf, id); | ||
111 | if (error) { | ||
112 | mark_quiesced(intf); | ||
113 | intf->condition = USB_INTERFACE_UNBOUND; | ||
114 | } else | ||
115 | intf->condition = USB_INTERFACE_BOUND; | ||
116 | } | ||
117 | |||
118 | return error; | ||
119 | } | ||
120 | |||
121 | /* called from driver core with usb_bus_type.subsys writelock */ | ||
122 | static int usb_unbind_interface(struct device *dev) | ||
123 | { | ||
124 | struct usb_interface *intf = to_usb_interface(dev); | ||
125 | struct usb_driver *driver = to_usb_driver(intf->dev.driver); | ||
126 | |||
127 | intf->condition = USB_INTERFACE_UNBINDING; | ||
128 | |||
129 | /* release all urbs for this interface */ | ||
130 | usb_disable_interface(interface_to_usbdev(intf), intf); | ||
131 | |||
132 | if (driver && driver->disconnect) | ||
133 | driver->disconnect(intf); | ||
134 | |||
135 | /* reset other interface state */ | ||
136 | usb_set_interface(interface_to_usbdev(intf), | ||
137 | intf->altsetting[0].desc.bInterfaceNumber, | ||
138 | 0); | ||
139 | usb_set_intfdata(intf, NULL); | ||
140 | intf->condition = USB_INTERFACE_UNBOUND; | ||
141 | mark_quiesced(intf); | ||
142 | |||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * usb_register - register a USB driver | ||
148 | * @new_driver: USB operations for the driver | ||
149 | * | ||
150 | * Registers a USB driver with the USB core. The list of unattached | ||
151 | * interfaces will be rescanned whenever a new driver is added, allowing | ||
152 | * the new driver to attach to any recognized devices. | ||
153 | * Returns a negative error code on failure and 0 on success. | ||
154 | * | ||
155 | * NOTE: if you want your driver to use the USB major number, you must call | ||
156 | * usb_register_dev() to enable that functionality. This function no longer | ||
157 | * takes care of that. | ||
158 | */ | ||
159 | int usb_register(struct usb_driver *new_driver) | ||
160 | { | ||
161 | int retval = 0; | ||
162 | |||
163 | if (nousb) | ||
164 | return -ENODEV; | ||
165 | |||
166 | new_driver->driver.name = (char *)new_driver->name; | ||
167 | new_driver->driver.bus = &usb_bus_type; | ||
168 | new_driver->driver.probe = usb_probe_interface; | ||
169 | new_driver->driver.remove = usb_unbind_interface; | ||
170 | new_driver->driver.owner = new_driver->owner; | ||
171 | |||
172 | usb_lock_all_devices(); | ||
173 | retval = driver_register(&new_driver->driver); | ||
174 | usb_unlock_all_devices(); | ||
175 | |||
176 | if (!retval) { | ||
177 | pr_info("%s: registered new driver %s\n", | ||
178 | usbcore_name, new_driver->name); | ||
179 | usbfs_update_special(); | ||
180 | } else { | ||
181 | printk(KERN_ERR "%s: error %d registering driver %s\n", | ||
182 | usbcore_name, retval, new_driver->name); | ||
183 | } | ||
184 | |||
185 | return retval; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * usb_deregister - unregister a USB driver | ||
190 | * @driver: USB operations of the driver to unregister | ||
191 | * Context: must be able to sleep | ||
192 | * | ||
193 | * Unlinks the specified driver from the internal USB driver list. | ||
194 | * | ||
195 | * NOTE: If you called usb_register_dev(), you still need to call | ||
196 | * usb_deregister_dev() to clean up your driver's allocated minor numbers, | ||
197 | * this * call will no longer do it for you. | ||
198 | */ | ||
199 | void usb_deregister(struct usb_driver *driver) | ||
200 | { | ||
201 | pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); | ||
202 | |||
203 | usb_lock_all_devices(); | ||
204 | driver_unregister (&driver->driver); | ||
205 | usb_unlock_all_devices(); | ||
206 | |||
207 | usbfs_update_special(); | ||
208 | } | ||
209 | |||
210 | /** | 55 | /** |
211 | * usb_ifnum_to_if - get the interface object with a given interface number | 56 | * usb_ifnum_to_if - get the interface object with a given interface number |
212 | * @dev: the device whose current configuration is considered | 57 | * @dev: the device whose current configuration is considered |
@@ -352,138 +197,6 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
352 | mark_quiesced(iface); | 197 | mark_quiesced(iface); |
353 | } | 198 | } |
354 | 199 | ||
355 | /** | ||
356 | * usb_match_id - find first usb_device_id matching device or interface | ||
357 | * @interface: the interface of interest | ||
358 | * @id: array of usb_device_id structures, terminated by zero entry | ||
359 | * | ||
360 | * usb_match_id searches an array of usb_device_id's and returns | ||
361 | * the first one matching the device or interface, or null. | ||
362 | * This is used when binding (or rebinding) a driver to an interface. | ||
363 | * Most USB device drivers will use this indirectly, through the usb core, | ||
364 | * but some layered driver frameworks use it directly. | ||
365 | * These device tables are exported with MODULE_DEVICE_TABLE, through | ||
366 | * modutils and "modules.usbmap", to support the driver loading | ||
367 | * functionality of USB hotplugging. | ||
368 | * | ||
369 | * What Matches: | ||
370 | * | ||
371 | * The "match_flags" element in a usb_device_id controls which | ||
372 | * members are used. If the corresponding bit is set, the | ||
373 | * value in the device_id must match its corresponding member | ||
374 | * in the device or interface descriptor, or else the device_id | ||
375 | * does not match. | ||
376 | * | ||
377 | * "driver_info" is normally used only by device drivers, | ||
378 | * but you can create a wildcard "matches anything" usb_device_id | ||
379 | * as a driver's "modules.usbmap" entry if you provide an id with | ||
380 | * only a nonzero "driver_info" field. If you do this, the USB device | ||
381 | * driver's probe() routine should use additional intelligence to | ||
382 | * decide whether to bind to the specified interface. | ||
383 | * | ||
384 | * What Makes Good usb_device_id Tables: | ||
385 | * | ||
386 | * The match algorithm is very simple, so that intelligence in | ||
387 | * driver selection must come from smart driver id records. | ||
388 | * Unless you have good reasons to use another selection policy, | ||
389 | * provide match elements only in related groups, and order match | ||
390 | * specifiers from specific to general. Use the macros provided | ||
391 | * for that purpose if you can. | ||
392 | * | ||
393 | * The most specific match specifiers use device descriptor | ||
394 | * data. These are commonly used with product-specific matches; | ||
395 | * the USB_DEVICE macro lets you provide vendor and product IDs, | ||
396 | * and you can also match against ranges of product revisions. | ||
397 | * These are widely used for devices with application or vendor | ||
398 | * specific bDeviceClass values. | ||
399 | * | ||
400 | * Matches based on device class/subclass/protocol specifications | ||
401 | * are slightly more general; use the USB_DEVICE_INFO macro, or | ||
402 | * its siblings. These are used with single-function devices | ||
403 | * where bDeviceClass doesn't specify that each interface has | ||
404 | * its own class. | ||
405 | * | ||
406 | * Matches based on interface class/subclass/protocol are the | ||
407 | * most general; they let drivers bind to any interface on a | ||
408 | * multiple-function device. Use the USB_INTERFACE_INFO | ||
409 | * macro, or its siblings, to match class-per-interface style | ||
410 | * devices (as recorded in bDeviceClass). | ||
411 | * | ||
412 | * Within those groups, remember that not all combinations are | ||
413 | * meaningful. For example, don't give a product version range | ||
414 | * without vendor and product IDs; or specify a protocol without | ||
415 | * its associated class and subclass. | ||
416 | */ | ||
417 | const struct usb_device_id * | ||
418 | usb_match_id(struct usb_interface *interface, const struct usb_device_id *id) | ||
419 | { | ||
420 | struct usb_host_interface *intf; | ||
421 | struct usb_device *dev; | ||
422 | |||
423 | /* proc_connectinfo in devio.c may call us with id == NULL. */ | ||
424 | if (id == NULL) | ||
425 | return NULL; | ||
426 | |||
427 | intf = interface->cur_altsetting; | ||
428 | dev = interface_to_usbdev(interface); | ||
429 | |||
430 | /* It is important to check that id->driver_info is nonzero, | ||
431 | since an entry that is all zeroes except for a nonzero | ||
432 | id->driver_info is the way to create an entry that | ||
433 | indicates that the driver want to examine every | ||
434 | device and interface. */ | ||
435 | for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || | ||
436 | id->driver_info; id++) { | ||
437 | |||
438 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && | ||
439 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) | ||
440 | continue; | ||
441 | |||
442 | if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && | ||
443 | id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) | ||
444 | continue; | ||
445 | |||
446 | /* No need to test id->bcdDevice_lo != 0, since 0 is never | ||
447 | greater than any unsigned number. */ | ||
448 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && | ||
449 | (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) | ||
450 | continue; | ||
451 | |||
452 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && | ||
453 | (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) | ||
454 | continue; | ||
455 | |||
456 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && | ||
457 | (id->bDeviceClass != dev->descriptor.bDeviceClass)) | ||
458 | continue; | ||
459 | |||
460 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && | ||
461 | (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) | ||
462 | continue; | ||
463 | |||
464 | if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && | ||
465 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) | ||
466 | continue; | ||
467 | |||
468 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && | ||
469 | (id->bInterfaceClass != intf->desc.bInterfaceClass)) | ||
470 | continue; | ||
471 | |||
472 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && | ||
473 | (id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) | ||
474 | continue; | ||
475 | |||
476 | if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && | ||
477 | (id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) | ||
478 | continue; | ||
479 | |||
480 | return id; | ||
481 | } | ||
482 | |||
483 | return NULL; | ||
484 | } | ||
485 | |||
486 | |||
487 | static int __find_interface(struct device * dev, void * data) | 200 | static int __find_interface(struct device * dev, void * data) |
488 | { | 201 | { |
489 | struct usb_interface ** ret = (struct usb_interface **)data; | 202 | struct usb_interface ** ret = (struct usb_interface **)data; |
@@ -521,27 +234,6 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) | |||
521 | return ret ? intf : NULL; | 234 | return ret ? intf : NULL; |
522 | } | 235 | } |
523 | 236 | ||
524 | static int usb_device_match (struct device *dev, struct device_driver *drv) | ||
525 | { | ||
526 | struct usb_interface *intf; | ||
527 | struct usb_driver *usb_drv; | ||
528 | const struct usb_device_id *id; | ||
529 | |||
530 | /* check for generic driver, which we don't match any device with */ | ||
531 | if (drv == &usb_generic_driver) | ||
532 | return 0; | ||
533 | |||
534 | intf = to_usb_interface(dev); | ||
535 | usb_drv = to_usb_driver(drv); | ||
536 | |||
537 | id = usb_match_id (intf, usb_drv->id_table); | ||
538 | if (id) | ||
539 | return 1; | ||
540 | |||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | |||
545 | #ifdef CONFIG_HOTPLUG | 237 | #ifdef CONFIG_HOTPLUG |
546 | 238 | ||
547 | /* | 239 | /* |
@@ -1598,8 +1290,6 @@ module_exit(usb_exit); | |||
1598 | * driver modules to use. | 1290 | * driver modules to use. |
1599 | */ | 1291 | */ |
1600 | 1292 | ||
1601 | EXPORT_SYMBOL(usb_register); | ||
1602 | EXPORT_SYMBOL(usb_deregister); | ||
1603 | EXPORT_SYMBOL(usb_disabled); | 1293 | EXPORT_SYMBOL(usb_disabled); |
1604 | 1294 | ||
1605 | EXPORT_SYMBOL_GPL(usb_get_intf); | 1295 | EXPORT_SYMBOL_GPL(usb_get_intf); |
@@ -1617,7 +1307,6 @@ EXPORT_SYMBOL(usb_unlock_device); | |||
1617 | 1307 | ||
1618 | EXPORT_SYMBOL(usb_driver_claim_interface); | 1308 | EXPORT_SYMBOL(usb_driver_claim_interface); |
1619 | EXPORT_SYMBOL(usb_driver_release_interface); | 1309 | EXPORT_SYMBOL(usb_driver_release_interface); |
1620 | EXPORT_SYMBOL(usb_match_id); | ||
1621 | EXPORT_SYMBOL(usb_find_interface); | 1310 | EXPORT_SYMBOL(usb_find_interface); |
1622 | EXPORT_SYMBOL(usb_ifnum_to_if); | 1311 | EXPORT_SYMBOL(usb_ifnum_to_if); |
1623 | EXPORT_SYMBOL(usb_altnum_to_altsetting); | 1312 | EXPORT_SYMBOL(usb_altnum_to_altsetting); |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 1c4a68499dce..98e85fb4d3b7 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -33,6 +33,9 @@ extern void usb_host_cleanup(void); | |||
33 | extern int usb_suspend_device(struct usb_device *dev); | 33 | extern int usb_suspend_device(struct usb_device *dev); |
34 | extern int usb_resume_device(struct usb_device *dev); | 34 | extern int usb_resume_device(struct usb_device *dev); |
35 | 35 | ||
36 | extern struct device_driver usb_generic_driver; | ||
37 | extern int usb_generic_driver_data; | ||
38 | extern int usb_device_match(struct device *dev, struct device_driver *drv); | ||
36 | 39 | ||
37 | /* Interfaces and their "power state" are owned by usbcore */ | 40 | /* Interfaces and their "power state" are owned by usbcore */ |
38 | 41 | ||