blob: 0402177f93cdde2346586ff95b392256e17f84ce [file] [log] [blame]
Felipe Balbi2ccea032011-06-28 16:33:46 +03001/**
2 * udc.c - Core UDC Framework
3 *
4 * Copyright (C) 2010 Texas Instruments
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/device.h>
23#include <linux/list.h>
24#include <linux/err.h>
Felipe Balbia6989082011-12-15 13:31:48 +020025#include <linux/dma-mapping.h>
Felipe Balbi5702f752013-07-17 11:09:49 +030026#include <linux/workqueue.h>
Felipe Balbi2ccea032011-06-28 16:33:46 +030027
28#include <linux/usb/ch9.h>
29#include <linux/usb/gadget.h>
Michal Sojka0cfbd322014-09-24 22:43:21 +020030#include <linux/usb.h>
Felipe Balbi2ccea032011-06-28 16:33:46 +030031
Felipe Balbi5e42d712016-05-31 13:39:21 +030032#include "trace.h"
33
Felipe Balbi2ccea032011-06-28 16:33:46 +030034/**
35 * struct usb_udc - describes one usb device controller
36 * @driver - the gadget driver pointer. For use by the class code
37 * @dev - the child device to the actual controller
38 * @gadget - the gadget. For use by the class code
39 * @list - for use by the udc class driver
Peter Chen628ef0d2015-03-06 10:36:03 +080040 * @vbus - for udcs who care about vbus status, this value is real vbus status;
41 * for udcs who do not care about vbus status, this value is always true
Felipe Balbi2ccea032011-06-28 16:33:46 +030042 *
43 * This represents the internal data structure which is used by the UDC-class
44 * to hold information about udc driver and gadget together.
45 */
46struct usb_udc {
47 struct usb_gadget_driver *driver;
48 struct usb_gadget *gadget;
49 struct device dev;
50 struct list_head list;
Peter Chen628ef0d2015-03-06 10:36:03 +080051 bool vbus;
Felipe Balbi2ccea032011-06-28 16:33:46 +030052};
53
54static struct class *udc_class;
Felipe Balbi2ccea032011-06-28 16:33:46 +030055static LIST_HEAD(udc_list);
Ruslan Bilovol855ed042015-11-23 09:56:38 +010056static LIST_HEAD(gadget_driver_pending_list);
Felipe Balbi2ccea032011-06-28 16:33:46 +030057static DEFINE_MUTEX(udc_lock);
58
Ruslan Bilovol855ed042015-11-23 09:56:38 +010059static int udc_bind_to_driver(struct usb_udc *udc,
60 struct usb_gadget_driver *driver);
61
Felipe Balbi2ccea032011-06-28 16:33:46 +030062/* ------------------------------------------------------------------------- */
63
Felipe Balbi5a8d6512016-05-31 13:07:47 +030064/**
65 * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint
66 * @ep:the endpoint being configured
67 * @maxpacket_limit:value of maximum packet size limit
68 *
69 * This function should be used only in UDC drivers to initialize endpoint
70 * (usually in probe function).
71 */
72void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
73 unsigned maxpacket_limit)
74{
75 ep->maxpacket_limit = maxpacket_limit;
76 ep->maxpacket = maxpacket_limit;
Felipe Balbi5e42d712016-05-31 13:39:21 +030077
78 trace_usb_ep_set_maxpacket_limit(ep, 0);
Felipe Balbi5a8d6512016-05-31 13:07:47 +030079}
80EXPORT_SYMBOL_GPL(usb_ep_set_maxpacket_limit);
81
82/**
83 * usb_ep_enable - configure endpoint, making it usable
84 * @ep:the endpoint being configured. may not be the endpoint named "ep0".
85 * drivers discover endpoints through the ep_list of a usb_gadget.
86 *
87 * When configurations are set, or when interface settings change, the driver
88 * will enable or disable the relevant endpoints. while it is enabled, an
89 * endpoint may be used for i/o until the driver receives a disconnect() from
90 * the host or until the endpoint is disabled.
91 *
92 * the ep0 implementation (which calls this routine) must ensure that the
93 * hardware capabilities of each endpoint match the descriptor provided
94 * for it. for example, an endpoint named "ep2in-bulk" would be usable
95 * for interrupt transfers as well as bulk, but it likely couldn't be used
96 * for iso transfers or for endpoint 14. some endpoints are fully
97 * configurable, with more generic names like "ep-a". (remember that for
98 * USB, "in" means "towards the USB master".)
99 *
100 * returns zero, or a negative error code.
101 */
102int usb_ep_enable(struct usb_ep *ep)
103{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300104 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300105
106 if (ep->enabled)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300107 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300108
109 ret = ep->ops->enable(ep, ep->desc);
Colin Ian Kingf510b5a2016-07-25 22:57:36 +0100110 if (ret)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300111 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300112
113 ep->enabled = true;
114
Felipe Balbi5e42d712016-05-31 13:39:21 +0300115out:
116 trace_usb_ep_enable(ep, ret);
117
118 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300119}
120EXPORT_SYMBOL_GPL(usb_ep_enable);
121
122/**
123 * usb_ep_disable - endpoint is no longer usable
124 * @ep:the endpoint being unconfigured. may not be the endpoint named "ep0".
125 *
126 * no other task may be using this endpoint when this is called.
127 * any pending and uncompleted requests will complete with status
128 * indicating disconnect (-ESHUTDOWN) before this call returns.
129 * gadget drivers must call usb_ep_enable() again before queueing
130 * requests to the endpoint.
131 *
132 * returns zero, or a negative error code.
133 */
134int usb_ep_disable(struct usb_ep *ep)
135{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300136 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300137
138 if (!ep->enabled)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300139 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300140
141 ret = ep->ops->disable(ep);
Felipe Balbi5e42d712016-05-31 13:39:21 +0300142 if (ret) {
143 ret = ret;
144 goto out;
145 }
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300146
147 ep->enabled = false;
148
Felipe Balbi5e42d712016-05-31 13:39:21 +0300149out:
150 trace_usb_ep_disable(ep, ret);
151
152 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300153}
154EXPORT_SYMBOL_GPL(usb_ep_disable);
155
156/**
157 * usb_ep_alloc_request - allocate a request object to use with this endpoint
158 * @ep:the endpoint to be used with with the request
159 * @gfp_flags:GFP_* flags to use
160 *
161 * Request objects must be allocated with this call, since they normally
162 * need controller-specific setup and may even need endpoint-specific
163 * resources such as allocation of DMA descriptors.
164 * Requests may be submitted with usb_ep_queue(), and receive a single
165 * completion callback. Free requests with usb_ep_free_request(), when
166 * they are no longer needed.
167 *
168 * Returns the request, or null if one could not be allocated.
169 */
170struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
171 gfp_t gfp_flags)
172{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300173 struct usb_request *req = NULL;
174
175 req = ep->ops->alloc_request(ep, gfp_flags);
176
177 trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM);
178
179 return req;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300180}
181EXPORT_SYMBOL_GPL(usb_ep_alloc_request);
182
183/**
184 * usb_ep_free_request - frees a request object
185 * @ep:the endpoint associated with the request
186 * @req:the request being freed
187 *
188 * Reverses the effect of usb_ep_alloc_request().
189 * Caller guarantees the request is not queued, and that it will
190 * no longer be requeued (or otherwise used).
191 */
192void usb_ep_free_request(struct usb_ep *ep,
193 struct usb_request *req)
194{
195 ep->ops->free_request(ep, req);
Felipe Balbi5e42d712016-05-31 13:39:21 +0300196 trace_usb_ep_free_request(ep, req, 0);
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300197}
198EXPORT_SYMBOL_GPL(usb_ep_free_request);
199
200/**
201 * usb_ep_queue - queues (submits) an I/O request to an endpoint.
202 * @ep:the endpoint associated with the request
203 * @req:the request being submitted
204 * @gfp_flags: GFP_* flags to use in case the lower level driver couldn't
205 * pre-allocate all necessary memory with the request.
206 *
207 * This tells the device controller to perform the specified request through
208 * that endpoint (reading or writing a buffer). When the request completes,
209 * including being canceled by usb_ep_dequeue(), the request's completion
210 * routine is called to return the request to the driver. Any endpoint
211 * (except control endpoints like ep0) may have more than one transfer
212 * request queued; they complete in FIFO order. Once a gadget driver
213 * submits a request, that request may not be examined or modified until it
214 * is given back to that driver through the completion callback.
215 *
216 * Each request is turned into one or more packets. The controller driver
217 * never merges adjacent requests into the same packet. OUT transfers
218 * will sometimes use data that's already buffered in the hardware.
219 * Drivers can rely on the fact that the first byte of the request's buffer
220 * always corresponds to the first byte of some USB packet, for both
221 * IN and OUT transfers.
222 *
223 * Bulk endpoints can queue any amount of data; the transfer is packetized
224 * automatically. The last packet will be short if the request doesn't fill it
225 * out completely. Zero length packets (ZLPs) should be avoided in portable
226 * protocols since not all usb hardware can successfully handle zero length
227 * packets. (ZLPs may be explicitly written, and may be implicitly written if
228 * the request 'zero' flag is set.) Bulk endpoints may also be used
229 * for interrupt transfers; but the reverse is not true, and some endpoints
230 * won't support every interrupt transfer. (Such as 768 byte packets.)
231 *
232 * Interrupt-only endpoints are less functional than bulk endpoints, for
233 * example by not supporting queueing or not handling buffers that are
234 * larger than the endpoint's maxpacket size. They may also treat data
235 * toggle differently.
236 *
237 * Control endpoints ... after getting a setup() callback, the driver queues
238 * one response (even if it would be zero length). That enables the
239 * status ack, after transferring data as specified in the response. Setup
240 * functions may return negative error codes to generate protocol stalls.
241 * (Note that some USB device controllers disallow protocol stall responses
242 * in some cases.) When control responses are deferred (the response is
243 * written after the setup callback returns), then usb_ep_set_halt() may be
244 * used on ep0 to trigger protocol stalls. Depending on the controller,
245 * it may not be possible to trigger a status-stage protocol stall when the
246 * data stage is over, that is, from within the response's completion
247 * routine.
248 *
249 * For periodic endpoints, like interrupt or isochronous ones, the usb host
250 * arranges to poll once per interval, and the gadget driver usually will
251 * have queued some data to transfer at that time.
252 *
253 * Returns zero, or a negative error code. Endpoints that are not enabled
254 * report errors; errors will also be
255 * reported when the usb peripheral is disconnected.
256 */
257int usb_ep_queue(struct usb_ep *ep,
258 struct usb_request *req, gfp_t gfp_flags)
259{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300260 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300261
Felipe Balbi5e42d712016-05-31 13:39:21 +0300262 if (WARN_ON_ONCE(!ep->enabled && ep->address)) {
263 ret = -ESHUTDOWN;
264 goto out;
265 }
266
267 ret = ep->ops->queue(ep, req, gfp_flags);
268
269out:
270 trace_usb_ep_queue(ep, req, ret);
271
272 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300273}
274EXPORT_SYMBOL_GPL(usb_ep_queue);
275
276/**
277 * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint
278 * @ep:the endpoint associated with the request
279 * @req:the request being canceled
280 *
281 * If the request is still active on the endpoint, it is dequeued and its
282 * completion routine is called (with status -ECONNRESET); else a negative
283 * error code is returned. This is guaranteed to happen before the call to
284 * usb_ep_dequeue() returns.
285 *
286 * Note that some hardware can't clear out write fifos (to unlink the request
287 * at the head of the queue) except as part of disconnecting from usb. Such
288 * restrictions prevent drivers from supporting configuration changes,
289 * even to configuration zero (a "chapter 9" requirement).
290 */
291int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
292{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300293 int ret;
294
295 ret = ep->ops->dequeue(ep, req);
296 trace_usb_ep_dequeue(ep, req, ret);
297
298 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300299}
300EXPORT_SYMBOL_GPL(usb_ep_dequeue);
301
302/**
303 * usb_ep_set_halt - sets the endpoint halt feature.
304 * @ep: the non-isochronous endpoint being stalled
305 *
306 * Use this to stall an endpoint, perhaps as an error report.
307 * Except for control endpoints,
308 * the endpoint stays halted (will not stream any data) until the host
309 * clears this feature; drivers may need to empty the endpoint's request
310 * queue first, to make sure no inappropriate transfers happen.
311 *
312 * Note that while an endpoint CLEAR_FEATURE will be invisible to the
313 * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the
314 * current altsetting, see usb_ep_clear_halt(). When switching altsettings,
315 * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints.
316 *
317 * Returns zero, or a negative error code. On success, this call sets
318 * underlying hardware state that blocks data transfers.
319 * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any
320 * transfer requests are still queued, or if the controller hardware
321 * (usually a FIFO) still holds bytes that the host hasn't collected.
322 */
323int usb_ep_set_halt(struct usb_ep *ep)
324{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300325 int ret;
326
327 ret = ep->ops->set_halt(ep, 1);
328 trace_usb_ep_set_halt(ep, ret);
329
330 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300331}
332EXPORT_SYMBOL_GPL(usb_ep_set_halt);
333
334/**
335 * usb_ep_clear_halt - clears endpoint halt, and resets toggle
336 * @ep:the bulk or interrupt endpoint being reset
337 *
338 * Use this when responding to the standard usb "set interface" request,
339 * for endpoints that aren't reconfigured, after clearing any other state
340 * in the endpoint's i/o queue.
341 *
342 * Returns zero, or a negative error code. On success, this call clears
343 * the underlying hardware state reflecting endpoint halt and data toggle.
344 * Note that some hardware can't support this request (like pxa2xx_udc),
345 * and accordingly can't correctly implement interface altsettings.
346 */
347int usb_ep_clear_halt(struct usb_ep *ep)
348{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300349 int ret;
350
351 ret = ep->ops->set_halt(ep, 0);
352 trace_usb_ep_clear_halt(ep, ret);
353
354 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300355}
356EXPORT_SYMBOL_GPL(usb_ep_clear_halt);
357
358/**
359 * usb_ep_set_wedge - sets the halt feature and ignores clear requests
360 * @ep: the endpoint being wedged
361 *
362 * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
363 * requests. If the gadget driver clears the halt status, it will
364 * automatically unwedge the endpoint.
365 *
366 * Returns zero on success, else negative errno.
367 */
368int usb_ep_set_wedge(struct usb_ep *ep)
369{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300370 int ret;
371
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300372 if (ep->ops->set_wedge)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300373 ret = ep->ops->set_wedge(ep);
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300374 else
Felipe Balbi5e42d712016-05-31 13:39:21 +0300375 ret = ep->ops->set_halt(ep, 1);
376
377 trace_usb_ep_set_wedge(ep, ret);
378
379 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300380}
381EXPORT_SYMBOL_GPL(usb_ep_set_wedge);
382
383/**
384 * usb_ep_fifo_status - returns number of bytes in fifo, or error
385 * @ep: the endpoint whose fifo status is being checked.
386 *
387 * FIFO endpoints may have "unclaimed data" in them in certain cases,
388 * such as after aborted transfers. Hosts may not have collected all
389 * the IN data written by the gadget driver (and reported by a request
390 * completion). The gadget driver may not have collected all the data
391 * written OUT to it by the host. Drivers that need precise handling for
392 * fault reporting or recovery may need to use this call.
393 *
394 * This returns the number of such bytes in the fifo, or a negative
395 * errno if the endpoint doesn't use a FIFO or doesn't support such
396 * precise handling.
397 */
398int usb_ep_fifo_status(struct usb_ep *ep)
399{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300400 int ret;
401
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300402 if (ep->ops->fifo_status)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300403 ret = ep->ops->fifo_status(ep);
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300404 else
Felipe Balbi5e42d712016-05-31 13:39:21 +0300405 ret = -EOPNOTSUPP;
406
407 trace_usb_ep_fifo_status(ep, ret);
408
409 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300410}
411EXPORT_SYMBOL_GPL(usb_ep_fifo_status);
412
413/**
414 * usb_ep_fifo_flush - flushes contents of a fifo
415 * @ep: the endpoint whose fifo is being flushed.
416 *
417 * This call may be used to flush the "unclaimed data" that may exist in
418 * an endpoint fifo after abnormal transaction terminations. The call
419 * must never be used except when endpoint is not being used for any
420 * protocol translation.
421 */
422void usb_ep_fifo_flush(struct usb_ep *ep)
423{
424 if (ep->ops->fifo_flush)
425 ep->ops->fifo_flush(ep);
Felipe Balbi5e42d712016-05-31 13:39:21 +0300426
427 trace_usb_ep_fifo_flush(ep, 0);
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300428}
429EXPORT_SYMBOL_GPL(usb_ep_fifo_flush);
430
431/* ------------------------------------------------------------------------- */
432
433/**
434 * usb_gadget_frame_number - returns the current frame number
435 * @gadget: controller that reports the frame number
436 *
437 * Returns the usb frame number, normally eleven bits from a SOF packet,
438 * or negative errno if this device doesn't support this capability.
439 */
440int usb_gadget_frame_number(struct usb_gadget *gadget)
441{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300442 int ret;
443
444 ret = gadget->ops->get_frame(gadget);
445
446 trace_usb_gadget_frame_number(gadget, ret);
447
448 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300449}
450EXPORT_SYMBOL_GPL(usb_gadget_frame_number);
451
452/**
453 * usb_gadget_wakeup - tries to wake up the host connected to this gadget
454 * @gadget: controller used to wake up the host
455 *
456 * Returns zero on success, else negative error code if the hardware
457 * doesn't support such attempts, or its support has not been enabled
458 * by the usb host. Drivers must return device descriptors that report
459 * their ability to support this, or hosts won't enable it.
460 *
461 * This may also try to use SRP to wake the host and start enumeration,
462 * even if OTG isn't otherwise in use. OTG devices may also start
463 * remote wakeup even when hosts don't explicitly enable it.
464 */
465int usb_gadget_wakeup(struct usb_gadget *gadget)
466{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300467 int ret = 0;
468
469 if (!gadget->ops->wakeup) {
470 ret = -EOPNOTSUPP;
471 goto out;
472 }
473
474 ret = gadget->ops->wakeup(gadget);
475
476out:
477 trace_usb_gadget_wakeup(gadget, ret);
478
479 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300480}
481EXPORT_SYMBOL_GPL(usb_gadget_wakeup);
482
483/**
484 * usb_gadget_set_selfpowered - sets the device selfpowered feature.
485 * @gadget:the device being declared as self-powered
486 *
487 * this affects the device status reported by the hardware driver
488 * to reflect that it now has a local power supply.
489 *
490 * returns zero on success, else negative errno.
491 */
492int usb_gadget_set_selfpowered(struct usb_gadget *gadget)
493{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300494 int ret = 0;
495
496 if (!gadget->ops->set_selfpowered) {
497 ret = -EOPNOTSUPP;
498 goto out;
499 }
500
501 ret = gadget->ops->set_selfpowered(gadget, 1);
502
503out:
504 trace_usb_gadget_set_selfpowered(gadget, ret);
505
506 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300507}
508EXPORT_SYMBOL_GPL(usb_gadget_set_selfpowered);
509
510/**
511 * usb_gadget_clear_selfpowered - clear the device selfpowered feature.
512 * @gadget:the device being declared as bus-powered
513 *
514 * this affects the device status reported by the hardware driver.
515 * some hardware may not support bus-powered operation, in which
516 * case this feature's value can never change.
517 *
518 * returns zero on success, else negative errno.
519 */
520int usb_gadget_clear_selfpowered(struct usb_gadget *gadget)
521{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300522 int ret = 0;
523
524 if (!gadget->ops->set_selfpowered) {
525 ret = -EOPNOTSUPP;
526 goto out;
527 }
528
529 ret = gadget->ops->set_selfpowered(gadget, 0);
530
531out:
532 trace_usb_gadget_clear_selfpowered(gadget, ret);
533
534 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300535}
536EXPORT_SYMBOL_GPL(usb_gadget_clear_selfpowered);
537
538/**
539 * usb_gadget_vbus_connect - Notify controller that VBUS is powered
540 * @gadget:The device which now has VBUS power.
541 * Context: can sleep
542 *
543 * This call is used by a driver for an external transceiver (or GPIO)
544 * that detects a VBUS power session starting. Common responses include
545 * resuming the controller, activating the D+ (or D-) pullup to let the
546 * host detect that a USB device is attached, and starting to draw power
547 * (8mA or possibly more, especially after SET_CONFIGURATION).
548 *
549 * Returns zero on success, else negative errno.
550 */
551int usb_gadget_vbus_connect(struct usb_gadget *gadget)
552{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300553 int ret = 0;
554
555 if (!gadget->ops->vbus_session) {
556 ret = -EOPNOTSUPP;
557 goto out;
558 }
559
560 ret = gadget->ops->vbus_session(gadget, 1);
561
562out:
563 trace_usb_gadget_vbus_connect(gadget, ret);
564
565 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300566}
567EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect);
568
569/**
570 * usb_gadget_vbus_draw - constrain controller's VBUS power usage
571 * @gadget:The device whose VBUS usage is being described
572 * @mA:How much current to draw, in milliAmperes. This should be twice
573 * the value listed in the configuration descriptor bMaxPower field.
574 *
575 * This call is used by gadget drivers during SET_CONFIGURATION calls,
576 * reporting how much power the device may consume. For example, this
577 * could affect how quickly batteries are recharged.
578 *
579 * Returns zero on success, else negative errno.
580 */
581int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
582{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300583 int ret = 0;
584
585 if (!gadget->ops->vbus_draw) {
586 ret = -EOPNOTSUPP;
587 goto out;
588 }
589
590 ret = gadget->ops->vbus_draw(gadget, mA);
591 if (!ret)
592 gadget->mA = mA;
593
594out:
595 trace_usb_gadget_vbus_draw(gadget, ret);
596
597 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300598}
599EXPORT_SYMBOL_GPL(usb_gadget_vbus_draw);
600
601/**
602 * usb_gadget_vbus_disconnect - notify controller about VBUS session end
603 * @gadget:the device whose VBUS supply is being described
604 * Context: can sleep
605 *
606 * This call is used by a driver for an external transceiver (or GPIO)
607 * that detects a VBUS power session ending. Common responses include
608 * reversing everything done in usb_gadget_vbus_connect().
609 *
610 * Returns zero on success, else negative errno.
611 */
612int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
613{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300614 int ret = 0;
615
616 if (!gadget->ops->vbus_session) {
617 ret = -EOPNOTSUPP;
618 goto out;
619 }
620
621 ret = gadget->ops->vbus_session(gadget, 0);
622
623out:
624 trace_usb_gadget_vbus_disconnect(gadget, ret);
625
626 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300627}
628EXPORT_SYMBOL_GPL(usb_gadget_vbus_disconnect);
629
630/**
631 * usb_gadget_connect - software-controlled connect to USB host
632 * @gadget:the peripheral being connected
633 *
634 * Enables the D+ (or potentially D-) pullup. The host will start
635 * enumerating this gadget when the pullup is active and a VBUS session
636 * is active (the link is powered). This pullup is always enabled unless
637 * usb_gadget_disconnect() has been used to disable it.
638 *
639 * Returns zero on success, else negative errno.
640 */
641int usb_gadget_connect(struct usb_gadget *gadget)
642{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300643 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300644
Felipe Balbi5e42d712016-05-31 13:39:21 +0300645 if (!gadget->ops->pullup) {
646 ret = -EOPNOTSUPP;
647 goto out;
648 }
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300649
650 if (gadget->deactivated) {
651 /*
652 * If gadget is deactivated we only save new state.
653 * Gadget will be connected automatically after activation.
654 */
655 gadget->connected = true;
Felipe Balbi5e42d712016-05-31 13:39:21 +0300656 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300657 }
658
659 ret = gadget->ops->pullup(gadget, 1);
660 if (!ret)
661 gadget->connected = 1;
Felipe Balbi5e42d712016-05-31 13:39:21 +0300662
663out:
664 trace_usb_gadget_connect(gadget, ret);
665
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300666 return ret;
667}
668EXPORT_SYMBOL_GPL(usb_gadget_connect);
669
670/**
671 * usb_gadget_disconnect - software-controlled disconnect from USB host
672 * @gadget:the peripheral being disconnected
673 *
674 * Disables the D+ (or potentially D-) pullup, which the host may see
675 * as a disconnect (when a VBUS session is active). Not all systems
676 * support software pullup controls.
677 *
678 * Returns zero on success, else negative errno.
679 */
680int usb_gadget_disconnect(struct usb_gadget *gadget)
681{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300682 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300683
Felipe Balbi5e42d712016-05-31 13:39:21 +0300684 if (!gadget->ops->pullup) {
685 ret = -EOPNOTSUPP;
686 goto out;
687 }
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300688
689 if (gadget->deactivated) {
690 /*
691 * If gadget is deactivated we only save new state.
692 * Gadget will stay disconnected after activation.
693 */
694 gadget->connected = false;
Felipe Balbi5e42d712016-05-31 13:39:21 +0300695 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300696 }
697
698 ret = gadget->ops->pullup(gadget, 0);
699 if (!ret)
700 gadget->connected = 0;
Felipe Balbi5e42d712016-05-31 13:39:21 +0300701
702out:
703 trace_usb_gadget_disconnect(gadget, ret);
704
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300705 return ret;
706}
707EXPORT_SYMBOL_GPL(usb_gadget_disconnect);
708
709/**
710 * usb_gadget_deactivate - deactivate function which is not ready to work
711 * @gadget: the peripheral being deactivated
712 *
713 * This routine may be used during the gadget driver bind() call to prevent
714 * the peripheral from ever being visible to the USB host, unless later
715 * usb_gadget_activate() is called. For example, user mode components may
716 * need to be activated before the system can talk to hosts.
717 *
718 * Returns zero on success, else negative errno.
719 */
720int usb_gadget_deactivate(struct usb_gadget *gadget)
721{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300722 int ret = 0;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300723
724 if (gadget->deactivated)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300725 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300726
727 if (gadget->connected) {
728 ret = usb_gadget_disconnect(gadget);
729 if (ret)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300730 goto out;
731
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300732 /*
733 * If gadget was being connected before deactivation, we want
734 * to reconnect it in usb_gadget_activate().
735 */
736 gadget->connected = true;
737 }
738 gadget->deactivated = true;
739
Felipe Balbi5e42d712016-05-31 13:39:21 +0300740out:
741 trace_usb_gadget_deactivate(gadget, ret);
742
743 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300744}
745EXPORT_SYMBOL_GPL(usb_gadget_deactivate);
746
747/**
748 * usb_gadget_activate - activate function which is not ready to work
749 * @gadget: the peripheral being activated
750 *
751 * This routine activates gadget which was previously deactivated with
752 * usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed.
753 *
754 * Returns zero on success, else negative errno.
755 */
756int usb_gadget_activate(struct usb_gadget *gadget)
757{
Felipe Balbi5e42d712016-05-31 13:39:21 +0300758 int ret = 0;
759
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300760 if (!gadget->deactivated)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300761 goto out;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300762
763 gadget->deactivated = false;
764
765 /*
766 * If gadget has been connected before deactivation, or became connected
767 * while it was being deactivated, we call usb_gadget_connect().
768 */
769 if (gadget->connected)
Felipe Balbi5e42d712016-05-31 13:39:21 +0300770 ret = usb_gadget_connect(gadget);
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300771
Felipe Balbi5e42d712016-05-31 13:39:21 +0300772out:
773 trace_usb_gadget_activate(gadget, ret);
774
775 return ret;
Felipe Balbi5a8d6512016-05-31 13:07:47 +0300776}
777EXPORT_SYMBOL_GPL(usb_gadget_activate);
778
779/* ------------------------------------------------------------------------- */
780
Alan Stern908b9612013-07-12 11:06:21 -0400781#ifdef CONFIG_HAS_DMA
782
Yoshihiro Shimoda679ca392016-04-18 16:53:39 +0900783int usb_gadget_map_request_by_dev(struct device *dev,
Felipe Balbia6989082011-12-15 13:31:48 +0200784 struct usb_request *req, int is_in)
785{
786 if (req->length == 0)
787 return 0;
788
789 if (req->num_sgs) {
790 int mapped;
791
Yoshihiro Shimoda7ace8fc2015-07-13 18:10:05 +0900792 mapped = dma_map_sg(dev, req->sg, req->num_sgs,
Felipe Balbia6989082011-12-15 13:31:48 +0200793 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
794 if (mapped == 0) {
Yoshihiro Shimoda5096c4d2016-04-18 16:53:38 +0900795 dev_err(dev, "failed to map SGs\n");
Felipe Balbia6989082011-12-15 13:31:48 +0200796 return -EFAULT;
797 }
798
799 req->num_mapped_sgs = mapped;
800 } else {
Yoshihiro Shimoda7ace8fc2015-07-13 18:10:05 +0900801 req->dma = dma_map_single(dev, req->buf, req->length,
Felipe Balbia6989082011-12-15 13:31:48 +0200802 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
803
Yoshihiro Shimoda7ace8fc2015-07-13 18:10:05 +0900804 if (dma_mapping_error(dev, req->dma)) {
805 dev_err(dev, "failed to map buffer\n");
Felipe Balbia6989082011-12-15 13:31:48 +0200806 return -EFAULT;
807 }
808 }
809
810 return 0;
811}
Yoshihiro Shimoda679ca392016-04-18 16:53:39 +0900812EXPORT_SYMBOL_GPL(usb_gadget_map_request_by_dev);
813
814int usb_gadget_map_request(struct usb_gadget *gadget,
815 struct usb_request *req, int is_in)
816{
817 return usb_gadget_map_request_by_dev(gadget->dev.parent, req, is_in);
818}
Felipe Balbia6989082011-12-15 13:31:48 +0200819EXPORT_SYMBOL_GPL(usb_gadget_map_request);
820
Yoshihiro Shimoda679ca392016-04-18 16:53:39 +0900821void usb_gadget_unmap_request_by_dev(struct device *dev,
Felipe Balbia6989082011-12-15 13:31:48 +0200822 struct usb_request *req, int is_in)
823{
824 if (req->length == 0)
825 return;
826
827 if (req->num_mapped_sgs) {
Felipe Balbi23fd5372016-08-24 14:33:27 +0300828 dma_unmap_sg(dev, req->sg, req->num_sgs,
Felipe Balbia6989082011-12-15 13:31:48 +0200829 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
830
831 req->num_mapped_sgs = 0;
832 } else {
Yoshihiro Shimoda679ca392016-04-18 16:53:39 +0900833 dma_unmap_single(dev, req->dma, req->length,
Felipe Balbia6989082011-12-15 13:31:48 +0200834 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
835 }
836}
Yoshihiro Shimoda679ca392016-04-18 16:53:39 +0900837EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev);
838
839void usb_gadget_unmap_request(struct usb_gadget *gadget,
840 struct usb_request *req, int is_in)
841{
842 usb_gadget_unmap_request_by_dev(gadget->dev.parent, req, is_in);
843}
Felipe Balbia6989082011-12-15 13:31:48 +0200844EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
845
Alan Stern908b9612013-07-12 11:06:21 -0400846#endif /* CONFIG_HAS_DMA */
847
Felipe Balbia6989082011-12-15 13:31:48 +0200848/* ------------------------------------------------------------------------- */
849
Michal Sojka3fc2aa52014-09-24 22:43:18 +0200850/**
851 * usb_gadget_giveback_request - give the request back to the gadget layer
852 * Context: in_interrupt()
853 *
854 * This is called by device controller drivers in order to return the
855 * completed request back to the gadget layer.
856 */
857void usb_gadget_giveback_request(struct usb_ep *ep,
858 struct usb_request *req)
859{
Michal Sojka0cfbd322014-09-24 22:43:21 +0200860 if (likely(req->status == 0))
861 usb_led_activity(USB_LED_EVENT_GADGET);
862
Felipe Balbi5e42d712016-05-31 13:39:21 +0300863 trace_usb_gadget_giveback_request(ep, req, 0);
864
Michal Sojka3fc2aa52014-09-24 22:43:18 +0200865 req->complete(ep, req);
866}
867EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
868
869/* ------------------------------------------------------------------------- */
870
Robert Baldygab0aea002015-08-06 14:11:12 +0200871/**
872 * gadget_find_ep_by_name - returns ep whose name is the same as sting passed
873 * in second parameter or NULL if searched endpoint not found
874 * @g: controller to check for quirk
875 * @name: name of searched endpoint
876 */
877struct usb_ep *gadget_find_ep_by_name(struct usb_gadget *g, const char *name)
878{
879 struct usb_ep *ep;
880
881 gadget_for_each_ep(ep, g) {
882 if (!strcmp(ep->name, name))
883 return ep;
884 }
885
886 return NULL;
887}
888EXPORT_SYMBOL_GPL(gadget_find_ep_by_name);
889
890/* ------------------------------------------------------------------------- */
891
Robert Baldyga4278c682015-08-06 14:11:11 +0200892int usb_gadget_ep_match_desc(struct usb_gadget *gadget,
893 struct usb_ep *ep, struct usb_endpoint_descriptor *desc,
894 struct usb_ss_ep_comp_descriptor *ep_comp)
895{
896 u8 type;
897 u16 max;
898 int num_req_streams = 0;
899
900 /* endpoint already claimed? */
901 if (ep->claimed)
902 return 0;
903
904 type = usb_endpoint_type(desc);
905 max = 0x7ff & usb_endpoint_maxp(desc);
906
907 if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
908 return 0;
909 if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
910 return 0;
911
912 if (max > ep->maxpacket_limit)
913 return 0;
914
915 /* "high bandwidth" works only at high speed */
916 if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
917 return 0;
918
919 switch (type) {
920 case USB_ENDPOINT_XFER_CONTROL:
921 /* only support ep0 for portable CONTROL traffic */
922 return 0;
923 case USB_ENDPOINT_XFER_ISOC:
924 if (!ep->caps.type_iso)
925 return 0;
926 /* ISO: limit 1023 bytes full speed, 1024 high/super speed */
927 if (!gadget_is_dualspeed(gadget) && max > 1023)
928 return 0;
929 break;
930 case USB_ENDPOINT_XFER_BULK:
931 if (!ep->caps.type_bulk)
932 return 0;
933 if (ep_comp && gadget_is_superspeed(gadget)) {
934 /* Get the number of required streams from the
935 * EP companion descriptor and see if the EP
936 * matches it
937 */
938 num_req_streams = ep_comp->bmAttributes & 0x1f;
939 if (num_req_streams > ep->max_streams)
940 return 0;
941 }
942 break;
943 case USB_ENDPOINT_XFER_INT:
944 /* Bulk endpoints handle interrupt transfers,
945 * except the toggle-quirky iso-synch kind
946 */
947 if (!ep->caps.type_int && !ep->caps.type_bulk)
948 return 0;
949 /* INT: limit 64 bytes full speed, 1024 high/super speed */
950 if (!gadget_is_dualspeed(gadget) && max > 64)
951 return 0;
952 break;
953 }
954
955 return 1;
956}
957EXPORT_SYMBOL_GPL(usb_gadget_ep_match_desc);
958
959/* ------------------------------------------------------------------------- */
960
Felipe Balbi5702f752013-07-17 11:09:49 +0300961static void usb_gadget_state_work(struct work_struct *work)
962{
Peter Chendfea9c92015-03-06 10:36:02 +0800963 struct usb_gadget *gadget = work_to_gadget(work);
964 struct usb_udc *udc = gadget->udc;
Felipe Balbi5702f752013-07-17 11:09:49 +0300965
Peter Chendfea9c92015-03-06 10:36:02 +0800966 if (udc)
967 sysfs_notify(&udc->dev.kobj, NULL, "state");
Felipe Balbi5702f752013-07-17 11:09:49 +0300968}
969
Felipe Balbi49401f42011-12-19 12:57:04 +0200970void usb_gadget_set_state(struct usb_gadget *gadget,
971 enum usb_device_state state)
972{
973 gadget->state = state;
Felipe Balbi5702f752013-07-17 11:09:49 +0300974 schedule_work(&gadget->work);
Felipe Balbi49401f42011-12-19 12:57:04 +0200975}
976EXPORT_SYMBOL_GPL(usb_gadget_set_state);
977
978/* ------------------------------------------------------------------------- */
979
Peter Chen628ef0d2015-03-06 10:36:03 +0800980static void usb_udc_connect_control(struct usb_udc *udc)
981{
982 if (udc->vbus)
983 usb_gadget_connect(udc->gadget);
984 else
985 usb_gadget_disconnect(udc->gadget);
986}
987
988/**
989 * usb_udc_vbus_handler - updates the udc core vbus status, and try to
990 * connect or disconnect gadget
991 * @gadget: The gadget which vbus change occurs
992 * @status: The vbus status
993 *
994 * The udc driver calls it when it wants to connect or disconnect gadget
995 * according to vbus status.
996 */
997void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status)
998{
999 struct usb_udc *udc = gadget->udc;
1000
1001 if (udc) {
1002 udc->vbus = status;
1003 usb_udc_connect_control(udc);
1004 }
1005}
1006EXPORT_SYMBOL_GPL(usb_udc_vbus_handler);
1007
Felipe Balbi2ccea032011-06-28 16:33:46 +03001008/**
Peter Chen974a70b2014-09-12 09:32:41 +08001009 * usb_gadget_udc_reset - notifies the udc core that bus reset occurs
1010 * @gadget: The gadget which bus reset occurs
1011 * @driver: The gadget driver we want to notify
1012 *
1013 * If the udc driver has bus reset handler, it needs to call this when the bus
1014 * reset occurs, it notifies the gadget driver that the bus reset occurs as
1015 * well as updates gadget state.
1016 */
1017void usb_gadget_udc_reset(struct usb_gadget *gadget,
1018 struct usb_gadget_driver *driver)
1019{
1020 driver->reset(gadget);
1021 usb_gadget_set_state(gadget, USB_STATE_DEFAULT);
1022}
1023EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
1024
1025/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001026 * usb_gadget_udc_start - tells usb device controller to start up
Felipe Balbi2c683342014-10-17 11:34:07 -05001027 * @udc: The UDC to be started
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001028 *
1029 * This call is issued by the UDC Class driver when it's about
1030 * to register a gadget driver to the device controller, before
1031 * calling gadget driver's bind() method.
1032 *
1033 * It allows the controller to be powered off until strictly
1034 * necessary to have it powered on.
1035 *
1036 * Returns zero on success, else negative errno.
1037 */
Felipe Balbi2c683342014-10-17 11:34:07 -05001038static inline int usb_gadget_udc_start(struct usb_udc *udc)
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001039{
Felipe Balbi2c683342014-10-17 11:34:07 -05001040 return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001041}
1042
1043/**
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001044 * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
1045 * @gadget: The device we want to stop activity
1046 * @driver: The driver to unbind from @gadget
1047 *
1048 * This call is issued by the UDC Class driver after calling
1049 * gadget driver's unbind() method.
1050 *
1051 * The details are implementation specific, but it can go as
1052 * far as powering off UDC completely and disable its data
1053 * line pullups.
1054 */
Felipe Balbi2c683342014-10-17 11:34:07 -05001055static inline void usb_gadget_udc_stop(struct usb_udc *udc)
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001056{
Felipe Balbi22835b82014-10-17 12:05:12 -05001057 udc->gadget->ops->udc_stop(udc->gadget);
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001058}
1059
1060/**
Felipe Balbi2ccea032011-06-28 16:33:46 +03001061 * usb_udc_release - release the usb_udc struct
1062 * @dev: the dev member within usb_udc
1063 *
1064 * This is called by driver's core in order to free memory once the last
1065 * reference is released.
1066 */
1067static void usb_udc_release(struct device *dev)
1068{
1069 struct usb_udc *udc;
1070
1071 udc = container_of(dev, struct usb_udc, dev);
1072 dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
1073 kfree(udc);
1074}
1075
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +02001076static const struct attribute_group *usb_udc_attr_groups[];
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001077
1078static void usb_udc_nop_release(struct device *dev)
1079{
1080 dev_vdbg(dev, "%s\n", __func__);
1081}
1082
Felipe Balbi2ccea032011-06-28 16:33:46 +03001083/**
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001084 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
1085 * @parent: the parent device to this udc. Usually the controller driver's
1086 * device.
1087 * @gadget: the gadget to be added to the list.
1088 * @release: a gadget release function.
Felipe Balbi2ccea032011-06-28 16:33:46 +03001089 *
1090 * Returns zero on success, negative errno otherwise.
1091 */
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001092int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1093 void (*release)(struct device *dev))
Felipe Balbi2ccea032011-06-28 16:33:46 +03001094{
1095 struct usb_udc *udc;
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001096 struct usb_gadget_driver *driver;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001097 int ret = -ENOMEM;
1098
1099 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
1100 if (!udc)
1101 goto err1;
1102
Felipe Balbi7bce4012013-01-24 17:41:00 +02001103 dev_set_name(&gadget->dev, "gadget");
Felipe Balbi5702f752013-07-17 11:09:49 +03001104 INIT_WORK(&gadget->work, usb_gadget_state_work);
Felipe Balbi2ed14322013-02-26 10:59:41 +02001105 gadget->dev.parent = parent;
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001106
Felipe Balbiddf47cc2013-02-26 15:25:41 +02001107 if (release)
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001108 gadget->dev.release = release;
Felipe Balbiddf47cc2013-02-26 15:25:41 +02001109 else
1110 gadget->dev.release = usb_udc_nop_release;
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001111
Felipe Balbi7bce4012013-01-24 17:41:00 +02001112 ret = device_register(&gadget->dev);
1113 if (ret)
1114 goto err2;
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001115
Felipe Balbi2ccea032011-06-28 16:33:46 +03001116 device_initialize(&udc->dev);
1117 udc->dev.release = usb_udc_release;
1118 udc->dev.class = udc_class;
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +02001119 udc->dev.groups = usb_udc_attr_groups;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001120 udc->dev.parent = parent;
1121 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
1122 if (ret)
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001123 goto err3;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001124
1125 udc->gadget = gadget;
Peter Chendfea9c92015-03-06 10:36:02 +08001126 gadget->udc = udc;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001127
1128 mutex_lock(&udc_lock);
1129 list_add_tail(&udc->list, &udc_list);
1130
1131 ret = device_add(&udc->dev);
1132 if (ret)
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001133 goto err4;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001134
Felipe Balbi49401f42011-12-19 12:57:04 +02001135 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
Peter Chen628ef0d2015-03-06 10:36:03 +08001136 udc->vbus = true;
Felipe Balbi49401f42011-12-19 12:57:04 +02001137
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001138 /* pick up one of pending gadget drivers */
1139 list_for_each_entry(driver, &gadget_driver_pending_list, pending) {
1140 if (!driver->udc_name || strcmp(driver->udc_name,
1141 dev_name(&udc->dev)) == 0) {
1142 ret = udc_bind_to_driver(udc, driver);
Marek Szyprowski31b994a2016-02-08 13:42:14 +01001143 if (ret != -EPROBE_DEFER)
1144 list_del(&driver->pending);
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001145 if (ret)
Peter Chen17a1dc52016-07-11 09:58:16 +08001146 goto err5;
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001147 break;
1148 }
1149 }
1150
Felipe Balbi2ccea032011-06-28 16:33:46 +03001151 mutex_unlock(&udc_lock);
1152
1153 return 0;
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001154
Peter Chen17a1dc52016-07-11 09:58:16 +08001155err5:
1156 device_del(&udc->dev);
1157
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001158err4:
Felipe Balbi2ccea032011-06-28 16:33:46 +03001159 list_del(&udc->list);
1160 mutex_unlock(&udc_lock);
1161
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001162err3:
Felipe Balbi2ccea032011-06-28 16:33:46 +03001163 put_device(&udc->dev);
Alan Sternc93e64e2015-01-16 11:32:51 -05001164 device_del(&gadget->dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001165
Felipe Balbif07bd56b2013-01-24 14:52:24 +02001166err2:
Felipe Balbi7bce4012013-01-24 17:41:00 +02001167 put_device(&gadget->dev);
Felipe Balbic5dbc222013-04-02 17:06:28 +03001168 kfree(udc);
Felipe Balbi7bce4012013-01-24 17:41:00 +02001169
Felipe Balbi2ccea032011-06-28 16:33:46 +03001170err1:
1171 return ret;
1172}
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001173EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
1174
Felipe Balbi2ccea032011-06-28 16:33:46 +03001175/**
Marek Szyprowski175f7122016-02-18 11:34:43 +01001176 * usb_get_gadget_udc_name - get the name of the first UDC controller
1177 * This functions returns the name of the first UDC controller in the system.
1178 * Please note that this interface is usefull only for legacy drivers which
1179 * assume that there is only one UDC controller in the system and they need to
1180 * get its name before initialization. There is no guarantee that the UDC
1181 * of the returned name will be still available, when gadget driver registers
1182 * itself.
1183 *
1184 * Returns pointer to string with UDC controller name on success, NULL
1185 * otherwise. Caller should kfree() returned string.
1186 */
1187char *usb_get_gadget_udc_name(void)
1188{
1189 struct usb_udc *udc;
1190 char *name = NULL;
1191
1192 /* For now we take the first available UDC */
1193 mutex_lock(&udc_lock);
1194 list_for_each_entry(udc, &udc_list, list) {
1195 if (!udc->driver) {
1196 name = kstrdup(udc->gadget->name, GFP_KERNEL);
1197 break;
1198 }
1199 }
1200 mutex_unlock(&udc_lock);
1201 return name;
1202}
1203EXPORT_SYMBOL_GPL(usb_get_gadget_udc_name);
1204
1205/**
Felipe Balbi2ccea032011-06-28 16:33:46 +03001206 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
1207 * @parent: the parent device to this udc. Usually the controller
1208 * driver's device.
1209 * @gadget: the gadget to be added to the list
1210 *
1211 * Returns zero on success, negative errno otherwise.
1212 */
1213int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
1214{
Felipe Balbi792bfcf2013-02-26 14:47:44 +02001215 return usb_add_gadget_udc_release(parent, gadget, NULL);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001216}
1217EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
1218
1219static void usb_gadget_remove_driver(struct usb_udc *udc)
1220{
1221 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
Felipe Balbi8da9fe82014-10-17 11:54:46 -05001222 udc->driver->function);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001223
1224 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
1225
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +02001226 usb_gadget_disconnect(udc->gadget);
1227 udc->driver->disconnect(udc->gadget);
1228 udc->driver->unbind(udc->gadget);
Felipe Balbi2c683342014-10-17 11:34:07 -05001229 usb_gadget_udc_stop(udc);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001230
1231 udc->driver = NULL;
1232 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +02001233 udc->gadget->dev.driver = NULL;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001234}
1235
1236/**
1237 * usb_del_gadget_udc - deletes @udc from udc_list
1238 * @gadget: the gadget to be removed.
1239 *
1240 * This, will call usb_gadget_unregister_driver() if
1241 * the @udc is still busy.
1242 */
1243void usb_del_gadget_udc(struct usb_gadget *gadget)
1244{
Peter Chendfea9c92015-03-06 10:36:02 +08001245 struct usb_udc *udc = gadget->udc;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001246
Peter Chendfea9c92015-03-06 10:36:02 +08001247 if (!udc)
1248 return;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001249
Felipe Balbi2ccea032011-06-28 16:33:46 +03001250 dev_vdbg(gadget->dev.parent, "unregistering gadget\n");
1251
Peter Chendfea9c92015-03-06 10:36:02 +08001252 mutex_lock(&udc_lock);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001253 list_del(&udc->list);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001254
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001255 if (udc->driver) {
1256 struct usb_gadget_driver *driver = udc->driver;
1257
Felipe Balbi2ccea032011-06-28 16:33:46 +03001258 usb_gadget_remove_driver(udc);
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001259 list_add(&driver->pending, &gadget_driver_pending_list);
1260 }
1261 mutex_unlock(&udc_lock);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001262
1263 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
Felipe Balbi5702f752013-07-17 11:09:49 +03001264 flush_work(&gadget->work);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001265 device_unregister(&udc->dev);
Felipe Balbi7bce4012013-01-24 17:41:00 +02001266 device_unregister(&gadget->dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001267}
1268EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
1269
1270/* ------------------------------------------------------------------------- */
1271
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001272static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
Felipe Balbi2ccea032011-06-28 16:33:46 +03001273{
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001274 int ret;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001275
Felipe Balbi2ccea032011-06-28 16:33:46 +03001276 dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
1277 driver->function);
1278
1279 udc->driver = driver;
1280 udc->dev.driver = &driver->driver;
Felipe Balbi70d3a492013-02-26 13:51:24 +02001281 udc->gadget->dev.driver = &driver->driver;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001282
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +02001283 ret = driver->bind(udc->gadget, driver);
1284 if (ret)
1285 goto err1;
Felipe Balbi2c683342014-10-17 11:34:07 -05001286 ret = usb_gadget_udc_start(udc);
Felipe Balbi2d7ebbb2013-01-24 11:00:15 +02001287 if (ret) {
1288 driver->unbind(udc->gadget);
1289 goto err1;
Sebastian Andrzej Siewior352c2dc2011-06-23 14:26:15 +02001290 }
Peter Chen628ef0d2015-03-06 10:36:03 +08001291 usb_udc_connect_control(udc);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001292
1293 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001294 return 0;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001295err1:
Fabio Estevamf8cffc82013-09-28 00:05:34 -03001296 if (ret != -EISNAM)
1297 dev_err(&udc->dev, "failed to start %s: %d\n",
Felipe Balbi2ccea032011-06-28 16:33:46 +03001298 udc->driver->function, ret);
1299 udc->driver = NULL;
1300 udc->dev.driver = NULL;
Felipe Balbi70d3a492013-02-26 13:51:24 +02001301 udc->gadget->dev.driver = NULL;
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001302 return ret;
1303}
1304
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001305int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
1306{
1307 struct usb_udc *udc = NULL;
Ruslan Bilovol2284b292015-11-23 09:56:35 +01001308 int ret = -ENODEV;
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001309
1310 if (!driver || !driver->bind || !driver->setup)
1311 return -EINVAL;
1312
1313 mutex_lock(&udc_lock);
Ruslan Bilovol2284b292015-11-23 09:56:35 +01001314 if (driver->udc_name) {
1315 list_for_each_entry(udc, &udc_list, list) {
1316 ret = strcmp(driver->udc_name, dev_name(&udc->dev));
1317 if (!ret)
1318 break;
1319 }
Felix Hädicke64244ed2016-12-29 23:02:11 +01001320 if (ret)
1321 ret = -ENODEV;
1322 else if (udc->driver)
1323 ret = -EBUSY;
1324 else
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001325 goto found;
Ruslan Bilovol2284b292015-11-23 09:56:35 +01001326 } else {
1327 list_for_each_entry(udc, &udc_list, list) {
1328 /* For now we take the first one */
1329 if (!udc->driver)
1330 goto found;
1331 }
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001332 }
1333
Krzysztof Opasiakf1bddbb2016-05-05 10:46:05 +02001334 if (!driver->match_existing_only) {
1335 list_add_tail(&driver->pending, &gadget_driver_pending_list);
1336 pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n",
1337 driver->function);
1338 ret = 0;
1339 }
1340
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001341 mutex_unlock(&udc_lock);
Krzysztof Opasiakf1bddbb2016-05-05 10:46:05 +02001342 return ret;
Sebastian Andrzej Siewior4c49a5f2012-12-23 21:10:19 +01001343found:
1344 ret = udc_bind_to_driver(udc, driver);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001345 mutex_unlock(&udc_lock);
1346 return ret;
1347}
1348EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
1349
1350int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1351{
1352 struct usb_udc *udc = NULL;
1353 int ret = -ENODEV;
1354
1355 if (!driver || !driver->unbind)
1356 return -EINVAL;
1357
1358 mutex_lock(&udc_lock);
1359 list_for_each_entry(udc, &udc_list, list)
1360 if (udc->driver == driver) {
1361 usb_gadget_remove_driver(udc);
Peter Chenb5fb8d02014-04-29 13:26:29 +08001362 usb_gadget_set_state(udc->gadget,
1363 USB_STATE_NOTATTACHED);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001364 ret = 0;
1365 break;
1366 }
1367
Ruslan Bilovol855ed042015-11-23 09:56:38 +01001368 if (ret) {
1369 list_del(&driver->pending);
1370 ret = 0;
1371 }
Felipe Balbi2ccea032011-06-28 16:33:46 +03001372 mutex_unlock(&udc_lock);
1373 return ret;
1374}
1375EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
1376
1377/* ------------------------------------------------------------------------- */
1378
1379static ssize_t usb_udc_srp_store(struct device *dev,
1380 struct device_attribute *attr, const char *buf, size_t n)
1381{
Felipe Balbi1d91a962011-09-08 14:11:17 +03001382 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001383
1384 if (sysfs_streq(buf, "1"))
1385 usb_gadget_wakeup(udc->gadget);
1386
1387 return n;
1388}
1389static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
1390
1391static ssize_t usb_udc_softconn_store(struct device *dev,
1392 struct device_attribute *attr, const char *buf, size_t n)
1393{
Felipe Balbi865569b2011-09-08 14:12:18 +03001394 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001395
Felipe Balbibfa6b182014-10-17 11:10:25 -05001396 if (!udc->driver) {
1397 dev_err(dev, "soft-connect without a gadget driver\n");
1398 return -EOPNOTSUPP;
1399 }
1400
Felipe Balbi2ccea032011-06-28 16:33:46 +03001401 if (sysfs_streq(buf, "connect")) {
Felipe Balbi2c683342014-10-17 11:34:07 -05001402 usb_gadget_udc_start(udc);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001403 usb_gadget_connect(udc->gadget);
1404 } else if (sysfs_streq(buf, "disconnect")) {
Felipe Balbi83a787a2012-04-27 11:02:15 +03001405 usb_gadget_disconnect(udc->gadget);
Felipe Balbi0abd0692014-10-09 10:12:24 -05001406 udc->driver->disconnect(udc->gadget);
Felipe Balbi2c683342014-10-17 11:34:07 -05001407 usb_gadget_udc_stop(udc);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001408 } else {
1409 dev_err(dev, "unsupported command '%s'\n", buf);
1410 return -EINVAL;
1411 }
1412
1413 return n;
1414}
1415static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
1416
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001417static ssize_t state_show(struct device *dev, struct device_attribute *attr,
1418 char *buf)
Felipe Balbi49401f42011-12-19 12:57:04 +02001419{
1420 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
1421 struct usb_gadget *gadget = udc->gadget;
1422
1423 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
1424}
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001425static DEVICE_ATTR_RO(state);
Felipe Balbi49401f42011-12-19 12:57:04 +02001426
Michal Nazarewiczd327ab52011-11-19 18:27:37 +01001427#define USB_UDC_SPEED_ATTR(name, param) \
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001428ssize_t name##_show(struct device *dev, \
Michal Nazarewiczd327ab52011-11-19 18:27:37 +01001429 struct device_attribute *attr, char *buf) \
1430{ \
1431 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
1432 return snprintf(buf, PAGE_SIZE, "%s\n", \
1433 usb_speed_string(udc->gadget->param)); \
1434} \
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001435static DEVICE_ATTR_RO(name)
Michal Nazarewiczd327ab52011-11-19 18:27:37 +01001436
1437static USB_UDC_SPEED_ATTR(current_speed, speed);
1438static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
1439
Felipe Balbi2ccea032011-06-28 16:33:46 +03001440#define USB_UDC_ATTR(name) \
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001441ssize_t name##_show(struct device *dev, \
Felipe Balbi2ccea032011-06-28 16:33:46 +03001442 struct device_attribute *attr, char *buf) \
1443{ \
Sebastian Andrzej Siewior019f9762011-06-23 14:28:38 +02001444 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
Felipe Balbi2ccea032011-06-28 16:33:46 +03001445 struct usb_gadget *gadget = udc->gadget; \
1446 \
1447 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
1448} \
Greg Kroah-Hartmance26bd22013-08-23 16:34:43 -07001449static DEVICE_ATTR_RO(name)
Felipe Balbi2ccea032011-06-28 16:33:46 +03001450
Felipe Balbi2ccea032011-06-28 16:33:46 +03001451static USB_UDC_ATTR(is_otg);
1452static USB_UDC_ATTR(is_a_peripheral);
1453static USB_UDC_ATTR(b_hnp_enable);
1454static USB_UDC_ATTR(a_hnp_support);
1455static USB_UDC_ATTR(a_alt_hnp_support);
Peter Chen3f6dd4f2015-01-28 16:32:42 +08001456static USB_UDC_ATTR(is_selfpowered);
Felipe Balbi2ccea032011-06-28 16:33:46 +03001457
1458static struct attribute *usb_udc_attrs[] = {
1459 &dev_attr_srp.attr,
1460 &dev_attr_soft_connect.attr,
Felipe Balbi49401f42011-12-19 12:57:04 +02001461 &dev_attr_state.attr,
Michal Nazarewiczd327ab52011-11-19 18:27:37 +01001462 &dev_attr_current_speed.attr,
1463 &dev_attr_maximum_speed.attr,
Felipe Balbi2ccea032011-06-28 16:33:46 +03001464
Felipe Balbi2ccea032011-06-28 16:33:46 +03001465 &dev_attr_is_otg.attr,
1466 &dev_attr_is_a_peripheral.attr,
1467 &dev_attr_b_hnp_enable.attr,
1468 &dev_attr_a_hnp_support.attr,
1469 &dev_attr_a_alt_hnp_support.attr,
Peter Chen3f6dd4f2015-01-28 16:32:42 +08001470 &dev_attr_is_selfpowered.attr,
Felipe Balbi2ccea032011-06-28 16:33:46 +03001471 NULL,
1472};
1473
1474static const struct attribute_group usb_udc_attr_group = {
1475 .attrs = usb_udc_attrs,
1476};
1477
1478static const struct attribute_group *usb_udc_attr_groups[] = {
1479 &usb_udc_attr_group,
1480 NULL,
1481};
1482
1483static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
1484{
1485 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
1486 int ret;
1487
1488 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
1489 if (ret) {
1490 dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
1491 return ret;
1492 }
1493
1494 if (udc->driver) {
1495 ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
1496 udc->driver->function);
1497 if (ret) {
1498 dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
1499 return ret;
1500 }
1501 }
1502
1503 return 0;
1504}
1505
1506static int __init usb_udc_init(void)
1507{
1508 udc_class = class_create(THIS_MODULE, "udc");
1509 if (IS_ERR(udc_class)) {
1510 pr_err("failed to create udc class --> %ld\n",
1511 PTR_ERR(udc_class));
1512 return PTR_ERR(udc_class);
1513 }
1514
1515 udc_class->dev_uevent = usb_udc_uevent;
Felipe Balbi2ccea032011-06-28 16:33:46 +03001516 return 0;
1517}
1518subsys_initcall(usb_udc_init);
1519
1520static void __exit usb_udc_exit(void)
1521{
1522 class_destroy(udc_class);
1523}
1524module_exit(usb_udc_exit);
1525
1526MODULE_DESCRIPTION("UDC Framework");
1527MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
1528MODULE_LICENSE("GPL v2");