⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gadget.tmpl

📁 linux 内核源代码
💻 TMPL
📖 第 1 页 / 共 2 页
字号:
</para><sect1 id="lifecycle"><title>Driver Life Cycle</title><para>Gadget drivers make endpoint I/O requests to hardware withoutneeding to know many details of the hardware, but driversetup/configuration code needs to handle some differences.Use the API like this:</para><orderedlist numeration='arabic'><listitem><para>Register a driver for the particular device sideusb controller hardware,such as the net2280 on PCI (USB 2.0),sa11x0 or pxa25x as found in Linux PDAs,and so on.At this point the device is logically in the USB ch9 initial state("attached"), drawing no power and not usable(since it does not yet support enumeration).Any host should not see the device, since it's notactivated the data line pullup used by the host todetect a device, even if VBUS power is available.</para></listitem><listitem><para>Register a gadget driver that implements some higher leveldevice function.  That will then bind() to a usb_gadget, whichactivates the data line pullup sometime after detecting VBUS.</para></listitem><listitem><para>The hardware driver can now start enumerating.The steps it handles are to accept USB power and set_address requests.Other steps are handled by the gadget driver.If the gadget driver module is unloaded before the host starts toenumerate, steps before step 7 are skipped.</para></listitem><listitem><para>The gadget driver's setup() call returns usb descriptors,based both on what the bus interface hardware provides and on thefunctionality being implemented.That can involve alternate settings or configurations,unless the hardware prevents such operation.For OTG devices, each configuration descriptor includesan OTG descriptor.</para></listitem><listitem><para>The gadget driver handles the last step of enumeration,when the USB host issues a set_configuration call.It enables all endpoints used in that configuration,with all interfaces in their default settings.That involves using a list of the hardware's endpoints, enabling eachendpoint according to its descriptor.It may also involve using <function>usb_gadget_vbus_draw</function>to let more power be drawn from VBUS, as allowed by that configuration.For OTG devices, setting a configuration may also involve reportingHNP capabilities through a user interface.</para></listitem><listitem><para>Do real work and perform data transfers, possibly involvingchanges to interface settings or switching to new configurations, until thedevice is disconnect()ed from the host.Queue any number of transfer requests to each endpoint.It may be suspended and resumed several times before being disconnected.On disconnect, the drivers go back to step 3 (above).</para></listitem><listitem><para>When the gadget driver module is being unloaded,the driver unbind() callback is issued.  That lets the controllerdriver be unloaded.</para></listitem></orderedlist><para>Drivers will normally be arranged so that just loading thegadget driver module (or statically linking it into a Linux kernel)allows the peripheral device to be enumerated, but some driverswill defer enumeration until some higher level component (likea user mode daemon) enables it.Note that at this lowest level there are no policies about howep0 configuration logic is implemented,except that it should obey USB specifications.Such issues are in the domain of gadget drivers,including knowing about implementation constraintsimposed by some USB controllersor understanding that composite devices might happen tobe built by integrating reusable components.</para><para>Note that the lifecycle above can be slightly differentfor OTG devices.Other than providing an additional OTG descriptor in eachconfiguration, only the HNP-related differences are particularlyvisible to driver code.They involve reporting requirements during the SET_CONFIGURATIONrequest, and the option to invoke HNP during some suspend callbacks.Also, SRP changes the semantics of<function>usb_gadget_wakeup</function>slightly.</para></sect1><sect1 id="ch9"><title>USB 2.0 Chapter 9 Types and Constants</title><para>Gadget driversrely on common USB structures and constantsdefined in the<filename>&lt;linux/usb/ch9.h&gt;</filename>header file, which is standard in Linux 2.6 kernels.These are the same types and constants used by hostside drivers (and usbcore).</para>!Iinclude/linux/usb/ch9.h</sect1><sect1 id="core"><title>Core Objects and Methods</title><para>These are declared in<filename>&lt;linux/usb/gadget.h&gt;</filename>,and are used by gadget drivers to interact withUSB peripheral controller drivers.</para>	<!-- yeech, this is ugly in nsgmls PDF output.	     the PDF bookmark and refentry output nesting is wrong,	     and the member/argument documentation indents ugly.	     plus something (docproc?) adds whitespace before the	     descriptive paragraph text, so it can't line up right	     unless the explanations are trivial.	  -->!Iinclude/linux/usb/gadget.h</sect1><sect1 id="utils"><title>Optional Utilities</title><para>The core API is sufficient for writing a USB Gadget Driver,but some optional utilities are provided to simplify common tasks.These utilities include endpoint autoconfiguration.</para>!Edrivers/usb/gadget/usbstring.c!Edrivers/usb/gadget/config.c<!-- !Edrivers/usb/gadget/epautoconf.c --></sect1></chapter><chapter id="controllers"><title>Peripheral Controller Drivers</title><para>The first hardware supporting this API was the NetChip 2280controller, which supports USB 2.0 high speed and is based on PCI.This is the <filename>net2280</filename> driver module.The driver supports Linux kernel versions 2.4 and 2.6;contact NetChip Technologies for development boards and productinformation.</para> <para>Other hardware working in the "gadget" framework includes:Intel's PXA 25x and IXP42x series processors(<filename>pxa2xx_udc</filename>),Toshiba TC86c001 "Goku-S" (<filename>goku_udc</filename>),Renesas SH7705/7727 (<filename>sh_udc</filename>),MediaQ 11xx (<filename>mq11xx_udc</filename>),Hynix HMS30C7202 (<filename>h7202_udc</filename>),National 9303/4 (<filename>n9604_udc</filename>),Texas Instruments OMAP (<filename>omap_udc</filename>),Sharp LH7A40x (<filename>lh7a40x_udc</filename>),and more.Most of those are full speed controllers.</para><para>At this writing, there are people at work on drivers inthis framework for several other USB device controllers,with plans to make many of them be widely available.</para><!-- !Edrivers/usb/gadget/net2280.c --><para>A partial USB simulator,the <filename>dummy_hcd</filename> driver, is available.It can act like a net2280, a pxa25x, or an sa11x0 in termsof available endpoints and device speeds; and it simulatescontrol, bulk, and to some extent interrupt transfers.That lets you develop some parts of a gadget driver on a normal PC,without any special hardware, and perhaps with the assistanceof tools such as GDB running with User Mode Linux.At least one person has expressed interest in adapting thatapproach, hooking it up to a simulator for a microcontroller.Such simulators can help debug subsystems where the runtime hardwareis unfriendly to software development, or is not yet available.</para><para>Support for other controllers is expected to be developedand contributedover time, as this driver framework evolves.</para></chapter><chapter id="gadget"><title>Gadget Drivers</title><para>In addition to <emphasis>Gadget Zero</emphasis>(used primarily for testing and development with driversfor usb controller hardware), other gadget drivers exist.</para><para>There's an <emphasis>ethernet</emphasis> gadgetdriver, which implements one of the most useful<emphasis>Communications Device Class</emphasis> (CDC) models.  One of the standards for cable modem interoperability evenspecifies the use of this ethernet model as one of twomandatory options.Gadgets using this code look to a USB host as if they'rean Ethernet adapter.It provides access to a network where the gadget's CPU is one host,which could easily be bridging, routing, or firewallingaccess to other networks.Since some hardware can't fully implement the CDC Ethernetrequirements, this driver also implements a "good parts only"subset of CDC Ethernet.(That subset doesn't advertise itself as CDC Ethernet,to avoid creating problems.)</para><para>Support for Microsoft's <emphasis>RNDIS</emphasis>protocol has been contributed by Pengutronix and Auerswald GmbH.This is like CDC Ethernet, but it runs on more slightly USB hardware(but less than the CDC subset).However, its main claim to fame is being able to connect directly torecent versions of Windows, using drivers that Microsoft bundlesand supports, making it much simpler to network with Windows.</para><para>There is also support for user mode gadget drivers,using <emphasis>gadgetfs</emphasis>.This provides a <emphasis>User Mode API</emphasis> that presentseach endpoint as a single file descriptor.  I/O is done usingnormal <emphasis>read()</emphasis> and <emphasis>read()</emphasis> calls.Familiar tools like GDB and pthreads can be used todevelop and debug user mode drivers, so that once a robustcontroller driver is available many applications for itwon't require new kernel mode software.Linux 2.6 <emphasis>Async I/O (AIO)</emphasis>support is available, so that user mode softwarecan stream data with only slightly more overheadthan a kernel driver.</para><para>There's a USB Mass Storage class driver, which providesa different solution for interoperability with systems suchas MS-Windows and MacOS.That <emphasis>File-backed Storage</emphasis> driver uses afile or block device as backing store for a drive,like the <filename>loop</filename> driver.The USB host uses the BBB, CB, or CBI versions of the massstorage class specification, using transparent SCSI commandsto access the data from the backing store.</para><para>There's a "serial line" driver, useful for TTY styleoperation over USB.The latest version of that driver supports CDC ACM styleoperation, like a USB modem, and so on most hardware it caninteroperate easily with MS-Windows.One interesting use of that driver is in boot firmware (like a BIOS),which can sometimes use that model with very small systems withoutreal serial lines.</para><para>Support for other kinds of gadget is expected tobe developed and contributedover time, as this driver framework evolves.</para></chapter><chapter id="otg"><title>USB On-The-GO (OTG)</title><para>USB OTG support on Linux 2.6 was initially developedby Texas Instruments for<ulink url="http://www.omap.com">OMAP</ulink> 16xx and 17xxseries processors.Other OTG systems should work in similar ways, but thehardware level details could be very different.</para> <para>Systems need specialized hardware support to implement OTG,notably including a special <emphasis>Mini-AB</emphasis> jackand associated transciever to support <emphasis>Dual-Role</emphasis>operation:they can act either as a host, using the standardLinux-USB host side driver stack,or as a peripheral, using this "gadget" framework.To do that, the system software relies on small additionsto those programming interfaces,and on a new internal component (here called an "OTG Controller")affecting which driver stack connects to the OTG port.In each role, the system can re-use the existing pool ofhardware-neutral drivers, layered on top of the controllerdriver interfaces (<emphasis>usb_bus</emphasis> or<emphasis>usb_gadget</emphasis>).Such drivers need at most minor changes, and most of the callsadded to support OTG can also benefit non-OTG products.</para><itemizedlist>    <listitem><para>Gadget drivers test the <emphasis>is_otg</emphasis>	flag, and use it to determine whether or not to include	an OTG descriptor in each of their configurations.	</para></listitem>    <listitem><para>Gadget drivers may need changes to support the	two new OTG protocols, exposed in new gadget attributes	such as <emphasis>b_hnp_enable</emphasis> flag.	HNP support should be reported through a user interface	(two LEDs could suffice), and is triggered in some cases	when the host suspends the peripheral.	SRP support can be user-initiated just like remote wakeup,	probably by pressing the same button.	</para></listitem>    <listitem><para>On the host side, USB device drivers need	to be taught to trigger HNP at appropriate moments, using	<function>usb_suspend_device()</function>.	That also conserves battery power, which is useful even	for non-OTG configurations.	</para></listitem>    <listitem><para>Also on the host side, a driver must support the	OTG "Targeted Peripheral List".  That's just a whitelist,	used to reject peripherals not supported with a given	Linux OTG host.	<emphasis>This whitelist is product-specific;	each product must modify <filename>otg_whitelist.h</filename>	to match its interoperability specification.	</emphasis>	</para>	<para>Non-OTG Linux hosts, like PCs and workstations,	normally have some solution for adding drivers, so that	peripherals that aren't recognized can eventually be supported.	That approach is unreasonable for consumer products that may	never have their firmware upgraded, and where it's usually	unrealistic to expect traditional PC/workstation/server kinds	of support model to work.	For example, it's often impractical to change device firmware	once the product has been distributed, so driver bugs can't	normally be fixed if they're found after shipment.	</para></listitem></itemizedlist><para>Additional changes are needed below those hardware-neutral<emphasis>usb_bus</emphasis> and <emphasis>usb_gadget</emphasis>driver interfaces; those aren't discussed here in any detail.Those affect the hardware-specific code for each USB Host or Peripheralcontroller, and how the HCD initializes (since OTG can be active onlyon a single port).They also involve what may be called an <emphasis>OTG ControllerDriver</emphasis>, managing the OTG transceiver and the OTG statemachine logic as well as much of the root hub behavior for theOTG port.The OTG controller driver needs to activate and deactivate USBcontrollers depending on the relevant device role.Some related changes were needed inside usbcore, so that itcan identify OTG-capable devices and respond appropriatelyto HNP or SRP protocols.</para> </chapter></book><!--	vim:syntax=sgml:sw=4-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -