musb_host.c 62 KB

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