4 * (C) Copyright Linus Torvalds 1999
5 * (C) Copyright Johannes Erdfelt 1999
7 * NOTE! This is not actually a driver at all, rather this is
8 * just a collection of helper routines that implement the
9 * generic USB things that the real drivers can use..
11 * Think of this as a "USB library" rather than anything else.
12 * It should be considered a slave, with no callbacks. Callbacks
16 #include <linux/config.h>
17 #include <linux/string.h>
18 #include <linux/bitops.h>
19 #include <linux/malloc.h>
24 * We have a per-interface "registered driver" list.
26 static LIST_HEAD(usb_driver_list
);
27 static LIST_HEAD(usb_bus_list
);
29 int usb_register(struct usb_driver
*new_driver
)
31 struct list_head
*tmp
;
33 printk("usbcore: Registering new driver %s\n", new_driver
->name
);
35 /* Add it to the list of known drivers */
36 list_add(&new_driver
->driver_list
, &usb_driver_list
);
39 * We go through all existing devices, and see if any of them would
40 * be acceptable to the new driver.. This is done using a depth-first
41 * search for devices without a registered driver already, then
42 * running 'probe' with each of the drivers registered on every one
45 tmp
= usb_bus_list
.next
;
46 while (tmp
!= &usb_bus_list
) {
47 struct usb_bus
*bus
= list_entry(tmp
,struct usb_bus
, bus_list
);
50 usb_check_support(bus
->root_hub
);
55 void usb_deregister(struct usb_driver
*driver
)
57 struct list_head
*tmp
;
59 printk("usbcore: Deregistering driver %s\n", driver
->name
);
62 * first we remove the driver, to be sure it doesn't get used by
63 * another thread while we are stepping through removing entries
65 list_del(&driver
->driver_list
);
67 tmp
= usb_bus_list
.next
;
68 while (tmp
!= &usb_bus_list
) {
69 struct usb_bus
*bus
= list_entry(tmp
,struct usb_bus
,bus_list
);
72 usb_driver_purge(driver
, bus
->root_hub
);
77 * This function is part of a depth-first search down the device tree,
78 * removing any instances of a device driver.
80 static void usb_driver_purge(struct usb_driver
*driver
,struct usb_device
*dev
)
85 printk(KERN_ERR
"usbcore: null device being purged!!!\n");
89 for (i
=0; i
<USB_MAXCHILDREN
; i
++)
91 usb_driver_purge(driver
, dev
->children
[i
]);
93 /* now we check this device */
94 if (dev
->driver
== driver
) {
96 * Note: this is not the correct way to do this, this
97 * uninitializes and reinitializes EVERY driver
99 printk(KERN_INFO
"disconnect driverless device %d\n",
101 dev
->driver
->disconnect(dev
);
105 * This will go back through the list looking for a driver
106 * that can handle the device
108 usb_find_driver(dev
);
113 * New functions for (de)registering a controller
115 struct usb_bus
*usb_alloc_bus(struct usb_operations
*op
)
119 bus
= kmalloc(sizeof(*bus
), GFP_KERNEL
);
123 memset(&bus
->devmap
, 0, sizeof(struct usb_devmap
));
126 bus
->root_hub
= NULL
;
129 INIT_LIST_HEAD(&bus
->bus_list
);
134 void usb_free_bus(struct usb_bus
*bus
)
142 void usb_register_bus(struct usb_bus
*bus
)
144 proc_usb_add_bus(bus
);
146 /* Add it to the list of buses */
147 list_add(&bus
->bus_list
, &usb_bus_list
);
149 printk("New USB bus registered\n");
152 void usb_deregister_bus(struct usb_bus
*bus
)
155 * NOTE: make sure that all the devices are removed by the
156 * controller code, as well as having it call this when cleaning
159 list_del(&bus
->bus_list
);
161 proc_usb_remove_bus(bus
);
165 * This function is for doing a depth-first search for devices which
166 * have support, for dynamic loading of driver modules.
168 static void usb_check_support(struct usb_device
*dev
)
173 printk(KERN_ERR
"usbcore: null device being checked!!!\n");
177 for (i
=0; i
<USB_MAXCHILDREN
; i
++)
178 if (dev
->children
[i
])
179 usb_check_support(dev
->children
[i
]);
181 /* now we check this device */
182 if (!dev
->driver
&& dev
->devnum
> 0)
183 usb_find_driver(dev
);
186 * This entrypoint gets called for each new device.
188 * We now walk the list of registered USB drivers,
189 * looking for one that will accept this device as
192 static int usb_find_driver(struct usb_device
*dev
)
194 struct list_head
*tmp
= usb_driver_list
.next
;
196 while (tmp
!= &usb_driver_list
) {
197 struct usb_driver
*driver
= list_entry(tmp
, struct usb_driver
,
200 if (driver
->probe(dev
))
202 dev
->driver
= driver
;
207 * Ok, no driver accepted the device, so show the info
214 * Only HC's should call usb_alloc_dev and usb_free_dev directly
215 * Anybody may use usb_inc_dev_use or usb_dec_dev_use
217 struct usb_device
*usb_alloc_dev(struct usb_device
*parent
, struct usb_bus
*bus
)
219 struct usb_device
*dev
;
221 dev
= kmalloc(sizeof(*dev
), GFP_KERNEL
);
225 memset(dev
, 0, sizeof(*dev
));
228 dev
->parent
= parent
;
229 atomic_set(&dev
->refcnt
, 1);
231 dev
->bus
->op
->allocate(dev
);
236 void usb_free_dev(struct usb_device
*dev
)
238 if (atomic_dec_and_test(&dev
->refcnt
)) {
239 usb_destroy_configuration(dev
);
241 dev
->bus
->op
->deallocate(dev
);
246 void usb_inc_dev_use(struct usb_device
*dev
)
248 atomic_inc(&dev
->refcnt
);
251 static int usb_parse_endpoint(struct usb_device
*dev
, struct usb_endpoint_descriptor
*endpoint
, unsigned char *buffer
, int size
)
253 struct usb_descriptor_header
*header
;
256 header
= (struct usb_descriptor_header
*)buffer
;
258 /* Everything should be fine being passed into here, but we sanity */
260 if (header
->bLength
> size
) {
261 printk(KERN_ERR
"usb: ran out of descriptors parsing\n");
265 if (header
->bDescriptorType
!= USB_DT_ENDPOINT
) {
266 printk(KERN_INFO
"usb: unexpected descriptor 0x%X\n",
267 endpoint
->bDescriptorType
);
271 memcpy(endpoint
, buffer
, USB_DT_ENDPOINT_SIZE
);
272 le16_to_cpus(&endpoint
->wMaxPacketSize
);
274 buffer
+= header
->bLength
;
275 size
-= header
->bLength
;
276 parsed
+= header
->bLength
;
278 /* Skip over the rest of the Class Specific or Vendor Specific */
280 while (size
>= sizeof(struct usb_descriptor_header
)) {
281 header
= (struct usb_descriptor_header
*)buffer
;
283 if (header
->bLength
< 2) {
284 printk(KERN_ERR
"usb: invalid descriptor length of %d\n", header
->bLength
);
288 /* If we find another descriptor which is at or below us */
289 /* in the descriptor heirarchy then return */
290 if ((header
->bDescriptorType
== USB_DT_ENDPOINT
) ||
291 (header
->bDescriptorType
== USB_DT_INTERFACE
) ||
292 (header
->bDescriptorType
== USB_DT_CONFIG
) ||
293 (header
->bDescriptorType
== USB_DT_DEVICE
))
296 printk(KERN_INFO
"usb: skipping descriptor 0x%X\n",
297 header
->bDescriptorType
);
299 buffer
+= header
->bLength
;
300 size
-= header
->bLength
;
301 parsed
+= header
->bLength
;
308 static int usb_parse_hid(struct usb_device
*dev
, struct usb_hid_descriptor
*hid
, unsigned char *ptr
, int len
)
310 int parsed
= usb_expect_descriptor(ptr
, len
, USB_DT_HID
, ptr
[0]);
316 memcpy(hid
, ptr
+ parsed
, ptr
[parsed
]);
317 le16_to_cpus(&hid
->bcdHID
);
319 for (i
=0; i
<hid
->bNumDescriptors
; i
++)
320 le16_to_cpus(&(hid
->desc
[i
].wDescriptorLength
));
322 return parsed
+ ptr
[parsed
];
326 static int usb_parse_interface(struct usb_device
*dev
, struct usb_interface
*interface
, unsigned char *buffer
, int size
)
329 int retval
, parsed
= 0;
330 struct usb_descriptor_header
*header
;
331 struct usb_interface_descriptor
*ifp
;
333 interface
->act_altsetting
= 0;
334 interface
->num_altsetting
= 0;
336 interface
->altsetting
= kmalloc(sizeof(struct usb_interface_descriptor
) * USB_MAXALTSETTING
, GFP_KERNEL
);
337 if (!interface
->altsetting
) {
338 printk("couldn't kmalloc interface->altsetting\n");
343 ifp
= interface
->altsetting
+ interface
->num_altsetting
;
344 interface
->num_altsetting
++;
346 if (interface
->num_altsetting
>= USB_MAXALTSETTING
) {
347 printk(KERN_WARNING
"usb: too many alternate settings\n");
350 memcpy(ifp
, buffer
, USB_DT_INTERFACE_SIZE
);
352 /* Skip over the interface */
353 buffer
+= ifp
->bLength
;
354 parsed
+= ifp
->bLength
;
355 size
-= ifp
->bLength
;
357 /* Skip over at Interface class or vendor descriptors */
358 while (size
>= sizeof(struct usb_descriptor_header
)) {
359 header
= (struct usb_descriptor_header
*)buffer
;
361 if (header
->bLength
< 2) {
362 printk(KERN_ERR
"usb: invalid descriptor length of %d\n", header
->bLength
);
366 /* If we find another descriptor which is at or below us */
367 /* in the descriptor heirarchy then return */
368 if ((header
->bDescriptorType
== USB_DT_INTERFACE
) ||
369 (header
->bDescriptorType
== USB_DT_ENDPOINT
))
372 if ((header
->bDescriptorType
== USB_DT_CONFIG
) ||
373 (header
->bDescriptorType
== USB_DT_DEVICE
))
376 if (header
->bDescriptorType
== USB_DT_HID
)
377 printk(KERN_INFO
"usb: skipping HID descriptor\n");
379 printk(KERN_INFO
"usb: unexpected descriptor 0x%X\n",
380 header
->bDescriptorType
);
382 buffer
+= header
->bLength
;
383 parsed
+= header
->bLength
;
384 size
-= header
->bLength
;
387 if (ifp
->bNumEndpoints
> USB_MAXENDPOINTS
) {
388 printk(KERN_WARNING
"usb: too many endpoints\n");
392 ifp
->endpoint
= (struct usb_endpoint_descriptor
*)
393 kmalloc(ifp
->bNumEndpoints
*
394 sizeof(struct usb_endpoint_descriptor
), GFP_KERNEL
);
395 if (!ifp
->endpoint
) {
396 printk(KERN_WARNING
"usb: out of memory\n");
400 memset(ifp
->endpoint
, 0, ifp
->bNumEndpoints
*
401 sizeof(struct usb_endpoint_descriptor
));
403 for (i
= 0; i
< ifp
->bNumEndpoints
; i
++) {
404 header
= (struct usb_descriptor_header
*)buffer
;
406 if (header
->bLength
> size
) {
407 printk(KERN_ERR
"usb: ran out of descriptors parsing\n");
411 retval
= usb_parse_endpoint(dev
, ifp
->endpoint
+ i
, buffer
, size
);
420 /* We check to see if it's an alternate to this one */
421 ifp
= (struct usb_interface_descriptor
*)buffer
;
422 if (size
< USB_DT_INTERFACE_SIZE
||
423 ifp
->bDescriptorType
!= USB_DT_INTERFACE
||
424 !ifp
->bAlternateSetting
)
431 static int usb_parse_configuration(struct usb_device
*dev
, struct usb_config_descriptor
*config
, char *buffer
)
436 struct usb_descriptor_header
*header
;
438 memcpy(config
, buffer
, USB_DT_INTERFACE_SIZE
);
440 le16_to_cpus(&config
->wTotalLength
);
441 size
= config
->wTotalLength
;
443 if (config
->bNumInterfaces
> USB_MAXINTERFACES
) {
444 printk(KERN_WARNING
"usb: too many interfaces\n");
448 config
->interface
= (struct usb_interface
*)
449 kmalloc(config
->bNumInterfaces
*
450 sizeof(struct usb_interface
), GFP_KERNEL
);
451 if (!config
->interface
) {
452 printk(KERN_WARNING
"usb: out of memory\n");
456 memset(config
->interface
, 0,
457 config
->bNumInterfaces
*sizeof(struct usb_interface_descriptor
));
459 buffer
+= config
->bLength
;
460 size
-= config
->bLength
;
462 for (i
= 0; i
< config
->bNumInterfaces
; i
++) {
463 header
= (struct usb_descriptor_header
*)buffer
;
464 if (header
->bLength
> size
) {
465 printk(KERN_ERR
"usb: ran out of descriptors parsing\n");
469 if (header
->bDescriptorType
!= USB_DT_INTERFACE
) {
470 printk(KERN_INFO
"usb: unexpected descriptor 0x%X\n",
471 header
->bDescriptorType
);
473 buffer
+= header
->bLength
;
474 size
-= header
->bLength
;
478 retval
= usb_parse_interface(dev
, config
->interface
+ i
, buffer
, size
);
489 void usb_destroy_configuration(struct usb_device
*dev
)
496 for (c
= 0; c
< dev
->descriptor
.bNumConfigurations
; c
++) {
497 struct usb_config_descriptor
*cf
= &dev
->config
[c
];
502 for (i
= 0; i
< cf
->bNumInterfaces
; i
++) {
503 struct usb_interface
*ifp
=
506 if (!ifp
->altsetting
)
509 for (j
= 0; j
< ifp
->num_altsetting
; j
++) {
510 struct usb_interface_descriptor
*as
=
518 kfree(ifp
->altsetting
);
520 kfree(cf
->interface
);
530 void usb_init_root_hub(struct usb_device
*dev
)
537 * Something got disconnected. Get rid of it, and all of its children.
539 void usb_disconnect(struct usb_device
**pdev
)
541 struct usb_device
* dev
= *pdev
;
549 printk("USB disconnect on device %d\n", dev
->devnum
);
552 dev
->driver
->disconnect(dev
);
554 /* Free up all the children.. */
555 for (i
= 0; i
< USB_MAXCHILDREN
; i
++) {
556 struct usb_device
**child
= dev
->children
+ i
;
557 usb_disconnect(child
);
560 /* remove /proc/bus/usb entry */
561 proc_usb_remove_device(dev
);
563 /* Free up the device itself, including its device number */
565 clear_bit(dev
->devnum
, &dev
->bus
->devmap
.devicemap
);
571 * Connect a new USB device. This basically just initializes
572 * the USB device information and sets up the topology - it's
573 * up to the low-level driver to reset the port and actually
574 * do the setup (the upper levels don't know how to do that).
576 void usb_connect(struct usb_device
*dev
)
580 dev
->descriptor
.bMaxPacketSize0
= 8; /* XXX fixed 8 bytes for now */
582 devnum
= find_next_zero_bit(dev
->bus
->devmap
.devicemap
, 128, 1);
584 set_bit(devnum
, dev
->bus
->devmap
.devicemap
);
585 dev
->devnum
= devnum
;
590 * These are the actual routines to send
591 * and receive control messages.
593 int usb_set_address(struct usb_device
*dev
)
598 dr
.request
= USB_REQ_SET_ADDRESS
;
599 dr
.value
= dev
->devnum
;
603 return dev
->bus
->op
->control_msg(dev
, usb_snddefctrl(dev
), &dr
, NULL
, 0);
606 int usb_get_descriptor(struct usb_device
*dev
, unsigned char type
, unsigned char index
, void *buf
, int size
)
612 dr
.requesttype
= 0x80;
613 dr
.request
= USB_REQ_GET_DESCRIPTOR
;
614 dr
.value
= (type
<< 8) + index
;
619 if (!(result
= dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, buf
, size
))
620 || result
== USB_ST_STALL
)
626 int usb_get_string(struct usb_device
*dev
, unsigned short langid
, unsigned char index
, void *buf
, int size
)
630 dr
.requesttype
= 0x80;
631 dr
.request
= USB_REQ_GET_DESCRIPTOR
;
632 dr
.value
= (USB_DT_STRING
<< 8) + index
;
636 return dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, buf
, size
);
639 int usb_get_device_descriptor(struct usb_device
*dev
)
641 int ret
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0, &dev
->descriptor
,
642 sizeof(dev
->descriptor
));
644 le16_to_cpus(&dev
->descriptor
.bcdUSB
);
645 le16_to_cpus(&dev
->descriptor
.idVendor
);
646 le16_to_cpus(&dev
->descriptor
.idProduct
);
647 le16_to_cpus(&dev
->descriptor
.bcdDevice
);
652 int usb_get_status (struct usb_device
*dev
, int type
, int target
, void *data
)
656 dr
.requesttype
= USB_DIR_IN
| type
; /* USB_RECIP_DEVICE, _INTERFACE, or _ENDPOINT */
657 dr
.request
= USB_REQ_GET_STATUS
;
662 return dev
->bus
->op
->control_msg (dev
, usb_rcvctrlpipe (dev
,0), &dr
, data
, 2);
665 int usb_get_protocol(struct usb_device
*dev
)
667 unsigned char buf
[8];
670 dr
.requesttype
= USB_RT_HIDD
| 0x80;
671 dr
.request
= USB_REQ_GET_PROTOCOL
;
676 if (dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
, 0), &dr
, buf
, 1))
682 int usb_set_protocol(struct usb_device
*dev
, int protocol
)
686 dr
.requesttype
= USB_RT_HIDD
;
687 dr
.request
= USB_REQ_SET_PROTOCOL
;
692 if (dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
, 0), &dr
, NULL
, 0))
698 /* keyboards want a nonzero duration according to HID spec, but
699 mice should use infinity (0) -keryan */
700 int usb_set_idle(struct usb_device
*dev
, int duration
, int report_id
)
704 dr
.requesttype
= USB_RT_HIDD
;
705 dr
.request
= USB_REQ_SET_IDLE
;
706 dr
.value
= (duration
<< 8) | report_id
;
710 if (dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
, 0), &dr
, NULL
, 0))
716 static void usb_set_maxpacket(struct usb_device
*dev
)
719 struct usb_interface
*ifp
;
721 for (i
=0; i
<dev
->actconfig
->bNumInterfaces
; i
++) {
722 ifp
= dev
->actconfig
->interface
+ i
;
724 for (j
= 0; j
< ifp
->num_altsetting
; j
++) {
725 struct usb_interface_descriptor
*as
= ifp
->altsetting
+ j
;
726 struct usb_endpoint_descriptor
*ep
= as
->endpoint
;
729 for (e
=0; e
<as
->bNumEndpoints
; e
++) {
730 if (usb_endpoint_out(ep
[e
].bEndpointAddress
))
731 dev
->epmaxpacketout
[ep
[e
].bEndpointAddress
& 0x0f] =
732 ep
[e
].wMaxPacketSize
;
734 dev
->epmaxpacketin
[ep
[e
].bEndpointAddress
& 0x0f] =
735 ep
[e
].wMaxPacketSize
;
742 * endp: endpoint number in bits 0-3;
743 * direction flag in bit 7 (1 = IN, 0 = OUT)
745 int usb_clear_halt(struct usb_device
*dev
, int endp
)
751 //if (!usb_endpoint_halted(dev, endp & 0x0f, usb_endpoint_out(endp)))
754 dr
.requesttype
= USB_RT_ENDPOINT
;
755 dr
.request
= USB_REQ_CLEAR_FEATURE
;
760 result
= dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
762 /* don't clear if failed */
766 #if 1 /* let's be really tough */
767 dr
.requesttype
= 0x80 | USB_RT_ENDPOINT
;
768 dr
.request
= USB_REQ_GET_STATUS
;
772 result
= dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, &status
, 2);
777 return 1; /* still halted */
779 usb_endpoint_running(dev
, endp
& 0x0f, usb_endpoint_out(endp
));
781 /* toggle is reset on clear */
783 usb_settoggle(dev
, endp
& 0x0f, usb_endpoint_out(endp
), 0);
788 int usb_set_interface(struct usb_device
*dev
, int interface
, int alternate
)
793 dr
.request
= USB_REQ_SET_INTERFACE
;
794 dr
.value
= alternate
;
795 dr
.index
= interface
;
798 if (dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
, 0), &dr
, NULL
, 0))
801 dev
->ifnum
= interface
;
802 dev
->actconfig
->interface
[interface
].act_altsetting
= alternate
;
803 usb_set_maxpacket(dev
);
807 int usb_set_configuration(struct usb_device
*dev
, int configuration
)
811 struct usb_config_descriptor
*cp
= NULL
;
814 dr
.request
= USB_REQ_SET_CONFIGURATION
;
815 dr
.value
= configuration
;
819 for (i
=0; i
<dev
->descriptor
.bNumConfigurations
; i
++) {
820 if (dev
->config
[i
].bConfigurationValue
== configuration
) {
821 cp
= &dev
->config
[i
];
826 printk(KERN_INFO
"usb: selecting invalid configuration %d\n", configuration
);
829 if (dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
, 0), &dr
, NULL
, 0))
835 usb_set_maxpacket(dev
);
839 int usb_get_report(struct usb_device
*dev
, unsigned char type
, unsigned char id
, unsigned char index
, void *buf
, int size
)
843 dr
.requesttype
= USB_RT_HIDD
| 0x80;
844 dr
.request
= USB_REQ_GET_REPORT
;
845 dr
.value
= (type
<< 8) + id
;
849 if (dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
, 0), &dr
, buf
, size
))
855 int usb_get_configuration(struct usb_device
*dev
)
858 unsigned char buffer
[8];
859 unsigned char *bigbuffer
;
860 struct usb_config_descriptor
*desc
=
861 (struct usb_config_descriptor
*)buffer
;
863 if (dev
->descriptor
.bNumConfigurations
> USB_MAXCONFIG
) {
864 printk(KERN_WARNING
"usb: too many configurations\n");
868 dev
->config
= (struct usb_config_descriptor
*)
869 kmalloc(dev
->descriptor
.bNumConfigurations
*
870 sizeof(struct usb_config_descriptor
), GFP_KERNEL
);
872 printk(KERN_WARNING
"usb: out of memory.\n");
875 memset(dev
->config
, 0, dev
->descriptor
.bNumConfigurations
*
876 sizeof(struct usb_config_descriptor
));
878 for (cfgno
= 0; cfgno
< dev
->descriptor
.bNumConfigurations
; cfgno
++) {
881 /* We grab the first 8 bytes so we know how long the whole */
882 /* configuration is */
883 result
= usb_get_descriptor(dev
, USB_DT_CONFIG
, cfgno
, buffer
, 8);
887 /* Get the full buffer */
888 le16_to_cpus(&desc
->wTotalLength
);
890 bigbuffer
= kmalloc(desc
->wTotalLength
, GFP_KERNEL
);
894 /* Now that we know the length, get the whole thing */
895 result
= usb_get_descriptor(dev
, USB_DT_CONFIG
, cfgno
, bigbuffer
, desc
->wTotalLength
);
901 result
= usb_parse_configuration(dev
, &dev
->config
[cfgno
], bigbuffer
);
905 printk(KERN_INFO
"usb: descriptor data left\n");
914 char *usb_string(struct usb_device
*dev
, int index
)
919 unsigned char buffer
[256];
920 struct usb_string_descriptor desc
;
928 if (dev
->string_langid
== 0) {
929 /* read string descriptor 0 */
930 if (usb_get_string(dev
, 0, 0, u
.buffer
, 2) == 0
931 && u
.desc
.bLength
>= 4
932 && usb_get_string(dev
, 0, 0, u
.buffer
, 4) == 0)
933 dev
->string_langid
= le16_to_cpup(&u
.desc
.wData
[0]);
934 dev
->string_langid
|= 0x10000; /* so it's non-zero */
937 if (usb_get_string(dev
, dev
->string_langid
, index
, u
.buffer
, 2) ||
938 usb_get_string(dev
, dev
->string_langid
, index
, u
.buffer
,
942 len
= u
.desc
.bLength
/ 2; /* includes terminating null */
944 ptr
= kmalloc(len
, GFP_KERNEL
);
948 for (i
= 0; i
< len
- 1; ++i
)
949 ptr
[i
] = le16_to_cpup(&u
.desc
.wData
[i
]);
957 * By the time we get here, the device has gotten a new device ID
958 * and is in the default state. We need to identify the thing and
959 * get the ball rolling..
961 int usb_new_device(struct usb_device
*dev
)
965 printk(KERN_INFO
"USB new device connect, assigned device number %d\n",
968 dev
->maxpacketsize
= 0; /* Default to 8 byte max packet size */
969 dev
->epmaxpacketin
[0] = 8;
970 dev
->epmaxpacketout
[0] = 8;
972 /* We still haven't set the Address yet */
977 if (usb_get_descriptor(dev
, USB_DT_DEVICE
, 0, &dev
->descriptor
, 8)) {
978 printk(KERN_ERR
"usbcore: USB device not responding, giving up\n");
983 dev
->epmaxpacketin
[0] = dev
->descriptor
.bMaxPacketSize0
;
984 dev
->epmaxpacketout
[0] = dev
->descriptor
.bMaxPacketSize0
;
985 switch (dev
->descriptor
.bMaxPacketSize0
) {
986 case 8: dev
->maxpacketsize
= 0; break;
987 case 16: dev
->maxpacketsize
= 1; break;
988 case 32: dev
->maxpacketsize
= 2; break;
989 case 64: dev
->maxpacketsize
= 3; break;
994 if (usb_set_address(dev
)) {
995 printk(KERN_ERR
"usbcore: USB device not accepting new address\n");
1000 wait_ms(10); /* Let the SET_ADDRESS settle */
1002 if (usb_get_device_descriptor(dev
)) {
1003 printk(KERN_ERR
"usbcore: unable to get device descriptor\n");
1008 if (usb_get_configuration(dev
)) {
1009 printk(KERN_ERR
"usbcore: unable to get configuration\n");
1014 dev
->actconfig
= dev
->config
;
1016 usb_set_maxpacket(dev
);
1018 usb_show_string(dev
, "Manufacturer", dev
->descriptor
.iManufacturer
);
1019 usb_show_string(dev
, "Product", dev
->descriptor
.iProduct
);
1020 usb_show_string(dev
, "SerialNumber", dev
->descriptor
.iSerialNumber
);
1022 /* now that the basic setup is over, add a /proc/bus/usb entry */
1023 proc_usb_add_device(dev
);
1025 if (!usb_find_driver(dev
)) {
1027 * Ok, no driver accepted the device, so show the info for
1030 printk(KERN_DEBUG
"Unknown new USB device:\n");
1031 usb_show_device(dev
);
1037 int usb_control_msg(struct usb_device
*dev
, unsigned int pipe
, __u8 request
, __u8 requesttype
, __u16 value
, __u16 index
, void *data
, __u16 size
)
1041 dr
.requesttype
= requesttype
;
1042 dr
.request
= request
;
1043 dr
.value
= cpu_to_le16p(&value
);
1044 dr
.index
= cpu_to_le16p(&index
);
1045 dr
.length
= cpu_to_le16p(&size
);
1047 return dev
->bus
->op
->control_msg(dev
, pipe
, &dr
, data
, size
);
1050 void *usb_request_irq(struct usb_device
*dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
)
1052 return dev
->bus
->op
->request_irq(dev
, pipe
, handler
, period
, dev_id
);
1055 void *usb_request_bulk(struct usb_device
*dev
, unsigned int pipe
, usb_device_irq handler
, void *data
, int len
, void *dev_id
)
1057 return dev
->bus
->op
->request_bulk(dev
, pipe
, handler
, data
, len
, dev_id
);
1060 int usb_terminate_bulk(struct usb_device
*dev
, void *first
)
1062 return dev
->bus
->op
->terminate_bulk(dev
, first
);
1065 int usb_release_irq(struct usb_device
*dev
, void *handle
)
1067 return dev
->bus
->op
->release_irq(dev
, handle
);
1071 * usb_get_current_frame_number()
1073 * returns the current frame number for the parent USB bus/controller
1074 * of the given USB device.
1076 int usb_get_current_frame_number (struct usb_device
*usb_dev
)
1078 return usb_dev
->bus
->op
->get_frame_number (usb_dev
);
1081 int usb_init_isoc (struct usb_device
*usb_dev
,
1085 struct usb_isoc_desc
**isocdesc
)
1087 return usb_dev
->bus
->op
->init_isoc (usb_dev
, pipe
, frame_count
, context
, isocdesc
);
1090 void usb_free_isoc (struct usb_isoc_desc
*isocdesc
)
1092 isocdesc
->usb_dev
->bus
->op
->free_isoc (isocdesc
);
1095 int usb_run_isoc (struct usb_isoc_desc
*isocdesc
,
1096 struct usb_isoc_desc
*pr_isocdesc
)
1098 return isocdesc
->usb_dev
->bus
->op
->run_isoc (isocdesc
, pr_isocdesc
);
1101 int usb_kill_isoc (struct usb_isoc_desc
*isocdesc
)
1103 return isocdesc
->usb_dev
->bus
->op
->kill_isoc (isocdesc
);
1106 #ifdef CONFIG_PROC_FS
1107 struct list_head
*usb_driver_get_list(void)
1109 return &usb_driver_list
;
1112 struct list_head
*usb_bus_get_list(void)
1114 return &usb_bus_list
;