Changeset 8be7819 in mainline


Ignore:
Timestamp:
2011-10-30T19:59:15Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cae002c
Parents:
e462909
Message:

usbmid: Implement dev_remove and some minor refactoring.

Location:
uspace/drv/bus/usb/usbmid
Files:
3 edited

Legend:

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

    re462909 r8be7819  
    139139        int rc;
    140140
    141         int dev_class = dev->descriptors.device.device_class;
     141        unsigned dev_class = dev->descriptors.device.device_class;
    142142        if (dev_class != USB_CLASS_USE_INTERFACE) {
    143143                usb_log_warning(
    144                     "Device class: %d (%s), but expected class 0.\n",
    145                     dev_class, usb_str_class(dev_class));
     144                    "Device class: %u (%s), but expected class %u.\n",
     145                    dev_class, usb_str_class(dev_class),
     146                    USB_CLASS_USE_INTERFACE);
    146147                usb_log_error("Not multi interface device, refusing.\n");
    147148                return false;
    148149        }
    149150
    150         /* Short cuts to save on typing ;-). */
     151        /* Shortcuts to save on typing ;-). */
    151152        const void *config_descriptor_raw = dev->descriptors.configuration;
    152153        size_t config_descriptor_size = dev->descriptors.configuration_size;
     
    163164        }
    164165
     166        /* Create driver soft-state. */
    165167        usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
    166168        if (!usb_mid) {
     
    169171        }
    170172
    171         /* Create control function */
     173        /* Create control function. */
    172174        usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
    173175        if (usb_mid->ctl_fun == NULL) {
     
    175177                return false;
    176178        }
    177 
    178179        usb_mid->ctl_fun->ops = &mid_device_ops;
    179180
     181        /* Bind control function. */
    180182        rc = ddf_fun_bind(usb_mid->ctl_fun);
    181183        if (rc != EOK) {
     
    192194            &usb_mid->interface_list);
    193195
     196        /* Start child function for every interface. */
    194197        list_foreach(usb_mid->interface_list, link) {
    195                 usbmid_interface_t *iface = list_get_instance(link,
    196                     usbmid_interface_t, link);
     198                usbmid_interface_t *iface = usbmid_interface_from_link(link);
    197199
    198200                usb_log_info("Creating child for interface %d (%s).\n",
    199                     (int) iface->interface_no,
     201                    iface->interface_no,
    200202                    usb_str_class(iface->interface->interface_class));
    201203
  • uspace/drv/bus/usb/usbmid/main.c

    re462909 r8be7819  
    7474{
    7575        assert(dev);
    76         int ret = ENOTSUP;
     76
     77        /* Remove ctl function */
    7778        usb_mid_t *usb_mid = dev->driver_data;
    78         assert(usb_mid);
     79        int ret = ddf_fun_unbind(usb_mid->ctl_fun);
     80        if (ret != EOK) {
     81                usb_log_error("Failed to unbind USB MID ctl function: %s.\n",
     82                    str_error(ret));
     83                return ret;
     84        }
     85        ddf_fun_destroy(usb_mid->ctl_fun);
    7986
    80         /* Signal all interface functions */
    81         list_foreach(usb_mid->interface_list, item) {
     87        /* Remove all children */
     88        while (!list_empty(&usb_mid->interface_list)) {
     89                link_t *item = list_first(&usb_mid->interface_list);
     90                list_remove(item);
     91
    8292                usbmid_interface_t *iface = usbmid_interface_from_link(item);
    8393
    84                 usb_log_info("Signaling remove to child for interface "
    85                     "%d (%s).\n", iface->interface_no,
     94                usb_log_info("Removing child for interface %d (%s).\n",
     95                    iface->interface_no,
    8696                    usb_str_class(iface->interface->interface_class));
    87                 // TODO cascade the call.
     97
     98                /* Tell the child to go off-line. */
     99                int pret = ddf_fun_offline(iface->fun);
     100                if (pret != EOK) {
     101                        usb_log_warning("Failed to turn off child for interface"
     102                            " %d (%s): %s\n", iface->interface_no,
     103                            usb_str_class(iface->interface->interface_class),
     104                            str_error(pret));
     105                        ret = pret;
     106                }
     107
     108                /* Now remove the child. */
     109                pret = usbmid_interface_destroy(iface);
     110                if (pret != EOK) {
     111                        usb_log_error("Failed to remove child for interface "
     112                            "%d (%s): %s\n", iface->interface_no,
     113                            usb_str_class(iface->interface->interface_class),
     114                            str_error(pret));
     115                        ret = pret;
     116                }
    88117        }
    89118        return ret;
     
    117146                usbmid_interface_t *iface = usbmid_interface_from_link(item);
    118147
    119                 usb_log_info("Removing child for interface %d (%s).\n",
     148                usb_log_info("Child for interface %d (%s) gone.\n",
    120149                    iface->interface_no,
    121150                    usb_str_class(iface->interface->interface_class));
  • uspace/drv/bus/usb/usbmid/usbmid.c

    re462909 r8be7819  
    110110         * class name something humanly understandable.
    111111         */
    112         rc = asprintf(&child_name, "%s%d",
     112        rc = asprintf(&child_name, "%s%hhu",
    113113            usb_str_class(interface_descriptor->interface_class),
    114             (int) interface_descriptor->interface_number);
     114            interface_descriptor->interface_number);
    115115        if (rc < 0) {
    116116                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.