1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>struct usb_gadget_driver</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="USB Gadget API for Linux"><link rel="up" href="core.html" title="Core Objects and Methods"><link rel="prev" href="API-usb-gadget-disconnect.html" title="usb_gadget_disconnect"><link rel="next" href="API-usb-gadget-probe-driver.html" title="usb_gadget_probe_driver"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">struct usb_gadget_driver</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-usb-gadget-disconnect.html">Prev</a> </td><th width="60%" align="center">Core Objects and Methods</th><td width="20%" align="right"> <a accesskey="n" href="API-usb-gadget-probe-driver.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-struct-usb-gadget-driver"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>struct usb_gadget_driver — 2 driver for usb 'slave' devices 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="programlisting"> 4struct usb_gadget_driver { 5 char * function; 6 enum usb_device_speed max_speed; 7 int (* bind) (struct usb_gadget *gadget,struct usb_gadget_driver *driver); 8 void (* unbind) (struct usb_gadget *); 9 int (* setup) (struct usb_gadget *,const struct usb_ctrlrequest *); 10 void (* disconnect) (struct usb_gadget *); 11 void (* suspend) (struct usb_gadget *); 12 void (* resume) (struct usb_gadget *); 13 void (* reset) (struct usb_gadget *); 14 struct device_driver driver; 15}; </pre></div><div class="refsect1"><a name="idp1124187780"></a><h2>Members</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">function</span></dt><dd><p> 16 String describing the gadget's function 17 </p></dd><dt><span class="term">max_speed</span></dt><dd><p> 18 Highest speed the driver handles. 19 </p></dd><dt><span class="term">bind</span></dt><dd><p> 20 the driver's bind callback 21 </p></dd><dt><span class="term">unbind</span></dt><dd><p> 22 Invoked when the driver is unbound from a gadget, 23 usually from rmmod (after a disconnect is reported). 24 Called in a context that permits sleeping. 25 </p></dd><dt><span class="term">setup</span></dt><dd><p> 26 Invoked for ep0 control requests that aren't handled by 27 the hardware level driver. Most calls must be handled by 28 the gadget driver, including descriptor and configuration 29 management. The 16 bit members of the setup data are in 30 USB byte order. Called in_interrupt; this may not sleep. Driver 31 queues a response to ep0, or returns negative to stall. 32 </p></dd><dt><span class="term">disconnect</span></dt><dd><p> 33 Invoked after all transfers have been stopped, 34 when the host is disconnected. May be called in_interrupt; this 35 may not sleep. Some devices can't detect disconnect, so this might 36 not be called except as part of controller shutdown. 37 </p></dd><dt><span class="term">suspend</span></dt><dd><p> 38 Invoked on USB suspend. May be called in_interrupt. 39 </p></dd><dt><span class="term">resume</span></dt><dd><p> 40 Invoked on USB resume. May be called in_interrupt. 41 </p></dd><dt><span class="term">reset</span></dt><dd><p> 42 Invoked on USB bus reset. It is mandatory for all gadget drivers 43 and should be called in_interrupt. 44 </p></dd><dt><span class="term">driver</span></dt><dd><p> 45 Driver model state for this driver. 46 </p></dd></dl></div></div><div class="refsect1"><a name="idp1124196052"></a><h2>Description</h2><p> 47 Devices are disabled till a gadget driver successfully <code class="function">bind</code>s, which 48 means the driver will handle <code class="function">setup</code> requests needed to enumerate (and 49 meet <span class="quote">“<span class="quote">chapter 9</span>”</span> requirements) then do some useful work. 50 </p><p> 51 52 If gadget->is_otg is true, the gadget driver must provide an OTG 53 descriptor during enumeration, or else fail the <code class="function">bind</code> call. In such 54 cases, no USB traffic may flow until both <code class="function">bind</code> returns without 55 having called <code class="function">usb_gadget_disconnect</code>, and the USB host stack has 56 initialized. 57 </p><p> 58 59 Drivers use hardware-specific knowledge to configure the usb hardware. 60 endpoint addressing is only one of several hardware characteristics that 61 are in descriptors the ep0 implementation returns from <code class="function">setup</code> calls. 62 </p><p> 63 64 Except for ep0 implementation, most driver code shouldn't need change to 65 run on top of different usb controllers. It'll use endpoints set up by 66 that ep0 implementation. 67 </p><p> 68 69 The usb controller driver handles a few standard usb requests. Those 70 include set_address, and feature flags for devices, interfaces, and 71 endpoints (the get_status, set_feature, and clear_feature requests). 72 </p><p> 73 74 Accordingly, the driver's <code class="function">setup</code> callback must always implement all 75 get_descriptor requests, returning at least a device descriptor and 76 a configuration descriptor. Drivers must make sure the endpoint 77 descriptors match any hardware constraints. Some hardware also constrains 78 other descriptors. (The pxa250 allows only configurations 1, 2, or 3). 79 </p><p> 80 81 The driver's <code class="function">setup</code> callback must also implement set_configuration, 82 and should also implement set_interface, get_configuration, and 83 get_interface. Setting a configuration (or interface) is where 84 endpoints should be activated or (config 0) shut down. 85 </p><p> 86 87 (Note that only the default control endpoint is supported. Neither 88 hosts nor devices generally support control traffic except to ep0.) 89 </p><p> 90 91 Most devices will ignore USB suspend/resume operations, and so will 92 not provide those callbacks. However, some may need to change modes 93 when the host is not longer directing those activities. For example, 94 local controls (buttons, dials, etc) may need to be re-enabled since 95 the (remote) host can't do that any longer; or an error state might 96 be cleared, to make the device behave identically whether or not 97 power is maintained. 98</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-usb-gadget-disconnect.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="core.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-usb-gadget-probe-driver.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">usb_gadget_disconnect</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">usb_gadget_probe_driver</span></td></tr></table></div></body></html> 99