Ignore:
File:
1 edited

Legend:

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

    r281ebae r5097bed4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbhub
     28/** @addtogroup usb hub driver
    2929 * @{
    3030 */
     
    4646#include "usbhub_private.h"
    4747#include "port_status.h"
    48 #include "usb/usb.h"
    4948
    5049static usb_iface_t hub_usb_iface = {
     
    7675        //get some hub info
    7776        usb_address_t addr = usb_drv_get_my_address(hc, device);
    78         dprintf(1, "address of newly created hub = %d", addr);
     77        dprintf(1,"[usb_hub] address of newly created hub = %d", addr);
    7978        /*if(addr<0){
    8079                //return result;
     
    8685
    8786        // 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);
    8893
    8994        //printf("[usb_hub] creating serialized descriptor\n");
     
    9398        int opResult;
    9499        //printf("[usb_hub] starting control transaction\n");
    95        
    96         opResult = usb_drv_req_get_descriptor(hc, addr,
    97                         USB_REQUEST_TYPE_CLASS,
    98                         USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
     100        opResult = usb_drv_sync_control_read(
     101                        hc, target, &request, serialized_descriptor,
    99102                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    100 
    101         if (opResult != EOK) {
    102                 dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult);
     103        if (opResult != EOK) {
     104                dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult);
    103105                free(serialized_descriptor);
    104106                return result;
     
    107109        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    108110        if(descriptor==NULL){
    109                 dprintf(1, "could not deserialize descriptor ");
     111                dprintf(1,"[usb_hub] could not deserialize descriptor ");
    110112                result->port_count = 1;///\TODO this code is only for debug!!!
    111113                return result;
     
    127129        //finish
    128130
    129         dprintf(1, "hub info created");
     131        dprintf(1,"[usb_hub] hub info created");
    130132
    131133        return result;
     
    134136int usb_add_hub_device(device_t *dev) {
    135137        dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle);
    136         dprintf(1, "hub device");
     138        dprintf(1,"[usb_hub] hub device");
    137139
    138140        /*
     
    153155        int port;
    154156        int opResult;
     157        usb_device_request_setup_packet_t request;
    155158        usb_target_t target;
    156159        target.address = hub_info->usb_device->address;
     
    162165        usb_standard_device_descriptor_t std_descriptor;
    163166        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    164             &std_descriptor);
     167    &std_descriptor);
    165168        if(opResult!=EOK){
    166                 dprintf(1, "could not get device descriptor, %d",opResult);
     169                dprintf(1,"[usb_hub] could not get device descriptor, %d",opResult);
    167170                return opResult;
    168171        }
    169         dprintf(1, "hub has %d configurations",std_descriptor.configuration_count);
     172        dprintf(1,"[usb_hub] hub has %d configurations",std_descriptor.configuration_count);
    170173        if(std_descriptor.configuration_count<1){
    171                 dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE");
    172                 //shouldn`t I return?
     174                dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE");
    173175        }
    174176        /// \TODO check other configurations
     
    178180        &config_descriptor);
    179181        if(opResult!=EOK){
    180                 dprintf(1, "could not get configuration descriptor, %d",opResult);
     182                dprintf(1,"[usb_hub] could not get configuration descriptor, %d",opResult);
    181183                return opResult;
    182184        }
    183185        //set configuration
    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;
     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
    192197        for (port = 1; port < hub_info->port_count+1; ++port) {
    193198                usb_hub_set_power_port_request(&request, port);
    194199                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    195                 dprintf(1, "powering port %d",port);
     200                dprintf(1,"[usb_hub] powering port %d",port);
    196201                if (opResult != EOK) {
    197                         dprintf(1, "something went wrong when setting hub`s %dth port", port);
     202                        dprintf(1,"[usb_hub]something went wrong when setting hub`s %dth port", port);
    198203                }
    199204        }
     
    207212        futex_up(&usb_hub_list_lock);
    208213
    209         dprintf(1, "hub info added to list");
     214        dprintf(1,"[usb_hub] hub info added to list");
    210215        //(void)hub_info;
    211216        usb_hub_check_hub_changes();
     
    213218       
    214219
    215         dprintf(1, "hub dev added");
    216         dprintf(1, "\taddress %d, has %d ports ",
     220        dprintf(1,"[usb_hub] hub dev added");
     221        dprintf(1,"\taddress %d, has %d ports ",
    217222                        hub_info->usb_device->address,
    218223                        hub_info->port_count);
    219         dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);
     224        dprintf(1,"\tused configuration %d",config_descriptor.configuration_number);
    220225
    221226        return EOK;
    222227        //return ENOTSUP;
    223228}
     229
    224230
    225231
     
    231237
    232238/**
    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).
     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)
    235241 * @param hc
    236242 * @return
     
    238244inline static int usb_hub_release_default_address(int hc){
    239245        int opResult;
    240         dprintf(1, "releasing default address");
     246        dprintf(1,"[usb_hub] releasing default address");
    241247        opResult = usb_drv_release_default_address(hc);
    242248        if (opResult != EOK) {
    243                 dprintf(1, "failed to release default address");
     249                dprintf(1,"[usb_hub] failed to release default address");
    244250        }
    245251        return opResult;
     
    247253
    248254/**
    249  * Reset the port with new device and reserve the default address.
     255 * reset the port with new device and reserve the default address
    250256 * @param hc
    251257 * @param port
     
    255261        usb_device_request_setup_packet_t request;
    256262        int opResult;
    257         dprintf(1, "some connection changed");
     263        dprintf(1,"[usb_hub] some connection changed");
    258264        //get default address
    259265        opResult = usb_drv_reserve_default_address(hc);
    260266        if (opResult != EOK) {
    261                 dprintf(1, "cannot assign default address, it is probably used");
     267                dprintf(1,"[usb_hub] cannot assign default address, it is probably used");
    262268                return;
    263269        }
     
    270276                        );
    271277        if (opResult != EOK) {
    272                 dprintf(1, "something went wrong when reseting a port");
     278                dprintf(1,"[usb_hub] something went wrong when reseting a port");
    273279                usb_hub_release_default_address(hc);
    274280        }
     
    276282
    277283/**
    278  * Finalize adding new device after port reset
     284 * finalize adding new device after port reset
    279285 * @param hc
    280286 * @param port
     
    285291
    286292        int opResult;
    287         dprintf(1, "finalizing add device");
     293        dprintf(1,"[usb_hub] finalizing add device");
    288294        opResult = usb_hub_clear_port_feature(hc, target.address,
    289295            port, USB_HUB_FEATURE_C_PORT_RESET);
    290296        if (opResult != EOK) {
    291                 dprintf(1, "failed to clear port reset feature");
     297                dprintf(1,"[usb_hub] failed to clear port reset feature");
    292298                usb_hub_release_default_address(hc);
    293299                return;
     
    297303        usb_address_t new_device_address = usb_drv_request_address(hc);
    298304        if (new_device_address < 0) {
    299                 dprintf(1, "failed to get free USB address");
     305                dprintf(1,"[usb_hub] failed to get free USB address");
    300306                opResult = new_device_address;
    301307                usb_hub_release_default_address(hc);
    302308                return;
    303309        }
    304         dprintf(1, "setting new address");
     310        dprintf(1,"[usb_hub] setting new address");
    305311        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    306312            new_device_address);
    307313
    308314        if (opResult != EOK) {
    309                 dprintf(1, "could not set address for new device");
     315                dprintf(1,"[usb_hub] could not set address for new device");
    310316                usb_hub_release_default_address(hc);
    311317                return;
     
    322328            new_device_address, &child_handle);
    323329        if (opResult != EOK) {
    324                 dprintf(1, "could not start driver for new device");
     330                dprintf(1,"[usb_hub] could not start driver for new device");
    325331                return;
    326332        }
     
    330336        opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    331337        if (opResult != EOK) {
    332                 dprintf(1, "could not assign address of device in hcd");
    333                 return;
    334         }
    335         dprintf(1, "new device address %d, handle %zu",
     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",
    336342            new_device_address, child_handle);
    337343
     
    339345
    340346/**
    341  * Unregister device address in hc
     347 * unregister device address in hc
    342348 * @param hc
    343349 * @param port
     
    349355        int opResult;
    350356       
    351         /** \TODO remove device from device manager - not yet implemented in
    352          * devide manager
    353          */
     357        /// \TODO remove device
    354358
    355359        hub->attached_devs[port].devman_handle=0;
     
    358362                opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
    359363                if(opResult != EOK) {
    360                         dprintf(1, "could not release address of " \
    361                             "removed device: %d", opResult);
     364                        dprintf(1,
     365                                        "[usb_hub] could not release address of removed device: %d"
     366                                        ,opResult);
    362367                }
    363368                hub->attached_devs[port].address = 0;
    364369        }else{
    365                 dprintf(1, "this is strange, disconnected device had no address");
     370                dprintf(1,
     371                                "[usb_hub] this is strange, disconnected device had no address");
    366372                //device was disconnected before it`s port was reset - return default address
    367373                usb_drv_release_default_address(hc);
     
    370376
    371377/**
    372  * Process interrupts on given hub port
     378 * process interrupts on given hub port
    373379 * @param hc
    374380 * @param port
     
    377383static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    378384        uint16_t port, usb_address_t address) {
    379         dprintf(1, "interrupt at port %d", port);
     385        dprintf(1,"[usb_hub] interrupt at port %d", port);
    380386        //determine type of change
    381387        usb_target_t target;
     
    395401                        );
    396402        if (opResult != EOK) {
    397                 dprintf(1, "ERROR: could not get port status");
     403                dprintf(1,"[usb_hub] ERROR: could not get port status");
    398404                return;
    399405        }
    400406        if (rcvd_size != sizeof (usb_port_status_t)) {
    401                 dprintf(1, "ERROR: received status has incorrect size");
     407                dprintf(1,"[usb_hub] ERROR: received status has incorrect size");
    402408                return;
    403409        }
     
    408414                // TODO: check opResult
    409415                if (usb_port_dev_connected(&status)) {
    410                         dprintf(1, "some connection changed");
     416                        dprintf(1,"[usb_hub] some connection changed");
    411417                        usb_hub_init_add_device(hc, port, target);
    412418                } else {
     
    416422        //port reset
    417423        if (usb_port_reset_completed(&status)) {
    418                 dprintf(1, "port reset complete");
     424                dprintf(1,"[usb_hub] port reset complete");
    419425                if (usb_port_enabled(&status)) {
    420426                        usb_hub_finalize_add_device(hub, hc, port, target);
    421427                } else {
    422                         dprintf(1, "ERROR: port reset, but port still not enabled");
     428                        dprintf(1,"[usb_hub] ERROR: port reset, but port still not enabled");
    423429                }
    424430        }
     
    428434        usb_port_set_reset_completed(&status, false);
    429435        usb_port_set_dev_connected(&status, false);
    430         if (status>>16) {
    431                 dprintf(1, "there was some unsupported change on port %d: %X",port,status);
    432 
     436        if (status) {
     437                dprintf(1,"[usb_hub]there was some unsupported change on port %d",port);
    433438        }
    434439        /// \TODO handle other changes
     
    437442}
    438443
    439 /**
    440  * Check changes on all known hubs.
     444/* Check changes on all known hubs.
    441445 */
    442446void usb_hub_check_hub_changes(void) {
     
    458462                target.address = hub_info->usb_device->address;
    459463                target.endpoint = 1;/// \TODO get from endpoint descriptor
    460                 dprintf(1, "checking changes for hub at addr %d",
     464                dprintf(1,"[usb_hub] checking changes for hub at addr %d",
    461465                    target.address);
    462466
     
    488492
    489493                if (opResult != EOK) {
    490                         dprintf(1, "something went wrong while getting status of hub");
     494                        dprintf(1,"[usb_hub] something went wrong while getting status of hub");
    491495                        continue;
    492496                }
Note: See TracChangeset for help on using the changeset viewer.