Changeset bf5a3be in mainline


Ignore:
Timestamp:
2010-12-19T14:40:29Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2972e21
Parents:
f088c00
Message:

added creation of device match ids

new debug output system
TODO: set address

get descriptor/parse descriptor

device removal

Location:
uspace/drv/uhci
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/main.c

    rf088c00 rbf5a3be  
    2727 */
    2828#include <usb/hcdhubd.h>
    29 #include <usb/debug.h>
    3029#include <errno.h>
    3130
     31#include "debug.h"
    3232#include "iface.h"
    3333#include "name.h"
     
    4141static int uhci_add_device(device_t *device)
    4242{
    43         usb_dprintf(NAME, 1, "uhci_add_device() called\n");
     43//      usb_dprintf(NAME, DEBUG, "uhci_add_device() called\n");
     44        uhci_print_info( "uhci_add_device() called\n" );
    4445        device->ops = &uhci_ops;
    4546
    4647        uhci_init( device, (void*)0xc020 );
    47 
    48         /*
    49          * We need to announce the presence of our root hub.
    50          */
    51 //      usb_dprintf(NAME, 2, "adding root hub\n");
    52 //      usb_hcd_add_root_hub(device);
    5348
    5449        return EOK;
     
    6964         * Do some global initializations.
    7065         */
    71         sleep( 5);
    72         usb_dprintf_enable(NAME, 5);
     66        sleep( 5 );
     67        usb_dprintf_enable(NAME, DEBUG_LEVEL_INFO);
    7368
    7469        return driver_main(&uhci_driver);
  • uspace/drv/uhci/root_hub/root_hub.c

    rf088c00 rbf5a3be  
     1#include <bool.h>
    12#include <ddi.h>
     3#include <devman.h>
    24#include <async.h>
    35#include <errno.h>
     
    57#include <stdio.h>
    68
    7 #include <usb/debug.h>
    8 
    99#include "../name.h"
    1010#include "../uhci.h"
     11#include "../debug.h"
    1112#include "port_status.h"
    1213#include "root_hub.h"
    1314
    1415#define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */
     16
     17struct usb_match {
     18        int id_score;
     19        const char *id_string;
     20};
    1521
    1622static int uhci_root_hub_check_ports( void *hc );
     
    1925static int uhci_root_hub_report_new_device(
    2026  device_t *hc, usb_address_t address, int port, devman_handle_t *handle );
     27static int uhci_root_hub_port_set_enabled(
     28  uhci_root_hub_t *instance, unsigned port, bool enabled );
    2129
    2230/*----------------------------------------------------------------------------*/
     
    2937        const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)&regs);
    3038        if (ret < 0) {
    31                 printf( NAME": Failed to gain access to port registers at %p\n", regs );
     39                uhci_print_error(
     40                  ": Failed to gain access to port registers at %p\n", regs );
    3241                return ret;
    3342        }
     
    3746        hub->checker = fibril_create( uhci_root_hub_check_ports, hc );
    3847        if (hub->checker == 0) {
    39                 printf( NAME": failed to launch root hub fibril." );
     48                uhci_print_error( ": failed to launch root hub fibril." );
    4049                return ENOMEM;
    4150        }
     
    5160        //destroy fibril here
    5261        //disable access to registers
     62        return EOK;
     63}
     64/*----------------------------------------------------------------------------*/
     65static int uhci_root_hub_port_set_enabled( uhci_root_hub_t *instance,
     66  unsigned port, bool enabled )
     67{
     68        assert( instance );
     69        assert( instance->registers );
     70        assert( port < UHCI_ROOT_HUB_PORT_COUNT );
     71
     72        volatile uint16_t * address =
     73                &(instance->registers->portsc[port]);
     74
     75        /* read register value */
     76        port_status_t port_status;
     77        port_status.raw_value = pio_read_16( address );
     78
     79        /* enable port: register write */
     80        port_status.status.enabled_change = 0;
     81        port_status.status.enabled = (bool)enabled;
     82        pio_write_16( address, port_status.raw_value );
     83
     84        uhci_print_info( "Enabled port %d.\n", port );
    5385        return EOK;
    5486}
     
    6597                                &(uhci_instance->root_hub.registers->portsc[i]);
    6698
    67                         usb_dprintf( NAME, 1, "Port(%d) status address %p:\n", i, address );
     99                        uhci_print_info( "Port(%d) status address %p:\n", i, address );
    68100
    69101                        /* read register value */
     
    72104
    73105                        /* debug print */
    74                         usb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, port_status.raw_value );
     106                        uhci_print_info( "Port(%d) status %#x:\n", i, port_status.raw_value );
    75107                        print_port_status( &port_status );
    76108
     
    96128        assert( port < UHCI_ROOT_HUB_PORT_COUNT );
    97129
    98         usb_dprintf( NAME, 2, "Adding new device on port %d.\n", port );
     130        uhci_print_info( "Adding new device on port %d.\n", port );
    99131
    100132        uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
     
    104136
    105137        /* enable port */
    106         {
    107                 volatile uint16_t * address =
    108                         &(uhci_instance->root_hub.registers->portsc[port]);
    109 
    110                 /* read register value */
    111                 port_status_t port_status;
    112                 port_status.raw_value = pio_read_16( address );
    113 
    114                 /* enable port: register write */
    115                 port_status.status.enabled = 1;
    116                 pio_write_16( address, port_status.raw_value );
    117 
    118                 usb_dprintf( NAME, 2, "Enabled port %d.\n", port );
    119         }
     138        uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, true );
    120139
    121140        /* assign address to device */
    122         usb_address_t address =
    123          uhci_root_hub_assign_address( hc );
    124         if (address <= 0) {
    125                 printf( NAME": Failed to assign address to the device" );
    126                 return ENOMEM;
    127         }
     141        usb_address_t address = uhci_root_hub_assign_address( hc );
     142
    128143        /* release default address */
    129144        usb_address_keeping_release_default( &uhci_instance->address_manager );
     145
     146        if (address <= 0) { /* address assigning went wrong */
     147                uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, false );
     148                uhci_print_error( "Failed to assign address to the device" );
     149                return ENOMEM;
     150        }
    130151
    131152        /* report to devman */
     
    148169        uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
    149170        /* get new address */
    150         const usb_address_t usb_address = usb_address_keeping_request(
    151           &uhci_instance->address_manager );
     171        const usb_address_t usb_address =
     172          usb_address_keeping_request( &uhci_instance->address_manager );
    152173
    153174        /* assign new address */
    154         /* TODO send new address*/
    155         usb_dprintf( NAME, 3, "Assigned address 0x%x.\n", usb_address );
     175        /* TODO send new address to the device*/
     176        uhci_print_error( "Assigned address %#x.\n", usb_address );
    156177
    157178        return usb_address;
     
    165186        assert( address <= USB11_ADDRESS_MAX );
    166187
    167         int ret;
    168188        device_t *child = create_device();
    169189        if (child == NULL)
    170190                { return ENOMEM; }
     191
    171192        char *name;
    172 
    173         ret = asprintf( &name, "usbdevice on hc%p/%d/0x%x", hc, hub_port, address );
     193        int ret;
     194
     195        ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address );
    174196        if (ret < 0) {
    175                 usb_dprintf( NAME, 4, "Failed to create device name.\n" );
     197                uhci_print_error( "Failed to create device name.\n" );
    176198                delete_device( child );
    177199                return ret;
     
    179201        child->name = name;
    180202
    181         /* TODO create match ids */
     203        /* TODO get and parse device descriptor */
     204        const int vendor = 1;
     205        const int product = 1;
     206        const char* release = "unknown";
     207        const char* class = "unknown";
     208
     209        /* create match ids TODO fix class printf*/
     210        static const struct usb_match usb_matches[] = {
     211          { 100, "usb&vendor=%d&product=%d&release=%s" },
     212          {  90, "usb&vendor=%d&product=%d" },
     213          {  50, "usb&class=%d" },
     214          {   1, "usb&fallback" }
     215        };
     216
     217        unsigned i = 0;
     218        for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) {
     219                char *match_str;
     220                const int ret = asprintf(
     221                  &match_str, usb_matches[i].id_string, vendor, product, release, class );
     222                if (ret < 0 ) {
     223                        uhci_print_error( "Failed to create matchid string.\n" );
     224                        delete_device( child );
     225                        return ret;
     226                }
     227                uhci_print_info( "Adding match id rule:%s\n", match_str );
     228
     229                match_id_t *id = create_match_id();
     230                if (id == NULL) {
     231                        uhci_print_error( "Failed to create matchid.\n" );
     232                        delete_device( child );
     233                        free( match_str );
     234                        return ENOMEM;
     235                }
     236                id->id = match_str;
     237                id->score = usb_matches[i].id_score;
     238                add_match_id( &child->match_ids, id );
     239
     240                uhci_print_info( "Added match id, score: %d, string %s\n",
     241                  id->score, id->id );
     242        }
    182243
    183244        ret = child_device_register( child, hc );
    184245        if (ret < 0) {
    185                 usb_dprintf( NAME, 4, "Failed to create device name.\n" );
     246                uhci_print_error( "Failed to create device name.\n" );
    186247                delete_device( child );
    187248                return ret;
  • uspace/drv/uhci/uhci.c

    rf088c00 rbf5a3be  
    33#include <usb/usb.h>
    44
     5#include "debug.h"
    56#include "name.h"
    67#include "uhci.h"
     
    1011{
    1112        assert( device );
    12         usb_dprintf(NAME, 1, "Initializing device at address %p\n", device);
     13        uhci_print_info( "Initializing device at address %p\n", device);
    1314
    1415        /* create instance */
     
    5253        )
    5354{
    54         usb_dprintf(NAME, 1, "transfer IN [%d.%d (%s); %zu]\n",
     55        uhci_print_info( "transfer IN [%d.%d (%s); %zu]\n",
    5556            target.address, target.endpoint,
    5657            usb_str_transfer_type(transfer_type),
     
    6869  )
    6970{
    70         usb_dprintf(NAME, 1, "transfer OUT [%d.%d (%s); %zu]\n",
     71        uhci_print_info( "transfer OUT [%d.%d (%s); %zu]\n",
    7172            target.address, target.endpoint,
    7273            usb_str_transfer_type(transfer_type),
     
    8485  )
    8586{
    86         usb_dprintf(NAME, 1, "transfer SETUP [%d.%d (%s); %zu]\n",
     87        uhci_print_info( "transfer SETUP [%d.%d (%s); %zu]\n",
    8788            target.address, target.endpoint,
    8889            usb_str_transfer_type(transfer_type),
Note: See TracChangeset for help on using the changeset viewer.