Changeset d81ef61c in mainline for uspace/drv/usbhub/usbhub.c
- Timestamp:
- 2011-02-18T14:24:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 50ba203
- Parents:
- fe1776c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
rfe1776c2 rd81ef61c 41 41 #include <usb/descriptor.h> 42 42 #include <usb/devreq.h> 43 #include <usb/request.h> 43 44 #include <usb/classes/hub.h> 44 45 … … 47 48 #include "port_status.h" 48 49 #include "usb/usb.h" 50 #include "usb/pipes.h" 49 51 50 52 static usb_iface_t hub_usb_iface = { … … 62 64 //********************************************* 63 65 64 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc) {66 usb_hub_info_t * usb_create_hub_info(device_t * device) { 65 67 usb_hub_info_t* result = usb_new(usb_hub_info_t); 68 usb_device_connection_initialize_from_device(&result->connection, device); 69 usb_endpoint_pipe_initialize_default_control(&result->endpoints.control, 70 &result->connection); 71 72 66 73 //result->device = device; 67 74 result->port_count = -1; … … 69 76 result->device = device; 70 77 71 72 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);73 if (hc < 0) {74 return result;75 }76 //get some hub info77 usb_address_t addr = usb_drv_get_my_address(hc, device);78 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);79 /*if(addr<0){80 //return result;81 82 }*/83 84 78 result->usb_device = usb_new(usb_hcd_attached_device_info_t); 85 result->usb_device->address = addr; 86 79 87 80 // get hub descriptor 88 81 … … 93 86 int opResult; 94 87 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 95 96 opResult = usb_ drv_req_get_descriptor(hc, addr,88 usb_endpoint_pipe_start_session(&result->endpoints.control); 89 opResult = usb_request_get_descriptor(&result->endpoints.control, 97 90 USB_REQUEST_TYPE_CLASS, 98 91 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 99 92 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 93 usb_endpoint_pipe_end_session(&result->endpoints.control); 94 95 /* Initialize the interrupt endpoint. 96 usb_endpoint_pipe_initalize( 97 &hub_data->endpoints->status_change, 98 &endpiont_descriptor, &hub_data->connection); 99 100 */ /// \TODO add this call 100 101 101 102 if (opResult != EOK) { … … 142 143 dev->ops = &hub_device_ops; 143 144 144 //create the hub structure 145 //get hc connection 146 int hc = usb_drv_hc_connect_auto(dev, 0); 147 if (hc < 0) { 148 return hc; 149 } 150 151 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 145 146 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 147 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 152 148 int port; 153 149 int opResult; 154 usb_target_t target;155 target.address = hub_info->usb_device->address;156 target.endpoint = 0;150 //usb_target_t target; 151 //target.address = hub_info->usb_device->address; 152 //target.endpoint = 0; 157 153 158 154 //get configuration descriptor … … 160 156 // and all should be checked 161 157 usb_standard_device_descriptor_t std_descriptor; 162 opResult = usb_ drv_req_get_device_descriptor(hc, target.address,158 opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control, 163 159 &std_descriptor); 164 160 if(opResult!=EOK){ … … 173 169 /// \TODO check other configurations 174 170 usb_standard_configuration_descriptor_t config_descriptor; 175 opResult = usb_ drv_req_get_bare_configuration_descriptor(hc,176 target.address, 0,171 opResult = usb_request_get_bare_configuration_descriptor( 172 &hub_info->endpoints.control, 0, 177 173 &config_descriptor); 178 174 if(opResult!=EOK){ … … 181 177 } 182 178 //set configuration 183 opResult = usb_ drv_req_set_configuration(hc, target.address,179 opResult = usb_request_set_configuration(&hub_info->endpoints.control, 184 180 config_descriptor.configuration_number); 185 181 … … 191 187 for (port = 1; port < hub_info->port_count+1; ++port) { 192 188 usb_hub_set_power_port_request(&request, port); 193 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 189 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 190 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 194 191 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 195 192 if (opResult != EOK) { … … 199 196 //ports powered, hub seems to be enabled 200 197 201 async_hangup(hc); 198 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 199 //async_hangup(hc); 202 200 203 201 //add the hub to list … … 251 249 * @param target 252 250 */ 253 static void usb_hub_init_add_device( int hc, uint16_t port, usb_target_t target) {251 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) { 254 252 usb_device_request_setup_packet_t request; 255 253 int opResult; 256 254 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 257 255 //get default address 256 ///////////////here ended pipe api upgrading 257 gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld 258 258 opResult = usb_drv_reserve_default_address(hc); 259 259 if (opResult != EOK) { … … 374 374 * @param target 375 375 */ 376 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,377 uint16_t port , usb_address_t address) {376 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 377 uint16_t port) { 378 378 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 379 379 //determine type of change 380 int opResult = usb_endpoint_pipe_start_session(&hub->endpoints.control); 381 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; 382 if(opResult != EOK){ 383 continue; 384 } 385 386 /* 380 387 usb_target_t target; 381 388 target.address=address; 382 389 target.endpoint=0; 390 */ 391 383 392 usb_port_status_t status; 384 393 size_t rcvd_size; 385 394 usb_device_request_setup_packet_t request; 386 int opResult;395 //int opResult; 387 396 usb_hub_set_port_status_request(&request, port); 388 397 //endpoint 0 389 398 390 opResult = usb_ drv_sync_control_read(391 hc, target,392 &request, 399 opResult = usb_endpoint_pipe_control_read( 400 pipe, 401 &request, sizeof(usb_device_request_setup_packet_t), 393 402 &status, 4, &rcvd_size 394 403 ); … … 403 412 //something connected/disconnected 404 413 if (usb_port_connect_change(&status)) { 405 opResult = usb_hub_clear_port_feature( hc, target.address,414 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 406 415 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 407 416 // TODO: check opResult 408 417 if (usb_port_dev_connected(&status)) { 409 418 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 410 usb_hub_init_add_device(h c, port, target);419 usb_hub_init_add_device(hub, port); 411 420 } else { 412 usb_hub_removed_device(hub, hc, port, target);421 usb_hub_removed_device(hub, port); 413 422 } 414 423 } … … 417 426 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 418 427 if (usb_port_enabled(&status)) { 419 usb_hub_finalize_add_device(hub, hc, port, target);428 usb_hub_finalize_add_device(hub, port); 420 429 } else { 421 430 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 433 442 /// \TODO handle other changes 434 443 /// \TODO debug log for various situations 444 usb_endpoint_pipe_end_session(&hub->endpoints.control); 445 435 446 436 447 } … … 450 461 fibril_mutex_unlock(&usb_hub_list_lock); 451 462 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 463 int opResult; 464 465 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 466 if(opResult != EOK){ 467 continue; 468 } 452 469 /* 453 470 * Check status change pipe of this hub. 454 471 */ 455 472 /* 456 473 usb_target_t target; 457 474 target.address = hub_info->usb_device->address; … … 459 476 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 460 477 target.address); 461 478 */ 462 479 size_t port_count = hub_info->port_count; 463 480 464 481 /* 465 482 * Connect to respective HC. 466 * /483 * 467 484 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 468 485 if (hc < 0) { 469 486 continue; 470 } 487 }*/ 471 488 472 489 /// FIXME: count properly … … 480 497 * Send the request. 481 498 */ 482 int opResult = usb_drv_async_interrupt_in(hc, target, 499 opResult = usb_endpoint_pipe_read( 500 &hub_info->endpoints.status_change, 483 501 change_bitmap, byte_length, &actual_size, 484 &handle);502 ); 485 503 486 504 usb_drv_async_wait_for(handle); … … 497 515 if (interrupt) { 498 516 usb_hub_process_interrupt( 499 hub_info, hc, port, hub_info->usb_device->address);517 hub_info, port); 500 518 } 501 519 } 520 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 502 521 free(change_bitmap); 503 504 async_hangup(hc); 522 523 524 //async_hangup(hc); 505 525 fibril_mutex_lock(&usb_hub_list_lock); 506 526 }
Note:
See TracChangeset
for help on using the changeset viewer.