Ignore:
File:
1 edited

Legend:

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

    rfeeac0d r3121b5f  
    3131 */
    3232
    33 /* XXX Fix this */
    34 #define _DDF_DATA_IMPLANT
    35 
    3633/**
    3734 * @file
     
    4239#include <stdlib.h>
    4340#include <usb_iface.h>
    44 #include <usb/ddfiface.h>
    4541#include <usb/dev/pipes.h>
    4642#include <usb/classes/classes.h>
     
    4844#include "usbmid.h"
    4945
    50 /** Callback for DDF USB interface. */
    51 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)
    5263{
    5364        usbmid_interface_t *iface = ddf_fun_data_get(fun);
    5465        assert(iface);
    5566
    56         if (iface_no != NULL) {
     67        if (iface_no)
    5768                *iface_no = iface->interface_no;
    58         }
    5969
    6070        return EOK;
    6171}
    6272
    63 /** DDF interface of the child - interface function. */
     73/** DDF interface of the child - USB functions. */
    6474static usb_iface_t child_usb_iface = {
    65         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    66         .get_my_address = usb_iface_get_my_address_forward_impl,
    67         .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,
    6877};
    6978
     
    8190                return ret;
    8291        }
    83         /* NOTE: usbmid->interface points somewhere, but we did not
    84          * allocate that space, so don't touch */
    8592        ddf_fun_destroy(mid_iface->fun);
    86         /* NOTE: mid_iface is invalid at this point, it was assigned to
    87          * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
    8893        return EOK;
    8994}
     
    98103 */
    99104int usbmid_spawn_interface_child(usb_device_t *parent,
    100     usbmid_interface_t *iface,
     105    usbmid_interface_t **iface_ret,
    101106    const usb_standard_device_descriptor_t *device_descriptor,
    102107    const usb_standard_interface_descriptor_t *interface_descriptor)
     
    119124
    120125        /* Create the device. */
    121         child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
     126        child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
    122127        free(child_name);
    123128        if (child == NULL) {
     
    135140        }
    136141
    137         list_foreach(match_ids.ids, link, match_id_t, match_id) {
     142        list_foreach(match_ids.ids, link) {
     143                match_id_t *match_id = list_get_instance(link, match_id_t, link);
    138144                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    139145                if (rc != EOK) {
     
    144150        }
    145151        clean_match_ids(&match_ids);
     152        ddf_fun_set_ops(child, &child_device_ops);
     153
     154        usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
     155
     156        iface->fun = child;
     157        iface->interface_no = interface_descriptor->interface_number;
     158        link_initialize(&iface->link);
    146159
    147160        rc = ddf_fun_bind(child);
     
    151164                return rc;
    152165        }
    153 
    154         iface->fun = child;
    155         ddf_fun_data_implant(child, iface);
    156         ddf_fun_set_ops(child, &child_device_ops);
     166        *iface_ret = iface;
    157167
    158168        return EOK;
Note: See TracChangeset for help on using the changeset viewer.