Changeset 54b141a in mainline for uspace/drv/usbhub/utils.c


Ignore:
Timestamp:
2010-12-04T17:01:24Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e28d228
Parents:
2cb6571 (diff), ad104e0 (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.
Message:

Merge with vojtechhorky/

File:
1 moved

Legend:

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

    r2cb6571 r54b141a  
    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);
    111 
    112111usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
    113112        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
    114         //get parent device
    115         device_t * my_hcd = device;
    116         while (my_hcd->parent)
    117                 my_hcd = my_hcd->parent;
    118         //dev->
    119         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    120         //we add the hub into the first hc
    121         //link_t *link_hc = hc_list.next;
    122         //usb_hc_device_t *hc = list_get_instance(link_hc,
    123         //              usb_hc_device_t, link);
    124         //must get generic device info
    125 
    126113
    127114        return result;
     
    134121 */
    135122int usb_add_hub_device(device_t *dev) {
    136         //usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link);
    137         assert(dev->parent);
    138         usb_hc_device_t *hc = (usb_hc_device_t*)dev->parent->driver_data;
    139         usb_address_t addr =usb_use_free_address(hc);
    140         if(addr<0){
    141                 printf("[hcdhubd] ERROR: cannot find an address \n");
    142         }
    143         set_hub_address(hc, addr);
     123        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    144124
    145125        check_hub_changes();
     
    150130         * connected devices.
    151131         */
    152         //insert hub into list
    153         //find owner hcd
    154         device_t * my_hcd = dev;
    155         while (my_hcd->parent)
    156                 my_hcd = my_hcd->parent;
    157         //dev->
    158         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    159         my_hcd = dev;
    160         while (my_hcd->parent)
    161                 my_hcd = my_hcd->parent;
    162         //dev->
    163 
    164         printf("[hcdhubd]%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    165132
    166133        //create the hub structure
    167134        usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev);
    168 
    169 
    170         //append into the list
    171         //we add the hub into the first hc
    172         list_append(&hub_info->link, &hc->hubs);
    173 
    174 
     135        (void)hub_info;
    175136
    176137        return EOK;
     
    178139}
    179140
    180 /** Sample usage of usb_hc_async functions.
    181  * This function sets hub address using standard SET_ADDRESS request.
    182  *
    183  * @warning This function shall be removed once you are familiar with
    184  * the usb_hc_ API.
    185  *
    186  * @param hc Host controller the hub belongs to.
    187  * @param address New hub address.
    188  */
    189 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {
    190         printf("[hcdhubd]%s: setting hub address to %d\n", hc->generic->name, address);
    191         usb_target_t target = {0, 0};
    192         usb_handle_t handle;
    193         int rc;
    194 
    195         usb_device_request_setup_packet_t setup_packet = {
    196                 .request_type = 0,
    197                 .request = USB_DEVREQ_SET_ADDRESS,
    198                 .index = 0,
    199                 .length = 0,
    200         };
    201         setup_packet.value = address;
    202 
    203         rc = usb_hc_async_control_write_setup(hc, target,
    204                         &setup_packet, sizeof (setup_packet), &handle);
    205         if (rc != EOK) {
    206                 return;
    207         }
    208 
    209         rc = usb_hc_async_wait_for(handle);
    210         if (rc != EOK) {
    211                 return;
    212         }
    213 
    214         rc = usb_hc_async_control_write_status(hc, target, &handle);
    215         if (rc != EOK) {
    216                 return;
    217         }
    218 
    219         rc = usb_hc_async_wait_for(handle);
    220         if (rc != EOK) {
    221                 return;
    222         }
    223 
    224         printf("[hcdhubd]%s: hub address changed successfully to %d\n",
    225                         hc->generic->name, address);
    226 }
    227141
    228142/** Check changes on all known hubs.
     
    230144static void check_hub_changes(void) {
    231145        /*
    232          * Iterate through all HCs.
     146         * Iterate through all hubs.
    233147         */
    234         link_t *link_hc;
    235         for (link_hc = hc_list.next;
    236                         link_hc != &hc_list;
    237                         link_hc = link_hc->next) {
    238                 usb_hc_device_t *hc = list_get_instance(link_hc,
    239                                 usb_hc_device_t, link);
     148        for (; false; ) {
    240149                /*
    241                  * Iterate through all their hubs.
     150                 * Check status change pipe of this hub.
    242151                 */
    243                 link_t *link_hub;
    244                 for (link_hub = hc->hubs.next;
    245                                 link_hub != &hc->hubs;
    246                                 link_hub = link_hub->next) {
    247                         usb_hcd_hub_info_t *hub = list_get_instance(link_hub,
    248                                         usb_hcd_hub_info_t, link);
     152                usb_target_t target = {
     153                        .address = 5,
     154                        .endpoint = 1
     155                };
    249156
    250                         /*
    251                          * Check status change pipe of this hub.
    252                          */
    253                         usb_target_t target = {
    254                                 .address = hub->device->address,
    255                                 .endpoint = 1
    256                         };
     157                size_t port_count = 7;
    257158
    258                         // FIXME: count properly
    259                         size_t byte_length = (hub->port_count / 8) + 1;
     159                /*
     160                 * Connect to respective HC.
     161                 */
     162                int hc = usb_drv_hc_connect(NULL, 0);
     163                if (hc < 0) {
     164                        continue;
     165                }
    260166
    261                         void *change_bitmap = malloc(byte_length);
    262                         size_t actual_size;
    263                         usb_handle_t handle;
     167                // FIXME: count properly
     168                size_t byte_length = (port_count / 8) + 1;
    264169
    265                         /*
    266                          * Send the request.
    267                          * FIXME: check returned value for possible errors
    268                          */
    269                         usb_hc_async_interrupt_in(hc, target,
    270                                         change_bitmap, byte_length, &actual_size,
    271                                         &handle);
     170                void *change_bitmap = malloc(byte_length);
     171                size_t actual_size;
     172                usb_handle_t handle;
    272173
    273                         usb_hc_async_wait_for(handle);
     174                /*
     175                 * Send the request.
     176                 * FIXME: check returned value for possible errors
     177                 */
     178                usb_drv_async_interrupt_in(hc, target,
     179                                change_bitmap, byte_length, &actual_size,
     180                                &handle);
    274181
    275                         /*
    276                          * TODO: handle the changes.
    277                          */
    278                 }
     182                usb_drv_async_wait_for(handle);
     183
     184                /*
     185                 * TODO: handle the changes.
     186                 */
     187
     188
     189                /*
     190                 * Hang-up the HC-connected phone.
     191                 */
     192                ipc_hangup(hc);
    279193        }
    280194}
Note: See TracChangeset for help on using the changeset viewer.