Changes in / [423e8c81:62066b4] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r423e8c81 r62066b4 43 43 #include <usb/recognise.h> 44 44 #include <usb/devreq.h> 45 #include <usb/request.h> 45 46 #include <usb/classes/hub.h> 46 47 … … 49 50 #include "port_status.h" 50 51 #include "usb/usb.h" 52 #include "usb/pipes.h" 51 53 52 54 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle) … … 69 71 //********************************************* 70 72 71 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc) {73 usb_hub_info_t * usb_create_hub_info(device_t * device) { 72 74 usb_hub_info_t* result = usb_new(usb_hub_info_t); 75 usb_device_connection_initialize_from_device(&result->device_connection, 76 device); 77 usb_hc_connection_initialize_from_device(&result->connection, 78 device); 79 usb_endpoint_pipe_initialize_default_control(&result->endpoints.control, 80 &result->device_connection); 81 82 73 83 //result->device = device; 74 84 result->port_count = -1; … … 76 86 result->device = device; 77 87 78 79 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 80 if (hc < 0) { 81 return result; 82 } 83 //get some hub info 84 usb_address_t addr = usb_drv_get_my_address(hc, device); 85 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 86 /*if(addr<0){ 87 //return result; 88 89 }*/ 90 91 result->address = addr; 92 88 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 89 93 90 // get hub descriptor 94 91 … … 99 96 int opResult; 100 97 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 101 102 opResult = usb_ drv_req_get_descriptor(hc, addr,98 usb_endpoint_pipe_start_session(&result->endpoints.control); 99 opResult = usb_request_get_descriptor(&result->endpoints.control, 103 100 USB_REQUEST_TYPE_CLASS, 104 101 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 105 102 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 103 usb_endpoint_pipe_end_session(&result->endpoints.control); 104 105 /* Initialize the interrupt endpoint. 106 usb_endpoint_pipe_initalize( 107 &hub_data->endpoints->status_change, 108 &endpiont_descriptor, &hub_data->connection); 109 110 */ /// \TODO add this call 106 111 107 112 if (opResult != EOK) { … … 119 124 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 120 125 result->port_count = descriptor->ports_count; 121 result->attached_devs = (usb_h ub_attached_device_t*)122 malloc((result->port_count+1) * sizeof(usb_h ub_attached_device_t));126 result->attached_devs = (usb_hc_attached_device_t*) 127 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t)); 123 128 int i; 124 129 for(i=0;i<result->port_count+1;++i){ 125 result->attached_devs[i]. devman_handle=0;130 result->attached_devs[i].handle=0; 126 131 result->attached_devs[i].address=0; 127 132 } … … 148 153 dev->ops = &hub_device_ops; 149 154 150 //create the hub structure 151 //get hc connection 152 int hc = usb_drv_hc_connect_auto(dev, 0); 153 if (hc < 0) { 154 return hc; 155 } 156 157 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 155 156 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 157 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 158 158 159 int port; 159 160 int opResult; 160 usb_target_t target;161 target.address = hub_info->address;162 target.endpoint = 0;161 //usb_target_t target; 162 //target.address = hub_info->usb_device->address; 163 //target.endpoint = 0; 163 164 164 165 //get configuration descriptor … … 166 167 // and all should be checked 167 168 usb_standard_device_descriptor_t std_descriptor; 168 opResult = usb_ drv_req_get_device_descriptor(hc, target.address,169 opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control, 169 170 &std_descriptor); 170 171 if(opResult!=EOK){ … … 179 180 /// \TODO check other configurations 180 181 usb_standard_configuration_descriptor_t config_descriptor; 181 opResult = usb_ drv_req_get_bare_configuration_descriptor(hc,182 target.address, 0,182 opResult = usb_request_get_bare_configuration_descriptor( 183 &hub_info->endpoints.control, 0, 183 184 &config_descriptor); 184 185 if(opResult!=EOK){ … … 187 188 } 188 189 //set configuration 189 opResult = usb_ drv_req_set_configuration(hc, target.address,190 opResult = usb_request_set_configuration(&hub_info->endpoints.control, 190 191 config_descriptor.configuration_number); 191 192 … … 197 198 for (port = 1; port < hub_info->port_count+1; ++port) { 198 199 usb_hub_set_power_port_request(&request, port); 199 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 200 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 201 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 200 202 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 201 203 if (opResult != EOK) { … … 205 207 //ports powered, hub seems to be enabled 206 208 207 async_hangup(hc); 209 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 210 //async_hangup(hc); 208 211 209 212 //add the hub to list … … 219 222 220 223 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 224 //address is lost... 221 225 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 222 hub_info->address,226 //hub_info->endpoints.control., 223 227 hub_info->port_count); 224 228 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 257 261 * @param target 258 262 */ 259 static void usb_hub_init_add_device( int hc, uint16_t port, usb_target_t target) {263 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) { 260 264 usb_device_request_setup_packet_t request; 261 265 int opResult; 262 266 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 267 assert(hub->endpoints.control.hc_phone); 263 268 //get default address 264 opResult = usb_drv_reserve_default_address(hc); 269 //opResult = usb_drv_reserve_default_address(hc); 270 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 265 271 if (opResult != EOK) { 266 272 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 269 275 //reset port 270 276 usb_hub_set_reset_port_request(&request, port); 271 opResult = usb_ drv_sync_control_write(272 hc, target,273 &request, 277 opResult = usb_endpoint_pipe_control_write( 278 &hub->endpoints.control, 279 &request,sizeof(usb_device_request_setup_packet_t), 274 280 NULL, 0 275 281 ); 276 282 if (opResult != EOK) { 277 283 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 278 usb_hub_release_default_address(hc); 284 //usb_hub_release_default_address(hc); 285 usb_hc_release_default_address(&hub->connection); 279 286 } 280 287 } … … 287 294 */ 288 295 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 289 int hc, uint16_t port, usb_target_t target) {296 uint16_t port) { 290 297 291 298 int opResult; 292 299 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 293 opResult = usb_hub_clear_port_feature( hc, target.address,300 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 294 301 port, USB_HUB_FEATURE_C_PORT_RESET); 302 295 303 if (opResult != EOK) { 296 304 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 297 usb_hub_release_default_address(hc); 298 return; 299 } 300 301 /* Request address at from host controller. */ 302 usb_address_t new_device_address = usb_drv_request_address(hc); 305 usb_hc_release_default_address(&hub->connection); 306 return; 307 } 308 //create connection to device 309 usb_endpoint_pipe_t new_device_pipe; 310 usb_device_connection_t new_device_connection; 311 usb_device_connection_initialize_on_default_address( 312 &new_device_connection, 313 &hub->connection 314 ); 315 usb_endpoint_pipe_initialize_default_control( 316 &new_device_pipe, 317 &new_device_connection); 318 /// \TODO get highspeed info 319 320 321 322 323 324 /* Request address from host controller. */ 325 usb_address_t new_device_address = usb_hc_request_address( 326 &hub->connection, 327 USB_SPEED_LOW/// \TODO fullspeed?? 328 ); 303 329 if (new_device_address < 0) { 304 330 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 305 331 opResult = new_device_address; 306 usb_h ub_release_default_address(hc);332 usb_hc_release_default_address(&hub->connection); 307 333 return; 308 334 } 309 335 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 310 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 311 new_device_address); 336 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 337 // new_device_address); 338 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 312 339 313 340 if (opResult != EOK) { 314 341 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 315 usb_hub_release_default_address(hc); 316 return; 317 } 318 319 320 opResult = usb_hub_release_default_address(hc); 342 usb_hc_release_default_address(&hub->connection); 343 return; 344 } 345 346 347 //opResult = usb_hub_release_default_address(hc); 348 opResult = usb_hc_release_default_address(&hub->connection); 321 349 if(opResult!=EOK){ 322 350 return; 323 351 } 324 352 325 devman_handle_t hc_handle;326 opResult = usb_drv_find_hc(hub->device, &hc_handle);327 if (opResult != EOK) {328 usb_log_error("Failed to get handle of host controller: %s.\n",329 str_error(opResult));330 return;331 }332 333 353 devman_handle_t child_handle; 334 opResult = usb_device_register_child_in_devman(new_device_address, 335 hc_handle, hub->device, &child_handle); 354 //?? 355 opResult = usb_device_register_child_in_devman(new_device_address, 356 hub->connection.hc_handle, hub->device, &child_handle); 357 336 358 if (opResult != EOK) { 337 359 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 338 360 return; 339 361 } 340 hub->attached_devs[port]. devman_handle = child_handle;362 hub->attached_devs[port].handle = child_handle; 341 363 hub->attached_devs[port].address = new_device_address; 342 364 343 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 365 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 366 opResult = usb_hc_register_device( 367 &hub->connection, 368 &hub->attached_devs[port]); 344 369 if (opResult != EOK) { 345 370 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 358 383 */ 359 384 static void usb_hub_removed_device( 360 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {385 usb_hub_info_t * hub,uint16_t port) { 361 386 //usb_device_request_setup_packet_t request; 362 387 int opResult; … … 365 390 * devide manager 366 391 */ 367 368 hub->attached_devs[port].devman_handle=0; 392 369 393 //close address 370 394 if(hub->attached_devs[port].address!=0){ 371 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 395 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 396 opResult = usb_hc_unregister_device( 397 &hub->connection, hub->attached_devs[port].address); 372 398 if(opResult != EOK) { 373 399 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 375 401 } 376 402 hub->attached_devs[port].address = 0; 403 hub->attached_devs[port].handle = 0; 377 404 }else{ 378 405 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 379 406 //device was disconnected before it`s port was reset - return default address 380 usb_drv_release_default_address(hc); 407 //usb_drv_release_default_address(hc); 408 usb_hc_release_default_address(&hub->connection); 381 409 } 382 410 } … … 388 416 * @param target 389 417 */ 390 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,391 uint16_t port , usb_address_t address) {418 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 419 uint16_t port) { 392 420 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 393 421 //determine type of change 422 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; 423 int opResult = usb_endpoint_pipe_start_session(pipe); 424 425 if(opResult != EOK){ 426 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult); 427 } 428 429 /* 394 430 usb_target_t target; 395 431 target.address=address; 396 432 target.endpoint=0; 433 */ 434 397 435 usb_port_status_t status; 398 436 size_t rcvd_size; 399 437 usb_device_request_setup_packet_t request; 400 int opResult;438 //int opResult; 401 439 usb_hub_set_port_status_request(&request, port); 402 440 //endpoint 0 403 441 404 opResult = usb_ drv_sync_control_read(405 hc, target,406 &request, 442 opResult = usb_endpoint_pipe_control_read( 443 pipe, 444 &request, sizeof(usb_device_request_setup_packet_t), 407 445 &status, 4, &rcvd_size 408 446 ); … … 417 455 //something connected/disconnected 418 456 if (usb_port_connect_change(&status)) { 419 opResult = usb_hub_clear_port_feature( hc, target.address,457 opResult = usb_hub_clear_port_feature(pipe, 420 458 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 421 459 // TODO: check opResult 422 460 if (usb_port_dev_connected(&status)) { 423 461 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 424 usb_hub_init_add_device(h c, port, target);462 usb_hub_init_add_device(hub, port); 425 463 } else { 426 usb_hub_removed_device(hub, hc, port, target);464 usb_hub_removed_device(hub, port); 427 465 } 428 466 } … … 431 469 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 432 470 if (usb_port_enabled(&status)) { 433 usb_hub_finalize_add_device(hub, hc, port, target);471 usb_hub_finalize_add_device(hub, port); 434 472 } else { 435 473 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 447 485 /// \TODO handle other changes 448 486 /// \TODO debug log for various situations 487 usb_endpoint_pipe_end_session(pipe); 488 449 489 450 490 } … … 464 504 fibril_mutex_unlock(&usb_hub_list_lock); 465 505 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 506 int opResult; 507 508 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 509 if(opResult != EOK){ 510 continue; 511 } 466 512 /* 467 513 * Check status change pipe of this hub. 468 514 */ 469 515 /* 470 516 usb_target_t target; 471 517 target.address = hub_info->address; … … 473 519 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 474 520 target.address); 475 521 */ 476 522 size_t port_count = hub_info->port_count; 477 523 478 524 /* 479 525 * Connect to respective HC. 480 * /526 * 481 527 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 482 528 if (hc < 0) { 483 529 continue; 484 } 530 }*/ 485 531 486 532 /// FIXME: count properly … … 489 535 void *change_bitmap = malloc(byte_length); 490 536 size_t actual_size; 491 usb_handle_t handle;537 //usb_handle_t handle; 492 538 493 539 /* 494 540 * Send the request. 495 541 */ 496 int opResult = usb_drv_async_interrupt_in(hc, target, 497 change_bitmap, byte_length, &actual_size, 498 &handle); 499 500 usb_drv_async_wait_for(handle); 542 opResult = usb_endpoint_pipe_read( 543 &hub_info->endpoints.status_change, 544 change_bitmap, byte_length, &actual_size 545 ); 546 547 //usb_drv_async_wait_for(handle); 501 548 502 549 if (opResult != EOK) { … … 511 558 if (interrupt) { 512 559 usb_hub_process_interrupt( 513 hub_info, hc, port, hub_info->address);560 hub_info, port); 514 561 } 515 562 } 563 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 516 564 free(change_bitmap); 517 518 async_hangup(hc); 565 566 567 //async_hangup(hc); 519 568 fibril_mutex_lock(&usb_hub_list_lock); 520 569 } -
uspace/drv/usbhub/usbhub.h
r423e8c81 r62066b4 42 42 #define NAME "usbhub" 43 43 44 /** basic information about device attached to hub */ 45 typedef struct{ 46 usb_address_t address; 47 devman_handle_t devman_handle; 48 }usb_hub_attached_device_t; 44 //#include "usb/hcdhubd.h" 45 #include <usb/usbdrv.h> 46 #include <usb/hub.h> 47 48 #include <usb/pipes.h> 49 50 /* Hub endpoints. */ 51 typedef struct { 52 usb_endpoint_pipe_t control; 53 usb_endpoint_pipe_t status_change; 54 } usb_hub_endpoints_t; 55 56 49 57 50 58 /** Information about attached hub. */ … … 52 60 /** Number of ports. */ 53 61 int port_count; 54 /** attached device handles */55 usb_h ub_attached_device_t * attached_devs;56 /** USB address of the hub. */57 usb_address_t address;62 /** attached device handles, for each port one */ 63 usb_hc_attached_device_t * attached_devs; 64 /** General usb device info. */ 65 //usb_hcd_attached_device_info_t * usb_device; 58 66 /** General device info*/ 59 67 device_t * device; 68 /** connection to hcd */ 69 //usb_device_connection_t connection; 70 usb_hc_connection_t connection; 71 /** */ 72 usb_device_connection_t device_connection; 73 /** hub endpoints */ 74 usb_hub_endpoints_t endpoints; 60 75 } usb_hub_info_t; 61 76 -
uspace/drv/usbhub/usbhub_private.h
r423e8c81 r62066b4 45 45 #include <fibril_synch.h> 46 46 47 #include <usb/classes/hub.h> 47 48 #include <usb/usb.h> 48 49 #include <usb/usbdrv.h> 49 #include <usb/classes/hub.h> 50 #include <usb/devreq.h>50 51 //#include <usb/devreq.h> 51 52 #include <usb/debug.h> 52 53 … … 77 78 * @return 78 79 */ 79 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc);80 usb_hub_info_t * usb_create_hub_info(device_t * device); 80 81 81 82 /** List of hubs maanged by this driver */ … … 98 99 * @return error code 99 100 */ 101 /* 100 102 int usb_drv_sync_control_read( 101 int phone, usb_target_t target,103 usb_endpoint_pipe_t *pipe, 102 104 usb_device_request_setup_packet_t * request, 103 105 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size 104 ); 106 );*/ 105 107 106 108 /** … … 115 117 * @return error code 116 118 */ 117 int usb_drv_sync_control_write(118 int phone, usb_target_t target,119 /*int usb_drv_sync_control_write( 120 usb_endpoint_pipe_t *pipe, 119 121 usb_device_request_setup_packet_t * request, 120 122 void * sent_buffer, size_t sent_size 121 ); 123 );*/ 122 124 123 125 /** … … 147 149 * @return Operation result 148 150 */ 149 static inline int usb_hub_clear_port_feature( int hc, usb_address_t address,151 static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe, 150 152 int port_index, 151 153 usb_hub_class_feature_t feature) { 152 usb_target_t target = { 153 .address = address, 154 .endpoint = 0 155 }; 154 156 155 usb_device_request_setup_packet_t clear_request = { 157 156 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, … … 161 160 }; 162 161 clear_request.value = feature; 163 return usb_ drv_psync_control_write(hc, target, &clear_request,162 return usb_endpoint_pipe_control_write(pipe, &clear_request, 164 163 sizeof(clear_request), NULL, 0); 165 164 } -
uspace/drv/usbhub/utils.c
r423e8c81 r62066b4 114 114 115 115 //control transactions 116 116 /* 117 117 int usb_drv_sync_control_read( 118 118 int phone, usb_target_t target, … … 199 199 } 200 200 201 201 */ 202 202 203 203 -
uspace/lib/usb/include/usb/classes/hub.h
r423e8c81 r62066b4 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010 Matus Dekanek 3 3 * All rights reserved. 4 4 * … … 33 33 * @brief USB hub related structures. 34 34 */ 35 #ifndef LIBUSB_ HUB_H_36 #define LIBUSB_ HUB_H_35 #ifndef LIBUSB_CLASS_HUB_H_ 36 #define LIBUSB_CLASS_HUB_H_ 37 37 38 38 #include <sys/types.h>
Note:
See TracChangeset
for help on using the changeset viewer.