Changeset 95067954 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-05-29T21:59:22Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3dfdcb7
Parents:
bd7acda (diff), 98e15b1 (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:

code tiding

File:
1 edited

Legend:

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

    rbd7acda r95067954  
    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);
     
    252251        /// \TODO this is not semantically correct
    253252        bool is_power_switched =
    254             ((descriptor->hub_characteristics & 1) ==0);
     253            ((descriptor->hub_characteristics & 1) == 0);
    255254        bool has_individual_port_powering =
    256             ((descriptor->hub_characteristics & 1) !=0);
     255            ((descriptor->hub_characteristics & 1) != 0);
    257256        hub_info->ports = malloc(
    258257            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
    259         if(!hub_info->ports){
     258        if (!hub_info->ports) {
    260259                return ENOMEM;
    261260        }
     
    264263                usb_hub_port_init(&hub_info->ports[port]);
    265264        }
    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");
     265        if (is_power_switched) {
     266                usb_log_debug("Hub power switched\n");
     267
     268                if (!has_individual_port_powering) {
     269                        usb_log_debug("Has_global powering\n");
    271270                        opResult = usb_hub_set_feature(hub_info->control_pipe,
    272271                            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    273272                        if (opResult != EOK) {
    274                                 usb_log_error("cannot power hub: %s\n",
     273                                usb_log_error("Cannot power hub: %s\n",
    275274                                    str_error(opResult));
    276275                        }
     
    278277
    279278                for (port = 1; port <= hub_info->port_count; ++port) {
    280                         usb_log_debug("Powering port %zu.\n",port);
     279                        usb_log_debug("Powering port %zu.\n", port);
    281280                        opResult = usb_hub_set_port_feature(hub_info->control_pipe,
    282281                            port, USB_HUB_FEATURE_PORT_POWER);
     
    286285                        }
    287286                }
    288                
    289         }else{
    290                 usb_log_debug("!is_power_switched, not going to be powered\n");
    291         }
    292         usb_log_debug2("freeing data\n");
     287
     288        } else {
     289                usb_log_debug("Power not switched, not going to be powered\n");
     290        }
     291        usb_log_debug2("Freeing data\n");
    293292        free(descriptor);
    294293        return EOK;
     
    303302 * @return error code
    304303 */
    305 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {
     304static int usb_hub_set_configuration(usb_hub_info_t *hub_info) {
    306305        //device descriptor
    307306        usb_standard_device_descriptor_t *std_descriptor
    308307            = &hub_info->usb_device->descriptors.device;
    309         usb_log_debug("hub has %d configurations\n",
     308        usb_log_debug("Hub has %d configurations\n",
    310309            std_descriptor->configuration_count);
    311310        if (std_descriptor->configuration_count < 1) {
    312                 usb_log_error("there are no configurations available\n");
     311                usb_log_error("There are no configurations available\n");
    313312                return EINVAL;
    314313        }
     
    328327                return opResult;
    329328        }
    330         usb_log_debug("\tused configuration %d\n",
     329        usb_log_debug("\tUsed configuration %d\n",
    331330            config_descriptor->configuration_number);
    332331
     
    343342 * @return error code
    344343 */
    345 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
     344static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
    346345        int rc;
    347346
     
    367366//*********************************************
    368367
    369 
    370368/**
    371369 * process hub over current change
     
    376374 * @return error code
    377375 */
    378 static int usb_process_hub_over_current(usb_hub_info_t * hub_info,
     376static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    379377    usb_hub_status_t status) {
    380378        int opResult;
    381         if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
     379        if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) {
    382380                //poweroff all ports
    383381                unsigned int port;
    384                 for(port = 1;port <= hub_info->port_count;++port){
     382                for (port = 1; port <= hub_info->port_count; ++port) {
    385383                        opResult = usb_hub_clear_port_feature(
    386                             hub_info->control_pipe,port,
     384                            hub_info->control_pipe, port,
    387385                            USB_HUB_FEATURE_PORT_POWER);
    388386                        if (opResult != EOK) {
    389387                                usb_log_warning(
    390                                     "cannot power off port %d;  %d\n",
    391                                     port, opResult);
     388                                    "Cannot power off port %d;  %s\n",
     389                                    port, str_error(opResult));
    392390                        }
    393391                }
     
    395393                //power all ports
    396394                unsigned int port;
    397                 for(port = 1;port <= hub_info->port_count;++port){
     395                for (port = 1; port <= hub_info->port_count; ++port) {
    398396                        opResult = usb_hub_set_port_feature(
    399                             hub_info->control_pipe,port,
     397                            hub_info->control_pipe, port,
    400398                            USB_HUB_FEATURE_PORT_POWER);
    401399                        if (opResult != EOK) {
    402400                                usb_log_warning(
    403                                     "cannot power off port %d;  %d\n",
    404                                     port, opResult);
     401                                    "Cannot power off port %d;  %s\n",
     402                                    port, str_error(opResult));
    405403                        }
    406404                }
     
    417415 * @return error code
    418416 */
    419 static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
     417static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
    420418    usb_hub_status_t status) {
    421419        int opResult = EOK;
    422420        opResult = usb_hub_clear_feature(hub_info->control_pipe,
    423421            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);
     422        if (opResult != EOK) {
     423                usb_log_error("Cannnot clear hub power change flag: "
     424                    "%s\n",
     425                    str_error(opResult));
    428426        }
    429427        return opResult;
     
    437435 * @param hub_info hub instance
    438436 */
    439 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {
    440         usb_log_debug("global interrupt on a hub\n");
     437static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) {
     438        usb_log_debug("Global interrupt on a hub\n");
    441439        usb_pipe_t *pipe = hub_info->control_pipe;
    442440        int opResult;
     
    455453            );
    456454        if (opResult != EOK) {
    457                 usb_log_error("could not get hub status\n");
     455                usb_log_error("Could not get hub status: %s\n",
     456                    str_error(opResult));
    458457                return;
    459458        }
    460459        if (rcvd_size != sizeof (usb_port_status_t)) {
    461                 usb_log_error("received status has incorrect size\n");
     460                usb_log_error("Received status has incorrect size\n");
    462461                return;
    463462        }
    464463        //port reset
    465464        if (
    466             usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     465            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
    467466                usb_process_hub_over_current(hub_info, status);
    468467        }
    469468        if (
    470             usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     469            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
    471470                usb_process_hub_local_power_change(hub_info, status);
    472471        }
     
    481480 * @param data pointer to usb_hub_info_t structure
    482481 */
    483 static void usb_hub_polling_terminated_callback(usb_device_t * device,
    484     bool was_error, void * data){
     482static void usb_hub_polling_terminated_callback(usb_device_t *device,
     483    bool was_error, void *data) {
    485484        usb_hub_info_t * hub = data;
    486485        assert(hub);
Note: See TracChangeset for help on using the changeset viewer.