Changes in / [b330b309:cee51fd] in mainline
- Location:
- uspace/drv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
rb330b309 rcee51fd 43 43 #include <usb/classes/hub.h> 44 44 45 /**46 * standart device descriptor for ohci root hub47 */48 45 static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = 49 46 { … … 64 61 }; 65 62 66 /**67 * standart configuration descriptor with filled common values68 * for ohci root hubs69 */70 63 static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = 71 64 { … … 80 73 }; 81 74 82 /**83 * standart ohci root hub interface descriptor84 */85 75 static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = 86 76 { … … 97 87 }; 98 88 99 /**100 * standart ohci root hub endpoint descriptor101 */102 89 static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = 103 90 { … … 286 273 287 274 /** 275 * create standard device descriptor for a hub 276 * @return newly allocated descriptor 277 */ 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 guessed 291 descriptor->max_packet_size = 8; 292 descriptor->product_id = 0x0001; 293 /// \TODO these values migt be different 294 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 /** 288 302 * create standart configuration descriptor for the root hub instance 289 303 * @param instance root hub instance … … 293 307 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){ 294 308 usb_standard_configuration_descriptor_t * descriptor = 309 (usb_standard_configuration_descriptor_t*) 295 310 malloc(sizeof(usb_standard_configuration_descriptor_t)); 296 memcpy(descriptor, &ohci_rh_conf_descriptor, 297 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; 298 319 /// \TODO should this include device descriptor? 299 constsize_t hub_descriptor_size = 7 +320 size_t hub_descriptor_size = 7 + 300 321 2* (instance->port_count / 8 + 301 322 ((instance->port_count % 8 > 0) ? 1 : 0)); … … 309 330 310 331 /** 332 * create standard interface descriptor for a root hub 333 * @return newly allocated descriptor 334 */ 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 hub 355 * @return newly allocated descriptor 356 */ 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 /** 311 372 * create answer to a descriptor request 312 373 * … … 325 386 const uint16_t setup_request_value = setup_request->value_high; 326 387 //(setup_request->value_low << 8); 388 #if 0 327 389 bool del = false; 390 //this code was merged from development and has to be reviewed 328 391 switch (setup_request_value) 329 392 { 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 } 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; 377 490 } 378 491 if(request->buffer_size < size){ … … 381 494 request->transfered_size = size; 382 495 memcpy(request->buffer,result_descriptor,size); 383 if ( del)496 if (result_descriptor) 384 497 free(result_descriptor); 385 498 return EOK; … … 648 761 void rh_interrupt(rh_t *instance) 649 762 { 650 usb_log_info("Whoa whoa wait, I`m not supposed to receive anyinterrupts, am I?\n");763 usb_log_info("Whoa whoa wait, I`m not supposed to receive interrupts, am I?\n"); 651 764 /* TODO: implement? */ 652 765 } -
uspace/drv/ohci/root_hub.h
rb330b309 rcee51fd 41 41 #include "batch.h" 42 42 43 /**44 * ohci root hub representation45 */46 43 typedef struct rh { 47 /** pointer to ohci driver registers */48 44 ohci_regs_t *registers; 49 /** usb address of the root hub */50 45 usb_address_t address; 51 /** ddf device information */52 46 ddf_dev_t *device; 53 /** hub port count */54 47 int port_count; 55 48 } rh_t; -
uspace/drv/usbhub/port_status.h
rb330b309 rcee51fd 79 79 80 80 /** 81 * set the device request to be a port feature enable request82 * @param request83 * @param port84 * @param feature_selector85 */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_selector89 ){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 /**99 81 * set the device request to be a port enable request 100 82 * @param request … … 209 191 request->length = 0; 210 192 } 211 212 193 213 194 /** get i`th bit of port status */ -
uspace/drv/usbhub/usbhub.c
rb330b309 rcee51fd 53 53 #include "usb/classes/classes.h" 54 54 55 56 55 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 57 56 usb_speed_t speed); 58 57 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 */ 58 static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub, 59 usb_hub_descriptor_t * descriptor); 60 71 61 int usb_hub_control_loop(void * hub_info_param){ 72 62 usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param; … … 113 103 * This function is hub-specific and should be run only after the hub is 114 104 * configured using usb_hub_set_configuration function. 115 * @param hub_info hub representation105 * @param hub_info pointer to structure with usb hub data 116 106 * @return error code 117 107 */ … … 159 149 hub_info->attached_devs[i].address=0; 160 150 } 161 //handle non-removable devices 162 usb_hub_trigger_connecting_non_removable_devices(hub_info, descriptor); 151 usb_hub_attach_non_removable_devices(hub_info, descriptor); 163 152 usb_log_debug2("freeing data\n"); 164 153 free(serialized_descriptor); … … 172 161 * Check whether there is at least one configuration and sets the first one. 173 162 * This function should be run prior to running any hub-specific action. 174 * @param hub_info hub representation175 * @return error code163 * @param hub_info 164 * @return 176 165 */ 177 166 static int usb_hub_set_configuration(usb_hub_info_t * hub_info){ … … 281 270 282 271 /** 283 * triggers actions to connect non0removable devices272 * Perform \a usb_hub_init_add_device on all ports with non-removable device 284 273 * 285 274 * This will trigger operations leading to activated non-removable device. 286 275 * Control pipe of the hub must be open fo communication. 287 * @param hub hub representation276 * @param hub hub instance 288 277 * @param descriptor usb hub descriptor 289 278 * @return error code 290 279 */ 291 static int usb_hub_ trigger_connecting_non_removable_devices(usb_hub_info_t * hub,280 static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub, 292 281 usb_hub_descriptor_t * descriptor) 293 282 { … … 298 287 usb_port_status_t status; 299 288 uint8_t * non_removable_dev_bitmap = descriptor->devices_removable; 289 //initialize all connected, non-removable devices 300 290 int port; 301 291 for(port=1;port<=descriptor->ports_count;++port){ … … 315 305 return opResult; 316 306 } 317 // set the status change bit, so it will be noticed in driver loop307 //this should be true.. 318 308 if(usb_port_dev_connected(&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 } 309 usb_hub_init_add_device(hub,port,usb_port_speed(&status)); 331 310 } 332 311 } … … 356 335 /** 357 336 * Reset the port with new device and reserve the default address. 358 * @param h ub hub representation359 * @param port port number, starting from 1360 * @param speed transfer speed of attached device, one of low, full or high337 * @param hc 338 * @param port 339 * @param target 361 340 */ 362 341 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, … … 391 370 if (opResult != EOK) { 392 371 usb_log_error("something went wrong when reseting a port %d\n",opResult); 372 //usb_hub_release_default_address(hc); 393 373 usb_hub_release_default_address(hub); 394 374 } … … 398 378 /** 399 379 * Finalize adding new device after port reset 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 380 * @param hc 381 * @param port 382 * @param target 405 383 */ 406 384 static void usb_hub_finalize_add_device( usb_hub_info_t * hub, … … 452 430 } 453 431 432 454 433 //opResult = usb_hub_release_default_address(hc); 455 434 opResult = usb_hub_release_default_address(hub); … … 486 465 487 466 /** 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 467 * Unregister device address in hc 468 * @param hc 469 * @param port 470 * @param target 495 471 */ 496 472 static void usb_hub_removed_device( … … 531 507 * Turn off the power on the port. 532 508 * 533 * @param hub hub representation534 * @param port port number, starting from 1509 * @param hub 510 * @param port 535 511 */ 536 512 static void usb_hub_over_current( usb_hub_info_t * hub, … … 547 523 /** 548 524 * Process interrupts on given hub port 549 * 550 * Accepts connection, over current and port reset change. 551 * @param hub hub representation 552 * @param port port number, starting from 1 525 * @param hc 526 * @param port 527 * @param target 553 528 */ 554 529 static void usb_hub_process_interrupt(usb_hub_info_t * hub, … … 621 596 622 597 /** 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 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 628 602 */ 629 603 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
Note:
See TracChangeset
for help on using the changeset viewer.