Changeset b330b309 in mainline
- Timestamp:
- 2011-03-26T20:22:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 51e5608
- Parents:
- cee51fd (diff), df3ad97 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
rcee51fd rb330b309 43 43 #include <usb/classes/hub.h> 44 44 45 /** 46 * standart device descriptor for ohci root hub 47 */ 45 48 static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = 46 49 { … … 61 64 }; 62 65 66 /** 67 * standart configuration descriptor with filled common values 68 * for ohci root hubs 69 */ 63 70 static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = 64 71 { … … 73 80 }; 74 81 82 /** 83 * standart ohci root hub interface descriptor 84 */ 75 85 static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = 76 86 { … … 87 97 }; 88 98 99 /** 100 * standart ohci root hub endpoint descriptor 101 */ 89 102 static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = 90 103 { … … 273 286 274 287 /** 275 * create standard device descriptor for a hub276 * @return newly allocated descriptor277 */278 static usb_standard_device_descriptor_t *279 usb_ohci_rh_create_standard_device_descriptor(){280 usb_standard_device_descriptor_t * descriptor =281 (usb_standard_device_descriptor_t*)282 malloc(sizeof(usb_standard_device_descriptor_t));283 descriptor->configuration_count = 1;284 descriptor->descriptor_type = USB_DESCTYPE_DEVICE;285 descriptor->device_class = USB_CLASS_HUB;286 descriptor->device_protocol = 0;287 descriptor->device_subclass = 0;288 descriptor->device_version = 0;289 descriptor->length = sizeof(usb_standard_device_descriptor_t);290 /// \TODO this value is guessed291 descriptor->max_packet_size = 8;292 descriptor->product_id = 0x0001;293 /// \TODO these values migt be different294 descriptor->str_serial_number = 0;295 descriptor->str_serial_number = 0;296 descriptor->usb_spec_version = 0;297 descriptor->vendor_id = 0x16db;298 return descriptor;299 }300 301 /**302 288 * create standart configuration descriptor for the root hub instance 303 289 * @param instance root hub instance … … 307 293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){ 308 294 usb_standard_configuration_descriptor_t * descriptor = 309 (usb_standard_configuration_descriptor_t*)310 295 malloc(sizeof(usb_standard_configuration_descriptor_t)); 311 /// \TODO some values are default or guessed 312 descriptor->attributes = 1<<7; 313 descriptor->configuration_number = 1; 314 descriptor->descriptor_type = USB_DESCTYPE_CONFIGURATION; 315 descriptor->interface_count = 1; 316 descriptor->length = sizeof(usb_standard_configuration_descriptor_t); 317 descriptor->max_power = 100; 318 descriptor->str_configuration = 0; 296 memcpy(descriptor, &ohci_rh_conf_descriptor, 297 sizeof(usb_standard_configuration_descriptor_t)); 319 298 /// \TODO should this include device descriptor? 320 size_t hub_descriptor_size = 7 +299 const size_t hub_descriptor_size = 7 + 321 300 2* (instance->port_count / 8 + 322 301 ((instance->port_count % 8 > 0) ? 1 : 0)); … … 330 309 331 310 /** 332 * create standard interface descriptor for a root hub333 * @return newly allocated descriptor334 */335 static usb_standard_interface_descriptor_t *336 usb_ohci_rh_create_standard_interface_descriptor(){337 usb_standard_interface_descriptor_t * descriptor =338 (usb_standard_interface_descriptor_t*)339 malloc(sizeof(usb_standard_interface_descriptor_t));340 descriptor->alternate_setting = 0;341 descriptor->descriptor_type = USB_DESCTYPE_INTERFACE;342 descriptor->endpoint_count = 1;343 descriptor->interface_class = USB_CLASS_HUB;344 /// \TODO is this correct?345 descriptor->interface_number = 1;346 descriptor->interface_protocol = 0;347 descriptor->interface_subclass = 0;348 descriptor->length = sizeof(usb_standard_interface_descriptor_t);349 descriptor->str_interface = 0;350 return descriptor;351 }352 353 /**354 * create standard endpoint descriptor for a root hub355 * @return newly allocated descriptor356 */357 static usb_standard_endpoint_descriptor_t *358 usb_ohci_rh_create_standard_endpoint_descriptor(){359 usb_standard_endpoint_descriptor_t * descriptor =360 (usb_standard_endpoint_descriptor_t*)361 malloc(sizeof(usb_standard_endpoint_descriptor_t));362 descriptor->attributes = USB_TRANSFER_INTERRUPT;363 descriptor->descriptor_type = USB_DESCTYPE_ENDPOINT;364 descriptor->endpoint_address = 1 + (1<<7);365 descriptor->length = sizeof(usb_standard_endpoint_descriptor_t);366 descriptor->max_packet_size = 8;367 descriptor->poll_interval = 255;368 return descriptor;369 }370 371 /**372 311 * create answer to a descriptor request 373 312 * … … 386 325 const uint16_t setup_request_value = setup_request->value_high; 387 326 //(setup_request->value_low << 8); 388 #if 0389 327 bool del = false; 390 //this code was merged from development and has to be reviewed391 328 switch (setup_request_value) 392 329 { 393 case USB_DESCTYPE_HUB: { 394 uint8_t * descriptor; 395 usb_create_serialized_hub_descriptor( 396 instance, &descriptor, &size); 397 result_descriptor = descriptor; 398 break; 399 } 400 case USB_DESCTYPE_DEVICE: { 401 usb_log_debug("USB_DESCTYPE_DEVICE\n"); 402 result_descriptor = &ohci_rh_device_descriptor; 403 size = sizeof(ohci_rh_device_descriptor); 404 break; 405 } 406 case USB_DESCTYPE_CONFIGURATION: { 407 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 408 usb_standard_configuration_descriptor_t * descriptor = 409 malloc(sizeof(usb_standard_configuration_descriptor_t)); 410 memcpy(descriptor, &ohci_rh_conf_descriptor, 411 sizeof(usb_standard_configuration_descriptor_t)); 412 /// \TODO should this include device descriptor? 413 const size_t hub_descriptor_size = 7 + 414 2* (instance->port_count / 8 + 415 ((instance->port_count % 8 > 0) ? 1 : 0)); 416 descriptor->total_length = 417 sizeof(usb_standard_configuration_descriptor_t)+ 418 sizeof(usb_standard_endpoint_descriptor_t)+ 419 sizeof(usb_standard_interface_descriptor_t)+ 420 hub_descriptor_size; 421 result_descriptor = descriptor; 422 size = sizeof(usb_standard_configuration_descriptor_t); 423 del = true; 424 break; 425 } 426 case USB_DESCTYPE_INTERFACE: { 427 usb_log_debug("USB_DESCTYPE_INTERFACE\n"); 428 result_descriptor = &ohci_rh_iface_descriptor; 429 size = sizeof(ohci_rh_iface_descriptor); 430 break; 431 } 432 case USB_DESCTYPE_ENDPOINT: { 433 usb_log_debug("USB_DESCTYPE_ENDPOINT\n"); 434 result_descriptor = &ohci_rh_ep_descriptor; 435 size = sizeof(ohci_rh_ep_descriptor); 436 break; 437 } 438 default: { 439 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value); 440 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ", 441 setup_request->request_type, 442 setup_request->request, 443 setup_request_value, 444 setup_request->index, 445 setup_request->length 446 ); 447 return EINVAL; 448 } 449 } 450 #endif 451 if(setup_request_value == USB_DESCTYPE_HUB){ 452 usb_log_debug("USB_DESCTYPE_HUB\n"); 453 //create hub descriptor 454 uint8_t * descriptor; 455 usb_create_serialized_hub_descriptor(instance, 456 &descriptor, &size); 457 result_descriptor = descriptor; 458 }else if(setup_request_value == USB_DESCTYPE_DEVICE){ 459 //create std device descriptor 460 usb_log_debug("USB_DESCTYPE_DEVICE\n"); 461 result_descriptor = 462 usb_ohci_rh_create_standard_device_descriptor(); 463 size = sizeof(usb_standard_device_descriptor_t); 464 }else if(setup_request_value == USB_DESCTYPE_CONFIGURATION){ 465 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 466 result_descriptor = 467 usb_ohci_rh_create_standart_configuration_descriptor(instance); 468 size = sizeof(usb_standard_configuration_descriptor_t); 469 470 }else if(setup_request_value == USB_DESCTYPE_INTERFACE){ 471 usb_log_debug("USB_DESCTYPE_INTERFACE\n"); 472 result_descriptor = 473 usb_ohci_rh_create_standard_interface_descriptor(); 474 size = sizeof(usb_standard_interface_descriptor_t); 475 }else if(setup_request_value == USB_DESCTYPE_ENDPOINT){ 476 usb_log_debug("USB_DESCTYPE_ENDPOINT\n"); 477 result_descriptor = 478 usb_ohci_rh_create_standard_endpoint_descriptor(); 479 size = sizeof(usb_standard_endpoint_descriptor_t); 480 }else{ 481 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value); 482 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ", 483 setup_request->request_type, 484 setup_request->request, 485 setup_request_value, 486 setup_request->index, 487 setup_request->length 488 ); 489 return EINVAL; 330 case USB_DESCTYPE_HUB: { 331 uint8_t * descriptor; 332 usb_create_serialized_hub_descriptor( 333 instance, &descriptor, &size); 334 result_descriptor = descriptor; 335 if(result_descriptor) del = true; 336 break; 337 } 338 case USB_DESCTYPE_DEVICE: { 339 usb_log_debug("USB_DESCTYPE_DEVICE\n"); 340 result_descriptor = &ohci_rh_device_descriptor; 341 size = sizeof(ohci_rh_device_descriptor); 342 break; 343 } 344 case USB_DESCTYPE_CONFIGURATION: { 345 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n"); 346 usb_standard_configuration_descriptor_t * descriptor = 347 usb_ohci_rh_create_standart_configuration_descriptor( 348 instance); 349 result_descriptor = descriptor; 350 size = sizeof(usb_standard_configuration_descriptor_t); 351 del = true; 352 break; 353 } 354 case USB_DESCTYPE_INTERFACE: { 355 usb_log_debug("USB_DESCTYPE_INTERFACE\n"); 356 result_descriptor = &ohci_rh_iface_descriptor; 357 size = sizeof(ohci_rh_iface_descriptor); 358 break; 359 } 360 case USB_DESCTYPE_ENDPOINT: { 361 usb_log_debug("USB_DESCTYPE_ENDPOINT\n"); 362 result_descriptor = &ohci_rh_ep_descriptor; 363 size = sizeof(ohci_rh_ep_descriptor); 364 break; 365 } 366 default: { 367 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value); 368 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ", 369 setup_request->request_type, 370 setup_request->request, 371 setup_request_value, 372 setup_request->index, 373 setup_request->length 374 ); 375 return EINVAL; 376 } 490 377 } 491 378 if(request->buffer_size < size){ … … 494 381 request->transfered_size = size; 495 382 memcpy(request->buffer,result_descriptor,size); 496 if ( result_descriptor)383 if (del) 497 384 free(result_descriptor); 498 385 return EOK; … … 761 648 void rh_interrupt(rh_t *instance) 762 649 { 763 usb_log_info("Whoa whoa wait, I`m not supposed to receive interrupts, am I?\n");650 usb_log_info("Whoa whoa wait, I`m not supposed to receive any interrupts, am I?\n"); 764 651 /* TODO: implement? */ 765 652 } -
uspace/drv/ohci/root_hub.h
rcee51fd rb330b309 41 41 #include "batch.h" 42 42 43 /** 44 * ohci root hub representation 45 */ 43 46 typedef struct rh { 47 /** pointer to ohci driver registers */ 44 48 ohci_regs_t *registers; 49 /** usb address of the root hub */ 45 50 usb_address_t address; 51 /** ddf device information */ 46 52 ddf_dev_t *device; 53 /** hub port count */ 47 54 int port_count; 48 55 } rh_t; -
uspace/drv/usbhub/port_status.h
rcee51fd rb330b309 79 79 80 80 /** 81 * set the device request to be a port feature enable request 82 * @param request 83 * @param port 84 * @param feature_selector 85 */ 86 static inline void usb_hub_set_enable_port_feature_request( 87 usb_device_request_setup_packet_t * request, uint16_t port, 88 uint16_t feature_selector 89 ){ 90 request->index = port; 91 request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE; 92 request->request = USB_HUB_REQUEST_SET_FEATURE; 93 request->value = feature_selector; 94 request->length = 0; 95 } 96 97 98 /** 81 99 * set the device request to be a port enable request 82 100 * @param request … … 191 209 request->length = 0; 192 210 } 211 193 212 194 213 /** get i`th bit of port status */ -
uspace/drv/usbhub/usbhub.c
rcee51fd rb330b309 53 53 #include "usb/classes/classes.h" 54 54 55 55 56 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 56 57 usb_speed_t speed); 57 58 58 static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub, 59 usb_hub_descriptor_t * descriptor); 60 59 static int usb_hub_trigger_connecting_non_removable_devices( 60 usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor); 61 62 /** 63 * control loop running in hub`s fibril 64 * 65 * Hub`s fibril periodically asks for changes on hub and if needded calls 66 * change handling routine. 67 * @warning currently hub driver asks for changes once a second 68 * @param hub_info_param hub representation pointer 69 * @return zero 70 */ 61 71 int usb_hub_control_loop(void * hub_info_param){ 62 72 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param; … … 103 113 * This function is hub-specific and should be run only after the hub is 104 114 * configured using usb_hub_set_configuration function. 105 * @param hub_info pointer to structure with usb hub data115 * @param hub_info hub representation 106 116 * @return error code 107 117 */ … … 149 159 hub_info->attached_devs[i].address=0; 150 160 } 151 usb_hub_attach_non_removable_devices(hub_info, descriptor); 161 //handle non-removable devices 162 usb_hub_trigger_connecting_non_removable_devices(hub_info, descriptor); 152 163 usb_log_debug2("freeing data\n"); 153 164 free(serialized_descriptor); … … 161 172 * Check whether there is at least one configuration and sets the first one. 162 173 * This function should be run prior to running any hub-specific action. 163 * @param hub_info 164 * @return 174 * @param hub_info hub representation 175 * @return error code 165 176 */ 166 177 static int usb_hub_set_configuration(usb_hub_info_t * hub_info){ … … 270 281 271 282 /** 272 * Perform \a usb_hub_init_add_device on all ports with non-removable device283 * triggers actions to connect non0removable devices 273 284 * 274 285 * This will trigger operations leading to activated non-removable device. 275 286 * Control pipe of the hub must be open fo communication. 276 * @param hub hub instance287 * @param hub hub representation 277 288 * @param descriptor usb hub descriptor 278 289 * @return error code 279 290 */ 280 static int usb_hub_ attach_non_removable_devices(usb_hub_info_t * hub,291 static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub, 281 292 usb_hub_descriptor_t * descriptor) 282 293 { … … 287 298 usb_port_status_t status; 288 299 uint8_t * non_removable_dev_bitmap = descriptor->devices_removable; 289 //initialize all connected, non-removable devices290 300 int port; 291 301 for(port=1;port<=descriptor->ports_count;++port){ … … 305 315 return opResult; 306 316 } 307 // this should be true..317 //set the status change bit, so it will be noticed in driver loop 308 318 if(usb_port_dev_connected(&status)){ 309 usb_hub_init_add_device(hub,port,usb_port_speed(&status)); 319 usb_hub_set_enable_port_feature_request(&request, port, 320 USB_HUB_FEATURE_C_PORT_CONNECTION); 321 opResult = usb_pipe_control_read( 322 hub->control_pipe, 323 &request, sizeof(usb_device_request_setup_packet_t), 324 &status, 4, &rcvd_size 325 ); 326 if (opResult != EOK) { 327 usb_log_warning( 328 "could not set port change on port %d errno:%d\n", 329 port, opResult); 330 } 310 331 } 311 332 } … … 335 356 /** 336 357 * Reset the port with new device and reserve the default address. 337 * @param h c338 * @param port 339 * @param target358 * @param hub hub representation 359 * @param port port number, starting from 1 360 * @param speed transfer speed of attached device, one of low, full or high 340 361 */ 341 362 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, … … 370 391 if (opResult != EOK) { 371 392 usb_log_error("something went wrong when reseting a port %d\n",opResult); 372 //usb_hub_release_default_address(hc);373 393 usb_hub_release_default_address(hub); 374 394 } … … 378 398 /** 379 399 * Finalize adding new device after port reset 380 * @param hc 381 * @param port 382 * @param target 400 * 401 * Set device`s address and start it`s driver. 402 * @param hub hub representation 403 * @param port port number, starting from 1 404 * @param speed transfer speed of attached device, one of low, full or high 383 405 */ 384 406 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, … … 430 452 } 431 453 432 433 454 //opResult = usb_hub_release_default_address(hc); 434 455 opResult = usb_hub_release_default_address(hub); … … 465 486 466 487 /** 467 * Unregister device address in hc 468 * @param hc 469 * @param port 470 * @param target 488 * routine called when a device on port has been removed 489 * 490 * If the device on port had default address, it releases default address. 491 * Otherwise does not do anything, because DDF does not allow to remove device 492 * from it`s device tree. 493 * @param hub hub representation 494 * @param port port number, starting from 1 471 495 */ 472 496 static void usb_hub_removed_device( … … 507 531 * Turn off the power on the port. 508 532 * 509 * @param hub 510 * @param port 533 * @param hub hub representation 534 * @param port port number, starting from 1 511 535 */ 512 536 static void usb_hub_over_current( usb_hub_info_t * hub, … … 523 547 /** 524 548 * Process interrupts on given hub port 525 * @param hc 526 * @param port 527 * @param target 549 * 550 * Accepts connection, over current and port reset change. 551 * @param hub hub representation 552 * @param port port number, starting from 1 528 553 */ 529 554 static void usb_hub_process_interrupt(usb_hub_info_t * hub, … … 596 621 597 622 /** 598 * Check changes on particular hub 599 * @param hub_info_param pointer to usb_hub_info_t structure 600 * @return error code if there is problem when initializing communication with 601 * hub, EOK otherwise 623 * check changes on hub 624 * 625 * Handles changes on each port with a status change. 626 * @param hub_info hub representation 627 * @return error code 602 628 */ 603 629 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
Note:
See TracChangeset
for help on using the changeset viewer.