Changeset f9dd44d in mainline
- Timestamp:
- 2011-01-14T14:44:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2e38385
- Parents:
- 977fcea
- Location:
- uspace/drv/uhci
- Files:
-
- 6 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/Makefile
r977fcea rf9dd44d 38 38 root_hub/port_status.c \ 39 39 root_hub/root_hub.c \ 40 uhci.c \ 41 utils/fibril_semaphore.c \ 42 utils/hc_synchronizer.c \ 43 utils/usb_device.c 40 uhci.c 44 41 45 42 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/uhci/root_hub/port.c
r977fcea rf9dd44d 1 1 2 2 #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 */ 4 4 #include <usb/usb.h> 5 #include <usb/usbdrv.h> 5 6 6 7 #include "debug.h" … … 8 9 #include "port.h" 9 10 #include "port_status.h" 10 #include "utils/hc_synchronizer.h"11 #include "utils/usb_device.h"12 11 13 12 static int uhci_port_new_device(uhci_port_t *port); 14 13 static int uhci_port_remove_device(uhci_port_t *port); 15 14 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 16 static usb_address_t assign_address_to_zero_device(device_t *hc);17 15 18 16 /*----------------------------------------------------------------------------*/ … … 21 19 uhci_port_t *port_instance = port; 22 20 assert(port_instance); 21 port_instance->hc_phone = devman_device_connect(port_instance->hc->handle, 0); 23 22 24 23 while (1) { … … 52 51 assert(port->hc); 53 52 53 54 54 uhci_print_info("Adding new device on port %d.\n", port->number); 55 55 … … 59 59 usb_address_keeping_reserve_default(&uhci_instance->address_manager); 60 60 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 61 68 /* enable port */ 62 69 uhci_port_set_enabled( port, true ); 63 70 64 71 /* 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 ); 66 73 67 74 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); 70 77 uhci_port_set_enabled(port, false); 71 78 usb_address_keeping_release_default(&uhci_instance->address_manager); … … 79 86 assert(port->attached_device == 0); 80 87 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); 91 90 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 } 93 96 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);107 97 108 98 return EOK; … … 138 128 } 139 129 /*----------------------------------------------------------------------------*/ 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 = 0164 };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 } -
uspace/drv/uhci/root_hub/port.h
r977fcea rf9dd44d 47 47 unsigned number; 48 48 unsigned wait_period_usec; 49 int hc_phone; 49 50 devman_handle_t attached_device; 50 51 } uhci_port_t; … … 58 59 port->hc = hc; 59 60 port->number = number; 61 port->hc_phone = -1; 60 62 port->wait_period_usec = usec; 61 63 port->attached_device = 0; -
uspace/drv/uhci/root_hub/root_hub.c
r977fcea rf9dd44d 8 8 #include "root_hub.h" 9 9 10 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */10 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 seconds */ 11 11 12 12 int uhci_root_hub_init( uhci_root_hub_t *hub, device_t *hc, void *addr ) -
uspace/drv/uhci/uhci.c
r977fcea rf9dd44d 6 6 #include "name.h" 7 7 #include "uhci.h" 8 9 8 10 9 int uhci_init(device_t *device, void *regs) … … 58 57 size); 59 58 60 return ENOTSUP; 59 callback( dev, 0, USB_OUTCOME_OK, arg ); 60 61 return EOK; 61 62 } 62 63 /*----------------------------------------------------------------------------*/ … … 74 75 size); 75 76 76 return ENOTSUP; 77 callback( dev, USB_OUTCOME_OK, arg ); 78 return EOK; 77 79 } 78 80 /*----------------------------------------------------------------------------*/ … … 89 91 usb_str_transfer_type(transfer_type), 90 92 size); 93 91 94 callback( dev, USB_OUTCOME_OK, arg ); 92 93 return ENOTSUP; 95 return EOK; 94 96 } 95 97 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.