usb.c (529c0d9b8cdfae232e4ed082fd8cde5416b266b7) usb.c (5853e1335cfc76c230cc28c4226b4d513ddb7542)
1/*
2 * Most of this source has been derived from the Linux USB
3 * project:
4 * (C) Copyright Linus Torvalds 1999
5 * (C) Copyright Johannes Erdfelt 1999-2001
6 * (C) Copyright Andreas Gal 1999
7 * (C) Copyright Gregory P. Smith 1999
8 * (C) Copyright Deti Fliegl 1999 (new USB architecture)

--- 841 unchanged lines hidden (view full) ---

850{
851 dev_index--;
852 debug("Freeing device node: %d\n", dev_index);
853 memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
854 usb_dev[dev_index].devnum = -1;
855}
856
857/*
1/*
2 * Most of this source has been derived from the Linux USB
3 * project:
4 * (C) Copyright Linus Torvalds 1999
5 * (C) Copyright Johannes Erdfelt 1999-2001
6 * (C) Copyright Andreas Gal 1999
7 * (C) Copyright Gregory P. Smith 1999
8 * (C) Copyright Deti Fliegl 1999 (new USB architecture)

--- 841 unchanged lines hidden (view full) ---

850{
851 dev_index--;
852 debug("Freeing device node: %d\n", dev_index);
853 memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
854 usb_dev[dev_index].devnum = -1;
855}
856
857/*
858 * XHCI issues Enable Slot command and thereafter
859 * allocates device contexts. Provide a weak alias
860 * function for the purpose, so that XHCI overrides it
861 * and EHCI/OHCI just work out of the box.
862 */
863__weak int usb_alloc_device(struct usb_device *udev)
864{
865 return 0;
866}
867/*
858 * By the time we get here, the device has gotten a new device ID
859 * and is in the default state. We need to identify the thing and
860 * get the ball rolling..
861 *
862 * Returns 0 for success, != 0 for error.
863 */
864int usb_new_device(struct usb_device *dev)
865{
866 int addr, err;
867 int tmp;
868 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
869
868 * By the time we get here, the device has gotten a new device ID
869 * and is in the default state. We need to identify the thing and
870 * get the ball rolling..
871 *
872 * Returns 0 for success, != 0 for error.
873 */
874int usb_new_device(struct usb_device *dev)
875{
876 int addr, err;
877 int tmp;
878 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
879
880 /*
881 * Allocate usb 3.0 device context.
882 * USB 3.0 (xHCI) protocol tries to allocate device slot
883 * and related data structures first. This call does that.
884 * Refer to sec 4.3.2 in xHCI spec rev1.0
885 */
886 if (usb_alloc_device(dev)) {
887 printf("Cannot allocate device context to get SLOT_ID\n");
888 return -1;
889 }
890
870 /* We still haven't set the Address yet */
871 addr = dev->devnum;
872 dev->devnum = 0;
873
874#ifdef CONFIG_LEGACY_USB_INIT_SEQ
875 /* this is the old and known way of initializing devices, it is
876 * different than what Windows and Linux are doing. Windows and Linux
877 * both retrieve 64 bytes while reading the device descriptor

--- 14 unchanged lines hidden (view full) ---

892#else
893 /* This is a Windows scheme of initialization sequence, with double
894 * reset of the device (Linux uses the same sequence)
895 * Some equipment is said to work only with such init sequence; this
896 * patch is based on the work by Alan Stern:
897 * http://sourceforge.net/mailarchive/forum.php?
898 * thread_id=5729457&forum_id=5398
899 */
891 /* We still haven't set the Address yet */
892 addr = dev->devnum;
893 dev->devnum = 0;
894
895#ifdef CONFIG_LEGACY_USB_INIT_SEQ
896 /* this is the old and known way of initializing devices, it is
897 * different than what Windows and Linux are doing. Windows and Linux
898 * both retrieve 64 bytes while reading the device descriptor

--- 14 unchanged lines hidden (view full) ---

913#else
914 /* This is a Windows scheme of initialization sequence, with double
915 * reset of the device (Linux uses the same sequence)
916 * Some equipment is said to work only with such init sequence; this
917 * patch is based on the work by Alan Stern:
918 * http://sourceforge.net/mailarchive/forum.php?
919 * thread_id=5729457&forum_id=5398
920 */
900 struct usb_device_descriptor *desc;
921 __maybe_unused struct usb_device_descriptor *desc;
901 int port = -1;
902 struct usb_device *parent = dev->parent;
903 unsigned short portstatus;
904
905 /* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
906 * only 18 bytes long, this will terminate with a short packet. But if
907 * the maxpacket size is 8 or 16 the device may be waiting to transmit
908 * some more, or keeps on retransmitting the 8 byte header. */
909
910 desc = (struct usb_device_descriptor *)tmpbuf;
911 dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
912 /* Default to 64 byte max packet size */
913 dev->maxpacketsize = PACKET_SIZE_64;
914 dev->epmaxpacketin[0] = 64;
915 dev->epmaxpacketout[0] = 64;
916
922 int port = -1;
923 struct usb_device *parent = dev->parent;
924 unsigned short portstatus;
925
926 /* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
927 * only 18 bytes long, this will terminate with a short packet. But if
928 * the maxpacket size is 8 or 16 the device may be waiting to transmit
929 * some more, or keeps on retransmitting the 8 byte header. */
930
931 desc = (struct usb_device_descriptor *)tmpbuf;
932 dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
933 /* Default to 64 byte max packet size */
934 dev->maxpacketsize = PACKET_SIZE_64;
935 dev->epmaxpacketin[0] = 64;
936 dev->epmaxpacketout[0] = 64;
937
938 /*
939 * XHCI needs to issue a Address device command to setup
940 * proper device context structures, before it can interact
941 * with the device. So a get_descriptor will fail before any
942 * of that is done for XHCI unlike EHCI.
943 */
944#ifndef CONFIG_USB_XHCI
917 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
918 if (err < 0) {
919 debug("usb_new_device: usb_get_descriptor() failed\n");
920 return 1;
921 }
922
923 dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
924 /*
925 * Fetch the device class, driver can use this info
926 * to differentiate between HUB and DEVICE.
927 */
928 dev->descriptor.bDeviceClass = desc->bDeviceClass;
945 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
946 if (err < 0) {
947 debug("usb_new_device: usb_get_descriptor() failed\n");
948 return 1;
949 }
950
951 dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
952 /*
953 * Fetch the device class, driver can use this info
954 * to differentiate between HUB and DEVICE.
955 */
956 dev->descriptor.bDeviceClass = desc->bDeviceClass;
957#endif
929
958
930 /* find the port number we're at */
931 if (parent) {
932 int j;
933
959 if (parent) {
960 int j;
961
962 /* find the port number we're at */
934 for (j = 0; j < parent->maxchild; j++) {
935 if (parent->children[j] == dev) {
936 port = j;
937 break;
938 }
939 }
940 if (port < 0) {
941 printf("usb_new_device:cannot locate device's port.\n");

--- 99 unchanged lines hidden ---
963 for (j = 0; j < parent->maxchild; j++) {
964 if (parent->children[j] == dev) {
965 port = j;
966 break;
967 }
968 }
969 if (port < 0) {
970 printf("usb_new_device:cannot locate device's port.\n");

--- 99 unchanged lines hidden ---