Changeset b330b309 in mainline


Ignore:
Timestamp:
2011-03-26T20:22:17Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51e5608
Parents:
cee51fd (diff), df3ad97 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

fix for #132(non-removable devices) 2.0
code cleaned for ohci root hub

Location:
uspace/drv
Files:
4 edited

Legend:

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

    rcee51fd rb330b309  
    4343#include <usb/classes/hub.h>
    4444
     45/**
     46 *      standart device descriptor for ohci root hub
     47 */
    4548static const usb_standard_device_descriptor_t ohci_rh_device_descriptor =
    4649{
     
    6164};
    6265
     66/**
     67 * standart configuration descriptor with filled common values
     68 * for ohci root hubs
     69 */
    6370static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor =
    6471{
     
    7380};
    7481
     82/**
     83 * standart ohci root hub interface descriptor
     84 */
    7585static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor =
    7686{
     
    8797};
    8898
     99/**
     100 * standart ohci root hub endpoint descriptor
     101 */
    89102static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor =
    90103{
     
    273286
    274287/**
    275  * create standard device descriptor for a hub
    276  * @return newly allocated descriptor
    277  */
    278 static usb_standard_device_descriptor_t *
    279         usb_ohci_rh_create_standard_device_descriptor(){
    280         usb_standard_device_descriptor_t * descriptor =
    281                                 (usb_standard_device_descriptor_t*)
    282                                 malloc(sizeof(usb_standard_device_descriptor_t));
    283         descriptor->configuration_count = 1;
    284         descriptor->descriptor_type = USB_DESCTYPE_DEVICE;
    285         descriptor->device_class = USB_CLASS_HUB;
    286         descriptor->device_protocol = 0;
    287         descriptor->device_subclass = 0;
    288         descriptor->device_version = 0;
    289         descriptor->length = sizeof(usb_standard_device_descriptor_t);
    290         /// \TODO this value is guessed
    291         descriptor->max_packet_size = 8;
    292         descriptor->product_id = 0x0001;
    293         /// \TODO these values migt be different
    294         descriptor->str_serial_number = 0;
    295         descriptor->str_serial_number = 0;
    296         descriptor->usb_spec_version = 0;
    297         descriptor->vendor_id = 0x16db;
    298         return descriptor;
    299 }
    300 
    301 /**
    302288 * create standart configuration descriptor for the root hub instance
    303289 * @param instance root hub instance
     
    307293usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    308294        usb_standard_configuration_descriptor_t * descriptor =
    309                         (usb_standard_configuration_descriptor_t*)
    310295                        malloc(sizeof(usb_standard_configuration_descriptor_t));
    311         /// \TODO some values are default or guessed
    312         descriptor->attributes = 1<<7;
    313         descriptor->configuration_number = 1;
    314         descriptor->descriptor_type = USB_DESCTYPE_CONFIGURATION;
    315         descriptor->interface_count = 1;
    316         descriptor->length = sizeof(usb_standard_configuration_descriptor_t);
    317         descriptor->max_power = 100;
    318         descriptor->str_configuration = 0;
     296        memcpy(descriptor, &ohci_rh_conf_descriptor,
     297                sizeof(usb_standard_configuration_descriptor_t));
    319298        /// \TODO should this include device descriptor?
    320         size_t hub_descriptor_size = 7 +
     299        const size_t hub_descriptor_size = 7 +
    321300                        2* (instance->port_count / 8 +
    322301                        ((instance->port_count % 8 > 0) ? 1 : 0));
     
    330309
    331310/**
    332  * create standard interface descriptor for a root hub
    333  * @return newly allocated descriptor
    334  */
    335 static usb_standard_interface_descriptor_t *
    336 usb_ohci_rh_create_standard_interface_descriptor(){
    337         usb_standard_interface_descriptor_t * descriptor =
    338                                 (usb_standard_interface_descriptor_t*)
    339                                 malloc(sizeof(usb_standard_interface_descriptor_t));
    340         descriptor->alternate_setting = 0;
    341         descriptor->descriptor_type = USB_DESCTYPE_INTERFACE;
    342         descriptor->endpoint_count = 1;
    343         descriptor->interface_class = USB_CLASS_HUB;
    344         /// \TODO is this correct?
    345         descriptor->interface_number = 1;
    346         descriptor->interface_protocol = 0;
    347         descriptor->interface_subclass = 0;
    348         descriptor->length = sizeof(usb_standard_interface_descriptor_t);
    349         descriptor->str_interface = 0;
    350         return descriptor;
    351 }
    352 
    353 /**
    354  * create standard endpoint descriptor for a root hub
    355  * @return newly allocated descriptor
    356  */
    357 static usb_standard_endpoint_descriptor_t *
    358 usb_ohci_rh_create_standard_endpoint_descriptor(){
    359         usb_standard_endpoint_descriptor_t * descriptor =
    360                         (usb_standard_endpoint_descriptor_t*)
    361                         malloc(sizeof(usb_standard_endpoint_descriptor_t));
    362         descriptor->attributes = USB_TRANSFER_INTERRUPT;
    363         descriptor->descriptor_type = USB_DESCTYPE_ENDPOINT;
    364         descriptor->endpoint_address = 1 + (1<<7);
    365         descriptor->length = sizeof(usb_standard_endpoint_descriptor_t);
    366         descriptor->max_packet_size = 8;
    367         descriptor->poll_interval = 255;
    368         return descriptor;
    369 }
    370 
    371 /**
    372311 * create answer to a descriptor request
    373312 *
     
    386325        const uint16_t setup_request_value = setup_request->value_high;
    387326                        //(setup_request->value_low << 8);
    388 #if 0
    389327        bool del = false;
    390         //this code was merged from development and has to be reviewed
    391328        switch (setup_request_value)
    392329        {
    393         case USB_DESCTYPE_HUB: {
    394                 uint8_t * descriptor;
    395                 usb_create_serialized_hub_descriptor(
    396                     instance, &descriptor, &size);
    397                 result_descriptor = descriptor;
    398                 break;
    399         }
    400         case USB_DESCTYPE_DEVICE: {
    401                 usb_log_debug("USB_DESCTYPE_DEVICE\n");
    402                 result_descriptor = &ohci_rh_device_descriptor;
    403                 size = sizeof(ohci_rh_device_descriptor);
    404                 break;
    405         }
    406         case USB_DESCTYPE_CONFIGURATION: {
    407                 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    408                 usb_standard_configuration_descriptor_t * descriptor =
    409                                 malloc(sizeof(usb_standard_configuration_descriptor_t));
    410                 memcpy(descriptor, &ohci_rh_conf_descriptor,
    411                     sizeof(usb_standard_configuration_descriptor_t));
    412                 /// \TODO should this include device descriptor?
    413                 const size_t hub_descriptor_size = 7 +
    414                                 2* (instance->port_count / 8 +
    415                                 ((instance->port_count % 8 > 0) ? 1 : 0));
    416                 descriptor->total_length =
    417                                 sizeof(usb_standard_configuration_descriptor_t)+
    418                                 sizeof(usb_standard_endpoint_descriptor_t)+
    419                                 sizeof(usb_standard_interface_descriptor_t)+
    420                                 hub_descriptor_size;
    421                 result_descriptor = descriptor;
    422                 size = sizeof(usb_standard_configuration_descriptor_t);
    423                 del = true;
    424                 break;
    425         }
    426         case USB_DESCTYPE_INTERFACE: {
    427                 usb_log_debug("USB_DESCTYPE_INTERFACE\n");
    428                 result_descriptor = &ohci_rh_iface_descriptor;
    429                 size = sizeof(ohci_rh_iface_descriptor);
    430                 break;
    431         }
    432         case USB_DESCTYPE_ENDPOINT: {
    433                 usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
    434                 result_descriptor = &ohci_rh_ep_descriptor;
    435                 size = sizeof(ohci_rh_ep_descriptor);
    436                 break;
    437         }
    438         default: {
    439                 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
    440                 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
    441                                 setup_request->request_type,
    442                                 setup_request->request,
    443                                 setup_request_value,
    444                                 setup_request->index,
    445                                 setup_request->length
    446                                 );
    447                 return EINVAL;
    448         }
    449         }
    450 #endif
    451         if(setup_request_value == USB_DESCTYPE_HUB){
    452                 usb_log_debug("USB_DESCTYPE_HUB\n");
    453                 //create hub descriptor
    454                 uint8_t * descriptor;
    455                 usb_create_serialized_hub_descriptor(instance,
    456                                 &descriptor, &size);
    457                 result_descriptor = descriptor;
    458         }else if(setup_request_value == USB_DESCTYPE_DEVICE){
    459                 //create std device descriptor
    460                 usb_log_debug("USB_DESCTYPE_DEVICE\n");
    461                 result_descriptor =
    462                                 usb_ohci_rh_create_standard_device_descriptor();
    463                 size = sizeof(usb_standard_device_descriptor_t);
    464         }else if(setup_request_value == USB_DESCTYPE_CONFIGURATION){
    465                 usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    466                 result_descriptor =
    467                                 usb_ohci_rh_create_standart_configuration_descriptor(instance);
    468                 size = sizeof(usb_standard_configuration_descriptor_t);
    469 
    470         }else if(setup_request_value == USB_DESCTYPE_INTERFACE){
    471                 usb_log_debug("USB_DESCTYPE_INTERFACE\n");
    472                 result_descriptor =
    473                                 usb_ohci_rh_create_standard_interface_descriptor();
    474                 size = sizeof(usb_standard_interface_descriptor_t);
    475         }else if(setup_request_value == USB_DESCTYPE_ENDPOINT){
    476                 usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
    477                 result_descriptor =
    478                                 usb_ohci_rh_create_standard_endpoint_descriptor();
    479                 size = sizeof(usb_standard_endpoint_descriptor_t);
    480         }else{
    481                 usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
    482                 usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
    483                                 setup_request->request_type,
    484                                 setup_request->request,
    485                                 setup_request_value,
    486                                 setup_request->index,
    487                                 setup_request->length
    488                                 );
    489                 return EINVAL;
     330                case USB_DESCTYPE_HUB: {
     331                        uint8_t * descriptor;
     332                        usb_create_serialized_hub_descriptor(
     333                                instance, &descriptor, &size);
     334                        result_descriptor = descriptor;
     335                        if(result_descriptor) del = true;
     336                        break;
     337                }
     338                case USB_DESCTYPE_DEVICE: {
     339                        usb_log_debug("USB_DESCTYPE_DEVICE\n");
     340                        result_descriptor = &ohci_rh_device_descriptor;
     341                        size = sizeof(ohci_rh_device_descriptor);
     342                        break;
     343                }
     344                case USB_DESCTYPE_CONFIGURATION: {
     345                        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;
     352                        break;
     353                }
     354                case USB_DESCTYPE_INTERFACE: {
     355                        usb_log_debug("USB_DESCTYPE_INTERFACE\n");
     356                        result_descriptor = &ohci_rh_iface_descriptor;
     357                        size = sizeof(ohci_rh_iface_descriptor);
     358                        break;
     359                }
     360                case USB_DESCTYPE_ENDPOINT: {
     361                        usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
     362                        result_descriptor = &ohci_rh_ep_descriptor;
     363                        size = sizeof(ohci_rh_ep_descriptor);
     364                        break;
     365                }
     366                default: {
     367                        usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
     368                        usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
     369                                        setup_request->request_type,
     370                                        setup_request->request,
     371                                        setup_request_value,
     372                                        setup_request->index,
     373                                        setup_request->length
     374                                        );
     375                        return EINVAL;
     376                }
    490377        }
    491378        if(request->buffer_size < size){
     
    494381        request->transfered_size = size;
    495382        memcpy(request->buffer,result_descriptor,size);
    496         if (result_descriptor)
     383        if (del)
    497384                free(result_descriptor);
    498385        return EOK;
     
    761648void rh_interrupt(rh_t *instance)
    762649{
    763         usb_log_info("Whoa whoa wait, I`m not supposed to receive interrupts, am I?\n");
     650        usb_log_info("Whoa whoa wait, I`m not supposed to receive any interrupts, am I?\n");
    764651        /* TODO: implement? */
    765652}
  • uspace/drv/ohci/root_hub.h

    rcee51fd rb330b309  
    4141#include "batch.h"
    4242
     43/**
     44 * ohci root hub representation
     45 */
    4346typedef struct rh {
     47        /** pointer to ohci driver registers */
    4448        ohci_regs_t *registers;
     49        /** usb address of the root hub */
    4550        usb_address_t address;
     51        /** ddf device information */
    4652        ddf_dev_t *device;
     53        /** hub port count */
    4754        int port_count;
    4855} rh_t;
  • uspace/drv/usbhub/port_status.h

    rcee51fd rb330b309  
    7979
    8080/**
     81 * set the device request to be a port feature enable request
     82 * @param request
     83 * @param port
     84 * @param feature_selector
     85 */
     86static inline void usb_hub_set_enable_port_feature_request(
     87usb_device_request_setup_packet_t * request, uint16_t port,
     88                uint16_t feature_selector
     89){
     90        request->index = port;
     91        request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
     92        request->request = USB_HUB_REQUEST_SET_FEATURE;
     93        request->value = feature_selector;
     94        request->length = 0;
     95}
     96
     97
     98/**
    8199 * set the device request to be a port enable request
    82100 * @param request
     
    191209        request->length = 0;
    192210}
     211
    193212
    194213/** get i`th bit of port status */
  • uspace/drv/usbhub/usbhub.c

    rcee51fd rb330b309  
    5353#include "usb/classes/classes.h"
    5454
     55
    5556static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    5657                usb_speed_t speed);
    5758
    58 static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
    59 usb_hub_descriptor_t * descriptor);
    60 
     59static int usb_hub_trigger_connecting_non_removable_devices(
     60                usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor);
     61
     62/**
     63 * control loop running in hub`s fibril
     64 *
     65 * Hub`s fibril periodically asks for changes on hub and if needded calls
     66 * change handling routine.
     67 * @warning currently hub driver asks for changes once a second
     68 * @param hub_info_param hub representation pointer
     69 * @return zero
     70 */
    6171int usb_hub_control_loop(void * hub_info_param){
    6272        usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
     
    103113 * This function is hub-specific and should be run only after the hub is
    104114 * configured using usb_hub_set_configuration function.
    105  * @param hub_info pointer to structure with usb hub data
     115 * @param hub_info hub representation
    106116 * @return error code
    107117 */
     
    149159                hub_info->attached_devs[i].address=0;
    150160        }
    151         usb_hub_attach_non_removable_devices(hub_info, descriptor);
     161        //handle non-removable devices
     162        usb_hub_trigger_connecting_non_removable_devices(hub_info, descriptor);
    152163        usb_log_debug2("freeing data\n");
    153164        free(serialized_descriptor);
     
    161172 * Check whether there is at least one configuration and sets the first one.
    162173 * This function should be run prior to running any hub-specific action.
    163  * @param hub_info
    164  * @return
     174 * @param hub_info hub representation
     175 * @return error code
    165176 */
    166177static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
     
    270281
    271282/**
    272  * Perform \a usb_hub_init_add_device on all ports with non-removable device
     283 * triggers actions to connect non0removable devices
    273284 *
    274285 * This will trigger operations leading to activated non-removable device.
    275286 * Control pipe of the hub must be open fo communication.
    276  * @param hub hub instance
     287 * @param hub hub representation
    277288 * @param descriptor usb hub descriptor
    278289 * @return error code
    279290 */
    280 static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
     291static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub,
    281292                usb_hub_descriptor_t * descriptor)
    282293{
     
    287298        usb_port_status_t status;
    288299        uint8_t * non_removable_dev_bitmap = descriptor->devices_removable;
    289         //initialize all connected, non-removable devices
    290300        int port;
    291301        for(port=1;port<=descriptor->ports_count;++port){
     
    305315                                return opResult;
    306316                        }
    307                         //this should be true..
     317                        //set the status change bit, so it will be noticed in driver loop
    308318                        if(usb_port_dev_connected(&status)){
    309                                 usb_hub_init_add_device(hub,port,usb_port_speed(&status));
     319                                usb_hub_set_enable_port_feature_request(&request, port,
     320                                                USB_HUB_FEATURE_C_PORT_CONNECTION);
     321                                opResult = usb_pipe_control_read(
     322                                                hub->control_pipe,
     323                                                &request, sizeof(usb_device_request_setup_packet_t),
     324                                                &status, 4, &rcvd_size
     325                                                );
     326                                if (opResult != EOK) {
     327                                        usb_log_warning(
     328                                                        "could not set port change on port %d errno:%d\n",
     329                                                        port, opResult);
     330                                }
    310331                        }
    311332                }
     
    335356/**
    336357 * Reset the port with new device and reserve the default address.
    337  * @param hc
    338  * @param port
    339  * @param target
     358 * @param hub hub representation
     359 * @param port port number, starting from 1
     360 * @param speed transfer speed of attached device, one of low, full or high
    340361 */
    341362static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     
    370391        if (opResult != EOK) {
    371392                usb_log_error("something went wrong when reseting a port %d\n",opResult);
    372                 //usb_hub_release_default_address(hc);
    373393                usb_hub_release_default_address(hub);
    374394        }
     
    378398/**
    379399 * Finalize adding new device after port reset
    380  * @param hc
    381  * @param port
    382  * @param target
     400 *
     401 * Set device`s address and start it`s driver.
     402 * @param hub hub representation
     403 * @param port port number, starting from 1
     404 * @param speed transfer speed of attached device, one of low, full or high
    383405 */
    384406static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
     
    430452        }
    431453
    432 
    433454        //opResult = usb_hub_release_default_address(hc);
    434455        opResult = usb_hub_release_default_address(hub);
     
    465486
    466487/**
    467  * Unregister device address in hc
    468  * @param hc
    469  * @param port
    470  * @param target
     488 * routine called when a device on port has been removed
     489 *
     490 * If the device on port had default address, it releases default address.
     491 * Otherwise does not do anything, because DDF does not allow to remove device
     492 * from it`s device tree.
     493 * @param hub hub representation
     494 * @param port port number, starting from 1
    471495 */
    472496static void usb_hub_removed_device(
     
    507531 * Turn off the power on the port.
    508532 *
    509  * @param hub
    510  * @param port
     533 * @param hub hub representation
     534 * @param port port number, starting from 1
    511535 */
    512536static void usb_hub_over_current( usb_hub_info_t * hub,
     
    523547/**
    524548 * Process interrupts on given hub port
    525  * @param hc
    526  * @param port
    527  * @param target
     549 *
     550 * Accepts connection, over current and port reset change.
     551 * @param hub hub representation
     552 * @param port port number, starting from 1
    528553 */
    529554static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     
    596621
    597622/**
    598  * Check changes on particular hub
    599  * @param hub_info_param pointer to usb_hub_info_t structure
    600  * @return error code if there is problem when initializing communication with
    601  * hub, EOK otherwise
     623 * check changes on hub
     624 *
     625 * Handles changes on each port with a status change.
     626 * @param hub_info hub representation
     627 * @return error code
    602628 */
    603629int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
Note: See TracChangeset for help on using the changeset viewer.