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