Changeset 6bb83c7 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-02-20T21:33:03Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
070f11e, 62066b4
Parents:
50ba203
Message:

usbhub uses new api, it is compilable. cannot guarantee functionality

File:
1 edited

Legend:

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

    r50ba203 r6bb83c7  
    6868usb_hub_info_t * usb_create_hub_info(device_t * device) {
    6969        usb_hub_info_t* result = usb_new(usb_hub_info_t);
    70         usb_device_connection_initialize_from_device(&result->connection, device);
     70        usb_device_connection_initialize_from_device(&result->device_connection,
     71                        device);
     72        usb_hc_connection_initialize_from_device(&result->connection,
     73                        device);
    7174        usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,
    72             &result->connection);
     75            &result->device_connection);
    7376       
    7477
     
    7881        result->device = device;
    7982
    80 <<<<<<< TREE
    81         result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     83        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    8284       
    83 =======
    84 
    85         dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
    86         if (hc < 0) {
    87                 return result;
    88         }
    89         //get some hub info
    90         usb_address_t addr = usb_drv_get_my_address(hc, device);
    91         dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
    92         /*if(addr<0){
    93                 //return result;
    94 
    95         }*/
    96 
    97         result->address = addr;
    98 
    99 >>>>>>> MERGE-SOURCE
    10085        // get hub descriptor
    10186
     
    134119        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    135120        result->port_count = descriptor->ports_count;
    136         result->attached_devs = (usb_hub_attached_device_t*)
    137             malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
     121        result->attached_devs = (usb_hc_attached_device_t*)
     122            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    138123        int i;
    139124        for(i=0;i<result->port_count+1;++i){
    140                 result->attached_devs[i].devman_handle=0;
     125                result->attached_devs[i].handle=0;
    141126                result->attached_devs[i].address=0;
    142127        }
     
    166151        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    167152        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     153
    168154        int port;
    169155        int opResult;
    170 <<<<<<< TREE
    171156        //usb_target_t target;
    172157        //target.address = hub_info->usb_device->address;
    173158        //target.endpoint = 0;
    174 =======
    175         usb_target_t target;
    176         target.address = hub_info->address;
    177         target.endpoint = 0;
    178 >>>>>>> MERGE-SOURCE
    179159
    180160        //get configuration descriptor
     
    237217
    238218        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     219        //address is lost...
    239220        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    240                         hub_info->address,
     221                        //hub_info->endpoints.control.,
    241222                        hub_info->port_count);
    242223        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    279260        int opResult;
    280261        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     262        assert(hub->endpoints.control.hc_phone);
    281263        //get default address
    282         ///////////////here ended pipe api upgrading
    283         gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld
    284         opResult = usb_drv_reserve_default_address(hc);
     264        //opResult = usb_drv_reserve_default_address(hc);
     265        opResult = usb_hc_reserve_default_address(&hub->connection, false);
    285266        if (opResult != EOK) {
    286267                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
     
    289270        //reset port
    290271        usb_hub_set_reset_port_request(&request, port);
    291         opResult = usb_drv_sync_control_write(
    292                         hc, target,
    293                         &request,
     272        opResult = usb_endpoint_pipe_control_write(
     273                        &hub->endpoints.control,
     274                        &request,sizeof(usb_device_request_setup_packet_t),
    294275                        NULL, 0
    295276                        );
    296277        if (opResult != EOK) {
    297278                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
    298                 usb_hub_release_default_address(hc);
     279                //usb_hub_release_default_address(hc);
     280                usb_hc_release_default_address(&hub->connection);
    299281        }
    300282}
     
    307289 */
    308290static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    309                 int hc, uint16_t port, usb_target_t target) {
     291                uint16_t port) {
    310292
    311293        int opResult;
    312294        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
    313         opResult = usb_hub_clear_port_feature(hc, target.address,
     295        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    314296            port, USB_HUB_FEATURE_C_PORT_RESET);
     297
    315298        if (opResult != EOK) {
    316299                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
    317                 usb_hub_release_default_address(hc);
    318                 return;
    319         }
    320 
    321         /* Request address at from host controller. */
    322         usb_address_t new_device_address = usb_drv_request_address(hc);
     300                usb_hc_release_default_address(&hub->connection);
     301                return;
     302        }
     303        //create connection to device
     304        usb_endpoint_pipe_t new_device_pipe;
     305        usb_device_connection_t new_device_connection;
     306        usb_device_connection_initialize_on_default_address(
     307                        &new_device_connection,
     308                        &hub->connection
     309                        );
     310        usb_endpoint_pipe_initialize_default_control(
     311                        &new_device_pipe,
     312                        &new_device_connection);
     313        /// \TODO get highspeed info
     314
     315
     316
     317
     318
     319        /* Request address from host controller. */
     320        usb_address_t new_device_address = usb_hc_request_address(
     321                        &hub->connection,
     322                        false/// \TODO fullspeed??
     323                        );
    323324        if (new_device_address < 0) {
    324325                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    325326                opResult = new_device_address;
    326                 usb_hub_release_default_address(hc);
     327                usb_hc_release_default_address(&hub->connection);
    327328                return;
    328329        }
    329330        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
    330         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    331             new_device_address);
     331        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     332        //    new_device_address);
     333        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    332334
    333335        if (opResult != EOK) {
    334336                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
    335                 usb_hub_release_default_address(hc);
    336                 return;
    337         }
    338 
    339 
    340         opResult = usb_hub_release_default_address(hc);
     337                usb_hc_release_default_address(&hub->connection);
     338                return;
     339        }
     340
     341
     342        //opResult = usb_hub_release_default_address(hc);
     343        opResult = usb_hc_release_default_address(&hub->connection);
    341344        if(opResult!=EOK){
    342345                return;
    343346        }
    344347
    345         devman_handle_t hc_handle;
    346         opResult = usb_drv_find_hc(hub->device, &hc_handle);
    347         if (opResult != EOK) {
    348                 usb_log_error("Failed to get handle of host controller: %s.\n",
    349                     str_error(opResult));
    350                 return;
    351         }
    352 
    353348        devman_handle_t child_handle;
    354         opResult = usb_device_register_child_in_devman(new_device_address,
    355             hc_handle, hub->device, &child_handle);
     349        //??
     350    opResult = usb_device_register_child_in_devman(new_device_address,
     351            hub->connection.hc_handle, hub->device, &child_handle);
     352
    356353        if (opResult != EOK) {
    357354                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
    358355                return;
    359356        }
    360         hub->attached_devs[port].devman_handle = child_handle;
     357        hub->attached_devs[port].handle = child_handle;
    361358        hub->attached_devs[port].address = new_device_address;
    362359
    363         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     360        //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     361        opResult = usb_hc_register_device(
     362                        &hub->connection,
     363                        &hub->attached_devs[port]);
    364364        if (opResult != EOK) {
    365365                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     
    378378 */
    379379static void usb_hub_removed_device(
    380     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     380    usb_hub_info_t * hub,uint16_t port) {
    381381        //usb_device_request_setup_packet_t request;
    382382        int opResult;
     
    385385         * devide manager
    386386         */
    387 
    388         hub->attached_devs[port].devman_handle=0;
     387       
    389388        //close address
    390389        if(hub->attached_devs[port].address!=0){
    391                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     390                //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     391                opResult = usb_hc_unregister_device(
     392                                &hub->connection, hub->attached_devs[port].address);
    392393                if(opResult != EOK) {
    393394                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
     
    395396                }
    396397                hub->attached_devs[port].address = 0;
     398                hub->attached_devs[port].handle = 0;
    397399        }else{
    398400                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    399401                //device was disconnected before it`s port was reset - return default address
    400                 usb_drv_release_default_address(hc);
     402                //usb_drv_release_default_address(hc);
     403                usb_hc_release_default_address(&hub->connection);
    401404        }
    402405}
     
    412415        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    413416        //determine type of change
    414         int opResult = usb_endpoint_pipe_start_session(&hub->endpoints.control);
    415417        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     418        int opResult = usb_endpoint_pipe_start_session(pipe);
     419       
    416420        if(opResult != EOK){
    417                 continue;
     421                dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
    418422        }
    419423
     
    446450        //something connected/disconnected
    447451        if (usb_port_connect_change(&status)) {
    448                 opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     452                opResult = usb_hub_clear_port_feature(pipe,
    449453                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    450454                // TODO: check opResult
     
    476480        /// \TODO handle other changes
    477481        /// \TODO debug log for various situations
    478         usb_endpoint_pipe_end_session(&hub->endpoints.control);
     482        usb_endpoint_pipe_end_session(pipe);
    479483
    480484
     
    526530                void *change_bitmap = malloc(byte_length);
    527531                size_t actual_size;
    528                 usb_handle_t handle;
     532                //usb_handle_t handle;
    529533
    530534                /*
     
    533537                opResult = usb_endpoint_pipe_read(
    534538                                &hub_info->endpoints.status_change,
    535                                 change_bitmap, byte_length, &actual_size,
     539                                change_bitmap, byte_length, &actual_size
    536540                                );
    537541
    538                 usb_drv_async_wait_for(handle);
     542                //usb_drv_async_wait_for(handle);
    539543
    540544                if (opResult != EOK) {
     
    549553                        if (interrupt) {
    550554                                usb_hub_process_interrupt(
    551 <<<<<<< TREE
    552555                                        hub_info, port);
    553 =======
    554                                         hub_info, hc, port, hub_info->address);
    555 >>>>>>> MERGE-SOURCE
    556556                        }
    557557                }
Note: See TracChangeset for help on using the changeset viewer.