Changes in uspace/drv/usbhub/usbhub.c [5097bed4:281ebae] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r5097bed4 r281ebae 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup usb hub driver28 /** @addtogroup drvusbhub 29 29 * @{ 30 30 */ … … 46 46 #include "usbhub_private.h" 47 47 #include "port_status.h" 48 #include "usb/usb.h" 48 49 49 50 static usb_iface_t hub_usb_iface = { … … 75 76 //get some hub info 76 77 usb_address_t addr = usb_drv_get_my_address(hc, device); 77 dprintf(1, "[usb_hub]address of newly created hub = %d", addr);78 dprintf(1, "address of newly created hub = %d", addr); 78 79 /*if(addr<0){ 79 80 //return result; … … 85 86 86 87 // get hub descriptor 87 usb_target_t target;88 target.address = addr;89 target.endpoint = 0;90 usb_device_request_setup_packet_t request;91 //printf("[usb_hub] creating descriptor request\n");92 usb_hub_set_descriptor_request(&request);93 88 94 89 //printf("[usb_hub] creating serialized descriptor\n"); … … 98 93 int opResult; 99 94 //printf("[usb_hub] starting control transaction\n"); 100 opResult = usb_drv_sync_control_read( 101 hc, target, &request, serialized_descriptor, 95 96 opResult = usb_drv_req_get_descriptor(hc, addr, 97 USB_REQUEST_TYPE_CLASS, 98 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 102 99 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 103 if (opResult != EOK) { 104 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult); 100 101 if (opResult != EOK) { 102 dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult); 105 103 free(serialized_descriptor); 106 104 return result; … … 109 107 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 110 108 if(descriptor==NULL){ 111 dprintf(1, "[usb_hub]could not deserialize descriptor ");109 dprintf(1, "could not deserialize descriptor "); 112 110 result->port_count = 1;///\TODO this code is only for debug!!! 113 111 return result; … … 129 127 //finish 130 128 131 dprintf(1, "[usb_hub]hub info created");129 dprintf(1, "hub info created"); 132 130 133 131 return result; … … 136 134 int usb_add_hub_device(device_t *dev) { 137 135 dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle); 138 dprintf(1, "[usb_hub]hub device");136 dprintf(1, "hub device"); 139 137 140 138 /* … … 155 153 int port; 156 154 int opResult; 157 usb_device_request_setup_packet_t request;158 155 usb_target_t target; 159 156 target.address = hub_info->usb_device->address; … … 165 162 usb_standard_device_descriptor_t std_descriptor; 166 163 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 167 &std_descriptor);164 &std_descriptor); 168 165 if(opResult!=EOK){ 169 dprintf(1, "[usb_hub]could not get device descriptor, %d",opResult);166 dprintf(1, "could not get device descriptor, %d",opResult); 170 167 return opResult; 171 168 } 172 dprintf(1, "[usb_hub]hub has %d configurations",std_descriptor.configuration_count);169 dprintf(1, "hub has %d configurations",std_descriptor.configuration_count); 173 170 if(std_descriptor.configuration_count<1){ 174 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE"); 171 dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 172 //shouldn`t I return? 175 173 } 176 174 /// \TODO check other configurations … … 180 178 &config_descriptor); 181 179 if(opResult!=EOK){ 182 dprintf(1, "[usb_hub]could not get configuration descriptor, %d",opResult);180 dprintf(1, "could not get configuration descriptor, %d",opResult); 183 181 return opResult; 184 182 } 185 183 //set configuration 186 request.request_type = 0; 187 request.request = USB_DEVREQ_SET_CONFIGURATION; 188 request.index=0; 189 request.length=0; 190 request.value_high=0; 191 request.value_low = config_descriptor.configuration_number; 192 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 193 if (opResult != EOK) { 194 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult); 195 } 196 184 opResult = usb_drv_req_set_configuration(hc, target.address, 185 config_descriptor.configuration_number); 186 187 if (opResult != EOK) { 188 dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult); 189 } 190 191 usb_device_request_setup_packet_t request; 197 192 for (port = 1; port < hub_info->port_count+1; ++port) { 198 193 usb_hub_set_power_port_request(&request, port); 199 194 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 200 dprintf(1, "[usb_hub]powering port %d",port);195 dprintf(1, "powering port %d",port); 201 196 if (opResult != EOK) { 202 dprintf(1, "[usb_hub]something went wrong when setting hub`s %dth port", port);197 dprintf(1, "something went wrong when setting hub`s %dth port", port); 203 198 } 204 199 } … … 212 207 futex_up(&usb_hub_list_lock); 213 208 214 dprintf(1, "[usb_hub]hub info added to list");209 dprintf(1, "hub info added to list"); 215 210 //(void)hub_info; 216 211 usb_hub_check_hub_changes(); … … 218 213 219 214 220 dprintf(1, "[usb_hub]hub dev added");221 dprintf(1, "\taddress %d, has %d ports ",215 dprintf(1, "hub dev added"); 216 dprintf(1, "\taddress %d, has %d ports ", 222 217 hub_info->usb_device->address, 223 218 hub_info->port_count); 224 dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);219 dprintf(1, "\tused configuration %d",config_descriptor.configuration_number); 225 220 226 221 return EOK; 227 222 //return ENOTSUP; 228 223 } 229 230 224 231 225 … … 237 231 238 232 /** 239 * convenience function for releasing default address and writing debug info240 * (these few lines are used too often to be written again and again) 233 * Convenience function for releasing default address and writing debug info 234 * (these few lines are used too often to be written again and again). 241 235 * @param hc 242 236 * @return … … 244 238 inline static int usb_hub_release_default_address(int hc){ 245 239 int opResult; 246 dprintf(1, "[usb_hub]releasing default address");240 dprintf(1, "releasing default address"); 247 241 opResult = usb_drv_release_default_address(hc); 248 242 if (opResult != EOK) { 249 dprintf(1, "[usb_hub]failed to release default address");243 dprintf(1, "failed to release default address"); 250 244 } 251 245 return opResult; … … 253 247 254 248 /** 255 * reset the port with new device and reserve the default address249 * Reset the port with new device and reserve the default address. 256 250 * @param hc 257 251 * @param port … … 261 255 usb_device_request_setup_packet_t request; 262 256 int opResult; 263 dprintf(1, "[usb_hub]some connection changed");257 dprintf(1, "some connection changed"); 264 258 //get default address 265 259 opResult = usb_drv_reserve_default_address(hc); 266 260 if (opResult != EOK) { 267 dprintf(1, "[usb_hub]cannot assign default address, it is probably used");261 dprintf(1, "cannot assign default address, it is probably used"); 268 262 return; 269 263 } … … 276 270 ); 277 271 if (opResult != EOK) { 278 dprintf(1, "[usb_hub]something went wrong when reseting a port");272 dprintf(1, "something went wrong when reseting a port"); 279 273 usb_hub_release_default_address(hc); 280 274 } … … 282 276 283 277 /** 284 * finalize adding new device after port reset278 * Finalize adding new device after port reset 285 279 * @param hc 286 280 * @param port … … 291 285 292 286 int opResult; 293 dprintf(1, "[usb_hub]finalizing add device");287 dprintf(1, "finalizing add device"); 294 288 opResult = usb_hub_clear_port_feature(hc, target.address, 295 289 port, USB_HUB_FEATURE_C_PORT_RESET); 296 290 if (opResult != EOK) { 297 dprintf(1, "[usb_hub]failed to clear port reset feature");291 dprintf(1, "failed to clear port reset feature"); 298 292 usb_hub_release_default_address(hc); 299 293 return; … … 303 297 usb_address_t new_device_address = usb_drv_request_address(hc); 304 298 if (new_device_address < 0) { 305 dprintf(1, "[usb_hub]failed to get free USB address");299 dprintf(1, "failed to get free USB address"); 306 300 opResult = new_device_address; 307 301 usb_hub_release_default_address(hc); 308 302 return; 309 303 } 310 dprintf(1, "[usb_hub]setting new address");304 dprintf(1, "setting new address"); 311 305 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 312 306 new_device_address); 313 307 314 308 if (opResult != EOK) { 315 dprintf(1, "[usb_hub]could not set address for new device");309 dprintf(1, "could not set address for new device"); 316 310 usb_hub_release_default_address(hc); 317 311 return; … … 328 322 new_device_address, &child_handle); 329 323 if (opResult != EOK) { 330 dprintf(1, "[usb_hub]could not start driver for new device");324 dprintf(1, "could not start driver for new device"); 331 325 return; 332 326 } … … 336 330 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 337 331 if (opResult != EOK) { 338 dprintf(1, "[usb_hub]could not assign address of device in hcd");339 return; 340 } 341 dprintf(1, "[usb_hub]new device address %d, handle %zu",332 dprintf(1, "could not assign address of device in hcd"); 333 return; 334 } 335 dprintf(1, "new device address %d, handle %zu", 342 336 new_device_address, child_handle); 343 337 … … 345 339 346 340 /** 347 * unregister device address in hc341 * Unregister device address in hc 348 342 * @param hc 349 343 * @param port … … 355 349 int opResult; 356 350 357 /// \TODO remove device 351 /** \TODO remove device from device manager - not yet implemented in 352 * devide manager 353 */ 358 354 359 355 hub->attached_devs[port].devman_handle=0; … … 362 358 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 363 359 if(opResult != EOK) { 364 dprintf(1, 365 "[usb_hub] could not release address of removed device: %d" 366 ,opResult); 360 dprintf(1, "could not release address of " \ 361 "removed device: %d", opResult); 367 362 } 368 363 hub->attached_devs[port].address = 0; 369 364 }else{ 370 dprintf(1, 371 "[usb_hub] this is strange, disconnected device had no address"); 365 dprintf(1, "this is strange, disconnected device had no address"); 372 366 //device was disconnected before it`s port was reset - return default address 373 367 usb_drv_release_default_address(hc); … … 376 370 377 371 /** 378 * process interrupts on given hub port372 * Process interrupts on given hub port 379 373 * @param hc 380 374 * @param port … … 383 377 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 384 378 uint16_t port, usb_address_t address) { 385 dprintf(1, "[usb_hub]interrupt at port %d", port);379 dprintf(1, "interrupt at port %d", port); 386 380 //determine type of change 387 381 usb_target_t target; … … 401 395 ); 402 396 if (opResult != EOK) { 403 dprintf(1, "[usb_hub]ERROR: could not get port status");397 dprintf(1, "ERROR: could not get port status"); 404 398 return; 405 399 } 406 400 if (rcvd_size != sizeof (usb_port_status_t)) { 407 dprintf(1, "[usb_hub]ERROR: received status has incorrect size");401 dprintf(1, "ERROR: received status has incorrect size"); 408 402 return; 409 403 } … … 414 408 // TODO: check opResult 415 409 if (usb_port_dev_connected(&status)) { 416 dprintf(1, "[usb_hub]some connection changed");410 dprintf(1, "some connection changed"); 417 411 usb_hub_init_add_device(hc, port, target); 418 412 } else { … … 422 416 //port reset 423 417 if (usb_port_reset_completed(&status)) { 424 dprintf(1, "[usb_hub]port reset complete");418 dprintf(1, "port reset complete"); 425 419 if (usb_port_enabled(&status)) { 426 420 usb_hub_finalize_add_device(hub, hc, port, target); 427 421 } else { 428 dprintf(1, "[usb_hub]ERROR: port reset, but port still not enabled");422 dprintf(1, "ERROR: port reset, but port still not enabled"); 429 423 } 430 424 } … … 434 428 usb_port_set_reset_completed(&status, false); 435 429 usb_port_set_dev_connected(&status, false); 436 if (status) { 437 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port); 430 if (status>>16) { 431 dprintf(1, "there was some unsupported change on port %d: %X",port,status); 432 438 433 } 439 434 /// \TODO handle other changes … … 442 437 } 443 438 444 /* Check changes on all known hubs. 439 /** 440 * Check changes on all known hubs. 445 441 */ 446 442 void usb_hub_check_hub_changes(void) { … … 462 458 target.address = hub_info->usb_device->address; 463 459 target.endpoint = 1;/// \TODO get from endpoint descriptor 464 dprintf(1, "[usb_hub]checking changes for hub at addr %d",460 dprintf(1, "checking changes for hub at addr %d", 465 461 target.address); 466 462 … … 492 488 493 489 if (opResult != EOK) { 494 dprintf(1, "[usb_hub]something went wrong while getting status of hub");490 dprintf(1, "something went wrong while getting status of hub"); 495 491 continue; 496 492 }
Note:
See TracChangeset
for help on using the changeset viewer.