Changeset 306a36d in mainline for uspace/lib/usbhost/src
- Timestamp:
- 2017-11-19T23:43:31Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ff14aede
- Parents:
- e76c0ea
- Location:
- uspace/lib/usbhost/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/hcd.c
re76c0ea r306a36d 35 35 36 36 #include <usb/debug.h> 37 #include <usb/descriptor.h> 37 38 #include <usb/request.h> 38 39 … … 40 41 #include <async.h> 41 42 #include <errno.h> 43 #include <macros.h> 42 44 #include <usb_iface.h> 43 45 #include <str_error.h> … … 59 61 hcd_set_implementation(hcd, NULL, NULL, NULL); 60 62 } 63 64 /** Get max packet size for the control endpoint 0. 65 * 66 * For LS, HS, and SS devices this value is fixed. For FS devices we must fetch 67 * the first 8B of the device descriptor to determine it. 68 * 69 * @return Combined value of max_packet_size and scheduling oppertunities, 70 * see usb_standard_device_descriptor_t. 71 */ 72 int hcd_get_ep0_max_packet_size(uint16_t *mps, hcd_t *hcd, device_t *dev) 73 { 74 static const uint16_t mps_fixed [] = { 75 [USB_SPEED_LOW] = 8, 76 [USB_SPEED_HIGH] = 64, 77 [USB_SPEED_SUPER] = 512, 78 }; 79 80 if (dev->speed < ARRAY_SIZE(mps_fixed) && mps_fixed[dev->speed] != 0) { 81 *mps = mps_fixed[dev->speed]; 82 return EOK; 83 } 84 85 const usb_target_t control_ep = {{ 86 .address = dev->address, 87 .endpoint = 0, 88 }}; 89 90 usb_standard_device_descriptor_t desc = { 0 }; 91 const usb_device_request_setup_packet_t get_device_desc_8 = 92 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE); 93 94 usb_log_debug("Requesting first 8B of device descriptor."); 95 ssize_t got = hcd_send_batch_sync(hcd, dev, control_ep, USB_DIRECTION_IN, 96 (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8, 97 "read first 8 bytes of dev descriptor"); 98 99 if (got != CTRL_PIPE_MIN_PACKET_SIZE) { 100 const int err = got < 0 ? got : EOVERFLOW; 101 usb_log_error("Failed to get 8B of dev descr: %s.", str_error(err)); 102 return err; 103 } 104 105 *mps = uint16_usb2host(desc.max_packet_size); 106 return EOK; 107 } 108 61 109 62 110 /** Prepare generic usb_transfer_batch and schedule it. -
uspace/lib/usbhost/src/usb2_bus.c
re76c0ea r306a36d 132 132 } 133 133 134 /* Get max packet size for default pipe */ 135 usb_standard_device_descriptor_t desc = { 0 }; 136 const usb_device_request_setup_packet_t get_device_desc_8 = 137 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE); 138 139 usb_log_debug("Device(%d): Requesting first 8B of device descriptor.", 140 address); 141 ssize_t got = hcd_send_batch_sync(hcd, dev, usb2_default_target, USB_DIRECTION_IN, 142 (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8, 143 "read first 8 bytes of dev descriptor"); 144 145 if (got != CTRL_PIPE_MIN_PACKET_SIZE) { 146 err = got < 0 ? got : EOVERFLOW; 147 usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.", 148 address, str_error(err)); 149 goto err_default_control_ep; 150 } 134 uint16_t max_packet_size; 135 if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, hcd, dev))) 136 goto err_address; 151 137 152 138 /* Set new address */ … … 158 144 if (err != 0) { 159 145 usb_log_error("Device(%d): Failed to set new address: %s.", 160 address, str_error( got));146 address, str_error(err)); 161 147 goto err_default_control_ep; 162 148 } … … 175 161 .transfer_type = USB_TRANSFER_CONTROL, 176 162 .direction = USB_DIRECTION_BOTH, 177 .max_packet_size = ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)),178 .packets = ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(desc.max_packet_size)),163 .max_packet_size = max_packet_size, 164 .packets = 1, 179 165 }; 180 166
Note:
See TracChangeset
for help on using the changeset viewer.