Ignore:
File:
1 edited

Legend:

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

    r5097bed4 r281ebae  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb hub driver
     28/** @addtogroup drvusbhub
    2929 * @{
    3030 */
     
    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] address of newly created hub = %d", addr);
     78        dprintf(1, "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);
    103         if (opResult != EOK) {
    104                 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult);
     100
     101        if (opResult != EOK) {
     102                dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult);
    105103                free(serialized_descriptor);
    106104                return result;
     
    109107        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    110108        if(descriptor==NULL){
    111                 dprintf(1,"[usb_hub] could not deserialize descriptor ");
     109                dprintf(1, "could not deserialize descriptor ");
    112110                result->port_count = 1;///\TODO this code is only for debug!!!
    113111                return result;
     
    129127        //finish
    130128
    131         dprintf(1,"[usb_hub] hub info created");
     129        dprintf(1, "hub info created");
    132130
    133131        return result;
     
    136134int usb_add_hub_device(device_t *dev) {
    137135        dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle);
    138         dprintf(1,"[usb_hub] hub device");
     136        dprintf(1, "hub device");
    139137
    140138        /*
     
    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;
     
    165162        usb_standard_device_descriptor_t std_descriptor;
    166163        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    167     &std_descriptor);
     164            &std_descriptor);
    168165        if(opResult!=EOK){
    169                 dprintf(1,"[usb_hub] could not get device descriptor, %d",opResult);
     166                dprintf(1, "could not get device descriptor, %d",opResult);
    170167                return opResult;
    171168        }
    172         dprintf(1,"[usb_hub] hub has %d configurations",std_descriptor.configuration_count);
     169        dprintf(1, "hub has %d configurations",std_descriptor.configuration_count);
    173170        if(std_descriptor.configuration_count<1){
    174                 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE");
     171                dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE");
     172                //shouldn`t I return?
    175173        }
    176174        /// \TODO check other configurations
     
    180178        &config_descriptor);
    181179        if(opResult!=EOK){
    182                 dprintf(1,"[usb_hub] could not get configuration descriptor, %d",opResult);
     180                dprintf(1, "could not get configuration descriptor, %d",opResult);
    183181                return opResult;
    184182        }
    185183        //set configuration
    186         request.request_type = 0;
    187         request.request = USB_DEVREQ_SET_CONFIGURATION;
    188         request.index=0;
    189         request.length=0;
    190         request.value_high=0;
    191         request.value_low = config_descriptor.configuration_number;
    192         opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    193         if (opResult != EOK) {
    194                 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult);
    195         }
    196 
     184        opResult = usb_drv_req_set_configuration(hc, target.address,
     185    config_descriptor.configuration_number);
     186
     187        if (opResult != EOK) {
     188                dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult);
     189        }
     190
     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);
    199194                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    200                 dprintf(1,"[usb_hub] powering port %d",port);
     195                dprintf(1, "powering port %d",port);
    201196                if (opResult != EOK) {
    202                         dprintf(1,"[usb_hub]something went wrong when setting hub`s %dth port", port);
     197                        dprintf(1, "something went wrong when setting hub`s %dth port", port);
    203198                }
    204199        }
     
    212207        futex_up(&usb_hub_list_lock);
    213208
    214         dprintf(1,"[usb_hub] hub info added to list");
     209        dprintf(1, "hub info added to list");
    215210        //(void)hub_info;
    216211        usb_hub_check_hub_changes();
     
    218213       
    219214
    220         dprintf(1,"[usb_hub] hub dev added");
    221         dprintf(1,"\taddress %d, has %d ports ",
     215        dprintf(1, "hub dev added");
     216        dprintf(1, "\taddress %d, has %d ports ",
    222217                        hub_info->usb_device->address,
    223218                        hub_info->port_count);
    224         dprintf(1,"\tused configuration %d",config_descriptor.configuration_number);
     219        dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);
    225220
    226221        return EOK;
    227222        //return ENOTSUP;
    228223}
    229 
    230224
    231225
     
    237231
    238232/**
    239  * convenience function for releasing default address and writing debug info
    240  * (these few lines are used too often to be written again and again)
     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).
    241235 * @param hc
    242236 * @return
     
    244238inline static int usb_hub_release_default_address(int hc){
    245239        int opResult;
    246         dprintf(1,"[usb_hub] releasing default address");
     240        dprintf(1, "releasing default address");
    247241        opResult = usb_drv_release_default_address(hc);
    248242        if (opResult != EOK) {
    249                 dprintf(1,"[usb_hub] failed to release default address");
     243                dprintf(1, "failed to release default address");
    250244        }
    251245        return opResult;
     
    253247
    254248/**
    255  * reset the port with new device and reserve the default address
     249 * Reset the port with new device and reserve the default address.
    256250 * @param hc
    257251 * @param port
     
    261255        usb_device_request_setup_packet_t request;
    262256        int opResult;
    263         dprintf(1,"[usb_hub] some connection changed");
     257        dprintf(1, "some connection changed");
    264258        //get default address
    265259        opResult = usb_drv_reserve_default_address(hc);
    266260        if (opResult != EOK) {
    267                 dprintf(1,"[usb_hub] cannot assign default address, it is probably used");
     261                dprintf(1, "cannot assign default address, it is probably used");
    268262                return;
    269263        }
     
    276270                        );
    277271        if (opResult != EOK) {
    278                 dprintf(1,"[usb_hub] something went wrong when reseting a port");
     272                dprintf(1, "something went wrong when reseting a port");
    279273                usb_hub_release_default_address(hc);
    280274        }
     
    282276
    283277/**
    284  * finalize adding new device after port reset
     278 * Finalize adding new device after port reset
    285279 * @param hc
    286280 * @param port
     
    291285
    292286        int opResult;
    293         dprintf(1,"[usb_hub] finalizing add device");
     287        dprintf(1, "finalizing add device");
    294288        opResult = usb_hub_clear_port_feature(hc, target.address,
    295289            port, USB_HUB_FEATURE_C_PORT_RESET);
    296290        if (opResult != EOK) {
    297                 dprintf(1,"[usb_hub] failed to clear port reset feature");
     291                dprintf(1, "failed to clear port reset feature");
    298292                usb_hub_release_default_address(hc);
    299293                return;
     
    303297        usb_address_t new_device_address = usb_drv_request_address(hc);
    304298        if (new_device_address < 0) {
    305                 dprintf(1,"[usb_hub] failed to get free USB address");
     299                dprintf(1, "failed to get free USB address");
    306300                opResult = new_device_address;
    307301                usb_hub_release_default_address(hc);
    308302                return;
    309303        }
    310         dprintf(1,"[usb_hub] setting new address");
     304        dprintf(1, "setting new address");
    311305        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    312306            new_device_address);
    313307
    314308        if (opResult != EOK) {
    315                 dprintf(1,"[usb_hub] could not set address for new device");
     309                dprintf(1, "could not set address for new device");
    316310                usb_hub_release_default_address(hc);
    317311                return;
     
    328322            new_device_address, &child_handle);
    329323        if (opResult != EOK) {
    330                 dprintf(1,"[usb_hub] could not start driver for new device");
     324                dprintf(1, "could not start driver for new device");
    331325                return;
    332326        }
     
    336330        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    337331        if (opResult != EOK) {
    338                 dprintf(1,"[usb_hub] could not assign address of device in hcd");
    339                 return;
    340         }
    341         dprintf(1,"[usb_hub] new device address %d, handle %zu",
     332                dprintf(1, "could not assign address of device in hcd");
     333                return;
     334        }
     335        dprintf(1, "new device address %d, handle %zu",
    342336            new_device_address, child_handle);
    343337
     
    345339
    346340/**
    347  * unregister device address in hc
     341 * Unregister device address in hc
    348342 * @param hc
    349343 * @param port
     
    355349        int opResult;
    356350       
    357         /// \TODO remove device
     351        /** \TODO remove device from device manager - not yet implemented in
     352         * devide manager
     353         */
    358354
    359355        hub->attached_devs[port].devman_handle=0;
     
    362358                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    363359                if(opResult != EOK) {
    364                         dprintf(1,
    365                                         "[usb_hub] could not release address of removed device: %d"
    366                                         ,opResult);
     360                        dprintf(1, "could not release address of " \
     361                            "removed device: %d", opResult);
    367362                }
    368363                hub->attached_devs[port].address = 0;
    369364        }else{
    370                 dprintf(1,
    371                                 "[usb_hub] this is strange, disconnected device had no address");
     365                dprintf(1, "this is strange, disconnected device had no address");
    372366                //device was disconnected before it`s port was reset - return default address
    373367                usb_drv_release_default_address(hc);
     
    376370
    377371/**
    378  * process interrupts on given hub port
     372 * Process interrupts on given hub port
    379373 * @param hc
    380374 * @param port
     
    383377static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    384378        uint16_t port, usb_address_t address) {
    385         dprintf(1,"[usb_hub] interrupt at port %d", port);
     379        dprintf(1, "interrupt at port %d", port);
    386380        //determine type of change
    387381        usb_target_t target;
     
    401395                        );
    402396        if (opResult != EOK) {
    403                 dprintf(1,"[usb_hub] ERROR: could not get port status");
     397                dprintf(1, "ERROR: could not get port status");
    404398                return;
    405399        }
    406400        if (rcvd_size != sizeof (usb_port_status_t)) {
    407                 dprintf(1,"[usb_hub] ERROR: received status has incorrect size");
     401                dprintf(1, "ERROR: received status has incorrect size");
    408402                return;
    409403        }
     
    414408                // TODO: check opResult
    415409                if (usb_port_dev_connected(&status)) {
    416                         dprintf(1,"[usb_hub] some connection changed");
     410                        dprintf(1, "some connection changed");
    417411                        usb_hub_init_add_device(hc, port, target);
    418412                } else {
     
    422416        //port reset
    423417        if (usb_port_reset_completed(&status)) {
    424                 dprintf(1,"[usb_hub] port reset complete");
     418                dprintf(1, "port reset complete");
    425419                if (usb_port_enabled(&status)) {
    426420                        usb_hub_finalize_add_device(hub, hc, port, target);
    427421                } else {
    428                         dprintf(1,"[usb_hub] ERROR: port reset, but port still not enabled");
     422                        dprintf(1, "ERROR: port reset, but port still not enabled");
    429423                }
    430424        }
     
    434428        usb_port_set_reset_completed(&status, false);
    435429        usb_port_set_dev_connected(&status, false);
    436         if (status) {
    437                 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port);
     430        if (status>>16) {
     431                dprintf(1, "there was some unsupported change on port %d: %X",port,status);
     432
    438433        }
    439434        /// \TODO handle other changes
     
    442437}
    443438
    444 /* Check changes on all known hubs.
     439/**
     440 * Check changes on all known hubs.
    445441 */
    446442void usb_hub_check_hub_changes(void) {
     
    462458                target.address = hub_info->usb_device->address;
    463459                target.endpoint = 1;/// \TODO get from endpoint descriptor
    464                 dprintf(1,"[usb_hub] checking changes for hub at addr %d",
     460                dprintf(1, "checking changes for hub at addr %d",
    465461                    target.address);
    466462
     
    492488
    493489                if (opResult != EOK) {
    494                         dprintf(1,"[usb_hub] something went wrong while getting status of hub");
     490                        dprintf(1, "something went wrong while getting status of hub");
    495491                        continue;
    496492                }
Note: See TracChangeset for help on using the changeset viewer.