Changes in uspace/drv/uhci-rhd/port.c [dced52a:87157982] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-rhd/port.c
rdced52a r87157982 34 34 #include <errno.h> 35 35 #include <str_error.h> 36 #include <fibril_synch.h>37 36 38 37 #include <usb/usb.h> /* usb_address_t */ … … 46 45 #include "port_status.h" 47 46 48 static int uhci_port_new_device(uhci_port_t *port , uint16_t status);47 static int uhci_port_new_device(uhci_port_t *port); 49 48 static int uhci_port_remove_device(uhci_port_t *port); 50 49 static int uhci_port_set_enabled(uhci_port_t *port, bool enabled); 51 50 static int uhci_port_check(void *port); 52 static int new_device_enable_port(int portno, void *arg);53 51 54 52 int uhci_port_init( 55 53 uhci_port_t *port, port_status_t *address, unsigned number, 56 unsigned usec, ddf_dev_t *rh )54 unsigned usec, ddf_dev_t *rh, int parent_phone) 57 55 { 58 56 assert(port); … … 71 69 port->checker = fibril_create(uhci_port_check, port); 72 70 if (port->checker == 0) { 73 usb_log_error("Port(%p - %d): failed to launch root hub fibril.", 74 port->address, port->number); 71 usb_log_error(": failed to launch root hub fibril."); 75 72 return ENOMEM; 76 73 } 77 74 fibril_add_ready(port->checker); 78 usb_log_debug( "Port(%p - %d): Added fibril. %x\n",79 port->address, port->number, port->checker);75 usb_log_debug( 76 "Added fibril for port %d: %p.\n", number, port->checker); 80 77 return EOK; 81 78 } … … 93 90 uhci_port_t *port_instance = port; 94 91 assert(port_instance); 95 // port_status_write(port_instance->address, 0);96 97 unsigned count = 0;98 92 99 93 while (1) { 100 async_usleep(port_instance->wait_period_usec);101 102 94 /* read register value */ 103 95 port_status_t port_status = … … 105 97 106 98 /* debug print */ 107 static fibril_mutex_t dbg_mtx = FIBRIL_MUTEX_INITIALIZER(dbg_mtx); 108 fibril_mutex_lock(&dbg_mtx); 109 usb_log_debug2("Port(%p - %d): Status: %#04x. === %u\n", 110 port_instance->address, port_instance->number, port_status, count++); 111 // print_port_status(port_status); 112 fibril_mutex_unlock(&dbg_mtx); 113 114 if ((port_status & STATUS_CONNECTED_CHANGED) != 0) { 115 usb_log_debug("Port(%p - %d): Connected change detected: %x.\n", 116 port_instance->address, port_instance->number, port_status); 117 118 99 usb_log_debug("Port %d status at %p: 0x%04x.\n", 100 port_instance->number, port_instance->address, port_status); 101 print_port_status(port_status); 102 103 if (port_status & STATUS_CONNECTED_CHANGED) { 119 104 int rc = usb_hc_connection_open( 120 105 &port_instance->hc_connection); 121 106 if (rc != EOK) { 122 usb_log_error("Port(%p - %d): Failed to connect to HC.", 123 port_instance->address, port_instance->number); 124 continue; 107 usb_log_error("Failed to connect to HC."); 108 goto next; 125 109 } 126 110 127 /* remove any old device */128 if (port_instance->attached_device) {129 u sb_log_debug("Port(%p - %d): Removing device.\n",130 port_instance->address, port_instance->number);111 if (port_status & STATUS_CONNECTED) { 112 /* new device */ 113 uhci_port_new_device(port_instance); 114 } else { 131 115 uhci_port_remove_device(port_instance); 132 }133 134 if ((port_status & STATUS_CONNECTED) != 0) {135 /* new device */136 uhci_port_new_device(port_instance, port_status);137 } else {138 /* ack changes by writing one to WC bits */139 port_status_write(port_instance->address, port_status);140 usb_log_debug("Port(%p - %d): Change status ACK.\n",141 port_instance->address, port_instance->number);142 116 } 143 117 … … 145 119 &port_instance->hc_connection); 146 120 if (rc != EOK) { 147 usb_log_error(" Port(%p - %d): Failed to disconnect from HC.",148 port_instance->address, port_instance->number);121 usb_log_error("Failed to disconnect from HC."); 122 goto next; 149 123 } 150 124 } 125 next: 126 async_usleep(port_instance->wait_period_usec); 151 127 } 152 128 return EOK; … … 163 139 uhci_port_t *port = (uhci_port_t *) arg; 164 140 165 usb_log_debug2("Port(%p - %d): new_device_enable_port.\n", 166 port->address, port->number); 141 usb_log_debug("new_device_enable_port(%d)\n", port->number); 167 142 168 143 /* … … 172 147 async_usleep(100000); 173 148 149 /* Enable the port. */ 150 uhci_port_set_enabled(port, true); 174 151 175 152 /* The hub maintains the reset signal to that port for 10 ms … … 177 154 */ 178 155 { 179 usb_log_debug(" Port(%p - %d): Reset Signal start.\n",180 port-> address, port->number);156 usb_log_debug("Reset Signal start on port %d.\n", 157 port->number); 181 158 port_status_t port_status = 182 159 port_status_read(port->address); … … 188 165 port_status &= ~STATUS_IN_RESET; 189 166 port_status_write(port->address, port_status); 190 usb_log_debug("Port(%p - %d): Reset Signal stop.\n", 191 port->address, port->number); 192 } 193 194 /* Enable the port. */ 195 uhci_port_set_enabled(port, true); 196 197 return EOK; 198 } 199 200 /*----------------------------------------------------------------------------*/ 201 static int uhci_port_new_device(uhci_port_t *port, uint16_t status) 167 usb_log_debug("Reset Signal stop on port %d.\n", 168 port->number); 169 } 170 171 return EOK; 172 } 173 174 /*----------------------------------------------------------------------------*/ 175 static int uhci_port_new_device(uhci_port_t *port) 202 176 { 203 177 assert(port); 204 178 assert(usb_hc_connection_is_opened(&port->hc_connection)); 205 179 206 usb_log_info("Port(%p-%d): Detected new device.\n", 207 port->address, port->number); 180 usb_log_info("Detected new device on port %u.\n", port->number); 208 181 209 182 usb_address_t dev_addr; 210 183 int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection, 211 ((status & STATUS_LOW_SPEED) != 0) ? USB_SPEED_LOW :USB_SPEED_FULL,184 USB_SPEED_FULL, 212 185 new_device_enable_port, port->number, port, 213 186 &dev_addr, &port->attached_device, NULL, NULL, NULL); 214 215 187 if (rc != EOK) { 216 usb_log_error(" Port(%p-%d): Failed(%d) adding new device: %s.\n",217 port-> address, port->number, rc, str_error(rc));188 usb_log_error("Failed adding new device on port %u: %s.\n", 189 port->number, str_error(rc)); 218 190 uhci_port_set_enabled(port, false); 219 191 return rc; 220 192 } 221 193 222 usb_log_info(" Port(%p-%d): New devicehas address %d (handle %zu).\n",223 port-> address, port->number, dev_addr, port->attached_device);194 usb_log_info("New device on port %u has address %d (handle %zu).\n", 195 port->number, dev_addr, port->attached_device); 224 196 225 197 return EOK; … … 229 201 static int uhci_port_remove_device(uhci_port_t *port) 230 202 { 231 usb_log_error(" Port(%p-%d):Don't know how to remove device %#x.\n",232 port->address, port->number,(unsigned int)port->attached_device);203 usb_log_error("Don't know how to remove device %#x.\n", 204 (unsigned int)port->attached_device); 233 205 // uhci_port_set_enabled(port, false); 234 206 return EOK; … … 251 223 port_status_write(port->address, port_status); 252 224 253 usb_log_info(" Port(%p-%d): %sabled port.\n",254 port->address, port->number, enabled ? "En" : "Dis");225 usb_log_info("%s port %d.\n", 226 enabled ? "Enabled" : "Disabled", port->number); 255 227 return EOK; 256 228 }
Note:
See TracChangeset
for help on using the changeset viewer.