Changes in / [063ead6f:da7c0a9] in mainline
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r063ead6f rda7c0a9 44 44 #include <usb/recognise.h> 45 45 #include <usb/devreq.h> 46 #include <usb/request.h> 46 47 #include <usb/classes/hub.h> 47 48 … … 50 51 #include "port_status.h" 51 52 #include "usb/usb.h" 53 #include "usb/pipes.h" 52 54 53 55 static device_ops_t hub_device_ops = { … … 61 63 //********************************************* 62 64 63 usb_hub_info_t * usb_create_hub_info(device_t * device , int hc) {65 usb_hub_info_t * usb_create_hub_info(device_t * device) { 64 66 usb_hub_info_t* result = usb_new(usb_hub_info_t); 67 usb_device_connection_initialize_from_device(&result->device_connection, 68 device); 69 usb_hc_connection_initialize_from_device(&result->connection, 70 device); 71 usb_endpoint_pipe_initialize_default_control(&result->endpoints.control, 72 &result->device_connection); 73 74 65 75 //result->device = device; 66 76 result->port_count = -1; … … 68 78 result->device = device; 69 79 70 71 dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc); 72 if (hc < 0) { 73 return result; 74 } 75 //get some hub info 76 usb_address_t addr = usb_drv_get_my_address(hc, device); 77 dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr); 78 /*if(addr<0){ 79 //return result; 80 81 }*/ 82 83 result->address = addr; 84 80 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); 81 85 82 // get hub descriptor 86 83 … … 91 88 int opResult; 92 89 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 93 94 opResult = usb_ drv_req_get_descriptor(hc, addr,90 usb_endpoint_pipe_start_session(&result->endpoints.control); 91 opResult = usb_request_get_descriptor(&result->endpoints.control, 95 92 USB_REQUEST_TYPE_CLASS, 96 93 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 97 94 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 95 usb_endpoint_pipe_end_session(&result->endpoints.control); 96 97 /* Initialize the interrupt endpoint. 98 usb_endpoint_pipe_initalize( 99 &hub_data->endpoints->status_change, 100 &endpiont_descriptor, &hub_data->connection); 101 102 */ /// \TODO add this call 98 103 99 104 if (opResult != EOK) { … … 111 116 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 112 117 result->port_count = descriptor->ports_count; 113 result->attached_devs = (usb_h ub_attached_device_t*)114 malloc((result->port_count+1) * sizeof(usb_h ub_attached_device_t));118 result->attached_devs = (usb_hc_attached_device_t*) 119 malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t)); 115 120 int i; 116 121 for(i=0;i<result->port_count+1;++i){ 117 result->attached_devs[i]. devman_handle=0;122 result->attached_devs[i].handle=0; 118 123 result->attached_devs[i].address=0; 119 124 } … … 140 145 dev->ops = &hub_device_ops; 141 146 142 //create the hub structure 143 //get hc connection 144 int hc = usb_drv_hc_connect_auto(dev, 0); 145 if (hc < 0) { 146 return hc; 147 } 148 149 usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc); 147 148 usb_hub_info_t * hub_info = usb_create_hub_info(dev); 149 usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 150 150 151 int port; 151 152 int opResult; 152 usb_target_t target;153 target.address = hub_info->address;154 target.endpoint = 0;153 //usb_target_t target; 154 //target.address = hub_info->usb_device->address; 155 //target.endpoint = 0; 155 156 156 157 //get configuration descriptor … … 158 159 // and all should be checked 159 160 usb_standard_device_descriptor_t std_descriptor; 160 opResult = usb_ drv_req_get_device_descriptor(hc, target.address,161 opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control, 161 162 &std_descriptor); 162 163 if(opResult!=EOK){ … … 171 172 /// \TODO check other configurations 172 173 usb_standard_configuration_descriptor_t config_descriptor; 173 opResult = usb_ drv_req_get_bare_configuration_descriptor(hc,174 target.address, 0,174 opResult = usb_request_get_bare_configuration_descriptor( 175 &hub_info->endpoints.control, 0, 175 176 &config_descriptor); 176 177 if(opResult!=EOK){ … … 179 180 } 180 181 //set configuration 181 opResult = usb_ drv_req_set_configuration(hc, target.address,182 opResult = usb_request_set_configuration(&hub_info->endpoints.control, 182 183 config_descriptor.configuration_number); 183 184 … … 189 190 for (port = 1; port < hub_info->port_count+1; ++port) { 190 191 usb_hub_set_power_port_request(&request, port); 191 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 192 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 193 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 192 194 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 193 195 if (opResult != EOK) { … … 197 199 //ports powered, hub seems to be enabled 198 200 199 async_hangup(hc); 201 usb_endpoint_pipe_end_session(&hub_info->endpoints.control); 202 //async_hangup(hc); 200 203 201 204 //add the hub to list … … 211 214 212 215 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 216 //address is lost... 213 217 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 214 hub_info->address,218 //hub_info->endpoints.control., 215 219 hub_info->port_count); 216 220 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number); … … 249 253 * @param target 250 254 */ 251 static void usb_hub_init_add_device( int hc, uint16_t port, usb_target_t target) {255 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) { 252 256 usb_device_request_setup_packet_t request; 253 257 int opResult; 254 258 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 259 assert(hub->endpoints.control.hc_phone); 255 260 //get default address 256 opResult = usb_drv_reserve_default_address(hc); 261 //opResult = usb_drv_reserve_default_address(hc); 262 opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW); 263 257 264 if (opResult != EOK) { 258 265 dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used"); … … 261 268 //reset port 262 269 usb_hub_set_reset_port_request(&request, port); 263 opResult = usb_ drv_sync_control_write(264 hc, target,265 &request, 270 opResult = usb_endpoint_pipe_control_write( 271 &hub->endpoints.control, 272 &request,sizeof(usb_device_request_setup_packet_t), 266 273 NULL, 0 267 274 ); 268 275 if (opResult != EOK) { 269 276 dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port"); 270 usb_hub_release_default_address(hc); 277 //usb_hub_release_default_address(hc); 278 usb_hc_release_default_address(&hub->connection); 271 279 } 272 280 } … … 279 287 */ 280 288 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, 281 int hc, uint16_t port, usb_target_t target) {289 uint16_t port) { 282 290 283 291 int opResult; 284 292 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 285 opResult = usb_hub_clear_port_feature( hc, target.address,293 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 286 294 port, USB_HUB_FEATURE_C_PORT_RESET); 295 287 296 if (opResult != EOK) { 288 297 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 289 usb_hub_release_default_address(hc); 290 return; 291 } 292 293 /* Request address at from host controller. */ 294 usb_address_t new_device_address = usb_drv_request_address(hc); 298 usb_hc_release_default_address(&hub->connection); 299 return; 300 } 301 //create connection to device 302 usb_endpoint_pipe_t new_device_pipe; 303 usb_device_connection_t new_device_connection; 304 usb_device_connection_initialize_on_default_address( 305 &new_device_connection, 306 &hub->connection 307 ); 308 usb_endpoint_pipe_initialize_default_control( 309 &new_device_pipe, 310 &new_device_connection); 311 /// \TODO get highspeed info 312 313 314 315 316 317 /* Request address from host controller. */ 318 usb_address_t new_device_address = usb_hc_request_address( 319 &hub->connection, 320 USB_SPEED_LOW/// \TODO fullspeed?? 321 ); 295 322 if (new_device_address < 0) { 296 323 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 297 324 opResult = new_device_address; 298 usb_h ub_release_default_address(hc);325 usb_hc_release_default_address(&hub->connection); 299 326 return; 300 327 } 301 328 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 302 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 303 new_device_address); 329 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 330 // new_device_address); 331 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 304 332 305 333 if (opResult != EOK) { 306 334 dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device"); 307 usb_hub_release_default_address(hc); 308 return; 309 } 310 311 312 opResult = usb_hub_release_default_address(hc); 335 usb_hc_release_default_address(&hub->connection); 336 return; 337 } 338 339 340 //opResult = usb_hub_release_default_address(hc); 341 opResult = usb_hc_release_default_address(&hub->connection); 313 342 if(opResult!=EOK){ 314 343 return; 315 344 } 316 345 317 devman_handle_t hc_handle;318 opResult = usb_drv_find_hc(hub->device, &hc_handle);319 if (opResult != EOK) {320 usb_log_error("Failed to get handle of host controller: %s.\n",321 str_error(opResult));322 return;323 }324 325 346 devman_handle_t child_handle; 326 opResult = usb_device_register_child_in_devman(new_device_address, 327 hc_handle, hub->device, &child_handle); 347 //?? 348 opResult = usb_device_register_child_in_devman(new_device_address, 349 hub->connection.hc_handle, hub->device, &child_handle); 350 328 351 if (opResult != EOK) { 329 352 dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device"); 330 353 return; 331 354 } 332 hub->attached_devs[port]. devman_handle = child_handle;355 hub->attached_devs[port].handle = child_handle; 333 356 hub->attached_devs[port].address = new_device_address; 334 357 335 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 358 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 359 opResult = usb_hc_register_device( 360 &hub->connection, 361 &hub->attached_devs[port]); 336 362 if (opResult != EOK) { 337 363 dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd"); … … 350 376 */ 351 377 static void usb_hub_removed_device( 352 usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {378 usb_hub_info_t * hub,uint16_t port) { 353 379 //usb_device_request_setup_packet_t request; 354 380 int opResult; … … 357 383 * devide manager 358 384 */ 359 360 hub->attached_devs[port].devman_handle=0; 385 361 386 //close address 362 387 if(hub->attached_devs[port].address!=0){ 363 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 388 //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 389 opResult = usb_hc_unregister_device( 390 &hub->connection, hub->attached_devs[port].address); 364 391 if(opResult != EOK) { 365 392 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ … … 367 394 } 368 395 hub->attached_devs[port].address = 0; 396 hub->attached_devs[port].handle = 0; 369 397 }else{ 370 398 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 371 399 //device was disconnected before it`s port was reset - return default address 372 usb_drv_release_default_address(hc); 400 //usb_drv_release_default_address(hc); 401 usb_hc_release_default_address(&hub->connection); 373 402 } 374 403 } … … 380 409 * @param target 381 410 */ 382 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,383 uint16_t port , usb_address_t address) {411 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 412 uint16_t port) { 384 413 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 385 414 //determine type of change 415 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; 416 int opResult = usb_endpoint_pipe_start_session(pipe); 417 418 if(opResult != EOK){ 419 dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult); 420 } 421 422 /* 386 423 usb_target_t target; 387 424 target.address=address; 388 425 target.endpoint=0; 426 */ 427 389 428 usb_port_status_t status; 390 429 size_t rcvd_size; 391 430 usb_device_request_setup_packet_t request; 392 int opResult;431 //int opResult; 393 432 usb_hub_set_port_status_request(&request, port); 394 433 //endpoint 0 395 434 396 opResult = usb_ drv_sync_control_read(397 hc, target,398 &request, 435 opResult = usb_endpoint_pipe_control_read( 436 pipe, 437 &request, sizeof(usb_device_request_setup_packet_t), 399 438 &status, 4, &rcvd_size 400 439 ); … … 409 448 //something connected/disconnected 410 449 if (usb_port_connect_change(&status)) { 411 opResult = usb_hub_clear_port_feature( hc, target.address,450 opResult = usb_hub_clear_port_feature(pipe, 412 451 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 413 452 // TODO: check opResult 414 453 if (usb_port_dev_connected(&status)) { 415 454 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 416 usb_hub_init_add_device(h c, port, target);455 usb_hub_init_add_device(hub, port); 417 456 } else { 418 usb_hub_removed_device(hub, hc, port, target);457 usb_hub_removed_device(hub, port); 419 458 } 420 459 } … … 423 462 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 424 463 if (usb_port_enabled(&status)) { 425 usb_hub_finalize_add_device(hub, hc, port, target);464 usb_hub_finalize_add_device(hub, port); 426 465 } else { 427 466 dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled"); … … 439 478 /// \TODO handle other changes 440 479 /// \TODO debug log for various situations 480 usb_endpoint_pipe_end_session(pipe); 481 441 482 442 483 } … … 456 497 fibril_mutex_unlock(&usb_hub_list_lock); 457 498 usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data); 499 int opResult; 500 501 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 502 if(opResult != EOK){ 503 continue; 504 } 458 505 /* 459 506 * Check status change pipe of this hub. 460 507 */ 461 508 /* 462 509 usb_target_t target; 463 510 target.address = hub_info->address; … … 465 512 dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d", 466 513 target.address); 467 514 */ 468 515 size_t port_count = hub_info->port_count; 469 516 470 517 /* 471 518 * Connect to respective HC. 472 * /519 * 473 520 int hc = usb_drv_hc_connect_auto(hub_info->device, 0); 474 521 if (hc < 0) { 475 522 continue; 476 } 523 }*/ 477 524 478 525 /// FIXME: count properly … … 481 528 void *change_bitmap = malloc(byte_length); 482 529 size_t actual_size; 483 usb_handle_t handle;530 //usb_handle_t handle; 484 531 485 532 /* 486 533 * Send the request. 487 534 */ 488 int opResult = usb_drv_async_interrupt_in(hc, target, 489 change_bitmap, byte_length, &actual_size, 490 &handle); 491 492 usb_drv_async_wait_for(handle); 535 opResult = usb_endpoint_pipe_read( 536 &hub_info->endpoints.status_change, 537 change_bitmap, byte_length, &actual_size 538 ); 539 540 //usb_drv_async_wait_for(handle); 493 541 494 542 if (opResult != EOK) { … … 503 551 if (interrupt) { 504 552 usb_hub_process_interrupt( 505 hub_info, hc, port, hub_info->address);553 hub_info, port); 506 554 } 507 555 } 556 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 508 557 free(change_bitmap); 509 510 async_hangup(hc); 558 559 560 //async_hangup(hc); 511 561 fibril_mutex_lock(&usb_hub_list_lock); 512 562 } -
uspace/drv/usbhub/usbhub.h
r063ead6f rda7c0a9 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
r063ead6f rda7c0a9 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
r063ead6f rda7c0a9 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
r063ead6f rda7c0a9 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.