Ignore:
File:
1 edited

Legend:

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

    r6ab7f3e9 r3ef91c88  
    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                     " %s\n",
    103                     str_error(opResult));
     101                usb_log_error("could not initialize connection to device, "
     102                    "errno %d\n",
     103                    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, %s\n",
    112                     str_error(opResult));
     111                usb_log_error("could not set hub configuration, errno %d\n",
     112                    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, %s\n",
    120                     str_error(opResult));
     119                usb_log_error("could process hub specific info, errno %d\n",
     120                    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
    141142
    142143/** Callback for polling hub for changes.
     
    192193 * @return basic usb_hub_info_t structure
    193194 */
    194 static 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));
     195static 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));
    196197        if (!result) return NULL;
    197198        result->usb_device = usb_dev;
     
    201202
    202203        result->ports = NULL;
    203         result->port_count = (size_t) - 1;
     204        result->port_count = (size_t) -1;
    204205        fibril_mutex_initialize(&result->port_mutex);
    205206
     
    220221 * @return error code
    221222 */
    222 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info) {
     223static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {
    223224        // get hub descriptor
    224         usb_log_debug("Creating serialized descriptor\n");
     225        usb_log_debug("creating serialized descriptor\n");
    225226        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
    226227        usb_hub_descriptor_t * descriptor;
     
    234235
    235236        if (opResult != EOK) {
    236                 usb_log_error("Failed when receiving hub descriptor, "
    237                     "%s\n",
    238                     str_error(opResult));
     237                usb_log_error("failed when receiving hub descriptor, "
     238                    "badcode = %d\n",
     239                    opResult);
    239240                free(serialized_descriptor);
    240241                return opResult;
    241242        }
    242         usb_log_debug2("Deserializing descriptor\n");
     243        usb_log_debug2("deserializing descriptor\n");
    243244        descriptor = usb_create_deserialized_hub_desriptor(
    244245            serialized_descriptor);
     
    251252        /// \TODO this is not semantically correct
    252253        bool is_power_switched =
    253             ((descriptor->hub_characteristics & 1) == 0);
     254            ((descriptor->hub_characteristics & 1) ==0);
    254255        bool has_individual_port_powering =
    255             ((descriptor->hub_characteristics & 1) != 0);
     256            ((descriptor->hub_characteristics & 1) !=0);
    256257        hub_info->ports = malloc(
    257258            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
    258         if (!hub_info->ports) {
     259        if(!hub_info->ports){
    259260                return ENOMEM;
    260261        }
     
    263264                usb_hub_port_init(&hub_info->ports[port]);
    264265        }
    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");
     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");
    270271                        opResult = usb_hub_set_feature(hub_info->control_pipe,
    271272                            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    272273                        if (opResult != EOK) {
    273                                 usb_log_error("Cannot power hub: %s\n",
     274                                usb_log_error("cannot power hub: %s\n",
    274275                                    str_error(opResult));
    275276                        }
     
    277278
    278279                for (port = 1; port <= hub_info->port_count; ++port) {
    279                         usb_log_debug("Powering port %zu.\n", port);
     280                        usb_log_debug("Powering port %zu.\n",port);
    280281                        opResult = usb_hub_set_port_feature(hub_info->control_pipe,
    281282                            port, USB_HUB_FEATURE_PORT_POWER);
     
    285286                        }
    286287                }
    287 
    288         } else {
    289                 usb_log_debug("Power not switched, not going to be powered\n");
    290         }
    291         usb_log_debug2("Freeing data\n");
     288               
     289        }else{
     290                usb_log_debug("!is_power_switched, not going to be powered\n");
     291        }
     292        usb_log_debug2("freeing data\n");
    292293        free(descriptor);
    293294        return EOK;
     
    302303 * @return error code
    303304 */
    304 static int usb_hub_set_configuration(usb_hub_info_t *hub_info) {
     305static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {
    305306        //device descriptor
    306307        usb_standard_device_descriptor_t *std_descriptor
    307308            = &hub_info->usb_device->descriptors.device;
    308         usb_log_debug("Hub has %d configurations\n",
     309        usb_log_debug("hub has %d configurations\n",
    309310            std_descriptor->configuration_count);
    310311        if (std_descriptor->configuration_count < 1) {
    311                 usb_log_error("There are no configurations available\n");
     312                usb_log_error("there are no configurations available\n");
    312313                return EINVAL;
    313314        }
     
    327328                return opResult;
    328329        }
    329         usb_log_debug("\tUsed configuration %d\n",
     330        usb_log_debug("\tused configuration %d\n",
    330331            config_descriptor->configuration_number);
    331332
     
    342343 * @return error code
    343344 */
    344 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
     345static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
    345346        int rc;
    346347
     
    366367//*********************************************
    367368
     369
    368370/**
    369371 * process hub over current change
     
    374376 * @return error code
    375377 */
    376 static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
     378static int usb_process_hub_over_current(usb_hub_info_t * hub_info,
    377379    usb_hub_status_t status) {
    378380        int opResult;
    379         if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) {
     381        if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
    380382                //poweroff all ports
    381383                unsigned int port;
    382                 for (port = 1; port <= hub_info->port_count; ++port) {
     384                for(port = 1;port <= hub_info->port_count;++port){
    383385                        opResult = usb_hub_clear_port_feature(
    384                             hub_info->control_pipe, port,
     386                            hub_info->control_pipe,port,
    385387                            USB_HUB_FEATURE_PORT_POWER);
    386388                        if (opResult != EOK) {
    387389                                usb_log_warning(
    388                                     "Cannot power off port %d;  %s\n",
    389                                     port, str_error(opResult));
     390                                    "cannot power off port %d;  %d\n",
     391                                    port, opResult);
    390392                        }
    391393                }
     
    393395                //power all ports
    394396                unsigned int port;
    395                 for (port = 1; port <= hub_info->port_count; ++port) {
     397                for(port = 1;port <= hub_info->port_count;++port){
    396398                        opResult = usb_hub_set_port_feature(
    397                             hub_info->control_pipe, port,
     399                            hub_info->control_pipe,port,
    398400                            USB_HUB_FEATURE_PORT_POWER);
    399401                        if (opResult != EOK) {
    400402                                usb_log_warning(
    401                                     "Cannot power off port %d;  %s\n",
    402                                     port, str_error(opResult));
     403                                    "cannot power off port %d;  %d\n",
     404                                    port, opResult);
    403405                        }
    404406                }
     
    415417 * @return error code
    416418 */
    417 static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
     419static int usb_process_hub_local_power_change(usb_hub_info_t * hub_info,
    418420    usb_hub_status_t status) {
    419421        int opResult = EOK;
    420422        opResult = usb_hub_clear_feature(hub_info->control_pipe,
    421423            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    422         if (opResult != EOK) {
    423                 usb_log_error("Cannnot clear hub power change flag: "
    424                     "%s\n",
    425                     str_error(opResult));
     424                if (opResult != EOK) {
     425                usb_log_error("cannnot clear hub power change flag: "
     426                    "%d\n",
     427                    opResult);
    426428        }
    427429        return opResult;
     
    435437 * @param hub_info hub instance
    436438 */
    437 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) {
    438         usb_log_debug("Global interrupt on a hub\n");
     439static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {
     440        usb_log_debug("global interrupt on a hub\n");
    439441        usb_pipe_t *pipe = hub_info->control_pipe;
    440442        int opResult;
     
    453455            );
    454456        if (opResult != EOK) {
    455                 usb_log_error("Could not get hub status: %s\n",
    456                     str_error(opResult));
     457                usb_log_error("could not get hub status\n");
    457458                return;
    458459        }
    459460        if (rcvd_size != sizeof (usb_port_status_t)) {
    460                 usb_log_error("Received status has incorrect size\n");
     461                usb_log_error("received status has incorrect size\n");
    461462                return;
    462463        }
    463464        //port reset
    464465        if (
    465             usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     466            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
    466467                usb_process_hub_over_current(hub_info, status);
    467468        }
    468469        if (
    469             usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     470            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
    470471                usb_process_hub_local_power_change(hub_info, status);
    471472        }
     
    480481 * @param data pointer to usb_hub_info_t structure
    481482 */
    482 static void usb_hub_polling_terminated_callback(usb_device_t *device,
    483     bool was_error, void *data) {
     483static void usb_hub_polling_terminated_callback(usb_device_t * device,
     484    bool was_error, void * data){
    484485        usb_hub_info_t * hub = data;
    485486        assert(hub);
     
    515516        fibril_mutex_unlock(&hub->pending_ops_mutex);
    516517
     518        usb_device_destroy(hub->usb_device);
     519
    517520        free(hub->ports);
    518521        free(hub);
Note: See TracChangeset for help on using the changeset viewer.