Changeset df6ded8 in mainline for uspace/drv/bus/usb/usbmid/main.c
- Timestamp:
- 2018-02-28T16:37:50Z (7 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/main.c
rf5e5f73 rdf6ded8 1 1 /* 2 2 * Copyright (c) 2011 Vojtech Horky 3 * Copyright (c) 2018 Petr Manek, Ondrej Hlavaty 3 4 * All rights reserved. 4 5 * … … 51 52 static errno_t usbmid_device_add(usb_device_t *dev) 52 53 { 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)); 54 55 55 56 return usbmid_explore_device(dev); 57 } 58 59 static 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; 56 78 } 57 79 … … 70 92 errno_t ret = ddf_fun_unbind(usb_mid->ctl_fun); 71 93 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.", 73 95 str_error(ret)); 74 96 return ret; … … 77 99 78 100 /* 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'.", 86 103 ddf_fun_get_name(iface->fun)); 87 104 88 /* Tell the child to go off -line. */105 /* Tell the child to go offline. */ 89 106 errno_t pret = ddf_fun_offline(iface->fun); 90 107 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", 92 109 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;102 110 } 103 111 } 104 return ret; 112 113 return destroy_interfaces(usb_mid); 105 114 } 106 115 … … 116 125 assert(usb_mid); 117 126 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)); 119 128 120 129 /* Remove ctl function */ 121 130 errno_t ret = ddf_fun_unbind(usb_mid->ctl_fun); 122 131 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.", 124 133 str_error(ret)); 125 134 return ret; … … 127 136 ddf_fun_destroy(usb_mid->ctl_fun); 128 137 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 } 133 141 134 usbmid_interface_t *iface = usbmid_interface_from_link(item); 142 static 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; 135 148 136 usb_log_info("Child `%s' is gone.\n",137 ddf_fun_get_name(iface->fun)); 149 return ddf_fun_online(fun); 150 } 138 151 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;152 static 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); 147 160 } 148 161 … … 150 163 static const usb_driver_ops_t mid_driver_ops = { 151 164 .device_add = usbmid_device_add, 152 .device_rem = usbmid_device_remove,165 .device_remove = usbmid_device_remove, 153 166 .device_gone = usbmid_device_gone, 167 .function_online = usbmid_function_online, 168 .function_offline = usbmid_function_offline 154 169 }; 155 170
Note:
See TracChangeset
for help on using the changeset viewer.