Changeset 01eeaaf in mainline for uspace/drv/bus/usb/vhc/main.c


Ignore:
Timestamp:
2012-12-22T15:07:29Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f6577d9
Parents:
94c40ce2
Message:

vhc: Port to libusbhost.

Device removal works OK.
Tested on vuh boot and vuh lw1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/vhc/main.c

    r94c40ce2 r01eeaaf  
    4444#include <ddf/driver.h>
    4545
     46#include <usb/host/ddf_helpers.h>
     47
    4648#include <usb/usb.h>
    4749#include <usb/ddfiface.h>
     
    5254
    5355static ddf_dev_ops_t vhc_ops = {
     56#if 0
    5457        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
    5558        .interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
     59#endif
    5660        .close = on_client_close,
    5761        .default_handler = default_connection_handler
    5862};
    5963
     64static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
     65{
     66        assert(dev);
     67        assert(fun);
     68
     69        *fun = ddf_fun_create(dev, fun_exposed, "ctl");
     70        if (!*fun)
     71                return ENOMEM;
     72
     73        vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
     74        if (!vhc) {
     75                ddf_fun_destroy(*fun);
     76        }
     77        ddf_fun_set_ops(*fun, &vhc_ops);
     78        const int ret = ddf_fun_bind(*fun);
     79        if (ret != EOK) {
     80                ddf_fun_destroy(*fun);
     81                *fun = NULL;
     82                return ret;
     83        }
     84        vhc_data_init(vhc);
     85        // TODO: This limits us to single vhc instance.
     86        virthub_init(&virtual_hub_device);
     87        vhc->hub = &virtual_hub_device;
     88        return EOK;
     89}
     90
     91
    6092static int vhc_dev_add(ddf_dev_t *dev)
    6193{
     94        /* Initialize virtual structure */
     95        ddf_fun_t *ctl_fun = NULL;
     96        int ret = vhc_control_node(dev, &ctl_fun);
     97        if (ret != EOK) {
     98                usb_log_error("Failed to setup control node.\n");
     99                return ret;
     100        }
     101        vhc_data_t *data = ddf_fun_data_get(ctl_fun);
     102
     103        /* Initialize generic structures */
     104        ret = hcd_ddf_setup_device(dev, NULL, USB_SPEED_FULL,
     105            BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
     106        if (ret != EOK) {
     107                usb_log_error("Failed to init HCD structures: %s.\n",
     108                   str_error(ret));
     109                free(data);
     110                return ret;
     111        }
     112
     113        hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL);
     114
     115        /* Add virtual hub device */
     116        usb_address_t address = 1;
     117        ret = vhc_virtdev_plug_hub(data, data->hub, NULL, address);
     118        if (ret != EOK) {
     119                usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
     120                free(data);
     121                return ret;
     122        }
     123
     124        // TODO fix the address hack
     125        ret = hcd_ddf_setup_hub(dev, &address);
     126        if (ret != EOK) {
     127                usb_log_error("Failed to init VHC root hub: %s\n",
     128                        str_error(ret));
     129                // TODO do something here...
     130        }
     131
     132        return ret;
     133#if 0
    62134        static int vhc_count = 0;
    63135        int rc;
     
    124196
    125197        return EOK;
     198#endif
    126199}
    127200
     
    137210
    138211int main(int argc, char * argv[])
    139 {       
     212{
    140213        log_init(NAME);
    141214
     
    145218}
    146219
    147 
    148220/**
    149221 * @}
Note: See TracChangeset for help on using the changeset viewer.