Changes in uspace/drv/usbhub/usbhub.c [281ebae:5097bed4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r281ebae r5097bed4 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhub28 /** @addtogroup usb hub driver 29 29 * @{ 30 30 */ … … 46 46 #include "usbhub_private.h" 47 47 #include "port_status.h" 48 #include "usb/usb.h"49 48 50 49 static usb_iface_t hub_usb_iface = { … … 76 75 //get some hub info 77 76 usb_address_t addr = usb_drv_get_my_address(hc, device); 78 dprintf(1, "address of newly created hub = %d", addr);77 dprintf(1,"[usb_hub] address of newly created hub = %d", addr); 79 78 /*if(addr<0){ 80 79 //return result; … … 86 85 87 86 // get hub descriptor 87 usb_target_t target; 88 target.address = addr; 89 target.endpoint = 0; 90 usb_device_request_setup_packet_t request; 91 //printf("[usb_hub] creating descriptor request\n"); 92 usb_hub_set_descriptor_request(&request); 88 93 89 94 //printf("[usb_hub] creating serialized descriptor\n"); … … 93 98 int opResult; 94 99 //printf("[usb_hub] starting control transaction\n"); 95 96 opResult = usb_drv_req_get_descriptor(hc, addr, 97 USB_REQUEST_TYPE_CLASS, 98 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 100 opResult = usb_drv_sync_control_read( 101 hc, target, &request, serialized_descriptor, 99 102 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 100 101 if (opResult != EOK) { 102 dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult); 103 if (opResult != EOK) { 104 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult); 103 105 free(serialized_descriptor); 104 106 return result; … … 107 109 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 108 110 if(descriptor==NULL){ 109 dprintf(1, "could not deserialize descriptor ");111 dprintf(1,"[usb_hub] could not deserialize descriptor "); 110 112 result->port_count = 1;///\TODO this code is only for debug!!! 111 113 return result; … … 127 129 //finish 128 130 129 dprintf(1, "hub info created");131 dprintf(1,"[usb_hub] hub info created"); 130 132 131 133 return result; … … 134 136 int usb_add_hub_device(device_t *dev) { 135 137 dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle); 136 dprintf(1, "hub device");138 dprintf(1,"[usb_hub] hub device"); 137 139 138 140 /* … … 153 155 int port; 154 156 int opResult; 157 usb_device_request_setup_packet_t request; 155 158 usb_target_t target; 156 159 target.address = hub_info->usb_device->address; … … 162 165 usb_standard_device_descriptor_t std_descriptor; 163 166 opResult = usb_drv_req_get_device_descriptor(hc, target.address, 164 167 &std_descriptor); 165 168 if(opResult!=EOK){ 166 dprintf(1, "could not get device descriptor, %d",opResult);169 dprintf(1,"[usb_hub] could not get device descriptor, %d",opResult); 167 170 return opResult; 168 171 } 169 dprintf(1, "hub has %d configurations",std_descriptor.configuration_count);172 dprintf(1,"[usb_hub] hub has %d configurations",std_descriptor.configuration_count); 170 173 if(std_descriptor.configuration_count<1){ 171 dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 172 //shouldn`t I return? 174 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE"); 173 175 } 174 176 /// \TODO check other configurations … … 178 180 &config_descriptor); 179 181 if(opResult!=EOK){ 180 dprintf(1, "could not get configuration descriptor, %d",opResult);182 dprintf(1,"[usb_hub] could not get configuration descriptor, %d",opResult); 181 183 return opResult; 182 184 } 183 185 //set configuration 184 opResult = usb_drv_req_set_configuration(hc, target.address, 185 config_descriptor.configuration_number); 186 187 if (opResult != EOK) { 188 dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult); 189 } 190 191 usb_device_request_setup_packet_t request; 186 request.request_type = 0; 187 request.request = USB_DEVREQ_SET_CONFIGURATION; 188 request.index=0; 189 request.length=0; 190 request.value_high=0; 191 request.value_low = config_descriptor.configuration_number; 192 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 193 if (opResult != EOK) { 194 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult); 195 } 196 192 197 for (port = 1; port < hub_info->port_count+1; ++port) { 193 198 usb_hub_set_power_port_request(&request, port); 194 199 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 195 dprintf(1, "powering port %d",port);200 dprintf(1,"[usb_hub] powering port %d",port); 196 201 if (opResult != EOK) { 197 dprintf(1, "something went wrong when setting hub`s %dth port", port);202 dprintf(1,"[usb_hub]something went wrong when setting hub`s %dth port", port); 198 203 } 199 204 } … … 207 212 futex_up(&usb_hub_list_lock); 208 213 209 dprintf(1, "hub info added to list");214 dprintf(1,"[usb_hub] hub info added to list"); 210 215 //(void)hub_info; 211 216 usb_hub_check_hub_changes(); … … 213 218 214 219 215 dprintf(1, "hub dev added");216 dprintf(1, 220 dprintf(1,"[usb_hub] hub dev added"); 221 dprintf(1,"\taddress %d, has %d ports ", 217 222 hub_info->usb_device->address, 218 223 hub_info->port_count); 219 dprintf(1, 224 dprintf(1,"\tused configuration %d",config_descriptor.configuration_number); 220 225 221 226 return EOK; 222 227 //return ENOTSUP; 223 228 } 229 224 230 225 231 … … 231 237 232 238 /** 233 * Convenience function for releasing default address and writing debug info234 * (these few lines are used too often to be written again and again) .239 * convenience function for releasing default address and writing debug info 240 * (these few lines are used too often to be written again and again) 235 241 * @param hc 236 242 * @return … … 238 244 inline static int usb_hub_release_default_address(int hc){ 239 245 int opResult; 240 dprintf(1, "releasing default address");246 dprintf(1,"[usb_hub] releasing default address"); 241 247 opResult = usb_drv_release_default_address(hc); 242 248 if (opResult != EOK) { 243 dprintf(1, "failed to release default address");249 dprintf(1,"[usb_hub] failed to release default address"); 244 250 } 245 251 return opResult; … … 247 253 248 254 /** 249 * Reset the port with new device and reserve the default address.255 * reset the port with new device and reserve the default address 250 256 * @param hc 251 257 * @param port … … 255 261 usb_device_request_setup_packet_t request; 256 262 int opResult; 257 dprintf(1, "some connection changed");263 dprintf(1,"[usb_hub] some connection changed"); 258 264 //get default address 259 265 opResult = usb_drv_reserve_default_address(hc); 260 266 if (opResult != EOK) { 261 dprintf(1, "cannot assign default address, it is probably used");267 dprintf(1,"[usb_hub] cannot assign default address, it is probably used"); 262 268 return; 263 269 } … … 270 276 ); 271 277 if (opResult != EOK) { 272 dprintf(1, "something went wrong when reseting a port");278 dprintf(1,"[usb_hub] something went wrong when reseting a port"); 273 279 usb_hub_release_default_address(hc); 274 280 } … … 276 282 277 283 /** 278 * Finalize adding new device after port reset284 * finalize adding new device after port reset 279 285 * @param hc 280 286 * @param port … … 285 291 286 292 int opResult; 287 dprintf(1, "finalizing add device");293 dprintf(1,"[usb_hub] finalizing add device"); 288 294 opResult = usb_hub_clear_port_feature(hc, target.address, 289 295 port, USB_HUB_FEATURE_C_PORT_RESET); 290 296 if (opResult != EOK) { 291 dprintf(1, "failed to clear port reset feature");297 dprintf(1,"[usb_hub] failed to clear port reset feature"); 292 298 usb_hub_release_default_address(hc); 293 299 return; … … 297 303 usb_address_t new_device_address = usb_drv_request_address(hc); 298 304 if (new_device_address < 0) { 299 dprintf(1, "failed to get free USB address");305 dprintf(1,"[usb_hub] failed to get free USB address"); 300 306 opResult = new_device_address; 301 307 usb_hub_release_default_address(hc); 302 308 return; 303 309 } 304 dprintf(1, "setting new address");310 dprintf(1,"[usb_hub] setting new address"); 305 311 opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 306 312 new_device_address); 307 313 308 314 if (opResult != EOK) { 309 dprintf(1, "could not set address for new device");315 dprintf(1,"[usb_hub] could not set address for new device"); 310 316 usb_hub_release_default_address(hc); 311 317 return; … … 322 328 new_device_address, &child_handle); 323 329 if (opResult != EOK) { 324 dprintf(1, "could not start driver for new device");330 dprintf(1,"[usb_hub] could not start driver for new device"); 325 331 return; 326 332 } … … 330 336 opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 331 337 if (opResult != EOK) { 332 dprintf(1, "could not assign address of device in hcd");333 return; 334 } 335 dprintf(1, "new device address %d, handle %zu",338 dprintf(1,"[usb_hub] could not assign address of device in hcd"); 339 return; 340 } 341 dprintf(1,"[usb_hub] new device address %d, handle %zu", 336 342 new_device_address, child_handle); 337 343 … … 339 345 340 346 /** 341 * Unregister device address in hc347 * unregister device address in hc 342 348 * @param hc 343 349 * @param port … … 349 355 int opResult; 350 356 351 /** \TODO remove device from device manager - not yet implemented in 352 * devide manager 353 */ 357 /// \TODO remove device 354 358 355 359 hub->attached_devs[port].devman_handle=0; … … 358 362 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address); 359 363 if(opResult != EOK) { 360 dprintf(1, "could not release address of " \ 361 "removed device: %d", opResult); 364 dprintf(1, 365 "[usb_hub] could not release address of removed device: %d" 366 ,opResult); 362 367 } 363 368 hub->attached_devs[port].address = 0; 364 369 }else{ 365 dprintf(1, "this is strange, disconnected device had no address"); 370 dprintf(1, 371 "[usb_hub] this is strange, disconnected device had no address"); 366 372 //device was disconnected before it`s port was reset - return default address 367 373 usb_drv_release_default_address(hc); … … 370 376 371 377 /** 372 * Process interrupts on given hub port378 * process interrupts on given hub port 373 379 * @param hc 374 380 * @param port … … 377 383 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, 378 384 uint16_t port, usb_address_t address) { 379 dprintf(1, "interrupt at port %d", port);385 dprintf(1,"[usb_hub] interrupt at port %d", port); 380 386 //determine type of change 381 387 usb_target_t target; … … 395 401 ); 396 402 if (opResult != EOK) { 397 dprintf(1, "ERROR: could not get port status");403 dprintf(1,"[usb_hub] ERROR: could not get port status"); 398 404 return; 399 405 } 400 406 if (rcvd_size != sizeof (usb_port_status_t)) { 401 dprintf(1, "ERROR: received status has incorrect size");407 dprintf(1,"[usb_hub] ERROR: received status has incorrect size"); 402 408 return; 403 409 } … … 408 414 // TODO: check opResult 409 415 if (usb_port_dev_connected(&status)) { 410 dprintf(1, "some connection changed");416 dprintf(1,"[usb_hub] some connection changed"); 411 417 usb_hub_init_add_device(hc, port, target); 412 418 } else { … … 416 422 //port reset 417 423 if (usb_port_reset_completed(&status)) { 418 dprintf(1, "port reset complete");424 dprintf(1,"[usb_hub] port reset complete"); 419 425 if (usb_port_enabled(&status)) { 420 426 usb_hub_finalize_add_device(hub, hc, port, target); 421 427 } else { 422 dprintf(1, "ERROR: port reset, but port still not enabled");428 dprintf(1,"[usb_hub] ERROR: port reset, but port still not enabled"); 423 429 } 424 430 } … … 428 434 usb_port_set_reset_completed(&status, false); 429 435 usb_port_set_dev_connected(&status, false); 430 if (status>>16) { 431 dprintf(1, "there was some unsupported change on port %d: %X",port,status); 432 436 if (status) { 437 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port); 433 438 } 434 439 /// \TODO handle other changes … … 437 442 } 438 443 439 /** 440 * Check changes on all known hubs. 444 /* Check changes on all known hubs. 441 445 */ 442 446 void usb_hub_check_hub_changes(void) { … … 458 462 target.address = hub_info->usb_device->address; 459 463 target.endpoint = 1;/// \TODO get from endpoint descriptor 460 dprintf(1, "checking changes for hub at addr %d",464 dprintf(1,"[usb_hub] checking changes for hub at addr %d", 461 465 target.address); 462 466 … … 488 492 489 493 if (opResult != EOK) { 490 dprintf(1, "something went wrong while getting status of hub");494 dprintf(1,"[usb_hub] something went wrong while getting status of hub"); 491 495 continue; 492 496 }
Note:
See TracChangeset
for help on using the changeset viewer.