Changeset b4b534ac in mainline for uspace/drv/bus/usb/usbmid/explore.c
- Timestamp:
- 2016-07-22T08:24:47Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/explore.c
r5b18137 rb4b534ac 34 34 * Exploration of available interfaces in the USB device. 35 35 */ 36 #include <ddf/driver.h>37 36 #include <errno.h> 38 37 #include <str_error.h> … … 41 40 #include <usb/dev/request.h> 42 41 #include <usb/dev/dp.h> 43 #include <usb/ddfiface.h>44 42 #include "usbmid.h" 45 46 /** Operations of the device itself. */47 static ddf_dev_ops_t mid_device_ops = {48 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl49 };50 43 51 44 /** Tell whether given interface is already in the list. … … 57 50 static bool interface_in_list(const list_t *list, int interface_no) 58 51 { 59 list_foreach(*list, link, usbmid_interface_t, iface) {52 list_foreach(*list, link, const usbmid_interface_t, iface) { 60 53 if (iface->interface_no == interface_no) { 61 54 return true; … … 71 64 * @param config_descriptor_size Size of configuration descriptor in bytes. 72 65 * @param list List where to add the interfaces. 73 * @return EOK on success, ENOMEM if out of memory.74 66 */ 75 static int create_interfaces( usb_mid_t *mid,const uint8_t *config_descriptor,76 size_t config_descriptor_size )67 static int create_interfaces(const uint8_t *config_descriptor, 68 size_t config_descriptor_size, list_t *list, usb_device_t *usb_dev) 77 69 { 70 assert(config_descriptor); 71 assert(usb_dev); 72 78 73 const usb_dp_parser_data_t data = { 79 74 .data = config_descriptor, … … 91 86 /* Walk all descriptors nested in the current configuration decriptor; 92 87 * i.e. all interface descriptors. */ 93 for (; interface_ptr != NULL;88 for (; interface_ptr != NULL; 94 89 interface_ptr = usb_dp_get_sibling_descriptor( 95 90 &parser, &data, config_descriptor, interface_ptr)) … … 103 98 104 99 /* Skip alternate interfaces. */ 105 if (interface_in_list(&mid->interface_list, 106 interface->interface_number)) { 100 if (interface_in_list(list, interface->interface_number)) { 107 101 /* TODO: add the alternatives and create match ids 108 102 * for them. */ … … 110 104 } 111 105 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 106 117 usbmid_interface_t *iface = ddf_fun_data_alloc(fun, 118 sizeof(usbmid_interface_t)); 119 if (iface == NULL) 120 goto error; 107 usb_log_info("Creating child for interface %d (%s).\n", 108 interface->interface_number, 109 usb_str_class(interface->interface_class)); 121 110 122 link_initialize(&iface->link); 123 iface->fun = fun; 124 iface->interface_no = interface->interface_number; 125 iface->interface = interface; 126 127 list_append(&iface->link, &mid->interface_list); 111 usbmid_interface_t *iface = NULL; 112 const int rc = usbmid_spawn_interface_child(usb_dev, &iface, 113 &usb_device_descriptors(usb_dev)->device, interface); 114 if (rc != EOK) { 115 //TODO: Do something about that failure. 116 usb_log_error("Failed to create interface child for " 117 "%d (%s): %s.\n", interface->interface_number, 118 usb_str_class(interface->interface_class), 119 str_error(rc)); 120 } else { 121 list_append(&iface->link, list); 122 } 128 123 } 129 130 124 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;141 125 } 142 126 … … 149 133 * @return Whether to accept this device from devman. 150 134 */ 151 boolusbmid_explore_device(usb_device_t *dev)135 int usbmid_explore_device(usb_device_t *dev) 152 136 { 153 int rc;154 155 unsigned dev_class = dev->descriptors.device.device_class;137 assert(dev); 138 const unsigned dev_class = 139 usb_device_descriptors(dev)->device.device_class; 156 140 if (dev_class != USB_CLASS_USE_INTERFACE) { 157 141 usb_log_warning( … … 159 143 dev_class, usb_str_class(dev_class), 160 144 USB_CLASS_USE_INTERFACE); 161 usb_log_error("Not multiinterface device, refusing.\n");162 return false;145 usb_log_error("Not a multi-interface device, refusing.\n"); 146 return ENOTSUP; 163 147 } 164 148 165 /* Shortcuts to save on typing ;-). */ 166 const void *config_descriptor_raw = dev->descriptors.configuration; 167 size_t config_descriptor_size = dev->descriptors.configuration_size; 149 /* Get coonfiguration descriptor. */ 150 const size_t config_descriptor_size = 151 usb_device_descriptors(dev)->full_config_size; 152 const void *config_descriptor_raw = 153 usb_device_descriptors(dev)->full_config; 168 154 const usb_standard_configuration_descriptor_t *config_descriptor = 169 155 config_descriptor_raw; 170 156 171 157 /* Select the first configuration */ 172 rc = usb_request_set_configuration(&dev->ctrl_pipe,158 int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev), 173 159 config_descriptor->configuration_number); 174 160 if (rc != EOK) { 175 161 usb_log_error("Failed to set device configuration: %s.\n", 176 162 str_error(rc)); 177 return false;163 return rc; 178 164 } 179 165 180 166 /* Create driver soft-state. */ 181 167 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); 182 168 if (!usb_mid) { 183 169 usb_log_error("Failed to create USB MID structure.\n"); 184 return false;170 return ENOMEM; 185 171 } 186 172 187 usb_mid->dev = dev->ddf_dev;188 189 173 /* Create control function. */ 190 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");174 usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl"); 191 175 if (usb_mid->ctl_fun == NULL) { 192 176 usb_log_error("Failed to create control function.\n"); 193 return false;177 return ENOMEM; 194 178 } 195 ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops);196 179 197 180 /* Bind control function. */ … … 201 184 str_error(rc)); 202 185 ddf_fun_destroy(usb_mid->ctl_fun); 203 return false;186 return rc; 204 187 } 205 188 206 189 /* Create interface children. */ 207 190 list_initialize(&usb_mid->interface_list); 208 create_interfaces(usb_mid, config_descriptor_raw, config_descriptor_size); 191 create_interfaces(config_descriptor_raw, config_descriptor_size, 192 &usb_mid->interface_list, dev); 209 193 210 /* Start child function for every interface. */ 211 list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) { 212 usb_log_info("Creating child for interface %d (%s).\n", 213 iface->interface_no, 214 usb_str_class(iface->interface->interface_class)); 215 216 rc = usbmid_spawn_interface_child(dev, iface, 217 &dev->descriptors.device, iface->interface); 218 if (rc != EOK) { 219 usb_log_error("Failed to create interface child: %s.\n", 220 str_error(rc)); 221 } 222 } 223 224 return true; 194 return EOK; 225 195 } 226 196
Note:
See TracChangeset
for help on using the changeset viewer.