Changeset 243cb86 in mainline for uspace/drv/usbhub/utils.c


Ignore:
Timestamp:
2010-12-12T10:50:19Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8365533
Parents:
101ef25c (diff), ebb98c5 (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 from development + several changes to hid driver.

Changes to hid driver:

  • copied some code to usbkbd_get_descriptors() function
  • base structure for hid descriptor and report parser (files uspace/lib/usb/include/usb/classes/hidparser.h

and uspace/lib/usb/src/hidparser.c)

File:
1 moved

Legend:

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

    r101ef25c r243cb86  
    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         /// @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 
    127113
    128114        return result;
     
    135121 */
    136122int 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);
     123        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    139124
    140125        check_hub_changes();
     
    145130         * connected devices.
    146131         */
    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);
    160132
    161133        //create the hub structure
    162134        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 
     135        (void)hub_info;
    170136
    171137        return EOK;
     
    173139}
    174140
    175 /** Sample usage of usb_hc_async functions.
    176  * This function sets hub address using standard SET_ADDRESS request.
    177  *
    178  * @warning This function shall be removed once you are familiar with
    179  * the usb_hc_ API.
    180  *
    181  * @param hc Host controller the hub belongs to.
    182  * @param address New hub address.
    183  */
    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);
    186         usb_target_t target = {0, 0};
    187         usb_handle_t handle;
    188         int rc;
    189 
    190         usb_device_request_setup_packet_t setup_packet = {
    191                 .request_type = 0,
    192                 .request = USB_DEVREQ_SET_ADDRESS,
    193                 .index = 0,
    194                 .length = 0,
    195         };
    196         setup_packet.value = address;
    197 
    198         rc = usb_hc_async_control_write_setup(hc, target,
    199                         &setup_packet, sizeof (setup_packet), &handle);
    200         if (rc != EOK) {
    201                 return;
    202         }
    203 
    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);
    220 }
    221141
    222142/** Check changes on all known hubs.
     
    224144static void check_hub_changes(void) {
    225145        /*
    226          * Iterate through all HCs.
     146         * Iterate through all hubs.
    227147         */
    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                          */
     148        for (; false; ) {
     149                /*
     150                 * Check status change pipe of this hub.
     151                 */
     152                usb_target_t target = {
     153                        .address = 5,
     154                        .endpoint = 1
     155                };
     156
     157                size_t port_count = 7;
     158
     159                /*
     160                 * Connect to respective HC.
     161                 */
     162                int hc = usb_drv_hc_connect(NULL, 0);
     163                if (hc < 0) {
     164                        continue;
    272165                }
     166
     167                // FIXME: count properly
     168                size_t byte_length = (port_count / 8) + 1;
     169
     170                void *change_bitmap = malloc(byte_length);
     171                size_t actual_size;
     172                usb_handle_t handle;
     173
     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);
     181
     182                usb_drv_async_wait_for(handle);
     183
     184                /*
     185                 * TODO: handle the changes.
     186                 */
     187
     188                /*
     189                 * WARNING: sample code, will not work out of the box.
     190                 * And does not contain code for checking for errors.
     191                 */
     192#if 0
     193                /*
     194                 * Before opening the port, we must acquire the default
     195                 * address.
     196                 */
     197                usb_drv_reserve_default_address(hc);
     198
     199                usb_address_t new_device_address = usb_drv_request_address(hc);
     200
     201                // TODO: open the port
     202
     203                // TODO: send request for setting address to new_device_address
     204
     205                /*
     206                 * Once new address is set, we can release the default
     207                 * address.
     208                 */
     209                usb_drv_release_default_address(hc);
     210
     211                /*
     212                 * Obtain descriptors and create match ids for devman.
     213                 */
     214
     215                // TODO: get device descriptors
     216
     217                // TODO: create match ids
     218
     219                // TODO: add child device
     220
     221                // child_device_register sets the device handle
     222                // TODO: store it here
     223                devman_handle_t new_device_handle = 0;
     224
     225                /*
     226                 * Inform the HC that the new device has devman handle
     227                 * assigned.
     228                 */
     229                usb_drv_bind_address(hc, new_device_address, new_device_handle);
     230
     231                /*
     232                 * That's all.
     233                 */
     234#endif
     235
     236
     237                /*
     238                 * Hang-up the HC-connected phone.
     239                 */
     240                ipc_hangup(hc);
    273241        }
    274242}
Note: See TracChangeset for help on using the changeset viewer.