Changeset 8ba18c6 in mainline


Ignore:
Timestamp:
2011-02-20T17:02:53Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5c3ace2
Parents:
18cb870
Message:

MID driver can tell interface number to child

Location:
uspace/drv/usbmid
Files:
2 edited

Legend:

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

    r18cb870 r8ba18c6  
    6868}
    6969
     70/** Callback for DDF USB interface. */
     71static int usb_iface_get_interface_impl(device_t *device, devman_handle_t handle,
     72    int *iface_no)
     73{
     74        assert(device);
     75
     76        usbmid_interface_t *iface = device->driver_data;
     77        assert(iface);
     78
     79        if (iface_no != NULL) {
     80                *iface_no = iface->interface_no;
     81        }
     82
     83        return EOK;
     84}
     85
    7086static usb_iface_t child_usb_iface = {
    7187        .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
    72         .get_address = usb_iface_get_address_impl
     88        .get_address = usb_iface_get_address_impl,
     89        .get_interface = usb_iface_get_interface_impl
    7390};
    7491
     
    121138}
    122139
     140/** Create new interface for USB MID device.
     141 *
     142 * @param dev Backing generic DDF child device (representing interface).
     143 * @param iface_no Interface number.
     144 * @return New interface.
     145 * @retval NULL Error occured.
     146 */
     147usbmid_interface_t *usbmid_interface_create(device_t *dev, int iface_no)
     148{
     149        usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
     150        if (iface == NULL) {
     151                usb_log_error("Out of memory (wanted %zuB).\n",
     152                    sizeof(usbmid_interface_t));
     153                return NULL;
     154        }
     155
     156        iface->dev = dev;
     157        iface->interface_no = iface_no;
     158
     159        return iface;
     160}
     161
    123162
    124163/** Spawn new child device from one interface.
     
    135174        device_t *child = NULL;
    136175        char *child_name = NULL;
     176        usbmid_interface_t *child_as_interface = NULL;
    137177        int rc;
    138178
     
    155195                goto error_leave;
    156196        }
     197
     198        child_as_interface = usbmid_interface_create(child,
     199            (int) interface_descriptor->interface_number);
     200        if (child_as_interface == NULL) {
     201                rc = ENOMEM;
     202                goto error_leave;
     203        }
     204
     205        child->driver_data = child_as_interface;
    157206        child->parent = parent->dev;
    158207        child->name = child_name;
     
    181230                free(child_name);
    182231        }
     232        if (child_as_interface != NULL) {
     233                free(child_as_interface);
     234        }
    183235
    184236        return rc;
  • uspace/drv/usbmid/usbmid.h

    r18cb870 r8ba18c6  
    5454} usbmid_device_t;
    5555
     56typedef struct {
     57        /** Device container. */
     58        device_t *dev;
     59
     60        /** Interface number. */
     61        int interface_no;
     62} usbmid_interface_t;
     63
    5664usbmid_device_t *usbmid_device_create(device_t *);
     65usbmid_interface_t *usbmid_interface_create(device_t *, int);
    5766bool usbmid_explore_device(usbmid_device_t *);
    5867int usbmid_spawn_interface_child(usbmid_device_t *,
Note: See TracChangeset for help on using the changeset viewer.