Changeset f9dd44d in mainline for uspace/drv/uhci/root_hub/port.c


Ignore:
Timestamp:
2011-01-14T14:44:22Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2e38385
Parents:
977fcea
Message:

refactoring, use libusb device identification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/root_hub/port.c

    r977fcea rf9dd44d  
    11
    22#include <errno.h>
    3 #include <usb/devreq.h> /* for usb_device_request_setup_packet_t */
     3//#include <usb/devreq.h> /* for usb_device_request_setup_packet_t */
    44#include <usb/usb.h>
     5#include <usb/usbdrv.h>
    56
    67#include "debug.h"
     
    89#include "port.h"
    910#include "port_status.h"
    10 #include "utils/hc_synchronizer.h"
    11 #include "utils/usb_device.h"
    1211
    1312static int uhci_port_new_device(uhci_port_t *port);
    1413static int uhci_port_remove_device(uhci_port_t *port);
    1514static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
    16 static usb_address_t assign_address_to_zero_device(device_t *hc);
    1715
    1816/*----------------------------------------------------------------------------*/
     
    2119        uhci_port_t *port_instance = port;
    2220        assert(port_instance);
     21        port_instance->hc_phone = devman_device_connect(port_instance->hc->handle, 0);
    2322
    2423        while (1) {
     
    5251        assert(port->hc);
    5352
     53
    5454        uhci_print_info("Adding new device on port %d.\n", port->number);
    5555
     
    5959        usb_address_keeping_reserve_default(&uhci_instance->address_manager);
    6060
     61        const usb_address_t usb_address =
     62          usb_address_keeping_request(&uhci_instance->address_manager);
     63
     64        if (usb_address <= 0) {
     65                return usb_address;
     66        }
     67
    6168        /* enable port */
    6269        uhci_port_set_enabled( port, true );
    6370
    6471        /* assign address to device */
    65         usb_address_t address = assign_address_to_zero_device(port->hc);
     72        int ret = usb_drv_req_set_address( port->hc_phone, 0, usb_address );
    6673
    6774
    68         if (address <= 0) { /* address assigning went wrong */
    69                 uhci_print_error("Failed to assign address to the device.\n");
     75        if (ret != EOK) { /* address assigning went wrong */
     76                uhci_print_error("Failed(%d) to assign address to the device.\n", ret);
    7077                uhci_port_set_enabled(port, false);
    7178                usb_address_keeping_release_default(&uhci_instance->address_manager);
     
    7986        assert(port->attached_device == 0);
    8087
    81 #define CHECK_RET_DELETE_CHILD_RETURN(ret, child, message, args...)\
    82         if (ret < 0) { \
    83                 uhci_print_error("Failed(%d) to "message, ret, ##args); \
    84                 if (child) { \
    85                         delete_device(child); \
    86                 } \
    87                 uhci_port_set_enabled(port, false); \
    88                 usb_address_keeping_release(&uhci_instance->address_manager, address); \
    89                 return ret; \
    90         } else (void)0
     88        ret = usb_drv_register_child_in_devman(port->hc_phone, port->hc, usb_address,
     89                &port->attached_device);
    9190
    92         device_t *child = create_device();
     91        if (ret != EOK) { /* something went wrong */
     92                uhci_print_error("Failed(%d) in usb_drv_register_child.\n", ret);
     93                uhci_port_set_enabled(port, false);
     94                return ENOMEM;
     95        }
    9396
    94         int ret = child ? EOK : ENOMEM;
    95         CHECK_RET_DELETE_CHILD_RETURN(ret, child, "create device.\n" );
    96 
    97         ret = usb_device_init(child, port->hc, address, port->number );
    98         CHECK_RET_DELETE_CHILD_RETURN(ret, child, "init usb device.\n" );
    99 
    100         ret = child_device_register(child, port->hc);
    101         CHECK_RET_DELETE_CHILD_RETURN(ret, child, "register usb device.\n" );
    102 
    103         /* store device and bind address, can not fail */
    104         port->attached_device = child->handle;
    105         usb_address_keeping_devman_bind(&uhci_instance->address_manager,
    106           address, port->attached_device);
    10797
    10898        return EOK;
     
    138128}
    139129/*----------------------------------------------------------------------------*/
    140 static usb_address_t assign_address_to_zero_device( device_t *hc )
    141 {
    142         assert( hc );
    143         assert( hc->driver_data );
    144 
    145         uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
    146 
    147         /* get new address */
    148         const usb_address_t usb_address =
    149           usb_address_keeping_request(&uhci_instance->address_manager);
    150 
    151         if (usb_address <= 0) {
    152                 return usb_address;
    153         }
    154 
    155         /* assign new address */
    156         usb_target_t new_device = { USB_ADDRESS_DEFAULT, 0 };
    157         usb_device_request_setup_packet_t data =
    158         {
    159                 .request_type = 0,
    160                 .request = USB_DEVREQ_SET_ADDRESS,
    161                 { .value = usb_address },
    162                 .index = 0,
    163                 .length = 0
    164         };
    165 
    166         sync_value_t sync;
    167         uhci_setup_sync(hc, new_device,
    168           USB_TRANSFER_CONTROL, &data, sizeof(data), &sync);
    169 
    170         if (sync.result != USB_OUTCOME_OK) {
    171                 uhci_print_error(
    172                   "Failed to assign address to the connected device.\n");
    173                 usb_address_keeping_release(&uhci_instance->address_manager,
    174                   usb_address);
    175                 return -1;
    176         }
    177 
    178         uhci_print_info("Assigned address %#x.\n", usb_address);
    179         return usb_address;
    180 }
Note: See TracChangeset for help on using the changeset viewer.