pxa25x_udc.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  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_register_driver(struct usb_gadget_driver *driver)
  1071. {
  1072. struct pxa25x_udc *dev = the_controller;
  1073. int retval;
  1074. if (!driver
  1075. || driver->speed < USB_SPEED_FULL
  1076. || !driver->bind
  1077. || !driver->disconnect
  1078. || !driver->setup)
  1079. return -EINVAL;
  1080. if (!dev)
  1081. return -ENODEV;
  1082. if (dev->driver)
  1083. return -EBUSY;
  1084. /* first hook up the driver ... */
  1085. dev->driver = driver;
  1086. dev->gadget.dev.driver = &driver->driver;
  1087. dev->pullup = 1;
  1088. retval = device_add (&dev->gadget.dev);
  1089. if (retval) {
  1090. fail:
  1091. dev->driver = NULL;
  1092. dev->gadget.dev.driver = NULL;
  1093. return retval;
  1094. }
  1095. retval = driver->bind(&dev->gadget);
  1096. if (retval) {
  1097. DMSG("bind to driver %s --> error %d\n",
  1098. driver->driver.name, retval);
  1099. device_del (&dev->gadget.dev);
  1100. goto fail;
  1101. }
  1102. /* ... then enable host detection and ep0; and we're ready
  1103. * for set_configuration as well as eventual disconnect.
  1104. */
  1105. DMSG("registered gadget driver '%s'\n", driver->driver.name);
  1106. /* connect to bus through transceiver */
  1107. if (dev->transceiver) {
  1108. retval = otg_set_peripheral(dev->transceiver, &dev->gadget);
  1109. if (retval) {
  1110. DMSG("can't bind to transceiver\n");
  1111. if (driver->unbind)
  1112. driver->unbind(&dev->gadget);
  1113. goto bind_fail;
  1114. }
  1115. }
  1116. pullup(dev);
  1117. dump_state(dev);
  1118. return 0;
  1119. bind_fail:
  1120. return retval;
  1121. }
  1122. EXPORT_SYMBOL(usb_gadget_register_driver);
  1123. static void
  1124. stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
  1125. {
  1126. int i;
  1127. /* don't disconnect drivers more than once */
  1128. if (dev->gadget.speed == USB_SPEED_UNKNOWN)
  1129. driver = NULL;
  1130. dev->gadget.speed = USB_SPEED_UNKNOWN;
  1131. /* prevent new request submissions, kill any outstanding requests */
  1132. for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  1133. struct pxa25x_ep *ep = &dev->ep[i];
  1134. ep->stopped = 1;
  1135. nuke(ep, -ESHUTDOWN);
  1136. }
  1137. del_timer_sync(&dev->timer);
  1138. /* report disconnect; the driver is already quiesced */
  1139. if (driver)
  1140. driver->disconnect(&dev->gadget);
  1141. /* re-init driver-visible data structures */
  1142. udc_reinit(dev);
  1143. }
  1144. int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  1145. {
  1146. struct pxa25x_udc *dev = the_controller;
  1147. if (!dev)
  1148. return -ENODEV;
  1149. if (!driver || driver != dev->driver || !driver->unbind)
  1150. return -EINVAL;
  1151. local_irq_disable();
  1152. dev->pullup = 0;
  1153. pullup(dev);
  1154. stop_activity(dev, driver);
  1155. local_irq_enable();
  1156. if (dev->transceiver)
  1157. (void) otg_set_peripheral(dev->transceiver, NULL);
  1158. driver->unbind(&dev->gadget);
  1159. dev->gadget.dev.driver = NULL;
  1160. dev->driver = NULL;
  1161. device_del (&dev->gadget.dev);
  1162. DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
  1163. dump_state(dev);
  1164. return 0;
  1165. }
  1166. EXPORT_SYMBOL(usb_gadget_unregister_driver);
  1167. /*-------------------------------------------------------------------------*/
  1168. #ifdef CONFIG_ARCH_LUBBOCK
  1169. /* Lubbock has separate connect and disconnect irqs. More typical designs
  1170. * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
  1171. */
  1172. static irqreturn_t
  1173. lubbock_vbus_irq(int irq, void *_dev)
  1174. {
  1175. struct pxa25x_udc *dev = _dev;
  1176. int vbus;
  1177. dev->stats.irqs++;
  1178. switch (irq) {
  1179. case LUBBOCK_USB_IRQ:
  1180. vbus = 1;
  1181. disable_irq(LUBBOCK_USB_IRQ);
  1182. enable_irq(LUBBOCK_USB_DISC_IRQ);
  1183. break;
  1184. case LUBBOCK_USB_DISC_IRQ:
  1185. vbus = 0;
  1186. disable_irq(LUBBOCK_USB_DISC_IRQ);
  1187. enable_irq(LUBBOCK_USB_IRQ);
  1188. break;
  1189. default:
  1190. return IRQ_NONE;
  1191. }
  1192. pxa25x_udc_vbus_session(&dev->gadget, vbus);
  1193. return IRQ_HANDLED;
  1194. }
  1195. #endif
  1196. static irqreturn_t udc_vbus_irq(int irq, void *_dev)
  1197. {
  1198. struct pxa25x_udc *dev = _dev;
  1199. pxa25x_udc_vbus_session(&dev->gadget, is_vbus_present());
  1200. return IRQ_HANDLED;
  1201. }
  1202. /*-------------------------------------------------------------------------*/
  1203. static inline void clear_ep_state (struct pxa25x_udc *dev)
  1204. {
  1205. unsigned i;
  1206. /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
  1207. * fifos, and pending transactions mustn't be continued in any case.
  1208. */
  1209. for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
  1210. nuke(&dev->ep[i], -ECONNABORTED);
  1211. }
  1212. static void udc_watchdog(unsigned long _dev)
  1213. {
  1214. struct pxa25x_udc *dev = (void *)_dev;
  1215. local_irq_disable();
  1216. if (dev->ep0state == EP0_STALL
  1217. && (UDCCS0 & UDCCS0_FST) == 0
  1218. && (UDCCS0 & UDCCS0_SST) == 0) {
  1219. UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
  1220. DBG(DBG_VERBOSE, "ep0 re-stall\n");
  1221. start_watchdog(dev);
  1222. }
  1223. local_irq_enable();
  1224. }
  1225. static void handle_ep0 (struct pxa25x_udc *dev)
  1226. {
  1227. u32 udccs0 = UDCCS0;
  1228. struct pxa25x_ep *ep = &dev->ep [0];
  1229. struct pxa25x_request *req;
  1230. union {
  1231. struct usb_ctrlrequest r;
  1232. u8 raw [8];
  1233. u32 word [2];
  1234. } u;
  1235. if (list_empty(&ep->queue))
  1236. req = NULL;
  1237. else
  1238. req = list_entry(ep->queue.next, struct pxa25x_request, queue);
  1239. /* clear stall status */
  1240. if (udccs0 & UDCCS0_SST) {
  1241. nuke(ep, -EPIPE);
  1242. UDCCS0 = UDCCS0_SST;
  1243. del_timer(&dev->timer);
  1244. ep0_idle(dev);
  1245. }
  1246. /* previous request unfinished? non-error iff back-to-back ... */
  1247. if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
  1248. nuke(ep, 0);
  1249. del_timer(&dev->timer);
  1250. ep0_idle(dev);
  1251. }
  1252. switch (dev->ep0state) {
  1253. case EP0_IDLE:
  1254. /* late-breaking status? */
  1255. udccs0 = UDCCS0;
  1256. /* start control request? */
  1257. if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
  1258. == (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
  1259. int i;
  1260. nuke (ep, -EPROTO);
  1261. /* read SETUP packet */
  1262. for (i = 0; i < 8; i++) {
  1263. if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
  1264. bad_setup:
  1265. DMSG("SETUP %d!\n", i);
  1266. goto stall;
  1267. }
  1268. u.raw [i] = (u8) UDDR0;
  1269. }
  1270. if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
  1271. goto bad_setup;
  1272. got_setup:
  1273. DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  1274. u.r.bRequestType, u.r.bRequest,
  1275. le16_to_cpu(u.r.wValue),
  1276. le16_to_cpu(u.r.wIndex),
  1277. le16_to_cpu(u.r.wLength));
  1278. /* cope with automagic for some standard requests. */
  1279. dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
  1280. == USB_TYPE_STANDARD;
  1281. dev->req_config = 0;
  1282. dev->req_pending = 1;
  1283. switch (u.r.bRequest) {
  1284. /* hardware restricts gadget drivers here! */
  1285. case USB_REQ_SET_CONFIGURATION:
  1286. if (u.r.bRequestType == USB_RECIP_DEVICE) {
  1287. /* reflect hardware's automagic
  1288. * up to the gadget driver.
  1289. */
  1290. config_change:
  1291. dev->req_config = 1;
  1292. clear_ep_state(dev);
  1293. /* if !has_cfr, there's no synch
  1294. * else use AREN (later) not SA|OPR
  1295. * USIR0_IR0 acts edge sensitive
  1296. */
  1297. }
  1298. break;
  1299. /* ... and here, even more ... */
  1300. case USB_REQ_SET_INTERFACE:
  1301. if (u.r.bRequestType == USB_RECIP_INTERFACE) {
  1302. /* udc hardware is broken by design:
  1303. * - altsetting may only be zero;
  1304. * - hw resets all interfaces' eps;
  1305. * - ep reset doesn't include halt(?).
  1306. */
  1307. DMSG("broken set_interface (%d/%d)\n",
  1308. le16_to_cpu(u.r.wIndex),
  1309. le16_to_cpu(u.r.wValue));
  1310. goto config_change;
  1311. }
  1312. break;
  1313. /* hardware was supposed to hide this */
  1314. case USB_REQ_SET_ADDRESS:
  1315. if (u.r.bRequestType == USB_RECIP_DEVICE) {
  1316. ep0start(dev, 0, "address");
  1317. return;
  1318. }
  1319. break;
  1320. }
  1321. if (u.r.bRequestType & USB_DIR_IN)
  1322. dev->ep0state = EP0_IN_DATA_PHASE;
  1323. else
  1324. dev->ep0state = EP0_OUT_DATA_PHASE;
  1325. i = dev->driver->setup(&dev->gadget, &u.r);
  1326. if (i < 0) {
  1327. /* hardware automagic preventing STALL... */
  1328. if (dev->req_config) {
  1329. /* hardware sometimes neglects to tell
  1330. * tell us about config change events,
  1331. * so later ones may fail...
  1332. */
  1333. WARNING("config change %02x fail %d?\n",
  1334. u.r.bRequest, i);
  1335. return;
  1336. /* TODO experiment: if has_cfr,
  1337. * hardware didn't ACK; maybe we
  1338. * could actually STALL!
  1339. */
  1340. }
  1341. DBG(DBG_VERBOSE, "protocol STALL, "
  1342. "%02x err %d\n", UDCCS0, i);
  1343. stall:
  1344. /* the watchdog timer helps deal with cases
  1345. * where udc seems to clear FST wrongly, and
  1346. * then NAKs instead of STALLing.
  1347. */
  1348. ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
  1349. start_watchdog(dev);
  1350. dev->ep0state = EP0_STALL;
  1351. /* deferred i/o == no response yet */
  1352. } else if (dev->req_pending) {
  1353. if (likely(dev->ep0state == EP0_IN_DATA_PHASE
  1354. || dev->req_std || u.r.wLength))
  1355. ep0start(dev, 0, "defer");
  1356. else
  1357. ep0start(dev, UDCCS0_IPR, "defer/IPR");
  1358. }
  1359. /* expect at least one data or status stage irq */
  1360. return;
  1361. } else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
  1362. == (UDCCS0_OPR|UDCCS0_SA))) {
  1363. unsigned i;
  1364. /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
  1365. * still observed on a pxa255 a0.
  1366. */
  1367. DBG(DBG_VERBOSE, "e131\n");
  1368. nuke(ep, -EPROTO);
  1369. /* read SETUP data, but don't trust it too much */
  1370. for (i = 0; i < 8; i++)
  1371. u.raw [i] = (u8) UDDR0;
  1372. if ((u.r.bRequestType & USB_RECIP_MASK)
  1373. > USB_RECIP_OTHER)
  1374. goto stall;
  1375. if (u.word [0] == 0 && u.word [1] == 0)
  1376. goto stall;
  1377. goto got_setup;
  1378. } else {
  1379. /* some random early IRQ:
  1380. * - we acked FST
  1381. * - IPR cleared
  1382. * - OPR got set, without SA (likely status stage)
  1383. */
  1384. UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
  1385. }
  1386. break;
  1387. case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
  1388. if (udccs0 & UDCCS0_OPR) {
  1389. UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
  1390. DBG(DBG_VERBOSE, "ep0in premature status\n");
  1391. if (req)
  1392. done(ep, req, 0);
  1393. ep0_idle(dev);
  1394. } else /* irq was IPR clearing */ {
  1395. if (req) {
  1396. /* this IN packet might finish the request */
  1397. (void) write_ep0_fifo(ep, req);
  1398. } /* else IN token before response was written */
  1399. }
  1400. break;
  1401. case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
  1402. if (udccs0 & UDCCS0_OPR) {
  1403. if (req) {
  1404. /* this OUT packet might finish the request */
  1405. if (read_ep0_fifo(ep, req))
  1406. done(ep, req, 0);
  1407. /* else more OUT packets expected */
  1408. } /* else OUT token before read was issued */
  1409. } else /* irq was IPR clearing */ {
  1410. DBG(DBG_VERBOSE, "ep0out premature status\n");
  1411. if (req)
  1412. done(ep, req, 0);
  1413. ep0_idle(dev);
  1414. }
  1415. break;
  1416. case EP0_END_XFER:
  1417. if (req)
  1418. done(ep, req, 0);
  1419. /* ack control-IN status (maybe in-zlp was skipped)
  1420. * also appears after some config change events.
  1421. */
  1422. if (udccs0 & UDCCS0_OPR)
  1423. UDCCS0 = UDCCS0_OPR;
  1424. ep0_idle(dev);
  1425. break;
  1426. case EP0_STALL:
  1427. UDCCS0 = UDCCS0_FST;
  1428. break;
  1429. }
  1430. USIR0 = USIR0_IR0;
  1431. }
  1432. static void handle_ep(struct pxa25x_ep *ep)
  1433. {
  1434. struct pxa25x_request *req;
  1435. int is_in = ep->bEndpointAddress & USB_DIR_IN;
  1436. int completed;
  1437. u32 udccs, tmp;
  1438. do {
  1439. completed = 0;
  1440. if (likely (!list_empty(&ep->queue)))
  1441. req = list_entry(ep->queue.next,
  1442. struct pxa25x_request, queue);
  1443. else
  1444. req = NULL;
  1445. // TODO check FST handling
  1446. udccs = *ep->reg_udccs;
  1447. if (unlikely(is_in)) { /* irq from TPC, SST, or (ISO) TUR */
  1448. tmp = UDCCS_BI_TUR;
  1449. if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
  1450. tmp |= UDCCS_BI_SST;
  1451. tmp &= udccs;
  1452. if (likely (tmp))
  1453. *ep->reg_udccs = tmp;
  1454. if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
  1455. completed = write_fifo(ep, req);
  1456. } else { /* irq from RPC (or for ISO, ROF) */
  1457. if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
  1458. tmp = UDCCS_BO_SST | UDCCS_BO_DME;
  1459. else
  1460. tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
  1461. tmp &= udccs;
  1462. if (likely(tmp))
  1463. *ep->reg_udccs = tmp;
  1464. /* fifos can hold packets, ready for reading... */
  1465. if (likely(req)) {
  1466. completed = read_fifo(ep, req);
  1467. } else
  1468. pio_irq_disable (ep->bEndpointAddress);
  1469. }
  1470. ep->pio_irqs++;
  1471. } while (completed);
  1472. }
  1473. /*
  1474. * pxa25x_udc_irq - interrupt handler
  1475. *
  1476. * avoid delays in ep0 processing. the control handshaking isn't always
  1477. * under software control (pxa250c0 and the pxa255 are better), and delays
  1478. * could cause usb protocol errors.
  1479. */
  1480. static irqreturn_t
  1481. pxa25x_udc_irq(int irq, void *_dev)
  1482. {
  1483. struct pxa25x_udc *dev = _dev;
  1484. int handled;
  1485. dev->stats.irqs++;
  1486. do {
  1487. u32 udccr = UDCCR;
  1488. handled = 0;
  1489. /* SUSpend Interrupt Request */
  1490. if (unlikely(udccr & UDCCR_SUSIR)) {
  1491. udc_ack_int_UDCCR(UDCCR_SUSIR);
  1492. handled = 1;
  1493. DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
  1494. ? "" : "+disconnect");
  1495. if (!is_vbus_present())
  1496. stop_activity(dev, dev->driver);
  1497. else if (dev->gadget.speed != USB_SPEED_UNKNOWN
  1498. && dev->driver
  1499. && dev->driver->suspend)
  1500. dev->driver->suspend(&dev->gadget);
  1501. ep0_idle (dev);
  1502. }
  1503. /* RESume Interrupt Request */
  1504. if (unlikely(udccr & UDCCR_RESIR)) {
  1505. udc_ack_int_UDCCR(UDCCR_RESIR);
  1506. handled = 1;
  1507. DBG(DBG_VERBOSE, "USB resume\n");
  1508. if (dev->gadget.speed != USB_SPEED_UNKNOWN
  1509. && dev->driver
  1510. && dev->driver->resume
  1511. && is_vbus_present())
  1512. dev->driver->resume(&dev->gadget);
  1513. }
  1514. /* ReSeT Interrupt Request - USB reset */
  1515. if (unlikely(udccr & UDCCR_RSTIR)) {
  1516. udc_ack_int_UDCCR(UDCCR_RSTIR);
  1517. handled = 1;
  1518. if ((UDCCR & UDCCR_UDA) == 0) {
  1519. DBG(DBG_VERBOSE, "USB reset start\n");
  1520. /* reset driver and endpoints,
  1521. * in case that's not yet done
  1522. */
  1523. stop_activity (dev, dev->driver);
  1524. } else {
  1525. DBG(DBG_VERBOSE, "USB reset end\n");
  1526. dev->gadget.speed = USB_SPEED_FULL;
  1527. memset(&dev->stats, 0, sizeof dev->stats);
  1528. /* driver and endpoints are still reset */
  1529. }
  1530. } else {
  1531. u32 usir0 = USIR0 & ~UICR0;
  1532. u32 usir1 = USIR1 & ~UICR1;
  1533. int i;
  1534. if (unlikely (!usir0 && !usir1))
  1535. continue;
  1536. DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
  1537. /* control traffic */
  1538. if (usir0 & USIR0_IR0) {
  1539. dev->ep[0].pio_irqs++;
  1540. handle_ep0(dev);
  1541. handled = 1;
  1542. }
  1543. /* endpoint data transfers */
  1544. for (i = 0; i < 8; i++) {
  1545. u32 tmp = 1 << i;
  1546. if (i && (usir0 & tmp)) {
  1547. handle_ep(&dev->ep[i]);
  1548. USIR0 |= tmp;
  1549. handled = 1;
  1550. }
  1551. #ifndef CONFIG_USB_PXA25X_SMALL
  1552. if (usir1 & tmp) {
  1553. handle_ep(&dev->ep[i+8]);
  1554. USIR1 |= tmp;
  1555. handled = 1;
  1556. }
  1557. #endif
  1558. }
  1559. }
  1560. /* we could also ask for 1 msec SOF (SIR) interrupts */
  1561. } while (handled);
  1562. return IRQ_HANDLED;
  1563. }
  1564. /*-------------------------------------------------------------------------*/
  1565. static void nop_release (struct device *dev)
  1566. {
  1567. DMSG("%s %s\n", __func__, dev_name(dev));
  1568. }
  1569. /* this uses load-time allocation and initialization (instead of
  1570. * doing it at run-time) to save code, eliminate fault paths, and
  1571. * be more obviously correct.
  1572. */
  1573. static struct pxa25x_udc memory = {
  1574. .gadget = {
  1575. .ops = &pxa25x_udc_ops,
  1576. .ep0 = &memory.ep[0].ep,
  1577. .name = driver_name,
  1578. .dev = {
  1579. .init_name = "gadget",
  1580. .release = nop_release,
  1581. },
  1582. },
  1583. /* control endpoint */
  1584. .ep[0] = {
  1585. .ep = {
  1586. .name = ep0name,
  1587. .ops = &pxa25x_ep_ops,
  1588. .maxpacket = EP0_FIFO_SIZE,
  1589. },
  1590. .dev = &memory,
  1591. .reg_udccs = &UDCCS0,
  1592. .reg_uddr = &UDDR0,
  1593. },
  1594. /* first group of endpoints */
  1595. .ep[1] = {
  1596. .ep = {
  1597. .name = "ep1in-bulk",
  1598. .ops = &pxa25x_ep_ops,
  1599. .maxpacket = BULK_FIFO_SIZE,
  1600. },
  1601. .dev = &memory,
  1602. .fifo_size = BULK_FIFO_SIZE,
  1603. .bEndpointAddress = USB_DIR_IN | 1,
  1604. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1605. .reg_udccs = &UDCCS1,
  1606. .reg_uddr = &UDDR1,
  1607. },
  1608. .ep[2] = {
  1609. .ep = {
  1610. .name = "ep2out-bulk",
  1611. .ops = &pxa25x_ep_ops,
  1612. .maxpacket = BULK_FIFO_SIZE,
  1613. },
  1614. .dev = &memory,
  1615. .fifo_size = BULK_FIFO_SIZE,
  1616. .bEndpointAddress = 2,
  1617. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1618. .reg_udccs = &UDCCS2,
  1619. .reg_ubcr = &UBCR2,
  1620. .reg_uddr = &UDDR2,
  1621. },
  1622. #ifndef CONFIG_USB_PXA25X_SMALL
  1623. .ep[3] = {
  1624. .ep = {
  1625. .name = "ep3in-iso",
  1626. .ops = &pxa25x_ep_ops,
  1627. .maxpacket = ISO_FIFO_SIZE,
  1628. },
  1629. .dev = &memory,
  1630. .fifo_size = ISO_FIFO_SIZE,
  1631. .bEndpointAddress = USB_DIR_IN | 3,
  1632. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1633. .reg_udccs = &UDCCS3,
  1634. .reg_uddr = &UDDR3,
  1635. },
  1636. .ep[4] = {
  1637. .ep = {
  1638. .name = "ep4out-iso",
  1639. .ops = &pxa25x_ep_ops,
  1640. .maxpacket = ISO_FIFO_SIZE,
  1641. },
  1642. .dev = &memory,
  1643. .fifo_size = ISO_FIFO_SIZE,
  1644. .bEndpointAddress = 4,
  1645. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1646. .reg_udccs = &UDCCS4,
  1647. .reg_ubcr = &UBCR4,
  1648. .reg_uddr = &UDDR4,
  1649. },
  1650. .ep[5] = {
  1651. .ep = {
  1652. .name = "ep5in-int",
  1653. .ops = &pxa25x_ep_ops,
  1654. .maxpacket = INT_FIFO_SIZE,
  1655. },
  1656. .dev = &memory,
  1657. .fifo_size = INT_FIFO_SIZE,
  1658. .bEndpointAddress = USB_DIR_IN | 5,
  1659. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1660. .reg_udccs = &UDCCS5,
  1661. .reg_uddr = &UDDR5,
  1662. },
  1663. /* second group of endpoints */
  1664. .ep[6] = {
  1665. .ep = {
  1666. .name = "ep6in-bulk",
  1667. .ops = &pxa25x_ep_ops,
  1668. .maxpacket = BULK_FIFO_SIZE,
  1669. },
  1670. .dev = &memory,
  1671. .fifo_size = BULK_FIFO_SIZE,
  1672. .bEndpointAddress = USB_DIR_IN | 6,
  1673. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1674. .reg_udccs = &UDCCS6,
  1675. .reg_uddr = &UDDR6,
  1676. },
  1677. .ep[7] = {
  1678. .ep = {
  1679. .name = "ep7out-bulk",
  1680. .ops = &pxa25x_ep_ops,
  1681. .maxpacket = BULK_FIFO_SIZE,
  1682. },
  1683. .dev = &memory,
  1684. .fifo_size = BULK_FIFO_SIZE,
  1685. .bEndpointAddress = 7,
  1686. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1687. .reg_udccs = &UDCCS7,
  1688. .reg_ubcr = &UBCR7,
  1689. .reg_uddr = &UDDR7,
  1690. },
  1691. .ep[8] = {
  1692. .ep = {
  1693. .name = "ep8in-iso",
  1694. .ops = &pxa25x_ep_ops,
  1695. .maxpacket = ISO_FIFO_SIZE,
  1696. },
  1697. .dev = &memory,
  1698. .fifo_size = ISO_FIFO_SIZE,
  1699. .bEndpointAddress = USB_DIR_IN | 8,
  1700. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1701. .reg_udccs = &UDCCS8,
  1702. .reg_uddr = &UDDR8,
  1703. },
  1704. .ep[9] = {
  1705. .ep = {
  1706. .name = "ep9out-iso",
  1707. .ops = &pxa25x_ep_ops,
  1708. .maxpacket = ISO_FIFO_SIZE,
  1709. },
  1710. .dev = &memory,
  1711. .fifo_size = ISO_FIFO_SIZE,
  1712. .bEndpointAddress = 9,
  1713. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1714. .reg_udccs = &UDCCS9,
  1715. .reg_ubcr = &UBCR9,
  1716. .reg_uddr = &UDDR9,
  1717. },
  1718. .ep[10] = {
  1719. .ep = {
  1720. .name = "ep10in-int",
  1721. .ops = &pxa25x_ep_ops,
  1722. .maxpacket = INT_FIFO_SIZE,
  1723. },
  1724. .dev = &memory,
  1725. .fifo_size = INT_FIFO_SIZE,
  1726. .bEndpointAddress = USB_DIR_IN | 10,
  1727. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1728. .reg_udccs = &UDCCS10,
  1729. .reg_uddr = &UDDR10,
  1730. },
  1731. /* third group of endpoints */
  1732. .ep[11] = {
  1733. .ep = {
  1734. .name = "ep11in-bulk",
  1735. .ops = &pxa25x_ep_ops,
  1736. .maxpacket = BULK_FIFO_SIZE,
  1737. },
  1738. .dev = &memory,
  1739. .fifo_size = BULK_FIFO_SIZE,
  1740. .bEndpointAddress = USB_DIR_IN | 11,
  1741. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1742. .reg_udccs = &UDCCS11,
  1743. .reg_uddr = &UDDR11,
  1744. },
  1745. .ep[12] = {
  1746. .ep = {
  1747. .name = "ep12out-bulk",
  1748. .ops = &pxa25x_ep_ops,
  1749. .maxpacket = BULK_FIFO_SIZE,
  1750. },
  1751. .dev = &memory,
  1752. .fifo_size = BULK_FIFO_SIZE,
  1753. .bEndpointAddress = 12,
  1754. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1755. .reg_udccs = &UDCCS12,
  1756. .reg_ubcr = &UBCR12,
  1757. .reg_uddr = &UDDR12,
  1758. },
  1759. .ep[13] = {
  1760. .ep = {
  1761. .name = "ep13in-iso",
  1762. .ops = &pxa25x_ep_ops,
  1763. .maxpacket = ISO_FIFO_SIZE,
  1764. },
  1765. .dev = &memory,
  1766. .fifo_size = ISO_FIFO_SIZE,
  1767. .bEndpointAddress = USB_DIR_IN | 13,
  1768. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1769. .reg_udccs = &UDCCS13,
  1770. .reg_uddr = &UDDR13,
  1771. },
  1772. .ep[14] = {
  1773. .ep = {
  1774. .name = "ep14out-iso",
  1775. .ops = &pxa25x_ep_ops,
  1776. .maxpacket = ISO_FIFO_SIZE,
  1777. },
  1778. .dev = &memory,
  1779. .fifo_size = ISO_FIFO_SIZE,
  1780. .bEndpointAddress = 14,
  1781. .bmAttributes = USB_ENDPOINT_XFER_ISOC,
  1782. .reg_udccs = &UDCCS14,
  1783. .reg_ubcr = &UBCR14,
  1784. .reg_uddr = &UDDR14,
  1785. },
  1786. .ep[15] = {
  1787. .ep = {
  1788. .name = "ep15in-int",
  1789. .ops = &pxa25x_ep_ops,
  1790. .maxpacket = INT_FIFO_SIZE,
  1791. },
  1792. .dev = &memory,
  1793. .fifo_size = INT_FIFO_SIZE,
  1794. .bEndpointAddress = USB_DIR_IN | 15,
  1795. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1796. .reg_udccs = &UDCCS15,
  1797. .reg_uddr = &UDDR15,
  1798. },
  1799. #endif /* !CONFIG_USB_PXA25X_SMALL */
  1800. };
  1801. #define CP15R0_VENDOR_MASK 0xffffe000
  1802. #if defined(CONFIG_ARCH_PXA)
  1803. #define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
  1804. #elif defined(CONFIG_ARCH_IXP4XX)
  1805. #define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
  1806. #endif
  1807. #define CP15R0_PROD_MASK 0x000003f0
  1808. #define PXA25x 0x00000100 /* and PXA26x */
  1809. #define PXA210 0x00000120
  1810. #define CP15R0_REV_MASK 0x0000000f
  1811. #define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
  1812. #define PXA255_A0 0x00000106 /* or PXA260_B1 */
  1813. #define PXA250_C0 0x00000105 /* or PXA26x_B0 */
  1814. #define PXA250_B2 0x00000104
  1815. #define PXA250_B1 0x00000103 /* or PXA260_A0 */
  1816. #define PXA250_B0 0x00000102
  1817. #define PXA250_A1 0x00000101
  1818. #define PXA250_A0 0x00000100
  1819. #define PXA210_C0 0x00000125
  1820. #define PXA210_B2 0x00000124
  1821. #define PXA210_B1 0x00000123
  1822. #define PXA210_B0 0x00000122
  1823. #define IXP425_A0 0x000001c1
  1824. #define IXP425_B0 0x000001f1
  1825. #define IXP465_AD 0x00000200
  1826. /*
  1827. * probe - binds to the platform device
  1828. */
  1829. static int __init pxa25x_udc_probe(struct platform_device *pdev)
  1830. {
  1831. struct pxa25x_udc *dev = &memory;
  1832. int retval, vbus_irq, irq;
  1833. u32 chiprev;
  1834. /* insist on Intel/ARM/XScale */
  1835. asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
  1836. if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
  1837. pr_err("%s: not XScale!\n", driver_name);
  1838. return -ENODEV;
  1839. }
  1840. /* trigger chiprev-specific logic */
  1841. switch (chiprev & CP15R0_PRODREV_MASK) {
  1842. #if defined(CONFIG_ARCH_PXA)
  1843. case PXA255_A0:
  1844. dev->has_cfr = 1;
  1845. break;
  1846. case PXA250_A0:
  1847. case PXA250_A1:
  1848. /* A0/A1 "not released"; ep 13, 15 unusable */
  1849. /* fall through */
  1850. case PXA250_B2: case PXA210_B2:
  1851. case PXA250_B1: case PXA210_B1:
  1852. case PXA250_B0: case PXA210_B0:
  1853. /* OUT-DMA is broken ... */
  1854. /* fall through */
  1855. case PXA250_C0: case PXA210_C0:
  1856. break;
  1857. #elif defined(CONFIG_ARCH_IXP4XX)
  1858. case IXP425_A0:
  1859. case IXP425_B0:
  1860. case IXP465_AD:
  1861. dev->has_cfr = 1;
  1862. break;
  1863. #endif
  1864. default:
  1865. pr_err("%s: unrecognized processor: %08x\n",
  1866. driver_name, chiprev);
  1867. /* iop3xx, ixp4xx, ... */
  1868. return -ENODEV;
  1869. }
  1870. irq = platform_get_irq(pdev, 0);
  1871. if (irq < 0)
  1872. return -ENODEV;
  1873. dev->clk = clk_get(&pdev->dev, NULL);
  1874. if (IS_ERR(dev->clk)) {
  1875. retval = PTR_ERR(dev->clk);
  1876. goto err_clk;
  1877. }
  1878. pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
  1879. dev->has_cfr ? "" : " (!cfr)",
  1880. SIZE_STR "(pio)"
  1881. );
  1882. /* other non-static parts of init */
  1883. dev->dev = &pdev->dev;
  1884. dev->mach = pdev->dev.platform_data;
  1885. dev->transceiver = otg_get_transceiver();
  1886. if (gpio_is_valid(dev->mach->gpio_vbus)) {
  1887. if ((retval = gpio_request(dev->mach->gpio_vbus,
  1888. "pxa25x_udc GPIO VBUS"))) {
  1889. dev_dbg(&pdev->dev,
  1890. "can't get vbus gpio %d, err: %d\n",
  1891. dev->mach->gpio_vbus, retval);
  1892. goto err_gpio_vbus;
  1893. }
  1894. gpio_direction_input(dev->mach->gpio_vbus);
  1895. vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
  1896. } else
  1897. vbus_irq = 0;
  1898. if (gpio_is_valid(dev->mach->gpio_pullup)) {
  1899. if ((retval = gpio_request(dev->mach->gpio_pullup,
  1900. "pca25x_udc GPIO PULLUP"))) {
  1901. dev_dbg(&pdev->dev,
  1902. "can't get pullup gpio %d, err: %d\n",
  1903. dev->mach->gpio_pullup, retval);
  1904. goto err_gpio_pullup;
  1905. }
  1906. gpio_direction_output(dev->mach->gpio_pullup, 0);
  1907. }
  1908. init_timer(&dev->timer);
  1909. dev->timer.function = udc_watchdog;
  1910. dev->timer.data = (unsigned long) dev;
  1911. device_initialize(&dev->gadget.dev);
  1912. dev->gadget.dev.parent = &pdev->dev;
  1913. dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
  1914. the_controller = dev;
  1915. platform_set_drvdata(pdev, dev);
  1916. udc_disable(dev);
  1917. udc_reinit(dev);
  1918. dev->vbus = !!is_vbus_present();
  1919. /* irq setup after old hardware state is cleaned up */
  1920. retval = request_irq(irq, pxa25x_udc_irq,
  1921. IRQF_DISABLED, driver_name, dev);
  1922. if (retval != 0) {
  1923. pr_err("%s: can't get irq %d, err %d\n",
  1924. driver_name, irq, retval);
  1925. goto err_irq1;
  1926. }
  1927. dev->got_irq = 1;
  1928. #ifdef CONFIG_ARCH_LUBBOCK
  1929. if (machine_is_lubbock()) {
  1930. retval = request_irq(LUBBOCK_USB_DISC_IRQ,
  1931. lubbock_vbus_irq,
  1932. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  1933. driver_name, dev);
  1934. if (retval != 0) {
  1935. pr_err("%s: can't get irq %i, err %d\n",
  1936. driver_name, LUBBOCK_USB_DISC_IRQ, retval);
  1937. lubbock_fail0:
  1938. goto err_irq_lub;
  1939. }
  1940. retval = request_irq(LUBBOCK_USB_IRQ,
  1941. lubbock_vbus_irq,
  1942. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  1943. driver_name, dev);
  1944. if (retval != 0) {
  1945. pr_err("%s: can't get irq %i, err %d\n",
  1946. driver_name, LUBBOCK_USB_IRQ, retval);
  1947. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  1948. goto lubbock_fail0;
  1949. }
  1950. } else
  1951. #endif
  1952. if (vbus_irq) {
  1953. retval = request_irq(vbus_irq, udc_vbus_irq,
  1954. IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  1955. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  1956. driver_name, dev);
  1957. if (retval != 0) {
  1958. pr_err("%s: can't get irq %i, err %d\n",
  1959. driver_name, vbus_irq, retval);
  1960. goto err_vbus_irq;
  1961. }
  1962. }
  1963. create_debug_files(dev);
  1964. return 0;
  1965. err_vbus_irq:
  1966. #ifdef CONFIG_ARCH_LUBBOCK
  1967. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  1968. err_irq_lub:
  1969. #endif
  1970. free_irq(irq, dev);
  1971. err_irq1:
  1972. if (gpio_is_valid(dev->mach->gpio_pullup))
  1973. gpio_free(dev->mach->gpio_pullup);
  1974. err_gpio_pullup:
  1975. if (gpio_is_valid(dev->mach->gpio_vbus))
  1976. gpio_free(dev->mach->gpio_vbus);
  1977. err_gpio_vbus:
  1978. if (dev->transceiver) {
  1979. otg_put_transceiver(dev->transceiver);
  1980. dev->transceiver = NULL;
  1981. }
  1982. clk_put(dev->clk);
  1983. err_clk:
  1984. return retval;
  1985. }
  1986. static void pxa25x_udc_shutdown(struct platform_device *_dev)
  1987. {
  1988. pullup_off();
  1989. }
  1990. static int __exit pxa25x_udc_remove(struct platform_device *pdev)
  1991. {
  1992. struct pxa25x_udc *dev = platform_get_drvdata(pdev);
  1993. if (dev->driver)
  1994. return -EBUSY;
  1995. dev->pullup = 0;
  1996. pullup(dev);
  1997. remove_debug_files(dev);
  1998. if (dev->got_irq) {
  1999. free_irq(platform_get_irq(pdev, 0), dev);
  2000. dev->got_irq = 0;
  2001. }
  2002. #ifdef CONFIG_ARCH_LUBBOCK
  2003. if (machine_is_lubbock()) {
  2004. free_irq(LUBBOCK_USB_DISC_IRQ, dev);
  2005. free_irq(LUBBOCK_USB_IRQ, dev);
  2006. }
  2007. #endif
  2008. if (gpio_is_valid(dev->mach->gpio_vbus)) {
  2009. free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
  2010. gpio_free(dev->mach->gpio_vbus);
  2011. }
  2012. if (gpio_is_valid(dev->mach->gpio_pullup))
  2013. gpio_free(dev->mach->gpio_pullup);
  2014. clk_put(dev->clk);
  2015. if (dev->transceiver) {
  2016. otg_put_transceiver(dev->transceiver);
  2017. dev->transceiver = NULL;
  2018. }
  2019. platform_set_drvdata(pdev, NULL);
  2020. the_controller = NULL;
  2021. return 0;
  2022. }
  2023. /*-------------------------------------------------------------------------*/
  2024. #ifdef CONFIG_PM
  2025. /* USB suspend (controlled by the host) and system suspend (controlled
  2026. * by the PXA) don't necessarily work well together. If USB is active,
  2027. * the 48 MHz clock is required; so the system can't enter 33 MHz idle
  2028. * mode, or any deeper PM saving state.
  2029. *
  2030. * For now, we punt and forcibly disconnect from the USB host when PXA
  2031. * enters any suspend state. While we're disconnected, we always disable
  2032. * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
  2033. * Boards without software pullup control shouldn't use those states.
  2034. * VBUS IRQs should probably be ignored so that the PXA device just acts
  2035. * "dead" to USB hosts until system resume.
  2036. */
  2037. static int pxa25x_udc_suspend(struct platform_device *dev, pm_message_t state)
  2038. {
  2039. struct pxa25x_udc *udc = platform_get_drvdata(dev);
  2040. unsigned long flags;
  2041. if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
  2042. WARNING("USB host won't detect disconnect!\n");
  2043. udc->suspended = 1;
  2044. local_irq_save(flags);
  2045. pullup(udc);
  2046. local_irq_restore(flags);
  2047. return 0;
  2048. }
  2049. static int pxa25x_udc_resume(struct platform_device *dev)
  2050. {
  2051. struct pxa25x_udc *udc = platform_get_drvdata(dev);
  2052. unsigned long flags;
  2053. udc->suspended = 0;
  2054. local_irq_save(flags);
  2055. pullup(udc);
  2056. local_irq_restore(flags);
  2057. return 0;
  2058. }
  2059. #else
  2060. #define pxa25x_udc_suspend NULL
  2061. #define pxa25x_udc_resume NULL
  2062. #endif
  2063. /*-------------------------------------------------------------------------*/
  2064. static struct platform_driver udc_driver = {
  2065. .shutdown = pxa25x_udc_shutdown,
  2066. .remove = __exit_p(pxa25x_udc_remove),
  2067. .suspend = pxa25x_udc_suspend,
  2068. .resume = pxa25x_udc_resume,
  2069. .driver = {
  2070. .owner = THIS_MODULE,
  2071. .name = "pxa25x-udc",
  2072. },
  2073. };
  2074. static int __init udc_init(void)
  2075. {
  2076. pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
  2077. return platform_driver_probe(&udc_driver, pxa25x_udc_probe);
  2078. }
  2079. module_init(udc_init);
  2080. static void __exit udc_exit(void)
  2081. {
  2082. platform_driver_unregister(&udc_driver);
  2083. }
  2084. module_exit(udc_exit);
  2085. MODULE_DESCRIPTION(DRIVER_DESC);
  2086. MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
  2087. MODULE_LICENSE("GPL");
  2088. MODULE_ALIAS("platform:pxa25x-udc");