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