Changes in uspace/drv/usbhub/usbhub.c [6ab7f3e9:3ef91c88] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r6ab7f3e9 r3ef91c88 56 56 57 57 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,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 * hub_info,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 * hub_info);73 74 static void usb_hub_polling_terminated_callback(usb_device_t * device,75 bool was_error, void * data);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 * usb_dev) {92 int usb_hub_add_device(usb_device_t * usb_dev) { 93 93 if (!usb_dev) return EINVAL; 94 usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev);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 " %s\n",103 str_error(opResult));101 usb_log_error("could not initialize connection to device, " 102 "errno %d\n", 103 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, %s\n",112 str_error(opResult));111 usb_log_error("could not set hub configuration, errno %d\n", 112 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, %s\n",120 str_error(opResult));119 usb_log_error("could process hub specific info, errno %d\n", 120 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 141 142 142 143 /** Callback for polling hub for changes. … … 192 193 * @return basic usb_hub_info_t structure 193 194 */ 194 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {195 usb_hub_info_t * result = malloc(sizeof 195 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 196 usb_hub_info_t * result = malloc(sizeof(usb_hub_info_t)); 196 197 if (!result) return NULL; 197 198 result->usb_device = usb_dev; … … 201 202 202 203 result->ports = NULL; 203 result->port_count = (size_t) - 204 result->port_count = (size_t) -1; 204 205 fibril_mutex_initialize(&result->port_mutex); 205 206 … … 220 221 * @return error code 221 222 */ 222 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {223 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) { 223 224 // get hub descriptor 224 usb_log_debug(" Creating serialized descriptor\n");225 usb_log_debug("creating serialized descriptor\n"); 225 226 uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE]; 226 227 usb_hub_descriptor_t * descriptor; … … 234 235 235 236 if (opResult != EOK) { 236 usb_log_error(" Failed when receiving hub descriptor, "237 " %s\n",238 str_error(opResult));237 usb_log_error("failed when receiving hub descriptor, " 238 "badcode = %d\n", 239 opResult); 239 240 free(serialized_descriptor); 240 241 return opResult; 241 242 } 242 usb_log_debug2(" Deserializing descriptor\n");243 usb_log_debug2("deserializing descriptor\n"); 243 244 descriptor = usb_create_deserialized_hub_desriptor( 244 245 serialized_descriptor); … … 251 252 /// \TODO this is not semantically correct 252 253 bool is_power_switched = 253 ((descriptor->hub_characteristics & 1) == 254 ((descriptor->hub_characteristics & 1) ==0); 254 255 bool has_individual_port_powering = 255 ((descriptor->hub_characteristics & 1) != 256 ((descriptor->hub_characteristics & 1) !=0); 256 257 hub_info->ports = malloc( 257 258 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 258 if (!hub_info->ports){259 if(!hub_info->ports){ 259 260 return ENOMEM; 260 261 } … … 263 264 usb_hub_port_init(&hub_info->ports[port]); 264 265 } 265 if (is_power_switched){266 usb_log_debug(" Hub powerswitched\n");267 268 if (!has_individual_port_powering){269 usb_log_debug(" Has_globalpowering\n");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"); 270 271 opResult = usb_hub_set_feature(hub_info->control_pipe, 271 272 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 272 273 if (opResult != EOK) { 273 usb_log_error(" Cannot power hub: %s\n",274 usb_log_error("cannot power hub: %s\n", 274 275 str_error(opResult)); 275 276 } … … 277 278 278 279 for (port = 1; port <= hub_info->port_count; ++port) { 279 usb_log_debug("Powering port %zu.\n", 280 usb_log_debug("Powering port %zu.\n",port); 280 281 opResult = usb_hub_set_port_feature(hub_info->control_pipe, 281 282 port, USB_HUB_FEATURE_PORT_POWER); … … 285 286 } 286 287 } 287 288 } else{289 usb_log_debug(" Power notswitched, not going to be powered\n");290 } 291 usb_log_debug2(" Freeing data\n");288 289 }else{ 290 usb_log_debug("!is_power_switched, not going to be powered\n"); 291 } 292 usb_log_debug2("freeing data\n"); 292 293 free(descriptor); 293 294 return EOK; … … 302 303 * @return error code 303 304 */ 304 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {305 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) { 305 306 //device descriptor 306 307 usb_standard_device_descriptor_t *std_descriptor 307 308 = &hub_info->usb_device->descriptors.device; 308 usb_log_debug(" Hub has %d configurations\n",309 usb_log_debug("hub has %d configurations\n", 309 310 std_descriptor->configuration_count); 310 311 if (std_descriptor->configuration_count < 1) { 311 usb_log_error(" There are no configurations available\n");312 usb_log_error("there are no configurations available\n"); 312 313 return EINVAL; 313 314 } … … 327 328 return opResult; 328 329 } 329 usb_log_debug("\t Used configuration %d\n",330 usb_log_debug("\tused configuration %d\n", 330 331 config_descriptor->configuration_number); 331 332 … … 342 343 * @return error code 343 344 */ 344 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){345 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){ 345 346 int rc; 346 347 … … 366 367 //********************************************* 367 368 369 368 370 /** 369 371 * process hub over current change … … 374 376 * @return error code 375 377 */ 376 static int usb_process_hub_over_current(usb_hub_info_t * hub_info,378 static int usb_process_hub_over_current(usb_hub_info_t * hub_info, 377 379 usb_hub_status_t status) { 378 380 int opResult; 379 if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)){381 if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){ 380 382 //poweroff all ports 381 383 unsigned int port; 382 for (port = 1; port <= hub_info->port_count; ++port){384 for(port = 1;port <= hub_info->port_count;++port){ 383 385 opResult = usb_hub_clear_port_feature( 384 hub_info->control_pipe, 386 hub_info->control_pipe,port, 385 387 USB_HUB_FEATURE_PORT_POWER); 386 388 if (opResult != EOK) { 387 389 usb_log_warning( 388 " Cannot power off port %d; %s\n",389 port, str_error(opResult));390 "cannot power off port %d; %d\n", 391 port, opResult); 390 392 } 391 393 } … … 393 395 //power all ports 394 396 unsigned int port; 395 for (port = 1; port <= hub_info->port_count; ++port){397 for(port = 1;port <= hub_info->port_count;++port){ 396 398 opResult = usb_hub_set_port_feature( 397 hub_info->control_pipe, 399 hub_info->control_pipe,port, 398 400 USB_HUB_FEATURE_PORT_POWER); 399 401 if (opResult != EOK) { 400 402 usb_log_warning( 401 " Cannot power off port %d; %s\n",402 port, str_error(opResult));403 "cannot power off port %d; %d\n", 404 port, opResult); 403 405 } 404 406 } … … 415 417 * @return error code 416 418 */ 417 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,419 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info, 418 420 usb_hub_status_t status) { 419 421 int opResult = EOK; 420 422 opResult = usb_hub_clear_feature(hub_info->control_pipe, 421 423 USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 422 if (opResult != EOK) {423 usb_log_error(" Cannnot clear hub power change flag: "424 "% s\n",425 str_error(opResult));424 if (opResult != EOK) { 425 usb_log_error("cannnot clear hub power change flag: " 426 "%d\n", 427 opResult); 426 428 } 427 429 return opResult; … … 435 437 * @param hub_info hub instance 436 438 */ 437 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {438 usb_log_debug(" Global interrupt on a hub\n");439 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) { 440 usb_log_debug("global interrupt on a hub\n"); 439 441 usb_pipe_t *pipe = hub_info->control_pipe; 440 442 int opResult; … … 453 455 ); 454 456 if (opResult != EOK) { 455 usb_log_error("Could not get hub status: %s\n", 456 str_error(opResult)); 457 usb_log_error("could not get hub status\n"); 457 458 return; 458 459 } 459 460 if (rcvd_size != sizeof (usb_port_status_t)) { 460 usb_log_error(" Received status has incorrect size\n");461 usb_log_error("received status has incorrect size\n"); 461 462 return; 462 463 } 463 464 //port reset 464 465 if ( 465 usb_hub_is_status(status, 16 +USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {466 usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) { 466 467 usb_process_hub_over_current(hub_info, status); 467 468 } 468 469 if ( 469 usb_hub_is_status(status, 16 +USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {470 usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) { 470 471 usb_process_hub_local_power_change(hub_info, status); 471 472 } … … 480 481 * @param data pointer to usb_hub_info_t structure 481 482 */ 482 static void usb_hub_polling_terminated_callback(usb_device_t * device,483 bool was_error, void * data){483 static void usb_hub_polling_terminated_callback(usb_device_t * device, 484 bool was_error, void * data){ 484 485 usb_hub_info_t * hub = data; 485 486 assert(hub); … … 515 516 fibril_mutex_unlock(&hub->pending_ops_mutex); 516 517 518 usb_device_destroy(hub->usb_device); 519 517 520 free(hub->ports); 518 521 free(hub);
Note:
See TracChangeset
for help on using the changeset viewer.