Changeset e1dbcbc in mainline for uspace/drv/usbhub/usbhub.c
- Timestamp:
- 2011-04-29T13:43:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a81a1d09
- Parents:
- 380e0364 (diff), f19f1b7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r380e0364 re1dbcbc 45 45 #include <usb/request.h> 46 46 #include <usb/classes/hub.h> 47 #include <usb/devpoll.h> 47 48 #include <stdio.h> 48 49 … … 71 72 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info); 72 73 73 74 /// \TODO malloc checking75 74 76 75 //********************************************* … … 104 103 } 105 104 106 usb_pipe_start_session(hub_info->control_pipe);107 105 //set hub configuration 108 106 opResult = usb_hub_set_configuration(hub_info); … … 121 119 return opResult; 122 120 } 123 usb_pipe_end_session(hub_info->control_pipe); 124 125 /// \TODO what is this? 126 usb_log_debug("Creating `hub' function.\n"); 121 122 usb_log_debug("Creating 'hub' function in DDF.\n"); 127 123 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 128 124 fun_exposed, "hub"); … … 152 148 bool hub_port_changes_callback(usb_device_t *dev, 153 149 uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) { 150 usb_log_debug("hub_port_changes_callback\n"); 154 151 usb_hub_info_t *hub = (usb_hub_info_t *) arg; 155 152 … … 174 171 leave: 175 172 /* FIXME: proper interval. */ 176 async_usleep(1000 * 1000 * 10);173 async_usleep(1000 * 250); 177 174 178 175 return true; … … 216 213 // get hub descriptor 217 214 usb_log_debug("creating serialized descriptor\n"); 218 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);215 uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE]; 219 216 usb_hub_descriptor_t * descriptor; 220 217 int opResult; … … 234 231 } 235 232 usb_log_debug2("deserializing descriptor\n"); 236 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 233 descriptor = usb_create_deserialized_hub_desriptor( 234 serialized_descriptor); 237 235 if (descriptor == NULL) { 238 236 usb_log_warning("could not deserialize descriptor \n"); 239 return opResult;237 return ENOMEM; 240 238 } 241 239 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 242 240 hub_info->port_count = descriptor->ports_count; 243 241 /// \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); 244 246 hub_info->ports = malloc( 245 247 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 248 if(!hub_info->ports){ 249 return ENOMEM; 250 } 246 251 size_t port; 247 for (port = 0; port < hub_info->port_count + 1; port++) {252 for (port = 0; port < hub_info->port_count + 1; ++port) { 248 253 usb_hub_port_init(&hub_info->ports[port]); 249 254 } 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 } 250 281 usb_log_debug2("freeing data\n"); 251 free(serialized_descriptor);252 free(descriptor->devices_removable);253 282 free(descriptor); 254 283 return EOK; … … 312 341 * auto destruction, this could work better. 313 342 */ 314 int rc = usb_ pipe_start_session(hub_info->control_pipe);343 int rc = usb_hc_connection_open(&hub_info->connection); 315 344 if (rc != EOK) { 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); 345 //usb_pipe_end_session(hub_info->control_pipe); 323 346 usb_log_error("Failed to open connection to HC: %s.\n", 324 347 str_error(rc)); … … 336 359 } 337 360 338 usb_log_info("Controlling hub `%s' (% dports).\n",361 usb_log_info("Controlling hub `%s' (%zu ports).\n", 339 362 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 340 363 return EOK; … … 389 412 usb_hub_status_t status) { 390 413 int opResult; 391 if ( usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) {414 if (!usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) { 392 415 //restart power on hub 393 416 opResult = usb_hub_set_feature(hub_info->control_pipe, … … 399 422 } else {//power reestablished on hub- restart ports 400 423 size_t port; 401 for (port = 0; port <hub_info->port_count; ++port) {424 for (port = 1; port <= hub_info->port_count; ++port) { 402 425 opResult = usb_hub_set_port_feature( 403 426 hub_info->control_pipe, 404 427 port, USB_HUB_FEATURE_PORT_POWER); 405 428 if (opResult != EOK) { 406 usb_log_error(" cannot power on port %d; %d\n",407 port, opResult);429 usb_log_error("Cannot power on port %zu: %s.\n", 430 port, str_error(opResult)); 408 431 } 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); 409 439 } 410 440 }
Note:
See TracChangeset
for help on using the changeset viewer.