Changeset e991937 in mainline for uspace/lib/usbhost/src/ddf_helpers.c


Ignore:
Timestamp:
2013-08-07T12:10:51Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2757247
Parents:
d8d100c
Message:

usb: hc function no longer represents the HC nor holds its data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    rd8d100c re991937  
    4747
    4848typedef struct hc_dev {
    49         ddf_fun_t *hc_fun;
     49        ddf_fun_t *ctl_fun;
    5050        list_t devices;
    5151        fibril_mutex_t guard;
     52        hcd_t hcd;
    5253} hc_dev_t;
    5354
     
    6061{
    6162        hc_dev_t *hc_dev = dev_to_hc_dev(dev);
    62         if (!hc_dev || !hc_dev->hc_fun) {
     63        if (!hc_dev) {
    6364                usb_log_error("Invalid HCD device.\n");
    6465                return NULL;
    6566        }
    66         return ddf_fun_data_get(hc_dev->hc_fun);
     67        return &hc_dev->hcd;
    6768}
    6869
     
    563564 * This function does all the ddf work for hc driver.
    564565 */
    565 int hcd_ddf_setup_device(ddf_dev_t *device, ddf_fun_t **hc_fun,
    566     usb_speed_t max_speed, size_t bw, bw_count_func_t bw_count)
    567 {
    568         if (!device)
    569                 return EBADMEM;
    570 
    571         int ret = ENOMEM;
     566int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
     567    size_t bw, bw_count_func_t bw_count)
     568{
     569        assert(device);
     570
    572571        hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
    573572        if (instance == NULL) {
     
    577576        list_initialize(&instance->devices);
    578577        fibril_mutex_initialize(&instance->guard);
    579 
    580         instance->hc_fun = ddf_fun_create(device, fun_exposed, "hc");
    581         if (!instance->hc_fun) {
     578        hcd_init(&instance->hcd, max_speed, bw, bw_count);
     579
     580        int ret = ENOMEM;
     581        instance->ctl_fun = ddf_fun_create(device, fun_exposed, "ctl");
     582        if (!instance->ctl_fun) {
    582583                usb_log_error("Failed to create HCD ddf fun.\n");
    583584                goto err_destroy_fun;
    584585        }
    585586
    586         hcd_t *hcd = ddf_fun_data_alloc(instance->hc_fun, sizeof(hcd_t));
    587         if (!instance->hc_fun) {
    588                 usb_log_error("Failed to allocate HCD ddf fun data.\n");
     587        ret = ddf_fun_bind(instance->ctl_fun);
     588        if (ret != EOK) {
     589                usb_log_error("Failed to bind ctl_fun: %s.\n", str_error(ret));
    589590                goto err_destroy_fun;
    590591        }
    591592
    592         hcd_init(hcd, max_speed, bw, bw_count);
    593 
    594         ret = ddf_fun_bind(instance->hc_fun);
    595         if (ret != EOK) {
    596                 usb_log_error("Failed to bind hc_fun: %s.\n", str_error(ret));
    597                 goto err_destroy_fun;
    598         }
    599 
    600         ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
     593        ret = ddf_fun_add_to_category(instance->ctl_fun, USB_HC_CATEGORY);
    601594        if (ret != EOK) {
    602595                usb_log_error("Failed to add fun to category: %s.\n",
    603596                    str_error(ret));
    604                 ddf_fun_unbind(instance->hc_fun);
     597                ddf_fun_unbind(instance->ctl_fun);
    605598                goto err_destroy_fun;
    606599        }
    607600
    608601        /* HC should be ok at this point (except it can't do anything) */
    609         if (hc_fun)
    610                 *hc_fun = instance->hc_fun;
    611602        return EOK;
    612603
    613604err_destroy_fun:
    614         ddf_fun_destroy(instance->hc_fun);
    615         instance->hc_fun = NULL;
     605        ddf_fun_destroy(instance->ctl_fun);
     606        instance->ctl_fun = NULL;
    616607        return ret;
    617608}
    618609
     610void hcd_ddf_clean_hc(ddf_dev_t *device)
     611{
     612        assert(device);
     613        hc_dev_t *hc = dev_to_hc_dev(device);
     614        assert(hc);
     615        const int ret = ddf_fun_unbind(hc->ctl_fun);
     616        if (ret == EOK)
     617                ddf_fun_destroy(hc->ctl_fun);
     618}
    619619/**
    620620 * @}
Note: See TracChangeset for help on using the changeset viewer.