Changeset 18e35a7 in mainline
- Timestamp:
- 2010-12-18T15:40:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f088c00
- Parents:
- 3515533
- Location:
- uspace/drv/uhci
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci/root_hub/port_status.c
r3515533 r18e35a7 4 4 #include "port_status.h" 5 5 6 void print_port_status( port_status_t *status )6 void print_port_status( const port_status_t *status ) 7 7 { 8 8 assert( status ); 9 printf( "\tsuspended: %s\n", status->s uspended ? "YES" : "NO" );10 printf( "\tin reset: %s\n", status-> reset ? "YES" : "NO" );11 printf( "\tlow speed: %s\n", status-> low_speed ? "YES" : "NO" );12 printf( "\tresume detected: %s\n", status-> resume ? "YES" : "NO" );9 printf( "\tsuspended: %s\n", status->status.suspended ? "YES" : "NO" ); 10 printf( "\tin reset: %s\n", status->status.reset ? "YES" : "NO" ); 11 printf( "\tlow speed: %s\n", status->status.low_speed ? "YES" : "NO" ); 12 printf( "\tresume detected: %s\n", status->status.resume ? "YES" : "NO" ); 13 13 printf( "\talways \"1\" reserved bit: %s\n", 14 status-> always_one ? "YES" : "NO" );14 status->status.always_one ? "YES" : "NO" ); 15 15 /* line status skipped */ 16 printf( "\tenable/disable change: %s\n", status-> enabled_change ? "YES" : "NO" );17 printf( "\tport enabled: %s\n", status-> enabled ? "YES" : "NO" );18 printf( "\tconnect change: %s\n", status-> connect_change ? "YES" : "NO" );19 printf( "\tconnected: %s\n", status-> connected ? "YES" : "NO" );16 printf( "\tenable/disable change: %s\n", status->status.enabled_change ? "YES" : "NO" ); 17 printf( "\tport enabled: %s\n", status->status.enabled ? "YES" : "NO" ); 18 printf( "\tconnect change: %s\n", status->status.connect_change ? "YES" : "NO" ); 19 printf( "\tconnected: %s\n", status->status.connected ? "YES" : "NO" ); 20 20 } -
uspace/drv/uhci/root_hub/port_status.h
r3515533 r18e35a7 37 37 #include <stdint.h> 38 38 39 typedef struct port_status{39 struct port_register { 40 40 uint8_t connected:1; 41 41 uint8_t connect_change:1; … … 66 66 // uint8_t connect_change:1; 67 67 // uint8_t connected:1; 68 } __attribute__((packed)) port_status_t;68 } __attribute__((packed)); 69 69 70 void print_port_status( port_status_t *status ); 70 typedef union port_status { 71 struct port_register status; 72 uint16_t raw_value; 73 } port_status_t; 74 75 void print_port_status( const port_status_t *status ); 71 76 #endif 72 77 /** -
uspace/drv/uhci/root_hub/root_hub.c
r3515533 r18e35a7 4 4 #include <stdint.h> 5 5 #include <stdio.h> 6 6 7 #include <usb/debug.h> 7 8 … … 11 12 #include "root_hub.h" 12 13 13 static int uhci_root_hub_check_ports( void * device ); 14 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */ 15 16 static int uhci_root_hub_check_ports( void *hc ); 17 static int uhci_root_hub_new_device( device_t *hc, unsigned port ); 18 static usb_address_t uhci_root_hub_assign_address( device_t *hc ); 19 static int uhci_root_hub_report_new_device( 20 device_t *hc, usb_address_t address, int port, devman_handle_t *handle ); 21 14 22 /*----------------------------------------------------------------------------*/ 15 int uhci_root_hub_init( uhci_root_hub_t *hub, device_t * device, void *addr )23 int uhci_root_hub_init( uhci_root_hub_t *hub, device_t *hc, void *addr ) 16 24 { 17 25 assert( hub ); 18 hub->checker = fibril_create( uhci_root_hub_check_ports, device ); 26 27 /* allow access to root hub registers */ 28 port_regs_t *regs; 29 const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)®s); 30 if (ret < 0) { 31 printf( NAME": Failed to gain access to port registers at %p\n", regs ); 32 return ret; 33 } 34 hub->registers = regs; 35 36 /* add fibril for periodic checks */ 37 hub->checker = fibril_create( uhci_root_hub_check_ports, hc ); 19 38 if (hub->checker == 0) { 20 printf( NAME": Failed to launch root hub fibril." );39 printf( NAME": failed to launch root hub fibril." ); 21 40 return ENOMEM; 22 41 } 23 42 fibril_add_ready( hub->checker ); 24 port_regs_t *regs;25 const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)®s);26 if (ret < 0) {27 printf(NAME": Failed to gain access to port registers at %p\n", regs);28 return ret;29 }30 hub->registers = regs;31 43 32 44 return EOK; … … 36 48 { 37 49 assert( instance ); 50 // TODO: 38 51 //destroy fibril here 52 //disable access to registers 39 53 return EOK; 40 54 } … … 44 58 assert( device ); 45 59 uhci_t *uhci_instance = ((device_t*)device)->driver_data; 60 46 61 while (1) { 47 62 int i = 0; … … 51 66 52 67 usb_dprintf( NAME, 1, "Port(%d) status address %p:\n", i, address ); 53 uint16_t value = pio_read_16( address ); 54 usb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, value ); 55 print_port_status( (port_status_t*)&value ); 68 69 /* read register value */ 70 port_status_t port_status; 71 port_status.raw_value = pio_read_16( address ); 72 73 /* debug print */ 74 usb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, port_status.raw_value ); 75 print_port_status( &port_status ); 76 77 if (port_status.status.connect_change) { 78 if (port_status.status.connected) { 79 /* assign address and report new device */ 80 uhci_root_hub_new_device( (device_t*)device, i ); 81 } else { 82 /* TODO */ 83 /* remove device here */ 84 } 85 } 56 86 } 57 async_usleep( 1000000);87 async_usleep( ROOT_HUB_WAIT_USEC ); 58 88 } 59 89 return ENOTSUP; 60 90 } 91 /*----------------------------------------------------------------------------*/ 92 int uhci_root_hub_new_device( device_t *hc, unsigned port ) 93 { 94 assert( hc ); 95 assert( hc->driver_data ); 96 assert( port < UHCI_ROOT_HUB_PORT_COUNT ); 97 98 usb_dprintf( NAME, 2, "Adding new device on port %d.\n", port ); 99 100 uhci_t *uhci_instance = (uhci_t*)hc->driver_data; 101 102 /* enable port */ 103 { 104 volatile uint16_t * address = 105 &(uhci_instance->root_hub.registers->portsc[port]); 106 107 /* read register value */ 108 port_status_t port_status; 109 port_status.raw_value = pio_read_16( address ); 110 111 /* enable port: register write */ 112 port_status.status.enabled = 1; 113 pio_write_16( address, port_status.raw_value ); 114 115 usb_dprintf( NAME, 2, "Enabled port %d.\n", port ); 116 } 117 118 /* assign address to device */ 119 usb_address_t address = 120 uhci_root_hub_assign_address( hc ); 121 if (address <= 0) { 122 printf( NAME": Failed to assign address to the device" ); 123 return ENOMEM; 124 } 125 126 /* report to devman */ 127 devman_handle_t child = 0; 128 uhci_root_hub_report_new_device( hc, address, port, &child ); 129 130 /* bind address */ 131 usb_address_keeping_devman_bind( &uhci_instance->address_manager, 132 address, child ); 133 134 135 return EOK; 136 } 137 /*----------------------------------------------------------------------------*/ 138 static usb_address_t uhci_root_hub_assign_address( device_t *hc ) 139 { 140 assert( hc ); 141 assert( hc->driver_data ); 142 143 uhci_t *uhci_instance = (uhci_t*)hc->driver_data; 144 /* get new address */ 145 const usb_address_t usb_address = usb_address_keeping_request( 146 &uhci_instance->address_manager ); 147 148 /* get default address */ 149 usb_address_keeping_reserve_default( &uhci_instance->address_manager ); 150 151 /* assign new address */ 152 /* TODO send new address*/ 153 usb_dprintf( NAME, 3, "Assigned address 0x%x.\n", usb_address ); 154 155 /* release default address */ 156 usb_address_keeping_release_default( &uhci_instance->address_manager ); 157 158 return usb_address; 159 } 160 /*----------------------------------------------------------------------------*/ 161 static int uhci_root_hub_report_new_device( 162 device_t *hc, usb_address_t address, int hub_port, devman_handle_t *handle ) 163 { 164 assert( hc ); 165 assert( address > 0 ); 166 assert( address <= USB11_ADDRESS_MAX ); 167 168 int ret; 169 device_t *child = create_device(); 170 if (child == NULL) 171 { return ENOMEM; } 172 char *name; 173 174 ret = asprintf( &name, "usbdevice on hc%p/%d/0x%x", hc, hub_port, address ); 175 if (ret < 0) { 176 usb_dprintf( NAME, 4, "Failed to create device name.\n" ); 177 delete_device( child ); 178 return ret; 179 } 180 child->name = name; 181 182 /* TODO create match ids */ 183 184 ret = child_device_register( child, hc ); 185 if (ret < 0) { 186 usb_dprintf( NAME, 4, "Failed to create device name.\n" ); 187 delete_device( child ); 188 return ret; 189 } 190 191 if (handle != NULL) 192 { *handle = child->handle; } 193 194 return EOK; 195 } -
uspace/drv/uhci/uhci.c
r3515533 r18e35a7 1 1 #include <errno.h> 2 2 #include <usb/debug.h> 3 #include <usb/usb.h> 3 4 4 5 #include "name.h" … … 16 17 { return ENOMEM; } 17 18 memset( instance, 0, sizeof(uhci_t) ); 19 20 /* init address keeper(libusb) */ 21 usb_address_keeping_init( &instance->address_manager, USB11_ADDRESS_MAX ); 18 22 19 23 /* allow access to hc control registers */
Note:
See TracChangeset
for help on using the changeset viewer.