aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/DocBook/gadget.tmpl
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /Documentation/DocBook/gadget.tmpl
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/DocBook/gadget.tmpl')
-rw-r--r--Documentation/DocBook/gadget.tmpl752
1 files changed, 752 insertions, 0 deletions
diff --git a/Documentation/DocBook/gadget.tmpl b/Documentation/DocBook/gadget.tmpl
new file mode 100644
index 000000000000..a34442436128
--- /dev/null
+++ b/Documentation/DocBook/gadget.tmpl
@@ -0,0 +1,752 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4
5<book id="USB-Gadget-API">
6 <bookinfo>
7 <title>USB Gadget API for Linux</title>
8 <date>20 August 2004</date>
9 <edition>20 August 2004</edition>
10
11 <legalnotice>
12 <para>
13 This documentation is free software; you can redistribute
14 it and/or modify it under the terms of the GNU General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later
17 version.
18 </para>
19
20 <para>
21 This program is distributed in the hope that it will be
22 useful, but WITHOUT ANY WARRANTY; without even the implied
23 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 See the GNU General Public License for more details.
25 </para>
26
27 <para>
28 You should have received a copy of the GNU General Public
29 License along with this program; if not, write to the Free
30 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 MA 02111-1307 USA
32 </para>
33
34 <para>
35 For more details see the file COPYING in the source
36 distribution of Linux.
37 </para>
38 </legalnotice>
39 <copyright>
40 <year>2003-2004</year>
41 <holder>David Brownell</holder>
42 </copyright>
43
44 <author>
45 <firstname>David</firstname>
46 <surname>Brownell</surname>
47 <affiliation>
48 <address><email>dbrownell@users.sourceforge.net</email></address>
49 </affiliation>
50 </author>
51 </bookinfo>
52
53<toc></toc>
54
55<chapter><title>Introduction</title>
56
57<para>This document presents a Linux-USB "Gadget"
58kernel mode
59API, for use within peripherals and other USB devices
60that embed Linux.
61It provides an overview of the API structure,
62and shows how that fits into a system development project.
63This is the first such API released on Linux to address
64a number of important problems, including: </para>
65
66<itemizedlist>
67 <listitem><para>Supports USB 2.0, for high speed devices which
68 can stream data at several dozen megabytes per second.
69 </para></listitem>
70 <listitem><para>Handles devices with dozens of endpoints just as
71 well as ones with just two fixed-function ones. Gadget drivers
72 can be written so they're easy to port to new hardware.
73 </para></listitem>
74 <listitem><para>Flexible enough to expose more complex USB device
75 capabilities such as multiple configurations, multiple interfaces,
76 composite devices,
77 and alternate interface settings.
78 </para></listitem>
79 <listitem><para>USB "On-The-Go" (OTG) support, in conjunction
80 with updates to the Linux-USB host side.
81 </para></listitem>
82 <listitem><para>Sharing data structures and API models with the
83 Linux-USB host side API. This helps the OTG support, and
84 looks forward to more-symmetric frameworks (where the same
85 I/O model is used by both host and device side drivers).
86 </para></listitem>
87 <listitem><para>Minimalist, so it's easier to support new device
88 controller hardware. I/O processing doesn't imply large
89 demands for memory or CPU resources.
90 </para></listitem>
91</itemizedlist>
92
93
94<para>Most Linux developers will not be able to use this API, since they
95have USB "host" hardware in a PC, workstation, or server.
96Linux users with embedded systems are more likely to
97have USB peripheral hardware.
98To distinguish drivers running inside such hardware from the
99more familiar Linux "USB device drivers",
100which are host side proxies for the real USB devices,
101a different term is used:
102the drivers inside the peripherals are "USB gadget drivers".
103In USB protocol interactions, the device driver is the master
104(or "client driver")
105and the gadget driver is the slave (or "function driver").
106</para>
107
108<para>The gadget API resembles the host side Linux-USB API in that both
109use queues of request objects to package I/O buffers, and those requests
110may be submitted or canceled.
111They share common definitions for the standard USB
112<emphasis>Chapter 9</emphasis> messages, structures, and constants.
113Also, both APIs bind and unbind drivers to devices.
114The APIs differ in detail, since the host side's current
115URB framework exposes a number of implementation details
116and assumptions that are inappropriate for a gadget API.
117While the model for control transfers and configuration
118management is necessarily different (one side is a hardware-neutral master,
119the other is a hardware-aware slave), the endpoint I/0 API used here
120should also be usable for an overhead-reduced host side API.
121</para>
122
123</chapter>
124
125<chapter id="structure"><title>Structure of Gadget Drivers</title>
126
127<para>A system running inside a USB peripheral
128normally has at least three layers inside the kernel to handle
129USB protocol processing, and may have additional layers in
130user space code.
131The "gadget" API is used by the middle layer to interact
132with the lowest level (which directly handles hardware).
133</para>
134
135<para>In Linux, from the bottom up, these layers are:
136</para>
137
138<variablelist>
139
140 <varlistentry>
141 <term><emphasis>USB Controller Driver</emphasis></term>
142
143 <listitem>
144 <para>This is the lowest software level.
145 It is the only layer that talks to hardware,
146 through registers, fifos, dma, irqs, and the like.
147 The <filename>&lt;linux/usb_gadget.h&gt;</filename> API abstracts
148 the peripheral controller endpoint hardware.
149 That hardware is exposed through endpoint objects, which accept
150 streams of IN/OUT buffers, and through callbacks that interact
151 with gadget drivers.
152 Since normal USB devices only have one upstream
153 port, they only have one of these drivers.
154 The controller driver can support any number of different
155 gadget drivers, but only one of them can be used at a time.
156 </para>
157
158 <para>Examples of such controller hardware include
159 the PCI-based NetChip 2280 USB 2.0 high speed controller,
160 the SA-11x0 or PXA-25x UDC (found within many PDAs),
161 and a variety of other products.
162 </para>
163
164 </listitem></varlistentry>
165
166 <varlistentry>
167 <term><emphasis>Gadget Driver</emphasis></term>
168
169 <listitem>
170 <para>The lower boundary of this driver implements hardware-neutral
171 USB functions, using calls to the controller driver.
172 Because such hardware varies widely in capabilities and restrictions,
173 and is used in embedded environments where space is at a premium,
174 the gadget driver is often configured at compile time
175 to work with endpoints supported by one particular controller.
176 Gadget drivers may be portable to several different controllers,
177 using conditional compilation.
178 (Recent kernels substantially simplify the work involved in
179 supporting new hardware, by <emphasis>autoconfiguring</emphasis>
180 endpoints automatically for many bulk-oriented drivers.)
181 Gadget driver responsibilities include:
182 </para>
183 <itemizedlist>
184 <listitem><para>handling setup requests (ep0 protocol responses)
185 possibly including class-specific functionality
186 </para></listitem>
187 <listitem><para>returning configuration and string descriptors
188 </para></listitem>
189 <listitem><para>(re)setting configurations and interface
190 altsettings, including enabling and configuring endpoints
191 </para></listitem>
192 <listitem><para>handling life cycle events, such as managing
193 bindings to hardware,
194 USB suspend/resume, remote wakeup,
195 and disconnection from the USB host.
196 </para></listitem>
197 <listitem><para>managing IN and OUT transfers on all currently
198 enabled endpoints
199 </para></listitem>
200 </itemizedlist>
201
202 <para>
203 Such drivers may be modules of proprietary code, although
204 that approach is discouraged in the Linux community.
205 </para>
206 </listitem></varlistentry>
207
208 <varlistentry>
209 <term><emphasis>Upper Level</emphasis></term>
210
211 <listitem>
212 <para>Most gadget drivers have an upper boundary that connects
213 to some Linux driver or framework in Linux.
214 Through that boundary flows the data which the gadget driver
215 produces and/or consumes through protocol transfers over USB.
216 Examples include:
217 </para>
218 <itemizedlist>
219 <listitem><para>user mode code, using generic (gadgetfs)
220 or application specific files in
221 <filename>/dev</filename>
222 </para></listitem>
223 <listitem><para>networking subsystem (for network gadgets,
224 like the CDC Ethernet Model gadget driver)
225 </para></listitem>
226 <listitem><para>data capture drivers, perhaps video4Linux or
227 a scanner driver; or test and measurement hardware.
228 </para></listitem>
229 <listitem><para>input subsystem (for HID gadgets)
230 </para></listitem>
231 <listitem><para>sound subsystem (for audio gadgets)
232 </para></listitem>
233 <listitem><para>file system (for PTP gadgets)
234 </para></listitem>
235 <listitem><para>block i/o subsystem (for usb-storage gadgets)
236 </para></listitem>
237 <listitem><para>... and more </para></listitem>
238 </itemizedlist>
239 </listitem></varlistentry>
240
241 <varlistentry>
242 <term><emphasis>Additional Layers</emphasis></term>
243
244 <listitem>
245 <para>Other layers may exist.
246 These could include kernel layers, such as network protocol stacks,
247 as well as user mode applications building on standard POSIX
248 system call APIs such as
249 <emphasis>open()</emphasis>, <emphasis>close()</emphasis>,
250 <emphasis>read()</emphasis> and <emphasis>write()</emphasis>.
251 On newer systems, POSIX Async I/O calls may be an option.
252 Such user mode code will not necessarily be subject to
253 the GNU General Public License (GPL).
254 </para>
255 </listitem></varlistentry>
256
257
258</variablelist>
259
260<para>OTG-capable systems will also need to include a standard Linux-USB
261host side stack,
262with <emphasis>usbcore</emphasis>,
263one or more <emphasis>Host Controller Drivers</emphasis> (HCDs),
264<emphasis>USB Device Drivers</emphasis> to support
265the OTG "Targeted Peripheral List",
266and so forth.
267There will also be an <emphasis>OTG Controller Driver</emphasis>,
268which is visible to gadget and device driver developers only indirectly.
269That helps the host and device side USB controllers implement the
270two new OTG protocols (HNP and SRP).
271Roles switch (host to peripheral, or vice versa) using HNP
272during USB suspend processing, and SRP can be viewed as a
273more battery-friendly kind of device wakeup protocol.
274</para>
275
276<para>Over time, reusable utilities are evolving to help make some
277gadget driver tasks simpler.
278For example, building configuration descriptors from vectors of
279descriptors for the configurations interfaces and endpoints is
280now automated, and many drivers now use autoconfiguration to
281choose hardware endpoints and initialize their descriptors.
282
283A potential example of particular interest
284is code implementing standard USB-IF protocols for
285HID, networking, storage, or audio classes.
286Some developers are interested in KDB or KGDB hooks, to let
287target hardware be remotely debugged.
288Most such USB protocol code doesn't need to be hardware-specific,
289any more than network protocols like X11, HTTP, or NFS are.
290Such gadget-side interface drivers should eventually be combined,
291to implement composite devices.
292</para>
293
294</chapter>
295
296
297<chapter id="api"><title>Kernel Mode Gadget API</title>
298
299<para>Gadget drivers declare themselves through a
300<emphasis>struct usb_gadget_driver</emphasis>, which is responsible for
301most parts of enumeration for a <emphasis>struct usb_gadget</emphasis>.
302The response to a set_configuration usually involves
303enabling one or more of the <emphasis>struct usb_ep</emphasis> objects
304exposed by the gadget, and submitting one or more
305<emphasis>struct usb_request</emphasis> buffers to transfer data.
306Understand those four data types, and their operations, and
307you will understand how this API works.
308</para>
309
310<note><title>Incomplete Data Type Descriptions</title>
311
312<para>This documentation was prepared using the standard Linux
313kernel <filename>docproc</filename> tool, which turns text
314and in-code comments into SGML DocBook and then into usable
315formats such as HTML or PDF.
316Other than the "Chapter 9" data types, most of the significant
317data types and functions are described here.
318</para>
319
320<para>However, docproc does not understand all the C constructs
321that are used, so some relevant information is likely omitted from
322what you are reading.
323One example of such information is endpoint autoconfiguration.
324You'll have to read the header file, and use example source
325code (such as that for "Gadget Zero"), to fully understand the API.
326</para>
327
328<para>The part of the API implementing some basic
329driver capabilities is specific to the version of the
330Linux kernel that's in use.
331The 2.6 kernel includes a <emphasis>driver model</emphasis>
332framework that has no analogue on earlier kernels;
333so those parts of the gadget API are not fully portable.
334(They are implemented on 2.4 kernels, but in a different way.)
335The driver model state is another part of this API that is
336ignored by the kerneldoc tools.
337</para>
338</note>
339
340<para>The core API does not expose
341every possible hardware feature, only the most widely available ones.
342There are significant hardware features, such as device-to-device DMA
343(without temporary storage in a memory buffer)
344that would be added using hardware-specific APIs.
345</para>
346
347<para>This API allows drivers to use conditional compilation to handle
348endpoint capabilities of different hardware, but doesn't require that.
349Hardware tends to have arbitrary restrictions, relating to
350transfer types, addressing, packet sizes, buffering, and availability.
351As a rule, such differences only matter for "endpoint zero" logic
352that handles device configuration and management.
353The API supports limited run-time
354detection of capabilities, through naming conventions for endpoints.
355Many drivers will be able to at least partially autoconfigure
356themselves.
357In particular, driver init sections will often have endpoint
358autoconfiguration logic that scans the hardware's list of endpoints
359to find ones matching the driver requirements
360(relying on those conventions), to eliminate some of the most
361common reasons for conditional compilation.
362</para>
363
364<para>Like the Linux-USB host side API, this API exposes
365the "chunky" nature of USB messages: I/O requests are in terms
366of one or more "packets", and packet boundaries are visible to drivers.
367Compared to RS-232 serial protocols, USB resembles
368synchronous protocols like HDLC
369(N bytes per frame, multipoint addressing, host as the primary
370station and devices as secondary stations)
371more than asynchronous ones
372(tty style: 8 data bits per frame, no parity, one stop bit).
373So for example the controller drivers won't buffer
374two single byte writes into a single two-byte USB IN packet,
375although gadget drivers may do so when they implement
376protocols where packet boundaries (and "short packets")
377are not significant.
378</para>
379
380<sect1 id="lifecycle"><title>Driver Life Cycle</title>
381
382<para>Gadget drivers make endpoint I/O requests to hardware without
383needing to know many details of the hardware, but driver
384setup/configuration code needs to handle some differences.
385Use the API like this:
386</para>
387
388<orderedlist numeration='arabic'>
389
390<listitem><para>Register a driver for the particular device side
391usb controller hardware,
392such as the net2280 on PCI (USB 2.0),
393sa11x0 or pxa25x as found in Linux PDAs,
394and so on.
395At this point the device is logically in the USB ch9 initial state
396("attached"), drawing no power and not usable
397(since it does not yet support enumeration).
398Any host should not see the device, since it's not
399activated the data line pullup used by the host to
400detect a device, even if VBUS power is available.
401</para></listitem>
402
403<listitem><para>Register a gadget driver that implements some higher level
404device function. That will then bind() to a usb_gadget, which
405activates the data line pullup sometime after detecting VBUS.
406</para></listitem>
407
408<listitem><para>The hardware driver can now start enumerating.
409The steps it handles are to accept USB power and set_address requests.
410Other steps are handled by the gadget driver.
411If the gadget driver module is unloaded before the host starts to
412enumerate, steps before step 7 are skipped.
413</para></listitem>
414
415<listitem><para>The gadget driver's setup() call returns usb descriptors,
416based both on what the bus interface hardware provides and on the
417functionality being implemented.
418That can involve alternate settings or configurations,
419unless the hardware prevents such operation.
420For OTG devices, each configuration descriptor includes
421an OTG descriptor.
422</para></listitem>
423
424<listitem><para>The gadget driver handles the last step of enumeration,
425when the USB host issues a set_configuration call.
426It enables all endpoints used in that configuration,
427with all interfaces in their default settings.
428That involves using a list of the hardware's endpoints, enabling each
429endpoint according to its descriptor.
430It may also involve using <function>usb_gadget_vbus_draw</function>
431to let more power be drawn from VBUS, as allowed by that configuration.
432For OTG devices, setting a configuration may also involve reporting
433HNP capabilities through a user interface.
434</para></listitem>
435
436<listitem><para>Do real work and perform data transfers, possibly involving
437changes to interface settings or switching to new configurations, until the
438device is disconnect()ed from the host.
439Queue any number of transfer requests to each endpoint.
440It may be suspended and resumed several times before being disconnected.
441On disconnect, the drivers go back to step 3 (above).
442</para></listitem>
443
444<listitem><para>When the gadget driver module is being unloaded,
445the driver unbind() callback is issued. That lets the controller
446driver be unloaded.
447</para></listitem>
448
449</orderedlist>
450
451<para>Drivers will normally be arranged so that just loading the
452gadget driver module (or statically linking it into a Linux kernel)
453allows the peripheral device to be enumerated, but some drivers
454will defer enumeration until some higher level component (like
455a user mode daemon) enables it.
456Note that at this lowest level there are no policies about how
457ep0 configuration logic is implemented,
458except that it should obey USB specifications.
459Such issues are in the domain of gadget drivers,
460including knowing about implementation constraints
461imposed by some USB controllers
462or understanding that composite devices might happen to
463be built by integrating reusable components.
464</para>
465
466<para>Note that the lifecycle above can be slightly different
467for OTG devices.
468Other than providing an additional OTG descriptor in each
469configuration, only the HNP-related differences are particularly
470visible to driver code.
471They involve reporting requirements during the SET_CONFIGURATION
472request, and the option to invoke HNP during some suspend callbacks.
473Also, SRP changes the semantics of
474<function>usb_gadget_wakeup</function>
475slightly.
476</para>
477
478</sect1>
479
480<sect1 id="ch9"><title>USB 2.0 Chapter 9 Types and Constants</title>
481
482<para>Gadget drivers
483rely on common USB structures and constants
484defined in the
485<filename>&lt;linux/usb_ch9.h&gt;</filename>
486header file, which is standard in Linux 2.6 kernels.
487These are the same types and constants used by host
488side drivers (and usbcore).
489</para>
490
491!Iinclude/linux/usb_ch9.h
492</sect1>
493
494<sect1 id="core"><title>Core Objects and Methods</title>
495
496<para>These are declared in
497<filename>&lt;linux/usb_gadget.h&gt;</filename>,
498and are used by gadget drivers to interact with
499USB peripheral controller drivers.
500</para>
501
502 <!-- yeech, this is ugly in nsgmls PDF output.
503
504 the PDF bookmark and refentry output nesting is wrong,
505 and the member/argument documentation indents ugly.
506
507 plus something (docproc?) adds whitespace before the
508 descriptive paragraph text, so it can't line up right
509 unless the explanations are trivial.
510 -->
511
512!Iinclude/linux/usb_gadget.h
513</sect1>
514
515<sect1 id="utils"><title>Optional Utilities</title>
516
517<para>The core API is sufficient for writing a USB Gadget Driver,
518but some optional utilities are provided to simplify common tasks.
519These utilities include endpoint autoconfiguration.
520</para>
521
522!Edrivers/usb/gadget/usbstring.c
523!Edrivers/usb/gadget/config.c
524<!-- !Edrivers/usb/gadget/epautoconf.c -->
525</sect1>
526
527</chapter>
528
529<chapter id="controllers"><title>Peripheral Controller Drivers</title>
530
531<para>The first hardware supporting this API was the NetChip 2280
532controller, which supports USB 2.0 high speed and is based on PCI.
533This is the <filename>net2280</filename> driver module.
534The driver supports Linux kernel versions 2.4 and 2.6;
535contact NetChip Technologies for development boards and product
536information.
537</para>
538
539<para>Other hardware working in the "gadget" framework includes:
540Intel's PXA 25x and IXP42x series processors
541(<filename>pxa2xx_udc</filename>),
542Toshiba TC86c001 "Goku-S" (<filename>goku_udc</filename>),
543Renesas SH7705/7727 (<filename>sh_udc</filename>),
544MediaQ 11xx (<filename>mq11xx_udc</filename>),
545Hynix HMS30C7202 (<filename>h7202_udc</filename>),
546National 9303/4 (<filename>n9604_udc</filename>),
547Texas Instruments OMAP (<filename>omap_udc</filename>),
548Sharp LH7A40x (<filename>lh7a40x_udc</filename>),
549and more.
550Most of those are full speed controllers.
551</para>
552
553<para>At this writing, there are people at work on drivers in
554this framework for several other USB device controllers,
555with plans to make many of them be widely available.
556</para>
557
558<!-- !Edrivers/usb/gadget/net2280.c -->
559
560<para>A partial USB simulator,
561the <filename>dummy_hcd</filename> driver, is available.
562It can act like a net2280, a pxa25x, or an sa11x0 in terms
563of available endpoints and device speeds; and it simulates
564control, bulk, and to some extent interrupt transfers.
565That lets you develop some parts of a gadget driver on a normal PC,
566without any special hardware, and perhaps with the assistance
567of tools such as GDB running with User Mode Linux.
568At least one person has expressed interest in adapting that
569approach, hooking it up to a simulator for a microcontroller.
570Such simulators can help debug subsystems where the runtime hardware
571is unfriendly to software development, or is not yet available.
572</para>
573
574<para>Support for other controllers is expected to be developed
575and contributed
576over time, as this driver framework evolves.
577</para>
578
579</chapter>
580
581<chapter id="gadget"><title>Gadget Drivers</title>
582
583<para>In addition to <emphasis>Gadget Zero</emphasis>
584(used primarily for testing and development with drivers
585for usb controller hardware), other gadget drivers exist.
586</para>
587
588<para>There's an <emphasis>ethernet</emphasis> gadget
589driver, which implements one of the most useful
590<emphasis>Communications Device Class</emphasis> (CDC) models.
591One of the standards for cable modem interoperability even
592specifies the use of this ethernet model as one of two
593mandatory options.
594Gadgets using this code look to a USB host as if they're
595an Ethernet adapter.
596It provides access to a network where the gadget's CPU is one host,
597which could easily be bridging, routing, or firewalling
598access to other networks.
599Since some hardware can't fully implement the CDC Ethernet
600requirements, this driver also implements a "good parts only"
601subset of CDC Ethernet.
602(That subset doesn't advertise itself as CDC Ethernet,
603to avoid creating problems.)
604</para>
605
606<para>Support for Microsoft's <emphasis>RNDIS</emphasis>
607protocol has been contributed by Pengutronix and Auerswald GmbH.
608This is like CDC Ethernet, but it runs on more slightly USB hardware
609(but less than the CDC subset).
610However, its main claim to fame is being able to connect directly to
611recent versions of Windows, using drivers that Microsoft bundles
612and supports, making it much simpler to network with Windows.
613</para>
614
615<para>There is also support for user mode gadget drivers,
616using <emphasis>gadgetfs</emphasis>.
617This provides a <emphasis>User Mode API</emphasis> that presents
618each endpoint as a single file descriptor. I/O is done using
619normal <emphasis>read()</emphasis> and <emphasis>read()</emphasis> calls.
620Familiar tools like GDB and pthreads can be used to
621develop and debug user mode drivers, so that once a robust
622controller driver is available many applications for it
623won't require new kernel mode software.
624Linux 2.6 <emphasis>Async I/O (AIO)</emphasis>
625support is available, so that user mode software
626can stream data with only slightly more overhead
627than a kernel driver.
628</para>
629
630<para>There's a USB Mass Storage class driver, which provides
631a different solution for interoperability with systems such
632as MS-Windows and MacOS.
633That <emphasis>File-backed Storage</emphasis> driver uses a
634file or block device as backing store for a drive,
635like the <filename>loop</filename> driver.
636The USB host uses the BBB, CB, or CBI versions of the mass
637storage class specification, using transparent SCSI commands
638to access the data from the backing store.
639</para>
640
641<para>There's a "serial line" driver, useful for TTY style
642operation over USB.
643The latest version of that driver supports CDC ACM style
644operation, like a USB modem, and so on most hardware it can
645interoperate easily with MS-Windows.
646One interesting use of that driver is in boot firmware (like a BIOS),
647which can sometimes use that model with very small systems without
648real serial lines.
649</para>
650
651<para>Support for other kinds of gadget is expected to
652be developed and contributed
653over time, as this driver framework evolves.
654</para>
655
656</chapter>
657
658<chapter id="otg"><title>USB On-The-GO (OTG)</title>
659
660<para>USB OTG support on Linux 2.6 was initially developed
661by Texas Instruments for
662<ulink url="http://www.omap.com">OMAP</ulink> 16xx and 17xx
663series processors.
664Other OTG systems should work in similar ways, but the
665hardware level details could be very different.
666</para>
667
668<para>Systems need specialized hardware support to implement OTG,
669notably including a special <emphasis>Mini-AB</emphasis> jack
670and associated transciever to support <emphasis>Dual-Role</emphasis>
671operation:
672they can act either as a host, using the standard
673Linux-USB host side driver stack,
674or as a peripheral, using this "gadget" framework.
675To do that, the system software relies on small additions
676to those programming interfaces,
677and on a new internal component (here called an "OTG Controller")
678affecting which driver stack connects to the OTG port.
679In each role, the system can re-use the existing pool of
680hardware-neutral drivers, layered on top of the controller
681driver interfaces (<emphasis>usb_bus</emphasis> or
682<emphasis>usb_gadget</emphasis>).
683Such drivers need at most minor changes, and most of the calls
684added to support OTG can also benefit non-OTG products.
685</para>
686
687<itemizedlist>
688 <listitem><para>Gadget drivers test the <emphasis>is_otg</emphasis>
689 flag, and use it to determine whether or not to include
690 an OTG descriptor in each of their configurations.
691 </para></listitem>
692 <listitem><para>Gadget drivers may need changes to support the
693 two new OTG protocols, exposed in new gadget attributes
694 such as <emphasis>b_hnp_enable</emphasis> flag.
695 HNP support should be reported through a user interface
696 (two LEDs could suffice), and is triggered in some cases
697 when the host suspends the peripheral.
698 SRP support can be user-initiated just like remote wakeup,
699 probably by pressing the same button.
700 </para></listitem>
701 <listitem><para>On the host side, USB device drivers need
702 to be taught to trigger HNP at appropriate moments, using
703 <function>usb_suspend_device()</function>.
704 That also conserves battery power, which is useful even
705 for non-OTG configurations.
706 </para></listitem>
707 <listitem><para>Also on the host side, a driver must support the
708 OTG "Targeted Peripheral List". That's just a whitelist,
709 used to reject peripherals not supported with a given
710 Linux OTG host.
711 <emphasis>This whitelist is product-specific;
712 each product must modify <filename>otg_whitelist.h</filename>
713 to match its interoperability specification.
714 </emphasis>
715 </para>
716 <para>Non-OTG Linux hosts, like PCs and workstations,
717 normally have some solution for adding drivers, so that
718 peripherals that aren't recognized can eventually be supported.
719 That approach is unreasonable for consumer products that may
720 never have their firmware upgraded, and where it's usually
721 unrealistic to expect traditional PC/workstation/server kinds
722 of support model to work.
723 For example, it's often impractical to change device firmware
724 once the product has been distributed, so driver bugs can't
725 normally be fixed if they're found after shipment.
726 </para></listitem>
727</itemizedlist>
728
729<para>
730Additional changes are needed below those hardware-neutral
731<emphasis>usb_bus</emphasis> and <emphasis>usb_gadget</emphasis>
732driver interfaces; those aren't discussed here in any detail.
733Those affect the hardware-specific code for each USB Host or Peripheral
734controller, and how the HCD initializes (since OTG can be active only
735on a single port).
736They also involve what may be called an <emphasis>OTG Controller
737Driver</emphasis>, managing the OTG transceiver and the OTG state
738machine logic as well as much of the root hub behavior for the
739OTG port.
740The OTG controller driver needs to activate and deactivate USB
741controllers depending on the relevant device role.
742Some related changes were needed inside usbcore, so that it
743can identify OTG-capable devices and respond appropriately
744to HNP or SRP protocols.
745</para>
746
747</chapter>
748
749</book>
750<!--
751 vim:syntax=sgml:sw=4
752-->