pxa25x_udc.c 60 KB

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