musb_core.c 61 KB

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