aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb
diff options
context:
space:
mode:
authorFelipe Balbi <felipe.balbi@linux.intel.com>2016-05-31 06:07:47 -0400
committerFelipe Balbi <felipe.balbi@linux.intel.com>2016-06-21 03:38:34 -0400
commit5a8d651a2bde01e00caf78496390d6ae46df80af (patch)
tree13237dee50d4ce6f31d7114975a40809cfb136ee /include/linux/usb
parentd6dc2e76a860d6be0129daae43e5f12461531d20 (diff)
usb: gadget: move gadget API functions to udc-core
instead of defining all functions as static inlines, let's move them to udc-core and export them with EXPORT_SYMBOL_GPL, that way we can make sure that only GPL drivers will use them. As a side effect, it'll be nicer to add tracepoints to the gadget API. While at that, also fix Kconfig dependencies to avoid randconfig build failures. Acked-By: Sebastian Reichel <sre@kernel.org> Acked-by: Peter Chen <peter.chen@nxp.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Diffstat (limited to 'include/linux/usb')
-rw-r--r--include/linux/usb/gadget.h585
1 files changed, 60 insertions, 525 deletions
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index fefe8b06a63d..c6e1149ddb0d 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -228,307 +228,49 @@ struct usb_ep {
228 228
229/*-------------------------------------------------------------------------*/ 229/*-------------------------------------------------------------------------*/
230 230
231/** 231#if IS_ENABLED(CONFIG_USB_GADGET)
232 * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint 232void usb_ep_set_maxpacket_limit(struct usb_ep *ep, unsigned maxpacket_limit);
233 * @ep:the endpoint being configured 233int usb_ep_enable(struct usb_ep *ep);
234 * @maxpacket_limit:value of maximum packet size limit 234int usb_ep_disable(struct usb_ep *ep);
235 * 235struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
236 * This function should be used only in UDC drivers to initialize endpoint 236void usb_ep_free_request(struct usb_ep *ep, struct usb_request *req);
237 * (usually in probe function). 237int usb_ep_queue(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags);
238 */ 238int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req);
239int usb_ep_set_halt(struct usb_ep *ep);
240int usb_ep_clear_halt(struct usb_ep *ep);
241int usb_ep_set_wedge(struct usb_ep *ep);
242int usb_ep_fifo_status(struct usb_ep *ep);
243void usb_ep_fifo_flush(struct usb_ep *ep);
244#else
239static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, 245static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
240 unsigned maxpacket_limit) 246 unsigned maxpacket_limit)
241{ 247{ }
242 ep->maxpacket_limit = maxpacket_limit;
243 ep->maxpacket = maxpacket_limit;
244}
245
246/**
247 * usb_ep_enable - configure endpoint, making it usable
248 * @ep:the endpoint being configured. may not be the endpoint named "ep0".
249 * drivers discover endpoints through the ep_list of a usb_gadget.
250 *
251 * When configurations are set, or when interface settings change, the driver
252 * will enable or disable the relevant endpoints. while it is enabled, an
253 * endpoint may be used for i/o until the driver receives a disconnect() from
254 * the host or until the endpoint is disabled.
255 *
256 * the ep0 implementation (which calls this routine) must ensure that the
257 * hardware capabilities of each endpoint match the descriptor provided
258 * for it. for example, an endpoint named "ep2in-bulk" would be usable
259 * for interrupt transfers as well as bulk, but it likely couldn't be used
260 * for iso transfers or for endpoint 14. some endpoints are fully
261 * configurable, with more generic names like "ep-a". (remember that for
262 * USB, "in" means "towards the USB master".)
263 *
264 * returns zero, or a negative error code.
265 */
266static inline int usb_ep_enable(struct usb_ep *ep) 248static inline int usb_ep_enable(struct usb_ep *ep)
267{ 249{ return 0; }
268 int ret;
269
270 if (ep->enabled)
271 return 0;
272
273 ret = ep->ops->enable(ep, ep->desc);
274 if (ret)
275 return ret;
276
277 ep->enabled = true;
278
279 return 0;
280}
281
282/**
283 * usb_ep_disable - endpoint is no longer usable
284 * @ep:the endpoint being unconfigured. may not be the endpoint named "ep0".
285 *
286 * no other task may be using this endpoint when this is called.
287 * any pending and uncompleted requests will complete with status
288 * indicating disconnect (-ESHUTDOWN) before this call returns.
289 * gadget drivers must call usb_ep_enable() again before queueing
290 * requests to the endpoint.
291 *
292 * returns zero, or a negative error code.
293 */
294static inline int usb_ep_disable(struct usb_ep *ep) 250static inline int usb_ep_disable(struct usb_ep *ep)
295{ 251{ return 0; }
296 int ret;
297
298 if (!ep->enabled)
299 return 0;
300
301 ret = ep->ops->disable(ep);
302 if (ret)
303 return ret;
304
305 ep->enabled = false;
306
307 return 0;
308}
309
310/**
311 * usb_ep_alloc_request - allocate a request object to use with this endpoint
312 * @ep:the endpoint to be used with with the request
313 * @gfp_flags:GFP_* flags to use
314 *
315 * Request objects must be allocated with this call, since they normally
316 * need controller-specific setup and may even need endpoint-specific
317 * resources such as allocation of DMA descriptors.
318 * Requests may be submitted with usb_ep_queue(), and receive a single
319 * completion callback. Free requests with usb_ep_free_request(), when
320 * they are no longer needed.
321 *
322 * Returns the request, or null if one could not be allocated.
323 */
324static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, 252static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
325 gfp_t gfp_flags) 253 gfp_t gfp_flags)
326{ 254{ return NULL; }
327 return ep->ops->alloc_request(ep, gfp_flags);
328}
329
330/**
331 * usb_ep_free_request - frees a request object
332 * @ep:the endpoint associated with the request
333 * @req:the request being freed
334 *
335 * Reverses the effect of usb_ep_alloc_request().
336 * Caller guarantees the request is not queued, and that it will
337 * no longer be requeued (or otherwise used).
338 */
339static inline void usb_ep_free_request(struct usb_ep *ep, 255static inline void usb_ep_free_request(struct usb_ep *ep,
340 struct usb_request *req) 256 struct usb_request *req)
341{ 257{ }
342 ep->ops->free_request(ep, req); 258static inline int usb_ep_queue(struct usb_ep *ep, struct usb_request *req,
343} 259 gfp_t gfp_flags)
344 260{ return 0; }
345/**
346 * usb_ep_queue - queues (submits) an I/O request to an endpoint.
347 * @ep:the endpoint associated with the request
348 * @req:the request being submitted
349 * @gfp_flags: GFP_* flags to use in case the lower level driver couldn't
350 * pre-allocate all necessary memory with the request.
351 *
352 * This tells the device controller to perform the specified request through
353 * that endpoint (reading or writing a buffer). When the request completes,
354 * including being canceled by usb_ep_dequeue(), the request's completion
355 * routine is called to return the request to the driver. Any endpoint
356 * (except control endpoints like ep0) may have more than one transfer
357 * request queued; they complete in FIFO order. Once a gadget driver
358 * submits a request, that request may not be examined or modified until it
359 * is given back to that driver through the completion callback.
360 *
361 * Each request is turned into one or more packets. The controller driver
362 * never merges adjacent requests into the same packet. OUT transfers
363 * will sometimes use data that's already buffered in the hardware.
364 * Drivers can rely on the fact that the first byte of the request's buffer
365 * always corresponds to the first byte of some USB packet, for both
366 * IN and OUT transfers.
367 *
368 * Bulk endpoints can queue any amount of data; the transfer is packetized
369 * automatically. The last packet will be short if the request doesn't fill it
370 * out completely. Zero length packets (ZLPs) should be avoided in portable
371 * protocols since not all usb hardware can successfully handle zero length
372 * packets. (ZLPs may be explicitly written, and may be implicitly written if
373 * the request 'zero' flag is set.) Bulk endpoints may also be used
374 * for interrupt transfers; but the reverse is not true, and some endpoints
375 * won't support every interrupt transfer. (Such as 768 byte packets.)
376 *
377 * Interrupt-only endpoints are less functional than bulk endpoints, for
378 * example by not supporting queueing or not handling buffers that are
379 * larger than the endpoint's maxpacket size. They may also treat data
380 * toggle differently.
381 *
382 * Control endpoints ... after getting a setup() callback, the driver queues
383 * one response (even if it would be zero length). That enables the
384 * status ack, after transferring data as specified in the response. Setup
385 * functions may return negative error codes to generate protocol stalls.
386 * (Note that some USB device controllers disallow protocol stall responses
387 * in some cases.) When control responses are deferred (the response is
388 * written after the setup callback returns), then usb_ep_set_halt() may be
389 * used on ep0 to trigger protocol stalls. Depending on the controller,
390 * it may not be possible to trigger a status-stage protocol stall when the
391 * data stage is over, that is, from within the response's completion
392 * routine.
393 *
394 * For periodic endpoints, like interrupt or isochronous ones, the usb host
395 * arranges to poll once per interval, and the gadget driver usually will
396 * have queued some data to transfer at that time.
397 *
398 * Returns zero, or a negative error code. Endpoints that are not enabled
399 * report errors; errors will also be
400 * reported when the usb peripheral is disconnected.
401 */
402static inline int usb_ep_queue(struct usb_ep *ep,
403 struct usb_request *req, gfp_t gfp_flags)
404{
405 if (WARN_ON_ONCE(!ep->enabled && ep->address))
406 return -ESHUTDOWN;
407
408 return ep->ops->queue(ep, req, gfp_flags);
409}
410
411/**
412 * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint
413 * @ep:the endpoint associated with the request
414 * @req:the request being canceled
415 *
416 * If the request is still active on the endpoint, it is dequeued and its
417 * completion routine is called (with status -ECONNRESET); else a negative
418 * error code is returned. This is guaranteed to happen before the call to
419 * usb_ep_dequeue() returns.
420 *
421 * Note that some hardware can't clear out write fifos (to unlink the request
422 * at the head of the queue) except as part of disconnecting from usb. Such
423 * restrictions prevent drivers from supporting configuration changes,
424 * even to configuration zero (a "chapter 9" requirement).
425 */
426static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) 261static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
427{ 262{ return 0; }
428 return ep->ops->dequeue(ep, req);
429}
430
431/**
432 * usb_ep_set_halt - sets the endpoint halt feature.
433 * @ep: the non-isochronous endpoint being stalled
434 *
435 * Use this to stall an endpoint, perhaps as an error report.
436 * Except for control endpoints,
437 * the endpoint stays halted (will not stream any data) until the host
438 * clears this feature; drivers may need to empty the endpoint's request
439 * queue first, to make sure no inappropriate transfers happen.
440 *
441 * Note that while an endpoint CLEAR_FEATURE will be invisible to the
442 * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the
443 * current altsetting, see usb_ep_clear_halt(). When switching altsettings,
444 * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints.
445 *
446 * Returns zero, or a negative error code. On success, this call sets
447 * underlying hardware state that blocks data transfers.
448 * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any
449 * transfer requests are still queued, or if the controller hardware
450 * (usually a FIFO) still holds bytes that the host hasn't collected.
451 */
452static inline int usb_ep_set_halt(struct usb_ep *ep) 263static inline int usb_ep_set_halt(struct usb_ep *ep)
453{ 264{ return 0; }
454 return ep->ops->set_halt(ep, 1);
455}
456
457/**
458 * usb_ep_clear_halt - clears endpoint halt, and resets toggle
459 * @ep:the bulk or interrupt endpoint being reset
460 *
461 * Use this when responding to the standard usb "set interface" request,
462 * for endpoints that aren't reconfigured, after clearing any other state
463 * in the endpoint's i/o queue.
464 *
465 * Returns zero, or a negative error code. On success, this call clears
466 * the underlying hardware state reflecting endpoint halt and data toggle.
467 * Note that some hardware can't support this request (like pxa2xx_udc),
468 * and accordingly can't correctly implement interface altsettings.
469 */
470static inline int usb_ep_clear_halt(struct usb_ep *ep) 265static inline int usb_ep_clear_halt(struct usb_ep *ep)
471{ 266{ return 0; }
472 return ep->ops->set_halt(ep, 0); 267static inline int usb_ep_set_wedge(struct usb_ep *ep)
473} 268{ return 0; }
474
475/**
476 * usb_ep_set_wedge - sets the halt feature and ignores clear requests
477 * @ep: the endpoint being wedged
478 *
479 * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
480 * requests. If the gadget driver clears the halt status, it will
481 * automatically unwedge the endpoint.
482 *
483 * Returns zero on success, else negative errno.
484 */
485static inline int
486usb_ep_set_wedge(struct usb_ep *ep)
487{
488 if (ep->ops->set_wedge)
489 return ep->ops->set_wedge(ep);
490 else
491 return ep->ops->set_halt(ep, 1);
492}
493
494/**
495 * usb_ep_fifo_status - returns number of bytes in fifo, or error
496 * @ep: the endpoint whose fifo status is being checked.
497 *
498 * FIFO endpoints may have "unclaimed data" in them in certain cases,
499 * such as after aborted transfers. Hosts may not have collected all
500 * the IN data written by the gadget driver (and reported by a request
501 * completion). The gadget driver may not have collected all the data
502 * written OUT to it by the host. Drivers that need precise handling for
503 * fault reporting or recovery may need to use this call.
504 *
505 * This returns the number of such bytes in the fifo, or a negative
506 * errno if the endpoint doesn't use a FIFO or doesn't support such
507 * precise handling.
508 */
509static inline int usb_ep_fifo_status(struct usb_ep *ep) 269static inline int usb_ep_fifo_status(struct usb_ep *ep)
510{ 270{ return 0; }
511 if (ep->ops->fifo_status)
512 return ep->ops->fifo_status(ep);
513 else
514 return -EOPNOTSUPP;
515}
516
517/**
518 * usb_ep_fifo_flush - flushes contents of a fifo
519 * @ep: the endpoint whose fifo is being flushed.
520 *
521 * This call may be used to flush the "unclaimed data" that may exist in
522 * an endpoint fifo after abnormal transaction terminations. The call
523 * must never be used except when endpoint is not being used for any
524 * protocol translation.
525 */
526static inline void usb_ep_fifo_flush(struct usb_ep *ep) 271static inline void usb_ep_fifo_flush(struct usb_ep *ep)
527{ 272{ }
528 if (ep->ops->fifo_flush) 273#endif /* USB_GADGET */
529 ep->ops->fifo_flush(ep);
530}
531
532 274
533/*-------------------------------------------------------------------------*/ 275/*-------------------------------------------------------------------------*/
534 276
@@ -760,251 +502,44 @@ static inline int gadget_is_otg(struct usb_gadget *g)
760#endif 502#endif
761} 503}
762 504
763/** 505/*-------------------------------------------------------------------------*/
764 * usb_gadget_frame_number - returns the current frame number
765 * @gadget: controller that reports the frame number
766 *
767 * Returns the usb frame number, normally eleven bits from a SOF packet,
768 * or negative errno if this device doesn't support this capability.
769 */
770static inline int usb_gadget_frame_number(struct usb_gadget *gadget)
771{
772 return gadget->ops->get_frame(gadget);
773}
774 506
775/** 507#if IS_ENABLED(CONFIG_USB_GADGET)
776 * usb_gadget_wakeup - tries to wake up the host connected to this gadget 508int usb_gadget_frame_number(struct usb_gadget *gadget);
777 * @gadget: controller used to wake up the host 509int usb_gadget_wakeup(struct usb_gadget *gadget);
778 * 510int usb_gadget_set_selfpowered(struct usb_gadget *gadget);
779 * Returns zero on success, else negative error code if the hardware 511int usb_gadget_clear_selfpowered(struct usb_gadget *gadget);
780 * doesn't support such attempts, or its support has not been enabled 512int usb_gadget_vbus_connect(struct usb_gadget *gadget);
781 * by the usb host. Drivers must return device descriptors that report 513int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA);
782 * their ability to support this, or hosts won't enable it. 514int usb_gadget_vbus_disconnect(struct usb_gadget *gadget);
783 * 515int usb_gadget_connect(struct usb_gadget *gadget);
784 * This may also try to use SRP to wake the host and start enumeration, 516int usb_gadget_disconnect(struct usb_gadget *gadget);
785 * even if OTG isn't otherwise in use. OTG devices may also start 517int usb_gadget_deactivate(struct usb_gadget *gadget);
786 * remote wakeup even when hosts don't explicitly enable it. 518int usb_gadget_activate(struct usb_gadget *gadget);
787 */ 519#else
520static inline int usb_gadget_frame_number(struct usb_gadget *gadget)
521{ return 0; }
788static inline int usb_gadget_wakeup(struct usb_gadget *gadget) 522static inline int usb_gadget_wakeup(struct usb_gadget *gadget)
789{ 523{ return 0; }
790 if (!gadget->ops->wakeup)
791 return -EOPNOTSUPP;
792 return gadget->ops->wakeup(gadget);
793}
794
795/**
796 * usb_gadget_set_selfpowered - sets the device selfpowered feature.
797 * @gadget:the device being declared as self-powered
798 *
799 * this affects the device status reported by the hardware driver
800 * to reflect that it now has a local power supply.
801 *
802 * returns zero on success, else negative errno.
803 */
804static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget) 524static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget)
805{ 525{ return 0; }
806 if (!gadget->ops->set_selfpowered)
807 return -EOPNOTSUPP;
808 return gadget->ops->set_selfpowered(gadget, 1);
809}
810
811/**
812 * usb_gadget_clear_selfpowered - clear the device selfpowered feature.
813 * @gadget:the device being declared as bus-powered
814 *
815 * this affects the device status reported by the hardware driver.
816 * some hardware may not support bus-powered operation, in which
817 * case this feature's value can never change.
818 *
819 * returns zero on success, else negative errno.
820 */
821static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) 526static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget)
822{ 527{ return 0; }
823 if (!gadget->ops->set_selfpowered)
824 return -EOPNOTSUPP;
825 return gadget->ops->set_selfpowered(gadget, 0);
826}
827
828/**
829 * usb_gadget_vbus_connect - Notify controller that VBUS is powered
830 * @gadget:The device which now has VBUS power.
831 * Context: can sleep
832 *
833 * This call is used by a driver for an external transceiver (or GPIO)
834 * that detects a VBUS power session starting. Common responses include
835 * resuming the controller, activating the D+ (or D-) pullup to let the
836 * host detect that a USB device is attached, and starting to draw power
837 * (8mA or possibly more, especially after SET_CONFIGURATION).
838 *
839 * Returns zero on success, else negative errno.
840 */
841static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) 528static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget)
842{ 529{ return 0; }
843 if (!gadget->ops->vbus_session)
844 return -EOPNOTSUPP;
845 return gadget->ops->vbus_session(gadget, 1);
846}
847
848/**
849 * usb_gadget_vbus_draw - constrain controller's VBUS power usage
850 * @gadget:The device whose VBUS usage is being described
851 * @mA:How much current to draw, in milliAmperes. This should be twice
852 * the value listed in the configuration descriptor bMaxPower field.
853 *
854 * This call is used by gadget drivers during SET_CONFIGURATION calls,
855 * reporting how much power the device may consume. For example, this
856 * could affect how quickly batteries are recharged.
857 *
858 * Returns zero on success, else negative errno.
859 */
860static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) 530static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
861{ 531{ return 0; }
862 if (!gadget->ops->vbus_draw)
863 return -EOPNOTSUPP;
864 return gadget->ops->vbus_draw(gadget, mA);
865}
866
867/**
868 * usb_gadget_vbus_disconnect - notify controller about VBUS session end
869 * @gadget:the device whose VBUS supply is being described
870 * Context: can sleep
871 *
872 * This call is used by a driver for an external transceiver (or GPIO)
873 * that detects a VBUS power session ending. Common responses include
874 * reversing everything done in usb_gadget_vbus_connect().
875 *
876 * Returns zero on success, else negative errno.
877 */
878static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) 532static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
879{ 533{ return 0; }
880 if (!gadget->ops->vbus_session)
881 return -EOPNOTSUPP;
882 return gadget->ops->vbus_session(gadget, 0);
883}
884
885/**
886 * usb_gadget_connect - software-controlled connect to USB host
887 * @gadget:the peripheral being connected
888 *
889 * Enables the D+ (or potentially D-) pullup. The host will start
890 * enumerating this gadget when the pullup is active and a VBUS session
891 * is active (the link is powered). This pullup is always enabled unless
892 * usb_gadget_disconnect() has been used to disable it.
893 *
894 * Returns zero on success, else negative errno.
895 */
896static inline int usb_gadget_connect(struct usb_gadget *gadget) 534static inline int usb_gadget_connect(struct usb_gadget *gadget)
897{ 535{ return 0; }
898 int ret;
899
900 if (!gadget->ops->pullup)
901 return -EOPNOTSUPP;
902
903 if (gadget->deactivated) {
904 /*
905 * If gadget is deactivated we only save new state.
906 * Gadget will be connected automatically after activation.
907 */
908 gadget->connected = true;
909 return 0;
910 }
911
912 ret = gadget->ops->pullup(gadget, 1);
913 if (!ret)
914 gadget->connected = 1;
915 return ret;
916}
917
918/**
919 * usb_gadget_disconnect - software-controlled disconnect from USB host
920 * @gadget:the peripheral being disconnected
921 *
922 * Disables the D+ (or potentially D-) pullup, which the host may see
923 * as a disconnect (when a VBUS session is active). Not all systems
924 * support software pullup controls.
925 *
926 * Returns zero on success, else negative errno.
927 */
928static inline int usb_gadget_disconnect(struct usb_gadget *gadget) 536static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
929{ 537{ return 0; }
930 int ret;
931
932 if (!gadget->ops->pullup)
933 return -EOPNOTSUPP;
934
935 if (gadget->deactivated) {
936 /*
937 * If gadget is deactivated we only save new state.
938 * Gadget will stay disconnected after activation.
939 */
940 gadget->connected = false;
941 return 0;
942 }
943
944 ret = gadget->ops->pullup(gadget, 0);
945 if (!ret)
946 gadget->connected = 0;
947 return ret;
948}
949
950/**
951 * usb_gadget_deactivate - deactivate function which is not ready to work
952 * @gadget: the peripheral being deactivated
953 *
954 * This routine may be used during the gadget driver bind() call to prevent
955 * the peripheral from ever being visible to the USB host, unless later
956 * usb_gadget_activate() is called. For example, user mode components may
957 * need to be activated before the system can talk to hosts.
958 *
959 * Returns zero on success, else negative errno.
960 */
961static inline int usb_gadget_deactivate(struct usb_gadget *gadget) 538static inline int usb_gadget_deactivate(struct usb_gadget *gadget)
962{ 539{ return 0; }
963 int ret;
964
965 if (gadget->deactivated)
966 return 0;
967
968 if (gadget->connected) {
969 ret = usb_gadget_disconnect(gadget);
970 if (ret)
971 return ret;
972 /*
973 * If gadget was being connected before deactivation, we want
974 * to reconnect it in usb_gadget_activate().
975 */
976 gadget->connected = true;
977 }
978 gadget->deactivated = true;
979
980 return 0;
981}
982
983/**
984 * usb_gadget_activate - activate function which is not ready to work
985 * @gadget: the peripheral being activated
986 *
987 * This routine activates gadget which was previously deactivated with
988 * usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed.
989 *
990 * Returns zero on success, else negative errno.
991 */
992static inline int usb_gadget_activate(struct usb_gadget *gadget) 540static inline int usb_gadget_activate(struct usb_gadget *gadget)
993{ 541{ return 0; }
994 if (!gadget->deactivated) 542#endif /* CONFIG_USB_GADGET */
995 return 0;
996
997 gadget->deactivated = false;
998
999 /*
1000 * If gadget has been connected before deactivation, or became connected
1001 * while it was being deactivated, we call usb_gadget_connect().
1002 */
1003 if (gadget->connected)
1004 return usb_gadget_connect(gadget);
1005
1006 return 0;
1007}
1008 543
1009/*-------------------------------------------------------------------------*/ 544/*-------------------------------------------------------------------------*/
1010 545