musb_core.c 60 KB

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