Changeset 193da9d6 in mainline


Ignore:
Timestamp:
2011-09-19T14:15:55Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a05ced0
Parents:
34a0d17
Message:

usbhub: Rename usbhub_private.h ⇒ utils.h.

Add error checks, comments, and slight refactoring.

Location:
uspace/drv/bus/usb/usbhub
Files:
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/port_status.h

    r34a0d17 r193da9d6  
    11/*
    22 * Copyright (c) 2010 Matus Dekanek
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    3637#include <sys/types.h>
    3738#include <usb/dev/request.h>
    38 #include "usbhub_private.h"
    3939
    4040/**
  • uspace/drv/bus/usb/usbhub/ports.c

    r34a0d17 r193da9d6  
    4444#include "ports.h"
    4545#include "usbhub.h"
    46 #include "usbhub_private.h"
     46#include "utils.h"
    4747#include "port_status.h"
    4848
  • uspace/drv/bus/usb/usbhub/ports.h

    r34a0d17 r193da9d6  
    6262 * @param port Port to be initialized.
    6363 */
    64 static inline void usb_hub_port_init(usb_hub_port_t *port) {
     64static inline void usb_hub_port_init(usb_hub_port_t *port)
     65{
     66        assert(port);
    6567        port->attached_device.address = -1;
    6668        port->attached_device.handle = 0;
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r34a0d17 r193da9d6  
    3838#include <str_error.h>
    3939#include <inttypes.h>
    40 
    41 #include <usb_iface.h>
     40#include <stdio.h>
     41
     42#include <usb/usb.h>
     43#include <usb/dev/pipes.h>
     44#include <usb/classes/classes.h>
    4245#include <usb/ddfiface.h>
    4346#include <usb/descriptor.h>
     
    4649#include <usb/classes/hub.h>
    4750#include <usb/dev/poll.h>
    48 #include <stdio.h>
     51#include <usb_iface.h>
    4952
    5053#include "usbhub.h"
    51 #include "usbhub_private.h"
     54#include "utils.h"
    5255#include "port_status.h"
    53 #include <usb/usb.h>
    54 #include <usb/dev/pipes.h>
    55 #include <usb/classes/classes.h>
    5656
    5757#define HUB_FNC_NAME "hub"
    5858
     59static int usb_set_first_configuration(usb_device_t *usb_device);
    5960static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
    6061static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
    61 static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
    6262static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    6363    usb_hub_status_t status);
     
    8585int usb_hub_add_device(usb_device_t *usb_dev)
    8686{
    87         if (!usb_dev) return EINVAL;
     87        assert(usb_dev);
     88        /* Create driver soft-state structure */
    8889        usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev);
    89 
    90         //create hc connection
     90        if (hub_info == NULL) {
     91                usb_log_error("Failed to create hun driver structure.\n");
     92                return ENOMEM;
     93        }
     94
     95        /* Create hc connection */
    9196        usb_log_debug("Initializing USB wire abstraction.\n");
    9297        int opResult = usb_hc_connection_initialize_from_device(
     
    99104        }
    100105
    101         //set hub configuration
    102         opResult = usb_hub_set_configuration(hub_info);
     106        /* Set hub's first configuration. (There should be only one) */
     107        opResult = usb_set_first_configuration(usb_dev);
    103108        if (opResult != EOK) {
    104109                usb_log_error("Could not set hub configuration: %s\n",
     
    233238 * information. If there are non-removable devices, start initializing them.
    234239 * This function is hub-specific and should be run only after the hub is
    235  * configured using usb_hub_set_configuration function.
     240 * configured using usb_set_first_configuration function.
    236241 * @param hub_info hub representation
    237242 * @return error code
     
    239244int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
    240245{
     246        assert(hub_info);
    241247        // get hub descriptor
    242248        usb_log_debug("Retrieving descriptor\n");
     
    267273        hub_info->port_count = descriptor.ports_count;
    268274
     275        // TODO Why +1 ?
    269276        hub_info->ports =
    270277            malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
     
    304311
    305312        } else {
    306                 usb_log_debug("Power not switched, not going to be powered\n");
     313                usb_log_debug("Power not switched, ports always powered\n");
    307314        }
    308315        return EOK;
     
    310317
    311318/**
    312  * Set configuration of hub
     319 * Set configuration of and USB device
    313320 *
    314321 * Check whether there is at least one configuration and sets the first one.
    315322 * This function should be run prior to running any hub-specific action.
    316  * @param hub_info hub representation
     323 * @param usb_device usb device representation
    317324 * @return error code
    318325 */
    319 static int usb_hub_set_configuration(usb_hub_info_t *hub_info)
     326static int usb_set_first_configuration(usb_device_t *usb_device)
    320327{
    321         //device descriptor
    322         const usb_standard_device_descriptor_t *std_descriptor
    323             = &hub_info->usb_device->descriptors.device;
    324         usb_log_debug("Hub has %d configurations\n",
    325             std_descriptor->configuration_count);
    326 
    327         if (std_descriptor->configuration_count < 1) {
     328        assert(usb_device);
     329        /* Get number of possible configurations from device descriptor */
     330        const size_t configuration_count =
     331            usb_device->descriptors.device.configuration_count;
     332        usb_log_debug("Hub has %d configurations.\n", configuration_count);
     333
     334        if (configuration_count < 1) {
    328335                usb_log_error("There are no configurations available\n");
    329336                return EINVAL;
    330337        }
    331338
     339        // TODO: Make sure that there is enough data and the cast is correct
    332340        usb_standard_configuration_descriptor_t *config_descriptor
    333341            = (usb_standard_configuration_descriptor_t *)
    334             hub_info->usb_device->descriptors.configuration;
    335 
    336         /* Set configuration. */
    337         int opResult = usb_request_set_configuration(
    338             &hub_info->usb_device->ctrl_pipe,
    339             config_descriptor->configuration_number);
    340 
     342            usb_device->descriptors.configuration;
     343
     344        /* Set configuration. Use the configuration that was in
     345         * usb_device->descriptors.configuration */
     346        const int opResult = usb_request_set_configuration(
     347            &usb_device->ctrl_pipe, config_descriptor->configuration_number);
    341348        if (opResult != EOK) {
    342349                usb_log_error("Failed to set hub configuration: %s.\n",
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r34a0d17 r193da9d6  
    5656        size_t port_count;
    5757
    58         /** attached device handles, for each port one */
     58        /** Attached device handles, for each port one */
    5959        usb_hub_port_t *ports;
    6060
    6161        fibril_mutex_t port_mutex;
    6262
    63         /** connection to hcd */
     63        /** Connection to hcd */
    6464        usb_hc_connection_t connection;
    6565
  • uspace/drv/bus/usb/usbhub/utils.c

    r34a0d17 r193da9d6  
    4242
    4343#include "usbhub.h"
    44 #include "usbhub_private.h"
    45 #include "port_status.h"
     44#include "utils.h"
    4645
    4746
  • uspace/drv/bus/usb/usbhub/utils.h

    r34a0d17 r193da9d6  
    11/*
    22 * Copyright (c) 2010 Matus Dekanek
     3 * Copyright (c) 2011 Jan Vesely
    34 * All rights reserved.
    45 *
     
    3435 */
    3536
    36 #ifndef USBHUB_PRIVATE_H
    37 #define USBHUB_PRIVATE_H
    38 
    39 #include "usbhub.h"
     37#ifndef USBHUB_UTILS_H
     38#define USBHUB_UTILS_H
    4039
    4140#include <adt/list.h>
     
    4847#include <usb/debug.h>
    4948#include <usb/dev/request.h>
     49
     50#include "usbhub.h"
    5051
    5152//************
     
    166167}
    167168
    168 
    169169void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t *descriptor);
    170170
     
    175175    void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor);
    176176
    177 
    178 #endif  /* USBHUB_PRIVATE_H */
    179 
     177#endif
    180178/**
    181179 * @}
Note: See TracChangeset for help on using the changeset viewer.