Changes in uspace/drv/usbhub/usbhub.c [28cb8bf7:d81ef61c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r28cb8bf7 rd81ef61c 36 36 #include <bool.h> 37 37 #include <errno.h> 38 #include <str_error.h>39 38 40 39 #include <usb_iface.h> 41 40 #include <usb/usbdrv.h> 42 41 #include <usb/descriptor.h> 43 #include <usb/recognise.h>44 42 #include <usb/devreq.h> 43 #include <usb/request.h> 45 44 #include <usb/classes/hub.h> 46 45 … … 49 48 #include "port_status.h" 50 49 #include "usb/usb.h" 50 #include "usb/pipes.h" 51 51 52 52 static usb_iface_t hub_usb_iface = { … … 64 64 //********************************************* 65 65 66 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) { 67 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 68 73 //result->device = device; 69 74 result->port_count = -1; … … 71 76 result->device = device; 72 77 73 74 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 75 if (hc < 0) { 76 return result; 77 } 78 //get some hub info 79 usb_address_t addr = usb_drv_get_my_address(hc, device); 80 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 81 /*if(addr<0){ 82 //return result; 83 84 }*/ 85 86 result->address = addr; 87 78 result->usb_device = usb_new(usb_hcd_attached_device_info_t); 79 88 80 // get hub descriptor 89 81 … … 94 86 int opResult; 95 87 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 96 97 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, 98 90 USB_REQUEST_TYPE_CLASS, 99 91 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 100 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 101 101 102 102 if (opResult != EOK) { … … 143 143 dev->ops = &hub_device_ops; 144 144 145 //create the hub structure 146 //get hc connection 147 int hc = usb_drv_hc_connect_auto(dev, 0); 148 if (hc < 0) { 149 return hc; 150 } 151 152 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); 153 148 int port; 154 149 int opResult; 155 usb_target_t target;156 target.address = hub_info->address;157 target.endpoint = 0;150 //usb_target_t target; 151 //target.address = hub_info->usb_device->address; 152 //target.endpoint = 0; 158 153 159 154 //get configuration descriptor … … 161 156 // and all should be checked 162 157 usb_standard_device_descriptor_t std_descriptor; 163 opResult = usb_ drv_req_get_device_descriptor(hc, target.address,158 opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control, 164 159 &std_descriptor); 165 160 if(opResult!=EOK){ … … 174 169 /// \TODO check other configurations 175 170 usb_standard_configuration_descriptor_t config_descriptor; 176 opResult = usb_ drv_req_get_bare_configuration_descriptor(hc,177 target.address, 0,171 opResult = usb_request_get_bare_configuration_descriptor( 172 &hub_info->endpoints.control, 0, 178 173 &config_descriptor); 179 174 if(opResult!=EOK){ … … 182 177 } 183 178 //set configuration 184 opResult = usb_ drv_req_set_configuration(hc, target.address,179 opResult = usb_request_set_configuration(&hub_info->endpoints.control, 185 180 config_descriptor.configuration_number); 186 181 … … 192 187 for (port = 1; port < hub_info->port_count+1; ++port) { 193 188 usb_hub_set_power_port_request(&request, port); 194 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); 195 191 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 196 192 if (opResult != EOK) { … … 200 196 //ports powered, hub seems to be enabled 201 197 202 async_hangup(hc); 198 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 199 //async_hangup(hc); 203 200 204 201 //add the hub to list … … 215 212 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 216 213 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 217 hub_info-> address,214 hub_info->usb_device->address, 218 215 hub_info->port_count); 219 216 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 252 249 * @param target 253 250 */ 254 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) { 255 252 usb_device_request_setup_packet_t request; 256 253 int opResult; 257 254 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 258 255 //get default address 256 ///////////////here ended pipe api upgrading 257 gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld 259 258 opResult = usb_drv_reserve_default_address(hc); 260 259 if (opResult != EOK) { … … 318 317 } 319 318 320 devman_handle_t hc_handle;321 opResult = usb_drv_find_hc(hub->device, &hc_handle);322 if (opResult != EOK) {323 usb_log_error("Failed to get handle of host controller: %s.\n",324 str_error(opResult));325 return;326 }327 328 319 devman_handle_t child_handle; 329 opResult = usb_device_register_child_in_devman(new_device_address,330 hc_handle, hub->device, &child_handle);320 opResult = usb_drv_register_child_in_devman(hc, hub->device, 321 new_device_address, &child_handle); 331 322 if (opResult != EOK) { 332 323 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); … … 383 374 * @param target 384 375 */ 385 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,386 uint16_t port , usb_address_t address) {376 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 377 uint16_t port) { 387 378 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 388 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 /* 389 387 usb_target_t target; 390 388 target.address=address; 391 389 target.endpoint=0; 390 */ 391 392 392 usb_port_status_t status; 393 393 size_t rcvd_size; 394 394 usb_device_request_setup_packet_t request; 395 int opResult;395 //int opResult; 396 396 usb_hub_set_port_status_request(&request, port); 397 397 //endpoint 0 398 398 399 opResult = usb_ drv_sync_control_read(400 hc, target,401 &request, 399 opResult = usb_endpoint_pipe_control_read( 400 pipe, 401 &request, sizeof(usb_device_request_setup_packet_t), 402 402 &status, 4, &rcvd_size 403 403 ); … … 412 412 //something connected/disconnected 413 413 if (usb_port_connect_change(&status)) { 414 opResult = usb_hub_clear_port_feature( hc, target.address,414 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 415 415 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 416 416 // TODO: check opResult 417 417 if (usb_port_dev_connected(&status)) { 418 418 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 419 usb_hub_init_add_device(h c, port, target);419 usb_hub_init_add_device(hub, port); 420 420 } else { 421 usb_hub_removed_device(hub, hc, port, target);421 usb_hub_removed_device(hub, port); 422 422 } 423 423 } … … 426 426 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 427 427 if (usb_port_enabled(&status)) { 428 usb_hub_finalize_add_device(hub, hc, port, target);428 usb_hub_finalize_add_device(hub, port); 429 429 } else { 430 430 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 442 442 /// \TODO handle other changes 443 443 /// \TODO debug log for various situations 444 usb_endpoint_pipe_end_session(&hub->endpoints.control); 445 444 446 445 447 } … … 459 461 fibril_mutex_unlock(&usb_hub_list_lock); 460 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 } 461 469 /* 462 470 * Check status change pipe of this hub. 463 471 */ 464 472 /* 465 473 usb_target_t target; 466 target.address = hub_info-> address;474 target.address = hub_info->usb_device->address; 467 475 target.endpoint = 1;/// \TODO get from endpoint descriptor 468 476 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 469 477 target.address); 470 478 */ 471 479 size_t port_count = hub_info->port_count; 472 480 473 481 /* 474 482 * Connect to respective HC. 475 * /483 * 476 484 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 477 485 if (hc < 0) { 478 486 continue; 479 } 487 }*/ 480 488 481 489 /// FIXME: count properly … … 489 497 * Send the request. 490 498 */ 491 int opResult = usb_drv_async_interrupt_in(hc, target, 499 opResult = usb_endpoint_pipe_read( 500 &hub_info->endpoints.status_change, 492 501 change_bitmap, byte_length, &actual_size, 493 &handle);502 ); 494 503 495 504 usb_drv_async_wait_for(handle); … … 506 515 if (interrupt) { 507 516 usb_hub_process_interrupt( 508 hub_info, hc, port, hub_info->address);517 hub_info, port); 509 518 } 510 519 } 520 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 511 521 free(change_bitmap); 512 513 async_hangup(hc); 522 523 524 //async_hangup(hc); 514 525 fibril_mutex_lock(&usb_hub_list_lock); 515 526 }
Note:
See TracChangeset
for help on using the changeset viewer.