Commit c008faa77358bb5b313696dd1d5bb8afa03a6ca2
Committed by
Marek Vasut
1 parent
1897d60130
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
usb: Only get 64 bytes device descriptor for full speed devices
Full speed device endpoint 0 can have 8/16/32/64 bMaxPacketSize0. Other speed devices report fixed value per USB spec. So it only makes sense if we send a get device descriptor with 64 bytes to full speed devices. While we are here, update the comment block to be within 80 cols. Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Showing 1 changed file with 15 additions and 14 deletions Side-by-side Diff
common/usb.c
... | ... | @@ -970,23 +970,24 @@ |
970 | 970 | dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; |
971 | 971 | dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; |
972 | 972 | |
973 | - if (do_read) { | |
973 | + if (do_read && dev->speed == USB_SPEED_FULL) { | |
974 | 974 | int err; |
975 | 975 | |
976 | 976 | /* |
977 | - * Validate we've received only at least 8 bytes, not that we've | |
978 | - * received the entire descriptor. The reasoning is: | |
979 | - * - The code only uses fields in the first 8 bytes, so that's all we | |
980 | - * need to have fetched at this stage. | |
981 | - * - The smallest maxpacket size is 8 bytes. Before we know the actual | |
982 | - * maxpacket the device uses, the USB controller may only accept a | |
983 | - * single packet. Consequently we are only guaranteed to receive 1 | |
984 | - * packet (at least 8 bytes) even in a non-error case. | |
977 | + * Validate we've received only at least 8 bytes, not that | |
978 | + * we've received the entire descriptor. The reasoning is: | |
979 | + * - The code only uses fields in the first 8 bytes, so | |
980 | + * that's all we need to have fetched at this stage. | |
981 | + * - The smallest maxpacket size is 8 bytes. Before we know | |
982 | + * the actual maxpacket the device uses, the USB controller | |
983 | + * may only accept a single packet. Consequently we are only | |
984 | + * guaranteed to receive 1 packet (at least 8 bytes) even in | |
985 | + * a non-error case. | |
985 | 986 | * |
986 | - * At least the DWC2 controller needs to be programmed with the number | |
987 | - * of packets in addition to the number of bytes. A request for 64 | |
988 | - * bytes of data with the maxpacket guessed as 64 (above) yields a | |
989 | - * request for 1 packet. | |
987 | + * At least the DWC2 controller needs to be programmed with | |
988 | + * the number of packets in addition to the number of bytes. | |
989 | + * A request for 64 bytes of data with the maxpacket guessed | |
990 | + * as 64 (above) yields a request for 1 packet. | |
990 | 991 | */ |
991 | 992 | err = get_descriptor_len(dev, 64, 8); |
992 | 993 | if (err) |
... | ... | @@ -1009,7 +1010,7 @@ |
1009 | 1010 | dev->maxpacketsize = PACKET_SIZE_64; |
1010 | 1011 | break; |
1011 | 1012 | default: |
1012 | - printf("usb_new_device: invalid max packet size\n"); | |
1013 | + printf("%s: invalid max packet size\n", __func__); | |
1013 | 1014 | return -EIO; |
1014 | 1015 | } |
1015 | 1016 |