Changeset ea6de35 in mainline


Ignore:
Timestamp:
2011-09-23T09:15:29Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
75eb6735
Parents:
bf73a02
Message:

usbhub: Refactoring

Add note about GET_STATUS request.
Make parameters const if possible.

File:
1 edited

Legend:

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

    rbf73a02 rea6de35  
    6969static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
    7070static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
    71 static void usb_process_hub_over_current(usb_hub_info_t *hub_info,
     71static void usb_hub_over_current(const usb_hub_info_t *hub_info,
    7272    usb_hub_status_t status);
    73 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info);
     73static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info);
    7474static void usb_hub_polling_terminated_callback(usb_device_t *device,
    7575    bool was_error, void *data);
    7676
    77 
    78 //*********************************************
    79 //
    80 //  hub driver code, initialization
    81 //
    82 //*********************************************
    83 
    8477/**
    8578 * Initialize hub device driver fibril
    8679 *
    87  * Creates hub representation and fibril that periodically checks hub`s status.
     80 * Creates hub representation and fibril that periodically checks hub's status.
    8881 * Hub representation is passed to the fibril.
    8982 * @param usb_dev generic usb device information
     
    185178        const bool change = change_bitmap[0] & 1;
    186179        if (change) {
    187                 usb_hub_process_global_interrupt(hub);
     180                usb_hub_global_interrupt(hub);
    188181        }
    189182
     
    221214{
    222215        assert(usb_dev);
    223         usb_hub_info_t *result = malloc(sizeof(usb_hub_info_t));
    224         if (!result)
     216        usb_hub_info_t *info = malloc(sizeof(usb_hub_info_t));
     217        if (!info)
    225218            return NULL;
    226219
    227         result->usb_device = usb_dev;
    228         result->control_pipe = &usb_dev->ctrl_pipe;
    229         result->is_default_address_used = false;
    230 
    231         result->ports = NULL;
    232         result->port_count = -1;
    233         fibril_mutex_initialize(&result->port_mutex);
    234         fibril_mutex_initialize(&result->pending_ops_mutex);
    235         fibril_condvar_initialize(&result->pending_ops_cv);
    236         result->pending_ops_count = 0;
    237 
    238         return result;
     220        info->usb_device = usb_dev;
     221        info->control_pipe = &usb_dev->ctrl_pipe;
     222        info->is_default_address_used = false;
     223
     224        info->ports = NULL;
     225        info->port_count = -1;
     226        fibril_mutex_initialize(&info->port_mutex);
     227        fibril_mutex_initialize(&info->pending_ops_mutex);
     228        fibril_condvar_initialize(&info->pending_ops_cv);
     229        info->pending_ops_count = 0;
     230
     231        return info;
    239232}
    240233
     
    242235 * Load hub-specific information into hub_info structure and process if needed
    243236 *
    244  * Particularly read port count and initialize structure holding port
    245  * information. If there are non-removable devices, start initializing them.
     237 * Read port count and initialize structures holding per port information.
     238 * If there are any non-removable devices, start initializing them.
    246239 * This function is hub-specific and should be run only after the hub is
    247240 * configured using usb_set_first_configuration function.
     
    252245{
    253246        assert(hub_info);
    254         // get hub descriptor
     247
     248        /* Get hub descriptor. */
    255249        usb_log_debug("Retrieving descriptor\n");
    256250        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
     
    322316        return EOK;
    323317}
    324 
     318/*----------------------------------------------------------------------------*/
    325319/**
    326320 * Set configuration of and USB device
     
    350344
    351345        /* Set configuration. Use the configuration that was in
    352          * usb_device->descriptors.configuration */
     346         * usb_device->descriptors.configuration i.e. The first one. */
    353347        const int opResult = usb_request_set_configuration(
    354348            &usb_device->ctrl_pipe, config_descriptor->configuration_number);
     
    356350                usb_log_error("Failed to set hub configuration: %s.\n",
    357351                    str_error(opResult));
    358                 return opResult;
    359         }
    360         usb_log_debug("\tUsed configuration %d\n",
    361             config_descriptor->configuration_number);
    362 
    363         return EOK;
    364 }
    365 
    366 //*********************************************
    367 //
    368 //  change handling functions
    369 //
    370 //*********************************************
    371 
    372 /**
    373  * process hub over current change
     352        } else {
     353                usb_log_debug("\tUsed configuration %d\n",
     354                    config_descriptor->configuration_number);
     355        }
     356        return opResult;
     357}
     358/*----------------------------------------------------------------------------*/
     359/**
     360 * Process hub over current change
    374361 *
    375362 * This means either to power off the hub or power it on.
     
    378365 * @return error code
    379366 */
    380 static void usb_process_hub_over_current(usb_hub_info_t *hub_info,
     367static void usb_hub_over_current(const usb_hub_info_t *hub_info,
    381368    usb_hub_status_t status)
    382369{
     
    416403/*----------------------------------------------------------------------------*/
    417404/**
    418  * process hub interrupts
    419  *
    420  * The change can be either in the over-current condition or
    421  * local-power change.
     405 * Process hub interrupts.
     406 *
     407 * The change can be either in the over-current condition or local-power change.
    422408 * @param hub_info hub instance
    423409 */
    424 static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info)
     410static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info)
    425411{
    426412        assert(hub_info);
     
    428414        usb_log_debug("Global interrupt on a hub\n");
    429415        usb_pipe_t *ctrlpipe = &hub_info->usb_device->ctrl_pipe;
    430         int opResult;
    431416
    432417        usb_hub_status_t status;
    433418        size_t rcvd_size;
    434 
    435         opResult = usb_pipe_control_read(
     419        /* NOTE: We can't use standard USB GET_STATUS request, because
     420         * hubs reply is 4byte instead of 2 */
     421        const int opResult = usb_pipe_control_read(
    436422            ctrlpipe, &get_hub_status_request, sizeof(get_hub_status_request),
    437423            &status, sizeof(usb_hub_status_t), &rcvd_size);
     
    448434        /* Handle status changes */
    449435        if (status & USB_HUB_STATUS_C_OVER_CURRENT)
    450                 usb_process_hub_over_current(hub_info, status);
     436                usb_hub_over_current(hub_info, status);
    451437
    452438        if (status & USB_HUB_STATUS_C_LOCAL_POWER) {
     
    473459        }
    474460}
    475 
     461/*----------------------------------------------------------------------------*/
    476462/**
    477463 * callback called from hub polling fibril when the fibril terminates
     
    483469 */
    484470static void usb_hub_polling_terminated_callback(usb_device_t *device,
    485     bool was_error, void *data) {
    486         usb_hub_info_t * hub = data;
     471    bool was_error, void *data)
     472{
     473        usb_hub_info_t *hub = data;
    487474        assert(hub);
    488475
     
    522509        free(hub);
    523510}
    524 
    525 
    526 
    527 
    528511/**
    529512 * @}
Note: See TracChangeset for help on using the changeset viewer.