Changes in uspace/drv/bus/usb/usbhub/usbhub.c [4ca778b:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/usbhub.c
r4ca778b r3e6a98c5 45 45 #include <usb/dev/pipes.h> 46 46 #include <usb/classes/classes.h> 47 #include <usb/ddfiface.h> 47 48 #include <usb/descriptor.h> 48 49 #include <usb/dev/recognise.h> … … 56 57 57 58 #define HUB_FNC_NAME "hub" 58 /** Hub status-change endpoint description.59 *60 * For more information see section 11.15.1 of USB 1.1 specification.61 */62 const usb_endpoint_description_t hub_status_change_endpoint_description =63 {64 .transfer_type = USB_TRANSFER_INTERRUPT,65 .direction = USB_DIRECTION_IN,66 .interface_class = USB_CLASS_HUB,67 .interface_subclass = 0,68 .interface_protocol = 0,69 .flags = 070 };71 59 72 60 /** Standard get hub global status request */ … … 111 99 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 112 100 113 usb_pipe_t *control_pipe = usb_device_get_default_pipe(usb_dev); 114 115 int opResult = usb_pipe_start_long_transfer(control_pipe); 101 102 int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe); 116 103 if (opResult != EOK) { 117 104 usb_log_error("Failed to start long ctrl pipe transfer: %s\n", … … 123 110 opResult = usb_set_first_configuration(usb_dev); 124 111 if (opResult != EOK) { 125 usb_pipe_end_long_transfer( control_pipe);112 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 126 113 usb_log_error("Could not set hub configuration: %s\n", 127 114 str_error(opResult)); … … 132 119 opResult = usb_hub_process_hub_specific_info(hub_dev); 133 120 if (opResult != EOK) { 134 usb_pipe_end_long_transfer( control_pipe);121 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 135 122 usb_log_error("Could process hub specific info, %s\n", 136 123 str_error(opResult)); … … 140 127 /* Create hub control function. */ 141 128 usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n"); 142 hub_dev->hub_fun = usb_device_ddf_fun_create(hub_dev->usb_device,129 hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev, 143 130 fun_exposed, HUB_FNC_NAME); 144 131 if (hub_dev->hub_fun == NULL) { 145 usb_pipe_end_long_transfer( control_pipe);132 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 146 133 usb_log_error("Failed to create hub function.\n"); 147 134 return ENOMEM; … … 151 138 opResult = ddf_fun_bind(hub_dev->hub_fun); 152 139 if (opResult != EOK) { 153 usb_pipe_end_long_transfer( control_pipe);140 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 154 141 usb_log_error("Failed to bind hub function: %s.\n", 155 142 str_error(opResult)); … … 159 146 160 147 /* Start hub operation. */ 161 opResult = usb_device_auto_poll_desc(hub_dev->usb_device, 162 &hub_status_change_endpoint_description, 163 hub_port_changes_callback, ((hub_dev->port_count + 1 + 7) / 8), 164 -1, usb_hub_polling_terminated_callback, hub_dev); 165 if (opResult != EOK) { 166 usb_pipe_end_long_transfer(control_pipe); 148 opResult = usb_device_auto_poll(hub_dev->usb_device, 0, 149 hub_port_changes_callback, ((hub_dev->port_count + 1 + 8) / 8), 150 usb_hub_polling_terminated_callback, hub_dev); 151 if (opResult != EOK) { 152 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 167 153 /* Function is already bound */ 168 154 ddf_fun_unbind(hub_dev->hub_fun); … … 174 160 hub_dev->running = true; 175 161 usb_log_info("Controlling hub '%s' (%zu ports).\n", 176 usb_device_get_name(hub_dev->usb_device), hub_dev->port_count);177 178 usb_pipe_end_long_transfer( control_pipe);162 ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count); 163 164 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe); 179 165 return EOK; 180 166 } … … 199 185 { 200 186 assert(usb_dev); 201 usb_hub_dev_t *hub = usb_dev ice_data_get(usb_dev);187 usb_hub_dev_t *hub = usb_dev->driver_data; 202 188 assert(hub); 203 189 unsigned tries = 10; … … 213 199 214 200 for (size_t port = 0; port < hub->port_count; ++port) { 215 const int ret = usb_hub_port_fini(&hub->ports[port], hub); 216 if (ret != EOK) 217 return ret; 201 if (hub->ports[port].attached_device.fun) { 202 const int ret = 203 usb_hub_port_fini(&hub->ports[port], hub); 204 if (ret != EOK) 205 return ret; 206 } 218 207 } 219 208 free(hub->ports); … … 258 247 259 248 /* N + 1 bit indicates change on port N */ 260 for (size_t port = 0; port < hub->port_count ; ++port) {249 for (size_t port = 0; port < hub->port_count + 1; port++) { 261 250 const size_t bit = port + 1; 262 251 const bool change = (change_bitmap[bit / 8] >> (bit % 8)) & 1; … … 284 273 /* Get hub descriptor. */ 285 274 usb_log_debug("Retrieving descriptor\n"); 286 usb_pipe_t *control_pipe = 287 usb_device_get_default_pipe(hub_dev->usb_device); 275 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 288 276 289 277 usb_hub_descriptor_header_t descriptor; … … 323 311 } 324 312 325 usb_log_info("Hub port power switching enabled (%s).\n", 326 hub_dev->per_port_power ? "per port" : "ganged"); 313 usb_log_info("Hub port power switching enabled.\n"); 327 314 328 315 for (size_t port = 0; port < hub_dev->port_count; ++port) { … … 358 345 /* Get number of possible configurations from device descriptor */ 359 346 const size_t configuration_count = 360 usb_device _descriptors(usb_device)->device.configuration_count;347 usb_device->descriptors.device.configuration_count; 361 348 usb_log_debug("Hub has %zu configurations.\n", configuration_count); 362 349 … … 366 353 } 367 354 368 // TODO: Make sure that the cast is correct 369 const size_t config_size = 370 usb_device_descriptors(usb_device)->full_config_size; 371 const usb_standard_configuration_descriptor_t *config_descriptor = 372 usb_device_descriptors(usb_device)->full_config; 373 374 if (config_size < sizeof(usb_standard_configuration_descriptor_t)) { 355 if (usb_device->descriptors.configuration_size 356 < sizeof(usb_standard_configuration_descriptor_t)) { 375 357 usb_log_error("Configuration descriptor is not big enough" 376 358 " to fit standard configuration descriptor.\n"); … … 378 360 } 379 361 362 // TODO: Make sure that the cast is correct 363 usb_standard_configuration_descriptor_t *config_descriptor 364 = (usb_standard_configuration_descriptor_t *) 365 usb_device->descriptors.configuration; 366 380 367 /* Set configuration. Use the configuration that was in 381 368 * usb_device->descriptors.configuration i.e. The first one. */ 382 369 const int opResult = usb_request_set_configuration( 383 usb_device_get_default_pipe(usb_device), 384 config_descriptor->configuration_number); 370 &usb_device->ctrl_pipe, config_descriptor->configuration_number); 385 371 if (opResult != EOK) { 386 372 usb_log_error("Failed to set hub configuration: %s.\n", … … 442 428 assert(hub_dev->usb_device); 443 429 usb_log_debug("Global interrupt on a hub\n"); 444 usb_pipe_t *control_pipe = 445 usb_device_get_default_pipe(hub_dev->usb_device); 430 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 446 431 447 432 usb_hub_status_t status; … … 467 452 /* Ack change in hub OC flag */ 468 453 const int ret = usb_request_clear_feature( 469 control_pipe, USB_REQUEST_TYPE_CLASS,454 &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS, 470 455 USB_REQUEST_RECIPIENT_DEVICE, 471 456 USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
Note:
See TracChangeset
for help on using the changeset viewer.