Changeset 0bd2879 in mainline
- Timestamp:
- 2011-01-08T21:51:41Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 977fcea
- Parents:
- 602eac5
- Location:
- uspace/drv/uhci
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/Makefile
r602eac5 r0bd2879 41 41 utils/fibril_semaphore.c \ 42 42 utils/hc_synchronizer.c \ 43 utils/ identify.c43 utils/usb_device.c 44 44 45 45 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/uhci/root_hub/port.c
r602eac5 r0bd2879 9 9 #include "port_status.h" 10 10 #include "utils/hc_synchronizer.h" 11 #include "utils/identify.h" 12 13 struct usb_match { 14 int id_score; 15 const char *id_string; 16 }; 11 #include "utils/usb_device.h" 17 12 18 13 static int uhci_port_new_device(uhci_port_t *port); 14 static int uhci_port_remove_device(uhci_port_t *port); 19 15 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 20 static usb_address_t assign_address_to_zero_device( device_t *hc ); 21 static int report_new_device( 22 device_t *hc, usb_address_t address, int hub_port, devman_handle_t *handle); 16 static usb_address_t assign_address_to_zero_device(device_t *hc); 23 17 24 18 /*----------------------------------------------------------------------------*/ … … 43 37 if (port_status & STATUS_CONNECTED_CHANGED) { 44 38 if (port_status & STATUS_CONNECTED) { 45 /* assign address and report new device */46 39 uhci_port_new_device(port_instance); 47 40 } else { 48 /* TODO */ 49 /* remove device here */ 50 uhci_print_error( 51 "Don't know how to remove device %#x.\n", 52 port_instance->attached_device); 53 uhci_port_set_enabled(port_instance, false); 41 uhci_port_remove_device(port_instance); 54 42 } 55 43 } … … 77 65 usb_address_t address = assign_address_to_zero_device(port->hc); 78 66 67 68 if (address <= 0) { /* address assigning went wrong */ 69 uhci_print_error("Failed to assign address to the device.\n"); 70 uhci_port_set_enabled(port, false); 71 usb_address_keeping_release_default(&uhci_instance->address_manager); 72 return ENOMEM; 73 } 74 79 75 /* release default address */ 80 76 usb_address_keeping_release_default(&uhci_instance->address_manager); 81 77 82 if (address <= 0) { /* address assigning went wrong */ 83 uhci_port_set_enabled(port, false); 84 uhci_print_error("Failed to assign address to the device.\n"); 85 return ENOMEM; 86 } 78 /* communicate and possibly report to devman */ 79 assert(port->attached_device == 0); 87 80 88 /* communicate and possibly report to devman */ 89 assert( port->attached_device == 0 ); 90 report_new_device(port->hc, address, port->number, 91 &port->attached_device); 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 92 91 93 /* bind address */ 92 device_t *child = create_device(); 93 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; 94 105 usb_address_keeping_devman_bind(&uhci_instance->address_manager, 95 106 address, port->attached_device); 96 107 108 return EOK; 109 } 110 /*----------------------------------------------------------------------------*/ 111 static int uhci_port_remove_device(uhci_port_t *port) 112 { 113 uhci_print_error( "Don't know how to remove device %#x.\n", 114 port->attached_device); 115 uhci_port_set_enabled(port, false); 97 116 return EOK; 98 117 } … … 114 133 port_status_write( port->address, port_status ); 115 134 116 /*117 port_status.status.enabled = enabled;118 pio_write_16( port->address, port_status.raw_value );119 */120 121 135 uhci_print_info( "%s port %d.\n", 122 136 enabled ? "Enabled" : "Disabled", port->number ); 123 return EOK;124 }125 /*----------------------------------------------------------------------------*/126 static int report_new_device(127 device_t *hc, usb_address_t address, int hub_port, devman_handle_t *handle)128 {129 assert( hc );130 assert( address > 0 );131 assert( address <= USB11_ADDRESS_MAX );132 133 device_t *child = create_device();134 if (child == NULL)135 { return ENOMEM; }136 137 int ret = 0;138 #define CHECK_RET_DELETE_CHILD_RETURN(ret, child, message, args...)\139 if (ret < 0) { \140 uhci_print_error("Failed(%d) to "message, ret, ##args); \141 delete_device(child); \142 return ret; \143 } else (void)0144 145 char *name;146 147 /* create name */148 ret = asprintf(&name, "usbdevice on hc%p/%d(%#x)", hc, hub_port, address);149 CHECK_RET_DELETE_CHILD_RETURN(ret, child, "create device name.\n");150 151 child->name = name;152 153 /* use descriptors to identify the device */154 ret = identify_device(hc, child, address);155 CHECK_RET_DELETE_CHILD_RETURN(ret, child, "identify device.\n");156 157 /* all went well, tell devman */158 ret = child_device_register( child, hc );159 CHECK_RET_DELETE_CHILD_RETURN(ret, child, "register device.\n");160 161 if (handle != NULL)162 { *handle = child->handle; }163 164 137 return EOK; 165 138 } … … 171 144 172 145 uhci_t *uhci_instance = (uhci_t*)hc->driver_data; 146 173 147 /* get new address */ 174 148 const usb_address_t usb_address = -
uspace/drv/uhci/utils/usb_device.c
r602eac5 r0bd2879 32 32 #include <usb/usbdrv.h> 33 33 34 #include "identify.h" 34 #include "debug.h" 35 #include "usb_device.h" 35 36 37 /*----------------------------------------------------------------------------*/ 38 #define CHECK_RET_RETURN(ret, child, message, args...)\ 39 if (ret < 0) { \ 40 uhci_print_error("Failed(%d) to "message, ret, ##args); \ 41 return ret; \ 42 } else (void)0 43 44 int usb_device_init(device_t *device, device_t *hc, usb_address_t address, 45 int hub_port) 46 { 47 assert(device); 48 assert(hc); 49 50 int ret = 0; 51 char *name; 52 53 /* create name */ 54 ret = asprintf(&name, "usbdevice on hc%p/root_hub[%d]/%#x", 55 hc, hub_port, address); 56 CHECK_RET_RETURN(ret, child, "create device name.\n"); 57 58 device->name = name; 59 60 /* use descriptors to identify the device */ 61 ret = usb_device_identify(device, hc, address); 62 CHECK_RET_RETURN(ret, child, "identify device.\n"); 63 64 return EOK; 65 } 66 /*----------------------------------------------------------------------------*/ 36 67 struct device_descriptor_packet 37 68 { … … 66 97 } 67 98 /*----------------------------------------------------------------------------*/ 68 int identify_device(device_t *hc, device_t *child, usb_address_t address)99 int usb_device_identify(device_t *device, device_t *hc, usb_address_t address) 69 100 { 101 assert(device); 102 assert(hc); 103 70 104 struct device_descriptor_packet packet = 71 105 DEVICE_DESCRIPTOR_PACKET_INITIALIZER; … … 73 107 packet.descriptor.device_class = USB_CLASS_HUB; 74 108 usb_drv_create_match_ids_from_device_descriptor( 75 & child->match_ids, &packet.descriptor );109 &device->match_ids, &packet.descriptor ); 76 110 77 111 return 0; 78 112 } 113 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci/utils/usb_device.h
r602eac5 r0bd2879 38 38 #include <usb/usb.h> 39 39 40 int identify_device(device_t *hc, device_t *child, usb_address_t address); 40 int usb_device_identify(device_t *device, device_t *hc, usb_address_t address); 41 42 int usb_device_init(device_t *device, device_t *hc, usb_address_t address, 43 int port); 41 44 42 45 #endif
Note:
See TracChangeset
for help on using the changeset viewer.