Changeset f35b294 in mainline
- Timestamp:
- 2011-04-09T17:50:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a43f1d18
- Parents:
- 1e1b1a9
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ohci/root_hub.c
r1e1b1a9 rf35b294 115 115 116 116 static const uint32_t hub_set_feature_valid_mask = 117 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT); 117 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) | 118 (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER); 118 119 119 120 … … 586 587 if (!((1 << feature) & hub_set_feature_valid_mask)) 587 588 return EINVAL; 589 if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER) 590 feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16; 588 591 instance->registers->rh_status = 589 592 (instance->registers->rh_status | (1 << feature)) -
uspace/drv/usbhub/port_status.h
r1e1b1a9 rf35b294 96 96 usb_hub_create_port_status_request(uint16_t port) { 97 97 usb_device_request_setup_packet_t * result = 98 usb_new(usb_device_request_setup_packet_t);98 malloc(sizeof(usb_device_request_setup_packet_t)); 99 99 usb_hub_set_port_status_request(result, port); 100 100 return result; … … 158 158 usb_hub_create_enable_port_request(uint16_t port) { 159 159 usb_device_request_setup_packet_t * result = 160 usb_new(usb_device_request_setup_packet_t);160 malloc(sizeof(usb_device_request_setup_packet_t)); 161 161 usb_hub_set_enable_port_request(result, port); 162 162 return result; … … 186 186 usb_hub_create_disable_port_request(uint16_t port) { 187 187 usb_device_request_setup_packet_t * result = 188 usb_new(usb_device_request_setup_packet_t);188 malloc(sizeof(usb_device_request_setup_packet_t)); 189 189 usb_hub_set_disable_port_request(result, port); 190 190 return result; … … 214 214 usb_hub_create_reset_port_request(uint16_t port) { 215 215 usb_device_request_setup_packet_t * result = 216 usb_new(usb_device_request_setup_packet_t);216 malloc(sizeof(usb_device_request_setup_packet_t)); 217 217 usb_hub_set_reset_port_request(result, port); 218 218 return result; … … 256 256 * @return 257 257 */ 258 static inline bool usb_port_ get_bit(usb_port_status_t *status, int idx) {259 return ( (*status)&(1 << idx))!=0;258 static inline bool usb_port_is_status(usb_port_status_t status, int idx) { 259 return (status&(1 << idx))!=0; 260 260 } 261 261 … … 267 267 * @param value 268 268 */ 269 static inline void usb_port_s et_bit(269 static inline void usb_port_status_set_bit( 270 270 usb_port_status_t * status, int idx, bool value) { 271 271 (*status) = value ? … … 281 281 * @return 282 282 */ 283 static inline bool usb_hub_ get_bit(usb_hub_status_t *status, int idx) {284 return ( (*status)&(1 << idx))!=0;283 static inline bool usb_hub_is_status(usb_hub_status_t status, int idx) { 284 return (status&(1 << idx))!=0; 285 285 } 286 286 … … 292 292 * @param value 293 293 */ 294 static inline void usb_hub_s et_bit(294 static inline void usb_hub_status_set_bit( 295 295 usb_hub_status_t * status, int idx, bool value) { 296 296 (*status) = value ? … … 299 299 } 300 300 301 302 #if 0 301 303 /** 302 304 * connection status geter for port status … … 425 427 } 426 428 429 #endif 430 427 431 //low speed device attached 428 432 /** … … 432 436 * @return true if low speed device is attached 433 437 */ 434 static inline bool usb_port_low_speed(usb_port_status_t *status) {435 return usb_port_ get_bit(status, 9);436 } 437 438 /** 439 * set device connected bit in port status438 static inline bool usb_port_low_speed(usb_port_status_t status) { 439 return usb_port_is_status(status, 9); 440 } 441 442 /** 443 * set low speed device connected bit in port status 440 444 * 441 445 * @param status … … 443 447 */ 444 448 static inline void usb_port_set_low_speed(usb_port_status_t * status, bool low_speed) { 445 usb_port_s et_bit(status, 9, low_speed);449 usb_port_status_set_bit(status, 9, low_speed); 446 450 } 447 451 … … 453 457 * @return true if high speed device is on port 454 458 */ 455 static inline bool usb_port_high_speed(usb_port_status_t *status) {456 return usb_port_ get_bit(status, 10);459 static inline bool usb_port_high_speed(usb_port_status_t status) { 460 return usb_port_is_status(status, 10); 457 461 } 458 462 … … 464 468 */ 465 469 static inline void usb_port_set_high_speed(usb_port_status_t * status, bool high_speed) { 466 usb_port_s et_bit(status, 10, high_speed);470 usb_port_status_set_bit(status, 10, high_speed); 467 471 } 468 472 … … 473 477 * @return speed of usb device (for more see usb specification) 474 478 */ 475 static inline usb_speed_t usb_port_speed(usb_port_status_t *status) {479 static inline usb_speed_t usb_port_speed(usb_port_status_t status) { 476 480 if (usb_port_low_speed(status)) 477 481 return USB_SPEED_LOW; … … 481 485 } 482 486 483 487 #if 0 484 488 //connect change 485 489 /** … … 673 677 usb_hub_set_bit(status, 17, change); 674 678 } 679 #endif 675 680 676 681 -
uspace/drv/usbhub/usbhub.c
r1e1b1a9 rf35b294 61 61 static int usb_hub_set_configuration(usb_hub_info_t * hub_info); 62 62 63 //static int usb_hub_check_hub_changes(usb_hub_info_t * hub_info_param);63 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info); 64 64 65 65 static int usb_process_hub_over_current(usb_hub_info_t * hub_info, 66 66 usb_hub_status_t status); 67 67 68 68 static int usb_process_hub_power_change(usb_hub_info_t * hub_info, 69 69 usb_hub_status_t status); 70 70 71 71 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info); … … 79 79 // 80 80 //********************************************* 81 82 83 81 84 82 /** … … 96 94 usb_log_debug("Initializing USB wire abstraction.\n"); 97 95 int opResult = usb_hc_connection_initialize_from_device( 98 99 96 &hub_info->connection, 97 hub_info->usb_device->ddf_dev); 100 98 if (opResult != EOK) { 101 99 usb_log_error("could not initialize connection to device, " 102 103 100 "errno %d\n", 101 opResult); 104 102 free(hub_info); 105 103 return opResult; … … 111 109 if (opResult != EOK) { 112 110 usb_log_error("could not set hub configuration, errno %d\n", 113 111 opResult); 114 112 free(hub_info); 115 113 return opResult; … … 118 116 opResult = usb_hub_process_hub_specific_info(hub_info); 119 117 if (opResult != EOK) { 120 usb_log_error("could not set hub configuration, errno %d\n",121 118 usb_log_error("could process hub specific info, errno %d\n", 119 opResult); 122 120 free(hub_info); 123 121 return opResult; 124 122 } 125 123 usb_pipe_end_session(hub_info->control_pipe); 126 127 124 128 125 /// \TODO what is this? 129 126 usb_log_debug("Creating `hub' function.\n"); 130 127 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 131 128 fun_exposed, "hub"); 132 129 assert(hub_fun != NULL); 133 130 hub_fun->ops = NULL; 134 131 135 int rc = ddf_fun_bind(hub_fun); 136 assert(rc == EOK); 137 rc = ddf_fun_add_to_class(hub_fun, "hub"); 138 assert(rc == EOK); 139 132 opResult = ddf_fun_bind(hub_fun); 133 assert(opResult == EOK); 134 opResult = ddf_fun_add_to_class(hub_fun, "hub"); 135 assert(opResult == EOK); 136 137 opResult = usb_hub_start_hub_fibril(hub_info); 138 if(opResult!=EOK) 139 free(hub_info); 140 return opResult; 141 } 142 143 144 /** Callback for polling hub for changes. 145 * 146 * @param dev Device where the change occured. 147 * @param change_bitmap Bitmap of changed ports. 148 * @param change_bitmap_size Size of the bitmap in bytes. 149 * @param arg Custom argument, points to @c usb_hub_info_t. 150 * @return Whether to continue polling. 151 */ 152 bool hub_port_changes_callback(usb_device_t *dev, 153 uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) { 154 usb_hub_info_t *hub = (usb_hub_info_t *) arg; 155 156 /* FIXME: check that we received enough bytes. */ 157 if (change_bitmap_size == 0) { 158 goto leave; 159 } 160 161 bool change; 162 change = ((uint8_t*) change_bitmap)[0] & 1; 163 if (change) { 164 usb_hub_process_global_interrupt(hub); 165 } 166 167 size_t port; 168 for (port = 1; port < hub->port_count + 1; port++) { 169 bool change = (change_bitmap[port / 8] >> (port % 8)) % 2; 170 if (change) { 171 usb_hub_process_interrupt(hub, port); 172 } 173 } 174 leave: 175 /* FIXME: proper interval. */ 176 async_usleep(1000 * 1000 * 10); 177 178 return true; 179 } 180 181 /** 182 * release default address used by given hub 183 * 184 * Also unsets hub->is_default_address_used. Convenience wrapper function. 185 * @note hub->connection MUST be open for communication 186 * @param hub hub representation 187 * @return error code 188 */ 189 int usb_hub_release_default_address(usb_hub_info_t * hub) { 190 int opResult = usb_hc_release_default_address(&hub->connection); 191 if (opResult != EOK) { 192 usb_log_error("could not release default address, errno %d\n", 193 opResult); 194 return opResult; 195 } 196 hub->is_default_address_used = false; 197 return EOK; 198 } 199 200 201 //********************************************* 202 // 203 // support functions 204 // 205 //********************************************* 206 207 /** 208 * create usb_hub_info_t structure 209 * 210 * Does only basic copying of known information into new structure. 211 * @param usb_dev usb device structure 212 * @return basic usb_hub_info_t structure 213 */ 214 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 215 usb_hub_info_t * result = malloc(sizeof(usb_hub_info_t)); 216 if (!result) return NULL; 217 result->usb_device = usb_dev; 218 result->status_change_pipe = usb_dev->pipes[0].pipe; 219 result->control_pipe = &usb_dev->ctrl_pipe; 220 result->is_default_address_used = false; 221 return result; 222 } 223 224 /** 225 * Load hub-specific information into hub_info structure and process if needed 226 * 227 * Particularly read port count and initialize structure holding port 228 * information. If there are non-removable devices, start initializing them. 229 * This function is hub-specific and should be run only after the hub is 230 * configured using usb_hub_set_configuration function. 231 * @param hub_info hub representation 232 * @return error code 233 */ 234 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) { 235 // get hub descriptor 236 usb_log_debug("creating serialized descriptor\n"); 237 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 238 usb_hub_descriptor_t * descriptor; 239 int opResult; 240 241 size_t received_size; 242 opResult = usb_request_get_descriptor(hub_info->control_pipe, 243 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 244 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 245 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 246 247 if (opResult != EOK) { 248 usb_log_error("failed when receiving hub descriptor, " 249 "badcode = %d\n", 250 opResult); 251 free(serialized_descriptor); 252 return opResult; 253 } 254 usb_log_debug2("deserializing descriptor\n"); 255 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 256 if (descriptor == NULL) { 257 usb_log_warning("could not deserialize descriptor \n"); 258 return opResult; 259 } 260 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 261 hub_info->port_count = descriptor->ports_count; 262 /// \TODO this is not semantically correct 263 hub_info->ports = malloc( 264 sizeof (usb_hub_port_t) * (hub_info->port_count + 1)); 265 size_t port; 266 for (port = 0; port < hub_info->port_count + 1; port++) { 267 usb_hub_port_init(&hub_info->ports[port]); 268 } 269 usb_log_debug2("freeing data\n"); 270 free(serialized_descriptor); 271 free(descriptor->devices_removable); 272 free(descriptor); 273 return EOK; 274 } 275 276 /** 277 * Set configuration of hub 278 * 279 * Check whether there is at least one configuration and sets the first one. 280 * This function should be run prior to running any hub-specific action. 281 * @param hub_info hub representation 282 * @return error code 283 */ 284 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) { 285 //device descriptor 286 usb_standard_device_descriptor_t *std_descriptor 287 = &hub_info->usb_device->descriptors.device; 288 usb_log_debug("hub has %d configurations\n", 289 std_descriptor->configuration_count); 290 if (std_descriptor->configuration_count < 1) { 291 usb_log_error("there are no configurations available\n"); 292 return EINVAL; 293 } 294 295 usb_standard_configuration_descriptor_t *config_descriptor 296 = (usb_standard_configuration_descriptor_t *) 297 hub_info->usb_device->descriptors.configuration; 298 299 /* Set configuration. */ 300 int opResult = usb_request_set_configuration( 301 &hub_info->usb_device->ctrl_pipe, 302 config_descriptor->configuration_number); 303 304 if (opResult != EOK) { 305 usb_log_error("Failed to set hub configuration: %s.\n", 306 str_error(opResult)); 307 return opResult; 308 } 309 usb_log_debug("\tused configuration %d\n", 310 config_descriptor->configuration_number); 311 312 return EOK; 313 } 314 315 /** 316 * create and start fibril with hub control loop 317 * 318 * Before the fibril is started, the control pipe and host controller 319 * connection of the hub is open. 320 * 321 * @param hub_info hub representing structure 322 * @return error code 323 */ 324 static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){ 140 325 /* 141 326 * The processing will require opened control pipe and connection … … 146 331 * auto destruction, this could work better. 147 332 */ 148 rc = usb_pipe_start_session(&usb_dev->ctrl_pipe);333 int rc = usb_pipe_start_session(hub_info->control_pipe); 149 334 if (rc != EOK) { 150 335 usb_log_error("Failed to start session on control pipe: %s.\n", 151 336 str_error(rc)); 152 goto leave;337 return rc; 153 338 } 154 339 rc = usb_hc_connection_open(&hub_info->connection); 155 340 if (rc != EOK) { 156 usb_pipe_end_session( &usb_dev->ctrl_pipe);341 usb_pipe_end_session(hub_info->control_pipe); 157 342 usb_log_error("Failed to open connection to HC: %s.\n", 158 343 str_error(rc)); 159 goto leave;344 return rc; 160 345 } 161 346 162 347 rc = usb_device_auto_poll(hub_info->usb_device, 0, 163 hub_port_changes_callback, ((hub_info->port_count +1) / 8) + 1,348 hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1, 164 349 NULL, hub_info); 165 350 if (rc != EOK) { … … 171 356 172 357 usb_log_info("Controlling hub `%s' (%d ports).\n", 173 358 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 174 359 return EOK; 175 leave: 176 free(hub_info); 177 178 return rc; 179 } 180 181 182 //********************************************* 183 // 184 // hub driver code, main loop and port handling 185 // 186 //********************************************* 187 188 189 /** Callback for polling hub for changes. 190 * 191 * @param dev Device where the change occured. 192 * @param change_bitmap Bitmap of changed ports. 193 * @param change_bitmap_size Size of the bitmap in bytes. 194 * @param arg Custom argument, points to @c usb_hub_info_t. 195 * @return Whether to continue polling. 196 */ 197 bool hub_port_changes_callback(usb_device_t *dev, 198 uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) 199 { 200 usb_hub_info_t *hub = (usb_hub_info_t *) arg; 201 202 /* FIXME: check that we received enough bytes. */ 203 if (change_bitmap_size == 0) { 204 goto leave; 205 } 206 207 bool change; 208 change = ((uint8_t*)change_bitmap)[0] & 1; 209 if(change){ 210 usb_hub_process_global_interrupt(hub); 211 } 212 213 size_t port; 214 for (port = 1; port < hub->port_count + 1; port++) { 215 bool change = (change_bitmap[port / 8] >> (port % 8)) % 2; 216 if (change) { 217 usb_hub_process_interrupt(hub, port); 218 } 219 } 220 221 222 223 224 225 leave: 226 /* FIXME: proper interval. */ 227 async_usleep(1000 * 1000 * 10 ); 228 229 return true; 230 } 231 232 233 /** 234 * release default address used by given hub 235 * 236 * Also unsets hub->is_default_address_used. Convenience wrapper function. 237 * @note hub->connection MUST be open for communication 238 * @param hub hub representation 239 * @return error code 240 */ 241 int usb_hub_release_default_address(usb_hub_info_t * hub) { 242 int opResult = usb_hc_release_default_address(&hub->connection); 243 if (opResult != EOK) { 244 usb_log_error("could not release default address, errno %d\n", 245 opResult); 246 return opResult; 247 } 248 hub->is_default_address_used = false; 249 return EOK; 250 } 251 252 253 //********************************************* 254 // 255 // support functions 256 // 257 //********************************************* 258 259 /** 260 * create usb_hub_info_t structure 261 * 262 * Does only basic copying of known information into new structure. 263 * @param usb_dev usb device structure 264 * @return basic usb_hub_info_t structure 265 */ 266 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 267 usb_hub_info_t * result = usb_new(usb_hub_info_t); 268 if (!result) return NULL; 269 result->usb_device = usb_dev; 270 result->status_change_pipe = usb_dev->pipes[0].pipe; 271 result->control_pipe = &usb_dev->ctrl_pipe; 272 result->is_default_address_used = false; 273 return result; 274 } 275 276 277 /** 278 * Load hub-specific information into hub_info structure and process if needed 279 * 280 * Particularly read port count and initialize structure holding port 281 * information. If there are non-removable devices, start initializing them. 282 * This function is hub-specific and should be run only after the hub is 283 * configured using usb_hub_set_configuration function. 284 * @param hub_info hub representation 285 * @return error code 286 */ 287 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) { 288 // get hub descriptor 289 usb_log_debug("creating serialized descriptor\n"); 290 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 291 usb_hub_descriptor_t * descriptor; 292 int opResult; 293 294 size_t received_size; 295 opResult = usb_request_get_descriptor(hub_info->control_pipe, 296 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 297 USB_DESCTYPE_HUB, 298 0, 0, serialized_descriptor, 299 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 300 301 if (opResult != EOK) { 302 usb_log_error("failed when receiving hub descriptor, " 303 "badcode = %d\n", 304 opResult); 305 free(serialized_descriptor); 306 return opResult; 307 } 308 usb_log_debug2("deserializing descriptor\n"); 309 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 310 if (descriptor == NULL) { 311 usb_log_warning("could not deserialize descriptor \n"); 312 return opResult; 313 } 314 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 315 hub_info->port_count = descriptor->ports_count; 316 /// \TODO this is not semantically correct 317 hub_info->ports = malloc(sizeof(usb_hub_port_t) * (hub_info->port_count+1)); 318 size_t port; 319 for (port = 0; port < hub_info->port_count + 1; port++) { 320 usb_hub_port_init(&hub_info->ports[port]); 321 } 322 usb_log_debug2("freeing data\n"); 323 free(serialized_descriptor); 324 free(descriptor->devices_removable); 325 free(descriptor); 326 return EOK; 327 } 328 329 /** 330 * Set configuration of hub 331 * 332 * Check whether there is at least one configuration and sets the first one. 333 * This function should be run prior to running any hub-specific action. 334 * @param hub_info hub representation 335 * @return error code 336 */ 337 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) { 338 //device descriptor 339 usb_standard_device_descriptor_t *std_descriptor 340 = &hub_info->usb_device->descriptors.device; 341 usb_log_debug("hub has %d configurations\n", 342 std_descriptor->configuration_count); 343 if (std_descriptor->configuration_count < 1) { 344 usb_log_error("there are no configurations available\n"); 345 return EINVAL; 346 } 347 348 usb_standard_configuration_descriptor_t *config_descriptor 349 = (usb_standard_configuration_descriptor_t *) 350 hub_info->usb_device->descriptors.configuration; 351 352 /* Set configuration. */ 353 int opResult = usb_request_set_configuration( 354 &hub_info->usb_device->ctrl_pipe, 355 config_descriptor->configuration_number); 356 357 if (opResult != EOK) { 358 usb_log_error("Failed to set hub configuration: %s.\n", 359 str_error(opResult)); 360 return opResult; 361 } 362 usb_log_debug("\tused configuration %d\n", 363 config_descriptor->configuration_number); 364 365 return EOK; 366 } 367 368 #if 0 369 /** 370 * check changes on hub 371 * 372 * Handles changes on each port with a status change. 373 * @param hub_info hub representation 374 * @return error code 375 */ 376 static int usb_hub_check_hub_changes(usb_hub_info_t * hub_info) { 377 int opResult; 378 opResult = usb_pipe_start_session( 379 hub_info->status_change_pipe); 380 //this might not be necessary - if all non-removables are ok, it is 381 //not needed here 382 opResult = usb_pipe_start_session(hub_info->control_pipe); 383 if (opResult != EOK) { 384 usb_log_error("could not initialize communication for hub; %d\n", 385 opResult); 386 return opResult; 387 } 388 389 size_t port_count = hub_info->port_count; 390 size_t byte_length = ((port_count + 1) / 8) + 1; 391 void *change_bitmap = malloc(byte_length); 392 size_t actual_size; 393 394 /* 395 * Send the request. 396 */ 397 opResult = usb_pipe_read( 398 hub_info->status_change_pipe, 399 change_bitmap, byte_length, &actual_size 400 ); 401 402 if (opResult != EOK) { 403 free(change_bitmap); 404 usb_log_warning("something went wrong while getting the" 405 "status of hub\n"); 406 usb_pipe_end_session(hub_info->status_change_pipe); 407 return opResult; 408 } 409 unsigned int port; 410 411 if (opResult != EOK) { 412 usb_log_error("could not start control pipe session %d\n", 413 opResult); 414 usb_pipe_end_session(hub_info->status_change_pipe); 415 return opResult; 416 } 417 opResult = usb_hc_connection_open(&hub_info->connection); 418 if (opResult != EOK) { 419 usb_log_error("could not start host controller session %d\n", 420 opResult); 421 usb_pipe_end_session(hub_info->control_pipe); 422 usb_pipe_end_session(hub_info->status_change_pipe); 423 return opResult; 424 } 425 426 ///todo, opresult check, pre obe konekce 427 bool interrupt; 428 interrupt = ((uint8_t*)change_bitmap)[0] & 1; 429 if(interrupt){ 430 usb_hub_process_global_interrupt(hub_info); 431 } 432 for (port = 1; port < port_count + 1; ++port) { 433 interrupt = 434 ((uint8_t*) change_bitmap)[port / 8] & (1<<(port % 8)); 435 if (interrupt) { 436 usb_hub_process_interrupt( 437 hub_info, port); 438 } 439 } 440 /// \todo check hub status 441 usb_hc_connection_close(&hub_info->connection); 442 usb_pipe_end_session(hub_info->control_pipe); 443 usb_pipe_end_session(hub_info->status_change_pipe); 444 free(change_bitmap); 445 return EOK; 446 } 447 448 #endif 360 } 361 362 //********************************************* 363 // 364 // change handling functions 365 // 366 //********************************************* 367 449 368 450 369 /** … … 457 376 */ 458 377 static int usb_process_hub_over_current(usb_hub_info_t * hub_info, 459 usb_hub_status_t status) 460 { 378 usb_hub_status_t status) { 461 379 int opResult; 462 if (usb_hub_over_current(&status)){380 if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){ 463 381 opResult = usb_hub_clear_feature(hub_info->control_pipe, 464 USB_HUB_FEATURE_PORT_POWER);382 USB_HUB_FEATURE_HUB_LOCAL_POWER); 465 383 if (opResult != EOK) { 466 384 usb_log_error("cannot power off hub: %d\n", 467 385 opResult); 468 386 } 469 } else{387 } else { 470 388 opResult = usb_hub_set_feature(hub_info->control_pipe, 471 USB_HUB_FEATURE_PORT_POWER);389 USB_HUB_FEATURE_HUB_LOCAL_POWER); 472 390 if (opResult != EOK) { 473 391 usb_log_error("cannot power on hub: %d\n", 474 392 opResult); 475 393 } 476 394 } … … 488 406 */ 489 407 static int usb_process_hub_power_change(usb_hub_info_t * hub_info, 490 usb_hub_status_t status) 491 { 408 usb_hub_status_t status) { 492 409 int opResult; 493 if (usb_hub_local_power_lost(&status)){410 if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) { 494 411 //restart power on hub 495 412 opResult = usb_hub_set_feature(hub_info->control_pipe, 496 USB_HUB_FEATURE_PORT_POWER);413 USB_HUB_FEATURE_HUB_LOCAL_POWER); 497 414 if (opResult != EOK) { 498 415 usb_log_error("cannot power on hub: %d\n", 499 416 opResult); 500 417 } 501 } else{//power reestablished on hub- restart ports418 } else {//power reestablished on hub- restart ports 502 419 size_t port; 503 for (port=0;port<hub_info->port_count;++port){420 for (port = 0; port < hub_info->port_count; ++port) { 504 421 opResult = usb_hub_set_port_feature( 505 506 422 hub_info->control_pipe, 423 port, USB_HUB_FEATURE_PORT_POWER); 507 424 if (opResult != EOK) { 508 425 usb_log_error("cannot power on port %d; %d\n", 509 426 port, opResult); 510 427 } 511 428 } … … 521 438 * @param hub_info hub instance 522 439 */ 523 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {440 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) { 524 441 usb_log_debug("global interrupt on a hub\n"); 525 442 usb_pipe_t *pipe = hub_info->control_pipe; … … 534 451 535 452 opResult = usb_pipe_control_read( 536 537 538 539 453 pipe, 454 &request, sizeof (usb_device_request_setup_packet_t), 455 &status, 4, &rcvd_size 456 ); 540 457 if (opResult != EOK) { 541 458 usb_log_error("could not get hub status\n"); … … 547 464 } 548 465 //port reset 549 if ( usb_hub_over_current_change(&status)) {550 usb_process_hub_over_current(hub_info,status);551 }552 if (usb_hub_local_power_change(&status)) {553 usb_process_hub_power_change(hub_info,status);554 }555 } 556 557 466 if ( 467 usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) { 468 usb_process_hub_over_current(hub_info, status); 469 } 470 if ( 471 usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) { 472 usb_process_hub_power_change(hub_info, status); 473 } 474 } 558 475 559 476 /** -
uspace/drv/usbhub/usbhub_private.h
r1e1b1a9 rf35b294 54 54 // 55 55 //************ 56 #define usb_new(type) (type*)malloc(sizeof(type))57 56 58 57 59 /**60 * Create hub structure instance61 *62 * Set the address and port count information most importantly.63 *64 * @param device65 * @param hc host controller phone66 * @return67 */68 58 usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device); 69 59 -
uspace/drv/usbhub/utils.c
r1e1b1a9 rf35b294 60 60 size_t size = 7; 61 61 //variable size according to port count 62 size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 > 0) ? 1 : 0);62 size_t var_size = (descriptor->ports_count+7)/8; 63 63 size += 2 * var_size; 64 uint8_t * result = (uint8_t*)malloc(size);64 uint8_t * result = malloc(size); 65 65 //size 66 66 result[0] = size; … … 84 84 } 85 85 86 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) { 87 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 86 usb_hub_descriptor_t * usb_deserialize_hub_desriptor( 87 void * serialized_descriptor) { 88 uint8_t * sdescriptor = serialized_descriptor; 88 89 89 90 if (sdescriptor[1] != USB_DESCTYPE_HUB) { 90 usb_log_warning("trying to deserialize wrong descriptor %x\n",sdescriptor[1]); 91 usb_log_warning("trying to deserialize wrong descriptor %x\n", 92 sdescriptor[1]); 91 93 return NULL; 92 94 } 93 95 94 usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t);96 usb_hub_descriptor_t * result = malloc(sizeof(usb_hub_descriptor_t)); 95 97 96 98 … … 100 102 result->pwr_on_2_good_time = sdescriptor[5]; 101 103 result->current_requirement = sdescriptor[6]; 102 size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0) 103 ? 1 : 0); 104 size_t var_size = (result->ports_count+7) / 8; 104 105 result->devices_removable = (uint8_t*) malloc(var_size); 105 106 -
uspace/lib/usb/include/usb/classes/hub.h
r1e1b1a9 rf35b294 43 43 */ 44 44 typedef enum { 45 USB_HUB_FEATURE_HUB_LOCAL_POWER = 0, 46 USB_HUB_FEATURE_HUB_OVER_CURRENT = 1, 45 47 USB_HUB_FEATURE_C_HUB_LOCAL_POWER = 0, 46 48 USB_HUB_FEATURE_C_HUB_OVER_CURRENT = 1, … … 59 61 /* USB_HUB_FEATURE_ = , */ 60 62 } usb_hub_class_feature_t; 63 61 64 62 65 /** Header of standard hub descriptor without the "variadic" part. */
Note:
See TracChangeset
for help on using the changeset viewer.