Changeset b4b534ac in mainline for uspace/drv/bus/usb/usbmid/usbmid.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmid/usbmid.c

    r5b18137 rb4b534ac  
    3939#include <stdlib.h>
    4040#include <usb_iface.h>
    41 #include <usb/ddfiface.h>
    4241#include <usb/dev/pipes.h>
    4342#include <usb/classes/classes.h>
     
    4544#include "usbmid.h"
    4645
    47 /** Callback for DDF USB interface. */
    48 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
     46/** Get USB device handle by calling the parent usb_device_t.
     47 *
     48 * @param[in] fun Device function the operation is running on.
     49 * @param[out] handle Device handle.
     50 * @return Error code.
     51 */
     52static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
     53{
     54        assert(fun);
     55        assert(handle);
     56        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     57        *handle = usb_device_get_devman_handle(usb_dev);
     58        return EOK;
     59}
     60
     61/** Callback for DDF USB get interface. */
     62static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no)
    4963{
    5064        usbmid_interface_t *iface = ddf_fun_data_get(fun);
    5165        assert(iface);
    5266
    53         if (iface_no != NULL) {
     67        if (iface_no)
    5468                *iface_no = iface->interface_no;
    55         }
    5669
    5770        return EOK;
    5871}
    5972
    60 /** DDF interface of the child - interface function. */
     73/** DDF interface of the child - USB functions. */
    6174static usb_iface_t child_usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    63         .get_my_address = usb_iface_get_my_address_forward_impl,
    64         .get_my_interface = usb_iface_get_interface_impl,
     75        .get_my_device_handle = usb_iface_device_handle,
     76        .get_my_interface = usb_iface_iface_no,
    6577};
    6678
     
    7890                return ret;
    7991        }
    80         /* NOTE: usbmid->interface points somewhere, but we did not
    81          * allocate that space, so don't touch */
    8292        ddf_fun_destroy(mid_iface->fun);
    83         /* NOTE: mid_iface is invalid at this point, it was assigned to
    84          * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
    8593        return EOK;
    8694}
     
    95103 */
    96104int usbmid_spawn_interface_child(usb_device_t *parent,
    97     usbmid_interface_t *iface,
     105    usbmid_interface_t **iface_ret,
    98106    const usb_standard_device_descriptor_t *device_descriptor,
    99107    const usb_standard_interface_descriptor_t *interface_descriptor)
    100108{
     109        ddf_fun_t *child = NULL;
    101110        char *child_name = NULL;
    102111        int rc;
     
    110119            usb_str_class(interface_descriptor->interface_class),
    111120            interface_descriptor->interface_number);
    112         if (rc < 0)
     121        if (rc < 0) {
    113122                return ENOMEM;
     123        }
    114124
    115         rc = ddf_fun_set_name(iface->fun, child_name);
     125        /* Create the device. */
     126        child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
    116127        free(child_name);
    117         if (rc != EOK)
     128        if (child == NULL) {
    118129                return ENOMEM;
     130        }
    119131
    120132        match_id_list_t match_ids;
     
    123135        rc = usb_device_create_match_ids_from_interface(device_descriptor,
    124136            interface_descriptor, &match_ids);
    125         if (rc != EOK)
     137        if (rc != EOK) {
     138                ddf_fun_destroy(child);
    126139                return rc;
     140        }
    127141
    128142        list_foreach(match_ids.ids, link, match_id_t, match_id) {
    129                 rc = ddf_fun_add_match_id(iface->fun, match_id->id, match_id->score);
     143                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    130144                if (rc != EOK) {
    131145                        clean_match_ids(&match_ids);
     146                        ddf_fun_destroy(child);
    132147                        return rc;
    133148                }
    134149        }
    135150        clean_match_ids(&match_ids);
     151        ddf_fun_set_ops(child, &child_device_ops);
    136152
    137         ddf_fun_set_ops(iface->fun, &child_device_ops);
     153        usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
    138154
    139         rc = ddf_fun_bind(iface->fun);
    140         if (rc != EOK)
     155        iface->fun = child;
     156        iface->interface_no = interface_descriptor->interface_number;
     157        link_initialize(&iface->link);
     158
     159        rc = ddf_fun_bind(child);
     160        if (rc != EOK) {
     161                /* This takes care of match_id deallocation as well. */
     162                ddf_fun_destroy(child);
    141163                return rc;
     164        }
     165        *iface_ret = iface;
    142166
    143167        return EOK;
Note: See TracChangeset for help on using the changeset viewer.