Changeset ea6de35 in mainline
- Timestamp:
- 2011-09-23T09:15:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 75eb6735
- Parents:
- bf73a02
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/usbhub.c
rbf73a02 rea6de35 69 69 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev); 70 70 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info); 71 static void usb_ process_hub_over_current(usb_hub_info_t *hub_info,71 static void usb_hub_over_current(const usb_hub_info_t *hub_info, 72 72 usb_hub_status_t status); 73 static void usb_hub_ process_global_interrupt(usb_hub_info_t *hub_info);73 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info); 74 74 static void usb_hub_polling_terminated_callback(usb_device_t *device, 75 75 bool was_error, void *data); 76 76 77 78 //*********************************************79 //80 // hub driver code, initialization81 //82 //*********************************************83 84 77 /** 85 78 * Initialize hub device driver fibril 86 79 * 87 * Creates hub representation and fibril that periodically checks hub `s status.80 * Creates hub representation and fibril that periodically checks hub's status. 88 81 * Hub representation is passed to the fibril. 89 82 * @param usb_dev generic usb device information … … 185 178 const bool change = change_bitmap[0] & 1; 186 179 if (change) { 187 usb_hub_ process_global_interrupt(hub);180 usb_hub_global_interrupt(hub); 188 181 } 189 182 … … 221 214 { 222 215 assert(usb_dev); 223 usb_hub_info_t * result= malloc(sizeof(usb_hub_info_t));224 if (! result)216 usb_hub_info_t *info = malloc(sizeof(usb_hub_info_t)); 217 if (!info) 225 218 return NULL; 226 219 227 result->usb_device = usb_dev;228 result->control_pipe = &usb_dev->ctrl_pipe;229 result->is_default_address_used = false;230 231 result->ports = NULL;232 result->port_count = -1;233 fibril_mutex_initialize(& result->port_mutex);234 fibril_mutex_initialize(& result->pending_ops_mutex);235 fibril_condvar_initialize(& result->pending_ops_cv);236 result->pending_ops_count = 0;237 238 return result;220 info->usb_device = usb_dev; 221 info->control_pipe = &usb_dev->ctrl_pipe; 222 info->is_default_address_used = false; 223 224 info->ports = NULL; 225 info->port_count = -1; 226 fibril_mutex_initialize(&info->port_mutex); 227 fibril_mutex_initialize(&info->pending_ops_mutex); 228 fibril_condvar_initialize(&info->pending_ops_cv); 229 info->pending_ops_count = 0; 230 231 return info; 239 232 } 240 233 … … 242 235 * Load hub-specific information into hub_info structure and process if needed 243 236 * 244 * Particularly read port count and initialize structure holding port245 * information. If there arenon-removable devices, start initializing them.237 * Read port count and initialize structures holding per port information. 238 * If there are any non-removable devices, start initializing them. 246 239 * This function is hub-specific and should be run only after the hub is 247 240 * configured using usb_set_first_configuration function. … … 252 245 { 253 246 assert(hub_info); 254 // get hub descriptor 247 248 /* Get hub descriptor. */ 255 249 usb_log_debug("Retrieving descriptor\n"); 256 250 uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE]; … … 322 316 return EOK; 323 317 } 324 318 /*----------------------------------------------------------------------------*/ 325 319 /** 326 320 * Set configuration of and USB device … … 350 344 351 345 /* Set configuration. Use the configuration that was in 352 * usb_device->descriptors.configuration */346 * usb_device->descriptors.configuration i.e. The first one. */ 353 347 const int opResult = usb_request_set_configuration( 354 348 &usb_device->ctrl_pipe, config_descriptor->configuration_number); … … 356 350 usb_log_error("Failed to set hub configuration: %s.\n", 357 351 str_error(opResult)); 358 return opResult; 359 } 360 usb_log_debug("\tUsed configuration %d\n", 361 config_descriptor->configuration_number); 362 363 return EOK; 364 } 365 366 //********************************************* 367 // 368 // change handling functions 369 // 370 //********************************************* 371 372 /** 373 * process hub over current change 352 } else { 353 usb_log_debug("\tUsed configuration %d\n", 354 config_descriptor->configuration_number); 355 } 356 return opResult; 357 } 358 /*----------------------------------------------------------------------------*/ 359 /** 360 * Process hub over current change 374 361 * 375 362 * This means either to power off the hub or power it on. … … 378 365 * @return error code 379 366 */ 380 static void usb_ process_hub_over_current(usb_hub_info_t *hub_info,367 static void usb_hub_over_current(const usb_hub_info_t *hub_info, 381 368 usb_hub_status_t status) 382 369 { … … 416 403 /*----------------------------------------------------------------------------*/ 417 404 /** 418 * process hub interrupts 419 * 420 * The change can be either in the over-current condition or 421 * local-power change. 405 * Process hub interrupts. 406 * 407 * The change can be either in the over-current condition or local-power change. 422 408 * @param hub_info hub instance 423 409 */ 424 static void usb_hub_ process_global_interrupt(usb_hub_info_t *hub_info)410 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info) 425 411 { 426 412 assert(hub_info); … … 428 414 usb_log_debug("Global interrupt on a hub\n"); 429 415 usb_pipe_t *ctrlpipe = &hub_info->usb_device->ctrl_pipe; 430 int opResult;431 416 432 417 usb_hub_status_t status; 433 418 size_t rcvd_size; 434 435 opResult = usb_pipe_control_read( 419 /* NOTE: We can't use standard USB GET_STATUS request, because 420 * hubs reply is 4byte instead of 2 */ 421 const int opResult = usb_pipe_control_read( 436 422 ctrlpipe, &get_hub_status_request, sizeof(get_hub_status_request), 437 423 &status, sizeof(usb_hub_status_t), &rcvd_size); … … 448 434 /* Handle status changes */ 449 435 if (status & USB_HUB_STATUS_C_OVER_CURRENT) 450 usb_ process_hub_over_current(hub_info, status);436 usb_hub_over_current(hub_info, status); 451 437 452 438 if (status & USB_HUB_STATUS_C_LOCAL_POWER) { … … 473 459 } 474 460 } 475 461 /*----------------------------------------------------------------------------*/ 476 462 /** 477 463 * callback called from hub polling fibril when the fibril terminates … … 483 469 */ 484 470 static void usb_hub_polling_terminated_callback(usb_device_t *device, 485 bool was_error, void *data) { 486 usb_hub_info_t * hub = data; 471 bool was_error, void *data) 472 { 473 usb_hub_info_t *hub = data; 487 474 assert(hub); 488 475 … … 522 509 free(hub); 523 510 } 524 525 526 527 528 511 /** 529 512 * @}
Note:
See TracChangeset
for help on using the changeset viewer.