Lines Matching +full:usb +full:- +full:c
2 USB Gadget API for Linux
11 This document presents a Linux-USB "Gadget" kernel mode API, for use
12 within peripherals and other USB devices that embed Linux. It provides
17 - Supports USB 2.0, for high speed devices which can stream data at
20 - Handles devices with dozens of endpoints just as well as ones with
21 just two fixed-function ones. Gadget drivers can be written so
24 - Flexible enough to expose more complex USB device capabilities such
28 - USB "On-The-Go" (OTG) support, in conjunction with updates to the
29 Linux-USB host side.
31 - Sharing data structures and API models with the Linux-USB host side
32 API. This helps the OTG support, and looks forward to more-symmetric
36 - Minimalist, so it's easier to support new device controller hardware.
41 USB ``host`` hardware in a PC, workstation, or server. Linux users with
42 embedded systems are more likely to have USB peripheral hardware. To
44 Linux "USB device drivers", which are host side proxies for the real USB
46 are "USB gadget drivers". In USB protocol interactions, the device
50 The gadget API resembles the host side Linux-USB API in that both use
53 USB *Chapter 9* messages, structures, and constants. Also, both APIs
58 necessarily different (one side is a hardware-neutral master, the other
59 is a hardware-aware slave), the endpoint I/0 API used here should also
60 be usable for an overhead-reduced host side API.
65 A system running inside a USB peripheral normally has at least three
66 layers inside the kernel to handle USB protocol processing, and may have
73 *USB Controller Driver*
76 ``<linux/usb/gadget.h>`` API abstracts the peripheral controller
79 callbacks that interact with gadget drivers. Since normal USB
84 Examples of such controller hardware include the PCI-based NetChip
85 2280 USB 2.0 high speed controller, the SA-11x0 or PXA-25x UDC
89 The lower boundary of this driver implements hardware-neutral USB
98 automatically for many bulk-oriented drivers.) Gadget driver
101 - handling setup requests (ep0 protocol responses) possibly
102 including class-specific functionality
104 - returning configuration and string descriptors
106 - (re)setting configurations and interface altsettings, including
109 - handling life cycle events, such as managing bindings to
110 hardware, USB suspend/resume, remote wakeup, and disconnection
111 from the USB host.
113 - managing IN and OUT transfers on all currently enabled endpoints
122 protocol transfers over USB. Examples include:
124 - user mode code, using generic (gadgetfs) or application specific
127 - networking subsystem (for network gadgets, like the CDC Ethernet
130 - data capture drivers, perhaps video4Linux or a scanner driver; or
133 - input subsystem (for HID gadgets)
135 - sound subsystem (for audio gadgets)
137 - file system (for PTP gadgets)
139 - block i/o subsystem (for usb-storage gadgets)
141 - ... and more
151 OTG-capable systems will also need to include a standard Linux-USB host
153 (HCDs), *USB Device Drivers* to support the OTG "Targeted Peripheral
156 That helps the host and device side USB controllers implement the two
158 vice versa) using HNP during USB suspend processing, and SRP can be
159 viewed as a more battery-friendly kind of device wakeup protocol.
167 USB-IF protocols for HID, networking, storage, or audio classes. Some
169 be remotely debugged. Most such USB protocol code doesn't need to be
170 hardware-specific, any more than network protocols like X11, HTTP, or
171 NFS are. Such gadget-side interface drivers should eventually be
178 :c:type:`usb_gadget_driver`, which is responsible for most parts of enumeration
206 such as device-to-device DMA (without temporary storage in a memory
207 buffer) that would be added using hardware-specific APIs.
214 device configuration and management. The API supports limited run-time
223 Like the Linux-USB host side API, this API exposes the "chunky" nature
224 of USB messages: I/O requests are in terms of one or more "packets", and
225 packet boundaries are visible to drivers. Compared to RS-232 serial
226 protocols, USB resembles synchronous protocols like HDLC (N bytes per
230 drivers won't buffer two single byte writes into a single two-byte USB
236 -----------------
242 1. Register a driver for the particular device side usb controller
243 hardware, such as the net2280 on PCI (USB 2.0), sa11x0 or pxa25x as
245 in the USB ch9 initial state (``attached``), drawing no power and not
251 function. That will then bind() to a :c:type:`usb_gadget`, which activates
255 are to accept USB ``power`` and ``set_address`` requests. Other steps are
259 4. The gadget driver's ``setup()`` call returns usb descriptors, based both
265 5. The gadget driver handles the last step of enumeration, when the USB
291 USB specifications. Such issues are in the domain of gadget drivers,
292 including knowing about implementation constraints imposed by some USB
298 only the HNP-related differences are particularly visible to driver
303 USB 2.0 Chapter 9 Types and Constants
304 -------------------------------------
306 Gadget drivers rely on common USB structures and constants defined in
307 the :ref:`linux/usb/ch9.h <usb_chapter9>` header file, which is standard in
312 ------------------------
314 These are declared in ``<linux/usb/gadget.h>``, and are used by gadget
315 drivers to interact with USB peripheral controller drivers.
317 .. kernel-doc:: include/linux/usb/gadget.h
321 ------------------
323 The core API is sufficient for writing a USB Gadget Driver, but some
327 .. kernel-doc:: drivers/usb/gadget/usbstring.c
330 .. kernel-doc:: drivers/usb/gadget/config.c
334 --------------------------
336 The core API is sufficient for writing drivers for composite USB devices
338 multi-configuration devices (also more than one function, but not
345 :c:type:`usb_function`, which packages a user visible role such as "network
349 .. kernel-doc:: include/linux/usb/composite.h
352 .. kernel-doc:: drivers/usb/gadget/composite.c
356 --------------------------
359 to this framework. Near-term plans include converting all of them,
366 which supports USB 2.0 high speed and is based on PCI. This is the
373 "Goku-S" (``goku_udc``), Renesas SH7705/7727 (``sh_udc``), MediaQ 11xx
379 for several other USB device controllers, with plans to make many of
382 A partial USB simulator, the ``dummy_hcd`` driver, is available. It can
400 with drivers for usb controller hardware), other gadget drivers exist.
406 USB host as if they're an Ethernet adapter. It provides access to a
416 on more slightly USB hardware (but less than the CDC subset). However,
430 There's a USB Mass Storage class driver, which provides a different
431 solution for interoperability with systems such as MS-Windows and MacOS.
433 for a drive, like the ``loop`` driver. The USB host uses the BBB, CB, or
437 There's a "serial line" driver, useful for TTY style operation over USB.
439 a USB modem, and so on most hardware it can interoperate easily with
440 MS-Windows. One interesting use of that driver is in boot firmware (like
447 USB On-The-GO (OTG)
450 USB OTG support on Linux 2.6 was initially developed by Texas
456 including a special *Mini-AB* jack and associated transceiver to support
457 *Dual-Role* operation: they can act either as a host, using the standard
458 Linux-USB host side driver stack, or as a peripheral, using this
462 connects to the OTG port. In each role, the system can re-use the
463 existing pool of hardware-neutral drivers, layered on top of the
464 controller driver interfaces (:c:type:`usb_bus` or :c:type:`usb_gadget`).
466 support OTG can also benefit non-OTG products.
468 - Gadget drivers test the ``is_otg`` flag, and use it to determine
472 - Gadget drivers may need changes to support the two new OTG protocols,
476 peripheral. SRP support can be user-initiated just like remote
479 - On the host side, USB device drivers need to be taught to trigger HNP
481 conserves battery power, which is useful even for non-OTG
484 - Also on the host side, a driver must support the OTG "Targeted
487 product-specific; each product must modify* ``otg_whitelist.h`` *to
490 Non-OTG Linux hosts, like PCs and workstations, normally have some
500 Additional changes are needed below those hardware-neutral :c:type:`usb_bus`
501 and :c:type:`usb_gadget` driver interfaces; those aren't discussed here in any
502 detail. Those affect the hardware-specific code for each USB Host or
507 The OTG controller driver needs to activate and deactivate USB
509 were needed inside usbcore, so that it can identify OTG-capable devices