Changeset 95067954 in mainline for uspace/drv/usbhub/usbhub.c
- Timestamp:
- 2011-05-29T21:59:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3dfdcb7
- Parents:
- bd7acda (diff), 98e15b1 (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
rbd7acda r95067954 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); … … 252 251 /// \TODO this is not semantically correct 253 252 bool is_power_switched = 254 ((descriptor->hub_characteristics & 1) == 0);253 ((descriptor->hub_characteristics & 1) == 0); 255 254 bool has_individual_port_powering = 256 ((descriptor->hub_characteristics & 1) != 0);255 ((descriptor->hub_characteristics & 1) != 0); 257 256 hub_info->ports = malloc( 258 257 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 259 if (!hub_info->ports){258 if (!hub_info->ports) { 260 259 return ENOMEM; 261 260 } … … 264 263 usb_hub_port_init(&hub_info->ports[port]); 265 264 } 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");265 if (is_power_switched) { 266 usb_log_debug("Hub power switched\n"); 267 268 if (!has_individual_port_powering) { 269 usb_log_debug("Has_global powering\n"); 271 270 opResult = usb_hub_set_feature(hub_info->control_pipe, 272 271 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 273 272 if (opResult != EOK) { 274 usb_log_error(" cannot power hub: %s\n",273 usb_log_error("Cannot power hub: %s\n", 275 274 str_error(opResult)); 276 275 } … … 278 277 279 278 for (port = 1; port <= hub_info->port_count; ++port) { 280 usb_log_debug("Powering port %zu.\n", port);279 usb_log_debug("Powering port %zu.\n", port); 281 280 opResult = usb_hub_set_port_feature(hub_info->control_pipe, 282 281 port, USB_HUB_FEATURE_PORT_POWER); … … 286 285 } 287 286 } 288 289 } else{290 usb_log_debug(" !is_power_switched, not going to be powered\n");291 } 292 usb_log_debug2(" freeing data\n");287 288 } else { 289 usb_log_debug("Power not switched, not going to be powered\n"); 290 } 291 usb_log_debug2("Freeing data\n"); 293 292 free(descriptor); 294 293 return EOK; … … 303 302 * @return error code 304 303 */ 305 static int usb_hub_set_configuration(usb_hub_info_t * 304 static int usb_hub_set_configuration(usb_hub_info_t *hub_info) { 306 305 //device descriptor 307 306 usb_standard_device_descriptor_t *std_descriptor 308 307 = &hub_info->usb_device->descriptors.device; 309 usb_log_debug(" hub has %d configurations\n",308 usb_log_debug("Hub has %d configurations\n", 310 309 std_descriptor->configuration_count); 311 310 if (std_descriptor->configuration_count < 1) { 312 usb_log_error(" there are no configurations available\n");311 usb_log_error("There are no configurations available\n"); 313 312 return EINVAL; 314 313 } … … 328 327 return opResult; 329 328 } 330 usb_log_debug("\t used configuration %d\n",329 usb_log_debug("\tUsed configuration %d\n", 331 330 config_descriptor->configuration_number); 332 331 … … 343 342 * @return error code 344 343 */ 345 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){344 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) { 346 345 int rc; 347 346 … … 367 366 //********************************************* 368 367 369 370 368 /** 371 369 * process hub over current change … … 376 374 * @return error code 377 375 */ 378 static int usb_process_hub_over_current(usb_hub_info_t * 376 static int usb_process_hub_over_current(usb_hub_info_t *hub_info, 379 377 usb_hub_status_t status) { 380 378 int opResult; 381 if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)){379 if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) { 382 380 //poweroff all ports 383 381 unsigned int port; 384 for (port = 1;port <= hub_info->port_count;++port){382 for (port = 1; port <= hub_info->port_count; ++port) { 385 383 opResult = usb_hub_clear_port_feature( 386 hub_info->control_pipe, port,384 hub_info->control_pipe, port, 387 385 USB_HUB_FEATURE_PORT_POWER); 388 386 if (opResult != EOK) { 389 387 usb_log_warning( 390 " cannot power off port %d; %d\n",391 port, opResult);388 "Cannot power off port %d; %s\n", 389 port, str_error(opResult)); 392 390 } 393 391 } … … 395 393 //power all ports 396 394 unsigned int port; 397 for (port = 1;port <= hub_info->port_count;++port){395 for (port = 1; port <= hub_info->port_count; ++port) { 398 396 opResult = usb_hub_set_port_feature( 399 hub_info->control_pipe, port,397 hub_info->control_pipe, port, 400 398 USB_HUB_FEATURE_PORT_POWER); 401 399 if (opResult != EOK) { 402 400 usb_log_warning( 403 " cannot power off port %d; %d\n",404 port, opResult);401 "Cannot power off port %d; %s\n", 402 port, str_error(opResult)); 405 403 } 406 404 } … … 417 415 * @return error code 418 416 */ 419 static int usb_process_hub_local_power_change(usb_hub_info_t * 417 static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info, 420 418 usb_hub_status_t status) { 421 419 int opResult = EOK; 422 420 opResult = usb_hub_clear_feature(hub_info->control_pipe, 423 421 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 424 425 usb_log_error(" cannnot clear hub power change flag: "426 "% d\n",427 opResult);422 if (opResult != EOK) { 423 usb_log_error("Cannnot clear hub power change flag: " 424 "%s\n", 425 str_error(opResult)); 428 426 } 429 427 return opResult; … … 437 435 * @param hub_info hub instance 438 436 */ 439 static void usb_hub_process_global_interrupt(usb_hub_info_t * 440 usb_log_debug(" global interrupt on a hub\n");437 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) { 438 usb_log_debug("Global interrupt on a hub\n"); 441 439 usb_pipe_t *pipe = hub_info->control_pipe; 442 440 int opResult; … … 455 453 ); 456 454 if (opResult != EOK) { 457 usb_log_error("could not get hub status\n"); 455 usb_log_error("Could not get hub status: %s\n", 456 str_error(opResult)); 458 457 return; 459 458 } 460 459 if (rcvd_size != sizeof (usb_port_status_t)) { 461 usb_log_error(" received status has incorrect size\n");460 usb_log_error("Received status has incorrect size\n"); 462 461 return; 463 462 } 464 463 //port reset 465 464 if ( 466 usb_hub_is_status(status, 16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {465 usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) { 467 466 usb_process_hub_over_current(hub_info, status); 468 467 } 469 468 if ( 470 usb_hub_is_status(status, 16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {469 usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) { 471 470 usb_process_hub_local_power_change(hub_info, status); 472 471 } … … 481 480 * @param data pointer to usb_hub_info_t structure 482 481 */ 483 static void usb_hub_polling_terminated_callback(usb_device_t * 484 bool was_error, void * data){482 static void usb_hub_polling_terminated_callback(usb_device_t *device, 483 bool was_error, void *data) { 485 484 usb_hub_info_t * hub = data; 486 485 assert(hub);
Note:
See TracChangeset
for help on using the changeset viewer.