Changeset e6223239 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-03-26T15:56:57Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3da9b2
Parents:
f97717d9
Message:

attaching non-removable devices

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    rf97717d9 re6223239  
    5353#include "usb/classes/classes.h"
    5454
     55static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     56                usb_speed_t speed);
     57
     58static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
     59usb_hub_descriptor_t * descriptor);
     60
    5561int usb_hub_control_loop(void * hub_info_param){
    5662        usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
     
    9197
    9298/**
    93  * Load hub-specific information into hub_info structure.
     99 * Load hub-specific information into hub_info structure and process if needed
    94100 *
    95101 * Particularly read port count and initialize structure holding port
    96  * information.
     102 * information. If there are non-removable devices, start initializing them.
    97103 * This function is hub-specific and should be run only after the hub is
    98104 * configured using usb_hub_set_configuration function.
     
    100106 * @return error code
    101107 */
    102 static int usb_hub_get_hub_specific_info(usb_hub_info_t * hub_info){
     108static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info){
    103109        // get hub descriptor
    104110        usb_log_debug("creating serialized descriptor\n");
     
    107113
    108114        /* this was one fix of some bug, should not be needed anymore
     115         * these lines allow to reset hub once more, it can be used as
     116         * brute-force initialization for non-removable devices
    109117        int opResult = usb_request_set_configuration(&result->endpoints.control, 1);
    110118        if(opResult!=EOK){
     
    141149                hub_info->attached_devs[i].address=0;
    142150        }
     151        usb_hub_attach_non_removable_devices(hub_info, descriptor);
    143152        usb_log_debug2("freeing data\n");
    144153        free(serialized_descriptor);
     
    218227        }
    219228        //get port count and create attached_devs
    220         opResult = usb_hub_get_hub_specific_info(hub_info);
     229        opResult = usb_hub_process_hub_specific_info(hub_info);
    221230        if(opResult!=EOK){
    222231                usb_log_error("could not set hub configuration, errno %d\n",opResult);
     
    256265//*********************************************
    257266//
    258 //  hub driver code, main loop
     267//  hub driver code, main loop and port handling
    259268//
    260269//*********************************************
     270
     271/**
     272 * Perform \a usb_hub_init_add_device on all ports with non-removable device
     273 *
     274 * This will trigger operations leading to activated non-removable device.
     275 * Control pipe of the hub must be open fo communication.
     276 * @param hub hub instance
     277 * @param descriptor usb hub descriptor
     278 * @return error code
     279 */
     280static int usb_hub_attach_non_removable_devices(usb_hub_info_t * hub,
     281                usb_hub_descriptor_t * descriptor)
     282{
     283        usb_log_info("attaching non-removable devices(if any)\n");
     284        usb_device_request_setup_packet_t request;
     285        int opResult;
     286        size_t rcvd_size;
     287        usb_port_status_t status;
     288        uint8_t * non_removable_dev_bitmap = descriptor->devices_removable;
     289        //initialize all connected, non-removable devices
     290        int port;
     291        for(port=1;port<=descriptor->ports_count;++port){
     292                bool is_non_removable =
     293                                ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
     294                if(is_non_removable){
     295                        usb_log_debug("non-removable device on port %d\n",port);
     296                        usb_hub_set_port_status_request(&request, port);
     297                        opResult = usb_pipe_control_read(
     298                                        hub->control_pipe,
     299                                        &request, sizeof(usb_device_request_setup_packet_t),
     300                                        &status, 4, &rcvd_size
     301                                        );
     302                        if (opResult != EOK) {
     303                                usb_log_error("could not get port status of port %d errno:%d\n",
     304                                                port, opResult);
     305                                return opResult;
     306                        }
     307                        //this should be true..
     308                        if(usb_port_dev_connected(&status)){
     309                                usb_hub_init_add_device(hub,port,usb_port_speed(&status));
     310                        }
     311                }
     312        }
     313        return EOK;
     314}
     315
    261316
    262317/**
Note: See TracChangeset for help on using the changeset viewer.