musb_core.c 60 KB

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