Lines Matching +full:short +full:- +full:descriptor
1 // SPDX-License-Identifier: GPL-2.0+
6 * (C) Copyright Johannes Erdfelt 1999-2001
15 * Adapted for U-Boot:
71 usb_dev[i].devnum = -1; in usb_init()
79 if (ret == -ENODEV) { /* No such device. */ in usb_init()
106 usb_free_device(dev->controller); in usb_init()
113 dev_index - start_index); in usb_init()
124 return usb_started ? 0 : -ENODEV; in usb_init()
189 /*-------------------------------------------------------------------
209 * returns the transferred length if OK or -1 if error. The transferred length
210 * and the current status are stored in the dev->act_len and dev->status.
214 unsigned short value, unsigned short index, in usb_control_msg()
215 void *data, unsigned short size, int timeout) in usb_control_msg()
222 return -EINVAL; in usb_control_msg()
226 setup_packet->requesttype = requesttype; in usb_control_msg()
227 setup_packet->request = request; in usb_control_msg()
228 setup_packet->value = cpu_to_le16(value); in usb_control_msg()
229 setup_packet->index = cpu_to_le16(index); in usb_control_msg()
230 setup_packet->length = cpu_to_le16(size); in usb_control_msg()
234 dev->status = USB_ST_NOT_PROC; /*not yet processed */ in usb_control_msg()
247 while (timeout--) { in usb_control_msg()
248 if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC)) in usb_control_msg()
252 if (dev->status) in usb_control_msg()
253 return -1; in usb_control_msg()
255 return dev->act_len; in usb_control_msg()
259 /*-------------------------------------------------------------------
268 return -EINVAL; in usb_bulk_msg()
269 dev->status = USB_ST_NOT_PROC; /*not yet processed */ in usb_bulk_msg()
271 return -EIO; in usb_bulk_msg()
272 while (timeout--) { in usb_bulk_msg()
273 if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC)) in usb_bulk_msg()
277 *actual_length = dev->act_len; in usb_bulk_msg()
278 if (dev->status == 0) in usb_bulk_msg()
281 return -EIO; in usb_bulk_msg()
285 /*-------------------------------------------------------------------
295 /* direction is out -> use emaxpacket out */ in usb_maxpacket()
297 return dev->epmaxpacketout[((pipe>>15) & 0xf)]; in usb_maxpacket()
299 return dev->epmaxpacketin[((pipe>>15) & 0xf)]; in usb_maxpacket()
306 * is used as loop-count 'i', but gets overwritten later on.
320 ep = &dev->config.if_desc[if_idx].ep_desc[ep_idx]; in usb_set_maxpacket_ep()
322 b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; in usb_set_maxpacket_ep()
323 ep_wMaxPacketSize = get_unaligned(&ep->wMaxPacketSize); in usb_set_maxpacket_ep()
325 if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == in usb_set_maxpacket_ep()
328 dev->epmaxpacketout[b] = ep_wMaxPacketSize; in usb_set_maxpacket_ep()
329 dev->epmaxpacketin[b] = ep_wMaxPacketSize; in usb_set_maxpacket_ep()
331 b, dev->epmaxpacketin[b]); in usb_set_maxpacket_ep()
333 if ((ep->bEndpointAddress & 0x80) == 0) { in usb_set_maxpacket_ep()
335 if (ep_wMaxPacketSize > dev->epmaxpacketout[b]) { in usb_set_maxpacket_ep()
336 dev->epmaxpacketout[b] = ep_wMaxPacketSize; in usb_set_maxpacket_ep()
338 b, dev->epmaxpacketout[b]); in usb_set_maxpacket_ep()
342 if (ep_wMaxPacketSize > dev->epmaxpacketin[b]) { in usb_set_maxpacket_ep()
343 dev->epmaxpacketin[b] = ep_wMaxPacketSize; in usb_set_maxpacket_ep()
345 b, dev->epmaxpacketin[b]); in usb_set_maxpacket_ep()
358 for (i = 0; i < dev->config.desc.bNumInterfaces; i++) in usb_set_maxpacket()
359 for (ii = 0; ii < dev->config.if_desc[i].desc.bNumEndpoints; ii++) in usb_set_maxpacket()
366 * Parse the config, located in buffer, and fills the dev->config structure.
378 ifno = -1; in usb_parse_config()
379 epno = -1; in usb_parse_config()
380 curr_if_num = -1; in usb_parse_config()
382 dev->configno = cfgno; in usb_parse_config()
384 if (head->bDescriptorType != USB_DT_CONFIG) { in usb_parse_config()
386 head->bDescriptorType); in usb_parse_config()
387 return -EINVAL; in usb_parse_config()
389 if (head->bLength != USB_DT_CONFIG_SIZE) { in usb_parse_config()
390 printf("ERROR: Invalid USB CFG length (%d)\n", head->bLength); in usb_parse_config()
391 return -EINVAL; in usb_parse_config()
393 memcpy(&dev->config, head, USB_DT_CONFIG_SIZE); in usb_parse_config()
394 dev->config.no_of_if = 0; in usb_parse_config()
396 index = dev->config.desc.bLength; in usb_parse_config()
400 while (index + 1 < dev->config.desc.wTotalLength && head->bLength) { in usb_parse_config()
401 switch (head->bDescriptorType) { in usb_parse_config()
403 if (head->bLength != USB_DT_INTERFACE_SIZE) { in usb_parse_config()
405 head->bLength); in usb_parse_config()
409 dev->config.desc.wTotalLength) { in usb_parse_config()
410 puts("USB IF descriptor overflowed buffer!\n"); in usb_parse_config()
414 head)->bInterfaceNumber != curr_if_num) { in usb_parse_config()
416 ifno = dev->config.no_of_if; in usb_parse_config()
420 return -EINVAL; in usb_parse_config()
422 if_desc = &dev->config.if_desc[ifno]; in usb_parse_config()
423 dev->config.no_of_if++; in usb_parse_config()
426 if_desc->no_of_ep = 0; in usb_parse_config()
427 if_desc->num_altsetting = 1; in usb_parse_config()
429 if_desc->desc.bInterfaceNumber; in usb_parse_config()
433 if_desc = &dev->config.if_desc[ifno]; in usb_parse_config()
434 if_desc->num_altsetting++; in usb_parse_config()
439 if (head->bLength != USB_DT_ENDPOINT_SIZE && in usb_parse_config()
440 head->bLength != USB_DT_ENDPOINT_AUDIO_SIZE) { in usb_parse_config()
442 head->bLength); in usb_parse_config()
445 if (index + head->bLength > in usb_parse_config()
446 dev->config.desc.wTotalLength) { in usb_parse_config()
447 puts("USB EP descriptor overflowed buffer!\n"); in usb_parse_config()
451 puts("Endpoint descriptor out of order!\n"); in usb_parse_config()
454 epno = dev->config.if_desc[ifno].no_of_ep; in usb_parse_config()
455 if_desc = &dev->config.if_desc[ifno]; in usb_parse_config()
458 if_desc->desc.bInterfaceNumber); in usb_parse_config()
459 return -EINVAL; in usb_parse_config()
462 if_desc->no_of_ep++; in usb_parse_config()
463 memcpy(&if_desc->ep_desc[epno], head, in usb_parse_config()
465 ep_wMaxPacketSize = get_unaligned(&dev->config.\ in usb_parse_config()
470 &dev->config.\ in usb_parse_config()
477 if (head->bLength != USB_DT_SS_EP_COMP_SIZE) { in usb_parse_config()
479 head->bLength); in usb_parse_config()
483 dev->config.desc.wTotalLength) { in usb_parse_config()
484 puts("USB EPC descriptor overflowed buffer!\n"); in usb_parse_config()
488 puts("EPC descriptor out of order!\n"); in usb_parse_config()
491 if_desc = &dev->config.if_desc[ifno]; in usb_parse_config()
492 memcpy(&if_desc->ss_ep_comp_desc[epno], head, in usb_parse_config()
496 if (head->bLength == 0) in usb_parse_config()
497 return -EINVAL; in usb_parse_config()
500 head->bDescriptorType); in usb_parse_config()
507 for (i = 0; i < head->bLength; i++) in usb_parse_config()
514 index += head->bLength; in usb_parse_config()
522 * endp: endpoint number in bits 0-3;
576 printf("unable to get descriptor, error %lX\n", in usb_get_configuration_len()
577 dev->status); in usb_get_configuration_len()
579 printf("config descriptor too short " \ in usb_get_configuration_len()
581 return -EIO; in usb_get_configuration_len()
583 return le16_to_cpu(config->wTotalLength); in usb_get_configuration_len()
598 le16_to_cpu(config->wTotalLength)); in usb_get_configuration_no()
599 config->wTotalLength = result; /* validated, with CPU byte order */ in usb_get_configuration_no()
605 * set address of a device to the value in dev->devnum.
610 debug("set address %d\n", dev->devnum); in usb_set_address()
613 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT); in usb_set_address()
624 for (i = 0; i < dev->config.desc.bNumInterfaces; i++) { in usb_set_interface()
625 if (dev->config.if_desc[i].desc.bInterfaceNumber == interface) { in usb_set_interface()
626 if_face = &dev->config.if_desc[i]; in usb_set_interface()
632 return -EINVAL; in usb_set_interface()
639 * unusable in U-Boot. in usb_set_interface()
641 if (if_face->num_altsetting == 1) in usb_set_interface()
667 dev->toggle[0] = 0; in usb_set_configuration()
668 dev->toggle[1] = 0; in usb_set_configuration()
671 return -EIO; in usb_set_configuration()
707 * get class descriptor
720 static int usb_get_string(struct usb_device *dev, unsigned short langid, in usb_get_string()
761 /* Try to read the string descriptor by asking for the maximum in usb_string_sub()
765 /* If that failed try to read the descriptor length, then in usb_string_sub()
777 /* There might be extra junk at the end of the descriptor */ in usb_string_sub()
781 rc = rc - (rc & 1); /* force a multiple of two */ in usb_string_sub()
785 rc = -EINVAL; in usb_string_sub()
804 return -EINVAL; in usb_string()
809 if (!dev->have_langid) { in usb_string()
812 debug("error getting string descriptor 0 " \ in usb_string()
813 "(error=%lx)\n", dev->status); in usb_string()
814 return -EIO; in usb_string()
816 debug("string descriptor 0 too short\n"); in usb_string()
817 return -EIO; in usb_string()
819 dev->have_langid = -1; in usb_string()
820 dev->string_langid = tbuf[2] | (tbuf[3] << 8); in usb_string()
824 dev->devnum, dev->string_langid); in usb_string()
828 err = usb_string_sub(dev, dev->string_langid, index, tbuf); in usb_string()
832 size--; /* leave room for trailing NULL char in output buffer */ in usb_string()
837 buf[idx++] = '?'; /* non-ASCII character */ in usb_string()
855 * if the device is not assigned (dev->devnum==-1) returns NULL
859 if (usb_dev[index].devnum == -1) in usb_get_dev_index()
871 return -ENOSPC; in usb_alloc_new_device()
881 *devp = &usb_dev[dev_index - 1]; in usb_alloc_new_device()
893 dev_index--; in usb_free_device()
896 usb_dev[dev_index].devnum = -1; in usb_free_device()
930 printf("unable to get device descriptor (error=%d)\n", in get_descriptor_len()
934 printf("USB device descriptor short read (expected %i, got %i)\n", in get_descriptor_len()
936 return -EIO; in get_descriptor_len()
939 memcpy(&dev->descriptor, tmpbuf, sizeof(dev->descriptor)); in get_descriptor_len()
956 * send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is in usb_setup_descriptor()
957 * only 18 bytes long, this will terminate with a short packet. But if in usb_setup_descriptor()
962 if (dev->speed == USB_SPEED_LOW) { in usb_setup_descriptor()
963 dev->descriptor.bMaxPacketSize0 = 8; in usb_setup_descriptor()
964 dev->maxpacketsize = PACKET_SIZE_8; in usb_setup_descriptor()
966 dev->descriptor.bMaxPacketSize0 = 64; in usb_setup_descriptor()
967 dev->maxpacketsize = PACKET_SIZE_64; in usb_setup_descriptor()
969 dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; in usb_setup_descriptor()
970 dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; in usb_setup_descriptor()
972 if (do_read && dev->speed == USB_SPEED_FULL) { in usb_setup_descriptor()
977 * we've received the entire descriptor. The reasoning is: in usb_setup_descriptor()
978 * - The code only uses fields in the first 8 bytes, so in usb_setup_descriptor()
980 * - The smallest maxpacket size is 8 bytes. Before we know in usb_setup_descriptor()
984 * a non-error case. in usb_setup_descriptor()
996 dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; in usb_setup_descriptor()
997 dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; in usb_setup_descriptor()
998 switch (dev->descriptor.bMaxPacketSize0) { in usb_setup_descriptor()
1000 dev->maxpacketsize = PACKET_SIZE_8; in usb_setup_descriptor()
1003 dev->maxpacketsize = PACKET_SIZE_16; in usb_setup_descriptor()
1006 dev->maxpacketsize = PACKET_SIZE_32; in usb_setup_descriptor()
1009 dev->maxpacketsize = PACKET_SIZE_64; in usb_setup_descriptor()
1013 return -EIO; in usb_setup_descriptor()
1042 dev->devnum = addr; in usb_prepare_device()
1048 "(error=%lX)\n", dev->status); in usb_prepare_device()
1055 * If we haven't read device descriptor before, read it here in usb_prepare_device()
1078 le16_to_cpus(&dev->descriptor.bcdUSB); in usb_select_config()
1079 le16_to_cpus(&dev->descriptor.idVendor); in usb_select_config()
1080 le16_to_cpus(&dev->descriptor.idProduct); in usb_select_config()
1081 le16_to_cpus(&dev->descriptor.bcdDevice); in usb_select_config()
1085 * about this first Get Descriptor request. If there are any other in usb_select_config()
1096 err = -ENOMEM; in usb_select_config()
1103 dev->descriptor.idVendor, dev->descriptor.idProduct); in usb_select_config()
1115 err = usb_set_configuration(dev, dev->config.desc.bConfigurationValue); in usb_select_config()
1118 "len %d, status %lX\n", dev->act_len, dev->status); in usb_select_config()
1130 dev->descriptor.iManufacturer, dev->descriptor.iProduct, in usb_select_config()
1131 dev->descriptor.iSerialNumber); in usb_select_config()
1132 memset(dev->mf, 0, sizeof(dev->mf)); in usb_select_config()
1133 memset(dev->prod, 0, sizeof(dev->prod)); in usb_select_config()
1134 memset(dev->serial, 0, sizeof(dev->serial)); in usb_select_config()
1135 if (dev->descriptor.iManufacturer) in usb_select_config()
1136 usb_string(dev, dev->descriptor.iManufacturer, in usb_select_config()
1137 dev->mf, sizeof(dev->mf)); in usb_select_config()
1138 if (dev->descriptor.iProduct) in usb_select_config()
1139 usb_string(dev, dev->descriptor.iProduct, in usb_select_config()
1140 dev->prod, sizeof(dev->prod)); in usb_select_config()
1141 if (dev->descriptor.iSerialNumber) in usb_select_config()
1142 usb_string(dev, dev->descriptor.iSerialNumber, in usb_select_config()
1143 dev->serial, sizeof(dev->serial)); in usb_select_config()
1144 debug("Manufacturer %s\n", dev->mf); in usb_select_config()
1145 debug("Product %s\n", dev->prod); in usb_select_config()
1146 debug("SerialNumber %s\n", dev->serial); in usb_select_config()
1158 addr = dev->devnum; in usb_setup_device()
1159 dev->devnum = 0; in usb_setup_device()
1191 err = usb_setup_device(dev, do_read, dev->parent); in usb_new_device()
1221 return parent->children[port] != NULL; in usb_device_has_child_on_port()
1233 * When called from usb-uclass.c: usb_scan_device() udev->dev points in usb_find_usb2_hub_address_port()
1236 * for the first usb-2 parent start with udev->dev not in usb_find_usb2_hub_address_port()
1237 * udev->dev->parent . in usb_find_usb2_hub_address_port()
1240 parent = udev->dev; in usb_find_usb2_hub_address_port()
1243 while (uparent->speed != USB_SPEED_HIGH) { in usb_find_usb2_hub_address_port()
1246 if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB) { in usb_find_usb2_hub_address_port()
1247 printf("Error: Cannot find high speed parent of usb-1 device\n"); in usb_find_usb2_hub_address_port()
1254 parent = dev->parent; in usb_find_usb2_hub_address_port()
1257 *hub_address = uparent->devnum; in usb_find_usb2_hub_address_port()
1258 *hub_port = ttdev->portnr; in usb_find_usb2_hub_address_port()
1265 while (udev->parent->parent != NULL) in usb_find_usb2_hub_address_port()
1266 if (udev->parent->speed != USB_SPEED_HIGH) { in usb_find_usb2_hub_address_port()
1267 udev = udev->parent; in usb_find_usb2_hub_address_port()
1269 *hub_address = udev->parent->devnum; in usb_find_usb2_hub_address_port()
1270 *hub_port = udev->portnr; in usb_find_usb2_hub_address_port()
1274 printf("Error: Cannot find high speed parent of usb-1 device\n"); in usb_find_usb2_hub_address_port()