Changeset bf5a3be in mainline
- Timestamp:
- 2010-12-19T14:40:29Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2972e21
- Parents:
- f088c00
- Location:
- uspace/drv/uhci
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/main.c
rf088c00 rbf5a3be 27 27 */ 28 28 #include <usb/hcdhubd.h> 29 #include <usb/debug.h>30 29 #include <errno.h> 31 30 31 #include "debug.h" 32 32 #include "iface.h" 33 33 #include "name.h" … … 41 41 static int uhci_add_device(device_t *device) 42 42 { 43 usb_dprintf(NAME, 1, "uhci_add_device() called\n"); 43 // usb_dprintf(NAME, DEBUG, "uhci_add_device() called\n"); 44 uhci_print_info( "uhci_add_device() called\n" ); 44 45 device->ops = &uhci_ops; 45 46 46 47 uhci_init( device, (void*)0xc020 ); 47 48 /*49 * We need to announce the presence of our root hub.50 */51 // usb_dprintf(NAME, 2, "adding root hub\n");52 // usb_hcd_add_root_hub(device);53 48 54 49 return EOK; … … 69 64 * Do some global initializations. 70 65 */ 71 sleep( 5 );72 usb_dprintf_enable(NAME, 5);66 sleep( 5 ); 67 usb_dprintf_enable(NAME, DEBUG_LEVEL_INFO); 73 68 74 69 return driver_main(&uhci_driver); -
uspace/drv/uhci/root_hub/root_hub.c
rf088c00 rbf5a3be 1 #include <bool.h> 1 2 #include <ddi.h> 3 #include <devman.h> 2 4 #include <async.h> 3 5 #include <errno.h> … … 5 7 #include <stdio.h> 6 8 7 #include <usb/debug.h>8 9 9 #include "../name.h" 10 10 #include "../uhci.h" 11 #include "../debug.h" 11 12 #include "port_status.h" 12 13 #include "root_hub.h" 13 14 14 15 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */ 16 17 struct usb_match { 18 int id_score; 19 const char *id_string; 20 }; 15 21 16 22 static int uhci_root_hub_check_ports( void *hc ); … … 19 25 static int uhci_root_hub_report_new_device( 20 26 device_t *hc, usb_address_t address, int port, devman_handle_t *handle ); 27 static int uhci_root_hub_port_set_enabled( 28 uhci_root_hub_t *instance, unsigned port, bool enabled ); 21 29 22 30 /*----------------------------------------------------------------------------*/ … … 29 37 const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)®s); 30 38 if (ret < 0) { 31 printf( NAME": Failed to gain access to port registers at %p\n", regs ); 39 uhci_print_error( 40 ": Failed to gain access to port registers at %p\n", regs ); 32 41 return ret; 33 42 } … … 37 46 hub->checker = fibril_create( uhci_root_hub_check_ports, hc ); 38 47 if (hub->checker == 0) { 39 printf( NAME": failed to launch root hub fibril." );48 uhci_print_error( ": failed to launch root hub fibril." ); 40 49 return ENOMEM; 41 50 } … … 51 60 //destroy fibril here 52 61 //disable access to registers 62 return EOK; 63 } 64 /*----------------------------------------------------------------------------*/ 65 static int uhci_root_hub_port_set_enabled( uhci_root_hub_t *instance, 66 unsigned port, bool enabled ) 67 { 68 assert( instance ); 69 assert( instance->registers ); 70 assert( port < UHCI_ROOT_HUB_PORT_COUNT ); 71 72 volatile uint16_t * address = 73 &(instance->registers->portsc[port]); 74 75 /* read register value */ 76 port_status_t port_status; 77 port_status.raw_value = pio_read_16( address ); 78 79 /* enable port: register write */ 80 port_status.status.enabled_change = 0; 81 port_status.status.enabled = (bool)enabled; 82 pio_write_16( address, port_status.raw_value ); 83 84 uhci_print_info( "Enabled port %d.\n", port ); 53 85 return EOK; 54 86 } … … 65 97 &(uhci_instance->root_hub.registers->portsc[i]); 66 98 67 u sb_dprintf( NAME, 1,"Port(%d) status address %p:\n", i, address );99 uhci_print_info( "Port(%d) status address %p:\n", i, address ); 68 100 69 101 /* read register value */ … … 72 104 73 105 /* debug print */ 74 u sb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, port_status.raw_value );106 uhci_print_info( "Port(%d) status %#x:\n", i, port_status.raw_value ); 75 107 print_port_status( &port_status ); 76 108 … … 96 128 assert( port < UHCI_ROOT_HUB_PORT_COUNT ); 97 129 98 u sb_dprintf( NAME, 2,"Adding new device on port %d.\n", port );130 uhci_print_info( "Adding new device on port %d.\n", port ); 99 131 100 132 uhci_t *uhci_instance = (uhci_t*)hc->driver_data; … … 104 136 105 137 /* enable port */ 106 { 107 volatile uint16_t * address = 108 &(uhci_instance->root_hub.registers->portsc[port]); 109 110 /* read register value */ 111 port_status_t port_status; 112 port_status.raw_value = pio_read_16( address ); 113 114 /* enable port: register write */ 115 port_status.status.enabled = 1; 116 pio_write_16( address, port_status.raw_value ); 117 118 usb_dprintf( NAME, 2, "Enabled port %d.\n", port ); 119 } 138 uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, true ); 120 139 121 140 /* assign address to device */ 122 usb_address_t address = 123 uhci_root_hub_assign_address( hc ); 124 if (address <= 0) { 125 printf( NAME": Failed to assign address to the device" ); 126 return ENOMEM; 127 } 141 usb_address_t address = uhci_root_hub_assign_address( hc ); 142 128 143 /* release default address */ 129 144 usb_address_keeping_release_default( &uhci_instance->address_manager ); 145 146 if (address <= 0) { /* address assigning went wrong */ 147 uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, false ); 148 uhci_print_error( "Failed to assign address to the device" ); 149 return ENOMEM; 150 } 130 151 131 152 /* report to devman */ … … 148 169 uhci_t *uhci_instance = (uhci_t*)hc->driver_data; 149 170 /* get new address */ 150 const usb_address_t usb_address = usb_address_keeping_request(151 &uhci_instance->address_manager );171 const usb_address_t usb_address = 172 usb_address_keeping_request( &uhci_instance->address_manager ); 152 173 153 174 /* assign new address */ 154 /* TODO send new address */155 u sb_dprintf( NAME, 3, "Assigned address 0x%x.\n", usb_address );175 /* TODO send new address to the device*/ 176 uhci_print_error( "Assigned address %#x.\n", usb_address ); 156 177 157 178 return usb_address; … … 165 186 assert( address <= USB11_ADDRESS_MAX ); 166 187 167 int ret;168 188 device_t *child = create_device(); 169 189 if (child == NULL) 170 190 { return ENOMEM; } 191 171 192 char *name; 172 173 ret = asprintf( &name, "usbdevice on hc%p/%d/0x%x", hc, hub_port, address ); 193 int ret; 194 195 ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address ); 174 196 if (ret < 0) { 175 u sb_dprintf( NAME, 4,"Failed to create device name.\n" );197 uhci_print_error( "Failed to create device name.\n" ); 176 198 delete_device( child ); 177 199 return ret; … … 179 201 child->name = name; 180 202 181 /* TODO create match ids */ 203 /* TODO get and parse device descriptor */ 204 const int vendor = 1; 205 const int product = 1; 206 const char* release = "unknown"; 207 const char* class = "unknown"; 208 209 /* create match ids TODO fix class printf*/ 210 static const struct usb_match usb_matches[] = { 211 { 100, "usb&vendor=%d&product=%d&release=%s" }, 212 { 90, "usb&vendor=%d&product=%d" }, 213 { 50, "usb&class=%d" }, 214 { 1, "usb&fallback" } 215 }; 216 217 unsigned i = 0; 218 for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) { 219 char *match_str; 220 const int ret = asprintf( 221 &match_str, usb_matches[i].id_string, vendor, product, release, class ); 222 if (ret < 0 ) { 223 uhci_print_error( "Failed to create matchid string.\n" ); 224 delete_device( child ); 225 return ret; 226 } 227 uhci_print_info( "Adding match id rule:%s\n", match_str ); 228 229 match_id_t *id = create_match_id(); 230 if (id == NULL) { 231 uhci_print_error( "Failed to create matchid.\n" ); 232 delete_device( child ); 233 free( match_str ); 234 return ENOMEM; 235 } 236 id->id = match_str; 237 id->score = usb_matches[i].id_score; 238 add_match_id( &child->match_ids, id ); 239 240 uhci_print_info( "Added match id, score: %d, string %s\n", 241 id->score, id->id ); 242 } 182 243 183 244 ret = child_device_register( child, hc ); 184 245 if (ret < 0) { 185 u sb_dprintf( NAME, 4,"Failed to create device name.\n" );246 uhci_print_error( "Failed to create device name.\n" ); 186 247 delete_device( child ); 187 248 return ret; -
uspace/drv/uhci/uhci.c
rf088c00 rbf5a3be 3 3 #include <usb/usb.h> 4 4 5 #include "debug.h" 5 6 #include "name.h" 6 7 #include "uhci.h" … … 10 11 { 11 12 assert( device ); 12 u sb_dprintf(NAME, 1,"Initializing device at address %p\n", device);13 uhci_print_info( "Initializing device at address %p\n", device); 13 14 14 15 /* create instance */ … … 52 53 ) 53 54 { 54 u sb_dprintf(NAME, 1,"transfer IN [%d.%d (%s); %zu]\n",55 uhci_print_info( "transfer IN [%d.%d (%s); %zu]\n", 55 56 target.address, target.endpoint, 56 57 usb_str_transfer_type(transfer_type), … … 68 69 ) 69 70 { 70 u sb_dprintf(NAME, 1,"transfer OUT [%d.%d (%s); %zu]\n",71 uhci_print_info( "transfer OUT [%d.%d (%s); %zu]\n", 71 72 target.address, target.endpoint, 72 73 usb_str_transfer_type(transfer_type), … … 84 85 ) 85 86 { 86 u sb_dprintf(NAME, 1,"transfer SETUP [%d.%d (%s); %zu]\n",87 uhci_print_info( "transfer SETUP [%d.%d (%s); %zu]\n", 87 88 target.address, target.endpoint, 88 89 usb_str_transfer_type(transfer_type),
Note:
See TracChangeset
for help on using the changeset viewer.