Changeset 9c7ed9c in mainline


Ignore:
Timestamp:
2012-12-16T21:42:20Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
21be46a
Parents:
5994cc3
Message:

libusbhost,hcd: Add generic device_add function.

This will be useful later.
Switch rh initialization to use this function.

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r5994cc3 r9c7ed9c  
    3838
    3939#include <assert.h>
     40#include <adt/list.h>
    4041#include <usbhc_iface.h>
    4142
     
    5657        /** Endpoint manager. */
    5758        usb_endpoint_manager_t ep_manager;
     59        /** Added devices */
     60        list_t devices;
    5861
    5962        /** Device specific driver data. */
     
    8083        usb_device_manager_init(&hcd->dev_manager, max_speed);
    8184        usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
     85        list_initialize(&hcd->devices);
     86
    8287        hcd->private_data = NULL;
    8388        hcd->schedule = NULL;
     
    110115}
    111116
     117
     118int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
     119    usb_address_t address, usb_speed_t speed, const char *name,
     120    const match_id_list_t *mids);
     121
    112122int hcd_setup_device(ddf_dev_t *device);
    113123int hcd_setup_hub(hcd_t *instance, usb_address_t *address, ddf_dev_t *dev);
  • uspace/lib/usbhost/src/hcd.c

    r5994cc3 r9c7ed9c  
    4343typedef struct hc_dev {
    4444        ddf_fun_t *hc_fun;
    45         ddf_fun_t *rh_fun;
    4645} hc_dev_t;
    4746
     
    6261
    6362typedef struct usb_dev {
     63        link_t link;
     64        ddf_fun_t *fun;
    6465        usb_address_t address;
    6566        usb_speed_t speed;
     
    106107};
    107108/** Standard USB RH options (RH interface) */
    108 static ddf_dev_ops_t rh_ops = {
     109static ddf_dev_ops_t usb_ops = {
    109110        .interfaces[USB_DEV_IFACE] = &usb_iface,
    110111};
     
    115116};
    116117
     118int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
     119    usb_address_t address, usb_speed_t speed, const char *name,
     120    const match_id_list_t *mids)
     121{
     122        assert(instance);
     123        assert(parent);
     124        hc_dev_t *hc_dev = ddf_dev_data_get(parent);
     125        devman_handle_t hc_handle = ddf_fun_get_handle(hc_dev->hc_fun);
     126
     127        //TODO more checks
     128        ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
     129        if (!fun)
     130                return ENOMEM;
     131        usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t));
     132        if (!info) {
     133                ddf_fun_destroy(fun);
     134                return ENOMEM;
     135        }
     136        info->address = address;
     137        info->speed = speed;
     138        info->handle = hc_handle;
     139        info->fun = fun;
     140        link_initialize(&info->link);
     141
     142        ddf_fun_set_ops(fun, &usb_ops);
     143        list_foreach(mids->ids, iter) {
     144                match_id_t *mid = list_get_instance(iter, match_id_t, link);
     145                ddf_fun_add_match_id(fun, mid->id, mid->score);
     146        }
     147
     148        int ret = ddf_fun_bind(fun);
     149        if (ret != EOK) {
     150                ddf_fun_destroy(fun);
     151                return ret;
     152        }
     153
     154        ret = usb_device_manager_bind_address(&instance->dev_manager,
     155            address, ddf_fun_get_handle(fun));
     156        if (ret != EOK)
     157                usb_log_warning("Failed to bind root hub address: %s.\n",
     158                    str_error(ret));
     159
     160        list_append(&info->link, &instance->devices);
     161        return EOK;
     162}
     163
    117164/** Announce root hub to the DDF
    118165 *
     
    126173        assert(address);
    127174        assert(device);
    128 
    129         hc_dev_t *hc_dev = ddf_dev_data_get(device);
    130         hc_dev->rh_fun = ddf_fun_create(device, fun_inner, "rh");
    131         if (!hc_dev->rh_fun)
    132                 return ENOMEM;
    133         usb_dev_t *rh = ddf_fun_data_alloc(hc_dev->rh_fun, sizeof(usb_dev_t));
    134         if (!rh) {
    135                 ddf_fun_destroy(hc_dev->rh_fun);
    136                 return ENOMEM;
    137         }
    138 
    139175
    140176        int ret = usb_device_manager_request_address(&instance->dev_manager,
     
    143179                usb_log_error("Failed to get root hub address: %s\n",
    144180                    str_error(ret));
    145                 ddf_fun_destroy(hc_dev->rh_fun);
    146181                return ret;
    147182        }
    148 
    149         rh->address = *address;
    150         rh->speed = USB_SPEED_FULL;
    151         rh->handle = ddf_fun_get_handle(hc_dev->hc_fun);
    152 
    153         ddf_fun_set_ops(hc_dev->rh_fun, &rh_ops);
    154183
    155184#define CHECK_RET_UNREG_RETURN(ret, message...) \
     
    161190        usb_device_manager_release_address( \
    162191            &instance->dev_manager, *address); \
    163         ddf_fun_destroy(hc_dev->rh_fun); \
    164192        return ret; \
    165193} else (void)0
     
    170198            0, NULL, NULL);
    171199        CHECK_RET_UNREG_RETURN(ret,
    172             "Failed to register root hub control endpoint: %s.\n",
    173             str_error(ret));
    174 
    175         ret = ddf_fun_add_match_id(hc_dev->rh_fun, "usb&class=hub", 100);
     200            "Failed to add root hub control endpoint: %s.\n", str_error(ret));
     201
     202        match_id_t mid = { .id = "usb&class=hub", .score = 100 };
     203        link_initialize(&mid.link);
     204        match_id_list_t mid_list;
     205        init_match_ids(&mid_list);
     206        add_match_id(&mid_list, &mid);
     207
     208        ret = hcd_add_device(
     209            instance, device, *address, USB_SPEED_FULL, "rh", &mid_list);
    176210        CHECK_RET_UNREG_RETURN(ret,
    177             "Failed to add root hub match-id: %s.\n", str_error(ret));
    178 
    179         ret = ddf_fun_bind(hc_dev->rh_fun);
    180         CHECK_RET_UNREG_RETURN(ret,
    181             "Failed to bind root hub function: %s.\n", str_error(ret));
    182 
    183         ret = usb_device_manager_bind_address(&instance->dev_manager,
    184             *address, ddf_fun_get_handle(hc_dev->rh_fun));
    185         if (ret != EOK)
    186                 usb_log_warning("Failed to bind root hub address: %s.\n",
    187                     str_error(ret));
    188 
     211            "Failed to add hcd device: %s.\n", str_error(ret));
    189212
    190213        return EOK;
Note: See TracChangeset for help on using the changeset viewer.