Changeset 87a3df7f in mainline
- Timestamp:
- 2014-07-21T20:37:58Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b5111c46
- Parents:
- 54a1ca7
- Location:
- uspace/drv/bus/usb/usbmid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/explore.c
r54a1ca7 r87a3df7f 34 34 * Exploration of available interfaces in the USB device. 35 35 */ 36 #include <ddf/driver.h> 36 37 #include <errno.h> 37 38 #include <str_error.h> … … 70 71 * @param config_descriptor_size Size of configuration descriptor in bytes. 71 72 * @param list List where to add the interfaces. 72 */ 73 static void create_interfaces(const uint8_t *config_descriptor, 74 size_t config_descriptor_size, list_t *list) 73 * @return EOK on success, ENOMEM if out of memory. 74 */ 75 static int create_interfaces(usb_mid_t *mid, const uint8_t *config_descriptor, 76 size_t config_descriptor_size) 75 77 { 76 78 const usb_dp_parser_data_t data = { … … 101 103 102 104 /* Skip alternate interfaces. */ 103 if (interface_in_list(list, interface->interface_number)) { 105 if (interface_in_list(&mid->interface_list, 106 interface->interface_number)) { 104 107 /* TODO: add the alternatives and create match ids 105 108 * for them. */ 106 109 continue; 107 110 } 108 usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t)); 109 if (iface == NULL) { 110 //TODO: Do something about that failure. 111 break; 112 } 111 112 /* Create the function */ 113 ddf_fun_t *fun = ddf_fun_create(mid->dev, fun_inner, NULL); 114 if (fun == NULL) 115 goto error; 116 117 usbmid_interface_t *iface = ddf_fun_data_alloc(fun, 118 sizeof(usbmid_interface_t)); 119 if (iface == NULL) 120 goto error; 113 121 114 122 link_initialize(&iface->link); 115 iface->fun = NULL;123 iface->fun = fun; 116 124 iface->interface_no = interface->interface_number; 117 125 iface->interface = interface; 118 126 119 list_append(&iface->link, list); 120 } 127 list_append(&iface->link, &mid->interface_list); 128 } 129 130 return EOK; 131 error: 132 while (!list_empty(&mid->interface_list)) { 133 link_t *link = list_first(&mid->interface_list); 134 usbmid_interface_t *iface = list_get_instance(link, 135 usbmid_interface_t, link); 136 137 ddf_fun_destroy(iface->fun); 138 } 139 140 return ENOMEM; 121 141 } 122 142 … … 165 185 } 166 186 187 usb_mid->dev = dev->ddf_dev; 188 167 189 /* Create control function. */ 168 190 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); … … 182 204 } 183 205 184 185 206 /* Create interface children. */ 186 207 list_initialize(&usb_mid->interface_list); 187 create_interfaces(config_descriptor_raw, config_descriptor_size, 188 &usb_mid->interface_list); 208 create_interfaces(usb_mid, config_descriptor_raw, config_descriptor_size); 189 209 190 210 /* Start child function for every interface. */ -
uspace/drv/bus/usb/usbmid/usbmid.c
r54a1ca7 r87a3df7f 30 30 * @{ 31 31 */ 32 33 /* XXX Fix this */34 #define _DDF_DATA_IMPLANT35 32 36 33 /** … … 102 99 const usb_standard_interface_descriptor_t *interface_descriptor) 103 100 { 104 ddf_fun_t *child = NULL;105 101 char *child_name = NULL; 106 102 int rc; … … 114 110 usb_str_class(interface_descriptor->interface_class), 115 111 interface_descriptor->interface_number); 116 if (rc < 0) {112 if (rc < 0) 117 113 return ENOMEM; 118 }119 114 120 /* Create the device. */ 121 child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name); 115 rc = ddf_fun_set_name(iface->fun, child_name); 122 116 free(child_name); 123 if ( child == NULL) {117 if (rc != EOK) 124 118 return ENOMEM; 125 }126 119 127 120 match_id_list_t match_ids; … … 130 123 rc = usb_device_create_match_ids_from_interface(device_descriptor, 131 124 interface_descriptor, &match_ids); 132 if (rc != EOK) { 133 ddf_fun_destroy(child); 125 if (rc != EOK) 134 126 return rc; 135 }136 127 137 128 list_foreach(match_ids.ids, link, match_id_t, match_id) { 138 rc = ddf_fun_add_match_id( child, match_id->id, match_id->score);129 rc = ddf_fun_add_match_id(iface->fun, match_id->id, match_id->score); 139 130 if (rc != EOK) { 140 131 clean_match_ids(&match_ids); 141 ddf_fun_destroy(child);142 132 return rc; 143 133 } … … 145 135 clean_match_ids(&match_ids); 146 136 147 rc = ddf_fun_bind(child);148 if (rc != EOK) { 149 /* This takes care of match_id deallocation as well. */150 ddf_fun_destroy(child);137 ddf_fun_set_ops(iface->fun, &child_device_ops); 138 139 rc = ddf_fun_bind(iface->fun); 140 if (rc != EOK) 151 141 return rc; 152 }153 154 iface->fun = child;155 ddf_fun_data_implant(child, iface);156 ddf_fun_set_ops(child, &child_device_ops);157 142 158 143 return EOK; -
uspace/drv/bus/usb/usbmid/usbmid.h
r54a1ca7 r87a3df7f 60 60 /** Container to hold all the function pointers */ 61 61 typedef struct usb_mid { 62 ddf_dev_t *dev; 62 63 ddf_fun_t *ctl_fun; 63 64 list_t interface_list;
Note:
See TracChangeset
for help on using the changeset viewer.