Changeset 5da18c7 in mainline for uspace/drv/usbhub/usbhub.c
- Timestamp:
- 2011-05-30T18:41:16Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 109d55c
- Parents:
- a2a3763 (diff), 8c74d15 (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/usbhub/usbhub.c
ra2a3763 r5da18c7 56 56 57 57 58 static usb_hub_info_t * usb_hub_info_create(usb_device_t * 59 60 static int usb_hub_process_hub_specific_info(usb_hub_info_t * 61 62 static int usb_hub_set_configuration(usb_hub_info_t * 63 64 static int usb_hub_start_hub_fibril(usb_hub_info_t * 65 66 static int usb_process_hub_over_current(usb_hub_info_t * 58 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev); 59 60 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info); 61 62 static int usb_hub_set_configuration(usb_hub_info_t *hub_info); 63 64 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info); 65 66 static int usb_process_hub_over_current(usb_hub_info_t *hub_info, 67 67 usb_hub_status_t status); 68 68 69 static int usb_process_hub_local_power_change(usb_hub_info_t * 69 static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info, 70 70 usb_hub_status_t status); 71 71 72 static void usb_hub_process_global_interrupt(usb_hub_info_t * 73 74 static void usb_hub_polling_terminated_callback(usb_device_t * 75 bool was_error, void * 72 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info); 73 74 static void usb_hub_polling_terminated_callback(usb_device_t *device, 75 bool was_error, void *data); 76 76 77 77 … … 90 90 * @return error code 91 91 */ 92 int usb_hub_add_device(usb_device_t * 92 int usb_hub_add_device(usb_device_t *usb_dev) { 93 93 if (!usb_dev) return EINVAL; 94 usb_hub_info_t * 94 usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev); 95 95 //create hc connection 96 96 usb_log_debug("Initializing USB wire abstraction.\n"); … … 99 99 hub_info->usb_device->ddf_dev); 100 100 if (opResult != EOK) { 101 usb_log_error(" could not initialize connection to device, "102 " errno %d\n",103 opResult);101 usb_log_error("Could not initialize connection to device, " 102 " %s\n", 103 str_error(opResult)); 104 104 free(hub_info); 105 105 return opResult; … … 109 109 opResult = usb_hub_set_configuration(hub_info); 110 110 if (opResult != EOK) { 111 usb_log_error(" could not set hub configuration, errno %d\n",112 opResult);111 usb_log_error("Could not set hub configuration, %s\n", 112 str_error(opResult)); 113 113 free(hub_info); 114 114 return opResult; … … 117 117 opResult = usb_hub_process_hub_specific_info(hub_info); 118 118 if (opResult != EOK) { 119 usb_log_error(" could process hub specific info, errno %d\n",120 opResult);119 usb_log_error("Could process hub specific info, %s\n", 120 str_error(opResult)); 121 121 free(hub_info); 122 122 return opResult; … … 135 135 136 136 opResult = usb_hub_start_hub_fibril(hub_info); 137 if (opResult!=EOK)137 if (opResult != EOK) 138 138 free(hub_info); 139 139 return opResult; 140 140 } 141 142 141 143 142 /** Callback for polling hub for changes. … … 193 192 * @return basic usb_hub_info_t structure 194 193 */ 195 static usb_hub_info_t * usb_hub_info_create(usb_device_t * 196 usb_hub_info_t * result = malloc(sizeof (usb_hub_info_t));194 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev) { 195 usb_hub_info_t * result = malloc(sizeof (usb_hub_info_t)); 197 196 if (!result) return NULL; 198 197 result->usb_device = usb_dev; … … 202 201 203 202 result->ports = NULL; 204 result->port_count = (size_t) - 1;203 result->port_count = (size_t) - 1; 205 204 fibril_mutex_initialize(&result->port_mutex); 206 205 … … 221 220 * @return error code 222 221 */ 223 static int usb_hub_process_hub_specific_info(usb_hub_info_t * 222 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info) { 224 223 // get hub descriptor 225 usb_log_debug(" creating serialized descriptor\n");224 usb_log_debug("Creating serialized descriptor\n"); 226 225 uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE]; 227 226 usb_hub_descriptor_t * descriptor; … … 235 234 236 235 if (opResult != EOK) { 237 usb_log_error(" failed when receiving hub descriptor, "238 " badcode = %d\n",239 opResult);236 usb_log_error("Failed when receiving hub descriptor, " 237 "%s\n", 238 str_error(opResult)); 240 239 free(serialized_descriptor); 241 240 return opResult; 242 241 } 243 usb_log_debug2(" deserializing descriptor\n");242 usb_log_debug2("Deserializing descriptor\n"); 244 243 descriptor = usb_create_deserialized_hub_desriptor( 245 244 serialized_descriptor); … … 250 249 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 251 250 hub_info->port_count = descriptor->ports_count; 252 /// \TODO this is not semantically correct253 251 bool is_power_switched = 254 ((descriptor->hub_characteristics & 1) == 0);252 ((descriptor->hub_characteristics & 1) == 0); 255 253 bool has_individual_port_powering = 256 ((descriptor->hub_characteristics & 1) != 0);254 ((descriptor->hub_characteristics & 1) != 0); 257 255 hub_info->ports = malloc( 258 256 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 259 if (!hub_info->ports){257 if (!hub_info->ports) { 260 258 return ENOMEM; 261 259 } … … 264 262 usb_hub_port_init(&hub_info->ports[port]); 265 263 } 266 if (is_power_switched){267 usb_log_debug(" is_power_switched\n");268 269 if (!has_individual_port_powering){270 usb_log_debug(" !has_individual_port_powering\n");264 if (is_power_switched) { 265 usb_log_debug("Hub power switched\n"); 266 267 if (!has_individual_port_powering) { 268 usb_log_debug("Has_global powering\n"); 271 269 opResult = usb_hub_set_feature(hub_info->control_pipe, 272 270 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 273 271 if (opResult != EOK) { 274 usb_log_error(" cannot power hub: %s\n",272 usb_log_error("Cannot power hub: %s\n", 275 273 str_error(opResult)); 276 274 } … … 278 276 279 277 for (port = 1; port <= hub_info->port_count; ++port) { 280 usb_log_debug("Powering port %zu.\n", port);278 usb_log_debug("Powering port %zu.\n", port); 281 279 opResult = usb_hub_set_port_feature(hub_info->control_pipe, 282 280 port, USB_HUB_FEATURE_PORT_POWER); … … 286 284 } 287 285 } 288 289 } else{290 usb_log_debug(" !is_power_switched, not going to be powered\n");291 } 292 usb_log_debug2(" freeing data\n");286 287 } else { 288 usb_log_debug("Power not switched, not going to be powered\n"); 289 } 290 usb_log_debug2("Freeing data\n"); 293 291 free(descriptor); 294 292 return EOK; … … 303 301 * @return error code 304 302 */ 305 static int usb_hub_set_configuration(usb_hub_info_t * 303 static int usb_hub_set_configuration(usb_hub_info_t *hub_info) { 306 304 //device descriptor 307 305 usb_standard_device_descriptor_t *std_descriptor 308 306 = &hub_info->usb_device->descriptors.device; 309 usb_log_debug(" hub has %d configurations\n",307 usb_log_debug("Hub has %d configurations\n", 310 308 std_descriptor->configuration_count); 311 309 if (std_descriptor->configuration_count < 1) { 312 usb_log_error(" there are no configurations available\n");310 usb_log_error("There are no configurations available\n"); 313 311 return EINVAL; 314 312 } … … 328 326 return opResult; 329 327 } 330 usb_log_debug("\t used configuration %d\n",328 usb_log_debug("\tUsed configuration %d\n", 331 329 config_descriptor->configuration_number); 332 330 … … 343 341 * @return error code 344 342 */ 345 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){343 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) { 346 344 int rc; 347 345 … … 367 365 //********************************************* 368 366 369 370 367 /** 371 368 * process hub over current change … … 376 373 * @return error code 377 374 */ 378 static int usb_process_hub_over_current(usb_hub_info_t * 375 static int usb_process_hub_over_current(usb_hub_info_t *hub_info, 379 376 usb_hub_status_t status) { 380 377 int opResult; 381 if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)){378 if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) { 382 379 //poweroff all ports 383 380 unsigned int port; 384 for (port = 1;port <= hub_info->port_count;++port){381 for (port = 1; port <= hub_info->port_count; ++port) { 385 382 opResult = usb_hub_clear_port_feature( 386 hub_info->control_pipe, port,383 hub_info->control_pipe, port, 387 384 USB_HUB_FEATURE_PORT_POWER); 388 385 if (opResult != EOK) { 389 386 usb_log_warning( 390 " cannot power off port %d; %d\n",391 port, opResult);387 "Cannot power off port %d; %s\n", 388 port, str_error(opResult)); 392 389 } 393 390 } … … 395 392 //power all ports 396 393 unsigned int port; 397 for (port = 1;port <= hub_info->port_count;++port){394 for (port = 1; port <= hub_info->port_count; ++port) { 398 395 opResult = usb_hub_set_port_feature( 399 hub_info->control_pipe, port,396 hub_info->control_pipe, port, 400 397 USB_HUB_FEATURE_PORT_POWER); 401 398 if (opResult != EOK) { 402 399 usb_log_warning( 403 " cannot power off port %d; %d\n",404 port, opResult);400 "Cannot power off port %d; %s\n", 401 port, str_error(opResult)); 405 402 } 406 403 } … … 417 414 * @return error code 418 415 */ 419 static int usb_process_hub_local_power_change(usb_hub_info_t * 416 static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info, 420 417 usb_hub_status_t status) { 421 418 int opResult = EOK; 422 419 opResult = usb_hub_clear_feature(hub_info->control_pipe, 423 420 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 424 425 usb_log_error(" cannnot clear hub power change flag: "426 "% d\n",427 opResult);421 if (opResult != EOK) { 422 usb_log_error("Cannnot clear hub power change flag: " 423 "%s\n", 424 str_error(opResult)); 428 425 } 429 426 return opResult; … … 437 434 * @param hub_info hub instance 438 435 */ 439 static void usb_hub_process_global_interrupt(usb_hub_info_t * 440 usb_log_debug(" global interrupt on a hub\n");436 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) { 437 usb_log_debug("Global interrupt on a hub\n"); 441 438 usb_pipe_t *pipe = hub_info->control_pipe; 442 439 int opResult; … … 455 452 ); 456 453 if (opResult != EOK) { 457 usb_log_error("could not get hub status\n"); 454 usb_log_error("Could not get hub status: %s\n", 455 str_error(opResult)); 458 456 return; 459 457 } 460 458 if (rcvd_size != sizeof (usb_port_status_t)) { 461 usb_log_error(" received status has incorrect size\n");459 usb_log_error("Received status has incorrect size\n"); 462 460 return; 463 461 } 464 462 //port reset 465 463 if ( 466 usb_hub_is_status(status, 16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {464 usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) { 467 465 usb_process_hub_over_current(hub_info, status); 468 466 } 469 467 if ( 470 usb_hub_is_status(status, 16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {468 usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) { 471 469 usb_process_hub_local_power_change(hub_info, status); 472 470 } … … 481 479 * @param data pointer to usb_hub_info_t structure 482 480 */ 483 static void usb_hub_polling_terminated_callback(usb_device_t * 484 bool was_error, void * data){481 static void usb_hub_polling_terminated_callback(usb_device_t *device, 482 bool was_error, void *data) { 485 483 usb_hub_info_t * hub = data; 486 484 assert(hub);
Note:
See TracChangeset
for help on using the changeset viewer.