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


Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (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.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

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

    rf5e5f73 rdf6ded8  
    11/*
    22 * Copyright (c) 2011 Vojtech Horky
     3 * Copyright (c) 2018 Petr Manek, Ondrej Hlavaty
    34 * All rights reserved.
    45 *
     
    5152static errno_t usbmid_device_add(usb_device_t *dev)
    5253{
    53         usb_log_info("Taking care of new MID `%s'.\n", usb_device_get_name(dev));
     54        usb_log_info("Taking care of new MID `%s'.", usb_device_get_name(dev));
    5455
    5556        return usbmid_explore_device(dev);
     57}
     58
     59static errno_t destroy_interfaces(usb_mid_t *usb_mid)
     60{
     61        errno_t ret = EOK;
     62
     63        while (!list_empty(&usb_mid->interface_list)) {
     64                link_t *item = list_first(&usb_mid->interface_list);
     65                list_remove(item);
     66
     67                usbmid_interface_t *iface = usbmid_interface_from_link(item);
     68
     69                const errno_t pret = usbmid_interface_destroy(iface);
     70                if (pret != EOK) {
     71                        usb_log_error("Failed to remove child `%s': %s",
     72                            ddf_fun_get_name(iface->fun), str_error(pret));
     73                        ret = pret;
     74                }
     75        }
     76
     77        return ret;
    5678}
    5779
     
    7092        errno_t ret = ddf_fun_unbind(usb_mid->ctl_fun);
    7193        if (ret != EOK) {
    72                 usb_log_error("Failed to unbind USB MID ctl function: %s.\n",
     94                usb_log_error("Failed to unbind USB MID ctl function: %s.",
    7395                    str_error(ret));
    7496                return ret;
     
    7799
    78100        /* Remove all children */
    79         while (!list_empty(&usb_mid->interface_list)) {
    80                 link_t *item = list_first(&usb_mid->interface_list);
    81                 list_remove(item);
    82 
    83                 usbmid_interface_t *iface = usbmid_interface_from_link(item);
    84 
    85                 usb_log_info("Removing child `%s'.\n",
     101        list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
     102                usb_log_info("Removing child `%s'.",
    86103                    ddf_fun_get_name(iface->fun));
    87104
    88                 /* Tell the child to go off-line. */
     105                /* Tell the child to go offline. */
    89106                errno_t pret = ddf_fun_offline(iface->fun);
    90107                if (pret != EOK) {
    91                         usb_log_warning("Failed to turn off child `%s': %s\n",
     108                        usb_log_warning("Failed to turn off child `%s': %s",
    92109                            ddf_fun_get_name(iface->fun), str_error(pret));
    93                         ret = pret;
    94                 }
    95 
    96                 /* Now remove the child. */
    97                 pret = usbmid_interface_destroy(iface);
    98                 if (pret != EOK) {
    99                         usb_log_error("Failed to destroy child `%s': %s\n",
    100                             ddf_fun_get_name(iface->fun), str_error(pret));
    101                         ret = pret;
    102110                }
    103111        }
    104         return ret;
     112
     113        return destroy_interfaces(usb_mid);
    105114}
    106115
     
    116125        assert(usb_mid);
    117126
    118         usb_log_info("USB MID gone: `%s'.\n", usb_device_get_name(dev));
     127        usb_log_info("USB MID gone: `%s'.", usb_device_get_name(dev));
    119128
    120129        /* Remove ctl function */
    121130        errno_t ret = ddf_fun_unbind(usb_mid->ctl_fun);
    122131        if (ret != EOK) {
    123                 usb_log_error("Failed to unbind USB MID ctl function: %s.\n",
     132                usb_log_error("Failed to unbind USB MID ctl function: %s.",
    124133                    str_error(ret));
    125134                return ret;
     
    127136        ddf_fun_destroy(usb_mid->ctl_fun);
    128137
    129         /* Now remove all other functions */
    130         while (!list_empty(&usb_mid->interface_list)) {
    131                 link_t *item = list_first(&usb_mid->interface_list);
    132                 list_remove(item);
     138        /* Destroy children and tell their drivers they are gone. */
     139        return destroy_interfaces(usb_mid);
     140}
    133141
    134                 usbmid_interface_t *iface = usbmid_interface_from_link(item);
     142static errno_t usbmid_function_online(ddf_fun_t *fun)
     143{
     144        usb_device_t *usb_dev = ddf_dev_data_get(ddf_fun_get_dev(fun));
     145        usb_mid_t *usb_mid = usb_device_data_get(usb_dev);
     146        if (fun == usb_mid->ctl_fun)
     147                return ENOTSUP;
    135148
    136                 usb_log_info("Child `%s' is gone.\n",
    137                     ddf_fun_get_name(iface->fun));
     149        return ddf_fun_online(fun);
     150}
    138151
    139                 const errno_t pret = usbmid_interface_destroy(iface);
    140                 if (pret != EOK) {
    141                         usb_log_error("Failed to remove child `%s': %s\n",
    142                             ddf_fun_get_name(iface->fun), str_error(pret));
    143                         ret = pret;
    144                 }
    145         }
    146         return ret;
     152static errno_t usbmid_function_offline(ddf_fun_t *fun)
     153{
     154        usb_device_t *usb_dev = ddf_dev_data_get(ddf_fun_get_dev(fun));
     155        usb_mid_t *usb_mid = usb_device_data_get(usb_dev);
     156        if (fun == usb_mid->ctl_fun)
     157                return ENOTSUP;
     158
     159        return ddf_fun_offline(fun);
    147160}
    148161
     
    150163static const usb_driver_ops_t mid_driver_ops = {
    151164        .device_add = usbmid_device_add,
    152         .device_rem = usbmid_device_remove,
     165        .device_remove = usbmid_device_remove,
    153166        .device_gone = usbmid_device_gone,
     167        .function_online = usbmid_function_online,
     168        .function_offline = usbmid_function_offline
    154169};
    155170
Note: See TracChangeset for help on using the changeset viewer.