.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | | -/** |
---|
| 2 | +/* |
---|
3 | 3 | * udc.c - Core UDC Framework |
---|
4 | 4 | * |
---|
5 | 5 | * Copyright (C) 2010 Texas Instruments |
---|
.. | .. |
---|
23 | 23 | |
---|
24 | 24 | /** |
---|
25 | 25 | * struct usb_udc - describes one usb device controller |
---|
26 | | - * @driver - the gadget driver pointer. For use by the class code |
---|
27 | | - * @dev - the child device to the actual controller |
---|
28 | | - * @gadget - the gadget. For use by the class code |
---|
29 | | - * @list - for use by the udc class driver |
---|
30 | | - * @vbus - for udcs who care about vbus status, this value is real vbus status; |
---|
| 26 | + * @driver: the gadget driver pointer. For use by the class code |
---|
| 27 | + * @dev: the child device to the actual controller |
---|
| 28 | + * @gadget: the gadget. For use by the class code |
---|
| 29 | + * @list: for use by the udc class driver |
---|
| 30 | + * @vbus: for udcs who care about vbus status, this value is real vbus status; |
---|
31 | 31 | * for udcs who do not care about vbus status, this value is always true |
---|
| 32 | + * @started: the UDC's started state. True if the UDC had started. |
---|
32 | 33 | * |
---|
33 | 34 | * This represents the internal data structure which is used by the UDC-class |
---|
34 | 35 | * to hold information about udc driver and gadget together. |
---|
.. | .. |
---|
39 | 40 | struct device dev; |
---|
40 | 41 | struct list_head list; |
---|
41 | 42 | bool vbus; |
---|
| 43 | + bool started; |
---|
42 | 44 | }; |
---|
43 | 45 | |
---|
44 | 46 | static struct class *udc_class; |
---|
.. | .. |
---|
85 | 87 | * for interrupt transfers as well as bulk, but it likely couldn't be used |
---|
86 | 88 | * for iso transfers or for endpoint 14. some endpoints are fully |
---|
87 | 89 | * configurable, with more generic names like "ep-a". (remember that for |
---|
88 | | - * USB, "in" means "towards the USB master".) |
---|
| 90 | + * USB, "in" means "towards the USB host".) |
---|
89 | 91 | * |
---|
90 | | - * This routine must be called in process context. |
---|
| 92 | + * This routine may be called in an atomic (interrupt) context. |
---|
91 | 93 | * |
---|
92 | 94 | * returns zero, or a negative error code. |
---|
93 | 95 | */ |
---|
.. | .. |
---|
132 | 134 | * gadget drivers must call usb_ep_enable() again before queueing |
---|
133 | 135 | * requests to the endpoint. |
---|
134 | 136 | * |
---|
135 | | - * This routine must be called in process context. |
---|
| 137 | + * This routine may be called in an atomic (interrupt) context. |
---|
136 | 138 | * |
---|
137 | 139 | * returns zero, or a negative error code. |
---|
138 | 140 | */ |
---|
.. | .. |
---|
292 | 294 | * @ep:the endpoint associated with the request |
---|
293 | 295 | * @req:the request being canceled |
---|
294 | 296 | * |
---|
295 | | - * If the request is still active on the endpoint, it is dequeued and its |
---|
296 | | - * completion routine is called (with status -ECONNRESET); else a negative |
---|
297 | | - * error code is returned. This is guaranteed to happen before the call to |
---|
298 | | - * usb_ep_dequeue() returns. |
---|
| 297 | + * If the request is still active on the endpoint, it is dequeued and |
---|
| 298 | + * eventually its completion routine is called (with status -ECONNRESET); |
---|
| 299 | + * else a negative error code is returned. This routine is asynchronous, |
---|
| 300 | + * that is, it may return before the completion routine runs. |
---|
299 | 301 | * |
---|
300 | 302 | * Note that some hardware can't clear out write fifos (to unlink the request |
---|
301 | 303 | * at the head of the queue) except as part of disconnecting from usb. Such |
---|
.. | .. |
---|
507 | 509 | EXPORT_SYMBOL_GPL(usb_gadget_wakeup); |
---|
508 | 510 | |
---|
509 | 511 | /** |
---|
510 | | - * usb_gsi_ep_op - performs operation on GSI accelerated EP based on EP op code |
---|
511 | | - * |
---|
512 | | - * Operations such as EP configuration, TRB allocation, StartXfer etc. |
---|
513 | | - * See gsi_ep_op for more details. |
---|
514 | | - */ |
---|
515 | | -int usb_gsi_ep_op(struct usb_ep *ep, |
---|
516 | | - struct usb_gsi_request *req, enum gsi_ep_op op) |
---|
517 | | -{ |
---|
518 | | - if (ep && ep->ops && ep->ops->gsi_ep_op) |
---|
519 | | - return ep->ops->gsi_ep_op(ep, req, op); |
---|
520 | | - |
---|
521 | | - return -EOPNOTSUPP; |
---|
522 | | -} |
---|
523 | | -EXPORT_SYMBOL_GPL(usb_gsi_ep_op); |
---|
524 | | - |
---|
525 | | -/** |
---|
526 | | - * usb_gadget_func_wakeup - send a function remote wakeup up notification |
---|
527 | | - * to the host connected to this gadget |
---|
528 | | - * @gadget: controller used to wake up the host |
---|
529 | | - * @interface_id: the interface which triggered the remote wakeup event |
---|
530 | | - * |
---|
531 | | - * Returns zero on success. Otherwise, negative error code is returned. |
---|
532 | | - */ |
---|
533 | | -int usb_gadget_func_wakeup(struct usb_gadget *gadget, |
---|
534 | | - int interface_id) |
---|
535 | | -{ |
---|
536 | | - if (!gadget || (gadget->speed != USB_SPEED_SUPER)) |
---|
537 | | - return -EOPNOTSUPP; |
---|
538 | | - |
---|
539 | | - if (!gadget->ops || !gadget->ops->func_wakeup) |
---|
540 | | - return -EOPNOTSUPP; |
---|
541 | | - |
---|
542 | | - return gadget->ops->func_wakeup(gadget, interface_id); |
---|
543 | | -} |
---|
544 | | -EXPORT_SYMBOL_GPL(usb_gadget_func_wakeup); |
---|
545 | | - |
---|
546 | | -/** |
---|
547 | 512 | * usb_gadget_set_selfpowered - sets the device selfpowered feature. |
---|
548 | 513 | * @gadget:the device being declared as self-powered |
---|
549 | 514 | * |
---|
.. | .. |
---|
738 | 703 | * as a disconnect (when a VBUS session is active). Not all systems |
---|
739 | 704 | * support software pullup controls. |
---|
740 | 705 | * |
---|
| 706 | + * Following a successful disconnect, invoke the ->disconnect() callback |
---|
| 707 | + * for the current gadget driver so that UDC drivers don't need to. |
---|
| 708 | + * |
---|
741 | 709 | * Returns zero on success, else negative errno. |
---|
742 | 710 | */ |
---|
743 | 711 | int usb_gadget_disconnect(struct usb_gadget *gadget) |
---|
.. | .. |
---|
748 | 716 | ret = -EOPNOTSUPP; |
---|
749 | 717 | goto out; |
---|
750 | 718 | } |
---|
| 719 | + |
---|
| 720 | + if (!gadget->connected) |
---|
| 721 | + goto out; |
---|
751 | 722 | |
---|
752 | 723 | if (gadget->deactivated) { |
---|
753 | 724 | /* |
---|
.. | .. |
---|
761 | 732 | ret = gadget->ops->pullup(gadget, 0); |
---|
762 | 733 | if (!ret) |
---|
763 | 734 | gadget->connected = 0; |
---|
| 735 | + |
---|
| 736 | + if (gadget->udc->driver) |
---|
| 737 | + gadget->udc->driver->disconnect(gadget); |
---|
764 | 738 | |
---|
765 | 739 | out: |
---|
766 | 740 | trace_usb_gadget_disconnect(gadget, ret); |
---|
.. | .. |
---|
787 | 761 | if (!gadget || gadget->deactivated) |
---|
788 | 762 | goto out; |
---|
789 | 763 | |
---|
790 | | - if (gadget->connected && !gadget->uvc_enabled) { |
---|
| 764 | + if (gadget->connected) { |
---|
791 | 765 | ret = usb_gadget_disconnect(gadget); |
---|
792 | 766 | if (ret) |
---|
793 | 767 | goto out; |
---|
.. | .. |
---|
923 | 897 | |
---|
924 | 898 | /** |
---|
925 | 899 | * usb_gadget_giveback_request - give the request back to the gadget layer |
---|
| 900 | + * @ep: the endpoint to be used with with the request |
---|
| 901 | + * @req: the request being given back |
---|
| 902 | + * |
---|
926 | 903 | * Context: in_interrupt() |
---|
927 | 904 | * |
---|
928 | 905 | * This is called by device controller drivers in order to return the |
---|
.. | .. |
---|
1030 | 1007 | } |
---|
1031 | 1008 | EXPORT_SYMBOL_GPL(usb_gadget_ep_match_desc); |
---|
1032 | 1009 | |
---|
| 1010 | +/** |
---|
| 1011 | + * usb_gadget_check_config - checks if the UDC can support the binded |
---|
| 1012 | + * configuration |
---|
| 1013 | + * @gadget: controller to check the USB configuration |
---|
| 1014 | + * |
---|
| 1015 | + * Ensure that a UDC is able to support the requested resources by a |
---|
| 1016 | + * configuration, and that there are no resource limitations, such as |
---|
| 1017 | + * internal memory allocated to all requested endpoints. |
---|
| 1018 | + * |
---|
| 1019 | + * Returns zero on success, else a negative errno. |
---|
| 1020 | + */ |
---|
| 1021 | +int usb_gadget_check_config(struct usb_gadget *gadget) |
---|
| 1022 | +{ |
---|
| 1023 | + if (gadget->ops->check_config) |
---|
| 1024 | + return gadget->ops->check_config(gadget); |
---|
| 1025 | + return 0; |
---|
| 1026 | +} |
---|
| 1027 | +EXPORT_SYMBOL_GPL(usb_gadget_check_config); |
---|
| 1028 | + |
---|
1033 | 1029 | /* ------------------------------------------------------------------------- */ |
---|
1034 | 1030 | |
---|
1035 | 1031 | static void usb_gadget_state_work(struct work_struct *work) |
---|
.. | .. |
---|
1051 | 1047 | |
---|
1052 | 1048 | /* ------------------------------------------------------------------------- */ |
---|
1053 | 1049 | |
---|
1054 | | -static void usb_udc_connect_control(struct usb_udc *udc) |
---|
| 1050 | +static int usb_udc_connect_control(struct usb_udc *udc) |
---|
1055 | 1051 | { |
---|
| 1052 | + int ret; |
---|
| 1053 | + |
---|
1056 | 1054 | if (udc->vbus) |
---|
1057 | | - usb_gadget_connect(udc->gadget); |
---|
| 1055 | + ret = usb_gadget_connect(udc->gadget); |
---|
1058 | 1056 | else |
---|
1059 | | - usb_gadget_disconnect(udc->gadget); |
---|
| 1057 | + ret = usb_gadget_disconnect(udc->gadget); |
---|
| 1058 | + |
---|
| 1059 | + return ret; |
---|
1060 | 1060 | } |
---|
1061 | 1061 | |
---|
1062 | 1062 | /** |
---|
.. | .. |
---|
1111 | 1111 | */ |
---|
1112 | 1112 | static inline int usb_gadget_udc_start(struct usb_udc *udc) |
---|
1113 | 1113 | { |
---|
1114 | | - return udc->gadget->ops->udc_start(udc->gadget, udc->driver); |
---|
| 1114 | + int ret; |
---|
| 1115 | + |
---|
| 1116 | + if (udc->started) { |
---|
| 1117 | + dev_err(&udc->dev, "UDC had already started\n"); |
---|
| 1118 | + return -EBUSY; |
---|
| 1119 | + } |
---|
| 1120 | + |
---|
| 1121 | + ret = udc->gadget->ops->udc_start(udc->gadget, udc->driver); |
---|
| 1122 | + if (!ret) |
---|
| 1123 | + udc->started = true; |
---|
| 1124 | + |
---|
| 1125 | + return ret; |
---|
1115 | 1126 | } |
---|
1116 | 1127 | |
---|
1117 | 1128 | /** |
---|
1118 | 1129 | * usb_gadget_udc_stop - tells usb device controller we don't need it anymore |
---|
1119 | | - * @gadget: The device we want to stop activity |
---|
1120 | | - * @driver: The driver to unbind from @gadget |
---|
| 1130 | + * @udc: The UDC to be stopped |
---|
1121 | 1131 | * |
---|
1122 | 1132 | * This call is issued by the UDC Class driver after calling |
---|
1123 | 1133 | * gadget driver's unbind() method. |
---|
.. | .. |
---|
1128 | 1138 | */ |
---|
1129 | 1139 | static inline void usb_gadget_udc_stop(struct usb_udc *udc) |
---|
1130 | 1140 | { |
---|
| 1141 | + if (!udc->started) { |
---|
| 1142 | + dev_err(&udc->dev, "UDC had already stopped\n"); |
---|
| 1143 | + return; |
---|
| 1144 | + } |
---|
| 1145 | + |
---|
1131 | 1146 | udc->gadget->ops->udc_stop(udc->gadget); |
---|
| 1147 | + udc->started = false; |
---|
1132 | 1148 | } |
---|
1133 | 1149 | |
---|
1134 | 1150 | /** |
---|
.. | .. |
---|
1144 | 1160 | static inline void usb_gadget_udc_set_speed(struct usb_udc *udc, |
---|
1145 | 1161 | enum usb_device_speed speed) |
---|
1146 | 1162 | { |
---|
1147 | | - if (udc->gadget->ops->udc_set_speed) { |
---|
1148 | | - enum usb_device_speed s; |
---|
| 1163 | + struct usb_gadget *gadget = udc->gadget; |
---|
| 1164 | + enum usb_device_speed s; |
---|
1149 | 1165 | |
---|
1150 | | - s = min(speed, udc->gadget->max_speed); |
---|
1151 | | - udc->gadget->ops->udc_set_speed(udc->gadget, s); |
---|
1152 | | - } |
---|
| 1166 | + if (speed == USB_SPEED_UNKNOWN) |
---|
| 1167 | + s = gadget->max_speed; |
---|
| 1168 | + else |
---|
| 1169 | + s = min(speed, gadget->max_speed); |
---|
| 1170 | + |
---|
| 1171 | + if (s == USB_SPEED_SUPER_PLUS && gadget->ops->udc_set_ssp_rate) |
---|
| 1172 | + gadget->ops->udc_set_ssp_rate(gadget, gadget->max_ssp_rate); |
---|
| 1173 | + else if (gadget->ops->udc_set_speed) |
---|
| 1174 | + gadget->ops->udc_set_speed(gadget, s); |
---|
| 1175 | +} |
---|
| 1176 | + |
---|
| 1177 | +/** |
---|
| 1178 | + * usb_gadget_enable_async_callbacks - tell usb device controller to enable asynchronous callbacks |
---|
| 1179 | + * @udc: The UDC which should enable async callbacks |
---|
| 1180 | + * |
---|
| 1181 | + * This routine is used when binding gadget drivers. It undoes the effect |
---|
| 1182 | + * of usb_gadget_disable_async_callbacks(); the UDC driver should enable IRQs |
---|
| 1183 | + * (if necessary) and resume issuing callbacks. |
---|
| 1184 | + * |
---|
| 1185 | + * This routine will always be called in process context. |
---|
| 1186 | + */ |
---|
| 1187 | +static inline void usb_gadget_enable_async_callbacks(struct usb_udc *udc) |
---|
| 1188 | +{ |
---|
| 1189 | + struct usb_gadget *gadget = udc->gadget; |
---|
| 1190 | + |
---|
| 1191 | + if (gadget->ops->udc_async_callbacks) |
---|
| 1192 | + gadget->ops->udc_async_callbacks(gadget, true); |
---|
| 1193 | +} |
---|
| 1194 | + |
---|
| 1195 | +/** |
---|
| 1196 | + * usb_gadget_disable_async_callbacks - tell usb device controller to disable asynchronous callbacks |
---|
| 1197 | + * @udc: The UDC which should disable async callbacks |
---|
| 1198 | + * |
---|
| 1199 | + * This routine is used when unbinding gadget drivers. It prevents a race: |
---|
| 1200 | + * The UDC driver doesn't know when the gadget driver's ->unbind callback |
---|
| 1201 | + * runs, so unless it is told to disable asynchronous callbacks, it might |
---|
| 1202 | + * issue a callback (such as ->disconnect) after the unbind has completed. |
---|
| 1203 | + * |
---|
| 1204 | + * After this function runs, the UDC driver must suppress all ->suspend, |
---|
| 1205 | + * ->resume, ->disconnect, ->reset, and ->setup callbacks to the gadget driver |
---|
| 1206 | + * until async callbacks are again enabled. A simple-minded but effective |
---|
| 1207 | + * way to accomplish this is to tell the UDC hardware not to generate any |
---|
| 1208 | + * more IRQs. |
---|
| 1209 | + * |
---|
| 1210 | + * Request completion callbacks must still be issued. However, it's okay |
---|
| 1211 | + * to defer them until the request is cancelled, since the pull-up will be |
---|
| 1212 | + * turned off during the time period when async callbacks are disabled. |
---|
| 1213 | + * |
---|
| 1214 | + * This routine will always be called in process context. |
---|
| 1215 | + */ |
---|
| 1216 | +static inline void usb_gadget_disable_async_callbacks(struct usb_udc *udc) |
---|
| 1217 | +{ |
---|
| 1218 | + struct usb_gadget *gadget = udc->gadget; |
---|
| 1219 | + |
---|
| 1220 | + if (gadget->ops->udc_async_callbacks) |
---|
| 1221 | + gadget->ops->udc_async_callbacks(gadget, false); |
---|
1153 | 1222 | } |
---|
1154 | 1223 | |
---|
1155 | 1224 | /** |
---|
.. | .. |
---|
1194 | 1263 | } |
---|
1195 | 1264 | |
---|
1196 | 1265 | /** |
---|
1197 | | - * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list |
---|
| 1266 | + * usb_initialize_gadget - initialize a gadget and its embedded struct device |
---|
1198 | 1267 | * @parent: the parent device to this udc. Usually the controller driver's |
---|
1199 | 1268 | * device. |
---|
1200 | | - * @gadget: the gadget to be added to the list. |
---|
| 1269 | + * @gadget: the gadget to be initialized. |
---|
1201 | 1270 | * @release: a gadget release function. |
---|
1202 | 1271 | * |
---|
1203 | 1272 | * Returns zero on success, negative errno otherwise. |
---|
1204 | 1273 | * Calls the gadget release function in the latter case. |
---|
1205 | 1274 | */ |
---|
1206 | | -int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, |
---|
| 1275 | +void usb_initialize_gadget(struct device *parent, struct usb_gadget *gadget, |
---|
1207 | 1276 | void (*release)(struct device *dev)) |
---|
1208 | 1277 | { |
---|
1209 | | - struct usb_udc *udc; |
---|
1210 | | - int ret = -ENOMEM; |
---|
1211 | | - |
---|
1212 | 1278 | dev_set_name(&gadget->dev, "gadget"); |
---|
1213 | 1279 | INIT_WORK(&gadget->work, usb_gadget_state_work); |
---|
1214 | 1280 | gadget->dev.parent = parent; |
---|
.. | .. |
---|
1219 | 1285 | gadget->dev.release = usb_udc_nop_release; |
---|
1220 | 1286 | |
---|
1221 | 1287 | device_initialize(&gadget->dev); |
---|
| 1288 | +} |
---|
| 1289 | +EXPORT_SYMBOL_GPL(usb_initialize_gadget); |
---|
| 1290 | + |
---|
| 1291 | +/** |
---|
| 1292 | + * usb_add_gadget - adds a new gadget to the udc class driver list |
---|
| 1293 | + * @gadget: the gadget to be added to the list. |
---|
| 1294 | + * |
---|
| 1295 | + * Returns zero on success, negative errno otherwise. |
---|
| 1296 | + * Does not do a final usb_put_gadget() if an error occurs. |
---|
| 1297 | + */ |
---|
| 1298 | +int usb_add_gadget(struct usb_gadget *gadget) |
---|
| 1299 | +{ |
---|
| 1300 | + struct usb_udc *udc; |
---|
| 1301 | + int ret = -ENOMEM; |
---|
1222 | 1302 | |
---|
1223 | 1303 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); |
---|
1224 | 1304 | if (!udc) |
---|
1225 | | - goto err_put_gadget; |
---|
| 1305 | + goto error; |
---|
1226 | 1306 | |
---|
1227 | 1307 | device_initialize(&udc->dev); |
---|
1228 | 1308 | udc->dev.release = usb_udc_release; |
---|
1229 | 1309 | udc->dev.class = udc_class; |
---|
1230 | 1310 | udc->dev.groups = usb_udc_attr_groups; |
---|
1231 | | - udc->dev.parent = parent; |
---|
1232 | | - ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); |
---|
| 1311 | + udc->dev.parent = gadget->dev.parent; |
---|
| 1312 | + ret = dev_set_name(&udc->dev, "%s", |
---|
| 1313 | + kobject_name(&gadget->dev.parent->kobj)); |
---|
1233 | 1314 | if (ret) |
---|
1234 | 1315 | goto err_put_udc; |
---|
1235 | 1316 | |
---|
.. | .. |
---|
1239 | 1320 | |
---|
1240 | 1321 | udc->gadget = gadget; |
---|
1241 | 1322 | gadget->udc = udc; |
---|
| 1323 | + |
---|
| 1324 | + udc->started = false; |
---|
1242 | 1325 | |
---|
1243 | 1326 | mutex_lock(&udc_lock); |
---|
1244 | 1327 | list_add_tail(&udc->list, &udc_list); |
---|
.. | .. |
---|
1260 | 1343 | return 0; |
---|
1261 | 1344 | |
---|
1262 | 1345 | err_del_udc: |
---|
| 1346 | + flush_work(&gadget->work); |
---|
1263 | 1347 | device_del(&udc->dev); |
---|
1264 | 1348 | |
---|
1265 | 1349 | err_unlist_udc: |
---|
.. | .. |
---|
1271 | 1355 | err_put_udc: |
---|
1272 | 1356 | put_device(&udc->dev); |
---|
1273 | 1357 | |
---|
1274 | | - err_put_gadget: |
---|
1275 | | - put_device(&gadget->dev); |
---|
| 1358 | + error: |
---|
| 1359 | + return ret; |
---|
| 1360 | +} |
---|
| 1361 | +EXPORT_SYMBOL_GPL(usb_add_gadget); |
---|
| 1362 | + |
---|
| 1363 | +/** |
---|
| 1364 | + * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list |
---|
| 1365 | + * @parent: the parent device to this udc. Usually the controller driver's |
---|
| 1366 | + * device. |
---|
| 1367 | + * @gadget: the gadget to be added to the list. |
---|
| 1368 | + * @release: a gadget release function. |
---|
| 1369 | + * |
---|
| 1370 | + * Returns zero on success, negative errno otherwise. |
---|
| 1371 | + * Calls the gadget release function in the latter case. |
---|
| 1372 | + */ |
---|
| 1373 | +int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, |
---|
| 1374 | + void (*release)(struct device *dev)) |
---|
| 1375 | +{ |
---|
| 1376 | + int ret; |
---|
| 1377 | + |
---|
| 1378 | + usb_initialize_gadget(parent, gadget, release); |
---|
| 1379 | + ret = usb_add_gadget(gadget); |
---|
| 1380 | + if (ret) |
---|
| 1381 | + usb_put_gadget(gadget); |
---|
1276 | 1382 | return ret; |
---|
1277 | 1383 | } |
---|
1278 | 1384 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); |
---|
.. | .. |
---|
1329 | 1435 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
---|
1330 | 1436 | |
---|
1331 | 1437 | usb_gadget_disconnect(udc->gadget); |
---|
1332 | | - udc->driver->disconnect(udc->gadget); |
---|
| 1438 | + usb_gadget_disable_async_callbacks(udc); |
---|
| 1439 | + if (udc->gadget->irq) |
---|
| 1440 | + synchronize_irq(udc->gadget->irq); |
---|
1333 | 1441 | udc->driver->unbind(udc->gadget); |
---|
1334 | 1442 | usb_gadget_udc_stop(udc); |
---|
1335 | 1443 | |
---|
1336 | 1444 | udc->driver = NULL; |
---|
1337 | | - udc->dev.driver = NULL; |
---|
1338 | 1445 | udc->gadget->dev.driver = NULL; |
---|
1339 | 1446 | } |
---|
1340 | 1447 | |
---|
1341 | 1448 | /** |
---|
1342 | | - * usb_del_gadget_udc - deletes @udc from udc_list |
---|
| 1449 | + * usb_del_gadget - deletes @udc from udc_list |
---|
1343 | 1450 | * @gadget: the gadget to be removed. |
---|
1344 | 1451 | * |
---|
1345 | | - * This, will call usb_gadget_unregister_driver() if |
---|
| 1452 | + * This will call usb_gadget_unregister_driver() if |
---|
1346 | 1453 | * the @udc is still busy. |
---|
| 1454 | + * It will not do a final usb_put_gadget(). |
---|
1347 | 1455 | */ |
---|
1348 | | -void usb_del_gadget_udc(struct usb_gadget *gadget) |
---|
| 1456 | +void usb_del_gadget(struct usb_gadget *gadget) |
---|
1349 | 1457 | { |
---|
1350 | 1458 | struct usb_udc *udc = gadget->udc; |
---|
1351 | 1459 | |
---|
.. | .. |
---|
1368 | 1476 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); |
---|
1369 | 1477 | flush_work(&gadget->work); |
---|
1370 | 1478 | device_unregister(&udc->dev); |
---|
1371 | | - device_unregister(&gadget->dev); |
---|
1372 | | - memset(&gadget->dev, 0x00, sizeof(gadget->dev)); |
---|
| 1479 | + device_del(&gadget->dev); |
---|
| 1480 | +} |
---|
| 1481 | +EXPORT_SYMBOL_GPL(usb_del_gadget); |
---|
| 1482 | + |
---|
| 1483 | +/** |
---|
| 1484 | + * usb_del_gadget_udc - deletes @udc from udc_list |
---|
| 1485 | + * @gadget: the gadget to be removed. |
---|
| 1486 | + * |
---|
| 1487 | + * Calls usb_del_gadget() and does a final usb_put_gadget(). |
---|
| 1488 | + */ |
---|
| 1489 | +void usb_del_gadget_udc(struct usb_gadget *gadget) |
---|
| 1490 | +{ |
---|
| 1491 | + usb_del_gadget(gadget); |
---|
| 1492 | + usb_put_gadget(gadget); |
---|
1373 | 1493 | } |
---|
1374 | 1494 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); |
---|
1375 | 1495 | |
---|
.. | .. |
---|
1383 | 1503 | driver->function); |
---|
1384 | 1504 | |
---|
1385 | 1505 | udc->driver = driver; |
---|
1386 | | - udc->dev.driver = &driver->driver; |
---|
1387 | 1506 | udc->gadget->dev.driver = &driver->driver; |
---|
1388 | 1507 | |
---|
1389 | 1508 | usb_gadget_udc_set_speed(udc, driver->max_speed); |
---|
.. | .. |
---|
1392 | 1511 | if (ret) |
---|
1393 | 1512 | goto err1; |
---|
1394 | 1513 | ret = usb_gadget_udc_start(udc); |
---|
1395 | | - if (ret) { |
---|
1396 | | - driver->unbind(udc->gadget); |
---|
1397 | | - goto err1; |
---|
1398 | | - } |
---|
1399 | | - usb_udc_connect_control(udc); |
---|
| 1514 | + if (ret) |
---|
| 1515 | + goto err_start; |
---|
| 1516 | + |
---|
| 1517 | + usb_gadget_enable_async_callbacks(udc); |
---|
| 1518 | + ret = usb_udc_connect_control(udc); |
---|
| 1519 | + if (ret) |
---|
| 1520 | + goto err_connect_control; |
---|
1400 | 1521 | |
---|
1401 | 1522 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
---|
1402 | 1523 | return 0; |
---|
| 1524 | + |
---|
| 1525 | +err_connect_control: |
---|
| 1526 | + usb_gadget_disable_async_callbacks(udc); |
---|
| 1527 | + if (udc->gadget->irq) |
---|
| 1528 | + synchronize_irq(udc->gadget->irq); |
---|
| 1529 | + usb_gadget_udc_stop(udc); |
---|
| 1530 | + |
---|
| 1531 | +err_start: |
---|
| 1532 | + driver->unbind(udc->gadget); |
---|
| 1533 | + |
---|
1403 | 1534 | err1: |
---|
1404 | 1535 | if (ret != -EISNAM) |
---|
1405 | 1536 | dev_err(&udc->dev, "failed to start %s: %d\n", |
---|
1406 | 1537 | udc->driver->function, ret); |
---|
1407 | 1538 | udc->driver = NULL; |
---|
1408 | | - udc->dev.driver = NULL; |
---|
1409 | 1539 | udc->gadget->dev.driver = NULL; |
---|
1410 | 1540 | return ret; |
---|
1411 | 1541 | } |
---|
.. | .. |
---|
1447 | 1577 | } |
---|
1448 | 1578 | |
---|
1449 | 1579 | mutex_unlock(&udc_lock); |
---|
| 1580 | + if (ret) |
---|
| 1581 | + pr_warn("udc-core: couldn't find an available UDC or it's busy\n"); |
---|
1450 | 1582 | return ret; |
---|
1451 | 1583 | found: |
---|
1452 | 1584 | ret = udc_bind_to_driver(udc, driver); |
---|
.. | .. |
---|
1522 | 1654 | usb_gadget_connect(udc->gadget); |
---|
1523 | 1655 | } else if (sysfs_streq(buf, "disconnect")) { |
---|
1524 | 1656 | usb_gadget_disconnect(udc->gadget); |
---|
1525 | | - udc->driver->disconnect(udc->gadget); |
---|
1526 | 1657 | usb_gadget_udc_stop(udc); |
---|
1527 | 1658 | } else { |
---|
1528 | 1659 | dev_err(dev, "unsupported command '%s'\n", buf); |
---|