pxa25x_udc.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  1. /*
  2. * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
  3. *
  4. * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
  5. * Copyright (C) 2003 Robert Schwebel, Pengutronix
  6. * Copyright (C) 2003 Benedikt Spranger, Pengutronix
  7. * Copyright (C) 2003 David Brownell
  8. * Copyright (C) 2003 Joshua Wise
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. /* #define VERBOSE_DEBUG */
  26. #include <linux/device.h>
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/ioport.h>
  30. #include <linux/types.h>
  31. #include <linux/errno.h>
  32. #include <linux/delay.h>
  33. #include <linux/slab.h>
  34. #include <linux/init.h>
  35. #include <linux/timer.h>
  36. #include <linux/list.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/mm.h>
  39. #include <linux/platform_device.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/irq.h>
  42. #include <linux/clk.h>
  43. #include <linux/err.h>
  44. #include <linux/seq_file.h>
  45. #include <linux/debugfs.h>
  46. #include <linux/io.h>
  47. #include <asm/byteorder.h>
  48. #include <asm/dma.h>
  49. #include <asm/gpio.h>
  50. #include <asm/system.h>
  51. #include <asm/mach-types.h>
  52. #include <asm/unaligned.h>
  53. #include <linux/usb/ch9.h>
  54. #include <linux/usb/gadget.h>
  55. #include <linux/usb/otg.h>
  56. /*
  57. * This driver is PXA25x only. Grab the right register definitions.
  58. */
  59. #ifdef CONFIG_ARCH_PXA
  60. #include <mach/pxa25x-udc.h>
  61. #endif
  62. #include <asm/mach/udc_pxa2xx.h>
  63. /*
  64. * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
  65. * series processors. The UDC for the IXP 4xx series is very similar.
  66. * There are fifteen endpoints, in addition to ep0.
  67. *
  68. * Such controller drivers work with a gadget driver. The gadget driver
  69. * returns descriptors, implements configuration and data protocols used
  70. * by the host to interact with this device, and allocates endpoints to
  71. * the different protocol interfaces. The controller driver virtualizes
  72. * usb hardware so that the gadget drivers will be more portable.
  73. *
  74. * This UDC hardware wants to implement a bit too much USB protocol, so
  75. * it constrains the sorts of USB configuration change events that work.
  76. * The errata for these chips are misleading; some "fixed" bugs from
  77. * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
  78. *
  79. * Note that the UDC hardware supports DMA (except on IXP) but that's
  80. * not used here. IN-DMA (to host) is simple enough, when the data is
  81. * suitably aligned (16 bytes) ... the network stack doesn't do that,
  82. * other software can. OUT-DMA is buggy in most chip versions, as well
  83. * as poorly designed (data toggle not automatic). So this driver won't
  84. * bother using DMA. (Mostly-working IN-DMA support was available in
  85. * kernels before 2.6.23, but was never enabled or well tested.)
  86. */
  87. #define DRIVER_VERSION "30-June-2007"
  88. #define DRIVER_DESC "PXA 25x USB Device Controller driver"
  89. static const char driver_name [] = "pxa25x_udc";
  90. static const char ep0name [] = "ep0";
  91. #ifdef CONFIG_ARCH_IXP4XX
  92. /* cpu-specific register addresses are compiled in to this code */
  93. #ifdef CONFIG_ARCH_PXA
  94. #error "Can't configure both IXP and PXA"
  95. #endif
  96. /* IXP doesn't yet support <linux/clk.h> */
  97. #define clk_get(dev,name) NULL
  98. #define clk_enable(clk) do { } while (0)
  99. #define clk_disable(clk) do { } while (0)
  100. #define clk_put(clk) do { } while (0)
  101. #endif
  102. #include "pxa25x_udc.h"
  103. #ifdef CONFIG_USB_PXA25X_SMALL
  104. #define SIZE_STR " (small)"
  105. #else
  106. #define SIZE_STR ""
  107. #endif
  108. /* ---------------------------------------------------------------------------
  109. * endpoint related parts of the api to the usb controller hardware,
  110. * used by gadget driver; and the inner talker-to-hardware core.
  111. * ---------------------------------------------------------------------------
  112. */
  113. static void pxa25x_ep_fifo_flush (struct usb_ep *ep);
  114. static void nuke (struct pxa25x_ep *, int status);
  115. /* one GPIO should be used to detect VBUS from the host */
  116. static int is_vbus_present(void)
  117. {
  118. struct pxa2xx_udc_mach_info *mach = the_controller->mach;
  119. if (gpio_is_valid(mach->gpio_vbus)) {
  120. int value = gpio_get_value(mach->gpio_vbus);
  121. if (mach->gpio_vbus_inverted)
  122. return !value;
  123. else
  124. return !!value;
  125. }
  126. if (mach->udc_is_connected)
  127. return mach->udc_is_connected();
  128. return 1;
  129. }
  130. /* one GPIO should control a D+ pullup, so host sees this device (or not) */
  131. static void pullup_off(void)
  132. {
  133. struct pxa2xx_udc_mach_info *mach = the_controller->mach;
  134. int off_level = mach->gpio_pullup_inverted;
  135. if (gpio_is_valid(mach->gpio_pullup))
  136. gpio_set_value(mach->gpio_pullup, off_level);
  137. else if (mach->udc_command)
  138. mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
  139. }
  140. static void pullup_on(void)
  141. {
  142. struct pxa2xx_udc_mach_info *mach = the_controller->mach;
  143. int on_level = !mach->gpio_pullup_inverted;
  144. if (gpio_is_valid(mach->gpio_pullup))
  145. gpio_set_value(mach->gpio_pullup, on_level);
  146. else if (mach->udc_command)
  147. mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
  148. }
  149. static void pio_irq_enable(int bEndpointAddress)
  150. {
  151. bEndpointAddress &= 0xf;
  152. if (bEndpointAddress < 8)
  153. UICR0 &= ~(1 << bEndpointAddress);
  154. else {
  155. bEndpointAddress -= 8;
  156. UICR1 &= ~(1 << bEndpointAddress);
  157. }
  158. }
  159. static void pio_irq_disable(int bEndpointAddress)
  160. {
  161. bEndpointAddress &= 0xf;
  162. if (bEndpointAddress < 8)
  163. UICR0 |= 1 << bEndpointAddress;
  164. else {
  165. bEndpointAddress -= 8;
  166. UICR1 |= 1 << bEndpointAddress;
  167. }
  168. }
  169. /* The UDCCR reg contains mask and interrupt status bits,
  170. * so using '|=' isn't safe as it may ack an interrupt.
  171. */
  172. #define UDCCR_MASK_BITS (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
  173. static inline void udc_set_mask_UDCCR(int mask)
  174. {
  175. UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
  176. }
  177. static inline void udc_clear_mask_UDCCR(int mask)
  178. {
  179. UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
  180. }
  181. static inline void udc_ack_int_UDCCR(int mask)
  182. {
  183. /* udccr contains the bits we dont want to change */
  184. __u32 udccr = UDCCR & UDCCR_MASK_BITS;
  185. UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
  186. }
  187. /*
  188. * endpoint enable/disable
  189. *
  190. * we need to verify the descriptors used to enable endpoints. since pxa25x
  191. * endpoint configurations are fixed, and are pretty much always enabled,
  192. * there's not a lot to manage here.
  193. *
  194. * because pxa25x can't selectively initialize bulk (or interrupt) endpoints,
  195. * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
  196. * for a single interface (with only the default altsetting) and for gadget
  197. * drivers that don't halt endpoints (not reset by set_interface). that also
  198. * means that if you use ISO, you must violate the USB spec rule that all
  199. * iso endpoints must be in non-default altsettings.
  200. */
  201. static int pxa25x_ep_enable (struct usb_ep *_ep,
  202. const struct usb_endpoint_descriptor *desc)
  203. {
  204. struct pxa25x_ep *ep;
  205. struct pxa25x_udc *dev;
  206. ep = container_of (_ep, struct pxa25x_ep, ep);
  207. if (!_ep || !desc || ep->desc || _ep->name == ep0name
  208. || desc->bDescriptorType != USB_DT_ENDPOINT
  209. || ep->bEndpointAddress != desc->bEndpointAddress
  210. || ep->fifo_size < le16_to_cpu
  211. (desc->wMaxPacketSize)) {
  212. DMSG("%s, bad ep or descriptor\n", __func__);
  213. return -EINVAL;
  214. }
  215. /* xfer types must match, except that interrupt ~= bulk */
  216. if (ep->bmAttributes != desc->bmAttributes
  217. && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
  218. && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
  219. DMSG("%s, %s type mismatch\n", __func__, _ep->name);
  220. return -EINVAL;
  221. }
  222. /* hardware _could_ do smaller, but driver doesn't */
  223. if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
  224. && le16_to_cpu (desc->wMaxPacketSize)
  225. != BULK_FIFO_SIZE)
  226. || !desc->wMaxPacketSize) {
  227. DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
  228. return -ERANGE;
  229. }
  230. dev = ep->dev;
  231. if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
  232. DMSG("%s, bogus device state\n", __func__);
  233. return -ESHUTDOWN;
  234. }
  235. ep->desc = desc;
  236. ep->stopped = 0;
  237. ep->pio_irqs = 0;
  238. ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
  239. /* flush fifo (mostly for OUT buffers) */
  240. pxa25x_ep_fifo_flush (_ep);
  241. /* ... reset halt state too, if we could ... */
  242. DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
  243. return 0;
  244. }
  245. static int pxa25x_ep_disable (struct usb_ep *_ep)
  246. {
  247. struct pxa25x_ep *ep;
  248. unsigned long flags;
  249. ep = container_of (_ep, struct pxa25x_ep, ep);
  250. if (!_ep || !ep->desc) {
  251. DMSG("%s, %s not enabled\n", __func__,
  252. _ep ? ep->ep.name : NULL);
  253. return -EINVAL;
  254. }
  255. local_irq_save(flags);
  256. nuke (ep, -ESHUTDOWN);
  257. /* flush fifo (mostly for IN buffers) */
  258. pxa25x_ep_fifo_flush (_ep);
  259. ep->desc = NULL;
  260. ep->stopped = 1;
  261. local_irq_restore(flags);
  262. DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
  263. return 0;
  264. }
  265. /*-------------------------------------------------------------------------*/
  266. /* for the pxa25x, these can just wrap kmalloc/kfree. gadget drivers
  267. * must still pass correctly initialized endpoints, since other controller
  268. * drivers may care about how it's currently set up (dma issues etc).
  269. */
  270. /*
  271. * pxa25x_ep_alloc_request - allocate a request data structure
  272. */
  273. static struct usb_request *
  274. pxa25x_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
  275. {
  276. struct pxa25x_request *req;
  277. req = kzalloc(sizeof(*req), gfp_flags);
  278. if (!req)
  279. return NULL;
  280. INIT_LIST_HEAD (&req->queue);
  281. return &req->req;
  282. }
  283. /*
  284. * pxa25x_ep_free_request - deallocate a request data structure
  285. */
  286. static void
  287. pxa25x_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
  288. {
  289. struct pxa25x_request *req;
  290. req = container_of (_req, struct pxa25x_request, req);
  291. WARN_ON(!list_empty (&req->queue));
  292. kfree(req);
  293. }
  294. /*-------------------------------------------------------------------------*/
  295. /*
  296. * done - retire a request; caller blocked irqs
  297. */
  298. static void done(struct pxa25x_ep *ep, struct pxa25x_request *req, int status)
  299. {
  300. unsigned stopped = ep->stopped;
  301. list_del_init(&req->queue);
  302. if (likely (req->req.status == -EINPROGRESS))
  303. req->req.status = status;
  304. else
  305. status = req->req.status;
  306. if (status && status != -ESHUTDOWN)
  307. DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n",
  308. ep->ep.name, &req->req, status,
  309. req->req.actual, req->req.length);
  310. /* don't modify queue heads during completion callback */
  311. ep->stopped = 1;
  312. req->req.complete(&ep->ep, &req->req);
  313. ep->stopped = stopped;
  314. }
  315. static inline void ep0_idle (struct pxa25x_udc *dev)
  316. {
  317. dev->ep0state = EP0_IDLE;
  318. }
  319. static int
  320. write_packet(volatile u32 *uddr, struct pxa25x_request *req, unsigned max)
  321. {
  322. u8 *buf;
  323. unsigned length, count;
  324. buf = req->req.buf + req->req.actual;
  325. prefetch(buf);
  326. /* how big will this packet be? */
  327. length = min(req->req.length - req->req.actual, max);
  328. req->req.actual += length;
  329. count = length;
  330. while (likely(count--))
  331. *uddr = *buf++;
  332. return length;
  333. }
  334. /*
  335. * write to an IN endpoint fifo, as many packets as possible.
  336. * irqs will use this to write the rest later.
  337. * caller guarantees at least one packet buffer is ready (or a zlp).
  338. */
  339. static int
  340. write_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
  341. {
  342. unsigned max;
  343. max = le16_to_cpu(ep->desc->wMaxPacketSize);
  344. do {
  345. unsigned count;
  346. int is_last, is_short;
  347. count = write_packet(ep->reg_uddr, req, max);
  348. /* last packet is usually short (or a zlp) */
  349. if (unlikely (count != max))
  350. is_last = is_short = 1;
  351. else {
  352. if (likely(req->req.length != req->req.actual)
  353. || req->req.zero)
  354. is_last = 0;
  355. else
  356. is_last = 1;
  357. /* interrupt/iso maxpacket may not fill the fifo */
  358. is_short = unlikely (max < ep->fifo_size);
  359. }
  360. DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n",
  361. ep->ep.name, count,
  362. is_last ? "/L" : "", is_short ? "/S" : "",
  363. req->req.length - req->req.actual, req);
  364. /* let loose that packet. maybe try writing another one,
  365. * double buffering might work. TSP, TPC, and TFS
  366. * bit values are the same for all normal IN endpoints.
  367. */
  368. *ep->reg_udccs = UDCCS_BI_TPC;
  369. if (is_short)
  370. *ep->reg_udccs = UDCCS_BI_TSP;
  371. /* requests complete when all IN data is in the FIFO */
  372. if (is_last) {
  373. done (ep, req, 0);
  374. if (list_empty(&ep->queue))
  375. pio_irq_disable (ep->bEndpointAddress);
  376. return 1;
  377. }
  378. // TODO experiment: how robust can fifo mode tweaking be?
  379. // double buffering is off in the default fifo mode, which
  380. // prevents TFS from being set here.
  381. } while (*ep->reg_udccs & UDCCS_BI_TFS);
  382. return 0;
  383. }
  384. /* caller asserts req->pending (ep0 irq status nyet cleared); starts
  385. * ep0 data stage. these chips want very simple state transitions.
  386. */
  387. static inline
  388. void ep0start(struct pxa25x_udc *dev, u32 flags, const char *tag)
  389. {
  390. UDCCS0 = flags|UDCCS0_SA|UDCCS0_OPR;
  391. USIR0 = USIR0_IR0;
  392. dev->req_pending = 0;
  393. DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
  394. __func__, tag, UDCCS0, flags);
  395. }
  396. static int
  397. write_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
  398. {
  399. unsigned count;
  400. int is_short;
  401. count = write_packet(&UDDR0, req, EP0_FIFO_SIZE);
  402. ep->dev->stats.write.bytes += count;
  403. /* last packet "must be" short (or a zlp) */
  404. is_short = (count != EP0_FIFO_SIZE);
  405. DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
  406. req->req.length - req->req.actual, req);
  407. if (unlikely (is_short)) {
  408. if (ep->dev->req_pending)
  409. ep0start(ep->dev, UDCCS0_IPR, "short IN");
  410. else
  411. UDCCS0 = UDCCS0_IPR;
  412. count = req->req.length;
  413. done (ep, req, 0);
  414. ep0_idle(ep->dev);
  415. #ifndef CONFIG_ARCH_IXP4XX
  416. #if 1
  417. /* This seems to get rid of lost status irqs in some cases:
  418. * host responds quickly, or next request involves config
  419. * change automagic, or should have been hidden, or ...
  420. *
  421. * FIXME get rid of all udelays possible...
  422. */
  423. if (count >= EP0_FIFO_SIZE) {
  424. count = 100;
  425. do {
  426. if ((UDCCS0 & UDCCS0_OPR) != 0) {
  427. /* clear OPR, generate ack */
  428. UDCCS0 = UDCCS0_OPR;
  429. break;
  430. }
  431. count--;
  432. udelay(1);
  433. } while (count);
  434. }
  435. #endif
  436. #endif
  437. } else if (ep->dev->req_pending)
  438. ep0start(ep->dev, 0, "IN");
  439. return is_short;
  440. }
  441. /*
  442. * read_fifo - unload packet(s) from the fifo we use for usb OUT
  443. * transfers and put them into the request. caller should have made
  444. * sure there's at least one packet ready.
  445. *
  446. * returns true if the request completed because of short packet or the
  447. * request buffer having filled (and maybe overran till end-of-packet).
  448. */
  449. static int
  450. read_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
  451. {
  452. for (;;) {
  453. u32 udccs;
  454. u8 *buf;
  455. unsigned bufferspace, count, is_short;
  456. /* make sure there's a packet in the FIFO.
  457. * UDCCS_{BO,IO}_RPC are all the same bit value.
  458. * UDCCS_{BO,IO}_RNE are all the same bit value.
  459. */
  460. udccs = *ep->reg_udccs;
  461. if (unlikely ((udccs & UDCCS_BO_RPC) == 0))
  462. break;
  463. buf = req->req.buf + req->req.actual;
  464. prefetchw(buf);
  465. bufferspace = req->req.length - req->req.actual;
  466. /* read all bytes from this packet */
  467. if (likely (udccs & UDCCS_BO_RNE)) {
  468. count = 1 + (0x0ff & *ep->reg_ubcr);
  469. req->req.actual += min (count, bufferspace);
  470. } else /* zlp */
  471. count = 0;
  472. is_short = (count < ep->ep.maxpacket);
  473. DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n",
  474. ep->ep.name, udccs, count,
  475. is_short ? "/S" : "",
  476. req, req->req.actual, req->req.length);
  477. while (likely (count-- != 0)) {
  478. u8 byte = (u8) *ep->reg_uddr;
  479. if (unlikely (bufferspace == 0)) {
  480. /* this happens when the driver's buffer
  481. * is smaller than what the host sent.
  482. * discard the extra data.
  483. */
  484. if (req->req.status != -EOVERFLOW)
  485. DMSG("%s overflow %d\n",
  486. ep->ep.name, count);
  487. req->req.status = -EOVERFLOW;
  488. } else {
  489. *buf++ = byte;
  490. bufferspace--;
  491. }
  492. }
  493. *ep->reg_udccs = UDCCS_BO_RPC;
  494. /* RPC/RSP/RNE could now reflect the other packet buffer */
  495. /* iso is one request per packet */
  496. if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
  497. if (udccs & UDCCS_IO_ROF)
  498. req->req.status = -EHOSTUNREACH;
  499. /* more like "is_done" */
  500. is_short = 1;
  501. }
  502. /* completion */
  503. if (is_short || req->req.actual == req->req.length) {
  504. done (ep, req, 0);
  505. if (list_empty(&ep->queue))
  506. pio_irq_disable (ep->bEndpointAddress);
  507. return 1;
  508. }
  509. /* finished that packet. the next one may be waiting... */
  510. }
  511. return 0;
  512. }
  513. /*
  514. * special ep0 version of the above. no UBCR0 or double buffering; status
  515. * handshaking is magic. most device protocols don't need control-OUT.
  516. * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
  517. * protocols do use them.
  518. */
  519. static int
  520. read_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
  521. {
  522. u8 *buf, byte;
  523. unsigned bufferspace;
  524. buf = req->req.buf + req->req.actual;
  525. bufferspace = req->req.length - req->req.actual;
  526. while (UDCCS0 & UDCCS0_RNE) {
  527. byte = (u8) UDDR0;
  528. if (unlikely (bufferspace == 0)) {
  529. /* this happens when the driver's buffer
  530. * is smaller than what the host sent.
  531. * discard the extra data.
  532. */
  533. if (req->req.status != -EOVERFLOW)
  534. DMSG("%s overflow\n", ep->ep.name);
  535. req->req.status = -EOVERFLOW;
  536. } else {
  537. *buf++ = byte;
  538. req->req.actual++;
  539. bufferspace--;
  540. }
  541. }
  542. UDCCS0 = UDCCS0_OPR | UDCCS0_IPR;
  543. /* completion */
  544. if (req->req.actual >= req->req.length)
  545. return 1;
  546. /* finished that packet. the next one may be waiting... */
  547. return 0;
  548. }
  549. /*-------------------------------------------------------------------------*/
  550. static int
  551. pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
  552. {
  553. struct pxa25x_request *req;
  554. struct pxa25x_ep *ep;
  555. struct pxa25x_udc *dev;
  556. unsigned long flags;
  557. req = container_of(_req, struct pxa25x_request, req);
  558. if (unlikely (!_req || !_req->complete || !_req->buf
  559. || !list_empty(&req->queue))) {
  560. DMSG("%s, bad params\n", __func__);
  561. return -EINVAL;
  562. }
  563. ep = container_of(_ep, struct pxa25x_ep, ep);
  564. if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
  565. DMSG("%s, bad ep\n", __func__);
  566. return -EINVAL;
  567. }
  568. dev = ep->dev;
  569. if (unlikely (!dev->driver
  570. || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
  571. DMSG("%s, bogus device state\n", __func__);
  572. return -ESHUTDOWN;
  573. }
  574. /* iso is always one packet per request, that's the only way
  575. * we can report per-packet status. that also helps with dma.
  576. */
  577. if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
  578. && req->req.length > le16_to_cpu
  579. (ep->desc->wMaxPacketSize)))
  580. return -EMSGSIZE;
  581. DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
  582. _ep->name, _req, _req->length, _req->buf);
  583. local_irq_save(flags);
  584. _req->status = -EINPROGRESS;
  585. _req->actual = 0;
  586. /* kickstart this i/o queue? */
  587. if (list_empty(&ep->queue) && !ep->stopped) {
  588. if (ep->desc == NULL/* ep0 */) {
  589. unsigned length = _req->length;
  590. switch (dev->ep0state) {
  591. case EP0_IN_DATA_PHASE:
  592. dev->stats.write.ops++;
  593. if (write_ep0_fifo(ep, req))
  594. req = NULL;
  595. break;
  596. case EP0_OUT_DATA_PHASE:
  597. dev->stats.read.ops++;
  598. /* messy ... */
  599. if (dev->req_config) {
  600. DBG(DBG_VERBOSE, "ep0 config ack%s\n",
  601. dev->has_cfr ? "" : " raced");
  602. if (dev->has_cfr)
  603. UDCCFR = UDCCFR_AREN|UDCCFR_ACM
  604. |UDCCFR_MB1;
  605. done(ep, req, 0);
  606. dev->ep0state = EP0_END_XFER;
  607. local_irq_restore (flags);
  608. return 0;
  609. }
  610. if (dev->req_pending)
  611. ep0start(dev, UDCCS0_IPR, "OUT");
  612. if (length == 0 || ((UDCCS0 & UDCCS0_RNE) != 0
  613. && read_ep0_fifo(ep, req))) {
  614. ep0_idle(dev);
  615. done(ep, req, 0);
  616. req = NULL;
  617. }
  618. break;
  619. default:
  620. DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
  621. local_irq_restore (flags);
  622. return -EL2HLT;
  623. }
  624. /* can the FIFO can satisfy the request immediately? */
  625. } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
  626. if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
  627. && write_fifo(ep, req))
  628. req = NULL;
  629. } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
  630. && read_fifo(ep, req)) {
  631. req = NULL;
  632. }
  633. if (likely (req && ep->desc))
  634. pio_irq_enable(ep->bEndpointAddress);
  635. }
  636. /* pio or dma irq handler advances the queue. */
  637. if (likely(req != NULL))
  638. list_add_tail(&req->queue, &ep->queue);
  639. local_irq_restore(flags);
  640. return 0;
  641. }
  642. /*
  643. * nuke - dequeue ALL requests
  644. */
  645. static void nuke(struct pxa25x_ep *ep, int status)
  646. {
  647. struct pxa25x_request *req;
  648. /* called with irqs blocked */
  649. while (!list_empty(&ep->queue)) {
  650. req = list_entry(ep->queue.next,
  651. struct pxa25x_request,
  652. queue);
  653. done(ep, req, status);
  654. }
  655. if (ep->desc)
  656. pio_irq_disable (ep->bEndpointAddress);
  657. }
  658. /* dequeue JUST ONE request */
  659. static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
  660. {
  661. struct pxa25x_ep *ep;
  662. struct pxa25x_request *req;
  663. unsigned long flags;
  664. ep = container_of(_ep, struct pxa25x_ep, ep);
  665. if (!_ep || ep->ep.name == ep0name)
  666. return -EINVAL;
  667. local_irq_save(flags);
  668. /* make sure it's actually queued on this endpoint */
  669. list_for_each_entry (req, &ep->queue, queue) {
  670. if (&req->req == _req)
  671. break;
  672. }
  673. if (&req->req != _req) {
  674. local_irq_restore(flags);
  675. return -EINVAL;
  676. }
  677. done(ep, req, -ECONNRESET);
  678. local_irq_restore(flags);
  679. return 0;
  680. }
  681. /*-------------------------------------------------------------------------*/
  682. static int pxa25x_ep_set_halt(struct usb_ep *_ep, int value)
  683. {
  684. struct pxa25x_ep *ep;
  685. unsigned long flags;
  686. ep = container_of(_ep, struct pxa25x_ep, ep);
  687. if (unlikely (!_ep
  688. || (!ep->desc && ep->ep.name != ep0name))
  689. || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
  690. DMSG("%s, bad ep\n", __func__);
  691. return -EINVAL;
  692. }
  693. if (value == 0) {
  694. /* this path (reset toggle+halt) is needed to implement
  695. * SET_INTERFACE on normal hardware. but it can't be
  696. * done from software on the PXA UDC, and the hardware
  697. * forgets to do it as part of SET_INTERFACE automagic.
  698. */
  699. DMSG("only host can clear %s halt\n", _ep->name);
  700. return -EROFS;
  701. }
  702. local_irq_save(flags);
  703. if ((ep->bEndpointAddress & USB_DIR_IN) != 0
  704. && ((*ep->reg_udccs & UDCCS_BI_TFS) == 0
  705. || !list_empty(&ep->queue))) {
  706. local_irq_restore(flags);
  707. return -EAGAIN;
  708. }
  709. /* FST bit is the same for control, bulk in, bulk out, interrupt in */
  710. *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF;
  711. /* ep0 needs special care */
  712. if (!ep->desc) {
  713. start_watchdog(ep->dev);
  714. ep->dev->req_pending = 0;
  715. ep->dev->ep0state = EP0_STALL;
  716. /* and bulk/intr endpoints like dropping stalls too */
  717. } else {
  718. unsigned i;
  719. for (i = 0; i < 1000; i += 20) {
  720. if (*ep->reg_udccs & UDCCS_BI_SST)
  721. break;
  722. udelay(20);
  723. }
  724. }
  725. local_irq_restore(flags);
  726. DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
  727. return 0;
  728. }
  729. static int pxa25x_ep_fifo_status(struct usb_ep *_ep)
  730. {
  731. struct pxa25x_ep *ep;
  732. ep = container_of(_ep, struct pxa25x_ep, ep);
  733. if (!_ep) {
  734. DMSG("%s, bad ep\n", __func__);
  735. return -ENODEV;
  736. }
  737. /* pxa can't report unclaimed bytes from IN fifos */
  738. if ((ep->bEndpointAddress & USB_DIR_IN) != 0)
  739. return -EOPNOTSUPP;
  740. if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
  741. || (*ep->reg_udccs & UDCCS_BO_RFS) == 0)
  742. return 0;
  743. else
  744. return (*ep->reg_ubcr & 0xfff) + 1;
  745. }
  746. static void pxa25x_ep_fifo_flush(struct usb_ep *_ep)
  747. {
  748. struct pxa25x_ep *ep;
  749. ep = container_of(_ep, struct pxa25x_ep, ep);
  750. if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
  751. DMSG("%s, bad ep\n", __func__);
  752. return;
  753. }
  754. /* toggle and halt bits stay unchanged */
  755. /* for OUT, just read and discard the FIFO contents. */
  756. if ((ep->bEndpointAddress & USB_DIR_IN) == 0) {
  757. while (((*ep->reg_udccs) & UDCCS_BO_RNE) != 0)
  758. (void) *ep->reg_uddr;
  759. return;
  760. }
  761. /* most IN status is the same, but ISO can't stall */
  762. *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
  763. | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
  764. ? 0 : UDCCS_BI_SST);
  765. }
  766. static struct usb_ep_ops pxa25x_ep_ops = {
  767. .enable = pxa25x_ep_enable,
  768. .disable = pxa25x_ep_disable,
  769. .alloc_request = pxa25x_ep_alloc_request,
  770. .free_request = pxa25x_ep_free_request,
  771. .queue = pxa25x_ep_queue,
  772. .dequeue = pxa25x_ep_dequeue,
  773. .set_halt = pxa25x_ep_set_halt,
  774. .fifo_status = pxa25x_ep_fifo_status,
  775. .fifo_flush = pxa25x_ep_fifo_flush,
  776. };
  777. /* ---------------------------------------------------------------------------
  778. * device-scoped parts of the api to the usb controller hardware
  779. * ---------------------------------------------------------------------------
  780. */
  781. static int pxa25x_udc_get_frame(struct usb_gadget *_gadget)
  782. {
  783. return ((UFNRH & 0x07) << 8) | (UFNRL & 0xff);
  784. }
  785. static int pxa25x_udc_wakeup(struct usb_gadget *_gadget)
  786. {
  787. /* host may not have enabled remote wakeup */
  788. if ((UDCCS0 & UDCCS0_DRWF) == 0)
  789. return -EHOSTUNREACH;
  790. udc_set_mask_UDCCR(UDCCR_RSM);
  791. return 0;
  792. }
  793. static void stop_activity(struct pxa25x_udc *, struct usb_gadget_driver *);
  794. static void udc_enable (struct pxa25x_udc *);
  795. static void udc_disable(struct pxa25x_udc *);
  796. /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
  797. * in active use.
  798. */
  799. static int pullup(struct pxa25x_udc *udc)
  800. {
  801. int is_active = udc->vbus && udc->pullup && !udc->suspended;
  802. DMSG("%s\n", is_active ? "active" : "inactive");
  803. if (is_active) {
  804. if (!udc->active) {
  805. udc->active = 1;
  806. /* Enable clock for USB device */
  807. clk_enable(udc->clk);
  808. udc_enable(udc);
  809. }
  810. } else {
  811. if (udc->active) {
  812. if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
  813. DMSG("disconnect %s\n", udc->driver
  814. ? udc->driver->driver.name
  815. : "(no driver)");
  816. stop_activity(udc, udc->driver);
  817. }
  818. udc_disable(udc);
  819. /* Disable clock for USB device */
  820. clk_disable(udc->clk);
  821. udc->active = 0;
  822. }
  823. }
  824. return 0;
  825. }
  826. /* VBUS reporting logically comes from a transceiver */
  827. static int pxa25x_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
  828. {
  829. struct pxa25x_udc *udc;
  830. udc = container_of(_gadget, struct pxa25x_udc, gadget);
  831. udc->vbus = is_active;
  832. DMSG("vbus %s\n", is_active ? "supplied" : "inactive");
  833. pullup(udc);
  834. return 0;
  835. }
  836. /* drivers may have software control over D+ pullup */
  837. static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active)
  838. {
  839. struct pxa25x_udc *udc;
  840. udc = container_of(_gadget, struct pxa25x_udc, gadget);
  841. /* not all boards support pullup control */
  842. if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
  843. return -EOPNOTSUPP;
  844. udc->pullup = (is_active != 0);
  845. pullup(udc);
  846. return 0;
  847. }
  848. /* boards may consume current from VBUS, up to 100-500mA based on config.
  849. * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs
  850. * violate USB specs.
  851. */
  852. static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
  853. {
  854. struct pxa25x_udc *udc;
  855. udc = container_of(_gadget, struct pxa25x_udc, gadget);
  856. if (udc->transceiver)
  857. return otg_set_power(udc->transceiver, mA);
  858. return -EOPNOTSUPP;
  859. }
  860. static const struct usb_gadget_ops pxa25x_udc_ops = {
  861. .get_frame = pxa25x_udc_get_frame,
  862. .wakeup = pxa25x_udc_wakeup,
  863. .vbus_session = pxa25x_udc_vbus_session,
  864. .pullup = pxa25x_udc_pullup,
  865. .vbus_draw = pxa25x_udc_vbus_draw,
  866. };
  867. /*-------------------------------------------------------------------------*/
  868. #ifdef CONFIG_USB_GADGET_DEBUG_FS
  869. static int
  870. udc_seq_show(struct seq_file *m, void *_d)
  871. {
  872. struct pxa25x_udc *dev = m->private;
  873. unsigned long flags;
  874. int i;
  875. u32 tmp;
  876. local_irq_save(flags);
  877. /* basic device status */
  878. seq_printf(m, DRIVER_DESC "\n"
  879. "%s version: %s\nGadget driver: %s\nHost %s\n\n",
  880. driver_name, DRIVER_VERSION SIZE_STR "(pio)",
  881. dev->driver ? dev->driver->driver.name : "(none)",
  882. is_vbus_present() ? "full speed" : "disconnected");
  883. /* registers for device and ep0 */
  884. seq_printf(m,
  885. "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
  886. UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
  887. tmp = UDCCR;
  888. seq_printf(m,
  889. "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
  890. (tmp & UDCCR_REM) ? " rem" : "",
  891. (tmp & UDCCR_RSTIR) ? " rstir" : "",
  892. (tmp & UDCCR_SRM) ? " srm" : "",
  893. (tmp & UDCCR_SUSIR) ? " susir" : "",
  894. (tmp & UDCCR_RESIR) ? " resir" : "",
  895. (tmp & UDCCR_RSM) ? " rsm" : "",
  896. (tmp & UDCCR_UDA) ? " uda" : "",
  897. (tmp & UDCCR_UDE) ? " ude" : "");
  898. tmp = UDCCS0;
  899. seq_printf(m,
  900. "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
  901. (tmp & UDCCS0_SA) ? " sa" : "",
  902. (tmp & UDCCS0_RNE) ? " rne" : "",
  903. (tmp & UDCCS0_FST) ? " fst" : "",
  904. (tmp & UDCCS0_SST) ? " sst" : "",
  905. (tmp & UDCCS0_DRWF) ? " dwrf" : "",
  906. (tmp & UDCCS0_FTF) ? " ftf" : "",
  907. (tmp & UDCCS0_IPR) ? " ipr" : "",
  908. (tmp & UDCCS0_OPR) ? " opr" : "");
  909. if (dev->has_cfr) {
  910. tmp = UDCCFR;
  911. seq_printf(m,
  912. "udccfr %02X =%s%s\n", tmp,
  913. (tmp & UDCCFR_AREN) ? " aren" : "",
  914. (tmp & UDCCFR_ACM) ? " acm" : "");
  915. }
  916. if (!is_vbus_present() || !dev->driver)
  917. goto done;
  918. seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
  919. dev->stats.write.bytes, dev->stats.write.ops,
  920. dev->stats.read.bytes, dev->stats.read.ops,
  921. dev->stats.irqs);
  922. /* dump endpoint queues */
  923. for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  924. struct pxa25x_ep *ep = &dev->ep [i];
  925. struct pxa25x_request *req;
  926. if (i != 0) {
  927. const struct usb_endpoint_descriptor *desc;
  928. desc = ep->desc;
  929. if (!desc)
  930. continue;
  931. tmp = *dev->ep [i].reg_udccs;
  932. seq_printf(m,
  933. "%s max %d %s udccs %02x irqs %lu\n",
  934. ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
  935. "pio", tmp, ep->pio_irqs);
  936. /* TODO translate all five groups of udccs bits! */
  937. } else /* ep0 should only have one transfer queued */
  938. seq_printf(m, "ep0 max 16 pio irqs %lu\n",
  939. ep->pio_irqs);
  940. if (list_empty(&ep->queue)) {
  941. seq_printf(m, "\t(nothing queued)\n");
  942. continue;
  943. }
  944. list_for_each_entry(req, &ep->queue, queue) {
  945. seq_printf(m,
  946. "\treq %p len %d/%d buf %p\n",
  947. &req->req, req->req.actual,
  948. req->req.length, req->req.buf);
  949. }
  950. }
  951. done:
  952. local_irq_restore(flags);
  953. return 0;
  954. }
  955. static int
  956. udc_debugfs_open(struct inode *inode, struct file *file)
  957. {
  958. return single_open(file, udc_seq_show, inode->i_private);
  959. }
  960. static const struct file_operations debug_fops = {
  961. .open = udc_debugfs_open,
  962. .read = seq_read,
  963. .llseek = seq_lseek,
  964. .release = single_release,
  965. .owner = THIS_MODULE,
  966. };
  967. #define create_debug_files(dev) \
  968. do { \
  969. dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
  970. S_IRUGO, NULL, dev, &debug_fops); \
  971. } while (0)
  972. #define remove_debug_files(dev) \
  973. do { \
  974. if (dev->debugfs_udc) \
  975. debugfs_remove(dev->debugfs_udc); \
  976. } while (0)
  977. #else /* !CONFIG_USB_GADGET_DEBUG_FILES */
  978. #define create_debug_files(dev) do {} while (0)
  979. #define remove_debug_files(dev) do {} while (0)
  980. #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
  981. /*-------------------------------------------------------------------------*/
  982. /*
  983. * udc_disable - disable USB device controller
  984. */
  985. static void udc_disable(struct pxa25x_udc *dev)
  986. {
  987. /* block all irqs */
  988. udc_set_mask_UDCCR(UDCCR_SRM|UDCCR_REM);
  989. UICR0 = UICR1 = 0xff;
  990. UFNRH = UFNRH_SIM;
  991. /* if hardware supports it, disconnect from usb */
  992. pullup_off();
  993. udc_clear_mask_UDCCR(UDCCR_UDE);
  994. ep0_idle (dev);
  995. dev->gadget.speed = USB_SPEED_UNKNOWN;
  996. }
  997. /*
  998. * udc_reinit - initialize software state
  999. */
  1000. static void udc_reinit(struct pxa25x_udc *dev)
  1001. {
  1002. u32 i;
  1003. /* device/ep0 records init */
  1004. INIT_LIST_HEAD (&dev->gadget.ep_list);
  1005. INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
  1006. dev->ep0state = EP0_IDLE;
  1007. /* basic endpoint records init */
  1008. for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  1009. struct pxa25x_ep *ep = &dev->ep[i];
  1010. if (i != 0)
  1011. list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
  1012. ep->desc = NULL;
  1013. ep->stopped = 0;
  1014. INIT_LIST_HEAD (&ep->queue);
  1015. ep->pio_irqs = 0;
  1016. }
  1017. /* the rest was statically initialized, and is read-only */
  1018. }
  1019. /* until it's enabled, this UDC should be completely invisible
  1020. * to any USB host.
  1021. */
  1022. static void udc_enable (struct pxa25x_udc *dev)
  1023. {
  1024. udc_clear_mask_UDCCR(UDCCR_UDE);
  1025. /* try to clear these bits before we enable the udc */
  1026. udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
  1027. ep0_idle(dev);
  1028. dev->gadget.speed = USB_SPEED_UNKNOWN;
  1029. dev->stats.irqs = 0;
  1030. /*
  1031. * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
  1032. * - enable UDC
  1033. * - if RESET is already in progress, ack interrupt
  1034. * - unmask reset interrupt
  1035. */
  1036. udc_set_mask_UDCCR(UDCCR_UDE);
  1037. if (!(UDCCR & UDCCR_UDA))
  1038. udc_ack_int_UDCCR(UDCCR_RSTIR);
  1039. if (dev->has_cfr /* UDC_RES2 is defined */) {
  1040. /* pxa255 (a0+) can avoid a set_config race that could
  1041. * prevent gadget drivers from configuring correctly
  1042. */
  1043. UDCCFR = UDCCFR_ACM | UDCCFR_MB1;
  1044. } else {
  1045. /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
  1046. * which could result in missing packets and interrupts.
  1047. * supposedly one bit per endpoint, controlling whether it
  1048. * double buffers or not; ACM/AREN bits fit into the holes.
  1049. * zero bits (like USIR0_IRx) disable double buffering.
  1050. */
  1051. UDC_RES1 = 0x00;
  1052. UDC_RES2 = 0x00;
  1053. }
  1054. /* enable suspend/resume and reset irqs */
  1055. udc_clear_mask_UDCCR(UDCCR_SRM | UDCCR_REM);
  1056. /* enable ep0 irqs */
  1057. UICR0 &= ~UICR0_IM0;
  1058. /* if hardware supports it, pullup D+ and wait for reset */
  1059. pullup_on();
  1060. }
  1061. /* when a driver is successfully registered, it will receive
  1062. * control requests including set_configuration(), which enables
  1063. * non-control requests. then usb traffic follows until a
  1064. * disconnect is reported. then a host may connect again, or
  1065. * the driver might get unbound.
  1066. */
  1067. int usb_gadget_register_driver(struct usb_gadget_driver *driver)
  1068. {
  1069. struct pxa25x_udc *dev = the_controller;
  1070. int retval;
  1071. if (!driver
  1072. || driver->speed < USB_SPEED_FULL
  1073. || !driver->bind
  1074. || !driver->disconnect
  1075. || !driver->setup)
  1076. return -EINVAL;
  1077. if (!dev)
  1078. return -ENODEV;
  1079. if (dev->driver)
  1080. return -EBUSY;
  1081. /* first hook up the driver ... */
  1082. dev->driver = driver;
  1083. dev->gadget.dev.driver = &driver->driver;
  1084. dev->pullup = 1;
  1085. retval = device_add (&dev->gadget.dev);
  1086. if (retval) {
  1087. fail:
  1088. dev->driver = NULL;
  1089. dev->gadget.dev.driver = NULL;
  1090. return retval;
  1091. }
  1092. retval = driver->bind(&dev->gadget);
  1093. if (retval) {
  1094. DMSG("bind to driver %s --> error %d\n",
  1095. driver->driver.name, retval);
  1096. device_del (&dev->gadget.dev);
  1097. goto fail;
  1098. }
  1099. /* ... then enable host detection and ep0; and we're ready
  1100. * for set_configuration as well as eventual disconnect.
  1101. */
  1102. DMSG("registered gadget driver '%s'\n", driver->driver.name);
  1103. /* connect to bus through transceiver */
  1104. if (dev->transceiver) {
  1105. retval = otg_set_peripheral(dev->transceiver, &dev->gadget);
  1106. if (retval) {
  1107. DMSG("can't bind to transceiver\n");
  1108. if (driver->unbind)
  1109. driver->unbind(&dev->gadget);
  1110. goto bind_fail;
  1111. }
  1112. }
  1113. pullup(dev);
  1114. dump_state(dev);
  1115. return 0;
  1116. bind_fail:
  1117. return retval;
  1118. }
  1119. EXPORT_SYMBOL(usb_gadget_register_driver);
  1120. static void
  1121. stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
  1122. {
  1123. int i;
  1124. /* don't disconnect drivers more than once */
  1125. if (dev->gadget.speed == USB_SPEED_UNKNOWN)
  1126. driver = NULL;
  1127. dev->gadget.speed = USB_SPEED_UNKNOWN;
  1128. /* prevent new request submissions, kill any outstanding requests */
  1129. for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  1130. struct pxa25x_ep *ep = &dev->ep[i];
  1131. ep->stopped = 1;
  1132. nuke(ep, -ESHUTDOWN);
  1133. }
  1134. del_timer_sync(&dev->timer);
  1135. /* report disconnect; the driver is already quiesced */
  1136. if (driver)
  1137. driver->disconnect(&dev->gadget);
  1138. /* re-init driver-visible data structures */
  1139. udc_reinit(dev);
  1140. }
  1141. int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  1142. {
  1143. struct pxa25x_udc *dev = the_controller;
  1144. if (!dev)
  1145. return -ENODEV;
  1146. if (!driver || driver != dev->driver || !driver->unbind)
  1147. return -EINVAL;
  1148. local_irq_disable();
  1149. dev->pullup = 0;
  1150. pullup(dev);
  1151. stop_activity(dev, driver);
  1152. local_irq_enable();
  1153. if (dev->transceiver)
  1154. (void) otg_set_peripheral(dev->transceiver, NULL);
  1155. driver->unbind(&dev->gadget);
  1156. dev->gadget.dev.driver = NULL;
  1157. dev->driver = NULL;
  1158. device_del (&dev->gadget.dev);
  1159. DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
  1160. dump_state(dev);
  1161. return 0;
  1162. }
  1163. EXPORT_SYMBOL(usb_gadget_unregister_driver);
  1164. /*-------------------------------------------------------------------------*/
  1165. #ifdef CONFIG_ARCH_LUBBOCK
  1166. /* Lubbock has separate connect and disconnect irqs. More typical designs
  1167. * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
  1168. */
  1169. static irqreturn_t
  1170. lubbock_vbus_irq(int irq, void *_dev)
  1171. {
  1172. struct pxa25x_udc *dev = _dev;
  1173. int vbus;
  1174. dev->stats.irqs++;
  1175. switch (irq) {
  1176. case LUBBOCK_USB_IRQ:
  1177. vbus = 1;
  1178. disable_irq(LUBBOCK_USB_IRQ);
  1179. enable_irq(LUBBOCK_USB_DISC_IRQ);
  1180. break;
  1181. case LUBBOCK_USB_DISC_IRQ:
  1182. vbus = 0;
  1183. disable_irq(LUBBOCK_USB_DISC_IRQ);
  1184. enable_irq(LUBBOCK_USB_IRQ);
  1185. break;
  1186. default:
  1187. return IRQ_NONE;
  1188. }
  1189. pxa25x_udc_vbus_session(&dev->gadget, vbus);
  1190. return IRQ_HANDLED;
  1191. }
  1192. #endif
  1193. static irqreturn_t udc_vbus_irq(int irq, void *_dev)
  1194. {
  1195. struct pxa25x_udc *dev = _dev;
  1196. pxa25x_udc_vbus_session(&dev->gadget, is_vbus_present());
  1197. return IRQ_HANDLED;
  1198. }
  1199. /*-------------------------------------------------------------------------*/
  1200. static inline void clear_ep_state (struct pxa25x_udc *dev)
  1201. {
  1202. unsigned i;
  1203. /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
  1204. * fifos, and pending transactions mustn't be continued in any case.
  1205. */
  1206. for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
  1207. nuke(&dev->ep[i], -ECONNABORTED);
  1208. }
  1209. static void udc_watchdog(unsigned long _dev)
  1210. {
  1211. struct pxa25x_udc *dev = (void *)_dev;
  1212. local_irq_disable();
  1213. if (dev->ep0state == EP0_STALL
  1214. && (UDCCS0 & UDCCS0_FST) == 0
  1215. && (UDCCS0 & UDCCS0_SST) == 0) {
  1216. UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
  1217. DBG(DBG_VERBOSE, "ep0 re-stall\n");
  1218. start_watchdog(dev);
  1219. }
  1220. local_irq_enable();
  1221. }
  1222. static void handle_ep0 (struct pxa25x_udc *dev)
  1223. {
  1224. u32 udccs0 = UDCCS0;
  1225. struct pxa25x_ep *ep = &dev->ep [0];
  1226. struct pxa25x_request *req;
  1227. union {
  1228. struct usb_ctrlrequest r;
  1229. u8 raw [8];
  1230. u32 word [2];
  1231. } u;
  1232. if (list_empty(&ep->queue))
  1233. req = NULL;
  1234. else
  1235. req = list_entry(ep->queue.next, struct pxa25x_request, queue);
  1236. /* clear stall status */
  1237. if (udccs0 & UDCCS0_SST) {
  1238. nuke(ep, -EPIPE);
  1239. UDCCS0 = UDCCS0_SST;
  1240. del_timer(&dev->timer);
  1241. ep0_idle(dev);
  1242. }
  1243. /* previous request unfinished? non-error iff back-to-back ... */
  1244. if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
  1245. nuke(ep, 0);
  1246. del_timer(&dev->timer);
  1247. ep0_idle(dev);
  1248. }
  1249. switch (dev->ep0state) {
  1250. case EP0_IDLE:
  1251. /* late-breaking status? */
  1252. udccs0 = UDCCS0;
  1253. /* start control request? */
  1254. if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
  1255. == (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
  1256. int i;
  1257. nuke (ep, -EPROTO);
  1258. /* read SETUP packet */
  1259. for (i = 0; i < 8; i++) {
  1260. if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
  1261. bad_setup:
  1262. DMSG("SETUP %d!\n", i);
  1263. goto stall;
  1264. }
  1265. u.raw [i] = (u8) UDDR0;
  1266. }
  1267. if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
  1268. goto bad_setup;
  1269. got_setup:
  1270. DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  1271. u.r.bRequestType, u.r.bRequest,
  1272. le16_to_cpu(u.r.wValue),
  1273. le16_to_cpu(u.r.wIndex),
  1274. le16_to_cpu(u.r.wLength));
  1275. /* cope with automagic for some standard requests. */
  1276. dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
  1277. == USB_TYPE_STANDARD;
  1278. dev->req_config = 0;
  1279. dev->req_pending = 1;
  1280. switch (u.r.bRequest) {
  1281. /* hardware restricts gadget drivers here! */
  1282. case USB_REQ_SET_CONFIGURATION:
  1283. if (u.r.bRequestType == USB_RECIP_DEVICE) {
  1284. /* reflect hardware's automagic
  1285. * up to the gadget driver.
  1286. */
  1287. config_change:
  1288. dev->req_config = 1;
  1289. clear_ep_state(dev);
  1290. /* if !has_cfr, there's no synch
  1291. * else use AREN (later) not SA|OPR
  1292. * USIR0_IR0 acts edge sensitive
  1293. */
  1294. }
  1295. break;
  1296. /* ... and here, even more ... */
  1297. case USB_REQ_SET_INTERFACE:
  1298. if (u.r.bRequestType == USB_RECIP_INTERFACE) {
  1299. /* udc hardware is broken by design:
  1300. * - altsetting may only be zero;
  1301. * - hw resets all interfaces' eps;
  1302. * - ep reset doesn't include halt(?).
  1303. */
  1304. DMSG("broken set_interface (%d/%d)\n",
  1305. le16_to_cpu(u.r.wIndex),
  1306. le16_to_cpu(u.r.wValue));
  1307. goto config_change;
  1308. }
  1309. break;
  1310. /* hardware was supposed to hide this */
  1311. case USB_REQ_SET_ADDRESS:
  1312. if (u.r.bRequestType == USB_RECIP_DEVICE) {
  1313. ep0start(dev, 0, "address");
  1314. return;
  1315. }
  1316. break;
  1317. }
  1318. if (u.r.bRequestType & USB_DIR_IN)
  1319. dev->ep0state = EP0_IN_DATA_PHASE;
  1320. else
  1321. dev->ep0state = EP0_OUT_DATA_PHASE;
  1322. i = dev->driver->setup(&dev->gadget, &u.r);
  1323. if (i < 0) {
  1324. /* hardware automagic preventing STALL... */
  1325. if (dev->req_config) {
  1326. /* hardware sometimes neglects to tell
  1327. * tell us about config change events,
  1328. * so later ones may fail...
  1329. */
  1330. WARNING("config change %02x fail %d?\n",
  1331. u.r.bRequest, i);
  1332. return;
  1333. /* TODO experiment: if has_cfr,
  1334. * hardware didn't ACK; maybe we
  1335. * could actually STALL!
  1336. */
  1337. }
  1338. DBG(DBG_VERBOSE, "protocol STALL, "
  1339. "%02x err %d\n", UDCCS0, i);
  1340. stall:
  1341. /* the watchdog timer helps deal with cases
  1342. * where udc seems to clear FST wrongly, and
  1343. * then NAKs instead of STALLing.
  1344. */
  1345. ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
  1346. start_watchdog(dev);
  1347. dev->ep0state = EP0_STALL;
  1348. /* deferred i/o == no response yet */
  1349. } else if (dev->req_pending) {
  1350. if (likely(dev->ep0state == EP0_IN_DATA_PHASE
  1351. || dev->req_std || u.r.wLength))
  1352. ep0start(dev, 0, "defer");
  1353. else
  1354. ep0start(dev, UDCCS0_IPR, "defer/IPR");
  1355. }
  1356. /* expect at least one data or status stage irq */
  1357. return;
  1358. } else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
  1359. == (UDCCS0_OPR|UDCCS0_SA))) {
  1360. unsigned i;
  1361. /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
  1362. * still observed on a pxa255 a0.
  1363. */
  1364. DBG(DBG_VERBOSE, "e131\n");
  1365. nuke(ep, -EPROTO);
  1366. /* read SETUP data, but don't trust it too much */
  1367. for (i = 0; i < 8; i++)
  1368. u.raw [i] = (u8) UDDR0;
  1369. if ((u.r.bRequestType & USB_RECIP_MASK)
  1370. > USB_RECIP_OTHER)
  1371. goto stall;
  1372. if (u.word [0] == 0 && u.word [1] == 0)
  1373. goto stall;
  1374. goto got_setup;
  1375. } else {
  1376. /* some random early IRQ:
  1377. * - we acked FST
  1378. * - IPR cleared
  1379. * - OPR got set, without SA (likely status stage)
  1380. */
  1381. UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
  1382. }
  1383. break;
  1384. case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
  1385. if (udccs0 & UDCCS0_OPR) {
  1386. UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
  1387. DBG(DBG_VERBOSE, "ep0in premature status\n");
  1388. if (req)
  1389. done(ep, req, 0);
  1390. ep0_idle(dev);
  1391. } else /* irq was IPR clearing */ {
  1392. if (req) {
  1393. /* this IN packet might finish the request */
  1394. (void) write_ep0_fifo(ep, req);
  1395. } /* else IN token before response was written */
  1396. }
  1397. break;
  1398. case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
  1399. if (udccs0 & UDCCS0_OPR) {
  1400. if (req) {
  1401. /* this OUT packet might finish the request */
  1402. if (read_ep0_fifo(ep, req))
  1403. done(ep, req, 0);
  1404. /* else more OUT packets expected */
  1405. } /* else OUT token before read was issued */
  1406. } else /* irq was IPR clearing */ {
  1407. DBG(DBG_VERBOSE, "ep0out premature status\n");
  1408. if (req)
  1409. done(ep, req, 0);
  1410. ep0_idle(dev);
  1411. }
  1412. break;
  1413. case EP0_END_XFER:
  1414. if (req)
  1415. done(ep, req, 0);
  1416. /* ack control-IN status (maybe in-zlp was skipped)
  1417. * also appears after some config change events.
  1418. */
  1419. if (udccs0 & UDCCS0_OPR)
  1420. UDCCS0 = UDCCS0_OPR;
  1421. ep0_idle(dev);
  1422. break;
  1423. case EP0_STALL:
  1424. UDCCS0 = UDCCS0_FST;
  1425. break;
  1426. }
  1427. USIR0 = USIR0_IR0;
  1428. }
  1429. static void handle_ep(struct pxa25x_ep *ep)
  1430. {
  1431. struct pxa25x_request *req;
  1432. int is_in = ep->bEndpointAddress & USB_DIR_IN;
  1433. int completed;
  1434. u32 udccs, tmp;
  1435. do {
  1436. completed = 0;
  1437. if (likely (!list_empty(&ep->queue)))
  1438. req = list_entry(ep->queue.next,
  1439. struct pxa25x_request, queue);
  1440. else
  1441. req = NULL;
  1442. // TODO check FST handling
  1443. udccs = *ep->reg_udccs;
  1444. if (unlikely(is_in)) { /* irq from TPC, SST, or (ISO) TUR */
  1445. tmp = UDCCS_BI_TUR;
  1446. if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
  1447. tmp |= UDCCS_BI_SST;
  1448. tmp &= udccs;
  1449. if (likely (tmp))
  1450. *ep->reg_udccs = tmp;
  1451. if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
  1452. completed = write_fifo(ep, req);
  1453. } else { /* irq from RPC (or for ISO, ROF) */
  1454. if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
  1455. tmp = UDCCS_BO_SST | UDCCS_BO_DME;
  1456. else
  1457. tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
  1458. tmp &= udccs;
  1459. if (likely(tmp))
  1460. *ep->reg_udccs = tmp;
  1461. /* fifos can hold packets, ready for reading... */
  1462. if (likely(req)) {
  1463. completed = read_fifo(ep, req);
  1464. } else
  1465. pio_irq_disable (ep->bEndpointAddress);
  1466. }
  1467. ep->pio_irqs++;
  1468. } while (completed);
  1469. }
  1470. /*
  1471. * pxa25x_udc_irq - interrupt handler
  1472. *
  1473. * avoid delays in ep0 processing. the control handshaking isn't always
  1474. * under software control (pxa250c0 and the pxa255 are better), and delays
  1475. * could cause usb protocol errors.
  1476. */
  1477. static irqreturn_t
  1478. pxa25x_udc_irq(int irq, void *_dev)
  1479. {
  1480. struct pxa25x_udc *dev = _dev;
  1481. int handled;
  1482. dev->stats.irqs++;
  1483. do {
  1484. u32 udccr = UDCCR;
  1485. handled = 0;
  1486. /* SUSpend Interrupt Request */
  1487. if (unlikely(udccr & UDCCR_SUSIR)) {
  1488. udc_ack_int_UDCCR(UDCCR_SUSIR);
  1489. handled = 1;
  1490. DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
  1491. ? "" : "+disconnect");
  1492. if (!is_vbus_present())
  1493. stop_activity(dev, dev->driver);
  1494. else if (dev->gadget.speed != USB_SPEED_UNKNOWN
  1495. && dev->driver
  1496. && dev->driver->suspend)
  1497. dev->driver->suspend(&dev->gadget);
  1498. ep0_idle (dev);
  1499. }
  1500. /* RESume Interrupt Request */
  1501. if (unlikely(udccr & UDCCR_RESIR)) {
  1502. udc_ack_int_UDCCR(UDCCR_RESIR);
  1503. handled = 1;
  1504. DBG(DBG_VERBOSE, "USB resume\n");
  1505. if (dev->gadget.speed != USB_SPEED_UNKNOWN
  1506. && dev->driver
  1507. && dev->driver->resume
  1508. && is_vbus_present())
  1509. dev->driver->resume(&dev->gadget);
  1510. }
  1511. /* ReSeT Interrupt Request - USB reset */
  1512. if (unlikely(udccr & UDCCR_RSTIR)) {
  1513. udc_ack_int_UDCCR(UDCCR_RSTIR);
  1514. handled = 1;
  1515. if ((UDCCR & UDCCR_UDA) == 0) {
  1516. DBG(DBG_VERBOSE, "USB reset start\n");
  1517. /* reset driver and endpoints,
  1518. * in case that's not yet done
  1519. */
  1520. stop_activity (dev, dev->driver);
  1521. } else {
  1522. DBG(DBG_VERBOSE, "USB reset end\n");
  1523. dev->gadget.speed = USB_SPEED_FULL;
  1524. memset(&dev->stats, 0, sizeof dev->stats);
  1525. /* driver and endpoints are still reset */
  1526. }
  1527. } else {
  1528. u32 usir0 = USIR0 & ~UICR0;
  1529. u32 usir1 = USIR1 & ~UICR1;
  1530. int i;
  1531. if (unlikely (!usir0 && !usir1))
  1532. continue;
  1533. DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
  1534. /* control traffic */
  1535. if (usir0 & USIR0_IR0) {
  1536. dev->ep[0].pio_irqs++;
  1537. handle_ep0(dev);
  1538. handled = 1;
  1539. }
  1540. /* endpoint data transfers */
  1541. for (i = 0; i < 8; i++) {
  1542. u32 tmp = 1 << i;
  1543. if (i && (usir0 & tmp)) {
  1544. handle_ep(&dev->ep[i]);
  1545. USIR0 |= tmp;
  1546. handled = 1;
  1547. }
  1548. #ifndef CONFIG_USB_PXA25X_SMALL
  1549. if (usir1 & tmp) {
  1550. handle_ep(&dev->ep[i+8]);
  1551. USIR1 |= tmp;
  1552. handled = 1;
  1553. }
  1554. #endif
  1555. }
  1556. }
  1557. /* we could also ask for 1 msec SOF (SIR) interrupts */
  1558. } while (handled);
  1559. return IRQ_HANDLED;
  1560. }
  1561. /*-------------------------------------------------------------------------*/
  1562. static void nop_release (struct device *dev)
  1563. {
  1564. DMSG("%s %s\n", __func__, dev_name(dev));
  1565. }
  1566. /* this uses load-time allocation and initialization (instead of
  1567. * doing it at run-time) to save code, eliminate fault paths, and
  1568. * be more obviously correct.
  1569. */
  1570. static struct pxa25x_udc memory = {
  1571. .gadget = {
  1572. .ops = &pxa25x_udc_ops,
  1573. .ep0 = &memory.ep[0].ep,
  1574. .name = driver_name,
  1575. .dev = {
  1576. .init_name = "gadget",
  1577. .release = nop_release,
  1578. },
  1579. },
  1580. /* control endpoint */
  1581. .ep[0] = {
  1582. .ep = {
  1583. .name = ep0name,
  1584. .ops = &pxa25x_ep_ops,
  1585. .maxpacket = EP0_FIFO_SIZE,
  1586. },
  1587. .dev = &memory,
  1588. .reg_udccs = &UDCCS0,
  1589. .reg_uddr = &UDDR0,
  1590. },
  1591. /* first group of endpoints */
  1592. .ep[1] = {
  1593. .ep = {
  1594. .name = "ep1in-bulk",
  1595. .ops = &pxa25x_ep_ops,
  1596. .maxpacket = BULK_FIFO_SIZE,
  1597. },
  1598. .dev = &memory,
  1599. .fifo_size = BULK_FIFO_SIZE,
  1600. .bEndpointAddress = USB_DIR_IN | 1,
  1601. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1602. .reg_udccs = &UDCCS1,
  1603. .reg_uddr = &UDDR1,
  1604. },
  1605. .ep[2] = {
  1606. .ep = {
  1607. .name = "ep2out-bulk",
  1608. .ops = &pxa25x_ep_ops,
  1609. .maxpacket = BULK_FIFO_SIZE,
  1610. },
  1611. .dev = &memory,
  1612. .fifo_size = BULK_FIFO_SIZE,
  1613. .bEndpointAddress = 2,
  1614. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1615. .reg_udccs = &UDCCS2,
  1616. .reg_ubcr = &UBCR2,
  1617. .reg_uddr = &UDDR2,
  1618. },
  1619. #ifndef CONFIG_USB_PXA25X_SMALL
  1620. .ep[3] = {
  1621. .ep = {
  1622. .name = "ep3in-iso",
  1623. .ops = &pxa25x_ep_ops,
  1624. .maxpacket = ISO_FIFO_SIZE,
  1625. },
  1626. .dev = &memory,
  1627. .fifo_size = ISO_FIFO_SIZE,
  1628. .bEndpointAddress = USB_DIR_IN | 3,
  1629. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1630. .reg_udccs = &UDCCS3,
  1631. .reg_uddr = &UDDR3,
  1632. },
  1633. .ep[4] = {
  1634. .ep = {
  1635. .name = "ep4out-iso",
  1636. .ops = &pxa25x_ep_ops,
  1637. .maxpacket = ISO_FIFO_SIZE,
  1638. },
  1639. .dev = &memory,
  1640. .fifo_size = ISO_FIFO_SIZE,
  1641. .bEndpointAddress = 4,
  1642. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1643. .reg_udccs = &UDCCS4,
  1644. .reg_ubcr = &UBCR4,
  1645. .reg_uddr = &UDDR4,
  1646. },
  1647. .ep[5] = {
  1648. .ep = {
  1649. .name = "ep5in-int",
  1650. .ops = &pxa25x_ep_ops,
  1651. .maxpacket = INT_FIFO_SIZE,
  1652. },
  1653. .dev = &memory,
  1654. .fifo_size = INT_FIFO_SIZE,
  1655. .bEndpointAddress = USB_DIR_IN | 5,
  1656. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1657. .reg_udccs = &UDCCS5,
  1658. .reg_uddr = &UDDR5,
  1659. },
  1660. /* second group of endpoints */
  1661. .ep[6] = {
  1662. .ep = {
  1663. .name = "ep6in-bulk",
  1664. .ops = &pxa25x_ep_ops,
  1665. .maxpacket = BULK_FIFO_SIZE,
  1666. },
  1667. .dev = &memory,
  1668. .fifo_size = BULK_FIFO_SIZE,
  1669. .bEndpointAddress = USB_DIR_IN | 6,
  1670. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1671. .reg_udccs = &UDCCS6,
  1672. .reg_uddr = &UDDR6,
  1673. },
  1674. .ep[7] = {
  1675. .ep = {
  1676. .name = "ep7out-bulk",
  1677. .ops = &pxa25x_ep_ops,
  1678. .maxpacket = BULK_FIFO_SIZE,
  1679. },
  1680. .dev = &memory,
  1681. .fifo_size = BULK_FIFO_SIZE,
  1682. .bEndpointAddress = 7,
  1683. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1684. .reg_udccs = &UDCCS7,
  1685. .reg_ubcr = &UBCR7,
  1686. .reg_uddr = &UDDR7,
  1687. },
  1688. .ep[8] = {
  1689. .ep = {
  1690. .name = "ep8in-iso",
  1691. .ops = &pxa25x_ep_ops,
  1692. .maxpacket = ISO_FIFO_SIZE,
  1693. },
  1694. .dev = &memory,
  1695. .fifo_size = ISO_FIFO_SIZE,
  1696. .bEndpointAddress = USB_DIR_IN | 8,
  1697. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1698. .reg_udccs = &UDCCS8,
  1699. .reg_uddr = &UDDR8,
  1700. },
  1701. .ep[9] = {
  1702. .ep = {
  1703. .name = "ep9out-iso",
  1704. .ops = &pxa25x_ep_ops,
  1705. .maxpacket = ISO_FIFO_SIZE,
  1706. },
  1707. .dev = &memory,
  1708. .fifo_size = ISO_FIFO_SIZE,
  1709. .bEndpointAddress = 9,
  1710. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1711. .reg_udccs = &UDCCS9,
  1712. .reg_ubcr = &UBCR9,
  1713. .reg_uddr = &UDDR9,
  1714. },
  1715. .ep[10] = {
  1716. .ep = {
  1717. .name = "ep10in-int",
  1718. .ops = &pxa25x_ep_ops,
  1719. .maxpacket = INT_FIFO_SIZE,
  1720. },
  1721. .dev = &memory,
  1722. .fifo_size = INT_FIFO_SIZE,
  1723. .bEndpointAddress = USB_DIR_IN | 10,
  1724. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1725. .reg_udccs = &UDCCS10,
  1726. .reg_uddr = &UDDR10,
  1727. },
  1728. /* third group of endpoints */
  1729. .ep[11] = {
  1730. .ep = {
  1731. .name = "ep11in-bulk",
  1732. .ops = &pxa25x_ep_ops,
  1733. .maxpacket = BULK_FIFO_SIZE,
  1734. },
  1735. .dev = &memory,
  1736. .fifo_size = BULK_FIFO_SIZE,
  1737. .bEndpointAddress = USB_DIR_IN | 11,
  1738. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1739. .reg_udccs = &UDCCS11,
  1740. .reg_uddr = &UDDR11,
  1741. },
  1742. .ep[12] = {
  1743. .ep = {
  1744. .name = "ep12out-bulk",
  1745. .ops = &pxa25x_ep_ops,
  1746. .maxpacket = BULK_FIFO_SIZE,
  1747. },
  1748. .dev = &memory,
  1749. .fifo_size = BULK_FIFO_SIZE,
  1750. .bEndpointAddress = 12,
  1751. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1752. .reg_udccs = &UDCCS12,
  1753. .reg_ubcr = &UBCR12,
  1754. .reg_uddr = &UDDR12,
  1755. },
  1756. .ep[13] = {
  1757. .ep = {
  1758. .name = "ep13in-iso",
  1759. .ops = &pxa25x_ep_ops,
  1760. .maxpacket = ISO_FIFO_SIZE,
  1761. },
  1762. .dev = &memory,
  1763. .fifo_size = ISO_FIFO_SIZE,
  1764. .bEndpointAddress = USB_DIR_IN | 13,
  1765. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1766. .reg_udccs = &UDCCS13,
  1767. .reg_uddr = &UDDR13,
  1768. },
  1769. .ep[14] = {
  1770. .ep = {
  1771. .name = "ep14out-iso",
  1772. .ops = &pxa25x_ep_ops,
  1773. .maxpacket = ISO_FIFO_SIZE,
  1774. },
  1775. .dev = &memory,
  1776. .fifo_size = ISO_FIFO_SIZE,
  1777. .bEndpointAddress = 14,
  1778. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1779. .reg_udccs = &UDCCS14,
  1780. .reg_ubcr = &UBCR14,
  1781. .reg_uddr = &UDDR14,
  1782. },
  1783. .ep[15] = {
  1784. .ep = {
  1785. .name = "ep15in-int",
  1786. .ops = &pxa25x_ep_ops,
  1787. .maxpacket = INT_FIFO_SIZE,
  1788. },
  1789. .dev = &memory,
  1790. .fifo_size = INT_FIFO_SIZE,
  1791. .bEndpointAddress = USB_DIR_IN | 15,
  1792. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1793. .reg_udccs = &UDCCS15,
  1794. .reg_uddr = &UDDR15,
  1795. },
  1796. #endif /* !CONFIG_USB_PXA25X_SMALL */
  1797. };
  1798. #define CP15R0_VENDOR_MASK 0xffffe000
  1799. #if defined(CONFIG_ARCH_PXA)
  1800. #define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
  1801. #elif defined(CONFIG_ARCH_IXP4XX)
  1802. #define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
  1803. #endif
  1804. #define CP15R0_PROD_MASK 0x000003f0
  1805. #define PXA25x 0x00000100 /* and PXA26x */
  1806. #define PXA210 0x00000120
  1807. #define CP15R0_REV_MASK 0x0000000f
  1808. #define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
  1809. #define PXA255_A0 0x00000106 /* or PXA260_B1 */
  1810. #define PXA250_C0 0x00000105 /* or PXA26x_B0 */
  1811. #define PXA250_B2 0x00000104
  1812. #define PXA250_B1 0x00000103 /* or PXA260_A0 */
  1813. #define PXA250_B0 0x00000102
  1814. #define PXA250_A1 0x00000101
  1815. #define PXA250_A0 0x00000100
  1816. #define PXA210_C0 0x00000125
  1817. #define PXA210_B2 0x00000124
  1818. #define PXA210_B1 0x00000123
  1819. #define PXA210_B0 0x00000122
  1820. #define IXP425_A0 0x000001c1
  1821. #define IXP425_B0 0x000001f1
  1822. #define IXP465_AD 0x00000200
  1823. /*
  1824. * probe - binds to the platform device
  1825. */
  1826. static int __init pxa25x_udc_probe(struct platform_device *pdev)
  1827. {
  1828. struct pxa25x_udc *dev = &memory;
  1829. int retval, vbus_irq, irq;
  1830. u32 chiprev;
  1831. /* insist on Intel/ARM/XScale */
  1832. asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
  1833. if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
  1834. pr_err("%s: not XScale!\n", driver_name);
  1835. return -ENODEV;
  1836. }
  1837. /* trigger chiprev-specific logic */
  1838. switch (chiprev & CP15R0_PRODREV_MASK) {
  1839. #if defined(CONFIG_ARCH_PXA)
  1840. case PXA255_A0:
  1841. dev->has_cfr = 1;
  1842. break;
  1843. case PXA250_A0:
  1844. case PXA250_A1:
  1845. /* A0/A1 "not released"; ep 13, 15 unusable */
  1846. /* fall through */
  1847. case PXA250_B2: case PXA210_B2:
  1848. case PXA250_B1: case PXA210_B1:
  1849. case PXA250_B0: case PXA210_B0:
  1850. /* OUT-DMA is broken ... */
  1851. /* fall through */
  1852. case PXA250_C0: case PXA210_C0:
  1853. break;
  1854. #elif defined(CONFIG_ARCH_IXP4XX)
  1855. case IXP425_A0:
  1856. case IXP425_B0:
  1857. case IXP465_AD:
  1858. dev->has_cfr = 1;
  1859. break;
  1860. #endif
  1861. default:
  1862. pr_err("%s: unrecognized processor: %08x\n",
  1863. driver_name, chiprev);
  1864. /* iop3xx, ixp4xx, ... */
  1865. return -ENODEV;
  1866. }
  1867. irq = platform_get_irq(pdev, 0);
  1868. if (irq < 0)
  1869. return -ENODEV;
  1870. dev->clk = clk_get(&pdev->dev, NULL);
  1871. if (IS_ERR(dev->clk)) {
  1872. retval = PTR_ERR(dev->clk);
  1873. goto err_clk;
  1874. }
  1875. pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
  1876. dev->has_cfr ? "" : " (!cfr)",
  1877. SIZE_STR "(pio)"
  1878. );
  1879. /* other non-static parts of init */
  1880. dev->dev = &pdev->dev;
  1881. dev->mach = pdev->dev.platform_data;
  1882. dev->transceiver = otg_get_transceiver();
  1883. if (gpio_is_valid(dev->mach->gpio_vbus)) {
  1884. if ((retval = gpio_request(dev->mach->gpio_vbus,
  1885. "pxa25x_udc GPIO VBUS"))) {
  1886. dev_dbg(&pdev->dev,
  1887. "can't get vbus gpio %d, err: %d\n",
  1888. dev->mach->gpio_vbus, retval);
  1889. goto err_gpio_vbus;
  1890. }
  1891. gpio_direction_input(dev->mach->gpio_vbus);
  1892. vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
  1893. } else
  1894. vbus_irq = 0;
  1895. if (gpio_is_valid(dev->mach->gpio_pullup)) {
  1896. if ((retval = gpio_request(dev->mach->gpio_pullup,
  1897. "pca25x_udc GPIO PULLUP"))) {
  1898. dev_dbg(&pdev->dev,
  1899. "can't get pullup gpio %d, err: %d\n",
  1900. dev->mach->gpio_pullup, retval);
  1901. goto err_gpio_pullup;
  1902. }
  1903. gpio_direction_output(dev->mach->gpio_pullup, 0);
  1904. }
  1905. init_timer(&dev->timer);
  1906. dev->timer.function = udc_watchdog;
  1907. dev->timer.data = (unsigned long) dev;
  1908. device_initialize(&dev->gadget.dev);
  1909. dev->gadget.dev.parent = &pdev->dev;
  1910. dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
  1911. the_controller = dev;
  1912. platform_set_drvdata(pdev, dev);
  1913. udc_disable(dev);
  1914. udc_reinit(dev);
  1915. dev->vbus = !!is_vbus_present();
  1916. /* irq setup after old hardware state is cleaned up */
  1917. retval = request_irq(irq, pxa25x_udc_irq,
  1918. IRQF_DISABLED, driver_name, dev);
  1919. if (retval != 0) {
  1920. pr_err("%s: can't get irq %d, err %d\n",
  1921. driver_name, irq, retval);
  1922. goto err_irq1;
  1923. }
  1924. dev->got_irq = 1;
  1925. #ifdef CONFIG_ARCH_LUBBOCK
  1926. if (machine_is_lubbock()) {
  1927. retval = request_irq(LUBBOCK_USB_DISC_IRQ,
  1928. lubbock_vbus_irq,
  1929. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  1930. driver_name, dev);
  1931. if (retval != 0) {
  1932. pr_err("%s: can't get irq %i, err %d\n",
  1933. driver_name, LUBBOCK_USB_DISC_IRQ, retval);
  1934. lubbock_fail0:
  1935. goto err_irq_lub;
  1936. }
  1937. retval = request_irq(LUBBOCK_USB_IRQ,
  1938. lubbock_vbus_irq,
  1939. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  1940. driver_name, dev);
  1941. if (retval != 0) {
  1942. pr_err("%s: can't get irq %i, err %d\n",
  1943. driver_name, LUBBOCK_USB_IRQ, retval);
  1944. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  1945. goto lubbock_fail0;
  1946. }
  1947. } else
  1948. #endif
  1949. if (vbus_irq) {
  1950. retval = request_irq(vbus_irq, udc_vbus_irq,
  1951. IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  1952. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  1953. driver_name, dev);
  1954. if (retval != 0) {
  1955. pr_err("%s: can't get irq %i, err %d\n",
  1956. driver_name, vbus_irq, retval);
  1957. goto err_vbus_irq;
  1958. }
  1959. }
  1960. create_debug_files(dev);
  1961. return 0;
  1962. err_vbus_irq:
  1963. #ifdef CONFIG_ARCH_LUBBOCK
  1964. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  1965. err_irq_lub:
  1966. #endif
  1967. free_irq(irq, dev);
  1968. err_irq1:
  1969. if (gpio_is_valid(dev->mach->gpio_pullup))
  1970. gpio_free(dev->mach->gpio_pullup);
  1971. err_gpio_pullup:
  1972. if (gpio_is_valid(dev->mach->gpio_vbus))
  1973. gpio_free(dev->mach->gpio_vbus);
  1974. err_gpio_vbus:
  1975. if (dev->transceiver) {
  1976. otg_put_transceiver(dev->transceiver);
  1977. dev->transceiver = NULL;
  1978. }
  1979. clk_put(dev->clk);
  1980. err_clk:
  1981. return retval;
  1982. }
  1983. static void pxa25x_udc_shutdown(struct platform_device *_dev)
  1984. {
  1985. pullup_off();
  1986. }
  1987. static int __exit pxa25x_udc_remove(struct platform_device *pdev)
  1988. {
  1989. struct pxa25x_udc *dev = platform_get_drvdata(pdev);
  1990. if (dev->driver)
  1991. return -EBUSY;
  1992. dev->pullup = 0;
  1993. pullup(dev);
  1994. remove_debug_files(dev);
  1995. if (dev->got_irq) {
  1996. free_irq(platform_get_irq(pdev, 0), dev);
  1997. dev->got_irq = 0;
  1998. }
  1999. #ifdef CONFIG_ARCH_LUBBOCK
  2000. if (machine_is_lubbock()) {
  2001. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  2002. free_irq(LUBBOCK_USB_IRQ, dev);
  2003. }
  2004. #endif
  2005. if (gpio_is_valid(dev->mach->gpio_vbus)) {
  2006. free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
  2007. gpio_free(dev->mach->gpio_vbus);
  2008. }
  2009. if (gpio_is_valid(dev->mach->gpio_pullup))
  2010. gpio_free(dev->mach->gpio_pullup);
  2011. clk_put(dev->clk);
  2012. if (dev->transceiver) {
  2013. otg_put_transceiver(dev->transceiver);
  2014. dev->transceiver = NULL;
  2015. }
  2016. platform_set_drvdata(pdev, NULL);
  2017. the_controller = NULL;
  2018. return 0;
  2019. }
  2020. /*-------------------------------------------------------------------------*/
  2021. #ifdef CONFIG_PM
  2022. /* USB suspend (controlled by the host) and system suspend (controlled
  2023. * by the PXA) don't necessarily work well together. If USB is active,
  2024. * the 48 MHz clock is required; so the system can't enter 33 MHz idle
  2025. * mode, or any deeper PM saving state.
  2026. *
  2027. * For now, we punt and forcibly disconnect from the USB host when PXA
  2028. * enters any suspend state. While we're disconnected, we always disable
  2029. * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
  2030. * Boards without software pullup control shouldn't use those states.
  2031. * VBUS IRQs should probably be ignored so that the PXA device just acts
  2032. * "dead" to USB hosts until system resume.
  2033. */
  2034. static int pxa25x_udc_suspend(struct platform_device *dev, pm_message_t state)
  2035. {
  2036. struct pxa25x_udc *udc = platform_get_drvdata(dev);
  2037. unsigned long flags;
  2038. if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
  2039. WARNING("USB host won't detect disconnect!\n");
  2040. udc->suspended = 1;
  2041. local_irq_save(flags);
  2042. pullup(udc);
  2043. local_irq_restore(flags);
  2044. return 0;
  2045. }
  2046. static int pxa25x_udc_resume(struct platform_device *dev)
  2047. {
  2048. struct pxa25x_udc *udc = platform_get_drvdata(dev);
  2049. unsigned long flags;
  2050. udc->suspended = 0;
  2051. local_irq_save(flags);
  2052. pullup(udc);
  2053. local_irq_restore(flags);
  2054. return 0;
  2055. }
  2056. #else
  2057. #define pxa25x_udc_suspend NULL
  2058. #define pxa25x_udc_resume NULL
  2059. #endif
  2060. /*-------------------------------------------------------------------------*/
  2061. static struct platform_driver udc_driver = {
  2062. .shutdown = pxa25x_udc_shutdown,
  2063. .remove = __exit_p(pxa25x_udc_remove),
  2064. .suspend = pxa25x_udc_suspend,
  2065. .resume = pxa25x_udc_resume,
  2066. .driver = {
  2067. .owner = THIS_MODULE,
  2068. .name = "pxa25x-udc",
  2069. },
  2070. };
  2071. static int __init udc_init(void)
  2072. {
  2073. pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
  2074. return platform_driver_probe(&udc_driver, pxa25x_udc_probe);
  2075. }
  2076. module_init(udc_init);
  2077. static void __exit udc_exit(void)
  2078. {
  2079. platform_driver_unregister(&udc_driver);
  2080. }
  2081. module_exit(udc_exit);
  2082. MODULE_DESCRIPTION(DRIVER_DESC);
  2083. MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
  2084. MODULE_LICENSE("GPL");
  2085. MODULE_ALIAS("platform:pxa25x-udc");