Changeset 6c399765 in mainline
- Timestamp:
- 2011-04-03T20:06:39Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 195890b
- Parents:
- fefc27d
- Location:
- uspace/drv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
rfefc27d r6c399765 244 244 { 245 245 assert(instance); 246 instance->address = -1;246 //instance->address = -1; 247 247 instance->registers = regs; 248 248 instance->device = dev; … … 278 278 request->transfered_size = 4; 279 279 uint32_buffer[0] = instance->registers->rh_port_status[port -1]; 280 #if 0 281 int i; 282 for(i=0;i<instance->port_count;++i){ 283 usb_log_debug("port status %d,x%x\n", 284 instance->registers->rh_port_status[i], 285 instance->registers->rh_port_status[i]); 286 } 287 #endif 280 288 return EOK; 281 289 } … … 298 306 uint32_buffer[0] = mask & instance->registers->rh_status; 299 307 return EOK; 300 301 308 } 302 309 … … 339 346 * Result contains bitmap where bit 0 indicates change on hub and 340 347 * bit i indicates change on i`th port (i>0). For more info see 341 * Hub and Port status bitmap specification in USB specification. 348 * Hub and Port status bitmap specification in USB specification 349 * (chapter 11.13.4) 342 350 * @param instance root hub instance 343 351 * @param@out buffer pointer to created interrupt mas … … 347 355 size_t * buffer_size){ 348 356 int bit_count = instance->port_count + 1; 349 (*buffer_size) = (bit_count / 8) + (bit_count%8==0)?0:1; 357 (*buffer_size) = (bit_count / 8) + ((bit_count%8==0)?0:1); 358 350 359 (*buffer) = malloc(*buffer_size); 351 360 uint8_t * bitmap = (uint8_t*)(*buffer); 352 uint32_t mask = (1<<16) + (1<<17); 361 uint32_t mask = (1<<(USB_HUB_FEATURE_C_HUB_LOCAL_POWER+16)) 362 | (1<<(USB_HUB_FEATURE_C_HUB_OVER_CURRENT+16)); 353 363 bzero(bitmap,(*buffer_size)); 354 364 if(instance->registers->rh_status & mask){ … … 358 368 mask = 0; 359 369 int i; 360 for(i=16;i<=20;++i) 370 for(i=16;i<=20;++i){ 361 371 mask += 1<<i; 372 } 362 373 for(port = 1; port<=instance->port_count;++port){ 363 374 if(mask & instance->registers->rh_port_status[port-1]){ 364 bitmap[(port +1)/8] += 1<<(port%8);375 bitmap[(port)/8] += 1<<(port%8); 365 376 } 366 377 } … … 436 447 request->transfered_size = size; 437 448 memcpy(request->transport_buffer,result_descriptor,size); 438 usb_log_debug("sent desctiptor: %s\n",439 usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));440 449 if (del) 441 450 free(result_descriptor); -
uspace/drv/usbhub/usbhub.c
rfefc27d r6c399765 54 54 55 55 56 static voidusb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,56 static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 57 57 usb_speed_t speed); 58 58 … … 76 76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once 77 77 errorCode = usb_hub_check_hub_changes(hub_info); 78 78 79 } 79 80 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); … … 125 126 * these lines allow to reset hub once more, it can be used as 126 127 * brute-force initialization for non-removable devices 127 int opResult = usb_request_set_configuration(&result->endpoints.control, 1); 128 */ 129 int opResult = usb_request_set_configuration(hub_info->control_pipe, 130 1); 128 131 if(opResult!=EOK){ 129 132 usb_log_error("could not set default configuration, errno %d",opResult); 130 133 return opResult; 131 134 } 132 */ 135 136 133 137 size_t received_size; 134 intopResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,138 opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe, 135 139 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 136 140 USB_DESCTYPE_HUB, … … 163 167 usb_log_debug2("freeing data\n"); 164 168 free(serialized_descriptor); 165 free(descriptor->devices_removable); 166 free(descriptor); 169 hub_info->descriptor = descriptor; 170 hub_info->not_initialized_non_removables = 171 (uint8_t*)malloc((hub_info->port_count+8)/8); 172 memcpy(hub_info->not_initialized_non_removables, 173 descriptor->devices_removable, 174 (hub_info->port_count+8)/8 175 ); 176 177 //free(descriptor->devices_removable); 178 //free(descriptor); 167 179 return EOK; 168 180 } … … 289 301 * @return error code 290 302 */ 291 static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub, 303 static int usb_hub_trigger_connecting_non_removable_devices( 304 usb_hub_info_t * hub, 292 305 usb_hub_descriptor_t * descriptor) 293 306 { 294 307 usb_log_info("attaching non-removable devices(if any)\n"); 295 usb_device_request_setup_packet_t request;308 //usb_device_request_setup_packet_t request; 296 309 int opResult; 297 size_t rcvd_size;298 usb_port_status_t status;310 //size_t rcvd_size; 311 //usb_port_status_t status; 299 312 uint8_t * non_removable_dev_bitmap = descriptor->devices_removable; 300 313 int port; 314 315 opResult = usb_request_set_configuration(hub->control_pipe, 316 1); 317 if(opResult!=EOK){ 318 usb_log_error("could not set default configuration, errno %d",opResult); 319 return opResult; 320 } 321 #if 0 301 322 for(port=1;port<=descriptor->ports_count;++port){ 302 323 bool is_non_removable = … … 315 336 return opResult; 316 337 } 317 if(usb_port_dev_connected(&status)){ 318 usb_hub_set_enable_port_feature_request(&request, port, 319 USB_HUB_FEATURE_PORT_RESET); 320 opResult = usb_pipe_control_read( 321 hub->control_pipe, 322 &request, sizeof(usb_device_request_setup_packet_t), 323 &status, 4, &rcvd_size 324 ); 325 if (opResult != EOK) { 326 usb_log_warning( 327 "could not reset port %d errno:%d\n", 328 port, opResult); 329 } 330 usb_log_debug("port reset\n"); 338 //try to reset port 339 if(usb_port_dev_connected(&status) || true){ 340 usb_hub_set_enable_port_feature_request(&request, port, 341 USB_HUB_FEATURE_PORT_RESET); 342 opResult = usb_pipe_control_read( 343 hub->control_pipe, 344 &request, sizeof(usb_device_request_setup_packet_t), 345 &status, 4, &rcvd_size 346 ); 347 if (opResult != EOK) { 348 usb_log_warning( 349 "could not reset port %d errno:%d\n", 350 port, opResult); 351 } 352 usb_log_debug("port reset, should look like %d,x%x\n", 353 (1<<USB_HUB_FEATURE_PORT_RESET), 354 (1<<USB_HUB_FEATURE_PORT_RESET) 355 ); 331 356 } 332 357 //set the status change bit, so it will be noticed in driver loop 333 /*if(usb_port_dev_connected(&status)){358 if(usb_port_dev_connected(&status) && false){ 334 359 usb_hub_set_disable_port_feature_request(&request, port, 335 360 USB_HUB_FEATURE_PORT_CONNECTION); … … 358 383 } 359 384 usb_log_debug("port set to enabled - should lead to connection change\n"); 360 } */385 } 361 386 } 362 387 } 388 #endif 389 363 390 /// \TODO this is just a debug code 364 391 for(port=1;port<=descriptor->ports_count;++port){ … … 366 393 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2; 367 394 if(is_non_removable){ 368 usb_log_debug(" port %d is non-removable\n",port);395 usb_log_debug("CHECKING port %d is non-removable\n",port); 369 396 usb_port_status_t status; 370 397 size_t rcvd_size; … … 392 419 } 393 420 } 421 394 422 return EOK; 395 423 } … … 419 447 * @param port port number, starting from 1 420 448 * @param speed transfer speed of attached device, one of low, full or high 421 */ 422 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 449 * @return error code 450 */ 451 static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 423 452 usb_speed_t speed) { 424 453 //if this hub already uses default address, it cannot request it once more 425 if(hub->is_default_address_used) return ;454 if(hub->is_default_address_used) return EREFUSED; 426 455 usb_log_debug("some connection changed\n"); 427 456 assert(hub->control_pipe->hc_phone); … … 439 468 usb_log_warning("cannot assign default address, it is probably used %d\n", 440 469 opResult); 441 return ;470 return opResult; 442 471 } 443 472 hub->is_default_address_used = true; … … 453 482 usb_hub_release_default_address(hub); 454 483 } 455 return ;484 return opResult; 456 485 } 457 486 … … 670 699 } 671 700 } 672 usb_log_debug("status %x\n ",status);701 usb_log_debug("status x%x : %d\n ",status,status); 673 702 674 703 usb_port_set_connect_change(&status, false); … … 683 712 } 684 713 714 715 static int initialize_non_removable(usb_hub_info_t * hub_info, 716 unsigned int port){ 717 int opResult; 718 usb_log_debug("there is not pluged in non-removable device on " 719 "port %d\n",port 720 ); 721 //usb_hub_init_add_device(hub_info, port, usb_port_speed(&status)); 722 usb_port_status_t status; 723 size_t rcvd_size; 724 usb_device_request_setup_packet_t request; 725 //int opResult; 726 usb_hub_set_port_status_request(&request, port); 727 //endpoint 0 728 729 opResult = usb_pipe_control_read( 730 hub_info->control_pipe, 731 &request, sizeof(usb_device_request_setup_packet_t), 732 &status, 4, &rcvd_size 733 ); 734 if (opResult != EOK) { 735 usb_log_error("could not get port status %d\n",opResult); 736 return opResult; 737 } 738 if (rcvd_size != sizeof (usb_port_status_t)) { 739 usb_log_error("received status has incorrect size\n"); 740 return opResult; 741 } 742 usb_log_debug("port status %d, x%x\n",status,status); 743 if(usb_port_dev_connected(&status)){ 744 usb_log_debug("there is connected device on this port\n"); 745 } 746 if(!hub_info->is_default_address_used) 747 usb_hub_init_add_device(hub_info, port, usb_port_speed(&status)); 748 return opResult; 749 } 750 685 751 /** 686 752 * check changes on hub … … 694 760 opResult = usb_pipe_start_session( 695 761 hub_info->status_change_pipe); 762 //this might not be necessary - if all non-removables are ok, it is not needed here 763 opResult = usb_pipe_start_session(hub_info->control_pipe); 696 764 if(opResult != EOK){ 697 765 usb_log_error("could not initialize communication for hub; %d\n", … … 701 769 702 770 size_t port_count = hub_info->port_count; 771 //first check non-removable devices 772 { 773 unsigned int port; 774 for(port = 1; port<=port_count; ++port){ 775 bool is_non_removable = 776 hub_info->not_initialized_non_removables[port/8] 777 & (1 << (port%8)); 778 if(is_non_removable){ 779 opResult = initialize_non_removable(hub_info,port); 780 } 781 } 782 } 783 703 784 704 785 /// FIXME: count properly … … 722 803 } 723 804 unsigned int port; 724 opResult = usb_pipe_start_session(hub_info->control_pipe);805 725 806 if(opResult!=EOK){ 726 807 usb_log_error("could not start control pipe session %d\n", opResult); -
uspace/drv/usbhub/usbhub.h
rfefc27d r6c399765 43 43 44 44 #include <usb/hub.h> 45 #include <usb/classes/hub.h> 45 46 46 47 #include <usb/pipes.h> … … 84 85 /** generic usb device data*/ 85 86 usb_device_t * usb_device; 87 88 /** usb hub specific descriptor */ 89 usb_hub_descriptor_t * descriptor; 90 91 /** not yet initialized non-removable devices */ 92 uint8_t * not_initialized_non_removables; 93 86 94 } usb_hub_info_t; 87 95
Note:
See TracChangeset
for help on using the changeset viewer.