Changeset b276c3b in mainline for uspace/drv/uhci/root_hub/port.c


Ignore:
Timestamp:
2011-01-08T19:18:52Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
602eac5
Parents:
15be932
Message:

Refactoring - use the new blocking call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/root_hub/port.c

    r15be932 rb276c3b  
    11
    2 #include <atomic.h>
    32#include <errno.h>
    4 #include <usb/devreq.h>
     3#include <usb/devreq.h> /* for usb_device_request_setup_packet_t */
    54#include <usb/usb.h>
    65
     
    109#include "port_status.h"
    1110#include "utils/hc_synchronizer.h"
     11#include "utils/identify.h"
    1212
    1313struct usb_match {
     
    3535                port_status_t port_status =
    3636                        port_status_read(port_instance->address);
    37 //              port_status.raw_value = pio_read_16(port_instance->address);
    3837
    3938                /* debug print */
     
    8786        }
    8887
    89         /* report to devman */
     88        /* communicate and possibly report to devman */
    9089        assert( port->attached_device == 0 );
    9190        report_new_device(port->hc, address, port->number,
     
    136135                { return ENOMEM; }
    137136
     137        int ret = 0;
     138#define CHECK_RET_DELETE_CHILD_RETURN(ret, child, message, args...)\
     139        if (ret < 0) { \
     140                uhci_print_error("Failed(%d) to "message, ret, ##args); \
     141                delete_device(child); \
     142                return ret; \
     143        } else (void)0
     144
    138145        char *name;
    139         int ret;
    140 
    141         ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address );
    142         if (ret < 0) {
    143                 uhci_print_error( "Failed to create device name.\n" );
    144                 delete_device( child );
    145                 return ret;
    146         }
     146
     147        /* create name */
     148        ret = asprintf(&name, "usbdevice on hc%p/%d(%#x)", hc, hub_port, address);
     149        CHECK_RET_DELETE_CHILD_RETURN(ret, child, "create device name.\n");
     150
    147151        child->name = name;
    148152
    149         /* TODO get and parse device descriptor */
    150         const int vendor = 1;
    151         const int product = 1;
    152         const char* release = "unknown";
    153         const char* class = "unknown";
    154 
    155         /* create match ids TODO fix class printf*/
    156         static const struct usb_match usb_matches[] = {
    157           { 100, "usb&vendor=%d&product=%d&release=%s" },
    158           {  90, "usb&vendor=%d&product=%d" },
    159           {  50, "usb&class=%d" },
    160           {   1, "usb&fallback" }
    161         };
    162 
    163         unsigned i = 0;
    164         for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) {
    165                 char *match_str;
    166                 const int ret = asprintf(
    167                   &match_str, usb_matches[i].id_string, vendor, product, release, class );
    168                 if (ret < 0 ) {
    169                         uhci_print_error( "Failed to create matchid string.\n" );
    170                         delete_device( child );
    171                         return ret;
    172                 }
    173                 uhci_print_verbose( "Adding match id rule:%s\n", match_str );
    174 
    175                 match_id_t *id = create_match_id();
    176                 if (id == NULL) {
    177                         uhci_print_error( "Failed to create matchid.\n" );
    178                         delete_device( child );
    179                         free( match_str );
    180                         return ENOMEM;
    181                 }
    182                 id->id = match_str;
    183                 id->score = usb_matches[i].id_score;
    184                 add_match_id( &child->match_ids, id );
    185 
    186                 uhci_print_info( "Added match id, score: %d, string %s\n",
    187                   id->score, id->id );
    188         }
    189 
     153        /* use descriptors to identify the device */
     154        ret = identify_device(hc, child, address);
     155        CHECK_RET_DELETE_CHILD_RETURN(ret, child, "identify device.\n");
     156
     157        /* all went well, tell devman */
    190158        ret = child_device_register( child, hc );
    191         if (ret < 0) {
    192                 uhci_print_error( "Failed to create device name.\n" );
    193                 delete_device( child );
    194                 return ret;
    195         }
     159        CHECK_RET_DELETE_CHILD_RETURN(ret, child, "register device.\n");
    196160
    197161        if (handle != NULL)
     
    200164        return EOK;
    201165}
    202 
     166/*----------------------------------------------------------------------------*/
    203167static usb_address_t assign_address_to_zero_device( device_t *hc )
    204168{
     
    226190        };
    227191
    228         sync_value_t value;
    229         sync_init(&value);
    230 
    231         uhci_setup(
    232           hc, new_device, USB_TRANSFER_CONTROL, &data, sizeof(data),
    233                 sync_out_callback, (void*)&value);
    234         uhci_print_verbose("address assignment sent, waiting to complete.\n");
    235 
    236         sync_wait_for(&value);
    237         if (value.result != USB_OUTCOME_OK) {
     192        sync_value_t sync;
     193        uhci_setup_sync(hc, new_device,
     194          USB_TRANSFER_CONTROL, &data, sizeof(data), &sync);
     195
     196        if (sync.result != USB_OUTCOME_OK) {
    238197                uhci_print_error(
    239198                  "Failed to assign address to the connected device.\n");
Note: See TracChangeset for help on using the changeset viewer.