Changes in / [b330b309:cee51fd] in mainline


Ignore:
Location:
uspace/drv
Files:
4 edited

Legend:

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

    rb330b309 rcee51fd  
    4343#include <usb/classes/hub.h>
    4444
    45 /**
    46  *      standart device descriptor for ohci root hub
    47  */
    4845static const usb_standard_device_descriptor_t ohci_rh_device_descriptor =
    4946{
     
    6461};
    6562
    66 /**
    67  * standart configuration descriptor with filled common values
    68  * for ohci root hubs
    69  */
    7063static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor =
    7164{
     
    8073};
    8174
    82 /**
    83  * standart ohci root hub interface descriptor
    84  */
    8575static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor =
    8676{
     
    9787};
    9888
    99 /**
    100  * standart ohci root hub endpoint descriptor
    101  */
    10289static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor =
    10390{
     
    286273
    287274/**
     275 * create standard device descriptor for a hub
     276 * @return newly allocated descriptor
     277 */
     278static 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/**
    288302 * create standart configuration descriptor for the root hub instance
    289303 * @param instance root hub instance
     
    293307usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    294308        usb_standard_configuration_descriptor_t * descriptor =
     309                        (usb_standard_configuration_descriptor_t*)
    295310                        malloc(sizeof(usb_standard_configuration_descriptor_t));
    296         memcpy(descriptor, &ohci_rh_conf_descriptor,
    297                 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;
    298319        /// \TODO should this include device descriptor?
    299         const size_t hub_descriptor_size = 7 +
     320        size_t hub_descriptor_size = 7 +
    300321                        2* (instance->port_count / 8 +
    301322                        ((instance->port_count % 8 > 0) ? 1 : 0));
     
    309330
    310331/**
     332 * create standard interface descriptor for a root hub
     333 * @return newly allocated descriptor
     334 */
     335static usb_standard_interface_descriptor_t *
     336usb_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 */
     357static usb_standard_endpoint_descriptor_t *
     358usb_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/**
    311372 * create answer to a descriptor request
    312373 *
     
    325386        const uint16_t setup_request_value = setup_request->value_high;
    326387                        //(setup_request->value_low << 8);
     388#if 0
    327389        bool del = false;
     390        //this code was merged from development and has to be reviewed
    328391        switch (setup_request_value)
    329392        {
    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                 }
     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;
    377490        }
    378491        if(request->buffer_size < size){
     
    381494        request->transfered_size = size;
    382495        memcpy(request->buffer,result_descriptor,size);
    383         if (del)
     496        if (result_descriptor)
    384497                free(result_descriptor);
    385498        return EOK;
     
    648761void rh_interrupt(rh_t *instance)
    649762{
    650         usb_log_info("Whoa whoa wait, I`m not supposed to receive any interrupts, am I?\n");
     763        usb_log_info("Whoa whoa wait, I`m not supposed to receive interrupts, am I?\n");
    651764        /* TODO: implement? */
    652765}
  • uspace/drv/ohci/root_hub.h

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

    rb330b309 rcee51fd  
    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  */
    86 static inline void usb_hub_set_enable_port_feature_request(
    87 usb_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 /**
    9981 * set the device request to be a port enable request
    10082 * @param request
     
    209191        request->length = 0;
    210192}
    211 
    212193
    213194/** get i`th bit of port status */
  • uspace/drv/usbhub/usbhub.c

    rb330b309 rcee51fd  
    5353#include "usb/classes/classes.h"
    5454
    55 
    5655static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    5756                usb_speed_t speed);
    5857
    59 static 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  */
     58static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
     59usb_hub_descriptor_t * descriptor);
     60
    7161int usb_hub_control_loop(void * hub_info_param){
    7262        usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
     
    113103 * This function is hub-specific and should be run only after the hub is
    114104 * configured using usb_hub_set_configuration function.
    115  * @param hub_info hub representation
     105 * @param hub_info pointer to structure with usb hub data
    116106 * @return error code
    117107 */
     
    159149                hub_info->attached_devs[i].address=0;
    160150        }
    161         //handle non-removable devices
    162         usb_hub_trigger_connecting_non_removable_devices(hub_info, descriptor);
     151        usb_hub_attach_non_removable_devices(hub_info, descriptor);
    163152        usb_log_debug2("freeing data\n");
    164153        free(serialized_descriptor);
     
    172161 * Check whether there is at least one configuration and sets the first one.
    173162 * This function should be run prior to running any hub-specific action.
    174  * @param hub_info hub representation
    175  * @return error code
     163 * @param hub_info
     164 * @return
    176165 */
    177166static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
     
    281270
    282271/**
    283  * triggers actions to connect non0removable devices
     272 * Perform \a usb_hub_init_add_device on all ports with non-removable device
    284273 *
    285274 * This will trigger operations leading to activated non-removable device.
    286275 * Control pipe of the hub must be open fo communication.
    287  * @param hub hub representation
     276 * @param hub hub instance
    288277 * @param descriptor usb hub descriptor
    289278 * @return error code
    290279 */
    291 static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub,
     280static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
    292281                usb_hub_descriptor_t * descriptor)
    293282{
     
    298287        usb_port_status_t status;
    299288        uint8_t * non_removable_dev_bitmap = descriptor->devices_removable;
     289        //initialize all connected, non-removable devices
    300290        int port;
    301291        for(port=1;port<=descriptor->ports_count;++port){
     
    315305                                return opResult;
    316306                        }
    317                         //set the status change bit, so it will be noticed in driver loop
     307                        //this should be true..
    318308                        if(usb_port_dev_connected(&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                                 }
     309                                usb_hub_init_add_device(hub,port,usb_port_speed(&status));
    331310                        }
    332311                }
     
    356335/**
    357336 * Reset the port with new device and reserve the default address.
    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
     337 * @param hc
     338 * @param port
     339 * @param target
    361340 */
    362341static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     
    391370        if (opResult != EOK) {
    392371                usb_log_error("something went wrong when reseting a port %d\n",opResult);
     372                //usb_hub_release_default_address(hc);
    393373                usb_hub_release_default_address(hub);
    394374        }
     
    398378/**
    399379 * Finalize adding new device after port reset
    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
     380 * @param hc
     381 * @param port
     382 * @param target
    405383 */
    406384static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
     
    452430        }
    453431
     432
    454433        //opResult = usb_hub_release_default_address(hc);
    455434        opResult = usb_hub_release_default_address(hub);
     
    486465
    487466/**
    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
     467 * Unregister device address in hc
     468 * @param hc
     469 * @param port
     470 * @param target
    495471 */
    496472static void usb_hub_removed_device(
     
    531507 * Turn off the power on the port.
    532508 *
    533  * @param hub hub representation
    534  * @param port port number, starting from 1
     509 * @param hub
     510 * @param port
    535511 */
    536512static void usb_hub_over_current( usb_hub_info_t * hub,
     
    547523/**
    548524 * Process interrupts on given hub port
    549  *
    550  * Accepts connection, over current and port reset change.
    551  * @param hub hub representation
    552  * @param port port number, starting from 1
     525 * @param hc
     526 * @param port
     527 * @param target
    553528 */
    554529static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     
    621596
    622597/**
    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
     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
    628602 */
    629603int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
Note: See TracChangeset for help on using the changeset viewer.