Changeset fd9b3a67 in mainline
- Timestamp:
- 2013-01-27T00:44:23Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 71384bd3
- Parents:
- 8b68bdf
- Location:
- uspace/lib/usbdev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/include/usb/dev/driver.h
r8b68bdf rfd9b3a67 43 43 #include <usb_iface.h> 44 44 45 /** USB device structure. */ 46 typedef struct { 47 /** Connection to USB hc, used by wire and arbitrary requests. */ 48 usb_hc_connection_t hc_conn; 49 /** Connection backing the pipes. 50 * Typically, you will not need to use this attribute at all. 51 */ 52 usb_device_connection_t wire; 53 /** The default control pipe. */ 54 usb_pipe_t ctrl_pipe; 55 56 /** Other endpoint pipes. 57 * This is an array of other endpoint pipes in the same order as 58 * in usb_driver_t. 59 */ 60 usb_endpoint_mapping_t *pipes; 61 /** Number of other endpoint pipes. */ 62 size_t pipes_count; 63 /** Current interface. 64 * Usually, drivers operate on single interface only. 65 * This item contains the value of the interface or -1 for any. 66 */ 67 int interface_no; 68 /** Alternative interfaces. */ 69 usb_alternate_interfaces_t alternate_interfaces; 70 71 /** Some useful descriptors for USB device. */ 72 struct { 73 /** Standard device descriptor. */ 74 usb_standard_device_descriptor_t device; 75 /** Full configuration descriptor of current configuration. */ 76 const uint8_t *configuration; 77 size_t configuration_size; 78 } descriptors; 79 80 /** Generic DDF device backing this one. DO NOT TOUCH! */ 81 ddf_dev_t *ddf_dev; 82 /** Custom driver data. 83 * Do not use the entry in generic device, that is already used 84 * by the framework. 85 */ 86 void *driver_data; 87 88 usb_dev_session_t *bus_session; 89 } usb_device_t; 45 typedef struct usb_device usb_device_t; 90 46 91 47 /** USB driver ops. */ … … 142 98 int usb_driver_main(const usb_driver_t *); 143 99 144 int usb_device_init(usb_device_t *, ddf_dev_t *, 145 const usb_endpoint_description_t **, const char **); 146 void usb_device_deinit(usb_device_t *); 100 int usb_device_create_ddf(ddf_dev_t *, const usb_endpoint_description_t **, const char **); 101 void usb_device_destroy_ddf(ddf_dev_t *); 147 102 148 103 const char* usb_device_get_name(usb_device_t *); -
uspace/lib/usbdev/src/devdrv.c
r8b68bdf rfd9b3a67 40 40 #include <str_error.h> 41 41 #include <assert.h> 42 43 /** USB device structure. */ 44 typedef struct usb_device { 45 /** Connection to USB hc, used by wire and arbitrary requests. */ 46 usb_hc_connection_t hc_conn; 47 /** Connection backing the pipes. 48 * Typically, you will not need to use this attribute at all. 49 */ 50 usb_device_connection_t wire; 51 /** The default control pipe. */ 52 usb_pipe_t ctrl_pipe; 53 54 /** Other endpoint pipes. 55 * This is an array of other endpoint pipes in the same order as 56 * in usb_driver_t. 57 */ 58 usb_endpoint_mapping_t *pipes; 59 /** Number of other endpoint pipes. */ 60 size_t pipes_count; 61 /** Current interface. 62 * Usually, drivers operate on single interface only. 63 * This item contains the value of the interface or -1 for any. 64 */ 65 int interface_no; 66 /** Alternative interfaces. */ 67 usb_alternate_interfaces_t alternate_interfaces; 68 69 /** Some useful descriptors for USB device. */ 70 struct { 71 /** Standard device descriptor. */ 72 usb_standard_device_descriptor_t device; 73 /** Full configuration descriptor of current configuration. */ 74 const uint8_t *configuration; 75 size_t configuration_size; 76 } descriptors; 77 78 /** Generic DDF device backing this one. DO NOT TOUCH! */ 79 ddf_dev_t *ddf_dev; 80 /** Custom driver data. 81 * Do not use the entry in generic device, that is already used 82 * by the framework. 83 */ 84 void *driver_data; 85 86 usb_dev_session_t *bus_session; 87 } usb_device_t; 42 88 43 89 /** Count number of pipes the driver expects. … … 350 396 * @return Error code. 351 397 */ 352 int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,398 static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev, 353 399 const usb_endpoint_description_t **endpoints, const char **errstr_ptr) 354 400 { … … 446 492 * Does not free/destroy supplied pointer. 447 493 */ 448 void usb_device_deinit(usb_device_t *dev)494 static void usb_device_fini(usb_device_t *dev) 449 495 { 450 496 if (dev) { … … 461 507 } 462 508 509 int usb_device_create_ddf(ddf_dev_t *ddf_dev, 510 const usb_endpoint_description_t **desc, const char **err) 511 { 512 assert(ddf_dev); 513 assert(err); 514 usb_device_t *dev = ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t)); 515 if (dev == NULL) { 516 *err = "DDF data alloc"; 517 return ENOMEM; 518 } 519 return usb_device_init(dev, ddf_dev, desc, err); 520 } 521 522 void usb_device_destroy_ddf(ddf_dev_t *ddf_dev) 523 { 524 assert(ddf_dev); 525 usb_device_t *dev = ddf_dev_data_get(ddf_dev); 526 assert(dev); 527 usb_device_fini(dev); 528 return; 529 } 530 463 531 const char *usb_device_get_name(usb_device_t *usb_dev) 464 532 { -
uspace/lib/usbdev/src/driver.c
r8b68bdf rfd9b3a67 54 54 assert(driver->ops->device_add); 55 55 56 /* Get place for driver data. */57 usb_device_t *dev = ddf_dev_data_alloc(gen_dev, sizeof(usb_device_t));58 if (dev == NULL) {59 usb_log_error("USB device `%s' structure allocation failed.\n",60 ddf_dev_get_name(gen_dev));61 return ENOMEM;62 }63 64 56 /* Initialize generic USB driver data. */ 65 57 const char *err_msg = NULL; 66 int rc = usb_device_ init(dev,gen_dev, driver->endpoints, &err_msg);58 int rc = usb_device_create_ddf(gen_dev, driver->endpoints, &err_msg); 67 59 if (rc != EOK) { 68 60 usb_log_error("USB device `%s' init failed (%s): %s.\n", … … 72 64 73 65 /* Start USB driver specific initialization. */ 74 rc = driver->ops->device_add(d ev);66 rc = driver->ops->device_add(ddf_dev_data_get(gen_dev)); 75 67 if (rc != EOK) 76 usb_device_de init(dev);68 usb_device_destroy_ddf(gen_dev); 77 69 return rc; 78 70 } … … 96 88 if (ret != EOK) 97 89 return ret; 98 usb_device_de init(usb_dev);90 usb_device_destroy_ddf(gen_dev); 99 91 return EOK; 100 92 } … … 116 108 const int ret = driver->ops->device_gone(usb_dev); 117 109 if (ret == EOK) 118 usb_device_de init(usb_dev);110 usb_device_destroy_ddf(gen_dev); 119 111 120 112 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.