Changeset 5da18c7 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-05-30T18:41:16Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
109d55c
Parents:
a2a3763 (diff), 8c74d15 (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 development/ changes

File:
1 edited

Legend:

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

    ra2a3763 r5da18c7  
    5656
    5757
    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,
     58static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
     59
     60static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
     61
     62static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
     63
     64static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info);
     65
     66static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    6767    usb_hub_status_t status);
    6868
    69 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
     69static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
    7070    usb_hub_status_t status);
    7171
    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);
     72static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info);
     73
     74static void usb_hub_polling_terminated_callback(usb_device_t *device,
     75    bool was_error, void *data);
    7676
    7777
     
    9090 * @return error code
    9191 */
    92 int usb_hub_add_device(usb_device_t * usb_dev) {
     92int usb_hub_add_device(usb_device_t *usb_dev) {
    9393        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);
    9595        //create hc connection
    9696        usb_log_debug("Initializing USB wire abstraction.\n");
     
    9999            hub_info->usb_device->ddf_dev);
    100100        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));
    104104                free(hub_info);
    105105                return opResult;
     
    109109        opResult = usb_hub_set_configuration(hub_info);
    110110        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));
    113113                free(hub_info);
    114114                return opResult;
     
    117117        opResult = usb_hub_process_hub_specific_info(hub_info);
    118118        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));
    121121                free(hub_info);
    122122                return opResult;
     
    135135
    136136        opResult = usb_hub_start_hub_fibril(hub_info);
    137         if(opResult!=EOK)
     137        if (opResult != EOK)
    138138                free(hub_info);
    139139        return opResult;
    140140}
    141 
    142141
    143142/** Callback for polling hub for changes.
     
    193192 * @return basic usb_hub_info_t structure
    194193 */
    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));
     194static 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));
    197196        if (!result) return NULL;
    198197        result->usb_device = usb_dev;
     
    202201
    203202        result->ports = NULL;
    204         result->port_count = (size_t) -1;
     203        result->port_count = (size_t) - 1;
    205204        fibril_mutex_initialize(&result->port_mutex);
    206205
     
    221220 * @return error code
    222221 */
    223 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {
     222static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info) {
    224223        // get hub descriptor
    225         usb_log_debug("creating serialized descriptor\n");
     224        usb_log_debug("Creating serialized descriptor\n");
    226225        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
    227226        usb_hub_descriptor_t * descriptor;
     
    235234
    236235        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));
    240239                free(serialized_descriptor);
    241240                return opResult;
    242241        }
    243         usb_log_debug2("deserializing descriptor\n");
     242        usb_log_debug2("Deserializing descriptor\n");
    244243        descriptor = usb_create_deserialized_hub_desriptor(
    245244            serialized_descriptor);
     
    250249        usb_log_debug("setting port count to %d\n", descriptor->ports_count);
    251250        hub_info->port_count = descriptor->ports_count;
    252         /// \TODO this is not semantically correct
    253251        bool is_power_switched =
    254             ((descriptor->hub_characteristics & 1) ==0);
     252            ((descriptor->hub_characteristics & 1) == 0);
    255253        bool has_individual_port_powering =
    256             ((descriptor->hub_characteristics & 1) !=0);
     254            ((descriptor->hub_characteristics & 1) != 0);
    257255        hub_info->ports = malloc(
    258256            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
    259         if(!hub_info->ports){
     257        if (!hub_info->ports) {
    260258                return ENOMEM;
    261259        }
     
    264262                usb_hub_port_init(&hub_info->ports[port]);
    265263        }
    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");
     264        if (is_power_switched) {
     265                usb_log_debug("Hub power switched\n");
     266
     267                if (!has_individual_port_powering) {
     268                        usb_log_debug("Has_global powering\n");
    271269                        opResult = usb_hub_set_feature(hub_info->control_pipe,
    272270                            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    273271                        if (opResult != EOK) {
    274                                 usb_log_error("cannot power hub: %s\n",
     272                                usb_log_error("Cannot power hub: %s\n",
    275273                                    str_error(opResult));
    276274                        }
     
    278276
    279277                for (port = 1; port <= hub_info->port_count; ++port) {
    280                         usb_log_debug("Powering port %zu.\n",port);
     278                        usb_log_debug("Powering port %zu.\n", port);
    281279                        opResult = usb_hub_set_port_feature(hub_info->control_pipe,
    282280                            port, USB_HUB_FEATURE_PORT_POWER);
     
    286284                        }
    287285                }
    288                
    289         }else{
    290                 usb_log_debug("!is_power_switched, not going to be powered\n");
    291         }
    292         usb_log_debug2("freeing data\n");
     286
     287        } else {
     288                usb_log_debug("Power not switched, not going to be powered\n");
     289        }
     290        usb_log_debug2("Freeing data\n");
    293291        free(descriptor);
    294292        return EOK;
     
    303301 * @return error code
    304302 */
    305 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {
     303static int usb_hub_set_configuration(usb_hub_info_t *hub_info) {
    306304        //device descriptor
    307305        usb_standard_device_descriptor_t *std_descriptor
    308306            = &hub_info->usb_device->descriptors.device;
    309         usb_log_debug("hub has %d configurations\n",
     307        usb_log_debug("Hub has %d configurations\n",
    310308            std_descriptor->configuration_count);
    311309        if (std_descriptor->configuration_count < 1) {
    312                 usb_log_error("there are no configurations available\n");
     310                usb_log_error("There are no configurations available\n");
    313311                return EINVAL;
    314312        }
     
    328326                return opResult;
    329327        }
    330         usb_log_debug("\tused configuration %d\n",
     328        usb_log_debug("\tUsed configuration %d\n",
    331329            config_descriptor->configuration_number);
    332330
     
    343341 * @return error code
    344342 */
    345 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
     343static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
    346344        int rc;
    347345
     
    367365//*********************************************
    368366
    369 
    370367/**
    371368 * process hub over current change
     
    376373 * @return error code
    377374 */
    378 static int usb_process_hub_over_current(usb_hub_info_t * hub_info,
     375static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    379376    usb_hub_status_t status) {
    380377        int opResult;
    381         if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
     378        if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) {
    382379                //poweroff all ports
    383380                unsigned int port;
    384                 for(port = 1;port <= hub_info->port_count;++port){
     381                for (port = 1; port <= hub_info->port_count; ++port) {
    385382                        opResult = usb_hub_clear_port_feature(
    386                             hub_info->control_pipe,port,
     383                            hub_info->control_pipe, port,
    387384                            USB_HUB_FEATURE_PORT_POWER);
    388385                        if (opResult != EOK) {
    389386                                usb_log_warning(
    390                                     "cannot power off port %d;  %d\n",
    391                                     port, opResult);
     387                                    "Cannot power off port %d;  %s\n",
     388                                    port, str_error(opResult));
    392389                        }
    393390                }
     
    395392                //power all ports
    396393                unsigned int port;
    397                 for(port = 1;port <= hub_info->port_count;++port){
     394                for (port = 1; port <= hub_info->port_count; ++port) {
    398395                        opResult = usb_hub_set_port_feature(
    399                             hub_info->control_pipe,port,
     396                            hub_info->control_pipe, port,
    400397                            USB_HUB_FEATURE_PORT_POWER);
    401398                        if (opResult != EOK) {
    402399                                usb_log_warning(
    403                                     "cannot power off port %d;  %d\n",
    404                                     port, opResult);
     400                                    "Cannot power off port %d;  %s\n",
     401                                    port, str_error(opResult));
    405402                        }
    406403                }
     
    417414 * @return error code
    418415 */
    419 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
     416static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
    420417    usb_hub_status_t status) {
    421418        int opResult = EOK;
    422419        opResult = usb_hub_clear_feature(hub_info->control_pipe,
    423420            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    424                 if (opResult != EOK) {
    425                 usb_log_error("cannnot clear hub power change flag: "
    426                     "%d\n",
    427                     opResult);
     421        if (opResult != EOK) {
     422                usb_log_error("Cannnot clear hub power change flag: "
     423                    "%s\n",
     424                    str_error(opResult));
    428425        }
    429426        return opResult;
     
    437434 * @param hub_info hub instance
    438435 */
    439 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {
    440         usb_log_debug("global interrupt on a hub\n");
     436static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) {
     437        usb_log_debug("Global interrupt on a hub\n");
    441438        usb_pipe_t *pipe = hub_info->control_pipe;
    442439        int opResult;
     
    455452            );
    456453        if (opResult != EOK) {
    457                 usb_log_error("could not get hub status\n");
     454                usb_log_error("Could not get hub status: %s\n",
     455                    str_error(opResult));
    458456                return;
    459457        }
    460458        if (rcvd_size != sizeof (usb_port_status_t)) {
    461                 usb_log_error("received status has incorrect size\n");
     459                usb_log_error("Received status has incorrect size\n");
    462460                return;
    463461        }
    464462        //port reset
    465463        if (
    466             usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     464            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
    467465                usb_process_hub_over_current(hub_info, status);
    468466        }
    469467        if (
    470             usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     468            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
    471469                usb_process_hub_local_power_change(hub_info, status);
    472470        }
     
    481479 * @param data pointer to usb_hub_info_t structure
    482480 */
    483 static void usb_hub_polling_terminated_callback(usb_device_t * device,
    484     bool was_error, void * data){
     481static void usb_hub_polling_terminated_callback(usb_device_t *device,
     482    bool was_error, void *data) {
    485483        usb_hub_info_t * hub = data;
    486484        assert(hub);
Note: See TracChangeset for help on using the changeset viewer.