musb_core.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253
  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. * - <asm/arch/hdrc_cnf.h> for SOC or family details
  84. * - platform_device for addressing, irq, and platform_data
  85. * - platform_data is mostly for board-specific informarion
  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 debug;
  108. module_param(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. #ifndef CONFIG_USB_TUSB6010
  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. musb_root_disconnect(musb);
  689. if (musb->a_wait_bcon != 0)
  690. musb_platform_try_idle(musb, jiffies
  691. + msecs_to_jiffies(musb->a_wait_bcon));
  692. break;
  693. #endif /* HOST */
  694. #ifdef CONFIG_USB_MUSB_OTG
  695. case OTG_STATE_B_HOST:
  696. musb_hnp_stop(musb);
  697. break;
  698. case OTG_STATE_A_PERIPHERAL:
  699. musb_hnp_stop(musb);
  700. musb_root_disconnect(musb);
  701. /* FALLTHROUGH */
  702. case OTG_STATE_B_WAIT_ACON:
  703. /* FALLTHROUGH */
  704. #endif /* OTG */
  705. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  706. case OTG_STATE_B_PERIPHERAL:
  707. case OTG_STATE_B_IDLE:
  708. musb_g_disconnect(musb);
  709. break;
  710. #endif /* GADGET */
  711. default:
  712. WARNING("unhandled DISCONNECT transition (%s)\n",
  713. otg_state_string(musb));
  714. break;
  715. }
  716. schedule_work(&musb->irq_work);
  717. }
  718. if (int_usb & MUSB_INTR_SUSPEND) {
  719. DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
  720. otg_state_string(musb), devctl, power);
  721. handled = IRQ_HANDLED;
  722. switch (musb->xceiv.state) {
  723. #ifdef CONFIG_USB_MUSB_OTG
  724. case OTG_STATE_A_PERIPHERAL:
  725. /*
  726. * We cannot stop HNP here, devctl BDEVICE might be
  727. * still set.
  728. */
  729. break;
  730. #endif
  731. case OTG_STATE_B_PERIPHERAL:
  732. musb_g_suspend(musb);
  733. musb->is_active = is_otg_enabled(musb)
  734. && musb->xceiv.gadget->b_hnp_enable;
  735. if (musb->is_active) {
  736. #ifdef CONFIG_USB_MUSB_OTG
  737. musb->xceiv.state = OTG_STATE_B_WAIT_ACON;
  738. DBG(1, "HNP: Setting timer for b_ase0_brst\n");
  739. musb_otg_timer.data = (unsigned long)musb;
  740. mod_timer(&musb_otg_timer, jiffies
  741. + msecs_to_jiffies(TB_ASE0_BRST));
  742. #endif
  743. }
  744. break;
  745. case OTG_STATE_A_WAIT_BCON:
  746. if (musb->a_wait_bcon != 0)
  747. musb_platform_try_idle(musb, jiffies
  748. + msecs_to_jiffies(musb->a_wait_bcon));
  749. break;
  750. case OTG_STATE_A_HOST:
  751. musb->xceiv.state = OTG_STATE_A_SUSPEND;
  752. musb->is_active = is_otg_enabled(musb)
  753. && musb->xceiv.host->b_hnp_enable;
  754. break;
  755. case OTG_STATE_B_HOST:
  756. /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
  757. DBG(1, "REVISIT: SUSPEND as B_HOST\n");
  758. break;
  759. default:
  760. /* "should not happen" */
  761. musb->is_active = 0;
  762. break;
  763. }
  764. schedule_work(&musb->irq_work);
  765. }
  766. return handled;
  767. }
  768. /*-------------------------------------------------------------------------*/
  769. /*
  770. * Program the HDRC to start (enable interrupts, dma, etc.).
  771. */
  772. void musb_start(struct musb *musb)
  773. {
  774. void __iomem *regs = musb->mregs;
  775. u8 devctl = musb_readb(regs, MUSB_DEVCTL);
  776. DBG(2, "<== devctl %02x\n", devctl);
  777. /* Set INT enable registers, enable interrupts */
  778. musb_writew(regs, MUSB_INTRTXE, musb->epmask);
  779. musb_writew(regs, MUSB_INTRRXE, musb->epmask & 0xfffe);
  780. musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
  781. musb_writeb(regs, MUSB_TESTMODE, 0);
  782. /* put into basic highspeed mode and start session */
  783. musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
  784. | MUSB_POWER_SOFTCONN
  785. | MUSB_POWER_HSENAB
  786. /* ENSUSPEND wedges tusb */
  787. /* | MUSB_POWER_ENSUSPEND */
  788. );
  789. musb->is_active = 0;
  790. devctl = musb_readb(regs, MUSB_DEVCTL);
  791. devctl &= ~MUSB_DEVCTL_SESSION;
  792. if (is_otg_enabled(musb)) {
  793. /* session started after:
  794. * (a) ID-grounded irq, host mode;
  795. * (b) vbus present/connect IRQ, peripheral mode;
  796. * (c) peripheral initiates, using SRP
  797. */
  798. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  799. musb->is_active = 1;
  800. else
  801. devctl |= MUSB_DEVCTL_SESSION;
  802. } else if (is_host_enabled(musb)) {
  803. /* assume ID pin is hard-wired to ground */
  804. devctl |= MUSB_DEVCTL_SESSION;
  805. } else /* peripheral is enabled */ {
  806. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  807. musb->is_active = 1;
  808. }
  809. musb_platform_enable(musb);
  810. musb_writeb(regs, MUSB_DEVCTL, devctl);
  811. }
  812. static void musb_generic_disable(struct musb *musb)
  813. {
  814. void __iomem *mbase = musb->mregs;
  815. u16 temp;
  816. /* disable interrupts */
  817. musb_writeb(mbase, MUSB_INTRUSBE, 0);
  818. musb_writew(mbase, MUSB_INTRTXE, 0);
  819. musb_writew(mbase, MUSB_INTRRXE, 0);
  820. /* off */
  821. musb_writeb(mbase, MUSB_DEVCTL, 0);
  822. /* flush pending interrupts */
  823. temp = musb_readb(mbase, MUSB_INTRUSB);
  824. temp = musb_readw(mbase, MUSB_INTRTX);
  825. temp = musb_readw(mbase, MUSB_INTRRX);
  826. }
  827. /*
  828. * Make the HDRC stop (disable interrupts, etc.);
  829. * reversible by musb_start
  830. * called on gadget driver unregister
  831. * with controller locked, irqs blocked
  832. * acts as a NOP unless some role activated the hardware
  833. */
  834. void musb_stop(struct musb *musb)
  835. {
  836. /* stop IRQs, timers, ... */
  837. musb_platform_disable(musb);
  838. musb_generic_disable(musb);
  839. DBG(3, "HDRC disabled\n");
  840. /* FIXME
  841. * - mark host and/or peripheral drivers unusable/inactive
  842. * - disable DMA (and enable it in HdrcStart)
  843. * - make sure we can musb_start() after musb_stop(); with
  844. * OTG mode, gadget driver module rmmod/modprobe cycles that
  845. * - ...
  846. */
  847. musb_platform_try_idle(musb, 0);
  848. }
  849. static void musb_shutdown(struct platform_device *pdev)
  850. {
  851. struct musb *musb = dev_to_musb(&pdev->dev);
  852. unsigned long flags;
  853. spin_lock_irqsave(&musb->lock, flags);
  854. musb_platform_disable(musb);
  855. musb_generic_disable(musb);
  856. if (musb->clock) {
  857. clk_put(musb->clock);
  858. musb->clock = NULL;
  859. }
  860. spin_unlock_irqrestore(&musb->lock, flags);
  861. /* FIXME power down */
  862. }
  863. /*-------------------------------------------------------------------------*/
  864. /*
  865. * The silicon either has hard-wired endpoint configurations, or else
  866. * "dynamic fifo" sizing. The driver has support for both, though at this
  867. * writing only the dynamic sizing is very well tested. We use normal
  868. * idioms to so both modes are compile-tested, but dead code elimination
  869. * leaves only the relevant one in the object file.
  870. *
  871. * We don't currently use dynamic fifo setup capability to do anything
  872. * more than selecting one of a bunch of predefined configurations.
  873. */
  874. #if defined(CONFIG_USB_TUSB6010) || \
  875. defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
  876. static ushort __initdata fifo_mode = 4;
  877. #else
  878. static ushort __initdata fifo_mode = 2;
  879. #endif
  880. /* "modprobe ... fifo_mode=1" etc */
  881. module_param(fifo_mode, ushort, 0);
  882. MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  883. enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
  884. enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
  885. struct fifo_cfg {
  886. u8 hw_ep_num;
  887. enum fifo_style style;
  888. enum buf_mode mode;
  889. u16 maxpacket;
  890. };
  891. /*
  892. * tables defining fifo_mode values. define more if you like.
  893. * for host side, make sure both halves of ep1 are set up.
  894. */
  895. /* mode 0 - fits in 2KB */
  896. static struct fifo_cfg __initdata mode_0_cfg[] = {
  897. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  898. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  899. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
  900. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  901. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  902. };
  903. /* mode 1 - fits in 4KB */
  904. static struct fifo_cfg __initdata mode_1_cfg[] = {
  905. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  906. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  907. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  908. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  909. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  910. };
  911. /* mode 2 - fits in 4KB */
  912. static struct fifo_cfg __initdata mode_2_cfg[] = {
  913. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  914. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  915. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  916. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  917. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  918. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  919. };
  920. /* mode 3 - fits in 4KB */
  921. static struct fifo_cfg __initdata mode_3_cfg[] = {
  922. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  923. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  924. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  925. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  926. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  927. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  928. };
  929. /* mode 4 - fits in 16KB */
  930. static struct fifo_cfg __initdata mode_4_cfg[] = {
  931. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  932. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  933. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  934. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  935. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  936. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  937. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  938. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  939. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  940. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  941. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
  942. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
  943. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
  944. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
  945. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
  946. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
  947. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
  948. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
  949. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 512, },
  950. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 512, },
  951. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 512, },
  952. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 512, },
  953. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 512, },
  954. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 512, },
  955. { .hw_ep_num = 13, .style = FIFO_TX, .maxpacket = 512, },
  956. { .hw_ep_num = 13, .style = FIFO_RX, .maxpacket = 512, },
  957. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  958. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  959. };
  960. /*
  961. * configure a fifo; for non-shared endpoints, this may be called
  962. * once for a tx fifo and once for an rx fifo.
  963. *
  964. * returns negative errno or offset for next fifo.
  965. */
  966. static int __init
  967. fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
  968. const struct fifo_cfg *cfg, u16 offset)
  969. {
  970. void __iomem *mbase = musb->mregs;
  971. int size = 0;
  972. u16 maxpacket = cfg->maxpacket;
  973. u16 c_off = offset >> 3;
  974. u8 c_size;
  975. /* expect hw_ep has already been zero-initialized */
  976. size = ffs(max(maxpacket, (u16) 8)) - 1;
  977. maxpacket = 1 << size;
  978. c_size = size - 3;
  979. if (cfg->mode == BUF_DOUBLE) {
  980. if ((offset + (maxpacket << 1)) >
  981. (1 << (musb->config->ram_bits + 2)))
  982. return -EMSGSIZE;
  983. c_size |= MUSB_FIFOSZ_DPB;
  984. } else {
  985. if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
  986. return -EMSGSIZE;
  987. }
  988. /* configure the FIFO */
  989. musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
  990. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  991. /* EP0 reserved endpoint for control, bidirectional;
  992. * EP1 reserved for bulk, two unidirection halves.
  993. */
  994. if (hw_ep->epnum == 1)
  995. musb->bulk_ep = hw_ep;
  996. /* REVISIT error check: be sure ep0 can both rx and tx ... */
  997. #endif
  998. switch (cfg->style) {
  999. case FIFO_TX:
  1000. musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
  1001. musb_writew(mbase, MUSB_TXFIFOADD, c_off);
  1002. hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1003. hw_ep->max_packet_sz_tx = maxpacket;
  1004. break;
  1005. case FIFO_RX:
  1006. musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
  1007. musb_writew(mbase, MUSB_RXFIFOADD, c_off);
  1008. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1009. hw_ep->max_packet_sz_rx = maxpacket;
  1010. break;
  1011. case FIFO_RXTX:
  1012. musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
  1013. musb_writew(mbase, MUSB_TXFIFOADD, c_off);
  1014. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1015. hw_ep->max_packet_sz_rx = maxpacket;
  1016. musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
  1017. musb_writew(mbase, MUSB_RXFIFOADD, c_off);
  1018. hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
  1019. hw_ep->max_packet_sz_tx = maxpacket;
  1020. hw_ep->is_shared_fifo = true;
  1021. break;
  1022. }
  1023. /* NOTE rx and tx endpoint irqs aren't managed separately,
  1024. * which happens to be ok
  1025. */
  1026. musb->epmask |= (1 << hw_ep->epnum);
  1027. return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
  1028. }
  1029. static struct fifo_cfg __initdata ep0_cfg = {
  1030. .style = FIFO_RXTX, .maxpacket = 64,
  1031. };
  1032. static int __init ep_config_from_table(struct musb *musb)
  1033. {
  1034. const struct fifo_cfg *cfg;
  1035. unsigned i, n;
  1036. int offset;
  1037. struct musb_hw_ep *hw_ep = musb->endpoints;
  1038. switch (fifo_mode) {
  1039. default:
  1040. fifo_mode = 0;
  1041. /* FALLTHROUGH */
  1042. case 0:
  1043. cfg = mode_0_cfg;
  1044. n = ARRAY_SIZE(mode_0_cfg);
  1045. break;
  1046. case 1:
  1047. cfg = mode_1_cfg;
  1048. n = ARRAY_SIZE(mode_1_cfg);
  1049. break;
  1050. case 2:
  1051. cfg = mode_2_cfg;
  1052. n = ARRAY_SIZE(mode_2_cfg);
  1053. break;
  1054. case 3:
  1055. cfg = mode_3_cfg;
  1056. n = ARRAY_SIZE(mode_3_cfg);
  1057. break;
  1058. case 4:
  1059. cfg = mode_4_cfg;
  1060. n = ARRAY_SIZE(mode_4_cfg);
  1061. break;
  1062. }
  1063. printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
  1064. musb_driver_name, fifo_mode);
  1065. offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
  1066. /* assert(offset > 0) */
  1067. /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
  1068. * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
  1069. */
  1070. for (i = 0; i < n; i++) {
  1071. u8 epn = cfg->hw_ep_num;
  1072. if (epn >= musb->config->num_eps) {
  1073. pr_debug("%s: invalid ep %d\n",
  1074. musb_driver_name, epn);
  1075. continue;
  1076. }
  1077. offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
  1078. if (offset < 0) {
  1079. pr_debug("%s: mem overrun, ep %d\n",
  1080. musb_driver_name, epn);
  1081. return -EINVAL;
  1082. }
  1083. epn++;
  1084. musb->nr_endpoints = max(epn, musb->nr_endpoints);
  1085. }
  1086. printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n",
  1087. musb_driver_name,
  1088. n + 1, musb->config->num_eps * 2 - 1,
  1089. offset, (1 << (musb->config->ram_bits + 2)));
  1090. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1091. if (!musb->bulk_ep) {
  1092. pr_debug("%s: missing bulk\n", musb_driver_name);
  1093. return -EINVAL;
  1094. }
  1095. #endif
  1096. return 0;
  1097. }
  1098. /*
  1099. * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
  1100. * @param musb the controller
  1101. */
  1102. static int __init ep_config_from_hw(struct musb *musb)
  1103. {
  1104. u8 epnum = 0, reg;
  1105. struct musb_hw_ep *hw_ep;
  1106. void *mbase = musb->mregs;
  1107. DBG(2, "<== static silicon ep config\n");
  1108. /* FIXME pick up ep0 maxpacket size */
  1109. for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
  1110. musb_ep_select(mbase, epnum);
  1111. hw_ep = musb->endpoints + epnum;
  1112. /* read from core using indexed model */
  1113. reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE);
  1114. if (!reg) {
  1115. /* 0's returned when no more endpoints */
  1116. break;
  1117. }
  1118. musb->nr_endpoints++;
  1119. musb->epmask |= (1 << epnum);
  1120. hw_ep->max_packet_sz_tx = 1 << (reg & 0x0f);
  1121. /* shared TX/RX FIFO? */
  1122. if ((reg & 0xf0) == 0xf0) {
  1123. hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx;
  1124. hw_ep->is_shared_fifo = true;
  1125. continue;
  1126. } else {
  1127. hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4);
  1128. hw_ep->is_shared_fifo = false;
  1129. }
  1130. /* FIXME set up hw_ep->{rx,tx}_double_buffered */
  1131. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1132. /* pick an RX/TX endpoint for bulk */
  1133. if (hw_ep->max_packet_sz_tx < 512
  1134. || hw_ep->max_packet_sz_rx < 512)
  1135. continue;
  1136. /* REVISIT: this algorithm is lazy, we should at least
  1137. * try to pick a double buffered endpoint.
  1138. */
  1139. if (musb->bulk_ep)
  1140. continue;
  1141. musb->bulk_ep = hw_ep;
  1142. #endif
  1143. }
  1144. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1145. if (!musb->bulk_ep) {
  1146. pr_debug("%s: missing bulk\n", musb_driver_name);
  1147. return -EINVAL;
  1148. }
  1149. #endif
  1150. return 0;
  1151. }
  1152. enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
  1153. /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
  1154. * configure endpoints, or take their config from silicon
  1155. */
  1156. static int __init musb_core_init(u16 musb_type, struct musb *musb)
  1157. {
  1158. #ifdef MUSB_AHB_ID
  1159. u32 data;
  1160. #endif
  1161. u8 reg;
  1162. char *type;
  1163. u16 hwvers, rev_major, rev_minor;
  1164. char aInfo[78], aRevision[32], aDate[12];
  1165. void __iomem *mbase = musb->mregs;
  1166. int status = 0;
  1167. int i;
  1168. /* log core options (read using indexed model) */
  1169. musb_ep_select(mbase, 0);
  1170. reg = musb_readb(mbase, 0x10 + MUSB_CONFIGDATA);
  1171. strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
  1172. if (reg & MUSB_CONFIGDATA_DYNFIFO)
  1173. strcat(aInfo, ", dyn FIFOs");
  1174. if (reg & MUSB_CONFIGDATA_MPRXE) {
  1175. strcat(aInfo, ", bulk combine");
  1176. #ifdef C_MP_RX
  1177. musb->bulk_combine = true;
  1178. #else
  1179. strcat(aInfo, " (X)"); /* no driver support */
  1180. #endif
  1181. }
  1182. if (reg & MUSB_CONFIGDATA_MPTXE) {
  1183. strcat(aInfo, ", bulk split");
  1184. #ifdef C_MP_TX
  1185. musb->bulk_split = true;
  1186. #else
  1187. strcat(aInfo, " (X)"); /* no driver support */
  1188. #endif
  1189. }
  1190. if (reg & MUSB_CONFIGDATA_HBRXE) {
  1191. strcat(aInfo, ", HB-ISO Rx");
  1192. strcat(aInfo, " (X)"); /* no driver support */
  1193. }
  1194. if (reg & MUSB_CONFIGDATA_HBTXE) {
  1195. strcat(aInfo, ", HB-ISO Tx");
  1196. strcat(aInfo, " (X)"); /* no driver support */
  1197. }
  1198. if (reg & MUSB_CONFIGDATA_SOFTCONE)
  1199. strcat(aInfo, ", SoftConn");
  1200. printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
  1201. musb_driver_name, reg, aInfo);
  1202. #ifdef MUSB_AHB_ID
  1203. data = musb_readl(mbase, 0x404);
  1204. sprintf(aDate, "%04d-%02x-%02x", (data & 0xffff),
  1205. (data >> 16) & 0xff, (data >> 24) & 0xff);
  1206. /* FIXME ID2 and ID3 are unused */
  1207. data = musb_readl(mbase, 0x408);
  1208. printk(KERN_DEBUG "ID2=%lx\n", (long unsigned)data);
  1209. data = musb_readl(mbase, 0x40c);
  1210. printk(KERN_DEBUG "ID3=%lx\n", (long unsigned)data);
  1211. reg = musb_readb(mbase, 0x400);
  1212. musb_type = ('M' == reg) ? MUSB_CONTROLLER_MHDRC : MUSB_CONTROLLER_HDRC;
  1213. #else
  1214. aDate[0] = 0;
  1215. #endif
  1216. if (MUSB_CONTROLLER_MHDRC == musb_type) {
  1217. musb->is_multipoint = 1;
  1218. type = "M";
  1219. } else {
  1220. musb->is_multipoint = 0;
  1221. type = "";
  1222. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1223. #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
  1224. printk(KERN_ERR
  1225. "%s: kernel must blacklist external hubs\n",
  1226. musb_driver_name);
  1227. #endif
  1228. #endif
  1229. }
  1230. /* log release info */
  1231. hwvers = musb_readw(mbase, MUSB_HWVERS);
  1232. rev_major = (hwvers >> 10) & 0x1f;
  1233. rev_minor = hwvers & 0x3ff;
  1234. snprintf(aRevision, 32, "%d.%d%s", rev_major,
  1235. rev_minor, (hwvers & 0x8000) ? "RC" : "");
  1236. printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
  1237. musb_driver_name, type, aRevision, aDate);
  1238. /* configure ep0 */
  1239. musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
  1240. musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
  1241. /* discover endpoint configuration */
  1242. musb->nr_endpoints = 1;
  1243. musb->epmask = 1;
  1244. if (reg & MUSB_CONFIGDATA_DYNFIFO) {
  1245. if (musb->config->dyn_fifo)
  1246. status = ep_config_from_table(musb);
  1247. else {
  1248. ERR("reconfigure software for Dynamic FIFOs\n");
  1249. status = -ENODEV;
  1250. }
  1251. } else {
  1252. if (!musb->config->dyn_fifo)
  1253. status = ep_config_from_hw(musb);
  1254. else {
  1255. ERR("reconfigure software for static FIFOs\n");
  1256. return -ENODEV;
  1257. }
  1258. }
  1259. if (status < 0)
  1260. return status;
  1261. /* finish init, and print endpoint config */
  1262. for (i = 0; i < musb->nr_endpoints; i++) {
  1263. struct musb_hw_ep *hw_ep = musb->endpoints + i;
  1264. hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
  1265. #ifdef CONFIG_USB_TUSB6010
  1266. hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
  1267. hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
  1268. hw_ep->fifo_sync_va =
  1269. musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
  1270. if (i == 0)
  1271. hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
  1272. else
  1273. hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
  1274. #endif
  1275. hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
  1276. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1277. hw_ep->target_regs = MUSB_BUSCTL_OFFSET(i, 0) + mbase;
  1278. hw_ep->rx_reinit = 1;
  1279. hw_ep->tx_reinit = 1;
  1280. #endif
  1281. if (hw_ep->max_packet_sz_tx) {
  1282. printk(KERN_DEBUG
  1283. "%s: hw_ep %d%s, %smax %d\n",
  1284. musb_driver_name, i,
  1285. hw_ep->is_shared_fifo ? "shared" : "tx",
  1286. hw_ep->tx_double_buffered
  1287. ? "doublebuffer, " : "",
  1288. hw_ep->max_packet_sz_tx);
  1289. }
  1290. if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
  1291. printk(KERN_DEBUG
  1292. "%s: hw_ep %d%s, %smax %d\n",
  1293. musb_driver_name, i,
  1294. "rx",
  1295. hw_ep->rx_double_buffered
  1296. ? "doublebuffer, " : "",
  1297. hw_ep->max_packet_sz_rx);
  1298. }
  1299. if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
  1300. DBG(1, "hw_ep %d not configured\n", i);
  1301. }
  1302. return 0;
  1303. }
  1304. /*-------------------------------------------------------------------------*/
  1305. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
  1306. static irqreturn_t generic_interrupt(int irq, void *__hci)
  1307. {
  1308. unsigned long flags;
  1309. irqreturn_t retval = IRQ_NONE;
  1310. struct musb *musb = __hci;
  1311. spin_lock_irqsave(&musb->lock, flags);
  1312. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  1313. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  1314. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  1315. if (musb->int_usb || musb->int_tx || musb->int_rx)
  1316. retval = musb_interrupt(musb);
  1317. spin_unlock_irqrestore(&musb->lock, flags);
  1318. /* REVISIT we sometimes get spurious IRQs on g_ep0
  1319. * not clear why...
  1320. */
  1321. if (retval != IRQ_HANDLED)
  1322. DBG(5, "spurious?\n");
  1323. return IRQ_HANDLED;
  1324. }
  1325. #else
  1326. #define generic_interrupt NULL
  1327. #endif
  1328. /*
  1329. * handle all the irqs defined by the HDRC core. for now we expect: other
  1330. * irq sources (phy, dma, etc) will be handled first, musb->int_* values
  1331. * will be assigned, and the irq will already have been acked.
  1332. *
  1333. * called in irq context with spinlock held, irqs blocked
  1334. */
  1335. irqreturn_t musb_interrupt(struct musb *musb)
  1336. {
  1337. irqreturn_t retval = IRQ_NONE;
  1338. u8 devctl, power;
  1339. int ep_num;
  1340. u32 reg;
  1341. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1342. power = musb_readb(musb->mregs, MUSB_POWER);
  1343. DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n",
  1344. (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
  1345. musb->int_usb, musb->int_tx, musb->int_rx);
  1346. /* the core can interrupt us for multiple reasons; docs have
  1347. * a generic interrupt flowchart to follow
  1348. */
  1349. if (musb->int_usb & STAGE0_MASK)
  1350. retval |= musb_stage0_irq(musb, musb->int_usb,
  1351. devctl, power);
  1352. /* "stage 1" is handling endpoint irqs */
  1353. /* handle endpoint 0 first */
  1354. if (musb->int_tx & 1) {
  1355. if (devctl & MUSB_DEVCTL_HM)
  1356. retval |= musb_h_ep0_irq(musb);
  1357. else
  1358. retval |= musb_g_ep0_irq(musb);
  1359. }
  1360. /* RX on endpoints 1-15 */
  1361. reg = musb->int_rx >> 1;
  1362. ep_num = 1;
  1363. while (reg) {
  1364. if (reg & 1) {
  1365. /* musb_ep_select(musb->mregs, ep_num); */
  1366. /* REVISIT just retval = ep->rx_irq(...) */
  1367. retval = IRQ_HANDLED;
  1368. if (devctl & MUSB_DEVCTL_HM) {
  1369. if (is_host_capable())
  1370. musb_host_rx(musb, ep_num);
  1371. } else {
  1372. if (is_peripheral_capable())
  1373. musb_g_rx(musb, ep_num);
  1374. }
  1375. }
  1376. reg >>= 1;
  1377. ep_num++;
  1378. }
  1379. /* TX on endpoints 1-15 */
  1380. reg = musb->int_tx >> 1;
  1381. ep_num = 1;
  1382. while (reg) {
  1383. if (reg & 1) {
  1384. /* musb_ep_select(musb->mregs, ep_num); */
  1385. /* REVISIT just retval |= ep->tx_irq(...) */
  1386. retval = IRQ_HANDLED;
  1387. if (devctl & MUSB_DEVCTL_HM) {
  1388. if (is_host_capable())
  1389. musb_host_tx(musb, ep_num);
  1390. } else {
  1391. if (is_peripheral_capable())
  1392. musb_g_tx(musb, ep_num);
  1393. }
  1394. }
  1395. reg >>= 1;
  1396. ep_num++;
  1397. }
  1398. /* finish handling "global" interrupts after handling fifos */
  1399. if (musb->int_usb)
  1400. retval |= musb_stage2_irq(musb,
  1401. musb->int_usb, devctl, power);
  1402. return retval;
  1403. }
  1404. #ifndef CONFIG_MUSB_PIO_ONLY
  1405. static int __initdata use_dma = 1;
  1406. /* "modprobe ... use_dma=0" etc */
  1407. module_param(use_dma, bool, 0);
  1408. MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
  1409. void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
  1410. {
  1411. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1412. /* called with controller lock already held */
  1413. if (!epnum) {
  1414. #ifndef CONFIG_USB_TUSB_OMAP_DMA
  1415. if (!is_cppi_enabled()) {
  1416. /* endpoint 0 */
  1417. if (devctl & MUSB_DEVCTL_HM)
  1418. musb_h_ep0_irq(musb);
  1419. else
  1420. musb_g_ep0_irq(musb);
  1421. }
  1422. #endif
  1423. } else {
  1424. /* endpoints 1..15 */
  1425. if (transmit) {
  1426. if (devctl & MUSB_DEVCTL_HM) {
  1427. if (is_host_capable())
  1428. musb_host_tx(musb, epnum);
  1429. } else {
  1430. if (is_peripheral_capable())
  1431. musb_g_tx(musb, epnum);
  1432. }
  1433. } else {
  1434. /* receive */
  1435. if (devctl & MUSB_DEVCTL_HM) {
  1436. if (is_host_capable())
  1437. musb_host_rx(musb, epnum);
  1438. } else {
  1439. if (is_peripheral_capable())
  1440. musb_g_rx(musb, epnum);
  1441. }
  1442. }
  1443. }
  1444. }
  1445. #else
  1446. #define use_dma 0
  1447. #endif
  1448. /*-------------------------------------------------------------------------*/
  1449. #ifdef CONFIG_SYSFS
  1450. static ssize_t
  1451. musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1452. {
  1453. struct musb *musb = dev_to_musb(dev);
  1454. unsigned long flags;
  1455. int ret = -EINVAL;
  1456. spin_lock_irqsave(&musb->lock, flags);
  1457. ret = sprintf(buf, "%s\n", otg_state_string(musb));
  1458. spin_unlock_irqrestore(&musb->lock, flags);
  1459. return ret;
  1460. }
  1461. static ssize_t
  1462. musb_mode_store(struct device *dev, struct device_attribute *attr,
  1463. const char *buf, size_t n)
  1464. {
  1465. struct musb *musb = dev_to_musb(dev);
  1466. unsigned long flags;
  1467. spin_lock_irqsave(&musb->lock, flags);
  1468. if (!strncmp(buf, "host", 4))
  1469. musb_platform_set_mode(musb, MUSB_HOST);
  1470. if (!strncmp(buf, "peripheral", 10))
  1471. musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  1472. if (!strncmp(buf, "otg", 3))
  1473. musb_platform_set_mode(musb, MUSB_OTG);
  1474. spin_unlock_irqrestore(&musb->lock, flags);
  1475. return n;
  1476. }
  1477. static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
  1478. static ssize_t
  1479. musb_vbus_store(struct device *dev, struct device_attribute *attr,
  1480. const char *buf, size_t n)
  1481. {
  1482. struct musb *musb = dev_to_musb(dev);
  1483. unsigned long flags;
  1484. unsigned long val;
  1485. if (sscanf(buf, "%lu", &val) < 1) {
  1486. printk(KERN_ERR "Invalid VBUS timeout ms value\n");
  1487. return -EINVAL;
  1488. }
  1489. spin_lock_irqsave(&musb->lock, flags);
  1490. musb->a_wait_bcon = val;
  1491. if (musb->xceiv.state == OTG_STATE_A_WAIT_BCON)
  1492. musb->is_active = 0;
  1493. musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
  1494. spin_unlock_irqrestore(&musb->lock, flags);
  1495. return n;
  1496. }
  1497. static ssize_t
  1498. musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
  1499. {
  1500. struct musb *musb = dev_to_musb(dev);
  1501. unsigned long flags;
  1502. unsigned long val;
  1503. int vbus;
  1504. spin_lock_irqsave(&musb->lock, flags);
  1505. val = musb->a_wait_bcon;
  1506. vbus = musb_platform_get_vbus_status(musb);
  1507. spin_unlock_irqrestore(&musb->lock, flags);
  1508. return sprintf(buf, "Vbus %s, timeout %lu\n",
  1509. vbus ? "on" : "off", val);
  1510. }
  1511. static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
  1512. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1513. /* Gadget drivers can't know that a host is connected so they might want
  1514. * to start SRP, but users can. This allows userspace to trigger SRP.
  1515. */
  1516. static ssize_t
  1517. musb_srp_store(struct device *dev, struct device_attribute *attr,
  1518. const char *buf, size_t n)
  1519. {
  1520. struct musb *musb = dev_to_musb(dev);
  1521. unsigned short srp;
  1522. if (sscanf(buf, "%hu", &srp) != 1
  1523. || (srp != 1)) {
  1524. printk(KERN_ERR "SRP: Value must be 1\n");
  1525. return -EINVAL;
  1526. }
  1527. if (srp == 1)
  1528. musb_g_wakeup(musb);
  1529. return n;
  1530. }
  1531. static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
  1532. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1533. #endif /* sysfs */
  1534. /* Only used to provide driver mode change events */
  1535. static void musb_irq_work(struct work_struct *data)
  1536. {
  1537. struct musb *musb = container_of(data, struct musb, irq_work);
  1538. static int old_state;
  1539. if (musb->xceiv.state != old_state) {
  1540. old_state = musb->xceiv.state;
  1541. sysfs_notify(&musb->controller->kobj, NULL, "mode");
  1542. }
  1543. }
  1544. /* --------------------------------------------------------------------------
  1545. * Init support
  1546. */
  1547. static struct musb *__init
  1548. allocate_instance(struct device *dev,
  1549. struct musb_hdrc_config *config, void __iomem *mbase)
  1550. {
  1551. struct musb *musb;
  1552. struct musb_hw_ep *ep;
  1553. int epnum;
  1554. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1555. struct usb_hcd *hcd;
  1556. hcd = usb_create_hcd(&musb_hc_driver, dev, dev->bus_id);
  1557. if (!hcd)
  1558. return NULL;
  1559. /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
  1560. musb = hcd_to_musb(hcd);
  1561. INIT_LIST_HEAD(&musb->control);
  1562. INIT_LIST_HEAD(&musb->in_bulk);
  1563. INIT_LIST_HEAD(&musb->out_bulk);
  1564. hcd->uses_new_polling = 1;
  1565. musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
  1566. #else
  1567. musb = kzalloc(sizeof *musb, GFP_KERNEL);
  1568. if (!musb)
  1569. return NULL;
  1570. dev_set_drvdata(dev, musb);
  1571. #endif
  1572. musb->mregs = mbase;
  1573. musb->ctrl_base = mbase;
  1574. musb->nIrq = -ENODEV;
  1575. musb->config = config;
  1576. for (epnum = 0, ep = musb->endpoints;
  1577. epnum < musb->config->num_eps;
  1578. epnum++, ep++) {
  1579. ep->musb = musb;
  1580. ep->epnum = epnum;
  1581. }
  1582. musb->controller = dev;
  1583. return musb;
  1584. }
  1585. static void musb_free(struct musb *musb)
  1586. {
  1587. /* this has multiple entry modes. it handles fault cleanup after
  1588. * probe(), where things may be partially set up, as well as rmmod
  1589. * cleanup after everything's been de-activated.
  1590. */
  1591. #ifdef CONFIG_SYSFS
  1592. device_remove_file(musb->controller, &dev_attr_mode);
  1593. device_remove_file(musb->controller, &dev_attr_vbus);
  1594. #ifdef CONFIG_USB_MUSB_OTG
  1595. device_remove_file(musb->controller, &dev_attr_srp);
  1596. #endif
  1597. #endif
  1598. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1599. musb_gadget_cleanup(musb);
  1600. #endif
  1601. if (musb->nIrq >= 0) {
  1602. disable_irq_wake(musb->nIrq);
  1603. free_irq(musb->nIrq, musb);
  1604. }
  1605. if (is_dma_capable() && musb->dma_controller) {
  1606. struct dma_controller *c = musb->dma_controller;
  1607. (void) c->stop(c);
  1608. dma_controller_destroy(c);
  1609. }
  1610. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1611. musb_platform_exit(musb);
  1612. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1613. if (musb->clock) {
  1614. clk_disable(musb->clock);
  1615. clk_put(musb->clock);
  1616. }
  1617. #ifdef CONFIG_USB_MUSB_OTG
  1618. put_device(musb->xceiv.dev);
  1619. #endif
  1620. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1621. usb_put_hcd(musb_to_hcd(musb));
  1622. #else
  1623. kfree(musb);
  1624. #endif
  1625. }
  1626. /*
  1627. * Perform generic per-controller initialization.
  1628. *
  1629. * @pDevice: the controller (already clocked, etc)
  1630. * @nIrq: irq
  1631. * @mregs: virtual address of controller registers,
  1632. * not yet corrected for platform-specific offsets
  1633. */
  1634. static int __init
  1635. musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  1636. {
  1637. int status;
  1638. struct musb *musb;
  1639. struct musb_hdrc_platform_data *plat = dev->platform_data;
  1640. /* The driver might handle more features than the board; OK.
  1641. * Fail when the board needs a feature that's not enabled.
  1642. */
  1643. if (!plat) {
  1644. dev_dbg(dev, "no platform_data?\n");
  1645. return -ENODEV;
  1646. }
  1647. switch (plat->mode) {
  1648. case MUSB_HOST:
  1649. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1650. break;
  1651. #else
  1652. goto bad_config;
  1653. #endif
  1654. case MUSB_PERIPHERAL:
  1655. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1656. break;
  1657. #else
  1658. goto bad_config;
  1659. #endif
  1660. case MUSB_OTG:
  1661. #ifdef CONFIG_USB_MUSB_OTG
  1662. break;
  1663. #else
  1664. bad_config:
  1665. #endif
  1666. default:
  1667. dev_err(dev, "incompatible Kconfig role setting\n");
  1668. return -EINVAL;
  1669. }
  1670. /* allocate */
  1671. musb = allocate_instance(dev, plat->config, ctrl);
  1672. if (!musb)
  1673. return -ENOMEM;
  1674. spin_lock_init(&musb->lock);
  1675. musb->board_mode = plat->mode;
  1676. musb->board_set_power = plat->set_power;
  1677. musb->set_clock = plat->set_clock;
  1678. musb->min_power = plat->min_power;
  1679. /* Clock usage is chip-specific ... functional clock (DaVinci,
  1680. * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
  1681. * code does is make sure a clock handle is available; platform
  1682. * code manages it during start/stop and suspend/resume.
  1683. */
  1684. if (plat->clock) {
  1685. musb->clock = clk_get(dev, plat->clock);
  1686. if (IS_ERR(musb->clock)) {
  1687. status = PTR_ERR(musb->clock);
  1688. musb->clock = NULL;
  1689. goto fail;
  1690. }
  1691. }
  1692. /* assume vbus is off */
  1693. /* platform adjusts musb->mregs and musb->isr if needed,
  1694. * and activates clocks
  1695. */
  1696. musb->isr = generic_interrupt;
  1697. status = musb_platform_init(musb);
  1698. if (status < 0)
  1699. goto fail;
  1700. if (!musb->isr) {
  1701. status = -ENODEV;
  1702. goto fail2;
  1703. }
  1704. #ifndef CONFIG_MUSB_PIO_ONLY
  1705. if (use_dma && dev->dma_mask) {
  1706. struct dma_controller *c;
  1707. c = dma_controller_create(musb, musb->mregs);
  1708. musb->dma_controller = c;
  1709. if (c)
  1710. (void) c->start(c);
  1711. }
  1712. #endif
  1713. /* ideally this would be abstracted in platform setup */
  1714. if (!is_dma_capable() || !musb->dma_controller)
  1715. dev->dma_mask = NULL;
  1716. /* be sure interrupts are disabled before connecting ISR */
  1717. musb_platform_disable(musb);
  1718. musb_generic_disable(musb);
  1719. /* setup musb parts of the core (especially endpoints) */
  1720. status = musb_core_init(plat->config->multipoint
  1721. ? MUSB_CONTROLLER_MHDRC
  1722. : MUSB_CONTROLLER_HDRC, musb);
  1723. if (status < 0)
  1724. goto fail2;
  1725. /* Init IRQ workqueue before request_irq */
  1726. INIT_WORK(&musb->irq_work, musb_irq_work);
  1727. /* attach to the IRQ */
  1728. if (request_irq(nIrq, musb->isr, 0, dev->bus_id, musb)) {
  1729. dev_err(dev, "request_irq %d failed!\n", nIrq);
  1730. status = -ENODEV;
  1731. goto fail2;
  1732. }
  1733. musb->nIrq = nIrq;
  1734. /* FIXME this handles wakeup irqs wrong */
  1735. if (enable_irq_wake(nIrq) == 0)
  1736. device_init_wakeup(dev, 1);
  1737. pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n",
  1738. musb_driver_name,
  1739. ({char *s;
  1740. switch (musb->board_mode) {
  1741. case MUSB_HOST: s = "Host"; break;
  1742. case MUSB_PERIPHERAL: s = "Peripheral"; break;
  1743. default: s = "OTG"; break;
  1744. }; s; }),
  1745. ctrl,
  1746. (is_dma_capable() && musb->dma_controller)
  1747. ? "DMA" : "PIO",
  1748. musb->nIrq);
  1749. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1750. /* host side needs more setup, except for no-host modes */
  1751. if (musb->board_mode != MUSB_PERIPHERAL) {
  1752. struct usb_hcd *hcd = musb_to_hcd(musb);
  1753. if (musb->board_mode == MUSB_OTG)
  1754. hcd->self.otg_port = 1;
  1755. musb->xceiv.host = &hcd->self;
  1756. hcd->power_budget = 2 * (plat->power ? : 250);
  1757. }
  1758. #endif /* CONFIG_USB_MUSB_HDRC_HCD */
  1759. /* For the host-only role, we can activate right away.
  1760. * (We expect the ID pin to be forcibly grounded!!)
  1761. * Otherwise, wait till the gadget driver hooks up.
  1762. */
  1763. if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
  1764. MUSB_HST_MODE(musb);
  1765. musb->xceiv.default_a = 1;
  1766. musb->xceiv.state = OTG_STATE_A_IDLE;
  1767. status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
  1768. if (status)
  1769. goto fail;
  1770. DBG(1, "%s mode, status %d, devctl %02x %c\n",
  1771. "HOST", status,
  1772. musb_readb(musb->mregs, MUSB_DEVCTL),
  1773. (musb_readb(musb->mregs, MUSB_DEVCTL)
  1774. & MUSB_DEVCTL_BDEVICE
  1775. ? 'B' : 'A'));
  1776. } else /* peripheral is enabled */ {
  1777. MUSB_DEV_MODE(musb);
  1778. musb->xceiv.default_a = 0;
  1779. musb->xceiv.state = OTG_STATE_B_IDLE;
  1780. status = musb_gadget_setup(musb);
  1781. if (status)
  1782. goto fail;
  1783. DBG(1, "%s mode, status %d, dev%02x\n",
  1784. is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
  1785. status,
  1786. musb_readb(musb->mregs, MUSB_DEVCTL));
  1787. }
  1788. return 0;
  1789. fail:
  1790. if (musb->clock)
  1791. clk_put(musb->clock);
  1792. device_init_wakeup(dev, 0);
  1793. musb_free(musb);
  1794. return status;
  1795. #ifdef CONFIG_SYSFS
  1796. status = device_create_file(dev, &dev_attr_mode);
  1797. status = device_create_file(dev, &dev_attr_vbus);
  1798. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1799. status = device_create_file(dev, &dev_attr_srp);
  1800. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1801. status = 0;
  1802. #endif
  1803. return status;
  1804. fail2:
  1805. musb_platform_exit(musb);
  1806. goto fail;
  1807. }
  1808. /*-------------------------------------------------------------------------*/
  1809. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  1810. * bridge to a platform device; this driver then suffices.
  1811. */
  1812. #ifndef CONFIG_MUSB_PIO_ONLY
  1813. static u64 *orig_dma_mask;
  1814. #endif
  1815. static int __init musb_probe(struct platform_device *pdev)
  1816. {
  1817. struct device *dev = &pdev->dev;
  1818. int irq = platform_get_irq(pdev, 0);
  1819. struct resource *iomem;
  1820. void __iomem *base;
  1821. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1822. if (!iomem || irq == 0)
  1823. return -ENODEV;
  1824. base = ioremap(iomem->start, iomem->end - iomem->start + 1);
  1825. if (!base) {
  1826. dev_err(dev, "ioremap failed\n");
  1827. return -ENOMEM;
  1828. }
  1829. #ifndef CONFIG_MUSB_PIO_ONLY
  1830. /* clobbered by use_dma=n */
  1831. orig_dma_mask = dev->dma_mask;
  1832. #endif
  1833. return musb_init_controller(dev, irq, base);
  1834. }
  1835. static int __devexit musb_remove(struct platform_device *pdev)
  1836. {
  1837. struct musb *musb = dev_to_musb(&pdev->dev);
  1838. void __iomem *ctrl_base = musb->ctrl_base;
  1839. /* this gets called on rmmod.
  1840. * - Host mode: host may still be active
  1841. * - Peripheral mode: peripheral is deactivated (or never-activated)
  1842. * - OTG mode: both roles are deactivated (or never-activated)
  1843. */
  1844. musb_shutdown(pdev);
  1845. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1846. if (musb->board_mode == MUSB_HOST)
  1847. usb_remove_hcd(musb_to_hcd(musb));
  1848. #endif
  1849. musb_free(musb);
  1850. iounmap(ctrl_base);
  1851. device_init_wakeup(&pdev->dev, 0);
  1852. #ifndef CONFIG_MUSB_PIO_ONLY
  1853. pdev->dev.dma_mask = orig_dma_mask;
  1854. #endif
  1855. return 0;
  1856. }
  1857. #ifdef CONFIG_PM
  1858. static int musb_suspend(struct platform_device *pdev, pm_message_t message)
  1859. {
  1860. unsigned long flags;
  1861. struct musb *musb = dev_to_musb(&pdev->dev);
  1862. if (!musb->clock)
  1863. return 0;
  1864. spin_lock_irqsave(&musb->lock, flags);
  1865. if (is_peripheral_active(musb)) {
  1866. /* FIXME force disconnect unless we know USB will wake
  1867. * the system up quickly enough to respond ...
  1868. */
  1869. } else if (is_host_active(musb)) {
  1870. /* we know all the children are suspended; sometimes
  1871. * they will even be wakeup-enabled.
  1872. */
  1873. }
  1874. if (musb->set_clock)
  1875. musb->set_clock(musb->clock, 0);
  1876. else
  1877. clk_disable(musb->clock);
  1878. spin_unlock_irqrestore(&musb->lock, flags);
  1879. return 0;
  1880. }
  1881. static int musb_resume(struct platform_device *pdev)
  1882. {
  1883. unsigned long flags;
  1884. struct musb *musb = dev_to_musb(&pdev->dev);
  1885. if (!musb->clock)
  1886. return 0;
  1887. spin_lock_irqsave(&musb->lock, flags);
  1888. if (musb->set_clock)
  1889. musb->set_clock(musb->clock, 1);
  1890. else
  1891. clk_enable(musb->clock);
  1892. /* for static cmos like DaVinci, register values were preserved
  1893. * unless for some reason the whole soc powered down and we're
  1894. * not treating that as a whole-system restart (e.g. swsusp)
  1895. */
  1896. spin_unlock_irqrestore(&musb->lock, flags);
  1897. return 0;
  1898. }
  1899. #else
  1900. #define musb_suspend NULL
  1901. #define musb_resume NULL
  1902. #endif
  1903. static struct platform_driver musb_driver = {
  1904. .driver = {
  1905. .name = (char *)musb_driver_name,
  1906. .bus = &platform_bus_type,
  1907. .owner = THIS_MODULE,
  1908. },
  1909. .remove = __devexit_p(musb_remove),
  1910. .shutdown = musb_shutdown,
  1911. .suspend = musb_suspend,
  1912. .resume = musb_resume,
  1913. };
  1914. /*-------------------------------------------------------------------------*/
  1915. static int __init musb_init(void)
  1916. {
  1917. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1918. if (usb_disabled())
  1919. return 0;
  1920. #endif
  1921. pr_info("%s: version " MUSB_VERSION ", "
  1922. #ifdef CONFIG_MUSB_PIO_ONLY
  1923. "pio"
  1924. #elif defined(CONFIG_USB_TI_CPPI_DMA)
  1925. "cppi-dma"
  1926. #elif defined(CONFIG_USB_INVENTRA_DMA)
  1927. "musb-dma"
  1928. #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
  1929. "tusb-omap-dma"
  1930. #else
  1931. "?dma?"
  1932. #endif
  1933. ", "
  1934. #ifdef CONFIG_USB_MUSB_OTG
  1935. "otg (peripheral+host)"
  1936. #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
  1937. "peripheral"
  1938. #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
  1939. "host"
  1940. #endif
  1941. ", debug=%d\n",
  1942. musb_driver_name, debug);
  1943. return platform_driver_probe(&musb_driver, musb_probe);
  1944. }
  1945. /* make us init after usbcore and before usb
  1946. * gadget and host-side drivers start to register
  1947. */
  1948. subsys_initcall(musb_init);
  1949. static void __exit musb_cleanup(void)
  1950. {
  1951. platform_driver_unregister(&musb_driver);
  1952. }
  1953. module_exit(musb_cleanup);