Changes in uspace/drv/usbhub/usbhub.c [361fcec:46e078a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r361fcec r46e078a 45 45 #include <usb/request.h> 46 46 #include <usb/classes/hub.h> 47 #include <usb/devpoll.h>48 47 #include <stdio.h> 49 48 … … 72 71 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info); 73 72 73 74 /// \TODO malloc checking 74 75 75 76 //********************************************* … … 103 104 } 104 105 106 usb_pipe_start_session(hub_info->control_pipe); 105 107 //set hub configuration 106 108 opResult = usb_hub_set_configuration(hub_info); … … 119 121 return opResult; 120 122 } 121 122 usb_log_debug("Creating 'hub' function in DDF.\n"); 123 usb_pipe_end_session(hub_info->control_pipe); 124 125 /// \TODO what is this? 126 usb_log_debug("Creating `hub' function.\n"); 123 127 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 124 128 fun_exposed, "hub"); … … 148 152 bool hub_port_changes_callback(usb_device_t *dev, 149 153 uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) { 150 usb_log_debug("hub_port_changes_callback\n");151 154 usb_hub_info_t *hub = (usb_hub_info_t *) arg; 152 155 … … 171 174 leave: 172 175 /* FIXME: proper interval. */ 173 async_usleep(1000 * 250);176 async_usleep(1000 * 1000 * 10); 174 177 175 178 return true; … … 213 216 // get hub descriptor 214 217 usb_log_debug("creating serialized descriptor\n"); 215 uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];218 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 216 219 usb_hub_descriptor_t * descriptor; 217 220 int opResult; … … 231 234 } 232 235 usb_log_debug2("deserializing descriptor\n"); 233 descriptor = usb_create_deserialized_hub_desriptor( 234 serialized_descriptor); 236 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 235 237 if (descriptor == NULL) { 236 238 usb_log_warning("could not deserialize descriptor \n"); 237 return ENOMEM;239 return opResult; 238 240 } 239 241 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 240 242 hub_info->port_count = descriptor->ports_count; 241 243 /// \TODO this is not semantically correct 242 bool is_power_switched =243 ((descriptor->hub_characteristics & 1) ==0);244 bool has_individual_port_powering =245 ((descriptor->hub_characteristics & 1) !=0);246 244 hub_info->ports = malloc( 247 245 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 248 if(!hub_info->ports){249 return ENOMEM;250 }251 246 size_t port; 252 for (port = 0; port < hub_info->port_count + 1; ++port) {247 for (port = 0; port < hub_info->port_count + 1; port++) { 253 248 usb_hub_port_init(&hub_info->ports[port]); 254 249 } 255 if(is_power_switched){256 usb_log_debug("is_power_switched\n");257 258 if(!has_individual_port_powering){259 usb_log_debug("!has_individual_port_powering\n");260 opResult = usb_hub_set_feature(hub_info->control_pipe,261 USB_HUB_FEATURE_C_HUB_LOCAL_POWER);262 if (opResult != EOK) {263 usb_log_error("cannot power hub: %s\n",264 str_error(opResult));265 }266 }267 268 for (port = 1; port <= hub_info->port_count; ++port) {269 usb_log_debug("Powering port %zu.\n",port);270 opResult = usb_hub_set_port_feature(hub_info->control_pipe,271 port, USB_HUB_FEATURE_PORT_POWER);272 if (opResult != EOK) {273 usb_log_error("cannot power on port %zu: %s.\n",274 port, str_error(opResult));275 }276 }277 278 }else{279 usb_log_debug("!is_power_switched, not going to be powered\n");280 }281 250 usb_log_debug2("freeing data\n"); 251 free(serialized_descriptor); 252 free(descriptor->devices_removable); 282 253 free(descriptor); 283 254 return EOK; … … 341 312 * auto destruction, this could work better. 342 313 */ 343 int rc = usb_ hc_connection_open(&hub_info->connection);314 int rc = usb_pipe_start_session(hub_info->control_pipe); 344 315 if (rc != EOK) { 345 //usb_pipe_end_session(hub_info->control_pipe); 316 usb_log_error("Failed to start session on control pipe: %s.\n", 317 str_error(rc)); 318 return rc; 319 } 320 rc = usb_hc_connection_open(&hub_info->connection); 321 if (rc != EOK) { 322 usb_pipe_end_session(hub_info->control_pipe); 346 323 usb_log_error("Failed to open connection to HC: %s.\n", 347 324 str_error(rc)); … … 359 336 } 360 337 361 usb_log_info("Controlling hub `%s' (% zuports).\n",338 usb_log_info("Controlling hub `%s' (%d ports).\n", 362 339 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 363 340 return EOK; … … 412 389 usb_hub_status_t status) { 413 390 int opResult; 414 if ( !usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) {391 if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) { 415 392 //restart power on hub 416 393 opResult = usb_hub_set_feature(hub_info->control_pipe, … … 422 399 } else {//power reestablished on hub- restart ports 423 400 size_t port; 424 for (port = 1; port <=hub_info->port_count; ++port) {401 for (port = 0; port < hub_info->port_count; ++port) { 425 402 opResult = usb_hub_set_port_feature( 426 403 hub_info->control_pipe, 427 404 port, USB_HUB_FEATURE_PORT_POWER); 428 405 if (opResult != EOK) { 429 usb_log_error(" Cannot power on port %zu: %s.\n",430 port, str_error(opResult));406 usb_log_error("cannot power on port %d; %d\n", 407 port, opResult); 431 408 } 432 }433 opResult = usb_hub_clear_feature(hub_info->control_pipe,434 USB_HUB_FEATURE_C_HUB_LOCAL_POWER);435 if (opResult != EOK) {436 usb_log_error("cannnot clear hub power change flag: "437 "%d\n",438 opResult);439 409 } 440 410 }
Note:
See TracChangeset
for help on using the changeset viewer.