Ignore:
File:
1 edited

Legend:

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

    r56fd7cf rd3a1ad58  
    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>
    4743#include <usb/dev/recognise.h>
    4844#include "usbmid.h"
     45/** Get host controller handle by calling the parent usb_device_t.
     46 *
     47 * @param[in] fun Device function the operation is running on.
     48 * @param[out] handle Storage for the host controller handle.
     49 * @return Error code.
     50 */
     51static int usb_iface_device_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     52{
     53        assert(handle);
     54        assert(fun);
     55        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     56        assert(usb_dev);
     57        *handle = usb_device_hc_handle(usb_dev);
     58        return EOK;
     59}
     60
     61/** Get USB device address by calling the parent usb_device_t.
     62 *
     63 * @param[in] fun Device function the operation is running on.
     64 * @param[in] handle Devman handle of USB device we want address of.
     65 * @param[out] address Storage for USB address of device with handle @p handle.
     66 * @return Error code.
     67 */
     68static int usb_iface_device_address(ddf_fun_t *fun, usb_address_t *address)
     69{
     70        assert(address);
     71        assert(fun);
     72        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     73        assert(usb_dev);
     74        *address = usb_device_address(usb_dev);
     75        return EOK;
     76}
    4977
    5078/** Callback for DDF USB interface. */
    51 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
     79static int usb_iface_iface(ddf_fun_t *fun, int *iface_no)
    5280{
    5381        usbmid_interface_t *iface = ddf_fun_data_get(fun);
     
    6189}
    6290
     91static int usb_iface_register_endpoint(ddf_fun_t *fun, usb_endpoint_t ep,
     92    usb_transfer_type_t type, usb_direction_t dir, size_t mps, unsigned inter)
     93{
     94        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     95        assert(usb_dev);
     96        async_exch_t *exch = usb_device_bus_exchange_begin(usb_dev);
     97        if (!exch)
     98                return ENOMEM;
     99        const int ret = usb_register_endpoint(exch, ep, type, dir, mps, inter);
     100        usb_device_bus_exchange_end(exch);
     101        return ret;
     102}
     103
     104static int usb_iface_unregister_endpoint(ddf_fun_t *fun, usb_endpoint_t ep,
     105    usb_direction_t dir)
     106{
     107        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     108        assert(usb_dev);
     109        async_exch_t *exch = usb_device_bus_exchange_begin(usb_dev);
     110        if (!exch)
     111                return ENOMEM;
     112        const int ret = usb_unregister_endpoint(exch, ep, dir);
     113        usb_device_bus_exchange_end(exch);
     114        return ret;
     115}
     116
    63117/** DDF interface of the child - interface function. */
    64118static 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,
     119        .get_hc_handle = usb_iface_device_hc_handle,
     120        .get_my_address = usb_iface_device_address,
     121        .get_my_interface = usb_iface_iface,
     122        .register_endpoint = usb_iface_register_endpoint,
     123        .unregister_endpoint = usb_iface_unregister_endpoint,
    68124};
    69125
     
    81137                return ret;
    82138        }
    83         /* NOTE: usbmid->interface points somewhere, but we did not
    84          * allocate that space, so don't touch */
    85139        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 */
    88140        return EOK;
    89141}
     
    98150 */
    99151int usbmid_spawn_interface_child(usb_device_t *parent,
    100     usbmid_interface_t *iface,
     152    usbmid_interface_t **iface_ret,
    101153    const usb_standard_device_descriptor_t *device_descriptor,
    102154    const usb_standard_interface_descriptor_t *interface_descriptor)
     
    119171
    120172        /* Create the device. */
    121         child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
     173        child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
    122174        free(child_name);
    123175        if (child == NULL) {
     
    145197        }
    146198        clean_match_ids(&match_ids);
     199        ddf_fun_set_ops(child, &child_device_ops);
     200
     201        usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
     202
     203        iface->fun = child;
     204        iface->interface_no = interface_descriptor->interface_number;
     205        link_initialize(&iface->link);
    147206
    148207        rc = ddf_fun_bind(child);
     
    152211                return rc;
    153212        }
    154 
    155         iface->fun = child;
    156         ddf_fun_data_implant(child, iface);
    157         ddf_fun_set_ops(child, &child_device_ops);
     213        *iface_ret = iface;
    158214
    159215        return EOK;
Note: See TracChangeset for help on using the changeset viewer.