Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7267fa1 in mainline


Ignore:
Timestamp:
2011-12-11T17:51:21Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
c0fdc0e
Parents:
023a902
Message:

libusbdev: new_device_wrapper uses provided hc connection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/hub.c

    r023a902 r7267fa1  
    121121 * @return Error code.
    122122 */
    123 static int usb_request_set_address(usb_pipe_t *pipe, usb_address_t new_address,
    124     usb_hc_connection_t *hc_conn)
     123static int usb_request_set_address(usb_pipe_t *pipe, usb_address_t new_address)
    125124{
    126125        if ((new_address < 0) || (new_address >= USB11_ADDRESS_MAX)) {
     
    128127        }
    129128        assert(pipe);
    130         assert(hc_conn);
    131129        assert(pipe->wire != NULL);
    132130
     
    146144                    "Failed to unregister the old pipe on address change.\n");
    147145        }
     146        /* Address changed. We can release the default, thus
     147         * allowing other to access the default address. */
     148        usb_hc_unregister_device(pipe->wire->hc_connection,
     149            pipe->wire->address);
     150
    148151        /* The address is already changed so set it in the wire */
    149152        pipe->wire->address = new_address;
     
    196199 */
    197200int usb_hc_new_device_wrapper(ddf_dev_t *parent,
    198     usb_hc_connection_t *connection, usb_speed_t dev_speed,
     201    usb_hc_connection_t *hc_conn, usb_speed_t dev_speed,
    199202    int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address,
    200203    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    201204{
    202         if (new_fun == NULL || connection == NULL)
     205        if (new_fun == NULL || hc_conn == NULL)
    203206                return EINVAL;
    204 
    205         // TODO: Why not use provided connection?
    206         usb_hc_connection_t hc_conn;
    207         usb_hc_connection_initialize(&hc_conn, connection->hc_handle);
    208207
    209208        int rc;
     
    215214        }
    216215
    217         rc = usb_hc_connection_open(&hc_conn);
     216        /* We are gona do a lot of communication better open it in advance. */
     217        rc = usb_hc_connection_open(hc_conn);
    218218        if (rc != EOK) {
    219219                return rc;
    220220        }
    221221
    222         /*
    223          * Request new address.
    224          */
     222        /* Request a new address. */
    225223        usb_address_t dev_addr =
    226             usb_hc_request_address(&hc_conn, 0, false, dev_speed);
     224            usb_hc_request_address(hc_conn, 0, false, dev_speed);
    227225        if (dev_addr < 0) {
    228226                rc = EADDRNOTAVAIL;
    229227                goto close_connection;
     228        }
     229
     230        /* Initialize connection to device. */
     231        usb_device_connection_t dev_conn;
     232        rc = usb_device_connection_initialize_on_default_address(
     233            &dev_conn, hc_conn);
     234        if (rc != EOK) {
     235                rc = ENOTCONN;
     236                goto leave_release_free_address;
    230237        }
    231238
     
    236243         * (Someone else already wants to add a new device.)
    237244         */
    238         usb_device_connection_t dev_conn;
    239         rc = usb_device_connection_initialize_on_default_address(&dev_conn,
    240             &hc_conn);
    241         if (rc != EOK) {
    242                 rc = ENOTCONN;
    243                 goto leave_release_free_address;
    244         }
    245 
    246245        usb_pipe_t ctrl_pipe;
    247246        rc = usb_pipe_initialize_default_control(&ctrl_pipe, &dev_conn);
     
    252251
    253252        do {
    254                 rc = usb_hc_request_address(&hc_conn, USB_ADDRESS_DEFAULT,
     253                rc = usb_hc_request_address(hc_conn, USB_ADDRESS_DEFAULT,
    255254                    true, dev_speed);
    256255                if (rc == ENOENT) {
     
    306305        }
    307306
    308         rc = usb_request_set_address(&ctrl_pipe, dev_addr, &hc_conn);
     307        rc = usb_request_set_address(&ctrl_pipe, dev_addr);
    309308        if (rc != EOK) {
    310309                rc = ESTALL;
     
    312311        }
    313312
    314         /* Address changed. We can release the default, thus
    315          * allowing other to access the default address. */
    316         usb_hc_unregister_device(&hc_conn, USB_ADDRESS_DEFAULT);
    317313
    318314        /* Register the device with devman. */
     
    332328
    333329        /* Inform the host controller about the handle. */
    334         rc = usb_hc_register_device(&hc_conn, &new_device);
     330        rc = usb_hc_register_device(hc_conn, &new_device);
    335331        if (rc != EOK) {
    336332                /* We know nothing about that data. */
     
    357353         */
    358354leave_release_default_address:
    359         usb_hc_unregister_device(&hc_conn, USB_ADDRESS_DEFAULT);
     355        usb_hc_unregister_device(hc_conn, USB_ADDRESS_DEFAULT);
    360356
    361357leave_release_free_address:
     
    365361                    __FUNCTION__);
    366362
    367         if (usb_hc_unregister_device(&hc_conn, dev_addr) != EOK)
     363        if (usb_hc_unregister_device(hc_conn, dev_addr) != EOK)
    368364                usb_log_warning("%s: Failed to unregister device.\n",
    369365                    __FUNCTION__);
    370366
    371367close_connection:
    372         if (usb_hc_connection_close(&hc_conn) != EOK)
     368        if (usb_hc_connection_close(hc_conn) != EOK)
    373369                usb_log_warning("%s: Failed to close hc connection.\n",
    374370                    __FUNCTION__);
Note: See TracChangeset for help on using the changeset viewer.