Changeset 66a54cc in mainline


Ignore:
Timestamp:
2011-04-01T14:45:21Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03eea27
Parents:
87b52c9
Message:

ohci root hub driver fixes

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/hc.c

    r87b52c9 r66a54cc  
    5858
    5959        char *match_str = NULL;
    60         int ret = asprintf(&match_str, "usb&mid");
     60        int ret = asprintf(&match_str, "usb&class=hub");
    6161        ret = (match_str == NULL) ? ret : EOK;
    6262        if (ret < 0) {
  • uspace/drv/ohci/root_hub.c

    r87b52c9 r66a54cc  
    4040#include "root_hub.h"
    4141#include "usb/classes/classes.h"
     42#include "usb/devdrv.h"
    4243#include <usb/request.h>
    4344#include <usb/classes/hub.h>
     
    6162                /// \TODO these values migt be different
    6263                .str_serial_number = 0,
    63                 .usb_spec_version = 0,
     64                .usb_spec_version = 0x110,
    6465};
    6566
     
    110111};
    111112
    112 /** Root hub initialization
    113  * @return Error code.
    114  */
    115 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
    116 {
    117         assert(instance);
    118         instance->address = -1;
    119         instance->registers = regs;
    120         instance->device = dev;
    121 
    122 
    123         usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
    124 
    125         //start generic usb hub driver
    126        
    127         /* TODO: implement */
    128         return EOK;
    129 }
    130 /*----------------------------------------------------------------------------*/
    131 
    132 /**
    133  * create answer to port status_request
    134  *
    135  * Copy content of corresponding port status register to answer buffer.
    136  *
    137  * @param instance root hub instance
    138  * @param port port number, counted from 1
    139  * @param request structure containing both request and response information
    140  * @return error code
    141  */
    142 static int process_get_port_status_request(rh_t *instance, uint16_t port,
    143                 usb_transfer_batch_t * request){
    144         if(port<1 || port>instance->port_count)
    145                 return EINVAL;
    146         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    147         request->transfered_size = 4;
    148         uint32_buffer[0] = instance->registers->rh_port_status[port -1];
    149         return EOK;
    150 }
    151 
    152 /**
    153  * create answer to port status_request
    154  *
    155  * Copy content of hub status register to answer buffer.
    156  *
    157  * @param instance root hub instance
    158  * @param request structure containing both request and response information
    159  * @return error code
    160  */
    161 static int process_get_hub_status_request(rh_t *instance,
    162                 usb_transfer_batch_t * request){
    163         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    164         //bits, 0,1,16,17
    165         request->transfered_size = 4;
    166         uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
    167         uint32_buffer[0] = mask & instance->registers->rh_status;
    168         return EOK;
    169 
    170 }
    171 
    172113/**
    173114 * Create hub descriptor used in hub-driver <-> hub communication
    174  * 
     115 *
    175116 * This means creating byt array from data in root hub registers. For more
    176117 * info see usb hub specification.
     
    197138        result[2] = instance->port_count;
    198139        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    199         result[3] = 
     140        result[3] =
    200141                        ((hub_desc_reg >> 8) %2) +
    201142                        (((hub_desc_reg >> 9) %2) << 1) +
     
    219160        (*out_size) = size;
    220161}
     162
     163
     164/** initialize hub descriptors
     165 *
     166 * Initialized are device and full configuration descriptor. These need to
     167 * be initialized only once per hub.
     168 * @instance root hub instance
     169 */
     170static void rh_init_descriptors(rh_t *instance){
     171        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
     172                sizeof(ohci_rh_device_descriptor)
     173        );
     174        usb_standard_configuration_descriptor_t descriptor;
     175        memcpy(&descriptor,&ohci_rh_conf_descriptor,
     176                        sizeof(ohci_rh_conf_descriptor));
     177        uint8_t * hub_descriptor;
     178        size_t hub_desc_size;
     179        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
     180                        &hub_desc_size);
     181
     182        descriptor.total_length =
     183                        sizeof(usb_standard_configuration_descriptor_t)+
     184                        sizeof(usb_standard_endpoint_descriptor_t)+
     185                        sizeof(usb_standard_interface_descriptor_t)+
     186                        hub_desc_size;
     187       
     188        uint8_t * full_config_descriptor =
     189                        (uint8_t*) malloc(descriptor.total_length);
     190        memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));
     191        memcpy(full_config_descriptor + sizeof(descriptor),
     192                        &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));
     193        memcpy(full_config_descriptor + sizeof(descriptor) +
     194                                sizeof(ohci_rh_iface_descriptor),
     195                        &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
     196        memcpy(full_config_descriptor + sizeof(descriptor) +
     197                                sizeof(ohci_rh_iface_descriptor) +
     198                                sizeof(ohci_rh_ep_descriptor),
     199                        hub_descriptor, hub_desc_size);
     200       
     201        instance->descriptors.configuration = full_config_descriptor;
     202        instance->descriptors.configuration_size = descriptor.total_length;
     203}
     204
     205/** Root hub initialization
     206 * @return Error code.
     207 */
     208int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
     209{
     210        assert(instance);
     211        instance->address = -1;
     212        instance->registers = regs;
     213        instance->device = dev;
     214        rh_init_descriptors(instance);
     215
     216
     217        usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
     218
     219        //start generic usb hub driver
     220       
     221        /* TODO: implement */
     222        return EOK;
     223}
     224/*----------------------------------------------------------------------------*/
     225
     226/**
     227 * create answer to port status_request
     228 *
     229 * Copy content of corresponding port status register to answer buffer.
     230 *
     231 * @param instance root hub instance
     232 * @param port port number, counted from 1
     233 * @param request structure containing both request and response information
     234 * @return error code
     235 */
     236static int process_get_port_status_request(rh_t *instance, uint16_t port,
     237                usb_transfer_batch_t * request){
     238        if(port<1 || port>instance->port_count)
     239                return EINVAL;
     240        uint32_t * uint32_buffer = (uint32_t*)request->buffer;
     241        request->transfered_size = 4;
     242        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     243        return EOK;
     244}
     245
     246/**
     247 * create answer to port status_request
     248 *
     249 * Copy content of hub status register to answer buffer.
     250 *
     251 * @param instance root hub instance
     252 * @param request structure containing both request and response information
     253 * @return error code
     254 */
     255static int process_get_hub_status_request(rh_t *instance,
     256                usb_transfer_batch_t * request){
     257        uint32_t * uint32_buffer = (uint32_t*)request->buffer;
     258        //bits, 0,1,16,17
     259        request->transfered_size = 4;
     260        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
     261        uint32_buffer[0] = mask & instance->registers->rh_status;
     262        return EOK;
     263
     264}
     265
    221266
    222267
     
    284329        }
    285330}
    286 
    287 /**
    288  * create standart configuration descriptor for the root hub instance
    289  * @param instance root hub instance
    290  * @return newly allocated descriptor
    291  */
    292 static usb_standard_configuration_descriptor_t *
    293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    294         usb_standard_configuration_descriptor_t * descriptor =
    295                         malloc(sizeof(usb_standard_configuration_descriptor_t));
    296         memcpy(descriptor, &ohci_rh_conf_descriptor,
    297                 sizeof(usb_standard_configuration_descriptor_t));
    298         /// \TODO should this include device descriptor?
    299         const size_t hub_descriptor_size = 7 +
    300                         2* (instance->port_count / 8 +
    301                         ((instance->port_count % 8 > 0) ? 1 : 0));
    302         descriptor->total_length =
    303                         sizeof(usb_standard_configuration_descriptor_t)+
    304                         sizeof(usb_standard_endpoint_descriptor_t)+
    305                         sizeof(usb_standard_interface_descriptor_t)+
    306                         hub_descriptor_size;
    307         return descriptor;
    308 }
    309 
     331 
    310332/**
    311333 * create answer to a descriptor request
     
    344366                case USB_DESCTYPE_CONFIGURATION: {
    345367                        usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    346                         usb_standard_configuration_descriptor_t * descriptor =
    347                                         usb_ohci_rh_create_standart_configuration_descriptor(
    348                                                 instance);
    349                         result_descriptor = descriptor;
    350                         size = sizeof(usb_standard_configuration_descriptor_t);
    351                         del = true;
     368                        result_descriptor = instance->descriptors.configuration;
     369                        size = instance->descriptors.configuration_size;
    352370                        break;
    353371                }
     
    380398        }
    381399        request->transfered_size = size;
    382         memcpy(request->buffer,result_descriptor,size);
     400        memcpy(request->transport_buffer,result_descriptor,size);
     401        usb_log_debug("sent desctiptor: %s\n",
     402                        usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));
    383403        if (del)
    384404                free(result_descriptor);
  • uspace/drv/ohci/root_hub.h

    r87b52c9 r66a54cc  
    3737
    3838#include <usb/usb.h>
     39#include <usb/devdrv.h>
    3940
    4041#include "ohci_regs.h"
     
    5354        /** hub port count */
    5455        int port_count;
     56        /** hubs descriptors */
     57        usb_device_descriptors_t descriptors;
    5558} rh_t;
    5659
  • uspace/drv/usbhub/usbhub.c

    r87b52c9 r66a54cc  
    7474
    7575        while(errorCode == EOK){
     76                async_usleep(1000 * 1000 * 10 );/// \TODO proper number once
    7677                errorCode = usb_hub_check_hub_changes(hub_info);
    77                 async_usleep(1000 * 1000 );/// \TODO proper number once
    7878        }
    7979        usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
  • uspace/lib/usb/src/devdrv.c

    r87b52c9 r66a54cc  
    251251            &dev->descriptors.configuration_size);
    252252        if (rc != EOK) {
    253                 usb_log_error("Failed retrieving configuration descriptor: %s.\n",
     253                usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",
    254254                    dev->ddf_dev->name, str_error(rc));
    255255                return rc;
  • uspace/lib/usb/src/request.c

    r87b52c9 r66a54cc  
    529529                return rc;
    530530        }
    531 
    532531        if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {
    533532                return ENOENT;
Note: See TracChangeset for help on using the changeset viewer.