musb_core.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  1. /*
  2. * MUSB OTG driver core code
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. /*
  35. * Inventra (Multipoint) Dual-Role Controller Driver for Linux.
  36. *
  37. * This consists of a Host Controller Driver (HCD) and a peripheral
  38. * controller driver implementing the "Gadget" API; OTG support is
  39. * in the works. These are normal Linux-USB controller drivers which
  40. * use IRQs and have no dedicated thread.
  41. *
  42. * This version of the driver has only been used with products from
  43. * Texas Instruments. Those products integrate the Inventra logic
  44. * with other DMA, IRQ, and bus modules, as well as other logic that
  45. * needs to be reflected in this driver.
  46. *
  47. *
  48. * NOTE: the original Mentor code here was pretty much a collection
  49. * of mechanisms that don't seem to have been fully integrated/working
  50. * for *any* Linux kernel version. This version aims at Linux 2.6.now,
  51. * Key open issues include:
  52. *
  53. * - Lack of host-side transaction scheduling, for all transfer types.
  54. * The hardware doesn't do it; instead, software must.
  55. *
  56. * This is not an issue for OTG devices that don't support external
  57. * hubs, but for more "normal" USB hosts it's a user issue that the
  58. * "multipoint" support doesn't scale in the expected ways. That
  59. * includes DaVinci EVM in a common non-OTG mode.
  60. *
  61. * * Control and bulk use dedicated endpoints, and there's as
  62. * yet no mechanism to either (a) reclaim the hardware when
  63. * peripherals are NAKing, which gets complicated with bulk
  64. * endpoints, or (b) use more than a single bulk endpoint in
  65. * each direction.
  66. *
  67. * RESULT: one device may be perceived as blocking another one.
  68. *
  69. * * Interrupt and isochronous will dynamically allocate endpoint
  70. * hardware, but (a) there's no record keeping for bandwidth;
  71. * (b) in the common case that few endpoints are available, there
  72. * is no mechanism to reuse endpoints to talk to multiple devices.
  73. *
  74. * RESULT: At one extreme, bandwidth can be overcommitted in
  75. * some hardware configurations, no faults will be reported.
  76. * At the other extreme, the bandwidth capabilities which do
  77. * exist tend to be severely undercommitted. You can't yet hook
  78. * up both a keyboard and a mouse to an external USB hub.
  79. */
  80. /*
  81. * This gets many kinds of configuration information:
  82. * - Kconfig for everything user-configurable
  83. * - platform_device for addressing, irq, and platform_data
  84. * - platform_data is mostly for board-specific informarion
  85. * (plus recentrly, SOC or family details)
  86. *
  87. * Most of the conditional compilation will (someday) vanish.
  88. */
  89. #include <linux/module.h>
  90. #include <linux/kernel.h>
  91. #include <linux/sched.h>
  92. #include <linux/slab.h>
  93. #include <linux/init.h>
  94. #include <linux/list.h>
  95. #include <linux/kobject.h>
  96. #include <linux/platform_device.h>
  97. #include <linux/io.h>
  98. #ifdef CONFIG_ARM
  99. #include <mach/hardware.h>
  100. #include <mach/memory.h>
  101. #include <asm/mach-types.h>
  102. #endif
  103. #include "musb_core.h"
  104. #ifdef CONFIG_ARCH_DAVINCI
  105. #include "davinci.h"
  106. #endif
  107. unsigned musb_debug;
  108. module_param_named(debug, musb_debug, uint, S_IRUGO | S_IWUSR);
  109. MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
  110. #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
  111. #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
  112. #define MUSB_VERSION "6.0"
  113. #define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
  114. #define MUSB_DRIVER_NAME "musb_hdrc"
  115. const char musb_driver_name[] = MUSB_DRIVER_NAME;
  116. MODULE_DESCRIPTION(DRIVER_INFO);
  117. MODULE_AUTHOR(DRIVER_AUTHOR);
  118. MODULE_LICENSE("GPL");
  119. MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
  120. /*-------------------------------------------------------------------------*/
  121. static inline struct musb *dev_to_musb(struct device *dev)
  122. {
  123. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  124. /* usbcore insists dev->driver_data is a "struct hcd *" */
  125. return hcd_to_musb(dev_get_drvdata(dev));
  126. #else
  127. return dev_get_drvdata(dev);
  128. #endif
  129. }
  130. /*-------------------------------------------------------------------------*/
  131. #if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN)
  132. /*
  133. * Load an endpoint's FIFO
  134. */
  135. void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
  136. {
  137. void __iomem *fifo = hw_ep->fifo;
  138. prefetch((u8 *)src);
  139. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  140. 'T', hw_ep->epnum, fifo, len, src);
  141. /* we can't assume unaligned reads work */
  142. if (likely((0x01 & (unsigned long) src) == 0)) {
  143. u16 index = 0;
  144. /* best case is 32bit-aligned source address */
  145. if ((0x02 & (unsigned long) src) == 0) {
  146. if (len >= 4) {
  147. writesl(fifo, src + index, len >> 2);
  148. index += len & ~0x03;
  149. }
  150. if (len & 0x02) {
  151. musb_writew(fifo, 0, *(u16 *)&src[index]);
  152. index += 2;
  153. }
  154. } else {
  155. if (len >= 2) {
  156. writesw(fifo, src + index, len >> 1);
  157. index += len & ~0x01;
  158. }
  159. }
  160. if (len & 0x01)
  161. musb_writeb(fifo, 0, src[index]);
  162. } else {
  163. /* byte aligned */
  164. writesb(fifo, src, len);
  165. }
  166. }
  167. /*
  168. * Unload an endpoint's FIFO
  169. */
  170. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
  171. {
  172. void __iomem *fifo = hw_ep->fifo;
  173. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  174. 'R', hw_ep->epnum, fifo, len, dst);
  175. /* we can't assume unaligned writes work */
  176. if (likely((0x01 & (unsigned long) dst) == 0)) {
  177. u16 index = 0;
  178. /* best case is 32bit-aligned destination address */
  179. if ((0x02 & (unsigned long) dst) == 0) {
  180. if (len >= 4) {
  181. readsl(fifo, dst, len >> 2);
  182. index = len & ~0x03;
  183. }
  184. if (len & 0x02) {
  185. *(u16 *)&dst[index] = musb_readw(fifo, 0);
  186. index += 2;
  187. }
  188. } else {
  189. if (len >= 2) {
  190. readsw(fifo, dst, len >> 1);
  191. index = len & ~0x01;
  192. }
  193. }
  194. if (len & 0x01)
  195. dst[index] = musb_readb(fifo, 0);
  196. } else {
  197. /* byte aligned */
  198. readsb(fifo, dst, len);
  199. }
  200. }
  201. #endif /* normal PIO */
  202. /*-------------------------------------------------------------------------*/
  203. /* for high speed test mode; see USB 2.0 spec 7.1.20 */
  204. static const u8 musb_test_packet[53] = {
  205. /* implicit SYNC then DATA0 to start */
  206. /* JKJKJKJK x9 */
  207. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. /* JJKKJJKK x8 */
  209. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  210. /* JJJJKKKK x8 */
  211. 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
  212. /* JJJJJJJKKKKKKK x8 */
  213. 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  214. /* JJJJJJJK x8 */
  215. 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
  216. /* JKKKKKKK x10, JK */
  217. 0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
  218. /* implicit CRC16 then EOP to end */
  219. };
  220. void musb_load_testpacket(struct musb *musb)
  221. {
  222. void __iomem *regs = musb->endpoints[0].regs;
  223. musb_ep_select(musb->mregs, 0);
  224. musb_write_fifo(musb->control_ep,
  225. sizeof(musb_test_packet), musb_test_packet);
  226. musb_writew(regs, MUSB_CSR0, MUSB_CSR0_TXPKTRDY);
  227. }
  228. /*-------------------------------------------------------------------------*/
  229. const char *otg_state_string(struct musb *musb)
  230. {
  231. switch (musb->xceiv.state) {
  232. case OTG_STATE_A_IDLE: return "a_idle";
  233. case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
  234. case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
  235. case OTG_STATE_A_HOST: return "a_host";
  236. case OTG_STATE_A_SUSPEND: return "a_suspend";
  237. case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
  238. case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
  239. case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
  240. case OTG_STATE_B_IDLE: return "b_idle";
  241. case OTG_STATE_B_SRP_INIT: return "b_srp_init";
  242. case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
  243. case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
  244. case OTG_STATE_B_HOST: return "b_host";
  245. default: return "UNDEFINED";
  246. }
  247. }
  248. #ifdef CONFIG_USB_MUSB_OTG
  249. /*
  250. * See also USB_OTG_1-3.pdf 6.6.5 Timers
  251. * REVISIT: Are the other timers done in the hardware?
  252. */
  253. #define TB_ASE0_BRST 100 /* Min 3.125 ms */
  254. /*
  255. * Handles OTG hnp timeouts, such as b_ase0_brst
  256. */
  257. void musb_otg_timer_func(unsigned long data)
  258. {
  259. struct musb *musb = (struct musb *)data;
  260. unsigned long flags;
  261. spin_lock_irqsave(&musb->lock, flags);
  262. switch (musb->xceiv.state) {
  263. case OTG_STATE_B_WAIT_ACON:
  264. DBG(1, "HNP: b_wait_acon timeout; back to b_peripheral\n");
  265. musb_g_disconnect(musb);
  266. musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
  267. musb->is_active = 0;
  268. break;
  269. case OTG_STATE_A_WAIT_BCON:
  270. DBG(1, "HNP: a_wait_bcon timeout; back to a_host\n");
  271. musb_hnp_stop(musb);
  272. break;
  273. default:
  274. DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb));
  275. }
  276. musb->ignore_disconnect = 0;
  277. spin_unlock_irqrestore(&musb->lock, flags);
  278. }
  279. static DEFINE_TIMER(musb_otg_timer, musb_otg_timer_func, 0, 0);
  280. /*
  281. * Stops the B-device HNP state. Caller must take care of locking.
  282. */
  283. void musb_hnp_stop(struct musb *musb)
  284. {
  285. struct usb_hcd *hcd = musb_to_hcd(musb);
  286. void __iomem *mbase = musb->mregs;
  287. u8 reg;
  288. switch (musb->xceiv.state) {
  289. case OTG_STATE_A_PERIPHERAL:
  290. case OTG_STATE_A_WAIT_VFALL:
  291. case OTG_STATE_A_WAIT_BCON:
  292. DBG(1, "HNP: Switching back to A-host\n");
  293. musb_g_disconnect(musb);
  294. musb->xceiv.state = OTG_STATE_A_IDLE;
  295. MUSB_HST_MODE(musb);
  296. musb->is_active = 0;
  297. break;
  298. case OTG_STATE_B_HOST:
  299. DBG(1, "HNP: Disabling HR\n");
  300. hcd->self.is_b_host = 0;
  301. musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
  302. MUSB_DEV_MODE(musb);
  303. reg = musb_readb(mbase, MUSB_POWER);
  304. reg |= MUSB_POWER_SUSPENDM;
  305. musb_writeb(mbase, MUSB_POWER, reg);
  306. /* REVISIT: Start SESSION_REQUEST here? */
  307. break;
  308. default:
  309. DBG(1, "HNP: Stopping in unknown state %s\n",
  310. otg_state_string(musb));
  311. }
  312. /*
  313. * When returning to A state after HNP, avoid hub_port_rebounce(),
  314. * which cause occasional OPT A "Did not receive reset after connect"
  315. * errors.
  316. */
  317. musb->port1_status &=
  318. ~(1 << USB_PORT_FEAT_C_CONNECTION);
  319. }
  320. #endif
  321. /*
  322. * Interrupt Service Routine to record USB "global" interrupts.
  323. * Since these do not happen often and signify things of
  324. * paramount importance, it seems OK to check them individually;
  325. * the order of the tests is specified in the manual
  326. *
  327. * @param musb instance pointer
  328. * @param int_usb register contents
  329. * @param devctl
  330. * @param power
  331. */
  332. #define STAGE0_MASK (MUSB_INTR_RESUME | MUSB_INTR_SESSREQ \
  333. | MUSB_INTR_VBUSERROR | MUSB_INTR_CONNECT \
  334. | MUSB_INTR_RESET)
  335. static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
  336. u8 devctl, u8 power)
  337. {
  338. irqreturn_t handled = IRQ_NONE;
  339. void __iomem *mbase = musb->mregs;
  340. DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl,
  341. int_usb);
  342. /* in host mode, the peripheral may issue remote wakeup.
  343. * in peripheral mode, the host may resume the link.
  344. * spurious RESUME irqs happen too, paired with SUSPEND.
  345. */
  346. if (int_usb & MUSB_INTR_RESUME) {
  347. handled = IRQ_HANDLED;
  348. DBG(3, "RESUME (%s)\n", otg_state_string(musb));
  349. if (devctl & MUSB_DEVCTL_HM) {
  350. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  351. switch (musb->xceiv.state) {
  352. case OTG_STATE_A_SUSPEND:
  353. /* remote wakeup? later, GetPortStatus
  354. * will stop RESUME signaling
  355. */
  356. if (power & MUSB_POWER_SUSPENDM) {
  357. /* spurious */
  358. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  359. DBG(2, "Spurious SUSPENDM\n");
  360. break;
  361. }
  362. power &= ~MUSB_POWER_SUSPENDM;
  363. musb_writeb(mbase, MUSB_POWER,
  364. power | MUSB_POWER_RESUME);
  365. musb->port1_status |=
  366. (USB_PORT_STAT_C_SUSPEND << 16)
  367. | MUSB_PORT_STAT_RESUME;
  368. musb->rh_timer = jiffies
  369. + msecs_to_jiffies(20);
  370. musb->xceiv.state = OTG_STATE_A_HOST;
  371. musb->is_active = 1;
  372. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  373. break;
  374. case OTG_STATE_B_WAIT_ACON:
  375. musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
  376. musb->is_active = 1;
  377. MUSB_DEV_MODE(musb);
  378. break;
  379. default:
  380. WARNING("bogus %s RESUME (%s)\n",
  381. "host",
  382. otg_state_string(musb));
  383. }
  384. #endif
  385. } else {
  386. switch (musb->xceiv.state) {
  387. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  388. case OTG_STATE_A_SUSPEND:
  389. /* possibly DISCONNECT is upcoming */
  390. musb->xceiv.state = OTG_STATE_A_HOST;
  391. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  392. break;
  393. #endif
  394. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  395. case OTG_STATE_B_WAIT_ACON:
  396. case OTG_STATE_B_PERIPHERAL:
  397. /* disconnect while suspended? we may
  398. * not get a disconnect irq...
  399. */
  400. if ((devctl & MUSB_DEVCTL_VBUS)
  401. != (3 << MUSB_DEVCTL_VBUS_SHIFT)
  402. ) {
  403. musb->int_usb |= MUSB_INTR_DISCONNECT;
  404. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  405. break;
  406. }
  407. musb_g_resume(musb);
  408. break;
  409. case OTG_STATE_B_IDLE:
  410. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  411. break;
  412. #endif
  413. default:
  414. WARNING("bogus %s RESUME (%s)\n",
  415. "peripheral",
  416. otg_state_string(musb));
  417. }
  418. }
  419. }
  420. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  421. /* see manual for the order of the tests */
  422. if (int_usb & MUSB_INTR_SESSREQ) {
  423. DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb));
  424. /* IRQ arrives from ID pin sense or (later, if VBUS power
  425. * is removed) SRP. responses are time critical:
  426. * - turn on VBUS (with silicon-specific mechanism)
  427. * - go through A_WAIT_VRISE
  428. * - ... to A_WAIT_BCON.
  429. * a_wait_vrise_tmout triggers VBUS_ERROR transitions
  430. */
  431. musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
  432. musb->ep0_stage = MUSB_EP0_START;
  433. musb->xceiv.state = OTG_STATE_A_IDLE;
  434. MUSB_HST_MODE(musb);
  435. musb_set_vbus(musb, 1);
  436. handled = IRQ_HANDLED;
  437. }
  438. if (int_usb & MUSB_INTR_VBUSERROR) {
  439. int ignore = 0;
  440. /* During connection as an A-Device, we may see a short
  441. * current spikes causing voltage drop, because of cable
  442. * and peripheral capacitance combined with vbus draw.
  443. * (So: less common with truly self-powered devices, where
  444. * vbus doesn't act like a power supply.)
  445. *
  446. * Such spikes are short; usually less than ~500 usec, max
  447. * of ~2 msec. That is, they're not sustained overcurrent
  448. * errors, though they're reported using VBUSERROR irqs.
  449. *
  450. * Workarounds: (a) hardware: use self powered devices.
  451. * (b) software: ignore non-repeated VBUS errors.
  452. *
  453. * REVISIT: do delays from lots of DEBUG_KERNEL checks
  454. * make trouble here, keeping VBUS < 4.4V ?
  455. */
  456. switch (musb->xceiv.state) {
  457. case OTG_STATE_A_HOST:
  458. /* recovery is dicey once we've gotten past the
  459. * initial stages of enumeration, but if VBUS
  460. * stayed ok at the other end of the link, and
  461. * another reset is due (at least for high speed,
  462. * to redo the chirp etc), it might work OK...
  463. */
  464. case OTG_STATE_A_WAIT_BCON:
  465. case OTG_STATE_A_WAIT_VRISE:
  466. if (musb->vbuserr_retry) {
  467. musb->vbuserr_retry--;
  468. ignore = 1;
  469. devctl |= MUSB_DEVCTL_SESSION;
  470. musb_writeb(mbase, MUSB_DEVCTL, devctl);
  471. } else {
  472. musb->port1_status |=
  473. (1 << USB_PORT_FEAT_OVER_CURRENT)
  474. | (1 << USB_PORT_FEAT_C_OVER_CURRENT);
  475. }
  476. break;
  477. default:
  478. break;
  479. }
  480. DBG(1, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
  481. otg_state_string(musb),
  482. devctl,
  483. ({ char *s;
  484. switch (devctl & MUSB_DEVCTL_VBUS) {
  485. case 0 << MUSB_DEVCTL_VBUS_SHIFT:
  486. s = "<SessEnd"; break;
  487. case 1 << MUSB_DEVCTL_VBUS_SHIFT:
  488. s = "<AValid"; break;
  489. case 2 << MUSB_DEVCTL_VBUS_SHIFT:
  490. s = "<VBusValid"; break;
  491. /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
  492. default:
  493. s = "VALID"; break;
  494. }; s; }),
  495. VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
  496. musb->port1_status);
  497. /* go through A_WAIT_VFALL then start a new session */
  498. if (!ignore)
  499. musb_set_vbus(musb, 0);
  500. handled = IRQ_HANDLED;
  501. }
  502. if (int_usb & MUSB_INTR_CONNECT) {
  503. struct usb_hcd *hcd = musb_to_hcd(musb);
  504. handled = IRQ_HANDLED;
  505. musb->is_active = 1;
  506. set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
  507. musb->ep0_stage = MUSB_EP0_START;
  508. #ifdef CONFIG_USB_MUSB_OTG
  509. /* flush endpoints when transitioning from Device Mode */
  510. if (is_peripheral_active(musb)) {
  511. /* REVISIT HNP; just force disconnect */
  512. }
  513. musb_writew(mbase, MUSB_INTRTXE, musb->epmask);
  514. musb_writew(mbase, MUSB_INTRRXE, musb->epmask & 0xfffe);
  515. musb_writeb(mbase, MUSB_INTRUSBE, 0xf7);
  516. #endif
  517. musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
  518. |USB_PORT_STAT_HIGH_SPEED
  519. |USB_PORT_STAT_ENABLE
  520. );
  521. musb->port1_status |= USB_PORT_STAT_CONNECTION
  522. |(USB_PORT_STAT_C_CONNECTION << 16);
  523. /* high vs full speed is just a guess until after reset */
  524. if (devctl & MUSB_DEVCTL_LSDEV)
  525. musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
  526. if (hcd->status_urb)
  527. usb_hcd_poll_rh_status(hcd);
  528. else
  529. usb_hcd_resume_root_hub(hcd);
  530. MUSB_HST_MODE(musb);
  531. /* indicate new connection to OTG machine */
  532. switch (musb->xceiv.state) {
  533. case OTG_STATE_B_PERIPHERAL:
  534. if (int_usb & MUSB_INTR_SUSPEND) {
  535. DBG(1, "HNP: SUSPEND+CONNECT, now b_host\n");
  536. musb->xceiv.state = OTG_STATE_B_HOST;
  537. hcd->self.is_b_host = 1;
  538. int_usb &= ~MUSB_INTR_SUSPEND;
  539. } else
  540. DBG(1, "CONNECT as b_peripheral???\n");
  541. break;
  542. case OTG_STATE_B_WAIT_ACON:
  543. DBG(1, "HNP: Waiting to switch to b_host state\n");
  544. musb->xceiv.state = OTG_STATE_B_HOST;
  545. hcd->self.is_b_host = 1;
  546. break;
  547. default:
  548. if ((devctl & MUSB_DEVCTL_VBUS)
  549. == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
  550. musb->xceiv.state = OTG_STATE_A_HOST;
  551. hcd->self.is_b_host = 0;
  552. }
  553. break;
  554. }
  555. DBG(1, "CONNECT (%s) devctl %02x\n",
  556. otg_state_string(musb), devctl);
  557. }
  558. #endif /* CONFIG_USB_MUSB_HDRC_HCD */
  559. /* mentor saves a bit: bus reset and babble share the same irq.
  560. * only host sees babble; only peripheral sees bus reset.
  561. */
  562. if (int_usb & MUSB_INTR_RESET) {
  563. if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) {
  564. /*
  565. * Looks like non-HS BABBLE can be ignored, but
  566. * HS BABBLE is an error condition. For HS the solution
  567. * is to avoid babble in the first place and fix what
  568. * caused BABBLE. When HS BABBLE happens we can only
  569. * stop the session.
  570. */
  571. if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV))
  572. DBG(1, "BABBLE devctl: %02x\n", devctl);
  573. else {
  574. ERR("Stopping host session -- babble\n");
  575. musb_writeb(mbase, MUSB_DEVCTL, 0);
  576. }
  577. } else if (is_peripheral_capable()) {
  578. DBG(1, "BUS RESET as %s\n", otg_state_string(musb));
  579. switch (musb->xceiv.state) {
  580. #ifdef CONFIG_USB_OTG
  581. case OTG_STATE_A_SUSPEND:
  582. /* We need to ignore disconnect on suspend
  583. * otherwise tusb 2.0 won't reconnect after a
  584. * power cycle, which breaks otg compliance.
  585. */
  586. musb->ignore_disconnect = 1;
  587. musb_g_reset(musb);
  588. /* FALLTHROUGH */
  589. case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
  590. DBG(1, "HNP: Setting timer as %s\n",
  591. otg_state_string(musb));
  592. musb_otg_timer.data = (unsigned long)musb;
  593. mod_timer(&musb_otg_timer, jiffies
  594. + msecs_to_jiffies(100));
  595. break;
  596. case OTG_STATE_A_PERIPHERAL:
  597. musb_hnp_stop(musb);
  598. break;
  599. case OTG_STATE_B_WAIT_ACON:
  600. DBG(1, "HNP: RESET (%s), to b_peripheral\n",
  601. otg_state_string(musb));
  602. musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
  603. musb_g_reset(musb);
  604. break;
  605. #endif
  606. case OTG_STATE_B_IDLE:
  607. musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
  608. /* FALLTHROUGH */
  609. case OTG_STATE_B_PERIPHERAL:
  610. musb_g_reset(musb);
  611. break;
  612. default:
  613. DBG(1, "Unhandled BUS RESET as %s\n",
  614. otg_state_string(musb));
  615. }
  616. }
  617. handled = IRQ_HANDLED;
  618. }
  619. schedule_work(&musb->irq_work);
  620. return handled;
  621. }
  622. /*
  623. * Interrupt Service Routine to record USB "global" interrupts.
  624. * Since these do not happen often and signify things of
  625. * paramount importance, it seems OK to check them individually;
  626. * the order of the tests is specified in the manual
  627. *
  628. * @param musb instance pointer
  629. * @param int_usb register contents
  630. * @param devctl
  631. * @param power
  632. */
  633. static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
  634. u8 devctl, u8 power)
  635. {
  636. irqreturn_t handled = IRQ_NONE;
  637. #if 0
  638. /* REVISIT ... this would be for multiplexing periodic endpoints, or
  639. * supporting transfer phasing to prevent exceeding ISO bandwidth
  640. * limits of a given frame or microframe.
  641. *
  642. * It's not needed for peripheral side, which dedicates endpoints;
  643. * though it _might_ use SOF irqs for other purposes.
  644. *
  645. * And it's not currently needed for host side, which also dedicates
  646. * endpoints, relies on TX/RX interval registers, and isn't claimed
  647. * to support ISO transfers yet.
  648. */
  649. if (int_usb & MUSB_INTR_SOF) {
  650. void __iomem *mbase = musb->mregs;
  651. struct musb_hw_ep *ep;
  652. u8 epnum;
  653. u16 frame;
  654. DBG(6, "START_OF_FRAME\n");
  655. handled = IRQ_HANDLED;
  656. /* start any periodic Tx transfers waiting for current frame */
  657. frame = musb_readw(mbase, MUSB_FRAME);
  658. ep = musb->endpoints;
  659. for (epnum = 1; (epnum < musb->nr_endpoints)
  660. && (musb->epmask >= (1 << epnum));
  661. epnum++, ep++) {
  662. /*
  663. * FIXME handle framecounter wraps (12 bits)
  664. * eliminate duplicated StartUrb logic
  665. */
  666. if (ep->dwWaitFrame >= frame) {
  667. ep->dwWaitFrame = 0;
  668. pr_debug("SOF --> periodic TX%s on %d\n",
  669. ep->tx_channel ? " DMA" : "",
  670. epnum);
  671. if (!ep->tx_channel)
  672. musb_h_tx_start(musb, epnum);
  673. else
  674. cppi_hostdma_start(musb, epnum);
  675. }
  676. } /* end of for loop */
  677. }
  678. #endif
  679. if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
  680. DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
  681. otg_state_string(musb),
  682. MUSB_MODE(musb), devctl);
  683. handled = IRQ_HANDLED;
  684. switch (musb->xceiv.state) {
  685. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  686. case OTG_STATE_A_HOST:
  687. case OTG_STATE_A_SUSPEND:
  688. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  689. musb_root_disconnect(musb);
  690. if (musb->a_wait_bcon != 0)
  691. musb_platform_try_idle(musb, jiffies
  692. + msecs_to_jiffies(musb->a_wait_bcon));
  693. break;
  694. #endif /* HOST */
  695. #ifdef CONFIG_USB_MUSB_OTG
  696. case OTG_STATE_B_HOST:
  697. musb_hnp_stop(musb);
  698. break;
  699. case OTG_STATE_A_PERIPHERAL:
  700. musb_hnp_stop(musb);
  701. musb_root_disconnect(musb);
  702. /* FALLTHROUGH */
  703. case OTG_STATE_B_WAIT_ACON:
  704. /* FALLTHROUGH */
  705. #endif /* OTG */
  706. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  707. case OTG_STATE_B_PERIPHERAL:
  708. case OTG_STATE_B_IDLE:
  709. musb_g_disconnect(musb);
  710. break;
  711. #endif /* GADGET */
  712. default:
  713. WARNING("unhandled DISCONNECT transition (%s)\n",
  714. otg_state_string(musb));
  715. break;
  716. }
  717. schedule_work(&musb->irq_work);
  718. }
  719. if (int_usb & MUSB_INTR_SUSPEND) {
  720. DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
  721. otg_state_string(musb), devctl, power);
  722. handled = IRQ_HANDLED;
  723. switch (musb->xceiv.state) {
  724. #ifdef CONFIG_USB_MUSB_OTG
  725. case OTG_STATE_A_PERIPHERAL:
  726. /*
  727. * We cannot stop HNP here, devctl BDEVICE might be
  728. * still set.
  729. */
  730. break;
  731. #endif
  732. case OTG_STATE_B_PERIPHERAL:
  733. musb_g_suspend(musb);
  734. musb->is_active = is_otg_enabled(musb)
  735. && musb->xceiv.gadget->b_hnp_enable;
  736. if (musb->is_active) {
  737. #ifdef CONFIG_USB_MUSB_OTG
  738. musb->xceiv.state = OTG_STATE_B_WAIT_ACON;
  739. DBG(1, "HNP: Setting timer for b_ase0_brst\n");
  740. musb_otg_timer.data = (unsigned long)musb;
  741. mod_timer(&musb_otg_timer, jiffies
  742. + msecs_to_jiffies(TB_ASE0_BRST));
  743. #endif
  744. }
  745. break;
  746. case OTG_STATE_A_WAIT_BCON:
  747. if (musb->a_wait_bcon != 0)
  748. musb_platform_try_idle(musb, jiffies
  749. + msecs_to_jiffies(musb->a_wait_bcon));
  750. break;
  751. case OTG_STATE_A_HOST:
  752. musb->xceiv.state = OTG_STATE_A_SUSPEND;
  753. musb->is_active = is_otg_enabled(musb)
  754. && musb->xceiv.host->b_hnp_enable;
  755. break;
  756. case OTG_STATE_B_HOST:
  757. /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
  758. DBG(1, "REVISIT: SUSPEND as B_HOST\n");
  759. break;
  760. default:
  761. /* "should not happen" */
  762. musb->is_active = 0;
  763. break;
  764. }
  765. schedule_work(&musb->irq_work);
  766. }
  767. return handled;
  768. }
  769. /*-------------------------------------------------------------------------*/
  770. /*
  771. * Program the HDRC to start (enable interrupts, dma, etc.).
  772. */
  773. void musb_start(struct musb *musb)
  774. {
  775. void __iomem *regs = musb->mregs;
  776. u8 devctl = musb_readb(regs, MUSB_DEVCTL);
  777. DBG(2, "<== devctl %02x\n", devctl);
  778. /* Set INT enable registers, enable interrupts */
  779. musb_writew(regs, MUSB_INTRTXE, musb->epmask);
  780. musb_writew(regs, MUSB_INTRRXE, musb->epmask & 0xfffe);
  781. musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
  782. musb_writeb(regs, MUSB_TESTMODE, 0);
  783. /* put into basic highspeed mode and start session */
  784. musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
  785. | MUSB_POWER_SOFTCONN
  786. | MUSB_POWER_HSENAB
  787. /* ENSUSPEND wedges tusb */
  788. /* | MUSB_POWER_ENSUSPEND */
  789. );
  790. musb->is_active = 0;
  791. devctl = musb_readb(regs, MUSB_DEVCTL);
  792. devctl &= ~MUSB_DEVCTL_SESSION;
  793. if (is_otg_enabled(musb)) {
  794. /* session started after:
  795. * (a) ID-grounded irq, host mode;
  796. * (b) vbus present/connect IRQ, peripheral mode;
  797. * (c) peripheral initiates, using SRP
  798. */
  799. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  800. musb->is_active = 1;
  801. else
  802. devctl |= MUSB_DEVCTL_SESSION;
  803. } else if (is_host_enabled(musb)) {
  804. /* assume ID pin is hard-wired to ground */
  805. devctl |= MUSB_DEVCTL_SESSION;
  806. } else /* peripheral is enabled */ {
  807. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  808. musb->is_active = 1;
  809. }
  810. musb_platform_enable(musb);
  811. musb_writeb(regs, MUSB_DEVCTL, devctl);
  812. }
  813. static void musb_generic_disable(struct musb *musb)
  814. {
  815. void __iomem *mbase = musb->mregs;
  816. u16 temp;
  817. /* disable interrupts */
  818. musb_writeb(mbase, MUSB_INTRUSBE, 0);
  819. musb_writew(mbase, MUSB_INTRTXE, 0);
  820. musb_writew(mbase, MUSB_INTRRXE, 0);
  821. /* off */
  822. musb_writeb(mbase, MUSB_DEVCTL, 0);
  823. /* flush pending interrupts */
  824. temp = musb_readb(mbase, MUSB_INTRUSB);
  825. temp = musb_readw(mbase, MUSB_INTRTX);
  826. temp = musb_readw(mbase, MUSB_INTRRX);
  827. }
  828. /*
  829. * Make the HDRC stop (disable interrupts, etc.);
  830. * reversible by musb_start
  831. * called on gadget driver unregister
  832. * with controller locked, irqs blocked
  833. * acts as a NOP unless some role activated the hardware
  834. */
  835. void musb_stop(struct musb *musb)
  836. {
  837. /* stop IRQs, timers, ... */
  838. musb_platform_disable(musb);
  839. musb_generic_disable(musb);
  840. DBG(3, "HDRC disabled\n");
  841. /* FIXME
  842. * - mark host and/or peripheral drivers unusable/inactive
  843. * - disable DMA (and enable it in HdrcStart)
  844. * - make sure we can musb_start() after musb_stop(); with
  845. * OTG mode, gadget driver module rmmod/modprobe cycles that
  846. * - ...
  847. */
  848. musb_platform_try_idle(musb, 0);
  849. }
  850. static void musb_shutdown(struct platform_device *pdev)
  851. {
  852. struct musb *musb = dev_to_musb(&pdev->dev);
  853. unsigned long flags;
  854. spin_lock_irqsave(&musb->lock, flags);
  855. musb_platform_disable(musb);
  856. musb_generic_disable(musb);
  857. if (musb->clock) {
  858. clk_put(musb->clock);
  859. musb->clock = NULL;
  860. }
  861. spin_unlock_irqrestore(&musb->lock, flags);
  862. /* FIXME power down */
  863. }
  864. /*-------------------------------------------------------------------------*/
  865. /*
  866. * The silicon either has hard-wired endpoint configurations, or else
  867. * "dynamic fifo" sizing. The driver has support for both, though at this
  868. * writing only the dynamic sizing is very well tested. Since we switched
  869. * away from compile-time hardware parameters, we can no longer rely on
  870. * dead code elimination to leave only the relevant one in the object file.
  871. *
  872. * We don't currently use dynamic fifo setup capability to do anything
  873. * more than selecting one of a bunch of predefined configurations.
  874. */
  875. #if defined(CONFIG_USB_TUSB6010) || \
  876. defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
  877. static ushort __initdata fifo_mode = 4;
  878. #else
  879. static ushort __initdata fifo_mode = 2;
  880. #endif
  881. /* "modprobe ... fifo_mode=1" etc */
  882. module_param(fifo_mode, ushort, 0);
  883. MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  884. enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
  885. enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
  886. struct fifo_cfg {
  887. u8 hw_ep_num;
  888. enum fifo_style style;
  889. enum buf_mode mode;
  890. u16 maxpacket;
  891. };
  892. /*
  893. * tables defining fifo_mode values. define more if you like.
  894. * for host side, make sure both halves of ep1 are set up.
  895. */
  896. /* mode 0 - fits in 2KB */
  897. static struct fifo_cfg __initdata mode_0_cfg[] = {
  898. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  899. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  900. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
  901. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  902. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  903. };
  904. /* mode 1 - fits in 4KB */
  905. static struct fifo_cfg __initdata mode_1_cfg[] = {
  906. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  907. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  908. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  909. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  910. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  911. };
  912. /* mode 2 - fits in 4KB */
  913. static struct fifo_cfg __initdata mode_2_cfg[] = {
  914. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  915. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  916. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  917. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  918. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  919. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  920. };
  921. /* mode 3 - fits in 4KB */
  922. static struct fifo_cfg __initdata mode_3_cfg[] = {
  923. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  924. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  925. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  926. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  927. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  928. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  929. };
  930. /* mode 4 - fits in 16KB */
  931. static struct fifo_cfg __initdata mode_4_cfg[] = {
  932. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  933. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  934. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  935. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  936. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  937. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  938. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  939. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  940. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  941. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  942. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
  943. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
  944. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
  945. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
  946. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
  947. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
  948. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
  949. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
  950. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 512, },
  951. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 512, },
  952. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 512, },
  953. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 512, },
  954. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 512, },
  955. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 512, },
  956. { .hw_ep_num = 13, .style = FIFO_TX, .maxpacket = 512, },
  957. { .hw_ep_num = 13, .style = FIFO_RX, .maxpacket = 512, },
  958. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  959. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  960. };
  961. /*
  962. * configure a fifo; for non-shared endpoints, this may be called
  963. * once for a tx fifo and once for an rx fifo.
  964. *
  965. * returns negative errno or offset for next fifo.
  966. */
  967. static int __init
  968. fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
  969. const struct fifo_cfg *cfg, u16 offset)
  970. {
  971. void __iomem *mbase = musb->mregs;
  972. int size = 0;
  973. u16 maxpacket = cfg->maxpacket;
  974. u16 c_off = offset >> 3;
  975. u8 c_size;
  976. /* expect hw_ep has already been zero-initialized */
  977. size = ffs(max(maxpacket, (u16) 8)) - 1;
  978. maxpacket = 1 << size;
  979. c_size = size - 3;
  980. if (cfg->mode == BUF_DOUBLE) {
  981. if ((offset + (maxpacket << 1)) >
  982. (1 << (musb->config->ram_bits + 2)))
  983. return -EMSGSIZE;
  984. c_size |= MUSB_FIFOSZ_DPB;
  985. } else {
  986. if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
  987. return -EMSGSIZE;
  988. }
  989. /* configure the FIFO */
  990. musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
  991. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  992. /* EP0 reserved endpoint for control, bidirectional;
  993. * EP1 reserved for bulk, two unidirection halves.
  994. */
  995. if (hw_ep->epnum == 1)
  996. musb->bulk_ep = hw_ep;
  997. /* REVISIT error check: be sure ep0 can both rx and tx ... */
  998. #endif
  999. switch (cfg->style) {
  1000. case FIFO_TX:
  1001. musb_write_txfifosz(mbase, c_size);
  1002. musb_write_txfifoadd(mbase, c_off);
  1003. hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1004. hw_ep->max_packet_sz_tx = maxpacket;
  1005. break;
  1006. case FIFO_RX:
  1007. musb_write_rxfifosz(mbase, c_size);
  1008. musb_write_rxfifoadd(mbase, c_off);
  1009. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1010. hw_ep->max_packet_sz_rx = maxpacket;
  1011. break;
  1012. case FIFO_RXTX:
  1013. musb_write_txfifosz(mbase, c_size);
  1014. musb_write_txfifoadd(mbase, c_off);
  1015. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1016. hw_ep->max_packet_sz_rx = maxpacket;
  1017. musb_write_rxfifosz(mbase, c_size);
  1018. musb_write_rxfifoadd(mbase, c_off);
  1019. hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
  1020. hw_ep->max_packet_sz_tx = maxpacket;
  1021. hw_ep->is_shared_fifo = true;
  1022. break;
  1023. }
  1024. /* NOTE rx and tx endpoint irqs aren't managed separately,
  1025. * which happens to be ok
  1026. */
  1027. musb->epmask |= (1 << hw_ep->epnum);
  1028. return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
  1029. }
  1030. static struct fifo_cfg __initdata ep0_cfg = {
  1031. .style = FIFO_RXTX, .maxpacket = 64,
  1032. };
  1033. static int __init ep_config_from_table(struct musb *musb)
  1034. {
  1035. const struct fifo_cfg *cfg;
  1036. unsigned i, n;
  1037. int offset;
  1038. struct musb_hw_ep *hw_ep = musb->endpoints;
  1039. switch (fifo_mode) {
  1040. default:
  1041. fifo_mode = 0;
  1042. /* FALLTHROUGH */
  1043. case 0:
  1044. cfg = mode_0_cfg;
  1045. n = ARRAY_SIZE(mode_0_cfg);
  1046. break;
  1047. case 1:
  1048. cfg = mode_1_cfg;
  1049. n = ARRAY_SIZE(mode_1_cfg);
  1050. break;
  1051. case 2:
  1052. cfg = mode_2_cfg;
  1053. n = ARRAY_SIZE(mode_2_cfg);
  1054. break;
  1055. case 3:
  1056. cfg = mode_3_cfg;
  1057. n = ARRAY_SIZE(mode_3_cfg);
  1058. break;
  1059. case 4:
  1060. cfg = mode_4_cfg;
  1061. n = ARRAY_SIZE(mode_4_cfg);
  1062. break;
  1063. }
  1064. printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
  1065. musb_driver_name, fifo_mode);
  1066. offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
  1067. /* assert(offset > 0) */
  1068. /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
  1069. * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
  1070. */
  1071. for (i = 0; i < n; i++) {
  1072. u8 epn = cfg->hw_ep_num;
  1073. if (epn >= musb->config->num_eps) {
  1074. pr_debug("%s: invalid ep %d\n",
  1075. musb_driver_name, epn);
  1076. return -EINVAL;
  1077. }
  1078. offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
  1079. if (offset < 0) {
  1080. pr_debug("%s: mem overrun, ep %d\n",
  1081. musb_driver_name, epn);
  1082. return -EINVAL;
  1083. }
  1084. epn++;
  1085. musb->nr_endpoints = max(epn, musb->nr_endpoints);
  1086. }
  1087. printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n",
  1088. musb_driver_name,
  1089. n + 1, musb->config->num_eps * 2 - 1,
  1090. offset, (1 << (musb->config->ram_bits + 2)));
  1091. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1092. if (!musb->bulk_ep) {
  1093. pr_debug("%s: missing bulk\n", musb_driver_name);
  1094. return -EINVAL;
  1095. }
  1096. #endif
  1097. return 0;
  1098. }
  1099. /*
  1100. * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
  1101. * @param musb the controller
  1102. */
  1103. static int __init ep_config_from_hw(struct musb *musb)
  1104. {
  1105. u8 epnum = 0;
  1106. struct musb_hw_ep *hw_ep;
  1107. void *mbase = musb->mregs;
  1108. int ret = 0;
  1109. DBG(2, "<== static silicon ep config\n");
  1110. /* FIXME pick up ep0 maxpacket size */
  1111. for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
  1112. musb_ep_select(mbase, epnum);
  1113. hw_ep = musb->endpoints + epnum;
  1114. ret = musb_read_fifosize(musb, hw_ep, epnum);
  1115. if (ret < 0)
  1116. break;
  1117. /* FIXME set up hw_ep->{rx,tx}_double_buffered */
  1118. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1119. /* pick an RX/TX endpoint for bulk */
  1120. if (hw_ep->max_packet_sz_tx < 512
  1121. || hw_ep->max_packet_sz_rx < 512)
  1122. continue;
  1123. /* REVISIT: this algorithm is lazy, we should at least
  1124. * try to pick a double buffered endpoint.
  1125. */
  1126. if (musb->bulk_ep)
  1127. continue;
  1128. musb->bulk_ep = hw_ep;
  1129. #endif
  1130. }
  1131. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1132. if (!musb->bulk_ep) {
  1133. pr_debug("%s: missing bulk\n", musb_driver_name);
  1134. return -EINVAL;
  1135. }
  1136. #endif
  1137. return 0;
  1138. }
  1139. enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
  1140. /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
  1141. * configure endpoints, or take their config from silicon
  1142. */
  1143. static int __init musb_core_init(u16 musb_type, struct musb *musb)
  1144. {
  1145. #ifdef MUSB_AHB_ID
  1146. u32 data;
  1147. #endif
  1148. u8 reg;
  1149. char *type;
  1150. u16 hwvers, rev_major, rev_minor;
  1151. char aInfo[78], aRevision[32], aDate[12];
  1152. void __iomem *mbase = musb->mregs;
  1153. int status = 0;
  1154. int i;
  1155. /* log core options (read using indexed model) */
  1156. musb_ep_select(mbase, 0);
  1157. reg = musb_read_configdata(mbase);
  1158. strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
  1159. if (reg & MUSB_CONFIGDATA_DYNFIFO)
  1160. strcat(aInfo, ", dyn FIFOs");
  1161. if (reg & MUSB_CONFIGDATA_MPRXE) {
  1162. strcat(aInfo, ", bulk combine");
  1163. #ifdef C_MP_RX
  1164. musb->bulk_combine = true;
  1165. #else
  1166. strcat(aInfo, " (X)"); /* no driver support */
  1167. #endif
  1168. }
  1169. if (reg & MUSB_CONFIGDATA_MPTXE) {
  1170. strcat(aInfo, ", bulk split");
  1171. #ifdef C_MP_TX
  1172. musb->bulk_split = true;
  1173. #else
  1174. strcat(aInfo, " (X)"); /* no driver support */
  1175. #endif
  1176. }
  1177. if (reg & MUSB_CONFIGDATA_HBRXE) {
  1178. strcat(aInfo, ", HB-ISO Rx");
  1179. strcat(aInfo, " (X)"); /* no driver support */
  1180. }
  1181. if (reg & MUSB_CONFIGDATA_HBTXE) {
  1182. strcat(aInfo, ", HB-ISO Tx");
  1183. strcat(aInfo, " (X)"); /* no driver support */
  1184. }
  1185. if (reg & MUSB_CONFIGDATA_SOFTCONE)
  1186. strcat(aInfo, ", SoftConn");
  1187. printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
  1188. musb_driver_name, reg, aInfo);
  1189. #ifdef MUSB_AHB_ID
  1190. data = musb_readl(mbase, 0x404);
  1191. sprintf(aDate, "%04d-%02x-%02x", (data & 0xffff),
  1192. (data >> 16) & 0xff, (data >> 24) & 0xff);
  1193. /* FIXME ID2 and ID3 are unused */
  1194. data = musb_readl(mbase, 0x408);
  1195. printk(KERN_DEBUG "ID2=%lx\n", (long unsigned)data);
  1196. data = musb_readl(mbase, 0x40c);
  1197. printk(KERN_DEBUG "ID3=%lx\n", (long unsigned)data);
  1198. reg = musb_readb(mbase, 0x400);
  1199. musb_type = ('M' == reg) ? MUSB_CONTROLLER_MHDRC : MUSB_CONTROLLER_HDRC;
  1200. #else
  1201. aDate[0] = 0;
  1202. #endif
  1203. if (MUSB_CONTROLLER_MHDRC == musb_type) {
  1204. musb->is_multipoint = 1;
  1205. type = "M";
  1206. } else {
  1207. musb->is_multipoint = 0;
  1208. type = "";
  1209. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1210. #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
  1211. printk(KERN_ERR
  1212. "%s: kernel must blacklist external hubs\n",
  1213. musb_driver_name);
  1214. #endif
  1215. #endif
  1216. }
  1217. /* log release info */
  1218. hwvers = musb_read_hwvers(mbase);
  1219. rev_major = (hwvers >> 10) & 0x1f;
  1220. rev_minor = hwvers & 0x3ff;
  1221. snprintf(aRevision, 32, "%d.%d%s", rev_major,
  1222. rev_minor, (hwvers & 0x8000) ? "RC" : "");
  1223. printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
  1224. musb_driver_name, type, aRevision, aDate);
  1225. /* configure ep0 */
  1226. musb_configure_ep0(musb);
  1227. /* discover endpoint configuration */
  1228. musb->nr_endpoints = 1;
  1229. musb->epmask = 1;
  1230. if (reg & MUSB_CONFIGDATA_DYNFIFO) {
  1231. if (musb->config->dyn_fifo)
  1232. status = ep_config_from_table(musb);
  1233. else {
  1234. ERR("reconfigure software for Dynamic FIFOs\n");
  1235. status = -ENODEV;
  1236. }
  1237. } else {
  1238. if (!musb->config->dyn_fifo)
  1239. status = ep_config_from_hw(musb);
  1240. else {
  1241. ERR("reconfigure software for static FIFOs\n");
  1242. return -ENODEV;
  1243. }
  1244. }
  1245. if (status < 0)
  1246. return status;
  1247. /* finish init, and print endpoint config */
  1248. for (i = 0; i < musb->nr_endpoints; i++) {
  1249. struct musb_hw_ep *hw_ep = musb->endpoints + i;
  1250. hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
  1251. #ifdef CONFIG_USB_TUSB6010
  1252. hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
  1253. hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
  1254. hw_ep->fifo_sync_va =
  1255. musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
  1256. if (i == 0)
  1257. hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
  1258. else
  1259. hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
  1260. #endif
  1261. hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
  1262. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1263. hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
  1264. hw_ep->rx_reinit = 1;
  1265. hw_ep->tx_reinit = 1;
  1266. #endif
  1267. if (hw_ep->max_packet_sz_tx) {
  1268. printk(KERN_DEBUG
  1269. "%s: hw_ep %d%s, %smax %d\n",
  1270. musb_driver_name, i,
  1271. hw_ep->is_shared_fifo ? "shared" : "tx",
  1272. hw_ep->tx_double_buffered
  1273. ? "doublebuffer, " : "",
  1274. hw_ep->max_packet_sz_tx);
  1275. }
  1276. if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
  1277. printk(KERN_DEBUG
  1278. "%s: hw_ep %d%s, %smax %d\n",
  1279. musb_driver_name, i,
  1280. "rx",
  1281. hw_ep->rx_double_buffered
  1282. ? "doublebuffer, " : "",
  1283. hw_ep->max_packet_sz_rx);
  1284. }
  1285. if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
  1286. DBG(1, "hw_ep %d not configured\n", i);
  1287. }
  1288. return 0;
  1289. }
  1290. /*-------------------------------------------------------------------------*/
  1291. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
  1292. static irqreturn_t generic_interrupt(int irq, void *__hci)
  1293. {
  1294. unsigned long flags;
  1295. irqreturn_t retval = IRQ_NONE;
  1296. struct musb *musb = __hci;
  1297. spin_lock_irqsave(&musb->lock, flags);
  1298. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  1299. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  1300. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  1301. if (musb->int_usb || musb->int_tx || musb->int_rx)
  1302. retval = musb_interrupt(musb);
  1303. spin_unlock_irqrestore(&musb->lock, flags);
  1304. /* REVISIT we sometimes get spurious IRQs on g_ep0
  1305. * not clear why...
  1306. */
  1307. if (retval != IRQ_HANDLED)
  1308. DBG(5, "spurious?\n");
  1309. return IRQ_HANDLED;
  1310. }
  1311. #else
  1312. #define generic_interrupt NULL
  1313. #endif
  1314. /*
  1315. * handle all the irqs defined by the HDRC core. for now we expect: other
  1316. * irq sources (phy, dma, etc) will be handled first, musb->int_* values
  1317. * will be assigned, and the irq will already have been acked.
  1318. *
  1319. * called in irq context with spinlock held, irqs blocked
  1320. */
  1321. irqreturn_t musb_interrupt(struct musb *musb)
  1322. {
  1323. irqreturn_t retval = IRQ_NONE;
  1324. u8 devctl, power;
  1325. int ep_num;
  1326. u32 reg;
  1327. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1328. power = musb_readb(musb->mregs, MUSB_POWER);
  1329. DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n",
  1330. (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
  1331. musb->int_usb, musb->int_tx, musb->int_rx);
  1332. /* the core can interrupt us for multiple reasons; docs have
  1333. * a generic interrupt flowchart to follow
  1334. */
  1335. if (musb->int_usb & STAGE0_MASK)
  1336. retval |= musb_stage0_irq(musb, musb->int_usb,
  1337. devctl, power);
  1338. /* "stage 1" is handling endpoint irqs */
  1339. /* handle endpoint 0 first */
  1340. if (musb->int_tx & 1) {
  1341. if (devctl & MUSB_DEVCTL_HM)
  1342. retval |= musb_h_ep0_irq(musb);
  1343. else
  1344. retval |= musb_g_ep0_irq(musb);
  1345. }
  1346. /* RX on endpoints 1-15 */
  1347. reg = musb->int_rx >> 1;
  1348. ep_num = 1;
  1349. while (reg) {
  1350. if (reg & 1) {
  1351. /* musb_ep_select(musb->mregs, ep_num); */
  1352. /* REVISIT just retval = ep->rx_irq(...) */
  1353. retval = IRQ_HANDLED;
  1354. if (devctl & MUSB_DEVCTL_HM) {
  1355. if (is_host_capable())
  1356. musb_host_rx(musb, ep_num);
  1357. } else {
  1358. if (is_peripheral_capable())
  1359. musb_g_rx(musb, ep_num);
  1360. }
  1361. }
  1362. reg >>= 1;
  1363. ep_num++;
  1364. }
  1365. /* TX on endpoints 1-15 */
  1366. reg = musb->int_tx >> 1;
  1367. ep_num = 1;
  1368. while (reg) {
  1369. if (reg & 1) {
  1370. /* musb_ep_select(musb->mregs, ep_num); */
  1371. /* REVISIT just retval |= ep->tx_irq(...) */
  1372. retval = IRQ_HANDLED;
  1373. if (devctl & MUSB_DEVCTL_HM) {
  1374. if (is_host_capable())
  1375. musb_host_tx(musb, ep_num);
  1376. } else {
  1377. if (is_peripheral_capable())
  1378. musb_g_tx(musb, ep_num);
  1379. }
  1380. }
  1381. reg >>= 1;
  1382. ep_num++;
  1383. }
  1384. /* finish handling "global" interrupts after handling fifos */
  1385. if (musb->int_usb)
  1386. retval |= musb_stage2_irq(musb,
  1387. musb->int_usb, devctl, power);
  1388. return retval;
  1389. }
  1390. #ifndef CONFIG_MUSB_PIO_ONLY
  1391. static int __initdata use_dma = 1;
  1392. /* "modprobe ... use_dma=0" etc */
  1393. module_param(use_dma, bool, 0);
  1394. MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
  1395. void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
  1396. {
  1397. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1398. /* called with controller lock already held */
  1399. if (!epnum) {
  1400. #ifndef CONFIG_USB_TUSB_OMAP_DMA
  1401. if (!is_cppi_enabled()) {
  1402. /* endpoint 0 */
  1403. if (devctl & MUSB_DEVCTL_HM)
  1404. musb_h_ep0_irq(musb);
  1405. else
  1406. musb_g_ep0_irq(musb);
  1407. }
  1408. #endif
  1409. } else {
  1410. /* endpoints 1..15 */
  1411. if (transmit) {
  1412. if (devctl & MUSB_DEVCTL_HM) {
  1413. if (is_host_capable())
  1414. musb_host_tx(musb, epnum);
  1415. } else {
  1416. if (is_peripheral_capable())
  1417. musb_g_tx(musb, epnum);
  1418. }
  1419. } else {
  1420. /* receive */
  1421. if (devctl & MUSB_DEVCTL_HM) {
  1422. if (is_host_capable())
  1423. musb_host_rx(musb, epnum);
  1424. } else {
  1425. if (is_peripheral_capable())
  1426. musb_g_rx(musb, epnum);
  1427. }
  1428. }
  1429. }
  1430. }
  1431. #else
  1432. #define use_dma 0
  1433. #endif
  1434. /*-------------------------------------------------------------------------*/
  1435. #ifdef CONFIG_SYSFS
  1436. static ssize_t
  1437. musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1438. {
  1439. struct musb *musb = dev_to_musb(dev);
  1440. unsigned long flags;
  1441. int ret = -EINVAL;
  1442. spin_lock_irqsave(&musb->lock, flags);
  1443. ret = sprintf(buf, "%s\n", otg_state_string(musb));
  1444. spin_unlock_irqrestore(&musb->lock, flags);
  1445. return ret;
  1446. }
  1447. static ssize_t
  1448. musb_mode_store(struct device *dev, struct device_attribute *attr,
  1449. const char *buf, size_t n)
  1450. {
  1451. struct musb *musb = dev_to_musb(dev);
  1452. unsigned long flags;
  1453. int status;
  1454. spin_lock_irqsave(&musb->lock, flags);
  1455. if (sysfs_streq(buf, "host"))
  1456. status = musb_platform_set_mode(musb, MUSB_HOST);
  1457. else if (sysfs_streq(buf, "peripheral"))
  1458. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  1459. else if (sysfs_streq(buf, "otg"))
  1460. status = musb_platform_set_mode(musb, MUSB_OTG);
  1461. else
  1462. status = -EINVAL;
  1463. spin_unlock_irqrestore(&musb->lock, flags);
  1464. return (status == 0) ? n : status;
  1465. }
  1466. static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
  1467. static ssize_t
  1468. musb_vbus_store(struct device *dev, struct device_attribute *attr,
  1469. const char *buf, size_t n)
  1470. {
  1471. struct musb *musb = dev_to_musb(dev);
  1472. unsigned long flags;
  1473. unsigned long val;
  1474. if (sscanf(buf, "%lu", &val) < 1) {
  1475. printk(KERN_ERR "Invalid VBUS timeout ms value\n");
  1476. return -EINVAL;
  1477. }
  1478. spin_lock_irqsave(&musb->lock, flags);
  1479. musb->a_wait_bcon = val;
  1480. if (musb->xceiv.state == OTG_STATE_A_WAIT_BCON)
  1481. musb->is_active = 0;
  1482. musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
  1483. spin_unlock_irqrestore(&musb->lock, flags);
  1484. return n;
  1485. }
  1486. static ssize_t
  1487. musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
  1488. {
  1489. struct musb *musb = dev_to_musb(dev);
  1490. unsigned long flags;
  1491. unsigned long val;
  1492. int vbus;
  1493. spin_lock_irqsave(&musb->lock, flags);
  1494. val = musb->a_wait_bcon;
  1495. vbus = musb_platform_get_vbus_status(musb);
  1496. spin_unlock_irqrestore(&musb->lock, flags);
  1497. return sprintf(buf, "Vbus %s, timeout %lu\n",
  1498. vbus ? "on" : "off", val);
  1499. }
  1500. static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
  1501. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1502. /* Gadget drivers can't know that a host is connected so they might want
  1503. * to start SRP, but users can. This allows userspace to trigger SRP.
  1504. */
  1505. static ssize_t
  1506. musb_srp_store(struct device *dev, struct device_attribute *attr,
  1507. const char *buf, size_t n)
  1508. {
  1509. struct musb *musb = dev_to_musb(dev);
  1510. unsigned short srp;
  1511. if (sscanf(buf, "%hu", &srp) != 1
  1512. || (srp != 1)) {
  1513. printk(KERN_ERR "SRP: Value must be 1\n");
  1514. return -EINVAL;
  1515. }
  1516. if (srp == 1)
  1517. musb_g_wakeup(musb);
  1518. return n;
  1519. }
  1520. static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
  1521. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1522. #endif /* sysfs */
  1523. /* Only used to provide driver mode change events */
  1524. static void musb_irq_work(struct work_struct *data)
  1525. {
  1526. struct musb *musb = container_of(data, struct musb, irq_work);
  1527. static int old_state;
  1528. if (musb->xceiv.state != old_state) {
  1529. old_state = musb->xceiv.state;
  1530. sysfs_notify(&musb->controller->kobj, NULL, "mode");
  1531. }
  1532. }
  1533. /* --------------------------------------------------------------------------
  1534. * Init support
  1535. */
  1536. static struct musb *__init
  1537. allocate_instance(struct device *dev,
  1538. struct musb_hdrc_config *config, void __iomem *mbase)
  1539. {
  1540. struct musb *musb;
  1541. struct musb_hw_ep *ep;
  1542. int epnum;
  1543. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1544. struct usb_hcd *hcd;
  1545. hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev));
  1546. if (!hcd)
  1547. return NULL;
  1548. /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
  1549. musb = hcd_to_musb(hcd);
  1550. INIT_LIST_HEAD(&musb->control);
  1551. INIT_LIST_HEAD(&musb->in_bulk);
  1552. INIT_LIST_HEAD(&musb->out_bulk);
  1553. hcd->uses_new_polling = 1;
  1554. musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
  1555. #else
  1556. musb = kzalloc(sizeof *musb, GFP_KERNEL);
  1557. if (!musb)
  1558. return NULL;
  1559. dev_set_drvdata(dev, musb);
  1560. #endif
  1561. musb->mregs = mbase;
  1562. musb->ctrl_base = mbase;
  1563. musb->nIrq = -ENODEV;
  1564. musb->config = config;
  1565. BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
  1566. for (epnum = 0, ep = musb->endpoints;
  1567. epnum < musb->config->num_eps;
  1568. epnum++, ep++) {
  1569. ep->musb = musb;
  1570. ep->epnum = epnum;
  1571. }
  1572. musb->controller = dev;
  1573. return musb;
  1574. }
  1575. static void musb_free(struct musb *musb)
  1576. {
  1577. /* this has multiple entry modes. it handles fault cleanup after
  1578. * probe(), where things may be partially set up, as well as rmmod
  1579. * cleanup after everything's been de-activated.
  1580. */
  1581. #ifdef CONFIG_SYSFS
  1582. device_remove_file(musb->controller, &dev_attr_mode);
  1583. device_remove_file(musb->controller, &dev_attr_vbus);
  1584. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1585. device_remove_file(musb->controller, &dev_attr_srp);
  1586. #endif
  1587. #endif
  1588. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1589. musb_gadget_cleanup(musb);
  1590. #endif
  1591. if (musb->nIrq >= 0) {
  1592. if (musb->irq_wake)
  1593. disable_irq_wake(musb->nIrq);
  1594. free_irq(musb->nIrq, musb);
  1595. }
  1596. if (is_dma_capable() && musb->dma_controller) {
  1597. struct dma_controller *c = musb->dma_controller;
  1598. (void) c->stop(c);
  1599. dma_controller_destroy(c);
  1600. }
  1601. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1602. musb_platform_exit(musb);
  1603. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1604. if (musb->clock) {
  1605. clk_disable(musb->clock);
  1606. clk_put(musb->clock);
  1607. }
  1608. #ifdef CONFIG_USB_MUSB_OTG
  1609. put_device(musb->xceiv.dev);
  1610. #endif
  1611. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1612. usb_put_hcd(musb_to_hcd(musb));
  1613. #else
  1614. kfree(musb);
  1615. #endif
  1616. }
  1617. /*
  1618. * Perform generic per-controller initialization.
  1619. *
  1620. * @pDevice: the controller (already clocked, etc)
  1621. * @nIrq: irq
  1622. * @mregs: virtual address of controller registers,
  1623. * not yet corrected for platform-specific offsets
  1624. */
  1625. static int __init
  1626. musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  1627. {
  1628. int status;
  1629. struct musb *musb;
  1630. struct musb_hdrc_platform_data *plat = dev->platform_data;
  1631. /* The driver might handle more features than the board; OK.
  1632. * Fail when the board needs a feature that's not enabled.
  1633. */
  1634. if (!plat) {
  1635. dev_dbg(dev, "no platform_data?\n");
  1636. return -ENODEV;
  1637. }
  1638. switch (plat->mode) {
  1639. case MUSB_HOST:
  1640. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1641. break;
  1642. #else
  1643. goto bad_config;
  1644. #endif
  1645. case MUSB_PERIPHERAL:
  1646. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1647. break;
  1648. #else
  1649. goto bad_config;
  1650. #endif
  1651. case MUSB_OTG:
  1652. #ifdef CONFIG_USB_MUSB_OTG
  1653. break;
  1654. #else
  1655. bad_config:
  1656. #endif
  1657. default:
  1658. dev_err(dev, "incompatible Kconfig role setting\n");
  1659. return -EINVAL;
  1660. }
  1661. /* allocate */
  1662. musb = allocate_instance(dev, plat->config, ctrl);
  1663. if (!musb)
  1664. return -ENOMEM;
  1665. spin_lock_init(&musb->lock);
  1666. musb->board_mode = plat->mode;
  1667. musb->board_set_power = plat->set_power;
  1668. musb->set_clock = plat->set_clock;
  1669. musb->min_power = plat->min_power;
  1670. /* Clock usage is chip-specific ... functional clock (DaVinci,
  1671. * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
  1672. * code does is make sure a clock handle is available; platform
  1673. * code manages it during start/stop and suspend/resume.
  1674. */
  1675. if (plat->clock) {
  1676. musb->clock = clk_get(dev, plat->clock);
  1677. if (IS_ERR(musb->clock)) {
  1678. status = PTR_ERR(musb->clock);
  1679. musb->clock = NULL;
  1680. goto fail;
  1681. }
  1682. }
  1683. /* assume vbus is off */
  1684. /* platform adjusts musb->mregs and musb->isr if needed,
  1685. * and activates clocks
  1686. */
  1687. musb->isr = generic_interrupt;
  1688. status = musb_platform_init(musb);
  1689. if (status < 0)
  1690. goto fail;
  1691. if (!musb->isr) {
  1692. status = -ENODEV;
  1693. goto fail2;
  1694. }
  1695. #ifndef CONFIG_MUSB_PIO_ONLY
  1696. if (use_dma && dev->dma_mask) {
  1697. struct dma_controller *c;
  1698. c = dma_controller_create(musb, musb->mregs);
  1699. musb->dma_controller = c;
  1700. if (c)
  1701. (void) c->start(c);
  1702. }
  1703. #endif
  1704. /* ideally this would be abstracted in platform setup */
  1705. if (!is_dma_capable() || !musb->dma_controller)
  1706. dev->dma_mask = NULL;
  1707. /* be sure interrupts are disabled before connecting ISR */
  1708. musb_platform_disable(musb);
  1709. musb_generic_disable(musb);
  1710. /* setup musb parts of the core (especially endpoints) */
  1711. status = musb_core_init(plat->config->multipoint
  1712. ? MUSB_CONTROLLER_MHDRC
  1713. : MUSB_CONTROLLER_HDRC, musb);
  1714. if (status < 0)
  1715. goto fail2;
  1716. /* Init IRQ workqueue before request_irq */
  1717. INIT_WORK(&musb->irq_work, musb_irq_work);
  1718. /* attach to the IRQ */
  1719. if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
  1720. dev_err(dev, "request_irq %d failed!\n", nIrq);
  1721. status = -ENODEV;
  1722. goto fail2;
  1723. }
  1724. musb->nIrq = nIrq;
  1725. /* FIXME this handles wakeup irqs wrong */
  1726. if (enable_irq_wake(nIrq) == 0) {
  1727. musb->irq_wake = 1;
  1728. device_init_wakeup(dev, 1);
  1729. } else {
  1730. musb->irq_wake = 0;
  1731. }
  1732. pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n",
  1733. musb_driver_name,
  1734. ({char *s;
  1735. switch (musb->board_mode) {
  1736. case MUSB_HOST: s = "Host"; break;
  1737. case MUSB_PERIPHERAL: s = "Peripheral"; break;
  1738. default: s = "OTG"; break;
  1739. }; s; }),
  1740. ctrl,
  1741. (is_dma_capable() && musb->dma_controller)
  1742. ? "DMA" : "PIO",
  1743. musb->nIrq);
  1744. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1745. /* host side needs more setup, except for no-host modes */
  1746. if (musb->board_mode != MUSB_PERIPHERAL) {
  1747. struct usb_hcd *hcd = musb_to_hcd(musb);
  1748. if (musb->board_mode == MUSB_OTG)
  1749. hcd->self.otg_port = 1;
  1750. musb->xceiv.host = &hcd->self;
  1751. hcd->power_budget = 2 * (plat->power ? : 250);
  1752. }
  1753. #endif /* CONFIG_USB_MUSB_HDRC_HCD */
  1754. /* For the host-only role, we can activate right away.
  1755. * (We expect the ID pin to be forcibly grounded!!)
  1756. * Otherwise, wait till the gadget driver hooks up.
  1757. */
  1758. if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
  1759. MUSB_HST_MODE(musb);
  1760. musb->xceiv.default_a = 1;
  1761. musb->xceiv.state = OTG_STATE_A_IDLE;
  1762. status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
  1763. if (status)
  1764. goto fail;
  1765. DBG(1, "%s mode, status %d, devctl %02x %c\n",
  1766. "HOST", status,
  1767. musb_readb(musb->mregs, MUSB_DEVCTL),
  1768. (musb_readb(musb->mregs, MUSB_DEVCTL)
  1769. & MUSB_DEVCTL_BDEVICE
  1770. ? 'B' : 'A'));
  1771. } else /* peripheral is enabled */ {
  1772. MUSB_DEV_MODE(musb);
  1773. musb->xceiv.default_a = 0;
  1774. musb->xceiv.state = OTG_STATE_B_IDLE;
  1775. status = musb_gadget_setup(musb);
  1776. if (status)
  1777. goto fail;
  1778. DBG(1, "%s mode, status %d, dev%02x\n",
  1779. is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
  1780. status,
  1781. musb_readb(musb->mregs, MUSB_DEVCTL));
  1782. }
  1783. #ifdef CONFIG_SYSFS
  1784. status = device_create_file(dev, &dev_attr_mode);
  1785. status = device_create_file(dev, &dev_attr_vbus);
  1786. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1787. status = device_create_file(dev, &dev_attr_srp);
  1788. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1789. status = 0;
  1790. #endif
  1791. if (status)
  1792. goto fail2;
  1793. return 0;
  1794. fail2:
  1795. #ifdef CONFIG_SYSFS
  1796. device_remove_file(musb->controller, &dev_attr_mode);
  1797. device_remove_file(musb->controller, &dev_attr_vbus);
  1798. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1799. device_remove_file(musb->controller, &dev_attr_srp);
  1800. #endif
  1801. #endif
  1802. musb_platform_exit(musb);
  1803. fail:
  1804. dev_err(musb->controller,
  1805. "musb_init_controller failed with status %d\n", status);
  1806. if (musb->clock)
  1807. clk_put(musb->clock);
  1808. device_init_wakeup(dev, 0);
  1809. musb_free(musb);
  1810. return status;
  1811. }
  1812. /*-------------------------------------------------------------------------*/
  1813. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  1814. * bridge to a platform device; this driver then suffices.
  1815. */
  1816. #ifndef CONFIG_MUSB_PIO_ONLY
  1817. static u64 *orig_dma_mask;
  1818. #endif
  1819. static int __init musb_probe(struct platform_device *pdev)
  1820. {
  1821. struct device *dev = &pdev->dev;
  1822. int irq = platform_get_irq(pdev, 0);
  1823. struct resource *iomem;
  1824. void __iomem *base;
  1825. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1826. if (!iomem || irq == 0)
  1827. return -ENODEV;
  1828. base = ioremap(iomem->start, iomem->end - iomem->start + 1);
  1829. if (!base) {
  1830. dev_err(dev, "ioremap failed\n");
  1831. return -ENOMEM;
  1832. }
  1833. #ifndef CONFIG_MUSB_PIO_ONLY
  1834. /* clobbered by use_dma=n */
  1835. orig_dma_mask = dev->dma_mask;
  1836. #endif
  1837. return musb_init_controller(dev, irq, base);
  1838. }
  1839. static int __devexit musb_remove(struct platform_device *pdev)
  1840. {
  1841. struct musb *musb = dev_to_musb(&pdev->dev);
  1842. void __iomem *ctrl_base = musb->ctrl_base;
  1843. /* this gets called on rmmod.
  1844. * - Host mode: host may still be active
  1845. * - Peripheral mode: peripheral is deactivated (or never-activated)
  1846. * - OTG mode: both roles are deactivated (or never-activated)
  1847. */
  1848. musb_shutdown(pdev);
  1849. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1850. if (musb->board_mode == MUSB_HOST)
  1851. usb_remove_hcd(musb_to_hcd(musb));
  1852. #endif
  1853. musb_free(musb);
  1854. iounmap(ctrl_base);
  1855. device_init_wakeup(&pdev->dev, 0);
  1856. #ifndef CONFIG_MUSB_PIO_ONLY
  1857. pdev->dev.dma_mask = orig_dma_mask;
  1858. #endif
  1859. return 0;
  1860. }
  1861. #ifdef CONFIG_PM
  1862. static int musb_suspend(struct platform_device *pdev, pm_message_t message)
  1863. {
  1864. unsigned long flags;
  1865. struct musb *musb = dev_to_musb(&pdev->dev);
  1866. if (!musb->clock)
  1867. return 0;
  1868. spin_lock_irqsave(&musb->lock, flags);
  1869. if (is_peripheral_active(musb)) {
  1870. /* FIXME force disconnect unless we know USB will wake
  1871. * the system up quickly enough to respond ...
  1872. */
  1873. } else if (is_host_active(musb)) {
  1874. /* we know all the children are suspended; sometimes
  1875. * they will even be wakeup-enabled.
  1876. */
  1877. }
  1878. if (musb->set_clock)
  1879. musb->set_clock(musb->clock, 0);
  1880. else
  1881. clk_disable(musb->clock);
  1882. spin_unlock_irqrestore(&musb->lock, flags);
  1883. return 0;
  1884. }
  1885. static int musb_resume(struct platform_device *pdev)
  1886. {
  1887. unsigned long flags;
  1888. struct musb *musb = dev_to_musb(&pdev->dev);
  1889. if (!musb->clock)
  1890. return 0;
  1891. spin_lock_irqsave(&musb->lock, flags);
  1892. if (musb->set_clock)
  1893. musb->set_clock(musb->clock, 1);
  1894. else
  1895. clk_enable(musb->clock);
  1896. /* for static cmos like DaVinci, register values were preserved
  1897. * unless for some reason the whole soc powered down and we're
  1898. * not treating that as a whole-system restart (e.g. swsusp)
  1899. */
  1900. spin_unlock_irqrestore(&musb->lock, flags);
  1901. return 0;
  1902. }
  1903. #else
  1904. #define musb_suspend NULL
  1905. #define musb_resume NULL
  1906. #endif
  1907. static struct platform_driver musb_driver = {
  1908. .driver = {
  1909. .name = (char *)musb_driver_name,
  1910. .bus = &platform_bus_type,
  1911. .owner = THIS_MODULE,
  1912. },
  1913. .remove = __devexit_p(musb_remove),
  1914. .shutdown = musb_shutdown,
  1915. .suspend = musb_suspend,
  1916. .resume = musb_resume,
  1917. };
  1918. /*-------------------------------------------------------------------------*/
  1919. static int __init musb_init(void)
  1920. {
  1921. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1922. if (usb_disabled())
  1923. return 0;
  1924. #endif
  1925. pr_info("%s: version " MUSB_VERSION ", "
  1926. #ifdef CONFIG_MUSB_PIO_ONLY
  1927. "pio"
  1928. #elif defined(CONFIG_USB_TI_CPPI_DMA)
  1929. "cppi-dma"
  1930. #elif defined(CONFIG_USB_INVENTRA_DMA)
  1931. "musb-dma"
  1932. #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
  1933. "tusb-omap-dma"
  1934. #else
  1935. "?dma?"
  1936. #endif
  1937. ", "
  1938. #ifdef CONFIG_USB_MUSB_OTG
  1939. "otg (peripheral+host)"
  1940. #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
  1941. "peripheral"
  1942. #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
  1943. "host"
  1944. #endif
  1945. ", debug=%d\n",
  1946. musb_driver_name, musb_debug);
  1947. return platform_driver_probe(&musb_driver, musb_probe);
  1948. }
  1949. /* make us init after usbcore and i2c (transceivers, regulators, etc)
  1950. * and before usb gadget and host-side drivers start to register
  1951. */
  1952. fs_initcall(musb_init);
  1953. static void __exit musb_cleanup(void)
  1954. {
  1955. platform_driver_unregister(&musb_driver);
  1956. }
  1957. module_exit(musb_cleanup);