Changes in uspace/drv/usbhub/usbhub.c [d81ef61c:28cb8bf7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
rd81ef61c r28cb8bf7 36 36 #include <bool.h> 37 37 #include <errno.h> 38 #include <str_error.h> 38 39 39 40 #include <usb_iface.h> 40 41 #include <usb/usbdrv.h> 41 42 #include <usb/descriptor.h> 43 #include <usb/recognise.h> 42 44 #include <usb/devreq.h> 43 #include <usb/request.h>44 45 #include <usb/classes/hub.h> 45 46 … … 48 49 #include "port_status.h" 49 50 #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 ) {66 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) { 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 73 68 //result->device = device; 74 69 result->port_count = -1; … … 76 71 result->device = device; 77 72 78 result->usb_device = usb_new(usb_hcd_attached_device_info_t); 79 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 80 88 // get hub descriptor 81 89 … … 86 94 int opResult; 87 95 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 88 usb_endpoint_pipe_start_session(&result->endpoints.control);89 opResult = usb_ request_get_descriptor(&result->endpoints.control,96 97 opResult = usb_drv_req_get_descriptor(hc, addr, 90 98 USB_REQUEST_TYPE_CLASS, 91 99 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 92 100 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 call101 101 102 102 if (opResult != EOK) { … … 143 143 dev->ops = &hub_device_ops; 144 144 145 146 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 147 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 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); 148 153 int port; 149 154 int opResult; 150 //usb_target_t target;151 //target.address = hub_info->usb_device->address;152 //target.endpoint = 0;155 usb_target_t target; 156 target.address = hub_info->address; 157 target.endpoint = 0; 153 158 154 159 //get configuration descriptor … … 156 161 // and all should be checked 157 162 usb_standard_device_descriptor_t std_descriptor; 158 opResult = usb_ request_get_device_descriptor(&hub_info->endpoints.control,163 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 159 164 &std_descriptor); 160 165 if(opResult!=EOK){ … … 169 174 /// \TODO check other configurations 170 175 usb_standard_configuration_descriptor_t config_descriptor; 171 opResult = usb_ request_get_bare_configuration_descriptor(172 &hub_info->endpoints.control, 0,176 opResult = usb_drv_req_get_bare_configuration_descriptor(hc, 177 target.address, 0, 173 178 &config_descriptor); 174 179 if(opResult!=EOK){ … … 177 182 } 178 183 //set configuration 179 opResult = usb_ request_set_configuration(&hub_info->endpoints.control,184 opResult = usb_drv_req_set_configuration(hc, target.address, 180 185 config_descriptor.configuration_number); 181 186 … … 187 192 for (port = 1; port < hub_info->port_count+1; ++port) { 188 193 usb_hub_set_power_port_request(&request, port); 189 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 190 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 194 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 191 195 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 192 196 if (opResult != EOK) { … … 196 200 //ports powered, hub seems to be enabled 197 201 198 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 199 //async_hangup(hc); 202 async_hangup(hc); 200 203 201 204 //add the hub to list … … 212 215 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 213 216 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 214 hub_info-> usb_device->address,217 hub_info->address, 215 218 hub_info->port_count); 216 219 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 249 252 * @param target 250 253 */ 251 static void usb_hub_init_add_device( usb_hub_info_t * hub, uint16_t port) {254 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) { 252 255 usb_device_request_setup_packet_t request; 253 256 int opResult; 254 257 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 255 258 //get default address 256 ///////////////here ended pipe api upgrading257 gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld258 259 opResult = usb_drv_reserve_default_address(hc); 259 260 if (opResult != EOK) { … … 317 318 } 318 319 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 319 328 devman_handle_t child_handle; 320 opResult = usb_drv_register_child_in_devman(hc, hub->device,321 new_device_address, &child_handle);329 opResult = usb_device_register_child_in_devman(new_device_address, 330 hc_handle, hub->device, &child_handle); 322 331 if (opResult != EOK) { 323 332 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); … … 374 383 * @param target 375 384 */ 376 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 377 uint16_t port ) {385 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 386 uint16_t port, usb_address_t address) { 378 387 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 379 388 //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 /*387 389 usb_target_t target; 388 390 target.address=address; 389 391 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_ endpoint_pipe_control_read(400 pipe,401 &request, sizeof(usb_device_request_setup_packet_t),399 opResult = usb_drv_sync_control_read( 400 hc, target, 401 &request, 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( &hub->endpoints.control,414 opResult = usb_hub_clear_port_feature(hc, target.address, 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 ub, port);419 usb_hub_init_add_device(hc, port, target); 420 420 } else { 421 usb_hub_removed_device(hub, port);421 usb_hub_removed_device(hub, hc, port, target); 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, port);428 usb_hub_finalize_add_device(hub, hc, port, target); 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 446 444 447 445 } … … 461 459 fibril_mutex_unlock(&usb_hub_list_lock); 462 460 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 }469 461 /* 470 462 * Check status change pipe of this hub. 471 463 */ 472 /* 464 473 465 usb_target_t target; 474 target.address = hub_info-> usb_device->address;466 target.address = hub_info->address; 475 467 target.endpoint = 1;/// \TODO get from endpoint descriptor 476 468 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 477 469 target.address); 478 */ 470 479 471 size_t port_count = hub_info->port_count; 480 472 481 473 /* 482 474 * Connect to respective HC. 483 * 475 */ 484 476 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 485 477 if (hc < 0) { 486 478 continue; 487 } */479 } 488 480 489 481 /// FIXME: count properly … … 497 489 * Send the request. 498 490 */ 499 opResult = usb_endpoint_pipe_read( 500 &hub_info->endpoints.status_change, 491 int opResult = usb_drv_async_interrupt_in(hc, target, 501 492 change_bitmap, byte_length, &actual_size, 502 );493 &handle); 503 494 504 495 usb_drv_async_wait_for(handle); … … 515 506 if (interrupt) { 516 507 usb_hub_process_interrupt( 517 hub_info, port);508 hub_info, hc, port, hub_info->address); 518 509 } 519 510 } 520 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);521 511 free(change_bitmap); 522 523 524 //async_hangup(hc); 512 513 async_hangup(hc); 525 514 fibril_mutex_lock(&usb_hub_list_lock); 526 515 }
Note:
See TracChangeset
for help on using the changeset viewer.