Changeset 6c69d19 in mainline for uspace/drv/bus/usb/usbhub/usbhub.c


Ignore:
Timestamp:
2011-07-25T20:34:17Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00c2de63, c936c7f
Parents:
5889fc74 (diff), d542aad (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.
Message:

Merge libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r5889fc74 r6c69d19  
    220220 * @return error code
    221221 */
    222 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info) {
     222int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
     223{
    223224        // get hub descriptor
    224         usb_log_debug("Creating serialized descriptor\n");
     225        usb_log_debug("Retrieving descriptor\n");
    225226        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
    226         usb_hub_descriptor_t * descriptor;
    227227        int opResult;
    228228
     
    234234
    235235        if (opResult != EOK) {
    236                 usb_log_error("Failed when receiving hub descriptor, "
    237                     "%s\n",
    238                     str_error(opResult));
    239                 free(serialized_descriptor);
     236                usb_log_error("Failed to receive hub descriptor: %s.\n",
     237                    str_error(opResult));
    240238                return opResult;
    241239        }
    242         usb_log_debug2("Deserializing descriptor\n");
    243         descriptor = usb_create_deserialized_hub_desriptor(
    244             serialized_descriptor);
    245         if (descriptor == NULL) {
    246                 usb_log_warning("could not deserialize descriptor \n");
    247                 return ENOMEM;
    248         }
    249         usb_log_debug("setting port count to %d\n", descriptor->ports_count);
    250         hub_info->port_count = descriptor->ports_count;
    251         bool is_power_switched =
    252             ((descriptor->hub_characteristics & 1) == 0);
    253         bool has_individual_port_powering =
    254             ((descriptor->hub_characteristics & 1) != 0);
    255         hub_info->ports = malloc(
    256             sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
     240        usb_log_debug2("Parsing descriptor\n");
     241        usb_hub_descriptor_t descriptor;
     242        opResult = usb_deserialize_hub_desriptor(
     243                serialized_descriptor, received_size, &descriptor);
     244        if (opResult != EOK) {
     245                usb_log_error("Could not parse descriptor: %s\n",
     246                    str_error(opResult));
     247                return opResult;
     248        }
     249        usb_log_debug("Setting port count to %d.\n", descriptor.ports_count);
     250        hub_info->port_count = descriptor.ports_count;
     251
     252        hub_info->ports =
     253            malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
    257254        if (!hub_info->ports) {
    258255                return ENOMEM;
    259256        }
     257
    260258        size_t port;
    261259        for (port = 0; port < hub_info->port_count + 1; ++port) {
    262260                usb_hub_port_init(&hub_info->ports[port]);
    263261        }
     262
     263        const bool is_power_switched =
     264            !(descriptor.hub_characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
    264265        if (is_power_switched) {
    265266                usb_log_debug("Hub power switched\n");
    266 
    267                 if (!has_individual_port_powering) {
    268                         //this setting actually makes no difference
    269                         usb_log_debug("Hub has global powering\n");
    270                 }
     267                const bool per_port_power = descriptor.hub_characteristics
     268                    & HUB_CHAR_POWER_PER_PORT_FLAG;
    271269
    272270                for (port = 1; port <= hub_info->port_count; ++port) {
    273271                        usb_log_debug("Powering port %zu.\n", port);
    274                         opResult = usb_hub_set_port_feature(hub_info->control_pipe,
     272                        opResult = usb_hub_set_port_feature(
     273                            hub_info->control_pipe,
    275274                            port, USB_HUB_FEATURE_PORT_POWER);
    276275                        if (opResult != EOK) {
    277276                                usb_log_error("Cannot power on port %zu: %s.\n",
    278277                                    port, str_error(opResult));
     278                        } else {
     279                                if (!per_port_power) {
     280                                        usb_log_debug(
     281                                            "Ganged power switching mode, "
     282                                            "one port is enough.\n");
     283                                        break;
     284                                }
    279285                        }
    280286                }
     
    283289                usb_log_debug("Power not switched, not going to be powered\n");
    284290        }
    285         usb_log_debug2("Freeing data\n");
    286         free(descriptor);
    287291        return EOK;
    288292}
Note: See TracChangeset for help on using the changeset viewer.