Changeset 4317827 in mainline for uspace/drv/usbhub/utils.c


Ignore:
Timestamp:
2010-12-04T14:00:41Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36c410e
Parents:
62c9661
Message:

USB hub driver in separate task

The commit only includes changes necessary to get working (i.e. appearing
under /dev/devices) hub and VHC.

Clean-up will come later.

File:
1 moved

Legend:

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

    r62c9661 r4317827  
    3333 * @brief Hub driver.
    3434 */
    35 #include <usb/hcdhubd.h>
     35#include <driver.h>
    3636#include <usb/devreq.h>
    3737#include <usbhc_iface.h>
     38#include <usb/usbdrv.h>
    3839#include <usb/descriptor.h>
    3940#include <driver.h>
     
    4142#include <errno.h>
    4243#include <usb/classes/hub.h>
    43 #include "hcdhubd_private.h"
     44#include "usbhub.h"
    4445
    4546static void check_hub_changes(void);
     
    108109//*********************************************
    109110
    110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);
     111static void set_hub_address(device_t *dev, usb_address_t address);
    111112
    112113usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
    113114        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
    114         //get parent device
    115         /// @TODO this code is not correct
    116         device_t * my_hcd = device;
    117         while (my_hcd->parent)
    118                 my_hcd = my_hcd->parent;
    119         //dev->
    120         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    121         //we add the hub into the first hc
    122         //link_t *link_hc = hc_list.next;
    123         //usb_hc_device_t *hc = list_get_instance(link_hc,
    124         //              usb_hc_device_t, link);
    125         //must get generic device info
    126 
    127115
    128116        return result;
     
    135123 */
    136124int usb_add_hub_device(device_t *dev) {
    137         usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link);
    138         set_hub_address(hc, 5);
     125        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
     126        set_hub_address(dev, 5);
    139127
    140128        check_hub_changes();
     
    145133         * connected devices.
    146134         */
    147         //insert hub into list
    148         //find owner hcd
    149         device_t * my_hcd = dev;
    150         while (my_hcd->parent)
    151                 my_hcd = my_hcd->parent;
    152         //dev->
    153         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    154         my_hcd = dev;
    155         while (my_hcd->parent)
    156                 my_hcd = my_hcd->parent;
    157         //dev->
    158 
    159         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    160135
    161136        //create the hub structure
    162137        usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev);
    163 
    164 
    165         //append into the list
    166         //we add the hub into the first hc
    167         list_append(&hub_info->link, &hc->hubs);
    168 
    169 
     138        (void)hub_info;
    170139
    171140        return EOK;
     
    182151 * @param address New hub address.
    183152 */
    184 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {
    185         printf("%s: setting hub address to %d\n", hc->generic->name, address);
     153static void set_hub_address(device_t *dev, usb_address_t address) {
     154        printf(NAME ": setting hub address to %d\n", address);
    186155        usb_target_t target = {0, 0};
    187156        usb_handle_t handle;
     
    196165        setup_packet.value = address;
    197166
    198         rc = usb_hc_async_control_write_setup(hc, target,
     167        int hc = usb_drv_hc_connect(dev, 0);
     168
     169        rc = usb_drv_async_control_write_setup(hc, target,
    199170                        &setup_packet, sizeof (setup_packet), &handle);
    200171        if (rc != EOK) {
     
    202173        }
    203174
    204         rc = usb_hc_async_wait_for(handle);
    205         if (rc != EOK) {
    206                 return;
    207         }
    208 
    209         rc = usb_hc_async_control_write_status(hc, target, &handle);
    210         if (rc != EOK) {
    211                 return;
    212         }
    213 
    214         rc = usb_hc_async_wait_for(handle);
    215         if (rc != EOK) {
    216                 return;
    217         }
    218 
    219         printf("%s: hub address changed\n", hc->generic->name);
     175        rc = usb_drv_async_wait_for(handle);
     176        if (rc != EOK) {
     177                return;
     178        }
     179
     180        rc = usb_drv_async_control_write_status(hc, target, &handle);
     181        if (rc != EOK) {
     182                return;
     183        }
     184
     185        rc = usb_drv_async_wait_for(handle);
     186        if (rc != EOK) {
     187                return;
     188        }
     189
     190        printf(NAME ": hub address changed\n");
    220191}
    221192
     
    224195static void check_hub_changes(void) {
    225196        /*
    226          * Iterate through all HCs.
     197         * Iterate through all hubs.
    227198         */
    228         link_t *link_hc;
    229         for (link_hc = hc_list.next;
    230                         link_hc != &hc_list;
    231                         link_hc = link_hc->next) {
    232                 usb_hc_device_t *hc = list_get_instance(link_hc,
    233                                 usb_hc_device_t, link);
    234                 /*
    235                  * Iterate through all their hubs.
    236                  */
    237                 link_t *link_hub;
    238                 for (link_hub = hc->hubs.next;
    239                                 link_hub != &hc->hubs;
    240                                 link_hub = link_hub->next) {
    241                         usb_hcd_hub_info_t *hub = list_get_instance(link_hub,
    242                                         usb_hcd_hub_info_t, link);
    243 
    244                         /*
    245                          * Check status change pipe of this hub.
    246                          */
    247                         usb_target_t target = {
    248                                 .address = hub->device->address,
    249                                 .endpoint = 1
    250                         };
    251 
    252                         // FIXME: count properly
    253                         size_t byte_length = (hub->port_count / 8) + 1;
    254 
    255                         void *change_bitmap = malloc(byte_length);
    256                         size_t actual_size;
    257                         usb_handle_t handle;
    258 
    259                         /*
    260                          * Send the request.
    261                          * FIXME: check returned value for possible errors
    262                          */
    263                         usb_hc_async_interrupt_in(hc, target,
    264                                         change_bitmap, byte_length, &actual_size,
    265                                         &handle);
    266 
    267                         usb_hc_async_wait_for(handle);
    268 
    269                         /*
    270                          * TODO: handle the changes.
    271                          */
     199        for (; false; ) {
     200                /*
     201                 * Check status change pipe of this hub.
     202                 */
     203                usb_target_t target = {
     204                        .address = 5,
     205                        .endpoint = 1
     206                };
     207
     208                size_t port_count = 7;
     209
     210                /*
     211                 * Connect to respective HC.
     212                 */
     213                int hc = usb_drv_hc_connect(NULL, 0);
     214                if (hc < 0) {
     215                        continue;
    272216                }
     217
     218                // FIXME: count properly
     219                size_t byte_length = (port_count / 8) + 1;
     220
     221                void *change_bitmap = malloc(byte_length);
     222                size_t actual_size;
     223                usb_handle_t handle;
     224
     225                /*
     226                 * Send the request.
     227                 * FIXME: check returned value for possible errors
     228                 */
     229                usb_drv_async_interrupt_in(hc, target,
     230                                change_bitmap, byte_length, &actual_size,
     231                                &handle);
     232
     233                usb_drv_async_wait_for(handle);
     234
     235                /*
     236                 * TODO: handle the changes.
     237                 */
     238
     239
     240                /*
     241                 * Hang-up the HC-connected phone.
     242                 */
     243                ipc_hangup(hc);
    273244        }
    274245}
Note: See TracChangeset for help on using the changeset viewer.