Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-rhd/port.c

    rf673f60 r4e8e1f5  
    3636
    3737#include <usb/usb.h>    /* usb_address_t */
    38 #include <usb/usbdevice.h>
    39 #include <usb/hub.h>
    40 #include <usb/request.h>
     38#include <usb/usbdrv.h> /* usb_drv_*     */
    4139#include <usb/debug.h>
    4240#include <usb/recognise.h>
     
    6058        port->attached_device = 0;
    6159        port->rh = rh;
    62         int rc = usb_hc_connection_initialize_from_device(
    63             &port->hc_connection, rh);
    64         if (rc != EOK) {
    65                 usb_log_error("Failed to initialize connection to HC.");
    66                 return rc;
    67         }
     60        port->hc_phone = parent_phone;
    6861
    6962        port->checker = fibril_create(uhci_port_check, port);
     
    10598
    10699                if (port_status & STATUS_CONNECTED_CHANGED) {
    107                         int rc = usb_hc_connection_open(
    108                             &port_instance->hc_connection);
    109                         if (rc != EOK) {
    110                                 usb_log_error("Failed to connect to HC.");
    111                                 goto next;
    112                         }
    113 
    114100                        if (port_status & STATUS_CONNECTED) {
    115101                                /* new device */
     
    118104                                uhci_port_remove_device(port_instance);
    119105                        }
    120 
    121                         rc = usb_hc_connection_close(
    122                             &port_instance->hc_connection);
    123                         if (rc != EOK) {
    124                                 usb_log_error("Failed to disconnect from HC.");
    125                                 goto next;
    126                         }
    127106                }
    128         next:
    129107                async_usleep(port_instance->wait_period_usec);
    130108        }
     
    135113{
    136114        assert(port);
    137         assert(usb_hc_connection_is_opened(&port->hc_connection));
     115        assert(port->hc_phone);
    138116
    139117        usb_log_info("Adding new device on port %d.\n", port->number);
    140118
    141119        /* get address of the future device */
    142         const usb_address_t usb_address = usb_hc_request_address(&port->hc_connection);
     120        const usb_address_t usb_address = usb_drv_request_address(port->hc_phone);
    143121
    144122        if (usb_address <= 0) {
     
    150128
    151129        /* get default address */
    152         int ret = usb_hc_reserve_default_address(&port->hc_connection);
     130        int ret = usb_drv_reserve_default_address(port->hc_phone);
    153131        if (ret != EOK) {
    154132                usb_log_error("Failed to reserve default address on port %d.\n",
    155133                    port->number);
    156                 int ret2 = usb_hc_unregister_device(&port->hc_connection,
    157                     usb_address);
     134                int ret2 =
     135                  usb_drv_release_address(port->hc_phone, usb_address);
    158136                if (ret2 != EOK) {
    159137                        usb_log_fatal("Failed to return requested address on port %d.\n",
     
    196174        }
    197175
    198         /*
    199          * Initialize connection to the device.
    200          */
    201         /* FIXME: check for errors. */
    202         usb_device_connection_t new_dev_connection;
    203         usb_endpoint_pipe_t new_dev_ctrl_pipe;
    204         usb_device_connection_initialize_on_default_address(
    205             &new_dev_connection, &port->hc_connection);
    206         usb_endpoint_pipe_initialize_default_control(&new_dev_ctrl_pipe,
    207             &new_dev_connection);
    208 
    209         /*
    210          * Assign new address to the device. This function updates
    211          * the backing connection to still point to the same device.
    212          */
    213         /* FIXME: check for errors. */
    214         usb_endpoint_pipe_start_session(&new_dev_ctrl_pipe);
    215         ret = usb_request_set_address(&new_dev_ctrl_pipe, usb_address);
    216         usb_endpoint_pipe_end_session(&new_dev_ctrl_pipe);
     176        /* assign address to device */
     177        ret = usb_drv_req_set_address(port->hc_phone, 0, usb_address);
    217178
    218179        if (ret != EOK) { /* address assigning went wrong */
    219180                usb_log_error("Failed(%d) to assign address to the device.\n", ret);
    220181                uhci_port_set_enabled(port, false);
    221                 int release = usb_hc_release_default_address(&port->hc_connection);
     182                int release = usb_drv_release_default_address(port->hc_phone);
    222183                if (release != EOK) {
    223184                        usb_log_error("Failed to release default address on port %d.\n",
     
    233194
    234195        /* release default address */
    235         ret = usb_hc_release_default_address(&port->hc_connection);
     196        ret = usb_drv_release_default_address(port->hc_phone);
    236197        if (ret != EOK) {
    237198                usb_log_error("Failed to release default address on port %d.\n",
     
    245206        assert(port->attached_device == 0);
    246207
    247         ret = usb_device_register_child_in_devman(new_dev_connection.address,
    248             new_dev_connection.hc_handle, port->rh, &port->attached_device);
    249 
     208        devman_handle_t hc_handle;
     209        ret = usb_drv_find_hc(port->rh, &hc_handle);
     210        if (ret != EOK) {
     211                usb_log_error("Failed to get handle of host controller: %s.\n",
     212                    str_error(ret));
     213                uhci_port_set_enabled(port, false);
     214                return ENOMEM;
     215        }
     216
     217        ret = usb_device_register_child_in_devman(usb_address, hc_handle,
     218            port->rh, &port->attached_device);
    250219        if (ret != EOK) { /* something went wrong */
    251220                usb_log_error("Failed(%d) in usb_drv_register_child.\n", ret);
     
    256225                port->number, usb_address, port->attached_device);
    257226
    258         /*
    259          * Register the device in the host controller.
    260          */
    261         usb_hc_attached_device_t new_device = {
    262                 .address = new_dev_connection.address,
    263                 .handle = port->attached_device
    264         };
    265 
    266         ret = usb_hc_register_device(&port->hc_connection, &new_device);
     227        ret =
     228          usb_drv_bind_address(port->hc_phone, usb_address, port->attached_device);
    267229        // TODO: proper error check here
    268230        assert(ret == EOK);
Note: See TracChangeset for help on using the changeset viewer.