Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    r6986418 rf40a1e2  
    4646#include "usbhub_private.h"
    4747#include "port_status.h"
     48#include "usb/usb.h"
    4849
    4950static usb_iface_t hub_usb_iface = {
     
    7576        //get some hub info
    7677        usb_address_t addr = usb_drv_get_my_address(hc, device);
    77         dprintf(1,"[usb_hub] addres of newly created hub = %d", addr);
     78        dprintf(1,"[usb_hub] address of newly created hub = %d", addr);
    7879        /*if(addr<0){
    7980                //return result;
     
    8586
    8687        // get hub descriptor
    87         usb_target_t target;
    88         target.address = addr;
    89         target.endpoint = 0;
    90         usb_device_request_setup_packet_t request;
    91         //printf("[usb_hub] creating descriptor request\n");
    92         usb_hub_set_descriptor_request(&request);
    9388
    9489        //printf("[usb_hub] creating serialized descriptor\n");
     
    9893        int opResult;
    9994        //printf("[usb_hub] starting control transaction\n");
    100         opResult = usb_drv_sync_control_read(
    101                         hc, target, &request, serialized_descriptor,
     95       
     96        opResult = usb_drv_req_get_descriptor(hc, addr,
     97                        USB_REQUEST_TYPE_CLASS,
     98                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    10299                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     100
    103101        if (opResult != EOK) {
    104102                dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult);
     
    155153        int port;
    156154        int opResult;
    157         usb_device_request_setup_packet_t request;
    158155        usb_target_t target;
    159156        target.address = hub_info->usb_device->address;
     
    173170        if(std_descriptor.configuration_count<1){
    174171                dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE");
    175         }
     172                //shouldn`t I return?
     173        }
     174        /// \TODO check other configurations
    176175        usb_standard_configuration_descriptor_t config_descriptor;
    177176        opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
     
    183182        }
    184183        //set configuration
    185         request.request_type = 0;
    186         request.request = USB_DEVREQ_SET_CONFIGURATION;
    187         request.index=0;
    188         request.length=0;
    189         request.value_high=0;
    190         request.value_low = config_descriptor.configuration_number;
    191         opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
     184        opResult = usb_drv_req_set_configuration(hc, target.address,
     185    config_descriptor.configuration_number);
     186
    192187        if (opResult != EOK) {
    193188                dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult);
    194189        }
    195190
    196 
     191        usb_device_request_setup_packet_t request;
    197192        for (port = 1; port < hub_info->port_count+1; ++port) {
    198193                usb_hub_set_power_port_request(&request, port);
     
    205200        //ports powered, hub seems to be enabled
    206201
    207 
    208202        ipc_hangup(hc);
    209203
    210204        //add the hub to list
     205        futex_down(&usb_hub_list_lock);
    211206        usb_lst_append(&usb_hub_list, hub_info);
     207        futex_up(&usb_hub_list_lock);
     208
    212209        dprintf(1,"[usb_hub] hub info added to list");
    213210        //(void)hub_info;
     
    227224
    228225
    229 
    230226//*********************************************
    231227//
     
    235231
    236232/**
    237  * reset the port with new device and reserve the default address
     233 * Convenience function for releasing default address and writing debug info
     234 * (these few lines are used too often to be written again and again).
     235 * @param hc
     236 * @return
     237 */
     238inline static int usb_hub_release_default_address(int hc){
     239        int opResult;
     240        dprintf(1,"[usb_hub] releasing default address");
     241        opResult = usb_drv_release_default_address(hc);
     242        if (opResult != EOK) {
     243                dprintf(1,"[usb_hub] failed to release default address");
     244        }
     245        return opResult;
     246}
     247
     248/**
     249 * Reset the port with new device and reserve the default address.
    238250 * @param hc
    239251 * @param port
     
    259271        if (opResult != EOK) {
    260272                dprintf(1,"[usb_hub] something went wrong when reseting a port");
    261         }
    262 }
    263 
    264 /**
    265  * convenience function for releasing default address and writing debug info
    266  * (these few lines are used too often to be written again and again)
    267  * @param hc
    268  * @return
    269  */
    270 inline static int usb_hub_release_default_address(int hc){
    271         int opResult;
    272         dprintf(1,"[usb_hub] releasing default address");
    273         opResult = usb_drv_release_default_address(hc);
    274         if (opResult != EOK) {
    275                 dprintf(1,"[usb_hub] failed to release default address");
    276         }
    277         return opResult;
    278 }
    279 
    280 
    281 /**
    282  * finalize adding new device after port reset
     273                usb_hub_release_default_address(hc);
     274        }
     275}
     276
     277/**
     278 * Finalize adding new device after port reset
    283279 * @param hc
    284280 * @param port
     
    343339
    344340/**
    345  * unregister device address in hc, close the port
     341 * Unregister device address in hc
    346342 * @param hc
    347343 * @param port
     
    352348        //usb_device_request_setup_packet_t request;
    353349        int opResult;
    354         //disable port
    355         /*usb_hub_set_disable_port_request(&request, port);
    356         opResult = usb_drv_sync_control_write(
    357                         hc, target,
    358                         &request,
    359                         NULL, 0
    360                         );
    361         if (opResult != EOK) {
    362                 //continue;
    363                 printf("[usb_hub] something went wrong when disabling a port\n");
    364         }*/
    365         /// \TODO remove device
     350       
     351        /** \TODO remove device from device manager - not yet implemented in
     352         * devide manager
     353         */
    366354
    367355        hub->attached_devs[port].devman_handle=0;
     
    384372
    385373/**
    386  * process interrupts on given hub port
     374 * Process interrupts on given hub port
    387375 * @param hc
    388376 * @param port
     
    442430        usb_port_set_reset_completed(&status, false);
    443431        usb_port_set_dev_connected(&status, false);
    444         if (status) {
    445                 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port);
     432        if (status>>16) {
     433                dprintf(1,"[usb_hub]there was some unsupported change on port %d: %X",port,status);
     434
    446435        }
    447436        /// \TODO handle other changes
     
    450439}
    451440
    452 /* Check changes on all known hubs.
     441/**
     442 * Check changes on all known hubs.
    453443 */
    454444void usb_hub_check_hub_changes(void) {
     
    457447         */
    458448        usb_general_list_t * lst_item;
     449        futex_down(&usb_hub_list_lock);
    459450        for (lst_item = usb_hub_list.next;
    460451                        lst_item != &usb_hub_list;
    461452                        lst_item = lst_item->next) {
     453                futex_up(&usb_hub_list_lock);
    462454                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    463455                /*
     
    468460                target.address = hub_info->usb_device->address;
    469461                target.endpoint = 1;/// \TODO get from endpoint descriptor
    470                 /*dprintf(1,"[usb_hub] checking changes for hub at addr %d",
    471                     target.address);*/
     462                dprintf(1,"[usb_hub] checking changes for hub at addr %d",
     463                    target.address);
    472464
    473465                size_t port_count = hub_info->port_count;
     
    510502                        }
    511503                }
     504                free(change_bitmap);
    512505
    513506                ipc_hangup(hc);
    514         }
     507                futex_down(&usb_hub_list_lock);
     508        }
     509        futex_up(&usb_hub_list_lock);
    515510}
    516511
Note: See TracChangeset for help on using the changeset viewer.