musb_host.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327
  1. /*
  2. * MUSB OTG driver host support
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  26. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  28. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  29. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  32. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. #include <linux/module.h>
  36. #include <linux/kernel.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/slab.h>
  40. #include <linux/errno.h>
  41. #include <linux/init.h>
  42. #include <linux/list.h>
  43. #include "musb_core.h"
  44. #include "musb_host.h"
  45. /* MUSB HOST status 22-mar-2006
  46. *
  47. * - There's still lots of partial code duplication for fault paths, so
  48. * they aren't handled as consistently as they need to be.
  49. *
  50. * - PIO mostly behaved when last tested.
  51. * + including ep0, with all usbtest cases 9, 10
  52. * + usbtest 14 (ep0out) doesn't seem to run at all
  53. * + double buffered OUT/TX endpoints saw stalls(!) with certain usbtest
  54. * configurations, but otherwise double buffering passes basic tests.
  55. * + for 2.6.N, for N > ~10, needs API changes for hcd framework.
  56. *
  57. * - DMA (CPPI) ... partially behaves, not currently recommended
  58. * + about 1/15 the speed of typical EHCI implementations (PCI)
  59. * + RX, all too often reqpkt seems to misbehave after tx
  60. * + TX, no known issues (other than evident silicon issue)
  61. *
  62. * - DMA (Mentor/OMAP) ...has at least toggle update problems
  63. *
  64. * - [23-feb-2009] minimal traffic scheduling to avoid bulk RX packet
  65. * starvation ... nothing yet for TX, interrupt, or bulk.
  66. *
  67. * - Not tested with HNP, but some SRP paths seem to behave.
  68. *
  69. * NOTE 24-August-2006:
  70. *
  71. * - Bulk traffic finally uses both sides of hardware ep1, freeing up an
  72. * extra endpoint for periodic use enabling hub + keybd + mouse. That
  73. * mostly works, except that with "usbnet" it's easy to trigger cases
  74. * with "ping" where RX loses. (a) ping to davinci, even "ping -f",
  75. * fine; but (b) ping _from_ davinci, even "ping -c 1", ICMP RX loses
  76. * although ARP RX wins. (That test was done with a full speed link.)
  77. */
  78. /*
  79. * NOTE on endpoint usage:
  80. *
  81. * CONTROL transfers all go through ep0. BULK ones go through dedicated IN
  82. * and OUT endpoints ... hardware is dedicated for those "async" queue(s).
  83. * (Yes, bulk _could_ use more of the endpoints than that, and would even
  84. * benefit from it.)
  85. *
  86. * INTERUPPT and ISOCHRONOUS transfers are scheduled to the other endpoints.
  87. * So far that scheduling is both dumb and optimistic: the endpoint will be
  88. * "claimed" until its software queue is no longer refilled. No multiplexing
  89. * of transfers between endpoints, or anything clever.
  90. */
  91. static void musb_ep_program(struct musb *musb, u8 epnum,
  92. struct urb *urb, int is_out,
  93. u8 *buf, u32 offset, u32 len);
  94. /*
  95. * Clear TX fifo. Needed to avoid BABBLE errors.
  96. */
  97. static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep)
  98. {
  99. void __iomem *epio = ep->regs;
  100. u16 csr;
  101. u16 lastcsr = 0;
  102. int retries = 1000;
  103. csr = musb_readw(epio, MUSB_TXCSR);
  104. while (csr & MUSB_TXCSR_FIFONOTEMPTY) {
  105. if (csr != lastcsr)
  106. DBG(3, "Host TX FIFONOTEMPTY csr: %02x\n", csr);
  107. lastcsr = csr;
  108. csr |= MUSB_TXCSR_FLUSHFIFO;
  109. musb_writew(epio, MUSB_TXCSR, csr);
  110. csr = musb_readw(epio, MUSB_TXCSR);
  111. if (WARN(retries-- < 1,
  112. "Could not flush host TX%d fifo: csr: %04x\n",
  113. ep->epnum, csr))
  114. return;
  115. mdelay(1);
  116. }
  117. }
  118. static void musb_h_ep0_flush_fifo(struct musb_hw_ep *ep)
  119. {
  120. void __iomem *epio = ep->regs;
  121. u16 csr;
  122. int retries = 5;
  123. /* scrub any data left in the fifo */
  124. do {
  125. csr = musb_readw(epio, MUSB_TXCSR);
  126. if (!(csr & (MUSB_CSR0_TXPKTRDY | MUSB_CSR0_RXPKTRDY)))
  127. break;
  128. musb_writew(epio, MUSB_TXCSR, MUSB_CSR0_FLUSHFIFO);
  129. csr = musb_readw(epio, MUSB_TXCSR);
  130. udelay(10);
  131. } while (--retries);
  132. WARN(!retries, "Could not flush host TX%d fifo: csr: %04x\n",
  133. ep->epnum, csr);
  134. /* and reset for the next transfer */
  135. musb_writew(epio, MUSB_TXCSR, 0);
  136. }
  137. /*
  138. * Start transmit. Caller is responsible for locking shared resources.
  139. * musb must be locked.
  140. */
  141. static inline void musb_h_tx_start(struct musb_hw_ep *ep)
  142. {
  143. u16 txcsr;
  144. /* NOTE: no locks here; caller should lock and select EP */
  145. if (ep->epnum) {
  146. txcsr = musb_readw(ep->regs, MUSB_TXCSR);
  147. txcsr |= MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_H_WZC_BITS;
  148. musb_writew(ep->regs, MUSB_TXCSR, txcsr);
  149. } else {
  150. txcsr = MUSB_CSR0_H_SETUPPKT | MUSB_CSR0_TXPKTRDY;
  151. musb_writew(ep->regs, MUSB_CSR0, txcsr);
  152. }
  153. }
  154. static inline void musb_h_tx_dma_start(struct musb_hw_ep *ep)
  155. {
  156. u16 txcsr;
  157. /* NOTE: no locks here; caller should lock and select EP */
  158. txcsr = musb_readw(ep->regs, MUSB_TXCSR);
  159. txcsr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_H_WZC_BITS;
  160. if (is_cppi_enabled())
  161. txcsr |= MUSB_TXCSR_DMAMODE;
  162. musb_writew(ep->regs, MUSB_TXCSR, txcsr);
  163. }
  164. /*
  165. * Start the URB at the front of an endpoint's queue
  166. * end must be claimed from the caller.
  167. *
  168. * Context: controller locked, irqs blocked
  169. */
  170. static void
  171. musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
  172. {
  173. u16 frame;
  174. u32 len;
  175. void __iomem *mbase = musb->mregs;
  176. struct urb *urb = next_urb(qh);
  177. void *buf = urb->transfer_buffer;
  178. u32 offset = 0;
  179. struct musb_hw_ep *hw_ep = qh->hw_ep;
  180. unsigned pipe = urb->pipe;
  181. u8 address = usb_pipedevice(pipe);
  182. int epnum = hw_ep->epnum;
  183. /* initialize software qh state */
  184. qh->offset = 0;
  185. qh->segsize = 0;
  186. /* gather right source of data */
  187. switch (qh->type) {
  188. case USB_ENDPOINT_XFER_CONTROL:
  189. /* control transfers always start with SETUP */
  190. is_in = 0;
  191. hw_ep->out_qh = qh;
  192. musb->ep0_stage = MUSB_EP0_START;
  193. buf = urb->setup_packet;
  194. len = 8;
  195. break;
  196. case USB_ENDPOINT_XFER_ISOC:
  197. qh->iso_idx = 0;
  198. qh->frame = 0;
  199. offset = urb->iso_frame_desc[0].offset;
  200. len = urb->iso_frame_desc[0].length;
  201. break;
  202. default: /* bulk, interrupt */
  203. /* actual_length may be nonzero on retry paths */
  204. buf = urb->transfer_buffer + urb->actual_length;
  205. len = urb->transfer_buffer_length - urb->actual_length;
  206. }
  207. DBG(4, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n",
  208. qh, urb, address, qh->epnum,
  209. is_in ? "in" : "out",
  210. ({char *s; switch (qh->type) {
  211. case USB_ENDPOINT_XFER_CONTROL: s = ""; break;
  212. case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break;
  213. case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break;
  214. default: s = "-intr"; break;
  215. }; s; }),
  216. epnum, buf + offset, len);
  217. /* Configure endpoint */
  218. if (is_in || hw_ep->is_shared_fifo)
  219. hw_ep->in_qh = qh;
  220. else
  221. hw_ep->out_qh = qh;
  222. musb_ep_program(musb, epnum, urb, !is_in, buf, offset, len);
  223. /* transmit may have more work: start it when it is time */
  224. if (is_in)
  225. return;
  226. /* determine if the time is right for a periodic transfer */
  227. switch (qh->type) {
  228. case USB_ENDPOINT_XFER_ISOC:
  229. case USB_ENDPOINT_XFER_INT:
  230. DBG(3, "check whether there's still time for periodic Tx\n");
  231. frame = musb_readw(mbase, MUSB_FRAME);
  232. /* FIXME this doesn't implement that scheduling policy ...
  233. * or handle framecounter wrapping
  234. */
  235. if ((urb->transfer_flags & URB_ISO_ASAP)
  236. || (frame >= urb->start_frame)) {
  237. /* REVISIT the SOF irq handler shouldn't duplicate
  238. * this code; and we don't init urb->start_frame...
  239. */
  240. qh->frame = 0;
  241. goto start;
  242. } else {
  243. qh->frame = urb->start_frame;
  244. /* enable SOF interrupt so we can count down */
  245. DBG(1, "SOF for %d\n", epnum);
  246. #if 1 /* ifndef CONFIG_ARCH_DAVINCI */
  247. musb_writeb(mbase, MUSB_INTRUSBE, 0xff);
  248. #endif
  249. }
  250. break;
  251. default:
  252. start:
  253. DBG(4, "Start TX%d %s\n", epnum,
  254. hw_ep->tx_channel ? "dma" : "pio");
  255. if (!hw_ep->tx_channel)
  256. musb_h_tx_start(hw_ep);
  257. else if (is_cppi_enabled() || tusb_dma_omap())
  258. musb_h_tx_dma_start(hw_ep);
  259. }
  260. }
  261. /* caller owns controller lock, irqs are blocked */
  262. static void
  263. __musb_giveback(struct musb *musb, struct urb *urb, int status)
  264. __releases(musb->lock)
  265. __acquires(musb->lock)
  266. {
  267. DBG(({ int level; switch (status) {
  268. case 0:
  269. level = 4;
  270. break;
  271. /* common/boring faults */
  272. case -EREMOTEIO:
  273. case -ESHUTDOWN:
  274. case -ECONNRESET:
  275. case -EPIPE:
  276. level = 3;
  277. break;
  278. default:
  279. level = 2;
  280. break;
  281. }; level; }),
  282. "complete %p %pF (%d), dev%d ep%d%s, %d/%d\n",
  283. urb, urb->complete, status,
  284. usb_pipedevice(urb->pipe),
  285. usb_pipeendpoint(urb->pipe),
  286. usb_pipein(urb->pipe) ? "in" : "out",
  287. urb->actual_length, urb->transfer_buffer_length
  288. );
  289. usb_hcd_unlink_urb_from_ep(musb_to_hcd(musb), urb);
  290. spin_unlock(&musb->lock);
  291. usb_hcd_giveback_urb(musb_to_hcd(musb), urb, status);
  292. spin_lock(&musb->lock);
  293. }
  294. /* For bulk/interrupt endpoints only */
  295. static inline void musb_save_toggle(struct musb_qh *qh, int is_in,
  296. struct urb *urb)
  297. {
  298. void __iomem *epio = qh->hw_ep->regs;
  299. u16 csr;
  300. /*
  301. * FIXME: the current Mentor DMA code seems to have
  302. * problems getting toggle correct.
  303. */
  304. if (is_in)
  305. csr = musb_readw(epio, MUSB_RXCSR) & MUSB_RXCSR_H_DATATOGGLE;
  306. else
  307. csr = musb_readw(epio, MUSB_TXCSR) & MUSB_TXCSR_H_DATATOGGLE;
  308. usb_settoggle(urb->dev, qh->epnum, !is_in, csr ? 1 : 0);
  309. }
  310. /* caller owns controller lock, irqs are blocked */
  311. static struct musb_qh *
  312. musb_giveback(struct musb_qh *qh, struct urb *urb, int status)
  313. {
  314. struct musb_hw_ep *ep = qh->hw_ep;
  315. struct musb *musb = ep->musb;
  316. int is_in = usb_pipein(urb->pipe);
  317. int ready = qh->is_ready;
  318. /* save toggle eagerly, for paranoia */
  319. switch (qh->type) {
  320. case USB_ENDPOINT_XFER_BULK:
  321. case USB_ENDPOINT_XFER_INT:
  322. musb_save_toggle(qh, is_in, urb);
  323. break;
  324. case USB_ENDPOINT_XFER_ISOC:
  325. if (status == 0 && urb->error_count)
  326. status = -EXDEV;
  327. break;
  328. }
  329. qh->is_ready = 0;
  330. __musb_giveback(musb, urb, status);
  331. qh->is_ready = ready;
  332. /* reclaim resources (and bandwidth) ASAP; deschedule it, and
  333. * invalidate qh as soon as list_empty(&hep->urb_list)
  334. */
  335. if (list_empty(&qh->hep->urb_list)) {
  336. struct list_head *head;
  337. if (is_in)
  338. ep->rx_reinit = 1;
  339. else
  340. ep->tx_reinit = 1;
  341. /* clobber old pointers to this qh */
  342. if (is_in || ep->is_shared_fifo)
  343. ep->in_qh = NULL;
  344. else
  345. ep->out_qh = NULL;
  346. qh->hep->hcpriv = NULL;
  347. switch (qh->type) {
  348. case USB_ENDPOINT_XFER_CONTROL:
  349. case USB_ENDPOINT_XFER_BULK:
  350. /* fifo policy for these lists, except that NAKing
  351. * should rotate a qh to the end (for fairness).
  352. */
  353. if (qh->mux == 1) {
  354. head = qh->ring.prev;
  355. list_del(&qh->ring);
  356. kfree(qh);
  357. qh = first_qh(head);
  358. break;
  359. }
  360. case USB_ENDPOINT_XFER_ISOC:
  361. case USB_ENDPOINT_XFER_INT:
  362. /* this is where periodic bandwidth should be
  363. * de-allocated if it's tracked and allocated;
  364. * and where we'd update the schedule tree...
  365. */
  366. kfree(qh);
  367. qh = NULL;
  368. break;
  369. }
  370. }
  371. return qh;
  372. }
  373. /*
  374. * Advance this hardware endpoint's queue, completing the specified urb and
  375. * advancing to either the next urb queued to that qh, or else invalidating
  376. * that qh and advancing to the next qh scheduled after the current one.
  377. *
  378. * Context: caller owns controller lock, irqs are blocked
  379. */
  380. static void
  381. musb_advance_schedule(struct musb *musb, struct urb *urb,
  382. struct musb_hw_ep *hw_ep, int is_in)
  383. {
  384. struct musb_qh *qh;
  385. if (is_in || hw_ep->is_shared_fifo)
  386. qh = hw_ep->in_qh;
  387. else
  388. qh = hw_ep->out_qh;
  389. if (urb->status == -EINPROGRESS)
  390. qh = musb_giveback(qh, urb, 0);
  391. else
  392. qh = musb_giveback(qh, urb, urb->status);
  393. if (qh != NULL && qh->is_ready) {
  394. DBG(4, "... next ep%d %cX urb %p\n",
  395. hw_ep->epnum, is_in ? 'R' : 'T',
  396. next_urb(qh));
  397. musb_start_urb(musb, is_in, qh);
  398. }
  399. }
  400. static u16 musb_h_flush_rxfifo(struct musb_hw_ep *hw_ep, u16 csr)
  401. {
  402. /* we don't want fifo to fill itself again;
  403. * ignore dma (various models),
  404. * leave toggle alone (may not have been saved yet)
  405. */
  406. csr |= MUSB_RXCSR_FLUSHFIFO | MUSB_RXCSR_RXPKTRDY;
  407. csr &= ~(MUSB_RXCSR_H_REQPKT
  408. | MUSB_RXCSR_H_AUTOREQ
  409. | MUSB_RXCSR_AUTOCLEAR);
  410. /* write 2x to allow double buffering */
  411. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  412. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  413. /* flush writebuffer */
  414. return musb_readw(hw_ep->regs, MUSB_RXCSR);
  415. }
  416. /*
  417. * PIO RX for a packet (or part of it).
  418. */
  419. static bool
  420. musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
  421. {
  422. u16 rx_count;
  423. u8 *buf;
  424. u16 csr;
  425. bool done = false;
  426. u32 length;
  427. int do_flush = 0;
  428. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  429. void __iomem *epio = hw_ep->regs;
  430. struct musb_qh *qh = hw_ep->in_qh;
  431. int pipe = urb->pipe;
  432. void *buffer = urb->transfer_buffer;
  433. /* musb_ep_select(mbase, epnum); */
  434. rx_count = musb_readw(epio, MUSB_RXCOUNT);
  435. DBG(3, "RX%d count %d, buffer %p len %d/%d\n", epnum, rx_count,
  436. urb->transfer_buffer, qh->offset,
  437. urb->transfer_buffer_length);
  438. /* unload FIFO */
  439. if (usb_pipeisoc(pipe)) {
  440. int status = 0;
  441. struct usb_iso_packet_descriptor *d;
  442. if (iso_err) {
  443. status = -EILSEQ;
  444. urb->error_count++;
  445. }
  446. d = urb->iso_frame_desc + qh->iso_idx;
  447. buf = buffer + d->offset;
  448. length = d->length;
  449. if (rx_count > length) {
  450. if (status == 0) {
  451. status = -EOVERFLOW;
  452. urb->error_count++;
  453. }
  454. DBG(2, "** OVERFLOW %d into %d\n", rx_count, length);
  455. do_flush = 1;
  456. } else
  457. length = rx_count;
  458. urb->actual_length += length;
  459. d->actual_length = length;
  460. d->status = status;
  461. /* see if we are done */
  462. done = (++qh->iso_idx >= urb->number_of_packets);
  463. } else {
  464. /* non-isoch */
  465. buf = buffer + qh->offset;
  466. length = urb->transfer_buffer_length - qh->offset;
  467. if (rx_count > length) {
  468. if (urb->status == -EINPROGRESS)
  469. urb->status = -EOVERFLOW;
  470. DBG(2, "** OVERFLOW %d into %d\n", rx_count, length);
  471. do_flush = 1;
  472. } else
  473. length = rx_count;
  474. urb->actual_length += length;
  475. qh->offset += length;
  476. /* see if we are done */
  477. done = (urb->actual_length == urb->transfer_buffer_length)
  478. || (rx_count < qh->maxpacket)
  479. || (urb->status != -EINPROGRESS);
  480. if (done
  481. && (urb->status == -EINPROGRESS)
  482. && (urb->transfer_flags & URB_SHORT_NOT_OK)
  483. && (urb->actual_length
  484. < urb->transfer_buffer_length))
  485. urb->status = -EREMOTEIO;
  486. }
  487. musb_read_fifo(hw_ep, length, buf);
  488. csr = musb_readw(epio, MUSB_RXCSR);
  489. csr |= MUSB_RXCSR_H_WZC_BITS;
  490. if (unlikely(do_flush))
  491. musb_h_flush_rxfifo(hw_ep, csr);
  492. else {
  493. /* REVISIT this assumes AUTOCLEAR is never set */
  494. csr &= ~(MUSB_RXCSR_RXPKTRDY | MUSB_RXCSR_H_REQPKT);
  495. if (!done)
  496. csr |= MUSB_RXCSR_H_REQPKT;
  497. musb_writew(epio, MUSB_RXCSR, csr);
  498. }
  499. return done;
  500. }
  501. /* we don't always need to reinit a given side of an endpoint...
  502. * when we do, use tx/rx reinit routine and then construct a new CSR
  503. * to address data toggle, NYET, and DMA or PIO.
  504. *
  505. * it's possible that driver bugs (especially for DMA) or aborting a
  506. * transfer might have left the endpoint busier than it should be.
  507. * the busy/not-empty tests are basically paranoia.
  508. */
  509. static void
  510. musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
  511. {
  512. u16 csr;
  513. /* NOTE: we know the "rx" fifo reinit never triggers for ep0.
  514. * That always uses tx_reinit since ep0 repurposes TX register
  515. * offsets; the initial SETUP packet is also a kind of OUT.
  516. */
  517. /* if programmed for Tx, put it in RX mode */
  518. if (ep->is_shared_fifo) {
  519. csr = musb_readw(ep->regs, MUSB_TXCSR);
  520. if (csr & MUSB_TXCSR_MODE) {
  521. musb_h_tx_flush_fifo(ep);
  522. csr = musb_readw(ep->regs, MUSB_TXCSR);
  523. musb_writew(ep->regs, MUSB_TXCSR,
  524. csr | MUSB_TXCSR_FRCDATATOG);
  525. }
  526. /*
  527. * Clear the MODE bit (and everything else) to enable Rx.
  528. * NOTE: we mustn't clear the DMAMODE bit before DMAENAB.
  529. */
  530. if (csr & MUSB_TXCSR_DMAMODE)
  531. musb_writew(ep->regs, MUSB_TXCSR, MUSB_TXCSR_DMAMODE);
  532. musb_writew(ep->regs, MUSB_TXCSR, 0);
  533. /* scrub all previous state, clearing toggle */
  534. } else {
  535. csr = musb_readw(ep->regs, MUSB_RXCSR);
  536. if (csr & MUSB_RXCSR_RXPKTRDY)
  537. WARNING("rx%d, packet/%d ready?\n", ep->epnum,
  538. musb_readw(ep->regs, MUSB_RXCOUNT));
  539. musb_h_flush_rxfifo(ep, MUSB_RXCSR_CLRDATATOG);
  540. }
  541. /* target addr and (for multipoint) hub addr/port */
  542. if (musb->is_multipoint) {
  543. musb_write_rxfunaddr(ep->target_regs, qh->addr_reg);
  544. musb_write_rxhubaddr(ep->target_regs, qh->h_addr_reg);
  545. musb_write_rxhubport(ep->target_regs, qh->h_port_reg);
  546. } else
  547. musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg);
  548. /* protocol/endpoint, interval/NAKlimit, i/o size */
  549. musb_writeb(ep->regs, MUSB_RXTYPE, qh->type_reg);
  550. musb_writeb(ep->regs, MUSB_RXINTERVAL, qh->intv_reg);
  551. /* NOTE: bulk combining rewrites high bits of maxpacket */
  552. musb_writew(ep->regs, MUSB_RXMAXP, qh->maxpacket);
  553. ep->rx_reinit = 0;
  554. }
  555. static bool musb_tx_dma_program(struct dma_controller *dma,
  556. struct musb_hw_ep *hw_ep, struct musb_qh *qh,
  557. struct urb *urb, u32 offset, u32 length)
  558. {
  559. struct dma_channel *channel = hw_ep->tx_channel;
  560. void __iomem *epio = hw_ep->regs;
  561. u16 pkt_size = qh->maxpacket;
  562. u16 csr;
  563. u8 mode;
  564. #ifdef CONFIG_USB_INVENTRA_DMA
  565. if (length > channel->max_len)
  566. length = channel->max_len;
  567. csr = musb_readw(epio, MUSB_TXCSR);
  568. if (length > pkt_size) {
  569. mode = 1;
  570. csr |= MUSB_TXCSR_AUTOSET
  571. | MUSB_TXCSR_DMAMODE
  572. | MUSB_TXCSR_DMAENAB;
  573. } else {
  574. mode = 0;
  575. csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAMODE);
  576. csr |= MUSB_TXCSR_DMAENAB; /* against programmer's guide */
  577. }
  578. channel->desired_mode = mode;
  579. musb_writew(epio, MUSB_TXCSR, csr);
  580. #else
  581. if (!is_cppi_enabled() && !tusb_dma_omap())
  582. return false;
  583. channel->actual_len = 0;
  584. /*
  585. * TX uses "RNDIS" mode automatically but needs help
  586. * to identify the zero-length-final-packet case.
  587. */
  588. mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0;
  589. #endif
  590. qh->segsize = length;
  591. if (!dma->channel_program(channel, pkt_size, mode,
  592. urb->transfer_dma + offset, length)) {
  593. dma->channel_release(channel);
  594. hw_ep->tx_channel = NULL;
  595. csr = musb_readw(epio, MUSB_TXCSR);
  596. csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAENAB);
  597. musb_writew(epio, MUSB_TXCSR, csr | MUSB_TXCSR_H_WZC_BITS);
  598. return false;
  599. }
  600. return true;
  601. }
  602. /*
  603. * Program an HDRC endpoint as per the given URB
  604. * Context: irqs blocked, controller lock held
  605. */
  606. static void musb_ep_program(struct musb *musb, u8 epnum,
  607. struct urb *urb, int is_out,
  608. u8 *buf, u32 offset, u32 len)
  609. {
  610. struct dma_controller *dma_controller;
  611. struct dma_channel *dma_channel;
  612. u8 dma_ok;
  613. void __iomem *mbase = musb->mregs;
  614. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  615. void __iomem *epio = hw_ep->regs;
  616. struct musb_qh *qh;
  617. u16 packet_sz;
  618. if (!is_out || hw_ep->is_shared_fifo)
  619. qh = hw_ep->in_qh;
  620. else
  621. qh = hw_ep->out_qh;
  622. packet_sz = qh->maxpacket;
  623. DBG(3, "%s hw%d urb %p spd%d dev%d ep%d%s "
  624. "h_addr%02x h_port%02x bytes %d\n",
  625. is_out ? "-->" : "<--",
  626. epnum, urb, urb->dev->speed,
  627. qh->addr_reg, qh->epnum, is_out ? "out" : "in",
  628. qh->h_addr_reg, qh->h_port_reg,
  629. len);
  630. musb_ep_select(mbase, epnum);
  631. /* candidate for DMA? */
  632. dma_controller = musb->dma_controller;
  633. if (is_dma_capable() && epnum && dma_controller) {
  634. dma_channel = is_out ? hw_ep->tx_channel : hw_ep->rx_channel;
  635. if (!dma_channel) {
  636. dma_channel = dma_controller->channel_alloc(
  637. dma_controller, hw_ep, is_out);
  638. if (is_out)
  639. hw_ep->tx_channel = dma_channel;
  640. else
  641. hw_ep->rx_channel = dma_channel;
  642. }
  643. } else
  644. dma_channel = NULL;
  645. /* make sure we clear DMAEnab, autoSet bits from previous run */
  646. /* OUT/transmit/EP0 or IN/receive? */
  647. if (is_out) {
  648. u16 csr;
  649. u16 int_txe;
  650. u16 load_count;
  651. csr = musb_readw(epio, MUSB_TXCSR);
  652. /* disable interrupt in case we flush */
  653. int_txe = musb_readw(mbase, MUSB_INTRTXE);
  654. musb_writew(mbase, MUSB_INTRTXE, int_txe & ~(1 << epnum));
  655. /* general endpoint setup */
  656. if (epnum) {
  657. /* flush all old state, set default */
  658. musb_h_tx_flush_fifo(hw_ep);
  659. /*
  660. * We must not clear the DMAMODE bit before or in
  661. * the same cycle with the DMAENAB bit, so we clear
  662. * the latter first...
  663. */
  664. csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
  665. | MUSB_TXCSR_AUTOSET
  666. | MUSB_TXCSR_DMAENAB
  667. | MUSB_TXCSR_FRCDATATOG
  668. | MUSB_TXCSR_H_RXSTALL
  669. | MUSB_TXCSR_H_ERROR
  670. | MUSB_TXCSR_TXPKTRDY
  671. );
  672. csr |= MUSB_TXCSR_MODE;
  673. if (usb_gettoggle(urb->dev, qh->epnum, 1))
  674. csr |= MUSB_TXCSR_H_WR_DATATOGGLE
  675. | MUSB_TXCSR_H_DATATOGGLE;
  676. else
  677. csr |= MUSB_TXCSR_CLRDATATOG;
  678. musb_writew(epio, MUSB_TXCSR, csr);
  679. /* REVISIT may need to clear FLUSHFIFO ... */
  680. csr &= ~MUSB_TXCSR_DMAMODE;
  681. musb_writew(epio, MUSB_TXCSR, csr);
  682. csr = musb_readw(epio, MUSB_TXCSR);
  683. } else {
  684. /* endpoint 0: just flush */
  685. musb_h_ep0_flush_fifo(hw_ep);
  686. }
  687. /* target addr and (for multipoint) hub addr/port */
  688. if (musb->is_multipoint) {
  689. musb_write_txfunaddr(mbase, epnum, qh->addr_reg);
  690. musb_write_txhubaddr(mbase, epnum, qh->h_addr_reg);
  691. musb_write_txhubport(mbase, epnum, qh->h_port_reg);
  692. /* FIXME if !epnum, do the same for RX ... */
  693. } else
  694. musb_writeb(mbase, MUSB_FADDR, qh->addr_reg);
  695. /* protocol/endpoint/interval/NAKlimit */
  696. if (epnum) {
  697. musb_writeb(epio, MUSB_TXTYPE, qh->type_reg);
  698. if (can_bulk_split(musb, qh->type))
  699. musb_writew(epio, MUSB_TXMAXP,
  700. packet_sz
  701. | ((hw_ep->max_packet_sz_tx /
  702. packet_sz) - 1) << 11);
  703. else
  704. musb_writew(epio, MUSB_TXMAXP,
  705. packet_sz);
  706. musb_writeb(epio, MUSB_TXINTERVAL, qh->intv_reg);
  707. } else {
  708. musb_writeb(epio, MUSB_NAKLIMIT0, qh->intv_reg);
  709. if (musb->is_multipoint)
  710. musb_writeb(epio, MUSB_TYPE0,
  711. qh->type_reg);
  712. }
  713. if (can_bulk_split(musb, qh->type))
  714. load_count = min((u32) hw_ep->max_packet_sz_tx,
  715. len);
  716. else
  717. load_count = min((u32) packet_sz, len);
  718. if (dma_channel && musb_tx_dma_program(dma_controller,
  719. hw_ep, qh, urb, offset, len))
  720. load_count = 0;
  721. if (load_count) {
  722. /* PIO to load FIFO */
  723. qh->segsize = load_count;
  724. musb_write_fifo(hw_ep, load_count, buf);
  725. }
  726. /* re-enable interrupt */
  727. musb_writew(mbase, MUSB_INTRTXE, int_txe);
  728. /* IN/receive */
  729. } else {
  730. u16 csr;
  731. if (hw_ep->rx_reinit) {
  732. musb_rx_reinit(musb, qh, hw_ep);
  733. /* init new state: toggle and NYET, maybe DMA later */
  734. if (usb_gettoggle(urb->dev, qh->epnum, 0))
  735. csr = MUSB_RXCSR_H_WR_DATATOGGLE
  736. | MUSB_RXCSR_H_DATATOGGLE;
  737. else
  738. csr = 0;
  739. if (qh->type == USB_ENDPOINT_XFER_INT)
  740. csr |= MUSB_RXCSR_DISNYET;
  741. } else {
  742. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  743. if (csr & (MUSB_RXCSR_RXPKTRDY
  744. | MUSB_RXCSR_DMAENAB
  745. | MUSB_RXCSR_H_REQPKT))
  746. ERR("broken !rx_reinit, ep%d csr %04x\n",
  747. hw_ep->epnum, csr);
  748. /* scrub any stale state, leaving toggle alone */
  749. csr &= MUSB_RXCSR_DISNYET;
  750. }
  751. /* kick things off */
  752. if ((is_cppi_enabled() || tusb_dma_omap()) && dma_channel) {
  753. /* candidate for DMA */
  754. if (dma_channel) {
  755. dma_channel->actual_len = 0L;
  756. qh->segsize = len;
  757. /* AUTOREQ is in a DMA register */
  758. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  759. csr = musb_readw(hw_ep->regs,
  760. MUSB_RXCSR);
  761. /* unless caller treats short rx transfers as
  762. * errors, we dare not queue multiple transfers.
  763. */
  764. dma_ok = dma_controller->channel_program(
  765. dma_channel, packet_sz,
  766. !(urb->transfer_flags
  767. & URB_SHORT_NOT_OK),
  768. urb->transfer_dma + offset,
  769. qh->segsize);
  770. if (!dma_ok) {
  771. dma_controller->channel_release(
  772. dma_channel);
  773. hw_ep->rx_channel = NULL;
  774. dma_channel = NULL;
  775. } else
  776. csr |= MUSB_RXCSR_DMAENAB;
  777. }
  778. }
  779. csr |= MUSB_RXCSR_H_REQPKT;
  780. DBG(7, "RXCSR%d := %04x\n", epnum, csr);
  781. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  782. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  783. }
  784. }
  785. /*
  786. * Service the default endpoint (ep0) as host.
  787. * Return true until it's time to start the status stage.
  788. */
  789. static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb)
  790. {
  791. bool more = false;
  792. u8 *fifo_dest = NULL;
  793. u16 fifo_count = 0;
  794. struct musb_hw_ep *hw_ep = musb->control_ep;
  795. struct musb_qh *qh = hw_ep->in_qh;
  796. struct usb_ctrlrequest *request;
  797. switch (musb->ep0_stage) {
  798. case MUSB_EP0_IN:
  799. fifo_dest = urb->transfer_buffer + urb->actual_length;
  800. fifo_count = min_t(size_t, len, urb->transfer_buffer_length -
  801. urb->actual_length);
  802. if (fifo_count < len)
  803. urb->status = -EOVERFLOW;
  804. musb_read_fifo(hw_ep, fifo_count, fifo_dest);
  805. urb->actual_length += fifo_count;
  806. if (len < qh->maxpacket) {
  807. /* always terminate on short read; it's
  808. * rarely reported as an error.
  809. */
  810. } else if (urb->actual_length <
  811. urb->transfer_buffer_length)
  812. more = true;
  813. break;
  814. case MUSB_EP0_START:
  815. request = (struct usb_ctrlrequest *) urb->setup_packet;
  816. if (!request->wLength) {
  817. DBG(4, "start no-DATA\n");
  818. break;
  819. } else if (request->bRequestType & USB_DIR_IN) {
  820. DBG(4, "start IN-DATA\n");
  821. musb->ep0_stage = MUSB_EP0_IN;
  822. more = true;
  823. break;
  824. } else {
  825. DBG(4, "start OUT-DATA\n");
  826. musb->ep0_stage = MUSB_EP0_OUT;
  827. more = true;
  828. }
  829. /* FALLTHROUGH */
  830. case MUSB_EP0_OUT:
  831. fifo_count = min_t(size_t, qh->maxpacket,
  832. urb->transfer_buffer_length -
  833. urb->actual_length);
  834. if (fifo_count) {
  835. fifo_dest = (u8 *) (urb->transfer_buffer
  836. + urb->actual_length);
  837. DBG(3, "Sending %d byte%s to ep0 fifo %p\n",
  838. fifo_count,
  839. (fifo_count == 1) ? "" : "s",
  840. fifo_dest);
  841. musb_write_fifo(hw_ep, fifo_count, fifo_dest);
  842. urb->actual_length += fifo_count;
  843. more = true;
  844. }
  845. break;
  846. default:
  847. ERR("bogus ep0 stage %d\n", musb->ep0_stage);
  848. break;
  849. }
  850. return more;
  851. }
  852. /*
  853. * Handle default endpoint interrupt as host. Only called in IRQ time
  854. * from musb_interrupt().
  855. *
  856. * called with controller irqlocked
  857. */
  858. irqreturn_t musb_h_ep0_irq(struct musb *musb)
  859. {
  860. struct urb *urb;
  861. u16 csr, len;
  862. int status = 0;
  863. void __iomem *mbase = musb->mregs;
  864. struct musb_hw_ep *hw_ep = musb->control_ep;
  865. void __iomem *epio = hw_ep->regs;
  866. struct musb_qh *qh = hw_ep->in_qh;
  867. bool complete = false;
  868. irqreturn_t retval = IRQ_NONE;
  869. /* ep0 only has one queue, "in" */
  870. urb = next_urb(qh);
  871. musb_ep_select(mbase, 0);
  872. csr = musb_readw(epio, MUSB_CSR0);
  873. len = (csr & MUSB_CSR0_RXPKTRDY)
  874. ? musb_readb(epio, MUSB_COUNT0)
  875. : 0;
  876. DBG(4, "<== csr0 %04x, qh %p, count %d, urb %p, stage %d\n",
  877. csr, qh, len, urb, musb->ep0_stage);
  878. /* if we just did status stage, we are done */
  879. if (MUSB_EP0_STATUS == musb->ep0_stage) {
  880. retval = IRQ_HANDLED;
  881. complete = true;
  882. }
  883. /* prepare status */
  884. if (csr & MUSB_CSR0_H_RXSTALL) {
  885. DBG(6, "STALLING ENDPOINT\n");
  886. status = -EPIPE;
  887. } else if (csr & MUSB_CSR0_H_ERROR) {
  888. DBG(2, "no response, csr0 %04x\n", csr);
  889. status = -EPROTO;
  890. } else if (csr & MUSB_CSR0_H_NAKTIMEOUT) {
  891. DBG(2, "control NAK timeout\n");
  892. /* NOTE: this code path would be a good place to PAUSE a
  893. * control transfer, if another one is queued, so that
  894. * ep0 is more likely to stay busy. That's already done
  895. * for bulk RX transfers.
  896. *
  897. * if (qh->ring.next != &musb->control), then
  898. * we have a candidate... NAKing is *NOT* an error
  899. */
  900. musb_writew(epio, MUSB_CSR0, 0);
  901. retval = IRQ_HANDLED;
  902. }
  903. if (status) {
  904. DBG(6, "aborting\n");
  905. retval = IRQ_HANDLED;
  906. if (urb)
  907. urb->status = status;
  908. complete = true;
  909. /* use the proper sequence to abort the transfer */
  910. if (csr & MUSB_CSR0_H_REQPKT) {
  911. csr &= ~MUSB_CSR0_H_REQPKT;
  912. musb_writew(epio, MUSB_CSR0, csr);
  913. csr &= ~MUSB_CSR0_H_NAKTIMEOUT;
  914. musb_writew(epio, MUSB_CSR0, csr);
  915. } else {
  916. musb_h_ep0_flush_fifo(hw_ep);
  917. }
  918. musb_writeb(epio, MUSB_NAKLIMIT0, 0);
  919. /* clear it */
  920. musb_writew(epio, MUSB_CSR0, 0);
  921. }
  922. if (unlikely(!urb)) {
  923. /* stop endpoint since we have no place for its data, this
  924. * SHOULD NEVER HAPPEN! */
  925. ERR("no URB for end 0\n");
  926. musb_h_ep0_flush_fifo(hw_ep);
  927. goto done;
  928. }
  929. if (!complete) {
  930. /* call common logic and prepare response */
  931. if (musb_h_ep0_continue(musb, len, urb)) {
  932. /* more packets required */
  933. csr = (MUSB_EP0_IN == musb->ep0_stage)
  934. ? MUSB_CSR0_H_REQPKT : MUSB_CSR0_TXPKTRDY;
  935. } else {
  936. /* data transfer complete; perform status phase */
  937. if (usb_pipeout(urb->pipe)
  938. || !urb->transfer_buffer_length)
  939. csr = MUSB_CSR0_H_STATUSPKT
  940. | MUSB_CSR0_H_REQPKT;
  941. else
  942. csr = MUSB_CSR0_H_STATUSPKT
  943. | MUSB_CSR0_TXPKTRDY;
  944. /* flag status stage */
  945. musb->ep0_stage = MUSB_EP0_STATUS;
  946. DBG(5, "ep0 STATUS, csr %04x\n", csr);
  947. }
  948. musb_writew(epio, MUSB_CSR0, csr);
  949. retval = IRQ_HANDLED;
  950. } else
  951. musb->ep0_stage = MUSB_EP0_IDLE;
  952. /* call completion handler if done */
  953. if (complete)
  954. musb_advance_schedule(musb, urb, hw_ep, 1);
  955. done:
  956. return retval;
  957. }
  958. #ifdef CONFIG_USB_INVENTRA_DMA
  959. /* Host side TX (OUT) using Mentor DMA works as follows:
  960. submit_urb ->
  961. - if queue was empty, Program Endpoint
  962. - ... which starts DMA to fifo in mode 1 or 0
  963. DMA Isr (transfer complete) -> TxAvail()
  964. - Stop DMA (~DmaEnab) (<--- Alert ... currently happens
  965. only in musb_cleanup_urb)
  966. - TxPktRdy has to be set in mode 0 or for
  967. short packets in mode 1.
  968. */
  969. #endif
  970. /* Service a Tx-Available or dma completion irq for the endpoint */
  971. void musb_host_tx(struct musb *musb, u8 epnum)
  972. {
  973. int pipe;
  974. bool done = false;
  975. u16 tx_csr;
  976. size_t length = 0;
  977. size_t offset = 0;
  978. struct urb *urb;
  979. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  980. void __iomem *epio = hw_ep->regs;
  981. struct musb_qh *qh = hw_ep->is_shared_fifo ? hw_ep->in_qh
  982. : hw_ep->out_qh;
  983. u32 status = 0;
  984. void __iomem *mbase = musb->mregs;
  985. struct dma_channel *dma;
  986. urb = next_urb(qh);
  987. musb_ep_select(mbase, epnum);
  988. tx_csr = musb_readw(epio, MUSB_TXCSR);
  989. /* with CPPI, DMA sometimes triggers "extra" irqs */
  990. if (!urb) {
  991. DBG(4, "extra TX%d ready, csr %04x\n", epnum, tx_csr);
  992. return;
  993. }
  994. pipe = urb->pipe;
  995. dma = is_dma_capable() ? hw_ep->tx_channel : NULL;
  996. DBG(4, "OUT/TX%d end, csr %04x%s\n", epnum, tx_csr,
  997. dma ? ", dma" : "");
  998. /* check for errors */
  999. if (tx_csr & MUSB_TXCSR_H_RXSTALL) {
  1000. /* dma was disabled, fifo flushed */
  1001. DBG(3, "TX end %d stall\n", epnum);
  1002. /* stall; record URB status */
  1003. status = -EPIPE;
  1004. } else if (tx_csr & MUSB_TXCSR_H_ERROR) {
  1005. /* (NON-ISO) dma was disabled, fifo flushed */
  1006. DBG(3, "TX 3strikes on ep=%d\n", epnum);
  1007. status = -ETIMEDOUT;
  1008. } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) {
  1009. DBG(6, "TX end=%d device not responding\n", epnum);
  1010. /* NOTE: this code path would be a good place to PAUSE a
  1011. * transfer, if there's some other (nonperiodic) tx urb
  1012. * that could use this fifo. (dma complicates it...)
  1013. * That's already done for bulk RX transfers.
  1014. *
  1015. * if (bulk && qh->ring.next != &musb->out_bulk), then
  1016. * we have a candidate... NAKing is *NOT* an error
  1017. */
  1018. musb_ep_select(mbase, epnum);
  1019. musb_writew(epio, MUSB_TXCSR,
  1020. MUSB_TXCSR_H_WZC_BITS
  1021. | MUSB_TXCSR_TXPKTRDY);
  1022. return;
  1023. }
  1024. if (status) {
  1025. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1026. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1027. (void) musb->dma_controller->channel_abort(dma);
  1028. }
  1029. /* do the proper sequence to abort the transfer in the
  1030. * usb core; the dma engine should already be stopped.
  1031. */
  1032. musb_h_tx_flush_fifo(hw_ep);
  1033. tx_csr &= ~(MUSB_TXCSR_AUTOSET
  1034. | MUSB_TXCSR_DMAENAB
  1035. | MUSB_TXCSR_H_ERROR
  1036. | MUSB_TXCSR_H_RXSTALL
  1037. | MUSB_TXCSR_H_NAKTIMEOUT
  1038. );
  1039. musb_ep_select(mbase, epnum);
  1040. musb_writew(epio, MUSB_TXCSR, tx_csr);
  1041. /* REVISIT may need to clear FLUSHFIFO ... */
  1042. musb_writew(epio, MUSB_TXCSR, tx_csr);
  1043. musb_writeb(epio, MUSB_TXINTERVAL, 0);
  1044. done = true;
  1045. }
  1046. /* second cppi case */
  1047. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1048. DBG(4, "extra TX%d ready, csr %04x\n", epnum, tx_csr);
  1049. return;
  1050. }
  1051. if (is_dma_capable() && dma && !status) {
  1052. /*
  1053. * DMA has completed. But if we're using DMA mode 1 (multi
  1054. * packet DMA), we need a terminal TXPKTRDY interrupt before
  1055. * we can consider this transfer completed, lest we trash
  1056. * its last packet when writing the next URB's data. So we
  1057. * switch back to mode 0 to get that interrupt; we'll come
  1058. * back here once it happens.
  1059. */
  1060. if (tx_csr & MUSB_TXCSR_DMAMODE) {
  1061. /*
  1062. * We shouldn't clear DMAMODE with DMAENAB set; so
  1063. * clear them in a safe order. That should be OK
  1064. * once TXPKTRDY has been set (and I've never seen
  1065. * it being 0 at this moment -- DMA interrupt latency
  1066. * is significant) but if it hasn't been then we have
  1067. * no choice but to stop being polite and ignore the
  1068. * programmer's guide... :-)
  1069. *
  1070. * Note that we must write TXCSR with TXPKTRDY cleared
  1071. * in order not to re-trigger the packet send (this bit
  1072. * can't be cleared by CPU), and there's another caveat:
  1073. * TXPKTRDY may be set shortly and then cleared in the
  1074. * double-buffered FIFO mode, so we do an extra TXCSR
  1075. * read for debouncing...
  1076. */
  1077. tx_csr &= musb_readw(epio, MUSB_TXCSR);
  1078. if (tx_csr & MUSB_TXCSR_TXPKTRDY) {
  1079. tx_csr &= ~(MUSB_TXCSR_DMAENAB |
  1080. MUSB_TXCSR_TXPKTRDY);
  1081. musb_writew(epio, MUSB_TXCSR,
  1082. tx_csr | MUSB_TXCSR_H_WZC_BITS);
  1083. }
  1084. tx_csr &= ~(MUSB_TXCSR_DMAMODE |
  1085. MUSB_TXCSR_TXPKTRDY);
  1086. musb_writew(epio, MUSB_TXCSR,
  1087. tx_csr | MUSB_TXCSR_H_WZC_BITS);
  1088. /*
  1089. * There is no guarantee that we'll get an interrupt
  1090. * after clearing DMAMODE as we might have done this
  1091. * too late (after TXPKTRDY was cleared by controller).
  1092. * Re-read TXCSR as we have spoiled its previous value.
  1093. */
  1094. tx_csr = musb_readw(epio, MUSB_TXCSR);
  1095. }
  1096. /*
  1097. * We may get here from a DMA completion or TXPKTRDY interrupt.
  1098. * In any case, we must check the FIFO status here and bail out
  1099. * only if the FIFO still has data -- that should prevent the
  1100. * "missed" TXPKTRDY interrupts and deal with double-buffered
  1101. * FIFO mode too...
  1102. */
  1103. if (tx_csr & (MUSB_TXCSR_FIFONOTEMPTY | MUSB_TXCSR_TXPKTRDY)) {
  1104. DBG(2, "DMA complete but packet still in FIFO, "
  1105. "CSR %04x\n", tx_csr);
  1106. return;
  1107. }
  1108. }
  1109. if (!status || dma || usb_pipeisoc(pipe)) {
  1110. if (dma)
  1111. length = dma->actual_len;
  1112. else
  1113. length = qh->segsize;
  1114. qh->offset += length;
  1115. if (usb_pipeisoc(pipe)) {
  1116. struct usb_iso_packet_descriptor *d;
  1117. d = urb->iso_frame_desc + qh->iso_idx;
  1118. d->actual_length = length;
  1119. d->status = status;
  1120. if (++qh->iso_idx >= urb->number_of_packets) {
  1121. done = true;
  1122. } else {
  1123. d++;
  1124. offset = d->offset;
  1125. length = d->length;
  1126. }
  1127. } else if (dma) {
  1128. done = true;
  1129. } else {
  1130. /* see if we need to send more data, or ZLP */
  1131. if (qh->segsize < qh->maxpacket)
  1132. done = true;
  1133. else if (qh->offset == urb->transfer_buffer_length
  1134. && !(urb->transfer_flags
  1135. & URB_ZERO_PACKET))
  1136. done = true;
  1137. if (!done) {
  1138. offset = qh->offset;
  1139. length = urb->transfer_buffer_length - offset;
  1140. }
  1141. }
  1142. }
  1143. /* urb->status != -EINPROGRESS means request has been faulted,
  1144. * so we must abort this transfer after cleanup
  1145. */
  1146. if (urb->status != -EINPROGRESS) {
  1147. done = true;
  1148. if (status == 0)
  1149. status = urb->status;
  1150. }
  1151. if (done) {
  1152. /* set status */
  1153. urb->status = status;
  1154. urb->actual_length = qh->offset;
  1155. musb_advance_schedule(musb, urb, hw_ep, USB_DIR_OUT);
  1156. return;
  1157. } else if (usb_pipeisoc(pipe) && dma) {
  1158. if (musb_tx_dma_program(musb->dma_controller, hw_ep, qh, urb,
  1159. offset, length))
  1160. return;
  1161. } else if (tx_csr & MUSB_TXCSR_DMAENAB) {
  1162. DBG(1, "not complete, but DMA enabled?\n");
  1163. return;
  1164. }
  1165. /*
  1166. * PIO: start next packet in this URB.
  1167. *
  1168. * REVISIT: some docs say that when hw_ep->tx_double_buffered,
  1169. * (and presumably, FIFO is not half-full) we should write *two*
  1170. * packets before updating TXCSR; other docs disagree...
  1171. */
  1172. if (length > qh->maxpacket)
  1173. length = qh->maxpacket;
  1174. musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
  1175. qh->segsize = length;
  1176. musb_ep_select(mbase, epnum);
  1177. musb_writew(epio, MUSB_TXCSR,
  1178. MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY);
  1179. }
  1180. #ifdef CONFIG_USB_INVENTRA_DMA
  1181. /* Host side RX (IN) using Mentor DMA works as follows:
  1182. submit_urb ->
  1183. - if queue was empty, ProgramEndpoint
  1184. - first IN token is sent out (by setting ReqPkt)
  1185. LinuxIsr -> RxReady()
  1186. /\ => first packet is received
  1187. | - Set in mode 0 (DmaEnab, ~ReqPkt)
  1188. | -> DMA Isr (transfer complete) -> RxReady()
  1189. | - Ack receive (~RxPktRdy), turn off DMA (~DmaEnab)
  1190. | - if urb not complete, send next IN token (ReqPkt)
  1191. | | else complete urb.
  1192. | |
  1193. ---------------------------
  1194. *
  1195. * Nuances of mode 1:
  1196. * For short packets, no ack (+RxPktRdy) is sent automatically
  1197. * (even if AutoClear is ON)
  1198. * For full packets, ack (~RxPktRdy) and next IN token (+ReqPkt) is sent
  1199. * automatically => major problem, as collecting the next packet becomes
  1200. * difficult. Hence mode 1 is not used.
  1201. *
  1202. * REVISIT
  1203. * All we care about at this driver level is that
  1204. * (a) all URBs terminate with REQPKT cleared and fifo(s) empty;
  1205. * (b) termination conditions are: short RX, or buffer full;
  1206. * (c) fault modes include
  1207. * - iff URB_SHORT_NOT_OK, short RX status is -EREMOTEIO.
  1208. * (and that endpoint's dma queue stops immediately)
  1209. * - overflow (full, PLUS more bytes in the terminal packet)
  1210. *
  1211. * So for example, usb-storage sets URB_SHORT_NOT_OK, and would
  1212. * thus be a great candidate for using mode 1 ... for all but the
  1213. * last packet of one URB's transfer.
  1214. */
  1215. #endif
  1216. /* Schedule next QH from musb->in_bulk and move the current qh to
  1217. * the end; avoids starvation for other endpoints.
  1218. */
  1219. static void musb_bulk_rx_nak_timeout(struct musb *musb, struct musb_hw_ep *ep)
  1220. {
  1221. struct dma_channel *dma;
  1222. struct urb *urb;
  1223. void __iomem *mbase = musb->mregs;
  1224. void __iomem *epio = ep->regs;
  1225. struct musb_qh *cur_qh, *next_qh;
  1226. u16 rx_csr;
  1227. musb_ep_select(mbase, ep->epnum);
  1228. dma = is_dma_capable() ? ep->rx_channel : NULL;
  1229. /* clear nak timeout bit */
  1230. rx_csr = musb_readw(epio, MUSB_RXCSR);
  1231. rx_csr |= MUSB_RXCSR_H_WZC_BITS;
  1232. rx_csr &= ~MUSB_RXCSR_DATAERROR;
  1233. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1234. cur_qh = first_qh(&musb->in_bulk);
  1235. if (cur_qh) {
  1236. urb = next_urb(cur_qh);
  1237. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1238. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1239. musb->dma_controller->channel_abort(dma);
  1240. urb->actual_length += dma->actual_len;
  1241. dma->actual_len = 0L;
  1242. }
  1243. musb_save_toggle(cur_qh, 1, urb);
  1244. /* move cur_qh to end of queue */
  1245. list_move_tail(&cur_qh->ring, &musb->in_bulk);
  1246. /* get the next qh from musb->in_bulk */
  1247. next_qh = first_qh(&musb->in_bulk);
  1248. /* set rx_reinit and schedule the next qh */
  1249. ep->rx_reinit = 1;
  1250. musb_start_urb(musb, 1, next_qh);
  1251. }
  1252. }
  1253. /*
  1254. * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
  1255. * and high-bandwidth IN transfer cases.
  1256. */
  1257. void musb_host_rx(struct musb *musb, u8 epnum)
  1258. {
  1259. struct urb *urb;
  1260. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  1261. void __iomem *epio = hw_ep->regs;
  1262. struct musb_qh *qh = hw_ep->in_qh;
  1263. size_t xfer_len;
  1264. void __iomem *mbase = musb->mregs;
  1265. int pipe;
  1266. u16 rx_csr, val;
  1267. bool iso_err = false;
  1268. bool done = false;
  1269. u32 status;
  1270. struct dma_channel *dma;
  1271. musb_ep_select(mbase, epnum);
  1272. urb = next_urb(qh);
  1273. dma = is_dma_capable() ? hw_ep->rx_channel : NULL;
  1274. status = 0;
  1275. xfer_len = 0;
  1276. rx_csr = musb_readw(epio, MUSB_RXCSR);
  1277. val = rx_csr;
  1278. if (unlikely(!urb)) {
  1279. /* REVISIT -- THIS SHOULD NEVER HAPPEN ... but, at least
  1280. * usbtest #11 (unlinks) triggers it regularly, sometimes
  1281. * with fifo full. (Only with DMA??)
  1282. */
  1283. DBG(3, "BOGUS RX%d ready, csr %04x, count %d\n", epnum, val,
  1284. musb_readw(epio, MUSB_RXCOUNT));
  1285. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1286. return;
  1287. }
  1288. pipe = urb->pipe;
  1289. DBG(5, "<== hw %d rxcsr %04x, urb actual %d (+dma %zu)\n",
  1290. epnum, rx_csr, urb->actual_length,
  1291. dma ? dma->actual_len : 0);
  1292. /* check for errors, concurrent stall & unlink is not really
  1293. * handled yet! */
  1294. if (rx_csr & MUSB_RXCSR_H_RXSTALL) {
  1295. DBG(3, "RX end %d STALL\n", epnum);
  1296. /* stall; record URB status */
  1297. status = -EPIPE;
  1298. } else if (rx_csr & MUSB_RXCSR_H_ERROR) {
  1299. DBG(3, "end %d RX proto error\n", epnum);
  1300. status = -EPROTO;
  1301. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1302. } else if (rx_csr & MUSB_RXCSR_DATAERROR) {
  1303. if (USB_ENDPOINT_XFER_ISOC != qh->type) {
  1304. DBG(6, "RX end %d NAK timeout\n", epnum);
  1305. /* NOTE: NAKing is *NOT* an error, so we want to
  1306. * continue. Except ... if there's a request for
  1307. * another QH, use that instead of starving it.
  1308. *
  1309. * Devices like Ethernet and serial adapters keep
  1310. * reads posted at all times, which will starve
  1311. * other devices without this logic.
  1312. */
  1313. if (usb_pipebulk(urb->pipe)
  1314. && qh->mux == 1
  1315. && !list_is_singular(&musb->in_bulk)) {
  1316. musb_bulk_rx_nak_timeout(musb, hw_ep);
  1317. return;
  1318. }
  1319. musb_ep_select(mbase, epnum);
  1320. rx_csr |= MUSB_RXCSR_H_WZC_BITS;
  1321. rx_csr &= ~MUSB_RXCSR_DATAERROR;
  1322. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1323. goto finish;
  1324. } else {
  1325. DBG(4, "RX end %d ISO data error\n", epnum);
  1326. /* packet error reported later */
  1327. iso_err = true;
  1328. }
  1329. }
  1330. /* faults abort the transfer */
  1331. if (status) {
  1332. /* clean up dma and collect transfer count */
  1333. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1334. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1335. (void) musb->dma_controller->channel_abort(dma);
  1336. xfer_len = dma->actual_len;
  1337. }
  1338. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1339. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1340. done = true;
  1341. goto finish;
  1342. }
  1343. if (unlikely(dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY)) {
  1344. /* SHOULD NEVER HAPPEN ... but at least DaVinci has done it */
  1345. ERR("RX%d dma busy, csr %04x\n", epnum, rx_csr);
  1346. goto finish;
  1347. }
  1348. /* thorough shutdown for now ... given more precise fault handling
  1349. * and better queueing support, we might keep a DMA pipeline going
  1350. * while processing this irq for earlier completions.
  1351. */
  1352. /* FIXME this is _way_ too much in-line logic for Mentor DMA */
  1353. #ifndef CONFIG_USB_INVENTRA_DMA
  1354. if (rx_csr & MUSB_RXCSR_H_REQPKT) {
  1355. /* REVISIT this happened for a while on some short reads...
  1356. * the cleanup still needs investigation... looks bad...
  1357. * and also duplicates dma cleanup code above ... plus,
  1358. * shouldn't this be the "half full" double buffer case?
  1359. */
  1360. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1361. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1362. (void) musb->dma_controller->channel_abort(dma);
  1363. xfer_len = dma->actual_len;
  1364. done = true;
  1365. }
  1366. DBG(2, "RXCSR%d %04x, reqpkt, len %zu%s\n", epnum, rx_csr,
  1367. xfer_len, dma ? ", dma" : "");
  1368. rx_csr &= ~MUSB_RXCSR_H_REQPKT;
  1369. musb_ep_select(mbase, epnum);
  1370. musb_writew(epio, MUSB_RXCSR,
  1371. MUSB_RXCSR_H_WZC_BITS | rx_csr);
  1372. }
  1373. #endif
  1374. if (dma && (rx_csr & MUSB_RXCSR_DMAENAB)) {
  1375. xfer_len = dma->actual_len;
  1376. val &= ~(MUSB_RXCSR_DMAENAB
  1377. | MUSB_RXCSR_H_AUTOREQ
  1378. | MUSB_RXCSR_AUTOCLEAR
  1379. | MUSB_RXCSR_RXPKTRDY);
  1380. musb_writew(hw_ep->regs, MUSB_RXCSR, val);
  1381. #ifdef CONFIG_USB_INVENTRA_DMA
  1382. if (usb_pipeisoc(pipe)) {
  1383. struct usb_iso_packet_descriptor *d;
  1384. d = urb->iso_frame_desc + qh->iso_idx;
  1385. d->actual_length = xfer_len;
  1386. /* even if there was an error, we did the dma
  1387. * for iso_frame_desc->length
  1388. */
  1389. if (d->status != EILSEQ && d->status != -EOVERFLOW)
  1390. d->status = 0;
  1391. if (++qh->iso_idx >= urb->number_of_packets)
  1392. done = true;
  1393. else
  1394. done = false;
  1395. } else {
  1396. /* done if urb buffer is full or short packet is recd */
  1397. done = (urb->actual_length + xfer_len >=
  1398. urb->transfer_buffer_length
  1399. || dma->actual_len < qh->maxpacket);
  1400. }
  1401. /* send IN token for next packet, without AUTOREQ */
  1402. if (!done) {
  1403. val |= MUSB_RXCSR_H_REQPKT;
  1404. musb_writew(epio, MUSB_RXCSR,
  1405. MUSB_RXCSR_H_WZC_BITS | val);
  1406. }
  1407. DBG(4, "ep %d dma %s, rxcsr %04x, rxcount %d\n", epnum,
  1408. done ? "off" : "reset",
  1409. musb_readw(epio, MUSB_RXCSR),
  1410. musb_readw(epio, MUSB_RXCOUNT));
  1411. #else
  1412. done = true;
  1413. #endif
  1414. } else if (urb->status == -EINPROGRESS) {
  1415. /* if no errors, be sure a packet is ready for unloading */
  1416. if (unlikely(!(rx_csr & MUSB_RXCSR_RXPKTRDY))) {
  1417. status = -EPROTO;
  1418. ERR("Rx interrupt with no errors or packet!\n");
  1419. /* FIXME this is another "SHOULD NEVER HAPPEN" */
  1420. /* SCRUB (RX) */
  1421. /* do the proper sequence to abort the transfer */
  1422. musb_ep_select(mbase, epnum);
  1423. val &= ~MUSB_RXCSR_H_REQPKT;
  1424. musb_writew(epio, MUSB_RXCSR, val);
  1425. goto finish;
  1426. }
  1427. /* we are expecting IN packets */
  1428. #ifdef CONFIG_USB_INVENTRA_DMA
  1429. if (dma) {
  1430. struct dma_controller *c;
  1431. u16 rx_count;
  1432. int ret, length;
  1433. dma_addr_t buf;
  1434. rx_count = musb_readw(epio, MUSB_RXCOUNT);
  1435. DBG(2, "RX%d count %d, buffer 0x%x len %d/%d\n",
  1436. epnum, rx_count,
  1437. urb->transfer_dma
  1438. + urb->actual_length,
  1439. qh->offset,
  1440. urb->transfer_buffer_length);
  1441. c = musb->dma_controller;
  1442. if (usb_pipeisoc(pipe)) {
  1443. int status = 0;
  1444. struct usb_iso_packet_descriptor *d;
  1445. d = urb->iso_frame_desc + qh->iso_idx;
  1446. if (iso_err) {
  1447. status = -EILSEQ;
  1448. urb->error_count++;
  1449. }
  1450. if (rx_count > d->length) {
  1451. if (status == 0) {
  1452. status = -EOVERFLOW;
  1453. urb->error_count++;
  1454. }
  1455. DBG(2, "** OVERFLOW %d into %d\n",\
  1456. rx_count, d->length);
  1457. length = d->length;
  1458. } else
  1459. length = rx_count;
  1460. d->status = status;
  1461. buf = urb->transfer_dma + d->offset;
  1462. } else {
  1463. length = rx_count;
  1464. buf = urb->transfer_dma +
  1465. urb->actual_length;
  1466. }
  1467. dma->desired_mode = 0;
  1468. #ifdef USE_MODE1
  1469. /* because of the issue below, mode 1 will
  1470. * only rarely behave with correct semantics.
  1471. */
  1472. if ((urb->transfer_flags &
  1473. URB_SHORT_NOT_OK)
  1474. && (urb->transfer_buffer_length -
  1475. urb->actual_length)
  1476. > qh->maxpacket)
  1477. dma->desired_mode = 1;
  1478. if (rx_count < hw_ep->max_packet_sz_rx) {
  1479. length = rx_count;
  1480. dma->bDesiredMode = 0;
  1481. } else {
  1482. length = urb->transfer_buffer_length;
  1483. }
  1484. #endif
  1485. /* Disadvantage of using mode 1:
  1486. * It's basically usable only for mass storage class; essentially all
  1487. * other protocols also terminate transfers on short packets.
  1488. *
  1489. * Details:
  1490. * An extra IN token is sent at the end of the transfer (due to AUTOREQ)
  1491. * If you try to use mode 1 for (transfer_buffer_length - 512), and try
  1492. * to use the extra IN token to grab the last packet using mode 0, then
  1493. * the problem is that you cannot be sure when the device will send the
  1494. * last packet and RxPktRdy set. Sometimes the packet is recd too soon
  1495. * such that it gets lost when RxCSR is re-set at the end of the mode 1
  1496. * transfer, while sometimes it is recd just a little late so that if you
  1497. * try to configure for mode 0 soon after the mode 1 transfer is
  1498. * completed, you will find rxcount 0. Okay, so you might think why not
  1499. * wait for an interrupt when the pkt is recd. Well, you won't get any!
  1500. */
  1501. val = musb_readw(epio, MUSB_RXCSR);
  1502. val &= ~MUSB_RXCSR_H_REQPKT;
  1503. if (dma->desired_mode == 0)
  1504. val &= ~MUSB_RXCSR_H_AUTOREQ;
  1505. else
  1506. val |= MUSB_RXCSR_H_AUTOREQ;
  1507. val |= MUSB_RXCSR_AUTOCLEAR | MUSB_RXCSR_DMAENAB;
  1508. musb_writew(epio, MUSB_RXCSR,
  1509. MUSB_RXCSR_H_WZC_BITS | val);
  1510. /* REVISIT if when actual_length != 0,
  1511. * transfer_buffer_length needs to be
  1512. * adjusted first...
  1513. */
  1514. ret = c->channel_program(
  1515. dma, qh->maxpacket,
  1516. dma->desired_mode, buf, length);
  1517. if (!ret) {
  1518. c->channel_release(dma);
  1519. hw_ep->rx_channel = NULL;
  1520. dma = NULL;
  1521. /* REVISIT reset CSR */
  1522. }
  1523. }
  1524. #endif /* Mentor DMA */
  1525. if (!dma) {
  1526. done = musb_host_packet_rx(musb, urb,
  1527. epnum, iso_err);
  1528. DBG(6, "read %spacket\n", done ? "last " : "");
  1529. }
  1530. }
  1531. finish:
  1532. urb->actual_length += xfer_len;
  1533. qh->offset += xfer_len;
  1534. if (done) {
  1535. if (urb->status == -EINPROGRESS)
  1536. urb->status = status;
  1537. musb_advance_schedule(musb, urb, hw_ep, USB_DIR_IN);
  1538. }
  1539. }
  1540. /* schedule nodes correspond to peripheral endpoints, like an OHCI QH.
  1541. * the software schedule associates multiple such nodes with a given
  1542. * host side hardware endpoint + direction; scheduling may activate
  1543. * that hardware endpoint.
  1544. */
  1545. static int musb_schedule(
  1546. struct musb *musb,
  1547. struct musb_qh *qh,
  1548. int is_in)
  1549. {
  1550. int idle;
  1551. int best_diff;
  1552. int best_end, epnum;
  1553. struct musb_hw_ep *hw_ep = NULL;
  1554. struct list_head *head = NULL;
  1555. /* use fixed hardware for control and bulk */
  1556. if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
  1557. head = &musb->control;
  1558. hw_ep = musb->control_ep;
  1559. goto success;
  1560. }
  1561. /* else, periodic transfers get muxed to other endpoints */
  1562. /*
  1563. * We know this qh hasn't been scheduled, so all we need to do
  1564. * is choose which hardware endpoint to put it on ...
  1565. *
  1566. * REVISIT what we really want here is a regular schedule tree
  1567. * like e.g. OHCI uses.
  1568. */
  1569. best_diff = 4096;
  1570. best_end = -1;
  1571. for (epnum = 1, hw_ep = musb->endpoints + 1;
  1572. epnum < musb->nr_endpoints;
  1573. epnum++, hw_ep++) {
  1574. int diff;
  1575. if (is_in || hw_ep->is_shared_fifo) {
  1576. if (hw_ep->in_qh != NULL)
  1577. continue;
  1578. } else if (hw_ep->out_qh != NULL)
  1579. continue;
  1580. if (hw_ep == musb->bulk_ep)
  1581. continue;
  1582. if (is_in)
  1583. diff = hw_ep->max_packet_sz_rx - qh->maxpacket;
  1584. else
  1585. diff = hw_ep->max_packet_sz_tx - qh->maxpacket;
  1586. if (diff >= 0 && best_diff > diff) {
  1587. best_diff = diff;
  1588. best_end = epnum;
  1589. }
  1590. }
  1591. /* use bulk reserved ep1 if no other ep is free */
  1592. if (best_end < 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
  1593. hw_ep = musb->bulk_ep;
  1594. if (is_in)
  1595. head = &musb->in_bulk;
  1596. else
  1597. head = &musb->out_bulk;
  1598. /* Enable bulk RX NAK timeout scheme when bulk requests are
  1599. * multiplexed. This scheme doen't work in high speed to full
  1600. * speed scenario as NAK interrupts are not coming from a
  1601. * full speed device connected to a high speed device.
  1602. * NAK timeout interval is 8 (128 uframe or 16ms) for HS and
  1603. * 4 (8 frame or 8ms) for FS device.
  1604. */
  1605. if (is_in && qh->dev)
  1606. qh->intv_reg =
  1607. (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
  1608. goto success;
  1609. } else if (best_end < 0) {
  1610. return -ENOSPC;
  1611. }
  1612. idle = 1;
  1613. qh->mux = 0;
  1614. hw_ep = musb->endpoints + best_end;
  1615. DBG(4, "qh %p periodic slot %d\n", qh, best_end);
  1616. success:
  1617. if (head) {
  1618. idle = list_empty(head);
  1619. list_add_tail(&qh->ring, head);
  1620. qh->mux = 1;
  1621. }
  1622. qh->hw_ep = hw_ep;
  1623. qh->hep->hcpriv = qh;
  1624. if (idle)
  1625. musb_start_urb(musb, is_in, qh);
  1626. return 0;
  1627. }
  1628. static int musb_urb_enqueue(
  1629. struct usb_hcd *hcd,
  1630. struct urb *urb,
  1631. gfp_t mem_flags)
  1632. {
  1633. unsigned long flags;
  1634. struct musb *musb = hcd_to_musb(hcd);
  1635. struct usb_host_endpoint *hep = urb->ep;
  1636. struct musb_qh *qh;
  1637. struct usb_endpoint_descriptor *epd = &hep->desc;
  1638. int ret;
  1639. unsigned type_reg;
  1640. unsigned interval;
  1641. /* host role must be active */
  1642. if (!is_host_active(musb) || !musb->is_active)
  1643. return -ENODEV;
  1644. spin_lock_irqsave(&musb->lock, flags);
  1645. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  1646. qh = ret ? NULL : hep->hcpriv;
  1647. if (qh)
  1648. urb->hcpriv = qh;
  1649. spin_unlock_irqrestore(&musb->lock, flags);
  1650. /* DMA mapping was already done, if needed, and this urb is on
  1651. * hep->urb_list now ... so we're done, unless hep wasn't yet
  1652. * scheduled onto a live qh.
  1653. *
  1654. * REVISIT best to keep hep->hcpriv valid until the endpoint gets
  1655. * disabled, testing for empty qh->ring and avoiding qh setup costs
  1656. * except for the first urb queued after a config change.
  1657. */
  1658. if (qh || ret)
  1659. return ret;
  1660. /* Allocate and initialize qh, minimizing the work done each time
  1661. * hw_ep gets reprogrammed, or with irqs blocked. Then schedule it.
  1662. *
  1663. * REVISIT consider a dedicated qh kmem_cache, so it's harder
  1664. * for bugs in other kernel code to break this driver...
  1665. */
  1666. qh = kzalloc(sizeof *qh, mem_flags);
  1667. if (!qh) {
  1668. spin_lock_irqsave(&musb->lock, flags);
  1669. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1670. spin_unlock_irqrestore(&musb->lock, flags);
  1671. return -ENOMEM;
  1672. }
  1673. qh->hep = hep;
  1674. qh->dev = urb->dev;
  1675. INIT_LIST_HEAD(&qh->ring);
  1676. qh->is_ready = 1;
  1677. qh->maxpacket = le16_to_cpu(epd->wMaxPacketSize);
  1678. /* no high bandwidth support yet */
  1679. if (qh->maxpacket & ~0x7ff) {
  1680. ret = -EMSGSIZE;
  1681. goto done;
  1682. }
  1683. qh->epnum = usb_endpoint_num(epd);
  1684. qh->type = usb_endpoint_type(epd);
  1685. /* NOTE: urb->dev->devnum is wrong during SET_ADDRESS */
  1686. qh->addr_reg = (u8) usb_pipedevice(urb->pipe);
  1687. /* precompute rxtype/txtype/type0 register */
  1688. type_reg = (qh->type << 4) | qh->epnum;
  1689. switch (urb->dev->speed) {
  1690. case USB_SPEED_LOW:
  1691. type_reg |= 0xc0;
  1692. break;
  1693. case USB_SPEED_FULL:
  1694. type_reg |= 0x80;
  1695. break;
  1696. default:
  1697. type_reg |= 0x40;
  1698. }
  1699. qh->type_reg = type_reg;
  1700. /* Precompute RXINTERVAL/TXINTERVAL register */
  1701. switch (qh->type) {
  1702. case USB_ENDPOINT_XFER_INT:
  1703. /*
  1704. * Full/low speeds use the linear encoding,
  1705. * high speed uses the logarithmic encoding.
  1706. */
  1707. if (urb->dev->speed <= USB_SPEED_FULL) {
  1708. interval = max_t(u8, epd->bInterval, 1);
  1709. break;
  1710. }
  1711. /* FALLTHROUGH */
  1712. case USB_ENDPOINT_XFER_ISOC:
  1713. /* ISO always uses logarithmic encoding */
  1714. interval = min_t(u8, epd->bInterval, 16);
  1715. break;
  1716. default:
  1717. /* REVISIT we actually want to use NAK limits, hinting to the
  1718. * transfer scheduling logic to try some other qh, e.g. try
  1719. * for 2 msec first:
  1720. *
  1721. * interval = (USB_SPEED_HIGH == urb->dev->speed) ? 16 : 2;
  1722. *
  1723. * The downside of disabling this is that transfer scheduling
  1724. * gets VERY unfair for nonperiodic transfers; a misbehaving
  1725. * peripheral could make that hurt. That's perfectly normal
  1726. * for reads from network or serial adapters ... so we have
  1727. * partial NAKlimit support for bulk RX.
  1728. *
  1729. * The upside of disabling it is simpler transfer scheduling.
  1730. */
  1731. interval = 0;
  1732. }
  1733. qh->intv_reg = interval;
  1734. /* precompute addressing for external hub/tt ports */
  1735. if (musb->is_multipoint) {
  1736. struct usb_device *parent = urb->dev->parent;
  1737. if (parent != hcd->self.root_hub) {
  1738. qh->h_addr_reg = (u8) parent->devnum;
  1739. /* set up tt info if needed */
  1740. if (urb->dev->tt) {
  1741. qh->h_port_reg = (u8) urb->dev->ttport;
  1742. if (urb->dev->tt->hub)
  1743. qh->h_addr_reg =
  1744. (u8) urb->dev->tt->hub->devnum;
  1745. if (urb->dev->tt->multi)
  1746. qh->h_addr_reg |= 0x80;
  1747. }
  1748. }
  1749. }
  1750. /* invariant: hep->hcpriv is null OR the qh that's already scheduled.
  1751. * until we get real dma queues (with an entry for each urb/buffer),
  1752. * we only have work to do in the former case.
  1753. */
  1754. spin_lock_irqsave(&musb->lock, flags);
  1755. if (hep->hcpriv) {
  1756. /* some concurrent activity submitted another urb to hep...
  1757. * odd, rare, error prone, but legal.
  1758. */
  1759. kfree(qh);
  1760. ret = 0;
  1761. } else
  1762. ret = musb_schedule(musb, qh,
  1763. epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK);
  1764. if (ret == 0) {
  1765. urb->hcpriv = qh;
  1766. /* FIXME set urb->start_frame for iso/intr, it's tested in
  1767. * musb_start_urb(), but otherwise only konicawc cares ...
  1768. */
  1769. }
  1770. spin_unlock_irqrestore(&musb->lock, flags);
  1771. done:
  1772. if (ret != 0) {
  1773. spin_lock_irqsave(&musb->lock, flags);
  1774. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1775. spin_unlock_irqrestore(&musb->lock, flags);
  1776. kfree(qh);
  1777. }
  1778. return ret;
  1779. }
  1780. /*
  1781. * abort a transfer that's at the head of a hardware queue.
  1782. * called with controller locked, irqs blocked
  1783. * that hardware queue advances to the next transfer, unless prevented
  1784. */
  1785. static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh, int is_in)
  1786. {
  1787. struct musb_hw_ep *ep = qh->hw_ep;
  1788. void __iomem *epio = ep->regs;
  1789. unsigned hw_end = ep->epnum;
  1790. void __iomem *regs = ep->musb->mregs;
  1791. u16 csr;
  1792. int status = 0;
  1793. musb_ep_select(regs, hw_end);
  1794. if (is_dma_capable()) {
  1795. struct dma_channel *dma;
  1796. dma = is_in ? ep->rx_channel : ep->tx_channel;
  1797. if (dma) {
  1798. status = ep->musb->dma_controller->channel_abort(dma);
  1799. DBG(status ? 1 : 3,
  1800. "abort %cX%d DMA for urb %p --> %d\n",
  1801. is_in ? 'R' : 'T', ep->epnum,
  1802. urb, status);
  1803. urb->actual_length += dma->actual_len;
  1804. }
  1805. }
  1806. /* turn off DMA requests, discard state, stop polling ... */
  1807. if (is_in) {
  1808. /* giveback saves bulk toggle */
  1809. csr = musb_h_flush_rxfifo(ep, 0);
  1810. /* REVISIT we still get an irq; should likely clear the
  1811. * endpoint's irq status here to avoid bogus irqs.
  1812. * clearing that status is platform-specific...
  1813. */
  1814. } else if (ep->epnum) {
  1815. musb_h_tx_flush_fifo(ep);
  1816. csr = musb_readw(epio, MUSB_TXCSR);
  1817. csr &= ~(MUSB_TXCSR_AUTOSET
  1818. | MUSB_TXCSR_DMAENAB
  1819. | MUSB_TXCSR_H_RXSTALL
  1820. | MUSB_TXCSR_H_NAKTIMEOUT
  1821. | MUSB_TXCSR_H_ERROR
  1822. | MUSB_TXCSR_TXPKTRDY);
  1823. musb_writew(epio, MUSB_TXCSR, csr);
  1824. /* REVISIT may need to clear FLUSHFIFO ... */
  1825. musb_writew(epio, MUSB_TXCSR, csr);
  1826. /* flush cpu writebuffer */
  1827. csr = musb_readw(epio, MUSB_TXCSR);
  1828. } else {
  1829. musb_h_ep0_flush_fifo(ep);
  1830. }
  1831. if (status == 0)
  1832. musb_advance_schedule(ep->musb, urb, ep, is_in);
  1833. return status;
  1834. }
  1835. static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  1836. {
  1837. struct musb *musb = hcd_to_musb(hcd);
  1838. struct musb_qh *qh;
  1839. struct list_head *sched;
  1840. unsigned long flags;
  1841. int ret;
  1842. DBG(4, "urb=%p, dev%d ep%d%s\n", urb,
  1843. usb_pipedevice(urb->pipe),
  1844. usb_pipeendpoint(urb->pipe),
  1845. usb_pipein(urb->pipe) ? "in" : "out");
  1846. spin_lock_irqsave(&musb->lock, flags);
  1847. ret = usb_hcd_check_unlink_urb(hcd, urb, status);
  1848. if (ret)
  1849. goto done;
  1850. qh = urb->hcpriv;
  1851. if (!qh)
  1852. goto done;
  1853. /* Any URB not actively programmed into endpoint hardware can be
  1854. * immediately given back; that's any URB not at the head of an
  1855. * endpoint queue, unless someday we get real DMA queues. And even
  1856. * if it's at the head, it might not be known to the hardware...
  1857. *
  1858. * Otherwise abort current transfer, pending dma, etc.; urb->status
  1859. * has already been updated. This is a synchronous abort; it'd be
  1860. * OK to hold off until after some IRQ, though.
  1861. */
  1862. if (!qh->is_ready || urb->urb_list.prev != &qh->hep->urb_list)
  1863. ret = -EINPROGRESS;
  1864. else {
  1865. switch (qh->type) {
  1866. case USB_ENDPOINT_XFER_CONTROL:
  1867. sched = &musb->control;
  1868. break;
  1869. case USB_ENDPOINT_XFER_BULK:
  1870. if (qh->mux == 1) {
  1871. if (usb_pipein(urb->pipe))
  1872. sched = &musb->in_bulk;
  1873. else
  1874. sched = &musb->out_bulk;
  1875. break;
  1876. }
  1877. default:
  1878. /* REVISIT when we get a schedule tree, periodic
  1879. * transfers won't always be at the head of a
  1880. * singleton queue...
  1881. */
  1882. sched = NULL;
  1883. break;
  1884. }
  1885. }
  1886. /* NOTE: qh is invalid unless !list_empty(&hep->urb_list) */
  1887. if (ret < 0 || (sched && qh != first_qh(sched))) {
  1888. int ready = qh->is_ready;
  1889. ret = 0;
  1890. qh->is_ready = 0;
  1891. __musb_giveback(musb, urb, 0);
  1892. qh->is_ready = ready;
  1893. /* If nothing else (usually musb_giveback) is using it
  1894. * and its URB list has emptied, recycle this qh.
  1895. */
  1896. if (ready && list_empty(&qh->hep->urb_list)) {
  1897. qh->hep->hcpriv = NULL;
  1898. list_del(&qh->ring);
  1899. kfree(qh);
  1900. }
  1901. } else
  1902. ret = musb_cleanup_urb(urb, qh, urb->pipe & USB_DIR_IN);
  1903. done:
  1904. spin_unlock_irqrestore(&musb->lock, flags);
  1905. return ret;
  1906. }
  1907. /* disable an endpoint */
  1908. static void
  1909. musb_h_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
  1910. {
  1911. u8 epnum = hep->desc.bEndpointAddress;
  1912. unsigned long flags;
  1913. struct musb *musb = hcd_to_musb(hcd);
  1914. u8 is_in = epnum & USB_DIR_IN;
  1915. struct musb_qh *qh;
  1916. struct urb *urb;
  1917. struct list_head *sched;
  1918. spin_lock_irqsave(&musb->lock, flags);
  1919. qh = hep->hcpriv;
  1920. if (qh == NULL)
  1921. goto exit;
  1922. switch (qh->type) {
  1923. case USB_ENDPOINT_XFER_CONTROL:
  1924. sched = &musb->control;
  1925. break;
  1926. case USB_ENDPOINT_XFER_BULK:
  1927. if (qh->mux == 1) {
  1928. if (is_in)
  1929. sched = &musb->in_bulk;
  1930. else
  1931. sched = &musb->out_bulk;
  1932. break;
  1933. }
  1934. default:
  1935. /* REVISIT when we get a schedule tree, periodic transfers
  1936. * won't always be at the head of a singleton queue...
  1937. */
  1938. sched = NULL;
  1939. break;
  1940. }
  1941. /* NOTE: qh is invalid unless !list_empty(&hep->urb_list) */
  1942. /* kick first urb off the hardware, if needed */
  1943. qh->is_ready = 0;
  1944. if (!sched || qh == first_qh(sched)) {
  1945. urb = next_urb(qh);
  1946. /* make software (then hardware) stop ASAP */
  1947. if (!urb->unlinked)
  1948. urb->status = -ESHUTDOWN;
  1949. /* cleanup */
  1950. musb_cleanup_urb(urb, qh, urb->pipe & USB_DIR_IN);
  1951. /* Then nuke all the others ... and advance the
  1952. * queue on hw_ep (e.g. bulk ring) when we're done.
  1953. */
  1954. while (!list_empty(&hep->urb_list)) {
  1955. urb = next_urb(qh);
  1956. urb->status = -ESHUTDOWN;
  1957. musb_advance_schedule(musb, urb, qh->hw_ep, is_in);
  1958. }
  1959. } else {
  1960. /* Just empty the queue; the hardware is busy with
  1961. * other transfers, and since !qh->is_ready nothing
  1962. * will activate any of these as it advances.
  1963. */
  1964. while (!list_empty(&hep->urb_list))
  1965. __musb_giveback(musb, next_urb(qh), -ESHUTDOWN);
  1966. hep->hcpriv = NULL;
  1967. list_del(&qh->ring);
  1968. kfree(qh);
  1969. }
  1970. exit:
  1971. spin_unlock_irqrestore(&musb->lock, flags);
  1972. }
  1973. static int musb_h_get_frame_number(struct usb_hcd *hcd)
  1974. {
  1975. struct musb *musb = hcd_to_musb(hcd);
  1976. return musb_readw(musb->mregs, MUSB_FRAME);
  1977. }
  1978. static int musb_h_start(struct usb_hcd *hcd)
  1979. {
  1980. struct musb *musb = hcd_to_musb(hcd);
  1981. /* NOTE: musb_start() is called when the hub driver turns
  1982. * on port power, or when (OTG) peripheral starts.
  1983. */
  1984. hcd->state = HC_STATE_RUNNING;
  1985. musb->port1_status = 0;
  1986. return 0;
  1987. }
  1988. static void musb_h_stop(struct usb_hcd *hcd)
  1989. {
  1990. musb_stop(hcd_to_musb(hcd));
  1991. hcd->state = HC_STATE_HALT;
  1992. }
  1993. static int musb_bus_suspend(struct usb_hcd *hcd)
  1994. {
  1995. struct musb *musb = hcd_to_musb(hcd);
  1996. if (musb->xceiv.state == OTG_STATE_A_SUSPEND)
  1997. return 0;
  1998. if (is_host_active(musb) && musb->is_active) {
  1999. WARNING("trying to suspend as %s is_active=%i\n",
  2000. otg_state_string(musb), musb->is_active);
  2001. return -EBUSY;
  2002. } else
  2003. return 0;
  2004. }
  2005. static int musb_bus_resume(struct usb_hcd *hcd)
  2006. {
  2007. /* resuming child port does the work */
  2008. return 0;
  2009. }
  2010. const struct hc_driver musb_hc_driver = {
  2011. .description = "musb-hcd",
  2012. .product_desc = "MUSB HDRC host driver",
  2013. .hcd_priv_size = sizeof(struct musb),
  2014. .flags = HCD_USB2 | HCD_MEMORY,
  2015. /* not using irq handler or reset hooks from usbcore, since
  2016. * those must be shared with peripheral code for OTG configs
  2017. */
  2018. .start = musb_h_start,
  2019. .stop = musb_h_stop,
  2020. .get_frame_number = musb_h_get_frame_number,
  2021. .urb_enqueue = musb_urb_enqueue,
  2022. .urb_dequeue = musb_urb_dequeue,
  2023. .endpoint_disable = musb_h_disable,
  2024. .hub_status_data = musb_hub_status_data,
  2025. .hub_control = musb_hub_control,
  2026. .bus_suspend = musb_bus_suspend,
  2027. .bus_resume = musb_bus_resume,
  2028. /* .start_port_reset = NULL, */
  2029. /* .hub_irq_enable = NULL, */
  2030. };