Changeset 7363fc1 in mainline
- Timestamp:
- 2013-01-27T11:52:37Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7d20461
- Parents:
- 87619045
- Location:
- uspace/lib/usbdev
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/include/usb/dev/device.h
r87619045 r7363fc1 46 46 void usb_device_destroy_ddf(ddf_dev_t *); 47 47 48 const char* usb_device_get_name(usb_device_t *); 48 usb_device_t * usb_device_create(devman_handle_t); 49 void usb_device_destroy(usb_device_t *); 50 51 const char * usb_device_get_name(usb_device_t *); 49 52 ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *, fun_type_t, const char *); 50 53 -
uspace/lib/usbdev/src/devdrv.c
r87619045 r7363fc1 389 389 } 390 390 391 /** Clean instance of a USB device. 392 * 393 * @param dev Device to be de-initialized. 394 * 395 * Does not free/destroy supplied pointer. 396 */ 397 static void usb_device_fini(usb_device_t *usb_dev) 398 { 399 if (usb_dev) { 400 usb_dev_disconnect(usb_dev->bus_session); 401 /* Destroy existing pipes. */ 402 usb_device_destroy_pipes(usb_dev); 403 /* Ignore errors and hope for the best. */ 404 usb_hc_connection_deinitialize(&usb_dev->hc_conn); 405 usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces); 406 usb_device_release_descriptors(usb_dev); 407 free(usb_dev->driver_data); 408 usb_dev->driver_data = NULL; 409 } 410 } 411 391 412 /** Initialize new instance of USB device. 392 413 * … … 399 420 */ 400 421 static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev, 401 const usb_endpoint_description_t **endpoints, const char **errstr_ptr) 422 const usb_endpoint_description_t **endpoints, const char **errstr_ptr, 423 devman_handle_t handle) 402 424 { 403 425 assert(usb_dev != NULL); 404 426 assert(ddf_dev != NULL); 427 assert(errstr_ptr); 405 428 406 429 *errstr_ptr = NULL; … … 412 435 usb_dev->pipes = NULL; 413 436 414 usb_dev->bus_session = usb_dev_connect_to_self(ddf_dev); 437 if (ddf_dev) 438 usb_dev->bus_session = usb_dev_connect_to_self(ddf_dev); 439 else 440 usb_dev->bus_session = usb_dev_connect(handle); 441 415 442 if (!usb_dev->bus_session) { 416 443 *errstr_ptr = "device bus session create"; … … 425 452 &hc_handle, &address, &usb_dev->interface_no); 426 453 if (rc != EOK) { 454 usb_dev_disconnect(usb_dev->bus_session); 427 455 *errstr_ptr = "device parameters retrieval"; 428 456 return rc; … … 436 464 &usb_dev->wire, &usb_dev->hc_conn, address); 437 465 if (rc != EOK) { 466 usb_dev_disconnect(usb_dev->bus_session); 438 467 *errstr_ptr = "device connection initialization"; 439 468 return rc; … … 445 474 &usb_dev->ctrl_pipe, &usb_dev->wire); 446 475 if (rc != EOK) { 476 usb_dev_disconnect(usb_dev->bus_session); 447 477 *errstr_ptr = "default control pipe initialization"; 448 478 return rc; … … 452 482 rc = usb_hc_connection_open(&usb_dev->hc_conn); 453 483 if (rc != EOK) { 484 usb_dev_disconnect(usb_dev->bus_session); 454 485 *errstr_ptr = "hc connection open"; 455 486 return rc; … … 461 492 *errstr_ptr = "descriptor retrieval"; 462 493 usb_hc_connection_close(&usb_dev->hc_conn); 494 usb_dev_disconnect(usb_dev->bus_session); 463 495 return rc; 464 496 } … … 472 504 usb_dev->descriptors.configuration_size, usb_dev->interface_no); 473 505 474 /* Create and register other pipes than default control (EP 0) */ 475 rc = usb_device_create_pipes(usb_dev, endpoints); 476 if (rc != EOK) { 477 usb_hc_connection_close(&usb_dev->hc_conn); 478 /* Full configuration descriptor is allocated. */ 479 usb_device_release_descriptors(usb_dev); 480 /* Alternate interfaces may be allocated */ 481 usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces); 482 *errstr_ptr = "pipes initialization"; 483 return rc; 506 if (endpoints) { 507 /* Create and register other pipes than default control (EP 0)*/ 508 rc = usb_device_create_pipes(usb_dev, endpoints); 509 if (rc != EOK) { 510 usb_hc_connection_close(&usb_dev->hc_conn); 511 usb_device_fini(usb_dev); 512 *errstr_ptr = "pipes initialization"; 513 return rc; 514 } 484 515 } 485 516 … … 488 519 } 489 520 490 /** Clean instance of a USB device.491 *492 * @param dev Device to be de-initialized.493 *494 * Does not free/destroy supplied pointer.495 */496 static void usb_device_fini(usb_device_t *dev)497 {498 if (dev) {499 usb_dev_disconnect(dev->bus_session);500 /* Destroy existing pipes. */501 usb_device_destroy_pipes(dev);502 /* Ignore errors and hope for the best. */503 usb_hc_connection_deinitialize(&dev->hc_conn);504 usb_alternate_interfaces_deinit(&dev->alternate_interfaces);505 usb_device_release_descriptors(dev);506 free(dev->driver_data);507 dev->driver_data = NULL;508 }509 }510 511 521 int usb_device_create_ddf(ddf_dev_t *ddf_dev, 512 522 const usb_endpoint_description_t **desc, const char **err) … … 514 524 assert(ddf_dev); 515 525 assert(err); 516 usb_device_t *dev = ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t)); 517 if (dev == NULL) { 526 usb_device_t *usb_dev = 527 ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t)); 528 if (usb_dev == NULL) { 518 529 *err = "DDF data alloc"; 519 530 return ENOMEM; 520 531 } 521 return usb_device_init( dev, ddf_dev, desc, err);532 return usb_device_init(usb_dev, ddf_dev, desc, err, 0); 522 533 } 523 534 … … 525 536 { 526 537 assert(ddf_dev); 527 usb_device_t * dev = ddf_dev_data_get(ddf_dev);528 assert( dev);529 usb_device_fini( dev);538 usb_device_t *usb_dev = ddf_dev_data_get(ddf_dev); 539 assert(usb_dev); 540 usb_device_fini(usb_dev); 530 541 return; 542 } 543 544 usb_device_t * usb_device_create(devman_handle_t handle) 545 { 546 usb_device_t *usb_dev = malloc(sizeof(usb_device_t)); 547 if (!usb_dev) 548 return NULL; 549 const char* dummy = NULL; 550 const int ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle); 551 if (ret != EOK) { 552 free(usb_dev); 553 usb_dev = NULL; 554 } 555 return usb_dev; 556 557 } 558 559 void usb_device_destroy(usb_device_t *usb_dev) 560 { 561 if (usb_dev) { 562 usb_device_fini(usb_dev); 563 free(usb_dev); 564 } 531 565 } 532 566
Note:
See TracChangeset
for help on using the changeset viewer.