Changes in / [d527a4e:4d946647] in mainline
- Location:
- uspace/drv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
rd527a4e r4d946647 110 110 .poll_interval = 255, 111 111 }; 112 113 static const uint32_t hub_clear_feature_valid_mask = 114 (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) + 115 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 116 117 static const uint32_t hub_clear_feature_by_writing_one_mask = 118 1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER; 119 120 static const uint32_t hub_set_feature_valid_mask = 121 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 122 123 124 static const uint32_t hub_set_feature_direct_mask = 125 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 126 127 static const uint32_t port_set_feature_valid_mask = 128 (1 << USB_HUB_FEATURE_PORT_ENABLE) + 129 (1 << USB_HUB_FEATURE_PORT_SUSPEND) + 130 (1 << USB_HUB_FEATURE_PORT_RESET) + 131 (1 << USB_HUB_FEATURE_PORT_POWER); 132 133 static const uint32_t port_clear_feature_valid_mask = 134 (1 << USB_HUB_FEATURE_PORT_CONNECTION) + 135 (1 << USB_HUB_FEATURE_PORT_SUSPEND) + 136 (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) + 137 (1 << USB_HUB_FEATURE_PORT_POWER) + 138 (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) + 139 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) + 140 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) + 141 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) + 142 (1 << USB_HUB_FEATURE_C_PORT_RESET); 143 //note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED 144 145 146 112 147 113 148 /** … … 212 247 instance->registers = regs; 213 248 instance->device = dev; 249 instance->port_count = instance->registers->rh_desc_a & 0xff; 214 250 rh_init_descriptors(instance); 251 /// \TODO set port power mode 215 252 216 253 … … 426 463 427 464 /** 428 * process feature-enabling /disablingrequest on hub465 * process feature-enabling request on hub 429 466 * 430 467 * @param instance root hub instance 431 468 * @param feature feature selector 432 * @param enable enable or disable specified feature433 469 * @return error code 434 470 */ 435 471 static int process_hub_feature_set_request(rh_t *instance, 436 uint16_t feature , bool enable){437 if( feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)472 uint16_t feature){ 473 if(! ((1<<feature) & hub_set_feature_valid_mask)) 438 474 return EINVAL; 439 475 instance->registers->rh_status = 440 enable ?441 476 (instance->registers->rh_status | (1<<feature)) 442 : 443 (instance->registers->rh_status & (~(1<<feature))); 444 /// \TODO any error? 445 return EOK; 446 } 447 448 /** 449 * process feature-enabling/disabling request on hub 477 & (~ hub_clear_feature_by_writing_one_mask); 478 return EOK; 479 } 480 481 /** 482 * process feature-disabling request on hub 483 * 484 * @param instance root hub instance 485 * @param feature feature selector 486 * @return error code 487 */ 488 static int process_hub_feature_clear_request(rh_t *instance, 489 uint16_t feature){ 490 if(! ((1<<feature) & hub_clear_feature_valid_mask)) 491 return EINVAL; 492 //is the feature cleared directly? 493 if ((1<<feature) & hub_set_feature_direct_mask){ 494 instance->registers->rh_status = 495 (instance->registers->rh_status & (~(1<<feature))) 496 & (~ hub_clear_feature_by_writing_one_mask); 497 }else{//the feature is cleared by writing '1' 498 instance->registers->rh_status = 499 (instance->registers->rh_status 500 & (~ hub_clear_feature_by_writing_one_mask)) 501 | (1<<feature); 502 } 503 return EOK; 504 } 505 506 507 508 /** 509 * process feature-enabling request on hub 450 510 * 451 511 * @param instance root hub instance … … 456 516 */ 457 517 static int process_port_feature_set_request(rh_t *instance, 458 uint16_t feature, uint16_t port , bool enable){459 if( feature > USB_HUB_FEATURE_C_PORT_RESET)518 uint16_t feature, uint16_t port){ 519 if(!((1<<feature) & port_set_feature_valid_mask)) 460 520 return EINVAL; 461 521 if(port<1 || port>instance->port_count) 462 522 return EINVAL; 463 523 instance->registers->rh_port_status[port - 1] = 464 enable ?465 524 (instance->registers->rh_port_status[port - 1] | (1<<feature)) 466 : 467 (instance->registers->rh_port_status[port - 1] & (~(1<<feature))); 525 & (~port_clear_feature_valid_mask); 468 526 /// \TODO any error? 469 527 return EOK; 470 528 } 529 530 /** 531 * process feature-disabling request on hub 532 * 533 * @param instance root hub instance 534 * @param feature feature selector 535 * @param port port number, counted from 1 536 * @param enable enable or disable the specified feature 537 * @return error code 538 */ 539 static int process_port_feature_clear_request(rh_t *instance, 540 uint16_t feature, uint16_t port){ 541 if(!((1<<feature) & port_clear_feature_valid_mask)) 542 return EINVAL; 543 if(port<1 || port>instance->port_count) 544 return EINVAL; 545 if(feature == USB_HUB_FEATURE_PORT_POWER) 546 feature = USB_HUB_FEATURE_PORT_LOW_SPEED; 547 if(feature == USB_HUB_FEATURE_PORT_SUSPEND) 548 feature = USB_HUB_FEATURE_PORT_OVER_CURRENT; 549 instance->registers->rh_port_status[port - 1] = 550 (instance->registers->rh_port_status[port - 1] 551 & (~port_clear_feature_valid_mask)) 552 | (1<<feature); 553 /// \TODO any error? 554 return EOK; 555 } 556 471 557 472 558 /** … … 550 636 (usb_device_request_setup_packet_t*)request->setup_buffer; 551 637 request->transfered_size = 0; 552 if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE 553 || setup_request->request == USB_DEVREQ_SET_FEATURE){ 638 if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){ 554 639 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){ 555 640 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 556 return process_hub_feature_ set_request(instance, setup_request->value,557 setup_request-> request == USB_DEVREQ_SET_FEATURE);641 return process_hub_feature_clear_request(instance, 642 setup_request->value); 558 643 } 559 644 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){ 560 645 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 561 return process_port_feature_set_request(instance, setup_request->value, 562 setup_request->index, 563 setup_request->request == USB_DEVREQ_SET_FEATURE); 646 return process_port_feature_clear_request(instance, 647 setup_request->value, 648 setup_request->index); 649 } 650 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n", 651 setup_request->request_type); 652 return EINVAL; 653 } 654 if(setup_request->request == USB_DEVREQ_SET_FEATURE){ 655 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){ 656 usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n"); 657 return process_hub_feature_set_request(instance, 658 setup_request->value); 659 } 660 if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){ 661 usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n"); 662 return process_port_feature_set_request(instance, 663 setup_request->value, 664 setup_request->index); 564 665 } 565 666 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type); -
uspace/drv/usbhub/port_status.h
rd527a4e r4d946647 95 95 } 96 96 97 /** 98 * set the device request to be a port feature clear request 99 * @param request 100 * @param port 101 * @param feature_selector 102 */ 103 static inline void usb_hub_set_disable_port_feature_request( 104 usb_device_request_setup_packet_t * request, uint16_t port, 105 uint16_t feature_selector 106 ){ 107 request->index = port; 108 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE; 109 request->request = USB_HUB_REQUEST_CLEAR_FEATURE; 110 request->value = feature_selector; 111 request->length = 0; 112 } 97 113 98 114 /** -
uspace/drv/usbhub/usbhub.c
rd527a4e r4d946647 317 317 //set the status change bit, so it will be noticed in driver loop 318 318 if(usb_port_dev_connected(&status)){ 319 usb_hub_set_ enable_port_feature_request(&request, port,320 USB_HUB_FEATURE_ C_PORT_CONNECTION);319 usb_hub_set_disable_port_feature_request(&request, port, 320 USB_HUB_FEATURE_PORT_CONNECTION); 321 321 opResult = usb_pipe_control_read( 322 322 hub->control_pipe, … … 326 326 if (opResult != EOK) { 327 327 usb_log_warning( 328 "could not set port changeon port %d errno:%d\n",328 "could not clear port connection on port %d errno:%d\n", 329 329 port, opResult); 330 330 } 331 usb_log_debug("cleared port connection\n"); 332 usb_hub_set_enable_port_feature_request(&request, port, 333 USB_HUB_FEATURE_PORT_ENABLE); 334 opResult = usb_pipe_control_read( 335 hub->control_pipe, 336 &request, sizeof(usb_device_request_setup_packet_t), 337 &status, 4, &rcvd_size 338 ); 339 if (opResult != EOK) { 340 usb_log_warning( 341 "could not set port enabled on port %d errno:%d\n", 342 port, opResult); 343 } 344 usb_log_debug("port set to enabled - should lead to connection change\n"); 331 345 } 346 } 347 } 348 /// \TODO this is just a debug code 349 for(port=1;port<=descriptor->ports_count;++port){ 350 bool is_non_removable = 351 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2; 352 if(is_non_removable){ 353 usb_log_debug("port %d is non-removable\n",port); 354 usb_port_status_t status; 355 size_t rcvd_size; 356 usb_device_request_setup_packet_t request; 357 //int opResult; 358 usb_hub_set_port_status_request(&request, port); 359 //endpoint 0 360 opResult = usb_pipe_control_read( 361 hub->control_pipe, 362 &request, sizeof(usb_device_request_setup_packet_t), 363 &status, 4, &rcvd_size 364 ); 365 if (opResult != EOK) { 366 usb_log_error("could not get port status %d\n",opResult); 367 } 368 if (rcvd_size != sizeof (usb_port_status_t)) { 369 usb_log_error("received status has incorrect size\n"); 370 } 371 //something connected/disconnected 372 if (usb_port_connect_change(&status)) { 373 usb_log_debug("some connection changed\n"); 374 } 375 usb_log_debug("status: %s\n",usb_debug_str_buffer( 376 (uint8_t *)&status,4,4)); 332 377 } 333 378 } … … 582 627 //something connected/disconnected 583 628 if (usb_port_connect_change(&status)) { 629 usb_log_debug("connection change on port\n"); 584 630 if (usb_port_dev_connected(&status)) { 585 631 usb_log_debug("some connection changed\n"); … … 592 638 if (usb_port_overcurrent_change(&status)) { 593 639 //check if it was not auto-resolved 640 usb_log_debug("overcurrent change on port\n"); 594 641 if(usb_port_over_current(&status)){ 595 642 usb_hub_over_current(hub,port); … … 608 655 } 609 656 } 657 usb_log_debug("status %x\n ",status); 610 658 611 659 usb_port_set_connect_change(&status, false);
Note:
See TracChangeset
for help on using the changeset viewer.