Changeset 7034be15 in mainline for uspace/lib/usb/hcdhubd.c


Ignore:
Timestamp:
2010-11-19T23:00:31Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e27595b
Parents:
91db50ac
Message:

Various changes to HC driver framework API

Also, the root driver only registers VHC as its only child to clean-up
debug output from devman.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/hcdhubd.c

    r91db50ac r7034be15  
    3434 */
    3535#include "hcdhubd.h"
     36#include <usb_iface.h>
    3637#include <driver.h>
    3738#include <bool.h>
     
    4445static usb_hc_driver_t *hc_driver = NULL;
    4546
     47static usb_iface_t usb_interface = {
     48        .interrupt_out = NULL,
     49        .interrupt_in = NULL
     50};
     51
     52static device_ops_t usb_device_ops = {
     53        .interfaces[USB_DEV_IFACE] = &usb_interface
     54};
     55
    4656/** Callback when new device is detected and must be handled by this driver.
    4757 *
     
    6373                usb_hc_device_t *hc_dev = malloc(sizeof(usb_hc_device_t));
    6474                list_initialize(&hc_dev->link);
     75                hc_dev->transfer_ops = NULL;
    6576
    6677                hc_dev->generic = dev;
     
    7182                }
    7283
    73                 add_device_to_class(dev, "usbhc");
     84                /*
     85                 * Finish initialization of dev and hc_dev structures.
     86                 */
     87                hc_dev->generic->driver_data = hc_dev;
     88                dev->ops = &usb_device_ops;
     89
     90                /*
     91                 * FIXME: The following line causes devman to hang.
     92                 * Will investigate later why.
     93                 */
     94                // add_device_to_class(dev, "usbhc");
    7495
    7596                list_append(&hc_dev->link, &hc_list);
     
    128149                         * FIXME: check returned value for possible errors
    129150                         */
    130                         usb_hcd_local_transfer_interrupt_in(hc, target,
     151                        usb_hc_async_interrupt_in(hc, target,
    131152                            change_bitmap, byte_length, &actual_size,
    132153                            &handle);
    133154
    134                         usb_hcd_local_wait_for(handle);
     155                        usb_hc_async_wait_for(handle);
    135156
    136157                        /*
     
    187208int usb_hcd_add_root_hub(usb_hc_device_t *dev)
    188209{
     210        int rc;
     211
     212        /*
     213         * For testing/debugging purposes only.
     214         * Try to send some data to default USB address.
     215         */
     216        usb_target_t target = {0, 0};
     217        usb_handle_t handle = 0;
     218        char *data = (char *) "Hello, World!";
     219
     220
     221        (void)usb_hc_async_interrupt_out(dev, target, data, str_length(data), &handle);
     222        (void)usb_hc_async_wait_for(handle);
     223
    189224        /*
    190225         * Announce presence of child device.
     
    192227        device_t *hub = NULL;
    193228        match_id_t *match_id = NULL;
    194         int rc;
    195229
    196230        hub = create_device();
     
    215249
    216250        match_id->id = id;
    217         match_id->score = 10;
     251        match_id->score = 30;
    218252
    219253        add_match_id(&hub->match_ids, match_id);
     
    224258        }
    225259
     260        printf("%s: registered root hub\n", dev->generic->name);
    226261        return EOK;
    227262
     
    236271}
    237272
     273/** Issue interrupt OUT transfer to HC driven by current task.
     274 *
     275 * @param hc Host controller to handle the transfer.
     276 * @param target Target device address.
     277 * @param buffer Data buffer.
     278 * @param size Buffer size.
     279 * @param handle Transfer handle.
     280 * @return Error code.
     281 */
     282int usb_hc_async_interrupt_out(usb_hc_device_t *hc, usb_target_t target,
     283    void *buffer, size_t size,
     284    usb_handle_t *handle)
     285{
     286        if ((hc->transfer_ops == NULL)
     287            || (hc->transfer_ops->transfer_out == NULL)) {
     288                return ENOTSUP;
     289        }
     290
     291        /*
     292         * For debugging purposes only.
     293         * We need to find appropriate device in list of managed device
     294         * and pass it to the transfer callback function.
     295         */
     296        usb_hcd_attached_device_info_t dev = {
     297                .address = target.address,
     298                .endpoint_count = 0,
     299                .endpoints = NULL,
     300        };
     301        usb_hc_endpoint_info_t endpoint = {
     302                .endpoint = target.endpoint,
     303                .transfer_type = USB_TRANSFER_INTERRUPT,
     304                .direction = USB_DIRECTION_OUT,
     305                .data_toggle = 0
     306        };
     307
     308        hc->transfer_ops->transfer_out(hc, &dev, &endpoint, buffer, size, NULL, NULL);
     309
     310        *handle = NULL;
     311
     312        return EOK;
     313}
     314
    238315
    239316/** Issue interrupt IN transfer to HC driven by current task.
    240317 *
    241318 * @warning The @p buffer and @p actual_size parameters shall not be
    242  * touched until this transfer is waited for by usb_hcd_local_wait_for().
     319 * touched until this transfer is waited for by usb_hc_async_wait_for().
    243320 *
    244321 * @param hc Host controller to handle the transfer.
     
    250327 * @return Error code.
    251328 */
    252 int usb_hcd_local_transfer_interrupt_in(usb_hc_device_t *hc,
    253     usb_target_t target, void *buffer, size_t size, size_t *actual_size,
     329int usb_hc_async_interrupt_in(usb_hc_device_t *hc, usb_target_t target,
     330    void *buffer, size_t size, size_t *actual_size,
    254331    usb_handle_t *handle)
    255332{
     
    266343 * @return Error code.
    267344 */
    268 int usb_hcd_local_wait_for(usb_handle_t handle)
     345int usb_hc_async_wait_for(usb_handle_t handle)
    269346{
    270347        return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.