Changeset c85804f in mainline
- Timestamp:
- 2011-07-11T11:02:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 062b25f
- Parents:
- ece7f78
- Location:
- uspace/drv/bus/usb/ohci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/ohci_regs.h
rece7f78 rc85804f 159 159 #define RHDA_DT_FLAG (1 << 10) /* 1-Compound device, must be 0 */ 160 160 #define RHDA_OCPM_FLAG (1 << 11) /* Over-current mode: 0-global, 1-per port */ 161 #define RHDA_NOCP 161 #define RHDA_NOCP_FLAG (1 << 12) /* OC control: 0-use OCPM, 1-OC off */ 162 162 #define RHDA_POTPGT_MASK (0xff) /* Power on to power good time */ 163 163 #define RHDA_POTPGT_SHIFT (24) -
uspace/drv/bus/usb/ohci/root_hub.c
rece7f78 rc85804f 231 231 instance->port_count = 232 232 (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK; 233 if ( port_count > 15) {233 if (instance->port_count > 15) { 234 234 usb_log_error("OHCI specification does not allow more than 15" 235 235 " ports. Max 15 ports will be used"); … … 241 241 return ret; 242 242 } 243 /* Set port power mode to no-power-switching. */244 instance->registers->rh_desc_a |= RHDA_NPS_FLAG;245 instance->unfinished_interrupt_transfer = NULL;246 243 /* Don't forget the hub status bit and round up */ 247 244 instance->interrupt_mask_size = (instance->port_count + 1 + 8) / 8; 248 245 instance->interrupt_buffer[0] = 0; 249 246 instance->interrupt_buffer[1] = 0; 247 instance->unfinished_interrupt_transfer = NULL; 248 249 /* Set port power mode to no-power-switching. */ 250 instance->registers->rh_desc_a |= RHDA_NPS_FLAG; 250 251 251 252 usb_log_info("Root hub (%zu ports) initialized.\n", … … 313 314 /*----------------------------------------------------------------------------*/ 314 315 /** 315 * Create hub descriptor used in hub-driver <-> hub communication 316 * 317 * This means creating bit array from data in root hub registers. For more 318 * info see usb hub specification. 316 * Create hub descriptor. 317 * 318 * For descriptor format see USB hub specification (chapter 11.15.2.1, pg. 263) 319 319 * 320 320 * @param instance Root hub instance … … 325 325 assert(instance); 326 326 327 const size_t size = 7 + 328 ((instance->port_count + 7) / 8) * 2; 329 uint8_t * result = malloc(size); 327 const size_t bit_field_size = (instance->port_count + 1 + 7) / 8; 328 assert(bit_field_size == 2 || bit_field_size == 1); 329 /* 7 bytes + 2 port bit fields (port count + global bit) */ 330 const size_t size = 7 + (bit_field_size * 2); 331 332 uint8_t *result = malloc(size); 330 333 if (!result) 331 334 return ENOMEM; 332 335 333 bzero(result, size); 334 //size 336 /* bDescLength */ 335 337 result[0] = size; 336 / /descriptor type338 /* bDescriptorType */ 337 339 result[1] = USB_DESCTYPE_HUB; 340 /* bNmbrPorts */ 338 341 result[2] = instance->port_count; 339 const uint32_t hub_desc_reg = instance->registers->rh_desc_a; 340 result[3] = 341 ((hub_desc_reg >> 8) % 2) + 342 (((hub_desc_reg >> 9) % 2) << 1) + 343 (((hub_desc_reg >> 10) % 2) << 2) + 344 (((hub_desc_reg >> 11) % 2) << 3) + 345 (((hub_desc_reg >> 12) % 2) << 4); 342 const uint32_t hub_desc = instance->registers->rh_desc_a; 343 /* wHubCharacteristics */ 344 result[3] = 0 | 345 /* The lowest 2 bits indicate power switching mode */ 346 (((hub_desc & RHDA_PSM_FLAG) ? 1 : 0) << 0) | 347 (((hub_desc & RHDA_NPS_FLAG) ? 1 : 0) << 1) | 348 /* Bit 3 indicates device type (compound device) */ 349 (((hub_desc & RHDA_DT_FLAG) ? 1 : 0) << 2) | 350 /* Bits 4,5 indicate over-current protection mode */ 351 (((hub_desc & RHDA_OCPM_FLAG) ? 1 : 0) << 3) | 352 (((hub_desc & RHDA_NOCP_FLAG) ? 1 : 0) << 4); 353 354 /* Reserved */ 346 355 result[4] = 0; 347 result[5] = 50; /*descriptor->pwr_on_2_good_time*/ 348 result[6] = 50; 349 350 size_t port = 1; 351 for (; port <= instance->port_count; ++port) { 352 const uint8_t is_non_removable = 353 instance->registers->rh_desc_b >> port % 2; 354 result[7 + port / 8] += 355 is_non_removable << (port % 8); 356 } 357 const size_t var_size = (instance->port_count + 7) / 8; 358 size_t i = 0; 359 for (; i < var_size; ++i) { 360 result[7 + var_size + i] = 255; 356 /* bPwrOn2PwrGood */ 357 result[5] = (hub_desc >> RHDA_POTPGT_SHIFT) & RHDA_POTPGT_MASK; 358 /* bHubContrCurrent, root hubs don't need no power. */ 359 result[6] = 0; 360 361 const uint32_t port_desc = instance->registers->rh_desc_a; 362 /* Device Removable and some legacy 1.0 stuff*/ 363 result[7] = (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK & 0xff; 364 result[8] = 0xff; 365 if (bit_field_size == 2) { 366 result[8] = (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK >> 8; 367 result[9] = 0xff; 368 result[10] = 0xff; 361 369 } 362 370 instance->hub_descriptor = result; … … 378 386 379 387 memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor, 380 sizeof (ohci_rh_device_descriptor)381 ); 388 sizeof(ohci_rh_device_descriptor)); 389 382 390 usb_standard_configuration_descriptor_t descriptor; 383 391 memcpy(&descriptor, &ohci_rh_conf_descriptor, 384 sizeof 392 sizeof(ohci_rh_conf_descriptor)); 385 393 386 394 int opResult = create_serialized_hub_descriptor(instance); 387 if (opResult != EOK) {395 if (opResult != EOK) 388 396 return opResult; 389 } 397 390 398 descriptor.total_length = 391 sizeof 392 sizeof 393 sizeof 399 sizeof(usb_standard_configuration_descriptor_t) + 400 sizeof(usb_standard_endpoint_descriptor_t) + 401 sizeof(usb_standard_interface_descriptor_t) + 394 402 instance->descriptor_size; 395 403 396 uint8_t * 397 if (!full_config_descriptor) {404 uint8_t *full_config_descriptor = malloc(descriptor.total_length); 405 if (!full_config_descriptor) 398 406 return ENOMEM; 399 } 400 memcpy(full_config_descriptor, &descriptor, sizeof (descriptor)); 401 memcpy(full_config_descriptor + sizeof (descriptor), 402 &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor)); 403 memcpy(full_config_descriptor + sizeof (descriptor) + 404 sizeof (ohci_rh_iface_descriptor), 405 &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor)); 406 memcpy(full_config_descriptor + sizeof (descriptor) + 407 sizeof (ohci_rh_iface_descriptor) + 408 sizeof (ohci_rh_ep_descriptor), 409 instance->hub_descriptor, instance->descriptor_size); 407 408 uint8_t *place = full_config_descriptor; 409 memcpy(place, &descriptor, sizeof(descriptor)); 410 411 place += sizeof(descriptor); 412 memcpy(place, &ohci_rh_iface_descriptor, 413 sizeof(ohci_rh_iface_descriptor)); 414 415 place += sizeof(ohci_rh_iface_descriptor); 416 memcpy(place, &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor)); 417 418 place += sizeof(ohci_rh_iface_descriptor); 419 memcpy(place, instance->hub_descriptor, instance->descriptor_size); 410 420 411 421 instance->descriptors.configuration = full_config_descriptor; -
uspace/drv/bus/usb/ohci/root_hub.h
rece7f78 rc85804f 55 55 /** interrupt transfer waiting for an actual interrupt to occur */ 56 56 usb_transfer_batch_t * unfinished_interrupt_transfer; 57 /** pre-allocated interrupt mask57 /** Interrupt mask of changes 58 58 * 59 59 * OHCI support max 15 ports (specs page 124) + one global bit, it
Note:
See TracChangeset
for help on using the changeset viewer.