Changeset eda7a4e0 in mainline


Ignore:
Timestamp:
2011-10-13T11:43:23Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a14d6a7
Parents:
fb422312
Message:

usbhub: rename hub_info ⇒ hub_dev

File:
1 edited

Legend:

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

    rfb422312 reda7a4e0  
    6969static int usb_set_first_configuration(usb_device_t *usb_device);
    7070static usb_hub_dev_t * usb_hub_dev_create(usb_device_t *usb_dev);
    71 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_info);
    72 static void usb_hub_over_current(const usb_hub_dev_t *hub_info,
     71static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev);
     72static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
    7373    usb_hub_status_t status);
    74 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_info);
     74static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev);
    7575static void usb_hub_polling_terminated_callback(usb_device_t *device,
    7676    bool was_error, void *data);
     
    124124        assert(usb_dev);
    125125        /* Create driver soft-state structure */
    126         usb_hub_dev_t *hub_info = usb_hub_dev_create(usb_dev);
    127         if (hub_info == NULL) {
     126        usb_hub_dev_t *hub_dev = usb_hub_dev_create(usb_dev);
     127        if (hub_dev == NULL) {
    128128                usb_log_error("Failed to create hun driver structure.\n");
    129129                return ENOMEM;
     
    133133        usb_log_debug("Initializing USB wire abstraction.\n");
    134134        int opResult = usb_hc_connection_initialize_from_device(
    135             &hub_info->connection, hub_info->usb_device->ddf_dev);
     135            &hub_dev->connection, hub_dev->usb_device->ddf_dev);
    136136        if (opResult != EOK) {
    137137                usb_log_error("Could not initialize connection to device: %s\n",
    138138                    str_error(opResult));
    139                 free(hub_info);
     139                free(hub_dev);
    140140                return opResult;
    141141        }
     
    146146                usb_log_error("Could not set hub configuration: %s\n",
    147147                    str_error(opResult));
    148                 free(hub_info);
     148                free(hub_dev);
    149149                return opResult;
    150150        }
    151151
    152152        /* Get port count and create attached_devices. */
    153         opResult = usb_hub_process_hub_specific_info(hub_info);
     153        opResult = usb_hub_process_hub_specific_info(hub_dev);
    154154        if (opResult != EOK) {
    155155                usb_log_error("Could process hub specific info, %s\n",
    156156                    str_error(opResult));
    157                 free(hub_info);
     157                free(hub_dev);
    158158                return opResult;
    159159        }
    160160
    161161        usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
    162         hub_info->hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
     162        hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev,
    163163            fun_exposed, HUB_FNC_NAME);
    164         if (hub_info->hub_fun == NULL) {
     164        if (hub_dev->hub_fun == NULL) {
    165165                usb_log_error("Failed to create hub function.\n");
    166                 free(hub_info);
     166                free(hub_dev);
    167167                return ENOMEM;
    168168        }
    169169
    170         opResult = ddf_fun_bind(hub_info->hub_fun);
     170        opResult = ddf_fun_bind(hub_dev->hub_fun);
    171171        if (opResult != EOK) {
    172172                usb_log_error("Failed to bind hub function: %s.\n",
    173173                   str_error(opResult));
    174                 free(hub_info);
    175                 ddf_fun_destroy(hub_info->hub_fun);
     174                free(hub_dev);
     175                ddf_fun_destroy(hub_dev->hub_fun);
    176176                return opResult;
    177177        }
    178178
    179         opResult = usb_device_auto_poll(hub_info->usb_device, 0,
    180             hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
    181             usb_hub_polling_terminated_callback, hub_info);
     179        opResult = usb_device_auto_poll(hub_dev->usb_device, 0,
     180            hub_port_changes_callback, ((hub_dev->port_count + 1) / 8) + 1,
     181            usb_hub_polling_terminated_callback, hub_dev);
    182182        if (opResult != EOK) {
    183183                /* Function is already bound */
    184                 ddf_fun_unbind(hub_info->hub_fun);
    185                 ddf_fun_destroy(hub_info->hub_fun);
    186                 free(hub_info);
     184                ddf_fun_unbind(hub_dev->hub_fun);
     185                ddf_fun_destroy(hub_dev->hub_fun);
     186                free(hub_dev);
    187187                usb_log_error("Failed to create polling fibril: %s.\n",
    188188                    str_error(opResult));
    189189                return opResult;
    190190        }
    191         hub_info->running = true;
     191        hub_dev->running = true;
    192192        usb_log_info("Controlling hub '%s' (%zu ports).\n",
    193             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     193            hub_dev->usb_device->ddf_dev->name, hub_dev->port_count);
    194194
    195195        return EOK;
     
    243243{
    244244        assert(usb_dev);
    245         usb_hub_dev_t *info = malloc(sizeof(usb_hub_dev_t));
    246         if (!info)
     245        usb_hub_dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t));
     246        if (!hub_dev)
    247247            return NULL;
    248248
    249         info->usb_device = usb_dev;
    250 
    251         info->ports = NULL;
    252         info->port_count = -1;
    253         info->pending_ops_count = 0;
    254         info->running = false;
    255         fibril_mutex_initialize(&info->pending_ops_mutex);
    256         fibril_condvar_initialize(&info->pending_ops_cv);
    257         usb_dev->driver_data = info;
    258 
    259         return info;
    260 }
    261 /*----------------------------------------------------------------------------*/
    262 /**
    263  * Load hub-specific information into hub_info structure and process if needed
     249        hub_dev->usb_device = usb_dev;
     250
     251        hub_dev->ports = NULL;
     252        hub_dev->port_count = -1;
     253        hub_dev->pending_ops_count = 0;
     254        hub_dev->running = false;
     255        fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
     256        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
     257        usb_dev->driver_data = hub_dev;
     258
     259        return hub_dev;
     260}
     261/*----------------------------------------------------------------------------*/
     262/**
     263 * Load hub-specific information into hub_dev structure and process if needed
    264264 *
    265265 * Read port count and initialize structures holding per port information.
     
    267267 * This function is hub-specific and should be run only after the hub is
    268268 * configured using usb_set_first_configuration function.
    269  * @param hub_info hub representation
     269 * @param hub_dev hub representation
    270270 * @return error code
    271271 */
    272 static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_info)
    273 {
    274         assert(hub_info);
     272static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev)
     273{
     274        assert(hub_dev);
    275275
    276276        /* Get hub descriptor. */
    277277        usb_log_debug("Retrieving descriptor\n");
    278         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
     278        usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
    279279
    280280        usb_hub_descriptor_header_t descriptor;
     
    291291
    292292        usb_log_debug("Setting port count to %d.\n", descriptor.port_count);
    293         hub_info->port_count = descriptor.port_count;
     293        hub_dev->port_count = descriptor.port_count;
    294294
    295295        // TODO: +1 hack is no longer necessary
    296         hub_info->ports =
    297             calloc(hub_info->port_count + 1, sizeof(usb_hub_port_t));
    298         if (!hub_info->ports) {
     296        hub_dev->ports =
     297            calloc(hub_dev->port_count + 1, sizeof(usb_hub_port_t));
     298        if (!hub_dev->ports) {
    299299                return ENOMEM;
    300300        }
    301301
    302         for (size_t port = 1; port < hub_info->port_count + 1; ++port) {
    303                 usb_hub_port_init(&hub_info->ports[port], port, control_pipe);
     302        for (size_t port = 1; port < hub_dev->port_count + 1; ++port) {
     303                usb_hub_port_init(&hub_dev->ports[port], port, control_pipe);
    304304        }
    305305
     
    311311                    & HUB_CHAR_POWER_PER_PORT_FLAG;
    312312
    313                 for (size_t port = 1; port <= hub_info->port_count; ++port) {
     313                for (size_t port = 1; port <= hub_dev->port_count; ++port) {
    314314                        usb_log_debug("Powering port %zu.\n", port);
    315315                        opResult = usb_hub_port_set_feature(
    316                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     316                            &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER);
    317317                        if (opResult != EOK) {
    318318                                usb_log_error("Cannot power on port %zu: %s.\n",
     
    384384 *
    385385 * This means either to power off the hub or power it on.
    386  * @param hub_info hub instance
     386 * @param hub_dev hub instance
    387387 * @param status hub status bitmask
    388388 * @return error code
    389389 */
    390 static void usb_hub_over_current(const usb_hub_dev_t *hub_info,
     390static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
    391391    usb_hub_status_t status)
    392392{
     
    399399                 * ports on. */
    400400                size_t port;
    401                 for (port = 1; port <= hub_info->port_count; ++port) {
     401                for (port = 1; port <= hub_dev->port_count; ++port) {
    402402                        const int opResult = usb_hub_port_set_feature(
    403                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     403                            &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER);
    404404                        if (opResult != EOK) {
    405405                                usb_log_warning(
     
    411411        }
    412412        const int opResult = usb_request_clear_feature(
    413             &hub_info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
     413            &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
    414414            USB_REQUEST_RECIPIENT_DEVICE,
    415415            USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
     
    425425 *
    426426 * The change can be either in the over-current condition or local-power change.
    427  * @param hub_info hub instance
    428  */
    429 static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_info)
    430 {
    431         assert(hub_info);
    432         assert(hub_info->usb_device);
     427 * @param hub_dev hub instance
     428 */
     429static void usb_hub_global_interrupt(const usb_hub_dev_t *hub_dev)
     430{
     431        assert(hub_dev);
     432        assert(hub_dev->usb_device);
    433433        usb_log_debug("Global interrupt on a hub\n");
    434         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
     434        usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
    435435
    436436        usb_hub_status_t status;
     
    453453        /* Handle status changes */
    454454        if (status & USB_HUB_STATUS_C_OVER_CURRENT) {
    455                 usb_hub_over_current(hub_info, status);
     455                usb_hub_over_current(hub_dev, status);
    456456        }
    457457
     
    485485 * callback called from hub polling fibril when the fibril terminates
    486486 *
    487  * Should perform a cleanup - deletes hub_info.
     487 * Does not perform cleanup, just marks the hub as not running.
    488488 * @param device usb device afected
    489489 * @param was_error indicates that the fibril is stoped due to an error
Note: See TracChangeset for help on using the changeset viewer.